Fractal UI Motif Fractal UI Type
On this Page

CollisionRect

CollisionRect describes the measured bounds of one sortable item. It is a TypeScript type used with the collection helpers exported from fractalsvelte/motion; it has no runtime constructor or rendered component.

Usage

TypeScript
import { closestCenter, type CollisionRect } from "fractalsvelte/motion";

const rects: CollisionRect[] = [
	{ id: "alpha", left: 0, top: 0, width: 120, height: 48 },
	{ id: "beta", left: 0, top: 64, width: 120, height: 48 },
];

const closestId = closestCenter({ x: 60, y: 80 }, rects);
// "beta"

API

FieldTypeDescription
idstringStable identifier returned by collision resolution.
leftnumberLeft edge in the coordinate space used for the pointer.
topnumberTop edge in the coordinate space used for the pointer.
widthnumberMeasured width of the item.
heightnumberMeasured height of the item.

Pass a CollisionRect[] to closestCenter(point, rects) to find the closest item by centre point. The collection module also exports moveBetween for immutable list transfers and moveTreeNode for immutable nested-tree moves.