@n-uf/placement 26.12.10 → 26.12.12

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/split-decision.ts","../src/tiling/layout.ts","../src/tiling/drop.ts","../src/tiling/fold-steps.ts","../src/tiling/fold-plan.ts","../src/tiling/tree-layout.ts","../src/tiling/painted.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 * One split's decision: given its extent, its gutter, its stored ratio and what each side needs, how long each side\n * is along the split, and the ratio in effect. `layoutSplit` makes it for every split; a host that draws or stores a\n * split itself makes the same one. See docs/placement.md, Entry: tiling.\n */\n\n/** A px number: finite and above 0, else 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/** Where the net is on, each side needs at least this share of the extent, less half the gutter. */\nconst NET_SHARE = 0.05;\n\n/**\n * The needs fit within this share of the extent: a parent lands a nested split at exactly its need, and float error\n * may tip the sum over it by an ulp. Both sides of every boundary give the same lengths within this slack.\n */\nconst FIT = 1e-9;\n\n/**\n * A side's fixed length along its split. A **kept** length (`keep`) is exact: it is cut only by its box, the extent\n * less the gutter, never by its sibling's need, it decides its split over a fixed length that is not kept, and it is\n * its pane's need. A fixed length that is not kept is honoured between the two needs: no shorter than its own side's\n * need, no longer than what its sibling's need leaves (the extent less the gutter and that need). A host that wants a\n * length under a pane's floor honoured reports the pane's need as at most the length.\n */\nexport interface FixedLength {\n readonly length: number;\n readonly keep?: boolean;\n}\n\n/** Which step of the ladder decided a split. */\nexport type SplitStep = \"no-room\" | \"kept\" | \"fixed\" | \"ratio\" | \"squeezed\";\n\n/** One side of a split as its decision reads it: the layout's own inputs. */\nexport interface SplitSide {\n /**\n * The least length the side lands at where its split fits: a layout's own number is `SplitGeometry.needs` (the\n * side's floor as this split measures it, its kept length, or a nested split's need). Leave it out on both sides of\n * a split with no floors. `splitNeed` is a tree's need laid out alone, which is not a side's. A need that is not\n * finite and above 0 counts as 0, but a side that has one (NaN included) makes the split one with floors: the gap\n * rule no longer applies.\n */\n readonly need?: number;\n /** False where the side's floor said `net: false`; either side's false takes the net off the split. */\n readonly net?: boolean;\n /** The side's fixed length along the split. */\n readonly fixed?: FixedLength;\n}\n\n/** What one split does: each side's length along it, the ratio in effect, the step that decided, whether it has a divider. */\nexport interface SplitDecision {\n readonly a: number;\n readonly b: number;\n /** The ratio in effect: the middle of the gutter lies at the split's start plus the extent times this. */\n readonly ratio: number;\n readonly step: SplitStep;\n /** True where no fixed length decides the split: its gutter is a divider. */\n readonly divider: boolean;\n}\n\nconst usableFixed = (f: FixedLength | undefined): FixedLength | undefined => (f && Number.isFinite(f.length) && f.length > 0 ? f : undefined);\n\n/**\n * The least extent at which a split that a ratio decides fits its two needs: both needs and the gutter; where the net\n * is on and that extent's 5 % (less half the gutter) is above the smaller need, the extent at which the net's length\n * and the larger need fit, `(larger + g/2) / 0.95`. At that extent `decideSplit` lands both sides at their needs (the\n * smaller one at the net's length). Continuous where the two meet. For the needs of a split tree, not exported.\n */\nexport function ratioFitExtent(needA: number, needB: number, gutter: number, net: boolean): number {\n const g = px(gutter);\n const lower = Math.min(px(needA), px(needB));\n const upper = Math.max(px(needA), px(needB));\n const plain = lower + upper + g;\n if (!net || NET_SHARE * plain - g / 2 <= lower) return plain;\n // The smaller need is under the net: E − g = (NET_SHARE·E − g/2) + upper. The larger is then never under it.\n return (upper + g / 2) / (1 - NET_SHARE);\n}\n\n/**\n * One split's decision, the ladder, tested in this order (E the extent, g the gutter, room = E − g):\n *\n * 0. **No floors and no fixed length** (no side has a `need` or a usable `fixed`): the gap rule. The middle of the\n * gutter sits at `E × ratio`; a side too short for half the gutter is 0, and a 0-long second side may start up to\n * half a gutter past the end.\n * 1. **No room** (E under g): both sides are 0, and the ratio is 0.5.\n * 2. **Kept**: a kept length decides over one that is not kept (the first kept side, else the second). It takes\n * `min(length, room)`, whatever its sibling needs; the other side takes the rest. Two kept lengths take\n * `min(first, room)` and `min(second, room − first)`, and what is left stays empty.\n * 3. **Fixed**: else the first side with a usable fixed length (above 0, finite; an unusable first lets the second\n * decide) takes its length held between the two needs, `min(max(length, own need), room − need of its sibling)`;\n * the sibling takes the rest. Where the two needs don't fit the room, both are squeezed in proportion to them\n * (step 5), whatever the length. The stored ratio is never read.\n * 4. **Ratio**: else the ratio is clamped so each side lands at its need: within\n * `[(needA + g/2) / E, 1 − (needB + g/2) / E]`. Where the net is on (neither side's `net` is false), each need is\n * first raised to `0.05 × E − g/2`, which is the 0.05..0.95 bound while the needs fit.\n * 5. **Squeezed**: where the needs (raised by the net, in step 4 only) and the gutter don't fit the extent, both sides\n * share the room in proportion to their needs.\n *\n * Every step is continuous in the extent: changing it by d changes no side by more than d. At `E = g` both sides are\n * 0; the step is the ratio, or the squeeze where a side needs more than 0.\n */\nexport function decideSplit(extent: number, gutter: number, ratio: number | undefined, a: SplitSide, b: SplitSide): SplitDecision {\n const g = px(gutter);\n const E = Number.isFinite(extent) ? extent : 0;\n const fa = usableFixed(a.fixed);\n const fb = usableFixed(b.fixed);\n const floors = a.need !== undefined || b.need !== undefined;\n const lead = fa?.keep ? fa : fb?.keep ? fb : (fa ?? fb);\n if (!lead && !floors) {\n // The gap rule, exactly as it always was, on the extent as given (an infinite or NaN one included).\n const r = unit(ratio);\n return { a: Math.max(0, extent * r - g / 2), b: Math.max(0, extent * (1 - r) - g / 2), ratio: r, step: \"ratio\", divider: true };\n }\n if (E < g * (1 - FIT)) return { a: 0, b: 0, ratio: 0.5, step: \"no-room\", divider: !lead };\n const needA = px(a.need);\n const needB = px(b.need);\n if (!(E > 0)) {\n const step: SplitStep = lead ? (lead.keep ? \"kept\" : \"fixed\") : needA + needB > 0 ? \"squeezed\" : \"ratio\";\n return { a: 0, b: 0, ratio: 0.5, step, divider: !lead };\n }\n const room = Math.max(0, E - g);\n const at = (lengthA: number): number => (lengthA + g / 2) / E;\n const sides = (lengthA: number, step: SplitStep, divider: boolean): SplitDecision => {\n const la = Math.min(room, Math.max(0, lengthA));\n return { a: la, b: Math.max(0, room - la), ratio: at(la), step, divider };\n };\n const squeeze = (nA: number, nB: number, divider: boolean): SplitDecision => sides((room * nA) / (nA + nB), \"squeezed\", divider);\n if (lead) {\n const first = lead === fa;\n if (fa?.keep && fb?.keep) {\n const la = Math.min(fa.length, room);\n return { a: la, b: Math.min(fb.length, room - la), ratio: at(la), step: \"kept\", divider: false };\n }\n if (lead.keep) {\n const length = Math.min(lead.length, room);\n return sides(first ? length : room - length, \"kept\", false);\n }\n const own = first ? needA : needB;\n const other = first ? needB : needA;\n if (own + other > room + FIT * E) return first ? squeeze(own, other, false) : squeeze(other, own, false);\n const length = Math.min(Math.max(lead.length, own), room - other);\n return sides(first ? length : room - length, \"fixed\", false);\n }\n const net = a.net !== false && b.net !== false ? Math.max(0, NET_SHARE * E - g / 2) : 0;\n const nA = Math.max(needA, net);\n const nB = Math.max(needB, net);\n if (nA + nB > room + FIT * E) return squeeze(nA, nB, true);\n const lo = (nA + g / 2) / E;\n const hi = Math.max(lo, 1 - (nB + g / 2) / E);\n const r = Math.min(Math.max(unit(ratio), lo), hi);\n return { a: Math.max(0, E * r - g / 2), b: Math.max(0, E * (1 - r) - g / 2), ratio: r, step: \"ratio\", divider: true };\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 type { SplitFoldGeometry } from \"./fold\";\nimport { masterCount, masterRatio, masterStack, type MasterOptions, type TileOptions } from \"./order\";\nimport { panesOf, type Split } from \"./split\";\nimport { decideSplit, ratioFitExtent, type FixedLength, type SplitSide, type SplitStep } from \"./split-decision\";\n\nexport type { FixedLength } from \"./split-decision\";\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 usable length: finite and above 0. */\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\n\n/**\n * A node's own least length along a split. `net` (default true): where neither side of a split says false, each side\n * needs at least 5 % of the extent less half the gutter where a ratio decides the split, which is the 0.05..0.95 bound\n * while the needs fit.\n */\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 split is decided by `decideSplit` from its two sides' needs\n * (`splitNeed` and `SplitGeometry.needs`), fixed lengths and nets; see docs/placement.md, Entry: tiling.\n *\n * - `fixed(child, axis)`: a direct child's fixed length along its split, asked once per child and axis. A kept\n * length (`keep`) is exact: cut only by its box (the extent less the gutter), it decides over a length that is not\n * kept, and it is its pane's need; two kept lengths keep their own and the room left stays empty, the second cut at\n * the split's end. Else the first side with a usable length (above 0, finite; an unusable first lets the second\n * decide) takes it held between the two needs: no shorter than its own need, no longer than the extent less the\n * gutter and its sibling's need; where the needs don't fit, the split is squeezed by them. A pane's need is the host's\n * floor, so a host that wants a length under that floor honoured gives the pane a floor no larger than the length; a\n * split node's need is its panes' need. A split a fixed length decides has no divider; its stored\n * ratio is never read.\n * - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive, finite\n * and shorter than the cross extent, from the start of the cross axis instead of the whole cross extent; a longer\n * one takes the cross extent. It never enters a need.\n * - `floor(child, axis, split)`: a node's own least length along `axis`, asked at most once per node, axis and\n * measuring split in a layout. `split` is the nearest split above `child` that runs along `axis`, which may be its\n * parent or a split above a split across; where no split above a node runs along `axis`, it is not asked and its\n * own floor is 0. A side's need is its own floor, or its kept length, or for a nested split with an axis the larger\n * of its own floor and its sides' needs (along: both and the gutter, and where a ratio decides it with its net on,\n * room for the net's 5 % as well; across: the larger). Each side lands at its\n * need where the split's needs fit its extent; where they don't, both sides are squeezed in proportion. A master\n * split and a split with no axis report their own floor only. With no `floor` there are no needs, and a split with\n * no fixed length keeps the gap rule (`layoutSplit`). `giveWay` is the other policy of the same minimum: it floats\n * the newest pane instead of squeezing the ratio, and a host 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 /** The step of `decideSplit` that decided the split; `\"ratio\"` for a master split. */\n readonly step: SplitStep;\n /**\n * The two sides' needs as this split read them (each side's floor as it measures it, its kept length, or a nested\n * split's need): what a host passes to `decideSplit` for this split. Null without `floor`, and for a master split.\n */\n readonly needs: readonly [number, number] | null;\n}\n\n/**\n * A tree laid out: every open pane's rect, the geometry of each split that has an `id` and is drawn with its two sides,\n * and, under a fold (`layoutSplitTree`'s `fold`), each folded pane's segment of its spine and the folds, outermost\n * first. Without a fold, `spines` and `folds` are empty. A segment in `spines` is a content position, placed from its\n * rail box's top or left: it is where the segment is painted only where the rail's content fits its box\n * (`SplitFoldGeometry.railContentLength`) and the host's offset is 0; `paintedSpines` gives where each is painted at a\n * rail offset.\n */\nexport interface SplitLayout<K> {\n readonly panes: Map<K, Rect>;\n readonly splits: Map<string, SplitGeometry>;\n readonly spines: Map<K, Rect>;\n readonly folds: readonly SplitFoldGeometry<K>[];\n}\n\n/** Throws where a split tree's fold reaches a function that lays the tree out without it. */\nexport function refuseFold(options: object, name: string): void {\n if (\"fold\" in options) throw new Error(`${name} does not fold a split tree: use layoutSplitTree`);\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 /** Where each decided split's ratio in effect goes, by node; null unless asked (`laySplitTree`). */\n readonly ratios: Map<Split<K>, number> | null;\n /** The host's answers and the needs, for this layout. */\n readonly needs: Needs<K>;\n}\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** A map from node to a map of keys, made on first use. */\nconst slot = <K, V>(maps: Map<Split<K>, Map<string, V>>, node: Split<K>): Map<string, V> => {\n let m = maps.get(node);\n if (!m) maps.set(node, (m = new Map<string, V>()));\n return m;\n};\n\n/**\n * The needs of one layout, and the host's answers they read: `floor` is asked at most once per node, axis and\n * measuring split, `fixed` once per node and axis. A need reads what the layout reads, from where it reads it: a\n * node's own floor as measured by the nearest split above it that runs along the axis (none: 0, not asked), a kept\n * length of a split's direct child along its axis, and a nested split's sides, along it (with its net, where a ratio\n * decides it) or across it. A master split\n * and a split with no axis are not looked into. `fixedAcross` never enters a need.\n */\nclass Needs<K> {\n private readonly options: SplitOptions<K>;\n private readonly gap: number;\n private readonly handle: number;\n private readonly floors = new Map<Split<K>, Map<string, MinLength>>();\n private readonly fixeds = new Map<Split<K>, Map<string, FixedLength | undefined>>();\n private readonly found = new Map<Split<K>, Map<string, number>>();\n private readonly ids = new Map<Split<K>, number>();\n\n constructor(options: SplitOptions<K>, gap: number, handle: number) {\n this.options = options;\n this.gap = gap;\n this.handle = handle;\n }\n\n /** The key of an axis and a measuring split. */\n private key(axis: Axis, split: Split<K> | null): string {\n if (split === null) return axis;\n let id = this.ids.get(split);\n if (id === undefined) this.ids.set(split, (id = this.ids.size));\n return `${axis} ${id}`;\n }\n\n /** A split's gutter: its own gap, else the layout's, plus the handle. */\n gutter(split: Branch<K>): number {\n return (split.gap === undefined ? this.gap : px(split.gap)) + this.handle;\n }\n\n /** The host's floor of `node` along `axis`, as `split` measures it. */\n floor(node: Split<K>, axis: Axis, split: Split<K>): MinLength {\n const m = slot(this.floors, node);\n const k = this.key(axis, split);\n let f = m.get(k);\n if (f === undefined) m.set(k, (f = this.options.floor!(node, axis, split)));\n return f;\n }\n\n /** The host's fixed length of `child` along a split on `axis`. */\n fixed(child: Split<K>, axis: Axis): FixedLength | undefined {\n const m = slot(this.fixeds, child);\n if (!m.has(axis)) m.set(axis, this.options.fixed?.(child, axis));\n return m.get(axis);\n }\n\n /** The need of `child`, a direct child of `split`, which runs along `axis`: its kept length, or its own need. */\n side(child: Split<K>, axis: Axis, split: Split<K>): number {\n const f = this.fixed(child, axis);\n if (f?.keep && usable(f.length)) return f.length;\n return this.of(child, axis, split);\n }\n\n /** The need of `node` along `axis`, measured by `split` (null: no split above it runs along `axis`). */\n of(node: Split<K>, axis: Axis, split: Split<K> | null): number {\n const m = slot(this.found, node);\n const k = this.key(axis, split);\n const known = m.get(k);\n if (known !== undefined) return known;\n const own = split === null ? 0 : px(this.floor(node, axis, split).min);\n let need = own;\n if (!(\"pane\" in node) && !node.master && node.axis !== undefined) {\n need = node.axis === axis ? Math.max(own, this.along(node, axis)) : Math.max(own, this.of(node.a, axis, split), this.of(node.b, axis, split));\n }\n m.set(k, need);\n return need;\n }\n\n /**\n * The need of `split` along its own axis: both sides' needs and its gutter; where a ratio decides it (no usable fixed\n * length on either side) and its net is on, the least extent at which the net's 5 % fits as well.\n */\n private along(split: Branch<K>, axis: Axis): number {\n const a = this.side(split.a, axis, split);\n const b = this.side(split.b, axis, split);\n const led = [split.a, split.b].some((c) => usable(this.fixed(c, axis)?.length));\n const net = !led && this.floor(split.a, axis, split).net !== false && this.floor(split.b, axis, split).net !== false;\n return ratioFitExtent(a, b, this.gutter(split), net);\n }\n}\n\n/**\n * The least length `tree` lands at along `axis`, laid out alone in an area with `options`: where the area is at\n * least this long (allowing 1e-9 of it) along `axis`, no split on the way is squeezed by its needs, the net on or\n * off (a split a ratio decides with its net on needs room for the net's 5 % of its extent too). Except where the host\n * gives a split node its own kept or across length shorter than its need: that length is taken as it is, the splits\n * inside it along that axis are squeezed at any size, and its panes may land under their floors. A fixed length that\n * is not kept is no exception: a split node pinned shorter than its need lands at that need. It reads `floor`\n * and `fixed` as the layout does; no split measures the root, so a pane alone needs 0, and a split's own floor\n * counts only where a split above it measures it. 0 without `floor`. Not a side's need inside a tree: that is\n * `SplitGeometry.needs`, measured by its split. Not `StackFit.need` (what a stack's forms need).\n */\nexport function splitNeed<K>(tree: Split<K> | null, axis: Axis, options: SplitOptions<K> = {}): number {\n refuseFold(options, \"splitNeed\");\n if (!tree || !options.floor) return 0;\n return new Needs(options, px(options.gap), px(options.handle)).of(tree, axis, 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: that is the gap rule, for a split with no floors and no fixed length.\n * `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's minimums and fixed lengths, and each\n * split is then decided by `decideSplit`: with them every pane lies inside the area, at every size (a split under\n * its gutter lays both sides at no size, the second at its end). 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 refuseFold(options, \"layoutSplit\");\n const gap = px(options.gap);\n const handle = px(options.handle);\n const ctx: Ctx<K> = { options, gap, handle, panes: new Map(), splits: null, ratios: null, needs: new Needs(options, gap, handle) };\n lay(tree, area, ctx, false);\n return ctx.panes;\n}\n\n/**\n * The split tree laid out with no fold: `layoutSplit` and the geometry of every split that has an `id` (`layoutSplitTree`\n * without `fold`). `ratios`, when given, takes each decided split's ratio in effect, by node. Internal.\n */\nexport function laySplitTree<K>(\n tree: Split<K> | null,\n area: Rect,\n options: SplitOptions<K>,\n ratios: Map<Split<K>, number> | null = null,\n): { panes: Map<K, Rect>; splits: Map<string, SplitGeometry> } {\n const splits = new Map<string, SplitGeometry>();\n const gap = px(options.gap);\n const handle = px(options.handle);\n const ctx: Ctx<K> = { options, gap, handle, panes: new Map(), splits, ratios, needs: new Needs(options, gap, handle) };\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/** 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, step: \"ratio\", needs: 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 = ctx.needs.gutter(tree);\n const { fixedAcross, floor } = ctx.options;\n // Across the split a child with a fixed length shorter than the cross extent takes it from the start; the others,\n // and a longer one, 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 ? lenA : cross;\n const acrossB = usable(lenB) && lenB < cross ? lenB : cross;\n\n // Each side as the decision reads it: its fixed length, and with floors its need and its net (a kept side has none).\n const sideOf = (child: Split<K>): SplitSide => {\n const fixed = ctx.needs.fixed(child, axis);\n if (!floor) return { fixed };\n const kept = !!fixed?.keep && usable(fixed.length);\n return { fixed, need: ctx.needs.side(child, axis, tree), net: kept || ctx.needs.floor(child, axis, tree).net !== false };\n };\n const a = sideOf(tree.a);\n const b = sideOf(tree.b);\n const d = decideSplit(extent, gutter, tree.ratio, a, b);\n ctx.ratios?.set(tree, d.ratio);\n // The second side starts after the first and the gutter; under the gap rule, half a gutter past the ratio's middle.\n const startB = d.step === \"no-room\" ? origin + Math.max(0, extent) : d.step === \"ratio\" ? origin + extent * d.ratio + gutter / 2 : origin + d.a + gutter;\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 = d.divider ? strip(area, x, origin + extent * d.ratio, gutter) : null;\n const needs: readonly [number, number] | null = floor ? [a.need!, b.need!] : null;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio: d.ratio, divider, step: d.step, needs });\n }\n const lengthA = d.a;\n const lengthB = d.b;\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 { EPS, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { layoutSplit, refuseFold, 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 refuseFold(options, \"canDropOnPane\");\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. Reads no fold: throws when `options`\n * holds a `fold` key (under a fold the drag has no room rule).\n */\nexport function canSplitPane(target: Rect, side: Side, options: SplitRoomOptions): DropVerdict {\n refuseFold(options, \"canSplitPane\");\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/**\n * What `dropFits` reads: the `min` (as in `DropOptions`), the `side` of `at` the drop is on, for the reason, and under\n * a fold the panes the projected layout folds.\n */\nexport interface DropFitsOptions<K = unknown> {\n readonly min: number;\n readonly side: Side;\n /**\n * The panes the projected layout folds (a folding layout's `folds`, their `panes`): a folded `at` is not judged, as\n * the drop may fold it. `dragged` is judged whatever this holds: it must be drawn open. Default: none.\n */\n readonly folded?: ReadonlySet<K>;\n}\n\n/**\n * The fit rule: in `projected`, the rect of every pane drawn open in the layout the drop makes (the host's own\n * projection of `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and\n * high, to within `EPS` (a floor of `min` lands at `min` up to float error); an `at` in `options.folded` is not judged.\n * Fine when `area` has no width or no height (there is nothing to measure). `canDropOnPane`'s last rule. Reads no fold\n * (a folding host passes the folded panes as `folded`): throws when `options` holds a `fold` key.\n */\nexport function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions<K>): DropVerdict {\n refuseFold(options, \"dropFits\");\n if (!(area.width > 0 && area.height > 0)) return { ok: true };\n const min = px(options.min);\n const folded = options.folded;\n const fits = (r: Rect | undefined): boolean => !!r && r.width >= min - EPS && r.height >= min - EPS;\n return fits(projected.get(dragged)) && (fits(projected.get(at)) || folded?.has(at) === true)\n ? { ok: true }\n : { ok: false, reason: `${options.side} rejected: projected footprint of the two panes violates min ${min}px` };\n}\n","/**\n * The steps of a folding split tree and the count rule that judges a split with them. Internal: the fold's layout\n * reads them; nothing here is exported from an entry.\n *\n * A **step** of a subtree along an axis is one way it can be laid out with folding on: the least length at which it\n * keeps `panes` panes open, each on its fold floor, whichever side of every fold in it is shown. A subtree's steps\n * are a **frontier**: lengths and counts both strictly increase. The **count rule** keeps a split with the pair of its\n * sides' steps that fits and keeps the most panes, and folds it only where folding keeps strictly more, or no pair\n * fits.\n *\n * Words: a tiling **fold** shows one side of a split and draws the other as a **spine**, a thin strip on the edge it\n * sits on; a **rail** is a box edge already holding a spine, where a spine inside joins it at no cost.\n */\nimport type { Axis, Side } from \"../side\";\nimport type { SplitFold } from \"./fold\";\nimport type { SplitOptions } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\n\n/** One way a subtree can be laid out along an axis with folding on: its least length that keeps `panes` open. */\nexport interface FoldStep {\n readonly length: number;\n readonly panes: number;\n}\n\n/**\n * Which of a subtree's ways its steps count: `\"any\"`; `\"folded\"`, only the ways where the subtree's own split folds;\n * `\"open-side\"`, a fold's open side, laid out afresh in the whole open box, so its own pin does not apply.\n */\nexport type FoldForm = \"any\" | \"folded\" | \"open-side\";\n\n/** The pair of steps a kept split keeps: each side's length along the split, and the panes they keep together. */\nexport interface FoldKept {\n readonly panes: number;\n readonly a: number;\n readonly b: number;\n}\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** Lengths this close are one. */\nconst FIT = 1e-6;\n\nconst NO_RAILS: ReadonlySet<Side> = new Set<Side>();\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\nconst otherAxis = (axis: Axis): Axis => (axis === \"x\" ? \"y\" : \"x\");\n\n/** Whether `node` counts as one pane: a `{ pane }` node, or a master split (laid out flat, never folded). */\nconst isPane = <K>(node: Split<K>): boolean => \"pane\" in node || node.master !== undefined;\n\n/** The edges a split's two sides sit on: `a`'s, then `b`'s. */\nconst sideEdges = (axis: Axis): readonly [Side, Side] => (axis === \"x\" ? [\"left\", \"right\"] : [\"top\", \"bottom\"]);\n\n/** `rails` cut to `edge`: the one rail a side sitting on that edge touches. */\nconst railOn = (rails: ReadonlySet<Side>, edge: Side): ReadonlySet<Side> => (rails.has(edge) ? new Set<Side>([edge]) : NO_RAILS);\n\n/** Only the steps that gain a pane: lengths and counts both strictly increase. */\nfunction stepFrontier(steps: readonly FoldStep[]): FoldStep[] {\n const sorted = [...steps].sort((p, q) => p.length - q.length || q.panes - p.panes);\n const out: FoldStep[] = [];\n for (const step of sorted) {\n const last = out[out.length - 1];\n if (last === undefined || step.panes > last.panes) out.push(step);\n }\n return out;\n}\n\n/** The least length among `steps` that keeps at least `panes` open, or Infinity. */\nfunction leastLengthFor(steps: readonly FoldStep[], panes: number): number {\n for (const step of steps) if (step.panes >= panes) return step.length;\n return Infinity;\n}\n\n/**\n * The least length among `steps` that keeps as many panes as the most any step no longer than `length` keeps: what a\n * side counted at `length` needs at least. `length` itself where no step fits.\n */\nexport function leastKeeping(steps: readonly FoldStep[], length: number): number {\n let panes = -1;\n for (const step of steps) if (step.length <= length + FIT) panes = Math.max(panes, step.panes);\n if (panes < 0) return length;\n let least = length;\n for (const step of steps) if (step.panes >= panes) least = Math.min(least, step.length);\n return least;\n}\n\n/**\n * A kept split's pair: of the pairs of side steps that fit `extent` less `gutter`, the one with the most panes, and of\n * those the one whose range holds `middle` (the first side's length at the split's middle) nearest, so no stored ratio\n * chooses it. Null where no pair fits.\n */\nexport function bestKeptPair(a: readonly FoldStep[], b: readonly FoldStep[], extent: number, gutter: number, middle: number): FoldKept | null {\n const room = Math.max(0, extent - gutter) + FIT;\n let best: { panes: number; move: number; a: number; b: number } | null = null;\n for (const x of a) {\n for (const y of b) {\n if (x.length + y.length > room && x.length + y.length > 0) continue;\n const high = extent - gutter - y.length;\n const move = middle < x.length ? x.length - middle : middle > high ? middle - high : 0;\n const panes = x.panes + y.panes;\n if (best === null || panes > best.panes || (panes === best.panes && move < best.move - FIT)) best = { panes, move, a: x.length, b: y.length };\n }\n }\n return best === null ? null : { panes: best.panes, a: best.a, b: best.b };\n}\n\n/** The most panes a split keeps folded at `extent`, from its `\"folded\"` steps; -1 where none fits. */\nfunction foldedPanesAt(folded: readonly FoldStep[], extent: number): number {\n let panes = -1;\n for (const step of folded) if (step.length <= extent + FIT) panes = Math.max(panes, step.panes);\n return panes;\n}\n\n/**\n * The count rule for a split at `extent` along its axis: kept with the pair `bestKeptPair` takes, unless folding (its\n * `\"folded\"` steps) keeps strictly more panes, or no pair fits. A tie stays open.\n */\nexport function countRule(\n a: readonly FoldStep[],\n b: readonly FoldStep[],\n folded: readonly FoldStep[],\n extent: number,\n gutter: number,\n middle: number,\n): \"fold\" | FoldKept {\n const kept = bestKeptPair(a, b, extent, gutter, middle);\n if (kept === null) return \"fold\";\n return foldedPanesAt(folded, extent) > kept.panes ? \"fold\" : kept;\n}\n\n// ---------------------------------------------------------------- the memo\n\n/** Step lists by node, then by the rest of a call; and whether a node holds a pin inside, by node and axis. */\ninterface StepMemo {\n readonly steps: WeakMap<object, Map<string, readonly FoldStep[]>>;\n readonly pinned: WeakMap<object, Map<Axis, boolean>>;\n}\n\n/** A host's answers by identity, one level each: `floor`, `weight`, `fixed`, then `fixedAcross` to the lengths. */\ntype ByAnswer = WeakMap<object, ByAnswer | Map<string, StepMemo>>;\n\n/**\n * By the host's `floor`, then `weight`, `fixed` and `fixedAcross` (by identity, a level each, so an answer the host\n * drops frees what it keyed), then the lengths (gap, handle, spine).\n */\nconst MEMOS: ByAnswer = new WeakMap();\n\n/** Stands for an answer the host does not give. */\nconst ABSENT = {};\n\n/** A number per object, for keys: a node, given on first use and kept while the object lives. */\nconst IDS = new WeakMap<object, number>();\nlet nextId = 0;\nconst idOf = (o: object | undefined): string => {\n if (o === undefined) return \"-\";\n let id = IDS.get(o);\n if (id === undefined) IDS.set(o, (id = nextId++));\n return String(id);\n};\n\n/** Whether a split under a node, the node included, runs across an axis (a master split holds none): by node and axis. */\nconst ACROSS = new WeakMap<object, Map<Axis, boolean>>();\n\nfunction memoOf<K>(options: SplitOptions<K>, fold: SplitFold<K>): StepMemo {\n let level = MEMOS;\n for (const answer of [fold.floor, fold.weight, options.fixed]) {\n let next = level.get(answer ?? ABSENT) as ByAnswer | undefined;\n if (next === undefined) level.set(answer ?? ABSENT, (next = new WeakMap()));\n level = next;\n }\n let byLengths = level.get(options.fixedAcross ?? ABSENT) as Map<string, StepMemo> | undefined;\n if (byLengths === undefined) level.set(options.fixedAcross ?? ABSENT, (byLengths = new Map<string, StepMemo>()));\n const key = `${px(options.gap)}|${px(options.handle)}|${px(fold.spine)}`;\n let memo = byLengths.get(key);\n if (memo === undefined) byLengths.set(key, (memo = { steps: new WeakMap(), pinned: new WeakMap() }));\n return memo;\n}\n\n// ---------------------------------------------------------------- the steps\n\n/**\n * The steps of one folding split tree, as its host answers for it. Made for a tree; answers from a memo shared by every\n * tree with the same `fold.floor`, `fold.weight`, `fixed` and `fixedAcross` (by identity) and the same gap, handle and\n * spine, so a host that keeps those and its unchanged subtrees the same objects counts each subtree once. Nothing in it\n * reads `fold.order`: what folds never depends on which pane is kept open first. Trees are taken as never changed in\n * place.\n *\n * Every split outside a master split needs an `axis`: a split with none divides along its box's longer side, which a\n * count made bottom-up cannot know.\n */\nexport class FoldSteps<K> {\n private readonly options: SplitOptions<K>;\n private readonly fold: SplitFold<K>;\n private readonly memo: StepMemo;\n private readonly parents = new Map<Split<K>, Branch<K>>();\n\n constructor(tree: Split<K>, options: SplitOptions<K>, fold: SplitFold<K>) {\n this.options = options;\n this.fold = fold;\n this.memo = memoOf(options, fold);\n const walk = (node: Split<K>): void => {\n if (isPane(node) || \"pane\" in node) return;\n if (node.axis === undefined) throw new Error(\"a folding split tree needs an axis on every split outside a master split\");\n for (const child of [node.a, node.b]) {\n this.parents.set(child, node);\n walk(child);\n }\n };\n walk(tree);\n }\n\n /** A split's gutter: its own gap, else the layout's, plus the handle. */\n gutter(split: Branch<K>): number {\n return (split.gap === undefined ? px(this.options.gap) : px(split.gap)) + px(this.options.handle);\n }\n\n /** What a fold takes from its open side where its spine joins no rail: the spine and the split's gap. */\n spineCost(split: Branch<K>): number {\n return px(this.fold.spine) + (split.gap === undefined ? px(this.options.gap) : px(split.gap));\n }\n\n /** A pane's fold floor along `axis` at `boundary`: the host's, and at least 1 px. */\n floor(node: Split<K>, axis: Axis, boundary: Split<K> | null): number {\n const v = this.fold.floor(node, axis, boundary);\n return v > 1 ? v : 1;\n }\n\n /** What a pane counts: its weight, a master split the sum of its panes'. */\n weight(node: Split<K>): number {\n const of = (pane: K): number => this.fold.weight?.(pane) ?? 1;\n if (\"pane\" in node) return of(node.pane);\n return panesOf(node).reduce((n, pane) => n + of(pane), 0);\n }\n\n /**\n * A node's pin along `axis`, as the fold counts it: its fixed length along its parent split (`fixed`) where that split\n * runs along `axis`, else its length across it (`fixedAcross`); only at 1 px or more. The root has none.\n */\n pin(node: Split<K>, axis: Axis): number | null {\n const parent = this.parents.get(node);\n if (parent === undefined) return null;\n const length = parent.axis === axis ? this.options.fixed?.(node, axis)?.length : this.options.fixedAcross?.(node, parent.axis!);\n return length !== undefined && Number.isFinite(length) && length >= 1 ? length : null;\n }\n\n /**\n * The steps of `node` along `axis`, measured at `boundary` (the nearest split above it along `axis`; null: none is\n * counted). `rails`: the edges where the node's box sits against an open rail, where a spine joins that rail and costs\n * nothing. `form`: see `FoldForm`. `cross`: the most the judged box measures across `axis` (a node inside pinned across\n * shorter than it doesn't span the box, so no rail on that length reaches it). `counted`: the length the node is\n * counted at across `axis`, read where a split across is judged at it; Infinity counts every split across kept.\n *\n * - A pane: one step, its floor and its weight.\n * - A split pinned along `axis`: its own steps up to the pin; one pinned shorter than its least step, that step.\n * - A split across `axis`: in the form its own count rule gives it at `counted`, inside which splits back along\n * `axis` are counted kept (depth one). Kept: its sides side by side, each counted across at its share. Folded: for\n * each count up to the smaller of its sides' most, the larger of their least lengths, each side counted across at\n * the length less the spine where it joins no rail.\n * - A split along `axis`, kept: each pair of its sides' steps, the lengths plus its gutter, the panes added; a side\n * keeps a rail only on the edge it touches, and is counted across at its pin where that is shorter. Folded: for each\n * count from 0 up to the smaller of its sides' most, the larger of the two sides' least lengths, each side with its\n * spine's cost (none where the spine's edge is a rail).\n */\n steps(\n node: Split<K>,\n axis: Axis,\n boundary: Split<K> | null,\n rails: ReadonlySet<Side>,\n form: FoldForm = \"any\",\n cross: number = Infinity,\n counted: number = Infinity,\n ): readonly FoldStep[] {\n // A node pinned across shorter than the box it sits in is drawn short of the rail: no spine in it joins the rail.\n const acrossPin = form === \"any\" && rails.size > 0 ? this.pin(node, otherAxis(axis)) : null;\n const reach = acrossPin !== null && acrossPin < cross - FIT ? NO_RAILS : rails;\n // The length across is read only where a split across can be judged at it; the bound across only by a split along.\n const at = this.holdsSplitAcross(node, axis) ? Math.max(0, counted) : Infinity;\n const pane = isPane(node);\n const bound = !pane && (node as Branch<K>).axis === axis ? String(cross) : \"\";\n const parent = this.parents.get(node)?.axis ?? \"\";\n const key = pane ? `${axis}|${idOf(boundary ?? undefined)}` : `${axis}|${idOf(boundary ?? undefined)}|${[...reach].sort().join(\",\")}|${form}|${bound}|${at}|${parent}`;\n let byKey = this.memo.steps.get(node);\n const known = byKey?.get(key);\n if (known !== undefined) return known;\n const steps = this.build(node, axis, boundary, reach, form, cross, at);\n if (byKey === undefined) this.memo.steps.set(node, (byKey = new Map<string, readonly FoldStep[]>()));\n byKey.set(key, steps);\n return steps;\n }\n\n private build(node: Split<K>, axis: Axis, boundary: Split<K> | null, rails: ReadonlySet<Side>, form: FoldForm, cross: number, counted: number): readonly FoldStep[] {\n if (isPane(node) || \"pane\" in node) return [{ length: this.floor(node, axis, boundary), panes: this.weight(node) }];\n const pin = this.pin(node, axis);\n if (pin !== null && form === \"any\") {\n const within = this.steps(node, axis, boundary, rails, \"open-side\", cross, counted);\n const fitting = within.filter((step) => step.length <= pin);\n return fitting.length > 0 ? fitting : within.slice(0, 1);\n }\n if (node.axis !== axis) return this.acrossSteps(node, axis, boundary, rails, counted);\n const [aEdge, bEdge] = sideEdges(axis);\n const out: FoldStep[] = [];\n if (form !== \"folded\") {\n // Each side spans the split across: counted at the split's length across, or at its pin there where shorter.\n const acrossOf = (side: Split<K>): number => {\n const p = Number.isFinite(counted) ? this.pin(side, otherAxis(axis)) : null;\n return p === null ? counted : Math.min(p, counted);\n };\n const a = this.steps(node.a, axis, node, railOn(rails, aEdge), \"any\", cross, acrossOf(node.a));\n const b = this.steps(node.b, axis, node, railOn(rails, bEdge), \"any\", cross, acrossOf(node.b));\n const gutter = this.gutter(node);\n for (const x of a) for (const y of b) out.push({ length: x.length + gutter + y.length, panes: x.panes + y.panes });\n }\n const shown = (side: \"a\" | \"b\"): FoldStep[] => {\n const openEdge = side === \"a\" ? aEdge : bEdge;\n const spineEdge = side === \"a\" ? bEdge : aEdge;\n const cost = rails.has(spineEdge) ? 0 : this.spineCost(node);\n const openRails = new Set<Side>([...railOn(rails, openEdge), spineEdge]);\n return this.steps(node[side], axis, node, openRails, \"open-side\", cross, counted).map((step) => ({ length: step.length + cost, panes: step.panes }));\n };\n return stepFrontier([...out, ...foldedSteps(shown(\"a\"), shown(\"b\"))]);\n }\n\n /**\n * The steps along `axis` of `node`, a split across it, in the form its own count rule gives it at `length` (its\n * length along its own axis). Its own steps are counted with no length across them: depth one.\n */\n private acrossSteps(node: Branch<K>, axis: Axis, boundary: Split<K> | null, rails: ReadonlySet<Side>, length: number): readonly FoldStep[] {\n if (!Number.isFinite(length)) return besideSteps(this.steps(node.a, axis, boundary, NO_RAILS), this.steps(node.b, axis, boundary, NO_RAILS));\n const own = otherAxis(axis);\n const [aEdge, bEdge] = sideEdges(own);\n const ownRails = new Set<Side>([...railOn(rails, aEdge), ...railOn(rails, bEdge)]);\n const aOwn = this.steps(node.a, own, node, railOn(rails, aEdge));\n const bOwn = this.steps(node.b, own, node, railOn(rails, bEdge));\n const gutter = this.gutter(node);\n // At its all-open need or longer it keeps every pane, and each side at least its own all-open need, and so on\n // down: the same steps as with no length across, unless a pin along its axis inside cuts a side shorter.\n const allOpen = (aOwn[aOwn.length - 1]?.length ?? 0) + gutter + (bOwn[bOwn.length - 1]?.length ?? 0);\n if (length + FIT >= allOpen && !this.pinnedInside(node, own)) return this.acrossSteps(node, axis, boundary, rails, Infinity);\n const judged = countRule(aOwn, bOwn, this.steps(node, own, null, ownRails, \"folded\"), length, gutter, length / 2 - gutter / 2);\n // A side spans the split along `axis` but not its rails there; it touches the rail on its own edge, unless pinned\n // along `axis`, where it may fall short of it.\n const sideRails = (side: Split<K>, edges: ReadonlySet<Side>): ReadonlySet<Side> => (this.pin(side, axis) === null ? edges : NO_RAILS);\n if (judged !== \"fold\") {\n const room = Math.max(0, length - gutter);\n const aLength = Math.max(0, room - leastKeeping(bOwn, judged.b));\n const bLength = Math.max(0, room - leastKeeping(aOwn, aLength));\n return besideSteps(\n this.steps(node.a, axis, boundary, sideRails(node.a, railOn(rails, aEdge)), \"any\", Infinity, aLength),\n this.steps(node.b, axis, boundary, sideRails(node.b, railOn(rails, bEdge)), \"any\", Infinity, bLength),\n );\n }\n const shown = (side: \"a\" | \"b\"): readonly FoldStep[] => {\n const openEdge = side === \"a\" ? aEdge : bEdge;\n const spineEdge = side === \"a\" ? bEdge : aEdge;\n const open = Math.max(0, length - (rails.has(spineEdge) ? 0 : this.spineCost(node)));\n const openRails = new Set<Side>([...railOn(rails, openEdge), spineEdge]);\n return this.steps(node[side], axis, boundary, sideRails(node[side], openRails), \"open-side\", Infinity, open);\n };\n return stepFrontier(foldedSteps(shown(\"a\"), shown(\"b\")));\n }\n\n /** Whether `node`'s subtree, `node` included, holds a split (not a master split) across `axis`. */\n private holdsSplitAcross(node: Split<K>, axis: Axis): boolean {\n if (isPane(node) || \"pane\" in node) return false;\n let byAxis = ACROSS.get(node);\n const known = byAxis?.get(axis);\n if (known !== undefined) return known;\n const value = node.axis !== axis || this.holdsSplitAcross(node.a, axis) || this.holdsSplitAcross(node.b, axis);\n if (byAxis === undefined) ACROSS.set(node, (byAxis = new Map<Axis, boolean>()));\n byAxis.set(axis, value);\n return value;\n }\n\n /** Whether a node strictly inside `node` is pinned along `axis`. */\n private pinnedInside(node: Split<K>, axis: Axis): boolean {\n if (\"pane\" in node) return false;\n let byAxis = this.memo.pinned.get(node);\n const known = byAxis?.get(axis);\n if (known !== undefined) return known;\n const pinnedIn = (child: Split<K>): boolean => this.pin(child, axis) !== null || this.pinnedInside(child, axis);\n const value = pinnedIn(node.a) || pinnedIn(node.b);\n if (byAxis === undefined) this.memo.pinned.set(node, (byAxis = new Map<Axis, boolean>()));\n byAxis.set(axis, value);\n return value;\n }\n}\n\n/** A fold's steps from its two sides each shown: for each count both can keep, the larger of their least lengths. */\nfunction foldedSteps(a: readonly FoldStep[], b: readonly FoldStep[]): FoldStep[] {\n const most = Math.min(a[a.length - 1]?.panes ?? 0, b[b.length - 1]?.panes ?? 0);\n const out: FoldStep[] = [];\n for (let panes = 0; panes <= most; panes += 1) out.push({ length: Math.max(leastLengthFor(a, panes), leastLengthFor(b, panes)), panes });\n return out;\n}\n\n/** Each pair of `a` and `b` side by side across: the larger length, the panes added. */\nconst besideSteps = (a: readonly FoldStep[], b: readonly FoldStep[]): FoldStep[] =>\n stepFrontier(a.flatMap((x) => b.map((y) => ({ length: Math.max(x.length, y.length), panes: x.panes + y.panes }))));\n","/**\n * The layout of a folding split tree: what folds, which side of each fold shows, and every rect, from one walk. Internal:\n * `layoutSplitTree` calls it when its options hold a `fold`.\n *\n * At each split, top-down, the walk weighs the ways to draw it with the count rule (src/tiling/fold-steps.ts): kept,\n * with each side laid out as its steps allow, or folded. It takes the way that keeps the most panes open on their fold\n * floors whichever side of every fold shows, and on a tie it stays open. Each side is then decided the same way in the\n * length counted for it. Once all is decided, the walk draws: a kept split from its ratio on the needs of the forms its\n * sides chose, as the split layout decides a split, so the boundary moves only as far as a side's need asks. Folded,\n * the side holding the first pane of the order stays open in the split's box less a spine and a gap, and the other side\n * becomes a spine on the edge where it sits. Nested folds on one edge share one rail.\n *\n * What folds depends on the tree, the area and the host's answers only: the order chooses which side of a fold shows,\n * and no ratio decides anything (a split is judged at the length its parent counted for it, not at the box a ratio\n * gave it).\n */\nimport type { Rect } from \"../geometry\";\nimport type { Axis, Side } from \"../side\";\nimport type { SplitFold, SplitFoldGeometry } from \"./fold\";\nimport { countRule, FoldSteps, leastKeeping, type FoldKept, type FoldStep } from \"./fold-steps\";\nimport { laySplitTree, type FixedLength, type MinLength, type SplitGeometry, type SplitLayout, type SplitOptions } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** A length along each axis. */\ninterface Lengths {\n readonly x: number;\n readonly y: number;\n}\n\n/**\n * What a node's box is known to measure whatever the ratios: the length counted for it (what its parent's decision\n * guarantees it) and the most it can measure (the area cut by the needs of what sits beside it).\n */\ninterface Room {\n readonly counted: Lengths;\n readonly most: Lengths;\n}\n\n/** A rail open on one edge: the fold heading it (its index in `folds`), its box, and where the open side next to it starts. */\ninterface OpenRail {\n readonly fold: number;\n readonly rect: Rect;\n /** The open side's edge next to the rail: an x for a left or right rail, a y for a top or bottom one. */\n readonly boundary: number;\n}\n\ntype OpenRails = Readonly<Partial<Record<Side, OpenRail>>>;\n\n/** One side of a folded split laid out as the open one: its box, its room and rails, and what the spine takes. */\ninterface OpenLayout {\n readonly edge: Side;\n readonly openRect: Rect;\n readonly railRect: Rect;\n readonly railOf: number;\n readonly openRails: OpenRails;\n readonly openRoom: Room;\n /** What the spine and the split's gap take from the split's length: none where the spine joins a rail. */\n readonly taken: number;\n}\n\n/** A node as decided, before it is drawn: what folds, and the forms each kept split's sides chose. */\ntype Decided<K> =\n | { readonly kind: \"pane\"; readonly node: Split<K> }\n | { readonly kind: \"kept\"; readonly node: Branch<K>; readonly pair: FoldKept; readonly a: Decided<K>; readonly b: Decided<K> }\n | {\n readonly kind: \"fold\";\n readonly node: Branch<K>;\n readonly room: Room;\n readonly open: \"a\" | \"b\";\n /** Each side decided as the open one: whichever shows, the split holds room for it. */\n readonly sides: Readonly<Record<\"a\" | \"b\", { readonly layout: OpenLayout; readonly decided: Decided<K> }>>;\n };\n\ntype DecidedFold<K> = Extract<Decided<K>, { kind: \"fold\" }>;\n\nconst NO_RAILS: OpenRails = {};\nconst NONE: ReadonlySet<Side> = new Set<Side>();\nconst EDGES: readonly Side[] = [\"left\", \"right\", \"top\", \"bottom\"];\n\n/** Px between two segments of one rail. */\nconst SEGMENT_GAP = 2;\n\n/** Ratios this close are one. */\nconst RATIO_EPSILON = 1e-9;\n\n/** A segment this close to the floor reaches it. */\nconst FLOOR_EPSILON = 1e-9;\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\nconst otherAxis = (axis: Axis): Axis => (axis === \"x\" ? \"y\" : \"x\");\nconst lengthOf = (rect: Rect, axis: Axis): number => (axis === \"x\" ? rect.width : rect.height);\nconst isPane = <K>(node: Split<K>): boolean => \"pane\" in node || node.master !== undefined;\nconst sideEdges = (axis: Axis): readonly [Side, Side] => (axis === \"x\" ? [\"left\", \"right\"] : [\"top\", \"bottom\"]);\nconst nearPx = (a: number, b: number): boolean => Math.abs(a - b) <= 0.5;\n\n/** Whether a fold in `rect` with its spine on `edge` sits right against `rail`, along its whole length. */\nfunction joinsRail(rail: OpenRail, rect: Rect, edge: Side): boolean {\n switch (edge) {\n case \"left\":\n return nearPx(rect.x, rail.boundary) && nearPx(rect.y, rail.rect.y) && nearPx(rect.height, rail.rect.height);\n case \"right\":\n return nearPx(rect.x + rect.width, rail.boundary) && nearPx(rect.y, rail.rect.y) && nearPx(rect.height, rail.rect.height);\n case \"top\":\n return nearPx(rect.y, rail.boundary) && nearPx(rect.x, rail.rect.x) && nearPx(rect.width, rail.rect.width);\n case \"bottom\":\n return nearPx(rect.y + rect.height, rail.boundary) && nearPx(rect.x, rail.rect.x) && nearPx(rect.width, rail.rect.width);\n }\n}\n\n/** Where the open side next to a rail on `edge` starts, given that side's box. */\nfunction railBoundary(openRect: Rect, edge: Side): number {\n switch (edge) {\n case \"left\":\n return openRect.x;\n case \"right\":\n return openRect.x + openRect.width;\n case \"top\":\n return openRect.y;\n case \"bottom\":\n return openRect.y + openRect.height;\n }\n}\n\n/** The spine's and the open side's boxes in a folded split's `rect`. */\nfunction foldBoxes(rect: Rect, axis: Axis, edge: Side, spine: number, gap: number): { spineRect: Rect; openRect: Rect } {\n if (axis === \"x\") {\n const spineWidth = Math.max(0, Math.min(spine, rect.width));\n const openWidth = Math.max(0, rect.width - spine - gap);\n return edge === \"left\"\n ? { spineRect: { x: rect.x, y: rect.y, width: spineWidth, height: rect.height }, openRect: { x: rect.x + rect.width - openWidth, y: rect.y, width: openWidth, height: rect.height } }\n : { spineRect: { x: rect.x + rect.width - spineWidth, y: rect.y, width: spineWidth, height: rect.height }, openRect: { x: rect.x, y: rect.y, width: openWidth, height: rect.height } };\n }\n const spineHeight = Math.max(0, Math.min(spine, rect.height));\n const openHeight = Math.max(0, rect.height - spine - gap);\n return edge === \"top\"\n ? { spineRect: { x: rect.x, y: rect.y, width: rect.width, height: spineHeight }, openRect: { x: rect.x, y: rect.y + rect.height - openHeight, width: rect.width, height: openHeight } }\n : { spineRect: { x: rect.x, y: rect.y + rect.height - spineHeight, width: rect.width, height: spineHeight }, openRect: { x: rect.x, y: rect.y, width: rect.width, height: openHeight } };\n}\n\n/**\n * A rail's (or a spine's) segments by weight, from its top or left end, each as long as its share, with up to\n * `SEGMENT_GAP` px between two. `axis` is the folded split's: a sideways fold's rail runs top to bottom.\n */\nfunction segments(rail: Rect, axis: Axis, weights: readonly number[]): Rect[] {\n const along = axis === \"x\";\n const length = along ? rail.height : rail.width;\n const gap = weights.length > 1 ? Math.min(SEGMENT_GAP, length / (weights.length * 4)) : 0;\n const total = weights.reduce((sum, weight) => sum + weight, 0);\n const free = Math.max(0, length - gap * (weights.length - 1));\n const out: Rect[] = [];\n let offset = 0;\n weights.forEach((weight, index) => {\n const part = index === weights.length - 1 ? Math.max(0, length - offset) : (free * weight) / total;\n out.push(along ? { x: rail.x, y: rail.y + offset, width: rail.width, height: part } : { x: rail.x + offset, y: rail.y, width: part, height: rail.height });\n offset += part + gap;\n });\n return out;\n}\n\n/** The room of a box nothing outside it constrains: counted and at most its own size. */\nconst wholeRoom = (rect: Rect): Room => ({ counted: { x: rect.width, y: rect.height }, most: { x: rect.width, y: rect.height } });\n\n/** `lengths` with `axis` set to `value`. */\nconst withLength = (lengths: Lengths, axis: Axis, value: number): Lengths => (axis === \"x\" ? { x: value, y: lengths.y } : { x: lengths.x, y: value });\n\n/**\n * `tree` laid out in `area` with `fold`: see the module's comment. Where nothing folds and every kept split is drawn at\n * the ratio the layout without the fold draws it at, the panes and splits are that layout's (fresh maps), the needs\n * those the fold chose.\n */\nexport function foldLayout<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K>, fold: SplitFold<K>): SplitLayout<K> {\n const plainRatios = new Map<Split<K>, number>();\n const base = laySplitTree(tree, area, options, plainRatios);\n if (!tree) return { ...base, spines: new Map(), folds: [] };\n const steps = new FoldSteps(tree, options, fold);\n const order = fold.order;\n const targetOrder = fold.targetOrder ?? order;\n const weight = (pane: K): number => fold.weight?.(pane) ?? 1;\n const spine = px(fold.spine);\n const gapOf = (split: Branch<K>): number => (split.gap === undefined ? px(options.gap) : px(split.gap));\n\n const panes = new Map<K, Rect>();\n const splits = new Map<string, SplitGeometry>();\n const folds: SplitFoldGeometry<K>[] = [];\n /** Whether a kept split is drawn at another ratio than the layout without the fold draws it at. */\n const drawnAt = { moved: false };\n\n /** A child's length across its split, as the host fixes it (above 0), else null. */\n const pinAcross = (child: Split<K>, split: Branch<K>): number | null => {\n const length = options.fixedAcross?.(child, split.axis!);\n return usable(length) ? length : null;\n };\n /** A kept split's side counted across: at the split's length across, or at the side's length across where shorter. */\n const sideAcross = (side: Split<K>, split: Branch<K>, across: number): number => {\n const pin = pinAcross(side, split);\n return pin === null ? across : Math.min(pin, across);\n };\n\n /**\n * A kept split laid out in `rect` from its ratio, on the needs `a` and `b`, each side's net and fixed length as the\n * layout reads them, and each child's length across: the split layout's own arithmetic for one split.\n */\n const layOutKept = (node: Branch<K>, rect: Rect, a: number, b: number): { geometry: SplitGeometry; a: Rect; b: Rect } => {\n const axis = node.axis!;\n const sideOf = (child: Split<K>): { fixed: FixedLength | undefined; net: boolean } => {\n const fixed = options.fixed?.(child, axis);\n const kept = !!fixed?.keep && usable(fixed.length);\n return { fixed, net: kept || (options.floor ? options.floor(child, axis, node).net !== false : true) };\n };\n const sides = { a: sideOf(node.a), b: sideOf(node.b) };\n const one: Split<0 | 1> = {\n id: \"s\",\n a: { pane: 0 },\n b: { pane: 1 },\n axis,\n ...(node.ratio !== undefined ? { ratio: node.ratio } : {}),\n ...(node.gap !== undefined ? { gap: node.gap } : {}),\n };\n const second = (child: Split<0 | 1>): boolean => \"pane\" in child && child.pane === 1;\n const laid = laySplitTree(one, rect, {\n gap: options.gap,\n handle: options.handle,\n floor: (child): MinLength => (second(child) ? { min: b, net: sides.b.net } : { min: a, net: sides.a.net }),\n fixed: (child) => (second(child) ? sides.b.fixed : sides.a.fixed),\n fixedAcross: (child) => options.fixedAcross?.(second(child) ? node.b : node.a, axis),\n });\n const empty = (): Rect => ({ x: rect.x, y: rect.y, width: 0, height: 0 });\n return { geometry: laid.splits.get(\"s\")!, a: laid.panes.get(0) ?? empty(), b: laid.panes.get(1) ?? empty() };\n };\n\n /** The count rule on `split`, at the lengths counted for it (`rect`'s width and height), its rails and its bound across. */\n const judge = (split: Branch<K>, rect: Rect, crossMax: number, rails: ReadonlySet<Side>): \"fold\" | FoldKept => {\n const axis = split.axis!;\n const extent = Math.max(0, lengthOf(rect, axis));\n const gutter = steps.gutter(split);\n const [aEdge, bEdge] = sideEdges(axis);\n const onEdge = (edge: Side): ReadonlySet<Side> => (rails.has(edge) ? new Set<Side>([edge]) : NONE);\n // Rails as drawn: a node inside pinned across reaches a rail where its pin spans the box across, whatever the ratios.\n const cross = Math.max(0, crossMax);\n // Each side is counted across at the split's counted length across, or at its pin there where shorter, as drawn.\n const across = Math.max(0, lengthOf(rect, otherAxis(axis)));\n const a = steps.steps(split.a, axis, split, onEdge(aEdge), \"any\", cross, sideAcross(split.a, split, across));\n const b = steps.steps(split.b, axis, split, onEdge(bEdge), \"any\", cross, sideAcross(split.b, split, across));\n const folded = steps.steps(split, axis, null, rails, \"folded\", cross, across);\n const middle = extent / 2 - gutter / 2;\n return countRule(a, b, folded, extent, gutter, middle);\n };\n\n /** The side of `split` holding the first pane of the order it holds, else `\"a\"`. */\n const openSideOf = (split: Branch<K>): \"a\" | \"b\" => {\n const a = new Set(panesOf(split.a));\n const b = new Set(panesOf(split.b));\n for (const pane of order) {\n if (a.has(pane)) return \"a\";\n if (b.has(pane)) return \"b\";\n }\n return \"a\";\n };\n\n /**\n * `side` of folded `node` laid out as the open one in `rect`, with the other side's spine on its edge. `foldIndex`:\n * the fold's index in `folds` (-1 while deciding).\n */\n const openLayout = (node: Branch<K>, side: \"a\" | \"b\", rect: Rect, room: Room, rails: OpenRails, foldIndex: number): OpenLayout => {\n const axis = node.axis!;\n const [aEdge, bEdge] = sideEdges(axis);\n const edge = side === \"a\" ? bEdge : aEdge;\n const gap = gapOf(node);\n // A fold right against an enclosing fold's rail on the same edge joins that rail: no spine or gap of its own.\n const rail = rails[edge];\n const joined = rail !== undefined && joinsRail(rail, rect, edge);\n const own = joined ? null : foldBoxes(rect, axis, edge, spine, gap);\n const openRect = own === null ? { ...rect } : own.openRect;\n const railRect = own === null ? { ...rail!.rect } : own.spineRect;\n const railOf = own === null ? rail!.fold : foldIndex;\n const openRails: OpenRails = own === null ? rails : { ...rails, [edge]: { fold: foldIndex, rect: railRect, boundary: railBoundary(openRect, edge) } };\n // The open side's room is the split's less what the spine and gap take: a length, not read from the box.\n const taken = own === null ? 0 : spine + gap;\n const openRoom: Room = {\n counted: withLength(room.counted, axis, Math.max(0, room.counted[axis] - taken)),\n most: withLength(room.most, axis, Math.max(0, room.most[axis] - taken)),\n };\n return { edge, openRect, railRect, railOf, openRails, openRoom, taken };\n };\n\n /** `node` decided as folded: each side decided as the open one. The order chooses the side that shows, and only here. */\n const decideFold = (node: Branch<K>, rect: Rect, room: Room, rails: OpenRails): DecidedFold<K> => {\n const sideOf = (side: \"a\" | \"b\"): { layout: OpenLayout; decided: Decided<K> } => {\n const layout = openLayout(node, side, rect, room, rails, -1);\n return { layout, decided: decide(node[side], layout.openRect, layout.openRoom, layout.openRails) };\n };\n return { kind: \"fold\", node, room, open: openSideOf(node), sides: { a: sideOf(\"a\"), b: sideOf(\"b\") } };\n };\n\n /**\n * What folds, top-down. A split is judged at the length its parent counted for it, never at its box, so no ratio\n * decides anything; the box `rect` is read for edge facts only (which rails it sits against along its whole length).\n *\n * A kept split's sides are counted one after the other (across, a side pinned shorter at its pin): the first at what\n * the second needs to keep its pair's panes leaves (`leastKeeping`), then the second at what the first's chosen forms\n * leave. So slack a side cannot use goes to the other, each side is decided once, the two fit by construction, and\n * neither keeps fewer panes than the pair the count rule kept.\n */\n const decide = (node: Split<K>, rect: Rect, room: Room, rails: OpenRails): Decided<K> => {\n if (isPane(node) || \"pane\" in node) return { kind: \"pane\", node };\n const here = new Set<Side>(\n EDGES.filter((edge) => {\n const rail = rails[edge];\n return rail !== undefined && joinsRail(rail, rect, edge);\n }),\n );\n const judged: Lengths = { x: Math.max(0, room.counted.x), y: Math.max(0, room.counted.y) };\n const along = node.axis!;\n const across = otherAxis(along);\n const crossMax = Math.max(lengthOf(rect, across), room.most[across]);\n const verdict = judge(node, { x: rect.x, y: rect.y, width: judged.x, height: judged.y }, crossMax, here);\n if (verdict === \"fold\") return decideFold(node, rect, { counted: judged, most: room.most }, rails);\n const laid = layOutKept(node, rect, verdict.a, verdict.b);\n const gutter = steps.gutter(node);\n const sideRoom = (child: Split<K>, need: number, otherNeed: number): Room => {\n const pin = pinAcross(child, node);\n const counted = withLength(withLength(judged, along, need), across, pin === null ? judged[across] : Math.min(pin, judged[across]));\n return { counted, most: withLength(room.most, along, Math.max(0, room.most[along] - gutter - otherNeed)) };\n };\n const roomLength = Math.max(0, judged[along] - gutter);\n const bEdge: Side = along === \"x\" ? \"right\" : \"bottom\";\n const bRails = here.has(bEdge) ? new Set<Side>([bEdge]) : NONE;\n const bSteps: readonly FoldStep[] = steps.steps(node.b, along, node, bRails, \"any\", Math.max(0, crossMax), sideAcross(node.b, node, judged[across]));\n const bLeast = leastKeeping(bSteps, verdict.b);\n const a = decide(node.a, laid.a, sideRoom(node.a, Math.max(0, roomLength - bLeast), bLeast), rails);\n const aNeed = chosenNeed(a, along, node);\n // The second side's box with the first at its chosen need: no divider draws it longer than what the first leaves.\n const bRect = layOutKept(node, rect, aNeed, bLeast).b;\n const b = decide(node.b, bRect, sideRoom(node.b, Math.max(0, roomLength - aNeed), aNeed), rails);\n return { kind: \"kept\", node, pair: verdict, a, b };\n };\n\n const chosen = new WeakMap<Decided<K>, Map<Split<K> | null, Partial<Record<Axis, number>>>>();\n\n /**\n * The need along `axis` of the forms `decided` chose, measured by `boundary` (the nearest split along it): a pane its\n * fold floor; a kept split its sides' chosen needs plus its gutter along, the larger of them across; a fold the larger\n * over its two sides each as the open one, plus what its spine takes along, so the order moves nothing outside it.\n */\n const chosenNeed = (decided: Decided<K>, axis: Axis, boundary: Split<K> | null): number => {\n if (decided.kind === \"pane\") return steps.floor(decided.node, axis, boundary);\n let byBoundary = chosen.get(decided);\n const known = byBoundary?.get(boundary)?.[axis];\n if (known !== undefined) return known;\n const node = decided.node;\n const alongIt = node.axis === axis;\n let need = 0;\n if (decided.kind === \"kept\") {\n need = alongIt\n ? chosenNeed(decided.a, axis, node) + steps.gutter(node) + chosenNeed(decided.b, axis, node)\n : Math.max(chosenNeed(decided.a, axis, boundary), chosenNeed(decided.b, axis, boundary));\n } else {\n for (const side of [\"a\", \"b\"] as const) {\n const { layout, decided: open } = decided.sides[side];\n need = Math.max(need, alongIt ? chosenNeed(open, axis, node) + layout.taken : chosenNeed(open, axis, boundary));\n }\n }\n if (byBoundary === undefined) chosen.set(decided, (byBoundary = new Map<Split<K> | null, Partial<Record<Axis, number>>>()));\n byBoundary.set(boundary, { ...byBoundary.get(boundary), [axis]: need });\n return need;\n };\n\n /** Draws `decided` in `rect`: a kept split from its ratio on the chosen needs of its sides. */\n const draw = (decided: Decided<K>, rect: Rect, enclosing: readonly number[], rails: OpenRails): void => {\n if (decided.kind === \"fold\") {\n drawFold(decided, rect, enclosing, rails);\n return;\n }\n if (decided.kind === \"pane\") {\n const node = decided.node;\n if (\"pane\" in node) {\n panes.set(node.pane, { ...rect });\n return;\n }\n // A master split never folds: laid out as the layout lays it out, its panes flat.\n const laid = laySplitTree(node, rect, options);\n for (const [pane, r] of laid.panes) panes.set(pane, r);\n for (const [id, geometry] of laid.splits) splits.set(id, geometry);\n return;\n }\n const node = decided.node;\n const axis = node.axis!;\n const laid = layOutKept(node, rect, chosenNeed(decided.a, axis, node), chosenNeed(decided.b, axis, node));\n if (node.id !== undefined) splits.set(node.id, laid.geometry);\n if (!drawnAt.moved) {\n const plain = plainRatios.get(node);\n if (plain === undefined || !(Math.abs(plain - laid.geometry.ratio) <= RATIO_EPSILON)) drawnAt.moved = true;\n }\n draw(decided.a, laid.a, enclosing, rails);\n draw(decided.b, laid.b, enclosing, rails);\n };\n\n /** Draws a folded split: its open side in the box less the spine, the other side a spine on its edge. */\n const drawFold = (decided: DecidedFold<K>, rect: Rect, enclosing: readonly number[], rails: OpenRails): void => {\n const node = decided.node;\n const index = folds.length;\n const layout = openLayout(node, decided.open, rect, decided.room, rails, index);\n const folded = panesOf(node[decided.open === \"a\" ? \"b\" : \"a\"]);\n const shown = folded.filter((pane) => weight(pane) > 0);\n const target = targetOrder.find((pane) => shown.includes(pane)) ?? shown[0] ?? null;\n folds.push({\n id: node.id,\n axis: node.axis!,\n open: decided.open,\n edge: layout.edge,\n rect: { ...rect },\n openRect: layout.openRect,\n spine: { ...layout.railRect },\n rail: layout.railRect,\n // Set with the rail's segments, below.\n railContentLength: 0,\n railOf: layout.railOf,\n parent: enclosing.length > 0 ? enclosing[enclosing.length - 1]! : null,\n panes: folded,\n target,\n });\n draw(decided.sides[decided.open].decided, layout.openRect, [...enclosing, index], layout.openRails);\n };\n\n draw(decide(tree, area, wholeRoom(area), NO_RAILS), area, [], NO_RAILS);\n\n // Each rail's segments. A rail holding more than one fold is shared by its folds, by the panes that show in each (at\n // least 1); each fold's spine by its panes that show, in reading order. A pane that shows nothing has none, as the\n // rail gives it no share. Under a segment floor that a segment would fall under, every segment is the floor long.\n const onRail = new Map<number, number[]>();\n folds.forEach((each, index) => onRail.set(each.railOf, [...(onRail.get(each.railOf) ?? []), index]));\n const drawn: SplitFoldGeometry<K>[] = [...folds];\n const paneParts: Rect[][] = folds.map(() => []);\n const asked = px(fold.segmentFloor);\n for (const members of onRail.values()) {\n const head = folds[members[0]!]!;\n const along = head.axis === \"x\" ? \"height\" : \"width\";\n const length = head.rail[along];\n const shownOf = (i: number): K[] => folds[i]!.panes.filter((pane) => weight(pane) > 0);\n const shares = members.length < 2 ? [head.spine] : segments(head.rail, head.axis, members.map((i) => Math.max(1, shownOf(i).length)));\n let spinesOf = shares;\n let partsOf = members.map((i, n) => segments(shares[n]!, head.axis, shownOf(i).map(() => 1)));\n let content = length;\n // The floor used: never longer than the rail's box, so one pane alone always fits it.\n const floor = Math.min(asked, length);\n const shortest = Math.min(...members.map((i, n) => (shownOf(i).length > 0 ? Math.min(...partsOf[n]!.map((r) => r[along])) : shares[n]![along])));\n if (floor > 0 && shortest < floor - FLOOR_EPSILON) {\n // Every segment the floor long, 2 px apart, from the box's top or left; a fold showing nothing takes one length.\n const unit = (at: number, size: number): Rect => (head.axis === \"x\" ? { ...head.rail, y: head.rail.y + at, height: size } : { ...head.rail, x: head.rail.x + at, width: size });\n let at = 0;\n const floored: Rect[] = [];\n partsOf = members.map((i) => {\n const start = at;\n const parts: Rect[] = [];\n for (let u = 0; u < Math.max(1, shownOf(i).length); u++, at += floor + SEGMENT_GAP) parts.push(unit(at, floor));\n floored.push(unit(start, at - SEGMENT_GAP - start));\n return shownOf(i).length > 0 ? parts : [];\n });\n spinesOf = floored;\n content = Math.max(length, at - SEGMENT_GAP);\n }\n members.forEach((i, n) => {\n drawn[i] = { ...folds[i]!, spine: { ...spinesOf[n]! }, railContentLength: content };\n paneParts[i] = partsOf[n]!;\n });\n }\n // Each folded pane that shows: its segment, in the folds' order.\n const spines = new Map<K, Rect>();\n drawn.forEach((each, i) => each.panes.filter((pane) => weight(pane) > 0).forEach((pane, n) => spines.set(pane, paneParts[i]![n]!)));\n\n if (drawn.length === 0 && !drawnAt.moved) {\n // Nothing folds or moves: the layout without the fold, with the needs the fold chose.\n const out = new Map<string, SplitGeometry>();\n for (const [id, geometry] of base.splits) {\n const mine = splits.get(id);\n out.set(id, mine === undefined ? geometry : { ...geometry, needs: mine.needs });\n }\n return { panes: base.panes, splits: out, spines, folds: drawn };\n }\n return { panes, splits, spines, folds: drawn };\n}\n","/**\n * `layoutSplitTree`: the split tree laid out, folding or not. One function lays the tree out, so what a host draws,\n * what a drag hits and what is judged to fit all come from it. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { SplitFold } from \"./fold\";\nimport { foldLayout } from \"./fold-plan\";\nimport { laySplitTree, type SplitLayout, type SplitOptions } from \"./layout\";\nimport type { Split } from \"./split\";\n\n/**\n * `SplitOptions` plus the fold, which only `layoutSplitTree` (and the drag and its conformance runs) takes:\n * `layoutSplit`, `splitNeed`, `canDropOnPane`, `canSplitPane` and `dropFits` throw on it.\n */\nexport interface FoldingSplitOptions<K> extends SplitOptions<K> {\n readonly fold?: SplitFold<K>;\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\n * under another, or a later one beside it): the box it divides, its axis and ratio in effect (after the floors), and its\n * divider, the gutter strip between its two sides. A split that lays out as master and stack is reported too, its\n * nested splits are not.\n *\n * With `fold`, a split that cannot keep its panes on their fold floors may fold: one side stays open and the other is\n * drawn as a spine (`spines`, `folds`); a folded split is not in `splits`, and a kept split's `needs` are the pair the\n * fold chose. Every split outside a master split then needs an `axis` (throws otherwise); a master split never folds.\n * Where nothing folds and no boundary moves, the panes and splits are those without the fold on the same\n * `options.floor`: with `fold`, a kept split's net is on where there is no `floor` (a ratio of 0.02 lays out at 20 px of\n * 1000 without the fold, 50 px with it). A spine has a segment per folded pane that shows (weight 1), at a content\n * position (`paintedSpines` gives where it is painted). `tilingDrag` takes the fold too and lays every tree of a drag\n * out here, and so do the conformance runs. See `SplitFold`.\n */\nexport function layoutSplitTree<K>(tree: Split<K> | null, area: Rect, options: FoldingSplitOptions<K> = {}): SplitLayout<K> {\n if (options.fold) return foldLayout(tree, area, options, options.fold);\n return { ...laySplitTree(tree, area, options), spines: new Map(), folds: [] };\n}\n\n/** The options with the fold's order set to `order`; the same options without a fold. @internal */\nexport const withOrder = <K>(options: FoldingSplitOptions<K>, order: readonly K[]): FoldingSplitOptions<K> =>\n options.fold ? { ...options, fold: { ...options.fold, order } } : options;\n","/**\n * Where a folding layout's spine segments are painted: `paintedSpines(layout, railOffset)`. A rail whose content runs\n * past its box (a segment floor, `SplitFold.segmentFloor`) shows a part of it, moved by the host's offset; the layout's\n * `spines` are content positions, this is what is painted. The drag's hit reads it too, so a point over a rail answers\n * the pane painted there. Pure. See docs/placement.md, Entry: tiling, \"A folding split tree\".\n */\nimport { contains, type Point, type Rect } from \"../geometry\";\nimport type { SplitFoldGeometry } from \"./fold\";\n\n/** What a painted rail reads of a layout: its segments and its folds (a `SplitLayout`, or a drag's `TilingLaidOut`). */\nexport interface FoldedLayout<K> {\n readonly spines: ReadonlyMap<K, Rect>;\n readonly folds: readonly SplitFoldGeometry<K>[];\n}\n\n/**\n * How far a rail's content is moved along its edge, px, from the rail box's top or left (on a right-to-left page too:\n * the host converts). Asked with the fold heading the rail (`folds[railOf]`) and its index in `folds`, the host's key\n * for the rail. Not clamped: a segment moved past the box is cut, or not painted. A value that is not a finite number\n * reads 0.\n */\nexport type RailOffset<K> = (rail: SplitFoldGeometry<K>, index: number) => number;\n\n/** The offset of the rail headed by `folds[index]`, as read: a finite number, else 0. */\nfunction offsetOf<K>(folds: readonly SplitFoldGeometry<K>[], index: number, railOffset: RailOffset<K> | undefined): number {\n const v = railOffset?.(folds[index]!, index);\n return typeof v === \"number\" && Number.isFinite(v) ? v : 0;\n}\n\n/** `r` moved by `-offset` along a rail of `axis` (a sideways fold's rail runs top to bottom), cut to `box`; null when nothing is left. */\nfunction paint(r: Rect, axis: SplitFoldGeometry<unknown>[\"axis\"], offset: number, box: Rect): Rect | null {\n if (axis === \"x\") {\n const y0 = Math.max(r.y - offset, box.y);\n const y1 = Math.min(r.y - offset + r.height, box.y + box.height);\n return y1 > y0 ? { x: r.x, y: y0, width: r.width, height: y1 - y0 } : null;\n }\n const x0 = Math.max(r.x - offset, box.x);\n const x1 = Math.min(r.x - offset + r.width, box.x + box.width);\n return x1 > x0 ? { x: x0, y: r.y, width: x1 - x0, height: r.height } : null;\n}\n\n/**\n * Each spine segment of `layout` as it is painted: moved by its rail's offset along the rail (`railOffset`, default 0\n * everywhere) and cut to the rail's box; a segment wholly off the box is absent. Where a rail's content fits its box\n * and the offset is 0, this is `layout.spines`. Pure: every call reads the offsets anew.\n */\nexport function paintedSpines<K>(layout: FoldedLayout<K>, railOffset?: RailOffset<K>): Map<K, Rect> {\n const out = new Map<K, Rect>();\n const offsets = new Map<number, number>();\n for (const fold of layout.folds) {\n const head = layout.folds[fold.railOf]!;\n let offset = offsets.get(fold.railOf);\n if (offset === undefined) offsets.set(fold.railOf, (offset = offsetOf(layout.folds, fold.railOf, railOffset)));\n for (const pane of fold.panes) {\n const r = layout.spines.get(pane);\n if (!r) continue;\n const painted = paint(r, head.axis, offset, head.rail);\n if (painted) out.set(pane, painted);\n }\n }\n return out;\n}\n\n/**\n * The rail whose box holds `point` (the index of the fold heading it) and the pane painted there, null in a gap or\n * past the last segment; null when no rail's box holds it. @internal Read by the drag's hit.\n */\nexport function railAt<K>(layout: FoldedLayout<K>, point: Point, railOffset?: RailOffset<K>): { readonly rail: number; readonly pane: K | null } | null {\n const rail = layout.folds.findIndex((f, i) => f.railOf === i && contains(f.rail, point, 0));\n if (rail < 0) return null;\n for (const [pane, r] of paintedSpines(layout, railOffset)) {\n if (layout.folds.some((f) => f.railOf === rail && f.panes.includes(pane)) && contains(r, point, 0)) return { rail, pane };\n }\n return { rail, pane: null };\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 * - **A painted strip is read as painted and moves nothing** (under a fold). The frame on screen is the lift on the lift\n * basis; on the base basis it follows the hold: the base with nothing held, the lift at home, `after(held)` for a\n * place. Over a rail of that frame, at the host's offset, the read names the pane painted there and the frame stays:\n * on the lift basis nothing is held (the lift is drawn whatever is held), on the base basis the hold stays as it was\n * (home stays home, a held place stays held and a release commits it as previewed, nothing stays nothing). Off the\n * frame's rails the hold follows the basis's zone map. So on the base basis the open panes are tested against the\n * base while another frame may be painted; only a painted strip is read from the frame on screen.\n * - **A pane you see folded takes no drop** (under a fold, on the base basis). The hold does not change to a place\n * whose pane is a strip both at the lift and in the frame drawn for the hold, unless the hold is already a place of\n * that pane; where such a place is refused the hold stays as it is, and so does its frame. Off the strip the read\n * names no strip (`folded` is null). It is one check on the place's pane, no geometry: a pane open at the lift, a\n * pane the frame draws open (with nothing held the base is drawn), the lift basis and a layout without a fold are\n * held as before. So the place beside such a pane is reached only from a frame that draws it open.\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 { railAt, type RailOffset } from \"./painted\";\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/**\n * A point over a rail of a folding layout (`SplitLayout.folds`): the rail (the index in the basis's `folds` of the fold\n * heading it) and the pane whose spine segment is painted there (`paintedSpines`), null in a gap or past the last\n * segment. A rail takes no drop: the whole of its box is refused.\n */\nexport interface TilingFolded<K> {\n readonly rail: number;\n readonly pane: K | null;\n}\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 * Under a fold, the rail under the pointer in the frame drawn for the hold the read started from, and the pane\n * painted there; null off every rail of that frame. There the frame stays: nothing is held on the lift basis, and on\n * the base basis the hold is the one the read started from.\n */\n readonly folded: TilingFolded<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 /**\n * The hold rule: what is held at `point` after `state` (null: nothing held yet). Pure: a host with no intent steps it\n * itself. On the base basis it never changes to a place of a pane drawn as a strip at the lift and in the frame drawn\n * for `state`, unless `state` is already a place of that pane; there it stays `state`.\n */\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, the lift basis's mark, and the rail under the pointer. */\n read(frame: TilingHitFrame<TilingHitTarget<K>>, point: Point): TilingHitRead<K>;\n /**\n * Under a fold, with nothing held: the rail of the frame drawn then (the basis's layout) whose box holds `point`, and\n * the pane painted there at the drag's `railOffset`, read anew at every call; null off every rail. Pure. During a drag\n * the strip under the pointer is `read(...).folded`, read from the frame drawn for the hold.\n */\n foldedAt(point: Point): TilingFolded<K> | null;\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 /** The host's offset of each rail of the frame drawn (`TilingDragOptions.railOffset`). */\n readonly railOffset?: RailOffset<K>;\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 // Under a fold, the panes the base folds: one the lift draws open is still a target there, every place refused `folded`.\n const baseFolded = new Set(base.folds.flatMap((f) => f.panes));\n // The rails of a frame: a box takes no drop, wherever its segments are painted. The host's offsets are asked with the\n // folds of the frame drawn, at every call, never kept.\n const offsets: RailOffset<K> | undefined = ctx.railOffset;\n /** Whether `p` lies in a rail box of `frame` (its edges included). */\n const onRailOf = (frame: TilingLaidOut<T, K>, p: Point): boolean => frame.folds.some((f, i) => f.railOf === i && inside(f.rail, p));\n /** The basis's rails: what the zone map refuses, with nothing held. */\n const onRail = (p: Point): boolean => onRailOf(laid, p);\n /** The rail of `frame` at `p` and the pane painted there, at the host's offsets; null off its rails. */\n const foldedIn = (frame: TilingLaidOut<T, K>, p: Point): TilingFolded<K> | null => (onRailOf(frame, p) ? railAt(frame, p, offsets) : null);\n const foldedAt = (p: Point): TilingFolded<K> | null => foldedIn(laid, p);\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\n * member; on the lift, a pane the base folds is itself too (its places are refused `folded`, so a host can show it).\n */\n const atOf = (pane: K): K | null => {\n if (base.layout.has(pane) || baseFolded.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) || baseFolded.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 subject folded at the lift (carried in) opens on any drop, so no place is home for it, however alike.\n const carriedIn = lift.spines.has(subjectDrawn);\n /** A live place whose release has the lift's arrangement: it is home (never for a subject folded at the lift). */\n const homeLike = (p: Place<K>): boolean => {\n if (p === homePlace) return true;\n if (carriedIn) return false;\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 // A rail takes no drop, its edges included (where an open pane's edge meets it).\n if (onRail(p)) return { place: null, refused: 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 /**\n * The frame drawn for `state`: the lift on the lift basis; on the base basis the base with nothing held, the lift at\n * home, `after(held)` for a place.\n */\n const frameOf = (state: TilingHold | null): TilingLaidOut<T, K> => {\n if (basis === \"lift\") return lift;\n if (state === null) return base;\n if (state.place === \"home\") return lift;\n const place = byId.get(state.place);\n return place ? after(place.held) : base;\n };\n /** The pane a place names (beside it, a swap with it, a join to it); null for home. */\n const paneOf = (place: Place<K>): K | null => (place.held.kind === \"home\" ? null : place.held.at);\n /**\n * A pane you see folded takes no drop: on the base basis, whether the hold from `state` may not change to `place`\n * because the pane it names is a strip both at the lift and in the frame drawn for `state`, and `state` is not\n * already a place of that pane. A pane open at the lift, or drawn open in that frame, is not refused.\n */\n const seenFolded = (state: TilingHold | null, place: Place<K>): boolean => {\n if (basis !== \"base\") return false;\n const pane = paneOf(place);\n if (pane === null || !lift.spines.has(pane)) return false;\n const held = state === null ? null : byId.get(state.place);\n if (held && paneOf(held) === pane) return false;\n return frameOf(state).spines.has(pane);\n };\n const hold = (state: TilingHold | null, p: Point): TilingHold | null => {\n // A painted strip moves nothing: over a rail of the frame drawn for `state` the frame stays. The lift basis draws the\n // lift whatever is held, and holds nothing there; on the base basis the hold stays, so its frame does.\n if (onRailOf(frameOf(state), p)) return basis === \"lift\" ? null : state;\n // Off the frame's rails, the basis's map: its own rails take no drop.\n if (onRail(p)) return 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 // A pane you see folded takes no drop: the hold stays as it is (its frame with it).\n if (now && seenFolded(state, now)) return state;\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 // The hold the step at the last point started from: its frame is the one the pointer was over.\n let stepFrom: 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 stepFrom = state;\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 // The strip painted under the pointer in the frame it was over; there the hold stayed, whatever target the intent\n // shows (the frame does not move).\n const folded = foldedIn(frameOf(stepFrom), p);\n const kept = folded !== null && basis === \"base\";\n const shown = place && place !== homePlace && (kept || (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 || folded ? null : (rawAt(p).refused?.held ?? null);\n return { held, refused, mark: basis === \"lift\" && shown ? markOf(shown) : null, folded };\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 foldedAt,\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, and the host's\n * `fold`). Under a fold every layout of the drag is folded with its own order (`TilingLaidOut.order`), so the drag hits\n * and judges the rects the host draws.\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 type { SplitFoldGeometry } from \"./fold\";\nimport { createTilingHit, type TilingBasis, type TilingHit, type TilingHitOptions } from \"./hit\";\nimport type { RailOffset } from \"./painted\";\nimport { layoutSplitTree, withOrder, type FoldingSplitOptions } from \"./tree-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/**\n * What `tilingDrag` reads: the adapter, the stage, and the layout options (`SplitOptions` plus `min`, the least pane\n * width and height a drop keeps, and `fold`, as `layoutSplitTree` takes it). `fold.order` is the lift's order: the\n * drag derives the base's and each change's from it.\n */\nexport interface TilingDragOptions<T, K> extends DropOptions<K>, FoldingSplitOptions<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 * Under a fold whose rails' content runs past their boxes (`SplitFold.segmentFloor`), how far the host has moved each\n * rail of the frame it draws (`RailOffset`): asked with the folds of the frame drawn for the hold being read (the\n * lift on the lift basis; on the base basis the base with nothing held, the lift at home, `after(held)` for a place),\n * the fold heading the rail and its index in that frame's `folds`. The index is that frame's own, so a host whose\n * frames differ keys each rail by the fold's `id` (the folded split's own `id`); a fold with no `id` has no key that\n * stays the same across frames. Read at every hit read\n * (`hit.read`, `hit.foldedAt`), never kept: an offset change, and every change of the frame drawn, is a reason to read\n * again. Pass the hold whose frame is painted: a read between a hold change and its paint asks for rails not drawn\n * yet. Not clamped; a value that is not a finite number reads 0. Default: 0 everywhere.\n */\n readonly railOffset?: RailOffset<K>;\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) or when the lift folds the\n * subject (its spine segment is no gap: the pointer over it reads the spine).\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)`. Under a fold, on the base basis, a pane you see folded takes no\n * drop: the hold does not change to a place of a pane drawn as a strip at the lift and in the frame drawn for the\n * hold, unless it already holds a place of that pane.\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/** Every pane a layout folds: its folds' panes (on a spine, or showing nothing). */\nconst foldedOf = <K>(folds: readonly SplitFoldGeometry<K>[]): Set<K> => new Set(folds.flatMap((f) => f.panes));\n\n/** The keys of `lists`, in turn, each once. */\nfunction keyed<K>(lists: readonly (readonly K[])[]): K[] {\n const out = new Set<K>();\n for (const list of lists) for (const k of list) out.add(k);\n return [...out];\n}\n\n/** The order \"the panes `laid` draws open, in its order (then any its order does not name), then the rest of its order\". */\nconst openFirst = <T, K>(laid: TilingLaidOut<T, K>): K[] => keyed([laid.order.filter((k) => laid.layout.has(k)), [...laid.layout.keys()], laid.order]);\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 whether `at` is drawn open there) and on the change's own layout\n * (fit), never on another tree.\n * - **Under a fold** (`options.fold`) every layout is folded with its own order: the lift with the host's, the base\n * with the panes open at the lift first (a torn tab's stack mates in its place), each change with the subject first,\n * then the panes open at the lift. A pane\n * the base folds is refused `folded`; there is no room rule (the one verdict on room is `fit` on the change's\n * layout, where the subject must be drawn open and `at` may fold). The subject may be folded at the lift (a pane\n * carried in): its lift rect is then its spine segment and `home` is null.\n *\n * Throws when the subject is not in `tree` (neither drawn, open or on a spine, nor a member of a drawn stack): a drag\n * 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, order: readonly K[]): TilingLaidOut<T, K> => {\n const { panes, splits, spines, folds } = layoutSplitTree(ops.split(t), area, withOrder(options, order));\n return { tree: t, layout: panes, splits, spines, folds, order: options.fold ? order : [] };\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, options.fold?.order ?? []);\n const liftKey = drawnAs(tree, subjectKey);\n // Folded at the lift (a pane carried in, held as a spine), the subject's lift rect is its spine segment.\n const liftRect = lift.layout.get(liftKey) ?? lift.spines.get(liftKey);\n if (!liftRect) {\n const what = subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`;\n const drawn = options.fold ? \"drawn (open or on a spine)\" : \"drawn\";\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 // A tab torn out of a stack leaves its mates in its slot: they take its place in the order too, so the slot folds or\n // stays open as it did at the lift.\n const mates = subject.kind === \"pane\" ? (stackOf(tree, subjectKey)?.members ?? []).filter((m) => m !== subjectKey) : [];\n const liftOrder = openFirst(lift);\n const baseOrder: readonly K[] = keyed([liftOrder.flatMap((k) => (k === liftKey ? [k, ...mates] : [k])), mates]);\n const base = lay(ops.release(tree, subject), baseOrder);\n const takesPane = panesOf(ops.split(base.tree)).length < panesOf(ops.split(tree)).length;\n const home = takesPane && lift.layout.has(liftKey) ? { ...liftRect } : null;\n const liftFolded = foldedOf(lift.folds);\n const baseFolded = foldedOf(base.folds);\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 /** Under a fold, the panes `laid` opens and closes against the lift. */\n const foldChangesIn = (laid: TilingLaidOut<T, K>): { readonly opened: readonly K[]; readonly closed: readonly K[] } => {\n if (!options.fold) return { opened: [], closed: [] };\n const folded = foldedOf(laid.folds);\n return { opened: [...laid.layout.keys()].filter((k) => liftFolded.has(k)), closed: [...lift.layout.keys()].filter((k) => folded.has(k)) };\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 baseFolded.has(at) ? { code: \"folded\" } : { 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: [], opened: [], closed: [] });\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: [], opened: [], closed: [] };\n // Under a fold the base's rects are not the change's: room is judged by `fit` alone, on the change's own layout.\n const before = refusalBefore(held) ?? (held.kind === \"beside\" && !options.fold ? 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 changedTree = normalize(changed);\n const own = drawnAs(changedTree, subjectKey);\n // Open first: the subject, then the panes open at the lift, then the rest.\n const candidateOrder = keyed([[own], baseOrder]);\n const laid = lay(changedTree, candidateOrder);\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 // under a fold the subject must be drawn open, and `at` may fold (then it is not judged).\n // `side` only words `dropFits`' reason, which is not read here.\n const partner = drawnAs(laid.tree, held.at);\n const fits = dropFits(laid.layout, own, partner, area, {\n min: options.min,\n side: held.kind === \"beside\" ? held.side : \"left\",\n ...(options.fold ? { folded: foldedOf(laid.folds) } : {}),\n });\n if (!fits.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), ...foldChangesIn(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<K, TilingAfter<T, K>>()));\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 } : {}), ...(options.railOffset ? { railOffset: options.railOffset } : {}), after, lay: (t: T) => lay(t, baseOrder), 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, withOrder } from \"./tree-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 and the lift draws the subject open, else null (a subject on a spine has none). */\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 /**\n * `after(held).layout` is `after(held).tree` laid out (under a fold with `after(held).order`, its spines and folds\n * too); the landing is the subject's rect there, drawn open (home's, for a subject on a spine at the lift: its\n * segment); a refused place is the lift.\n */\n \"one-layout\",\n /** Under a fold, every pane the base folds is refused `folded` for every kind of place (a swap with the stack a tab is torn from stays `self`). */\n \"folded-refused\",\n /**\n * A swap puts the partner in the subject's lift rect and the subject in the partner's, and the others keep theirs.\n * Not checked under per-child layout callbacks (`fixed`, `fixedAcross`, `floor`), which may move the ratios, nor\n * under a fold (a swap can change which pane comes first, and so which side of a fold shows).\n */\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\n/** A held place in words, for a failure. @internal */\nexport const showHeld = (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}` : \"\"}`;\nconst show = showHeld;\n\n/**\n * Whether the lift draws `subject` (open, or on a spine): under a fold a pane that shows nothing (weight 0) and is\n * folded is drawn nowhere, so it cannot be lifted. @internal\n */\nexport function liftable<T, K>(tree: T, subject: TilingSubject<K>, options: TilingDragOptions<T, K>): boolean {\n if (!options.fold) return true;\n const { ops } = options;\n const key = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n const drawn = ops.stackOf?.(tree, key)?.active ?? key;\n const lift = layoutSplitTree(ops.split(tree), options.area, options);\n return lift.panes.has(drawn) || lift.spines.has(drawn);\n}\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, order: readonly K[]) => layoutSplitTree(ops.split(t), area, withOrder(options, order));\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 if (!liftable(tree, subject, options)) continue;\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 // A subject on a spine at the lift leaves no gap: its segment is no home.\n const gap = takes && subjectLift !== undefined;\n check(\"home-is-the-gap\", gap ? near(drag.home, subjectLift, EPS) : drag.home === null, () => `home ${JSON.stringify(drag.home)}, the release ${takes ? \"takes\" : \"takes no\"} drawn pane${subjectLift ? \"\" : \" (the subject is folded at the lift)\"}`);\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 // Under a fold, every pane the base folds, for every kind of place: refused `folded`.\n for (const at of new Set(drag.base.folds.flatMap((f) => f.panes))) {\n const kinds: TilingHeld<K>[] = [{ kind: \"swap\", at }, ...PANE_SIDES.map((side): TilingHeld<K> => ({ kind: \"beside\", at, side })), ...(ops.join ? [{ kind: \"join\", at } as const] : [])];\n for (const h of kinds) {\n const code = drag.after(h).refusal?.code;\n // A swap with the stack a tab is torn from is the subject's own place: `self`, folded or not.\n const own = h.kind === \"swap\" && subject.kind === \"pane\" && !!ops.stackOf && ops.stackOf(tree, subject.pane)?.id === ops.stackOf(tree, at)?.id && !!ops.stackOf(tree, at);\n check(\"folded-refused\", code === \"folded\" || (own && code === \"self\"), () => `${show(h)}: the base folds ${String(at)}, refused ${code ?? \"nothing\"}`);\n }\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 const again = lay(a.tree, a.order);\n // Home of a subject on a spine at the lift lands where it was: its segment.\n const lands = near(a.landing, h.kind === \"home\" ? (a.layout.get(own) ?? a.spines.get(own)) : a.layout.get(own), EPS);\n check(\n \"one-layout\",\n sameData(a.layout, again.panes) && sameData(a.spines, again.spines) && sameData(a.folds, again.folds) && lands,\n () => `${show(h)}: the layout or the landing is not after().tree's, laid out with after().order`,\n );\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. Under a fold a\n // swap can change which pane comes first, and so which side of a fold shows: not checked either.\n if (h.kind === \"swap\" && !callbacks && !options.fold) {\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, withOrder } from \"./tree-layout\";\nimport { paintedSpines } from \"./painted\";\nimport { PANE_REGION_DEFAULTS } from \"./regions\";\nimport type { Split } from \"./split\";\nimport { liftable, propertyTally, showHeld, 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, unless the map's place there names a pane drawn as a strip at\n * the lift and in the frame drawn for the place (a pane you see folded takes no drop).\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 (never for a subject folded at the lift: any drop opens it). */\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 /**\n * Under a fold, a painted strip is read as painted and moves nothing, in every frame: for each hold and the frame drawn\n * for it (the lift on the lift basis; on the base basis the base with nothing held, the lift at home, `after(held)`),\n * every point of that frame's rail boxes (edges included) reads `folded` with that rail and the pane painted there\n * (`paintedSpines` at the drag's rail offsets), null in a gap; the frame stays (the lift basis holds nothing, the base\n * basis keeps the hold), a second step changes nothing, a release gives what the frame shows, nothing is refused, and\n * with nothing held there is no place.\n */\n \"spine-no-place\",\n /**\n * Under a fold, on the lift basis, a pane the lift draws open and the base folds (the named case) is a target, and\n * every place on it is refused `folded`: the pointer over it holds nothing and names the refused place.\n */\n \"named-case-refused\",\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 => (h === null ? \"nothing\" : showHeld(h));\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 if (!liftable(tree, subject, options)) continue;\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 // Under a fold: the panes the base folds (a target on the lift basis where the lift draws one open, every place\n // refused), and the basis's rail boxes, which take no drop.\n const baseFolded = new Set(drag.base.folds.flatMap((f) => f.panes));\n const rails = laid.folds.map((f, i) => ({ f, i })).filter(({ f, i }) => f.railOf === i);\n const railOf = (p: Point): number | null => rails.find(({ f }) => inside(f.rail, p))?.i ?? null;\n const atOf = (pane: K): K | null => {\n if (drag.base.layout.has(pane) || baseFolded.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) || baseFolded.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, withOrder(options, laid.order)).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 subject folded at the lift opens on any drop: no place gives the lift back.\n const carriedIn = drag.lift.spines.has(subjectDrawn);\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 if (carriedIn) return false;\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 (railOf(p) !== null) return { raw: null, refused: null, box: null, pane: null, tie: false };\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 // Under a fold the layout may fold again around the landing, and a new split's fold floors move the landing's\n // edge without opening or folding anything (counted, not failed).\n if (others || options.fixed || options.fixedAcross || hasMaster || options.fold) {\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)) === 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 || !inside(e.box, z)) continue;\n const ang = rnd() * Math.PI * 2;\n const len = Math.sqrt(rnd()) * 0.9;\n const p = { x: z.x + Math.cos(ang) * ex * len, y: z.y + Math.sin(ang) * ey * len };\n // A rail holds nothing (spine-no-place): not a point of a place's measure.\n if (railOf(p) === null) path.push(p);\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)) && railOf(p) === null) 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 a strip of the frame drawn for the place, the place stays by the strip rule (spine-no-place), not a measure.\n const shownFrame = basis === \"lift\" ? drag.lift : drag.after(hit.heldOf(taken.place)!);\n if (shownFrame.folds.some((f, i) => f.railOf === i && inside(f.rail, p))) continue;\n // A pane you see folded takes no drop: where the map's place names a pane drawn as a strip at the lift and in that\n // frame, the place stays by that rule, not a measure.\n const mapHeld = hit.placeAt(p) === null ? null : hit.heldOf(hit.placeAt(p)!);\n const takenHeld = hit.heldOf(taken.place);\n if (basis === \"base\" && mapHeld && mapHeld.kind !== \"home\" && drag.lift.spines.has(mapHeld.at) && shownFrame.spines.has(mapHeld.at) && !(takenHeld && takenHeld.kind !== \"home\" && takenHeld.at === mapHeld.at)) 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 // ---- spine-no-place: a painted strip is read as painted and moves nothing, in every frame. For each hold S (nothing,\n // home, and places held at sample points) and the frame F drawn for it (`frameFor`), every point of F's rail boxes,\n // corners and edges included: the read names F's rail and the pane `paintedSpines(F, railOffset)` paints there (null\n // in a gap); the hold after it draws F again (the lift basis holds nothing, its frame is the lift whatever is held;\n // the base basis keeps S), and a second step at the point changes nothing; a release gives what F shows (the lift\n // tree from nothing or home, `after(S)` from a place); nothing is refused there; with nothing held there is no place.\n const frameFor = (s: TilingHold | null) =>\n basis === \"lift\" ? drag.lift : s === null ? drag.base : s.place === \"home\" ? drag.lift : drag.after(hit.heldOf(s.place)!);\n const holdStates: (TilingHold | null)[] = [null];\n if (home) holdStates.push({ place: \"home\", from: { x: home.x + home.width / 2, y: home.y + home.height / 2 } });\n const heldPlaces = new Set<string>();\n for (const q of samples) {\n if (heldPlaces.size >= 6) break;\n const s = hit.hold(null, q);\n if (s && s.place !== \"home\" && !heldPlaces.has(s.place)) {\n heldPlaces.add(s.place);\n holdStates.push(s);\n }\n }\n for (const s of holdStates) {\n const F = frameFor(s);\n const railsOfF = F.folds.map((f, i) => ({ f, i })).filter(({ f, i }) => f.railOf === i);\n if (railsOfF.length === 0) continue;\n const painted = paintedSpines(F, options.railOffset);\n // The stateful hit, brought to S: nothing held, then S's own point.\n const enter = (): boolean => {\n frame(FAR);\n if (s === null) return true;\n const r = frame(s.from);\n return s.place === \"home\" ? r.held?.kind === \"home\" : r.held !== null && show(r.held) === show(hit.heldOf(s.place));\n };\n const keeps = basis === \"lift\" ? null : s;\n const wantHeld = keeps === null ? null : keeps.place === \"home\" ? HOME : hit.heldOf(keeps.place);\n for (const { f, i } of railsOfF) {\n const r = f.rail;\n const points: Point[] = [\n { x: r.x, y: r.y },\n { x: r.x + r.width, y: r.y + r.height },\n { x: r.x + r.width / 2, y: r.y },\n { x: r.x, y: r.y + r.height / 2 },\n ];\n for (let k = 0; k < 16; k++) points.push(randomPoint(r));\n for (const p of points) {\n const want = [...painted].find(([pane, q]) => F.folds.some((g) => g.railOf === i && g.panes.includes(pane)) && inside(q, p))?.[0] ?? null;\n const step = hit.hold(s, p);\n const again = hit.hold(step, p);\n const where = `rail ${i} of the frame for ${s ? s.place : \"nothing\"} at ${p.x.toFixed(1)},${p.y.toFixed(1)}`;\n check(\n \"spine-no-place\",\n sameHold(step, keeps) && sameHold(again, keeps) && (s !== null || hit.placeAt(p) === null),\n () => `${where}: the hold went to ${holdName(step)}, then ${holdName(again)}; it stays ${holdName(keeps)} (place with nothing held: ${hit.placeAt(p)})`,\n );\n if (!enter()) continue;\n const read = frame(p);\n const second = frame(p);\n check(\n \"spine-no-place\",\n show(read.held) === show(wantHeld) && read.refused === null && hit.drawn(read) === F && JSON.stringify(second) === JSON.stringify(read),\n () => `${where}: held ${show(read.held)} (stays ${show(wantHeld)}), refused ${show(read.refused)}, the frame ${hit.drawn(read) === F ? \"stays\" : \"moved\"}`,\n );\n const rel = hit.release(read);\n check(\n \"spine-no-place\",\n wantHeld === null || wantHeld.kind === \"home\" ? rel.tree === drag.lift.tree : rel === drag.after(wantHeld),\n () => `${where}: a release commits ${show(rel.held)}, the frame shows ${show(wantHeld)}`,\n );\n const at = s === null ? hit.foldedAt(p) : read.folded;\n check(\n \"spine-no-place\",\n read.folded?.rail === i && read.folded.pane === want && at?.rail === i && at.pane === want,\n () => `${where}: reads ${JSON.stringify(read.folded)}, foldedAt ${JSON.stringify(at)}, painted ${String(want)}`,\n );\n }\n }\n }\n // ---- named-case-refused: on the lift, a pane the lift draws open and the base folds is a target, every place on\n // it refused `folded`; over it nothing is held and the refused place is named.\n if (basis === \"lift\") {\n for (const [pane, r] of drag.lift.layout) {\n // The pane, or what the base draws in its slot (a torn stack's remnant): folded there, it is the named case.\n const at = atOf(pane);\n if (at === null || !baseFolded.has(at)) continue;\n const target = hit.targets.find((t) => !t.part && !t.home && t.pane === pane);\n // A swap with the stack a tab is torn from is the subject's own place (`self`), folded or not.\n const torn = !!stackOf(drag.lift.tree, at) && stackOf(drag.lift.tree, at)?.id === stackOf(drag.lift.tree, subjectKey)?.id;\n const places: TilingHeld<K>[] = [...(torn ? [] : [{ kind: \"swap\", at } as const]), ...([\"top\", \"right\", \"bottom\", \"left\"] as const).map((side): TilingHeld<K> => ({ kind: \"beside\", at, side }))];\n const codes = places.map((h) => drag.after(h).refusal?.code);\n const c = { x: r.x + r.width / 2, y: r.y + r.height / 2 };\n const read = fresh(c);\n check(\n \"named-case-refused\",\n target?.at === at && codes.every((code) => code === \"folded\") && hit.placeAt(c) === null && read.held === null && read.refused !== null,\n () => `${String(pane)}, open at the lift and folded in the base as ${String(at)}: target ${target ? String(target.at) : \"none\"}, refusals ${codes.join(\",\")}, place ${hit.placeAt(c)}, refused ${show(read.refused)}`,\n );\n }\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] as (typeof zonesBefore)[number];\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 no `floor`, `fixed` or `fixedAcross`, and no gap, so the choice follows the tree's shape and its\n * ratios. px floors cannot fit a unit square: every split would be squeezed by its floors, and a px fixed length would\n * take the whole room. 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,QAAM,IAAI,MAAM;AAChB,QAAM,QAAQ,OAAO,IAAI;AACzB,MAAI,UAAU;AACZ,U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AO;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,UAAMU,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":["r","nA","nB","length","px","cross","px","FIT","px","of","cross","within","NO_RAILS","px","usable","otherAxis","isPane","sideEdges","cross","node","laid","unit","at","has","cross","slot","px","near","state","slot","px","lay","stack","x","lay","inside","sameRect","show","check","HOME","n","s","has","clamp","held","probes","places","overlap"]}
1
+ {"version":3,"sources":["../src/tiling/order.ts","../src/tiling/split.ts","../src/tiling/split-decision.ts","../src/tiling/layout.ts","../src/tiling/drop.ts","../src/tiling/fold-steps.ts","../src/tiling/fold-plan.ts","../src/tiling/tree-layout.ts","../src/tiling/painted.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 * One split's decision: given its extent, its gutter, its stored ratio and what each side needs, how long each side\n * is along the split, and the ratio in effect. `layoutSplit` makes it for every split; a host that draws or stores a\n * split itself makes the same one. See docs/placement.md, Entry: tiling.\n */\n\n/** A px number: finite and above 0, else 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/** Where the net is on, each side needs at least this share of the extent, less half the gutter. */\nconst NET_SHARE = 0.05;\n\n/**\n * The needs fit within this share of the extent: a parent lands a nested split at exactly its need, and float error\n * may tip the sum over it by an ulp. Both sides of every boundary give the same lengths within this slack.\n */\nconst FIT = 1e-9;\n\n/**\n * A side's fixed length along its split. A **kept** length (`keep`) is exact: it is cut only by its box, the extent\n * less the gutter, never by its sibling's need, it decides its split over a fixed length that is not kept, and it is\n * its pane's need. A fixed length that is not kept is honoured between the two needs: no shorter than its own side's\n * need, no longer than what its sibling's need leaves (the extent less the gutter and that need). A host that wants a\n * length under a pane's floor honoured reports the pane's need as at most the length.\n */\nexport interface FixedLength {\n readonly length: number;\n readonly keep?: boolean;\n}\n\n/** Which step of the ladder decided a split. */\nexport type SplitStep = \"no-room\" | \"kept\" | \"fixed\" | \"ratio\" | \"squeezed\";\n\n/** One side of a split as its decision reads it: the layout's own inputs. */\nexport interface SplitSide {\n /**\n * The least length the side lands at where its split fits: a layout's own number is `SplitGeometry.needs` (the\n * side's floor as this split measures it, its kept length, or a nested split's need). Leave it out on both sides of\n * a split with no floors. `splitNeed` is a tree's need laid out alone, which is not a side's. A need that is not\n * finite and above 0 counts as 0, but a side that has one (NaN included) makes the split one with floors: the gap\n * rule no longer applies.\n */\n readonly need?: number;\n /** False where the side's floor said `net: false`; either side's false takes the net off the split. */\n readonly net?: boolean;\n /** The side's fixed length along the split. */\n readonly fixed?: FixedLength;\n}\n\n/** What one split does: each side's length along it, the ratio in effect, the step that decided, whether it has a divider. */\nexport interface SplitDecision {\n readonly a: number;\n readonly b: number;\n /** The ratio in effect: the middle of the gutter lies at the split's start plus the extent times this. */\n readonly ratio: number;\n readonly step: SplitStep;\n /** True where no fixed length decides the split: its gutter is a divider. */\n readonly divider: boolean;\n}\n\nconst usableFixed = (f: FixedLength | undefined): FixedLength | undefined => (f && Number.isFinite(f.length) && f.length > 0 ? f : undefined);\n\n/**\n * The least extent at which a split that a ratio decides fits its two needs: both needs and the gutter; where the net\n * is on and that extent's 5 % (less half the gutter) is above the smaller need, the extent at which the net's length\n * and the larger need fit, `(larger + g/2) / 0.95`. At that extent `decideSplit` lands both sides at their needs (the\n * smaller one at the net's length). Continuous where the two meet. For the needs of a split tree, not exported.\n */\nexport function ratioFitExtent(needA: number, needB: number, gutter: number, net: boolean): number {\n const g = px(gutter);\n const lower = Math.min(px(needA), px(needB));\n const upper = Math.max(px(needA), px(needB));\n const plain = lower + upper + g;\n if (!net || NET_SHARE * plain - g / 2 <= lower) return plain;\n // The smaller need is under the net: E − g = (NET_SHARE·E − g/2) + upper. The larger is then never under it.\n return (upper + g / 2) / (1 - NET_SHARE);\n}\n\n/**\n * One split's decision, the ladder, tested in this order (E the extent, g the gutter, room = E − g):\n *\n * 0. **No floors and no fixed length** (no side has a `need` or a usable `fixed`): the gap rule. The middle of the\n * gutter sits at `E × ratio`; a side too short for half the gutter is 0, and a 0-long second side may start up to\n * half a gutter past the end.\n * 1. **No room** (E under g): both sides are 0, and the ratio is 0.5.\n * 2. **Kept**: a kept length decides over one that is not kept (the first kept side, else the second). It takes\n * `min(length, room)`, whatever its sibling needs; the other side takes the rest. Two kept lengths take\n * `min(first, room)` and `min(second, room − first)`, and what is left stays empty.\n * 3. **Fixed**: else the first side with a usable fixed length (above 0, finite; an unusable first lets the second\n * decide) takes its length held between the two needs, `min(max(length, own need), room − need of its sibling)`;\n * the sibling takes the rest. Where the two needs don't fit the room, both are squeezed in proportion to them\n * (step 5), whatever the length. The stored ratio is never read.\n * 4. **Ratio**: else the ratio is clamped so each side lands at its need: within\n * `[(needA + g/2) / E, 1 − (needB + g/2) / E]`. Where the net is on (neither side's `net` is false), each need is\n * first raised to `0.05 × E − g/2`, which is the 0.05..0.95 bound while the needs fit.\n * 5. **Squeezed**: where the needs (raised by the net, in step 4 only) and the gutter don't fit the extent, both sides\n * share the room in proportion to their needs.\n *\n * Every step is continuous in the extent: changing it by d changes no side by more than d. At `E = g` both sides are\n * 0; the step is the ratio, or the squeeze where a side needs more than 0.\n */\nexport function decideSplit(extent: number, gutter: number, ratio: number | undefined, a: SplitSide, b: SplitSide): SplitDecision {\n const g = px(gutter);\n const E = Number.isFinite(extent) ? extent : 0;\n const fa = usableFixed(a.fixed);\n const fb = usableFixed(b.fixed);\n const floors = a.need !== undefined || b.need !== undefined;\n const lead = fa?.keep ? fa : fb?.keep ? fb : (fa ?? fb);\n if (!lead && !floors) {\n // The gap rule, exactly as it always was, on the extent as given (an infinite or NaN one included).\n const r = unit(ratio);\n return { a: Math.max(0, extent * r - g / 2), b: Math.max(0, extent * (1 - r) - g / 2), ratio: r, step: \"ratio\", divider: true };\n }\n if (E < g * (1 - FIT)) return { a: 0, b: 0, ratio: 0.5, step: \"no-room\", divider: !lead };\n const needA = px(a.need);\n const needB = px(b.need);\n if (!(E > 0)) {\n const step: SplitStep = lead ? (lead.keep ? \"kept\" : \"fixed\") : needA + needB > 0 ? \"squeezed\" : \"ratio\";\n return { a: 0, b: 0, ratio: 0.5, step, divider: !lead };\n }\n const room = Math.max(0, E - g);\n const at = (lengthA: number): number => (lengthA + g / 2) / E;\n const sides = (lengthA: number, step: SplitStep, divider: boolean): SplitDecision => {\n const la = Math.min(room, Math.max(0, lengthA));\n return { a: la, b: Math.max(0, room - la), ratio: at(la), step, divider };\n };\n const squeeze = (nA: number, nB: number, divider: boolean): SplitDecision => sides((room * nA) / (nA + nB), \"squeezed\", divider);\n if (lead) {\n const first = lead === fa;\n if (fa?.keep && fb?.keep) {\n const la = Math.min(fa.length, room);\n return { a: la, b: Math.min(fb.length, room - la), ratio: at(la), step: \"kept\", divider: false };\n }\n if (lead.keep) {\n const length = Math.min(lead.length, room);\n return sides(first ? length : room - length, \"kept\", false);\n }\n const own = first ? needA : needB;\n const other = first ? needB : needA;\n if (own + other > room + FIT * E) return first ? squeeze(own, other, false) : squeeze(other, own, false);\n const length = Math.min(Math.max(lead.length, own), room - other);\n return sides(first ? length : room - length, \"fixed\", false);\n }\n const net = a.net !== false && b.net !== false ? Math.max(0, NET_SHARE * E - g / 2) : 0;\n const nA = Math.max(needA, net);\n const nB = Math.max(needB, net);\n if (nA + nB > room + FIT * E) return squeeze(nA, nB, true);\n const lo = (nA + g / 2) / E;\n const hi = Math.max(lo, 1 - (nB + g / 2) / E);\n const r = Math.min(Math.max(unit(ratio), lo), hi);\n return { a: Math.max(0, E * r - g / 2), b: Math.max(0, E * (1 - r) - g / 2), ratio: r, step: \"ratio\", divider: true };\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 type { SplitFoldGeometry } from \"./fold\";\nimport { masterCount, masterRatio, masterStack, type MasterOptions, type TileOptions } from \"./order\";\nimport { panesOf, type Split } from \"./split\";\nimport { decideSplit, ratioFitExtent, type FixedLength, type SplitSide, type SplitStep } from \"./split-decision\";\n\nexport type { FixedLength } from \"./split-decision\";\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 usable length: finite and above 0. */\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\n\n/**\n * A node's own least length along a split. `net` (default true): where neither side of a split says false, each side\n * needs at least 5 % of the extent less half the gutter where a ratio decides the split, which is the 0.05..0.95 bound\n * while the needs fit.\n */\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 split is decided by `decideSplit` from its two sides' needs\n * (`splitNeed` and `SplitGeometry.needs`), fixed lengths and nets; see docs/placement.md, Entry: tiling.\n *\n * - `fixed(child, axis)`: a direct child's fixed length along its split, asked once per child and axis. A kept\n * length (`keep`) is exact: cut only by its box (the extent less the gutter), it decides over a length that is not\n * kept, and it is its pane's need; two kept lengths keep their own and the room left stays empty, the second cut at\n * the split's end. Else the first side with a usable length (above 0, finite; an unusable first lets the second\n * decide) takes it held between the two needs: no shorter than its own need, no longer than the extent less the\n * gutter and its sibling's need; where the needs don't fit, the split is squeezed by them. A pane's need is the host's\n * floor, so a host that wants a length under that floor honoured gives the pane a floor no larger than the length; a\n * split node's need is its panes' need. A split a fixed length decides has no divider; its stored\n * ratio is never read.\n * - `fixedAcross(child, axis)`: the child's fixed length across the split; the child takes it, when positive, finite\n * and shorter than the cross extent, from the start of the cross axis instead of the whole cross extent; a longer\n * one takes the cross extent. It never enters a need.\n * - `floor(child, axis, split)`: a node's own least length along `axis`, asked at most once per node, axis and\n * measuring split in a layout. `split` is the nearest split above `child` that runs along `axis`, which may be its\n * parent or a split above a split across; where no split above a node runs along `axis`, it is not asked and its\n * own floor is 0. A side's need is its own floor, or its kept length, or for a nested split with an axis the larger\n * of its own floor and its sides' needs (along: both and the gutter, and where a ratio decides it with its net on,\n * room for the net's 5 % as well; across: the larger). Each side lands at its\n * need where the split's needs fit its extent; where they don't, both sides are squeezed in proportion. A master\n * split and a split with no axis report their own floor only. With no `floor` there are no needs, and a split with\n * no fixed length keeps the gap rule (`layoutSplit`). `giveWay` is the other policy of the same minimum: it floats\n * the newest pane instead of squeezing the ratio, and a host 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 /** The step of `decideSplit` that decided the split; `\"ratio\"` for a master split. */\n readonly step: SplitStep;\n /**\n * The two sides' needs as this split read them (each side's floor as it measures it, its kept length, or a nested\n * split's need): what a host passes to `decideSplit` for this split. Null without `floor`, and for a master split.\n */\n readonly needs: readonly [number, number] | null;\n}\n\n/**\n * A tree laid out: every open pane's rect, the geometry of each split that has an `id` and is drawn with its two sides,\n * and, under a fold (`layoutSplitTree`'s `fold`), each folded pane's segment of its spine and the folds, outermost\n * first. Without a fold, `spines` and `folds` are empty. A segment in `spines` is a content position, placed from its\n * rail box's top or left: it is where the segment is painted only where the rail's content fits its box\n * (`SplitFoldGeometry.railContentLength`) and the host's offset is 0; `paintedSpines` gives where each is painted at a\n * rail offset.\n */\nexport interface SplitLayout<K> {\n readonly panes: Map<K, Rect>;\n readonly splits: Map<string, SplitGeometry>;\n readonly spines: Map<K, Rect>;\n readonly folds: readonly SplitFoldGeometry<K>[];\n}\n\n/** Throws where a split tree's fold reaches a function that lays the tree out without it. */\nexport function refuseFold(options: object, name: string): void {\n if (\"fold\" in options) throw new Error(`${name} does not fold a split tree: use layoutSplitTree`);\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 /** Where each decided split's ratio in effect goes, by node; null unless asked (`laySplitTree`). */\n readonly ratios: Map<Split<K>, number> | null;\n /** The host's answers and the needs, for this layout. */\n readonly needs: Needs<K>;\n}\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** A map from node to a map of keys, made on first use. */\nconst slot = <K, V>(maps: Map<Split<K>, Map<string, V>>, node: Split<K>): Map<string, V> => {\n let m = maps.get(node);\n if (!m) maps.set(node, (m = new Map<string, V>()));\n return m;\n};\n\n/**\n * The needs of one layout, and the host's answers they read: `floor` is asked at most once per node, axis and\n * measuring split, `fixed` once per node and axis. A need reads what the layout reads, from where it reads it: a\n * node's own floor as measured by the nearest split above it that runs along the axis (none: 0, not asked), a kept\n * length of a split's direct child along its axis, and a nested split's sides, along it (with its net, where a ratio\n * decides it) or across it. A master split\n * and a split with no axis are not looked into. `fixedAcross` never enters a need.\n */\nclass Needs<K> {\n private readonly options: SplitOptions<K>;\n private readonly gap: number;\n private readonly handle: number;\n private readonly floors = new Map<Split<K>, Map<string, MinLength>>();\n private readonly fixeds = new Map<Split<K>, Map<string, FixedLength | undefined>>();\n private readonly found = new Map<Split<K>, Map<string, number>>();\n private readonly ids = new Map<Split<K>, number>();\n\n constructor(options: SplitOptions<K>, gap: number, handle: number) {\n this.options = options;\n this.gap = gap;\n this.handle = handle;\n }\n\n /** The key of an axis and a measuring split. */\n private key(axis: Axis, split: Split<K> | null): string {\n if (split === null) return axis;\n let id = this.ids.get(split);\n if (id === undefined) this.ids.set(split, (id = this.ids.size));\n return `${axis} ${id}`;\n }\n\n /** A split's gutter: its own gap, else the layout's, plus the handle. */\n gutter(split: Branch<K>): number {\n return (split.gap === undefined ? this.gap : px(split.gap)) + this.handle;\n }\n\n /** The host's floor of `node` along `axis`, as `split` measures it. */\n floor(node: Split<K>, axis: Axis, split: Split<K>): MinLength {\n const m = slot(this.floors, node);\n const k = this.key(axis, split);\n let f = m.get(k);\n if (f === undefined) m.set(k, (f = this.options.floor!(node, axis, split)));\n return f;\n }\n\n /** The host's fixed length of `child` along a split on `axis`. */\n fixed(child: Split<K>, axis: Axis): FixedLength | undefined {\n const m = slot(this.fixeds, child);\n if (!m.has(axis)) m.set(axis, this.options.fixed?.(child, axis));\n return m.get(axis);\n }\n\n /** The need of `child`, a direct child of `split`, which runs along `axis`: its kept length, or its own need. */\n side(child: Split<K>, axis: Axis, split: Split<K>): number {\n const f = this.fixed(child, axis);\n if (f?.keep && usable(f.length)) return f.length;\n return this.of(child, axis, split);\n }\n\n /** The need of `node` along `axis`, measured by `split` (null: no split above it runs along `axis`). */\n of(node: Split<K>, axis: Axis, split: Split<K> | null): number {\n const m = slot(this.found, node);\n const k = this.key(axis, split);\n const known = m.get(k);\n if (known !== undefined) return known;\n const own = split === null ? 0 : px(this.floor(node, axis, split).min);\n let need = own;\n if (!(\"pane\" in node) && !node.master && node.axis !== undefined) {\n need = node.axis === axis ? Math.max(own, this.along(node, axis)) : Math.max(own, this.of(node.a, axis, split), this.of(node.b, axis, split));\n }\n m.set(k, need);\n return need;\n }\n\n /**\n * The need of `split` along its own axis: both sides' needs and its gutter; where a ratio decides it (no usable fixed\n * length on either side) and its net is on, the least extent at which the net's 5 % fits as well.\n */\n private along(split: Branch<K>, axis: Axis): number {\n const a = this.side(split.a, axis, split);\n const b = this.side(split.b, axis, split);\n const led = [split.a, split.b].some((c) => usable(this.fixed(c, axis)?.length));\n const net = !led && this.floor(split.a, axis, split).net !== false && this.floor(split.b, axis, split).net !== false;\n return ratioFitExtent(a, b, this.gutter(split), net);\n }\n}\n\n/**\n * The least length `tree` lands at along `axis`, laid out alone in an area with `options`: where the area is at\n * least this long (allowing 1e-9 of it) along `axis`, no split on the way is squeezed by its needs, the net on or\n * off (a split a ratio decides with its net on needs room for the net's 5 % of its extent too). Except where the host\n * gives a split node its own kept or across length shorter than its need: that length is taken as it is, the splits\n * inside it along that axis are squeezed at any size, and its panes may land under their floors. A fixed length that\n * is not kept is no exception: a split node pinned shorter than its need lands at that need. It reads `floor`\n * and `fixed` as the layout does; no split measures the root, so a pane alone needs 0, and a split's own floor\n * counts only where a split above it measures it. 0 without `floor`. Not a side's need inside a tree: that is\n * `SplitGeometry.needs`, measured by its split. Not `StackFit.need` (what a stack's forms need).\n */\nexport function splitNeed<K>(tree: Split<K> | null, axis: Axis, options: SplitOptions<K> = {}): number {\n refuseFold(options, \"splitNeed\");\n if (!tree || !options.floor) return 0;\n return new Needs(options, px(options.gap), px(options.handle)).of(tree, axis, 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: that is the gap rule, for a split with no floors and no fixed length.\n * `options.floor`, `fixed` and `fixedAcross` (see `SplitOptions`) read the host's minimums and fixed lengths, and each\n * split is then decided by `decideSplit`: with them every pane lies inside the area, at every size (a split under\n * its gutter lays both sides at no size, the second at its end). 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 refuseFold(options, \"layoutSplit\");\n const gap = px(options.gap);\n const handle = px(options.handle);\n const ctx: Ctx<K> = { options, gap, handle, panes: new Map(), splits: null, ratios: null, needs: new Needs(options, gap, handle) };\n lay(tree, area, ctx, false);\n return ctx.panes;\n}\n\n/**\n * The split tree laid out with no fold: `layoutSplit` and the geometry of every split that has an `id` (`layoutSplitTree`\n * without `fold`). `ratios`, when given, takes each decided split's ratio in effect, by node. Internal.\n */\nexport function laySplitTree<K>(\n tree: Split<K> | null,\n area: Rect,\n options: SplitOptions<K>,\n ratios: Map<Split<K>, number> | null = null,\n): { panes: Map<K, Rect>; splits: Map<string, SplitGeometry> } {\n const splits = new Map<string, SplitGeometry>();\n const gap = px(options.gap);\n const handle = px(options.handle);\n const ctx: Ctx<K> = { options, gap, handle, panes: new Map(), splits, ratios, needs: new Needs(options, gap, handle) };\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/** 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, step: \"ratio\", needs: 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 = ctx.needs.gutter(tree);\n const { fixedAcross, floor } = ctx.options;\n // Across the split a child with a fixed length shorter than the cross extent takes it from the start; the others,\n // and a longer one, 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 ? lenA : cross;\n const acrossB = usable(lenB) && lenB < cross ? lenB : cross;\n\n // Each side as the decision reads it: its fixed length, and with floors its need and its net (a kept side has none).\n const sideOf = (child: Split<K>): SplitSide => {\n const fixed = ctx.needs.fixed(child, axis);\n if (!floor) return { fixed };\n const kept = !!fixed?.keep && usable(fixed.length);\n return { fixed, need: ctx.needs.side(child, axis, tree), net: kept || ctx.needs.floor(child, axis, tree).net !== false };\n };\n const a = sideOf(tree.a);\n const b = sideOf(tree.b);\n const d = decideSplit(extent, gutter, tree.ratio, a, b);\n ctx.ratios?.set(tree, d.ratio);\n // The second side starts after the first and the gutter; under the gap rule, half a gutter past the ratio's middle.\n const startB = d.step === \"no-room\" ? origin + Math.max(0, extent) : d.step === \"ratio\" ? origin + extent * d.ratio + gutter / 2 : origin + d.a + gutter;\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 = d.divider ? strip(area, x, origin + extent * d.ratio, gutter) : null;\n const needs: readonly [number, number] | null = floor ? [a.need!, b.need!] : null;\n ctx.splits.set(tree.id, { rect: owned ? area : { ...area }, axis, ratio: d.ratio, divider, step: d.step, needs });\n }\n const lengthA = d.a;\n const lengthB = d.b;\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 { EPS, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\nimport { layoutSplit, refuseFold, 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 refuseFold(options, \"canDropOnPane\");\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. Reads no fold: throws when `options`\n * holds a `fold` key (under a fold the drag has no room rule).\n */\nexport function canSplitPane(target: Rect, side: Side, options: SplitRoomOptions): DropVerdict {\n refuseFold(options, \"canSplitPane\");\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/**\n * What `dropFits` reads: the `min` (as in `DropOptions`), the `side` of `at` the drop is on, for the reason, and under\n * a fold the panes the projected layout folds.\n */\nexport interface DropFitsOptions<K = unknown> {\n readonly min: number;\n readonly side: Side;\n /**\n * The panes the projected layout folds (a folding layout's `folds`, their `panes`): a folded `at` is not judged, as\n * the drop may fold it. `dragged` is judged whatever this holds: it must be drawn open. Default: none.\n */\n readonly folded?: ReadonlySet<K>;\n}\n\n/**\n * The fit rule: in `projected`, the rect of every pane drawn open in the layout the drop makes (the host's own\n * projection of `dropOnPane`'s tree), whether `dragged` and `at` are both there and at least `options.min` wide and\n * high, to within `EPS` (a floor of `min` lands at `min` up to float error); an `at` in `options.folded` is not judged.\n * Fine when `area` has no width or no height (there is nothing to measure). `canDropOnPane`'s last rule. Reads no fold\n * (a folding host passes the folded panes as `folded`): throws when `options` holds a `fold` key.\n */\nexport function dropFits<K>(projected: ReadonlyMap<K, Rect>, dragged: K, at: K, area: Rect, options: DropFitsOptions<K>): DropVerdict {\n refuseFold(options, \"dropFits\");\n if (!(area.width > 0 && area.height > 0)) return { ok: true };\n const min = px(options.min);\n const folded = options.folded;\n const fits = (r: Rect | undefined): boolean => !!r && r.width >= min - EPS && r.height >= min - EPS;\n return fits(projected.get(dragged)) && (fits(projected.get(at)) || folded?.has(at) === true)\n ? { ok: true }\n : { ok: false, reason: `${options.side} rejected: projected footprint of the two panes violates min ${min}px` };\n}\n","/**\n * The steps of a folding split tree and the count rule that judges a split with them. Internal: the fold's layout\n * reads them; nothing here is exported from an entry.\n *\n * A **step** of a subtree along an axis is one way it can be laid out with folding on: the least length at which it\n * keeps `panes` panes open, each on its fold floor, whichever side of every fold in it is shown. A subtree's steps\n * are a **frontier**: lengths and counts both strictly increase. The **count rule** keeps a split with the pair of its\n * sides' steps that fits and keeps the most panes, and folds it only where folding keeps strictly more, or no pair\n * fits.\n *\n * Words: a tiling **fold** shows one side of a split and draws the other as a **spine**, a thin strip on the edge it\n * sits on; a **rail** is a box edge already holding a spine, where a spine inside joins it at no cost.\n */\nimport type { Axis, Side } from \"../side\";\nimport type { SplitFold } from \"./fold\";\nimport type { SplitOptions } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\n\n/** One way a subtree can be laid out along an axis with folding on: its least length that keeps `panes` open. */\nexport interface FoldStep {\n readonly length: number;\n readonly panes: number;\n}\n\n/**\n * Which of a subtree's ways its steps count: `\"any\"`; `\"folded\"`, only the ways where the subtree's own split folds;\n * `\"open-side\"`, a fold's open side, laid out afresh in the whole open box, so its own pin does not apply.\n */\nexport type FoldForm = \"any\" | \"folded\" | \"open-side\";\n\n/** The pair of steps a kept split keeps: each side's length along the split, and the panes they keep together. */\nexport interface FoldKept {\n readonly panes: number;\n readonly a: number;\n readonly b: number;\n}\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** Lengths this close are one. */\nconst FIT = 1e-6;\n\nconst NO_RAILS: ReadonlySet<Side> = new Set<Side>();\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\n\nconst otherAxis = (axis: Axis): Axis => (axis === \"x\" ? \"y\" : \"x\");\n\n/** Whether `node` counts as one pane: a `{ pane }` node, or a master split (laid out flat, never folded). */\nconst isPane = <K>(node: Split<K>): boolean => \"pane\" in node || node.master !== undefined;\n\n/** The edges a split's two sides sit on: `a`'s, then `b`'s. */\nconst sideEdges = (axis: Axis): readonly [Side, Side] => (axis === \"x\" ? [\"left\", \"right\"] : [\"top\", \"bottom\"]);\n\n/** `rails` cut to `edge`: the one rail a side sitting on that edge touches. */\nconst railOn = (rails: ReadonlySet<Side>, edge: Side): ReadonlySet<Side> => (rails.has(edge) ? new Set<Side>([edge]) : NO_RAILS);\n\n/** Only the steps that gain a pane: lengths and counts both strictly increase. */\nfunction stepFrontier(steps: readonly FoldStep[]): FoldStep[] {\n const sorted = [...steps].sort((p, q) => p.length - q.length || q.panes - p.panes);\n const out: FoldStep[] = [];\n for (const step of sorted) {\n const last = out[out.length - 1];\n if (last === undefined || step.panes > last.panes) out.push(step);\n }\n return out;\n}\n\n/** The least length among `steps` that keeps at least `panes` open, or Infinity. */\nfunction leastLengthFor(steps: readonly FoldStep[], panes: number): number {\n for (const step of steps) if (step.panes >= panes) return step.length;\n return Infinity;\n}\n\n/**\n * The least length among `steps` that keeps as many panes as the most any step no longer than `length` keeps: what a\n * side counted at `length` needs at least. `length` itself where no step fits.\n */\nexport function leastKeeping(steps: readonly FoldStep[], length: number): number {\n let panes = -1;\n for (const step of steps) if (step.length <= length + FIT) panes = Math.max(panes, step.panes);\n if (panes < 0) return length;\n let least = length;\n for (const step of steps) if (step.panes >= panes) least = Math.min(least, step.length);\n return least;\n}\n\n/**\n * A kept split's pair: of the pairs of side steps that fit `extent` less `gutter`, the one with the most panes, and of\n * those the one whose range holds `middle` (the first side's length at the split's middle) nearest, so no stored ratio\n * chooses it. Null where no pair fits.\n */\nexport function bestKeptPair(a: readonly FoldStep[], b: readonly FoldStep[], extent: number, gutter: number, middle: number): FoldKept | null {\n const room = Math.max(0, extent - gutter) + FIT;\n let best: { panes: number; move: number; a: number; b: number } | null = null;\n for (const x of a) {\n for (const y of b) {\n if (x.length + y.length > room && x.length + y.length > 0) continue;\n const high = extent - gutter - y.length;\n const move = middle < x.length ? x.length - middle : middle > high ? middle - high : 0;\n const panes = x.panes + y.panes;\n if (best === null || panes > best.panes || (panes === best.panes && move < best.move - FIT)) best = { panes, move, a: x.length, b: y.length };\n }\n }\n return best === null ? null : { panes: best.panes, a: best.a, b: best.b };\n}\n\n/** The most panes a split keeps folded at `extent`, from its `\"folded\"` steps; -1 where none fits. */\nfunction foldedPanesAt(folded: readonly FoldStep[], extent: number): number {\n let panes = -1;\n for (const step of folded) if (step.length <= extent + FIT) panes = Math.max(panes, step.panes);\n return panes;\n}\n\n/**\n * The count rule for a split at `extent` along its axis: kept with the pair `bestKeptPair` takes, unless folding (its\n * `\"folded\"` steps) keeps strictly more panes, or no pair fits. A tie stays open.\n */\nexport function countRule(\n a: readonly FoldStep[],\n b: readonly FoldStep[],\n folded: readonly FoldStep[],\n extent: number,\n gutter: number,\n middle: number,\n): \"fold\" | FoldKept {\n const kept = bestKeptPair(a, b, extent, gutter, middle);\n if (kept === null) return \"fold\";\n return foldedPanesAt(folded, extent) > kept.panes ? \"fold\" : kept;\n}\n\n// ---------------------------------------------------------------- the memo\n\n/** Step lists by node, then by the rest of a call; and whether a node holds a pin inside, by node and axis. */\ninterface StepMemo {\n readonly steps: WeakMap<object, Map<string, readonly FoldStep[]>>;\n readonly pinned: WeakMap<object, Map<Axis, boolean>>;\n}\n\n/** A host's answers by identity, one level each: `floor`, `weight`, `fixed`, then `fixedAcross` to the lengths. */\ntype ByAnswer = WeakMap<object, ByAnswer | Map<string, StepMemo>>;\n\n/**\n * By the host's `floor`, then `weight`, `fixed` and `fixedAcross` (by identity, a level each, so an answer the host\n * drops frees what it keyed), then the lengths (gap, handle, spine).\n */\nconst MEMOS: ByAnswer = new WeakMap();\n\n/** Stands for an answer the host does not give. */\nconst ABSENT = {};\n\n/** A number per object, for keys: a node, given on first use and kept while the object lives. */\nconst IDS = new WeakMap<object, number>();\nlet nextId = 0;\nconst idOf = (o: object | undefined): string => {\n if (o === undefined) return \"-\";\n let id = IDS.get(o);\n if (id === undefined) IDS.set(o, (id = nextId++));\n return String(id);\n};\n\n/** Whether a split under a node, the node included, runs across an axis (a master split holds none): by node and axis. */\nconst ACROSS = new WeakMap<object, Map<Axis, boolean>>();\n\nfunction memoOf<K>(options: SplitOptions<K>, fold: SplitFold<K>): StepMemo {\n let level = MEMOS;\n for (const answer of [fold.floor, fold.weight, options.fixed]) {\n let next = level.get(answer ?? ABSENT) as ByAnswer | undefined;\n if (next === undefined) level.set(answer ?? ABSENT, (next = new WeakMap()));\n level = next;\n }\n let byLengths = level.get(options.fixedAcross ?? ABSENT) as Map<string, StepMemo> | undefined;\n if (byLengths === undefined) level.set(options.fixedAcross ?? ABSENT, (byLengths = new Map<string, StepMemo>()));\n const key = `${px(options.gap)}|${px(options.handle)}|${px(fold.spine)}`;\n let memo = byLengths.get(key);\n if (memo === undefined) byLengths.set(key, (memo = { steps: new WeakMap(), pinned: new WeakMap() }));\n return memo;\n}\n\n// ---------------------------------------------------------------- the steps\n\n/**\n * The steps of one folding split tree, as its host answers for it. Made for a tree; answers from a memo shared by every\n * tree with the same `fold.floor`, `fold.weight`, `fixed` and `fixedAcross` (by identity) and the same gap, handle and\n * spine, so a host that keeps those and its unchanged subtrees the same objects counts each subtree once. Nothing in it\n * reads `fold.order`: what folds never depends on which pane is kept open first. Trees are taken as never changed in\n * place.\n *\n * Every split outside a master split needs an `axis`: a split with none divides along its box's longer side, which a\n * count made bottom-up cannot know.\n */\nexport class FoldSteps<K> {\n private readonly options: SplitOptions<K>;\n private readonly fold: SplitFold<K>;\n private readonly memo: StepMemo;\n private readonly parents = new Map<Split<K>, Branch<K>>();\n\n constructor(tree: Split<K>, options: SplitOptions<K>, fold: SplitFold<K>) {\n this.options = options;\n this.fold = fold;\n this.memo = memoOf(options, fold);\n const walk = (node: Split<K>): void => {\n if (isPane(node) || \"pane\" in node) return;\n if (node.axis === undefined) throw new Error(\"a folding split tree needs an axis on every split outside a master split\");\n for (const child of [node.a, node.b]) {\n this.parents.set(child, node);\n walk(child);\n }\n };\n walk(tree);\n }\n\n /** A split's gutter: its own gap, else the layout's, plus the handle. */\n gutter(split: Branch<K>): number {\n return (split.gap === undefined ? px(this.options.gap) : px(split.gap)) + px(this.options.handle);\n }\n\n /** What a fold takes from its open side where its spine joins no rail: the spine and the split's gap. */\n spineCost(split: Branch<K>): number {\n return px(this.fold.spine) + (split.gap === undefined ? px(this.options.gap) : px(split.gap));\n }\n\n /** A pane's fold floor along `axis` at `boundary`: the host's, and at least 1 px. */\n floor(node: Split<K>, axis: Axis, boundary: Split<K> | null): number {\n const v = this.fold.floor(node, axis, boundary);\n return v > 1 ? v : 1;\n }\n\n /** What a pane counts: its weight, a master split the sum of its panes'. */\n weight(node: Split<K>): number {\n const of = (pane: K): number => this.fold.weight?.(pane) ?? 1;\n if (\"pane\" in node) return of(node.pane);\n return panesOf(node).reduce((n, pane) => n + of(pane), 0);\n }\n\n /**\n * A node's pin along `axis`, as the fold counts it: its fixed length along its parent split (`fixed`) where that split\n * runs along `axis`, else its length across it (`fixedAcross`); only at 1 px or more. The root has none.\n */\n pin(node: Split<K>, axis: Axis): number | null {\n const parent = this.parents.get(node);\n if (parent === undefined) return null;\n const length = parent.axis === axis ? this.options.fixed?.(node, axis)?.length : this.options.fixedAcross?.(node, parent.axis!);\n return length !== undefined && Number.isFinite(length) && length >= 1 ? length : null;\n }\n\n /**\n * The steps of `node` along `axis`, measured at `boundary` (the nearest split above it along `axis`; null: none is\n * counted). `rails`: the edges where the node's box sits against an open rail, where a spine joins that rail and costs\n * nothing. `form`: see `FoldForm`. `cross`: the most the judged box measures across `axis` (a node inside pinned across\n * shorter than it doesn't span the box, so no rail on that length reaches it). `counted`: the length the node is\n * counted at across `axis`, read where a split across is judged at it; Infinity counts every split across kept.\n *\n * - A pane: one step, its floor and its weight.\n * - A split pinned along `axis`: its own steps up to the pin; one pinned shorter than its least step, that step.\n * - A split across `axis`: in the form its own count rule gives it at `counted`, inside which splits back along\n * `axis` are counted kept (depth one). Kept: its sides side by side, each counted across at its share. Folded: for\n * each count up to the smaller of its sides' most, the larger of their least lengths, each side counted across at\n * the length less the spine where it joins no rail.\n * - A split along `axis`, kept: each pair of its sides' steps, the lengths plus its gutter, the panes added; a side\n * keeps a rail only on the edge it touches, and is counted across at its pin where that is shorter. Folded: for each\n * count from 0 up to the smaller of its sides' most, the larger of the two sides' least lengths, each side with its\n * spine's cost (none where the spine's edge is a rail).\n */\n steps(\n node: Split<K>,\n axis: Axis,\n boundary: Split<K> | null,\n rails: ReadonlySet<Side>,\n form: FoldForm = \"any\",\n cross: number = Infinity,\n counted: number = Infinity,\n ): readonly FoldStep[] {\n // A node pinned across shorter than the box it sits in is drawn short of the rail: no spine in it joins the rail.\n const acrossPin = form === \"any\" && rails.size > 0 ? this.pin(node, otherAxis(axis)) : null;\n const reach = acrossPin !== null && acrossPin < cross - FIT ? NO_RAILS : rails;\n // The length across is read only where a split across can be judged at it; the bound across only by a split along.\n const at = this.holdsSplitAcross(node, axis) ? Math.max(0, counted) : Infinity;\n const pane = isPane(node);\n const bound = !pane && (node as Branch<K>).axis === axis ? String(cross) : \"\";\n const parent = this.parents.get(node)?.axis ?? \"\";\n const key = pane ? `${axis}|${idOf(boundary ?? undefined)}` : `${axis}|${idOf(boundary ?? undefined)}|${[...reach].sort().join(\",\")}|${form}|${bound}|${at}|${parent}`;\n let byKey = this.memo.steps.get(node);\n const known = byKey?.get(key);\n if (known !== undefined) return known;\n const steps = this.build(node, axis, boundary, reach, form, cross, at);\n if (byKey === undefined) this.memo.steps.set(node, (byKey = new Map<string, readonly FoldStep[]>()));\n byKey.set(key, steps);\n return steps;\n }\n\n private build(node: Split<K>, axis: Axis, boundary: Split<K> | null, rails: ReadonlySet<Side>, form: FoldForm, cross: number, counted: number): readonly FoldStep[] {\n if (isPane(node) || \"pane\" in node) return [{ length: this.floor(node, axis, boundary), panes: this.weight(node) }];\n const pin = this.pin(node, axis);\n if (pin !== null && form === \"any\") {\n const within = this.steps(node, axis, boundary, rails, \"open-side\", cross, counted);\n const fitting = within.filter((step) => step.length <= pin);\n return fitting.length > 0 ? fitting : within.slice(0, 1);\n }\n if (node.axis !== axis) return this.acrossSteps(node, axis, boundary, rails, counted);\n const [aEdge, bEdge] = sideEdges(axis);\n const out: FoldStep[] = [];\n if (form !== \"folded\") {\n // Each side spans the split across: counted at the split's length across, or at its pin there where shorter.\n const acrossOf = (side: Split<K>): number => {\n const p = Number.isFinite(counted) ? this.pin(side, otherAxis(axis)) : null;\n return p === null ? counted : Math.min(p, counted);\n };\n const a = this.steps(node.a, axis, node, railOn(rails, aEdge), \"any\", cross, acrossOf(node.a));\n const b = this.steps(node.b, axis, node, railOn(rails, bEdge), \"any\", cross, acrossOf(node.b));\n const gutter = this.gutter(node);\n for (const x of a) for (const y of b) out.push({ length: x.length + gutter + y.length, panes: x.panes + y.panes });\n }\n const shown = (side: \"a\" | \"b\"): FoldStep[] => {\n const openEdge = side === \"a\" ? aEdge : bEdge;\n const spineEdge = side === \"a\" ? bEdge : aEdge;\n const cost = rails.has(spineEdge) ? 0 : this.spineCost(node);\n const openRails = new Set<Side>([...railOn(rails, openEdge), spineEdge]);\n return this.steps(node[side], axis, node, openRails, \"open-side\", cross, counted).map((step) => ({ length: step.length + cost, panes: step.panes }));\n };\n return stepFrontier([...out, ...foldedSteps(shown(\"a\"), shown(\"b\"))]);\n }\n\n /**\n * The steps along `axis` of `node`, a split across it, in the form its own count rule gives it at `length` (its\n * length along its own axis). Its own steps are counted with no length across them: depth one.\n */\n private acrossSteps(node: Branch<K>, axis: Axis, boundary: Split<K> | null, rails: ReadonlySet<Side>, length: number): readonly FoldStep[] {\n if (!Number.isFinite(length)) return besideSteps(this.steps(node.a, axis, boundary, NO_RAILS), this.steps(node.b, axis, boundary, NO_RAILS));\n const own = otherAxis(axis);\n const [aEdge, bEdge] = sideEdges(own);\n const ownRails = new Set<Side>([...railOn(rails, aEdge), ...railOn(rails, bEdge)]);\n const aOwn = this.steps(node.a, own, node, railOn(rails, aEdge));\n const bOwn = this.steps(node.b, own, node, railOn(rails, bEdge));\n const gutter = this.gutter(node);\n // At its all-open need or longer it keeps every pane, and each side at least its own all-open need, and so on\n // down: the same steps as with no length across, unless a pin along its axis inside cuts a side shorter.\n const allOpen = (aOwn[aOwn.length - 1]?.length ?? 0) + gutter + (bOwn[bOwn.length - 1]?.length ?? 0);\n if (length + FIT >= allOpen && !this.pinnedInside(node, own)) return this.acrossSteps(node, axis, boundary, rails, Infinity);\n const judged = countRule(aOwn, bOwn, this.steps(node, own, null, ownRails, \"folded\"), length, gutter, length / 2 - gutter / 2);\n // A side spans the split along `axis` but not its rails there; it touches the rail on its own edge, unless pinned\n // along `axis`, where it may fall short of it.\n const sideRails = (side: Split<K>, edges: ReadonlySet<Side>): ReadonlySet<Side> => (this.pin(side, axis) === null ? edges : NO_RAILS);\n if (judged !== \"fold\") {\n const room = Math.max(0, length - gutter);\n const aLength = Math.max(0, room - leastKeeping(bOwn, judged.b));\n const bLength = Math.max(0, room - leastKeeping(aOwn, aLength));\n return besideSteps(\n this.steps(node.a, axis, boundary, sideRails(node.a, railOn(rails, aEdge)), \"any\", Infinity, aLength),\n this.steps(node.b, axis, boundary, sideRails(node.b, railOn(rails, bEdge)), \"any\", Infinity, bLength),\n );\n }\n const shown = (side: \"a\" | \"b\"): readonly FoldStep[] => {\n const openEdge = side === \"a\" ? aEdge : bEdge;\n const spineEdge = side === \"a\" ? bEdge : aEdge;\n const open = Math.max(0, length - (rails.has(spineEdge) ? 0 : this.spineCost(node)));\n const openRails = new Set<Side>([...railOn(rails, openEdge), spineEdge]);\n return this.steps(node[side], axis, boundary, sideRails(node[side], openRails), \"open-side\", Infinity, open);\n };\n return stepFrontier(foldedSteps(shown(\"a\"), shown(\"b\")));\n }\n\n /** Whether `node`'s subtree, `node` included, holds a split (not a master split) across `axis`. */\n private holdsSplitAcross(node: Split<K>, axis: Axis): boolean {\n if (isPane(node) || \"pane\" in node) return false;\n let byAxis = ACROSS.get(node);\n const known = byAxis?.get(axis);\n if (known !== undefined) return known;\n const value = node.axis !== axis || this.holdsSplitAcross(node.a, axis) || this.holdsSplitAcross(node.b, axis);\n if (byAxis === undefined) ACROSS.set(node, (byAxis = new Map<Axis, boolean>()));\n byAxis.set(axis, value);\n return value;\n }\n\n /** Whether a node strictly inside `node` is pinned along `axis`. */\n private pinnedInside(node: Split<K>, axis: Axis): boolean {\n if (\"pane\" in node) return false;\n let byAxis = this.memo.pinned.get(node);\n const known = byAxis?.get(axis);\n if (known !== undefined) return known;\n const pinnedIn = (child: Split<K>): boolean => this.pin(child, axis) !== null || this.pinnedInside(child, axis);\n const value = pinnedIn(node.a) || pinnedIn(node.b);\n if (byAxis === undefined) this.memo.pinned.set(node, (byAxis = new Map<Axis, boolean>()));\n byAxis.set(axis, value);\n return value;\n }\n}\n\n/** A fold's steps from its two sides each shown: for each count both can keep, the larger of their least lengths. */\nfunction foldedSteps(a: readonly FoldStep[], b: readonly FoldStep[]): FoldStep[] {\n const most = Math.min(a[a.length - 1]?.panes ?? 0, b[b.length - 1]?.panes ?? 0);\n const out: FoldStep[] = [];\n for (let panes = 0; panes <= most; panes += 1) out.push({ length: Math.max(leastLengthFor(a, panes), leastLengthFor(b, panes)), panes });\n return out;\n}\n\n/** Each pair of `a` and `b` side by side across: the larger length, the panes added. */\nconst besideSteps = (a: readonly FoldStep[], b: readonly FoldStep[]): FoldStep[] =>\n stepFrontier(a.flatMap((x) => b.map((y) => ({ length: Math.max(x.length, y.length), panes: x.panes + y.panes }))));\n","/**\n * The layout of a folding split tree: what folds, which side of each fold shows, and every rect, from one walk. Internal:\n * `layoutSplitTree` calls it when its options hold a `fold`.\n *\n * At each split, top-down, the walk weighs the ways to draw it with the count rule (src/tiling/fold-steps.ts): kept,\n * with each side laid out as its steps allow, or folded. It takes the way that keeps the most panes open on their fold\n * floors whichever side of every fold shows, and on a tie it stays open. Each side is then decided the same way in the\n * length counted for it. Once all is decided, the walk draws: a kept split from its ratio on the needs of the forms its\n * sides chose, as the split layout decides a split, so the boundary moves only as far as a side's need asks. Folded,\n * the side holding the first pane of the order stays open in the split's box less a spine and a gap, and the other side\n * becomes a spine on the edge where it sits. Nested folds on one edge share one rail.\n *\n * What folds depends on the tree, the area and the host's answers only: the order chooses which side of a fold shows,\n * and no ratio decides anything (a split is judged at the length its parent counted for it, not at the box a ratio\n * gave it).\n */\nimport type { Rect } from \"../geometry\";\nimport type { Axis, Side } from \"../side\";\nimport type { SplitFold, SplitFoldGeometry } from \"./fold\";\nimport { countRule, FoldSteps, leastKeeping, type FoldKept, type FoldStep } from \"./fold-steps\";\nimport { laySplitTree, type FixedLength, type MinLength, type SplitGeometry, type SplitLayout, type SplitOptions } from \"./layout\";\nimport { panesOf, type Split } from \"./split\";\n\ntype Branch<K> = Exclude<Split<K>, { readonly pane: K }>;\n\n/** A length along each axis. */\ninterface Lengths {\n readonly x: number;\n readonly y: number;\n}\n\n/**\n * What a node's box is known to measure whatever the ratios: the length counted for it (what its parent's decision\n * guarantees it) and the most it can measure (the area cut by the needs of what sits beside it).\n */\ninterface Room {\n readonly counted: Lengths;\n readonly most: Lengths;\n}\n\n/** A rail open on one edge: the fold heading it (its index in `folds`), its box, and where the open side next to it starts. */\ninterface OpenRail {\n readonly fold: number;\n readonly rect: Rect;\n /** The open side's edge next to the rail: an x for a left or right rail, a y for a top or bottom one. */\n readonly boundary: number;\n}\n\ntype OpenRails = Readonly<Partial<Record<Side, OpenRail>>>;\n\n/** One side of a folded split laid out as the open one: its box, its room and rails, and what the spine takes. */\ninterface OpenLayout {\n readonly edge: Side;\n readonly openRect: Rect;\n readonly railRect: Rect;\n readonly railOf: number;\n readonly openRails: OpenRails;\n readonly openRoom: Room;\n /** What the spine and the split's gap take from the split's length: none where the spine joins a rail. */\n readonly taken: number;\n}\n\n/** A node as decided, before it is drawn: what folds, and the forms each kept split's sides chose. */\ntype Decided<K> =\n | { readonly kind: \"pane\"; readonly node: Split<K> }\n | { readonly kind: \"kept\"; readonly node: Branch<K>; readonly pair: FoldKept; readonly a: Decided<K>; readonly b: Decided<K> }\n | {\n readonly kind: \"fold\";\n readonly node: Branch<K>;\n readonly room: Room;\n readonly open: \"a\" | \"b\";\n /** Each side decided as the open one: whichever shows, the split holds room for it. */\n readonly sides: Readonly<Record<\"a\" | \"b\", { readonly layout: OpenLayout; readonly decided: Decided<K> }>>;\n };\n\ntype DecidedFold<K> = Extract<Decided<K>, { kind: \"fold\" }>;\n\nconst NO_RAILS: OpenRails = {};\nconst NONE: ReadonlySet<Side> = new Set<Side>();\nconst EDGES: readonly Side[] = [\"left\", \"right\", \"top\", \"bottom\"];\n\n/** Px between two segments of one rail. */\nconst SEGMENT_GAP = 2;\n\n/** Ratios this close are one. */\nconst RATIO_EPSILON = 1e-9;\n\n/** A segment this close to the floor reaches it. */\nconst FLOOR_EPSILON = 1e-9;\n\nconst px = (v: number | undefined): number => (v !== undefined && Number.isFinite(v) && v > 0 ? v : 0);\nconst usable = (v: number | undefined): v is number => v !== undefined && Number.isFinite(v) && v > 0;\nconst otherAxis = (axis: Axis): Axis => (axis === \"x\" ? \"y\" : \"x\");\nconst lengthOf = (rect: Rect, axis: Axis): number => (axis === \"x\" ? rect.width : rect.height);\nconst isPane = <K>(node: Split<K>): boolean => \"pane\" in node || node.master !== undefined;\nconst sideEdges = (axis: Axis): readonly [Side, Side] => (axis === \"x\" ? [\"left\", \"right\"] : [\"top\", \"bottom\"]);\nconst nearPx = (a: number, b: number): boolean => Math.abs(a - b) <= 0.5;\n\n/** Whether a fold in `rect` with its spine on `edge` sits right against `rail`, along its whole length. */\nfunction joinsRail(rail: OpenRail, rect: Rect, edge: Side): boolean {\n switch (edge) {\n case \"left\":\n return nearPx(rect.x, rail.boundary) && nearPx(rect.y, rail.rect.y) && nearPx(rect.height, rail.rect.height);\n case \"right\":\n return nearPx(rect.x + rect.width, rail.boundary) && nearPx(rect.y, rail.rect.y) && nearPx(rect.height, rail.rect.height);\n case \"top\":\n return nearPx(rect.y, rail.boundary) && nearPx(rect.x, rail.rect.x) && nearPx(rect.width, rail.rect.width);\n case \"bottom\":\n return nearPx(rect.y + rect.height, rail.boundary) && nearPx(rect.x, rail.rect.x) && nearPx(rect.width, rail.rect.width);\n }\n}\n\n/** Where the open side next to a rail on `edge` starts, given that side's box. */\nfunction railBoundary(openRect: Rect, edge: Side): number {\n switch (edge) {\n case \"left\":\n return openRect.x;\n case \"right\":\n return openRect.x + openRect.width;\n case \"top\":\n return openRect.y;\n case \"bottom\":\n return openRect.y + openRect.height;\n }\n}\n\n/** The spine's and the open side's boxes in a folded split's `rect`. */\nfunction foldBoxes(rect: Rect, axis: Axis, edge: Side, spine: number, gap: number): { spineRect: Rect; openRect: Rect } {\n if (axis === \"x\") {\n const spineWidth = Math.max(0, Math.min(spine, rect.width));\n const openWidth = Math.max(0, rect.width - spine - gap);\n return edge === \"left\"\n ? { spineRect: { x: rect.x, y: rect.y, width: spineWidth, height: rect.height }, openRect: { x: rect.x + rect.width - openWidth, y: rect.y, width: openWidth, height: rect.height } }\n : { spineRect: { x: rect.x + rect.width - spineWidth, y: rect.y, width: spineWidth, height: rect.height }, openRect: { x: rect.x, y: rect.y, width: openWidth, height: rect.height } };\n }\n const spineHeight = Math.max(0, Math.min(spine, rect.height));\n const openHeight = Math.max(0, rect.height - spine - gap);\n return edge === \"top\"\n ? { spineRect: { x: rect.x, y: rect.y, width: rect.width, height: spineHeight }, openRect: { x: rect.x, y: rect.y + rect.height - openHeight, width: rect.width, height: openHeight } }\n : { spineRect: { x: rect.x, y: rect.y + rect.height - spineHeight, width: rect.width, height: spineHeight }, openRect: { x: rect.x, y: rect.y, width: rect.width, height: openHeight } };\n}\n\n/**\n * A rail's (or a spine's) segments by weight, from its top or left end, each as long as its share, with up to\n * `SEGMENT_GAP` px between two. `axis` is the folded split's: a sideways fold's rail runs top to bottom.\n */\nfunction segments(rail: Rect, axis: Axis, weights: readonly number[]): Rect[] {\n const along = axis === \"x\";\n const length = along ? rail.height : rail.width;\n const gap = weights.length > 1 ? Math.min(SEGMENT_GAP, length / (weights.length * 4)) : 0;\n const total = weights.reduce((sum, weight) => sum + weight, 0);\n const free = Math.max(0, length - gap * (weights.length - 1));\n const out: Rect[] = [];\n let offset = 0;\n weights.forEach((weight, index) => {\n const part = index === weights.length - 1 ? Math.max(0, length - offset) : (free * weight) / total;\n out.push(along ? { x: rail.x, y: rail.y + offset, width: rail.width, height: part } : { x: rail.x + offset, y: rail.y, width: part, height: rail.height });\n offset += part + gap;\n });\n return out;\n}\n\n/** The room of a box nothing outside it constrains: counted and at most its own size. */\nconst wholeRoom = (rect: Rect): Room => ({ counted: { x: rect.width, y: rect.height }, most: { x: rect.width, y: rect.height } });\n\n/** `lengths` with `axis` set to `value`. */\nconst withLength = (lengths: Lengths, axis: Axis, value: number): Lengths => (axis === \"x\" ? { x: value, y: lengths.y } : { x: lengths.x, y: value });\n\n/**\n * `tree` laid out in `area` with `fold`: see the module's comment. Where nothing folds and every kept split is drawn at\n * the ratio the layout without the fold draws it at, the panes and splits are that layout's (fresh maps), the needs\n * those the fold chose.\n */\nexport function foldLayout<K>(tree: Split<K> | null, area: Rect, options: SplitOptions<K>, fold: SplitFold<K>): SplitLayout<K> {\n const plainRatios = new Map<Split<K>, number>();\n const base = laySplitTree(tree, area, options, plainRatios);\n if (!tree) return { ...base, spines: new Map(), folds: [] };\n const steps = new FoldSteps(tree, options, fold);\n const order = fold.order;\n const targetOrder = fold.targetOrder ?? order;\n const weight = (pane: K): number => fold.weight?.(pane) ?? 1;\n const spine = px(fold.spine);\n const gapOf = (split: Branch<K>): number => (split.gap === undefined ? px(options.gap) : px(split.gap));\n\n const panes = new Map<K, Rect>();\n const splits = new Map<string, SplitGeometry>();\n const folds: SplitFoldGeometry<K>[] = [];\n /** Whether a kept split is drawn at another ratio than the layout without the fold draws it at. */\n const drawnAt = { moved: false };\n\n /** A child's length across its split, as the host fixes it (above 0), else null. */\n const pinAcross = (child: Split<K>, split: Branch<K>): number | null => {\n const length = options.fixedAcross?.(child, split.axis!);\n return usable(length) ? length : null;\n };\n /** A kept split's side counted across: at the split's length across, or at the side's length across where shorter. */\n const sideAcross = (side: Split<K>, split: Branch<K>, across: number): number => {\n const pin = pinAcross(side, split);\n return pin === null ? across : Math.min(pin, across);\n };\n\n /**\n * A kept split laid out in `rect` from its ratio, on the needs `a` and `b`, each side's net and fixed length as the\n * layout reads them, and each child's length across: the split layout's own arithmetic for one split.\n */\n const layOutKept = (node: Branch<K>, rect: Rect, a: number, b: number): { geometry: SplitGeometry; a: Rect; b: Rect } => {\n const axis = node.axis!;\n const sideOf = (child: Split<K>): { fixed: FixedLength | undefined; net: boolean } => {\n const fixed = options.fixed?.(child, axis);\n const kept = !!fixed?.keep && usable(fixed.length);\n return { fixed, net: kept || (options.floor ? options.floor(child, axis, node).net !== false : true) };\n };\n const sides = { a: sideOf(node.a), b: sideOf(node.b) };\n const one: Split<0 | 1> = {\n id: \"s\",\n a: { pane: 0 },\n b: { pane: 1 },\n axis,\n ...(node.ratio !== undefined ? { ratio: node.ratio } : {}),\n ...(node.gap !== undefined ? { gap: node.gap } : {}),\n };\n const second = (child: Split<0 | 1>): boolean => \"pane\" in child && child.pane === 1;\n const laid = laySplitTree(one, rect, {\n gap: options.gap,\n handle: options.handle,\n floor: (child): MinLength => (second(child) ? { min: b, net: sides.b.net } : { min: a, net: sides.a.net }),\n fixed: (child) => (second(child) ? sides.b.fixed : sides.a.fixed),\n fixedAcross: (child) => options.fixedAcross?.(second(child) ? node.b : node.a, axis),\n });\n const empty = (): Rect => ({ x: rect.x, y: rect.y, width: 0, height: 0 });\n return { geometry: laid.splits.get(\"s\")!, a: laid.panes.get(0) ?? empty(), b: laid.panes.get(1) ?? empty() };\n };\n\n /** The count rule on `split`, at the lengths counted for it (`rect`'s width and height), its rails and its bound across. */\n const judge = (split: Branch<K>, rect: Rect, crossMax: number, rails: ReadonlySet<Side>): \"fold\" | FoldKept => {\n const axis = split.axis!;\n const extent = Math.max(0, lengthOf(rect, axis));\n const gutter = steps.gutter(split);\n const [aEdge, bEdge] = sideEdges(axis);\n const onEdge = (edge: Side): ReadonlySet<Side> => (rails.has(edge) ? new Set<Side>([edge]) : NONE);\n // Rails as drawn: a node inside pinned across reaches a rail where its pin spans the box across, whatever the ratios.\n const cross = Math.max(0, crossMax);\n // Each side is counted across at the split's counted length across, or at its pin there where shorter, as drawn.\n const across = Math.max(0, lengthOf(rect, otherAxis(axis)));\n const a = steps.steps(split.a, axis, split, onEdge(aEdge), \"any\", cross, sideAcross(split.a, split, across));\n const b = steps.steps(split.b, axis, split, onEdge(bEdge), \"any\", cross, sideAcross(split.b, split, across));\n const folded = steps.steps(split, axis, null, rails, \"folded\", cross, across);\n const middle = extent / 2 - gutter / 2;\n return countRule(a, b, folded, extent, gutter, middle);\n };\n\n /** The side of `split` holding the first pane of the order it holds, else `\"a\"`. */\n const openSideOf = (split: Branch<K>): \"a\" | \"b\" => {\n const a = new Set(panesOf(split.a));\n const b = new Set(panesOf(split.b));\n for (const pane of order) {\n if (a.has(pane)) return \"a\";\n if (b.has(pane)) return \"b\";\n }\n return \"a\";\n };\n\n /**\n * `side` of folded `node` laid out as the open one in `rect`, with the other side's spine on its edge. `foldIndex`:\n * the fold's index in `folds` (-1 while deciding).\n */\n const openLayout = (node: Branch<K>, side: \"a\" | \"b\", rect: Rect, room: Room, rails: OpenRails, foldIndex: number): OpenLayout => {\n const axis = node.axis!;\n const [aEdge, bEdge] = sideEdges(axis);\n const edge = side === \"a\" ? bEdge : aEdge;\n const gap = gapOf(node);\n // A fold right against an enclosing fold's rail on the same edge joins that rail: no spine or gap of its own.\n const rail = rails[edge];\n const joined = rail !== undefined && joinsRail(rail, rect, edge);\n const own = joined ? null : foldBoxes(rect, axis, edge, spine, gap);\n const openRect = own === null ? { ...rect } : own.openRect;\n const railRect = own === null ? { ...rail!.rect } : own.spineRect;\n const railOf = own === null ? rail!.fold : foldIndex;\n const openRails: OpenRails = own === null ? rails : { ...rails, [edge]: { fold: foldIndex, rect: railRect, boundary: railBoundary(openRect, edge) } };\n // The open side's room is the split's less what the spine and gap take: a length, not read from the box.\n const taken = own === null ? 0 : spine + gap;\n const openRoom: Room = {\n counted: withLength(room.counted, axis, Math.max(0, room.counted[axis] - taken)),\n most: withLength(room.most, axis, Math.max(0, room.most[axis] - taken)),\n };\n return { edge, openRect, railRect, railOf, openRails, openRoom, taken };\n };\n\n /** `node` decided as folded: each side decided as the open one. The order chooses the side that shows, and only here. */\n const decideFold = (node: Branch<K>, rect: Rect, room: Room, rails: OpenRails): DecidedFold<K> => {\n const sideOf = (side: \"a\" | \"b\"): { layout: OpenLayout; decided: Decided<K> } => {\n const layout = openLayout(node, side, rect, room, rails, -1);\n return { layout, decided: decide(node[side], layout.openRect, layout.openRoom, layout.openRails) };\n };\n return { kind: \"fold\", node, room, open: openSideOf(node), sides: { a: sideOf(\"a\"), b: sideOf(\"b\") } };\n };\n\n /**\n * What folds, top-down. A split is judged at the length its parent counted for it, never at its box, so no ratio\n * decides anything; the box `rect` is read for edge facts only (which rails it sits against along its whole length).\n *\n * A kept split's sides are counted one after the other (across, a side pinned shorter at its pin): the first at what\n * the second needs to keep its pair's panes leaves (`leastKeeping`), then the second at what the first's chosen forms\n * leave. So slack a side cannot use goes to the other, each side is decided once, the two fit by construction, and\n * neither keeps fewer panes than the pair the count rule kept.\n */\n const decide = (node: Split<K>, rect: Rect, room: Room, rails: OpenRails): Decided<K> => {\n if (isPane(node) || \"pane\" in node) return { kind: \"pane\", node };\n const here = new Set<Side>(\n EDGES.filter((edge) => {\n const rail = rails[edge];\n return rail !== undefined && joinsRail(rail, rect, edge);\n }),\n );\n const judged: Lengths = { x: Math.max(0, room.counted.x), y: Math.max(0, room.counted.y) };\n const along = node.axis!;\n const across = otherAxis(along);\n const crossMax = Math.max(lengthOf(rect, across), room.most[across]);\n const verdict = judge(node, { x: rect.x, y: rect.y, width: judged.x, height: judged.y }, crossMax, here);\n if (verdict === \"fold\") return decideFold(node, rect, { counted: judged, most: room.most }, rails);\n const laid = layOutKept(node, rect, verdict.a, verdict.b);\n const gutter = steps.gutter(node);\n const sideRoom = (child: Split<K>, need: number, otherNeed: number): Room => {\n const pin = pinAcross(child, node);\n const counted = withLength(withLength(judged, along, need), across, pin === null ? judged[across] : Math.min(pin, judged[across]));\n return { counted, most: withLength(room.most, along, Math.max(0, room.most[along] - gutter - otherNeed)) };\n };\n const roomLength = Math.max(0, judged[along] - gutter);\n const bEdge: Side = along === \"x\" ? \"right\" : \"bottom\";\n const bRails = here.has(bEdge) ? new Set<Side>([bEdge]) : NONE;\n const bSteps: readonly FoldStep[] = steps.steps(node.b, along, node, bRails, \"any\", Math.max(0, crossMax), sideAcross(node.b, node, judged[across]));\n const bLeast = leastKeeping(bSteps, verdict.b);\n const a = decide(node.a, laid.a, sideRoom(node.a, Math.max(0, roomLength - bLeast), bLeast), rails);\n const aNeed = chosenNeed(a, along, node);\n // The second side's box with the first at its chosen need: no divider draws it longer than what the first leaves.\n const bRect = layOutKept(node, rect, aNeed, bLeast).b;\n const b = decide(node.b, bRect, sideRoom(node.b, Math.max(0, roomLength - aNeed), aNeed), rails);\n return { kind: \"kept\", node, pair: verdict, a, b };\n };\n\n const chosen = new WeakMap<Decided<K>, Map<Split<K> | null, Partial<Record<Axis, number>>>>();\n\n /**\n * The need along `axis` of the forms `decided` chose, measured by `boundary` (the nearest split along it): a pane its\n * fold floor; a kept split its sides' chosen needs plus its gutter along, the larger of them across; a fold the larger\n * over its two sides each as the open one, plus what its spine takes along, so the order moves nothing outside it.\n */\n const chosenNeed = (decided: Decided<K>, axis: Axis, boundary: Split<K> | null): number => {\n if (decided.kind === \"pane\") return steps.floor(decided.node, axis, boundary);\n let byBoundary = chosen.get(decided);\n const known = byBoundary?.get(boundary)?.[axis];\n if (known !== undefined) return known;\n const node = decided.node;\n const alongIt = node.axis === axis;\n let need = 0;\n if (decided.kind === \"kept\") {\n need = alongIt\n ? chosenNeed(decided.a, axis, node) + steps.gutter(node) + chosenNeed(decided.b, axis, node)\n : Math.max(chosenNeed(decided.a, axis, boundary), chosenNeed(decided.b, axis, boundary));\n } else {\n for (const side of [\"a\", \"b\"] as const) {\n const { layout, decided: open } = decided.sides[side];\n need = Math.max(need, alongIt ? chosenNeed(open, axis, node) + layout.taken : chosenNeed(open, axis, boundary));\n }\n }\n if (byBoundary === undefined) chosen.set(decided, (byBoundary = new Map<Split<K> | null, Partial<Record<Axis, number>>>()));\n byBoundary.set(boundary, { ...byBoundary.get(boundary), [axis]: need });\n return need;\n };\n\n /** Draws `decided` in `rect`: a kept split from its ratio on the chosen needs of its sides. */\n const draw = (decided: Decided<K>, rect: Rect, enclosing: readonly number[], rails: OpenRails): void => {\n if (decided.kind === \"fold\") {\n drawFold(decided, rect, enclosing, rails);\n return;\n }\n if (decided.kind === \"pane\") {\n const node = decided.node;\n if (\"pane\" in node) {\n panes.set(node.pane, { ...rect });\n return;\n }\n // A master split never folds: laid out as the layout lays it out, its panes flat.\n const laid = laySplitTree(node, rect, options);\n for (const [pane, r] of laid.panes) panes.set(pane, r);\n for (const [id, geometry] of laid.splits) splits.set(id, geometry);\n return;\n }\n const node = decided.node;\n const axis = node.axis!;\n const laid = layOutKept(node, rect, chosenNeed(decided.a, axis, node), chosenNeed(decided.b, axis, node));\n if (node.id !== undefined) splits.set(node.id, laid.geometry);\n if (!drawnAt.moved) {\n const plain = plainRatios.get(node);\n if (plain === undefined || !(Math.abs(plain - laid.geometry.ratio) <= RATIO_EPSILON)) drawnAt.moved = true;\n }\n draw(decided.a, laid.a, enclosing, rails);\n draw(decided.b, laid.b, enclosing, rails);\n };\n\n /** Draws a folded split: its open side in the box less the spine, the other side a spine on its edge. */\n const drawFold = (decided: DecidedFold<K>, rect: Rect, enclosing: readonly number[], rails: OpenRails): void => {\n const node = decided.node;\n const index = folds.length;\n const layout = openLayout(node, decided.open, rect, decided.room, rails, index);\n const folded = panesOf(node[decided.open === \"a\" ? \"b\" : \"a\"]);\n const shown = folded.filter((pane) => weight(pane) > 0);\n const target = targetOrder.find((pane) => shown.includes(pane)) ?? shown[0] ?? null;\n folds.push({\n id: node.id,\n axis: node.axis!,\n open: decided.open,\n edge: layout.edge,\n rect: { ...rect },\n openRect: layout.openRect,\n spine: { ...layout.railRect },\n rail: layout.railRect,\n // Set with the rail's segments, below.\n railContentLength: 0,\n railOf: layout.railOf,\n parent: enclosing.length > 0 ? enclosing[enclosing.length - 1]! : null,\n panes: folded,\n target,\n });\n draw(decided.sides[decided.open].decided, layout.openRect, [...enclosing, index], layout.openRails);\n };\n\n draw(decide(tree, area, wholeRoom(area), NO_RAILS), area, [], NO_RAILS);\n\n // Each rail's segments. A rail holding more than one fold is shared by its folds, by the panes that show in each (at\n // least 1); each fold's spine by its panes that show, in reading order. A pane that shows nothing has none, as the\n // rail gives it no share. Under a segment floor that a segment would fall under, every segment is the floor long.\n const onRail = new Map<number, number[]>();\n folds.forEach((each, index) => onRail.set(each.railOf, [...(onRail.get(each.railOf) ?? []), index]));\n const drawn: SplitFoldGeometry<K>[] = [...folds];\n const paneParts: Rect[][] = folds.map(() => []);\n const asked = px(fold.segmentFloor);\n for (const members of onRail.values()) {\n const head = folds[members[0]!]!;\n const along = head.axis === \"x\" ? \"height\" : \"width\";\n const length = head.rail[along];\n const shownOf = (i: number): K[] => folds[i]!.panes.filter((pane) => weight(pane) > 0);\n const shares = members.length < 2 ? [head.spine] : segments(head.rail, head.axis, members.map((i) => Math.max(1, shownOf(i).length)));\n let spinesOf = shares;\n let partsOf = members.map((i, n) => segments(shares[n]!, head.axis, shownOf(i).map(() => 1)));\n let content = length;\n // The floor used: never longer than the rail's box, so one pane alone always fits it.\n const floor = Math.min(asked, length);\n const shortest = Math.min(...members.map((i, n) => (shownOf(i).length > 0 ? Math.min(...partsOf[n]!.map((r) => r[along])) : shares[n]![along])));\n if (floor > 0 && shortest < floor - FLOOR_EPSILON) {\n // Every segment the floor long, 2 px apart, from the box's top or left; a fold showing nothing takes one length.\n const unit = (at: number, size: number): Rect => (head.axis === \"x\" ? { ...head.rail, y: head.rail.y + at, height: size } : { ...head.rail, x: head.rail.x + at, width: size });\n let at = 0;\n const floored: Rect[] = [];\n partsOf = members.map((i) => {\n const start = at;\n const parts: Rect[] = [];\n for (let u = 0; u < Math.max(1, shownOf(i).length); u++, at += floor + SEGMENT_GAP) parts.push(unit(at, floor));\n floored.push(unit(start, at - SEGMENT_GAP - start));\n return shownOf(i).length > 0 ? parts : [];\n });\n spinesOf = floored;\n content = Math.max(length, at - SEGMENT_GAP);\n }\n members.forEach((i, n) => {\n drawn[i] = { ...folds[i]!, spine: { ...spinesOf[n]! }, railContentLength: content };\n paneParts[i] = partsOf[n]!;\n });\n }\n // Each folded pane that shows: its segment, in the folds' order.\n const spines = new Map<K, Rect>();\n drawn.forEach((each, i) => each.panes.filter((pane) => weight(pane) > 0).forEach((pane, n) => spines.set(pane, paneParts[i]![n]!)));\n\n if (drawn.length === 0 && !drawnAt.moved) {\n // Nothing folds or moves: the layout without the fold, with the needs the fold chose.\n const out = new Map<string, SplitGeometry>();\n for (const [id, geometry] of base.splits) {\n const mine = splits.get(id);\n out.set(id, mine === undefined ? geometry : { ...geometry, needs: mine.needs });\n }\n return { panes: base.panes, splits: out, spines, folds: drawn };\n }\n return { panes, splits, spines, folds: drawn };\n}\n","/**\n * `layoutSplitTree`: the split tree laid out, folding or not. One function lays the tree out, so what a host draws,\n * what a drag hits and what is judged to fit all come from it. See docs/placement.md, Entry: tiling.\n */\nimport type { Rect } from \"../geometry\";\nimport type { SplitFold } from \"./fold\";\nimport { foldLayout } from \"./fold-plan\";\nimport { laySplitTree, type SplitLayout, type SplitOptions } from \"./layout\";\nimport type { Split } from \"./split\";\n\n/**\n * `SplitOptions` plus the fold, which only `layoutSplitTree` (and the drag and its conformance runs) takes:\n * `layoutSplit`, `splitNeed`, `canDropOnPane`, `canSplitPane` and `dropFits` throw on it.\n */\nexport interface FoldingSplitOptions<K> extends SplitOptions<K> {\n readonly fold?: SplitFold<K>;\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\n * under another, or a later one beside it): the box it divides, its axis and ratio in effect (after the floors), and its\n * divider, the gutter strip between its two sides. A split that lays out as master and stack is reported too, its\n * nested splits are not.\n *\n * With `fold`, a split that cannot keep its panes on their fold floors may fold: one side stays open and the other is\n * drawn as a spine (`spines`, `folds`); a folded split is not in `splits`, and a kept split's `needs` are the pair the\n * fold chose. Every split outside a master split then needs an `axis` (throws otherwise); a master split never folds.\n * Where nothing folds and no boundary moves, the panes and splits are those without the fold on the same\n * `options.floor`: with `fold`, a kept split's net is on where there is no `floor` (a ratio of 0.02 lays out at 20 px of\n * 1000 without the fold, 50 px with it). A spine has a segment per folded pane that shows (weight 1), at a content\n * position (`paintedSpines` gives where it is painted). `tilingDrag` takes the fold too and lays every tree of a drag\n * out here, and so do the conformance runs. See `SplitFold`.\n */\nexport function layoutSplitTree<K>(tree: Split<K> | null, area: Rect, options: FoldingSplitOptions<K> = {}): SplitLayout<K> {\n if (options.fold) return foldLayout(tree, area, options, options.fold);\n return { ...laySplitTree(tree, area, options), spines: new Map(), folds: [] };\n}\n\n/** The options with the fold's order set to `order`; the same options without a fold. @internal */\nexport const withOrder = <K>(options: FoldingSplitOptions<K>, order: readonly K[]): FoldingSplitOptions<K> =>\n options.fold ? { ...options, fold: { ...options.fold, order } } : options;\n","/**\n * Where a folding layout's spine segments are painted: `paintedSpines(layout, railOffset)`. A rail whose content runs\n * past its box (a segment floor, `SplitFold.segmentFloor`) shows a part of it, moved by the host's offset; the layout's\n * `spines` are content positions, this is what is painted. The drag's hit reads it too, so a point over a rail answers\n * the pane painted there. Pure. See docs/placement.md, Entry: tiling, \"A folding split tree\".\n */\nimport { contains, type Point, type Rect } from \"../geometry\";\nimport type { SplitFoldGeometry } from \"./fold\";\n\n/** What a painted rail reads of a layout: its segments and its folds (a `SplitLayout`, or a drag's `TilingLaidOut`). */\nexport interface FoldedLayout<K> {\n readonly spines: ReadonlyMap<K, Rect>;\n readonly folds: readonly SplitFoldGeometry<K>[];\n}\n\n/**\n * How far a rail's content is moved along its edge, px, from the rail box's top or left (on a right-to-left page too:\n * the host converts). Asked with the fold heading the rail (`folds[railOf]`) and its index in `folds`, the host's key\n * for the rail. Not clamped: a segment moved past the box is cut, or not painted. A value that is not a finite number\n * reads 0.\n */\nexport type RailOffset<K> = (rail: SplitFoldGeometry<K>, index: number) => number;\n\n/** The offset of the rail headed by `folds[index]`, as read: a finite number, else 0. */\nfunction offsetOf<K>(folds: readonly SplitFoldGeometry<K>[], index: number, railOffset: RailOffset<K> | undefined): number {\n const v = railOffset?.(folds[index]!, index);\n return typeof v === \"number\" && Number.isFinite(v) ? v : 0;\n}\n\n/** `r` moved by `-offset` along a rail of `axis` (a sideways fold's rail runs top to bottom), cut to `box`; null when nothing is left. */\nfunction paint(r: Rect, axis: SplitFoldGeometry<unknown>[\"axis\"], offset: number, box: Rect): Rect | null {\n if (axis === \"x\") {\n const y0 = Math.max(r.y - offset, box.y);\n const y1 = Math.min(r.y - offset + r.height, box.y + box.height);\n return y1 > y0 ? { x: r.x, y: y0, width: r.width, height: y1 - y0 } : null;\n }\n const x0 = Math.max(r.x - offset, box.x);\n const x1 = Math.min(r.x - offset + r.width, box.x + box.width);\n return x1 > x0 ? { x: x0, y: r.y, width: x1 - x0, height: r.height } : null;\n}\n\n/**\n * Each spine segment of `layout` as it is painted: moved by its rail's offset along the rail (`railOffset`, default 0\n * everywhere) and cut to the rail's box; a segment wholly off the box is absent. Where a rail's content fits its box\n * and the offset is 0, this is `layout.spines`. Pure: every call reads the offsets anew.\n */\nexport function paintedSpines<K>(layout: FoldedLayout<K>, railOffset?: RailOffset<K>): Map<K, Rect> {\n const out = new Map<K, Rect>();\n const offsets = new Map<number, number>();\n for (const fold of layout.folds) {\n const head = layout.folds[fold.railOf]!;\n let offset = offsets.get(fold.railOf);\n if (offset === undefined) offsets.set(fold.railOf, (offset = offsetOf(layout.folds, fold.railOf, railOffset)));\n for (const pane of fold.panes) {\n const r = layout.spines.get(pane);\n if (!r) continue;\n const painted = paint(r, head.axis, offset, head.rail);\n if (painted) out.set(pane, painted);\n }\n }\n return out;\n}\n\n/**\n * The rail whose box holds `point` (the index of the fold heading it) and the pane painted there, null in a gap or\n * past the last segment; null when no rail's box holds it. @internal Read by the drag's hit.\n */\nexport function railAt<K>(layout: FoldedLayout<K>, point: Point, railOffset?: RailOffset<K>): { readonly rail: number; readonly pane: K | null } | null {\n const rail = layout.folds.findIndex((f, i) => f.railOf === i && contains(f.rail, point, 0));\n if (rail < 0) return null;\n for (const [pane, r] of paintedSpines(layout, railOffset)) {\n if (layout.folds.some((f) => f.railOf === rail && f.panes.includes(pane)) && contains(r, point, 0)) return { rail, pane };\n }\n return { rail, pane: null };\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 * - **A painted strip is read as painted and moves nothing** (under a fold). The frame on screen is the lift on the lift\n * basis; on the base basis it follows the hold: the base with nothing held, the lift at home, `after(held)` for a\n * place. Over a rail of that frame, at the host's offset, the read names the pane painted there and the frame stays:\n * on the lift basis nothing is held (the lift is drawn whatever is held), on the base basis the hold stays as it was\n * (home stays home, a held place stays held and a release commits it as previewed, nothing stays nothing). Off the\n * frame's rails the hold follows the basis's zone map, and a rail of the basis that frame does not paint plays no\n * part: a hold inside its own keep stays, and the place is the map's. With nothing held the frame is the basis's\n * layout, so its strips take no drop. Strips are read from the frame on screen; places from the basis's map.\n * - **A pane you see folded takes no drop** (under a fold, on the base basis). The hold does not change to a place\n * whose pane is a strip both at the lift and in the frame drawn for the hold, unless the hold is already a place of\n * that pane; where such a place is refused the hold stays as it is, and so does its frame. Off the strip the read\n * names no strip (`folded` is null). It is one check on the place's pane, no geometry: a pane open at the lift, a\n * pane the frame draws open (with nothing held the base is drawn), the lift basis and a layout without a fold are\n * held as before. So the place beside such a pane is reached only from a frame that draws it open.\n * - **Where the hold starts**: a hit made at a pickup starts at home: make it with `start: \"home\"`. A hit made in\n * mid-drag starts from nothing held. The start applies once, to the first step of the drag's one hold; with no home it\n * is nothing held, so a host never branches on `home`. The resolved cap is `hit.cap`, beside the edge measure\n * (`hit.intent.tuning.band`).\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 { railAt, type RailOffset } from \"./painted\";\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 * Where the drag's one hold starts. A hit made at a pickup starts at home: make it with `start: \"home\"`. A hit made\n * in mid-drag starts from nothing held. Left out, the hold starts from nothing held; with `\"home\"` its first step is\n * the hold rule from home taken at that point (`hold({ place: \"home\", from: point }, point)`), and with no home\n * (`TilingHit.home` is null) it starts from nothing held as well. The start applies once, to the first step; a later\n * read never applies it again. The pure `hold(state, point)` does not read it.\n */\n readonly start?: \"home\";\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/**\n * A point over a rail of a folding layout (`SplitLayout.folds`): the rail (the index in the basis's `folds` of the fold\n * heading it) and the pane whose spine segment is painted there (`paintedSpines`), null in a gap or past the last\n * segment. A rail takes no drop: the whole of its box is refused.\n */\nexport interface TilingFolded<K> {\n readonly rail: number;\n readonly pane: K | null;\n}\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 * Under a fold, the rail under the pointer in the frame drawn for the hold the read started from, and the pane\n * painted there; null off every rail of that frame. There the frame stays: nothing is held on the lift basis, and on\n * the base basis the hold is the one the read started from.\n */\n readonly folded: TilingFolded<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 /**\n * The options for a drag intent (`createDragIntent({ ...hit.intent })`). Its `tuning.band` is the edge measure the\n * hit resolved, px.\n */\n readonly intent: TilingHitIntent<K>;\n /**\n * The cap the hit resolved: the most either measure is of the held zone's extent, per axis (`TilingHitOptions.cap`,\n * default 0.25, never below 0). Read-only; the edge measure beside it is `intent.tuning.band`.\n */\n readonly cap: number;\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 /**\n * The hold rule: what is held at `point` after `state` (null: nothing held yet). Pure: a host with no intent steps it\n * itself. On the base basis it never changes to a place of a pane drawn as a strip at the lift and in the frame drawn\n * for `state`, unless `state` is already a place of that pane; there it stays `state`.\n */\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, the lift basis's mark, and the rail under the pointer. */\n read(frame: TilingHitFrame<TilingHitTarget<K>>, point: Point): TilingHitRead<K>;\n /**\n * Under a fold, with nothing held: the rail of the frame drawn then (the basis's layout) whose box holds `point`, and\n * the pane painted there at the drag's `railOffset`, read anew at every call; null off every rail. Pure. During a drag\n * the strip under the pointer is `read(...).folded`, read from the frame drawn for the hold.\n */\n foldedAt(point: Point): TilingFolded<K> | null;\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 /** The host's offset of each rail of the frame drawn (`TilingDragOptions.railOffset`). */\n readonly railOffset?: RailOffset<K>;\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 // Under a fold, the panes the base folds: one the lift draws open is still a target there, every place refused `folded`.\n const baseFolded = new Set(base.folds.flatMap((f) => f.panes));\n // The rails of a frame: a box takes no drop, wherever its segments are painted. The host's offsets are asked with the\n // folds of the frame drawn, at every call, never kept.\n const offsets: RailOffset<K> | undefined = ctx.railOffset;\n /** Whether `p` lies in a rail box of `frame` (its edges included). */\n const onRailOf = (frame: TilingLaidOut<T, K>, p: Point): boolean => frame.folds.some((f, i) => f.railOf === i && inside(f.rail, p));\n /** The basis's rails: what the zone map refuses, with nothing held. */\n const onRail = (p: Point): boolean => onRailOf(laid, p);\n /** The rail of `frame` at `p` and the pane painted there, at the host's offsets; null off its rails. */\n const foldedIn = (frame: TilingLaidOut<T, K>, p: Point): TilingFolded<K> | null => (onRailOf(frame, p) ? railAt(frame, p, offsets) : null);\n const foldedAt = (p: Point): TilingFolded<K> | null => foldedIn(laid, p);\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\n * member; on the lift, a pane the base folds is itself too (its places are refused `folded`, so a host can show it).\n */\n const atOf = (pane: K): K | null => {\n if (base.layout.has(pane) || baseFolded.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) || baseFolded.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 subject folded at the lift (carried in) opens on any drop, so no place is home for it, however alike.\n const carriedIn = lift.spines.has(subjectDrawn);\n /** A live place whose release has the lift's arrangement: it is home (never for a subject folded at the lift). */\n const homeLike = (p: Place<K>): boolean => {\n if (p === homePlace) return true;\n if (carriedIn) return false;\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 /**\n * The topmost live place at `p` on the basis's map (no hold, home-likeness not applied), and the refused place it fell\n * through. It reads no rail: strips are read from the frame on screen (`hold`, `placeAt` with nothing held).\n */\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 // With nothing held the frame drawn is the basis's layout: its rails take no drop, their edges included (where an open\n // pane's edge meets one).\n const placeAt = (p: Point): string | null => (onRail(p) ? 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 /**\n * The frame drawn for `state`: the lift on the lift basis; on the base basis the base with nothing held, the lift at\n * home, `after(held)` for a place.\n */\n const frameOf = (state: TilingHold | null): TilingLaidOut<T, K> => {\n if (basis === \"lift\") return lift;\n if (state === null) return base;\n if (state.place === \"home\") return lift;\n const place = byId.get(state.place);\n return place ? after(place.held) : base;\n };\n /** The pane a place names (beside it, a swap with it, a join to it); null for home. */\n const paneOf = (place: Place<K>): K | null => (place.held.kind === \"home\" ? null : place.held.at);\n /**\n * A pane you see folded takes no drop: on the base basis, whether the hold from `state` may not change to `place`\n * because the pane it names is a strip both at the lift and in the frame drawn for `state`, and `state` is not\n * already a place of that pane. A pane open at the lift, or drawn open in that frame, is not refused.\n */\n const seenFolded = (state: TilingHold | null, place: Place<K>): boolean => {\n if (basis !== \"base\") return false;\n const pane = paneOf(place);\n if (pane === null || !lift.spines.has(pane)) return false;\n const held = state === null ? null : byId.get(state.place);\n if (held && paneOf(held) === pane) return false;\n return frameOf(state).spines.has(pane);\n };\n const hold = (state: TilingHold | null, p: Point): TilingHold | null => {\n // A painted strip moves nothing: over a rail of the frame drawn for `state` the frame stays. The lift basis draws the\n // lift whatever is held, and holds nothing there; on the base basis the hold stays, so its frame does. With nothing\n // held that frame is the basis's layout, so its strips take no drop.\n if (onRailOf(frameOf(state), p)) return basis === \"lift\" ? null : state;\n // Strips are read from the frame on screen; places from the basis's map. Off that frame's rails a rail of the basis\n // plays no part: a hold inside its own keep stays, and the place is the map's.\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 // A pane you see folded takes no drop: the hold stays as it is (its frame with it).\n if (now && seenFolded(state, now)) return state;\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 // `start: \"home\"` holds home before the first step, once; with no home the hold starts from nothing held.\n let startAtHome = options.start === \"home\" && home !== null;\n // The hold the step at the last point started from: its frame is the one the pointer was over.\n let stepFrom: 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 if (startAtHome) {\n startAtHome = false;\n state = { place: \"home\", from: { x: p.x, y: p.y } };\n }\n stepFrom = state;\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 // The strip painted under the pointer in the frame it was over; there the hold stayed, whatever target the intent\n // shows (the frame does not move).\n const folded = foldedIn(frameOf(stepFrom), p);\n const kept = folded !== null && basis === \"base\";\n const shown = place && place !== homePlace && (kept || (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 || folded ? null : (rawAt(p).refused?.held ?? null);\n return { held, refused, mark: basis === \"lift\" && shown ? markOf(shown) : null, folded };\n };\n\n return {\n basis,\n home: home ? { ...home } : null,\n cap,\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 foldedAt,\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, and the host's\n * `fold`). Under a fold every layout of the drag is folded with its own order (`TilingLaidOut.order`), so the drag hits\n * and judges the rects the host draws.\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 type { SplitFoldGeometry } from \"./fold\";\nimport { createTilingHit, type TilingBasis, type TilingHit, type TilingHitOptions } from \"./hit\";\nimport type { RailOffset } from \"./painted\";\nimport { layoutSplitTree, withOrder, type FoldingSplitOptions } from \"./tree-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/**\n * What `tilingDrag` reads: the adapter, the stage, and the layout options (`SplitOptions` plus `min`, the least pane\n * width and height a drop keeps, and `fold`, as `layoutSplitTree` takes it). `fold.order` is the lift's order: the\n * drag derives the base's and each change's from it.\n */\nexport interface TilingDragOptions<T, K> extends DropOptions<K>, FoldingSplitOptions<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 * Under a fold whose rails' content runs past their boxes (`SplitFold.segmentFloor`), how far the host has moved each\n * rail of the frame it draws (`RailOffset`): asked with the folds of the frame drawn for the hold being read (the\n * lift on the lift basis; on the base basis the base with nothing held, the lift at home, `after(held)` for a place),\n * the fold heading the rail and its index in that frame's `folds`. The index is that frame's own, so a host whose\n * frames differ keys each rail by the fold's `id` (the folded split's own `id`); a fold with no `id` has no key that\n * stays the same across frames. Read at every hit read\n * (`hit.read`, `hit.foldedAt`), never kept: an offset change, and every change of the frame drawn, is a reason to read\n * again. Pass the hold whose frame is painted: a read between a hold change and its paint asks for rails not drawn\n * yet. Not clamped; a value that is not a finite number reads 0. Default: 0 everywhere.\n */\n readonly railOffset?: RailOffset<K>;\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) or when the lift folds the\n * subject (its spine segment is no gap: the pointer over it reads the spine).\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)`. Under a fold, on the base basis, a pane you see folded takes no\n * drop: the hold does not change to a place of a pane drawn as a strip at the lift and in the frame drawn for the\n * hold, unless it already holds a place of that pane. A hit made at a pickup starts at home: make it with\n * `start: \"home\"`. A hit made in mid-drag starts from nothing held.\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/** Every pane a layout folds: its folds' panes (on a spine, or showing nothing). */\nconst foldedOf = <K>(folds: readonly SplitFoldGeometry<K>[]): Set<K> => new Set(folds.flatMap((f) => f.panes));\n\n/** The keys of `lists`, in turn, each once. */\nfunction keyed<K>(lists: readonly (readonly K[])[]): K[] {\n const out = new Set<K>();\n for (const list of lists) for (const k of list) out.add(k);\n return [...out];\n}\n\n/** The order \"the panes `laid` draws open, in its order (then any its order does not name), then the rest of its order\". */\nconst openFirst = <T, K>(laid: TilingLaidOut<T, K>): K[] => keyed([laid.order.filter((k) => laid.layout.has(k)), [...laid.layout.keys()], laid.order]);\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 whether `at` is drawn open there) and on the change's own layout\n * (fit), never on another tree.\n * - **Under a fold** (`options.fold`) every layout is folded with its own order: the lift with the host's, the base\n * with the panes open at the lift first (a torn tab's stack mates in its place), each change with the subject first,\n * then the panes open at the lift. A pane\n * the base folds is refused `folded`; there is no room rule (the one verdict on room is `fit` on the change's\n * layout, where the subject must be drawn open and `at` may fold). The subject may be folded at the lift (a pane\n * carried in): its lift rect is then its spine segment and `home` is null.\n *\n * Throws when the subject is not in `tree` (neither drawn, open or on a spine, nor a member of a drawn stack): a drag\n * 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, order: readonly K[]): TilingLaidOut<T, K> => {\n const { panes, splits, spines, folds } = layoutSplitTree(ops.split(t), area, withOrder(options, order));\n return { tree: t, layout: panes, splits, spines, folds, order: options.fold ? order : [] };\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, options.fold?.order ?? []);\n const liftKey = drawnAs(tree, subjectKey);\n // Folded at the lift (a pane carried in, held as a spine), the subject's lift rect is its spine segment.\n const liftRect = lift.layout.get(liftKey) ?? lift.spines.get(liftKey);\n if (!liftRect) {\n const what = subject.kind === \"pane\" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`;\n const drawn = options.fold ? \"drawn (open or on a spine)\" : \"drawn\";\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 // A tab torn out of a stack leaves its mates in its slot: they take its place in the order too, so the slot folds or\n // stays open as it did at the lift.\n const mates = subject.kind === \"pane\" ? (stackOf(tree, subjectKey)?.members ?? []).filter((m) => m !== subjectKey) : [];\n const liftOrder = openFirst(lift);\n const baseOrder: readonly K[] = keyed([liftOrder.flatMap((k) => (k === liftKey ? [k, ...mates] : [k])), mates]);\n const base = lay(ops.release(tree, subject), baseOrder);\n const takesPane = panesOf(ops.split(base.tree)).length < panesOf(ops.split(tree)).length;\n const home = takesPane && lift.layout.has(liftKey) ? { ...liftRect } : null;\n const liftFolded = foldedOf(lift.folds);\n const baseFolded = foldedOf(base.folds);\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 /** Under a fold, the panes `laid` opens and closes against the lift. */\n const foldChangesIn = (laid: TilingLaidOut<T, K>): { readonly opened: readonly K[]; readonly closed: readonly K[] } => {\n if (!options.fold) return { opened: [], closed: [] };\n const folded = foldedOf(laid.folds);\n return { opened: [...laid.layout.keys()].filter((k) => liftFolded.has(k)), closed: [...lift.layout.keys()].filter((k) => folded.has(k)) };\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 baseFolded.has(at) ? { code: \"folded\" } : { 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: [], opened: [], closed: [] });\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: [], opened: [], closed: [] };\n // Under a fold the base's rects are not the change's: room is judged by `fit` alone, on the change's own layout.\n const before = refusalBefore(held) ?? (held.kind === \"beside\" && !options.fold ? 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 changedTree = normalize(changed);\n const own = drawnAs(changedTree, subjectKey);\n // Open first: the subject, then the panes open at the lift, then the rest.\n const candidateOrder = keyed([[own], baseOrder]);\n const laid = lay(changedTree, candidateOrder);\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 // under a fold the subject must be drawn open, and `at` may fold (then it is not judged).\n // `side` only words `dropFits`' reason, which is not read here.\n const partner = drawnAs(laid.tree, held.at);\n const fits = dropFits(laid.layout, own, partner, area, {\n min: options.min,\n side: held.kind === \"beside\" ? held.side : \"left\",\n ...(options.fold ? { folded: foldedOf(laid.folds) } : {}),\n });\n if (!fits.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), ...foldChangesIn(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<K, TilingAfter<T, K>>()));\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 } : {}), ...(options.railOffset ? { railOffset: options.railOffset } : {}), after, lay: (t: T) => lay(t, baseOrder), 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, withOrder } from \"./tree-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 and the lift draws the subject open, else null (a subject on a spine has none). */\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 /**\n * `after(held).layout` is `after(held).tree` laid out (under a fold with `after(held).order`, its spines and folds\n * too); the landing is the subject's rect there, drawn open (home's, for a subject on a spine at the lift: its\n * segment); a refused place is the lift.\n */\n \"one-layout\",\n /** Under a fold, every pane the base folds is refused `folded` for every kind of place (a swap with the stack a tab is torn from stays `self`). */\n \"folded-refused\",\n /**\n * A swap puts the partner in the subject's lift rect and the subject in the partner's, and the others keep theirs.\n * Not checked under per-child layout callbacks (`fixed`, `fixedAcross`, `floor`), which may move the ratios, nor\n * under a fold (a swap can change which pane comes first, and so which side of a fold shows).\n */\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\n/** A held place in words, for a failure. @internal */\nexport const showHeld = (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}` : \"\"}`;\nconst show = showHeld;\n\n/**\n * Whether the lift draws `subject` (open, or on a spine): under a fold a pane that shows nothing (weight 0) and is\n * folded is drawn nowhere, so it cannot be lifted. @internal\n */\nexport function liftable<T, K>(tree: T, subject: TilingSubject<K>, options: TilingDragOptions<T, K>): boolean {\n if (!options.fold) return true;\n const { ops } = options;\n const key = subject.kind === \"pane\" ? subject.pane : subject.stack.active;\n const drawn = ops.stackOf?.(tree, key)?.active ?? key;\n const lift = layoutSplitTree(ops.split(tree), options.area, options);\n return lift.panes.has(drawn) || lift.spines.has(drawn);\n}\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, order: readonly K[]) => layoutSplitTree(ops.split(t), area, withOrder(options, order));\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 if (!liftable(tree, subject, options)) continue;\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 // A subject on a spine at the lift leaves no gap: its segment is no home.\n const gap = takes && subjectLift !== undefined;\n check(\"home-is-the-gap\", gap ? near(drag.home, subjectLift, EPS) : drag.home === null, () => `home ${JSON.stringify(drag.home)}, the release ${takes ? \"takes\" : \"takes no\"} drawn pane${subjectLift ? \"\" : \" (the subject is folded at the lift)\"}`);\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 // Under a fold, every pane the base folds, for every kind of place: refused `folded`.\n for (const at of new Set(drag.base.folds.flatMap((f) => f.panes))) {\n const kinds: TilingHeld<K>[] = [{ kind: \"swap\", at }, ...PANE_SIDES.map((side): TilingHeld<K> => ({ kind: \"beside\", at, side })), ...(ops.join ? [{ kind: \"join\", at } as const] : [])];\n for (const h of kinds) {\n const code = drag.after(h).refusal?.code;\n // A swap with the stack a tab is torn from is the subject's own place: `self`, folded or not.\n const own = h.kind === \"swap\" && subject.kind === \"pane\" && !!ops.stackOf && ops.stackOf(tree, subject.pane)?.id === ops.stackOf(tree, at)?.id && !!ops.stackOf(tree, at);\n check(\"folded-refused\", code === \"folded\" || (own && code === \"self\"), () => `${show(h)}: the base folds ${String(at)}, refused ${code ?? \"nothing\"}`);\n }\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 const again = lay(a.tree, a.order);\n // Home of a subject on a spine at the lift lands where it was: its segment.\n const lands = near(a.landing, h.kind === \"home\" ? (a.layout.get(own) ?? a.spines.get(own)) : a.layout.get(own), EPS);\n check(\n \"one-layout\",\n sameData(a.layout, again.panes) && sameData(a.spines, again.spines) && sameData(a.folds, again.folds) && lands,\n () => `${show(h)}: the layout or the landing is not after().tree's, laid out with after().order`,\n );\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. Under a fold a\n // swap can change which pane comes first, and so which side of a fold shows: not checked either.\n if (h.kind === \"swap\" && !callbacks && !options.fold) {\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, withOrder } from \"./tree-layout\";\nimport { paintedSpines } from \"./painted\";\nimport { PANE_REGION_DEFAULTS } from \"./regions\";\nimport type { Split } from \"./split\";\nimport { liftable, propertyTally, showHeld, 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, unless the map's place there names a pane drawn as a strip at\n * the lift and in the frame drawn for the place (a pane you see folded takes no drop).\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 (never for a subject folded at the lift: any drop opens it). */\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 /**\n * Under a fold, a painted strip is read as painted and moves nothing, in every frame: for each hold and the frame drawn\n * for it (the lift on the lift basis; on the base basis the base with nothing held, the lift at home, `after(held)`),\n * every point of that frame's rail boxes (edges included) reads `folded` with that rail and the pane painted there\n * (`paintedSpines` at the drag's rail offsets), null in a gap; the frame stays (the lift basis holds nothing, the base\n * basis keeps the hold), a second step changes nothing, a release gives what the frame shows, nothing is refused, and\n * with nothing held there is no place (the rails that take no place are those of the frame drawn for the hold).\n */\n \"spine-no-place\",\n /**\n * Under a fold, on the lift basis, a pane the lift draws open and the base folds (the named case) is a target, and\n * every place on it is refused `folded`: the pointer over it holds nothing and names the refused place.\n */\n \"named-case-refused\",\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 => (h === null ? \"nothing\" : showHeld(h));\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 if (!liftable(tree, subject, options)) continue;\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 // Under a fold: the panes the base folds (a target on the lift basis where the lift draws one open, every place\n // refused), and the basis's rail boxes, which take no place with nothing held (the rails that take no place are\n // those of the frame drawn for the hold, and with nothing held that frame is the basis's layout).\n const baseFolded = new Set(drag.base.folds.flatMap((f) => f.panes));\n const rails = laid.folds.map((f, i) => ({ f, i })).filter(({ f, i }) => f.railOf === i);\n const railOf = (p: Point): number | null => rails.find(({ f }) => inside(f.rail, p))?.i ?? null;\n const atOf = (pane: K): K | null => {\n if (drag.base.layout.has(pane) || baseFolded.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) || baseFolded.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, withOrder(options, laid.order)).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 subject folded at the lift opens on any drop: no place gives the lift back.\n const carriedIn = drag.lift.spines.has(subjectDrawn);\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 if (carriedIn) return false;\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 (railOf(p) !== null) return { raw: null, refused: null, box: null, pane: null, tie: false };\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 // Under a fold the layout may fold again around the landing, and a new split's fold floors move the landing's\n // edge without opening or folding anything (counted, not failed).\n if (others || options.fixed || options.fixedAcross || hasMaster || options.fold) {\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)) === 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 || !inside(e.box, z)) continue;\n const ang = rnd() * Math.PI * 2;\n const len = Math.sqrt(rnd()) * 0.9;\n const p = { x: z.x + Math.cos(ang) * ex * len, y: z.y + Math.sin(ang) * ey * len };\n // A rail holds nothing (spine-no-place): not a point of a place's measure.\n if (railOf(p) === null) path.push(p);\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)) && railOf(p) === null) 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 a strip of the frame drawn for the place, the place stays by the strip rule (spine-no-place), not a measure.\n const shownFrame = basis === \"lift\" ? drag.lift : drag.after(hit.heldOf(taken.place)!);\n if (shownFrame.folds.some((f, i) => f.railOf === i && inside(f.rail, p))) continue;\n // A pane you see folded takes no drop: where the map's place names a pane drawn as a strip at the lift and in that\n // frame, the place stays by that rule, not a measure.\n const mapHeld = hit.placeAt(p) === null ? null : hit.heldOf(hit.placeAt(p)!);\n const takenHeld = hit.heldOf(taken.place);\n if (basis === \"base\" && mapHeld && mapHeld.kind !== \"home\" && drag.lift.spines.has(mapHeld.at) && shownFrame.spines.has(mapHeld.at) && !(takenHeld && takenHeld.kind !== \"home\" && takenHeld.at === mapHeld.at)) 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 // ---- spine-no-place: a painted strip is read as painted and moves nothing, in every frame. For each hold S (nothing,\n // home, and places held at sample points) and the frame F drawn for it (`frameFor`), every point of F's rail boxes,\n // corners and edges included: the read names F's rail and the pane `paintedSpines(F, railOffset)` paints there (null\n // in a gap); the hold after it draws F again (the lift basis holds nothing, its frame is the lift whatever is held;\n // the base basis keeps S), and a second step at the point changes nothing; a release gives what F shows (the lift\n // tree from nothing or home, `after(S)` from a place); nothing is refused there; with nothing held there is no place.\n const frameFor = (s: TilingHold | null) =>\n basis === \"lift\" ? drag.lift : s === null ? drag.base : s.place === \"home\" ? drag.lift : drag.after(hit.heldOf(s.place)!);\n const holdStates: (TilingHold | null)[] = [null];\n if (home) holdStates.push({ place: \"home\", from: { x: home.x + home.width / 2, y: home.y + home.height / 2 } });\n const heldPlaces = new Set<string>();\n for (const q of samples) {\n if (heldPlaces.size >= 6) break;\n const s = hit.hold(null, q);\n if (s && s.place !== \"home\" && !heldPlaces.has(s.place)) {\n heldPlaces.add(s.place);\n holdStates.push(s);\n }\n }\n for (const s of holdStates) {\n const F = frameFor(s);\n const railsOfF = F.folds.map((f, i) => ({ f, i })).filter(({ f, i }) => f.railOf === i);\n if (railsOfF.length === 0) continue;\n const painted = paintedSpines(F, options.railOffset);\n // The stateful hit, brought to S: nothing held, then S's own point.\n const enter = (): boolean => {\n frame(FAR);\n if (s === null) return true;\n const r = frame(s.from);\n return s.place === \"home\" ? r.held?.kind === \"home\" : r.held !== null && show(r.held) === show(hit.heldOf(s.place));\n };\n const keeps = basis === \"lift\" ? null : s;\n const wantHeld = keeps === null ? null : keeps.place === \"home\" ? HOME : hit.heldOf(keeps.place);\n for (const { f, i } of railsOfF) {\n const r = f.rail;\n const points: Point[] = [\n { x: r.x, y: r.y },\n { x: r.x + r.width, y: r.y + r.height },\n { x: r.x + r.width / 2, y: r.y },\n { x: r.x, y: r.y + r.height / 2 },\n ];\n for (let k = 0; k < 16; k++) points.push(randomPoint(r));\n for (const p of points) {\n const want = [...painted].find(([pane, q]) => F.folds.some((g) => g.railOf === i && g.panes.includes(pane)) && inside(q, p))?.[0] ?? null;\n const step = hit.hold(s, p);\n const again = hit.hold(step, p);\n const where = `rail ${i} of the frame for ${s ? s.place : \"nothing\"} at ${p.x.toFixed(1)},${p.y.toFixed(1)}`;\n check(\n \"spine-no-place\",\n sameHold(step, keeps) && sameHold(again, keeps) && (s !== null || hit.placeAt(p) === null),\n () => `${where}: the hold went to ${holdName(step)}, then ${holdName(again)}; it stays ${holdName(keeps)} (place with nothing held: ${hit.placeAt(p)})`,\n );\n if (!enter()) continue;\n const read = frame(p);\n const second = frame(p);\n check(\n \"spine-no-place\",\n show(read.held) === show(wantHeld) && read.refused === null && hit.drawn(read) === F && JSON.stringify(second) === JSON.stringify(read),\n () => `${where}: held ${show(read.held)} (stays ${show(wantHeld)}), refused ${show(read.refused)}, the frame ${hit.drawn(read) === F ? \"stays\" : \"moved\"}`,\n );\n const rel = hit.release(read);\n check(\n \"spine-no-place\",\n wantHeld === null || wantHeld.kind === \"home\" ? rel.tree === drag.lift.tree : rel === drag.after(wantHeld),\n () => `${where}: a release commits ${show(rel.held)}, the frame shows ${show(wantHeld)}`,\n );\n const at = s === null ? hit.foldedAt(p) : read.folded;\n check(\n \"spine-no-place\",\n read.folded?.rail === i && read.folded.pane === want && at?.rail === i && at.pane === want,\n () => `${where}: reads ${JSON.stringify(read.folded)}, foldedAt ${JSON.stringify(at)}, painted ${String(want)}`,\n );\n }\n }\n }\n // ---- named-case-refused: on the lift, a pane the lift draws open and the base folds is a target, every place on\n // it refused `folded`; over it nothing is held and the refused place is named.\n if (basis === \"lift\") {\n for (const [pane, r] of drag.lift.layout) {\n // The pane, or what the base draws in its slot (a torn stack's remnant): folded there, it is the named case.\n const at = atOf(pane);\n if (at === null || !baseFolded.has(at)) continue;\n const target = hit.targets.find((t) => !t.part && !t.home && t.pane === pane);\n // A swap with the stack a tab is torn from is the subject's own place (`self`), folded or not.\n const torn = !!stackOf(drag.lift.tree, at) && stackOf(drag.lift.tree, at)?.id === stackOf(drag.lift.tree, subjectKey)?.id;\n const places: TilingHeld<K>[] = [...(torn ? [] : [{ kind: \"swap\", at } as const]), ...([\"top\", \"right\", \"bottom\", \"left\"] as const).map((side): TilingHeld<K> => ({ kind: \"beside\", at, side }))];\n const codes = places.map((h) => drag.after(h).refusal?.code);\n const c = { x: r.x + r.width / 2, y: r.y + r.height / 2 };\n const read = fresh(c);\n check(\n \"named-case-refused\",\n target?.at === at && codes.every((code) => code === \"folded\") && hit.placeAt(c) === null && read.held === null && read.refused !== null,\n () => `${String(pane)}, open at the lift and folded in the base as ${String(at)}: target ${target ? String(target.at) : \"none\"}, refusals ${codes.join(\",\")}, place ${hit.placeAt(c)}, refused ${show(read.refused)}`,\n );\n }\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] as (typeof zonesBefore)[number];\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 no `floor`, `fixed` or `fixedAcross`, and no gap, so the choice follows the tree's shape and its\n * ratios. px floors cannot fit a unit square: every split would be squeezed by its floors, and a px fixed length would\n * take the whole room. 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,OAA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;AACpB,QAAM,aAAa,cAAc,UAAU,cAAc;AAEzD,QAAM,SAAS,CAAC,GAAS,MAAwB,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,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,UAAMU,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":["r","nA","nB","length","px","cross","px","FIT","px","of","cross","within","NO_RAILS","px","usable","otherAxis","isPane","sideEdges","cross","node","laid","unit","at","has","cross","slot","px","near","state","slot","px","lay","stack","x","lay","inside","sameRect","show","check","HOME","n","s","has","clamp","held","probes","places","overlap"]}