@n-uf/placement 26.11.58 → 26.11.60

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tiling/order.ts","../src/tiling/split.ts","../src/tiling/layout.ts","../src/tiling/drop.ts","../src/tiling/regions.ts","../src/tiling/targets.ts","../src/tiling/give-way.ts","../src/tiling/drag.ts","../src/tiling/reference.ts","../src/tiling/conformance.ts","../src/tiling/neighbor.ts"],"sourcesContent":["/**\n * The order layouts: panes in order and an area in, a rect per pane out. Pure rect functions; a drop on one reorders\n * (the dragged pane inserted at an index, see `orderTargets`).\n */\nimport type { Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\n\n/**\n * How a layout spaces its panes: `gap` px between neighbors (default 0), `ratio` the master's share (default 0.5),\n * `handle` px a split's divider takes beside the gap (default 0; only a split tree reads it).\n */\nexport interface TileOptions {\n readonly gap?: number;\n readonly ratio?: number;\n readonly handle?: number;\n}\n\n/**\n * The master area: `count` panes (rounded, kept within 1..n; default 1) on `side` (default `\"left\"`). Left and right\n * make it a column of panes stacked vertically; top and bottom a row of panes side by side. The one home of the\n * concept: `masterStack` takes it in its options (`OrderOptions`), a split that lays out as master and stack in its\n * `master` field.\n */\nexport interface MasterOptions {\n readonly count?: number;\n readonly side?: Side;\n}\n\n/** What the order layouts take: `TileOptions` and the master area's `count` and `side` (`columns` and `grid` ignore them). */\nexport type OrderOptions = TileOptions & MasterOptions;\n\n/** An order layout: `masterStack`, `columns`, `grid`, or the app's own of the same shape. */\nexport type OrderLayout = <K>(panes: readonly K[], area: Rect, options?: OrderOptions) => Map<K, Rect>;\n\n/** The master's share in effect: clamped to 0.05..0.95; one that is not finite is 0.5. */\nexport const masterRatio = (v: number | undefined): number => (v === undefined || !Number.isFinite(v) ? 0.5 : Math.min(0.95, Math.max(0.05, v)));\n\n/** How many of `n` panes are masters for a requested `count`: rounded, within 1..n; NaN is 1. */\nexport function masterCount(count: number | undefined, n: number): number {\n const c = Math.round(count ?? 1);\n return Math.min(Math.max(Number.isNaN(c) ? 1 : c, 1), Math.max(n, 1));\n}\n\n/** `items` side by side or one above the other in equal shares of the box, `gap` between them. */\nfunction divide<K>(items: readonly K[], x: number, y: number, width: number, height: number, vertical: boolean, gap: number, out: Map<K, Rect>): void {\n const n = items.length;\n const total = gap * (n - 1);\n if (vertical) {\n const each = Math.max(0, (height - total) / n);\n items.forEach((pane, i) => out.set(pane, { x, y: y + i * (each + gap), width, height: each }));\n } else {\n const each = Math.max(0, (width - total) / n);\n items.forEach((pane, i) => out.set(pane, { x: x + i * (each + gap), y, width: each, height }));\n }\n}\n\n/**\n * Master and stack: the first `count` panes are the masters, in an area on `side` that takes `ratio` of the room the\n * gap leaves (clamped to 0.05..0.95; default 0.5); the rest are the stack, in the other area. Left and right make\n * each area a column of panes stacked vertically; top and bottom a row of panes side by side. Right and bottom put\n * the stack first in space. With no stack (n at most `count`) all the panes fill the area, stacked along the side's\n * cross axis. Each area divides its length equally between its panes, the gap between them.\n */\nexport function masterStack<K>(panes: readonly K[], area: Rect, options: OrderOptions = {}): Map<K, Rect> {\n const gap = options.gap !== undefined && Number.isFinite(options.gap) && options.gap > 0 ? options.gap : 0;\n const out = new Map<K, Rect>();\n if (panes.length === 0) return out;\n const side = options.side ?? \"left\";\n const ratio = masterRatio(options.ratio);\n const count = masterCount(options.count, panes.length);\n const masters = panes.slice(0, count);\n const stack = panes.slice(count);\n const column = side === \"left\" || side === \"right\";\n if (stack.length === 0) {\n divide(masters, area.x, area.y, area.width, area.height, column, gap, out);\n } else if (column) {\n const room = Math.max(0, area.width - gap);\n const masterWidth = room * ratio;\n const stackWidth = room * (1 - ratio);\n const masterX = side === \"left\" ? area.x : area.x + stackWidth + gap;\n const stackX = side === \"left\" ? area.x + masterWidth + gap : area.x;\n divide(masters, masterX, area.y, masterWidth, area.height, true, gap, out);\n divide(stack, stackX, area.y, stackWidth, area.height, true, gap, out);\n } else {\n const room = Math.max(0, area.height - gap);\n const masterHeight = room * ratio;\n const stackHeight = room * (1 - ratio);\n const masterY = side === \"top\" ? area.y : area.y + stackHeight + gap;\n const stackY = side === \"top\" ? area.y + masterHeight + gap : area.y;\n divide(masters, area.x, masterY, area.width, masterHeight, false, gap, out);\n divide(stack, area.x, stackY, area.width, stackHeight, false, gap, out);\n }\n return out;\n}\n\n/** Equal columns, full height. */\nexport function columns<K>(panes: readonly K[], area: Rect, options: TileOptions = {}): Map<K, Rect> {\n const gap = options.gap ?? 0;\n const out = new Map<K, Rect>();\n const n = panes.length;\n const w = (area.width - gap * (n - 1)) / Math.max(1, n);\n panes.forEach((id, i) => out.set(id, { x: area.x + i * (w + gap), y: area.y, width: w, height: area.height }));\n return out;\n}\n\n/** A grid as square as the count allows; the last row's cells widen to fill it. */\nexport function grid<K>(panes: readonly K[], area: Rect, options: TileOptions = {}): Map<K, Rect> {\n const gap = options.gap ?? 0;\n const out = new Map<K, Rect>();\n const n = panes.length;\n if (n === 0) return out;\n const cols = Math.ceil(Math.sqrt(n));\n const rows = Math.ceil(n / cols);\n const h = (area.height - gap * (rows - 1)) / rows;\n panes.forEach((id, i) => {\n const row = Math.floor(i / cols);\n const inRow = row === rows - 1 ? n - cols * (rows - 1) : cols;\n const col = i - row * cols;\n const w = (area.width - gap * (inRow - 1)) / inRow;\n out.set(id, { x: area.x + col * (w + gap), y: area.y + row * (h + gap), width: w, height: h });\n });\n return out;\n}\n","/**\n * The split tree: how panes divide an area. A node is a pane, or a split of its rect in two (`a` then `b`). A split\n * with an `axis` divides along it (`\"x\"`: `a` left of `b`; `\"y\"`: `a` above `b`) at `ratio`; one without divides\n * along the rect's longer side in halves, which is dwindle (split along the longer side). Pure: trees in, trees out.\n */\nimport type { Axis, Side } from \"../side\";\nimport type { MasterOptions } from \"./order\";\nimport type { PaneRegion } from \"./regions\";\n\n/**\n * A pane, or a split of its rect in two, `a` then `b`. A split takes its `axis` and its `ratio` (the first side's\n * share); `gap` replaces the layout's gap for this split (the handle stays global); `id` names the split so\n * `layoutSplitTree` reports its geometry. With `master`, the split lays its subtree out flat: its panes, in order,\n * as master and stack (`masterStack`) in its rect, by its `ratio` and gap; the splits under it are not laid out.\n */\nexport type Split<K> =\n | { readonly pane: K }\n | {\n readonly a: Split<K>;\n readonly b: Split<K>;\n readonly axis?: Axis;\n readonly ratio?: number;\n readonly gap?: number;\n readonly id?: string;\n readonly master?: MasterOptions;\n };\n\n/** The panes of `tree` in order (`a` before `b`). */\nexport const panesOf = <K>(tree: Split<K> | null): K[] => (!tree ? [] : \"pane\" in tree ? [tree.pane] : [...panesOf(tree.a), ...panesOf(tree.b)]);\n\nconst has = <K>(tree: Split<K> | null, pane: K): boolean => panesOf(tree).includes(pane);\n\n/** `tree` with each pane node `fn` gives a replacement for replaced. */\nfunction mapPanes<K>(tree: Split<K>, fn: (pane: K) => Split<K>): Split<K> {\n if (\"pane\" in tree) return fn(tree.pane);\n return { ...tree, a: mapPanes(tree.a, fn), b: mapPanes(tree.b, fn) };\n}\n\n/**\n * `tree` with pane `at` split in two, `pane` on its `side`. A side writes an explicit axis and ratio 0.5, so the side\n * means the same whatever the pane's shape; no side splits along the longer side, `pane` second (dwindle). An empty\n * tree becomes `pane` alone; an `at` that isn't in the tree (or null) splits the whole tree, so no pane is lost.\n */\nexport function splitPane<K>(tree: Split<K> | null, at: K | null, pane: K, side?: Side): Split<K> {\n const fresh: Split<K> = { pane };\n const split = (node: Split<K>): Split<K> => {\n if (!side) return { a: node, b: fresh };\n const axis = side === \"left\" || side === \"right\" ? \"x\" : \"y\";\n const first = side === \"left\" || side === \"top\";\n return first ? { a: fresh, b: node, axis, ratio: 0.5 } : { a: node, b: fresh, axis, ratio: 0.5 };\n };\n if (!tree) return fresh;\n if (at === null || !has(tree, at)) return split(tree);\n return mapPanes(tree, (p) => (p === at ? split({ pane: p }) : { pane: p }));\n}\n\n/** `tree` without `pane`: its sibling takes their parent's place. */\nexport function removePane<K>(tree: Split<K> | null, pane: K): Split<K> | null {\n if (!tree) return null;\n if (\"pane\" in tree) return tree.pane === pane ? null : tree;\n const a = removePane(tree.a, pane);\n const b = removePane(tree.b, pane);\n return a && b ? { ...tree, a, b } : (a ?? b);\n}\n\n/** `tree` with panes `x` and `y` in each other's place; unchanged unless both are in it. */\nexport function swapPanes<K>(tree: Split<K> | null, x: K, y: K): Split<K> | null {\n if (!tree || !has(tree, x) || !has(tree, y)) return tree;\n return mapPanes(tree, (p) => ({ pane: p === x ? y : p === y ? x : p }));\n}\n\n/** A dwindle tree for `panes`: each one splits the one before it along the longer side. */\nexport function splitFromOrder<K>(panes: readonly K[]): Split<K> | null {\n let t: Split<K> | null = null;\n panes.forEach((id, i) => {\n t = splitPane(t, i > 0 ? panes[i - 1]! : null, id);\n });\n return t;\n}\n\n/**\n * A drop of `dragged` on pane `at`'s `region`. A side splits `at` on that side (`dragged` taken out of its old place\n * first). The center swaps the two when `dragged` is in the tree; a pane from outside takes `at`'s place, with `at`\n * split off after it along the longer side. An `at` that isn't in the tree (or is `dragged` itself) changes nothing\n * but adding `dragged` when it is missing, as `splitPane` does. The set of panes is kept: the tree's, plus `dragged`.\n */\nexport function dropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion): Split<K> {\n if (!tree) return { pane: dragged };\n if (dragged === at || !has(tree, at)) return has(tree, dragged) ? tree : splitPane(tree, null, dragged);\n if (region !== \"center\") return splitPane(removePane(tree, dragged), at, dragged, region);\n if (has(tree, dragged)) return swapPanes(tree, dragged, at)!;\n return mapPanes(tree, (p) => (p === at ? { a: { pane: dragged }, b: { pane: p } } : { pane: p }));\n}\n","/**\n * The split tree laid out: the rect of every pane of a `Split` tree in an area, and the geometry of the splits that\n * have an id. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Axis } from \"../side\";\nimport { masterCount, masterRatio, masterStack, type MasterOptions, type TileOptions } from \"./order\";\nimport { panesOf, type Split } from \"./split\";\n\n/** A px option: a finite number, never below 0 (anything else is 0). */\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/** A ratio: clamped to 0..1; one that is not finite is 0.5. */\nconst unit = (v: number | undefined): number => (v === undefined || !Number.isFinite(v) ? 0.5 : Math.min(1, Math.max(0, v)));\n\n/** A usable length: finite and above 0. */\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\n\n/** The least a ratio may be in a split with a floor: within 5 and 95 % unless a side takes the net off. */\nconst NET: readonly [number, number] = [0.05, 0.95];\n\n/** A split child's fixed length along its split. `keep` marks one that holds its length even beside another. */\nexport interface FixedLength {\n readonly length: number;\n readonly keep?: boolean;\n}\n\n/** A split child's least length along its split. `net` (default true) keeps the split's ratio within 5..95 %. */\nexport interface MinLength {\n readonly min: number;\n readonly net?: boolean;\n}\n\n/**\n * What a split tree's layout reads of its host, each per split, of the split's two direct children.\n *\n * - `fixed(child, axis)`: the child's fixed length along the split, if it has one. The first child that reports one\n * decides: it takes its length when the length is above 0 and, with the gutter, less than the extent, and the other\n * side fills the rest (the gutter between). Otherwise, or with a length that does not fit, the split falls back to\n * its ratio, and the other child's length is not read. When both report a length with `keep`, each keeps its own,\n * in order, and the room left over stays empty; if the two (and the gutter) do not fit the extent, the second runs\n * past the end. A split a fixed length decides has no divider and no floor.\n * - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive and\n * finite, from the start of the cross axis instead of the whole cross extent. It is not checked against the cross\n * extent: a length larger than the cross extent makes a pane larger than the split's box.\n * - `floor(child, axis, split)`: the child's least length along the split. The ratio is clamped so each side keeps\n * its floor of the room less the gutter, within the net (5..95 %) unless either side says `net: false`; where the\n * two floors cannot both fit, the ratio is 0.5. With no `floor`, the ratio is only clamped to 0..1. `giveWay` is\n * the other policy of the same minimum: it floats the newest pane instead of squeezing the ratio, and a host\n * chooses one for a pane.\n */\nexport interface SplitOptions<K> extends TileOptions {\n readonly fixed?: (child: Split<K>, axis: Axis) => FixedLength | undefined;\n readonly fixedAcross?: (child: Split<K>, axis: Axis) => number | undefined;\n readonly floor?: (child: Split<K>, axis: Axis, split: Split<K>) => MinLength;\n}\n\n/** A laid-out split: the box it divides, its axis and ratio in effect, and the strip between its two sides. */\nexport interface SplitGeometry {\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n /**\n * The first side's share in effect: the middle of the gutter lies at the box's start plus its extent times this\n * (for a fixed-length child, the middle of the gutter after the first side over the extent). For a master split\n * it is the master area's share (clamped to 0.05..0.95) of the room less the gap, measured from the master's own\n * side: with the master on the right, ratio 0.3 in 1000 with a gap of 10, the divider lies at 693..703.\n */\n readonly ratio: number;\n /** The gutter between the two sides, as a rect inside `rect`; null where the split has none. */\n readonly divider: Rect | null;\n}\n\n/** A tree laid out: every pane's rect, and the geometry of each split that has an `id`. */\nexport interface SplitLayout<K> {\n readonly panes: Map<K, Rect>;\n readonly splits: Map<string, SplitGeometry>;\n}\n\ninterface Ctx<K> {\n readonly options: SplitOptions<K>;\n readonly gap: number;\n readonly handle: number;\n readonly panes: Map<K, Rect>;\n /** Where the geometry of the named splits goes; null for `layoutSplit`, which reports panes only and builds none. */\n readonly splits: Map<string, SplitGeometry> | null;\n}\n\n/**\n * The rect of every pane of `tree` in `area`. Each split's gutter is its gap (its own `gap`, else `options.gap`) plus\n * `options.handle`. A split's `ratio` is clamped to 0..1 (one that is not finite is 0.5), and the middle of the gutter\n * sits at `extent * ratio`: the first side is `extent * ratio` less half the gutter, the second starts half a gutter\n * past it and is the rest less half the gutter. No size is ever negative: a side too short for half the gutter is 0\n * along the axis, and the second side of a split with no room may then start up to half a gutter past the rect's end.\n * At ratio 0.5 both sides are equal. `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's\n * minimums and fixed lengths per split. A negative or non-finite `gap` or `handle` is 0. The area is taken as given:\n * with a negative width or height every length along that axis is 0 and a pane's size across it is copied as it\n * is, so pass an area with no negative side.\n */\nexport function layoutSplit<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K> = {}): Map<K, Rect> {\n const ctx: Ctx<K> = { options, gap: px(options.gap), handle: px(options.handle), panes: new Map(), splits: null };\n lay(tree, area, ctx, false);\n return ctx.panes;\n}\n\n/**\n * `layoutSplit` and the geometry of every split that has an `id` (a repeated id keeps the one laid out last: a split under another, or a later one beside it): the box it divides,\n * its axis and ratio in effect (after the floors), and its divider, the gutter strip between its two sides. A split\n * that lays out as master and stack is reported too, its nested splits are not.\n */\nexport function layoutSplitTree<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K> = {}): SplitLayout<K> {\n const splits = new Map<string, SplitGeometry>();\n const ctx: Ctx<K> = { options, gap: px(options.gap), handle: px(options.handle), panes: new Map(), splits };\n lay(tree, area, ctx, false);\n return { panes: ctx.panes, splits };\n}\n\n/** The strip `gutter` wide centered on `mid` across `box`, clipped to it. */\nfunction strip(box: Rect, x: boolean, mid: number, gutter: number): Rect {\n const lo = Math.max(x ? box.x : box.y, mid - gutter / 2);\n const hi = Math.min(x ? box.x + box.width : box.y + box.height, mid + gutter / 2);\n const length = Math.max(0, hi - lo);\n return x ? { x: lo, y: box.y, width: length, height: box.height } : { x: box.x, y: lo, width: box.width, height: length };\n}\n\n/**\n * `ratio` kept so the first side has `minA` and the second `minB` of the room less the gutter (at least 1 px of room),\n * within `net`; 0.5 where the two cannot both fit.\n */\nfunction clampByMin(ratio: number, extent: number, gutter: number, minA: number, minB: number, net: readonly [number, number]): number {\n const room = Math.max(extent - gutter, 1);\n const boundedMin = Math.min(Math.max(minA / room, net[0]), net[1]);\n const boundedMax = Math.max(Math.min(1 - minB / room, net[1]), net[0]);\n return boundedMin > boundedMax ? 0.5 : Math.min(Math.max(ratio, boundedMin), boundedMax);\n}\n\n/** A split that lays its panes out flat as master and stack: the gap only, never the handle. */\nfunction layMaster<K>(tree: Extract<Split<K>, { a: unknown }>, master: MasterOptions, area: Rect, ctx: Ctx<K>, owned: boolean): void {\n const gap = tree.gap === undefined ? ctx.gap : px(tree.gap);\n const panes = panesOf(tree);\n const ratio = masterRatio(tree.ratio);\n const side = master.side ?? \"left\";\n // Only the count and side come from `master`: the ratio and gap are the split's own.\n for (const [pane, r] of masterStack(panes, area, { gap, ratio, count: master.count, side })) ctx.panes.set(pane, r);\n if (tree.id === undefined || ctx.splits === null) return;\n const x = side === \"left\" || side === \"right\";\n const stacked = panes.length > masterCount(master.count, panes.length);\n const room = Math.max(0, (x ? area.width : area.height) - gap);\n const first = side === \"left\" || side === \"top\" ? room * ratio : room * (1 - ratio);\n const mid = (x ? area.x : area.y) + first + gap / 2;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis: x ? \"x\" : \"y\", ratio, divider: stacked ? strip(area, x, mid, gap) : null });\n}\n\n/**\n * Lays `tree` out in `area`. `owned` says `area` is a rect this layout made itself (a split's child), so a pane or a\n * split may keep it as its own; the caller's rect (the root) is copied, never kept.\n */\nfunction lay<K>(tree: Split<K> | null, area: Rect, ctx: Ctx<K>, owned: boolean): void {\n if (!tree) return;\n if (\"pane\" in tree) {\n ctx.panes.set(tree.pane, owned ? area : { ...area });\n return;\n }\n if (tree.master) {\n layMaster(tree, tree.master, area, ctx, owned);\n return;\n }\n const axis = tree.axis ?? (area.width >= area.height ? \"x\" : \"y\");\n const x = axis === \"x\";\n const extent = x ? area.width : area.height;\n const origin = x ? area.x : area.y;\n const cross = x ? area.height : area.width;\n const gutter = (tree.gap === undefined ? ctx.gap : px(tree.gap)) + ctx.handle;\n const { fixed, fixedAcross, floor } = ctx.options;\n // Across the split a child with a fixed length takes it from the start; the others take the whole cross extent.\n const lenA = fixedAcross?.(tree.a, axis);\n const lenB = fixedAcross?.(tree.b, axis);\n const acrossA = usable(lenA) ? lenA : cross;\n const acrossB = usable(lenB) ? lenB : cross;\n const fixedA = fixed?.(tree.a, axis);\n const fixedB = fixed?.(tree.b, axis);\n\n // The lengths of the two sides along the split, where the second starts, the ratio in effect and the divider.\n let lengthA: number;\n let lengthB: number;\n let startB: number;\n let ratio = unit(tree.ratio);\n let ruled = false; // the divider is the gutter strip at the ratio (a split no fixed length decides)\n const lead = fixedA ?? fixedB;\n if (fixedA && fixedB && fixedA.keep && fixedB.keep && usable(fixedA.length) && usable(fixedB.length)) {\n lengthA = fixedA.length;\n lengthB = fixedB.length;\n startB = origin + lengthA + gutter;\n ratio = extent > 0 ? (lengthA + gutter / 2) / extent : ratio;\n } else if (lead && usable(lead.length) && lead.length + gutter < extent) {\n const rest = Math.max(0, extent - lead.length - gutter);\n lengthA = lead === fixedA ? lead.length : rest;\n lengthB = lead === fixedA ? rest : lead.length;\n startB = origin + lengthA + gutter;\n ratio = (lengthA + gutter / 2) / extent;\n } else {\n if (floor) {\n const a = floor(tree.a, axis, tree);\n const b = floor(tree.b, axis, tree);\n const net = a.net === false || b.net === false ? ([0, 1] as const) : NET;\n ratio = clampByMin(Number.isFinite(tree.ratio ?? 0.5) ? (tree.ratio ?? 0.5) : 0.5, extent, gutter, px(a.min), px(b.min), net);\n }\n lengthA = Math.max(0, extent * ratio - gutter / 2);\n lengthB = Math.max(0, extent * (1 - ratio) - gutter / 2);\n startB = origin + extent * ratio + gutter / 2;\n ruled = true;\n }\n // The geometry is built only for a named split and only when the caller asked for it (`layoutSplitTree`).\n if (tree.id !== undefined && ctx.splits !== null) {\n const divider = ruled ? strip(area, x, origin + extent * ratio, gutter) : null;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio, divider });\n }\n if (x) {\n lay(tree.a, { x: area.x, y: area.y, width: lengthA, height: acrossA }, ctx, true);\n lay(tree.b, { x: startB, y: area.y, width: lengthB, height: acrossB }, ctx, true);\n } else {\n lay(tree.a, { x: area.x, y: area.y, width: acrossA, height: lengthA }, ctx, true);\n lay(tree.b, { x: area.x, y: startB, width: acrossB, height: lengthB }, ctx, true);\n }\n}\n","/**\n * Whether a drop on a pane leaves room: the rule a host asks before it offers a side of a pane as a drop place. See\n * docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { layoutSplit, type SplitOptions } from \"./layout\";\nimport type { PaneRegion } from \"./regions\";\nimport { dropOnPane, panesOf, removePane, type Split } from \"./split\";\n\n/** The layout options a drop is judged under, and `min`: the least width and height, px, a pane must keep. */\nexport interface DropOptions<K> extends SplitOptions<K> {\n readonly min: number;\n}\n\n/** A drop's verdict: `ok`, or not, with its `reason`. */\nexport interface DropVerdict {\n readonly ok: boolean;\n readonly reason?: string;\n}\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/**\n * Whether dropping `dragged` on pane `at`'s `region` leaves both at least `options.min` wide and high.\n *\n * - The center is fine unless `dragged` is `at`, or `at` is not in the tree (nothing to swap with).\n * - A side needs, in the layout of the tree without `dragged` (so `at` is measured where it will be when `dragged` is\n * lifted out), a span of `at` along the split of at least `2 * min` plus the gutter (the options' gap plus handle)\n * and across it of at least `min`; and in the layout of `dropOnPane(tree, dragged, at, region)` both `dragged` and\n * `at` at least `min` wide and high. That check is skipped when `area` has no width or no height. A pane that is\n * not in the tree counts as one being added; an `at` that is not in it (or is `dragged`) has no place to split.\n */\nexport function canDropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion, area: Rect, options: DropOptions<K>): DropVerdict {\n if (region === \"center\") {\n if (dragged === at) return { ok: false, reason: \"center swap blocked: a pane dropped on itself\" };\n return panesOf(tree).includes(at) ? { ok: true } : { ok: false, reason: \"center rejected: no pane to swap\" };\n }\n const target = layoutSplit(removePane(tree, dragged), area, options).get(at);\n if (!target) return { ok: false, reason: `${region} rejected: no pane to split` };\n const room = canSplitPane(target, region, options);\n if (!room.ok) return room;\n return dropFits(layoutSplit(dropOnPane(tree, dragged, at, region), area, options), dragged, at, area, { min: options.min, side: region });\n}\n\n/** What `canSplitPane` reads: `min` (as in `DropOptions`) and the gutter's parts, `gap` and `handle`, px. */\nexport interface SplitRoomOptions {\n readonly min: number;\n readonly gap?: number;\n readonly handle?: number;\n}\n\n/**\n * The room rule: whether a pane of rect `target` can take another on `side`, both at least `options.min` wide and\n * high. Along the split (width for left and right, height for top and bottom) the pane needs `2 * min` plus the\n * gutter (`gap` plus `handle`), across it `min`. The rect is the pane's as the host measures it, where it will be\n * when the dragged pane is lifted out. `canDropOnPane`'s first rule, for a side.\n */\nexport function canSplitPane(target: Rect, side: Side, options: SplitRoomOptions): DropVerdict {\n const min = px(options.min);\n const gutter = px(options.gap) + px(options.handle);\n const horizontal = side === \"left\" || side === \"right\";\n const along = horizontal ? target.width : target.height;\n const across = horizontal ? target.height : target.width;\n const need = min * 2 + gutter;\n if (along < need) return { ok: false, reason: `${side} rejected: axis span ${along.toFixed(1)}px < min ${need.toFixed(1)}px (2 panes + gutter ${gutter}px)` };\n if (across < min) return { ok: false, reason: `${side} rejected: cross span ${across.toFixed(1)}px < min ${min.toFixed(1)}px` };\n return { ok: true };\n}\n\n/** What `dropFits` reads: the `min` (as in `DropOptions`) and the `side` of `at` the drop is on, for the reason. */\nexport interface DropFitsOptions {\n readonly min: number;\n readonly side: Side;\n}\n\n/**\n * The fit rule: in `projected`, the rect of every pane in the layout the drop makes (the host's own projection of\n * `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and high. Fine\n * when `area` has no width or no height (there is nothing to measure). `canDropOnPane`'s last rule.\n */\nexport function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions): DropVerdict {\n if (!(area.width > 0 && area.height > 0)) return { ok: true };\n const min = px(options.min);\n const fits = (r: Rect | undefined): boolean => !!r && r.width >= min && r.height >= min;\n return fits(projected.get(dragged)) && fits(projected.get(at)) ? { ok: true } : { ok: false, reason: `${options.side} rejected: projected footprint of the two panes violates min ${min}px` };\n}\n","/**\n * A pane's drop regions: a center rectangle (a drop there swaps with the pane) and four side trapezoids (a drop there\n * splits the pane on that side), formed by the diagonals from each pane corner to the nearest corner of the center.\n * The five regions cover the pane with no gaps and no overlaps.\n *\n * Meant for `@n-uf/motion/drag`'s `placeOf(target, point, previous)`: one target per pane (`paneTargets`), its place\n * the region under the pointer, the previous region held for `hysteresis` px past its boundary so a pointer resting on\n * a boundary doesn't flicker. A region that takes no drop is the consumer's to answer with a null place.\n */\nimport { clamp, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Side } from \"../side\";\n\nexport type PaneRegion = \"center\" | Side;\n\n/** The sides in their tie-break order: at an exact diagonal the first wins (a corner resolves to `top`). */\nexport const PANE_SIDES: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"];\n\nexport interface PaneRegionOptions {\n /** The center rectangle's share of each pane axis (0.05 to 0.95); `centerX` / `centerY` override one axis. */\n readonly center?: number;\n readonly centerX?: number;\n readonly centerY?: number;\n /** The least the center spans on either axis, px (a small pane keeps a usable center). */\n readonly centerMin?: number;\n /** How far past its boundary the previous region holds, px. */\n readonly hysteresis?: number;\n /** Device pixels per px: the center's edges snap to that grid, as the browser draws them. */\n readonly pixelRatio?: number;\n /**\n * The pane's center rectangle as the host already has it (pane-local px, as `paneCenter` gives), used as it is in\n * place of measuring: `center`, `centerX`, `centerY`, `centerMin` and `pixelRatio` are not read. Only `paneRegion`\n * reads it; its `width` and `height` are the pane's own size for the hold toward the middle.\n */\n readonly paneCenter?: PaneCenter;\n}\n\nexport const PANE_REGION_DEFAULTS: Required<Omit<PaneRegionOptions, \"centerX\" | \"centerY\" | \"paneCenter\">> = { center: 0.34, centerMin: 24, hysteresis: 6, pixelRatio: 1 };\n\n/** The center rectangle of a pane of `size`, in pane-local px (origin at the pane's top-left corner). */\nexport interface PaneCenter {\n readonly width: number;\n readonly height: number;\n readonly left: number;\n readonly top: number;\n readonly right: number;\n readonly bottom: number;\n}\n\nconst snap = (v: number, ratio: number): number => Math.round(v * ratio) / ratio;\n\n/** Where the center rectangle of a pane of `size` lies, by these options. */\nexport function paneCenter(size: Size, options: PaneRegionOptions = {}): PaneCenter {\n const o = { ...PANE_REGION_DEFAULTS, ...options };\n const width = Math.max(0, size.width);\n const height = Math.max(0, size.height);\n const ratio = o.pixelRatio > 0 ? o.pixelRatio : 1;\n const rx = clamp(o.centerX ?? o.center, 0.05, 0.95);\n const ry = clamp(o.centerY ?? o.center, 0.05, 0.95);\n const cw = Math.min(width, Math.max(width * rx, Math.min(o.centerMin, width)));\n const ch = Math.min(height, Math.max(height * ry, Math.min(o.centerMin, height)));\n return { width, height, left: snap((width - cw) / 2, ratio), top: snap((height - ch) / 2, ratio), right: snap((width + cw) / 2, ratio), bottom: snap((height + ch) / 2, ratio) };\n}\n\n/** How deep past the center a point is toward each side, as a share of that side's band (positive: in that band). */\nfunction depths(p: Point, c: PaneCenter): { side: Side; depth: number }[] {\n return [\n { side: \"top\", depth: (c.top - p.y) / Math.max(c.top, 1) },\n { side: \"right\", depth: (p.x - c.right) / Math.max(c.width - c.right, 1) },\n { side: \"bottom\", depth: (p.y - c.bottom) / Math.max(c.height - c.bottom, 1) },\n { side: \"left\", depth: (c.left - p.x) / Math.max(c.left, 1) },\n ];\n}\n\n/** The region a pane-local point is in, by position alone. */\nfunction rawRegion(p: Point, c: PaneCenter): PaneRegion {\n if (p.x >= c.left && p.x <= c.right && p.y >= c.top && p.y <= c.bottom) return \"center\";\n let best: PaneRegion = \"center\";\n let deepest = 0;\n for (const d of depths(p, c)) {\n if (d.depth > deepest) {\n deepest = d.depth;\n best = d.side;\n }\n }\n return best;\n}\n\n/** `p` moved `by` px into `region` (toward the pane's middle for the center). */\nfunction toward(p: Point, region: PaneRegion, by: number, c: PaneCenter): Point {\n if (region === \"left\") return { x: p.x - by, y: p.y };\n if (region === \"right\") return { x: p.x + by, y: p.y };\n if (region === \"top\") return { x: p.x, y: p.y - by };\n if (region === \"bottom\") return { x: p.x, y: p.y + by };\n const dx = c.width / 2 - p.x;\n const dy = c.height / 2 - p.y;\n const len = Math.hypot(dx, dy);\n if (len <= by || len === 0) return { x: c.width / 2, y: c.height / 2 };\n return { x: p.x + (dx / len) * by, y: p.y + (dy / len) * by };\n}\n\n/**\n * The drop region of `pane` (in the same coordinates as `point`) the point is in. With a `previous` region, the point\n * has to be `hysteresis` px past that region's boundary before the region changes: no time-based debounce, only\n * geometry. A host that has measured the center itself passes it as `options.paneCenter`; the same center gives the\n * same region as the one measured here.\n */\nexport function paneRegion(pane: Rect, point: Point, previous: PaneRegion | null = null, options: PaneRegionOptions = {}): PaneRegion {\n const c = options.paneCenter ?? paneCenter(pane, options);\n const p = { x: point.x - pane.x, y: point.y - pane.y };\n const raw = rawRegion(p, c);\n const by = Math.max(0, options.hysteresis ?? PANE_REGION_DEFAULTS.hysteresis);\n if (previous === null || by === 0 || previous === raw) return raw;\n return rawRegion(toward(p, previous, by, c), c) === previous ? previous : raw;\n}\n","/**\n * Drop targets for tiling, in the root `Target` shape (what `@n-uf/motion/drag` takes). Both kinds come from one\n * helper: a pane target (`pane:<id>`, its hit the pane, the place in it its drop region) for the split tree, and an\n * insertion target (`at:<index>`, its hit and slot the dragged pane's rect with it inserted there) for an order layout.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Target } from \"../target\";\nimport type { OrderLayout, OrderOptions } from \"./order\";\n\n/** A split tree's target: drop on pane `pane` (the region under the pointer says how). */\nexport interface PaneTarget<K> extends Target {\n readonly pane: K;\n}\n\n/** An order layout's target: insert the dragged pane at `index`; `layout` is every pane's rect with it there. */\nexport interface OrderTarget<K> extends Target {\n readonly index: number;\n readonly layout: ReadonlyMap<K, Rect>;\n}\n\n/** The one shape both kinds share: a slot-sized drop with no precedence over any other. */\nconst tilingTarget = (id: string, hit: Rect, slot?: Rect): Target => ({ id, priority: 2, hit, ...(slot ? { slot } : {}) });\n\nexport interface PaneTargetsOptions<K> {\n /** A pane left out: the dragged one, when it is still laid out. */\n readonly except?: K;\n /**\n * A pane's key in its target's id (`pane:<key>`); default `String`. Keys must be unique across the panes: a drag\n * intent follows its targets by id, so two panes with one key would be one target.\n */\n readonly key?: (pane: K) => string;\n}\n\n/** One target per pane of `layout`, its id `pane:<key>`. */\nexport function paneTargets<K>(layout: ReadonlyMap<K, Rect>, options: PaneTargetsOptions<K> = {}): PaneTarget<K>[] {\n const key = options.key ?? String;\n return [...layout].filter(([k]) => k !== options.except).map(([pane, r]) => ({ ...tilingTarget(`pane:${key(pane)}`, r), pane }));\n}\n\n/**\n * One target per index `dragged` could be inserted at among `panes` (which don't hold it), laid out by `arrange` in\n * `area`. Each target's hit and slot is `dragged`'s rect with it there, so the targets cover the area as the layout\n * does. Ids are `at:<index>`, unique whatever the panes are.\n */\nexport function orderTargets<K>(arrange: OrderLayout, panes: readonly K[], dragged: K, area: Rect, options?: OrderOptions): OrderTarget<K>[] {\n return Array.from({ length: panes.length + 1 }, (_, index) => {\n const layout = arrange([...panes.slice(0, index), dragged, ...panes.slice(index)], area, options);\n const slot = layout.get(dragged)!;\n return { ...tilingTarget(`at:${index}`, slot, slot), index, layout };\n });\n}\n","import type { Rect, Size } from \"../geometry\";\n\n/**\n * The minimum-size give-way: while a pane is laid out below its minimum, the newest pane (highest `age`) floats and\n * the rest are laid out again. Stops when every pane keeps its minimum or one pane is left. `layout` lays out the\n * kept panes; the result says which are kept (in their order) and which float (newest first).\n */\nexport function giveWay<K>(panes: readonly K[], layout: (kept: readonly K[]) => ReadonlyMap<K, Rect>, min: (pane: K) => Size, age: (pane: K) => number): { kept: K[]; floats: K[] } {\n let kept = [...panes];\n const floats: K[] = [];\n for (;;) {\n const res = layout(kept);\n const broken = [...res].some(([k, r]) => r.width < min(k).width - 0.5 || r.height < min(k).height - 0.5);\n if (!broken || kept.length <= 1) return { kept, floats };\n const newest = kept.reduce((a, b) => (age(b) > age(a) ? b : a));\n kept = kept.filter((k) => k !== newest);\n floats.push(newest);\n }\n}\n","/**\n * One layout for a tiling drag's held frame and its commit, the layout half: `tilingDrag(tree, subject, options)` gives\n * the drag's base (the tree with the subject released, laid out), its home (the gap the release leaves) and\n * `after(held)`, THE layout of each held place: what a release there commits, and what a frame holding it draws.\n *\n * The host keeps its own tree type and its own changes; it hands them over as a `TilingTree` adapter. The library owns\n * the rules: what is released and when, which tree each change takes, home, the refusals, and the one layout per held\n * place. Geometry has one source: the adapter gives the tree as a `Split` (`split`), and the library lays it out with\n * `layoutSplitTree` under the drag's options (`SplitOptions` plus `min`, as `canDropOnPane` takes them).\n *\n * The hit half (targets, a pane's parts, `placeOf`) is not here yet. See docs/placement.md, Entry: tiling.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { canSplitPane, dropFits, type DropOptions } from \"./drop\";\nimport { layoutSplitTree, type SplitGeometry } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\n\n/** A stack as the adapter reports it: its id, its members in order, and the member it is drawn as. */\nexport interface TilingStack<K> {\n readonly id: string;\n readonly members: readonly K[];\n readonly active: K;\n}\n\n/**\n * What a drag moves: one pane (a member of a stack is torn out of it), or a whole stack, every member as one. A stack\n * subject carries the stack as the adapter reported it at the lift (`stackOf`), so the changes that place it after its\n * release (`beside`, `join`) have its members.\n */\nexport type TilingSubject<K> = { readonly kind: \"pane\"; readonly pane: K } | { readonly kind: \"stack\"; readonly stack: TilingStack<K> };\n\n/**\n * How a side drop sizes the split it makes. One kind today: the two panes take half each (the split `splitPane`\n * writes). A later rule may size the subject by its own length; it will be a new kind here, never an option.\n */\nexport type TilingSize = { readonly kind: \"half\" };\n\n/**\n * The host's tree, as a drag reads and changes it. Every function is pure: it never changes the tree it is given, and\n * returns a new tree (or the same one when nothing changes).\n *\n * Which tree each change takes, and why:\n * - `beside` and `join` take the **released** tree (`release`'s result): the subject leaves its old place first, so the\n * place it lands in is measured, and changed, without it. A pane beside its own old sibling then lands as if it were\n * new there, and a stack never holds the subject twice.\n * - `swap` takes the tree **with the subject still in it**: a swap exchanges two places, and the subject's old place is\n * exactly where the partner goes. With the subject released there would be no old place to give the partner.\n */\nexport interface TilingTree<T, K> {\n /** The tree as panes divide the area: a `Split` of the drawn panes (a stack stands in it as its active member's key). */\n split(tree: T): Split<K> | null;\n /** The stack `pane` is a member of, or null; leave it out when the tree has no stacks. */\n stackOf?(tree: T, pane: K): TilingStack<K> | null;\n /** `tree` without the subject: a pane leaves its place (or its stack), a stack leaves with every member. */\n release(tree: T, subject: TilingSubject<K>): T;\n /** The released tree with the subject placed on `side` of the drawn pane `at`, sized by `size`. */\n beside(released: T, subject: TilingSubject<K>, at: K, side: Side, size: TilingSize): T;\n /**\n * `tree` (the subject still in it) with the subject and the drawn pane `at` in each other's place.\n * - A pane subject and `at` each take the other's slot, in the split or in a stack. The swap moves `at` alone, never\n * the stack it stands for: when `at` is a stack's drawn member, the subject takes its place in that stack (drawn,\n * as `at` was) and the stack's other members stay; `at` goes to the subject's old slot (alone, or in the subject's\n * stack, at its index, when the subject is a member torn out of one).\n * - A whole stack subject trades its drawn slot in the split with `at`'s; when `at` is a stack's drawn member, the\n * two stacks trade places, each whole.\n */\n swap(tree: T, subject: TilingSubject<K>, at: K): T;\n /** The released tree with the subject joined to the drawn pane `at`'s stack (made one when `at` is alone), at `index` (default: last). Leave it out when the tree has no stacks: every join is refused `\"join\"`. */\n join?(released: T, subject: TilingSubject<K>, at: K, index?: number): T;\n /** Commit-time reconciliation: part of every `after` but home's, so what a frame draws is what a release stores. Default: none. */\n normalize?(tree: T): T;\n}\n\n/** What `tilingDrag` reads: the adapter, the stage, and the layout options (`SplitOptions` plus `min`, the least pane width and height a drop keeps). */\nexport interface TilingDragOptions<T, K> extends DropOptions<K> {\n readonly ops: TilingTree<T, K>;\n /** The stage the tree is laid out in, px. */\n readonly area: Rect;\n /** Panes that take no drop (a swap, a side or a join on one is refused `\"still\"`). Default: none. */\n readonly still?: (pane: K) => boolean;\n}\n\n/** A held place of a drag: where a release now lands. `at` is always a pane drawn in the base. */\nexport type TilingHeld<K> =\n | { readonly kind: \"home\" }\n | { readonly kind: \"swap\"; readonly at: K }\n | { readonly kind: \"beside\"; readonly at: K; readonly side: Side }\n | { readonly kind: \"join\"; readonly at: K; readonly index?: number };\n\n/**\n * Why a held place takes no release, as a code:\n * - `self`: the place is the subject's own (a swap or side of the subject itself, a swap with its own stack, a whole\n * stack joined to itself);\n * - `still`: `at` is a still pane;\n * - `missing`: `at` is not a pane drawn in the base;\n * - `join`: the adapter has no `join`;\n * - `room-along`, `room-across`: `at` is too short for two panes along the split, or too narrow across it, in the base\n * (`canSplitPane`): `need` and `have` px;\n * - `fit`: in the layout the release makes (a side, a swap or a join), `pane` (the subject's drawn key or `at`'s) is\n * below `min` wide or high, the fit rule of `dropFits`. A swap hands each pane the other's rect, so either may fall\n * below it; a join is judged on the stack's rect.\n */\nexport type TilingRefusal<K> =\n | { readonly code: \"self\" | \"still\" | \"missing\" | \"join\" }\n | { readonly code: \"room-along\" | \"room-across\"; readonly need: number; readonly have: number }\n | { readonly code: \"fit\"; readonly pane: K };\n\n/** A tree laid out: every drawn pane's rect, and the geometry of each split that has an id. */\nexport interface TilingLaidOut<T, K> {\n readonly tree: T;\n readonly layout: ReadonlyMap<K, Rect>;\n readonly splits: ReadonlyMap<string, SplitGeometry>;\n}\n\n/** A pane a commit moves, from where it was drawn at the lift to where the commit puts it. */\nexport interface TilingMove<K> {\n readonly pane: K;\n readonly from: Rect;\n readonly to: Rect;\n}\n\n/** THE layout of a held place: what a release commits, and what a frame holding it draws. */\nexport interface TilingAfter<T, K> extends TilingLaidOut<T, K> {\n readonly held: TilingHeld<K>;\n /**\n * Why a release here commits nothing, or null. A refused place's tree and layout are the lift's (what its release\n * keeps), its landing null and nothing moved; a frame holding it draws rest (the base).\n */\n readonly refusal: TilingRefusal<K> | null;\n /** The subject's rect in `layout`: its own when it is drawn, else its stack's. Null when refused. */\n readonly landing: Rect | null;\n /** Every other drawn pane whose rect differs from the lift's (the swap partner, the panes that give room), in `layout`'s order. */\n readonly moved: readonly TilingMove<K>[];\n}\n\n/** A drag of one subject: its base, its home, and the one layout of each held place. */\nexport interface TilingDrag<T, K> {\n readonly subject: TilingSubject<K>;\n /** The tree at the lift, laid out: what is drawn before the drag, and what a release on home commits. */\n readonly lift: TilingLaidOut<T, K>;\n /** The hit basis, fixed for the drag: the tree with the subject released, laid out. What a frame draws at rest (nothing held, or a refused place). */\n readonly base: TilingLaidOut<T, K>;\n /**\n * The gap the release leaves: the subject's lift rect when releasing it takes a drawn pane away (a pane alone, a\n * whole stack), null when it takes none (a member torn out of a stack that stays drawn).\n */\n readonly home: Rect | null;\n /** THE layout of `held`. Remembered per held place: the same place gives the same object. */\n after(held: TilingHeld<K>): TilingAfter<T, K>;\n}\n\nconst sameRect = (a: Rect, b: Rect): boolean => Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS && Math.abs(a.width - b.width) <= EPS && Math.abs(a.height - b.height) <= EPS;\n\n/** A px option as the drop rules read it: finite and above 0, else 0. */\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/**\n * The drag of `subject` in `tree`: its lift and base layouts, its home, and `after(held)`, the one layout of each held\n * place. `tree` is never changed; `after({ kind: \"home\" }).tree` is `tree` itself.\n *\n * - **`after(held).tree`** is what a release commits: `normalize(change)`, where the change is `beside` or `join` on\n * the released tree, or `swap` on the lift tree (see `TilingTree` for why). Home's is the lift tree, never normalized.\n * - **`layout`** is that tree laid out, so a frame that draws it draws exactly what the release stores.\n * - **Refusals** are judged on the base (room) and on the change's own layout (fit), never on another tree.\n *\n * Throws when the subject is not in `tree` (neither drawn nor a member of a drawn stack): a drag has nothing to lift.\n */\nexport function tilingDrag<T, K>(tree: T, subject: TilingSubject<K>, options: TilingDragOptions<T, K>): TilingDrag<T, K> {\n const { ops, area } = options;\n const normalize = (t: T): T => (ops.normalize ? ops.normalize(t) : t);\n const lay = (t: T): TilingLaidOut<T, K> => {\n const { panes, splits } = layoutSplitTree(ops.split(t), area, options);\n return { tree: t, layout: panes, splits };\n };\n const stackOf = (t: T, pane: K): TilingStack<K> | null => ops.stackOf?.(t, pane) ?? null;\n /** The key `pane` is drawn as in `t`: its stack's active member, or itself. */\n const drawnAs = (t: T, pane: K): K => stackOf(t, pane)?.active ?? pane;\n const subjectKey = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n\n const lift = lay(tree);\n const liftRect = lift.layout.get(drawnAs(tree, subjectKey));\n if (!liftRect) {\n const what = subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`;\n throw new Error(`tilingDrag: the subject (${what}) is not in the tree: it is neither drawn nor a member of a drawn stack`);\n }\n const base = lay(ops.release(tree, subject));\n const takesPane = panesOf(ops.split(base.tree)).length < panesOf(ops.split(tree)).length;\n const home = takesPane ? { ...liftRect } : null;\n\n /** Every drawn pane of `laid` but the subject's whose rect differs from where it was drawn at the lift. */\n const movedIn = (laid: TilingLaidOut<T, K>): TilingMove<K>[] => {\n const own = drawnAs(laid.tree, subjectKey);\n const out: TilingMove<K>[] = [];\n for (const [pane, to] of laid.layout) {\n if (pane === own) continue;\n const from = lift.layout.get(lift.layout.has(pane) ? pane : drawnAs(tree, pane));\n if (from && !sameRect(from, to)) out.push({ pane, from, to });\n }\n return out;\n };\n\n const inSubject = (pane: K): boolean => (subject.kind === \"pane\" ? pane === subject.pane : subject.stack.members.includes(pane));\n\n /** The refusal a held place has before any change is made: whose `at` it names, and whether the adapter can make it. */\n const refusalBefore = (held: Exclude<TilingHeld<K>, { kind: \"home\" }>): TilingRefusal<K> | null => {\n const at = held.at;\n if (inSubject(at)) return { code: \"self\" };\n if (held.kind === \"swap\") {\n // A swap with the stack the subject is torn from: the subject's own place.\n const own = stackOf(tree, subjectKey);\n if (own && stackOf(tree, at)?.id === own.id) return { code: \"self\" };\n }\n if (!base.layout.has(at)) return { code: \"missing\" };\n if (options.still?.(at)) return { code: \"still\" };\n if (held.kind === \"join\" && !ops.join) return { code: \"join\" };\n return null;\n };\n\n /** A refused place: the release commits nothing, so its layout is the lift's. */\n const refused = (held: TilingHeld<K>, refusal: TilingRefusal<K>): TilingAfter<T, K> => ({ ...lift, held, refusal, landing: null, moved: [] });\n\n /** The room rule on `at`'s base rect (`canSplitPane`), as a code with the numbers. */\n const roomFor = (at: K, side: Side): TilingRefusal<K> | null => {\n const r = base.layout.get(at)!;\n if (canSplitPane(r, side, options).ok) return null;\n const along = side === \"left\" || side === \"right\";\n const gutter = px(options.gap) + px(options.handle);\n const min = px(options.min);\n const span = along ? r.width : r.height;\n return span < min * 2 + gutter ? { code: \"room-along\", need: min * 2 + gutter, have: span } : { code: \"room-across\", need: min, have: along ? r.height : r.width };\n };\n\n const make = (held: TilingHeld<K>): TilingAfter<T, K> => {\n if (held.kind === \"home\") return { ...lift, held, refusal: null, landing: liftRect, moved: [] };\n const before = refusalBefore(held) ?? (held.kind === \"beside\" ? roomFor(held.at, held.side) : null);\n if (before) return refused(held, before);\n const changed =\n held.kind === \"swap\"\n ? ops.swap(tree, subject, held.at)\n : held.kind === \"beside\"\n ? ops.beside(base.tree, subject, held.at, held.side, { kind: \"half\" })\n : ops.join!(base.tree, subject, held.at, held.index);\n const laid = lay(normalize(changed));\n const own = drawnAs(laid.tree, subjectKey);\n // The fit rule, on every change: in the layout it makes, the subject and `at` (each as it is drawn there) keep `min`.\n // `side` only words `dropFits`' reason, which is not read here.\n const partner = drawnAs(laid.tree, held.at);\n if (!dropFits(laid.layout, own, partner, area, { min: options.min, side: held.kind === \"beside\" ? held.side : \"left\" }).ok) {\n const small = (r: Rect | undefined): boolean => !r || r.width < px(options.min) || r.height < px(options.min);\n return refused(held, { code: \"fit\", pane: small(laid.layout.get(own)) ? own : partner });\n }\n return { ...laid, held, refusal: null, landing: laid.layout.get(own) ?? null, moved: movedIn(laid) };\n };\n\n // Remembered per held place: by kind (and side or index), then by `at`, so keys need no string form.\n const homeAfter = make({ kind: \"home\" });\n const memo = new Map<string, Map<K, TilingAfter<T, K>>>();\n const after = (held: TilingHeld<K>): TilingAfter<T, K> => {\n if (held.kind === \"home\") return homeAfter;\n const k = held.kind === \"beside\" ? `beside:${held.side}` : held.kind === \"join\" ? `join:${held.index ?? \"\"}` : \"swap\";\n let byAt = memo.get(k);\n if (!byAt) memo.set(k, (byAt = new Map()));\n let a = byAt.get(held.at);\n if (!a) byAt.set(held.at, (a = make(held)));\n return a;\n };\n\n return { subject, lift, base, home, after };\n}\n","/**\n * The reference `TilingTree` adapter: placement's own `Split`, with optional stacks beside it. Tests, labs and hosts\n * whose tree is a `Split` use it as it is; a host with its own tree reads it as the worked example of each change.\n * See docs/placement.md, Entry: tiling.\n */\nimport type { TilingStack, TilingSubject, TilingTree } from \"./drag\";\nimport { removePane, splitPane, type Split } from \"./split\";\n\n/**\n * A split tree with stacks: `split` divides the area among the drawn panes, and each stack stands in it as its\n * `active` member's key. A pane in no stack is drawn alone. A stack of one is kept until `normalize` makes it a pane.\n */\nexport interface StackedSplit<K> {\n readonly split: Split<K> | null;\n readonly stacks?: readonly TilingStack<K>[];\n}\n\n/** `split` with every pane key mapped by `fn` (the same object where nothing changes). */\nfunction mapKeys<K>(split: Split<K> | null, fn: (k: K) => K): Split<K> | null {\n if (!split) return split;\n if (\"pane\" in split) {\n const k = fn(split.pane);\n return k === split.pane ? split : { pane: k };\n }\n const a = mapKeys(split.a, fn)!;\n const b = mapKeys(split.b, fn)!;\n return a === split.a && b === split.b ? split : { ...split, a, b };\n}\n\nconst stacksOf = <K>(t: StackedSplit<K>): readonly TilingStack<K>[] => t.stacks ?? [];\nconst of = <K>(split: Split<K> | null, stacks: readonly TilingStack<K>[]): StackedSplit<K> => (stacks.length ? { split, stacks } : { split });\nconst membersOf = <K>(s: TilingSubject<K>): readonly K[] => (s.kind === \"pane\" ? [s.pane] : s.stack.members);\nconst drawnOf = <K>(s: TilingSubject<K>): K => (s.kind === \"pane\" ? s.pane : s.stack.active);\n\n/**\n * The reference adapter over `StackedSplit<K>`:\n * - `release`: a whole stack leaves the split (its drawn key, `removePane`) and the stack list; a pane in a stack leaves\n * its members (the next member, else the one before, is drawn when it was the active one); a pane alone leaves the split;\n * - `beside`: `splitPane` on `at`'s side (a half split), a whole stack drawn as its active member and kept whole;\n * - `swap`: a pane trades keys with `at` wherever each is (the split, a stack's members), so each takes the other's\n * place; a whole stack trades its drawn place in the split with `at`'s;\n * - `join`: the subject's members go into `at`'s stack at `index` (default last; clamped), the first of them drawn; a\n * pane `at` alone becomes a stack, its id `stack:<at>` (made unique);\n * - `normalize`: a stack of fewer than two members becomes its pane; the same object when there is none.\n */\nexport function splitTreeOps<K>(): TilingTree<StackedSplit<K>, K> {\n return {\n split: (t) => t.split,\n stackOf: (t, pane) => stacksOf(t).find((s) => s.members.includes(pane)) ?? null,\n release(t, s) {\n if (s.kind === \"stack\") {\n const stack = stacksOf(t).find((x) => x.id === s.stack.id);\n return of(removePane(t.split, stack?.active ?? s.stack.active), stacksOf(t).filter((x) => x !== stack));\n }\n const stack = stacksOf(t).find((x) => x.members.includes(s.pane));\n if (!stack) return of(removePane(t.split, s.pane), stacksOf(t));\n const i = stack.members.indexOf(s.pane);\n const members = stack.members.filter((m) => m !== s.pane);\n if (members.length === 0) return of(removePane(t.split, s.pane), stacksOf(t).filter((x) => x !== stack));\n const active = stack.active === s.pane ? (members[i] ?? members[i - 1]!) : stack.active;\n const was = stack.active;\n return of(\n mapKeys(t.split, (k) => (k === was ? active : k)),\n stacksOf(t).map((x) => (x === stack ? { id: stack.id, members, active } : x)),\n );\n },\n beside(released, s, at, side) {\n const split = splitPane(released.split, at, drawnOf(s), side);\n return of(split, s.kind === \"pane\" ? stacksOf(released) : [...stacksOf(released), s.stack]);\n },\n swap(t, s, at) {\n if (s.kind === \"stack\") {\n const x = stacksOf(t).find((st) => st.id === s.stack.id)?.active ?? s.stack.active;\n return of(mapKeys(t.split, (k) => (k === x ? at : k === at ? x : k)), stacksOf(t));\n }\n const x = s.pane;\n const trade = (k: K): K => (k === x ? at : k === at ? x : k);\n return of(\n mapKeys(t.split, trade),\n stacksOf(t).map((st) => ({ id: st.id, members: st.members.map(trade), active: trade(st.active) })),\n );\n },\n join(released, s, at, index) {\n const moving = membersOf(s);\n const target = stacksOf(released).find((x) => x.members.includes(at));\n const into = target ? target.members : [at];\n const i = Math.max(0, Math.min(into.length, index ?? into.length));\n const members = [...into.slice(0, i), ...moving, ...into.slice(i)];\n const active = moving[0]!;\n const drawn = target ? target.active : at;\n const ids = new Set(stacksOf(released).map((x) => x.id));\n let id = target?.id ?? `stack:${String(at)}`;\n for (let n = 2; !target && ids.has(id); n++) id = `stack:${String(at)}:${n}`;\n const stack: TilingStack<K> = { id, members, active };\n return of(\n mapKeys(released.split, (k) => (k === drawn ? active : k)),\n target ? stacksOf(released).map((x) => (x === target ? stack : x)) : [...stacksOf(released), stack],\n );\n },\n normalize(t) {\n const kept = stacksOf(t).filter((s) => s.members.length >= 2);\n return kept.length === stacksOf(t).length ? t : of(t.split, kept);\n },\n };\n}\n","/**\n * The properties of a tiling drag's layout half, run on any `TilingTree` adapter: a host runs them on its own adapter\n * and trees, the library's tests on the reference one. Pure: no test runner, no DOM. See docs/placement.md, Entry: tiling.\n */\nimport { EPS, overlap, type Rect } from \"../geometry\";\nimport { PANE_SIDES } from \"./regions\";\nimport { layoutSplitTree } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\nimport { tilingDrag, type TilingDragOptions, type TilingHeld, type TilingSubject } from \"./drag\";\n\n/** The properties, by name (each is a key of `TilingConformance.counts`). */\nexport const TILING_PROPERTIES = [\n /** `after(home).tree` is the lift tree itself, its layout the lift's, never normalized. */\n \"home-is-lift\",\n /** `home` is the subject's lift rect when the release takes a drawn pane away, else null. */\n \"home-is-the-gap\",\n /** Home lies only over base panes whose rect changed when the subject was released. */\n \"home-over-changed\",\n /** `after(held).layout` is `after(held).tree` laid out; the landing is the subject's rect there; a refused place is the lift. */\n \"one-layout\",\n /** A swap puts the partner in the subject's lift rect and the subject in the partner's, and the others keep theirs. Not checked under per-child layout callbacks (`fixed`, `fixedAcross`, `floor`), which may move the ratios. */\n \"swap-exchanges\",\n /** A swap puts the partner in the subject's old slot of the split (as it is drawn there) and the subject in the partner's. Checked under every option, the per-child callbacks included. */\n \"swap-trades-slots\",\n /** A pane swapped with a stack's drawn member takes its place in that stack, and the stack's other members stay, in order; a member torn out of a stack leaves the partner in its place there. */\n \"swap-keeps-stack-mates\",\n /**\n * The subject is in every tree exactly once: no key (a drawn pane, or a member of a stack) is in an `after(held).tree`\n * twice; the base holds none of the subject's members (a torn member's stack mates stay); and every `after(held).tree`\n * holds the base's keys and the subject's, and no other. Catches an adapter whose `release` leaves the subject in.\n */\n \"subject-once\",\n /** `beside` and `join` commit `normalize(change(release(tree)))`: the subject is released first, then placed. */\n \"release-first\",\n /** A whole stack moves as one: after any change its members are in one stack, in their order. */\n \"stack-moves-whole\",\n /** `normalize` changes nothing on any `after(held).tree`. */\n \"normalize-idempotent\",\n /** The drag never changes the tree it is given, and remembers each held place (the same place, the same object). */\n \"nothing-changes\",\n] as const;\n\nexport type TilingProperty = (typeof TILING_PROPERTIES)[number];\n\n/** A conformance run: whether every property held, the first failures (in words), and per property how many checks ran and failed. */\nexport interface TilingConformance {\n readonly ok: boolean;\n readonly failures: readonly string[];\n readonly counts: Readonly<Record<TilingProperty, { readonly checked: number; readonly failed: number }>>;\n}\n\n/** Structural equality of plain data: primitives, arrays, plain objects, Maps and Sets. */\nfunction sameData(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (a instanceof Map || b instanceof Map) {\n if (!(a instanceof Map && b instanceof Map) || a.size !== b.size) return false;\n for (const [k, v] of a) if (!b.has(k) || !sameData(v, b.get(k))) return false;\n return true;\n }\n if (a instanceof Set || b instanceof Set) {\n if (!(a instanceof Set && b instanceof Set) || a.size !== b.size) return false;\n for (const v of a) if (!b.has(v)) return false;\n return true;\n }\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const ka = Object.keys(a).filter((k) => (a as Record<string, unknown>)[k] !== undefined);\n const kb = Object.keys(b).filter((k) => (b as Record<string, unknown>)[k] !== undefined);\n if (ka.length !== kb.length) return false;\n return ka.every((k) => sameData((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]));\n}\n\n/** A deep copy of plain data (arrays, plain objects, Maps, Sets), to prove the drag left its tree alone. */\nfunction copy<V>(v: V): V {\n if (typeof v !== \"object\" || v === null) return v;\n if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copy(x)])) as V;\n if (v instanceof Set) return new Set([...v].map(copy)) as V;\n if (Array.isArray(v)) return v.map(copy) as V;\n return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, copy(x)])) as V;\n}\n\nconst near = (a: Rect | undefined | null, b: Rect | undefined | null, by = 0.5): boolean =>\n !!a && !!b && Math.abs(a.x - b.x) <= by && Math.abs(a.y - b.y) <= by && Math.abs(a.width - b.width) <= by && Math.abs(a.height - b.height) <= by;\n\n/** The way from the root of `split` to the pane `key` (`a` and `b` at each split), or null when it is not drawn. */\nfunction pathOf<K>(split: Split<K> | null, key: K): readonly (\"a\" | \"b\")[] | null {\n if (!split) return null;\n if (\"pane\" in split) return split.pane === key ? [] : null;\n for (const side of [\"a\", \"b\"] as const) {\n const rest = pathOf(split[side], key);\n if (rest) return [side, ...rest];\n }\n return null;\n}\n\n/** The pane at the end of `path` in `split`, or undefined when the path does not end on a pane. */\nfunction paneAt<K>(split: Split<K> | null, path: readonly (\"a\" | \"b\")[]): K | undefined {\n let node = split;\n for (const side of path) {\n if (!node || \"pane\" in node) return undefined;\n node = node[side];\n }\n return node && \"pane\" in node ? node.pane : undefined;\n}\n\nconst sameList = <K>(a: readonly K[], b: readonly K[]): boolean => a.length === b.length && a.every((k, i) => Object.is(k, b[i]));\n\nconst show = (h: TilingHeld<unknown>): string =>\n h.kind === \"home\" ? \"home\" : `${h.kind} ${String(h.at)}${h.kind === \"beside\" ? ` ${h.side}` : h.kind === \"join\" && h.index !== undefined ? ` @${h.index}` : \"\"}`;\n\n/** Every subject a tree offers: each pane drawn alone, each stack whole, and each member of a stack torn out of it. */\nexport function tilingSubjects<T, K>(tree: T, options: Pick<TilingDragOptions<T, K>, \"ops\">): TilingSubject<K>[] {\n const { ops } = options;\n const out: TilingSubject<K>[] = [];\n for (const pane of panesOf(ops.split(tree))) {\n const stack = ops.stackOf?.(tree, pane) ?? null;\n if (!stack) out.push({ kind: \"pane\", pane });\n else out.push({ kind: \"stack\", stack }, ...stack.members.map((m): TilingSubject<K> => ({ kind: \"pane\", pane: m })));\n }\n return out;\n}\n\n/**\n * Runs every property on every subject of every tree (`tilingSubjects`) and every held place of its drag: home, and for\n * each pane drawn in the base a swap, the four sides and a join (last and first). Trees are taken as committed ones,\n * so `normalize` (if any) must leave them as they are. Gives the first `limit` failures (default 20) in words.\n */\nexport function tilingConformance<T, K>(trees: Iterable<T>, options: TilingDragOptions<T, K>, limit = 20): TilingConformance {\n const { ops, area } = options;\n const counts = Object.fromEntries(TILING_PROPERTIES.map((p) => [p, { checked: 0, failed: 0 }])) as Record<TilingProperty, { checked: number; failed: number }>;\n const failures: string[] = [];\n const norm = (t: T): T => (ops.normalize ? ops.normalize(t) : t);\n const lay = (t: T) => layoutSplitTree(ops.split(t), area, options).panes;\n const drawnAs = (t: T, k: K): K => ops.stackOf?.(t, k)?.active ?? k;\n const callbacks = !!(options.fixed || options.fixedAcross || options.floor);\n /** Every key of `t`: each drawn pane, a stack counted as its members. */\n const keysOf = (t: T): K[] => panesOf(ops.split(t)).flatMap((p) => ops.stackOf?.(t, p)?.members ?? [p]);\n /** The keys `keys` holds more than once. */\n const twice = (keys: readonly K[]): K[] => keys.filter((k, i) => keys.indexOf(k) !== i);\n let n = 0;\n for (const tree of trees) {\n const snapshot = copy(tree);\n for (const subject of tilingSubjects(tree, options)) {\n const name = `tree ${n}, ${subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`}`;\n const check = (p: TilingProperty, ok: boolean, why: () => string): void => {\n counts[p].checked++;\n if (ok) return;\n counts[p].failed++;\n if (failures.length < limit) failures.push(`${p}: ${name}: ${why()}`);\n };\n const drag = tilingDrag(tree, subject, options);\n const key = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n const liftOf = (k: K): Rect | undefined => drag.lift.layout.get(drag.lift.layout.has(k) ? k : drawnAs(tree, k));\n const subjectLift = liftOf(key);\n\n // The subject, exactly once: out of the base, and in every after's tree beside the base's keys.\n const members: readonly K[] = subject.kind === \"pane\" ? [subject.pane] : subject.stack.members;\n const baseKeys = keysOf(drag.base.tree);\n const kept = baseKeys.filter((k) => members.includes(k));\n check(\"subject-once\", kept.length === 0 && twice(baseKeys).length === 0, () => `the base holds ${kept.length ? `the subject's ${kept.map(String).join(\", \")}` : `${twice(baseKeys).map(String).join(\", \")} twice`}`);\n const want = new Set<K>([...baseKeys, ...members]);\n\n // Home.\n const home = drag.after({ kind: \"home\" });\n check(\"home-is-lift\", home.tree === tree && sameData(home.layout, drag.lift.layout) && home.refusal === null, () => \"after(home) is not the lift tree laid out\");\n const takes = panesOf(ops.split(drag.base.tree)).length < panesOf(ops.split(tree)).length;\n check(\"home-is-the-gap\", takes ? near(drag.home, subjectLift, EPS) : drag.home === null, () => `home ${JSON.stringify(drag.home)}, the release ${takes ? \"takes\" : \"takes no\"} drawn pane`);\n if (drag.home) {\n for (const [pane, r] of drag.base.layout) {\n if (overlap(drag.home, r) <= EPS) continue;\n check(\"home-over-changed\", !near(r, liftOf(pane), EPS), () => `home lies over ${String(pane)}, which the release left at ${JSON.stringify(r)}`);\n }\n }\n\n // Every held place on every base pane.\n const held: TilingHeld<K>[] = [{ kind: \"home\" }];\n for (const at of drag.base.layout.keys()) {\n held.push({ kind: \"swap\", at }, ...PANE_SIDES.map((side): TilingHeld<K> => ({ kind: \"beside\", at, side })));\n if (ops.join) held.push({ kind: \"join\", at }, { kind: \"join\", at, index: 0 });\n }\n for (const h of held) {\n const a = drag.after(h);\n check(\"nothing-changes\", drag.after(h) === a, () => `${show(h)}: after() gave a new object for the same place`);\n check(\"normalize-idempotent\", sameData(norm(a.tree), a.tree), () => `${show(h)}: normalize changes after().tree`);\n const keys = keysOf(a.tree);\n const extra = keys.filter((k) => !want.has(k));\n const lost = [...want].filter((k) => !keys.includes(k));\n check(\n \"subject-once\",\n twice(keys).length === 0 && extra.length === 0 && lost.length === 0,\n () => `${show(h)}: after().tree holds ${[twice(keys).length ? `${twice(keys).map(String).join(\", \")} twice` : \"\", extra.length ? `${extra.map(String).join(\", \")} it should not` : \"\", lost.length ? `no ${lost.map(String).join(\", \")}` : \"\"].filter(Boolean).join(\"; \")}`,\n );\n if (a.refusal) {\n check(\"one-layout\", a.tree === tree && a.landing === null && a.moved.length === 0, () => `${show(h)}: refused (${a.refusal!.code}) but not the lift`);\n continue;\n }\n const own = drawnAs(a.tree, key);\n check(\"one-layout\", sameData(a.layout, lay(a.tree)) && near(a.landing, a.layout.get(own), EPS), () => `${show(h)}: the layout or the landing is not after().tree's`);\n // Per-child layout callbacks (floors, fixed lengths) read which pane is where, so a swap may move the split\n // ratios themselves: the exchange is then what those callbacks make of it, and is not checked.\n if (h.kind === \"swap\" && !callbacks) {\n const partner = drawnAs(a.tree, h.at);\n const exchanged = near(a.layout.get(partner), subjectLift) && near(a.layout.get(own), liftOf(h.at));\n const others = [...a.layout].every(([p, r]) => p === own || p === partner || near(r, liftOf(p)));\n check(\"swap-exchanges\", exchanged && others, () => `${show(h)}: partner at ${JSON.stringify(a.layout.get(partner))} (subject was ${JSON.stringify(subjectLift)}), subject at ${JSON.stringify(a.layout.get(own))}${others ? \"\" : \", and another pane moved\"}`);\n }\n if (h.kind === \"swap\") {\n // The slots themselves, which no layout callback moves: the partner where the subject was drawn, and back.\n const liftSplit = ops.split(tree);\n const afterSplit = ops.split(a.tree);\n const subjectSlot = pathOf(liftSplit, drawnAs(tree, key));\n const partnerSlot = pathOf(liftSplit, h.at);\n const partnerThere = !!subjectSlot && paneAt(afterSplit, subjectSlot) === drawnAs(a.tree, h.at);\n const subjectThere = !!partnerSlot && paneAt(afterSplit, partnerSlot) === drawnAs(a.tree, key);\n check(\"swap-trades-slots\", partnerThere && subjectThere, () => `${show(h)}: ${partnerThere ? \"\" : `the partner is not in the subject's old slot (${String(subjectSlot && paneAt(afterSplit, subjectSlot))} is)`}${partnerThere || subjectThere ? \"\" : \"; \"}${subjectThere ? \"\" : `the subject is not in the partner's old slot (${String(partnerSlot && paneAt(afterSplit, partnerSlot))} is)`}`);\n if (subject.kind === \"pane\" && ops.stackOf) {\n // Each pane that stood in a stack is replaced there by the other, the stack's other members in place.\n for (const [from, to] of [\n [h.at, subject.pane],\n [subject.pane, h.at],\n ] as const) {\n const was = ops.stackOf(tree, from);\n if (!was) continue;\n const now = ops.stackOf(a.tree, to);\n const expect = was.members.map((m) => (m === from ? to : m));\n check(\"swap-keeps-stack-mates\", !!now && sameList(now.members, expect), () => `${show(h)}: ${String(to)} is in ${now ? `[${now.members.map(String).join(\", \")}]` : \"no stack\"}, expected [${expect.map(String).join(\", \")}]`);\n }\n }\n }\n if (h.kind === \"beside\" || h.kind === \"join\") {\n const released = ops.release(tree, subject);\n const changed = h.kind === \"beside\" ? ops.beside(released, subject, h.at, h.side, { kind: \"half\" }) : ops.join!(released, subject, h.at, h.index);\n check(\"release-first\", sameData(a.tree, norm(changed)), () => `${show(h)}: after().tree is not normalize(change(release(tree)))`);\n }\n if (subject.kind === \"stack\" && h.kind !== \"home\") {\n const ms = subject.stack.members;\n const st = ops.stackOf?.(a.tree, ms[0]!) ?? null;\n const i = st ? st.members.indexOf(ms[0]!) : -1;\n const whole = !!st && ms.every((m, j) => st.members[i + j] === m);\n check(\"stack-moves-whole\", whole, () => `${show(h)}: the stack's members are not together in one stack`);\n }\n }\n check(\"nothing-changes\", sameData(tree, snapshot), () => \"the drag changed the tree it was given\");\n }\n n++;\n }\n return { ok: failures.length === 0 && Object.values(counts).every((c) => c.failed === 0), failures, counts };\n}\n","/**\n * The nearest pane in a direction: the rule a host moves focus by. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\n\n/** A direction on the plane: `\"up\"` is toward smaller y. */\nexport type Direction = \"left\" | \"right\" | \"up\" | \"down\";\n\n/**\n * The pane nearest `from` in `direction`, or null when none lies that way. A candidate's center has to be strictly on\n * that side of `from`'s center. Its score is the center distance along the direction, plus a quarter of the center\n * distance across it, plus 100 when it does not overlap `from` across the direction (the overlap strictly above 0);\n * the lowest score wins, ties to the first in the map's order. A pane that is not in `rects` has no neighbor.\n *\n * The host chooses which rects to pass. One option: lay the tree out in a unit square (`{ x: 0, y: 0, width: 1,\n * height: 1 }`) with the host's px floors. A floor of tens of px cannot fit in a unit square, so a split's two floors\n * cannot both fit and it lays out at 0.5 whatever its ratio; fixed lengths in px along a split do not fit either, and\n * the area's size and the gap drop out. Fixed lengths across a split are not checked against the cross extent, so\n * they still apply in a unit square, and a host leaves `fixedAcross` out there. The rects of the real layout work too.\n */\nexport function neighbor<K>(rects: ReadonlyMap<K, Rect>, from: K, direction: Direction): K | null {\n const origin = rects.get(from);\n if (!origin) return null;\n const horizontal = direction === \"left\" || direction === \"right\";\n // Centers and ends as sums of edges (right = x + width), so a host that keeps edge rects gets the same bits.\n const center = (r: Rect, x: boolean): number => (x ? (r.x + (r.x + r.width)) / 2 : (r.y + (r.y + r.height)) / 2);\n const reach = (r: Rect, x: boolean): [number, number] => (x ? [r.x, r.x + r.width] : [r.y, r.y + r.height]);\n const fromAlong = center(origin, horizontal);\n const fromAcross = center(origin, !horizontal);\n const [originStart, originEnd] = reach(origin, !horizontal);\n const sign = direction === \"left\" || direction === \"up\" ? -1 : 1;\n let best: K | null = null;\n let bestScore = Number.POSITIVE_INFINITY;\n for (const [key, r] of rects) {\n if (key === from) continue;\n const along = center(r, horizontal);\n if (sign < 0 ? along >= fromAlong : along <= fromAlong) continue;\n const [start, end] = reach(r, !horizontal);\n const overlap = Math.max(0, Math.min(originEnd, end) - Math.max(originStart, start));\n const score = Math.abs(along - fromAlong) + Math.abs(center(r, !horizontal) - fromAcross) * 0.25 + (overlap > 0 ? 0 : 100);\n if (score < bestScore) {\n bestScore = score;\n best = key;\n }\n }\n return best;\n}\n"],"mappings":";;;;;;;AAmCO,IAA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B,UAAM,QAAQ,OAAO,GAAG,UAAU;AAClC,QAAI,OAAO,IAAI,SAAS,YAAY,SAAS,UAAW;AACxD,UAAM,CAAC,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,UAAU;AACzC,UAAMC,WAAU,KAAK,IAAI,GAAG,KAAK,IAAI,WAAW,GAAG,IAAI,KAAK,IAAI,aAAa,KAAK,CAAC;AACnF,UAAM,QAAQ,KAAK,IAAI,QAAQ,SAAS,IAAI,KAAK,IAAI,OAAO,GAAG,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQA,WAAU,IAAI,IAAI;AACtH,QAAI,QAAQ,WAAW;AACrB,kBAAY;AACZ,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":["px","px","lay","stack","x","lay","overlap"]}
1
+ {"version":3,"sources":["../src/tiling/order.ts","../src/tiling/split.ts","../src/tiling/layout.ts","../src/tiling/drop.ts","../src/tiling/regions.ts","../src/tiling/hit.ts","../src/tiling/targets.ts","../src/tiling/give-way.ts","../src/tiling/drag.ts","../src/tiling/reference.ts","../src/tiling/conformance.ts","../src/tiling/hit-conformance.ts","../src/tiling/neighbor.ts"],"sourcesContent":["/**\n * The order layouts: panes in order and an area in, a rect per pane out. Pure rect functions; a drop on one reorders\n * (the dragged pane inserted at an index, see `orderTargets`).\n */\nimport type { Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\n\n/**\n * How a layout spaces its panes: `gap` px between neighbors (default 0), `ratio` the master's share (default 0.5),\n * `handle` px a split's divider takes beside the gap (default 0; only a split tree reads it).\n */\nexport interface TileOptions {\n readonly gap?: number;\n readonly ratio?: number;\n readonly handle?: number;\n}\n\n/**\n * The master area: `count` panes (rounded, kept within 1..n; default 1) on `side` (default `\"left\"`). Left and right\n * make it a column of panes stacked vertically; top and bottom a row of panes side by side. The one home of the\n * concept: `masterStack` takes it in its options (`OrderOptions`), a split that lays out as master and stack in its\n * `master` field.\n */\nexport interface MasterOptions {\n readonly count?: number;\n readonly side?: Side;\n}\n\n/** What the order layouts take: `TileOptions` and the master area's `count` and `side` (`columns` and `grid` ignore them). */\nexport type OrderOptions = TileOptions & MasterOptions;\n\n/** An order layout: `masterStack`, `columns`, `grid`, or the app's own of the same shape. */\nexport type OrderLayout = <K>(panes: readonly K[], area: Rect, options?: OrderOptions) => Map<K, Rect>;\n\n/** The master's share in effect: clamped to 0.05..0.95; one that is not finite is 0.5. */\nexport const masterRatio = (v: number | undefined): number => (v === undefined || !Number.isFinite(v) ? 0.5 : Math.min(0.95, Math.max(0.05, v)));\n\n/** How many of `n` panes are masters for a requested `count`: rounded, within 1..n; NaN is 1. */\nexport function masterCount(count: number | undefined, n: number): number {\n const c = Math.round(count ?? 1);\n return Math.min(Math.max(Number.isNaN(c) ? 1 : c, 1), Math.max(n, 1));\n}\n\n/** `items` side by side or one above the other in equal shares of the box, `gap` between them. */\nfunction divide<K>(items: readonly K[], x: number, y: number, width: number, height: number, vertical: boolean, gap: number, out: Map<K, Rect>): void {\n const n = items.length;\n const total = gap * (n - 1);\n if (vertical) {\n const each = Math.max(0, (height - total) / n);\n items.forEach((pane, i) => out.set(pane, { x, y: y + i * (each + gap), width, height: each }));\n } else {\n const each = Math.max(0, (width - total) / n);\n items.forEach((pane, i) => out.set(pane, { x: x + i * (each + gap), y, width: each, height }));\n }\n}\n\n/**\n * Master and stack: the first `count` panes are the masters, in an area on `side` that takes `ratio` of the room the\n * gap leaves (clamped to 0.05..0.95; default 0.5); the rest are the stack, in the other area. Left and right make\n * each area a column of panes stacked vertically; top and bottom a row of panes side by side. Right and bottom put\n * the stack first in space. With no stack (n at most `count`) all the panes fill the area, stacked along the side's\n * cross axis. Each area divides its length equally between its panes, the gap between them.\n */\nexport function masterStack<K>(panes: readonly K[], area: Rect, options: OrderOptions = {}): Map<K, Rect> {\n const gap = options.gap !== undefined && Number.isFinite(options.gap) && options.gap > 0 ? options.gap : 0;\n const out = new Map<K, Rect>();\n if (panes.length === 0) return out;\n const side = options.side ?? \"left\";\n const ratio = masterRatio(options.ratio);\n const count = masterCount(options.count, panes.length);\n const masters = panes.slice(0, count);\n const stack = panes.slice(count);\n const column = side === \"left\" || side === \"right\";\n if (stack.length === 0) {\n divide(masters, area.x, area.y, area.width, area.height, column, gap, out);\n } else if (column) {\n const room = Math.max(0, area.width - gap);\n const masterWidth = room * ratio;\n const stackWidth = room * (1 - ratio);\n const masterX = side === \"left\" ? area.x : area.x + stackWidth + gap;\n const stackX = side === \"left\" ? area.x + masterWidth + gap : area.x;\n divide(masters, masterX, area.y, masterWidth, area.height, true, gap, out);\n divide(stack, stackX, area.y, stackWidth, area.height, true, gap, out);\n } else {\n const room = Math.max(0, area.height - gap);\n const masterHeight = room * ratio;\n const stackHeight = room * (1 - ratio);\n const masterY = side === \"top\" ? area.y : area.y + stackHeight + gap;\n const stackY = side === \"top\" ? area.y + masterHeight + gap : area.y;\n divide(masters, area.x, masterY, area.width, masterHeight, false, gap, out);\n divide(stack, area.x, stackY, area.width, stackHeight, false, gap, out);\n }\n return out;\n}\n\n/** Equal columns, full height. */\nexport function columns<K>(panes: readonly K[], area: Rect, options: TileOptions = {}): Map<K, Rect> {\n const gap = options.gap ?? 0;\n const out = new Map<K, Rect>();\n const n = panes.length;\n const w = (area.width - gap * (n - 1)) / Math.max(1, n);\n panes.forEach((id, i) => out.set(id, { x: area.x + i * (w + gap), y: area.y, width: w, height: area.height }));\n return out;\n}\n\n/** A grid as square as the count allows; the last row's cells widen to fill it. */\nexport function grid<K>(panes: readonly K[], area: Rect, options: TileOptions = {}): Map<K, Rect> {\n const gap = options.gap ?? 0;\n const out = new Map<K, Rect>();\n const n = panes.length;\n if (n === 0) return out;\n const cols = Math.ceil(Math.sqrt(n));\n const rows = Math.ceil(n / cols);\n const h = (area.height - gap * (rows - 1)) / rows;\n panes.forEach((id, i) => {\n const row = Math.floor(i / cols);\n const inRow = row === rows - 1 ? n - cols * (rows - 1) : cols;\n const col = i - row * cols;\n const w = (area.width - gap * (inRow - 1)) / inRow;\n out.set(id, { x: area.x + col * (w + gap), y: area.y + row * (h + gap), width: w, height: h });\n });\n return out;\n}\n","/**\n * The split tree: how panes divide an area. A node is a pane, or a split of its rect in two (`a` then `b`). A split\n * with an `axis` divides along it (`\"x\"`: `a` left of `b`; `\"y\"`: `a` above `b`) at `ratio`; one without divides\n * along the rect's longer side in halves, which is dwindle (split along the longer side). Pure: trees in, trees out.\n */\nimport type { Axis, Side } from \"../side\";\nimport type { MasterOptions } from \"./order\";\nimport type { PaneRegion } from \"./regions\";\n\n/**\n * A pane, or a split of its rect in two, `a` then `b`. A split takes its `axis` and its `ratio` (the first side's\n * share); `gap` replaces the layout's gap for this split (the handle stays global); `id` names the split so\n * `layoutSplitTree` reports its geometry. With `master`, the split lays its subtree out flat: its panes, in order,\n * as master and stack (`masterStack`) in its rect, by its `ratio` and gap; the splits under it are not laid out.\n */\nexport type Split<K> =\n | { readonly pane: K }\n | {\n readonly a: Split<K>;\n readonly b: Split<K>;\n readonly axis?: Axis;\n readonly ratio?: number;\n readonly gap?: number;\n readonly id?: string;\n readonly master?: MasterOptions;\n };\n\n/** The panes of `tree` in order (`a` before `b`). */\nexport const panesOf = <K>(tree: Split<K> | null): K[] => (!tree ? [] : \"pane\" in tree ? [tree.pane] : [...panesOf(tree.a), ...panesOf(tree.b)]);\n\nconst has = <K>(tree: Split<K> | null, pane: K): boolean => panesOf(tree).includes(pane);\n\n/** `tree` with each pane node `fn` gives a replacement for replaced. */\nfunction mapPanes<K>(tree: Split<K>, fn: (pane: K) => Split<K>): Split<K> {\n if (\"pane\" in tree) return fn(tree.pane);\n return { ...tree, a: mapPanes(tree.a, fn), b: mapPanes(tree.b, fn) };\n}\n\n/**\n * `tree` with pane `at` split in two, `pane` on its `side`. A side writes an explicit axis and ratio 0.5, so the side\n * means the same whatever the pane's shape; no side splits along the longer side, `pane` second (dwindle). An empty\n * tree becomes `pane` alone; an `at` that isn't in the tree (or null) splits the whole tree, so no pane is lost.\n */\nexport function splitPane<K>(tree: Split<K> | null, at: K | null, pane: K, side?: Side): Split<K> {\n const fresh: Split<K> = { pane };\n const split = (node: Split<K>): Split<K> => {\n if (!side) return { a: node, b: fresh };\n const axis = side === \"left\" || side === \"right\" ? \"x\" : \"y\";\n const first = side === \"left\" || side === \"top\";\n return first ? { a: fresh, b: node, axis, ratio: 0.5 } : { a: node, b: fresh, axis, ratio: 0.5 };\n };\n if (!tree) return fresh;\n if (at === null || !has(tree, at)) return split(tree);\n return mapPanes(tree, (p) => (p === at ? split({ pane: p }) : { pane: p }));\n}\n\n/** `tree` without `pane`: its sibling takes their parent's place. */\nexport function removePane<K>(tree: Split<K> | null, pane: K): Split<K> | null {\n if (!tree) return null;\n if (\"pane\" in tree) return tree.pane === pane ? null : tree;\n const a = removePane(tree.a, pane);\n const b = removePane(tree.b, pane);\n return a && b ? { ...tree, a, b } : (a ?? b);\n}\n\n/** `tree` with panes `x` and `y` in each other's place; unchanged unless both are in it. */\nexport function swapPanes<K>(tree: Split<K> | null, x: K, y: K): Split<K> | null {\n if (!tree || !has(tree, x) || !has(tree, y)) return tree;\n return mapPanes(tree, (p) => ({ pane: p === x ? y : p === y ? x : p }));\n}\n\n/** A dwindle tree for `panes`: each one splits the one before it along the longer side. */\nexport function splitFromOrder<K>(panes: readonly K[]): Split<K> | null {\n let t: Split<K> | null = null;\n panes.forEach((id, i) => {\n t = splitPane(t, i > 0 ? panes[i - 1]! : null, id);\n });\n return t;\n}\n\n/**\n * A drop of `dragged` on pane `at`'s `region`. A side splits `at` on that side (`dragged` taken out of its old place\n * first). The center swaps the two when `dragged` is in the tree; a pane from outside takes `at`'s place, with `at`\n * split off after it along the longer side. An `at` that isn't in the tree (or is `dragged` itself) changes nothing\n * but adding `dragged` when it is missing, as `splitPane` does. The set of panes is kept: the tree's, plus `dragged`.\n */\nexport function dropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion): Split<K> {\n if (!tree) return { pane: dragged };\n if (dragged === at || !has(tree, at)) return has(tree, dragged) ? tree : splitPane(tree, null, dragged);\n if (region !== \"center\") return splitPane(removePane(tree, dragged), at, dragged, region);\n if (has(tree, dragged)) return swapPanes(tree, dragged, at)!;\n return mapPanes(tree, (p) => (p === at ? { a: { pane: dragged }, b: { pane: p } } : { pane: p }));\n}\n","/**\n * The split tree laid out: the rect of every pane of a `Split` tree in an area, and the geometry of the splits that\n * have an id. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Axis } from \"../side\";\nimport { masterCount, masterRatio, masterStack, type MasterOptions, type TileOptions } from \"./order\";\nimport { panesOf, type Split } from \"./split\";\n\n/** A px option: a finite number, never below 0 (anything else is 0). */\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/** A ratio: clamped to 0..1; one that is not finite is 0.5. */\nconst unit = (v: number | undefined): number => (v === undefined || !Number.isFinite(v) ? 0.5 : Math.min(1, Math.max(0, v)));\n\n/** A usable length: finite and above 0. */\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\n\n/** The least a ratio may be in a split with a floor: within 5 and 95 % unless a side takes the net off. */\nconst NET: readonly [number, number] = [0.05, 0.95];\n\n/** A split child's fixed length along its split. `keep` marks one that holds its length even beside another. */\nexport interface FixedLength {\n readonly length: number;\n readonly keep?: boolean;\n}\n\n/** A split child's least length along its split. `net` (default true) keeps the split's ratio within 5..95 %. */\nexport interface MinLength {\n readonly min: number;\n readonly net?: boolean;\n}\n\n/**\n * What a split tree's layout reads of its host, each per split, of the split's two direct children.\n *\n * - `fixed(child, axis)`: the child's fixed length along the split, if it has one. The first child that reports one\n * decides: it takes its length when the length is above 0 and, with the gutter, less than the extent, and the other\n * side fills the rest (the gutter between). Otherwise, or with a length that does not fit, the split falls back to\n * its ratio, and the other child's length is not read. When both report a length with `keep`, each keeps its own,\n * in order, and the room left over stays empty; if the two (and the gutter) do not fit the extent, the second runs\n * past the end. A split a fixed length decides has no divider and no floor.\n * - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive and\n * finite, from the start of the cross axis instead of the whole cross extent. It is not checked against the cross\n * extent: a length larger than the cross extent makes a pane larger than the split's box.\n * - `floor(child, axis, split)`: the child's least length along the split. The ratio is clamped so each side keeps\n * its floor of the room less the gutter, within the net (5..95 %) unless either side says `net: false`; where the\n * two floors cannot both fit, the ratio is 0.5. With no `floor`, the ratio is only clamped to 0..1. `giveWay` is\n * the other policy of the same minimum: it floats the newest pane instead of squeezing the ratio, and a host\n * chooses one for a pane.\n */\nexport interface SplitOptions<K> extends TileOptions {\n readonly fixed?: (child: Split<K>, axis: Axis) => FixedLength | undefined;\n readonly fixedAcross?: (child: Split<K>, axis: Axis) => number | undefined;\n readonly floor?: (child: Split<K>, axis: Axis, split: Split<K>) => MinLength;\n}\n\n/** A laid-out split: the box it divides, its axis and ratio in effect, and the strip between its two sides. */\nexport interface SplitGeometry {\n readonly rect: Rect;\n readonly axis: \"x\" | \"y\";\n /**\n * The first side's share in effect: the middle of the gutter lies at the box's start plus its extent times this\n * (for a fixed-length child, the middle of the gutter after the first side over the extent). For a master split\n * it is the master area's share (clamped to 0.05..0.95) of the room less the gap, measured from the master's own\n * side: with the master on the right, ratio 0.3 in 1000 with a gap of 10, the divider lies at 693..703.\n */\n readonly ratio: number;\n /** The gutter between the two sides, as a rect inside `rect`; null where the split has none. */\n readonly divider: Rect | null;\n}\n\n/** A tree laid out: every pane's rect, and the geometry of each split that has an `id`. */\nexport interface SplitLayout<K> {\n readonly panes: Map<K, Rect>;\n readonly splits: Map<string, SplitGeometry>;\n}\n\ninterface Ctx<K> {\n readonly options: SplitOptions<K>;\n readonly gap: number;\n readonly handle: number;\n readonly panes: Map<K, Rect>;\n /** Where the geometry of the named splits goes; null for `layoutSplit`, which reports panes only and builds none. */\n readonly splits: Map<string, SplitGeometry> | null;\n}\n\n/**\n * The rect of every pane of `tree` in `area`. Each split's gutter is its gap (its own `gap`, else `options.gap`) plus\n * `options.handle`. A split's `ratio` is clamped to 0..1 (one that is not finite is 0.5), and the middle of the gutter\n * sits at `extent * ratio`: the first side is `extent * ratio` less half the gutter, the second starts half a gutter\n * past it and is the rest less half the gutter. No size is ever negative: a side too short for half the gutter is 0\n * along the axis, and the second side of a split with no room may then start up to half a gutter past the rect's end.\n * At ratio 0.5 both sides are equal. `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's\n * minimums and fixed lengths per split. A negative or non-finite `gap` or `handle` is 0. The area is taken as given:\n * with a negative width or height every length along that axis is 0 and a pane's size across it is copied as it\n * is, so pass an area with no negative side.\n */\nexport function layoutSplit<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K> = {}): Map<K, Rect> {\n const ctx: Ctx<K> = { options, gap: px(options.gap), handle: px(options.handle), panes: new Map(), splits: null };\n lay(tree, area, ctx, false);\n return ctx.panes;\n}\n\n/**\n * `layoutSplit` and the geometry of every split that has an `id` (a repeated id keeps the one laid out last: a split under another, or a later one beside it): the box it divides,\n * its axis and ratio in effect (after the floors), and its divider, the gutter strip between its two sides. A split\n * that lays out as master and stack is reported too, its nested splits are not.\n */\nexport function layoutSplitTree<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K> = {}): SplitLayout<K> {\n const splits = new Map<string, SplitGeometry>();\n const ctx: Ctx<K> = { options, gap: px(options.gap), handle: px(options.handle), panes: new Map(), splits };\n lay(tree, area, ctx, false);\n return { panes: ctx.panes, splits };\n}\n\n/** The strip `gutter` wide centered on `mid` across `box`, clipped to it. */\nfunction strip(box: Rect, x: boolean, mid: number, gutter: number): Rect {\n const lo = Math.max(x ? box.x : box.y, mid - gutter / 2);\n const hi = Math.min(x ? box.x + box.width : box.y + box.height, mid + gutter / 2);\n const length = Math.max(0, hi - lo);\n return x ? { x: lo, y: box.y, width: length, height: box.height } : { x: box.x, y: lo, width: box.width, height: length };\n}\n\n/**\n * `ratio` kept so the first side has `minA` and the second `minB` of the room less the gutter (at least 1 px of room),\n * within `net`; 0.5 where the two cannot both fit.\n */\nfunction clampByMin(ratio: number, extent: number, gutter: number, minA: number, minB: number, net: readonly [number, number]): number {\n const room = Math.max(extent - gutter, 1);\n const boundedMin = Math.min(Math.max(minA / room, net[0]), net[1]);\n const boundedMax = Math.max(Math.min(1 - minB / room, net[1]), net[0]);\n return boundedMin > boundedMax ? 0.5 : Math.min(Math.max(ratio, boundedMin), boundedMax);\n}\n\n/** A split that lays its panes out flat as master and stack: the gap only, never the handle. */\nfunction layMaster<K>(tree: Extract<Split<K>, { a: unknown }>, master: MasterOptions, area: Rect, ctx: Ctx<K>, owned: boolean): void {\n const gap = tree.gap === undefined ? ctx.gap : px(tree.gap);\n const panes = panesOf(tree);\n const ratio = masterRatio(tree.ratio);\n const side = master.side ?? \"left\";\n // Only the count and side come from `master`: the ratio and gap are the split's own.\n for (const [pane, r] of masterStack(panes, area, { gap, ratio, count: master.count, side })) ctx.panes.set(pane, r);\n if (tree.id === undefined || ctx.splits === null) return;\n const x = side === \"left\" || side === \"right\";\n const stacked = panes.length > masterCount(master.count, panes.length);\n const room = Math.max(0, (x ? area.width : area.height) - gap);\n const first = side === \"left\" || side === \"top\" ? room * ratio : room * (1 - ratio);\n const mid = (x ? area.x : area.y) + first + gap / 2;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis: x ? \"x\" : \"y\", ratio, divider: stacked ? strip(area, x, mid, gap) : null });\n}\n\n/**\n * Lays `tree` out in `area`. `owned` says `area` is a rect this layout made itself (a split's child), so a pane or a\n * split may keep it as its own; the caller's rect (the root) is copied, never kept.\n */\nfunction lay<K>(tree: Split<K> | null, area: Rect, ctx: Ctx<K>, owned: boolean): void {\n if (!tree) return;\n if (\"pane\" in tree) {\n ctx.panes.set(tree.pane, owned ? area : { ...area });\n return;\n }\n if (tree.master) {\n layMaster(tree, tree.master, area, ctx, owned);\n return;\n }\n const axis = tree.axis ?? (area.width >= area.height ? \"x\" : \"y\");\n const x = axis === \"x\";\n const extent = x ? area.width : area.height;\n const origin = x ? area.x : area.y;\n const cross = x ? area.height : area.width;\n const gutter = (tree.gap === undefined ? ctx.gap : px(tree.gap)) + ctx.handle;\n const { fixed, fixedAcross, floor } = ctx.options;\n // Across the split a child with a fixed length takes it from the start; the others take the whole cross extent.\n const lenA = fixedAcross?.(tree.a, axis);\n const lenB = fixedAcross?.(tree.b, axis);\n const acrossA = usable(lenA) ? lenA : cross;\n const acrossB = usable(lenB) ? lenB : cross;\n const fixedA = fixed?.(tree.a, axis);\n const fixedB = fixed?.(tree.b, axis);\n\n // The lengths of the two sides along the split, where the second starts, the ratio in effect and the divider.\n let lengthA: number;\n let lengthB: number;\n let startB: number;\n let ratio = unit(tree.ratio);\n let ruled = false; // the divider is the gutter strip at the ratio (a split no fixed length decides)\n const lead = fixedA ?? fixedB;\n if (fixedA && fixedB && fixedA.keep && fixedB.keep && usable(fixedA.length) && usable(fixedB.length)) {\n lengthA = fixedA.length;\n lengthB = fixedB.length;\n startB = origin + lengthA + gutter;\n ratio = extent > 0 ? (lengthA + gutter / 2) / extent : ratio;\n } else if (lead && usable(lead.length) && lead.length + gutter < extent) {\n const rest = Math.max(0, extent - lead.length - gutter);\n lengthA = lead === fixedA ? lead.length : rest;\n lengthB = lead === fixedA ? rest : lead.length;\n startB = origin + lengthA + gutter;\n ratio = (lengthA + gutter / 2) / extent;\n } else {\n if (floor) {\n const a = floor(tree.a, axis, tree);\n const b = floor(tree.b, axis, tree);\n const net = a.net === false || b.net === false ? ([0, 1] as const) : NET;\n ratio = clampByMin(Number.isFinite(tree.ratio ?? 0.5) ? (tree.ratio ?? 0.5) : 0.5, extent, gutter, px(a.min), px(b.min), net);\n }\n lengthA = Math.max(0, extent * ratio - gutter / 2);\n lengthB = Math.max(0, extent * (1 - ratio) - gutter / 2);\n startB = origin + extent * ratio + gutter / 2;\n ruled = true;\n }\n // The geometry is built only for a named split and only when the caller asked for it (`layoutSplitTree`).\n if (tree.id !== undefined && ctx.splits !== null) {\n const divider = ruled ? strip(area, x, origin + extent * ratio, gutter) : null;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio, divider });\n }\n if (x) {\n lay(tree.a, { x: area.x, y: area.y, width: lengthA, height: acrossA }, ctx, true);\n lay(tree.b, { x: startB, y: area.y, width: lengthB, height: acrossB }, ctx, true);\n } else {\n lay(tree.a, { x: area.x, y: area.y, width: acrossA, height: lengthA }, ctx, true);\n lay(tree.b, { x: area.x, y: startB, width: acrossB, height: lengthB }, ctx, true);\n }\n}\n","/**\n * Whether a drop on a pane leaves room: the rule a host asks before it offers a side of a pane as a drop place. See\n * docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { layoutSplit, type SplitOptions } from \"./layout\";\nimport type { PaneRegion } from \"./regions\";\nimport { dropOnPane, panesOf, removePane, type Split } from \"./split\";\n\n/** The layout options a drop is judged under, and `min`: the least width and height, px, a pane must keep. */\nexport interface DropOptions<K> extends SplitOptions<K> {\n readonly min: number;\n}\n\n/** A drop's verdict: `ok`, or not, with its `reason`. */\nexport interface DropVerdict {\n readonly ok: boolean;\n readonly reason?: string;\n}\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/**\n * Whether dropping `dragged` on pane `at`'s `region` leaves both at least `options.min` wide and high.\n *\n * - The center is fine unless `dragged` is `at`, or `at` is not in the tree (nothing to swap with).\n * - A side needs, in the layout of the tree without `dragged` (so `at` is measured where it will be when `dragged` is\n * lifted out), a span of `at` along the split of at least `2 * min` plus the gutter (the options' gap plus handle)\n * and across it of at least `min`; and in the layout of `dropOnPane(tree, dragged, at, region)` both `dragged` and\n * `at` at least `min` wide and high. That check is skipped when `area` has no width or no height. A pane that is\n * not in the tree counts as one being added; an `at` that is not in it (or is `dragged`) has no place to split.\n */\nexport function canDropOnPane<K>(tree: Split<K> | null, dragged: K, at: K, region: PaneRegion, area: Rect, options: DropOptions<K>): DropVerdict {\n if (region === \"center\") {\n if (dragged === at) return { ok: false, reason: \"center swap blocked: a pane dropped on itself\" };\n return panesOf(tree).includes(at) ? { ok: true } : { ok: false, reason: \"center rejected: no pane to swap\" };\n }\n const target = layoutSplit(removePane(tree, dragged), area, options).get(at);\n if (!target) return { ok: false, reason: `${region} rejected: no pane to split` };\n const room = canSplitPane(target, region, options);\n if (!room.ok) return room;\n return dropFits(layoutSplit(dropOnPane(tree, dragged, at, region), area, options), dragged, at, area, { min: options.min, side: region });\n}\n\n/** What `canSplitPane` reads: `min` (as in `DropOptions`) and the gutter's parts, `gap` and `handle`, px. */\nexport interface SplitRoomOptions {\n readonly min: number;\n readonly gap?: number;\n readonly handle?: number;\n}\n\n/**\n * The room rule: whether a pane of rect `target` can take another on `side`, both at least `options.min` wide and\n * high. Along the split (width for left and right, height for top and bottom) the pane needs `2 * min` plus the\n * gutter (`gap` plus `handle`), across it `min`. The rect is the pane's as the host measures it, where it will be\n * when the dragged pane is lifted out. `canDropOnPane`'s first rule, for a side.\n */\nexport function canSplitPane(target: Rect, side: Side, options: SplitRoomOptions): DropVerdict {\n const min = px(options.min);\n const gutter = px(options.gap) + px(options.handle);\n const horizontal = side === \"left\" || side === \"right\";\n const along = horizontal ? target.width : target.height;\n const across = horizontal ? target.height : target.width;\n const need = min * 2 + gutter;\n if (along < need) return { ok: false, reason: `${side} rejected: axis span ${along.toFixed(1)}px < min ${need.toFixed(1)}px (2 panes + gutter ${gutter}px)` };\n if (across < min) return { ok: false, reason: `${side} rejected: cross span ${across.toFixed(1)}px < min ${min.toFixed(1)}px` };\n return { ok: true };\n}\n\n/** What `dropFits` reads: the `min` (as in `DropOptions`) and the `side` of `at` the drop is on, for the reason. */\nexport interface DropFitsOptions {\n readonly min: number;\n readonly side: Side;\n}\n\n/**\n * The fit rule: in `projected`, the rect of every pane in the layout the drop makes (the host's own projection of\n * `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and high. Fine\n * when `area` has no width or no height (there is nothing to measure). `canDropOnPane`'s last rule.\n */\nexport function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions): DropVerdict {\n if (!(area.width > 0 && area.height > 0)) return { ok: true };\n const min = px(options.min);\n const fits = (r: Rect | undefined): boolean => !!r && r.width >= min && r.height >= min;\n return fits(projected.get(dragged)) && fits(projected.get(at)) ? { ok: true } : { ok: false, reason: `${options.side} rejected: projected footprint of the two panes violates min ${min}px` };\n}\n","/**\n * A pane's drop regions: a center rectangle (a drop there swaps with the pane) and four side trapezoids (a drop there\n * splits the pane on that side), formed by the diagonals from each pane corner to the nearest corner of the center.\n * The five regions cover the pane with no gaps and no overlaps.\n *\n * Meant for `@n-uf/motion/drag`'s `placeOf(target, point, previous)`: one target per pane (`paneTargets`), its place\n * the region under the pointer, the previous region held for `hysteresis` px past its boundary so a pointer resting on\n * a boundary doesn't flicker. A region that takes no drop is the consumer's to answer with a null place.\n */\nimport { clamp, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Side } from \"../side\";\n\nexport type PaneRegion = \"center\" | Side;\n\n/** The sides in their tie-break order: at an exact diagonal the first wins (a corner resolves to `top`). */\nexport const PANE_SIDES: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"];\n\nexport interface PaneRegionOptions {\n /** The center rectangle's share of each pane axis (0.05 to 0.95); `centerX` / `centerY` override one axis. */\n readonly center?: number;\n readonly centerX?: number;\n readonly centerY?: number;\n /** The least the center spans on either axis, px (a small pane keeps a usable center). */\n readonly centerMin?: number;\n /** How far past its boundary the previous region holds, px. */\n readonly hysteresis?: number;\n /** Device pixels per px: the center's edges snap to that grid, as the browser draws them. */\n readonly pixelRatio?: number;\n /**\n * The pane's center rectangle as the host already has it (pane-local px, as `paneCenter` gives), used as it is in\n * place of measuring: `center`, `centerX`, `centerY`, `centerMin` and `pixelRatio` are not read. Only `paneRegion`\n * reads it; its `width` and `height` are the pane's own size for the hold toward the middle.\n */\n readonly paneCenter?: PaneCenter;\n /**\n * The sides that exist (default: all four). A point is in the center unless it lies past the center's edge toward a\n * side that exists: a side left out gives its whole strip to the center, which then reaches the pane's edge there.\n */\n readonly sides?: readonly Side[];\n}\n\nexport const PANE_REGION_DEFAULTS: Required<Omit<PaneRegionOptions, \"centerX\" | \"centerY\" | \"paneCenter\" | \"sides\">> = { center: 0.34, centerMin: 24, hysteresis: 6, pixelRatio: 1 };\n\n/** The center rectangle of a pane of `size`, in pane-local px (origin at the pane's top-left corner). */\nexport interface PaneCenter {\n readonly width: number;\n readonly height: number;\n readonly left: number;\n readonly top: number;\n readonly right: number;\n readonly bottom: number;\n}\n\nconst snap = (v: number, ratio: number): number => Math.round(v * ratio) / ratio;\n\n/** Where the center rectangle of a pane of `size` lies, by these options. */\nexport function paneCenter(size: Size, options: PaneRegionOptions = {}): PaneCenter {\n const o = { ...PANE_REGION_DEFAULTS, ...options };\n const width = Math.max(0, size.width);\n const height = Math.max(0, size.height);\n const ratio = o.pixelRatio > 0 ? o.pixelRatio : 1;\n const rx = clamp(o.centerX ?? o.center, 0.05, 0.95);\n const ry = clamp(o.centerY ?? o.center, 0.05, 0.95);\n const cw = Math.min(width, Math.max(width * rx, Math.min(o.centerMin, width)));\n const ch = Math.min(height, Math.max(height * ry, Math.min(o.centerMin, height)));\n return { width, height, left: snap((width - cw) / 2, ratio), top: snap((height - ch) / 2, ratio), right: snap((width + cw) / 2, ratio), bottom: snap((height + ch) / 2, ratio) };\n}\n\n/** How deep past the center a point is toward each side, as a share of that side's band (positive: in that band). */\nfunction depths(p: Point, c: PaneCenter): { side: Side; depth: number }[] {\n return [\n { side: \"top\", depth: (c.top - p.y) / Math.max(c.top, 1) },\n { side: \"right\", depth: (p.x - c.right) / Math.max(c.width - c.right, 1) },\n { side: \"bottom\", depth: (p.y - c.bottom) / Math.max(c.height - c.bottom, 1) },\n { side: \"left\", depth: (c.left - p.x) / Math.max(c.left, 1) },\n ];\n}\n\n/** The region a pane-local point is in, by position alone: the side it is deepest past the center toward, of the sides that exist. */\nfunction rawRegion(p: Point, c: PaneCenter, sides?: readonly Side[]): PaneRegion {\n let best: PaneRegion = \"center\";\n let deepest = 0;\n for (const d of depths(p, c)) {\n if (sides && !sides.includes(d.side)) continue;\n if (d.depth > deepest) {\n deepest = d.depth;\n best = d.side;\n }\n }\n return best;\n}\n\n/** `p` moved `by` px into `region` (toward the pane's middle for the center). */\nfunction toward(p: Point, region: PaneRegion, by: number, c: PaneCenter): Point {\n if (region === \"left\") return { x: p.x - by, y: p.y };\n if (region === \"right\") return { x: p.x + by, y: p.y };\n if (region === \"top\") return { x: p.x, y: p.y - by };\n if (region === \"bottom\") return { x: p.x, y: p.y + by };\n const dx = c.width / 2 - p.x;\n const dy = c.height / 2 - p.y;\n const len = Math.hypot(dx, dy);\n if (len <= by || len === 0) return { x: c.width / 2, y: c.height / 2 };\n return { x: p.x + (dx / len) * by, y: p.y + (dy / len) * by };\n}\n\n/**\n * The regions of `pane` as convex polygons, in the same coordinates as `pane`: the center rectangle, and each side's\n * trapezoid from the pane's two corners on that side to the center's two nearest corners. They are the regions\n * `paneRegion` names (no hysteresis): a point inside one, off its shared edges, is in that region. A side left out of\n * `options.sides` has no polygon (empty); the center reaches the pane's edge there, and a neighboring side's polygon\n * takes the corner toward it.\n */\nexport function paneRegionShapes(pane: Rect, options: PaneRegionOptions = {}): Readonly<Record<PaneRegion, readonly Point[]>> {\n const c = options.paneCenter ?? paneCenter(pane, options);\n const at = (x: number, y: number): Point => ({ x: pane.x + x, y: pane.y + y });\n const [w, h] = [c.width, c.height];\n const has = (s: Side): boolean => !options.sides || options.sides.includes(s);\n const l = has(\"left\") ? c.left : 0;\n const r = has(\"right\") ? c.right : w;\n const t = has(\"top\") ? c.top : 0;\n const b = has(\"bottom\") ? c.bottom : h;\n return {\n center: [at(l, t), at(r, t), at(r, b), at(l, b)],\n top: has(\"top\") ? [at(0, 0), at(w, 0), has(\"right\") ? at(c.right, c.top) : at(w, c.top), has(\"left\") ? at(c.left, c.top) : at(0, c.top)] : [],\n right: has(\"right\") ? [at(w, 0), at(w, h), has(\"bottom\") ? at(c.right, c.bottom) : at(c.right, h), has(\"top\") ? at(c.right, c.top) : at(c.right, 0)] : [],\n bottom: has(\"bottom\") ? [at(w, h), at(0, h), has(\"left\") ? at(c.left, c.bottom) : at(0, c.bottom), has(\"right\") ? at(c.right, c.bottom) : at(w, c.bottom)] : [],\n left: has(\"left\") ? [at(0, h), at(0, 0), has(\"top\") ? at(c.left, c.top) : at(c.left, 0), has(\"bottom\") ? at(c.left, c.bottom) : at(c.left, h)] : [],\n };\n}\n\n/**\n * The drop region of `pane` (in the same coordinates as `point`) the point is in. With a `previous` region, the point\n * has to be `hysteresis` px past that region's boundary before the region changes: no time-based debounce, only\n * geometry. A host that has measured the center itself passes it as `options.paneCenter`; the same center gives the\n * same region as the one measured here.\n */\nexport function paneRegion(pane: Rect, point: Point, previous: PaneRegion | null = null, options: PaneRegionOptions = {}): PaneRegion {\n const c = options.paneCenter ?? paneCenter(pane, options);\n const p = { x: point.x - pane.x, y: point.y - pane.y };\n const raw = rawRegion(p, c, options.sides);\n const by = Math.max(0, options.hysteresis ?? PANE_REGION_DEFAULTS.hysteresis);\n if (previous === null || by === 0 || previous === raw) return raw;\n return rawRegion(toward(p, previous, by, c), c, options.sides) === previous ? previous : raw;\n}\n","/**\n * The hit half of a tiling drag: which place the pointer is over. `tilingDrag(...).hit(basis)` builds it once per drag,\n * at the lift, from one layout that never changes during the drag: `\"lift\"` (the tree at the lift, the subject's slot\n * open) for a host that draws only marks over it, `\"base\"` (the subject released, the gap closed) for a host that draws\n * the landed layout of the held place. Nothing is measured or laid out anew per frame.\n *\n * - **Targets**, in `@n-uf/motion/drag`'s target shape: one body target per pane the basis draws (not the subject's own\n * slot, not a still pane), its places the five regions of `paneRegion` (the center swaps, a side goes beside); one\n * target per part the adapter declares on that pane (`TilingTree.parts`: a title bar, a tab strip), its place a join,\n * a slot under the pointer giving the index; and home, the subject's lift rect, which wins over everything beneath it.\n * A side exists only for a new arrangement: on a run neighbor of the subject (next to it as a whole child of one run\n * on the lift tree, with the same bounds across), a side whose insert gives the lift's arrangement or the swap's is\n * gone and its strip belongs to the center; the swap then spans `neighborSwap` (0.56) across the run. The run-neighbor\n * rule removes sides first; home then takes what remains that gives the lift back.\n * - **Places**: a place exists when `after(place).refusal` is null. A refused zone holds nothing and falls to the target\n * beneath it (a refused part to the pane's body), never sideways. A place whose `after` equals the lift is home.\n * - **One hold rule, two measures**: the held place keeps its zone until the pointer is `edge` px past the edge of that\n * zone's visible part (the part no zone above it covers: home, a part over a body, a slot over its part; home wins over\n * what lies beneath it), home included; inside one pane, not over home, it also keeps until the pointer is `travel` px\n * from where the place was taken. Any change of place takes the point anew. Each measure is at most `cap` of the held\n * zone's extent on each axis: the edge measure per axis (a box around the zone, rounded at its corners), the travel\n * measure as an ellipse with those two radii.\n * - **The reader**: `read(frame, point)` turns a drag intent's frame into `{ held, refused, mark }`: the held place (home\n * included, null when nothing is held outside home), the refused place under the pointer when nothing is held, and, on\n * the lift basis, the mark: a region of the lift layout (the target's half for a side, its outline for a swap or a\n * join, and for a swap the wash in the open slot), never an `after` rect.\n *\n * See docs/placement.md, Entry: tiling, \"A tiling drag's hit half\".\n */\nimport { contains, type Point, type Rect } from \"../geometry\";\nimport type { Axis, Side } from \"../side\";\nimport type { Target } from \"../target\";\nimport { paneRegion, paneRegionShapes, type PaneRegion, type PaneRegionOptions } from \"./regions\";\nimport { panesOf, type Split } from \"./split\";\nimport type { TilingAfter, TilingHeld, TilingLaidOut, TilingTree } from \"./tree\";\n\nexport type { TilingPart } from \"./tree\";\n\n/** Which layout a drag hit-tests, fixed at the lift: the lift (a host that draws marks) or the base (a host that draws the landed layout). */\nexport type TilingBasis = \"lift\" | \"base\";\n\n/** A hit target, in `@n-uf/motion/drag`'s target shape. */\nexport interface TilingHitTarget<K> extends Target {\n /** The pane the basis draws under it (for home, the subject's own). */\n readonly pane: K;\n /** The pane its places name (`at`), as the base draws it. */\n readonly at: K;\n /** The part's key, on a part's target. */\n readonly part?: string;\n /** Home's target: the subject's lift rect. */\n readonly home?: true;\n}\n\n/**\n * The region options the hit reads: the center's share of each pane axis (`center`, or `centerX` / `centerY`), its\n * floor and the pixel grid. The sides and a run neighbor's share are the hit's own, and the hold is its own rule.\n */\nexport type TilingHitRegions = Pick<PaneRegionOptions, \"center\" | \"centerX\" | \"centerY\" | \"centerMin\" | \"pixelRatio\">;\n\n/** The hit's options. */\nexport interface TilingHitOptions<K> {\n /** The pane regions (`TilingHitRegions`). */\n readonly regions?: TilingHitRegions;\n /** A pane's key in target and place ids; default `String`. Keys must be unique across panes. */\n readonly key?: (pane: K) => string;\n /** The edge measure, px (default 6). */\n readonly edge?: number;\n /** The travel measure inside one pane, px (default 24). */\n readonly travel?: number;\n /** The most either measure is of the held zone's extent, per axis (default 0.25). */\n readonly cap?: number;\n /** A run neighbor's swap across the run, a share of its extent there (default 0.56): each side strip is half the rest. */\n readonly neighborSwap?: number;\n}\n\n/**\n * The hit's defaults: 6 px past the edge, 24 px of travel inside one pane, each at most a quarter of the zone (`cap`);\n * a run neighbor's swap spans 56 % across the run, each side strip 22 %, so a strip is about as large as a normal side\n * band (a side insert is as easy to hit there as on any other pane).\n */\nexport const TILING_HIT_DEFAULTS: { readonly edge: number; readonly travel: number; readonly cap: number; readonly neighborSwap: number } = {\n edge: 6,\n travel: 24,\n cap: 0.25,\n neighborSwap: 0.56,\n};\n\n/** What the hold rule keeps: the held place's id, and the point the place was taken from. */\nexport interface TilingHold {\n readonly place: string;\n readonly from: Point;\n}\n\n/** The part of a drag intent's frame the reader reads. */\nexport interface TilingHitFrame<T> {\n readonly shown: T | null;\n}\n\n/**\n * A lift-basis mark: a region of the lift layout, of the held place's kind. Beside: the target pane's half on that\n * side, as drawn. A swap: the target's outline, and the wash in the open slot (home; none when the release leaves no\n * slot). A join: the target's outline, and its slot when the join has an index.\n */\nexport type TilingMark<K> =\n | { readonly kind: \"beside\"; readonly at: K; readonly side: Side; readonly rect: Rect }\n | { readonly kind: \"swap\"; readonly at: K; readonly rect: Rect; readonly wash: Rect | null }\n | { readonly kind: \"join\"; readonly at: K; readonly rect: Rect; readonly slot: Rect | null };\n\n/** What a frame reads off the hit. */\nexport interface TilingHitRead<K> {\n /** The held place, home included; null when nothing is held outside home. */\n readonly held: TilingHeld<K> | null;\n /** The refused place under the pointer, when nothing is held (nothing is drawn for it). */\n readonly refused: TilingHeld<K> | null;\n /** The lift basis's mark for the held place; null on the base basis, at home, and with nothing held. */\n readonly mark: TilingMark<K> | null;\n}\n\n/**\n * The options a `@n-uf/motion/drag` intent takes to read the hit: no home (home is a place of the hit, held by the one\n * rule; the intent's own home test would cut it at the plain edge), no time-based gate or hold, and a band as wide as\n * the edge measure so the intent keeps every target the hit still holds. The hit decides; the intent shows it. A host\n * adds no time gate of its own (a dwell): the hold is the hit's, by distance.\n */\nexport interface TilingHitIntent<K> {\n readonly tuning: {\n readonly aimSpeed: number;\n readonly dwell: number;\n readonly switchHold: number;\n readonly roomAfter: number;\n readonly band: number;\n readonly bandShare: number;\n readonly breakthrough: number;\n readonly gapGrace: number;\n };\n readonly placeOf: (target: TilingHitTarget<K>, point: Point, previous: string | null) => string | null;\n}\n\n/**\n * A drag's hit: built once per drag and basis (`drag.hit(basis)` gives the same one again), its targets and zones fixed\n * for the drag. It hit-tests `drag[hit.basis]`, the lift or the base.\n */\nexport interface TilingHit<T, K> {\n readonly basis: TilingBasis;\n /** Home: the subject's lift rect, or null when the release leaves no slot. */\n readonly home: Rect | null;\n /** Every target, fixed for the drag. */\n readonly targets: readonly TilingHitTarget<K>[];\n /** The options for a drag intent (`createDragIntent({ ...hit.intent })`). */\n readonly intent: TilingHitIntent<K>;\n /** The zone map: the place id at `point` with nothing held (`\"home\"` for home), or null. Pure. */\n placeAt(point: Point): string | null;\n /** The hold rule: what is held at `point` after `state` (null: nothing held yet). Pure: a host with no intent steps it itself. */\n hold(state: TilingHold | null, point: Point): TilingHold | null;\n /** The place an id names (hosts never parse ids). */\n heldOf(id: string): TilingHeld<K> | null;\n /**\n * The intent's `placeOf`: the held place at `point` when it is on `target`, else null. Steps the drag's one hold, once\n * per point. `previous` is not read: the hold is the hit's. Home and a part are both priority 1, so where a part lies\n * over home the intent may pick the part; its `placeOf` then answers null, and home wins.\n */\n placeOf(target: TilingHitTarget<K>, point: Point, previous?: string | null): string | null;\n /** The intent's frame at `point`, read: the held place, the refused one, and the lift basis's mark. */\n read(frame: TilingHitFrame<TilingHitTarget<K>>, point: Point): TilingHitRead<K>;\n /** What a frame draws: the lift on the lift basis; on the base basis `after(held)`, the lift at home, the base with nothing held. */\n drawn(read: TilingHitRead<K>): TilingLaidOut<T, K>;\n /** What a release commits: `after(held)`, else home's. */\n release(read: TilingHitRead<K>): TilingAfter<T, K>;\n}\n\n/** What `tilingDrag` hands its hit. @internal */\nexport interface TilingHitContext<T, K> {\n readonly ops: TilingTree<T, K>;\n readonly lift: TilingLaidOut<T, K>;\n readonly base: TilingLaidOut<T, K>;\n readonly home: Rect | null;\n /** The subject's key: the pane, or the stack's active member. */\n readonly subjectKey: K;\n readonly inSubject: (pane: K) => boolean;\n readonly still?: (pane: K) => boolean;\n readonly after: (held: TilingHeld<K>) => TilingAfter<T, K>;\n /** A tree laid out on the drag's stage. */\n readonly lay: (tree: T) => TilingLaidOut<T, K>;\n /** The tree a swap or a side makes, whatever room it has (normalized). */\n readonly changeOf: (held: { kind: \"swap\"; at: K } | { kind: \"beside\"; at: K; side: Side }) => T;\n}\n\n/** A zone's convex piece, its extent, and the zones above it (what of the piece they cover is not its visible part). */\ninterface Piece {\n readonly poly: readonly Point[];\n readonly box: Rect;\n readonly cuts: () => readonly Rect[];\n}\n\ninterface Place<K> {\n readonly id: string;\n readonly held: TilingHeld<K>;\n /** The pane it lies on; null for home. */\n readonly pane: PaneHit<K> | null;\n readonly pieces: Piece[];\n readonly owners: Set<string>;\n readonly slot: Rect | null;\n}\n\ninterface PartHit<K> {\n readonly target: TilingHitTarget<K>;\n readonly place: Place<K>;\n readonly slots: readonly { readonly rect: Rect; readonly place: Place<K> }[];\n}\n\ninterface PaneHit<K> {\n readonly body: TilingHitTarget<K>;\n readonly parts: readonly PartHit<K>[];\n readonly regions: Readonly<Partial<Record<PaneRegion, Place<K>>>>;\n /** The region options of its map: the sides that exist, and a run neighbor's swap share across the run. */\n readonly options: PaneRegionOptions;\n}\n\nconst HOME: TilingHeld<never> = { kind: \"home\" };\nconst SIDES: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"];\n\nconst inside = (r: Rect, p: Point): boolean => contains(r, p, 0);\nconst rectPoly = (r: Rect): Point[] => [\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];\nfunction boxOf(poly: readonly Point[]): Rect {\n const xs = poly.map((p) => p.x);\n const ys = poly.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/** Whether `p` lies in the convex polygon `poly` (edges included). */\nfunction inConvex(poly: readonly Point[], p: Point): boolean {\n let pos = false;\n let neg = false;\n for (let i = 0; i < poly.length; i++) {\n const a = poly[i]!;\n const b = poly[(i + 1) % poly.length]!;\n const cross = (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);\n if (cross > 1e-9) pos = true;\n else if (cross < -1e-9) neg = true;\n if (pos && neg) return false;\n }\n return true;\n}\nconst segDist = (p: Point, a: Point, b: Point): number => {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const len = dx * dx + dy * dy;\n const t = len > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len)) : 0;\n return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));\n};\n/** Whether `p` lies within `ex` px left and right and `ey` px above and below of the convex polygon `poly`. */\nfunction nearPoly(poly: readonly Point[], p: Point, ex: number, ey: number): boolean {\n if (inConvex(poly, p)) return true;\n const sx = ex > 0 ? 1 / ex : 1e9;\n const sy = ey > 0 ? 1 / ey : 1e9;\n const q = { x: p.x * sx, y: p.y * sy };\n for (let i = 0; i < poly.length; i++) {\n const a = poly[i]!;\n const b = poly[(i + 1) % poly.length]!;\n if (segDist(q, { x: a.x * sx, y: a.y * sy }, { x: b.x * sx, y: b.y * sy }) <= 1) return true;\n }\n return false;\n}\n/** The part of the convex polygon `poly` where `a·x + b·y <= c` (convex, possibly empty). */\nfunction clipHalf(poly: readonly Point[], a: number, b: number, c: number): Point[] {\n const out: Point[] = [];\n for (let i = 0; i < poly.length; i++) {\n const p = poly[i]!;\n const q = poly[(i + 1) % poly.length]!;\n const fp = a * p.x + b * p.y - c;\n const fq = a * q.x + b * q.y - c;\n if (fp <= 0) out.push(p);\n if ((fp < 0 && fq > 0) || (fp > 0 && fq < 0)) {\n const t = fp / (fp - fq);\n out.push({ x: p.x + (q.x - p.x) * t, y: p.y + (q.y - p.y) * t });\n }\n }\n return out;\n}\nconst areaOf = (poly: readonly Point[]): number =>\n Math.abs(poly.reduce((s, p, i) => s + p.x * poly[(i + 1) % poly.length]!.y - poly[(i + 1) % poly.length]!.x * p.y, 0)) / 2;\n/** The convex polygon `poly` less the rect `r`: at most four convex pieces (left of it, right of it, above, below). */\nfunction minusRect(poly: readonly Point[], r: Rect): Point[][] {\n const [x0, x1, y0, y1] = [r.x, r.x + r.width, r.y, r.y + r.height];\n const pieces = [\n clipHalf(poly, 1, 0, x0),\n clipHalf(poly, -1, 0, -x1),\n clipHalf(clipHalf(clipHalf(poly, -1, 0, -x0), 1, 0, x1), 0, 1, y0),\n clipHalf(clipHalf(clipHalf(poly, -1, 0, -x0), 1, 0, x1), 0, -1, -y1),\n ];\n return pieces.filter((q) => q.length >= 3 && areaOf(q) > 1e-6);\n}\nconst half = (r: Rect, side: Side): Rect =>\n side === \"left\"\n ? { x: r.x, y: r.y, width: r.width / 2, height: r.height }\n : side === \"right\"\n ? { x: r.x + r.width / 2, y: r.y, width: r.width / 2, height: r.height }\n : side === \"top\"\n ? { x: r.x, y: r.y, width: r.width, height: r.height / 2 }\n : { x: r.x, y: r.y + r.height / 2, width: r.width, height: r.height / 2 };\n\n/** The hit of a drag on `basis`. @internal Built by `TilingDrag.hit`. */\nexport function createTilingHit<T, K>(ctx: TilingHitContext<T, K>, basis: TilingBasis, options: TilingHitOptions<K> = {}): TilingHit<T, K> {\n const { ops, lift, base, home, after } = ctx;\n const key = options.key ?? String;\n const edge = Math.max(0, options.edge ?? TILING_HIT_DEFAULTS.edge);\n const travel = Math.max(0, options.travel ?? TILING_HIT_DEFAULTS.travel);\n const cap = Math.max(0, options.cap ?? TILING_HIT_DEFAULTS.cap);\n const neighborSwap = options.neighborSwap ?? TILING_HIT_DEFAULTS.neighborSwap;\n // Only the options the hit reads, whatever else a caller passes.\n const given: TilingHitRegions = options.regions ?? {};\n const regionOptions: PaneRegionOptions = {\n ...(given.center !== undefined ? { center: given.center } : {}),\n ...(given.centerX !== undefined ? { centerX: given.centerX } : {}),\n ...(given.centerY !== undefined ? { centerY: given.centerY } : {}),\n ...(given.centerMin !== undefined ? { centerMin: given.centerMin } : {}),\n ...(given.pixelRatio !== undefined ? { pixelRatio: given.pixelRatio } : {}),\n hysteresis: 0,\n };\n const laid = basis === \"lift\" ? lift : base;\n const stackOf = (t: T, k: K) => ops.stackOf?.(t, k) ?? null;\n const drawnAs = (t: T, k: K): K => stackOf(t, k)?.active ?? k;\n const subjectDrawn = drawnAs(lift.tree, ctx.subjectKey);\n\n /** The pane the base draws for `pane` of the basis: itself, or (the subject's own stack, on the lift) its stack's drawn member. */\n const atOf = (pane: K): K | null => {\n if (base.layout.has(pane)) return pane;\n const members = stackOf(laid.tree, pane)?.members ?? [];\n for (const m of members) {\n if (ctx.inSubject(m)) continue;\n const d = drawnAs(base.tree, m);\n if (base.layout.has(d)) return d;\n }\n return null;\n };\n\n // Every place, by id; each zone of it is a piece.\n const byId = new Map<string, Place<K>>();\n const homePlace: Place<K> = { id: \"home\", held: HOME, pane: null, pieces: home ? [{ poly: rectPoly(home), box: home, cuts: () => [] }] : [], owners: new Set([\"home\"]), slot: null };\n byId.set(\"home\", homePlace);\n const placeFor = (id: string, held: TilingHeld<K>, pane: PaneHit<K>, owner: string, piece: Piece, slot: Rect | null = null): Place<K> => {\n let p = byId.get(id);\n if (!p) byId.set(id, (p = { id, held, pane, pieces: [], owners: new Set(), slot }));\n p.pieces.push(piece);\n p.owners.add(owner);\n return p;\n };\n\n // Liveness and home-likeness, once per place.\n const liveMemo = new Map<string, boolean>();\n const live = (p: Place<K>): boolean => {\n if (p === homePlace) return true;\n let v = liveMemo.get(p.id);\n if (v === undefined) liveMemo.set(p.id, (v = after(p.held).refusal === null));\n return v;\n };\n // ---- Arrangements: a tree with sizes ignored (which panes sit in which run, in which order; which tabs in which\n // stack, in which order). Nested splits along one axis are one run. A split's axis is its own, else the one its layout\n // divides along.\n type Branch = Exclude<Split<K>, { readonly pane: K }>;\n const unionOf = (node: Split<K>, layout: ReadonlyMap<K, Rect>): Rect | null => {\n const rs = panesOf(node).map((k) => layout.get(k)).filter((r): r is Rect => !!r);\n if (!rs.length) return null;\n const x = Math.min(...rs.map((r) => r.x));\n const y = Math.min(...rs.map((r) => r.y));\n return { x, y, width: Math.max(...rs.map((r) => r.x + r.width)) - x, height: Math.max(...rs.map((r) => r.y + r.height)) - y };\n };\n const axisOf = (node: Branch, layout: ReadonlyMap<K, Rect>): Axis => {\n if (node.axis) return node.axis;\n const a = unionOf(node.a, layout);\n const b = unionOf(node.b, layout);\n return a && b && (a.x + a.width <= b.x + 0.5 || b.x + b.width <= a.x + 0.5) ? \"x\" : \"y\";\n };\n /** The run `node` is the root of, along `axis`: same-axis splits flattened (a master split is not part of a run). */\n const runOf = (node: Split<K>, axis: Axis, layout: ReadonlyMap<K, Rect>): Split<K>[] =>\n \"pane\" in node || node.master || axisOf(node, layout) !== axis ? [node] : [...runOf(node.a, axis, layout), ...runOf(node.b, axis, layout)];\n const arrangementOf = (t: T): string => {\n const layout = ctx.lay(t).layout;\n const rec = (node: Split<K>): string => {\n if (\"pane\" in node) {\n const s = stackOf(t, node.pane);\n return s ? `[${s.members.map(String).join(\",\")}]` : String(node.pane);\n }\n if (node.master) return `m${JSON.stringify(node.master)}(${rec(node.a)}|${rec(node.b)})`;\n const axis = axisOf(node, layout);\n return `${axis}(${runOf(node, axis, layout).map(rec).join(\",\")})`;\n };\n const split = ops.split(t);\n return split ? rec(split) : \"\";\n };\n // Normalized, as every change's tree is (`changeOf`, `after`): the two are compared like with like.\n const liftArrangement = arrangementOf(ops.normalize ? ops.normalize(lift.tree) : lift.tree);\n const homeMemo = new Map<string, boolean>();\n /** A live place whose release has the lift's arrangement: it is home. */\n const homeLike = (p: Place<K>): boolean => {\n if (p === homePlace) return true;\n let v = homeMemo.get(p.id);\n if (v === undefined) {\n v = live(p) && (after(p.held).tree === lift.tree || arrangementOf(after(p.held).tree) === liftArrangement);\n homeMemo.set(p.id, v);\n }\n return v;\n };\n\n /**\n * The sides gone on each run neighbor of the subject, judged once on the lift tree: a pane next to the subject as a\n * whole child of one run, with the same bounds across the run (its rect, ±0.5 px). A side there is gone when its\n * insert gives the lift's arrangement (the side facing the subject) or the swap's (the far side, when the swap\n * trades the two whole occupants). Only when the release leaves a slot: a torn tab has no run neighbor.\n */\n const goneSides = new Map<K, { readonly axis: Axis; readonly sides: readonly Side[] }>();\n const liftSplit = ops.split(lift.tree);\n if (home && liftSplit) {\n const find = (node: Split<K>): { axis: Axis; run: Split<K>[]; i: number } | null => {\n if (\"pane\" in node) return null;\n if (node.master) return find(node.a) ?? find(node.b);\n const axis = axisOf(node, lift.layout);\n const run = runOf(node, axis, lift.layout);\n const i = run.findIndex((e) => \"pane\" in e && e.pane === subjectDrawn);\n if (i >= 0) return { axis, run, i };\n for (const e of run) {\n const f = find(e);\n if (f) return f;\n }\n return null;\n };\n const found = find(liftSplit);\n if (found) {\n const { axis, run, i } = found;\n for (const [j, facing, far] of [\n [i - 1, axis === \"x\" ? \"right\" : \"bottom\", axis === \"x\" ? \"left\" : \"top\"],\n [i + 1, axis === \"x\" ? \"left\" : \"top\", axis === \"x\" ? \"right\" : \"bottom\"],\n ] as const) {\n const e = run[j];\n if (!e || !(\"pane\" in e)) continue;\n const r = lift.layout.get(e.pane);\n const same = (a: number, b: number): boolean => Math.abs(a - b) <= 0.5;\n if (!r || (axis === \"y\" ? !same(r.x, home.x) || !same(r.width, home.width) : !same(r.y, home.y) || !same(r.height, home.height))) continue;\n const swap = arrangementOf(ctx.changeOf({ kind: \"swap\", at: e.pane }));\n const sides = ([facing, far] as const).filter((side) => {\n const a = arrangementOf(ctx.changeOf({ kind: \"beside\", at: e.pane, side }));\n return a === liftArrangement || a === swap;\n });\n if (sides.length) goneSides.set(e.pane, { axis, sides });\n }\n }\n }\n\n // The targets and their places, built once.\n const targets: TilingHitTarget<K>[] = [];\n const panes: PaneHit<K>[] = [];\n if (home) targets.push({ id: \"home\", priority: 1, hit: { ...home }, pane: subjectDrawn, at: subjectDrawn, home: true });\n for (const [pane, rect] of laid.layout) {\n if (basis === \"lift\" && home && pane === subjectDrawn) continue;\n const at = atOf(pane);\n if (at === null || ctx.still?.(at)) continue;\n const k = key(at);\n const body: TilingHitTarget<K> = { id: `pane:${key(pane)}`, priority: 2, hit: { ...rect }, pane, at };\n const parts: PartHit<K>[] = [];\n const regions: Partial<Record<PaneRegion, Place<K>>> = {};\n // A run neighbor: its gone sides give their strips to the center, and the swap spans the neighbor share across the run.\n const gone = goneSides.get(lift.layout.has(pane) ? pane : at);\n const paneOptions: PaneRegionOptions = gone\n ? { ...regionOptions, sides: SIDES.filter((s) => !gone.sides.includes(s)), ...(gone.axis === \"y\" ? { centerX: neighborSwap } : { centerY: neighborSwap }) }\n : regionOptions;\n const ph: PaneHit<K> = { body, parts, regions, options: paneOptions };\n const members = stackOf(laid.tree, pane)?.members ?? [pane];\n const indexOf = (i: number): number | undefined => (i < members.length ? members.slice(0, i).filter((m) => !ctx.inSubject(m)).length : undefined);\n const seen = new Set<string>();\n for (const part of ops.parts?.(laid.tree, pane, rect) ?? []) {\n let pid = `part:${key(pane)}:${part.key}`;\n for (let n = 2; seen.has(pid); n++) pid = `part:${key(pane)}:${part.key}#${n}`;\n seen.add(pid);\n const target: TilingHitTarget<K> = { id: pid, priority: 1, hit: { ...part.rect }, pane, at, part: part.key };\n targets.push(target);\n const slotRects = part.slots ?? [];\n const slots = slotRects.map((s, i) => {\n const index = indexOf(i);\n const held: TilingHeld<K> = index === undefined ? { kind: \"join\", at } : { kind: \"join\", at, index };\n const place = placeFor(`join:${k}:${index ?? \"\"}`, held, ph, pid, { poly: rectPoly(s), box: s, cuts: () => (home ? [home] : []) }, s);\n return { rect: s, place };\n });\n const whole = placeFor(`join:${k}:`, { kind: \"join\", at }, ph, pid, {\n poly: rectPoly(part.rect),\n box: part.rect,\n cuts: () => [...(home ? [home] : []), ...slots.filter((s) => live(s.place)).map((s) => s.rect)],\n });\n parts.push({ target, place: whole, slots });\n }\n const shapes = paneRegionShapes(rect, paneOptions);\n const above = (): readonly Rect[] => [\n ...(home ? [home] : []),\n ...parts.flatMap((p) => (live(p.place) ? [p.target.hit] : p.slots.filter((s) => live(s.place)).map((s) => s.rect))),\n ];\n for (const region of [\"center\", ...SIDES] as const) {\n if (region !== \"center\" && paneOptions.sides && !paneOptions.sides.includes(region)) continue;\n const held: TilingHeld<K> = region === \"center\" ? { kind: \"swap\", at } : { kind: \"beside\", at, side: region };\n const id = region === \"center\" ? `swap:${k}` : `beside:${region}:${k}`;\n regions[region] = placeFor(id, held, ph, body.id, { poly: shapes[region], box: boxOf(shapes[region]), cuts: above });\n }\n targets.push(body);\n panes.push(ph);\n }\n Object.freeze(targets);\n\n /** The topmost live place at `p` (no hold, home-likeness not applied), and the refused place it fell through. */\n const rawAt = (p: Point): { readonly place: Place<K> | null; readonly refused: Place<K> | null } => {\n if (home && inside(home, p)) return { place: homePlace, refused: null };\n const pane = panes.find((ph) => inside(ph.body.hit, p));\n if (!pane) return { place: null, refused: null };\n let refused: Place<K> | null = null;\n for (const part of pane.parts) {\n if (!inside(part.target.hit, p)) continue;\n const slot = part.slots.find((s) => inside(s.rect, p));\n if (slot) {\n if (live(slot.place)) return { place: slot.place, refused: null };\n refused ??= slot.place;\n }\n if (live(part.place)) return { place: part.place, refused: null };\n refused ??= part.place;\n }\n const place = pane.regions[paneRegion(pane.body.hit, p, null, pane.options)]!;\n return live(place) ? { place, refused: null } : { place: null, refused: refused ?? place };\n };\n const effective = (p: Place<K> | null): Place<K> | null => (p && homeLike(p) ? homePlace : p);\n const placeAt = (p: Point): string | null => effective(rawAt(p).place)?.id ?? null;\n\n let homeLikeAll: Place<K>[] | null = null;\n /** Every zone of home: its rect, and every place that gives the lift back. */\n const homePieces = (): Piece[] => {\n homeLikeAll ??= [...byId.values()].filter((p) => p !== homePlace && homeLike(p));\n return [...homePlace.pieces, ...homeLikeAll.flatMap((p) => p.pieces)];\n };\n const capped = (px: number, extent: number): number => Math.min(px, cap * extent);\n /** Each piece's visible part: the piece less every zone above it, as convex polygons (worked out once, when asked). */\n const visibleMemo = new Map<Piece, Point[][]>();\n const visibleOf = (piece: Piece): Point[][] => {\n let v = visibleMemo.get(piece);\n if (!v) visibleMemo.set(piece, (v = piece.cuts().reduce<Point[][]>((polys, r) => polys.flatMap((q) => minusRect(q, r)), [[...piece.poly]])));\n return v;\n };\n /**\n * The edge measure: `p` lies within `edge` px (capped by the piece's extent, per axis) of the visible part of one of\n * the place's zones. What a zone above covers is not the place's: a pointer over home, or over a part above a body,\n * is measured from where the held zone shows, never from where it runs on beneath.\n */\n const near = (place: Place<K>, p: Point): boolean =>\n (place === homePlace ? homePieces() : place.pieces).some((piece) => {\n const ex = capped(edge, piece.box.width);\n const ey = capped(edge, piece.box.height);\n return nearPoly(piece.poly, p, ex, ey) && visibleOf(piece).some((q) => nearPoly(q, p, ex, ey));\n });\n /** The travel measure: inside the held place's pane (not over home), within `travel` px (capped) of where it was taken. */\n const keepsByTravel = (place: Place<K>, from: Point, p: Point): boolean => {\n if (!place.pane || !inside(place.pane.body.hit, p) || (home && inside(home, p))) return false;\n const box = boxOf(place.pieces.flatMap((piece) => rectPoly(piece.box)));\n const rx = capped(travel, box.width);\n const ry = capped(travel, box.height);\n if (rx <= 0 || ry <= 0) return false;\n return ((p.x - from.x) / rx) ** 2 + ((p.y - from.y) / ry) ** 2 < 1;\n };\n const hold = (state: TilingHold | null, p: Point): TilingHold | null => {\n const now = effective(rawAt(p).place);\n if (state) {\n if (now && now.id === state.place) return state;\n const held = byId.get(state.place);\n if (held && (near(held, p) || keepsByTravel(held, state.from, p))) return state;\n }\n return now ? { place: now.id, from: { x: p.x, y: p.y } } : null;\n };\n\n // The drag's one hold, stepped once per point.\n let state: TilingHold | null = null;\n let last: Point | null = null;\n const current = (p: Point): TilingHold | null => {\n if (!last || last.x !== p.x || last.y !== p.y) {\n state = hold(state, p);\n last = { x: p.x, y: p.y };\n }\n return state;\n };\n const placeOf = (target: TilingHitTarget<K>, p: Point): string | null => {\n const s = current(p);\n return s && byId.get(s.place)?.owners.has(target.id) ? s.place : null;\n };\n const markOf = (place: Place<K>): TilingMark<K> | null => {\n const r = place.pane?.body.hit;\n const h = place.held;\n if (!r || h.kind === \"home\") return null;\n if (h.kind === \"beside\") return { kind: \"beside\", at: h.at, side: h.side, rect: half(r, h.side) };\n if (h.kind === \"swap\") return { kind: \"swap\", at: h.at, rect: { ...r }, wash: home ? { ...home } : null };\n return { kind: \"join\", at: h.at, rect: { ...r }, slot: place.slot ? { ...place.slot } : null };\n };\n const read = (frame: TilingHitFrame<TilingHitTarget<K>>, p: Point): TilingHitRead<K> => {\n const s = current(p);\n const place = s ? (byId.get(s.place) ?? null) : null;\n const shown = place && place !== homePlace && frame.shown && place.owners.has(frame.shown.id) ? place : null;\n const held: TilingHeld<K> | null = place === homePlace ? HOME : (shown?.held ?? null);\n const refused = held ? null : (rawAt(p).refused?.held ?? null);\n return { held, refused, mark: basis === \"lift\" && shown ? markOf(shown) : null };\n };\n\n return {\n basis,\n home: home ? { ...home } : null,\n targets,\n intent: {\n tuning: { aimSpeed: Infinity, dwell: 0, switchHold: 0, roomAfter: 0, band: edge, bandShare: 1, breakthrough: 0, gapGrace: 0 },\n placeOf: (t, p) => placeOf(t, p),\n },\n placeAt,\n hold,\n heldOf: (id) => byId.get(id)?.held ?? null,\n placeOf: (t, p) => placeOf(t, p),\n read,\n drawn: (r) => (basis === \"lift\" ? lift : r.held === null ? base : r.held.kind === \"home\" ? lift : after(r.held)),\n release: (r) => after(r.held ?? HOME),\n };\n}\n","/**\n * Drop targets for tiling, in the root `Target` shape (what `@n-uf/motion/drag` takes). Both kinds come from one\n * helper: a pane target (`pane:<id>`, its hit the pane, the place in it its drop region) for the split tree, and an\n * insertion target (`at:<index>`, its hit and slot the dragged pane's rect with it inserted there) for an order layout.\n */\nimport type { Rect } from \"../geometry\";\nimport type { Target } from \"../target\";\nimport type { OrderLayout, OrderOptions } from \"./order\";\n\n/** A split tree's target: drop on pane `pane` (the region under the pointer says how). */\nexport interface PaneTarget<K> extends Target {\n readonly pane: K;\n}\n\n/** An order layout's target: insert the dragged pane at `index`; `layout` is every pane's rect with it there. */\nexport interface OrderTarget<K> extends Target {\n readonly index: number;\n readonly layout: ReadonlyMap<K, Rect>;\n}\n\n/** The one shape both kinds share: a slot-sized drop with no precedence over any other. */\nconst tilingTarget = (id: string, hit: Rect, slot?: Rect): Target => ({ id, priority: 2, hit, ...(slot ? { slot } : {}) });\n\nexport interface PaneTargetsOptions<K> {\n /** A pane left out: the dragged one, when it is still laid out. */\n readonly except?: K;\n /**\n * A pane's key in its target's id (`pane:<key>`); default `String`. Keys must be unique across the panes: a drag\n * intent follows its targets by id, so two panes with one key would be one target.\n */\n readonly key?: (pane: K) => string;\n}\n\n/** One target per pane of `layout`, its id `pane:<key>`. */\nexport function paneTargets<K>(layout: ReadonlyMap<K, Rect>, options: PaneTargetsOptions<K> = {}): PaneTarget<K>[] {\n const key = options.key ?? String;\n return [...layout].filter(([k]) => k !== options.except).map(([pane, r]) => ({ ...tilingTarget(`pane:${key(pane)}`, r), pane }));\n}\n\n/**\n * One target per index `dragged` could be inserted at among `panes` (which don't hold it), laid out by `arrange` in\n * `area`. Each target's hit and slot is `dragged`'s rect with it there, so the targets cover the area as the layout\n * does. Ids are `at:<index>`, unique whatever the panes are.\n */\nexport function orderTargets<K>(arrange: OrderLayout, panes: readonly K[], dragged: K, area: Rect, options?: OrderOptions): OrderTarget<K>[] {\n return Array.from({ length: panes.length + 1 }, (_, index) => {\n const layout = arrange([...panes.slice(0, index), dragged, ...panes.slice(index)], area, options);\n const slot = layout.get(dragged)!;\n return { ...tilingTarget(`at:${index}`, slot, slot), index, layout };\n });\n}\n","import type { Rect, Size } from \"../geometry\";\n\n/**\n * The minimum-size give-way: while a pane is laid out below its minimum, the newest pane (highest `age`) floats and\n * the rest are laid out again. Stops when every pane keeps its minimum or one pane is left. `layout` lays out the\n * kept panes; the result says which are kept (in their order) and which float (newest first).\n */\nexport function giveWay<K>(panes: readonly K[], layout: (kept: readonly K[]) => ReadonlyMap<K, Rect>, min: (pane: K) => Size, age: (pane: K) => number): { kept: K[]; floats: K[] } {\n let kept = [...panes];\n const floats: K[] = [];\n for (;;) {\n const res = layout(kept);\n const broken = [...res].some(([k, r]) => r.width < min(k).width - 0.5 || r.height < min(k).height - 0.5);\n if (!broken || kept.length <= 1) return { kept, floats };\n const newest = kept.reduce((a, b) => (age(b) > age(a) ? b : a));\n kept = kept.filter((k) => k !== newest);\n floats.push(newest);\n }\n}\n","/**\n * One layout for a tiling drag's held frame and its commit, the layout half: `tilingDrag(tree, subject, options)` gives\n * the drag's base (the tree with the subject released, laid out), its home (the gap the release leaves) and\n * `after(held)`, THE layout of each held place: what a release there commits, and what a frame holding it draws.\n *\n * The host keeps its own tree type and its own changes; it hands them over as a `TilingTree` adapter. The library owns\n * the rules: what is released and when, which tree each change takes, home, the refusals, and the one layout per held\n * place. Geometry has one source: the adapter gives the tree as a `Split` (`split`), and the library lays it out with\n * `layoutSplitTree` under the drag's options (`SplitOptions` plus `min`, as `canDropOnPane` takes them).\n *\n * The hit half, which place the pointer is over, is `hit(basis)`: built once per drag on one fixed layout (./hit).\n * See docs/placement.md, Entry: tiling.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { canSplitPane, dropFits, type DropOptions } from \"./drop\";\nimport { createTilingHit, type TilingBasis, type TilingHit, type TilingHitOptions } from \"./hit\";\nimport { layoutSplitTree } from \"./layout\";\nimport { panesOf } from \"./split\";\nimport type { TilingAfter, TilingHeld, TilingLaidOut, TilingMove, TilingRefusal, TilingStack, TilingSubject, TilingTree } from \"./tree\";\n\nexport type { TilingAfter, TilingHeld, TilingLaidOut, TilingMove, TilingRefusal, TilingSize, TilingStack, TilingSubject, TilingTree } from \"./tree\";\n\n/** What `tilingDrag` reads: the adapter, the stage, and the layout options (`SplitOptions` plus `min`, the least pane width and height a drop keeps). */\nexport interface TilingDragOptions<T, K> extends DropOptions<K> {\n readonly ops: TilingTree<T, K>;\n /** The stage the tree is laid out in, px. */\n readonly area: Rect;\n /** Panes that take no drop (a swap, a side or a join on one is refused `\"still\"`). Default: none. */\n readonly still?: (pane: K) => boolean;\n}\n\n/**\n * A drag of one subject: its base, its home, and the one layout of each held place. Built per drag: its `after` and its\n * hits (with their hold) are remembered for that drag alone, so a drag cancelled and lifted again takes a new one.\n */\nexport interface TilingDrag<T, K> {\n readonly subject: TilingSubject<K>;\n /** The tree at the lift, laid out: what is drawn before the drag, and what a release on home commits. */\n readonly lift: TilingLaidOut<T, K>;\n /** The hit basis, fixed for the drag: the tree with the subject released, laid out. What a frame draws at rest (nothing held, or a refused place). */\n readonly base: TilingLaidOut<T, K>;\n /**\n * The gap the release leaves: the subject's lift rect when releasing it takes a drawn pane away (a pane alone, a\n * whole stack), null when it takes none (a member torn out of a stack that stays drawn).\n */\n readonly home: Rect | null;\n /** THE layout of `held`. Remembered per held place: the same place gives the same object. */\n after(held: TilingHeld<K>): TilingAfter<T, K>;\n /**\n * The drag's hit half on `basis`, built from that one layout and fixed for the drag: `\"lift\"` for a host that draws\n * marks over the lift, `\"base\"` for one that draws the held place's landed layout. Remembered per basis, as `after` is\n * per place: every call on one basis gives the same hit, with its one hold, and the first call's options stand. A\n * fresh hold is the pure `hit.hold(state, point)`.\n */\n hit(basis: TilingBasis, options?: TilingHitOptions<K>): TilingHit<T, K>;\n}\n\nconst sameRect = (a: Rect, b: Rect): boolean => Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS && Math.abs(a.width - b.width) <= EPS && Math.abs(a.height - b.height) <= EPS;\n\n/** A px option as the drop rules read it: finite and above 0, else 0. */\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\n/**\n * The drag of `subject` in `tree`: its lift and base layouts, its home, and `after(held)`, the one layout of each held\n * place. `tree` is never changed; `after({ kind: \"home\" }).tree` is `tree` itself.\n *\n * - **`after(held).tree`** is what a release commits: `normalize(change)`, where the change is `beside` or `join` on\n * the released tree, or `swap` on the lift tree (see `TilingTree` for why). Home's is the lift tree, never normalized.\n * - **`layout`** is that tree laid out, so a frame that draws it draws exactly what the release stores.\n * - **Refusals** are judged on the base (room) and on the change's own layout (fit), never on another tree.\n *\n * Throws when the subject is not in `tree` (neither drawn nor a member of a drawn stack): a drag has nothing to lift.\n */\nexport function tilingDrag<T, K>(tree: T, subject: TilingSubject<K>, options: TilingDragOptions<T, K>): TilingDrag<T, K> {\n const { ops, area } = options;\n const normalize = (t: T): T => (ops.normalize ? ops.normalize(t) : t);\n const lay = (t: T): TilingLaidOut<T, K> => {\n const { panes, splits } = layoutSplitTree(ops.split(t), area, options);\n return { tree: t, layout: panes, splits };\n };\n const stackOf = (t: T, pane: K): TilingStack<K> | null => ops.stackOf?.(t, pane) ?? null;\n /** The key `pane` is drawn as in `t`: its stack's active member, or itself. */\n const drawnAs = (t: T, pane: K): K => stackOf(t, pane)?.active ?? pane;\n const subjectKey = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n\n const lift = lay(tree);\n const liftRect = lift.layout.get(drawnAs(tree, subjectKey));\n if (!liftRect) {\n const what = subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`;\n throw new Error(`tilingDrag: the subject (${what}) is not in the tree: it is neither drawn nor a member of a drawn stack`);\n }\n const base = lay(ops.release(tree, subject));\n const takesPane = panesOf(ops.split(base.tree)).length < panesOf(ops.split(tree)).length;\n const home = takesPane ? { ...liftRect } : null;\n\n /** Every drawn pane of `laid` but the subject's whose rect differs from where it was drawn at the lift. */\n const movedIn = (laid: TilingLaidOut<T, K>): TilingMove<K>[] => {\n const own = drawnAs(laid.tree, subjectKey);\n const out: TilingMove<K>[] = [];\n for (const [pane, to] of laid.layout) {\n if (pane === own) continue;\n const from = lift.layout.get(lift.layout.has(pane) ? pane : drawnAs(tree, pane));\n if (from && !sameRect(from, to)) out.push({ pane, from, to });\n }\n return out;\n };\n\n const inSubject = (pane: K): boolean => (subject.kind === \"pane\" ? pane === subject.pane : subject.stack.members.includes(pane));\n\n /** The refusal a held place has before any change is made: whose `at` it names, and whether the adapter can make it. */\n const refusalBefore = (held: Exclude<TilingHeld<K>, { kind: \"home\" }>): TilingRefusal<K> | null => {\n const at = held.at;\n if (inSubject(at)) return { code: \"self\" };\n if (held.kind === \"swap\") {\n // A swap with the stack the subject is torn from: the subject's own place.\n const own = stackOf(tree, subjectKey);\n if (own && stackOf(tree, at)?.id === own.id) return { code: \"self\" };\n }\n if (!base.layout.has(at)) return { code: \"missing\" };\n if (options.still?.(at)) return { code: \"still\" };\n if (held.kind === \"join\" && !ops.join) return { code: \"join\" };\n return null;\n };\n\n /** A refused place: the release commits nothing, so its layout is the lift's. */\n const refused = (held: TilingHeld<K>, refusal: TilingRefusal<K>): TilingAfter<T, K> => ({ ...lift, held, refusal, landing: null, moved: [] });\n\n /** The room rule on `at`'s base rect (`canSplitPane`), as a code with the numbers. */\n const roomFor = (at: K, side: Side): TilingRefusal<K> | null => {\n const r = base.layout.get(at)!;\n if (canSplitPane(r, side, options).ok) return null;\n const along = side === \"left\" || side === \"right\";\n const gutter = px(options.gap) + px(options.handle);\n const min = px(options.min);\n const span = along ? r.width : r.height;\n return span < min * 2 + gutter ? { code: \"room-along\", need: min * 2 + gutter, have: span } : { code: \"room-across\", need: min, have: along ? r.height : r.width };\n };\n\n const make = (held: TilingHeld<K>): TilingAfter<T, K> => {\n if (held.kind === \"home\") return { ...lift, held, refusal: null, landing: liftRect, moved: [] };\n const before = refusalBefore(held) ?? (held.kind === \"beside\" ? roomFor(held.at, held.side) : null);\n if (before) return refused(held, before);\n const changed =\n held.kind === \"swap\"\n ? ops.swap(tree, subject, held.at)\n : held.kind === \"beside\"\n ? ops.beside(base.tree, subject, held.at, held.side, { kind: \"half\" })\n : ops.join!(base.tree, subject, held.at, held.index);\n const laid = lay(normalize(changed));\n const own = drawnAs(laid.tree, subjectKey);\n // The fit rule, on every change: in the layout it makes, the subject and `at` (each as it is drawn there) keep `min`.\n // `side` only words `dropFits`' reason, which is not read here.\n const partner = drawnAs(laid.tree, held.at);\n if (!dropFits(laid.layout, own, partner, area, { min: options.min, side: held.kind === \"beside\" ? held.side : \"left\" }).ok) {\n const small = (r: Rect | undefined): boolean => !r || r.width < px(options.min) || r.height < px(options.min);\n return refused(held, { code: \"fit\", pane: small(laid.layout.get(own)) ? own : partner });\n }\n return { ...laid, held, refusal: null, landing: laid.layout.get(own) ?? null, moved: movedIn(laid) };\n };\n\n // Remembered per held place: by kind (and side or index), then by `at`, so keys need no string form.\n const homeAfter = make({ kind: \"home\" });\n const memo = new Map<string, Map<K, TilingAfter<T, K>>>();\n const after = (held: TilingHeld<K>): TilingAfter<T, K> => {\n if (held.kind === \"home\") return homeAfter;\n const k = held.kind === \"beside\" ? `beside:${held.side}` : held.kind === \"join\" ? `join:${held.index ?? \"\"}` : \"swap\";\n let byAt = memo.get(k);\n if (!byAt) memo.set(k, (byAt = new Map()));\n let a = byAt.get(held.at);\n if (!a) byAt.set(held.at, (a = make(held)));\n return a;\n };\n\n /** The tree a change makes, whatever room it has: `normalize(swap(tree))`, or `normalize(beside(release(tree)))`. */\n const changeOf = (held: { kind: \"swap\"; at: K } | { kind: \"beside\"; at: K; side: Side }): T =>\n normalize(held.kind === \"swap\" ? ops.swap(tree, subject, held.at) : ops.beside(base.tree, subject, held.at, held.side, { kind: \"half\" }));\n // One hit per basis, remembered like `after`: the first call's options stand, and a host that asks again gets the\n // same hit (and its hold).\n const hits = new Map<TilingBasis, TilingHit<T, K>>();\n const hit = (basis: TilingBasis, hitOptions?: TilingHitOptions<K>): TilingHit<T, K> => {\n let h = hits.get(basis);\n if (!h) hits.set(basis, (h = createTilingHit({ ops, lift, base, home, subjectKey, inSubject, ...(options.still ? { still: options.still } : {}), after, lay, changeOf }, basis, hitOptions)));\n return h;\n };\n\n return { subject, lift, base, home, after, hit };\n}\n","/**\n * The reference `TilingTree` adapter: placement's own `Split`, with optional stacks beside it. Tests, labs and hosts\n * whose tree is a `Split` use it as it is; a host with its own tree reads it as the worked example of each change.\n * See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { TilingPart, TilingStack, TilingSubject, TilingTree } from \"./tree\";\nimport { removePane, splitPane, type Split } from \"./split\";\n\n/** The reference adapter's parts: none by default. */\nexport interface SplitTreeOpsOptions<K> {\n /** A title bar's height along each pane's top, px: its one part (a join). Default 0: no parts. */\n readonly bar?: number;\n /** A stack's tab width per member, px (default 80): its bar's slots. */\n readonly tab?: (member: K) => number;\n}\n\n/**\n * A split tree with stacks: `split` divides the area among the drawn panes, and each stack stands in it as its\n * `active` member's key. A pane in no stack is drawn alone. A stack of one is kept until `normalize` makes it a pane.\n */\nexport interface StackedSplit<K> {\n readonly split: Split<K> | null;\n readonly stacks?: readonly TilingStack<K>[];\n}\n\n/** `split` with every pane key mapped by `fn` (the same object where nothing changes). */\nfunction mapKeys<K>(split: Split<K> | null, fn: (k: K) => K): Split<K> | null {\n if (!split) return split;\n if (\"pane\" in split) {\n const k = fn(split.pane);\n return k === split.pane ? split : { pane: k };\n }\n const a = mapKeys(split.a, fn)!;\n const b = mapKeys(split.b, fn)!;\n return a === split.a && b === split.b ? split : { ...split, a, b };\n}\n\nconst stacksOf = <K>(t: StackedSplit<K>): readonly TilingStack<K>[] => t.stacks ?? [];\nconst of = <K>(split: Split<K> | null, stacks: readonly TilingStack<K>[]): StackedSplit<K> => (stacks.length ? { split, stacks } : { split });\nconst membersOf = <K>(s: TilingSubject<K>): readonly K[] => (s.kind === \"pane\" ? [s.pane] : s.stack.members);\nconst drawnOf = <K>(s: TilingSubject<K>): K => (s.kind === \"pane\" ? s.pane : s.stack.active);\n\n/**\n * The reference adapter over `StackedSplit<K>`:\n * - `release`: a whole stack leaves the split (its drawn key, `removePane`) and the stack list; a pane in a stack leaves\n * its members (the next member, else the one before, is drawn when it was the active one); a pane alone leaves the split;\n * - `beside`: `splitPane` on `at`'s side (a half split), a whole stack drawn as its active member and kept whole;\n * - `swap`: a pane trades keys with `at` wherever each is (the split, a stack's members), so each takes the other's\n * place; a whole stack trades its drawn place in the split with `at`'s;\n * - `join`: the subject's members go into `at`'s stack at `index` (default last; clamped), the first of them drawn; a\n * pane `at` alone becomes a stack, its id `stack:<at>` (made unique);\n * - `normalize`: a stack of fewer than two members becomes its pane; the same object when there is none;\n * - `parts` (with `options.bar`): a title bar along each pane's top, `bar` px high; a stack's bar has a slot per member,\n * left to right, each `tab(member)` px wide (default 80), cut at the bar's end.\n */\nexport function splitTreeOps<K>(options: SplitTreeOpsOptions<K> = {}): TilingTree<StackedSplit<K>, K> {\n const bar = options.bar ?? 0;\n const tab = options.tab ?? (() => 80);\n return {\n ...(bar > 0\n ? {\n parts(t: StackedSplit<K>, pane: K, r: Rect): readonly TilingPart[] {\n const rect: Rect = { x: r.x, y: r.y, width: r.width, height: Math.min(bar, r.height) };\n const stack = stacksOf(t).find((s) => s.members.includes(pane));\n if (!stack) return [{ key: \"bar\", rect }];\n const slots: Rect[] = [];\n let x = rect.x;\n for (const m of stack.members) {\n const width = Math.max(0, Math.min(tab(m), rect.x + rect.width - x));\n slots.push({ x, y: rect.y, width, height: rect.height });\n x += width;\n }\n return [{ key: \"bar\", rect, slots }];\n },\n }\n : {}),\n split: (t) => t.split,\n stackOf: (t, pane) => stacksOf(t).find((s) => s.members.includes(pane)) ?? null,\n release(t, s) {\n if (s.kind === \"stack\") {\n const stack = stacksOf(t).find((x) => x.id === s.stack.id);\n return of(removePane(t.split, stack?.active ?? s.stack.active), stacksOf(t).filter((x) => x !== stack));\n }\n const stack = stacksOf(t).find((x) => x.members.includes(s.pane));\n if (!stack) return of(removePane(t.split, s.pane), stacksOf(t));\n const i = stack.members.indexOf(s.pane);\n const members = stack.members.filter((m) => m !== s.pane);\n if (members.length === 0) return of(removePane(t.split, s.pane), stacksOf(t).filter((x) => x !== stack));\n const active = stack.active === s.pane ? (members[i] ?? members[i - 1]!) : stack.active;\n const was = stack.active;\n return of(\n mapKeys(t.split, (k) => (k === was ? active : k)),\n stacksOf(t).map((x) => (x === stack ? { id: stack.id, members, active } : x)),\n );\n },\n beside(released, s, at, side) {\n const split = splitPane(released.split, at, drawnOf(s), side);\n return of(split, s.kind === \"pane\" ? stacksOf(released) : [...stacksOf(released), s.stack]);\n },\n swap(t, s, at) {\n if (s.kind === \"stack\") {\n const x = stacksOf(t).find((st) => st.id === s.stack.id)?.active ?? s.stack.active;\n return of(mapKeys(t.split, (k) => (k === x ? at : k === at ? x : k)), stacksOf(t));\n }\n const x = s.pane;\n const trade = (k: K): K => (k === x ? at : k === at ? x : k);\n return of(\n mapKeys(t.split, trade),\n stacksOf(t).map((st) => ({ id: st.id, members: st.members.map(trade), active: trade(st.active) })),\n );\n },\n join(released, s, at, index) {\n const moving = membersOf(s);\n const target = stacksOf(released).find((x) => x.members.includes(at));\n const into = target ? target.members : [at];\n const i = Math.max(0, Math.min(into.length, index ?? into.length));\n const members = [...into.slice(0, i), ...moving, ...into.slice(i)];\n const active = moving[0]!;\n const drawn = target ? target.active : at;\n const ids = new Set(stacksOf(released).map((x) => x.id));\n let id = target?.id ?? `stack:${String(at)}`;\n for (let n = 2; !target && ids.has(id); n++) id = `stack:${String(at)}:${n}`;\n const stack: TilingStack<K> = { id, members, active };\n return of(\n mapKeys(released.split, (k) => (k === drawn ? active : k)),\n target ? stacksOf(released).map((x) => (x === target ? stack : x)) : [...stacksOf(released), stack],\n );\n },\n normalize(t) {\n const kept = stacksOf(t).filter((s) => s.members.length >= 2);\n return kept.length === stacksOf(t).length ? t : of(t.split, kept);\n },\n };\n}\n","/**\n * The properties of a tiling drag's layout half, run on any `TilingTree` adapter: a host runs them on its own adapter\n * and trees, the library's tests on the reference one. Pure: no test runner, no DOM. See docs/placement.md, Entry: tiling.\n */\nimport { EPS, overlap, type Rect } from \"../geometry\";\nimport { PANE_SIDES } from \"./regions\";\nimport { layoutSplitTree } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\nimport { tilingDrag, type TilingDragOptions, type TilingHeld, type TilingSubject } from \"./drag\";\n\n/** The properties, by name (each is a key of `TilingConformance.counts`). */\nexport const TILING_PROPERTIES = [\n /** `after(home).tree` is the lift tree itself, its layout the lift's, never normalized. */\n \"home-is-lift\",\n /** `home` is the subject's lift rect when the release takes a drawn pane away, else null. */\n \"home-is-the-gap\",\n /** Home lies only over base panes whose rect changed when the subject was released. */\n \"home-over-changed\",\n /** `after(held).layout` is `after(held).tree` laid out; the landing is the subject's rect there; a refused place is the lift. */\n \"one-layout\",\n /** A swap puts the partner in the subject's lift rect and the subject in the partner's, and the others keep theirs. Not checked under per-child layout callbacks (`fixed`, `fixedAcross`, `floor`), which may move the ratios. */\n \"swap-exchanges\",\n /** A swap puts the partner in the subject's old slot of the split (as it is drawn there) and the subject in the partner's. Checked under every option, the per-child callbacks included. */\n \"swap-trades-slots\",\n /** A pane swapped with a stack's drawn member takes its place in that stack, and the stack's other members stay, in order; a member torn out of a stack leaves the partner in its place there. */\n \"swap-keeps-stack-mates\",\n /**\n * The subject is in every tree exactly once: no key (a drawn pane, or a member of a stack) is in an `after(held).tree`\n * twice; the base holds none of the subject's members (a torn member's stack mates stay); and every `after(held).tree`\n * holds the base's keys and the subject's, and no other. Catches an adapter whose `release` leaves the subject in.\n */\n \"subject-once\",\n /** `beside` and `join` commit `normalize(change(release(tree)))`: the subject is released first, then placed. */\n \"release-first\",\n /** A whole stack moves as one: after any change its members are in one stack, in their order. */\n \"stack-moves-whole\",\n /** `normalize` changes nothing on any `after(held).tree`. */\n \"normalize-idempotent\",\n /** The drag never changes the tree it is given, and remembers each held place (the same place, the same object). */\n \"nothing-changes\",\n] as const;\n\nexport type TilingProperty = (typeof TILING_PROPERTIES)[number];\n\n/** A conformance run: whether every property held, the first failures (in words), and per property how many checks ran and failed. */\nexport interface TilingConformance {\n readonly ok: boolean;\n readonly failures: readonly string[];\n readonly counts: Readonly<Record<TilingProperty, { readonly checked: number; readonly failed: number }>>;\n}\n\n/** Structural equality of plain data: primitives, arrays, plain objects, Maps and Sets. */\nfunction sameData(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) return false;\n if (a instanceof Map || b instanceof Map) {\n if (!(a instanceof Map && b instanceof Map) || a.size !== b.size) return false;\n for (const [k, v] of a) if (!b.has(k) || !sameData(v, b.get(k))) return false;\n return true;\n }\n if (a instanceof Set || b instanceof Set) {\n if (!(a instanceof Set && b instanceof Set) || a.size !== b.size) return false;\n for (const v of a) if (!b.has(v)) return false;\n return true;\n }\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const ka = Object.keys(a).filter((k) => (a as Record<string, unknown>)[k] !== undefined);\n const kb = Object.keys(b).filter((k) => (b as Record<string, unknown>)[k] !== undefined);\n if (ka.length !== kb.length) return false;\n return ka.every((k) => sameData((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]));\n}\n\n/** A deep copy of plain data (arrays, plain objects, Maps, Sets), to prove the drag left its tree alone. */\nfunction copy<V>(v: V): V {\n if (typeof v !== \"object\" || v === null) return v;\n if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copy(x)])) as V;\n if (v instanceof Set) return new Set([...v].map(copy)) as V;\n if (Array.isArray(v)) return v.map(copy) as V;\n return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, copy(x)])) as V;\n}\n\nconst near = (a: Rect | undefined | null, b: Rect | undefined | null, by = 0.5): boolean =>\n !!a && !!b && Math.abs(a.x - b.x) <= by && Math.abs(a.y - b.y) <= by && Math.abs(a.width - b.width) <= by && Math.abs(a.height - b.height) <= by;\n\n/** The way from the root of `split` to the pane `key` (`a` and `b` at each split), or null when it is not drawn. */\nfunction pathOf<K>(split: Split<K> | null, key: K): readonly (\"a\" | \"b\")[] | null {\n if (!split) return null;\n if (\"pane\" in split) return split.pane === key ? [] : null;\n for (const side of [\"a\", \"b\"] as const) {\n const rest = pathOf(split[side], key);\n if (rest) return [side, ...rest];\n }\n return null;\n}\n\n/** The pane at the end of `path` in `split`, or undefined when the path does not end on a pane. */\nfunction paneAt<K>(split: Split<K> | null, path: readonly (\"a\" | \"b\")[]): K | undefined {\n let node = split;\n for (const side of path) {\n if (!node || \"pane\" in node) return undefined;\n node = node[side];\n }\n return node && \"pane\" in node ? node.pane : undefined;\n}\n\nconst sameList = <K>(a: readonly K[], b: readonly K[]): boolean => a.length === b.length && a.every((k, i) => Object.is(k, b[i]));\n\nconst show = (h: TilingHeld<unknown>): string =>\n h.kind === \"home\" ? \"home\" : `${h.kind} ${String(h.at)}${h.kind === \"beside\" ? ` ${h.side}` : h.kind === \"join\" && h.index !== undefined ? ` @${h.index}` : \"\"}`;\n\n/** Every subject a tree offers: each pane drawn alone, each stack whole, and each member of a stack torn out of it. */\nexport function tilingSubjects<T, K>(tree: T, options: Pick<TilingDragOptions<T, K>, \"ops\">): TilingSubject<K>[] {\n const { ops } = options;\n const out: TilingSubject<K>[] = [];\n for (const pane of panesOf(ops.split(tree))) {\n const stack = ops.stackOf?.(tree, pane) ?? null;\n if (!stack) out.push({ kind: \"pane\", pane });\n else out.push({ kind: \"stack\", stack }, ...stack.members.map((m): TilingSubject<K> => ({ kind: \"pane\", pane: m })));\n }\n return out;\n}\n\n/**\n * A property run's tally: per property how many checks ran and failed, the first `limit` failures in words, and a\n * check for one case, its name leading each failure. Shared by the drag's and the hit's conformance. @internal\n */\nexport function propertyTally<P extends string>(properties: readonly P[], limit: number) {\n const counts = Object.fromEntries(properties.map((p) => [p, { checked: 0, failed: 0 }])) as Record<P, { checked: number; failed: number }>;\n const failures: string[] = [];\n const checkFor =\n (name: string) =>\n (p: P, ok: boolean, why: () => string): void => {\n counts[p].checked++;\n if (ok) return;\n counts[p].failed++;\n if (failures.length < limit) failures.push(`${p}: ${name}: ${why()}`);\n };\n return { counts, failures, checkFor };\n}\n\n/**\n * Runs every property on every subject of every tree (`tilingSubjects`) and every held place of its drag: home, and for\n * each pane drawn in the base a swap, the four sides and a join (last and first). Trees are taken as committed ones,\n * so `normalize` (if any) must leave them as they are. Gives the first `limit` failures (default 20) in words.\n */\nexport function tilingConformance<T, K>(trees: Iterable<T>, options: TilingDragOptions<T, K>, limit = 20): TilingConformance {\n const { ops, area } = options;\n const { counts, failures, checkFor } = propertyTally(TILING_PROPERTIES, limit);\n const norm = (t: T): T => (ops.normalize ? ops.normalize(t) : t);\n const lay = (t: T) => layoutSplitTree(ops.split(t), area, options).panes;\n const drawnAs = (t: T, k: K): K => ops.stackOf?.(t, k)?.active ?? k;\n const callbacks = !!(options.fixed || options.fixedAcross || options.floor);\n /** Every key of `t`: each drawn pane, a stack counted as its members. */\n const keysOf = (t: T): K[] => panesOf(ops.split(t)).flatMap((p) => ops.stackOf?.(t, p)?.members ?? [p]);\n /** The keys `keys` holds more than once. */\n const twice = (keys: readonly K[]): K[] => keys.filter((k, i) => keys.indexOf(k) !== i);\n let n = 0;\n for (const tree of trees) {\n const snapshot = copy(tree);\n for (const subject of tilingSubjects(tree, options)) {\n const check = checkFor(`tree ${n}, ${subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`}`);\n const drag = tilingDrag(tree, subject, options);\n const key = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n const liftOf = (k: K): Rect | undefined => drag.lift.layout.get(drag.lift.layout.has(k) ? k : drawnAs(tree, k));\n const subjectLift = liftOf(key);\n\n // The subject, exactly once: out of the base, and in every after's tree beside the base's keys.\n const members: readonly K[] = subject.kind === \"pane\" ? [subject.pane] : subject.stack.members;\n const baseKeys = keysOf(drag.base.tree);\n const kept = baseKeys.filter((k) => members.includes(k));\n check(\"subject-once\", kept.length === 0 && twice(baseKeys).length === 0, () => `the base holds ${kept.length ? `the subject's ${kept.map(String).join(\", \")}` : `${twice(baseKeys).map(String).join(\", \")} twice`}`);\n const want = new Set<K>([...baseKeys, ...members]);\n\n // Home.\n const home = drag.after({ kind: \"home\" });\n check(\"home-is-lift\", home.tree === tree && sameData(home.layout, drag.lift.layout) && home.refusal === null, () => \"after(home) is not the lift tree laid out\");\n const takes = panesOf(ops.split(drag.base.tree)).length < panesOf(ops.split(tree)).length;\n check(\"home-is-the-gap\", takes ? near(drag.home, subjectLift, EPS) : drag.home === null, () => `home ${JSON.stringify(drag.home)}, the release ${takes ? \"takes\" : \"takes no\"} drawn pane`);\n if (drag.home) {\n for (const [pane, r] of drag.base.layout) {\n if (overlap(drag.home, r) <= EPS) continue;\n check(\"home-over-changed\", !near(r, liftOf(pane), EPS), () => `home lies over ${String(pane)}, which the release left at ${JSON.stringify(r)}`);\n }\n }\n\n // Every held place on every base pane.\n const held: TilingHeld<K>[] = [{ kind: \"home\" }];\n for (const at of drag.base.layout.keys()) {\n held.push({ kind: \"swap\", at }, ...PANE_SIDES.map((side): TilingHeld<K> => ({ kind: \"beside\", at, side })));\n if (ops.join) held.push({ kind: \"join\", at }, { kind: \"join\", at, index: 0 });\n }\n for (const h of held) {\n const a = drag.after(h);\n check(\"nothing-changes\", drag.after(h) === a, () => `${show(h)}: after() gave a new object for the same place`);\n check(\"normalize-idempotent\", sameData(norm(a.tree), a.tree), () => `${show(h)}: normalize changes after().tree`);\n const keys = keysOf(a.tree);\n const extra = keys.filter((k) => !want.has(k));\n const lost = [...want].filter((k) => !keys.includes(k));\n check(\n \"subject-once\",\n twice(keys).length === 0 && extra.length === 0 && lost.length === 0,\n () => `${show(h)}: after().tree holds ${[twice(keys).length ? `${twice(keys).map(String).join(\", \")} twice` : \"\", extra.length ? `${extra.map(String).join(\", \")} it should not` : \"\", lost.length ? `no ${lost.map(String).join(\", \")}` : \"\"].filter(Boolean).join(\"; \")}`,\n );\n if (a.refusal) {\n check(\"one-layout\", a.tree === tree && a.landing === null && a.moved.length === 0, () => `${show(h)}: refused (${a.refusal!.code}) but not the lift`);\n continue;\n }\n const own = drawnAs(a.tree, key);\n check(\"one-layout\", sameData(a.layout, lay(a.tree)) && near(a.landing, a.layout.get(own), EPS), () => `${show(h)}: the layout or the landing is not after().tree's`);\n // Per-child layout callbacks (floors, fixed lengths) read which pane is where, so a swap may move the split\n // ratios themselves: the exchange is then what those callbacks make of it, and is not checked.\n if (h.kind === \"swap\" && !callbacks) {\n const partner = drawnAs(a.tree, h.at);\n const exchanged = near(a.layout.get(partner), subjectLift) && near(a.layout.get(own), liftOf(h.at));\n const others = [...a.layout].every(([p, r]) => p === own || p === partner || near(r, liftOf(p)));\n check(\"swap-exchanges\", exchanged && others, () => `${show(h)}: partner at ${JSON.stringify(a.layout.get(partner))} (subject was ${JSON.stringify(subjectLift)}), subject at ${JSON.stringify(a.layout.get(own))}${others ? \"\" : \", and another pane moved\"}`);\n }\n if (h.kind === \"swap\") {\n // The slots themselves, which no layout callback moves: the partner where the subject was drawn, and back.\n const liftSplit = ops.split(tree);\n const afterSplit = ops.split(a.tree);\n const subjectSlot = pathOf(liftSplit, drawnAs(tree, key));\n const partnerSlot = pathOf(liftSplit, h.at);\n const partnerThere = !!subjectSlot && paneAt(afterSplit, subjectSlot) === drawnAs(a.tree, h.at);\n const subjectThere = !!partnerSlot && paneAt(afterSplit, partnerSlot) === drawnAs(a.tree, key);\n check(\"swap-trades-slots\", partnerThere && subjectThere, () => `${show(h)}: ${partnerThere ? \"\" : `the partner is not in the subject's old slot (${String(subjectSlot && paneAt(afterSplit, subjectSlot))} is)`}${partnerThere || subjectThere ? \"\" : \"; \"}${subjectThere ? \"\" : `the subject is not in the partner's old slot (${String(partnerSlot && paneAt(afterSplit, partnerSlot))} is)`}`);\n if (subject.kind === \"pane\" && ops.stackOf) {\n // Each pane that stood in a stack is replaced there by the other, the stack's other members in place.\n for (const [from, to] of [\n [h.at, subject.pane],\n [subject.pane, h.at],\n ] as const) {\n const was = ops.stackOf(tree, from);\n if (!was) continue;\n const now = ops.stackOf(a.tree, to);\n const expect = was.members.map((m) => (m === from ? to : m));\n check(\"swap-keeps-stack-mates\", !!now && sameList(now.members, expect), () => `${show(h)}: ${String(to)} is in ${now ? `[${now.members.map(String).join(\", \")}]` : \"no stack\"}, expected [${expect.map(String).join(\", \")}]`);\n }\n }\n }\n if (h.kind === \"beside\" || h.kind === \"join\") {\n const released = ops.release(tree, subject);\n const changed = h.kind === \"beside\" ? ops.beside(released, subject, h.at, h.side, { kind: \"half\" }) : ops.join!(released, subject, h.at, h.index);\n check(\"release-first\", sameData(a.tree, norm(changed)), () => `${show(h)}: after().tree is not normalize(change(release(tree)))`);\n }\n if (subject.kind === \"stack\" && h.kind !== \"home\") {\n const ms = subject.stack.members;\n const st = ops.stackOf?.(a.tree, ms[0]!) ?? null;\n const i = st ? st.members.indexOf(ms[0]!) : -1;\n const whole = !!st && ms.every((m, j) => st.members[i + j] === m);\n check(\"stack-moves-whole\", whole, () => `${show(h)}: the stack's members are not together in one stack`);\n }\n }\n check(\"nothing-changes\", sameData(tree, snapshot), () => \"the drag changed the tree it was given\");\n }\n n++;\n }\n return { ok: failures.length === 0 && Object.values(counts).every((c) => c.failed === 0), failures, counts };\n}\n","/**\n * The properties of a tiling drag's hit half (`TILING_HIT_PROPERTIES`), run on any `TilingTree` adapter: the library's tests on the reference\n * one, a host on its own (its `parts` included). Pure: no test runner, no DOM. The zone rule is checked against a second\n * copy of it written here (the center by its formula, the side regions as trapezoids), never the library's own call.\n * See docs/placement.md, Entry: tiling, \"A tiling drag's hit half\".\n */\nimport { contains, type Point, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { tilingDrag, type TilingDrag, type TilingDragOptions, type TilingHeld, type TilingSubject } from \"./drag\";\nimport { TILING_HIT_DEFAULTS, type TilingBasis, type TilingHit, type TilingHitOptions, type TilingHitRead, type TilingHitTarget, type TilingHold } from \"./hit\";\nimport { layoutSplitTree } from \"./layout\";\nimport { PANE_REGION_DEFAULTS } from \"./regions\";\nimport type { Split } from \"./split\";\nimport { propertyTally, tilingSubjects } from \"./conformance\";\n\n/** The properties, by name (each is a key of `TilingHitConformance.counts`). */\nexport const TILING_HIT_PROPERTIES = [\n /** The targets after any sequence of frames are the ones built at the lift; with nothing held the place at a point is the same before and after holding every other place. */\n \"fixed-map\",\n /** The place at a point is the one a second copy of the rule names: home inside its rect, a part over the body, a slot over its part, else the pane's region; a refused zone falls to the one beneath; a place that gives the lift back is home. */\n \"zone-rule\",\n /** A still pointer changes nothing: the same point again reads the same frame. */\n \"stillness\",\n /**\n * A path within the edge measure of the held zone's visible part, or inside its pane (not over home) within the travel\n * measure of where it was taken, never changes the place; and a point past both (over home's rim on the base included,\n * where a zone runs on beneath home) reads the zone map.\n */\n \"hold-measures\",\n /** A straight sweep meets each place but home (which shows nothing) at most once. */\n \"one-pass\",\n /** A place on the map is offered exactly when `after(place).refusal` is null (a side the run-neighbor rule removed is neither); over a refused zone nothing is held and the refusal is named. */\n \"existence\",\n /** Every place whose release gives the lift back reads as home, and its release commits the lift tree. */\n \"lift-equals-home\",\n /** With no hold: lift basis, the mark contains the pointer and lies inside the target pane as drawn; base basis, the landing contains the pointer for every insert and join (swaps whose landing lies beside the pointer are counted, not failed). */\n \"shown-under-pointer\",\n /** At every frame of a gesture a release commits `after(held)`, else the lift tree; the base basis draws `after(held)` for a held place, the lift at home, the base with nothing held. */\n \"shown-equals-landed\",\n /**\n * Among panes with the subject's bounds across its run, a side takes an insert exactly when that insert gives a new\n * arrangement, neither the lift's nor the swap's; a pane with other bounds across (a fixed length) keeps its sides. A\n * second copy judges it from the lift tree and the lift rects only, never the basis, and both bases are checked\n * against it, so a pane has the same sides on both.\n */\n \"new-arrangement-sides\",\n /** Every zone of every pane is convex: the midpoint of two points in one zone is in it too. */\n \"zones-convex\",\n /**\n * Room does not move the map: the same drag with every room check passing (`min: 0`) has the same sides on every\n * pane, every point reads the same place where both are live, and where a place is refused the point falls to the\n * target beneath (nothing, or a part's pane body), never to a neighboring zone.\n */\n \"room-free-map\",\n] as const;\n\nexport type TilingHitProperty = (typeof TILING_HIT_PROPERTIES)[number];\n\n/** A conformance run, as `tilingConformance`'s, and the rows the ruling counts rather than fails. */\nexport interface TilingHitConformance {\n readonly ok: boolean;\n readonly failures: readonly string[];\n readonly counts: Readonly<Record<TilingHitProperty, { readonly checked: number; readonly failed: number }>>;\n /**\n * The rows the ruling counts rather than fails, all on the base basis, where a frame draws the landed layout. Two\n * kinds of row, three counters: a swap whose landing lies beside the pointer, and an insert or join that moves other\n * panes, of which some also land beside the pointer.\n */\n readonly reported: {\n /** A held swap whose landing does not contain the pointer: the partner moved at the lift, and the swap is hit at its base rect. */\n readonly swapsBeside: number;\n /** An insert or join whose layout moves a pane other than its target (a floor, a fixed length, a master split laid out anew). */\n readonly insertsMoveOthers: number;\n /** Of `insertsMoveOthers`, the ones whose landing does not contain the pointer. */\n readonly insertsMoveOthersBeside: number;\n };\n}\n\n/** A small seeded generator (the library has no `Math.random`). */\nfunction seeded(seed: number): () => number {\n let s = seed >>> 0 || 1;\n return () => {\n s = (s + 0x6d2b79f5) >>> 0;\n let t = s;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n}\n\nconst inside = (r: Rect, p: Point): boolean => contains(r, p, 0);\nconst within = (a: Rect, b: Rect, e = 1e-6): boolean => a.x >= b.x - e && a.y >= b.y - e && a.x + a.width <= b.x + b.width + e && a.y + a.height <= b.y + b.height + e;\nconst sameRect = (a: Rect | undefined, b: Rect | undefined, e = 1e-3): boolean =>\n !!a && !!b && Math.abs(a.x - b.x) <= e && Math.abs(a.y - b.y) <= e && Math.abs(a.width - b.width) <= e && Math.abs(a.height - b.height) <= e;\nconst show = (h: TilingHeld<unknown> | null): string =>\n h === null ? \"nothing\" : h.kind === \"home\" ? \"home\" : `${h.kind} ${String(h.at)}${h.kind === \"beside\" ? ` ${h.side}` : h.kind === \"join\" && h.index !== undefined ? ` @${h.index}` : \"\"}`;\nconst cross = (a: Point, b: Point, p: Point): number => (b.x - a.x) * (p.y - a.y) - (b.y - a.y) * (p.x - a.x);\n/** Strictly inside the convex quad `q` (corners in order), by the signs of its edges. */\nfunction inQuad(q: readonly Point[], p: Point): boolean {\n const s = q.map((a, i) => cross(a, q[(i + 1) % q.length]!, p));\n return s.every((v) => v > 1e-9) || s.every((v) => v < -1e-9);\n}\n\n/**\n * Runs every property on every subject of every tree (`tilingSubjects`), on both bases, over seeded points,\n * walks and sweeps. Gives the first `limit` failures (default 20) in words.\n */\nexport function tilingHitConformance<T, K>(trees: Iterable<T>, options: TilingDragOptions<T, K>, hitOptions: TilingHitOptions<K> = {}, limit = 20): TilingHitConformance {\n const { ops, area } = options;\n const { counts, failures, checkFor } = propertyTally(TILING_HIT_PROPERTIES, limit);\n const reported = { swapsBeside: 0, insertsMoveOthers: 0, insertsMoveOthersBeside: 0 };\n const edge = hitOptions.edge ?? TILING_HIT_DEFAULTS.edge;\n const travel = hitOptions.travel ?? TILING_HIT_DEFAULTS.travel;\n const cap = hitOptions.cap ?? TILING_HIT_DEFAULTS.cap;\n // The ruling's swap share across a run neighbor, pinned here as a literal apart from the library's default.\n const neighborSwap = hitOptions.neighborSwap ?? 0.56;\n const reg = { ...PANE_REGION_DEFAULTS, ...hitOptions.regions };\n const stackOf = (t: T, k: K) => ops.stackOf?.(t, k) ?? null;\n const drawnAs = (t: T, k: K): K => stackOf(t, k)?.active ?? k;\n const keyOf = hitOptions.key ?? String;\n /** The sides a hit's map has on the pane `at`, as a word: a side's place exists only where its region does. */\n const sidesOnMap = (h: TilingHit<T, K>, at: K): string =>\n ([\"top\", \"right\", \"bottom\", \"left\"] as const).filter((s) => h.heldOf(`beside:${s}:${keyOf(at)}`) !== null).join(\",\");\n let n = 0;\n for (const tree of trees) {\n for (const subject of tilingSubjects(tree, options)) {\n const drag = tilingDrag(tree, subject, options);\n const name = `tree ${n}, ${subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`}`;\n for (const basis of [\"lift\", \"base\"] as const) {\n const check = checkFor(`${name}, ${basis}`);\n runOne(drag, subject, basis, check, seeded(1 + n * 7919 + (basis === \"base\" ? 1 : 0)));\n // room-free-map: the same drag with no minimum (every room check passes) has the same sides on every pane; a\n // point reads the same place where both are live; where the tight drag refuses a place, the point falls to the\n // target beneath (nothing, or for a part the region of its pane's body), never to a neighboring zone.\n const roomy = tilingDrag(tree, subject, { ...options, min: 0 });\n const [tight, loose] = [drag.hit(basis, hitOptions), roomy.hit(basis, hitOptions)];\n for (const t of tight.targets) {\n if (t.part || t.home) continue;\n check(\"room-free-map\", sidesOnMap(tight, t.at) === sidesOnMap(loose, t.at), () => `${String(t.at)} has sides ${sidesOnMap(tight, t.at)}, with all the room ${sidesOnMap(loose, t.at)}`);\n }\n const rnd = seeded(7 + n * 131 + (basis === \"base\" ? 1 : 0));\n const samples: Point[] = [];\n for (let i = 0; i < 120; i++) samples.push({ x: area.x + rnd() * area.width, y: area.y + rnd() * area.height });\n for (const t of tight.targets) if (t.part) for (let i = 0; i < 4; i++) samples.push({ x: t.hit.x + rnd() * t.hit.width, y: t.hit.y + rnd() * t.hit.height });\n for (const p of samples) {\n const [z, wide] = [tight.placeAt(p), loose.placeAt(p)];\n if (z === wide) continue;\n const onPart = tight.targets.find((t) => t.part && inside(t.hit, p));\n const h = z === null ? null : tight.heldOf(z);\n // Where the two differ, the tight place is refused there: nothing, or (over a part) its pane's body beneath.\n const beneath = z === null || (!!onPart && !!h && h.kind !== \"home\" && h.kind !== \"join\" && h.at === onPart.at);\n const wideHeld = wide === null ? null : loose.heldOf(wide);\n const refusedHere = wideHeld === null || wideHeld.kind === \"home\" || drag.after(wideHeld).refusal !== null;\n check(\"room-free-map\", beneath && refusedHere, () => `at ${p.x.toFixed(1)},${p.y.toFixed(1)}: ${z}, with all the room ${wide}`);\n }\n }\n // new-arrangement-sides, across the bases: the copy judges sides from the lift alone, so a pane has the same\n // sides on the lift map and the base map.\n const [onLift, onBase] = [drag.hit(\"lift\", hitOptions), drag.hit(\"base\", hitOptions)];\n const check = checkFor(name);\n for (const t of onBase.targets) {\n if (t.part || t.home || !onLift.targets.some((u) => !u.part && !u.home && u.at === t.at)) continue;\n check(\"new-arrangement-sides\", sidesOnMap(onLift, t.at) === sidesOnMap(onBase, t.at), () => `${String(t.at)} has ${sidesOnMap(onLift, t.at)} on the lift, ${sidesOnMap(onBase, t.at)} on the base`);\n }\n }\n n++;\n }\n return { ok: failures.length === 0 && Object.values(counts).every((c) => c.failed === 0), failures, counts, reported };\n\n function runOne(drag: TilingDrag<T, K>, subject: TilingSubject<K>, basis: TilingBasis, check: (p: TilingHitProperty, ok: boolean, why: () => string) => void, rnd: () => number): void {\n const hit = drag.hit(basis, hitOptions);\n const laid = basis === \"lift\" ? drag.lift : drag.base;\n const home = drag.home;\n const subjectKey = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n const inSubject = (k: K): boolean => (subject.kind === \"pane\" ? k === subject.pane : subject.stack.members.includes(k));\n const HOME: TilingHeld<K> = { kind: \"home\" };\n const targetsAtLift = hit.targets;\n const snapshot = JSON.stringify(hit.targets);\n\n // ---- The second copy of the zone rule.\n const subjectDrawn = drawnAs(drag.lift.tree, subjectKey);\n const atOf = (pane: K): K | null => {\n if (drag.base.layout.has(pane)) return pane;\n for (const m of stackOf(laid.tree, pane)?.members ?? []) {\n if (inSubject(m)) continue;\n const d = drawnAs(drag.base.tree, m);\n if (drag.base.layout.has(d)) return d;\n }\n return null;\n };\n // The second copy of the arrangement: every pane in reading order of its runs, a stack as its members, sizes dropped.\n // A split's axis is its own, else read off its two halves' panes as laid out; a split along its parent's axis joins\n // the parent's run; a master split stands apart.\n const flatOf = (t: T): string => {\n const placed = layoutSplitTree(ops.split(t), area, options).panes;\n const keysIn = (n: Split<K>): K[] => (\"pane\" in n ? [n.pane] : [...keysIn(n.a), ...keysIn(n.b)]);\n const box = (n: Split<K>) => {\n const rs = keysIn(n).map((k) => placed.get(k)).filter((r): r is Rect => !!r);\n return { x0: Math.min(...rs.map((r) => r.x)), x1: Math.max(...rs.map((r) => r.x + r.width)) };\n };\n const dir = (n: Exclude<Split<K>, { readonly pane: K }>): \"x\" | \"y\" => {\n if (n.axis) return n.axis;\n const [a, b] = [box(n.a), box(n.b)];\n return a.x1 <= b.x0 + 0.5 || b.x1 <= a.x0 + 0.5 ? \"x\" : \"y\";\n };\n const items = (n: Split<K>, d: \"x\" | \"y\" | null): string[] => {\n if (\"pane\" in n) {\n const s = stackOf(t, n.pane);\n return [s ? `<${s.members.map(String).join(\" \")}>` : String(n.pane)];\n }\n if (n.master) return [`M${JSON.stringify(n.master)}{${items(n.a, null).join(\";\")}|${items(n.b, null).join(\";\")}}`];\n const own = dir(n);\n if (own === d) return [...items(n.a, own), ...items(n.b, own)];\n return [`${own}{${[...items(n.a, own), ...items(n.b, own)].join(\";\")}}`];\n };\n const s = ops.split(t);\n return s ? items(s, null).join(\";\") : \"\";\n };\n const liftFlat = flatOf(ops.normalize ? ops.normalize(drag.lift.tree) : drag.lift.tree);\n const changed = (h: { kind: \"swap\"; at: K } | { kind: \"beside\"; at: K; side: Side }): T => {\n const t = h.kind === \"swap\" ? ops.swap(drag.lift.tree, subject, h.at) : ops.beside(ops.release(drag.lift.tree, subject), subject, h.at, h.side, { kind: \"half\" });\n return ops.normalize ? ops.normalize(t) : t;\n };\n const masterIn = (n: Split<K> | null): boolean => !!n && !(\"pane\" in n) && (!!n.master || masterIn(n.a) || masterIn(n.b));\n const hasMaster = masterIn(ops.split(drag.lift.tree));\n /** Whether the smallest split holding both `x` and `y` in the lift tree lays its panes out as master and stack. */\n const meetInMaster = (x: K, y: K): boolean => {\n let node = ops.split(drag.lift.tree);\n let master = false;\n while (node && !(\"pane\" in node)) {\n const has = (n: Split<K>, k: K): boolean => (\"pane\" in n ? n.pane === k : has(n.a, k) || has(n.b, k));\n master = !!node.master;\n if (has(node.a, x) && has(node.a, y)) node = node.a;\n else if (has(node.b, x) && has(node.b, y)) node = node.b;\n else break;\n }\n return master && !!node && !(\"pane\" in node);\n };\n /**\n * The second copy of the rule, by result: a side is gone when its insert gives no new arrangement (the lift's or the\n * swap's), the release leaves a slot, the two panes meet in no master split (a master split is no run), and the pane\n * has the subject's bounds across that side's axis (a narrower one, a fixed length across, keeps its side). The copy\n * asks this of every pane; the drag's own rule judges only a whole child of a run next to the subject.\n */\n const sidesOf = (at: K): Side[] => {\n const swap = flatOf(changed({ kind: \"swap\", at }));\n const r = drag.lift.layout.get(at);\n const same = (a: number, b: number): boolean => Math.abs(a - b) <= 0.5;\n return ([\"top\", \"right\", \"bottom\", \"left\"] as Side[]).filter((side) => {\n const f = flatOf(changed({ kind: \"beside\", at, side }));\n if (f !== liftFlat && f !== swap) return true;\n if (!home || !r || meetInMaster(subjectDrawn, at)) return true;\n const across = side === \"top\" || side === \"bottom\" ? same(r.x, home.x) && same(r.width, home.width) : same(r.y, home.y) && same(r.height, home.height);\n return !across;\n });\n };\n const panes: { pane: K; at: K; rect: Rect; sides: Side[] }[] = [];\n for (const [pane, rect] of laid.layout) {\n if (basis === \"lift\" && home && pane === subjectDrawn) continue;\n const at = atOf(pane);\n if (at === null || options.still?.(at)) continue;\n panes.push({ pane, at, rect, sides: sidesOf(at) });\n }\n /** The center rectangle, by its formula: the share of each axis (clamped), the floor, the device-pixel grid; a side gone toward a pane's edge reaches it. */\n const centerOf = (r: Rect, sides: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"]) => {\n const clamp = (v: number): number => Math.min(0.95, Math.max(0.05, v));\n const ratio = reg.pixelRatio > 0 ? reg.pixelRatio : 1;\n const alongGone = !sides.includes(\"top\") || !sides.includes(\"bottom\");\n const acrossGone = !sides.includes(\"left\") || !sides.includes(\"right\");\n // A run neighbor's swap share across the run (the copy's own literal default, above).\n const sx = alongGone ? neighborSwap : (reg.centerX ?? reg.center);\n const sy = acrossGone ? neighborSwap : (reg.centerY ?? reg.center);\n const cw = Math.min(r.width, Math.max(r.width * clamp(sx), Math.min(reg.centerMin, r.width)));\n const ch = Math.min(r.height, Math.max(r.height * clamp(sy), Math.min(reg.centerMin, r.height)));\n const g = (v: number): number => Math.round(v * ratio) / ratio;\n return {\n l: sides.includes(\"left\") ? r.x + g((r.width - cw) / 2) : r.x,\n t: sides.includes(\"top\") ? r.y + g((r.height - ch) / 2) : r.y,\n r: sides.includes(\"right\") ? r.x + g((r.width + cw) / 2) : r.x + r.width,\n b: sides.includes(\"bottom\") ? r.y + g((r.height + ch) / 2) : r.y + r.height,\n // The edges a side that exists is cut at (the band it would have had).\n cl: r.x + g((r.width - cw) / 2),\n ct: r.y + g((r.height - ch) / 2),\n cr: r.x + g((r.width + cw) / 2),\n cb: r.y + g((r.height + ch) / 2),\n };\n };\n /**\n * The region of `r` the point is in: the center (reaching the pane's edge where a side is gone), else a side that\n * exists and the point lies past the center toward, two such sides parted by the diagonal from the pane's corner to\n * the center's; null on a shared edge.\n */\n const regionOf = (r: Rect, p: Point, sides: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"]): \"center\" | Side | null => {\n const c = centerOf(r, sides);\n if (p.x >= c.l && p.x <= c.r && p.y >= c.t && p.y <= c.b) return \"center\";\n const past = sides.filter((s) => (s === \"top\" ? p.y < c.ct : s === \"bottom\" ? p.y > c.cb : s === \"left\" ? p.x < c.cl : p.x > c.cr));\n if (past.length === 1) return past[0]!;\n const [x0, y0, x1, y1] = [r.x, r.y, r.x + r.width, r.y + r.height];\n const quads: Record<Side, Point[]> = {\n top: [{ x: x0, y: y0 }, { x: x1, y: y0 }, { x: c.cr, y: c.ct }, { x: c.cl, y: c.ct }],\n right: [{ x: x1, y: y0 }, { x: x1, y: y1 }, { x: c.cr, y: c.cb }, { x: c.cr, y: c.ct }],\n bottom: [{ x: x1, y: y1 }, { x: x0, y: y1 }, { x: c.cl, y: c.cb }, { x: c.cr, y: c.cb }],\n left: [{ x: x0, y: y1 }, { x: x0, y: y0 }, { x: c.cl, y: c.ct }, { x: c.cl, y: c.cb }],\n };\n return past.find((s) => inQuad(quads[s], p)) ?? null;\n };\n /** The bounding box of a region of `r`. */\n const regionBox = (r: Rect, region: \"center\" | Side, sides?: readonly Side[]): Rect => {\n const c = centerOf(r, sides);\n if (region === \"center\") return { x: c.l, y: c.t, width: c.r - c.l, height: c.b - c.t };\n if (region === \"top\") return { x: r.x, y: r.y, width: r.width, height: c.ct - r.y };\n if (region === \"bottom\") return { x: r.x, y: c.cb, width: r.width, height: r.y + r.height - c.cb };\n if (region === \"left\") return { x: r.x, y: r.y, width: c.cl - r.x, height: r.height };\n return { x: c.cr, y: r.y, width: r.x + r.width - c.cr, height: r.height };\n };\n const live = (h: TilingHeld<K>): boolean => h.kind === \"home\" || drag.after(h).refusal === null;\n /** A live place whose release has the lift's arrangement (by the copy's own flattening). */\n const givesLift = (h: TilingHeld<K>): boolean => {\n if (h.kind === \"home\") return true;\n const a = drag.after(h);\n return !a.refusal && (a.tree === drag.lift.tree || flatOf(a.tree) === liftFlat);\n };\n interface Expect {\n /** The live place on top at the point, before home-likeness; null over nothing or a refused zone. */\n readonly raw: TilingHeld<K> | null;\n readonly refused: TilingHeld<K> | null;\n /** The zone the raw place lies in, and its extent (for the measures); the pane it lies on. */\n readonly box: Rect | null;\n readonly pane: { pane: K; at: K; rect: Rect } | null;\n /** A shared edge of two regions: not decided by this copy. */\n readonly tie: boolean;\n }\n const expectAt = (p: Point): Expect => {\n if (home && inside(home, p)) return { raw: HOME, refused: null, box: home, pane: null, tie: false };\n const pane = panes.find((x) => inside(x.rect, p));\n if (!pane) return { raw: null, refused: null, box: null, pane: null, tie: false };\n const members = stackOf(laid.tree, pane.pane)?.members ?? [pane.pane];\n let refused: TilingHeld<K> | null = null;\n for (const part of ops.parts?.(laid.tree, pane.pane, pane.rect) ?? []) {\n if (!inside(part.rect, p)) continue;\n const i = (part.slots ?? []).findIndex((s) => inside(s, p));\n if (i >= 0) {\n const index = i < members.length ? members.slice(0, i).filter((m) => !inSubject(m)).length : undefined;\n const held: TilingHeld<K> = index === undefined ? { kind: \"join\", at: pane.at } : { kind: \"join\", at: pane.at, index };\n if (live(held)) return { raw: held, refused: null, box: part.slots![i]!, pane, tie: false };\n refused ??= held;\n }\n const held: TilingHeld<K> = { kind: \"join\", at: pane.at };\n if (live(held)) return { raw: held, refused: null, box: part.rect, pane, tie: false };\n refused ??= held;\n }\n const region = regionOf(pane.rect, p, pane.sides);\n if (region === null) return { raw: null, refused: null, box: null, pane, tie: true };\n const held: TilingHeld<K> = region === \"center\" ? { kind: \"swap\", at: pane.at } : { kind: \"beside\", at: pane.at, side: region };\n return live(held) ? { raw: held, refused: null, box: regionBox(pane.rect, region, pane.sides), pane, tie: false } : { raw: null, refused: refused ?? held, box: null, pane, tie: false };\n };\n const expectedPlace = (e: Expect): TilingHeld<K> | null => (e.raw && givesLift(e.raw) ? HOME : e.raw);\n const placeAt = (p: Point): TilingHeld<K> | null => {\n const id = hit.placeAt(p);\n return id === null ? null : hit.heldOf(id);\n };\n\n // ---- Driving the hit as an intent with the hit's tuning does: the target the held place is on shows.\n const frame = (p: Point): TilingHitRead<K> => {\n const shown: TilingHitTarget<K> | null = hit.targets.find((t) => hit.placeOf(t, p) !== null) ?? null;\n return hit.read({ shown }, p);\n };\n const FAR: Point = { x: area.x - 1e5, y: area.y - 1e5 };\n const fresh = (p: Point): TilingHitRead<K> => {\n frame(FAR);\n return frame(p);\n };\n const randomPoint = (r: Rect): Point => ({ x: r.x + rnd() * r.width, y: r.y + rnd() * r.height });\n const samples: Point[] = [];\n for (let i = 0; i < 300; i++) samples.push(randomPoint(area));\n for (const t of hit.targets) for (let i = 0; i < 6; i++) samples.push(randomPoint(t.hit));\n const zonesBefore = samples.map((p) => hit.placeAt(p));\n\n // ---- zone-rule, existence, lift-equals-home, shown-under-pointer: point by point, from nothing held.\n for (const p of samples) {\n const e = expectAt(p);\n if (e.tie) continue;\n const want = expectedPlace(e);\n const got = placeAt(p);\n check(\"zone-rule\", show(got) === show(want), () => `at ${p.x.toFixed(1)},${p.y.toFixed(1)}: ${show(got)}, the rule says ${show(want)}`);\n if (got && got.kind !== \"home\") check(\"existence\", drag.after(got).refusal === null, () => `${show(got)} is offered but refused (${drag.after(got).refusal?.code})`);\n const r = fresh(p);\n if (e.raw === null && e.refused) check(\"existence\", r.held === null && show(r.refused) === show(e.refused), () => `over refused ${show(e.refused)}: held ${show(r.held)}, refused ${show(r.refused)}`);\n if (e.raw && e.raw.kind !== \"home\" && givesLift(e.raw)) {\n check(\"lift-equals-home\", r.held?.kind === \"home\" && hit.release(r).tree === drag.lift.tree, () => `${show(e.raw)} gives the lift back but reads ${show(r.held)}`);\n }\n if (basis === \"lift\" && r.mark && e.pane) {\n const m = r.mark;\n check(\"shown-under-pointer\", inside(m.rect, p) && within(m.rect, e.pane.rect) && (m.kind !== \"swap\" || sameRect(m.wash ?? undefined, home ?? undefined) || (m.wash === null && home === null)), () => `${show(r.held)}: mark ${JSON.stringify(m.rect)} at ${p.x.toFixed(1)},${p.y.toFixed(1)}, pane ${JSON.stringify(e.pane!.rect)}`);\n }\n if (basis === \"base\" && r.held && r.held.kind !== \"home\") {\n const a = drag.after(r.held);\n if (r.held.kind === \"swap\") {\n if (!a.landing || !inside(a.landing, p)) reported.swapsBeside++;\n } else {\n const at = drawnAs(a.tree, r.held.at);\n const own = drawnAs(a.tree, subjectKey);\n const others = [...a.layout].some(([k, rect]) => k !== at && k !== own && drag.base.layout.has(k) && !sameRect(rect, drag.base.layout.get(k)));\n const under = !!a.landing && inside(a.landing, p);\n // A fixed length keeps the subject's size wherever it lands, and a master split lays its stack out anew: the\n // landing need not reach the pointer (counted).\n if (others || options.fixed || options.fixedAcross || hasMaster) {\n reported.insertsMoveOthers++;\n if (!under) reported.insertsMoveOthersBeside++;\n } else check(\"shown-under-pointer\", under, () => `${show(r.held)}: landing ${JSON.stringify(a.landing)} does not contain ${p.x.toFixed(1)},${p.y.toFixed(1)}`);\n }\n }\n }\n\n // ---- new-arrangement-sides: at a point 1 px in from the middle of each of a pane's edges (off parts and home), a\n // side insert shows exactly when its insert gives a new arrangement (the copy's `sidesOf`); where it does not, no\n // insert of that side is offered there.\n for (const pn of panes) {\n const r = pn.rect;\n if (r.width < 4 || r.height < 4) continue;\n const partRects = (ops.parts?.(laid.tree, pn.pane, r) ?? []).map((q) => q.rect);\n const free = (p: Point): boolean => !(home && inside(home, p)) && !partRects.some((q) => inside(q, p));\n const probes: [Side, Point][] = [\n [\"top\", { x: r.x + r.width / 2, y: r.y + 1 }],\n [\"bottom\", { x: r.x + r.width / 2, y: r.y + r.height - 1 }],\n [\"left\", { x: r.x + 1, y: r.y + r.height / 2 }],\n [\"right\", { x: r.x + r.width - 1, y: r.y + r.height / 2 }],\n ];\n for (const [side, p] of probes) {\n if (!free(p)) continue;\n const got = placeAt(p);\n const want: TilingHeld<K> = { kind: \"beside\", at: pn.at, side };\n const isSide = got?.kind === \"beside\" && got.side === side;\n if (pn.sides.includes(side)) {\n // A pane narrower than the center's floor has no band there: the point is in its middle.\n // A side kept by the bounds clause whose insert gives the lift's arrangement reads as home.\n if (live(want) && regionOf(r, p, pn.sides) === side) check(\"new-arrangement-sides\", isSide || (givesLift(want) && got?.kind === \"home\"), () => `${String(pn.at)} reads ${show(got)} at its ${side} edge, a new arrangement`);\n } else {\n check(\"new-arrangement-sides\", !isSide, () => `${String(pn.at)} offers its ${side} insert, which gives the ${flatOf(changed(want as { kind: \"beside\"; at: K; side: Side })) === liftFlat ? \"lift's\" : \"swap's\"} arrangement`);\n }\n }\n }\n // ---- zones-convex: two points in one zone of a pane (off parts and home) have their midpoint in it too.\n for (const pn of panes) {\n const partRects = (ops.parts?.(laid.tree, pn.pane, pn.rect) ?? []).map((q) => q.rect);\n const free = (p: Point): boolean => !(home && inside(home, p)) && !partRects.some((q) => inside(q, p));\n for (let k = 0; k < 24; k++) {\n const a = randomPoint(pn.rect);\n const b = randomPoint(pn.rect);\n const m = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };\n if (!free(a) || !free(b) || !free(m)) continue;\n const za = hit.placeAt(a);\n if (za === null || za === \"home\" || za !== hit.placeAt(b)) continue;\n check(\"zones-convex\", hit.placeAt(m) === za, () => `${za} at ${a.x.toFixed(1)},${a.y.toFixed(1)} and ${b.x.toFixed(1)},${b.y.toFixed(1)}, ${hit.placeAt(m)} between`);\n }\n }\n\n // ---- Gestures: random walks and straight sweeps, through the intent-like driver.\n const checkFrame = (p: Point, r: TilingHitRead<K>): void => {\n const ok = r.held === null || r.held.kind === \"home\" || drag.after(r.held).refusal === null;\n const rel = hit.release(r);\n const drawn = hit.drawn(r);\n const wantDrawn = basis === \"lift\" ? drag.lift : r.held === null ? drag.base : r.held.kind === \"home\" ? drag.lift : drag.after(r.held);\n check(\n \"shown-equals-landed\",\n ok && rel === drag.after(r.held ?? HOME) && drawn === wantDrawn && (r.held !== null || rel.tree === drag.lift.tree),\n () => `at ${p.x.toFixed(1)},${p.y.toFixed(1)}: held ${show(r.held)}${ok ? \"\" : \" (refused)\"}, release ${show(rel.held)}`,\n );\n };\n const sameHold = (a: TilingHold | null, b: TilingHold | null): boolean => JSON.stringify(a) === JSON.stringify(b);\n const holdName = (s: TilingHold | null): string => (s ? `${s.place} from ${s.from.x.toFixed(1)},${s.from.y.toFixed(1)}` : \"nothing\");\n for (let w = 0; w < 4; w++) {\n frame(FAR);\n let p = randomPoint(area);\n // The pure hold along the same walk (the stateful one memoizes the last point, so it cannot show stillness).\n let state: TilingHold | null = null;\n for (let i = 0; i < 40; i++) {\n p = { x: Math.min(area.x + area.width, Math.max(area.x, p.x + (rnd() - 0.5) * 60)), y: Math.min(area.y + area.height, Math.max(area.y, p.y + (rnd() - 0.5) * 60)) };\n checkFrame(p, frame(p));\n state = hit.hold(state, p);\n // Stillness: the same point again changes nothing, from the walk's state and from nothing held.\n const still = hit.hold(state, p);\n check(\"stillness\", sameHold(still, state), () => `a still pointer at ${p.x.toFixed(1)},${p.y.toFixed(1)} changed ${holdName(state)} to ${holdName(still)}`);\n const fresh0 = hit.hold(null, p);\n const twice = hit.hold(fresh0, p);\n check(\"stillness\", sameHold(twice, fresh0), () => `at ${p.x.toFixed(1)},${p.y.toFixed(1)} hold(hold(null, p), p) is ${holdName(twice)}, hold(null, p) ${holdName(fresh0)}`);\n // Away (far outside the stage, where nothing is held) and back: as if nothing had been held.\n const back = hit.hold(hit.hold(state, FAR), p);\n check(\"stillness\", sameHold(back, fresh0), () => `away and back to ${p.x.toFixed(1)},${p.y.toFixed(1)} reads ${holdName(back)}, nothing held gives ${holdName(fresh0)}`);\n }\n }\n // One pass: a straight sweep meets each place at most once (the pure hold, so the stateful one is left alone). Home\n // shows nothing and may come back: its rect, then a title bar's join, then the pane's band that gives the lift back\n // is the ruling's own sequence for a drag onto the pane below.\n for (let s = 0; s < 6; s++) {\n const a = randomPoint(area);\n const b = randomPoint(area);\n const steps = Math.max(2, Math.ceil(Math.hypot(b.x - a.x, b.y - a.y) / 1.5));\n let state: TilingHold | null = null;\n const met: string[] = [];\n for (let i = 0; i <= steps; i++) {\n const p = { x: a.x + ((b.x - a.x) * i) / steps, y: a.y + ((b.y - a.y) * i) / steps };\n state = hit.hold(state, p);\n if (state && met[met.length - 1] !== state.place) met.push(state.place);\n }\n const twice = met.filter((m, i) => m !== \"home\" && met.indexOf(m) !== i);\n check(\"one-pass\", twice.length === 0, () => `a sweep from ${a.x.toFixed(0)},${a.y.toFixed(0)} to ${b.x.toFixed(0)},${b.y.toFixed(0)} met ${met.join(\" > \")}`);\n }\n // Wobble: within the edge measure of the held zone, or inside its pane within the travel measure, the place stays.\n for (let k = 0; k < 12; k++) {\n const a = samples[Math.floor(rnd() * samples.length)]!;\n const e = expectAt(a);\n if (e.tie || !e.raw || e.raw.kind === \"home\" || givesLift(e.raw) || !e.box || !e.pane) continue;\n const start = hit.hold(null, a);\n if (!start) continue;\n const box = e.box;\n const ex = Math.min(edge, cap * box.width);\n const ey = Math.min(edge, cap * box.height);\n const zoneOf = (p: Point): string => show(expectedPlace(expectAt(p)));\n const want = show(e.raw);\n const path: Point[] = [];\n for (let i = 0; i < 20 && path.length < 10; i++) {\n // A point of the same zone near the start, moved within the edge measure.\n const z = { x: a.x + (rnd() - 0.5) * box.width * 0.5, y: a.y + (rnd() - 0.5) * box.height * 0.5 };\n if (zoneOf(z) !== want || (e.box && !inside(e.box, z))) continue;\n const ang = rnd() * Math.PI * 2;\n const len = Math.sqrt(rnd()) * 0.9;\n path.push({ x: z.x + Math.cos(ang) * ex * len, y: z.y + Math.sin(ang) * ey * len });\n }\n // And points inside the pane (not over home) within the travel measure of the start.\n const tb = hit.heldOf(start.place)?.kind === \"join\" ? null : box;\n if (tb) {\n const rx = Math.min(travel, cap * tb.width);\n const ry = Math.min(travel, cap * tb.height);\n for (let i = 0; i < 10; i++) {\n const ang = rnd() * Math.PI * 2;\n const len = Math.sqrt(rnd()) * 0.9;\n const p = { x: a.x + Math.cos(ang) * rx * len, y: a.y + Math.sin(ang) * ry * len };\n if (inside(e.pane.rect, p) && !(home && inside(home, p))) path.push(p);\n }\n }\n let state: TilingHold | null = start;\n for (const p of path) {\n state = hit.hold(state, p);\n check(\"hold-measures\", state?.place === start.place, () => `${want} taken at ${a.x.toFixed(1)},${a.y.toFixed(1)} went to ${state ? show(hit.heldOf(state.place)) : \"nothing\"} at ${p.x.toFixed(1)},${p.y.toFixed(1)}`);\n if (state?.place !== start.place) break;\n }\n }\n // The upper bound: a place taken at one point and kept at another is within the edge measure of where its zone shows\n // on the map (probed every half pixel), or within the travel measure (at most `travel` px per axis) of where it was\n // taken. Past both the point reads the map. Probed at random pairs and, with a home, in home's rim, where a zone may\n // run on beneath home: home wins there, so a place is measured from its visible part alone.\n const shows = (p: Point, place: string): boolean => {\n for (let dx = -edge; dx <= edge; dx += 0.5) for (let dy = -edge; dy <= edge; dy += 0.5) if (hit.placeAt({ x: p.x + dx, y: p.y + dy }) === place) return true;\n return false;\n };\n const rim: Point[] = [];\n if (home && home.width > 2 * edge && home.height > 2 * edge) {\n const d = Math.min(edge / 2, 2);\n for (const f of [0.15, 0.5, 0.85]) {\n rim.push({ x: home.x + home.width * f, y: home.y + d }, { x: home.x + home.width * f, y: home.y + home.height - d });\n rim.push({ x: home.x + d, y: home.y + home.height * f }, { x: home.x + home.width - d, y: home.y + home.height * f });\n }\n }\n let probed = 0;\n const pairs: [Point, Point][] = [];\n for (const p of rim) for (let i = 0; i < 4; i++) pairs.push([randomPoint(area), p]);\n for (let i = 0; i < 40; i++) pairs.push([randomPoint(area), randomPoint(area)]);\n for (const [q, p] of pairs) {\n const taken = hit.hold(null, q);\n if (!taken || taken.place === \"home\") continue;\n const kept = hit.hold(taken, p);\n if (kept?.place !== taken.place || hit.placeAt(p) === taken.place) continue;\n // Over home the travel measure never keeps a place.\n if (!(home && inside(home, p)) && Math.abs(p.x - taken.from.x) < travel && Math.abs(p.y - taken.from.y) < travel) continue;\n if (probed++ >= 24) break;\n check(\"hold-measures\", shows(p, taken.place), () => `${taken.place} taken at ${q.x.toFixed(1)},${q.y.toFixed(1)} is kept at ${p.x.toFixed(1)},${p.y.toFixed(1)}, past both measures (the map reads ${hit.placeAt(p)})`);\n }\n\n // ---- fixed-map: the targets are the lift's, and the zone map never moved.\n check(\"fixed-map\", hit.targets === targetsAtLift && Object.isFrozen(hit.targets) && JSON.stringify(hit.targets) === snapshot, () => \"the targets changed during the drag\");\n const zonesAfter = samples.map((p) => hit.placeAt(p));\n const moved = zonesAfter.findIndex((z, i) => z !== zonesBefore[i]);\n check(\"fixed-map\", moved < 0, () => `the zone at ${samples[moved]!.x.toFixed(1)},${samples[moved]!.y.toFixed(1)} changed from ${zonesBefore[moved]} to ${zonesAfter[moved]}`);\n // Holding every other place, then nothing, then a point: the place there is what nothing held gives.\n const places = new Map<string, Point>();\n samples.forEach((p, i) => {\n const z = zonesBefore[i];\n if (z !== null && !places.has(z)) places.set(z, p);\n });\n const probes = samples.slice(0, 12);\n for (const [, at] of [...places].slice(0, 10)) {\n for (const q of probes) {\n frame(at);\n const r = fresh(q);\n const z = hit.placeAt(q);\n check(\"fixed-map\", show(r.held) === show(z === null ? null : hit.heldOf(z)), () => `after holding the place at ${at.x.toFixed(1)},${at.y.toFixed(1)}, the point ${q.x.toFixed(1)},${q.y.toFixed(1)} reads ${show(r.held)}, nothing held gives ${z}`);\n }\n }\n }\n}\n","/**\n * The nearest pane in a direction: the rule a host moves focus by. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\n\n/** A direction on the plane: `\"up\"` is toward smaller y. */\nexport type Direction = \"left\" | \"right\" | \"up\" | \"down\";\n\n/**\n * The pane nearest `from` in `direction`, or null when none lies that way. A candidate's center has to be strictly on\n * that side of `from`'s center. Its score is the center distance along the direction, plus a quarter of the center\n * distance across it, plus 100 when it does not overlap `from` across the direction (the overlap strictly above 0);\n * the lowest score wins, ties to the first in the map's order. A pane that is not in `rects` has no neighbor.\n *\n * The host chooses which rects to pass. One option: lay the tree out in a unit square (`{ x: 0, y: 0, width: 1,\n * height: 1 }`) with the host's px floors. A floor of tens of px cannot fit in a unit square, so a split's two floors\n * cannot both fit and it lays out at 0.5 whatever its ratio; fixed lengths in px along a split do not fit either, and\n * the area's size and the gap drop out. Fixed lengths across a split are not checked against the cross extent, so\n * they still apply in a unit square, and a host leaves `fixedAcross` out there. The rects of the real layout work too.\n */\nexport function neighbor<K>(rects: ReadonlyMap<K, Rect>, from: K, direction: Direction): K | null {\n const origin = rects.get(from);\n if (!origin) return null;\n const horizontal = direction === \"left\" || direction === \"right\";\n // Centers and ends as sums of edges (right = x + width), so a host that keeps edge rects gets the same bits.\n const center = (r: Rect, x: boolean): number => (x ? (r.x + (r.x + r.width)) / 2 : (r.y + (r.y + r.height)) / 2);\n const reach = (r: Rect, x: boolean): [number, number] => (x ? [r.x, r.x + r.width] : [r.y, r.y + r.height]);\n const fromAlong = center(origin, horizontal);\n const fromAcross = center(origin, !horizontal);\n const [originStart, originEnd] = reach(origin, !horizontal);\n const sign = direction === \"left\" || direction === \"up\" ? -1 : 1;\n let best: K | null = null;\n let bestScore = Number.POSITIVE_INFINITY;\n for (const [key, r] of rects) {\n if (key === from) continue;\n const along = center(r, horizontal);\n if (sign < 0 ? along >= fromAlong : along <= fromAlong) continue;\n const [start, end] = reach(r, !horizontal);\n const overlap = Math.max(0, Math.min(originEnd, end) - Math.max(originStart, start));\n const score = Math.abs(along - fromAlong) + Math.abs(center(r, !horizontal) - fromAcross) * 0.25 + (overlap > 0 ? 0 : 100);\n if (score < bestScore) {\n bestScore = score;\n best = key;\n }\n }\n return best;\n}\n"],"mappings":";;;;;;;;AAmCO,IAAM,cAAc,CAAC,MAAmC,MAAM,UAAa,CAAC,OAAO,SAAS,CAAC,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC;AAGvI,SAAS,YAAY,OAA2B,GAAmB;AACxE,QAAM,IAAI,KAAK,MAAM,SAAS,CAAC;AAC/B,SAAO,KAAK,IAAI,KAAK,IAAI,OAAO,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC,CAAC;AACtE;AAGA,SAAS,OAAU,OAAqB,GAAW,GAAW,OAAe,QAAgB,UAAmB,KAAa,KAAyB;AACpJ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AAE,WAAW;AAC9G,QAAM,QAAQ,CAAC,GAAS,MAAkC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM;AACzG,QAAM,YAAY,OAAO,QAAQ,UAAU;AAC3C,QAAM,aAAa,OAAO,QAAQ,CAAC,UAAU;AAC7C,QAAM,CAAC,aAAa,SAAS,IAAI,MAAM,QAAQ,CAAC,UAAU;AAC1D,QAAM,OAAO,cAAc,UAAU,cAAc,OAAO,KAAK;AAC/D,MAAI,OAAiB;AACrB,MAAI,YAAY,OAAO;AACvB,aAAW,CAAC,KAAK,CAAC,KAAK,OAAO;AAC5B,QAAI,QAAQ,KAAM;AAClB,UAAM,QAAQ,OAAO,GAAG,UAAU;AAClC,QAAI,OAAO,IAAI,SAAS,YAAY,SAAS,UAAW;AACxD,UAAM,CAAC,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC,UAAU;AACzC,UAAMS,WAAU,KAAK,IAAI,GAAG,KAAK,IAAI,WAAW,GAAG,IAAI,KAAK,IAAI,aAAa,KAAK,CAAC;AACnF,UAAM,QAAQ,KAAK,IAAI,QAAQ,SAAS,IAAI,KAAK,IAAI,OAAO,GAAG,CAAC,UAAU,IAAI,UAAU,IAAI,QAAQA,WAAU,IAAI,IAAI;AACtH,QAAI,QAAQ,WAAW;AACrB,kBAAY;AACZ,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":["cross","px","has","cross","px","near","state","px","lay","stack","x","lay","inside","sameRect","show","check","HOME","n","s","has","clamp","held","probes","overlap"]}