@weasel-js/guides 1.15.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -36
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/grid/roundToCell.ts","../src/grid/axes.ts","../src/grid/lattice.ts","../src/grid/reading.ts","../src/grid/regions.ts","../src/grid/pointToGridCell.ts","../src/grid/useGridCellHover.ts","../src/grid/layer.ts","../src/grid/cellHighlight.ts","../src/grid/fit.ts","../src/sources/lines.ts","../src/sources/grid.ts","../src/grid/preset.ts","../src/guides/useGuides.ts","../src/guides/layer.ts","../src/guides/alignment/derive.ts","../src/guides/alignment/spacing.ts","../src/guides/alignment/sceneBounds.ts","../src/strategies/onPlane.ts","../src/sources/guides.ts","../src/guides/alignment/match.ts","../src/sources/targets.ts","../src/sources/alignment.ts","../src/sources/spacing.ts","../src/spacingHints/distance.ts","../src/spacingHints/distanceReadout.ts","../src/spacingHints/preset.ts","../src/layout/snaps.ts","../src/layout/perContainer.ts","../src/layout/strategies/freeform.ts","../src/layout/strategies/tileGrid.ts","../src/layout/strategies/snapPoint.ts","../src/layout/strategies/sequence.ts","../src/layout/strategies/slots.ts","../src/layout/strategies/pack.ts","../src/layout/strategies/quadtree.ts","../src/layout/strategies/arrangements.ts"],"names":["lo","hi","mid","span","periodic","cell","applyToPoint","PATH_M","PATH_L","box","invert","viewportWorldRect","mat3","sceneUnitScopes","useState","useLatest","useCallback","EPS","AUTO_POSE_DESCRIPTOR","scenePoseFrame","visualBoundsViaDescriptor","nodeGates","cross","at","pack","createTransformOp","slots","defaultCenterOf","rectOf"],"mappings":";;;;;AACO,SAAS,WAAA,CAAY,OAAe,QAAA,EAA0B;AACnE,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,QAAQ,IAAI,QAAA,IAAY,CAAA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5C,EAAA,OAAO,CAAC,QAAQ,KAAA,KAAU;AACxB,IAAA,MAAM,EAAA,GAAK,MAAA,CAAO,KAAA,GAAQ,CAAA,GAAI,KAAA;AAC9B,IAAA,MAAM,EAAA,GAAK,MAAA,CAAO,MAAA,GAAS,CAAA,GAAI,KAAA;AAC/B,IAAA,MAAM,QAAQ,MAAA,GAAS,KAAA,GAAQ,KAAK,GAAA,CAAI,KAAA,GAAQ,GAAG,CAAC,CAAA;AACpD,IAAA,MAAM,MAAc,EAAC;AACrB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,EAAO,CAAA,EAAA,EAAK;AAC9B,MAAA,MAAM,KAAA,GAAQ,KAAA,GAAS,KAAA,GAAQ,CAAA,GAAK,KAAA;AACpC,MAAA,GAAA,CAAI,IAAA,CAAK;AAAA,QACP,CAAA,EAAG,OAAO,CAAA,GAAI,MAAA,CAAO,QAAQ,CAAA,GAAI,EAAA,GAAK,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA;AAAA,QACpD,CAAA,EAAG,OAAO,CAAA,GAAI,MAAA,CAAO,SAAS,CAAA,GAAI,EAAA,GAAK,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA;AAAA,QACrD;AAAA,OACD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["/** Round `value` to the nearest multiple of `cellSize`. Returns 0 when the result would be -0. */\nexport function roundToCell(value: number, cellSize: number): number {\n return Math.round(value / cellSize) * cellSize || 0;\n}\n","import type { PerAxis, PlaneValue } from '@weasel-js/core';\n\n/** A length on a grid: a bare number, or a value tagged with a unit. */\nexport type GridLength = Exclude<PlaneValue, PerAxis<unknown>>;\n\n/**\n * One axis of a grid: a pitch from zero; a pitch with an `offset` its lines\n * pass through, limited to `from`..`to` (inclusive); or lines at explicit\n * positions, for uneven bays. Positions are measured from the grid's origin:\n * a container's corner, or the root's origin. A pitch that is not a positive\n * finite number gives the axis no lines.\n */\nexport type GridAxis =\n | GridLength\n | { pitch: GridLength; offset?: GridLength; from?: GridLength; to?: GridLength }\n | { at: readonly GridLength[] };\n\n/** A grid's lines: one rule for both axes, or one per axis. An axis left out\n * has no lines: it draws none and nothing snaps on it. */\nexport type GridSpacing = GridLength | { x?: GridAxis; y?: GridAxis };\n\n/** An axis's lines, resolved to numbers in the space the grid runs in. */\nexport type AxisLines =\n | { pitch: number; offset: number; from: number; to: number }\n | { at: readonly number[] };\n\n/** A grid's lines on each axis, `null` where it has none. */\nexport type GridLines = PerAxis<AxisLines | null>;\n\ntype Axis = 'x' | 'y';\n\nexport function isGridLength(v: unknown): v is GridLength {\n return typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v);\n}\n\n/** `spacing`'s lines, each length read by `read` for its axis. */\nexport function resolveGridLines(spacing: GridSpacing, read: (v: GridLength, axis: Axis) => number): GridLines {\n const on = (axis: Axis): AxisLines | null => {\n const a = isGridLength(spacing) ? spacing : spacing[axis];\n if (a === undefined) return null;\n try {\n return resolveAxis(a, (v) => read(v, axis));\n } catch (e) {\n throw new Error(`${axis} axis: ${e instanceof Error ? e.message : String(e)}`);\n }\n };\n return { x: on('x'), y: on('y') };\n}\n\nfunction resolveAxis(a: GridAxis, read: (v: GridLength) => number): AxisLines | null {\n if (isGridLength(a)) return periodic(read(a), 0, -Infinity, Infinity);\n if ('at' in a) {\n const at = [...new Set(a.at.map(read))].filter(Number.isFinite).sort((p, q) => p - q);\n return at.length ? { at } : null;\n }\n return periodic(\n read(a.pitch),\n a.offset === undefined ? 0 : read(a.offset),\n a.from === undefined ? -Infinity : read(a.from),\n a.to === undefined ? Infinity : read(a.to),\n );\n}\n\nfunction periodic(pitch: number, offset: number, from: number, to: number): AxisLines | null {\n return pitch > 0 && Number.isFinite(pitch) && from <= to ? { pitch, offset, from, to } : null;\n}\n\nconst EPS = 1e-9;\n\n/** The first and last index `k` of `offset + k * pitch` inside the range. */\nfunction indexRange(a: { pitch: number; offset: number; from: number; to: number }): [number, number] {\n return [Math.ceil((a.from - a.offset) / a.pitch - EPS), Math.floor((a.to - a.offset) / a.pitch + EPS)];\n}\n\n/** The line at or before `v` and the one after it, nearer first, the upper\n * on a tie; at an end of the lines, the two nearest. Empty where the axis\n * has no line. */\nexport function linesNear(a: AxisLines, v: number): number[] {\n let pair: number[];\n if ('at' in a) {\n const i = Math.min(Math.max(0, lastAtOrBefore(a.at, v)), Math.max(0, a.at.length - 2));\n pair = a.at.slice(i, i + 2);\n } else {\n const [lo, hi] = indexRange(a);\n if (lo > hi) return [];\n const k = Math.min(Math.max(Math.floor((v - a.offset) / a.pitch), lo), Math.max(lo, hi - 1));\n pair = k + 1 <= hi ? [a.offset + k * a.pitch, a.offset + (k + 1) * a.pitch] : [a.offset + k * a.pitch];\n }\n return pair.length === 2 && v - pair[0]! >= pair[1]! - v ? [pair[1]!, pair[0]!] : pair;\n}\n\n/** The line nearest `v`, or `null` where the axis has none. */\nexport function nearestLine(a: AxisLines, v: number): number | null {\n let best: number | null = null;\n for (const l of linesNear(a, v)) if (best === null || Math.abs(l - v) < Math.abs(best - v)) best = l;\n return best;\n}\n\n/** Every line from `lo` to `hi`, in order. The caller bounds how many a\n * pitch gives over the span. */\nexport function linesIn(a: AxisLines, lo: number, hi: number): number[] {\n if ('at' in a) return a.at.filter((l) => l >= lo - EPS && l <= hi + EPS);\n const [k0, k1] = indexRange({ ...a, from: Math.max(a.from, lo), to: Math.min(a.to, hi) });\n const out: number[] = [];\n for (let k = k0; k <= k1; k++) out.push(a.offset + k * a.pitch);\n return out;\n}\n\n/** The cell holding `v`: the gap between two adjacent lines, numbered from\n * the line through the offset (or the first explicit line). An axis with\n * no lines is one cell, `0`, without end. `null` outside the lines. */\nexport function cellOf(a: AxisLines | null, v: number): { index: number; lo: number; hi: number } | null {\n if (!a) return { index: 0, lo: -Infinity, hi: Infinity };\n if ('at' in a) {\n const i = lastAtOrBefore(a.at, v);\n return i >= 0 && i < a.at.length - 1 ? { index: i, lo: a.at[i]!, hi: a.at[i + 1]! } : null;\n }\n const [lo, hi] = indexRange(a);\n const k = Math.floor((v - a.offset) / a.pitch);\n if (k < lo || k >= hi) return null;\n return { index: k, lo: a.offset + k * a.pitch, hi: a.offset + (k + 1) * a.pitch };\n}\n\n/** `a` with every position `p` moved to `p * scale + shift`. */\nexport function mapLines(a: AxisLines, scale: number, shift: number): AxisLines {\n const m = (p: number) => p * scale + shift;\n if ('at' in a) return { at: a.at.map(m).sort((p, q) => p - q) };\n const [from, to] = [m(a.from), m(a.to)].sort((p, q) => p - q) as [number, number];\n return { pitch: Math.abs(a.pitch * scale), offset: m(a.offset), from: Number.isNaN(from) ? -Infinity : from, to: Number.isNaN(to) ? Infinity : to };\n}\n\nfunction lastAtOrBefore(at: readonly number[], v: number): number {\n let lo = 0;\n let hi = at.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (at[mid]! <= v + EPS) {\n found = mid;\n lo = mid + 1;\n } else hi = mid - 1;\n }\n return found;\n}\n","import { resolveStrokeWidth, type CommandStroke, type DrawCommand, type View } from '@weasel-js/core';\nimport { PATH_L, PATH_M, pxExtent, pxExtentInFrame, type Affine, type PolygonPath } from '@weasel-js/geom';\nimport { linesIn, type AxisLines, type GridLines } from './axes';\n\n/** An axis-aligned rectangle, in whatever coordinates a lattice is drawn in. */\nexport type Rect = { x: number; y: number; width: number; height: number };\ntype Point = { x: number; y: number };\n\n/** The strokes of a lattice's three line families. */\nexport type LatticeStyles = { line: CommandStroke; accent: CommandStroke; sub: CommandStroke };\n\n/** How a lattice divides: accents every N cells, sub-lines per cell. Both\n * apply only to an axis with a pitch. */\nexport interface LatticeShape {\n accentEvery?: number | undefined;\n subdivisions?: number | undefined;\n}\n\n/** Closest, in CSS pixels, a line family is drawn; denser ones are left out. */\nconst MIN_SCREEN_SPACING = 4;\n\n// Written so a non-finite extent, which a zero view scale gives, fails it too.\nexport function hasArea(r: Rect): boolean {\n return r.width > 0 && r.height > 0 && Number.isFinite(r.width) && Number.isFinite(r.height);\n}\n\ntype Axis = 'x' | 'y';\nconst other = (axis: Axis): Axis => (axis === 'x' ? 'y' : 'x');\n\n/**\n * The lines of `lines` inside `b`: sub-lines, cell lines and accents. `b` is\n * in `frame`'s coordinates, which `frame` carries to world; absent, it is\n * world. A line runs across `b`, or across the other axis's range where its\n * pitch is limited to one. Lines are a screen pixel wide either way.\n */\nexport function lattice(\n b: Rect, lines: GridLines, shape: LatticeShape, view: View, styles: LatticeStyles, frame?: Affine,\n): DrawCommand[] {\n // Every line runs along one of the lattice's axes, so its width runs along\n // the other, and one pixel of it is that axis's extent.\n const px = frame ? pxExtentInFrame(1, view.scale, frame) : pxExtent(1, view.scale);\n const span = { x: [b.x, b.x + b.width] as const, y: [b.y, b.y + b.height] as const };\n const children: DrawCommand[] = [];\n\n // The stretch of `axis` a line across it covers.\n const across = (axis: Axis): [number, number] => {\n const a = lines[axis];\n const [lo, hi] = span[axis];\n return a && 'pitch' in a ? [Math.max(lo, a.from), Math.min(hi, a.to)] : [lo, hi];\n };\n\n const draw = (axis: Axis, at: readonly number[], s: CommandStroke): void => {\n const [lo, hi] = across(other(axis));\n if (!(hi > lo)) return;\n const width = resolveStrokeWidth(s.width ?? 1, 1) * px[axis];\n for (const p of at) {\n const coords = axis === 'x' ? [p, lo, p, hi] : [lo, p, hi, p];\n const path: PolygonPath = {\n kind: 'polygon', commands: new Uint8Array([PATH_M, PATH_L]), coords: new Float32Array(coords), fillRule: 'nonzero',\n };\n children.push({ kind: 'path', path, stroke: { ...s, width } });\n }\n };\n\n // A pitch's lines `every`-th apart, leaving out each `skipEvery`-th (the\n // ones a coarser family draws), and none once they would sit closer than\n // MIN_SCREEN_SPACING on screen.\n const periodic = (axis: Axis, a: Extract<AxisLines, { pitch: number }>, step: number, skipEvery: number, s: CommandStroke) => {\n if (!(step / px[axis] >= MIN_SCREEN_SPACING)) return;\n const at = linesIn({ ...a, pitch: step }, ...span[axis]);\n draw(axis, skipEvery > 0 ? at.filter((p) => Math.round((p - a.offset) / step) % skipEvery !== 0) : at, s);\n };\n\n const { accentEvery, subdivisions } = shape;\n const accentOn = accentEvery !== undefined && accentEvery > 0;\n const passes: ((axis: Axis, a: Extract<AxisLines, { pitch: number }>) => void)[] = [\n // Sub-lines first so cell lines paint on top, accents last of all.\n (axis, a) => { if (subdivisions && subdivisions > 1) periodic(axis, a, a.pitch / subdivisions, subdivisions, styles.sub); },\n (axis, a) => periodic(axis, a, a.pitch, accentOn ? accentEvery : 0, styles.line),\n (axis, a) => { if (accentOn) periodic(axis, a, a.pitch * accentEvery, 0, styles.accent); },\n ];\n for (const pass of passes) {\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (a && 'pitch' in a) pass(axis, a);\n }\n }\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (a && 'at' in a) draw(axis, thinned(linesIn(a, ...span[axis]), px[axis] * MIN_SCREEN_SPACING), styles.line);\n }\n return children;\n}\n\n/** `at` (ascending) less each line closer than `gap` to the last one kept. */\nfunction thinned(at: readonly number[], gap: number): number[] {\n const out: number[] = [];\n for (const p of at) if (out.length === 0 || p - out[out.length - 1]! >= gap) out.push(p);\n return out;\n}\n\n/** The axis-aligned box around `outline`. */\nexport function outlineBox(outline: readonly Point[]): Rect {\n const xs = outline.map((p) => p.x);\n const ys = outline.map((p) => p.y);\n const x = Math.min(...xs);\n const y = Math.min(...ys);\n return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };\n}\n\n/** Where `a` and `b` overlap; no area where they don't. */\nexport function intersect(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return { x, y, width: Math.min(end(a.x, a.width), end(b.x, b.width)) - x, height: Math.min(end(a.y, a.height), end(b.y, b.height)) - y };\n}\n\n// A rect without end on an axis starts at -Infinity and is Infinity wide, which do not sum.\nconst end = (start: number, size: number): number => (size === Infinity ? Infinity : start + size);\n","import {\n axisUnits, resolveScoped, resolveUnit, type PlaneUnits, type UnitScope,\n} from '@weasel-js/core';\nimport { resolveGridLines, type GridLength, type GridLines, type GridSpacing } from './axes';\n\n/** How a grid reads the unit scopes a scene's containers declare\n * (`GroupNode.units`). */\nexport interface GridScopes {\n /** The scene's outermost scope, as `sceneUnitScopes` is handed it. The grid's\n * `spacing` is read in its system, in place of `unitSystem`. */\n root: UnitScope;\n /** The grid inside a container's scope, written in that scope's units.\n * Default: the grid's `spacing`, read there, so a bare 10 is ten of its\n * base units. */\n spacing?: (scope: UnitScope) => GridSpacing;\n}\n\n/** A length in `chain`'s innermost units, in world units. Grid lengths are\n * measured from the grid's origin, so a unit that disagrees about zero\n * moves them nowhere. */\nfunction span(v: GridLength, chain: readonly UnitScope[]): number {\n const zero = typeof v === 'number' ? 0 : { ...v, value: 0 };\n return resolveScoped(v, chain) - resolveScoped(zero, chain);\n}\n\n/**\n * A grid's lines in world units: read in `chain` (the root alone by default)\n * when `scopes` is given, else against `unitSystem`. What every grid reader\n * that takes both asks.\n */\nexport function gridLines(\n spacing: GridSpacing,\n unitSystem: PlaneUnits | undefined,\n scopes: GridScopes | undefined,\n chain?: readonly UnitScope[],\n): GridLines {\n if (!scopes) return resolveGridLines(spacing, (v, axis) => resolveUnit(v, axisUnits(unitSystem, axis)));\n const at = chain ?? [scopes.root];\n return resolveGridLines(spacing, (v) => span(v, at));\n}\n\n/** The grid a container whose scopes are `chain` runs when nothing gives it\n * one of its own: `scopes.spacing` of its innermost scope, else `spacing`. */\nfunction scopeSpacing(\n spacing: GridSpacing, scopes: GridScopes | undefined, chain: readonly UnitScope[] | undefined,\n): GridSpacing {\n const inner = chain && chain.length > 1 ? chain[chain.length - 1]! : null;\n return inner && scopes?.spacing ? scopes.spacing(inner) : spacing;\n}\n\n/** A container's lattice in its own coordinates: its `own` grid (`gridOf`;\n * `null` for none), else the one its scope gives, read in `chain`. */\nexport function containerLines(\n own: GridSpacing | null | undefined,\n spacing: GridSpacing,\n unitSystem: PlaneUnits | undefined,\n scopes: GridScopes | undefined,\n chain: readonly UnitScope[] | undefined,\n): GridLines | null {\n if (own === null) return null;\n return gridLines(own ?? scopeSpacing(spacing, scopes, chain), unitSystem, scopes, chain);\n}\n","import {\n sceneBoxFrames, scenePoseFrame, sceneUnitScopes, type NodeId, type Scene, type ScopedScene, type UnitScope,\n} from '@weasel-js/core';\nimport { applyToPoint, pointInPolygon, type Affine } from '@weasel-js/geom';\nimport type { GridSpacing } from './axes';\n\ntype Point = { x: number; y: number };\n\n/** Which of a scene's containers run a grid of their own. */\nexport interface GridOwners {\n /** The scene's outermost unit scope: given, every container declaring a\n * scope (`GroupNode.units`) runs that scope's lattice, and lengths inside\n * a container are read in its scope. */\n root?: UnitScope;\n /** A container's own grid: `undefined` to leave it to the container's\n * parent, `null` for no grid inside it at all. Its children snap on it,\n * in the container's frame. */\n gridOf?: (id: NodeId) => GridSpacing | null | undefined;\n}\n\n/** A container running its own lattice, where a grid draws and hit-tests it\n * instead of its parent's. */\nexport interface GridRegion {\n /** The container's outline in world units, as a closed polygon. */\n outline: readonly Point[];\n /** The scopes its lattice is read in, outermost first, rooted at\n * `GridOwners.root`, the container's own scope last. Absent without one. */\n chain?: readonly UnitScope[];\n /** Its own grid, from `gridOf`: `null` for none. Absent, it runs the grid's\n * `spacing`, or its scope's (`GridScopes.spacing`). */\n spacing?: GridSpacing | null;\n /** Containers inside this one running their own. */\n regions?: readonly GridRegion[];\n /** The container's frame, its own coordinates to world (`sceneBoxFrames`):\n * its lattice runs from the frame's origin along its axes, in its units,\n * as `gridSnapSource` snaps. Absent, the lattice is world-aligned and runs\n * through the grid's anchor. */\n frame?: Affine;\n}\n\n/**\n * Every container in `scene` running its own grid, as `GridRegion`s nested\n * the way the containers are, each in its box frame. `outlineOf` gives a\n * node's world outline, or `null` to leave it, and every region inside it,\n * out; by default, a box pose's outline as it is drawn, and none for any\n * other pose.\n */\nexport function sceneGridRegions(\n scene: Scene<unknown, string, unknown>,\n owners: GridOwners,\n outlineOf?: (id: NodeId) => readonly Point[] | null,\n): GridRegion[] {\n const frames = sceneBoxFrames(scene);\n const poses = scenePoseFrame(scene);\n const boxOutline = (id: NodeId, frame: Affine): Point[] => {\n const { width, height } = poses.world(id) as { width: number; height: number };\n return [[0, 0], [width, 0], [width, height], [0, height]].map(([x, y]) => {\n const [wx, wy] = applyToPoint(frame, x!, y!);\n return { x: wx, y: wy };\n });\n };\n const children = new Map<NodeId | null, NodeId[]>();\n for (const id of scene.nodes.keys()) {\n if (!ownsGrid(scene, id, owners)) continue;\n const parent = gridOwner(scene, id, owners);\n children.set(parent, [...(children.get(parent) ?? []), id]);\n }\n const build = (parent: NodeId | null): GridRegion[] => {\n const out: GridRegion[] = [];\n for (const id of children.get(parent) ?? []) {\n const frame = frames(id);\n const outline = outlineOf ? outlineOf(id) : frame && boxOutline(id, frame);\n if (!outline) continue;\n const inner = build(id);\n const own = owners.gridOf?.(id);\n out.push({\n outline,\n ...(owners.root ? { chain: sceneUnitScopes(scene, id, owners.root, { inclusive: true }) } : {}),\n ...(own !== undefined ? { spacing: own } : {}),\n ...(inner.length ? { regions: inner } : {}),\n ...(frame ? { frame } : {}),\n });\n }\n return out;\n };\n return build(null);\n}\n\nfunction ownsGrid(scene: ScopedScene, id: NodeId, owners: GridOwners): boolean {\n return owners.gridOf?.(id) !== undefined || (owners.root !== undefined && scene.get(id)?.units !== undefined);\n}\n\n/** The nearest container above `id` running its own grid, or `null` for the\n * root's: whose lattice `id` sits on. `inclusive` counts `id` itself. */\nexport function gridOwner(scene: ScopedScene, id: NodeId, owners: GridOwners, inclusive = false): NodeId | null {\n for (let at = inclusive ? id : scene.get(id)?.parent ?? null; at !== null; at = scene.get(at)?.parent ?? null) {\n if (ownsGrid(scene, at, owners)) return at;\n }\n return null;\n}\n\n/** The innermost region holding `point`, or `null` outside them all. */\nexport function regionAt(regions: readonly GridRegion[] | undefined, point: Point): GridRegion | null {\n for (const r of regions ?? []) {\n const flat = r.outline.flatMap((p) => [p.x, p.y]);\n if (pointInPolygon(flat, point.x, point.y)) return regionAt(r.regions, point) ?? r;\n }\n return null;\n}\n","import type { PlaneUnits } from '@weasel-js/core';\nimport { applyToPoint, invert, type Affine } from '@weasel-js/geom';\nimport { cellOf, type GridLines, type GridSpacing } from './axes';\nimport { outlineBox, type Rect } from './lattice';\nimport { containerLines, gridLines, type GridScopes } from './reading';\nimport { regionAt, type GridRegion } from './regions';\n\n/** A cell of a grid: the gap between two adjacent lines on each axis,\n * numbered from the line through each axis's offset (or its first explicit\n * line). `box` is the cell in the grid's space: world, or `frame`'s, the\n * frame of the region whose lattice it is on. An axis with no lines is one\n * cell, `0`, spanning the region, or without end at the root. */\nexport interface GridCell {\n col: number;\n row: number;\n box: Rect;\n frame?: Affine;\n}\n\n/** Where a grid's containers run lattices of their own: the unit `scopes`\n * it reads, and the `regions` (`sceneGridRegions`) running them. */\nexport interface GridScoping {\n scopes?: GridScopes;\n regions?: readonly GridRegion[];\n}\n\n/**\n * The cell holding `point`, on the lattice of the innermost region holding\n * it, else the root's, which runs through `origin`. Pair with\n * `createCellHighlightLayer` (its `getCell` callback) to draw a snap-target\n * preview on the lattice `gridSnapSource` snaps to. `null` where `point` is\n * outside the lines: past a range a pitch is limited to, or the explicit\n * lines, or in a region with no grid.\n */\nexport function pointToGridCell(\n point: { x: number; y: number },\n spacing: GridSpacing,\n unitSystem?: PlaneUnits,\n origin: { x: number; y: number } = { x: 0, y: 0 },\n scoped?: GridScoping,\n): GridCell | null {\n const region = regionAt(scoped?.regions, point);\n if (!region) {\n const cell = cellIn(gridLines(spacing, unitSystem, scoped?.scopes), point.x - origin.x, point.y - origin.y);\n return cell && { ...cell, box: { ...cell.box, x: cell.box.x + origin.x, y: cell.box.y + origin.y } };\n }\n const lines = containerLines(region.spacing, spacing, unitSystem, scoped?.scopes, region.chain);\n if (!lines) return null;\n const back = region.frame && invert(region.frame);\n if (region.frame && !back) return null;\n const local = (p: { x: number; y: number }) => {\n if (!back) return p;\n const [x, y] = applyToPoint(back, p.x, p.y);\n return { x, y };\n };\n const at = local(point);\n const cell = cellIn(lines, at.x, at.y, outlineBox(region.outline.map(local)));\n return cell && (region.frame ? { ...cell, frame: region.frame } : cell);\n}\n\nfunction cellIn(lines: GridLines, x: number, y: number, within?: Rect): Omit<GridCell, 'frame'> | null {\n const cx = cellOf(lines.x, x);\n const cy = cellOf(lines.y, y);\n if (!cx || !cy) return null;\n const [x0, x1] = within && !lines.x ? [within.x, within.x + within.width] : [cx.lo, cx.hi];\n const [y0, y1] = within && !lines.y ? [within.y, within.y + within.height] : [cy.lo, cy.hi];\n return { col: cx.index, row: cy.index, box: { x: x0, y: y0, width: x1 - x0, height: y1 - y0 } };\n}\n","/**\n * Pointer-tracking glue that turns hover position into a grid cell, suitable\n * for dropping straight into `createCellHighlightLayer({ getCell })`.\n *\n * State updates only fire when the cell actually changes (not on every\n * pointer tick). Pass `onChange` to trigger a canvas redraw on each transition.\n */\n\nimport { useCallback, useEffect, useRef, useState, type RefObject } from 'react';\nimport {\n useLatest,\n screenToWorld,\n type ViewTransform,\n type PlaneUnits,\n} from '@weasel-js/core';\nimport type { GridSpacing } from './axes';\nimport { pointToGridCell, type GridCell } from './pointToGridCell';\nimport type { GridRegion } from './regions';\nimport type { GridScopes } from './reading';\n\n/** Options for `useGridCellHover`. */\nexport interface UseGridCellHoverOptions {\n /** Element to attach pointer listeners to (typically the canvas). */\n ref: RefObject<HTMLElement | null>;\n /** Read the current view transform. Called on every pointermove so it can\n * reflect live pan/zoom without a re-binding step. */\n view: () => ViewTransform;\n /** The grid's lines. Same value you pass to `createGridLayer`. */\n spacing: GridSpacing;\n /** Required if `spacing` is tagged (e.g. `{ value: 1, unit: 'ft' }`). */\n unitSystem?: PlaneUnits;\n /** Origin the cell grid is anchored to, in world units. Default `(0, 0)`. */\n origin?: { x: number; y: number };\n /** Read `spacing` in these scopes, as `createGridLayer` does. */\n scopes?: GridScopes;\n /** The containers running lattices of their own, read on every\n * pointermove: a cell inside one is on its lattice, in its frame. */\n regions?: () => readonly GridRegion[];\n /** Fires when the hovered cell changes (including to/from `null`). Use it\n * to invalidate your layer renderer. */\n onChange?: (cell: GridCell | null) => void;\n /** Disable the listeners without unmounting. Default `true`. */\n enabled?: boolean;\n}\n\n/** Return shape of `useGridCellHover`. */\nexport interface UseGridCellHoverReturn {\n /** Current hovered cell, or `null` when the pointer is outside the element. */\n cell: GridCell | null;\n /** Stable callback that returns the current cell — drop straight into\n * `createCellHighlightLayer({ getCell })`. */\n getCell: () => GridCell | null;\n}\n\nfunction cellsEqual(\n a: GridCell | null,\n b: GridCell | null,\n): boolean {\n if (a === b) return true;\n if (a === null || b === null) return false;\n return a.col === b.col && a.row === b.row\n && a.box.x === b.box.x && a.box.y === b.box.y && a.box.width === b.box.width && a.box.height === b.box.height\n && (a.frame === b.frame || (!!a.frame && !!b.frame && a.frame.every((v, i) => v === b.frame![i])));\n}\n\n/** Track which grid cell the pointer is over; pairs with `createCellHighlightLayer`. */\nexport function useGridCellHover(opts: UseGridCellHoverOptions): UseGridCellHoverReturn {\n const [cell, setCell] = useState<GridCell | null>(null);\n const cellRef = useRef<GridCell | null>(null);\n const optsRef = useLatest(opts);\n\n const getCell = useCallback(() => cellRef.current, []);\n\n const enabled = opts.enabled ?? true;\n useEffect(() => {\n if (!enabled) return;\n const el = opts.ref.current;\n if (!el) return;\n\n const update = (next: GridCell | null) => {\n if (cellsEqual(cellRef.current, next)) return;\n cellRef.current = next;\n setCell(next);\n optsRef.current.onChange?.(next);\n };\n\n const onMove = (e: PointerEvent) => {\n const o = optsRef.current;\n const rect = el.getBoundingClientRect();\n const sx = e.clientX - rect.left;\n const sy = e.clientY - rect.top;\n const [wx, wy] = screenToWorld(sx, sy, o.view());\n const scoped = { ...(o.scopes ? { scopes: o.scopes } : {}), ...(o.regions ? { regions: o.regions() } : {}) };\n update(pointToGridCell({ x: wx, y: wy }, o.spacing, o.unitSystem, o.origin, scoped));\n };\n const onLeave = () => update(null);\n\n el.addEventListener('pointermove', onMove);\n el.addEventListener('pointerleave', onLeave);\n el.addEventListener('pointercancel', onLeave);\n return () => {\n el.removeEventListener('pointermove', onMove);\n el.removeEventListener('pointerleave', onLeave);\n el.removeEventListener('pointercancel', onLeave);\n };\n }, [enabled, opts.ref, optsRef]);\n\n return { cell, getCell };\n}\n","/**\n * Grid overlay — a reusable render layer that draws a world-space grid with\n * optional finer subdivisions and accent lines every N cells.\n *\n * The layer renders in world space — the caller is expected to have applied\n * any view transform to the canvas context already. To draw a highlighted\n * cell (snap-target preview), stack `createCellHighlightLayer` alongside\n * this one.\n */\n\nimport {\n type DrawCommand,\n type RenderLayer,\n type CommandStroke,\n type PlaneUnits,\n viewportWorldRect,\n type Dims,\n type View,\n} from '@weasel-js/core';\nimport { applyToPoint, invert, mat3, PATH_L, PATH_M, PATH_Z, type PolygonPath } from '@weasel-js/geom';\nimport { mapLines, type GridLines, type GridSpacing } from './axes';\nimport { hasArea, intersect, lattice, outlineBox, type LatticeStyles, type Rect } from './lattice';\nimport type { GridRegion } from './regions';\nimport { containerLines, gridLines, type GridScopes } from './reading';\n\n/** Options for `createGridLayer`. */\nexport interface GridLayerOpts {\n /**\n * The grid's lines: a pitch for both axes, or a rule per axis (`{ x, y }`,\n * see `GridAxis`), an axis left out drawing none. Lengths are a bare\n * number in world (base) units or a tagged `{ value, unit }`, which needs\n * `unitSystem`.\n */\n spacing: GridSpacing;\n /** Optional unit system for resolving tagged `spacing` values. */\n unitSystem?: PlaneUnits;\n /** Read `spacing` in these scopes, in place of `unitSystem`: the root's\n * system outside every region, and each region's own scope inside it. */\n scopes?: GridScopes;\n /** The containers drawing a lattice of their own, read every paint, each\n * cut out of the lattice around it and drawn in its own `frame`:\n * `sceneGridRegions` builds them from a scene. */\n regions?: () => readonly GridRegion[];\n /**\n * The area to cover, in world units, read every paint with that paint's\n * view and canvas size. Lines start at its own `x`/`y`. Omitted, the grid\n * covers whatever the canvas shows, with its lines measured from world\n * zero so they stay put as the view pans.\n */\n bounds?: (view: View, dims: Dims) => Rect;\n /** Lines every N cells get the accent style. 0/undef = no accent. */\n accentEvery?: number;\n /** Optional finer subdivisions per cell. e.g. 4 -> 4 sub-lines per cell. */\n subdivisions?: number;\n /** Per-band stroke styles. Each is a Paint+width (etc.) — see `Stroke`. */\n style?: {\n line?: CommandStroke;\n accent?: CommandStroke;\n sub?: CommandStroke;\n };\n}\n\ntype Point = { x: number; y: number };\n\n// Defaults express weight via opacity rather than a fixed dark color so the\n// grid reads correctly against any background fill (kit demos use a neutral\n// gray; consumer apps may use cream / dark / themed surfaces). Override\n// per-canvas via `style.{line,accent,sub}.paint` if a hard color is needed.\nconst DEFAULT_LINE: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.08)' },\n width: 1,\n};\nconst DEFAULT_ACCENT: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.16)' },\n width: 1,\n};\nconst DEFAULT_SUB: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.04)' },\n width: 1,\n};\n\n/** Build a `RenderLayer` that draws a world-space grid with optional accent lines and subdivisions. */\nexport function createGridLayer(opts: GridLayerOpts): RenderLayer<unknown> {\n const styles: LatticeStyles = {\n line: opts.style?.line ?? DEFAULT_LINE,\n accent: opts.style?.accent ?? DEFAULT_ACCENT,\n sub: opts.style?.sub ?? DEFAULT_SUB,\n };\n\n return {\n id: 'grid',\n label: 'Grid',\n draw: (_data, view, dims) => {\n const b = opts.bounds ? opts.bounds(view, dims) : padded(viewportWorldRect(view, dims), view);\n if (!hasArea(b)) return [];\n // The root's lines run from the bounds' corner, else from world zero, as snapping reads them.\n const anchor = opts.bounds ? { x: b.x, y: b.y } : { x: 0, y: 0 };\n const root = lattice(b, placed(gridLines(opts.spacing, opts.unitSystem, opts.scopes), anchor), opts, view, styles);\n const regions = opts.regions?.() ?? [];\n if (regions.length === 0) return root;\n\n const children: DrawCommand[] = [{ kind: 'group', clip: withHoles(rectOutline(b), regions), children: root }];\n const visit = (r: GridRegion): void => {\n const own = containerLines(r.spacing, opts.spacing, opts.unitSystem, opts.scopes, r.chain);\n const lines = own\n ? regionLattice(r, b, (box, frame) => lattice(box, placed(own, frame ? { x: 0, y: 0 } : anchor), opts, view, styles, frame))\n : [];\n if (lines.length) children.push({ kind: 'group', clip: withHoles(r.outline, r.regions ?? []), children: lines });\n for (const inner of r.regions ?? []) visit(inner);\n };\n for (const r of regions) visit(r);\n // World-space commands; drawLayers wraps in viewToMat3 automatically.\n return children;\n },\n };\n}\n\n/** `r` grown by a screen pixel each way, so a line just off the canvas\n * still draws the half of it that is on. */\nfunction padded(r: Rect, view: View): Rect {\n const px = 1 / Math.abs(view.scale.x);\n const py = 1 / Math.abs(view.scale.y);\n return { x: r.x - px, y: r.y - py, width: r.width + 2 * px, height: r.height + 2 * py };\n}\n\n/** `lines` moved to run from `anchor`. */\nfunction placed(lines: GridLines, anchor: Point): GridLines {\n return { x: lines.x && mapLines(lines.x, 1, anchor.x), y: lines.y && mapLines(lines.y, 1, anchor.y) };\n}\n\nfunction rectOutline(r: Rect): Point[] {\n return [\n { x: r.x, y: r.y },\n { x: r.x + r.width, y: r.y },\n { x: r.x + r.width, y: r.y + r.height },\n { x: r.x, y: r.y + r.height },\n ];\n}\n\n/** `outline` with each of `holes` cut out of it. The renderer clips by\n * parity, so a hole is one more closed contour. */\nfunction withHoles(outline: readonly Point[], holes: readonly GridRegion[]): PolygonPath {\n const commands: number[] = [];\n const coords: number[] = [];\n for (const contour of [outline, ...holes.map((h) => h.outline)]) {\n contour.forEach((p, i) => {\n commands.push(i === 0 ? PATH_M : PATH_L);\n coords.push(p.x, p.y);\n });\n commands.push(PATH_Z);\n }\n return { kind: 'polygon', commands: new Uint8Array(commands), coords: new Float32Array(coords), fillRule: 'evenodd' };\n}\n\n/**\n * What `draw` gives for the part of `area` inside `r`, as `r` draws it: in\n * its `frame`, through it, or in world where it has none. A frame with no\n * inverse draws nothing.\n */\nfunction regionLattice(\n r: GridRegion, area: Rect, draw: (box: Rect, frame?: GridRegion['frame']) => DrawCommand[],\n): DrawCommand[] {\n if (!r.frame) {\n const box = intersect(outlineBox(r.outline), area);\n return hasArea(box) ? draw(box) : [];\n }\n const back = invert(r.frame);\n if (!back) return [];\n const local = (ps: readonly Point[]) => outlineBox(ps.map((p) => {\n const [x, y] = applyToPoint(back, p.x, p.y);\n return { x, y };\n }));\n const box = intersect(local(r.outline), local(rectOutline(area)));\n if (!hasArea(box)) return [];\n const lines = draw(box, r.frame);\n return lines.length ? [{ kind: 'group', transform: mat3.fromAffine(r.frame), children: lines }] : [];\n}\n","/**\n * Cell highlight overlay — a thin render layer that fills a single grid cell\n * (e.g. a snap-target preview). Stack it under or over `createGridLayer` in\n * a layer sequence.\n */\n\nimport { type DrawCommand, type RenderLayer, type CommandFill, viewportWorldRect } from '@weasel-js/core';\nimport { mat3 } from '@weasel-js/geom';\nimport { hasArea, intersect } from './lattice';\nimport type { GridCell } from './pointToGridCell';\n\n/** Options for `createCellHighlightLayer`. */\nexport interface CellHighlightLayerOpts {\n /** Cell to highlight, or `null` to skip drawing: its `box`, in its\n * `frame` where it has one (`pointToGridCell`, `useGridCellHover`). */\n getCell: () => GridCell | null;\n /** Fill for the highlighted cell. Defaults to a soft green. */\n fill?: CommandFill;\n}\n\nconst DEFAULT_FILL: CommandFill = { paint: { kind: 'solid', color: 'rgba(127,176,105,0.15)' } };\n\n/** Build a `RenderLayer` that fills a single grid cell — typically a snap-target preview. */\nexport function createCellHighlightLayer(opts: CellHighlightLayerOpts): RenderLayer<unknown> {\n const fill = opts.fill ?? DEFAULT_FILL;\n return {\n id: 'cell-highlight',\n label: 'Cell highlight',\n draw: (_data, view, dims) => {\n const cell = opts.getCell();\n if (!cell) return [];\n // A root cell on an axis with no lines runs without end: fill what the canvas shows of it.\n const box = cell.frame ? cell.box : intersect(cell.box, viewportWorldRect(view, dims));\n if (!hasArea(box)) return [];\n const children: DrawCommand[] = [{ kind: 'path', path: { kind: 'rect', ...box }, fill }];\n // World-space commands; drawLayers wraps in viewToMat3 automatically.\n return cell.frame ? [{ kind: 'group', transform: mat3.fromAffine(cell.frame), children }] : children;\n },\n };\n}\n","import { nearestLine, type GridLines } from './axes';\n\ntype Point = { x: number; y: number };\n\n/** A point of `gridFit` off its line on one axis, by `distance`. */\nexport interface GridMiss {\n index: number;\n axis: 'x' | 'y';\n distance: number;\n}\n\n/**\n * Whether every one of `points` sits within `tolerance` of a line on each\n * axis `lines` has lines on, so on a crossing where it has both: a hanger's\n * holes on a pegboard's. Points and tolerance are in the grid's own space,\n * measured from its origin; `gridLines` resolves a `GridSpacing` into it.\n */\nexport function gridFit(\n points: readonly Point[], lines: GridLines, tolerance = 1e-6,\n): { fits: boolean; misses: GridMiss[] } {\n const misses: GridMiss[] = [];\n points.forEach((p, index) => {\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (!a) continue;\n const near = nearestLine(a, p[axis]);\n const distance = near === null ? Infinity : Math.abs(p[axis] - near);\n if (distance > tolerance) misses.push({ index, axis, distance });\n }\n });\n return { fits: misses.length === 0, misses };\n}\n","import type { Bounds, Locus, SnapCollect, SnapFrame } from '@weasel-js/core';\n\ntype Point = { x: number; y: number };\ntype Axis = 'x' | 'y';\n\n/** The line `axis = offset` as a locus, through `near` on the other axis. */\nexport function axisLine(axis: Axis, offset: number, near: Point): Locus {\n return axis === 'x'\n ? { at: { x: offset, y: near.y }, dirs: [{ x: 0, y: 1 }] }\n : { at: { x: near.x, y: offset }, dirs: [{ x: 1, y: 0 }] };\n}\n\n/** The line `axis = offset` of `frame`'s own coordinates as a world locus,\n * through `near` (in the frame) on the other axis. */\nexport function frameLine(frame: SnapFrame, axis: Axis, offset: number, near: Point): Locus {\n const on = axis === 'x' ? { x: offset, y: near.y } : { x: near.x, y: offset };\n const at = frame.toWorld(on);\n const tip = frame.toWorld(axis === 'x' ? { x: offset, y: near.y + 1 } : { x: near.x + 1, y: offset });\n return { at, dirs: [{ x: tip.x - at.x, y: tip.y - at.y }] };\n}\n\n/** How far the resolved move `delta` carries a probe from where `q` saw it. */\nexport function landedShift(q: Pick<SnapCollect, 'delta0'>, delta: Point): Point {\n return { x: delta.x - q.delta0.x, y: delta.y - q.delta0.y };\n}\n\n/** The probe positions at which a side moving at `rate` per unit of the move\n * has moved by `by`: the line normal to `rate`, `by / |rate|` from `near`. */\nexport function sideLine(near: Point, rate: Point, by: number): Locus {\n const k = by / (rate.x * rate.x + rate.y * rate.y);\n return { at: { x: near.x + rate.x * k, y: near.y + rate.y * k }, dirs: [{ x: -rate.y, y: rate.x }] };\n}\n\n/** Where the resolved move `delta` puts the subject's box: the session's\n * answer, else `box` carried along as a move carries it. */\nexport function landedBox(q: Pick<SnapCollect, 'box' | 'boxAt' | 'delta0'>, delta: Point): Bounds | null {\n if (q.boxAt) return q.boxAt(delta);\n if (!q.box) return null;\n const shift = landedShift(q, delta);\n return { ...q.box, x: q.box.x + shift.x, y: q.box.y + shift.y };\n}\n","import {\n asNodeId, sceneUnitScopes,\n type NodeId, type PlaneUnits, type SnapCollect, type SnapFrame, type SnapSource, type SourceCandidate,\n} from '@weasel-js/core';\nimport { linesNear, mapLines, type GridLines, type GridSpacing } from '../grid/axes';\nimport { containerLines, gridLines, type GridScopes } from '../grid/reading';\nimport { gridOwner, type GridOwners } from '../grid/regions';\nimport { axisLine, frameLine } from './lines';\n\ntype Point = { x: number; y: number };\nconst AXES = ['x', 'y'] as const;\n\n/** Options for `gridSnapSource`. */\nexport interface GridSnapSourceOptions {\n /** The grid's lines, one rule for both axes or one per axis, in\n * `unitSystem`'s units. */\n spacing: GridSpacing;\n /** A point the root's lattice passes through. Default `(0, 0)`. */\n origin?: Point;\n unitSystem?: PlaneUnits;\n /** Read the unit scope the subject sits in: a node inside a millimeter\n * sub-assembly snaps on that scope's lattice, in that container's frame. */\n scopes?: GridScopes;\n /** A container's own grid, which its children snap on in its frame (from\n * its corner, turned and scaled as it is): the nearest container above\n * the subject with one, or with a unit scope under `scopes`. `null` for a\n * container with no grid inside it. */\n gridOf?: GridOwners['gridOf'];\n /** The source's id, so two grids can snap on one canvas. Default `'grid'`. */\n id?: string;\n}\n\n/** The lattice a gesture snaps on, and the frame of the container it runs\n * in, or none for the root's. */\ninterface Lattice {\n lines: GridLines | null;\n frame?: SnapFrame | undefined;\n}\n\n/**\n * A grid as snap targets: for each probe, the grid line on either side of it\n * on each axis the grid has lines on, so a move lands the drawn box, stroke\n * included, with an edge or its center on a line; on a turned container's\n * lattice, which no world-axis box lines up with, its pose origin. A subject\n * declaring snap anchors (`SceneCanvasSnap.anchors`) lands those instead of\n * its box. Nodes spread over containers snap on the lattice they all run,\n * along the world's axes, and on none where those differ. Its reach is unlimited and it is a fallback,\n * so it holds every axis no target claims and never displaces one. Its lines\n * are the camera's, carried into the plane a gesture runs in.\n */\nexport function gridSnapSource(opts: GridSnapSourceOptions): SnapSource {\n const { scopes, gridOf } = opts;\n const owners: GridOwners = { ...(scopes ? { root: scopes.root } : {}), ...(gridOf ? { gridOf } : {}) };\n const rootLines = gridLines(opts.spacing, opts.unitSystem, scopes);\n const latticeOf = (q: SnapCollect, owner: NodeId | null): Lattice => {\n if (owner === null) return { lines: rootLines };\n const chain = scopes && q.scene ? sceneUnitScopes(q.scene, owner, scopes.root, { inclusive: true }) : undefined;\n return {\n lines: containerLines(gridOf?.(owner), opts.spacing, opts.unitSystem, scopes, chain),\n frame: q.frameOf?.(owner),\n };\n };\n const latticeFor = (q: SnapCollect): Lattice => {\n const scene = q.scene;\n if ((!scopes && !gridOf) || !scene) return { lines: rootLines };\n if (q.ids?.length) {\n const held = [...new Set(q.ids.map((id) => gridOwner(scene, asNodeId(id), owners)))];\n if (held.length === 1) return latticeOf(q, held[0]!);\n // Spread over containers, it snaps on the lattice they all run, along the world's axes.\n const each = held.map((owner) => JSON.stringify(latticeOf(q, owner).lines));\n return { lines: each.every((l) => l === each[0]) ? latticeOf(q, held[0]!).lines : null };\n }\n if (q.parent === undefined) return { lines: rootLines };\n return latticeOf(q, gridOwner(scene, asNodeId(q.parent), owners, true));\n };\n const o = opts.origin ?? { x: 0, y: 0 };\n return {\n id: opts.id ?? 'grid',\n tier: 'fallback',\n reachPx: Infinity,\n roles: ['box', 'origin', 'pointer', 'anchor'],\n *collect(q) {\n const { lines, frame } = latticeFor(q);\n if (!lines) return;\n const plane = q.plane ?? null;\n const scale = (axis: 'x' | 'y') => (plane ? plane.scale[axis] : 1);\n const anchored = q.probes.some((p) => p.role === 'anchor');\n const skip = frame && turns(frame) ? 'box' : 'origin';\n const probes = q.probes.filter((p) => (anchored ? p.role === 'anchor' || p.role === 'pointer' : p.role !== skip));\n if (frame) {\n const local = { x: lines.x && mapLines(lines.x, scale('x'), 0), y: lines.y && mapLines(lines.y, scale('y'), 0) };\n for (const p of probes) yield* framedLines(p.id, p.at, local, frame);\n return;\n }\n // Root lines run through `origin`, in the camera's world, carried into the plane.\n const shift = (axis: 'x' | 'y') => o[axis] * scale(axis) + (plane ? plane.offset[axis] : 0);\n const world = { x: lines.x && mapLines(lines.x, scale('x'), shift('x')), y: lines.y && mapLines(lines.y, scale('y'), shift('y')) };\n for (const p of probes) {\n for (const axis of AXES) {\n const a = world[axis];\n if (a) for (const at of linesNear(a, p.at[axis])) yield { probe: p.id, locus: axisLine(axis, at, p.at) };\n }\n }\n },\n };\n}\n\n/** Whether `frame`'s axes are turned or skewed off the world's, so that a\n * world-axis box cannot line up with its lattice. */\nfunction turns(frame: SnapFrame): boolean {\n const o = frame.toWorld({ x: 0, y: 0 });\n const ex = frame.toWorld({ x: 1, y: 0 });\n const ey = frame.toWorld({ x: 0, y: 1 });\n const along = (a: Point, axis: 'x' | 'y') => {\n const d = { x: a.x - o.x, y: a.y - o.y };\n return axis === 'x' ? Math.abs(d.y) <= 1e-9 * Math.abs(d.x) : Math.abs(d.x) <= 1e-9 * Math.abs(d.y);\n };\n return !((along(ex, 'x') && along(ey, 'y')) || (along(ex, 'y') && along(ey, 'x')));\n}\n\n/** The lines of `frame`'s lattice either side of `at` on each of its axes. */\nfunction* framedLines(probe: string, at: Point, lines: GridLines, frame: SnapFrame): Generator<SourceCandidate> {\n const local = frame.toLocal(at);\n if (!local) return;\n for (const axis of AXES) {\n const a = lines[axis];\n if (a) for (const offset of linesNear(a, local[axis])) yield { probe, locus: frameLine(frame, axis, offset, local) };\n }\n}\n","import type { FeaturePreset } from '@weasel-js/core';\nimport { gridSnapSource, type GridSnapSourceOptions } from '../sources/grid';\nimport { createGridLayer, type GridLayerOpts } from './layer';\n\n/** Options for `createGridPreset`: the grid's, and how it snaps. */\nexport interface GridPresetOptions extends GridLayerOpts {\n /** Preset id. Default `'grid'`. */\n id?: string;\n /** Snap gestures to the grid's lines, on its `spacing`, `unitSystem` and\n * `scopes`; `origin` is where the snap lattice starts, and `gridOf` gives\n * containers their own (pair it with `regions` from `sceneGridRegions`\n * with the same `gridOf`, so what is drawn is what snaps). `false` draws\n * the grid without snapping to it. Default on, from `(0, 0)`. */\n snap?: false | Pick<GridSnapSourceOptions, 'origin' | 'gridOf'>;\n}\n\n/**\n * A grid as one `<SceneCanvas features>` preset: the lattice drawn in the\n * grid slot, and the snap source that pulls gestures onto it.\n */\nexport function createGridPreset(opts: GridPresetOptions): FeaturePreset {\n const { id = 'grid', snap = {}, ...layer } = opts;\n const { spacing, unitSystem, scopes } = layer;\n return {\n id,\n layers: { grid: { layer: createGridLayer(layer) } },\n snapSources: snap === false ? [] : [gridSnapSource({\n id,\n spacing,\n ...(unitSystem === undefined ? {} : { unitSystem }),\n ...(scopes === undefined ? {} : { scopes }),\n ...snap,\n })],\n };\n}\n","import { useCallback, useState } from 'react';\nimport { useLatest } from '@weasel-js/core';\nimport type { Guide } from './types';\n\n/** Return shape for `useGuides`. */\nexport interface UseGuidesReturn {\n /** Live list (state). Re-renders when guides change. */\n guides: Guide[];\n /** Stable getter; reads the latest list without forcing a re-render.\n * Pass to `guideSnapSource` and `createGuidesLayer`. */\n getGuides: () => Guide[];\n /** Add a guide. If a guide with the same id already exists it is replaced. */\n addGuide: (guide: Guide) => void;\n /** Remove a guide by id. No-op when missing. */\n removeGuide: (id: string) => void;\n /** Drop all guides. */\n clearGuides: () => void;\n}\n\n/**\n * In-memory guide storage. Holds a list of horizontal/vertical world-space\n * lines that callers can pass to `guideSnapSource` (snap source) and\n * `createGuidesLayer` (render layer).\n *\n * v1 is intentionally minimal: no undo integration, no persistence, no\n * batched mutation. Wrap calls in your own history-aware action if you\n * want guide CRUD to be undoable.\n */\nexport function useGuides(initial: Guide[] = []): UseGuidesReturn {\n const [guides, setGuides] = useState<Guide[]>(initial);\n const ref = useLatest(guides);\n\n const getGuides = useCallback(() => ref.current, [ref]);\n\n const addGuide = useCallback((guide: Guide) => {\n setGuides((prev) => {\n const idx = prev.findIndex((g) => g.id === guide.id);\n if (idx === -1) return [...prev, guide];\n const next = prev.slice();\n next[idx] = guide;\n return next;\n });\n }, []);\n\n const removeGuide = useCallback((id: string) => {\n setGuides((prev) => {\n const idx = prev.findIndex((g) => g.id === id);\n if (idx === -1) return prev;\n const next = prev.slice();\n next.splice(idx, 1);\n return next;\n });\n }, []);\n\n const clearGuides = useCallback(() => {\n setGuides((prev) => (prev.length === 0 ? prev : []));\n }, []);\n\n return { guides, getGuides, addGuide, removeGuide, clearGuides };\n}\n","/**\n * Guides overlay — a screen-space render layer that draws each guide as a\n * thin line, projecting the guide's world offset through the active view.\n * A guide with a `span` draws as a segment over that span with a tick at each\n * end; one without spans the full canvas. It also draws equal-spacing gaps\n * (`SpacingGap`) as ticked segments labeled with their size.\n *\n * Guides are not scene objects; they live outside the scene and are managed\n * via `useGuides`. Pair with `guideSnapSource` (snap source) to keep\n * the visual guide and the snap target in lockstep.\n */\n\nimport { measuredSegmentCommands, tickedSegment, type DrawCommand, type RenderLayer, type CommandStroke } from '@weasel-js/core';\nimport type { Guide, SpacingGap } from './types';\n\n/** Options for `createGuidesLayer`. */\nexport interface GuidesLayerOpts {\n /** Stable getter for the live guide list — typically `useGuides().getGuides`. */\n getGuides: () => readonly Guide[];\n /** Stable getter for the equal-spacing gaps to draw, such as\n * `matchSpacing`'s. */\n getGaps?: () => readonly SpacingGap[];\n /** `'span'` (default) draws a guide that carries a `span` as a segment over\n * it; `'full'` draws every guide across the whole canvas. */\n extent?: 'span' | 'full';\n /** Length in CSS px of the tick across each end of a segment. 0 for none.\n * Default 6. */\n ticks?: number;\n /** Label each gap with its size: `true` (default) prints it rounded to a\n * whole world unit, a function formats it, `false` omits the label. */\n gapLabels?: boolean | ((size: number) => string);\n /** Stroke width in CSS pixels. Default 1. */\n lineWidth?: number;\n /** Stroke color, and the gap labels' fill. Default a subtle blue. */\n color?: string;\n /** Gap marker color. Default `color`. */\n gapColor?: string;\n /** Optional dash pattern (CSS px). Currently unused — reserved for future\n * parity with chrome that supports dashes. */\n dash?: number[];\n /** Override the layer id. Useful if a consumer needs more than one\n * guides-layer (e.g. user-guides vs. system-guides). */\n id?: string;\n /** Override the layer label. */\n label?: string;\n}\n\nconst DEFAULT_COLOR = '#3aa0ff';\n/** Build a `RenderLayer` that draws guide lines and spacing gaps in screen\n * space, projected from world coordinates via the active view. */\nexport function createGuidesLayer(opts: GuidesLayerOpts): RenderLayer<unknown> {\n const lineWidth = opts.lineWidth ?? 1;\n const color = opts.color ?? DEFAULT_COLOR;\n const gapColor = opts.gapColor ?? color;\n const ticks = opts.ticks ?? 6;\n const spanned = (opts.extent ?? 'span') === 'span';\n const format = opts.gapLabels === false ? null\n : typeof opts.gapLabels === 'function' ? opts.gapLabels\n : (n: number) => String(Math.round(n));\n const stroke: CommandStroke = { paint: { kind: 'solid', color }, width: lineWidth };\n const gapStroke: CommandStroke = { paint: { kind: 'solid', color: gapColor }, width: lineWidth };\n\n return {\n id: opts.id ?? 'guides',\n label: opts.label ?? 'Guides',\n space: 'screen',\n draw: (_data, view, dims) => {\n const guides = opts.getGuides();\n const gaps = opts.getGaps?.() ?? [];\n if (guides.length === 0 && gaps.length === 0) return [];\n const sx = (x: number) => (x - view.x) * view.scale.x;\n const sy = (y: number) => (y - view.y) * view.scale.y;\n\n const out: DrawCommand[] = [];\n for (const g of guides) {\n const span = spanned ? g.span : undefined;\n if (g.axis === 'x') {\n const x = sx(g.offset);\n if (x < -lineWidth || x > dims.width + lineWidth) continue;\n const path = span\n ? tickedSegment(x, sy(span.min), x, sy(span.max), ticks)\n : tickedSegment(x, 0, x, dims.height, 0);\n out.push({ kind: 'path', path, stroke });\n } else {\n const y = sy(g.offset);\n if (y < -lineWidth || y > dims.height + lineWidth) continue;\n const path = span\n ? tickedSegment(sx(span.min), y, sx(span.max), y, ticks)\n : tickedSegment(0, y, dims.width, y, 0);\n out.push({ kind: 'path', path, stroke });\n }\n }\n\n for (const g of gaps) {\n const [x0, y0, x1, y1] = g.axis === 'x'\n ? [sx(g.min), sy(g.at), sx(g.max), sy(g.at)]\n : [sx(g.at), sy(g.min), sx(g.at), sy(g.max)];\n out.push(...measuredSegmentCommands(x0, y0, x1, y1, ticks, gapStroke, format?.(g.max - g.min) ?? null, gapColor));\n }\n return out;\n },\n };\n}\n","import type { Guide } from '../types';\nimport type { DeriveAlignmentGuidesOptions } from './types';\nimport {\n type Bounds,\n type PoseDescriptor,\n rectFromPlane,\n visualBoundsViaDescriptor,\n AUTO_POSE_DESCRIPTOR,\n} from '@weasel-js/core';\n\nconst EPS = 1e-3;\n\n/** Derive candidate alignment lines from a set of sibling poses plus an\n * optional page box. Each box contributes up to 3 guides per axis: the two\n * edges and the center. Overlapping offsets collapse to one candidate, whose\n * `span` covers every box that produced it.\n * Poses go through `opts.poseDescriptor`, so a rotated sibling advertises\n * its ink edges rather than its stored box.\n * The moving selection is measured with its stroke (`drawnBoundsOf`), so\n * pass each sibling's `drawnAABBOf` box as its target for the two to agree.\n * The lines are in the camera's world: a sibling on a parallax layer needs\n * `planeOf` to say which plane its pose is in. */\nexport function deriveAlignmentGuides<TPose = Bounds>(\n targets: readonly TPose[],\n opts: DeriveAlignmentGuidesOptions<TPose> = {},\n): Guide[] {\n const d = (opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const edges = opts.edges ?? true;\n const centers = opts.centers ?? true;\n // Dedup per axis: key = rounded offset. First writer wins (stable id).\n const seenX = new Map<number, Guide>();\n const seenY = new Map<number, Guide>();\n\n const add = (axis: 'x' | 'y', offset: number, b: Bounds): void => {\n const seen = axis === 'x' ? seenX : seenY;\n const key = Math.round(offset / EPS);\n const min = axis === 'x' ? b.y : b.x;\n const max = min + (axis === 'x' ? b.height : b.width);\n const prev = seen.get(key);\n if (prev) {\n prev.span = { min: Math.min(prev.span!.min, min), max: Math.max(prev.span!.max, max) };\n return;\n }\n seen.set(key, { id: `align:${axis}:${offset.toFixed(3)}`, axis, offset, span: { min, max } });\n };\n\n const emit = (b: Bounds): void => {\n if (edges) {\n add('x', b.x, b);\n add('x', b.x + b.width, b);\n add('y', b.y, b);\n add('y', b.y + b.height, b);\n }\n if (centers) {\n add('x', b.x + b.width / 2, b);\n add('y', b.y + b.height / 2, b);\n }\n };\n\n targets.forEach((t, i) => {\n const box = visualBoundsViaDescriptor(t, d);\n const plane = opts.planeOf?.(t, i);\n emit(plane ? rectFromPlane(plane, box) : box);\n });\n if (opts.page) emit(opts.page);\n\n return [...seenX.values(), ...seenY.values()];\n}\n","import type { Bounds } from '@weasel-js/core';\nimport type { SpacingGap } from '../types';\nimport type { SpacingEdge, SpacingMatchResult } from './types';\n\nconst EPS = 1e-6;\ntype Axis = 'x' | 'y';\n\nconst lo = (b: Bounds, a: Axis): number => (a === 'x' ? b.x : b.y);\nconst hi = (b: Bounds, a: Axis): number => (a === 'x' ? b.x + b.width : b.y + b.height);\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The shared range of two boxes on `axis`, or null when they share none. */\nfunction overlap(a: Bounds, b: Bounds, axis: Axis): [number, number] | null {\n const min = Math.max(lo(a, axis), lo(b, axis));\n const max = Math.min(hi(a, axis), hi(b, axis));\n return max - min > EPS ? [min, max] : null;\n}\n\nfunction gapBetween(a: Bounds, b: Bounds, axis: Axis): SpacingGap | null {\n const shared = overlap(a, b, cross(axis));\n if (shared === null) return null;\n return { axis, min: hi(a, axis), max: lo(b, axis), at: (shared[0] + shared[1]) / 2 };\n}\n\n/** Whether `b` covers any of the strip a gap marks out. */\nfunction hitsStrip(g: SpacingGap, b: Bounds, span: [number, number]): boolean {\n const c = cross(g.axis);\n return lo(b, g.axis) < g.max - EPS && hi(b, g.axis) > g.min + EPS\n && lo(b, c) < span[1] - EPS && hi(b, c) > span[0] + EPS;\n}\n\n/**\n * The visible gaps between neighboring boxes along `axis`: for `'x'`, each box\n * and the nearest box to its right that shares some of its vertical range, as\n * long as no third box stands in the strip between them. These are the gaps an\n * equal-spacing snap can reproduce.\n */\nexport function measureGaps(targets: readonly Bounds[], axis: 'x' | 'y'): SpacingGap[] {\n return measureGapSpans(targets, axis).map((m) => m.gap);\n}\n\n/** A measured gap, and the stretch of the other axis its two boxes share. */\nexport interface MeasuredGap { gap: SpacingGap; span: [number, number] }\n\n/** `measureGaps`, keeping each gap's shared span: what `referenceGaps`\n * filters. Quadratic in `targets`, so a caller matching every frame keeps\n * the result while the targets stand still. */\nexport function measureGapSpans(targets: readonly Bounds[], axis: Axis): MeasuredGap[] {\n const out: MeasuredGap[] = [];\n for (const a of targets) {\n let next: Bounds | null = null;\n for (const c of targets) {\n if (c === a || lo(c, axis) < hi(a, axis) + EPS) continue;\n if (overlap(a, c, cross(axis)) === null) continue;\n if (next === null || lo(c, axis) < lo(next, axis)) next = c;\n }\n if (next === null) continue;\n const gap = gapBetween(a, next, axis)!;\n const span = overlap(a, next, cross(axis))!;\n if (targets.some((t) => t !== a && t !== next && hitsStrip(gap, t, span))) continue;\n out.push({ gap, span });\n }\n return out.sort((p, q) => p.gap.min - q.gap.min || p.gap.at - q.gap.at);\n}\n\n/** A placement on one axis: the move that gives an equal gap of `size`. */\nexport interface SpacingOffer { delta: number; size: number }\n\n/** Every equal-spacing placement on one axis, unfiltered by reach: each\n * reference gap reproduced beside a neighbor, and centering between the two\n * neighbors. */\nexport function spacingOffers(\n b: Bounds,\n axis: Axis,\n edge: SpacingEdge,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n): SpacingOffer[] {\n const bLo = lo(b, axis);\n const bHi = hi(b, axis);\n const size = bHi - bLo;\n const center = (bLo + bHi) / 2;\n let left: Bounds | null = null;\n let right: Bounds | null = null;\n for (const t of targets) {\n if (overlap(t, b, cross(axis)) === null) continue;\n if (hi(t, axis) <= center && (left === null || hi(t, axis) > hi(left, axis))) left = t;\n if (lo(t, axis) >= center && (right === null || lo(t, axis) < lo(right, axis))) right = t;\n }\n const sizes = refs.map((g) => g.max - g.min);\n\n const out: SpacingOffer[] = [];\n const offer = (delta: number, gap: number): void => {\n if (gap > EPS) out.push({ delta, size: gap });\n };\n\n const L = left === null ? null : hi(left, axis);\n const R = right === null ? null : lo(right, axis);\n if (edge === 'both') {\n for (const g of sizes) {\n if (L !== null && (R === null || L + g + size <= R + EPS)) offer(L + g - bLo, g);\n if (R !== null && (L === null || R - g - size >= L - EPS)) offer(R - g - size - bLo, g);\n }\n if (L !== null && R !== null) {\n const g = (R - L - size) / 2;\n offer(L + g - bLo, g);\n }\n } else if (edge === 'max' && R !== null) {\n const own = L !== null ? [bLo - L] : [];\n for (const g of [...sizes, ...own]) if (R - g > bLo + EPS) offer(R - g - bHi, g);\n } else if (edge === 'min' && L !== null) {\n const own = R !== null ? [R - bHi] : [];\n for (const g of [...sizes, ...own]) if (L + g < bHi - EPS) offer(L + g - bLo, g);\n }\n return out;\n}\n\n/** The nearest equal-spacing placement on one axis within `tol`, or null. */\nfunction bestAxis(\n b: Bounds,\n axis: Axis,\n edge: SpacingEdge,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n tol: number,\n): SpacingOffer | null {\n let best: SpacingOffer | null = null;\n for (const o of spacingOffers(b, axis, edge, targets, refs)) {\n if (Math.abs(o.delta) > tol) continue;\n if (best === null || Math.abs(o.delta) < Math.abs(best.delta)) best = o;\n }\n return best;\n}\n\n/** Every gap of `size` on `axis` once the box sits at `b`: the matching\n * reference gaps, plus the box's own gaps to its two neighbors. */\nexport function equalGaps(\n b: Bounds,\n axis: Axis,\n size: number,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n): SpacingGap[] {\n const eq = (g: SpacingGap) => Math.abs(g.max - g.min - size) < 1e-3;\n const out = refs.filter(eq);\n // Only a box overlapping the gap-wide margins beside b can bound or block\n // one of b's own gaps, so the quadratic measure runs on those alone.\n const near = targets.filter((t) => hi(t, axis) > lo(b, axis) - size - EPS && lo(t, axis) < hi(b, axis) + size + EPS);\n const own = measureGaps([...near, b], axis).filter((g) =>\n (Math.abs(g.max - lo(b, axis)) < EPS || Math.abs(g.min - hi(b, axis)) < EPS) && eq(g));\n return [...out, ...own];\n}\n\n/** The measured gaps a box at `bounds` can reproduce: all but those it\n * stands inside. */\nexport function referenceGaps(bounds: Bounds, measured: readonly MeasuredGap[]): SpacingGap[] {\n return measured.filter((m) => !hitsStrip(m.gap, bounds, m.span)).map((m) => m.gap);\n}\n\n/**\n * Match a box against the gaps between `targets`, Figma's \"equal spacing\":\n * on each axis, find where the box's gap to a neighbor equals a gap that\n * already exists between two other boxes, or where it sits centered between\n * its two neighbors. `moving` says which edges move on each axis — `'both'`\n * for a translate, `'min'`/`'max'` for a resize dragging that edge, `null` to\n * leave the axis alone. Default `'both'` on each axis.\n *\n * Targets should exclude the box itself. A reference gap the box now stands\n * inside no longer counts. The returned gaps are every gap equal to the one\n * snapped to, with the box at its snapped position — ready to draw with\n * `createGuidesLayer`'s `getGaps`.\n */\nexport function matchSpacing(\n bounds: Bounds,\n targets: readonly Bounds[],\n worldTolerance: { x: number; y: number },\n moving: { x: SpacingEdge | null; y: SpacingEdge | null } = { x: 'both', y: 'both' },\n): SpacingMatchResult {\n const refsX = referenceGaps(bounds, measureGapSpans(targets, 'x'));\n const refsY = referenceGaps(bounds, measureGapSpans(targets, 'y'));\n const x = moving.x === null ? null : bestAxis(bounds, 'x', moving.x, targets, refsX, worldTolerance.x);\n const y = moving.y === null ? null : bestAxis(bounds, 'y', moving.y, targets, refsY, worldTolerance.y);\n const dx = x?.delta ?? 0;\n const dy = y?.delta ?? 0;\n const final = applyEdges(bounds, dx, dy, moving);\n return {\n dx,\n dy,\n gapsX: x === null ? [] : equalGaps(final, 'x', x.size, targets, refsX),\n gapsY: y === null ? [] : equalGaps(final, 'y', y.size, targets, refsY),\n };\n}\n\n/** Move the box's moving edges by the snap deltas. */\nexport function applyEdges(\n b: Bounds,\n dx: number,\n dy: number,\n moving: { x: SpacingEdge | null; y: SpacingEdge | null },\n): Bounds {\n let { x, y, width, height } = b;\n if (moving.x === 'both') x += dx;\n else if (moving.x === 'min') { x += dx; width -= dx; }\n else if (moving.x === 'max') width += dx;\n if (moving.y === 'both') y += dy;\n else if (moving.y === 'min') { y += dy; height -= dy; }\n else if (moving.y === 'max') height += dy;\n return { x, y, width, height };\n}\n","import {\n AUTO_POSE_DESCRIPTOR,\n type Bounds,\n type NodeId,\n nodeGates,\n type PoseDescriptor,\n type Scene,\n scenePoseFrame,\n unionAABB,\n visualBoundsViaDescriptor,\n} from '@weasel-js/core';\n\n\n/** Options shared by the scene readers below. */\nexport interface SceneBoundsOptions {\n /** How to read a pose's box. Pass the canvas's, so these agree with what it\n * draws. Default `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<unknown>;\n}\n\n/** The world box each id is drawn in, rotation included, skipping ids the\n * scene no longer holds. Read through the scene's composition. */\nexport function worldBoundsOf(\n scene: Scene<unknown, string, unknown>,\n ids: Iterable<NodeId>,\n opts: SceneBoundsOptions = {},\n): Bounds[] {\n const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;\n const frame = scenePoseFrame(scene);\n const out: Bounds[] = [];\n for (const id of ids) {\n if (scene.get(id) === undefined) continue;\n out.push(visualBoundsViaDescriptor(frame.world(id), d));\n }\n return out;\n}\n\n/** The union of `ids`' world boxes, or null when none is in the scene. */\nexport function worldUnionOf(\n scene: Scene<unknown, string, unknown>,\n ids: Iterable<NodeId>,\n opts: SceneBoundsOptions = {},\n): Bounds | null {\n const boxes = worldBoundsOf(scene, ids, opts);\n return boxes.length === 0 ? null : unionAABB(boxes);\n}\n\n/** Every node sharing a parent with one of `ids`, outside the set, and not\n * hidden (`nodeGates`). */\nexport function siblingIds(scene: Scene<unknown, string, unknown>, ids: readonly NodeId[]): NodeId[] {\n const moving = new Set(ids);\n const gates = nodeGates(scene);\n const parents = new Set<NodeId | null>();\n for (const id of ids) {\n const node = scene.get(id);\n if (node !== undefined) parents.add(node.parent);\n }\n const siblings: NodeId[] = [];\n for (const parent of parents) {\n for (const id of parent === null ? scene.roots : scene.childrenOf(parent)) {\n const node = scene.get(id);\n if (moving.has(id) || node === undefined || gates.hidden(id)) continue;\n siblings.push(id);\n }\n }\n return siblings;\n}\n\n/**\n * The world boxes of `ids`' siblings ({@link siblingIds}). What an\n * equal-spacing snap measures gaps between while `ids` move.\n */\nexport function siblingBounds(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n opts: SceneBoundsOptions = {},\n): Bounds[] {\n return worldBoundsOf(scene, siblingIds(scene, ids), opts);\n}\n","import type { GestureContext } from '@weasel-js/core';\nimport type { Guide } from '../guides/types';\n\n/** A gesture's `plane`: how the camera's world maps into the world its poses are in. */\ntype Plane = GestureContext<unknown>['plane'];\n\n/** Where a guide the camera draws lies along its own axis in the world a gesture's poses are in. */\nexport function guideOffsetOn(g: Guide, plane: Plane): number {\n return plane ? g.offset * plane.scale[g.axis] + plane.offset[g.axis] : g.offset;\n}\n\n","import type { SnapSource } from '@weasel-js/core';\nimport type { Guide } from '../guides/types';\nimport { guideOffsetOn } from '../strategies/onPlane';\nimport { axisLine } from './lines';\n\n/**\n * Ruler guides as snap targets: each guide within reach of a box or\n * pointer probe is a line it may land on: a moved box's edges and center,\n * stroke included. Reads `getGuides` every frame, so\n * a guide added mid-drag counts at once.\n */\nexport function guideSnapSource(getGuides: () => readonly Guide[]): SnapSource {\n return {\n id: 'guides',\n roles: ['box', 'pointer'],\n *collect(q) {\n const guides = getGuides();\n if (guides.length === 0) return;\n const reach = q.reachWorld(q.reachPx);\n for (const p of q.probes) {\n for (const g of guides) {\n const offset = guideOffsetOn(g, q.plane ?? null);\n if (Math.abs(p.at[g.axis] - offset) > reach) continue;\n yield { probe: p.id, locus: axisLine(g.axis, offset, p.at) };\n }\n }\n },\n };\n}\n","import type { Guide } from '../types';\n\n/** A matched guide whose span also covers the snapped box. */\nexport function stretchSpan(g: Guide | null, min: number, max: number): Guide | null {\n if (g === null || g.span === undefined) return g;\n return { ...g, span: { min: Math.min(g.span.min, min), max: Math.max(g.span.max, max) } };\n}\n","import { nodeGates, type Bounds, type NodeId, type Scene, type SceneNode, type SnapCollect } from '@weasel-js/core';\nimport { siblingIds } from '../guides/alignment/sceneBounds';\n\ntype AnyScene = Scene<unknown, string, unknown>;\n\nfunction visibleRoots(scene: AnyScene): readonly NodeId[] {\n const gates = nodeGates(scene);\n return scene.roots.filter((id) => !gates.hidden(id));\n}\n\n/** Which nodes may be targets; one that fails offers no lines or gaps. */\nexport type TargetFilter = (node: SceneNode<unknown, string, unknown>) => boolean;\n\n/** The nodes a gesture's subject lines up with: its siblings when it has\n * ids, the scene's visible top-level nodes for a point gesture. */\nfunction targetIds(scene: AnyScene, exclude: readonly string[], filter?: TargetFilter): readonly NodeId[] {\n const ids = exclude.length > 0\n ? siblingIds(scene, exclude as readonly NodeId[])\n : visibleRoots(scene);\n if (!filter) return ids;\n return ids.filter((id) => {\n const node = scene.get(id);\n return node !== undefined && filter(node);\n });\n}\n\n/** The target nodes' boxes, measured as the session measures its subject;\n * none from a host that measures no boxes. */\nexport function targetBoxes(q: SnapCollect, scene: AnyScene, filter?: TargetFilter): Bounds[] {\n const drawn = q.drawnBox;\n return drawn ? targetIds(scene, q.exclude, filter).flatMap((id) => drawn(id) ?? []) : [];\n}\n\n/**\n * `derive` over the query's target boxes, kept while the scene's version and\n * the excluded ids stand still: a drag asks every frame, and nothing it\n * reads changes until it commits.\n */\nexport function cachedPerScene<T>(\n derive: (boxes: readonly Bounds[]) => T, filter?: TargetFilter,\n): (q: SnapCollect) => T | null {\n let key: { scene: AnyScene; version: number; exclude: string } | null = null;\n let value: T | null = null;\n return (q) => {\n const scene = q.scene;\n if (!scene) return null;\n const version = scene.getVersion();\n const exclude = q.exclude.join('\\n');\n if (key === null || key.scene !== scene || key.version !== version || key.exclude !== exclude) {\n value = derive(targetBoxes(q, scene, filter));\n key = { scene, version, exclude };\n }\n return value;\n };\n}\n","import type { Bounds, SnapCollect, SnapMark, SnapProbeAt, SnapSource } from '@weasel-js/core';\nimport { deriveAlignmentGuides } from '../guides/alignment/derive';\nimport { stretchSpan } from '../guides/alignment/match';\nimport type { Guide } from '../guides/types';\nimport { axisLine, landedBox, landedShift } from './lines';\nimport { cachedPerScene, type TargetFilter } from './targets';\n\ntype Point = { x: number; y: number };\ntype Axis = 'x' | 'y';\n\n/** Options for `alignmentSnapSource`. */\nexport interface AlignmentSnapSourceOptions {\n /** A page box whose edges and center are lines too, in the camera's world. */\n page?: Bounds | (() => Bounds | null | undefined);\n /** The lines to align to, in place of the edges and centers of the\n * subject's siblings (of the scene's top-level nodes, for a point gesture). */\n getCandidates?: () => readonly Guide[];\n /** Which nodes offer lines. Narrows the default siblings; not `getCandidates`. */\n filter?: TargetFilter;\n /** The color of the lines it marks. Default: the readout layer's. */\n color?: string;\n /** Overrides the canvas's reach for these targets, in screen px. */\n reachPx?: number;\n}\n\n/** Each axis's lines, sorted by offset, so a probe finds the ones in reach\n * without walking the rest. */\ninterface LineIndex { x: readonly Guide[]; y: readonly Guide[] }\n\nfunction indexLines(lines: readonly Guide[]): LineIndex {\n const sorted = [...lines].sort((a, b) => a.offset - b.offset);\n return { x: sorted.filter((g) => g.axis === 'x'), y: sorted.filter((g) => g.axis === 'y') };\n}\n\nfunction* inReach(lines: readonly Guide[], v: number, reach: number): Generator<Guide> {\n let lo = 0;\n let hi = lines.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (lines[mid].offset < v - reach) lo = mid + 1;\n else hi = mid;\n }\n for (let i = lo; i < lines.length && lines[i].offset <= v + reach; i++) yield lines[i];\n}\n\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The line `g` drawn from the box (or point) a probe landed in to the\n * farthest sibling that shares it. */\nfunction lineMark(g: Guide, extent: [number, number], color: string | undefined): SnapMark {\n const span = stretchSpan(g, extent[0], extent[1])?.span ?? { min: extent[0], max: extent[1] };\n const ends = g.axis === 'x'\n ? { from: { x: g.offset, y: span.min }, to: { x: g.offset, y: span.max } }\n : { from: { x: span.min, y: g.offset }, to: { x: span.max, y: g.offset } };\n return { kind: 'line', ...ends, ...(color === undefined ? {} : { color }) };\n}\n\n/**\n * The edges and centers of the subject's siblings, and optionally a page, as\n * snap targets: each is a line a box or pointer probe may land on. A move's\n * left, center and right (top, center, bottom) all try every line, as Figma's\n * smart guides do. When the result meets a line, its mark runs from the\n * subject's box to the farthest sibling on that line.\n */\nexport function alignmentSnapSource(opts: AlignmentSnapSourceOptions = {}): SnapSource {\n const page = () => (typeof opts.page === 'function' ? opts.page() : opts.page) ?? undefined;\n const fromScene = cachedPerScene((boxes) => indexLines(deriveAlignmentGuides(boxes)), opts.filter);\n const linesFor = (q: SnapCollect): LineIndex[] => {\n const pageBox = page();\n const own = opts.getCandidates ? indexLines(opts.getCandidates()) : fromScene(q);\n return [...(own ? [own] : []), ...(pageBox ? [indexLines(deriveAlignmentGuides([], { page: pageBox }))] : [])];\n };\n return {\n id: 'alignment',\n ...(opts.reachPx === undefined ? {} : { reachPx: opts.reachPx }),\n roles: ['box', 'pointer'],\n *collect(q) {\n const indexes = linesFor(q);\n if (indexes.length === 0) return;\n const reach = q.reachWorld(q.reachPx);\n // A resize offers its dragged corner as pointer and as box; the box's\n // probes are the ones whose marks span it.\n const probes = q.probes.some((p) => p.role === 'box') ? q.probes.filter((p) => p.role === 'box') : q.probes;\n for (const p of probes) {\n for (const axis of ['x', 'y'] as const) {\n for (const index of indexes) {\n for (const g of inReach(index[axis], p.at[axis], reach)) {\n yield {\n probe: p.id,\n locus: axisLine(axis, g.offset, p.at),\n mark: (delta: Point) => lineMark(g, extentAcross(q, p, axis, delta), opts.color),\n };\n }\n }\n }\n }\n },\n };\n}\n\n/** Where the landed probe's box (its own point, for a pointer) spans the axis\n * across `axis`. */\nfunction extentAcross(q: SnapCollect, p: SnapProbeAt, axis: Axis, delta: Point): [number, number] {\n const c = cross(axis);\n const landed = p.role === 'box' ? landedBox(q, delta) : null;\n if (landed === null) {\n const shift = landedShift(q, delta);\n return [p.at[c] + shift[c], p.at[c] + shift[c]];\n }\n const lo = c === 'x' ? landed.x : landed.y;\n return [lo, lo + (c === 'x' ? landed.width : landed.height)];\n}\n","import type { Bounds, SnapCollect, SnapMark, SnapSource } from '@weasel-js/core';\nimport {\n equalGaps, measureGapSpans, referenceGaps, spacingOffers, type MeasuredGap,\n} from '../guides/alignment/spacing';\nimport type { SpacingEdge } from '../guides/alignment/types';\nimport type { SpacingGap } from '../guides/types';\nimport { landedBox, sideLine } from './lines';\nimport { cachedPerScene, type TargetFilter } from './targets';\n\ntype Point = { x: number; y: number };\n\n/** A side of the box the gesture moves on `axis`, at `rate` per unit of the move. */\ninterface Moving { axis: 'x' | 'y'; edge: SpacingEdge; rate: Point }\n\nconst TRANSLATE: readonly Moving[] = [\n { axis: 'x', edge: 'both', rate: { x: 1, y: 0 } },\n { axis: 'y', edge: 'both', rate: { x: 0, y: 1 } },\n];\n\n/** A move's whole box on each axis, else the sides a resize moves. */\nfunction movingSides(q: SnapCollect): readonly Moving[] {\n return q.sides ? q.sides.map((s) => ({ axis: s.axis, edge: s.side, rate: s.rate })) : TRANSLATE;\n}\n\n/** Options for `spacingSnapSource`. */\nexport interface SpacingSnapSourceOptions {\n /** The boxes to measure gaps between, in place of the subject's siblings. */\n getTargets?: () => readonly Bounds[];\n /** Which nodes offer gaps. Narrows the default siblings; not `getTargets`. */\n filter?: TargetFilter;\n /** The color of the gaps it marks. Default: the readout layer's. */\n color?: string;\n /** Overrides the canvas's reach for these targets, in screen px. */\n reachPx?: number;\n}\n\ninterface Measured { boxes: readonly Bounds[]; x: readonly MeasuredGap[]; y: readonly MeasuredGap[] }\n\nconst measureAll = (boxes: readonly Bounds[]): Measured =>\n ({ boxes, x: measureGapSpans(boxes, 'x'), y: measureGapSpans(boxes, 'y') });\n\nfunction gapMark(g: SpacingGap, color: string | undefined): SnapMark {\n const ends = g.axis === 'x'\n ? { from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at } }\n : { from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max } };\n return { kind: 'gap', ...ends, value: g.max - g.min, ...(color === undefined ? {} : { color }) };\n}\n\n/**\n * Equal spacing as snap targets, Figma's: on each axis, the positions of the\n * subject's box that make its gap to a neighbor equal one already between\n * two siblings, or center it between its two neighbors. A resize moves only\n * the sides it drags; on a turned or skewed box, the sides of its\n * axis-aligned extent the drag moves. When the result meets one, it marks\n * every gap of that size, the box's own included, where the box lands.\n */\nexport function spacingSnapSource(opts: SpacingSnapSourceOptions = {}): SnapSource {\n const fromScene = cachedPerScene(measureAll, opts.filter);\n return {\n id: 'spacing',\n ...(opts.reachPx === undefined ? {} : { reachPx: opts.reachPx }),\n roles: ['box'],\n gestures: ['move', 'resize'],\n *collect(q) {\n const box = q.box;\n const probe = q.probes.find((p) => p.role === 'box');\n const measured = opts.getTargets ? measureAll(opts.getTargets()) : fromScene(q);\n if (!box || !probe || !measured) return;\n const reach = q.reachWorld(q.reachPx);\n const refs = { x: referenceGaps(box, measured.x), y: referenceGaps(box, measured.y) };\n const seen = new Set<string>();\n for (const { axis, edge, rate } of movingSides(q)) {\n const speed = Math.hypot(rate.x, rate.y);\n for (const o of spacingOffers(box, axis, edge, measured.boxes, refs[axis])) {\n const key = `${axis}:${edge}:${o.delta.toFixed(6)}:${o.size.toFixed(6)}`;\n if (Math.abs(o.delta) / speed > reach || seen.has(key)) continue;\n seen.add(key);\n yield {\n probe: probe.id,\n locus: sideLine(probe.at, rate, o.delta),\n mark: (delta: Point) => {\n const landed = landedBox(q, delta) ?? box;\n return equalGaps(landed, axis, o.size, measured.boxes, refs[axis]).map((g) => gapMark(g, opts.color));\n },\n };\n }\n }\n },\n };\n}\n","import type { Bounds } from '@weasel-js/core';\nimport type { Guide, SpacingGap } from '../guides/types';\n\ntype Axis = 'x' | 'y';\n\nconst EPS = 1e-6;\nconst lo = (b: Bounds, a: Axis): number => (a === 'x' ? b.x : b.y);\nconst hi = (b: Bounds, a: Axis): number => (a === 'x' ? b.x + b.width : b.y + b.height);\nconst mid = (b: Bounds, a: Axis): number => (lo(b, a) + hi(b, a)) / 2;\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The distances `measureDistances` found, ready for `createGuidesLayer`:\n * `gaps` as its `getGaps`, `leaders` as its `getGuides`. */\nexport interface DistanceReadout {\n /** One measured distance per gap, labeled with its length when drawn. */\n gaps: SpacingGap[];\n /** Where a gap runs past the target, the line from the gap's end along the\n * target's edge to the target, so the number reads as reaching it. */\n leaders: Guide[];\n}\n\n/**\n * The distances between two boxes, on each axis where they separate: for\n * `from` left of `to`, the gap from `from`'s right edge to `to`'s left. A gap\n * is drawn through the range the boxes share on the other axis, or through\n * `from`'s center when they share none, with a leader to `to`. When one box\n * holds the other on an axis and they overlap on the other, the inner box's\n * distances to the outer's two edges on that axis instead. An axis where the\n * boxes partly overlap, or meet flush, has no distance.\n */\nexport function measureDistances(from: Bounds, to: Bounds): DistanceReadout {\n const out: DistanceReadout = { gaps: [], leaders: [] };\n for (const axis of ['x', 'y'] as const) measureAxis(from, to, axis, out);\n return out;\n}\n\nfunction measureAxis(from: Bounds, to: Bounds, axis: Axis, out: DistanceReadout): void {\n const c = cross(axis);\n const sharedMin = Math.max(lo(from, c), lo(to, c));\n const sharedMax = Math.min(hi(from, c), hi(to, c));\n const shares = sharedMax - sharedMin > EPS;\n const push = (min: number, max: number, at: number): void => {\n if (max - min > EPS) out.gaps.push({ axis, min, max, at });\n };\n\n const before = hi(from, axis) <= lo(to, axis) + EPS;\n const after = hi(to, axis) <= lo(from, axis) + EPS;\n if (before || after) {\n const [min, max] = before ? [hi(from, axis), lo(to, axis)] : [hi(to, axis), lo(from, axis)];\n if (max - min <= EPS) return;\n const at = shares ? (sharedMin + sharedMax) / 2 : mid(from, c);\n push(min, max, at);\n if (!shares) {\n const edge = before ? lo(to, axis) : hi(to, axis);\n const span = at < lo(to, c) ? { min: at, max: lo(to, c) } : { min: hi(to, c), max: at };\n out.leaders.push({ id: `distance:${axis}`, axis, offset: edge, span });\n }\n return;\n }\n if (!shares) return;\n const [inner, outer] = lo(from, axis) >= lo(to, axis) - EPS && hi(from, axis) <= hi(to, axis) + EPS\n ? [from, to]\n : lo(to, axis) >= lo(from, axis) - EPS && hi(to, axis) <= hi(from, axis) + EPS\n ? [to, from]\n : [null, null];\n if (inner === null || outer === null) return;\n const at = mid(inner, c);\n push(lo(outer, axis), lo(inner, axis), at);\n push(hi(inner, axis), hi(outer, axis), at);\n}\n","import type { Action, GestureBinding, ModSpec, NodeId, Scene, SnapMark, SnapOutcomeStore, SurfaceContribution } from '@weasel-js/core';\nimport { measureDistances, type DistanceReadout } from './distance';\nimport { worldBoundsOf, worldUnionOf } from '../guides/alignment/sceneBounds';\nimport type { ImmediateParams } from '@weasel-js/core';\n\n\n/** Options for `distanceReadout`. */\nexport interface DistanceReadoutOptions {\n /** The key held to show the readout. Default `'alt'`. */\n modifier?: 'alt' | 'ctrl' | 'meta' | 'shift';\n /** The color of the marks it writes. Default: the readout layer's. */\n color?: string;\n /** Contribution id, and the prefix of its action's. Default `'distanceReadout'`. */\n id?: string;\n}\n\n/** The readout as snap marks: a `distance` per gap, a `line` per leader. */\nfunction marksOf(r: DistanceReadout, color: string | undefined): SnapMark[] {\n const c = color === undefined ? {} : { color };\n return [\n ...r.gaps.map((g): SnapMark => g.axis === 'x'\n ? { kind: 'distance', from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at }, value: g.max - g.min, ...c }\n : { kind: 'distance', from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max }, value: g.max - g.min, ...c }),\n ...r.leaders.flatMap((l): SnapMark[] => {\n if (l.span === undefined) return [];\n return [l.axis === 'x'\n ? { kind: 'line', from: { x: l.offset, y: l.span.min }, to: { x: l.offset, y: l.span.max }, ...c }\n : { kind: 'line', from: { x: l.span.min, y: l.offset }, to: { x: l.span.max, y: l.offset }, ...c }];\n }),\n ];\n}\n\n/** What `distanceReadout` returns: a surface contribution, plus a read of\n * what it is showing. */\nexport interface DistanceReadoutContribution extends SurfaceContribution {\n /** The distances on screen now; empty while hidden. */\n read(): DistanceReadout;\n}\n\nconst EMPTY: DistanceReadout = { gaps: [], leaders: [] };\nconst MODIFIERS: readonly NonNullable<DistanceReadoutOptions['modifier']>[] = ['alt', 'ctrl', 'meta', 'shift'];\n\n/** The ids and every node under them: what the pick under the pointer skips. */\nfunction subtreeOf(scene: Scene<unknown, string, unknown>, ids: readonly NodeId[]): Set<NodeId> {\n const out = new Set<NodeId>();\n const stack = [...ids];\n while (stack.length > 0) {\n const id = stack.pop()!;\n if (out.has(id)) continue;\n out.add(id);\n stack.push(...scene.childrenOf(id));\n }\n return out;\n}\n\n/**\n * Distance readouts on hover: while `modifier` is held over a shape, the\n * distances from the selection's box to that shape's, on each axis where they\n * separate, measured by `measureDistances` and drawn as labeled gaps. Pass it\n * in `<SceneCanvas ambient>`. It runs on `hover` bindings, so it claims no\n * input, and it reads the canvas's `selection`, `scene`, `nodeAtPoint`,\n * `poseDescriptor`, and `snapReadout` deps. A press hides it.\n */\nexport function distanceReadout(opts: DistanceReadoutOptions = {}): DistanceReadoutContribution {\n const id = opts.id ?? 'distanceReadout';\n const modifier = opts.modifier ?? 'alt';\n let shown: DistanceReadout = EMPTY;\n let store: SnapOutcomeStore | null = null;\n const show = (next: DistanceReadout): void => {\n if (next === shown || (next.gaps.length === 0 && shown.gaps.length === 0)) return;\n shown = next;\n store?.set(marksOf(next, opts.color));\n };\n\n const action: Action = {\n id: `${id}.measure`,\n label: 'Measure distance to the shape under the pointer',\n requires: ['selection', 'scene', 'nodeAtPoint', 'poseDescriptor', 'snapReadout'],\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const p = params as (ImmediateParams & { show?: boolean }) | undefined;\n const { selection, scene, nodeAtPoint, poseDescriptor, snapReadout } = deps;\n if (snapReadout !== undefined) store = snapReadout.store;\n const ids = selection?.get() ?? [];\n if (p?.show !== true || p.world === undefined\n || scene === undefined || nodeAtPoint === undefined || ids.length === 0) {\n show(EMPTY);\n return;\n }\n const hit = nodeAtPoint(p.world, subtreeOf(scene, ids));\n const from = worldUnionOf(scene, ids, { poseDescriptor });\n const [to] = hit === null ? [] : worldBoundsOf(scene, [hit], { poseDescriptor });\n show(from === null || to === undefined ? EMPTY : measureDistances(from, to));\n },\n },\n };\n\n const mods = (held: boolean): ModSpec => Object.fromEntries(\n MODIFIERS.map((m) => [m, m === modifier ? held : 'optional']),\n );\n const bindings: GestureBinding[] = [\n { spec: { kind: 'hover', mods: mods(true) }, actionId: action.id, opts: { id: `${id}.show`, params: { show: true } } },\n { spec: { kind: 'hover', mods: mods(false) }, actionId: action.id, opts: { id: `${id}.hide`, params: { show: false } } },\n { spec: { kind: 'hover', motion: 'leave' }, actionId: action.id, opts: { id: `${id}.leave`, params: { show: false } } },\n ];\n\n return {\n id,\n eligibility: { always: true },\n actions: [action],\n bindings,\n attach: (api) => {\n const el = api.element;\n const hide = (): void => show(EMPTY);\n el?.addEventListener('pointerdown', hide, true);\n return () => {\n el?.removeEventListener('pointerdown', hide, true);\n show(EMPTY);\n store = null;\n };\n },\n read: () => shown,\n };\n}\n","import type { FeaturePreset, SnapSource, SurfaceContribution } from '@weasel-js/core';\nimport type { TargetFilter } from '../sources/targets';\nimport { alignmentSnapSource } from '../sources/alignment';\nimport { spacingSnapSource } from '../sources/spacing';\nimport { distanceReadout, type DistanceReadoutOptions } from './distanceReadout';\n\n/** Options for `createSpacingHintsPreset`. */\nexport interface SpacingHintsOptions {\n /** Preset id. Default `'spacingHints'`. */\n id?: string;\n /** Snap a move so its gap to a neighbor equals one already between its\n * siblings, and mark the equal gaps. Default true. */\n spacing?: boolean;\n /** Snap to the siblings' edges and centers too, and mark the line met.\n * Default false. */\n align?: boolean;\n /** Snap distance in screen px. Default the canvas's reach. */\n tolerance?: number;\n /** Which nodes the snap sources take as siblings to line up or space against. */\n filter?: TargetFilter;\n /** The Alt-hover distance readout, configured, or `false` for none. Default\n * on, with the preset's `color`. */\n readout?: false | Omit<DistanceReadoutOptions, 'color'>;\n /** The color of the marks and the readout. */\n color?: string;\n}\n\n/**\n * Spacing hints as one `<SceneCanvas features>` preset: snap sources for\n * equal spacing between siblings and, if asked, alignment to their edges\n * and centers, whose marks the canvas's snap readout draws; and holding Alt\n * over a shape measures its distance from the selection.\n */\nexport function createSpacingHintsPreset(opts: SpacingHintsOptions = {}): FeaturePreset {\n const id = opts.id ?? 'spacingHints';\n const color = opts.color === undefined ? {} : { color: opts.color };\n const own = {\n ...color,\n ...(opts.filter === undefined ? {} : { filter: opts.filter }),\n ...(opts.tolerance === undefined ? {} : { reachPx: opts.tolerance }),\n };\n const snapSources: SnapSource[] = [\n ...((opts.spacing ?? true) ? [spacingSnapSource(own)] : []),\n ...((opts.align ?? false) ? [alignmentSnapSource(own)] : []),\n ];\n const contributions: SurfaceContribution[] = [];\n if (opts.readout !== false) contributions.push(distanceReadout({ ...opts.readout, ...color }));\n return { id, snapSources, contributions };\n}\n","import type { DropTarget, LayoutSnap } from '@weasel-js/core';\n\nfunction dist2(a: { x: number; y: number }, b: { x: number; y: number }): number {\n const dx = a.x - b.x;\n const dy = a.y - b.y;\n return dx * dx + dy * dy;\n}\n\nfunction nearestOf<TPose>(\n targets: DropTarget<TPose>[],\n pointer: { x: number; y: number },\n): DropTarget<TPose> | null {\n if (targets.length === 0) return null;\n let best = targets[0];\n let bestD = dist2(best.origin, pointer);\n for (let i = 1; i < targets.length; i++) {\n const d = dist2(targets[i].origin, pointer);\n if (d < bestD) {\n bestD = d;\n best = targets[i];\n }\n }\n return best;\n}\n\n/** Snap policy that never picks a target — every drop is rejected, which is\n * what a free-form container wants. */\nexport function none<TPose>(): LayoutSnap<TPose> {\n return { pickTarget: () => null };\n}\n\n/** Snap policy that always picks the target closest to the pointer, however\n * far away it is. */\nexport function nearest<TPose>(): LayoutSnap<TPose> {\n return { pickTarget: (targets, pointer) => nearestOf(targets, pointer) };\n}\n\n/** Snap policy that picks the closest target, but only within `tolerance`\n * world units — beyond that the drop is rejected. */\nexport function nearestWithin<TPose>(opts: { tolerance: number }): LayoutSnap<TPose> {\n const tol2 = opts.tolerance * opts.tolerance;\n return {\n pickTarget(targets, pointer) {\n const got = nearestOf(targets, pointer);\n if (got === null) return null;\n return dist2(got.origin, pointer) <= tol2 ? got : null;\n },\n };\n}\n\nfunction rectContains(\n r: { x: number; y: number; width: number; height: number },\n p: { x: number; y: number },\n): boolean {\n return p.x >= r.x && p.x < r.x + r.width && p.y >= r.y && p.y < r.y + r.height;\n}\n\n/**\n * Region-aware snap. If the pointer falls inside any target's `hitBounds`,\n * that target wins; otherwise falls back to nearest-origin. Useful for\n * strategies whose targets are area-shaped (gutters, drop-zones, gridded\n * cells) rather than point-shaped.\n *\n * Pointer-in-multiple-bounds order: first match in iteration order wins, so\n * strategies should emit narrower/more-specific targets before broader ones\n * (e.g. row-gutter before tray-corner).\n */\nexport function containedThenNearest<TPose>(): LayoutSnap<TPose> {\n return {\n pickTarget(targets, pointer) {\n for (const t of targets) {\n if (t.hitBounds && rectContains(t.hitBounds, pointer)) return t;\n }\n return nearestOf(targets, pointer);\n },\n };\n}\n\ninterface CellMeta {\n cellRect: { x: number; y: number; width: number; height: number };\n}\n\nfunction isCellMeta(m: unknown): m is CellMeta {\n return (\n typeof m === 'object' &&\n m !== null &&\n 'cellRect' in m &&\n typeof (m as { cellRect: unknown }).cellRect === 'object'\n );\n}\n\n/**\n * Backwards-compatible cell snap. Prefer `containedThenNearest` for new\n * strategies; this variant remains for `tileGrid` and any caller that puts\n * its cell rect in `meta.cellRect` rather than `hitBounds`.\n */\nexport function cellAt<TPose>(): LayoutSnap<TPose> {\n return {\n pickTarget(targets, pointer) {\n for (const t of targets) {\n if (t.hitBounds && rectContains(t.hitBounds, pointer)) return t;\n if (isCellMeta(t.meta) && rectContains(t.meta.cellRect, pointer)) return t;\n }\n return nearestOf(targets, pointer);\n },\n };\n}\n","import type { LayoutContainer, LayoutSnap, LayoutStrategy } from '@weasel-js/core';\n\n/** Options for `perContainer`. */\nexport interface PerContainerOptions<TPose> {\n /** The snap every container shares: a strategy's `snap` is read with no\n * container in hand, so it cannot come from the one the factory builds. */\n snap: LayoutSnap<TPose>;\n /** Shared for the same reason. Absent, a container's body is its bounds. */\n contains?: LayoutStrategy<TPose>['contains'];\n /** How many containers' strategies to keep. Past it, the one used longest\n * ago is dropped and built again when next asked for. Default 256. */\n max?: number;\n}\n\n/** A strategy `perContainer` built, and the way to drop one container's state. */\nexport type PerContainerStrategy<TPose> = LayoutStrategy<TPose> & {\n /** Drop what was built for `containerId`: for a container that is gone, or\n * whose cached state no longer describes it. */\n forget(containerId: string): void;\n};\n\n/**\n * A layout strategy that keeps state, as one strategy value: `factory` runs\n * once for each container the layout is asked about, and what it returns\n * serves that container from then on, closing over whatever it caches — a\n * spatial index, the last arrangement, a solver's warm start.\n *\n * Declare the result on as many containers as you like. A method the built\n * strategy leaves out behaves as its absence would.\n */\nexport function perContainer<TPose>(\n factory: (container: LayoutContainer) => LayoutStrategy<TPose>,\n opts: PerContainerOptions<TPose>,\n): PerContainerStrategy<TPose> {\n const max = opts.max ?? 256;\n const built = new Map<string, LayoutStrategy<TPose>>();\n\n const of = (container: LayoutContainer): LayoutStrategy<TPose> => {\n let strategy = built.get(container.id);\n if (strategy) built.delete(container.id);\n else strategy = factory(container);\n // Re-inserted on every use, so the map's first key is the one used longest ago.\n built.set(container.id, strategy);\n if (built.size > max) built.delete(built.keys().next().value!);\n return strategy;\n };\n\n return {\n snap: opts.snap,\n contains: opts.contains,\n forget: (containerId) => void built.delete(containerId),\n\n childPoses: (container, children) => of(container).childPoses(container, children),\n getDropTargets: (container, children, dragged) => of(container).getDropTargets(container, children, dragged),\n reflowPoses: (container, children, dragged, target) =>\n of(container).reflowPoses(container, children, dragged, target),\n commitDrop: (container, children, dragged, target) =>\n of(container).commitDrop(container, children, dragged, target),\n\n dropRegion: (container) => of(container).dropRegion?.(container) ?? null,\n acceptsDrop: (container, dragged) => of(container).acceptsDrop?.(container, dragged) ?? true,\n arrive(container, children, arrivals) {\n const s = of(container);\n return s.arrive ? s.arrive(container, children, arrivals) : { poses: s.childPoses(container, children) };\n },\n depart(container, children, departed) {\n const s = of(container);\n return s.depart ? s.depart(container, children, departed) : { poses: s.childPoses(container, children) };\n },\n contentExtent: (container, children) =>\n of(container).contentExtent?.(container, children) ?? container.bounds,\n releaseDrop: (container, children, dragged) =>\n of(container).releaseDrop?.(container, children, dragged) ?? null,\n };\n}\n","import { createTransformOp, type LayoutSnap, type LayoutStrategy } from '@weasel-js/core';\nimport { none } from '../snaps';\n\n/** Options for `freeform`. */\nexport interface FreeformOptions<TPose> {\n snap?: LayoutSnap<TPose>;\n}\n\n/**\n * Identity layout: each child stays where it's stored, no reflow, no drop\n * targets. `snap` is accepted for API symmetry — overrides take effect only\n * if a caller wires up an external drop-target source, since `getDropTargets`\n * returns empty by default.\n */\nexport function freeform<TPose>(opts: FreeformOptions<TPose> = {}): LayoutStrategy<TPose> {\n const snap = opts.snap ?? none<TPose>();\n\n return {\n snap,\n\n childPoses(_container, children) {\n const out = new Map<string, TPose>();\n for (const c of children) out.set(c.id, c.pose);\n return out;\n },\n\n getDropTargets() {\n return [];\n },\n\n reflowPoses() {\n return new Map();\n },\n\n commitDrop(_container, _children, dragged, target) {\n return [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: 'Drop',\n }),\n ];\n },\n };\n}\n","import {\n createTransformOp,\n type Op,\n type ContainerBounds,\n type DropTarget,\n type LayoutArrival,\n type LayoutChild,\n type LayoutContainer,\n type LayoutDragged,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\nimport { cellAt } from '../snaps';\n\ninterface TileMeta {\n col: number;\n row: number;\n cellRect: Rect;\n}\n\n/**\n * What a `tileGrid` does with a child past its `cols × rows` cells.\n *\n * - `'reject'` (default) — the grid holds `cols × rows` and refuses more, by\n * any route: a drop finds no free cell, and an insert or reparent that would\n * overfill it is reverted whole.\n * - `'grow'` — the grid adds a line of cells whenever the last one fills\n * (a row, or a column for `flow: 'column'`) and the container grows by its\n * pitch to hold it, and gives the line back when children leave and it\n * empties. `rows` (or `cols`) is the minimum.\n * - `'scroll'` — the container keeps its size, and the extra children take\n * cells past its last visible line, at the same pitch. `contentExtent`\n * reports the region they cover, for a host to scroll over.\n */\nexport type TileGridOverflow = 'reject' | 'grow' | 'scroll';\n\n/** Options for `tileGrid`. */\nexport interface TileGridOptions<TPose> {\n cols: number;\n rows: number;\n /** Gap between cells, in world units. Default 0. */\n gap?: number;\n /** The order cells fill in: along each row (`'row'`, the default) or down\n * each column (`'column'`). It is also the direction an overflowing grid\n * runs on in. */\n flow?: 'row' | 'column';\n /** What happens past `cols × rows` children. Default `'reject'`. */\n overflow?: TileGridOverflow;\n snap?: LayoutSnap<TPose>;\n /** Optional: map a cell rect + the dragged pose to the new pose. Default\n * writes `{ x, y, width, height }` into the dragged pose (assumes\n * `RectPose`). `dragged` is the pre-drop pose of the child being placed —\n * use it to preserve fields the cell rect doesn't carry (e.g. rotation). */\n cellToPose?(cellRect: Rect, dragged: TPose): TPose;\n /** Optional: the point that decides which cell a child occupies — a child\n * occupies the cell containing it. Default reads `x`/`y` plus half of\n * `width`/`height` when the pose has them, which is the center of a\n * `RectPose` and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\nfunction defaultCenterOf(pose: unknown): { x: number; y: number } {\n const p = pose as { x?: number; y?: number; width?: number; height?: number };\n return { x: (p.x ?? 0) + (p.width ?? 0) / 2, y: (p.y ?? 0) + (p.height ?? 0) / 2 };\n}\n\n/**\n * Layout strategy that arranges children into a grid of cells, one child per\n * cell. What happens past `cols × rows` children is the `overflow` policy.\n *\n * A child occupies the cell its pose sits in (see `centerOf`). A drag from\n * inside the container swaps with the child in the cell it lands on; a drop\n * from outside is offered only the free cells, so it lands in the nearest\n * free one. A child that joins by an insert or a reparent is placed the same\n * way, in the free cell nearest to where it was put.\n */\nexport function tileGrid<TPose>(\n opts: TileGridOptions<TPose>,\n): LayoutStrategy<TPose> {\n const { cols, rows } = opts;\n const gap = opts.gap ?? 0;\n const byColumn = opts.flow === 'column';\n const overflow = opts.overflow ?? 'reject';\n const snap = opts.snap ?? cellAt<TPose>();\n const capacity = cols * rows;\n /** Cells per line in fill order, and the declared line count. */\n const perLine = byColumn ? rows : cols;\n const minLines = byColumn ? cols : rows;\n const cellToPose: (cell: Rect, dragged: TPose) => TPose =\n opts.cellToPose ?? ((cell, dragged) => {\n // Default: spread the cell rect over the dragged pose. Preserves any\n // extra fields the dragged pose carries.\n return { ...(dragged as object), ...cell } as TPose;\n });\n const centerOf = opts.centerOf ?? defaultCenterOf;\n\n const linesFor = (n: number): number => Math.max(minLines, Math.ceil(n / perLine));\n\n /** The grid over `bounds` while it holds `n` children: its cell pitch, and\n * how many cells it offers before running past the container. A growing\n * grid spreads its lines over the container, which it keeps sized to fit\n * them; the others always lay the declared grid over it. */\n function gridOf(bounds: ContainerBounds, n: number) {\n const lines = overflow === 'grow' ? linesFor(n) : minLines;\n const c = byColumn ? lines : cols;\n const r = byColumn ? rows : lines;\n const cw = (bounds.width - gap * (c - 1)) / c;\n const ch = (bounds.height - gap * (r - 1)) / r;\n\n function rectAt(index: number): Rect {\n const along = index % perLine;\n const line = Math.floor(index / perLine);\n const col = byColumn ? line : along;\n const row = byColumn ? along : line;\n return { x: bounds.x + col * (cw + gap), y: bounds.y + row * (ch + gap), width: cw, height: ch };\n }\n\n /** The cell index `pose` sits in, overflow cells past the container\n * included, or `null` in a gap or off the grid. */\n function indexOf(pose: TPose): number | null {\n const p = centerOf(pose);\n const col = Math.floor((p.x - bounds.x) / (cw + gap));\n const row = Math.floor((p.y - bounds.y) / (ch + gap));\n if (col < 0 || row < 0) return null;\n if (p.x - bounds.x - col * (cw + gap) >= cw) return null;\n if (p.y - bounds.y - row * (ch + gap) >= ch) return null;\n if (byColumn ? row >= rows : col >= cols) return null;\n return byColumn ? col * rows + row : row * cols + col;\n }\n\n /** The cells a drop may land in, or an arrival be placed in, with `n`\n * children in the grid: the declared grid when it refuses overflow, and\n * otherwise every whole line the children reach. */\n const cells = overflow === 'reject' ? capacity : linesFor(n) * perLine;\n\n /** The container bounds that hold `lines` lines at this pitch. */\n function boundsFor(lineCount: number): ContainerBounds {\n return byColumn\n ? { ...bounds, width: lineCount * cw + gap * (lineCount - 1) }\n : { ...bounds, height: lineCount * ch + gap * (lineCount - 1) };\n }\n\n return { rectAt, indexOf, cells, boundsFor };\n }\n\n const metaOf = (index: number, cellRect: Rect): TileMeta => {\n const along = index % perLine;\n const line = Math.floor(index / perLine);\n return byColumn\n ? { col: line, row: along, cellRect }\n : { col: along, row: line, cellRect };\n };\n const indexOfMeta = (m: TileMeta): number => (byColumn ? m.col * rows + m.row : m.row * cols + m.col);\n\n /** How many children the grid holds, not counting a drag from outside it. */\n const heldBy = (container: LayoutContainer, children: ReadonlyArray<LayoutChild<TPose>>, dragged?: LayoutDragged<TPose>): number =>\n dragged && dragged.sourceContainerId !== container.id\n ? children.filter((c) => c.id !== dragged.id).length\n : children.length;\n\n /** The swap dragging `dragged` onto `target` causes, or `null`. Preview and\n * commit both use it, so they cannot disagree. */\n function computeSwap(\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n dragged: LayoutDragged<TPose>,\n target: DropTarget<TPose> | null,\n ): { occupant: string; from: TPose; newPose: TPose } | null {\n if (target === null) return null;\n if (dragged.sourceContainerId !== container.id) return null;\n const grid = gridOf(container.bounds, children.length);\n const idx = indexOfMeta(target.meta as TileMeta);\n const occupant = children.find((c) => c.id !== dragged.id && grid.indexOf(c.pose) === idx);\n if (occupant === undefined) return null;\n // The occupant takes the cell the dragged child is leaving — where the\n // container state says it is now, which an earlier placement of the same\n // drop may have moved it to.\n const self = children.find((c) => c.id === dragged.id);\n const fromIdx = grid.indexOf(self ? self.pose : dragged.originPose);\n if (fromIdx === null || fromIdx === idx) return null;\n return { occupant: occupant.id, from: occupant.pose, newPose: cellToPose(grid.rectAt(fromIdx), occupant.pose) };\n }\n\n /**\n * Every child a cell of `into`, in the order of the cells they sit in on\n * `from`, so a reflow compacts the survivors rather than re-sorting them —\n * an earlier swap among them has to outlive a sibling leaving the grid.\n * Children sitting in no cell (a gap, or off the grid) sort last; ties break\n * by id so an arrangement with no cells yet is still deterministic. Past\n * the declared grid they run on at the same pitch.\n */\n function pack(\n from: ReturnType<typeof gridOf>,\n into: ReturnType<typeof gridOf>,\n children: ReadonlyArray<LayoutChild<TPose>>,\n ): Map<string, TPose> {\n const ordered = children\n .map((c) => ({ c, cell: from.indexOf(c.pose) }))\n .sort((a, b) => {\n if (a.cell !== b.cell) {\n if (a.cell === null) return 1;\n if (b.cell === null) return -1;\n return a.cell - b.cell;\n }\n return a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0;\n });\n const out = new Map<string, TPose>();\n for (let i = 0; i < ordered.length; i++) {\n out.set(ordered[i].c.id, cellToPose(into.rectAt(i), ordered[i].c.pose));\n }\n return out;\n }\n\n return {\n snap,\n\n childPoses(container, children) {\n const grid = gridOf(container.bounds, children.length);\n return pack(grid, grid, children);\n },\n\n getDropTargets(container, children, dragged) {\n const grid = gridOf(container.bounds, heldBy(container, children, dragged));\n // A drag from inside may land on an occupied cell and swap; one from\n // outside has nobody to swap with, so occupied cells are not offered.\n const occupied = new Set<number>();\n const fromOutside = dragged.sourceContainerId !== container.id;\n if (fromOutside) {\n for (const c of children) {\n if (c.id === dragged.id) continue;\n const idx = grid.indexOf(c.pose);\n if (idx !== null) occupied.add(idx);\n }\n }\n const offered: number[] = [];\n for (let i = 0; i < grid.cells; i++) if (!occupied.has(i)) offered.push(i);\n // A grid that takes overflow always has room for one more.\n if (fromOutside && offered.length === 0 && overflow !== 'reject') offered.push(grid.cells);\n return offered.map((i) => {\n const cellRect = grid.rectAt(i);\n return {\n pose: cellToPose(cellRect, dragged.pose),\n origin: { x: cellRect.x + cellRect.width / 2, y: cellRect.y + cellRect.height / 2 },\n meta: metaOf(i, cellRect) satisfies TileMeta,\n };\n });\n },\n\n reflowPoses(container, children, dragged, target) {\n const out = new Map<string, TPose>();\n const swap = computeSwap(container, children, dragged, target);\n if (swap !== null) {\n out.set(swap.occupant, swap.newPose);\n }\n return out;\n },\n\n commitDrop(container, children, dragged, target) {\n const ops: Op[] = [];\n\n let droppedPose: TPose;\n if (target === null) {\n droppedPose = dragged.pose;\n } else {\n const meta = target.meta as TileMeta;\n droppedPose = cellToPose(meta.cellRect, dragged.pose);\n const swap = computeSwap(container, children, dragged, target);\n if (swap !== null) {\n ops.push(\n createTransformOp<TPose>({\n id: swap.occupant,\n from: swap.from,\n to: swap.newPose,\n label: 'Tile swap',\n }),\n );\n }\n }\n ops.push(\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: droppedPose,\n label: 'Tile drop',\n }),\n );\n return ops;\n },\n\n arrive(container, children, arrivals): LayoutArrival<TPose> | null {\n const n = children.length;\n if (overflow === 'reject' && n > capacity) return null;\n // The grid as it stood before these joined: its pitch is the one the\n // arrivals are placed at, and a growing grid extends by it.\n const grid = gridOf(container.bounds, n - arrivals.size);\n const slots = overflow === 'reject' ? capacity : linesFor(n) * perLine;\n const taken = new Set<number>();\n for (const c of children) {\n if (arrivals.has(c.id)) continue;\n const idx = grid.indexOf(c.pose);\n if (idx !== null) taken.add(idx);\n }\n const poses = new Map<string, TPose>();\n for (const c of children) {\n if (!arrivals.has(c.id)) continue;\n const own = grid.indexOf(c.pose);\n let idx: number;\n if (own !== null && own < slots && !taken.has(own)) {\n idx = own;\n } else {\n const at = centerOf(c.pose);\n let best = -1;\n let bestD = Infinity;\n for (let i = 0; i < slots; i++) {\n if (taken.has(i)) continue;\n const r = grid.rectAt(i);\n const dx = r.x + r.width / 2 - at.x;\n const dy = r.y + r.height / 2 - at.y;\n const d = dx * dx + dy * dy;\n if (d < bestD) { bestD = d; best = i; }\n }\n if (best < 0) return null;\n idx = best;\n }\n taken.add(idx);\n poses.set(c.id, cellToPose(grid.rectAt(idx), c.pose));\n }\n if (overflow !== 'grow') return { poses };\n const lines = linesFor(n);\n if (lines === linesFor(n - arrivals.size)) return { poses };\n return { poses, bounds: grid.boundsFor(lines) };\n },\n\n depart(container, children, departed): LayoutArrival<TPose> {\n const n = children.length;\n // The grid as it stood with the departed still in it: a grown grid\n // gives back whole lines at that pitch, down to its declared count.\n const before = gridOf(container.bounds, n + departed.size);\n const lines = linesFor(n);\n if (overflow !== 'grow' || lines === linesFor(n + departed.size)) {\n return { poses: pack(before, before, children) };\n }\n const bounds = before.boundsFor(lines);\n return { poses: pack(before, gridOf(bounds, n), children), bounds };\n },\n\n contentExtent(container, children) {\n const grid = gridOf(container.bounds, children.length);\n const lines = Math.ceil(children.length / perLine);\n if (lines <= minLines) return container.bounds;\n const reach = grid.boundsFor(lines);\n return overflow === 'grow'\n ? container.bounds\n : { ...reach, width: Math.max(reach.width, container.bounds.width), height: Math.max(reach.height, container.bounds.height) };\n },\n };\n}\n","import {\n type Vec2,\n createTransformOp,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport { nearestWithin } from '../snaps';\n\n/** Which points within a container a child can snap to. */\nexport type SnapPattern = 'corners' | 'edges' | 'center' | 'grid';\n\n/** Options for `snapPoint`. */\nexport interface SnapPointOptions<TPose> {\n pattern: SnapPattern;\n /** Spacing for the 'grid' pattern, in world units. Default 50. */\n gridSpacing?: number;\n /** Tolerance for the default snap policy (nearestWithin). Default Infinity. */\n tolerance?: number;\n snap?: LayoutSnap<TPose>;\n}\n\nfunction buildPoints(\n bounds: { x: number; y: number; width: number; height: number },\n pattern: SnapPattern,\n gridSpacing: number,\n): Vec2[] {\n switch (pattern) {\n case 'corners':\n return [\n { x: bounds.x, y: bounds.y },\n { x: bounds.x + bounds.width, y: bounds.y },\n { x: bounds.x, y: bounds.y + bounds.height },\n { x: bounds.x + bounds.width, y: bounds.y + bounds.height },\n ];\n case 'edges':\n return [\n { x: bounds.x + bounds.width / 2, y: bounds.y },\n { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height },\n { x: bounds.x, y: bounds.y + bounds.height / 2 },\n { x: bounds.x + bounds.width, y: bounds.y + bounds.height / 2 },\n ];\n case 'center':\n return [{ x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }];\n case 'grid': {\n const out: Vec2[] = [];\n const cols = Math.floor(bounds.width / gridSpacing);\n const rows = Math.floor(bounds.height / gridSpacing);\n for (let j = 0; j <= rows; j++) {\n for (let i = 0; i <= cols; i++) {\n out.push({ x: bounds.x + i * gridSpacing, y: bounds.y + j * gridSpacing });\n }\n }\n return out;\n }\n }\n}\n\n/** Layout strategy that leaves children where they are but offers a fixed set\n * of points — corners, edge midpoints, center, or a grid — for a dragged\n * child to land on. */\nexport function snapPoint<TPose extends Vec2>(\n opts: SnapPointOptions<TPose>,\n): LayoutStrategy<TPose> {\n const gridSpacing = opts.gridSpacing ?? 50;\n const tolerance = opts.tolerance ?? Infinity;\n const snap = opts.snap ?? nearestWithin<TPose>({ tolerance });\n\n return {\n snap,\n\n childPoses(_container, children) {\n const out = new Map<string, TPose>();\n for (const c of children) out.set(c.id, c.pose);\n return out;\n },\n\n getDropTargets(container, _children, dragged) {\n const points = buildPoints(container.bounds, opts.pattern, gridSpacing);\n return points.map((p) => ({\n // Anchor the dragged child's top-left at the snap point.\n pose: { ...dragged.pose, x: p.x, y: p.y } as TPose,\n origin: p,\n }));\n },\n\n reflowPoses() {\n return new Map();\n },\n\n commitDrop(_container, _children, dragged, target) {\n const to = target === null ? dragged.pose : target.pose;\n return [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to,\n label: 'Snap drop',\n }),\n ];\n },\n };\n}\n","import {\n createTransformOp,\n type ContainerBounds,\n type LayoutArrival,\n type LayoutChild,\n type LayoutContainer,\n type LayoutDragged,\n type LayoutSnap,\n type LayoutStrategy,\n type Op,\n} from '@weasel-js/core';\n\n/** What makes a sequence layout a row of slots or a shelf-packed flow. */\nexport interface Sequencer<TPose> {\n /** `children` in sequence, read off the poses they were given when the\n * container was last arranged for `count` children. */\n order(\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n count: number,\n ): LayoutChild<TPose>[];\n /** A pose for every child of `sequence`, or `null` when the container\n * cannot hold them all. */\n place(container: LayoutContainer, sequence: ReadonlyArray<LayoutChild<TPose>>): Map<string, TPose> | null;\n /** The bounds the container takes to hold `sequence`, for one that sizes\n * itself to its children. */\n resize?(container: LayoutContainer, sequence: ReadonlyArray<LayoutChild<TPose>>): ContainerBounds | undefined;\n centerOf(pose: TPose): { x: number; y: number };\n snap: LayoutSnap<TPose>;\n /** Labels for the two kinds of op a drop writes. */\n labels: { drop: string; shift: string };\n}\n\ninterface IndexMeta {\n index: number;\n}\n\n/** The center of a `RectPose`, and the point itself for a point pose. */\nexport function defaultCenterOf(pose: unknown): { x: number; y: number } {\n const p = pose as { x?: number; y?: number; width?: number; height?: number };\n return { x: (p.x ?? 0) + (p.width ?? 0) / 2, y: (p.y ?? 0) + (p.height ?? 0) / 2 };\n}\n\nconst withAt = <T,>(list: readonly T[], index: number, item: T): T[] => [\n ...list.slice(0, index),\n item,\n ...list.slice(index),\n];\n\n/** The container's sequence without the dragged child, which counted\n * toward the last arrangement only if it came from here. */\nfunction othersOf<TPose>(\n seq: Sequencer<TPose>,\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n dragged: LayoutDragged<TPose>,\n): LayoutChild<TPose>[] {\n const held = children.filter((c) => c.id !== dragged.id);\n const count = held.length + (dragged.sourceContainerId === container.id ? 1 : 0);\n return seq.order(container, held, count);\n}\n\n/** The index that lands `child` nearest where it is now, among those the container can hold. */\nfunction nearestIndex<TPose>(\n seq: Sequencer<TPose>,\n container: LayoutContainer,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n child: LayoutChild<TPose>,\n): number | null {\n const at = seq.centerOf(child.pose);\n let best: number | null = null;\n let bestD = Infinity;\n for (let i = 0; i <= sequence.length; i++) {\n const pose = seq.place(container, withAt(sequence, i, child))?.get(child.id);\n if (pose === undefined) continue;\n const p = seq.centerOf(pose);\n const d = (p.x - at.x) ** 2 + (p.y - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n }\n return best;\n}\n\n/**\n * The behavior every layout that keeps its children in one ordered sequence\n * shares: a drop inserts at an index and shifts the children after it, an\n * arrival goes in at the index that lands it nearest where it was put, and a\n * departure closes the gap. The `Sequencer` says what the order is and where\n * a sequence sits.\n */\nexport function sequenceLayout<TPose>(seq: Sequencer<TPose>): LayoutStrategy<TPose> {\n const { centerOf } = seq;\n\n const moved = (a: TPose, b: TPose): boolean => {\n const p = centerOf(a);\n const q = centerOf(b);\n return p.x !== q.x || p.y !== q.y;\n };\n\n const arranged = (\n container: LayoutContainer,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n poses: Map<string, TPose>,\n ): LayoutArrival<TPose> => {\n const bounds = seq.resize?.(container, sequence);\n return bounds ? { poses, bounds } : { poses };\n };\n\n /** Where the siblings sit once the dragged child takes the index `target` names. */\n const shifted: LayoutStrategy<TPose>['reflowPoses'] = (container, children, dragged, target) => {\n if (!target) return new Map();\n const others = othersOf(seq, container, children, dragged);\n const self = { id: dragged.id, pose: dragged.pose };\n const poses = seq.place(container, withAt(others, (target.meta as IndexMeta).index, self)) ?? new Map();\n poses.delete(dragged.id);\n return poses;\n };\n\n return {\n snap: seq.snap,\n\n childPoses(container, children) {\n const sequence = seq.order(container, children, children.length);\n return seq.place(container, sequence) ?? new Map(children.map((c) => [c.id, c.pose]));\n },\n\n getDropTargets(container, children, dragged) {\n const others = othersOf(seq, container, children, dragged);\n const self = { id: dragged.id, pose: dragged.pose };\n const targets = [];\n for (let index = 0; index <= others.length; index++) {\n const pose = seq.place(container, withAt(others, index, self))?.get(dragged.id);\n if (pose === undefined) continue;\n targets.push({ pose, origin: centerOf(pose), meta: { index } satisfies IndexMeta });\n }\n return targets;\n },\n\n reflowPoses: shifted,\n\n commitDrop(container, children, dragged, target) {\n const ops: Op[] = [];\n if (target) {\n const poses = shifted(container, children, dragged, target);\n for (const c of children) {\n const to = poses.get(c.id);\n if (to !== undefined && moved(c.pose, to)) {\n ops.push(createTransformOp<TPose>({ id: c.id, from: c.pose, to, label: seq.labels.shift }));\n }\n }\n }\n ops.push(\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: seq.labels.drop,\n }),\n );\n return ops;\n },\n\n arrive(container, children, arrivals) {\n const held = children.filter((c) => !arrivals.has(c.id));\n let sequence = seq.order(container, held, held.length);\n for (const c of children) {\n if (!arrivals.has(c.id)) continue;\n const index = nearestIndex(seq, container, sequence, c);\n if (index === null) return null;\n sequence = withAt(sequence, index, c);\n }\n const poses = seq.place(container, sequence);\n return poses && arranged(container, sequence, poses);\n },\n\n depart(container, children, departed) {\n const sequence = seq.order(container, children, children.length + departed.size);\n const poses = seq.place(container, sequence) ?? new Map<string, TPose>();\n return arranged(container, sequence, poses);\n },\n };\n}\n","import type { LayoutSnap, LayoutStrategy } from '@weasel-js/core';\nimport { nearest } from '../snaps';\nimport type { Arrangement, Slot } from './arrangements';\nimport { defaultCenterOf, sequenceLayout } from './sequence';\n\n/** Options for `slots`. */\nexport interface SlotsOptions<TPose> {\n /** Where the slots are for a given child count: `rowSlots`, `gridSlots`,\n * `ringSlots`, or a function of your own. */\n arrangement: Arrangement;\n /** Which slot a drag means. Default `nearest()`. */\n snap?: LayoutSnap<TPose>;\n /** The pose a child takes in a slot. Default centers the child's own\n * `width`/`height` on the slot and keeps every other field. */\n slotToPose?(slot: Slot, pose: TPose): TPose;\n /** The point that decides which slot a child sits in. Default is the\n * center of a `RectPose`, and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\nfunction defaultSlotToPose<TPose>(slot: Slot, pose: TPose): TPose {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return { ...(pose as object), x: slot.x - width / 2, y: slot.y - height / 2 } as TPose;\n}\n\nfunction nearestSlot(at: { x: number; y: number }, places: readonly Slot[]): number {\n let best = -1;\n let bestD = Infinity;\n for (let i = 0; i < places.length; i++) {\n const d = (places[i]!.x - at.x) ** 2 + (places[i]!.y - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n }\n return best;\n}\n\n/**\n * Layout strategy that keeps its children in a sequence of slots — a row, a\n * grid, a ring — whose positions depend on how many children there are, so\n * the arrangement re-spaces itself as children come and go.\n *\n * A child's place in the sequence is the slot it sits nearest. Dropping a\n * drag on a slot inserts it there and shifts the children between; a drag\n * from outside is offered one slot more than the container holds. An insert\n * or reparent lands at the slot nearest where the child was put.\n */\nexport function slots<TPose>(opts: SlotsOptions<TPose>): LayoutStrategy<TPose> {\n const { arrangement } = opts;\n const slotToPose = opts.slotToPose ?? defaultSlotToPose;\n const centerOf = opts.centerOf ?? defaultCenterOf;\n\n return sequenceLayout<TPose>({\n snap: opts.snap ?? nearest<TPose>(),\n centerOf,\n labels: { drop: 'Slot drop', shift: 'Slot shift' },\n\n // Ties break by id, so a container nobody has arranged yet still has an order.\n order(container, children, count) {\n const places = arrangement(container.bounds, count);\n return children\n .map((c) => ({ c, slot: nearestSlot(centerOf(c.pose), places) }))\n .sort((a, b) => a.slot - b.slot || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0))\n .map((e) => e.c);\n },\n\n place(container, sequence) {\n const places = arrangement(container.bounds, sequence.length);\n if (places.length < sequence.length) return null;\n return new Map(sequence.map((c, i) => [c.id, slotToPose(places[i]!, c.pose)]));\n },\n });\n}\n","import type { Rect } from '@weasel-js/geom';\nimport type { ContainerBounds, LayoutChild, LayoutSnap, LayoutStrategy } from '@weasel-js/core';\nimport { nearest } from '../snaps';\nimport { sequenceLayout } from './sequence';\n\n\n/**\n * What `pack` does when its shelves run past the container's height.\n *\n * - `'reject'` (default) — refuse the child that would not fit, by any route.\n * - `'grow'` — the container's height follows its content, never below\n * `minHeight`.\n * - `'scroll'` — the container keeps its size and the shelves run on below\n * it; `contentExtent` reports the region they cover.\n */\nexport type PackOverflow = 'reject' | 'grow' | 'scroll';\n\n/** Options for `pack`. */\nexport interface PackOptions<TPose> {\n /** Space between neighbors on a shelf and between shelves, in world units. Default 0. */\n gap?: number;\n /** What happens past the container's height. Default `'reject'`. */\n overflow?: PackOverflow;\n /** The least height a `'grow'` container shrinks to. Default 0. */\n minHeight?: number;\n /** Which index a drag means. Default `nearest()`. */\n snap?: LayoutSnap<TPose>;\n /** A child's box. Default reads `x`, `y`, `width`, and `height` off the pose. */\n rectOf?(pose: TPose): Rect;\n /** `pose` with its box's top-left at `at`. Default writes `x` and `y`. */\n moveTo?(pose: TPose, at: { x: number; y: number }): TPose;\n}\n\n/**\n * Layout strategy that packs children of any size onto shelves: left to\n * right at their own sizes, wrapping at the container's width, each shelf as\n * tall as its tallest child. A child wider than the container is refused.\n *\n * The children's order is the order they read in — shelf by shelf, left to\n * right. A drop inserts at the index nearest the pointer and everything after\n * it reflows.\n */\nexport function pack<TPose>(opts: PackOptions<TPose> = {}): LayoutStrategy<TPose> {\n const gap = opts.gap ?? 0;\n const overflow = opts.overflow ?? 'reject';\n const minHeight = opts.minHeight ?? 0;\n const rectOf = opts.rectOf ?? ((pose: TPose) => pose as unknown as Rect);\n const moveTo = opts.moveTo ?? ((pose: TPose, at) => ({ ...(pose as object), ...at }) as TPose);\n\n // Ties break by id, so children nobody has arranged yet still have an order.\n const readingOrder = (children: ReadonlyArray<LayoutChild<TPose>>): LayoutChild<TPose>[] =>\n children\n .map((c) => ({ c, r: rectOf(c.pose) }))\n .sort((a, b) => a.r.y - b.r.y || a.r.x - b.r.x || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0))\n .map((e) => e.c);\n\n /** Shelf every child of `sequence`, and the height the shelves reach. Null when one is too wide. */\n function shelve(\n bounds: ContainerBounds,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n ): { poses: Map<string, TPose>; height: number } | null {\n const poses = new Map<string, TPose>();\n let x = 0;\n let y = 0;\n let shelf = 0;\n for (const c of sequence) {\n const { width, height } = rectOf(c.pose);\n if (width > bounds.width) return null;\n if (x > 0 && x + width > bounds.width) {\n y += shelf + gap;\n x = 0;\n shelf = 0;\n }\n poses.set(c.id, moveTo(c.pose, { x: bounds.x + x, y: bounds.y + y }));\n x += width + gap;\n shelf = Math.max(shelf, height);\n }\n return { poses, height: y + shelf };\n }\n\n const layout = sequenceLayout<TPose>({\n snap: opts.snap ?? nearest<TPose>(),\n labels: { drop: 'Pack drop', shift: 'Pack shift' },\n centerOf(pose) {\n const r = rectOf(pose);\n return { x: r.x + r.width / 2, y: r.y + r.height / 2 };\n },\n\n order: (_container, children) => readingOrder(children),\n\n place(container, sequence) {\n const shelved = shelve(container.bounds, sequence);\n if (!shelved) return null;\n return overflow === 'reject' && shelved.height > container.bounds.height ? null : shelved.poses;\n },\n\n resize(container, sequence) {\n if (overflow !== 'grow') return undefined;\n const height = Math.max(minHeight, shelve(container.bounds, sequence)?.height ?? 0);\n return height === container.bounds.height ? undefined : { ...container.bounds, height };\n },\n });\n\n return {\n ...layout,\n contentExtent(container, children) {\n const reach = shelve(container.bounds, readingOrder(children))?.height ?? 0;\n return { ...container.bounds, height: Math.max(container.bounds.height, reach) };\n },\n };\n}\n","import type { Rect } from '@weasel-js/geom';\nimport {\n createTransformOp,\n type ContainerBounds,\n type LayoutChild,\n type LayoutContainer,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport { containedThenNearest } from '../snaps';\nimport { defaultCenterOf } from './sequence';\n\n\n/** Options for `quadtree`. */\nexport interface QuadtreeOptions<TPose> {\n /** How many times the container may be quartered. Default 4, a 16 × 16 grid at its finest. */\n maxDepth?: number;\n /** Which free cell a drag means. Default `containedThenNearest()`. */\n snap?: LayoutSnap<TPose>;\n /** The length a cell's shorter side must reach to hold the child. Default\n * is the larger of the pose's `width` and `height`. */\n sizeOf?(pose: TPose): number;\n /** The pose a child takes in a cell. Default centers the child's own size\n * in the cell and keeps every other field. */\n cellToPose?(cell: Rect, pose: TPose): TPose;\n /** The point that decides which cell a child sits in. Default is the\n * center of a `RectPose`, and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\n/** One cell a child holds: {@link QuadtreeStrategy.cells}. */\nexport interface QuadtreeCell {\n id: string;\n /** How many times the container was quartered to reach the cell. */\n depth: number;\n rect: Rect;\n}\n\n/** A `quadtree` layout, which also reports the cells it has given out. */\nexport interface QuadtreeStrategy<TPose> extends LayoutStrategy<TPose> {\n /** The cell each child holds, largest first: what a debug overlay draws. */\n cells(container: LayoutContainer, children: ReadonlyArray<LayoutChild<TPose>>): QuadtreeCell[];\n}\n\ninterface Cell {\n depth: number;\n col: number;\n row: number;\n}\n\n/** Whether one cell is the other, or holds it. */\nfunction overlaps(a: Cell, b: Cell): boolean {\n const [outer, inner] = a.depth <= b.depth ? [a, b] : [b, a];\n const shift = inner.depth - outer.depth;\n return inner.col >> shift === outer.col && inner.row >> shift === outer.row;\n}\n\nfunction rectOf(bounds: ContainerBounds, cell: Cell): Rect {\n const width = bounds.width / 2 ** cell.depth;\n const height = bounds.height / 2 ** cell.depth;\n return { x: bounds.x + cell.col * width, y: bounds.y + cell.row * height, width, height }\n};\n\n/** The free cell at `depth` nearest `at`: the one holding it, if that is free. */\nfunction freeCell(bounds: ContainerBounds, taken: readonly Cell[], depth: number, at: { x: number; y: number }): Cell | null {\n let best: Cell | null = null;\n let bestD = Infinity;\n for (const cell of freeCells(taken, depth)) {\n const r = rectOf(bounds, cell);\n const d = (r.x + r.width / 2 - at.x) ** 2 + (r.y + r.height / 2 - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = cell;\n }\n }\n return best;\n}\n\nfunction freeCells(taken: readonly Cell[], depth: number): Cell[] {\n const out: Cell[] = [];\n const n = 2 ** depth;\n for (let row = 0; row < n; row++) {\n for (let col = 0; col < n; col++) {\n const cell = { depth, col, row };\n if (!taken.some((t) => overlaps(t, cell))) out.push(cell);\n }\n }\n return out;\n}\n\nfunction defaultCellToPose<TPose>(cell: Rect, pose: TPose): TPose {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return {\n ...(pose as object),\n x: cell.x + (cell.width - width) / 2,\n y: cell.y + (cell.height - height) / 2,\n } as TPose;\n}\n\n/**\n * Layout strategy that quarters its container as far as each child needs: a\n * child holds the smallest cell that fits it, so large and small children\n * share one container without a fixed grid. A cell is free while it, the\n * cells it sits inside, and the cells inside it hold nobody.\n *\n * A drag is offered the free cells of its own size. Children never move to\n * make room: a child that finds its cell covered goes to the nearest free\n * one, and an arrival with no free cell of its size is refused.\n */\nexport function quadtree<TPose>(opts: QuadtreeOptions<TPose> = {}): QuadtreeStrategy<TPose> {\n const maxDepth = opts.maxDepth ?? 4;\n const snap = opts.snap ?? containedThenNearest<TPose>();\n const cellToPose = opts.cellToPose ?? defaultCellToPose;\n const centerOf = opts.centerOf ?? defaultCenterOf;\n const sizeOf =\n opts.sizeOf ??\n ((pose: TPose) => {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return Math.max(width, height);\n });\n\n /** The deepest level whose cells still hold a child of this pose. */\n function depthOf(bounds: ContainerBounds, pose: TPose): number {\n const size = sizeOf(pose);\n const side = Math.min(bounds.width, bounds.height);\n let depth = 0;\n while (depth < maxDepth && side / 2 ** (depth + 1) >= size) depth++;\n return depth;\n }\n\n /** A cell for every child that finds one, larger children first so a small\n * one never takes the corner of a cell a large one needs whole. */\n function assign(bounds: ContainerBounds, children: ReadonlyArray<LayoutChild<TPose>>, held: readonly Cell[] = []) {\n const taken = [...held];\n const cells = new Map<string, Cell>();\n const bySize = children\n .map((c) => ({ c, depth: depthOf(bounds, c.pose) }))\n .sort((a, b) => a.depth - b.depth || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0));\n for (const { c, depth } of bySize) {\n const cell = freeCell(bounds, taken, depth, centerOf(c.pose));\n if (!cell) continue;\n taken.push(cell);\n cells.set(c.id, cell);\n }\n return { cells, taken };\n }\n\n return {\n snap,\n\n childPoses(container, children) {\n const { cells } = assign(container.bounds, children);\n return new Map(\n children.map((c) => {\n const cell = cells.get(c.id);\n return [c.id, cell ? cellToPose(rectOf(container.bounds, cell), c.pose) : c.pose];\n }),\n );\n },\n\n getDropTargets(container, children, dragged) {\n const { taken } = assign(container.bounds, children.filter((c) => c.id !== dragged.id));\n return freeCells(taken, depthOf(container.bounds, dragged.pose)).map((cell) => {\n const hitBounds = rectOf(container.bounds, cell);\n return {\n pose: cellToPose(hitBounds, dragged.pose),\n origin: { x: hitBounds.x + hitBounds.width / 2, y: hitBounds.y + hitBounds.height / 2 },\n hitBounds,\n };\n });\n },\n\n reflowPoses: () => new Map(),\n\n commitDrop: (_container, _children, dragged, target) => [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: 'Quadtree drop',\n }),\n ],\n\n arrive(container, children, arrivals) {\n const { taken } = assign(container.bounds, children.filter((c) => !arrivals.has(c.id)));\n const joining = children.filter((c) => arrivals.has(c.id));\n const { cells } = assign(container.bounds, joining, taken);\n if (cells.size < joining.length) return null;\n return {\n poses: new Map(joining.map((c) => [c.id, cellToPose(rectOf(container.bounds, cells.get(c.id)!), c.pose)])),\n };\n },\n\n cells(container, children) {\n const { cells } = assign(container.bounds, children);\n return [...cells]\n .map(([id, cell]) => ({ id, depth: cell.depth, rect: rectOf(container.bounds, cell) }))\n .sort((a, b) => a.depth - b.depth || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));\n },\n };\n}\n","import type { ContainerBounds } from '@weasel-js/core';\n\n/** One place a child's center goes. */\nexport interface Slot {\n x: number;\n y: number;\n /** The direction the slot faces, in radians, where the arrangement has one\n * — outward from the center on a ring. `slotToPose` decides what to do\n * with it; the default ignores it. */\n angle?: number;\n}\n\n/**\n * Where a container's slots are when it holds `count` children, in fill\n * order. Returning fewer than `count` caps the container: `slots` refuses\n * whatever would not fit.\n */\nexport type Arrangement = (bounds: ContainerBounds, count: number) => Slot[];\n\n/** Options for `rowSlots`. */\nexport interface RowSlotsOptions {\n /** The axis the row runs along. Default `'x'`. */\n axis?: 'x' | 'y';\n /** Distance between neighboring slots, in world units, the row centered in\n * the container. Absent, the slots divide the container's length evenly. */\n pitch?: number;\n}\n\n/** Slots in a line, centered across the container. */\nexport function rowSlots(opts: RowSlotsOptions = {}): Arrangement {\n const alongX = opts.axis !== 'y';\n return (bounds, count) => {\n const length = alongX ? bounds.width : bounds.height;\n const pitch = opts.pitch ?? length / Math.max(count, 1);\n const first = length / 2 - (pitch * (count - 1)) / 2;\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n const along = first + i * pitch;\n out.push(\n alongX\n ? { x: bounds.x + along, y: bounds.y + bounds.height / 2 }\n : { x: bounds.x + bounds.width / 2, y: bounds.y + along },\n );\n }\n return out;\n };\n}\n\n/** Options for `gridSlots`. */\nexport interface GridSlotsOptions {\n cols: number;\n /** Rows the grid has before any child needs one. Default 1. */\n rows?: number;\n}\n\n/** Slots at the centers of a grid that fills row by row, adding a row when the\n * last fills; the rows always divide the container's height. */\nexport function gridSlots(opts: GridSlotsOptions): Arrangement {\n return (bounds, count) => {\n const rows = Math.max(opts.rows ?? 1, Math.ceil(count / opts.cols));\n const cw = bounds.width / opts.cols;\n const ch = bounds.height / rows;\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n out.push({\n x: bounds.x + ((i % opts.cols) + 0.5) * cw,\n y: bounds.y + (Math.floor(i / opts.cols) + 0.5) * ch,\n });\n }\n return out;\n };\n}\n\n/** Options for `ringSlots`. */\nexport interface RingSlotsOptions {\n /** Angle of the first slot, in radians, 0 pointing along +x and positive\n * turning toward +y. Default −π/2: the top, on a y-down canvas. */\n start?: number;\n /** How far round the slots run. Default a full turn, which spaces them\n * evenly; anything less puts a slot on each end of the arc. */\n sweep?: number;\n /** Distance to pull the ring in from the container's edges. Default 0. */\n inset?: number;\n}\n\n/** Slots around the ellipse inscribed in the container, each facing outward. */\nexport function ringSlots(opts: RingSlotsOptions = {}): Arrangement {\n const start = opts.start ?? -Math.PI / 2;\n const sweep = opts.sweep ?? Math.PI * 2;\n const inset = opts.inset ?? 0;\n const closed = Math.abs(sweep) >= Math.PI * 2;\n return (bounds, count) => {\n const rx = bounds.width / 2 - inset;\n const ry = bounds.height / 2 - inset;\n const steps = closed ? count : Math.max(count - 1, 1);\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n const angle = start + (sweep * i) / steps;\n out.push({\n x: bounds.x + bounds.width / 2 + rx * Math.cos(angle),\n y: bounds.y + bounds.height / 2 + ry * Math.sin(angle),\n angle,\n });\n }\n return out;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/grid/roundToCell.ts","../src/grid/axes.ts","../src/grid/lattice.ts","../src/grid/reading.ts","../src/grid/regions.ts","../src/grid/pointToGridCell.ts","../src/grid/useGridCellHover.ts","../src/grid/layer.ts","../src/grid/cellHighlight.ts","../src/grid/fit.ts","../src/sources/lines.ts","../src/sources/grid.ts","../src/grid/preset.ts","../src/guides/useGuides.ts","../src/guides/layer.ts","../src/guides/alignment/derive.ts","../src/guides/alignment/spacing.ts","../src/guides/alignment/sceneBounds.ts","../src/strategies/onPlane.ts","../src/sources/guides.ts","../src/guides/alignment/match.ts","../src/sources/targets.ts","../src/sources/alignment.ts","../src/sources/spacing.ts","../src/spacingHints/distance.ts","../src/spacingHints/distanceReadout.ts","../src/spacingHints/preset.ts","../src/layout/snaps.ts","../src/layout/perContainer.ts","../src/layout/strategies/freeform.ts","../src/layout/strategies/tileGrid.ts","../src/layout/strategies/snapPoint.ts","../src/layout/strategies/sequence.ts","../src/layout/strategies/slots.ts","../src/layout/strategies/pack.ts","../src/layout/strategies/quadtree.ts","../src/layout/strategies/arrangements.ts"],"names":["lo","hi","mid","span","periodic","cell","applyToPoint","PATH_M","PATH_L","box","invert","viewportWorldRect","mat3","sceneUnitScopes","useState","useLatest","useCallback","EPS","AUTO_POSE_DESCRIPTOR","scenePoseFrame","visualBoundsViaDescriptor","nodeGates","cross","asNodeId","at","sceneMagnification","pack","createTransformOp","slots","defaultCenterOf","rectOf"],"mappings":";;;;;AACO,SAAS,WAAA,CAAY,OAAe,QAAA,EAA0B;AACnE,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,KAAA,GAAQ,QAAQ,IAAI,QAAA,IAAY,CAAA;AACpD;;;AC4BO,SAAS,aAAa,CAAA,EAA6B;AACxD,EAAA,OAAO,OAAO,MAAM,QAAA,IAAa,OAAO,MAAM,QAAA,IAAY,CAAA,KAAM,QAAQ,OAAA,IAAW,CAAA;AACrF;AAGO,SAAS,gBAAA,CAAiB,SAAsB,IAAA,EAAwD;AAC7G,EAAA,MAAM,EAAA,GAAK,CAAC,IAAA,KAAiC;AAC3C,IAAA,MAAM,IAAI,YAAA,CAAa,OAAO,CAAA,GAAI,OAAA,GAAU,QAAQ,IAAI,CAAA;AACxD,IAAA,IAAI,CAAA,KAAM,QAAW,OAAO,IAAA;AAC5B,IAAA,IAAI;AACF,MAAA,OAAO,YAAY,CAAA,EAAG,CAAC,MAAM,IAAA,CAAK,CAAA,EAAG,IAAI,CAAC,CAAA;AAAA,IAC5C,SAAS,CAAA,EA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MAAM,EAAA,GAAK,MAAA,CAAO,MAAA,GAAS,CAAA,GAAI,KAAA;AAC/B,IAAA,MAAM,QAAQ,MAAA,GAAS,KAAA,GAAQ,KAAK,GAAA,CAAI,KAAA,GAAQ,GAAG,CAAC,CAAA;AACpD,IAAA,MAAM,MAAc,EAAC;AACrB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,EAAO,CAAA,EAAA,EAAK;AAC9B,MAAA,MAAM,KAAA,GAAQ,KAAA,GAAS,KAAA,GAAQ,CAAA,GAAK,KAAA;AACpC,MAAA,GAAA,CAAI,IAAA,CAAK;AAAA,QACP,CAAA,EAAG,OAAO,CAAA,GAAI,MAAA,CAAO,QAAQ,CAAA,GAAI,EAAA,GAAK,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA;AAAA,QACpD,CAAA,EAAG,OAAO,CAAA,GAAI,MAAA,CAAO,SAAS,CAAA,GAAI,EAAA,GAAK,IAAA,CAAK,GAAA,CAAI,KAAK,CAAA;AAAA,QACrD;AAAA,OACD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["/** Round `value` to the nearest multiple of `cellSize`. Returns 0 when the result would be -0. */\nexport function roundToCell(value: number, cellSize: number): number {\n return Math.round(value / cellSize) * cellSize || 0;\n}\n","import type { PerAxis, PlaneValue } from '@weasel-js/core';\n\n/** A length on a grid: a bare number, or a value tagged with a unit. */\nexport type GridLength = Exclude<PlaneValue, PerAxis<unknown>>;\n\n/**\n * One axis of a grid: a pitch from zero; a pitch with an `offset` its lines\n * pass through, limited to `from`..`to` (inclusive); or lines at explicit\n * positions, for uneven bays. Positions are measured from the grid's origin:\n * a container's corner, or the root's origin. A pitch that is not a positive\n * finite number gives the axis no lines.\n */\nexport type GridAxis =\n | GridLength\n | { pitch: GridLength; offset?: GridLength; from?: GridLength; to?: GridLength }\n | { at: readonly GridLength[] };\n\n/** A grid's lines: one rule for both axes, or one per axis. An axis left out\n * has no lines: it draws none and nothing snaps on it. */\nexport type GridSpacing = GridLength | { x?: GridAxis; y?: GridAxis };\n\n/** An axis's lines, resolved to numbers in the space the grid runs in. */\nexport type AxisLines =\n | { pitch: number; offset: number; from: number; to: number }\n | { at: readonly number[] };\n\n/** A grid's lines on each axis, `null` where it has none. */\nexport type GridLines = PerAxis<AxisLines | null>;\n\ntype Axis = 'x' | 'y';\n\nexport function isGridLength(v: unknown): v is GridLength {\n return typeof v === 'number' || (typeof v === 'object' && v !== null && 'value' in v);\n}\n\n/** `spacing`'s lines, each length read by `read` for its axis. */\nexport function resolveGridLines(spacing: GridSpacing, read: (v: GridLength, axis: Axis) => number): GridLines {\n const on = (axis: Axis): AxisLines | null => {\n const a = isGridLength(spacing) ? spacing : spacing[axis];\n if (a === undefined) return null;\n try {\n return resolveAxis(a, (v) => read(v, axis));\n } catch (e) {\n throw new Error(`${axis} axis: ${e instanceof Error ? e.message : String(e)}`);\n }\n };\n return { x: on('x'), y: on('y') };\n}\n\nfunction resolveAxis(a: GridAxis, read: (v: GridLength) => number): AxisLines | null {\n if (isGridLength(a)) return periodic(read(a), 0, -Infinity, Infinity);\n if ('at' in a) {\n const at = [...new Set(a.at.map(read))].filter(Number.isFinite).sort((p, q) => p - q);\n return at.length ? { at } : null;\n }\n return periodic(\n read(a.pitch),\n a.offset === undefined ? 0 : read(a.offset),\n a.from === undefined ? -Infinity : read(a.from),\n a.to === undefined ? Infinity : read(a.to),\n );\n}\n\nfunction periodic(pitch: number, offset: number, from: number, to: number): AxisLines | null {\n return pitch > 0 && Number.isFinite(pitch) && from <= to ? { pitch, offset, from, to } : null;\n}\n\nconst EPS = 1e-9;\n\n/** The first and last index `k` of `offset + k * pitch` inside the range. */\nfunction indexRange(a: { pitch: number; offset: number; from: number; to: number }): [number, number] {\n return [Math.ceil((a.from - a.offset) / a.pitch - EPS), Math.floor((a.to - a.offset) / a.pitch + EPS)];\n}\n\n/** The line at or before `v` and the one after it, nearer first, the upper\n * on a tie; at an end of the lines, the two nearest. Empty where the axis\n * has no line. */\nexport function linesNear(a: AxisLines, v: number): number[] {\n let pair: number[];\n if ('at' in a) {\n const i = Math.min(Math.max(0, lastAtOrBefore(a.at, v)), Math.max(0, a.at.length - 2));\n pair = a.at.slice(i, i + 2);\n } else {\n const [lo, hi] = indexRange(a);\n if (lo > hi) return [];\n const k = Math.min(Math.max(Math.floor((v - a.offset) / a.pitch), lo), Math.max(lo, hi - 1));\n pair = k + 1 <= hi ? [a.offset + k * a.pitch, a.offset + (k + 1) * a.pitch] : [a.offset + k * a.pitch];\n }\n return pair.length === 2 && v - pair[0]! >= pair[1]! - v ? [pair[1]!, pair[0]!] : pair;\n}\n\n/** The line nearest `v`, or `null` where the axis has none. */\nexport function nearestLine(a: AxisLines, v: number): number | null {\n let best: number | null = null;\n for (const l of linesNear(a, v)) if (best === null || Math.abs(l - v) < Math.abs(best - v)) best = l;\n return best;\n}\n\n/** Every line from `lo` to `hi`, in order. The caller bounds how many a\n * pitch gives over the span. */\nexport function linesIn(a: AxisLines, lo: number, hi: number): number[] {\n if ('at' in a) return a.at.filter((l) => l >= lo - EPS && l <= hi + EPS);\n const [k0, k1] = indexRange({ ...a, from: Math.max(a.from, lo), to: Math.min(a.to, hi) });\n const out: number[] = [];\n for (let k = k0; k <= k1; k++) out.push(a.offset + k * a.pitch);\n return out;\n}\n\n/** The cell holding `v`: the gap between two adjacent lines, numbered from\n * the line through the offset (or the first explicit line). An axis with\n * no lines is one cell, `0`, without end. `null` outside the lines. */\nexport function cellOf(a: AxisLines | null, v: number): { index: number; lo: number; hi: number } | null {\n if (!a) return { index: 0, lo: -Infinity, hi: Infinity };\n if ('at' in a) {\n const i = lastAtOrBefore(a.at, v);\n return i >= 0 && i < a.at.length - 1 ? { index: i, lo: a.at[i]!, hi: a.at[i + 1]! } : null;\n }\n const [lo, hi] = indexRange(a);\n const k = Math.floor((v - a.offset) / a.pitch);\n if (k < lo || k >= hi) return null;\n return { index: k, lo: a.offset + k * a.pitch, hi: a.offset + (k + 1) * a.pitch };\n}\n\n/** `a` with every position `p` moved to `p * scale + shift`. */\nexport function mapLines(a: AxisLines, scale: number, shift: number): AxisLines {\n const m = (p: number) => p * scale + shift;\n if ('at' in a) return { at: a.at.map(m).sort((p, q) => p - q) };\n const [from, to] = [m(a.from), m(a.to)].sort((p, q) => p - q) as [number, number];\n return { pitch: Math.abs(a.pitch * scale), offset: m(a.offset), from: Number.isNaN(from) ? -Infinity : from, to: Number.isNaN(to) ? Infinity : to };\n}\n\nfunction lastAtOrBefore(at: readonly number[], v: number): number {\n let lo = 0;\n let hi = at.length - 1;\n let found = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (at[mid]! <= v + EPS) {\n found = mid;\n lo = mid + 1;\n } else hi = mid - 1;\n }\n return found;\n}\n","import { resolveStrokeWidth, type CommandStroke, type DrawCommand, type View } from '@weasel-js/core';\nimport { PATH_L, PATH_M, pxExtent, pxExtentInFrame, type Affine, type PolygonPath } from '@weasel-js/geom';\nimport { linesIn, type AxisLines, type GridLines } from './axes';\n\n/** An axis-aligned rectangle, in whatever coordinates a lattice is drawn in. */\nexport type Rect = { x: number; y: number; width: number; height: number };\ntype Point = { x: number; y: number };\n\n/** The strokes of a lattice's three line families. */\nexport type LatticeStyles = { line: CommandStroke; accent: CommandStroke; sub: CommandStroke };\n\n/** How a lattice divides: accents every N cells, sub-lines per cell. Both\n * apply only to an axis with a pitch. */\nexport interface LatticeShape {\n accentEvery?: number | undefined;\n subdivisions?: number | undefined;\n}\n\n/** Closest, in CSS pixels, a line family is drawn; denser ones are left out. */\nconst MIN_SCREEN_SPACING = 4;\n\n// Written so a non-finite extent, which a zero view scale gives, fails it too.\nexport function hasArea(r: Rect): boolean {\n return r.width > 0 && r.height > 0 && Number.isFinite(r.width) && Number.isFinite(r.height);\n}\n\ntype Axis = 'x' | 'y';\nconst other = (axis: Axis): Axis => (axis === 'x' ? 'y' : 'x');\n\n/**\n * The lines of `lines` inside `b`: sub-lines, cell lines and accents. `b` is\n * in `frame`'s coordinates, which `frame` carries to world; absent, it is\n * world. A line runs across `b`, or across the other axis's range where its\n * pitch is limited to one. Lines are a screen pixel wide either way.\n */\nexport function lattice(\n b: Rect, lines: GridLines, shape: LatticeShape, view: View, styles: LatticeStyles, frame?: Affine,\n): DrawCommand[] {\n // Every line runs along one of the lattice's axes, so its width runs along\n // the other, and one pixel of it is that axis's extent.\n const px = frame ? pxExtentInFrame(1, view.scale, frame) : pxExtent(1, view.scale);\n const span = { x: [b.x, b.x + b.width] as const, y: [b.y, b.y + b.height] as const };\n const children: DrawCommand[] = [];\n\n // The stretch of `axis` a line across it covers.\n const across = (axis: Axis): [number, number] => {\n const a = lines[axis];\n const [lo, hi] = span[axis];\n return a && 'pitch' in a ? [Math.max(lo, a.from), Math.min(hi, a.to)] : [lo, hi];\n };\n\n const draw = (axis: Axis, at: readonly number[], s: CommandStroke): void => {\n const [lo, hi] = across(other(axis));\n if (!(hi > lo)) return;\n const width = resolveStrokeWidth(s.width ?? 1, 1) * px[axis];\n for (const p of at) {\n const coords = axis === 'x' ? [p, lo, p, hi] : [lo, p, hi, p];\n const path: PolygonPath = {\n kind: 'polygon', commands: new Uint8Array([PATH_M, PATH_L]), coords: new Float32Array(coords), fillRule: 'nonzero',\n };\n children.push({ kind: 'path', path, stroke: { ...s, width } });\n }\n };\n\n // A pitch's lines `every`-th apart, leaving out each `skipEvery`-th (the\n // ones a coarser family draws), and none once they would sit closer than\n // MIN_SCREEN_SPACING on screen.\n const periodic = (axis: Axis, a: Extract<AxisLines, { pitch: number }>, step: number, skipEvery: number, s: CommandStroke) => {\n if (!(step / px[axis] >= MIN_SCREEN_SPACING)) return;\n const at = linesIn({ ...a, pitch: step }, ...span[axis]);\n draw(axis, skipEvery > 0 ? at.filter((p) => Math.round((p - a.offset) / step) % skipEvery !== 0) : at, s);\n };\n\n const { accentEvery, subdivisions } = shape;\n const accentOn = accentEvery !== undefined && accentEvery > 0;\n const passes: ((axis: Axis, a: Extract<AxisLines, { pitch: number }>) => void)[] = [\n // Sub-lines first so cell lines paint on top, accents last of all.\n (axis, a) => { if (subdivisions && subdivisions > 1) periodic(axis, a, a.pitch / subdivisions, subdivisions, styles.sub); },\n (axis, a) => periodic(axis, a, a.pitch, accentOn ? accentEvery : 0, styles.line),\n (axis, a) => { if (accentOn) periodic(axis, a, a.pitch * accentEvery, 0, styles.accent); },\n ];\n for (const pass of passes) {\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (a && 'pitch' in a) pass(axis, a);\n }\n }\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (a && 'at' in a) draw(axis, thinned(linesIn(a, ...span[axis]), px[axis] * MIN_SCREEN_SPACING), styles.line);\n }\n return children;\n}\n\n/** `at` (ascending) less each line closer than `gap` to the last one kept. */\nfunction thinned(at: readonly number[], gap: number): number[] {\n const out: number[] = [];\n for (const p of at) if (out.length === 0 || p - out[out.length - 1]! >= gap) out.push(p);\n return out;\n}\n\n/** The axis-aligned box around `outline`. */\nexport function outlineBox(outline: readonly Point[]): Rect {\n const xs = outline.map((p) => p.x);\n const ys = outline.map((p) => p.y);\n const x = Math.min(...xs);\n const y = Math.min(...ys);\n return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };\n}\n\n/** Where `a` and `b` overlap; no area where they don't. */\nexport function intersect(a: Rect, b: Rect): Rect {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n return { x, y, width: Math.min(end(a.x, a.width), end(b.x, b.width)) - x, height: Math.min(end(a.y, a.height), end(b.y, b.height)) - y };\n}\n\n// A rect without end on an axis starts at -Infinity and is Infinity wide, which do not sum.\nconst end = (start: number, size: number): number => (size === Infinity ? Infinity : start + size);\n","import {\n axisUnits, resolveScoped, resolveUnit, type PlaneUnits, type UnitScope,\n} from '@weasel-js/core';\nimport { resolveGridLines, type GridLength, type GridLines, type GridSpacing } from './axes';\n\n/** How a grid reads the unit scopes a scene's containers declare\n * (`GroupNode.units`). */\nexport interface GridScopes {\n /** The scene's outermost scope, as `sceneUnitScopes` is handed it. The grid's\n * `spacing` is read in its system, in place of `unitSystem`. */\n root: UnitScope;\n /** The grid inside a container's scope, written in that scope's units.\n * Default: the grid's `spacing`, read there, so a bare 10 is ten of its\n * base units. */\n spacing?: (scope: UnitScope) => GridSpacing;\n}\n\n/** A length in `chain`'s innermost units, in world units. Grid lengths are\n * measured from the grid's origin, so a unit that disagrees about zero\n * moves them nowhere. */\nfunction span(v: GridLength, chain: readonly UnitScope[]): number {\n const zero = typeof v === 'number' ? 0 : { ...v, value: 0 };\n return resolveScoped(v, chain) - resolveScoped(zero, chain);\n}\n\n/**\n * A grid's lines in world units: read in `chain` (the root alone by default)\n * when `scopes` is given, else against `unitSystem`. What every grid reader\n * that takes both asks.\n */\nexport function gridLines(\n spacing: GridSpacing,\n unitSystem: PlaneUnits | undefined,\n scopes: GridScopes | undefined,\n chain?: readonly UnitScope[],\n): GridLines {\n if (!scopes) return resolveGridLines(spacing, (v, axis) => resolveUnit(v, axisUnits(unitSystem, axis)));\n const at = chain ?? [scopes.root];\n return resolveGridLines(spacing, (v) => span(v, at));\n}\n\n/** The grid a container whose scopes are `chain` runs when nothing gives it\n * one of its own: `scopes.spacing` of its innermost scope, else `spacing`. */\nfunction scopeSpacing(\n spacing: GridSpacing, scopes: GridScopes | undefined, chain: readonly UnitScope[] | undefined,\n): GridSpacing {\n const inner = chain && chain.length > 1 ? chain[chain.length - 1]! : null;\n return inner && scopes?.spacing ? scopes.spacing(inner) : spacing;\n}\n\n/** A container's lattice in its own coordinates: its `own` grid (`gridOf`;\n * `null` for none), else the one its scope gives, read in `chain`. */\nexport function containerLines(\n own: GridSpacing | null | undefined,\n spacing: GridSpacing,\n unitSystem: PlaneUnits | undefined,\n scopes: GridScopes | undefined,\n chain: readonly UnitScope[] | undefined,\n): GridLines | null {\n if (own === null) return null;\n return gridLines(own ?? scopeSpacing(spacing, scopes, chain), unitSystem, scopes, chain);\n}\n","import {\n sceneBoxFrames, scenePoseFrame, sceneUnitScopes, type NodeId, type Scene, type ScopedScene, type UnitScope,\n} from '@weasel-js/core';\nimport { applyToPoint, pointInPolygon, type Affine } from '@weasel-js/geom';\nimport type { GridSpacing } from './axes';\n\ntype Point = { x: number; y: number };\n\n/** Which of a scene's containers run a grid of their own. */\nexport interface GridOwners {\n /** The scene's outermost unit scope: given, every container declaring a\n * scope (`GroupNode.units`) runs that scope's lattice, and lengths inside\n * a container are read in its scope. */\n root?: UnitScope;\n /** A container's own grid: `undefined` to leave it to the container's\n * parent, `null` for no grid inside it at all. Its children snap on it,\n * in the container's frame. */\n gridOf?: (id: NodeId) => GridSpacing | null | undefined;\n}\n\n/** A container running its own lattice, where a grid draws and hit-tests it\n * instead of its parent's. */\nexport interface GridRegion {\n /** The container's outline in world units, as a closed polygon. */\n outline: readonly Point[];\n /** The scopes its lattice is read in, outermost first, rooted at\n * `GridOwners.root`, the container's own scope last. Absent without one. */\n chain?: readonly UnitScope[];\n /** Its own grid, from `gridOf`: `null` for none. Absent, it runs the grid's\n * `spacing`, or its scope's (`GridScopes.spacing`). */\n spacing?: GridSpacing | null;\n /** Containers inside this one running their own. */\n regions?: readonly GridRegion[];\n /** The container's frame, its own coordinates to world (`sceneBoxFrames`):\n * its lattice runs from the frame's origin along its axes, in its units,\n * as `gridSnapSource` snaps. Absent, the lattice is world-aligned and runs\n * through the grid's anchor. */\n frame?: Affine;\n}\n\n/**\n * Every container in `scene` running its own grid, as `GridRegion`s nested\n * the way the containers are, each in its box frame. `outlineOf` gives a\n * node's world outline, or `null` to leave it, and every region inside it,\n * out; by default, a box pose's outline as it is drawn, and none for any\n * other pose.\n */\nexport function sceneGridRegions(\n scene: Scene<unknown, string, unknown>,\n owners: GridOwners,\n outlineOf?: (id: NodeId) => readonly Point[] | null,\n): GridRegion[] {\n const frames = sceneBoxFrames(scene);\n const poses = scenePoseFrame(scene);\n const boxOutline = (id: NodeId, frame: Affine): Point[] => {\n const { width, height } = poses.world(id) as { width: number; height: number };\n return [[0, 0], [width, 0], [width, height], [0, height]].map(([x, y]) => {\n const [wx, wy] = applyToPoint(frame, x!, y!);\n return { x: wx, y: wy };\n });\n };\n const children = new Map<NodeId | null, NodeId[]>();\n for (const id of scene.nodes.keys()) {\n if (!ownsGrid(scene, id, owners)) continue;\n const parent = gridOwner(scene, id, owners);\n children.set(parent, [...(children.get(parent) ?? []), id]);\n }\n const build = (parent: NodeId | null): GridRegion[] => {\n const out: GridRegion[] = [];\n for (const id of children.get(parent) ?? []) {\n const frame = frames(id);\n const outline = outlineOf ? outlineOf(id) : frame && boxOutline(id, frame);\n if (!outline) continue;\n const inner = build(id);\n const own = owners.gridOf?.(id);\n out.push({\n outline,\n ...(owners.root ? { chain: sceneUnitScopes(scene, id, owners.root, { inclusive: true }) } : {}),\n ...(own !== undefined ? { spacing: own } : {}),\n ...(inner.length ? { regions: inner } : {}),\n ...(frame ? { frame } : {}),\n });\n }\n return out;\n };\n return build(null);\n}\n\nfunction ownsGrid(scene: ScopedScene, id: NodeId, owners: GridOwners): boolean {\n return owners.gridOf?.(id) !== undefined || (owners.root !== undefined && scene.get(id)?.units !== undefined);\n}\n\n/** The nearest container above `id` running its own grid, or `null` for the\n * root's: whose lattice `id` sits on. `inclusive` counts `id` itself. */\nexport function gridOwner(scene: ScopedScene, id: NodeId, owners: GridOwners, inclusive = false): NodeId | null {\n for (let at = inclusive ? id : scene.get(id)?.parent ?? null; at !== null; at = scene.get(at)?.parent ?? null) {\n if (ownsGrid(scene, at, owners)) return at;\n }\n return null;\n}\n\n/** The innermost region holding `point`, or `null` outside them all. */\nexport function regionAt(regions: readonly GridRegion[] | undefined, point: Point): GridRegion | null {\n for (const r of regions ?? []) {\n const flat = r.outline.flatMap((p) => [p.x, p.y]);\n if (pointInPolygon(flat, point.x, point.y)) return regionAt(r.regions, point) ?? r;\n }\n return null;\n}\n","import type { PlaneUnits } from '@weasel-js/core';\nimport { applyToPoint, invert, type Affine } from '@weasel-js/geom';\nimport { cellOf, type GridLines, type GridSpacing } from './axes';\nimport { outlineBox, type Rect } from './lattice';\nimport { containerLines, gridLines, type GridScopes } from './reading';\nimport { regionAt, type GridRegion } from './regions';\n\n/** A cell of a grid: the gap between two adjacent lines on each axis,\n * numbered from the line through each axis's offset (or its first explicit\n * line). `box` is the cell in the grid's space: world, or `frame`'s, the\n * frame of the region whose lattice it is on. An axis with no lines is one\n * cell, `0`, spanning the region, or without end at the root. */\nexport interface GridCell {\n col: number;\n row: number;\n box: Rect;\n frame?: Affine;\n}\n\n/** Where a grid's containers run lattices of their own: the unit `scopes`\n * it reads, and the `regions` (`sceneGridRegions`) running them. */\nexport interface GridScoping {\n scopes?: GridScopes;\n regions?: readonly GridRegion[];\n}\n\n/**\n * The cell holding `point`, on the lattice of the innermost region holding\n * it, else the root's, which runs through `origin`. Pair with\n * `createCellHighlightLayer` (its `getCell` callback) to draw a snap-target\n * preview on the lattice `gridSnapSource` snaps to. `null` where `point` is\n * outside the lines: past a range a pitch is limited to, or the explicit\n * lines, or in a region with no grid.\n */\nexport function pointToGridCell(\n point: { x: number; y: number },\n spacing: GridSpacing,\n unitSystem?: PlaneUnits,\n origin: { x: number; y: number } = { x: 0, y: 0 },\n scoped?: GridScoping,\n): GridCell | null {\n const region = regionAt(scoped?.regions, point);\n if (!region) {\n const cell = cellIn(gridLines(spacing, unitSystem, scoped?.scopes), point.x - origin.x, point.y - origin.y);\n return cell && { ...cell, box: { ...cell.box, x: cell.box.x + origin.x, y: cell.box.y + origin.y } };\n }\n const lines = containerLines(region.spacing, spacing, unitSystem, scoped?.scopes, region.chain);\n if (!lines) return null;\n const back = region.frame && invert(region.frame);\n if (region.frame && !back) return null;\n const local = (p: { x: number; y: number }) => {\n if (!back) return p;\n const [x, y] = applyToPoint(back, p.x, p.y);\n return { x, y };\n };\n const at = local(point);\n const cell = cellIn(lines, at.x, at.y, outlineBox(region.outline.map(local)));\n return cell && (region.frame ? { ...cell, frame: region.frame } : cell);\n}\n\nfunction cellIn(lines: GridLines, x: number, y: number, within?: Rect): Omit<GridCell, 'frame'> | null {\n const cx = cellOf(lines.x, x);\n const cy = cellOf(lines.y, y);\n if (!cx || !cy) return null;\n const [x0, x1] = within && !lines.x ? [within.x, within.x + within.width] : [cx.lo, cx.hi];\n const [y0, y1] = within && !lines.y ? [within.y, within.y + within.height] : [cy.lo, cy.hi];\n return { col: cx.index, row: cy.index, box: { x: x0, y: y0, width: x1 - x0, height: y1 - y0 } };\n}\n","/**\n * Pointer-tracking glue that turns hover position into a grid cell, suitable\n * for dropping straight into `createCellHighlightLayer({ getCell })`.\n *\n * State updates only fire when the cell actually changes (not on every\n * pointer tick). Pass `onChange` to trigger a canvas redraw on each transition.\n */\n\nimport { useCallback, useEffect, useRef, useState, type RefObject } from 'react';\nimport {\n useLatest,\n screenToWorld,\n type ViewTransform,\n type PlaneUnits,\n} from '@weasel-js/core';\nimport type { GridSpacing } from './axes';\nimport { pointToGridCell, type GridCell } from './pointToGridCell';\nimport type { GridRegion } from './regions';\nimport type { GridScopes } from './reading';\n\n/** Options for `useGridCellHover`. */\nexport interface UseGridCellHoverOptions {\n /** Element to attach pointer listeners to (typically the canvas). */\n ref: RefObject<HTMLElement | null>;\n /** Read the current view transform. Called on every pointermove so it can\n * reflect live pan/zoom without a re-binding step. */\n view: () => ViewTransform;\n /** The grid's lines. Same value you pass to `createGridLayer`. */\n spacing: GridSpacing;\n /** Required if `spacing` is tagged (e.g. `{ value: 1, unit: 'ft' }`). */\n unitSystem?: PlaneUnits;\n /** Origin the cell grid is anchored to, in world units. Default `(0, 0)`. */\n origin?: { x: number; y: number };\n /** Read `spacing` in these scopes, as `createGridLayer` does. */\n scopes?: GridScopes;\n /** The containers running lattices of their own, read on every\n * pointermove: a cell inside one is on its lattice, in its frame. */\n regions?: () => readonly GridRegion[];\n /** Fires when the hovered cell changes (including to/from `null`). Use it\n * to invalidate your layer renderer. */\n onChange?: (cell: GridCell | null) => void;\n /** Disable the listeners without unmounting. Default `true`. */\n enabled?: boolean;\n}\n\n/** Return shape of `useGridCellHover`. */\nexport interface UseGridCellHoverReturn {\n /** Current hovered cell, or `null` when the pointer is outside the element. */\n cell: GridCell | null;\n /** Stable callback that returns the current cell — drop straight into\n * `createCellHighlightLayer({ getCell })`. */\n getCell: () => GridCell | null;\n}\n\nfunction cellsEqual(\n a: GridCell | null,\n b: GridCell | null,\n): boolean {\n if (a === b) return true;\n if (a === null || b === null) return false;\n return a.col === b.col && a.row === b.row\n && a.box.x === b.box.x && a.box.y === b.box.y && a.box.width === b.box.width && a.box.height === b.box.height\n && (a.frame === b.frame || (!!a.frame && !!b.frame && a.frame.every((v, i) => v === b.frame![i])));\n}\n\n/** Track which grid cell the pointer is over; pairs with `createCellHighlightLayer`. */\nexport function useGridCellHover(opts: UseGridCellHoverOptions): UseGridCellHoverReturn {\n const [cell, setCell] = useState<GridCell | null>(null);\n const cellRef = useRef<GridCell | null>(null);\n const optsRef = useLatest(opts);\n\n const getCell = useCallback(() => cellRef.current, []);\n\n const enabled = opts.enabled ?? true;\n useEffect(() => {\n if (!enabled) return;\n const el = opts.ref.current;\n if (!el) return;\n\n const update = (next: GridCell | null) => {\n if (cellsEqual(cellRef.current, next)) return;\n cellRef.current = next;\n setCell(next);\n optsRef.current.onChange?.(next);\n };\n\n const onMove = (e: PointerEvent) => {\n const o = optsRef.current;\n const rect = el.getBoundingClientRect();\n const sx = e.clientX - rect.left;\n const sy = e.clientY - rect.top;\n const [wx, wy] = screenToWorld(sx, sy, o.view());\n const scoped = { ...(o.scopes ? { scopes: o.scopes } : {}), ...(o.regions ? { regions: o.regions() } : {}) };\n update(pointToGridCell({ x: wx, y: wy }, o.spacing, o.unitSystem, o.origin, scoped));\n };\n const onLeave = () => update(null);\n\n el.addEventListener('pointermove', onMove);\n el.addEventListener('pointerleave', onLeave);\n el.addEventListener('pointercancel', onLeave);\n return () => {\n el.removeEventListener('pointermove', onMove);\n el.removeEventListener('pointerleave', onLeave);\n el.removeEventListener('pointercancel', onLeave);\n };\n }, [enabled, opts.ref, optsRef]);\n\n return { cell, getCell };\n}\n","/**\n * Grid overlay — a reusable render layer that draws a world-space grid with\n * optional finer subdivisions and accent lines every N cells.\n *\n * The layer renders in world space — the caller is expected to have applied\n * any view transform to the canvas context already. To draw a highlighted\n * cell (snap-target preview), stack `createCellHighlightLayer` alongside\n * this one.\n */\n\nimport {\n type DrawCommand,\n type RenderLayer,\n type CommandStroke,\n type PlaneUnits,\n viewportWorldRect,\n type Dims,\n type View,\n} from '@weasel-js/core';\nimport { applyToPoint, invert, mat3, PATH_L, PATH_M, PATH_Z, type PolygonPath } from '@weasel-js/geom';\nimport { mapLines, type GridLines, type GridSpacing } from './axes';\nimport { hasArea, intersect, lattice, outlineBox, type LatticeStyles, type Rect } from './lattice';\nimport type { GridRegion } from './regions';\nimport { containerLines, gridLines, type GridScopes } from './reading';\n\n/** Options for `createGridLayer`. */\nexport interface GridLayerOpts {\n /**\n * The grid's lines: a pitch for both axes, or a rule per axis (`{ x, y }`,\n * see `GridAxis`), an axis left out drawing none. Lengths are a bare\n * number in world (base) units or a tagged `{ value, unit }`, which needs\n * `unitSystem`.\n */\n spacing: GridSpacing;\n /** Optional unit system for resolving tagged `spacing` values. */\n unitSystem?: PlaneUnits;\n /** Read `spacing` in these scopes, in place of `unitSystem`: the root's\n * system outside every region, and each region's own scope inside it. */\n scopes?: GridScopes;\n /** The containers drawing a lattice of their own, read every paint, each\n * cut out of the lattice around it and drawn in its own `frame`:\n * `sceneGridRegions` builds them from a scene. */\n regions?: () => readonly GridRegion[];\n /**\n * The area to cover, in world units, read every paint with that paint's\n * view and canvas size. Lines start at its own `x`/`y`. Omitted, the grid\n * covers whatever the canvas shows, with its lines measured from world\n * zero so they stay put as the view pans.\n */\n bounds?: (view: View, dims: Dims) => Rect;\n /** Lines every N cells get the accent style. 0/undef = no accent. */\n accentEvery?: number;\n /** Optional finer subdivisions per cell. e.g. 4 -> 4 sub-lines per cell. */\n subdivisions?: number;\n /** Per-band stroke styles. Each is a Paint+width (etc.) — see `Stroke`. */\n style?: {\n line?: CommandStroke;\n accent?: CommandStroke;\n sub?: CommandStroke;\n };\n}\n\ntype Point = { x: number; y: number };\n\n// Defaults express weight via opacity rather than a fixed dark color so the\n// grid reads correctly against any background fill (kit demos use a neutral\n// gray; consumer apps may use cream / dark / themed surfaces). Override\n// per-canvas via `style.{line,accent,sub}.paint` if a hard color is needed.\nconst DEFAULT_LINE: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.08)' },\n width: 1,\n};\nconst DEFAULT_ACCENT: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.16)' },\n width: 1,\n};\nconst DEFAULT_SUB: CommandStroke = {\n paint: { kind: 'solid', color: 'rgba(255, 255, 255, 0.04)' },\n width: 1,\n};\n\n/** Build a `RenderLayer` that draws a world-space grid with optional accent lines and subdivisions. */\nexport function createGridLayer(opts: GridLayerOpts): RenderLayer<unknown> {\n const styles: LatticeStyles = {\n line: opts.style?.line ?? DEFAULT_LINE,\n accent: opts.style?.accent ?? DEFAULT_ACCENT,\n sub: opts.style?.sub ?? DEFAULT_SUB,\n };\n\n return {\n id: 'grid',\n label: 'Grid',\n draw: (_data, view, dims) => {\n const b = opts.bounds ? opts.bounds(view, dims) : padded(viewportWorldRect(view, dims), view);\n if (!hasArea(b)) return [];\n // The root's lines run from the bounds' corner, else from world zero, as snapping reads them.\n const anchor = opts.bounds ? { x: b.x, y: b.y } : { x: 0, y: 0 };\n const root = lattice(b, placed(gridLines(opts.spacing, opts.unitSystem, opts.scopes), anchor), opts, view, styles);\n const regions = opts.regions?.() ?? [];\n if (regions.length === 0) return root;\n\n const children: DrawCommand[] = [{ kind: 'group', clip: withHoles(rectOutline(b), regions), children: root }];\n const visit = (r: GridRegion): void => {\n const own = containerLines(r.spacing, opts.spacing, opts.unitSystem, opts.scopes, r.chain);\n const lines = own\n ? regionLattice(r, b, (box, frame) => lattice(box, placed(own, frame ? { x: 0, y: 0 } : anchor), opts, view, styles, frame))\n : [];\n if (lines.length) children.push({ kind: 'group', clip: withHoles(r.outline, r.regions ?? []), children: lines });\n for (const inner of r.regions ?? []) visit(inner);\n };\n for (const r of regions) visit(r);\n // World-space commands; drawLayers wraps in viewToMat3 automatically.\n return children;\n },\n };\n}\n\n/** `r` grown by a screen pixel each way, so a line just off the canvas\n * still draws the half of it that is on. */\nfunction padded(r: Rect, view: View): Rect {\n const px = 1 / Math.abs(view.scale.x);\n const py = 1 / Math.abs(view.scale.y);\n return { x: r.x - px, y: r.y - py, width: r.width + 2 * px, height: r.height + 2 * py };\n}\n\n/** `lines` moved to run from `anchor`. */\nfunction placed(lines: GridLines, anchor: Point): GridLines {\n return { x: lines.x && mapLines(lines.x, 1, anchor.x), y: lines.y && mapLines(lines.y, 1, anchor.y) };\n}\n\nfunction rectOutline(r: Rect): Point[] {\n return [\n { x: r.x, y: r.y },\n { x: r.x + r.width, y: r.y },\n { x: r.x + r.width, y: r.y + r.height },\n { x: r.x, y: r.y + r.height },\n ];\n}\n\n/** `outline` with each of `holes` cut out of it. The renderer clips by\n * parity, so a hole is one more closed contour. */\nfunction withHoles(outline: readonly Point[], holes: readonly GridRegion[]): PolygonPath {\n const commands: number[] = [];\n const coords: number[] = [];\n for (const contour of [outline, ...holes.map((h) => h.outline)]) {\n contour.forEach((p, i) => {\n commands.push(i === 0 ? PATH_M : PATH_L);\n coords.push(p.x, p.y);\n });\n commands.push(PATH_Z);\n }\n return { kind: 'polygon', commands: new Uint8Array(commands), coords: new Float32Array(coords), fillRule: 'evenodd' };\n}\n\n/**\n * What `draw` gives for the part of `area` inside `r`, as `r` draws it: in\n * its `frame`, through it, or in world where it has none. A frame with no\n * inverse draws nothing.\n */\nfunction regionLattice(\n r: GridRegion, area: Rect, draw: (box: Rect, frame?: GridRegion['frame']) => DrawCommand[],\n): DrawCommand[] {\n if (!r.frame) {\n const box = intersect(outlineBox(r.outline), area);\n return hasArea(box) ? draw(box) : [];\n }\n const back = invert(r.frame);\n if (!back) return [];\n const local = (ps: readonly Point[]) => outlineBox(ps.map((p) => {\n const [x, y] = applyToPoint(back, p.x, p.y);\n return { x, y };\n }));\n const box = intersect(local(r.outline), local(rectOutline(area)));\n if (!hasArea(box)) return [];\n const lines = draw(box, r.frame);\n return lines.length ? [{ kind: 'group', transform: mat3.fromAffine(r.frame), children: lines }] : [];\n}\n","/**\n * Cell highlight overlay — a thin render layer that fills a single grid cell\n * (e.g. a snap-target preview). Stack it under or over `createGridLayer` in\n * a layer sequence.\n */\n\nimport { type DrawCommand, type RenderLayer, type CommandFill, viewportWorldRect } from '@weasel-js/core';\nimport { mat3 } from '@weasel-js/geom';\nimport { hasArea, intersect } from './lattice';\nimport type { GridCell } from './pointToGridCell';\n\n/** Options for `createCellHighlightLayer`. */\nexport interface CellHighlightLayerOpts {\n /** Cell to highlight, or `null` to skip drawing: its `box`, in its\n * `frame` where it has one (`pointToGridCell`, `useGridCellHover`). */\n getCell: () => GridCell | null;\n /** Fill for the highlighted cell. Defaults to a soft green. */\n fill?: CommandFill;\n}\n\nconst DEFAULT_FILL: CommandFill = { paint: { kind: 'solid', color: 'rgba(127,176,105,0.15)' } };\n\n/** Build a `RenderLayer` that fills a single grid cell — typically a snap-target preview. */\nexport function createCellHighlightLayer(opts: CellHighlightLayerOpts): RenderLayer<unknown> {\n const fill = opts.fill ?? DEFAULT_FILL;\n return {\n id: 'cell-highlight',\n label: 'Cell highlight',\n draw: (_data, view, dims) => {\n const cell = opts.getCell();\n if (!cell) return [];\n // A root cell on an axis with no lines runs without end: fill what the canvas shows of it.\n const box = cell.frame ? cell.box : intersect(cell.box, viewportWorldRect(view, dims));\n if (!hasArea(box)) return [];\n const children: DrawCommand[] = [{ kind: 'path', path: { kind: 'rect', ...box }, fill }];\n // World-space commands; drawLayers wraps in viewToMat3 automatically.\n return cell.frame ? [{ kind: 'group', transform: mat3.fromAffine(cell.frame), children }] : children;\n },\n };\n}\n","import { nearestLine, type GridLines } from './axes';\n\ntype Point = { x: number; y: number };\n\n/** A point of `gridFit` off its line on one axis, by `distance`. */\nexport interface GridMiss {\n index: number;\n axis: 'x' | 'y';\n distance: number;\n}\n\n/**\n * Whether every one of `points` sits within `tolerance` of a line on each\n * axis `lines` has lines on, so on a crossing where it has both: a hanger's\n * holes on a pegboard's. Points and tolerance are in the grid's own space,\n * measured from its origin; `gridLines` resolves a `GridSpacing` into it.\n */\nexport function gridFit(\n points: readonly Point[], lines: GridLines, tolerance = 1e-6,\n): { fits: boolean; misses: GridMiss[] } {\n const misses: GridMiss[] = [];\n points.forEach((p, index) => {\n for (const axis of ['x', 'y'] as const) {\n const a = lines[axis];\n if (!a) continue;\n const near = nearestLine(a, p[axis]);\n const distance = near === null ? Infinity : Math.abs(p[axis] - near);\n if (distance > tolerance) misses.push({ index, axis, distance });\n }\n });\n return { fits: misses.length === 0, misses };\n}\n","import type { Bounds, Locus, SnapCollect, SnapFrame } from '@weasel-js/core';\n\ntype Point = { x: number; y: number };\ntype Axis = 'x' | 'y';\n\n/** The line `axis = offset` as a locus, through `near` on the other axis. */\nexport function axisLine(axis: Axis, offset: number, near: Point): Locus {\n return axis === 'x'\n ? { at: { x: offset, y: near.y }, dirs: [{ x: 0, y: 1 }] }\n : { at: { x: near.x, y: offset }, dirs: [{ x: 1, y: 0 }] };\n}\n\n/** The line `axis = offset` of `frame`'s own coordinates as a world locus,\n * through `near` (in the frame) on the other axis. */\nexport function frameLine(frame: SnapFrame, axis: Axis, offset: number, near: Point): Locus {\n const on = axis === 'x' ? { x: offset, y: near.y } : { x: near.x, y: offset };\n const at = frame.toWorld(on);\n const tip = frame.toWorld(axis === 'x' ? { x: offset, y: near.y + 1 } : { x: near.x + 1, y: offset });\n return { at, dirs: [{ x: tip.x - at.x, y: tip.y - at.y }] };\n}\n\n/** How far the resolved move `delta` carries a probe from where `q` saw it. */\nexport function landedShift(q: Pick<SnapCollect, 'delta0'>, delta: Point): Point {\n return { x: delta.x - q.delta0.x, y: delta.y - q.delta0.y };\n}\n\n/** The probe positions at which a side moving at `rate` per unit of the move\n * has moved by `by`: the line normal to `rate`, `by / |rate|` from `near`. */\nexport function sideLine(near: Point, rate: Point, by: number): Locus {\n const k = by / (rate.x * rate.x + rate.y * rate.y);\n return { at: { x: near.x + rate.x * k, y: near.y + rate.y * k }, dirs: [{ x: -rate.y, y: rate.x }] };\n}\n\n/** Where the resolved move `delta` puts the subject's box: the session's\n * answer, else `box` carried along as a move carries it. */\nexport function landedBox(q: Pick<SnapCollect, 'box' | 'boxAt' | 'delta0'>, delta: Point): Bounds | null {\n if (q.boxAt) return q.boxAt(delta);\n if (!q.box) return null;\n const shift = landedShift(q, delta);\n return { ...q.box, x: q.box.x + shift.x, y: q.box.y + shift.y };\n}\n","import {\n asNodeId, sceneUnitScopes,\n type NodeId, type PlaneUnits, type SnapCollect, type SnapFrame, type SnapSource, type SourceCandidate,\n} from '@weasel-js/core';\nimport { linesNear, mapLines, type GridLines, type GridSpacing } from '../grid/axes';\nimport { containerLines, gridLines, type GridScopes } from '../grid/reading';\nimport { gridOwner, type GridOwners } from '../grid/regions';\nimport { axisLine, frameLine } from './lines';\n\ntype Point = { x: number; y: number };\nconst AXES = ['x', 'y'] as const;\n\n/** Options for `gridSnapSource`. */\nexport interface GridSnapSourceOptions {\n /** The grid's lines, one rule for both axes or one per axis, in\n * `unitSystem`'s units. */\n spacing: GridSpacing;\n /** A point the root's lattice passes through. Default `(0, 0)`. */\n origin?: Point;\n unitSystem?: PlaneUnits;\n /** Read the unit scope the subject sits in: a node inside a millimeter\n * sub-assembly snaps on that scope's lattice, in that container's frame. */\n scopes?: GridScopes;\n /** A container's own grid, which its children snap on in its frame (from\n * its corner, turned and scaled as it is): the nearest container above\n * the subject with one, or with a unit scope under `scopes`. `null` for a\n * container with no grid inside it. */\n gridOf?: GridOwners['gridOf'];\n /** The source's id, so two grids can snap on one canvas. Default `'grid'`. */\n id?: string;\n}\n\n/** The lattice a gesture snaps on, and the frame of the container it runs\n * in, or none for the root's. */\ninterface Lattice {\n lines: GridLines | null;\n frame?: SnapFrame | undefined;\n}\n\n/**\n * A grid as snap targets: for each probe, the grid line on either side of it\n * on each axis the grid has lines on, so a move lands the drawn box, stroke\n * included, with an edge or its center on a line; on a turned container's\n * lattice, which no world-axis box lines up with, its pose origin. A subject\n * declaring snap anchors (`SceneCanvasSnap.anchors`) lands those instead of\n * its box. Nodes spread over containers snap on the lattice they all run,\n * along the world's axes, and on none where those differ. Its reach is unlimited and it is a fallback,\n * so it holds every axis no target claims and never displaces one. Its lines\n * are the camera's, carried into the plane a gesture runs in.\n */\nexport function gridSnapSource(opts: GridSnapSourceOptions): SnapSource {\n const { scopes, gridOf } = opts;\n const owners: GridOwners = { ...(scopes ? { root: scopes.root } : {}), ...(gridOf ? { gridOf } : {}) };\n const rootLines = gridLines(opts.spacing, opts.unitSystem, scopes);\n const latticeOf = (q: SnapCollect, owner: NodeId | null): Lattice => {\n if (owner === null) return { lines: rootLines };\n const chain = scopes && q.scene ? sceneUnitScopes(q.scene, owner, scopes.root, { inclusive: true }) : undefined;\n return {\n lines: containerLines(gridOf?.(owner), opts.spacing, opts.unitSystem, scopes, chain),\n frame: q.frameOf?.(owner),\n };\n };\n const latticeFor = (q: SnapCollect): Lattice => {\n const scene = q.scene;\n if ((!scopes && !gridOf) || !scene) return { lines: rootLines };\n if (q.ids?.length) {\n const held = [...new Set(q.ids.map((id) => gridOwner(scene, asNodeId(id), owners)))];\n if (held.length === 1) return latticeOf(q, held[0]!);\n // Spread over containers, it snaps on the lattice they all run, along the world's axes.\n const each = held.map((owner) => JSON.stringify(latticeOf(q, owner).lines));\n return { lines: each.every((l) => l === each[0]) ? latticeOf(q, held[0]!).lines : null };\n }\n if (q.parent === undefined) return { lines: rootLines };\n return latticeOf(q, gridOwner(scene, asNodeId(q.parent), owners, true));\n };\n const o = opts.origin ?? { x: 0, y: 0 };\n return {\n id: opts.id ?? 'grid',\n tier: 'fallback',\n reachPx: Infinity,\n roles: ['box', 'origin', 'pointer', 'anchor'],\n *collect(q) {\n const { lines, frame } = latticeFor(q);\n if (!lines) return;\n const plane = q.plane ?? null;\n const scale = (axis: 'x' | 'y') => (plane ? plane.scale[axis] : 1);\n const anchored = q.probes.some((p) => p.role === 'anchor');\n const skip = frame && turns(frame) ? 'box' : 'origin';\n const probes = q.probes.filter((p) => (anchored ? p.role === 'anchor' || p.role === 'pointer' : p.role !== skip));\n if (frame) {\n const local = { x: lines.x && mapLines(lines.x, scale('x'), 0), y: lines.y && mapLines(lines.y, scale('y'), 0) };\n for (const p of probes) yield* framedLines(p.id, p.at, local, frame);\n return;\n }\n // Root lines run through `origin`, in the camera's world, carried into the plane.\n const shift = (axis: 'x' | 'y') => o[axis] * scale(axis) + (plane ? plane.offset[axis] : 0);\n const world = { x: lines.x && mapLines(lines.x, scale('x'), shift('x')), y: lines.y && mapLines(lines.y, scale('y'), shift('y')) };\n for (const p of probes) {\n for (const axis of AXES) {\n const a = world[axis];\n if (a) for (const at of linesNear(a, p.at[axis])) yield { probe: p.id, locus: axisLine(axis, at, p.at) };\n }\n }\n },\n };\n}\n\n/** Whether `frame`'s axes are turned or skewed off the world's, so that a\n * world-axis box cannot line up with its lattice. */\nfunction turns(frame: SnapFrame): boolean {\n const o = frame.toWorld({ x: 0, y: 0 });\n const ex = frame.toWorld({ x: 1, y: 0 });\n const ey = frame.toWorld({ x: 0, y: 1 });\n const along = (a: Point, axis: 'x' | 'y') => {\n const d = { x: a.x - o.x, y: a.y - o.y };\n return axis === 'x' ? Math.abs(d.y) <= 1e-9 * Math.abs(d.x) : Math.abs(d.x) <= 1e-9 * Math.abs(d.y);\n };\n return !((along(ex, 'x') && along(ey, 'y')) || (along(ex, 'y') && along(ey, 'x')));\n}\n\n/** The lines of `frame`'s lattice either side of `at` on each of its axes. */\nfunction* framedLines(probe: string, at: Point, lines: GridLines, frame: SnapFrame): Generator<SourceCandidate> {\n const local = frame.toLocal(at);\n if (!local) return;\n for (const axis of AXES) {\n const a = lines[axis];\n if (a) for (const offset of linesNear(a, local[axis])) yield { probe, locus: frameLine(frame, axis, offset, local) };\n }\n}\n","import type { FeaturePreset } from '@weasel-js/core';\nimport { gridSnapSource, type GridSnapSourceOptions } from '../sources/grid';\nimport { createGridLayer, type GridLayerOpts } from './layer';\n\n/** Options for `createGridPreset`: the grid's, and how it snaps. */\nexport interface GridPresetOptions extends GridLayerOpts {\n /** Preset id. Default `'grid'`. */\n id?: string;\n /** Snap gestures to the grid's lines, on its `spacing`, `unitSystem` and\n * `scopes`; `origin` is where the snap lattice starts, and `gridOf` gives\n * containers their own (pair it with `regions` from `sceneGridRegions`\n * with the same `gridOf`, so what is drawn is what snaps). `false` draws\n * the grid without snapping to it. Default on, from `(0, 0)`. */\n snap?: false | Pick<GridSnapSourceOptions, 'origin' | 'gridOf'>;\n}\n\n/**\n * A grid as one `<SceneCanvas features>` preset: the lattice drawn in the\n * grid slot, and the snap source that pulls gestures onto it.\n */\nexport function createGridPreset(opts: GridPresetOptions): FeaturePreset {\n const { id = 'grid', snap = {}, ...layer } = opts;\n const { spacing, unitSystem, scopes } = layer;\n return {\n id,\n layers: { grid: { layer: createGridLayer(layer) } },\n snapSources: snap === false ? [] : [gridSnapSource({\n id,\n spacing,\n ...(unitSystem === undefined ? {} : { unitSystem }),\n ...(scopes === undefined ? {} : { scopes }),\n ...snap,\n })],\n };\n}\n","import { useCallback, useState } from 'react';\nimport { useLatest } from '@weasel-js/core';\nimport type { Guide } from './types';\n\n/** Return shape for `useGuides`. */\nexport interface UseGuidesReturn {\n /** Live list (state). Re-renders when guides change. */\n guides: Guide[];\n /** Stable getter; reads the latest list without forcing a re-render.\n * Pass to `guideSnapSource` and `createGuidesLayer`. */\n getGuides: () => Guide[];\n /** Add a guide. If a guide with the same id already exists it is replaced. */\n addGuide: (guide: Guide) => void;\n /** Remove a guide by id. No-op when missing. */\n removeGuide: (id: string) => void;\n /** Drop all guides. */\n clearGuides: () => void;\n}\n\n/**\n * In-memory guide storage. Holds a list of horizontal/vertical world-space\n * lines that callers can pass to `guideSnapSource` (snap source) and\n * `createGuidesLayer` (render layer).\n *\n * v1 is intentionally minimal: no undo integration, no persistence, no\n * batched mutation. Wrap calls in your own history-aware action if you\n * want guide CRUD to be undoable.\n */\nexport function useGuides(initial: Guide[] = []): UseGuidesReturn {\n const [guides, setGuides] = useState<Guide[]>(initial);\n const ref = useLatest(guides);\n\n const getGuides = useCallback(() => ref.current, [ref]);\n\n const addGuide = useCallback((guide: Guide) => {\n setGuides((prev) => {\n const idx = prev.findIndex((g) => g.id === guide.id);\n if (idx === -1) return [...prev, guide];\n const next = prev.slice();\n next[idx] = guide;\n return next;\n });\n }, []);\n\n const removeGuide = useCallback((id: string) => {\n setGuides((prev) => {\n const idx = prev.findIndex((g) => g.id === id);\n if (idx === -1) return prev;\n const next = prev.slice();\n next.splice(idx, 1);\n return next;\n });\n }, []);\n\n const clearGuides = useCallback(() => {\n setGuides((prev) => (prev.length === 0 ? prev : []));\n }, []);\n\n return { guides, getGuides, addGuide, removeGuide, clearGuides };\n}\n","/**\n * Guides overlay — a screen-space render layer that draws each guide as a\n * thin line, projecting the guide's world offset through the active view.\n * A guide with a `span` draws as a segment over that span with a tick at each\n * end; one without spans the full canvas. It also draws equal-spacing gaps\n * (`SpacingGap`) as ticked segments labeled with their size.\n *\n * Guides are not scene objects; they live outside the scene and are managed\n * via `useGuides`. Pair with `guideSnapSource` (snap source) to keep\n * the visual guide and the snap target in lockstep.\n */\n\nimport { measuredSegmentCommands, tickedSegment, viewWorldToScreen, type DrawCommand, type RenderLayer, type CommandStroke } from '@weasel-js/core';\nimport type { Guide, SpacingGap } from './types';\n\n/** Options for `createGuidesLayer`. */\nexport interface GuidesLayerOpts {\n /** Stable getter for the live guide list — typically `useGuides().getGuides`. */\n getGuides: () => readonly Guide[];\n /** Stable getter for the equal-spacing gaps to draw, such as\n * `matchSpacing`'s. */\n getGaps?: () => readonly SpacingGap[];\n /** `'span'` (default) draws a guide that carries a `span` as a segment over\n * it; `'full'` draws every guide across the whole canvas. */\n extent?: 'span' | 'full';\n /** Length in CSS px of the tick across each end of a segment. 0 for none.\n * Default 6. */\n ticks?: number;\n /** Label each gap with its size: `true` (default) prints it rounded to a\n * whole world unit, a function formats it, `false` omits the label. */\n gapLabels?: boolean | ((size: number) => string);\n /** Stroke width in CSS pixels. Default 1. */\n lineWidth?: number;\n /** Stroke color, and the gap labels' fill. Default a subtle blue. */\n color?: string;\n /** Gap marker color. Default `color`. */\n gapColor?: string;\n /** Optional dash pattern (CSS px). Currently unused — reserved for future\n * parity with chrome that supports dashes. */\n dash?: number[];\n /** Override the layer id. Useful if a consumer needs more than one\n * guides-layer (e.g. user-guides vs. system-guides). */\n id?: string;\n /** Override the layer label. */\n label?: string;\n}\n\nconst DEFAULT_COLOR = '#3aa0ff';\n/** Build a `RenderLayer` that draws guide lines and spacing gaps in screen\n * space, projected from world coordinates via the active view. */\nexport function createGuidesLayer(opts: GuidesLayerOpts): RenderLayer<unknown> {\n const lineWidth = opts.lineWidth ?? 1;\n const color = opts.color ?? DEFAULT_COLOR;\n const gapColor = opts.gapColor ?? color;\n const ticks = opts.ticks ?? 6;\n const spanned = (opts.extent ?? 'span') === 'span';\n const format = opts.gapLabels === false ? null\n : typeof opts.gapLabels === 'function' ? opts.gapLabels\n : (n: number) => String(Math.round(n));\n const stroke: CommandStroke = { paint: { kind: 'solid', color }, width: lineWidth };\n const gapStroke: CommandStroke = { paint: { kind: 'solid', color: gapColor }, width: lineWidth };\n\n return {\n id: opts.id ?? 'guides',\n label: opts.label ?? 'Guides',\n space: 'screen',\n draw: (_data, view, dims) => {\n const guides = opts.getGuides();\n const gaps = opts.getGaps?.() ?? [];\n if (guides.length === 0 && gaps.length === 0) return [];\n const out: DrawCommand[] = [];\n for (const g of guides) {\n const span = spanned ? g.span : undefined;\n if (g.axis === 'x') {\n const lo = viewWorldToScreen(view, { x: g.offset, y: span?.min ?? 0 });\n const x = lo.x;\n if (x < -lineWidth || x > dims.width + lineWidth) continue;\n const path = span\n ? tickedSegment(x, lo.y, x, viewWorldToScreen(view, { x: g.offset, y: span.max }).y, ticks)\n : tickedSegment(x, 0, x, dims.height, 0);\n out.push({ kind: 'path', path, stroke });\n } else {\n const lo = viewWorldToScreen(view, { x: span?.min ?? 0, y: g.offset });\n const y = lo.y;\n if (y < -lineWidth || y > dims.height + lineWidth) continue;\n const path = span\n ? tickedSegment(lo.x, y, viewWorldToScreen(view, { x: span.max, y: g.offset }).x, y, ticks)\n : tickedSegment(0, y, dims.width, y, 0);\n out.push({ kind: 'path', path, stroke });\n }\n }\n\n for (const g of gaps) {\n const a = viewWorldToScreen(view, g.axis === 'x' ? { x: g.min, y: g.at } : { x: g.at, y: g.min });\n const b = viewWorldToScreen(view, g.axis === 'x' ? { x: g.max, y: g.at } : { x: g.at, y: g.max });\n out.push(...measuredSegmentCommands(a.x, a.y, b.x, b.y, ticks, gapStroke, format?.(g.max - g.min) ?? null, gapColor));\n }\n return out;\n },\n };\n}\n","import type { Guide } from '../types';\nimport type { DeriveAlignmentGuidesOptions } from './types';\nimport {\n type Bounds,\n type PoseDescriptor,\n rectFromPlane,\n visualBoundsViaDescriptor,\n AUTO_POSE_DESCRIPTOR,\n} from '@weasel-js/core';\n\nconst EPS = 1e-3;\n\n/** Derive candidate alignment lines from a set of sibling poses plus an\n * optional page box. Each box contributes up to 3 guides per axis: the two\n * edges and the center. Overlapping offsets collapse to one candidate, whose\n * `span` covers every box that produced it.\n * Poses go through `opts.poseDescriptor`, so a rotated sibling advertises\n * its ink edges rather than its stored box.\n * The moving selection is measured with its stroke (`drawnBoundsOf`), so\n * pass each sibling's `drawnAABBOf` box as its target for the two to agree.\n * The lines are in the camera's world: a sibling on a parallax layer needs\n * `planeOf` to say which plane its pose is in. */\nexport function deriveAlignmentGuides<TPose = Bounds>(\n targets: readonly TPose[],\n opts: DeriveAlignmentGuidesOptions<TPose> = {},\n): Guide[] {\n const d = (opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR) as PoseDescriptor<TPose>;\n const edges = opts.edges ?? true;\n const centers = opts.centers ?? true;\n // Dedup per axis: key = rounded offset. First writer wins (stable id).\n const seenX = new Map<number, Guide>();\n const seenY = new Map<number, Guide>();\n\n const add = (axis: 'x' | 'y', offset: number, b: Bounds): void => {\n const seen = axis === 'x' ? seenX : seenY;\n const key = Math.round(offset / EPS);\n const min = axis === 'x' ? b.y : b.x;\n const max = min + (axis === 'x' ? b.height : b.width);\n const prev = seen.get(key);\n if (prev) {\n prev.span = { min: Math.min(prev.span!.min, min), max: Math.max(prev.span!.max, max) };\n return;\n }\n seen.set(key, { id: `align:${axis}:${offset.toFixed(3)}`, axis, offset, span: { min, max } });\n };\n\n const emit = (b: Bounds): void => {\n if (edges) {\n add('x', b.x, b);\n add('x', b.x + b.width, b);\n add('y', b.y, b);\n add('y', b.y + b.height, b);\n }\n if (centers) {\n add('x', b.x + b.width / 2, b);\n add('y', b.y + b.height / 2, b);\n }\n };\n\n targets.forEach((t, i) => {\n const box = visualBoundsViaDescriptor(t, d);\n const plane = opts.planeOf?.(t, i);\n emit(plane ? rectFromPlane(plane, box) : box);\n });\n if (opts.page) emit(opts.page);\n\n return [...seenX.values(), ...seenY.values()];\n}\n","import type { Bounds } from '@weasel-js/core';\nimport type { SpacingGap } from '../types';\nimport type { SpacingEdge, SpacingMatchResult } from './types';\n\nconst EPS = 1e-6;\ntype Axis = 'x' | 'y';\n\nconst lo = (b: Bounds, a: Axis): number => (a === 'x' ? b.x : b.y);\nconst hi = (b: Bounds, a: Axis): number => (a === 'x' ? b.x + b.width : b.y + b.height);\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The shared range of two boxes on `axis`, or null when they share none. */\nfunction overlap(a: Bounds, b: Bounds, axis: Axis): [number, number] | null {\n const min = Math.max(lo(a, axis), lo(b, axis));\n const max = Math.min(hi(a, axis), hi(b, axis));\n return max - min > EPS ? [min, max] : null;\n}\n\nfunction gapBetween(a: Bounds, b: Bounds, axis: Axis): SpacingGap | null {\n const shared = overlap(a, b, cross(axis));\n if (shared === null) return null;\n return { axis, min: hi(a, axis), max: lo(b, axis), at: (shared[0] + shared[1]) / 2 };\n}\n\n/** Whether `b` covers any of the strip a gap marks out. */\nfunction hitsStrip(g: SpacingGap, b: Bounds, span: [number, number]): boolean {\n const c = cross(g.axis);\n return lo(b, g.axis) < g.max - EPS && hi(b, g.axis) > g.min + EPS\n && lo(b, c) < span[1] - EPS && hi(b, c) > span[0] + EPS;\n}\n\n/**\n * The visible gaps between neighboring boxes along `axis`: for `'x'`, each box\n * and the nearest box to its right that shares some of its vertical range, as\n * long as no third box stands in the strip between them. These are the gaps an\n * equal-spacing snap can reproduce.\n */\nexport function measureGaps(targets: readonly Bounds[], axis: 'x' | 'y'): SpacingGap[] {\n return measureGapSpans(targets, axis).map((m) => m.gap);\n}\n\n/** A measured gap, and the stretch of the other axis its two boxes share. */\nexport interface MeasuredGap { gap: SpacingGap; span: [number, number] }\n\n/** `measureGaps`, keeping each gap's shared span: what `referenceGaps`\n * filters. Quadratic in `targets`, so a caller matching every frame keeps\n * the result while the targets stand still. */\nexport function measureGapSpans(targets: readonly Bounds[], axis: Axis): MeasuredGap[] {\n const out: MeasuredGap[] = [];\n for (const a of targets) {\n let next: Bounds | null = null;\n for (const c of targets) {\n if (c === a || lo(c, axis) < hi(a, axis) + EPS) continue;\n if (overlap(a, c, cross(axis)) === null) continue;\n if (next === null || lo(c, axis) < lo(next, axis)) next = c;\n }\n if (next === null) continue;\n const gap = gapBetween(a, next, axis)!;\n const span = overlap(a, next, cross(axis))!;\n if (targets.some((t) => t !== a && t !== next && hitsStrip(gap, t, span))) continue;\n out.push({ gap, span });\n }\n return out.sort((p, q) => p.gap.min - q.gap.min || p.gap.at - q.gap.at);\n}\n\n/** A placement on one axis: the move that gives an equal gap of `size`. */\nexport interface SpacingOffer { delta: number; size: number }\n\n/** Every equal-spacing placement on one axis, unfiltered by reach: each\n * reference gap reproduced beside a neighbor, and centering between the two\n * neighbors. */\nexport function spacingOffers(\n b: Bounds,\n axis: Axis,\n edge: SpacingEdge,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n): SpacingOffer[] {\n const bLo = lo(b, axis);\n const bHi = hi(b, axis);\n const size = bHi - bLo;\n const center = (bLo + bHi) / 2;\n let left: Bounds | null = null;\n let right: Bounds | null = null;\n for (const t of targets) {\n if (overlap(t, b, cross(axis)) === null) continue;\n if (hi(t, axis) <= center && (left === null || hi(t, axis) > hi(left, axis))) left = t;\n if (lo(t, axis) >= center && (right === null || lo(t, axis) < lo(right, axis))) right = t;\n }\n const sizes = refs.map((g) => g.max - g.min);\n\n const out: SpacingOffer[] = [];\n const offer = (delta: number, gap: number): void => {\n if (gap > EPS) out.push({ delta, size: gap });\n };\n\n const L = left === null ? null : hi(left, axis);\n const R = right === null ? null : lo(right, axis);\n if (edge === 'both') {\n for (const g of sizes) {\n if (L !== null && (R === null || L + g + size <= R + EPS)) offer(L + g - bLo, g);\n if (R !== null && (L === null || R - g - size >= L - EPS)) offer(R - g - size - bLo, g);\n }\n if (L !== null && R !== null) {\n const g = (R - L - size) / 2;\n offer(L + g - bLo, g);\n }\n } else if (edge === 'max' && R !== null) {\n const own = L !== null ? [bLo - L] : [];\n for (const g of [...sizes, ...own]) if (R - g > bLo + EPS) offer(R - g - bHi, g);\n } else if (edge === 'min' && L !== null) {\n const own = R !== null ? [R - bHi] : [];\n for (const g of [...sizes, ...own]) if (L + g < bHi - EPS) offer(L + g - bLo, g);\n }\n return out;\n}\n\n/** The nearest equal-spacing placement on one axis within `tol`, or null. */\nfunction bestAxis(\n b: Bounds,\n axis: Axis,\n edge: SpacingEdge,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n tol: number,\n): SpacingOffer | null {\n let best: SpacingOffer | null = null;\n for (const o of spacingOffers(b, axis, edge, targets, refs)) {\n if (Math.abs(o.delta) > tol) continue;\n if (best === null || Math.abs(o.delta) < Math.abs(best.delta)) best = o;\n }\n return best;\n}\n\n/** Every gap of `size` on `axis` once the box sits at `b`: the matching\n * reference gaps, plus the box's own gaps to its two neighbors. */\nexport function equalGaps(\n b: Bounds,\n axis: Axis,\n size: number,\n targets: readonly Bounds[],\n refs: readonly SpacingGap[],\n): SpacingGap[] {\n const eq = (g: SpacingGap) => Math.abs(g.max - g.min - size) < 1e-3;\n const out = refs.filter(eq);\n // Only a box overlapping the gap-wide margins beside b can bound or block\n // one of b's own gaps, so the quadratic measure runs on those alone.\n const near = targets.filter((t) => hi(t, axis) > lo(b, axis) - size - EPS && lo(t, axis) < hi(b, axis) + size + EPS);\n const own = measureGaps([...near, b], axis).filter((g) =>\n (Math.abs(g.max - lo(b, axis)) < EPS || Math.abs(g.min - hi(b, axis)) < EPS) && eq(g));\n return [...out, ...own];\n}\n\n/** The measured gaps a box at `bounds` can reproduce: all but those it\n * stands inside. */\nexport function referenceGaps(bounds: Bounds, measured: readonly MeasuredGap[]): SpacingGap[] {\n return measured.filter((m) => !hitsStrip(m.gap, bounds, m.span)).map((m) => m.gap);\n}\n\n/**\n * Match a box against the gaps between `targets`, Figma's \"equal spacing\":\n * on each axis, find where the box's gap to a neighbor equals a gap that\n * already exists between two other boxes, or where it sits centered between\n * its two neighbors. `moving` says which edges move on each axis — `'both'`\n * for a translate, `'min'`/`'max'` for a resize dragging that edge, `null` to\n * leave the axis alone. Default `'both'` on each axis.\n *\n * Targets should exclude the box itself. A reference gap the box now stands\n * inside no longer counts. The returned gaps are every gap equal to the one\n * snapped to, with the box at its snapped position — ready to draw with\n * `createGuidesLayer`'s `getGaps`.\n */\nexport function matchSpacing(\n bounds: Bounds,\n targets: readonly Bounds[],\n worldTolerance: { x: number; y: number },\n moving: { x: SpacingEdge | null; y: SpacingEdge | null } = { x: 'both', y: 'both' },\n): SpacingMatchResult {\n const refsX = referenceGaps(bounds, measureGapSpans(targets, 'x'));\n const refsY = referenceGaps(bounds, measureGapSpans(targets, 'y'));\n const x = moving.x === null ? null : bestAxis(bounds, 'x', moving.x, targets, refsX, worldTolerance.x);\n const y = moving.y === null ? null : bestAxis(bounds, 'y', moving.y, targets, refsY, worldTolerance.y);\n const dx = x?.delta ?? 0;\n const dy = y?.delta ?? 0;\n const final = applyEdges(bounds, dx, dy, moving);\n return {\n dx,\n dy,\n gapsX: x === null ? [] : equalGaps(final, 'x', x.size, targets, refsX),\n gapsY: y === null ? [] : equalGaps(final, 'y', y.size, targets, refsY),\n };\n}\n\n/** Move the box's moving edges by the snap deltas. */\nexport function applyEdges(\n b: Bounds,\n dx: number,\n dy: number,\n moving: { x: SpacingEdge | null; y: SpacingEdge | null },\n): Bounds {\n let { x, y, width, height } = b;\n if (moving.x === 'both') x += dx;\n else if (moving.x === 'min') { x += dx; width -= dx; }\n else if (moving.x === 'max') width += dx;\n if (moving.y === 'both') y += dy;\n else if (moving.y === 'min') { y += dy; height -= dy; }\n else if (moving.y === 'max') height += dy;\n return { x, y, width, height };\n}\n","import {\n AUTO_POSE_DESCRIPTOR,\n type Bounds,\n type NodeId,\n nodeGates,\n type PoseDescriptor,\n type Scene,\n scenePoseFrame,\n unionAABB,\n visualBoundsViaDescriptor,\n} from '@weasel-js/core';\n\n\n/** Options shared by the scene readers below. */\nexport interface SceneBoundsOptions {\n /** How to read a pose's box. Pass the canvas's, so these agree with what it\n * draws. Default `AUTO_POSE_DESCRIPTOR`. */\n poseDescriptor?: PoseDescriptor<unknown>;\n}\n\n/** The world box each id is drawn in, rotation included, skipping ids the\n * scene no longer holds. Read through the scene's composition. */\nexport function worldBoundsOf(\n scene: Scene<unknown, string, unknown>,\n ids: Iterable<NodeId>,\n opts: SceneBoundsOptions = {},\n): Bounds[] {\n const d = opts.poseDescriptor ?? AUTO_POSE_DESCRIPTOR;\n const frame = scenePoseFrame(scene);\n const out: Bounds[] = [];\n for (const id of ids) {\n if (scene.get(id) === undefined) continue;\n out.push(visualBoundsViaDescriptor(frame.world(id), d));\n }\n return out;\n}\n\n/** The union of `ids`' world boxes, or null when none is in the scene. */\nexport function worldUnionOf(\n scene: Scene<unknown, string, unknown>,\n ids: Iterable<NodeId>,\n opts: SceneBoundsOptions = {},\n): Bounds | null {\n const boxes = worldBoundsOf(scene, ids, opts);\n return boxes.length === 0 ? null : unionAABB(boxes);\n}\n\n/** Every node sharing a parent with one of `ids`, outside the set, and not\n * hidden (`nodeGates`). */\nexport function siblingIds(scene: Scene<unknown, string, unknown>, ids: readonly NodeId[]): NodeId[] {\n const moving = new Set(ids);\n const gates = nodeGates(scene);\n const parents = new Set<NodeId | null>();\n for (const id of ids) {\n const node = scene.get(id);\n if (node !== undefined) parents.add(node.parent);\n }\n const siblings: NodeId[] = [];\n for (const parent of parents) {\n for (const id of parent === null ? scene.roots : scene.childrenOf(parent)) {\n const node = scene.get(id);\n if (moving.has(id) || node === undefined || gates.hidden(id)) continue;\n siblings.push(id);\n }\n }\n return siblings;\n}\n\n/**\n * The world boxes of `ids`' siblings ({@link siblingIds}). What an\n * equal-spacing snap measures gaps between while `ids` move.\n */\nexport function siblingBounds(\n scene: Scene<unknown, string, unknown>,\n ids: readonly NodeId[],\n opts: SceneBoundsOptions = {},\n): Bounds[] {\n return worldBoundsOf(scene, siblingIds(scene, ids), opts);\n}\n","import type { GestureContext } from '@weasel-js/core';\nimport type { Guide } from '../guides/types';\n\n/** A gesture's `plane`: how the camera's world maps into the world its poses are in. */\ntype Plane = GestureContext<unknown>['plane'];\n\n/** Where a guide the camera draws lies along its own axis in the world a gesture's poses are in. */\nexport function guideOffsetOn(g: Guide, plane: Plane): number {\n return plane ? g.offset * plane.scale[g.axis] + plane.offset[g.axis] : g.offset;\n}\n\n","import type { SnapSource } from '@weasel-js/core';\nimport type { Guide } from '../guides/types';\nimport { guideOffsetOn } from '../strategies/onPlane';\nimport { axisLine } from './lines';\n\n/**\n * Ruler guides as snap targets: each guide within reach of a box or\n * pointer probe is a line it may land on: a moved box's edges and center,\n * stroke included. Reads `getGuides` every frame, so\n * a guide added mid-drag counts at once.\n */\nexport function guideSnapSource(getGuides: () => readonly Guide[]): SnapSource {\n return {\n id: 'guides',\n roles: ['box', 'pointer'],\n *collect(q) {\n const guides = getGuides();\n if (guides.length === 0) return;\n const reach = q.reachWorld(q.reachPx);\n for (const p of q.probes) {\n for (const g of guides) {\n const offset = guideOffsetOn(g, q.plane ?? null);\n if (Math.abs(p.at[g.axis] - offset) > reach) continue;\n yield { probe: p.id, locus: axisLine(g.axis, offset, p.at) };\n }\n }\n },\n };\n}\n","import type { Guide } from '../types';\n\n/** A matched guide whose span also covers the snapped box. */\nexport function stretchSpan(g: Guide | null, min: number, max: number): Guide | null {\n if (g === null || g.span === undefined) return g;\n return { ...g, span: { min: Math.min(g.span.min, min), max: Math.max(g.span.max, max) } };\n}\n","import { nodeGates, type Bounds, type NodeId, type Scene, type SceneNode, type SnapCollect } from '@weasel-js/core';\nimport { siblingIds } from '../guides/alignment/sceneBounds';\n\ntype AnyScene = Scene<unknown, string, unknown>;\n\nfunction visibleRoots(scene: AnyScene): readonly NodeId[] {\n const gates = nodeGates(scene);\n return scene.roots.filter((id) => !gates.hidden(id));\n}\n\n/** Which nodes may be targets; one that fails offers no lines or gaps. */\nexport type TargetFilter = (node: SceneNode<unknown, string, unknown>) => boolean;\n\n/** The nodes a gesture's subject lines up with: its siblings when it has\n * ids, the scene's visible top-level nodes for a point gesture. */\nfunction targetIds(scene: AnyScene, exclude: readonly string[], filter?: TargetFilter): readonly NodeId[] {\n const ids = exclude.length > 0\n ? siblingIds(scene, exclude as readonly NodeId[])\n : visibleRoots(scene);\n if (!filter) return ids;\n return ids.filter((id) => {\n const node = scene.get(id);\n return node !== undefined && filter(node);\n });\n}\n\n/** The target nodes' boxes, measured as the session measures its subject;\n * none from a host that measures no boxes. */\nexport function targetBoxes(q: SnapCollect, scene: AnyScene, filter?: TargetFilter): Bounds[] {\n const drawn = q.drawnBox;\n return drawn ? targetIds(scene, q.exclude, filter).flatMap((id) => drawn(id) ?? []) : [];\n}\n\n/**\n * `derive` over the query's target boxes, kept while the scene's version and\n * the excluded ids stand still: a drag asks every frame, and nothing it\n * reads changes until it commits.\n */\nexport function cachedPerScene<T>(\n derive: (boxes: readonly Bounds[]) => T, filter?: TargetFilter,\n): (q: SnapCollect) => T | null {\n let key: { scene: AnyScene; version: number; exclude: string } | null = null;\n let value: T | null = null;\n return (q) => {\n const scene = q.scene;\n if (!scene) return null;\n const version = scene.getVersion();\n const exclude = q.exclude.join('\\n');\n if (key === null || key.scene !== scene || key.version !== version || key.exclude !== exclude) {\n value = derive(targetBoxes(q, scene, filter));\n key = { scene, version, exclude };\n }\n return value;\n };\n}\n","import type { Bounds, SnapCollect, SnapMark, SnapProbeAt, SnapSource } from '@weasel-js/core';\nimport { deriveAlignmentGuides } from '../guides/alignment/derive';\nimport { stretchSpan } from '../guides/alignment/match';\nimport type { Guide } from '../guides/types';\nimport { axisLine, landedBox, landedShift } from './lines';\nimport { cachedPerScene, type TargetFilter } from './targets';\n\ntype Point = { x: number; y: number };\ntype Axis = 'x' | 'y';\n\n/** Options for `alignmentSnapSource`. */\nexport interface AlignmentSnapSourceOptions {\n /** A page box whose edges and center are lines too, in the camera's world. */\n page?: Bounds | (() => Bounds | null | undefined);\n /** The lines to align to, in place of the edges and centers of the\n * subject's siblings (of the scene's top-level nodes, for a point gesture). */\n getCandidates?: () => readonly Guide[];\n /** Which nodes offer lines. Narrows the default siblings; not `getCandidates`. */\n filter?: TargetFilter;\n /** The color of the lines it marks. Default: the readout layer's. */\n color?: string;\n /** Overrides the canvas's reach for these targets, in screen px. */\n reachPx?: number;\n}\n\n/** Each axis's lines, sorted by offset, so a probe finds the ones in reach\n * without walking the rest. */\ninterface LineIndex { x: readonly Guide[]; y: readonly Guide[] }\n\nfunction indexLines(lines: readonly Guide[]): LineIndex {\n const sorted = [...lines].sort((a, b) => a.offset - b.offset);\n return { x: sorted.filter((g) => g.axis === 'x'), y: sorted.filter((g) => g.axis === 'y') };\n}\n\nfunction* inReach(lines: readonly Guide[], v: number, reach: number): Generator<Guide> {\n let lo = 0;\n let hi = lines.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (lines[mid].offset < v - reach) lo = mid + 1;\n else hi = mid;\n }\n for (let i = lo; i < lines.length && lines[i].offset <= v + reach; i++) yield lines[i];\n}\n\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The line `g` drawn from the box (or point) a probe landed in to the\n * farthest sibling that shares it. */\nfunction lineMark(g: Guide, extent: [number, number], color: string | undefined): SnapMark {\n const span = stretchSpan(g, extent[0], extent[1])?.span ?? { min: extent[0], max: extent[1] };\n const ends = g.axis === 'x'\n ? { from: { x: g.offset, y: span.min }, to: { x: g.offset, y: span.max } }\n : { from: { x: span.min, y: g.offset }, to: { x: span.max, y: g.offset } };\n return { kind: 'line', ...ends, ...(color === undefined ? {} : { color }) };\n}\n\n/**\n * The edges and centers of the subject's siblings, and optionally a page, as\n * snap targets: each is a line a box or pointer probe may land on. A move's\n * left, center and right (top, center, bottom) all try every line, as Figma's\n * smart guides do. When the result meets a line, its mark runs from the\n * subject's box to the farthest sibling on that line.\n */\nexport function alignmentSnapSource(opts: AlignmentSnapSourceOptions = {}): SnapSource {\n const page = () => (typeof opts.page === 'function' ? opts.page() : opts.page) ?? undefined;\n const fromScene = cachedPerScene((boxes) => indexLines(deriveAlignmentGuides(boxes)), opts.filter);\n const linesFor = (q: SnapCollect): LineIndex[] => {\n const pageBox = page();\n const own = opts.getCandidates ? indexLines(opts.getCandidates()) : fromScene(q);\n return [...(own ? [own] : []), ...(pageBox ? [indexLines(deriveAlignmentGuides([], { page: pageBox }))] : [])];\n };\n return {\n id: 'alignment',\n ...(opts.reachPx === undefined ? {} : { reachPx: opts.reachPx }),\n roles: ['box', 'pointer'],\n *collect(q) {\n const indexes = linesFor(q);\n if (indexes.length === 0) return;\n const reach = q.reachWorld(q.reachPx);\n // A resize offers its dragged corner as pointer and as box; the box's\n // probes are the ones whose marks span it.\n const probes = q.probes.some((p) => p.role === 'box') ? q.probes.filter((p) => p.role === 'box') : q.probes;\n for (const p of probes) {\n for (const axis of ['x', 'y'] as const) {\n for (const index of indexes) {\n for (const g of inReach(index[axis], p.at[axis], reach)) {\n yield {\n probe: p.id,\n locus: axisLine(axis, g.offset, p.at),\n mark: (delta: Point) => lineMark(g, extentAcross(q, p, axis, delta), opts.color),\n };\n }\n }\n }\n }\n },\n };\n}\n\n/** Where the landed probe's box (its own point, for a pointer) spans the axis\n * across `axis`. */\nfunction extentAcross(q: SnapCollect, p: SnapProbeAt, axis: Axis, delta: Point): [number, number] {\n const c = cross(axis);\n const landed = p.role === 'box' ? landedBox(q, delta) : null;\n if (landed === null) {\n const shift = landedShift(q, delta);\n return [p.at[c] + shift[c], p.at[c] + shift[c]];\n }\n const lo = c === 'x' ? landed.x : landed.y;\n return [lo, lo + (c === 'x' ? landed.width : landed.height)];\n}\n","import { asNodeId, sceneMagnification, type Bounds, type SnapCollect, type SnapMark, type SnapSource } from '@weasel-js/core';\nimport {\n equalGaps, measureGapSpans, referenceGaps, spacingOffers, type MeasuredGap,\n} from '../guides/alignment/spacing';\nimport type { SpacingEdge } from '../guides/alignment/types';\nimport type { SpacingGap } from '../guides/types';\nimport { landedBox, sideLine } from './lines';\nimport { cachedPerScene, type TargetFilter } from './targets';\n\ntype Point = { x: number; y: number };\n\n/** A side of the box the gesture moves on `axis`, at `rate` per unit of the move. */\ninterface Moving { axis: 'x' | 'y'; edge: SpacingEdge; rate: Point }\n\nconst TRANSLATE: readonly Moving[] = [\n { axis: 'x', edge: 'both', rate: { x: 1, y: 0 } },\n { axis: 'y', edge: 'both', rate: { x: 0, y: 1 } },\n];\n\n/** A move's whole box on each axis, else the sides a resize moves. */\nfunction movingSides(q: SnapCollect): readonly Moving[] {\n return q.sides ? q.sides.map((s) => ({ axis: s.axis, edge: s.side, rate: s.rate })) : TRANSLATE;\n}\n\n/** Options for `spacingSnapSource`. */\nexport interface SpacingSnapSourceOptions {\n /** The boxes to measure gaps between, in place of the subject's siblings. */\n getTargets?: () => readonly Bounds[];\n /** Which nodes offer gaps. Narrows the default siblings; not `getTargets`. */\n filter?: TargetFilter;\n /** The color of the gaps it marks. Default: the readout layer's. */\n color?: string;\n /** Overrides the canvas's reach for these targets, in screen px. */\n reachPx?: number;\n}\n\ninterface Measured { boxes: readonly Bounds[]; x: readonly MeasuredGap[]; y: readonly MeasuredGap[] }\n\nconst measureAll = (boxes: readonly Bounds[]): Measured =>\n ({ boxes, x: measureGapSpans(boxes, 'x'), y: measureGapSpans(boxes, 'y') });\n\nfunction gapMark(g: SpacingGap, color: string | undefined, magnification: number): SnapMark {\n const ends = g.axis === 'x'\n ? { from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at } }\n : { from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max } };\n return { kind: 'gap', ...ends, value: (g.max - g.min) / magnification, ...(color === undefined ? {} : { color }) };\n}\n\n/**\n * Equal spacing as snap targets, Figma's: on each axis, the positions of the\n * subject's box that make its gap to a neighbor equal one already between\n * two siblings, or center it between its two neighbors. A resize moves only\n * the sides it drags; on a turned or skewed box, the sides of its\n * axis-aligned extent the drag moves. When the result meets one, it marks\n * every gap of that size, the box's own included, where the box lands.\n */\nexport function spacingSnapSource(opts: SpacingSnapSourceOptions = {}): SnapSource {\n const fromScene = cachedPerScene(measureAll, opts.filter);\n return {\n id: 'spacing',\n ...(opts.reachPx === undefined ? {} : { reachPx: opts.reachPx }),\n roles: ['box'],\n gestures: ['move', 'resize'],\n *collect(q) {\n const box = q.box;\n const probe = q.probes.find((p) => p.role === 'box');\n const measured = opts.getTargets ? measureAll(opts.getTargets()) : fromScene(q);\n if (!box || !probe || !measured) return;\n const reach = q.reachWorld(q.reachPx);\n const refs = { x: referenceGaps(box, measured.x), y: referenceGaps(box, measured.y) };\n const seen = new Set<string>();\n const magnification = q.scene && q.ids?.length ? sceneMagnification(q.scene, q.ids.map(asNodeId)) : 1;\n for (const { axis, edge, rate } of movingSides(q)) {\n const speed = Math.hypot(rate.x, rate.y);\n for (const o of spacingOffers(box, axis, edge, measured.boxes, refs[axis])) {\n const key = `${axis}:${edge}:${o.delta.toFixed(6)}:${o.size.toFixed(6)}`;\n if (Math.abs(o.delta) / speed > reach || seen.has(key)) continue;\n seen.add(key);\n yield {\n probe: probe.id,\n locus: sideLine(probe.at, rate, o.delta),\n mark: (delta: Point) => {\n const landed = landedBox(q, delta) ?? box;\n return equalGaps(landed, axis, o.size, measured.boxes, refs[axis]).map((g) => gapMark(g, opts.color, magnification));\n },\n };\n }\n }\n },\n };\n}\n","import type { Bounds } from '@weasel-js/core';\nimport type { Guide, SpacingGap } from '../guides/types';\n\ntype Axis = 'x' | 'y';\n\nconst EPS = 1e-6;\nconst lo = (b: Bounds, a: Axis): number => (a === 'x' ? b.x : b.y);\nconst hi = (b: Bounds, a: Axis): number => (a === 'x' ? b.x + b.width : b.y + b.height);\nconst mid = (b: Bounds, a: Axis): number => (lo(b, a) + hi(b, a)) / 2;\nconst cross = (a: Axis): Axis => (a === 'x' ? 'y' : 'x');\n\n/** The distances `measureDistances` found, ready for `createGuidesLayer`:\n * `gaps` as its `getGaps`, `leaders` as its `getGuides`. */\nexport interface DistanceReadout {\n /** One measured distance per gap, labeled with its length when drawn. */\n gaps: SpacingGap[];\n /** Where a gap runs past the target, the line from the gap's end along the\n * target's edge to the target, so the number reads as reaching it. */\n leaders: Guide[];\n}\n\n/**\n * The distances between two boxes, on each axis where they separate: for\n * `from` left of `to`, the gap from `from`'s right edge to `to`'s left. A gap\n * is drawn through the range the boxes share on the other axis, or through\n * `from`'s center when they share none, with a leader to `to`. When one box\n * holds the other on an axis and they overlap on the other, the inner box's\n * distances to the outer's two edges on that axis instead. An axis where the\n * boxes partly overlap, or meet flush, has no distance.\n */\nexport function measureDistances(from: Bounds, to: Bounds): DistanceReadout {\n const out: DistanceReadout = { gaps: [], leaders: [] };\n for (const axis of ['x', 'y'] as const) measureAxis(from, to, axis, out);\n return out;\n}\n\nfunction measureAxis(from: Bounds, to: Bounds, axis: Axis, out: DistanceReadout): void {\n const c = cross(axis);\n const sharedMin = Math.max(lo(from, c), lo(to, c));\n const sharedMax = Math.min(hi(from, c), hi(to, c));\n const shares = sharedMax - sharedMin > EPS;\n const push = (min: number, max: number, at: number): void => {\n if (max - min > EPS) out.gaps.push({ axis, min, max, at });\n };\n\n const before = hi(from, axis) <= lo(to, axis) + EPS;\n const after = hi(to, axis) <= lo(from, axis) + EPS;\n if (before || after) {\n const [min, max] = before ? [hi(from, axis), lo(to, axis)] : [hi(to, axis), lo(from, axis)];\n if (max - min <= EPS) return;\n const at = shares ? (sharedMin + sharedMax) / 2 : mid(from, c);\n push(min, max, at);\n if (!shares) {\n const edge = before ? lo(to, axis) : hi(to, axis);\n const span = at < lo(to, c) ? { min: at, max: lo(to, c) } : { min: hi(to, c), max: at };\n out.leaders.push({ id: `distance:${axis}`, axis, offset: edge, span });\n }\n return;\n }\n if (!shares) return;\n const [inner, outer] = lo(from, axis) >= lo(to, axis) - EPS && hi(from, axis) <= hi(to, axis) + EPS\n ? [from, to]\n : lo(to, axis) >= lo(from, axis) - EPS && hi(to, axis) <= hi(from, axis) + EPS\n ? [to, from]\n : [null, null];\n if (inner === null || outer === null) return;\n const at = mid(inner, c);\n push(lo(outer, axis), lo(inner, axis), at);\n push(hi(inner, axis), hi(outer, axis), at);\n}\n","import { sceneMagnification, type Action, type GestureBinding, type ModSpec, type NodeId, type Scene, type SnapMark, type SnapOutcomeStore, type SurfaceContribution } from '@weasel-js/core';\nimport { measureDistances, type DistanceReadout } from './distance';\nimport { worldBoundsOf, worldUnionOf } from '../guides/alignment/sceneBounds';\nimport type { ImmediateParams } from '@weasel-js/core';\n\n\n/** Options for `distanceReadout`. */\nexport interface DistanceReadoutOptions {\n /** The key held to show the readout. Default `'alt'`. */\n modifier?: 'alt' | 'ctrl' | 'meta' | 'shift';\n /** The color of the marks it writes. Default: the readout layer's. */\n color?: string;\n /** Contribution id, and the prefix of its action's. Default `'distanceReadout'`. */\n id?: string;\n}\n\n/** The readout as snap marks: a `distance` per gap, its value divided by the\n * magnification its ends are drawn at, and a `line` per leader. */\nfunction marksOf(r: DistanceReadout, color: string | undefined, magnification: number): SnapMark[] {\n const c = color === undefined ? {} : { color };\n return [\n ...r.gaps.map((g): SnapMark => {\n const value = (g.max - g.min) / magnification;\n return g.axis === 'x'\n ? { kind: 'distance', from: { x: g.min, y: g.at }, to: { x: g.max, y: g.at }, value, ...c }\n : { kind: 'distance', from: { x: g.at, y: g.min }, to: { x: g.at, y: g.max }, value, ...c };\n }),\n ...r.leaders.flatMap((l): SnapMark[] => {\n if (l.span === undefined) return [];\n return [l.axis === 'x'\n ? { kind: 'line', from: { x: l.offset, y: l.span.min }, to: { x: l.offset, y: l.span.max }, ...c }\n : { kind: 'line', from: { x: l.span.min, y: l.offset }, to: { x: l.span.max, y: l.offset }, ...c }];\n }),\n ];\n}\n\n/** What `distanceReadout` returns: a surface contribution, plus a read of\n * what it is showing. */\nexport interface DistanceReadoutContribution extends SurfaceContribution {\n /** The distances on screen now; empty while hidden. */\n read(): DistanceReadout;\n}\n\nconst EMPTY: DistanceReadout = { gaps: [], leaders: [] };\nconst MODIFIERS: readonly NonNullable<DistanceReadoutOptions['modifier']>[] = ['alt', 'ctrl', 'meta', 'shift'];\n\n/** The ids and every node under them: what the pick under the pointer skips. */\nfunction subtreeOf(scene: Scene<unknown, string, unknown>, ids: readonly NodeId[]): Set<NodeId> {\n const out = new Set<NodeId>();\n const stack = [...ids];\n while (stack.length > 0) {\n const id = stack.pop()!;\n if (out.has(id)) continue;\n out.add(id);\n stack.push(...scene.childrenOf(id));\n }\n return out;\n}\n\n/**\n * Distance readouts on hover: while `modifier` is held over a shape, the\n * distances from the selection's box to that shape's, on each axis where they\n * separate, measured by `measureDistances` and drawn as labeled gaps. Pass it\n * in `<SceneCanvas ambient>`. It runs on `hover` bindings, so it claims no\n * input, and it reads the canvas's `selection`, `scene`, `nodeAtPoint`,\n * `poseDescriptor`, and `snapReadout` deps. A press hides it.\n */\nexport function distanceReadout(opts: DistanceReadoutOptions = {}): DistanceReadoutContribution {\n const id = opts.id ?? 'distanceReadout';\n const modifier = opts.modifier ?? 'alt';\n let shown: DistanceReadout = EMPTY;\n let store: SnapOutcomeStore | null = null;\n const show = (next: DistanceReadout, magnification = 1): void => {\n if (next === shown || (next.gaps.length === 0 && shown.gaps.length === 0)) return;\n shown = next;\n store?.set(marksOf(next, opts.color, magnification));\n };\n\n const action: Action = {\n id: `${id}.measure`,\n label: 'Measure distance to the shape under the pointer',\n requires: ['selection', 'scene', 'nodeAtPoint', 'poseDescriptor', 'snapReadout'],\n invoker: {\n timing: 'immediate',\n run: (deps, params) => {\n const p = params as (ImmediateParams & { show?: boolean }) | undefined;\n const { selection, scene, nodeAtPoint, poseDescriptor, snapReadout } = deps;\n if (snapReadout !== undefined) store = snapReadout.store;\n const ids = selection?.get() ?? [];\n if (p?.show !== true || p.world === undefined\n || scene === undefined || nodeAtPoint === undefined || ids.length === 0) {\n show(EMPTY);\n return;\n }\n const hit = nodeAtPoint(p.world, subtreeOf(scene, ids));\n const from = worldUnionOf(scene, ids, { poseDescriptor });\n const [to] = hit === null ? [] : worldBoundsOf(scene, [hit], { poseDescriptor });\n if (from === null || to === undefined) show(EMPTY);\n else show(measureDistances(from, to), sceneMagnification(scene, [...ids, hit!]));\n },\n },\n };\n\n const mods = (held: boolean): ModSpec => Object.fromEntries(\n MODIFIERS.map((m) => [m, m === modifier ? held : 'optional']),\n );\n const bindings: GestureBinding[] = [\n { spec: { kind: 'hover', mods: mods(true) }, actionId: action.id, opts: { id: `${id}.show`, params: { show: true } } },\n { spec: { kind: 'hover', mods: mods(false) }, actionId: action.id, opts: { id: `${id}.hide`, params: { show: false } } },\n { spec: { kind: 'hover', motion: 'leave' }, actionId: action.id, opts: { id: `${id}.leave`, params: { show: false } } },\n ];\n\n return {\n id,\n eligibility: { always: true },\n actions: [action],\n bindings,\n attach: (api) => {\n const el = api.element;\n const hide = (): void => show(EMPTY);\n el?.addEventListener('pointerdown', hide, true);\n return () => {\n el?.removeEventListener('pointerdown', hide, true);\n show(EMPTY);\n store = null;\n };\n },\n read: () => shown,\n };\n}\n","import type { FeaturePreset, SnapSource, SurfaceContribution } from '@weasel-js/core';\nimport type { TargetFilter } from '../sources/targets';\nimport { alignmentSnapSource } from '../sources/alignment';\nimport { spacingSnapSource } from '../sources/spacing';\nimport { distanceReadout, type DistanceReadoutOptions } from './distanceReadout';\n\n/** Options for `createSpacingHintsPreset`. */\nexport interface SpacingHintsOptions {\n /** Preset id. Default `'spacingHints'`. */\n id?: string;\n /** Snap a move so its gap to a neighbor equals one already between its\n * siblings, and mark the equal gaps. Default true. */\n spacing?: boolean;\n /** Snap to the siblings' edges and centers too, and mark the line met.\n * Default false. */\n align?: boolean;\n /** Snap distance in screen px. Default the canvas's reach. */\n tolerance?: number;\n /** Which nodes the snap sources take as siblings to line up or space against. */\n filter?: TargetFilter;\n /** The Alt-hover distance readout, configured, or `false` for none. Default\n * on, with the preset's `color`. */\n readout?: false | Omit<DistanceReadoutOptions, 'color'>;\n /** The color of the marks and the readout. */\n color?: string;\n}\n\n/**\n * Spacing hints as one `<SceneCanvas features>` preset: snap sources for\n * equal spacing between siblings and, if asked, alignment to their edges\n * and centers, whose marks the canvas's snap readout draws; and holding Alt\n * over a shape measures its distance from the selection.\n */\nexport function createSpacingHintsPreset(opts: SpacingHintsOptions = {}): FeaturePreset {\n const id = opts.id ?? 'spacingHints';\n const color = opts.color === undefined ? {} : { color: opts.color };\n const own = {\n ...color,\n ...(opts.filter === undefined ? {} : { filter: opts.filter }),\n ...(opts.tolerance === undefined ? {} : { reachPx: opts.tolerance }),\n };\n const snapSources: SnapSource[] = [\n ...((opts.spacing ?? true) ? [spacingSnapSource(own)] : []),\n ...((opts.align ?? false) ? [alignmentSnapSource(own)] : []),\n ];\n const contributions: SurfaceContribution[] = [];\n if (opts.readout !== false) contributions.push(distanceReadout({ ...opts.readout, ...color }));\n return { id, snapSources, contributions };\n}\n","import type { DropTarget, LayoutSnap } from '@weasel-js/core';\nimport { distance2, rectContainsPointHalfOpen } from '@weasel-js/geom';\n\nfunction nearestOf<TPose>(\n targets: DropTarget<TPose>[],\n pointer: { x: number; y: number },\n): DropTarget<TPose> | null {\n if (targets.length === 0) return null;\n let best = targets[0];\n let bestD = distance2(best.origin, pointer);\n for (let i = 1; i < targets.length; i++) {\n const d = distance2(targets[i].origin, pointer);\n if (d < bestD) {\n bestD = d;\n best = targets[i];\n }\n }\n return best;\n}\n\n/** Snap policy that never picks a target — every drop is rejected, which is\n * what a free-form container wants. */\nexport function none<TPose>(): LayoutSnap<TPose> {\n return { pickTarget: () => null };\n}\n\n/** Snap policy that always picks the target closest to the pointer, however\n * far away it is. */\nexport function nearest<TPose>(): LayoutSnap<TPose> {\n return { pickTarget: (targets, pointer) => nearestOf(targets, pointer) };\n}\n\n/** Snap policy that picks the closest target, but only within `tolerance`\n * world units — beyond that the drop is rejected. */\nexport function nearestWithin<TPose>(opts: { tolerance: number }): LayoutSnap<TPose> {\n const tol2 = opts.tolerance * opts.tolerance;\n return {\n pickTarget(targets, pointer) {\n const got = nearestOf(targets, pointer);\n if (got === null) return null;\n return distance2(got.origin, pointer) <= tol2 ? got : null;\n },\n };\n}\n\n/**\n * Region-aware snap. If the pointer falls inside any target's `hitBounds`,\n * that target wins; otherwise falls back to nearest-origin. Useful for\n * strategies whose targets are area-shaped (gutters, drop-zones, gridded\n * cells) rather than point-shaped.\n *\n * Pointer-in-multiple-bounds order: first match in iteration order wins, so\n * strategies should emit narrower/more-specific targets before broader ones\n * (e.g. row-gutter before tray-corner).\n */\nexport function containedThenNearest<TPose>(): LayoutSnap<TPose> {\n return {\n pickTarget(targets, pointer) {\n for (const t of targets) {\n if (t.hitBounds && rectContainsPointHalfOpen(t.hitBounds, pointer.x, pointer.y)) return t;\n }\n return nearestOf(targets, pointer);\n },\n };\n}\n\ninterface CellMeta {\n cellRect: { x: number; y: number; width: number; height: number };\n}\n\nfunction isCellMeta(m: unknown): m is CellMeta {\n return (\n typeof m === 'object' &&\n m !== null &&\n 'cellRect' in m &&\n typeof (m as { cellRect: unknown }).cellRect === 'object'\n );\n}\n\n/**\n * Backwards-compatible cell snap. Prefer `containedThenNearest` for new\n * strategies; this variant remains for `tileGrid` and any caller that puts\n * its cell rect in `meta.cellRect` rather than `hitBounds`.\n */\nexport function cellAt<TPose>(): LayoutSnap<TPose> {\n return {\n pickTarget(targets, pointer) {\n for (const t of targets) {\n if (t.hitBounds && rectContainsPointHalfOpen(t.hitBounds, pointer.x, pointer.y)) return t;\n if (isCellMeta(t.meta) && rectContainsPointHalfOpen(t.meta.cellRect, pointer.x, pointer.y)) return t;\n }\n return nearestOf(targets, pointer);\n },\n };\n}\n","import type { LayoutContainer, LayoutSnap, LayoutStrategy } from '@weasel-js/core';\n\n/** Options for `perContainer`. */\nexport interface PerContainerOptions<TPose> {\n /** The snap every container shares: a strategy's `snap` is read with no\n * container in hand, so it cannot come from the one the factory builds. */\n snap: LayoutSnap<TPose>;\n /** Shared for the same reason. Absent, a container's body is its bounds. */\n contains?: LayoutStrategy<TPose>['contains'];\n /** How many containers' strategies to keep. Past it, the one used longest\n * ago is dropped and built again when next asked for. Default 256. */\n max?: number;\n}\n\n/** A strategy `perContainer` built, and the way to drop one container's state. */\nexport type PerContainerStrategy<TPose> = LayoutStrategy<TPose> & {\n /** Drop what was built for `containerId`: for a container that is gone, or\n * whose cached state no longer describes it. */\n forget(containerId: string): void;\n};\n\n/**\n * A layout strategy that keeps state, as one strategy value: `factory` runs\n * once for each container the layout is asked about, and what it returns\n * serves that container from then on, closing over whatever it caches — a\n * spatial index, the last arrangement, a solver's warm start.\n *\n * Declare the result on as many containers as you like. A method the built\n * strategy leaves out behaves as its absence would.\n */\nexport function perContainer<TPose>(\n factory: (container: LayoutContainer) => LayoutStrategy<TPose>,\n opts: PerContainerOptions<TPose>,\n): PerContainerStrategy<TPose> {\n const max = opts.max ?? 256;\n const built = new Map<string, LayoutStrategy<TPose>>();\n\n const of = (container: LayoutContainer): LayoutStrategy<TPose> => {\n let strategy = built.get(container.id);\n if (strategy) built.delete(container.id);\n else strategy = factory(container);\n // Re-inserted on every use, so the map's first key is the one used longest ago.\n built.set(container.id, strategy);\n if (built.size > max) built.delete(built.keys().next().value!);\n return strategy;\n };\n\n return {\n snap: opts.snap,\n contains: opts.contains,\n forget: (containerId) => void built.delete(containerId),\n\n childPoses: (container, children) => of(container).childPoses(container, children),\n getDropTargets: (container, children, dragged) => of(container).getDropTargets(container, children, dragged),\n reflowPoses: (container, children, dragged, target) =>\n of(container).reflowPoses(container, children, dragged, target),\n commitDrop: (container, children, dragged, target) =>\n of(container).commitDrop(container, children, dragged, target),\n\n dropRegion: (container) => of(container).dropRegion?.(container) ?? null,\n acceptsDrop: (container, dragged) => of(container).acceptsDrop?.(container, dragged) ?? true,\n arrive(container, children, arrivals) {\n const s = of(container);\n return s.arrive ? s.arrive(container, children, arrivals) : { poses: s.childPoses(container, children) };\n },\n depart(container, children, departed) {\n const s = of(container);\n return s.depart ? s.depart(container, children, departed) : { poses: s.childPoses(container, children) };\n },\n contentExtent: (container, children) =>\n of(container).contentExtent?.(container, children) ?? container.bounds,\n releaseDrop: (container, children, dragged) =>\n of(container).releaseDrop?.(container, children, dragged) ?? null,\n };\n}\n","import { createTransformOp, type LayoutSnap, type LayoutStrategy } from '@weasel-js/core';\nimport { none } from '../snaps';\n\n/** Options for `freeform`. */\nexport interface FreeformOptions<TPose> {\n snap?: LayoutSnap<TPose>;\n}\n\n/**\n * Identity layout: each child stays where it's stored, no reflow, no drop\n * targets. `snap` is accepted for API symmetry — overrides take effect only\n * if a caller wires up an external drop-target source, since `getDropTargets`\n * returns empty by default.\n */\nexport function freeform<TPose>(opts: FreeformOptions<TPose> = {}): LayoutStrategy<TPose> {\n const snap = opts.snap ?? none<TPose>();\n\n return {\n snap,\n\n childPoses(_container, children) {\n const out = new Map<string, TPose>();\n for (const c of children) out.set(c.id, c.pose);\n return out;\n },\n\n getDropTargets() {\n return [];\n },\n\n reflowPoses() {\n return new Map();\n },\n\n commitDrop(_container, _children, dragged, target) {\n return [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: 'Drop',\n }),\n ];\n },\n };\n}\n","import {\n createTransformOp,\n type Op,\n type ContainerBounds,\n type DropTarget,\n type LayoutArrival,\n type LayoutChild,\n type LayoutContainer,\n type LayoutDragged,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport type { Rect } from '@weasel-js/geom';\nimport { cellAt } from '../snaps';\n\ninterface TileMeta {\n col: number;\n row: number;\n cellRect: Rect;\n}\n\n/**\n * What a `tileGrid` does with a child past its `cols × rows` cells.\n *\n * - `'reject'` (default) — the grid holds `cols × rows` and refuses more, by\n * any route: a drop finds no free cell, and an insert or reparent that would\n * overfill it is reverted whole.\n * - `'grow'` — the grid adds a line of cells whenever the last one fills\n * (a row, or a column for `flow: 'column'`) and the container grows by its\n * pitch to hold it, and gives the line back when children leave and it\n * empties. `rows` (or `cols`) is the minimum.\n * - `'scroll'` — the container keeps its size, and the extra children take\n * cells past its last visible line, at the same pitch. `contentExtent`\n * reports the region they cover, for a host to scroll over.\n */\nexport type TileGridOverflow = 'reject' | 'grow' | 'scroll';\n\n/** Options for `tileGrid`. */\nexport interface TileGridOptions<TPose> {\n cols: number;\n rows: number;\n /** Gap between cells, in world units. Default 0. */\n gap?: number;\n /** The order cells fill in: along each row (`'row'`, the default) or down\n * each column (`'column'`). It is also the direction an overflowing grid\n * runs on in. */\n flow?: 'row' | 'column';\n /** What happens past `cols × rows` children. Default `'reject'`. */\n overflow?: TileGridOverflow;\n snap?: LayoutSnap<TPose>;\n /** Optional: map a cell rect + the dragged pose to the new pose. Default\n * writes `{ x, y, width, height }` into the dragged pose (assumes\n * `RectPose`). `dragged` is the pre-drop pose of the child being placed —\n * use it to preserve fields the cell rect doesn't carry (e.g. rotation). */\n cellToPose?(cellRect: Rect, dragged: TPose): TPose;\n /** Optional: the point that decides which cell a child occupies — a child\n * occupies the cell containing it. Default reads `x`/`y` plus half of\n * `width`/`height` when the pose has them, which is the center of a\n * `RectPose` and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\nfunction defaultCenterOf(pose: unknown): { x: number; y: number } {\n const p = pose as { x?: number; y?: number; width?: number; height?: number };\n return { x: (p.x ?? 0) + (p.width ?? 0) / 2, y: (p.y ?? 0) + (p.height ?? 0) / 2 };\n}\n\n/**\n * Layout strategy that arranges children into a grid of cells, one child per\n * cell. What happens past `cols × rows` children is the `overflow` policy.\n *\n * A child occupies the cell its pose sits in (see `centerOf`). A drag from\n * inside the container swaps with the child in the cell it lands on; a drop\n * from outside is offered only the free cells, so it lands in the nearest\n * free one. A child that joins by an insert or a reparent is placed the same\n * way, in the free cell nearest to where it was put.\n */\nexport function tileGrid<TPose>(\n opts: TileGridOptions<TPose>,\n): LayoutStrategy<TPose> {\n const { cols, rows } = opts;\n const gap = opts.gap ?? 0;\n const byColumn = opts.flow === 'column';\n const overflow = opts.overflow ?? 'reject';\n const snap = opts.snap ?? cellAt<TPose>();\n const capacity = cols * rows;\n /** Cells per line in fill order, and the declared line count. */\n const perLine = byColumn ? rows : cols;\n const minLines = byColumn ? cols : rows;\n const cellToPose: (cell: Rect, dragged: TPose) => TPose =\n opts.cellToPose ?? ((cell, dragged) => {\n // Default: spread the cell rect over the dragged pose. Preserves any\n // extra fields the dragged pose carries.\n return { ...(dragged as object), ...cell } as TPose;\n });\n const centerOf = opts.centerOf ?? defaultCenterOf;\n\n const linesFor = (n: number): number => Math.max(minLines, Math.ceil(n / perLine));\n\n /** The grid over `bounds` while it holds `n` children: its cell pitch, and\n * how many cells it offers before running past the container. A growing\n * grid spreads its lines over the container, which it keeps sized to fit\n * them; the others always lay the declared grid over it. */\n function gridOf(bounds: ContainerBounds, n: number) {\n const lines = overflow === 'grow' ? linesFor(n) : minLines;\n const c = byColumn ? lines : cols;\n const r = byColumn ? rows : lines;\n const cw = (bounds.width - gap * (c - 1)) / c;\n const ch = (bounds.height - gap * (r - 1)) / r;\n\n function rectAt(index: number): Rect {\n const along = index % perLine;\n const line = Math.floor(index / perLine);\n const col = byColumn ? line : along;\n const row = byColumn ? along : line;\n return { x: bounds.x + col * (cw + gap), y: bounds.y + row * (ch + gap), width: cw, height: ch };\n }\n\n /** The cell index `pose` sits in, overflow cells past the container\n * included, or `null` in a gap or off the grid. */\n function indexOf(pose: TPose): number | null {\n const p = centerOf(pose);\n const col = Math.floor((p.x - bounds.x) / (cw + gap));\n const row = Math.floor((p.y - bounds.y) / (ch + gap));\n if (col < 0 || row < 0) return null;\n if (p.x - bounds.x - col * (cw + gap) >= cw) return null;\n if (p.y - bounds.y - row * (ch + gap) >= ch) return null;\n if (byColumn ? row >= rows : col >= cols) return null;\n return byColumn ? col * rows + row : row * cols + col;\n }\n\n /** The cells a drop may land in, or an arrival be placed in, with `n`\n * children in the grid: the declared grid when it refuses overflow, and\n * otherwise every whole line the children reach. */\n const cells = overflow === 'reject' ? capacity : linesFor(n) * perLine;\n\n /** The container bounds that hold `lines` lines at this pitch. */\n function boundsFor(lineCount: number): ContainerBounds {\n return byColumn\n ? { ...bounds, width: lineCount * cw + gap * (lineCount - 1) }\n : { ...bounds, height: lineCount * ch + gap * (lineCount - 1) };\n }\n\n return { rectAt, indexOf, cells, boundsFor };\n }\n\n const metaOf = (index: number, cellRect: Rect): TileMeta => {\n const along = index % perLine;\n const line = Math.floor(index / perLine);\n return byColumn\n ? { col: line, row: along, cellRect }\n : { col: along, row: line, cellRect };\n };\n const indexOfMeta = (m: TileMeta): number => (byColumn ? m.col * rows + m.row : m.row * cols + m.col);\n\n /** How many children the grid holds, not counting a drag from outside it. */\n const heldBy = (container: LayoutContainer, children: ReadonlyArray<LayoutChild<TPose>>, dragged?: LayoutDragged<TPose>): number =>\n dragged && dragged.sourceContainerId !== container.id\n ? children.filter((c) => c.id !== dragged.id).length\n : children.length;\n\n /** The swap dragging `dragged` onto `target` causes, or `null`. Preview and\n * commit both use it, so they cannot disagree. */\n function computeSwap(\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n dragged: LayoutDragged<TPose>,\n target: DropTarget<TPose> | null,\n ): { occupant: string; from: TPose; newPose: TPose } | null {\n if (target === null) return null;\n if (dragged.sourceContainerId !== container.id) return null;\n const grid = gridOf(container.bounds, children.length);\n const idx = indexOfMeta(target.meta as TileMeta);\n const occupant = children.find((c) => c.id !== dragged.id && grid.indexOf(c.pose) === idx);\n if (occupant === undefined) return null;\n // The occupant takes the cell the dragged child is leaving — where the\n // container state says it is now, which an earlier placement of the same\n // drop may have moved it to.\n const self = children.find((c) => c.id === dragged.id);\n const fromIdx = grid.indexOf(self ? self.pose : dragged.originPose);\n if (fromIdx === null || fromIdx === idx) return null;\n return { occupant: occupant.id, from: occupant.pose, newPose: cellToPose(grid.rectAt(fromIdx), occupant.pose) };\n }\n\n /**\n * Every child a cell of `into`, in the order of the cells they sit in on\n * `from`, so a reflow compacts the survivors rather than re-sorting them —\n * an earlier swap among them has to outlive a sibling leaving the grid.\n * Children sitting in no cell (a gap, or off the grid) sort last; ties break\n * by id so an arrangement with no cells yet is still deterministic. Past\n * the declared grid they run on at the same pitch.\n */\n function pack(\n from: ReturnType<typeof gridOf>,\n into: ReturnType<typeof gridOf>,\n children: ReadonlyArray<LayoutChild<TPose>>,\n ): Map<string, TPose> {\n const ordered = children\n .map((c) => ({ c, cell: from.indexOf(c.pose) }))\n .sort((a, b) => {\n if (a.cell !== b.cell) {\n if (a.cell === null) return 1;\n if (b.cell === null) return -1;\n return a.cell - b.cell;\n }\n return a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0;\n });\n const out = new Map<string, TPose>();\n for (let i = 0; i < ordered.length; i++) {\n out.set(ordered[i].c.id, cellToPose(into.rectAt(i), ordered[i].c.pose));\n }\n return out;\n }\n\n return {\n snap,\n\n childPoses(container, children) {\n const grid = gridOf(container.bounds, children.length);\n return pack(grid, grid, children);\n },\n\n getDropTargets(container, children, dragged) {\n const grid = gridOf(container.bounds, heldBy(container, children, dragged));\n // A drag from inside may land on an occupied cell and swap; one from\n // outside has nobody to swap with, so occupied cells are not offered.\n const occupied = new Set<number>();\n const fromOutside = dragged.sourceContainerId !== container.id;\n if (fromOutside) {\n for (const c of children) {\n if (c.id === dragged.id) continue;\n const idx = grid.indexOf(c.pose);\n if (idx !== null) occupied.add(idx);\n }\n }\n const offered: number[] = [];\n for (let i = 0; i < grid.cells; i++) if (!occupied.has(i)) offered.push(i);\n // A grid that takes overflow always has room for one more.\n if (fromOutside && offered.length === 0 && overflow !== 'reject') offered.push(grid.cells);\n return offered.map((i) => {\n const cellRect = grid.rectAt(i);\n return {\n pose: cellToPose(cellRect, dragged.pose),\n origin: { x: cellRect.x + cellRect.width / 2, y: cellRect.y + cellRect.height / 2 },\n meta: metaOf(i, cellRect) satisfies TileMeta,\n };\n });\n },\n\n reflowPoses(container, children, dragged, target) {\n const out = new Map<string, TPose>();\n const swap = computeSwap(container, children, dragged, target);\n if (swap !== null) {\n out.set(swap.occupant, swap.newPose);\n }\n return out;\n },\n\n commitDrop(container, children, dragged, target) {\n const ops: Op[] = [];\n\n let droppedPose: TPose;\n if (target === null) {\n droppedPose = dragged.pose;\n } else {\n const meta = target.meta as TileMeta;\n droppedPose = cellToPose(meta.cellRect, dragged.pose);\n const swap = computeSwap(container, children, dragged, target);\n if (swap !== null) {\n ops.push(\n createTransformOp<TPose>({\n id: swap.occupant,\n from: swap.from,\n to: swap.newPose,\n label: 'Tile swap',\n }),\n );\n }\n }\n ops.push(\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: droppedPose,\n label: 'Tile drop',\n }),\n );\n return ops;\n },\n\n arrive(container, children, arrivals): LayoutArrival<TPose> | null {\n const n = children.length;\n if (overflow === 'reject' && n > capacity) return null;\n // The grid as it stood before these joined: its pitch is the one the\n // arrivals are placed at, and a growing grid extends by it.\n const grid = gridOf(container.bounds, n - arrivals.size);\n const slots = overflow === 'reject' ? capacity : linesFor(n) * perLine;\n const taken = new Set<number>();\n for (const c of children) {\n if (arrivals.has(c.id)) continue;\n const idx = grid.indexOf(c.pose);\n if (idx !== null) taken.add(idx);\n }\n const poses = new Map<string, TPose>();\n for (const c of children) {\n if (!arrivals.has(c.id)) continue;\n const own = grid.indexOf(c.pose);\n let idx: number;\n if (own !== null && own < slots && !taken.has(own)) {\n idx = own;\n } else {\n const at = centerOf(c.pose);\n let best = -1;\n let bestD = Infinity;\n for (let i = 0; i < slots; i++) {\n if (taken.has(i)) continue;\n const r = grid.rectAt(i);\n const dx = r.x + r.width / 2 - at.x;\n const dy = r.y + r.height / 2 - at.y;\n const d = dx * dx + dy * dy;\n if (d < bestD) { bestD = d; best = i; }\n }\n if (best < 0) return null;\n idx = best;\n }\n taken.add(idx);\n poses.set(c.id, cellToPose(grid.rectAt(idx), c.pose));\n }\n if (overflow !== 'grow') return { poses };\n const lines = linesFor(n);\n if (lines === linesFor(n - arrivals.size)) return { poses };\n return { poses, bounds: grid.boundsFor(lines) };\n },\n\n depart(container, children, departed): LayoutArrival<TPose> {\n const n = children.length;\n // The grid as it stood with the departed still in it: a grown grid\n // gives back whole lines at that pitch, down to its declared count.\n const before = gridOf(container.bounds, n + departed.size);\n const lines = linesFor(n);\n if (overflow !== 'grow' || lines === linesFor(n + departed.size)) {\n return { poses: pack(before, before, children) };\n }\n const bounds = before.boundsFor(lines);\n return { poses: pack(before, gridOf(bounds, n), children), bounds };\n },\n\n contentExtent(container, children) {\n const grid = gridOf(container.bounds, children.length);\n const lines = Math.ceil(children.length / perLine);\n if (lines <= minLines) return container.bounds;\n const reach = grid.boundsFor(lines);\n return overflow === 'grow'\n ? container.bounds\n : { ...reach, width: Math.max(reach.width, container.bounds.width), height: Math.max(reach.height, container.bounds.height) };\n },\n };\n}\n","import {\n type Vec2,\n createTransformOp,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport { nearestWithin } from '../snaps';\n\n/** Which points within a container a child can snap to. */\nexport type SnapPattern = 'corners' | 'edges' | 'center' | 'grid';\n\n/** Options for `snapPoint`. */\nexport interface SnapPointOptions<TPose> {\n pattern: SnapPattern;\n /** Spacing for the 'grid' pattern, in world units. Default 50. */\n gridSpacing?: number;\n /** Tolerance for the default snap policy (nearestWithin). Default Infinity. */\n tolerance?: number;\n snap?: LayoutSnap<TPose>;\n}\n\nfunction buildPoints(\n bounds: { x: number; y: number; width: number; height: number },\n pattern: SnapPattern,\n gridSpacing: number,\n): Vec2[] {\n switch (pattern) {\n case 'corners':\n return [\n { x: bounds.x, y: bounds.y },\n { x: bounds.x + bounds.width, y: bounds.y },\n { x: bounds.x, y: bounds.y + bounds.height },\n { x: bounds.x + bounds.width, y: bounds.y + bounds.height },\n ];\n case 'edges':\n return [\n { x: bounds.x + bounds.width / 2, y: bounds.y },\n { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height },\n { x: bounds.x, y: bounds.y + bounds.height / 2 },\n { x: bounds.x + bounds.width, y: bounds.y + bounds.height / 2 },\n ];\n case 'center':\n return [{ x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }];\n case 'grid': {\n const out: Vec2[] = [];\n const cols = Math.floor(bounds.width / gridSpacing);\n const rows = Math.floor(bounds.height / gridSpacing);\n for (let j = 0; j <= rows; j++) {\n for (let i = 0; i <= cols; i++) {\n out.push({ x: bounds.x + i * gridSpacing, y: bounds.y + j * gridSpacing });\n }\n }\n return out;\n }\n }\n}\n\n/** Layout strategy that leaves children where they are but offers a fixed set\n * of points — corners, edge midpoints, center, or a grid — for a dragged\n * child to land on. */\nexport function snapPoint<TPose extends Vec2>(\n opts: SnapPointOptions<TPose>,\n): LayoutStrategy<TPose> {\n const gridSpacing = opts.gridSpacing ?? 50;\n const tolerance = opts.tolerance ?? Infinity;\n const snap = opts.snap ?? nearestWithin<TPose>({ tolerance });\n\n return {\n snap,\n\n childPoses(_container, children) {\n const out = new Map<string, TPose>();\n for (const c of children) out.set(c.id, c.pose);\n return out;\n },\n\n getDropTargets(container, _children, dragged) {\n const points = buildPoints(container.bounds, opts.pattern, gridSpacing);\n return points.map((p) => ({\n // Anchor the dragged child's top-left at the snap point.\n pose: { ...dragged.pose, x: p.x, y: p.y } as TPose,\n origin: p,\n }));\n },\n\n reflowPoses() {\n return new Map();\n },\n\n commitDrop(_container, _children, dragged, target) {\n const to = target === null ? dragged.pose : target.pose;\n return [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to,\n label: 'Snap drop',\n }),\n ];\n },\n };\n}\n","import {\n createTransformOp,\n type ContainerBounds,\n type LayoutArrival,\n type LayoutChild,\n type LayoutContainer,\n type LayoutDragged,\n type LayoutSnap,\n type LayoutStrategy,\n type Op,\n} from '@weasel-js/core';\n\n/** What makes a sequence layout a row of slots or a shelf-packed flow. */\nexport interface Sequencer<TPose> {\n /** `children` in sequence, read off the poses they were given when the\n * container was last arranged for `count` children. */\n order(\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n count: number,\n ): LayoutChild<TPose>[];\n /** A pose for every child of `sequence`, or `null` when the container\n * cannot hold them all. */\n place(container: LayoutContainer, sequence: ReadonlyArray<LayoutChild<TPose>>): Map<string, TPose> | null;\n /** The bounds the container takes to hold `sequence`, for one that sizes\n * itself to its children. */\n resize?(container: LayoutContainer, sequence: ReadonlyArray<LayoutChild<TPose>>): ContainerBounds | undefined;\n centerOf(pose: TPose): { x: number; y: number };\n snap: LayoutSnap<TPose>;\n /** Labels for the two kinds of op a drop writes. */\n labels: { drop: string; shift: string };\n}\n\ninterface IndexMeta {\n index: number;\n}\n\n/** The center of a `RectPose`, and the point itself for a point pose. */\nexport function defaultCenterOf(pose: unknown): { x: number; y: number } {\n const p = pose as { x?: number; y?: number; width?: number; height?: number };\n return { x: (p.x ?? 0) + (p.width ?? 0) / 2, y: (p.y ?? 0) + (p.height ?? 0) / 2 };\n}\n\nconst withAt = <T,>(list: readonly T[], index: number, item: T): T[] => [\n ...list.slice(0, index),\n item,\n ...list.slice(index),\n];\n\n/** The container's sequence without the dragged child, which counted\n * toward the last arrangement only if it came from here. */\nfunction othersOf<TPose>(\n seq: Sequencer<TPose>,\n container: LayoutContainer,\n children: ReadonlyArray<LayoutChild<TPose>>,\n dragged: LayoutDragged<TPose>,\n): LayoutChild<TPose>[] {\n const held = children.filter((c) => c.id !== dragged.id);\n const count = held.length + (dragged.sourceContainerId === container.id ? 1 : 0);\n return seq.order(container, held, count);\n}\n\n/** The index that lands `child` nearest where it is now, among those the container can hold. */\nfunction nearestIndex<TPose>(\n seq: Sequencer<TPose>,\n container: LayoutContainer,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n child: LayoutChild<TPose>,\n): number | null {\n const at = seq.centerOf(child.pose);\n let best: number | null = null;\n let bestD = Infinity;\n for (let i = 0; i <= sequence.length; i++) {\n const pose = seq.place(container, withAt(sequence, i, child))?.get(child.id);\n if (pose === undefined) continue;\n const p = seq.centerOf(pose);\n const d = (p.x - at.x) ** 2 + (p.y - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n }\n return best;\n}\n\n/**\n * The behavior every layout that keeps its children in one ordered sequence\n * shares: a drop inserts at an index and shifts the children after it, an\n * arrival goes in at the index that lands it nearest where it was put, and a\n * departure closes the gap. The `Sequencer` says what the order is and where\n * a sequence sits.\n */\nexport function sequenceLayout<TPose>(seq: Sequencer<TPose>): LayoutStrategy<TPose> {\n const { centerOf } = seq;\n\n const moved = (a: TPose, b: TPose): boolean => {\n const p = centerOf(a);\n const q = centerOf(b);\n return p.x !== q.x || p.y !== q.y;\n };\n\n const arranged = (\n container: LayoutContainer,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n poses: Map<string, TPose>,\n ): LayoutArrival<TPose> => {\n const bounds = seq.resize?.(container, sequence);\n return bounds ? { poses, bounds } : { poses };\n };\n\n /** Where the siblings sit once the dragged child takes the index `target` names. */\n const shifted: LayoutStrategy<TPose>['reflowPoses'] = (container, children, dragged, target) => {\n if (!target) return new Map();\n const others = othersOf(seq, container, children, dragged);\n const self = { id: dragged.id, pose: dragged.pose };\n const poses = seq.place(container, withAt(others, (target.meta as IndexMeta).index, self)) ?? new Map();\n poses.delete(dragged.id);\n return poses;\n };\n\n return {\n snap: seq.snap,\n\n childPoses(container, children) {\n const sequence = seq.order(container, children, children.length);\n return seq.place(container, sequence) ?? new Map(children.map((c) => [c.id, c.pose]));\n },\n\n getDropTargets(container, children, dragged) {\n const others = othersOf(seq, container, children, dragged);\n const self = { id: dragged.id, pose: dragged.pose };\n const targets = [];\n for (let index = 0; index <= others.length; index++) {\n const pose = seq.place(container, withAt(others, index, self))?.get(dragged.id);\n if (pose === undefined) continue;\n targets.push({ pose, origin: centerOf(pose), meta: { index } satisfies IndexMeta });\n }\n return targets;\n },\n\n reflowPoses: shifted,\n\n commitDrop(container, children, dragged, target) {\n const ops: Op[] = [];\n if (target) {\n const poses = shifted(container, children, dragged, target);\n for (const c of children) {\n const to = poses.get(c.id);\n if (to !== undefined && moved(c.pose, to)) {\n ops.push(createTransformOp<TPose>({ id: c.id, from: c.pose, to, label: seq.labels.shift }));\n }\n }\n }\n ops.push(\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: seq.labels.drop,\n }),\n );\n return ops;\n },\n\n arrive(container, children, arrivals) {\n const held = children.filter((c) => !arrivals.has(c.id));\n let sequence = seq.order(container, held, held.length);\n for (const c of children) {\n if (!arrivals.has(c.id)) continue;\n const index = nearestIndex(seq, container, sequence, c);\n if (index === null) return null;\n sequence = withAt(sequence, index, c);\n }\n const poses = seq.place(container, sequence);\n return poses && arranged(container, sequence, poses);\n },\n\n depart(container, children, departed) {\n const sequence = seq.order(container, children, children.length + departed.size);\n const poses = seq.place(container, sequence) ?? new Map<string, TPose>();\n return arranged(container, sequence, poses);\n },\n };\n}\n","import type { LayoutSnap, LayoutStrategy } from '@weasel-js/core';\nimport { nearest } from '../snaps';\nimport type { Arrangement, Slot } from './arrangements';\nimport { defaultCenterOf, sequenceLayout } from './sequence';\n\n/** Options for `slots`. */\nexport interface SlotsOptions<TPose> {\n /** Where the slots are for a given child count: `rowSlots`, `gridSlots`,\n * `ringSlots`, or a function of your own. */\n arrangement: Arrangement;\n /** Which slot a drag means. Default `nearest()`. */\n snap?: LayoutSnap<TPose>;\n /** The pose a child takes in a slot. Default centers the child's own\n * `width`/`height` on the slot and keeps every other field. */\n slotToPose?(slot: Slot, pose: TPose): TPose;\n /** The point that decides which slot a child sits in. Default is the\n * center of a `RectPose`, and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\nfunction defaultSlotToPose<TPose>(slot: Slot, pose: TPose): TPose {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return { ...(pose as object), x: slot.x - width / 2, y: slot.y - height / 2 } as TPose;\n}\n\nfunction nearestSlot(at: { x: number; y: number }, places: readonly Slot[]): number {\n let best = -1;\n let bestD = Infinity;\n for (let i = 0; i < places.length; i++) {\n const d = (places[i]!.x - at.x) ** 2 + (places[i]!.y - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = i;\n }\n }\n return best;\n}\n\n/**\n * Layout strategy that keeps its children in a sequence of slots — a row, a\n * grid, a ring — whose positions depend on how many children there are, so\n * the arrangement re-spaces itself as children come and go.\n *\n * A child's place in the sequence is the slot it sits nearest. Dropping a\n * drag on a slot inserts it there and shifts the children between; a drag\n * from outside is offered one slot more than the container holds. An insert\n * or reparent lands at the slot nearest where the child was put.\n */\nexport function slots<TPose>(opts: SlotsOptions<TPose>): LayoutStrategy<TPose> {\n const { arrangement } = opts;\n const slotToPose = opts.slotToPose ?? defaultSlotToPose;\n const centerOf = opts.centerOf ?? defaultCenterOf;\n\n return sequenceLayout<TPose>({\n snap: opts.snap ?? nearest<TPose>(),\n centerOf,\n labels: { drop: 'Slot drop', shift: 'Slot shift' },\n\n // Ties break by id, so a container nobody has arranged yet still has an order.\n order(container, children, count) {\n const places = arrangement(container.bounds, count);\n return children\n .map((c) => ({ c, slot: nearestSlot(centerOf(c.pose), places) }))\n .sort((a, b) => a.slot - b.slot || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0))\n .map((e) => e.c);\n },\n\n place(container, sequence) {\n const places = arrangement(container.bounds, sequence.length);\n if (places.length < sequence.length) return null;\n return new Map(sequence.map((c, i) => [c.id, slotToPose(places[i]!, c.pose)]));\n },\n });\n}\n","import type { Rect } from '@weasel-js/geom';\nimport type { ContainerBounds, LayoutChild, LayoutSnap, LayoutStrategy } from '@weasel-js/core';\nimport { nearest } from '../snaps';\nimport { sequenceLayout } from './sequence';\n\n\n/**\n * What `pack` does when its shelves run past the container's height.\n *\n * - `'reject'` (default) — refuse the child that would not fit, by any route.\n * - `'grow'` — the container's height follows its content, never below\n * `minHeight`.\n * - `'scroll'` — the container keeps its size and the shelves run on below\n * it; `contentExtent` reports the region they cover.\n */\nexport type PackOverflow = 'reject' | 'grow' | 'scroll';\n\n/** Options for `pack`. */\nexport interface PackOptions<TPose> {\n /** Space between neighbors on a shelf and between shelves, in world units. Default 0. */\n gap?: number;\n /** What happens past the container's height. Default `'reject'`. */\n overflow?: PackOverflow;\n /** The least height a `'grow'` container shrinks to. Default 0. */\n minHeight?: number;\n /** Which index a drag means. Default `nearest()`. */\n snap?: LayoutSnap<TPose>;\n /** A child's box. Default reads `x`, `y`, `width`, and `height` off the pose. */\n rectOf?(pose: TPose): Rect;\n /** `pose` with its box's top-left at `at`. Default writes `x` and `y`. */\n moveTo?(pose: TPose, at: { x: number; y: number }): TPose;\n}\n\n/**\n * Layout strategy that packs children of any size onto shelves: left to\n * right at their own sizes, wrapping at the container's width, each shelf as\n * tall as its tallest child. A child wider than the container is refused.\n *\n * The children's order is the order they read in — shelf by shelf, left to\n * right. A drop inserts at the index nearest the pointer and everything after\n * it reflows.\n */\nexport function pack<TPose>(opts: PackOptions<TPose> = {}): LayoutStrategy<TPose> {\n const gap = opts.gap ?? 0;\n const overflow = opts.overflow ?? 'reject';\n const minHeight = opts.minHeight ?? 0;\n const rectOf = opts.rectOf ?? ((pose: TPose) => pose as unknown as Rect);\n const moveTo = opts.moveTo ?? ((pose: TPose, at) => ({ ...(pose as object), ...at }) as TPose);\n\n // Ties break by id, so children nobody has arranged yet still have an order.\n const readingOrder = (children: ReadonlyArray<LayoutChild<TPose>>): LayoutChild<TPose>[] =>\n children\n .map((c) => ({ c, r: rectOf(c.pose) }))\n .sort((a, b) => a.r.y - b.r.y || a.r.x - b.r.x || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0))\n .map((e) => e.c);\n\n /** Shelf every child of `sequence`, and the height the shelves reach. Null when one is too wide. */\n function shelve(\n bounds: ContainerBounds,\n sequence: ReadonlyArray<LayoutChild<TPose>>,\n ): { poses: Map<string, TPose>; height: number } | null {\n const poses = new Map<string, TPose>();\n let x = 0;\n let y = 0;\n let shelf = 0;\n for (const c of sequence) {\n const { width, height } = rectOf(c.pose);\n if (width > bounds.width) return null;\n if (x > 0 && x + width > bounds.width) {\n y += shelf + gap;\n x = 0;\n shelf = 0;\n }\n poses.set(c.id, moveTo(c.pose, { x: bounds.x + x, y: bounds.y + y }));\n x += width + gap;\n shelf = Math.max(shelf, height);\n }\n return { poses, height: y + shelf };\n }\n\n const layout = sequenceLayout<TPose>({\n snap: opts.snap ?? nearest<TPose>(),\n labels: { drop: 'Pack drop', shift: 'Pack shift' },\n centerOf(pose) {\n const r = rectOf(pose);\n return { x: r.x + r.width / 2, y: r.y + r.height / 2 };\n },\n\n order: (_container, children) => readingOrder(children),\n\n place(container, sequence) {\n const shelved = shelve(container.bounds, sequence);\n if (!shelved) return null;\n return overflow === 'reject' && shelved.height > container.bounds.height ? null : shelved.poses;\n },\n\n resize(container, sequence) {\n if (overflow !== 'grow') return undefined;\n const height = Math.max(minHeight, shelve(container.bounds, sequence)?.height ?? 0);\n return height === container.bounds.height ? undefined : { ...container.bounds, height };\n },\n });\n\n return {\n ...layout,\n contentExtent(container, children) {\n const reach = shelve(container.bounds, readingOrder(children))?.height ?? 0;\n return { ...container.bounds, height: Math.max(container.bounds.height, reach) };\n },\n };\n}\n","import type { Rect } from '@weasel-js/geom';\nimport {\n createTransformOp,\n type ContainerBounds,\n type LayoutChild,\n type LayoutContainer,\n type LayoutSnap,\n type LayoutStrategy,\n} from '@weasel-js/core';\nimport { containedThenNearest } from '../snaps';\nimport { defaultCenterOf } from './sequence';\n\n\n/** Options for `quadtree`. */\nexport interface QuadtreeOptions<TPose> {\n /** How many times the container may be quartered. Default 4, a 16 × 16 grid at its finest. */\n maxDepth?: number;\n /** Which free cell a drag means. Default `containedThenNearest()`. */\n snap?: LayoutSnap<TPose>;\n /** The length a cell's shorter side must reach to hold the child. Default\n * is the larger of the pose's `width` and `height`. */\n sizeOf?(pose: TPose): number;\n /** The pose a child takes in a cell. Default centers the child's own size\n * in the cell and keeps every other field. */\n cellToPose?(cell: Rect, pose: TPose): TPose;\n /** The point that decides which cell a child sits in. Default is the\n * center of a `RectPose`, and the point itself for a point pose. */\n centerOf?(pose: TPose): { x: number; y: number };\n}\n\n/** One cell a child holds: {@link QuadtreeStrategy.cells}. */\nexport interface QuadtreeCell {\n id: string;\n /** How many times the container was quartered to reach the cell. */\n depth: number;\n rect: Rect;\n}\n\n/** A `quadtree` layout, which also reports the cells it has given out. */\nexport interface QuadtreeStrategy<TPose> extends LayoutStrategy<TPose> {\n /** The cell each child holds, largest first: what a debug overlay draws. */\n cells(container: LayoutContainer, children: ReadonlyArray<LayoutChild<TPose>>): QuadtreeCell[];\n}\n\ninterface Cell {\n depth: number;\n col: number;\n row: number;\n}\n\n/** Whether one cell is the other, or holds it. */\nfunction overlaps(a: Cell, b: Cell): boolean {\n const [outer, inner] = a.depth <= b.depth ? [a, b] : [b, a];\n const shift = inner.depth - outer.depth;\n return inner.col >> shift === outer.col && inner.row >> shift === outer.row;\n}\n\nfunction rectOf(bounds: ContainerBounds, cell: Cell): Rect {\n const width = bounds.width / 2 ** cell.depth;\n const height = bounds.height / 2 ** cell.depth;\n return { x: bounds.x + cell.col * width, y: bounds.y + cell.row * height, width, height }\n};\n\n/** The free cell at `depth` nearest `at`: the one holding it, if that is free. */\nfunction freeCell(bounds: ContainerBounds, taken: readonly Cell[], depth: number, at: { x: number; y: number }): Cell | null {\n let best: Cell | null = null;\n let bestD = Infinity;\n for (const cell of freeCells(taken, depth)) {\n const r = rectOf(bounds, cell);\n const d = (r.x + r.width / 2 - at.x) ** 2 + (r.y + r.height / 2 - at.y) ** 2;\n if (d < bestD) {\n bestD = d;\n best = cell;\n }\n }\n return best;\n}\n\nfunction freeCells(taken: readonly Cell[], depth: number): Cell[] {\n const out: Cell[] = [];\n const n = 2 ** depth;\n for (let row = 0; row < n; row++) {\n for (let col = 0; col < n; col++) {\n const cell = { depth, col, row };\n if (!taken.some((t) => overlaps(t, cell))) out.push(cell);\n }\n }\n return out;\n}\n\nfunction defaultCellToPose<TPose>(cell: Rect, pose: TPose): TPose {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return {\n ...(pose as object),\n x: cell.x + (cell.width - width) / 2,\n y: cell.y + (cell.height - height) / 2,\n } as TPose;\n}\n\n/**\n * Layout strategy that quarters its container as far as each child needs: a\n * child holds the smallest cell that fits it, so large and small children\n * share one container without a fixed grid. A cell is free while it, the\n * cells it sits inside, and the cells inside it hold nobody.\n *\n * A drag is offered the free cells of its own size. Children never move to\n * make room: a child that finds its cell covered goes to the nearest free\n * one, and an arrival with no free cell of its size is refused.\n */\nexport function quadtree<TPose>(opts: QuadtreeOptions<TPose> = {}): QuadtreeStrategy<TPose> {\n const maxDepth = opts.maxDepth ?? 4;\n const snap = opts.snap ?? containedThenNearest<TPose>();\n const cellToPose = opts.cellToPose ?? defaultCellToPose;\n const centerOf = opts.centerOf ?? defaultCenterOf;\n const sizeOf =\n opts.sizeOf ??\n ((pose: TPose) => {\n const { width = 0, height = 0 } = pose as { width?: number; height?: number };\n return Math.max(width, height);\n });\n\n /** The deepest level whose cells still hold a child of this pose. */\n function depthOf(bounds: ContainerBounds, pose: TPose): number {\n const size = sizeOf(pose);\n const side = Math.min(bounds.width, bounds.height);\n let depth = 0;\n while (depth < maxDepth && side / 2 ** (depth + 1) >= size) depth++;\n return depth;\n }\n\n /** A cell for every child that finds one, larger children first so a small\n * one never takes the corner of a cell a large one needs whole. */\n function assign(bounds: ContainerBounds, children: ReadonlyArray<LayoutChild<TPose>>, held: readonly Cell[] = []) {\n const taken = [...held];\n const cells = new Map<string, Cell>();\n const bySize = children\n .map((c) => ({ c, depth: depthOf(bounds, c.pose) }))\n .sort((a, b) => a.depth - b.depth || (a.c.id < b.c.id ? -1 : a.c.id > b.c.id ? 1 : 0));\n for (const { c, depth } of bySize) {\n const cell = freeCell(bounds, taken, depth, centerOf(c.pose));\n if (!cell) continue;\n taken.push(cell);\n cells.set(c.id, cell);\n }\n return { cells, taken };\n }\n\n return {\n snap,\n\n childPoses(container, children) {\n const { cells } = assign(container.bounds, children);\n return new Map(\n children.map((c) => {\n const cell = cells.get(c.id);\n return [c.id, cell ? cellToPose(rectOf(container.bounds, cell), c.pose) : c.pose];\n }),\n );\n },\n\n getDropTargets(container, children, dragged) {\n const { taken } = assign(container.bounds, children.filter((c) => c.id !== dragged.id));\n return freeCells(taken, depthOf(container.bounds, dragged.pose)).map((cell) => {\n const hitBounds = rectOf(container.bounds, cell);\n return {\n pose: cellToPose(hitBounds, dragged.pose),\n origin: { x: hitBounds.x + hitBounds.width / 2, y: hitBounds.y + hitBounds.height / 2 },\n hitBounds,\n };\n });\n },\n\n reflowPoses: () => new Map(),\n\n commitDrop: (_container, _children, dragged, target) => [\n createTransformOp<TPose>({\n id: dragged.id,\n from: dragged.originPose,\n to: target?.pose ?? dragged.pose,\n label: 'Quadtree drop',\n }),\n ],\n\n arrive(container, children, arrivals) {\n const { taken } = assign(container.bounds, children.filter((c) => !arrivals.has(c.id)));\n const joining = children.filter((c) => arrivals.has(c.id));\n const { cells } = assign(container.bounds, joining, taken);\n if (cells.size < joining.length) return null;\n return {\n poses: new Map(joining.map((c) => [c.id, cellToPose(rectOf(container.bounds, cells.get(c.id)!), c.pose)])),\n };\n },\n\n cells(container, children) {\n const { cells } = assign(container.bounds, children);\n return [...cells]\n .map(([id, cell]) => ({ id, depth: cell.depth, rect: rectOf(container.bounds, cell) }))\n .sort((a, b) => a.depth - b.depth || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));\n },\n };\n}\n","import type { ContainerBounds } from '@weasel-js/core';\n\n/** One place a child's center goes. */\nexport interface Slot {\n x: number;\n y: number;\n /** The direction the slot faces, in radians, where the arrangement has one\n * — outward from the center on a ring. `slotToPose` decides what to do\n * with it; the default ignores it. */\n angle?: number;\n}\n\n/**\n * Where a container's slots are when it holds `count` children, in fill\n * order. Returning fewer than `count` caps the container: `slots` refuses\n * whatever would not fit.\n */\nexport type Arrangement = (bounds: ContainerBounds, count: number) => Slot[];\n\n/** Options for `rowSlots`. */\nexport interface RowSlotsOptions {\n /** The axis the row runs along. Default `'x'`. */\n axis?: 'x' | 'y';\n /** Distance between neighboring slots, in world units, the row centered in\n * the container. Absent, the slots divide the container's length evenly. */\n pitch?: number;\n}\n\n/** Slots in a line, centered across the container. */\nexport function rowSlots(opts: RowSlotsOptions = {}): Arrangement {\n const alongX = opts.axis !== 'y';\n return (bounds, count) => {\n const length = alongX ? bounds.width : bounds.height;\n const pitch = opts.pitch ?? length / Math.max(count, 1);\n const first = length / 2 - (pitch * (count - 1)) / 2;\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n const along = first + i * pitch;\n out.push(\n alongX\n ? { x: bounds.x + along, y: bounds.y + bounds.height / 2 }\n : { x: bounds.x + bounds.width / 2, y: bounds.y + along },\n );\n }\n return out;\n };\n}\n\n/** Options for `gridSlots`. */\nexport interface GridSlotsOptions {\n cols: number;\n /** Rows the grid has before any child needs one. Default 1. */\n rows?: number;\n}\n\n/** Slots at the centers of a grid that fills row by row, adding a row when the\n * last fills; the rows always divide the container's height. */\nexport function gridSlots(opts: GridSlotsOptions): Arrangement {\n return (bounds, count) => {\n const rows = Math.max(opts.rows ?? 1, Math.ceil(count / opts.cols));\n const cw = bounds.width / opts.cols;\n const ch = bounds.height / rows;\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n out.push({\n x: bounds.x + ((i % opts.cols) + 0.5) * cw,\n y: bounds.y + (Math.floor(i / opts.cols) + 0.5) * ch,\n });\n }\n return out;\n };\n}\n\n/** Options for `ringSlots`. */\nexport interface RingSlotsOptions {\n /** Angle of the first slot, in radians, 0 pointing along +x and positive\n * turning toward +y. Default −π/2: the top, on a y-down canvas. */\n start?: number;\n /** How far round the slots run. Default a full turn, which spaces them\n * evenly; anything less puts a slot on each end of the arc. */\n sweep?: number;\n /** Distance to pull the ring in from the container's edges. Default 0. */\n inset?: number;\n}\n\n/** Slots around the ellipse inscribed in the container, each facing outward. */\nexport function ringSlots(opts: RingSlotsOptions = {}): Arrangement {\n const start = opts.start ?? -Math.PI / 2;\n const sweep = opts.sweep ?? Math.PI * 2;\n const inset = opts.inset ?? 0;\n const closed = Math.abs(sweep) >= Math.PI * 2;\n return (bounds, count) => {\n const rx = bounds.width / 2 - inset;\n const ry = bounds.height / 2 - inset;\n const steps = closed ? count : Math.max(count - 1, 1);\n const out: Slot[] = [];\n for (let i = 0; i < count; i++) {\n const angle = start + (sweep * i) / steps;\n out.push({\n x: bounds.x + bounds.width / 2 + rx * Math.cos(angle),\n y: bounds.y + bounds.height / 2 + ry * Math.sin(angle),\n angle,\n });\n }\n return out;\n };\n}\n"]}
|