@n-uf/placement 26.11.17 → 26.11.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/scene.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/scene/model.ts","../src/scene/solve.ts","../src/scene/changes.ts","../src/scene/store.ts","../src/scene/targets.ts"],"sourcesContent":["/**\n * The scene's shapes: one model of a whole window. A scene is a stage (the window's inner rect), the edges along its\n * sides (bars and columns, each a stack of items), the items, the floats above the content, and the chrome that\n * floats and drop zones keep clear of. `solve(scene)` turns it into a `SceneLayout`: every rect a host draws.\n *\n * Plain data in and out, nothing module-global: two windows on one page are two scenes. No words, no time, no DOM.\n */\nimport type { Rect, Size } from \"../geometry\";\nimport type { CrossLimits, StackFit, StackForm, StackFormKind, StackNote } from \"../stack\";\n\n/** The host's kinds of item, such as \"panel\" and \"group\". An edge takes only the kinds it lists. */\nexport type Kind = string;\n\n/** A side of the stage. Left and right edges are columns (they run down); top and bottom edges are bars (they run across). */\nexport type Side = \"top\" | \"right\" | \"bottom\" | \"left\";\nexport const SIDES: readonly Side[] = [\"top\", \"right\", \"bottom\", \"left\"];\n\n/** Where an item sits along its edge: packed from the start, centred in the spare length, or packed from the end. */\nexport type Zone = \"start\" | \"center\" | \"end\";\nexport const ZONES: readonly Zone[] = [\"start\", \"center\", \"end\"];\n\n/** A float that follows the content: flush with that side or corner of `layout.content` until a drop gives it a real rect. */\nexport type FloatAnchor =\n | \"content-top-left\"\n | \"content-top\"\n | \"content-top-right\"\n | \"content-right\"\n | \"content-bottom-right\"\n | \"content-bottom\"\n | \"content-bottom-left\"\n | \"content-left\";\n\n/** Along which axis an item lies: a column runs down, a row (a bar) runs across. */\nexport type Orient = \"column\" | \"row\";\n\nexport interface SceneItem {\n readonly id: string;\n readonly kind: Kind;\n /**\n * Its forms along a column and along a row (a bar), largest first, as `./stack` takes them. An item with no forms for\n * an axis can't be laid out along it (`no-forms`).\n */\n readonly forms: { readonly column?: readonly StackForm[]; readonly row?: readonly StackForm[] };\n /** How recently it was used: the smaller, the longer ago, the sooner it gives way. */\n readonly used: number;\n /** Kept: gives way after every item that isn't. */\n readonly kept?: boolean;\n /**\n * The first form it may take, an index into the forms of the axis it lies along (default 0). Folding by hand sets it\n * (`fold`). A float with `from` over 0 is drawn as its bar: that form's natural length, at the float's place.\n */\n readonly from?: number;\n /**\n * Reserved room: a title, window controls, a page readout. It never changes form (it keeps `forms[from]`), is never\n * reordered, never dragged, and no hit or slot covers it. Its length may shrink to its form's `main.min` and grow\n * with spare room when the form `grows`; window controls have `min` equal to `natural`.\n */\n readonly fixed?: boolean;\n /** Closed: it keeps its place in its edge (or its float rect) but takes no room and has no targets. */\n readonly closed?: boolean;\n /** Its zone in its edge (default start). */\n readonly align?: Zone;\n /** Its size as a float: `floatAt` with no rect uses it, and a float drop sets it. */\n readonly floatSize?: Size;\n}\n\nexport interface Edge {\n readonly id: string;\n readonly side: Side;\n /** 0 is the outermost on its side (a title bar outside a toolbar). */\n readonly ring: number;\n /**\n * Top and bottom bars only: across the whole stage (`\"full\"`, the default) or between the side columns\n * (`\"between\"`). Left and right edges ignore it.\n */\n readonly span?: \"full\" | \"between\";\n /** The kinds a drop may bring here. Deny by default: an empty list takes nothing (an anchor). */\n readonly accepts: readonly Kind[];\n /** Ids in order, fixed and closed items included. */\n readonly items: readonly string[];\n /** The size it may take across (a column's width, a bar's height), and the rail width when nothing sets it. */\n readonly cross: CrossLimits;\n /** `\"overlay\"` lies over the content instead of shortening it (default `\"reserved\"`). */\n readonly mode?: \"reserved\" | \"overlay\";\n readonly gap?: number;\n readonly pad?: { readonly start?: number; readonly end?: number };\n /** The » entry's length along the edge. */\n readonly menu?: { readonly main: number };\n /**\n * The user's size across (a column dragged wider), clamped to `[max(cross.min, the widest open setter's cross.min),\n * cross.max]`, so an open item's `cross.min` wins over a smaller size. Used only while an item sets the cross size.\n */\n readonly size?: number;\n /** A column drawn as a rail (nothing in it sets its width) shows its closed items too, as tabs marked `closed`. */\n readonly railShowsClosed?: boolean;\n /** The drop strip's depth while the edge is empty, px (default {@link DEFAULT_STRIP}). */\n readonly strip?: number;\n /**\n * How a gap's hit runs along the edge. A number: a band that many px around the gap's insertion line (the first and\n * last also reach `endReach` past the edge's ends), clamped so neighbouring bands never overlap, so the body of an item\n * away from its edges is no gap and the pointer falls through to the float target, or to none. `\"middle\"`: the edge\n * split halfway between neighbouring lines, so every point of it is some gap. Default {@link DEFAULT_HIT_BAND} for left\n * and right edges, `\"middle\"` for bars.\n */\n readonly hitBand?: number | \"middle\";\n /**\n * A dynamic column (left and right only): made by a drop on a column line, deleted when it holds no item, folded whole\n * into its side's rail by give-way (`Scene.contentMin`) or when every member is folded by hand. Its `accepts`,\n * `cross`, `gap`, `pad` and `menu` come from `Scene.columns[side]` when the changes make it.\n */\n readonly column?: boolean;\n}\n\n/** What a side's new columns are made from. */\nexport interface ColumnTemplate {\n readonly accepts: readonly Kind[];\n readonly cross: CrossLimits;\n readonly gap?: number;\n readonly pad?: { readonly start?: number; readonly end?: number };\n readonly menu?: { readonly main: number };\n}\n\n/** A side's one rail strip: folded columns show in it as segments, in ring order. */\nexport interface RailSpec {\n /** Its width, px. */\n readonly width: number;\n /** The kinds a drop on the rail may bring (it docks folded). */\n readonly accepts: readonly Kind[];\n}\n\nexport interface SceneFloat {\n readonly id: string;\n /** Its rect in stage px (it never scrolls with the content). With `anchor`, only its size counts. */\n readonly rect: Rect;\n /** Follow the content's side or corner until a drop gives it a real rect. */\n readonly anchor?: FloatAnchor;\n /** Which of the item's forms it uses (default `\"column\"`). */\n readonly orient?: Orient;\n}\n\nexport interface Scene {\n /** The window's inner rect. */\n readonly stage: Rect;\n readonly edges: readonly Edge[];\n readonly items: Readonly<Record<string, SceneItem>>;\n /** Stacking order: the last is on top. */\n readonly floats: readonly SceneFloat[];\n /** The kinds that may float. Deny by default. */\n readonly floatKinds: readonly Kind[];\n /** Rects that floats and drop zones keep clear of (a title the host draws itself, a status line). */\n readonly chrome?: readonly Rect[];\n /** Spots where a release cancels: `targets` gives a `none` target over each. */\n readonly blocked?: readonly Rect[];\n /** Per side (left, right): what a new column is made from. A side without one gets no new columns. */\n readonly columns?: Partial<Record<\"left\" | \"right\", ColumnTemplate>>;\n /** Per side (left, right): its rail. A side without one keeps folded columns as columns. */\n readonly rails?: Partial<Record<\"left\" | \"right\", RailSpec>>;\n /**\n * The least the content may be. While the content is narrower than `width`, dynamic columns shrink toward their\n * minimum, then fold whole into their side's rail: unkept before kept, the one whose newest use is oldest first, the\n * outer first, the left first. Under `height`, a `content-short` note.\n */\n readonly contentMin?: { readonly width: number; readonly height: number };\n /**\n * How a one-panel column folded by hand shows (default `\"bar\"`): `\"bar\"` sends it to its side's rail; `\"ride\"` draws it\n * as a title bar over the first open column of its side, at that column's width, taking no width of its own.\n */\n readonly handFold?: \"bar\" | \"ride\";\n /** Space kept clear inside the stage's edges, px (default 0 each). */\n readonly inset?: { readonly top?: number; readonly right?: number; readonly bottom?: number; readonly left?: number };\n /** Space after each left or right edge and each rail that takes room, toward the content, px (default 0). */\n readonly gutter?: number;\n}\n\n/** An item as laid out. */\nexport interface SceneItemLayout {\n /** Stage px. An item in the » menu has the menu entry's rect. */\n readonly rect: Rect;\n readonly kind: Kind;\n /** The form it took: an index into the forms of its axis. */\n readonly form: number;\n readonly formKind: StackFormKind;\n /** Docked: its edge and zone. */\n readonly edge?: string;\n readonly zone?: Zone;\n readonly floating?: boolean;\n readonly inMenu?: boolean;\n /** A rail tab (its column is a rail). */\n readonly tab?: boolean;\n /** A closed item shown as a rail tab (`railShowsClosed`). */\n readonly closed?: boolean;\n readonly fixed?: boolean;\n /** Drawn as a segment of this side's rail (its column is folded). */\n readonly rail?: \"left\" | \"right\";\n /** Drawn as a title bar riding on this column (`handFold: \"ride\"`). */\n readonly rides?: string;\n /** Its column folded: by hand (every member folded) or by give-way. */\n readonly folded?: \"hand\" | \"auto\";\n}\n\n/** An edge as laid out. */\nexport interface SceneEdgeLayout {\n readonly side: Side;\n readonly ring: number;\n /** Stage px: the strip it takes (zero across when nothing is drawn in it). */\n readonly rect: Rect;\n /** Its size across. */\n readonly cross: number;\n /** Its » entry and the items in it, or null. */\n readonly menu: { readonly rect: Rect; readonly items: readonly string[] } | null;\n /** The ids drawn as rail tabs, in order (empty unless the column is a rail). */\n readonly tabs: readonly string[];\n /**\n * The stack fits behind it, in stack-local px: `stack` is the one drawn, `free` the first fit (before `size` or the\n * rail re-solved it). `solve`'s `previous` reads both; a host needs neither.\n */\n readonly stack: StackFit;\n readonly free: StackFit;\n /** A dynamic column folded into its side's rail (its rect is zero wide there): by hand or by give-way. */\n readonly folded?: \"hand\" | \"auto\";\n /** Shrunk by give-way below the width it asks for. */\n readonly shrunk?: boolean;\n /** Riding on this column (its rect is the bars'). */\n readonly rides?: string;\n}\n\n/** A side's rail as laid out. */\nexport interface SceneRailLayout {\n readonly rect: Rect;\n /** One per member of each folded column, in ring order. */\n readonly segments: readonly { readonly id: string; readonly edge: string; readonly rect: Rect }[];\n}\n\n/**\n * Why the layout looks as it does:\n * - a stack's note with its `edge` (`form-down`, `to-menu`, `too-wide`, `no-forms`, `overflow`);\n * - `unknown-item`: an id in an edge or a float that `items` lacks (left out);\n * - `twice`: an item placed in two places (the first in cut order wins, edges before floats);\n * - `float-clamped`, `float-moved`: a float was moved into the stage, or clear of what it would cover;\n * - `float-covers`: no clear place exists, and it covers the least it can.\n * - `column-shrunk`, `column-folded`, `kept-folded`: give-way by `contentMin.width`, in give-way order;\n * - `content-narrow`, `content-short`: the content is still under `contentMin` (overlay bars count against the height).\n * - `content-changed`: under `previous`, `content` is not the rect `previous.content` was (`from`, `to`). A host refits\n * its zoom only on this note.\n */\nexport type SceneNote =\n | ({ readonly edge: string } & StackNote)\n | { readonly code: \"unknown-item\"; readonly id: string }\n | { readonly code: \"twice\"; readonly id: string }\n | { readonly code: \"float-clamped\" | \"float-moved\" | \"float-covers\"; readonly id: string }\n | { readonly code: \"column-shrunk\"; readonly edge: string; readonly from: number; readonly to: number }\n | { readonly code: \"column-folded\" | \"kept-folded\"; readonly edge: string }\n | { readonly code: \"content-narrow\"; readonly width: number; readonly min: number }\n | { readonly code: \"content-short\"; readonly height: number; readonly min: number }\n | { readonly code: \"content-changed\"; readonly from: Rect; readonly to: Rect };\nexport type SceneNoteCode = SceneNote[\"code\"];\n\nexport interface SceneLayout {\n /** Every item drawn (closed items only when shown as rail tabs). */\n readonly items: Readonly<Record<string, SceneItemLayout>>;\n readonly edges: Readonly<Record<string, SceneEdgeLayout>>;\n /** What is left for the content (the pages). Overlay edges lie over it. */\n readonly content: Rect;\n /** The floats drawn, in stacking order (the last on top). */\n readonly floats: readonly string[];\n /** The rails shown (a side with a folded column). */\n readonly rails: Readonly<Partial<Record<\"left\" | \"right\", SceneRailLayout>>>;\n readonly notes: readonly SceneNote[];\n}\n\nexport interface SolveOptions {\n /**\n * The layout the scene had before: each edge's fit goes to `fitStack` as `previous`, so a press reshapes nothing. An\n * item docked now that was closed or absent then has just opened: it counts as the newest (its largest form while it\n * fits; the others give way by the usual rules), and its column is weighed anew by give-way.\n */\n readonly previous?: SceneLayout;\n /** Edge or item ids solved without `previous` (an edge, or the edges holding the item; a column weighed anew). */\n readonly fresh?: readonly string[];\n}\n\n/** A drop strip's depth inside the content while an edge is empty, px. */\nexport const DEFAULT_STRIP = 24;\n/** A column's gap hit: a band this many px around each gap's insertion line. */\nexport const DEFAULT_HIT_BAND = 24;\n/** A float's size when neither the item nor the call gives one, px. */\nexport const DEFAULT_FLOAT_SIZE: Size = { width: 280, height: 360 };\n\n/** The axis an edge's stack runs along. */\nexport const axisOf = (side: Side): Orient => (side === \"left\" || side === \"right\" ? \"column\" : \"row\");\nexport const zoneOf = (item: SceneItem | undefined): Zone => (item?.align === \"center\" || item?.align === \"end\" ? item.align : \"start\");\nexport const formsOf = (item: SceneItem, axis: Orient): readonly StackForm[] => item.forms[axis] ?? [];\n","/**\n * `solve(scene, { previous })`: the whole window's layout from one scene.\n *\n * 1. **The cut.** Reserved edges cut the stage from the outside in: first the full-span bars (top, then bottom, each\n * by ring), across the stage's whole width; then the columns (left, then right, by ring), down the height the full\n * bars left; then the `between` bars, across the width the columns left. What remains is `content`. Overlay edges\n * are cut the same way from a copy of the content, so they lie over it without shortening it.\n * 2. **Each edge is a stack** (`fitStack`): a column along the height it gets, a bar along the width, with each item's\n * `forms.column` or `forms.row`. Items are taken in zone order (start, center, end); `fixed` items keep their form;\n * closed items take no room. In a column, group forms take their own width (`ownCross`). The edge's thickness is\n * the stack's cross size; an edge with nothing in it takes none.\n * 3. **Rail and size.** A column in which nothing sets the width is a rail: its items with a `rail` form are re-solved\n * in it and listed as `tabs` (closed ones too with `railShowsClosed`). Otherwise, with `Edge.size`, the column is\n * re-solved at the user's size, clamped to `[max(cross.min, the widest open setter's cross.min), cross.max]`.\n * 4. **Zones.** When the items leave spare length (nothing grows), start items pack from the start, end items from the\n * end (before the » entry) and center items sit centred on the edge's middle, moved only as far as they must to\n * stay between the other two zones.\n * 5. **Floats** are fitted inside the stage, clear of every docked item (fixed ones and » entries included), every bar\n * and the chrome rects (`fitFloat`). An anchored float sits flush with that side or corner of `content` first. A\n * float with `from` over 0 is its bar: its form's natural length along its `orient`, its other size kept.\n *\n * 6. **Dynamic columns** (`Edge.column`, on a side with `Scene.rails[side]`): while the content is narrower than\n * `contentMin.width` (after `inset` and a `gutter` after each side edge and rail), they shrink toward their minimum\n * (the edge's `cross.min` and the widest open setter's), then fold whole into their side's one rail, unkept before\n * kept, the oldest newest use first, the outer first, the left first. A column whose members are all folded by hand\n * goes to the rail too, or with `handFold: \"ride\"` and one member it rides as a title bar over the side's first open\n * column, at its width, taking none. The rail lies just outside the side's first column, its segments (each member's\n * `rail` form) in ring order.\n *\n * `previous` (the layout before) gives each edge's fits to `fitStack` as `previous`, so a change of ages alone (a press)\n * changes no rect; columns folded or shrunk by give-way stay so while the content still fits, and room coming back\n * unfolds them in the reverse of give-way order. Pure: the same scene always lays out the same.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport { fitFloat } from \"../stack/floats\";\nimport { fitStack } from \"../stack/layout\";\nimport { formSetsCross, type StackFit, type StackForm, type StackInput, type StackItem } from \"../stack/model\";\nimport { axisOf, formsOf, zoneOf, type Edge, type FloatAnchor, type Scene, type SceneEdgeLayout, type SceneItem, type SceneItemLayout, type SceneLayout, type SceneNote, type SceneRailLayout, type SolveOptions, type Zone } from \"./model\";\n\nconst EPS = 1e-6;\nconst finite = (x: number | undefined, fallback: number): number => (typeof x === \"number\" && Number.isFinite(x) ? x : fallback);\nconst px = (x: number | undefined): number => Math.max(0, finite(x, 0));\n\n/** The order edges are cut in: full bars (top, bottom), columns (left, right), between bars (top, bottom); each by ring. */\nexport function cutOrder(edges: readonly Edge[]): Edge[] {\n const phase = (e: Edge): number => (e.side === \"left\" || e.side === \"right\" ? 1 : e.span === \"between\" ? 2 : 0);\n const sideRank = (e: Edge): number => (e.side === \"top\" || e.side === \"left\" ? 0 : 1);\n return edges\n .map((e, i) => ({ e, i }))\n .sort((a, b) => phase(a.e) - phase(b.e) || sideRank(a.e) - sideRank(b.e) || finite(a.e.ring, 0) - finite(b.e.ring, 0) || a.i - b.i)\n .map((x) => x.e);\n}\n\nconst ZONE_RANK: Record<Zone, number> = { start: 0, center: 1, end: 2 };\n\n/** The ids of an edge in drawing order: its items stably sorted by zone. */\nexport function zoneSorted(scene: Scene, ids: readonly string[]): string[] {\n return ids\n .map((id, i) => ({ id, i, z: ZONE_RANK[zoneOf(scene.items[id])] }))\n .sort((a, b) => a.z - b.z || a.i - b.i)\n .map((x) => x.id);\n}\n\nconst crossMinOf = (f: StackForm): number => finite(f.cross.min ?? f.cross.natural, 0);\n\nconst stackItemOf = (item: SceneItem, forms: readonly StackForm[], from?: number): StackItem => ({\n id: item.id,\n forms,\n used: finite(item.used, 0),\n ...(item.kept ? { kept: true } : {}),\n ...(from !== undefined ? { from } : item.from !== undefined ? { from: item.from } : {}),\n ...(item.fixed ? { fixed: true } : {}),\n});\n\n/** Whether anything drawn in the fit sets its cross size. */\nfunction hasSetter(fit: StackFit, forms: (id: string) => readonly StackForm[]): boolean {\n return fit.items.some((p) => p.kind !== \"menu\" && formSetsCross(forms(p.id)[p.form]!));\n}\n\ninterface EdgeSolve {\n readonly stack: StackFit;\n readonly free: StackFit;\n readonly tabs: readonly string[];\n readonly closedTabs: ReadonlySet<string>;\n readonly input: StackInput;\n}\n\n/** One edge's stack along `length`: the free fit, then the rail or the user's size. */\nfunction solveEdge(scene: Scene, edge: Edge, ids: readonly string[], length: number, room: number, previous: SceneEdgeLayout | undefined): EdgeSolve {\n const axis = axisOf(edge.side);\n const column = axis === \"column\";\n const ordered = zoneSorted(scene, ids);\n const formsById = (id: string): readonly StackForm[] => formsOf(scene.items[id]!, axis);\n // Never wider across than the room the cut leaves it.\n const maxOf = Number.isNaN(edge.cross.max) ? Infinity : edge.cross.max;\n const cross = { min: Math.min(px(edge.cross.min), room), max: Math.min(maxOf, room), rail: Math.min(px(edge.cross.rail ?? 30), room) };\n const base: Omit<StackInput, \"items\"> = {\n axis,\n length,\n cross,\n ...(edge.menu ? { menu: edge.menu } : {}),\n ...(edge.gap !== undefined ? { gap: edge.gap } : {}),\n ...(edge.pad ? { pad: edge.pad } : {}),\n ...(column ? { ownCross: true } : {}),\n };\n const open = ordered.filter((id) => !scene.items[id]!.closed);\n const input: StackInput = { ...base, items: open.map((id) => stackItemOf(scene.items[id]!, formsById(id))) };\n const free = fitStack(input, previous ? { previous: previous.free } : {});\n const none = new Set<string>();\n if (column && !hasSetter(free, formsById)) {\n // A rail: the items with a rail form take it (closed ones too, with `railShowsClosed`).\n const railIndex = (item: SceneItem, forms: readonly StackForm[]): number => {\n if (item.fixed) return -1;\n for (let j = Math.max(0, Math.floor(finite(item.from, 0))); j < forms.length; j++) if (forms[j]!.kind === \"rail\") return j;\n return -1;\n };\n const shown = ordered.filter((id) => {\n const it = scene.items[id]!;\n return !it.closed || (edge.railShowsClosed === true && railIndex(it, formsById(id)) >= 0);\n });\n const anyRail = shown.some((id) => railIndex(scene.items[id]!, formsById(id)) >= 0);\n if (anyRail) {\n const railInput: StackInput = {\n ...base,\n items: shown.map((id) => {\n const it = scene.items[id]!;\n const j = railIndex(it, formsById(id));\n return stackItemOf(it, formsById(id), j >= 0 ? j : undefined);\n }),\n };\n const stack = fitStack(railInput, previous ? { previous: previous.stack } : {});\n const tabs = stack.items.filter((p) => p.kind === \"rail\").map((p) => p.id);\n const closedTabs = new Set(shown.filter((id) => scene.items[id]!.closed));\n return { stack, free, tabs, closedTabs, input: railInput };\n }\n }\n const size = edge.size;\n if (typeof size === \"number\" && Number.isFinite(size) && hasSetter(free, formsById)) {\n const setters = free.items.filter((p) => p.kind !== \"menu\" && formSetsCross(formsById(p.id)[p.form]!));\n const lo = Math.max(px(edge.cross.min), ...setters.map((p) => crossMinOf(formsById(p.id)[p.form]!)));\n const s = Math.min(Math.max(size, lo), Math.max(lo, maxOf), room);\n if (Math.abs(s - free.cross) > EPS) {\n const sized: StackInput = { ...input, cross: { ...cross, min: s, max: s } };\n const stack = fitStack(sized, previous ? { previous: previous.stack } : {});\n return { stack, free, tabs: [], closedTabs: none, input: sized };\n }\n }\n return { stack: free, free, tabs: [], closedTabs: none, input };\n}\n\n/**\n * The fit with zones packed: when the drawn items leave spare length, start items pack from the start, end items from\n * the end (before the » entry), center items centred between. Returns the main-axis start per id.\n */\nfunction zoneStarts(scene: Scene, fit: StackFit, input: StackInput): Map<string, number> {\n const column = fit.axis === \"column\";\n const at = (r: Rect): number => (column ? r.y : r.x);\n const len = (r: Rect): number => (column ? r.height : r.width);\n const out = new Map<string, number>();\n const drawn = fit.items.filter((p) => p.kind !== \"menu\");\n for (const p of drawn) out.set(p.id, at(p.rect));\n const gap = px(input.gap);\n const start = px(input.pad?.start);\n const end = px(input.pad?.end);\n const menu = fit.menu ? len(fit.menu.rect) + (drawn.length > 0 ? gap : 0) : 0;\n const used = drawn.reduce((s, p) => s + len(p.rect), 0) + Math.max(0, drawn.length - 1) * gap;\n const spare = fit.length - start - end - menu - used;\n if (spare <= EPS) return out;\n const zone = (z: Zone) => drawn.filter((p) => zoneOf(scene.items[p.id]) === z);\n const total = (ps: readonly { rect: Rect }[]): number => ps.reduce((s, p) => s + len(p.rect), 0) + Math.max(0, ps.length - 1) * gap;\n const lay = (ps: readonly { id: string; rect: Rect }[], from: number): void => {\n let c = from;\n for (const p of ps) {\n out.set(p.id, c);\n c += len(p.rect) + gap;\n }\n };\n const s = zone(\"start\");\n const c = zone(\"center\");\n const e = zone(\"end\");\n lay(s, start);\n const endStart = fit.length - end - menu - total(e);\n lay(e, endStart);\n const lo = start + total(s) + (s.length > 0 ? gap : 0);\n const hi = endStart - (e.length > 0 ? gap : 0);\n // Centred on the edge's middle (so a centred readout stays put while the other zones change), kept between them.\n const mid = (fit.length - total(c)) / 2;\n lay(c, Math.max(lo, Math.min(mid, hi - total(c))));\n return out;\n}\n\n/** A float's rect flush with `content`'s side or corner. */\nexport function anchored(content: Rect, w: number, h: number, anchor: FloatAnchor): Rect {\n const left = content.x;\n const right = content.x + content.width - w;\n const midX = content.x + (content.width - w) / 2;\n const top = content.y;\n const bottom = content.y + content.height - h;\n const midY = content.y + (content.height - h) / 2;\n const at: Record<FloatAnchor, [number, number]> = {\n \"content-top-left\": [left, top],\n \"content-top\": [midX, top],\n \"content-top-right\": [right, top],\n \"content-right\": [right, midY],\n \"content-bottom-right\": [right, bottom],\n \"content-bottom\": [midX, bottom],\n \"content-bottom-left\": [left, bottom],\n \"content-left\": [left, midY],\n };\n const [x, y] = at[anchor] ?? at[\"content-top-right\"];\n return rect(x, y, w, h);\n}\n\nexport function solve(given: Scene, options: SolveOptions = {}): SceneLayout {\n const previous = options.previous;\n // Under `previous`, an item docked now that was closed or absent then has just opened: it counts as the newest, so it\n // keeps its largest form while it fits and the others give way by the usual rules.\n const opened = new Set<string>();\n if (previous) {\n for (const e of given.edges) {\n for (const id of e.items) {\n const it = Object.hasOwn(given.items, id) ? given.items[id] : undefined;\n const was = previous.items[id];\n if (it && !it.closed && !it.fixed && (!was || was.closed)) opened.add(id);\n }\n }\n }\n const newest = Object.values(given.items).reduce((m, it) => Math.max(m, finite(it.used, 0)), 0) + 1;\n const scene: Scene = opened.size === 0 ? given : { ...given, items: { ...given.items, ...Object.fromEntries([...opened].map((id) => [id, { ...given.items[id]!, used: newest }])) } };\n // `fresh` edges, and edges holding a `fresh` item, are solved without `previous`.\n const fresh = new Set(options.fresh ?? []);\n const prevEdge = (edge: Edge): SceneEdgeLayout | undefined => (!previous || fresh.has(edge.id) || edge.items.some((id) => fresh.has(id)) ? undefined : previous.edges[edge.id]);\n const notes: SceneNote[] = [];\n const items: Record<string, SceneItemLayout> = {};\n const edges: Record<string, SceneEdgeLayout> = {};\n const stage = rect(finite(scene.stage.x, 0), finite(scene.stage.y, 0), px(scene.stage.width), px(scene.stage.height));\n const order = cutOrder(scene.edges);\n\n // Who is where: the first place in cut order wins (edges before floats).\n const claimed = new Set<string>();\n const claim = (id: string): boolean => {\n if (!Object.hasOwn(scene.items, id)) {\n notes.push({ code: \"unknown-item\", id });\n return false;\n }\n if (claimed.has(id)) {\n notes.push({ code: \"twice\", id });\n return false;\n }\n claimed.add(id);\n return true;\n };\n const owned = new Map<Edge, string[]>();\n for (const e of order) owned.set(e, e.items.filter(claim));\n\n /** Draws an edge's stack at `r` (its stage rect): its items, notes and edge layout. */\n const emit = (edge: Edge, r: Rect, solved: EdgeSolve, extra: Partial<SceneEdgeLayout> = {}): void => {\n const column = axisOf(edge.side) === \"column\";\n const { stack } = solved;\n const thick = column ? r.width : r.height;\n const starts = zoneStarts(scene, stack, solved.input);\n const toStage = (l: Rect, id?: string): Rect => {\n const s = id !== undefined ? starts.get(id) : undefined;\n const x = column ? l.x : (s ?? l.x);\n const y = column ? (s ?? l.y) : l.y;\n return rect(r.x + x, r.y + y, l.width, l.height);\n };\n const tabs = new Set(solved.tabs);\n for (const p of stack.items) {\n const it = scene.items[p.id]!;\n const inMenu = p.kind === \"menu\";\n items[p.id] = {\n rect: toStage(p.rect, inMenu ? undefined : p.id),\n kind: it.kind,\n form: p.form,\n formKind: p.kind,\n edge: edge.id,\n zone: zoneOf(it),\n ...(inMenu ? { inMenu: true } : {}),\n ...(tabs.has(p.id) ? { tab: true } : {}),\n ...(solved.closedTabs.has(p.id) ? { closed: true } : {}),\n ...(it.fixed ? { fixed: true } : {}),\n };\n }\n for (const n of stack.notes) notes.push({ edge: edge.id, ...n });\n edges[edge.id] = {\n side: edge.side,\n ring: finite(edge.ring, 0),\n rect: r,\n cross: thick,\n menu: stack.menu ? { rect: toStage(stack.menu.rect), items: stack.menu.items } : null,\n tabs: solved.tabs,\n stack,\n free: solved.free,\n ...extra,\n };\n };\n\n const lay = (edge: Edge, area: Rect, cut: boolean): Rect => {\n const column = axisOf(edge.side) === \"column\";\n const length = column ? area.height : area.width;\n const room = Math.max(0, column ? area.width : area.height);\n const solved = solveEdge(scene, edge, owned.get(edge)!, length, room, prevEdge(edge));\n const thick = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, room);\n const r =\n edge.side === \"top\"\n ? rect(area.x, area.y, area.width, thick)\n : edge.side === \"bottom\"\n ? rect(area.x, area.y + area.height - thick, area.width, thick)\n : edge.side === \"left\"\n ? rect(area.x, area.y, thick, area.height)\n : rect(area.x + area.width - thick, area.y, thick, area.height);\n emit(edge, r, solved);\n if (!cut) return area;\n return edge.side === \"top\"\n ? rect(area.x, area.y + thick, area.width, area.height - thick)\n : edge.side === \"bottom\"\n ? rect(area.x, area.y, area.width, area.height - thick)\n : edge.side === \"left\"\n ? rect(area.x + thick, area.y, area.width - thick, area.height)\n : rect(area.x, area.y, area.width - thick, area.height);\n };\n\n const rails: Partial<Record<\"left\" | \"right\", SceneRailLayout>> = {};\n const gutter = px(scene.gutter);\n const isSide = (e: Edge): boolean => e.side === \"left\" || e.side === \"right\";\n\n /**\n * The reserved left and right edges, ring by ring, with column give-way: dynamic columns shrink toward their minimum,\n * then fold whole into their side's rail while the content is narrower than `contentMin.width`.\n */\n const laySides = (sideEdges: readonly Edge[], area: Rect): Rect => {\n const H = area.height;\n const ride = scene.handFold === \"ride\";\n interface Col {\n readonly edge: Edge;\n readonly side: \"left\" | \"right\";\n readonly solved: EdgeSolve;\n readonly width: number;\n readonly min: number;\n readonly visible: readonly string[];\n readonly dyn: boolean;\n readonly hand: boolean;\n readonly kept: boolean;\n readonly age: number;\n }\n const cols: Col[] = sideEdges.map((edge) => {\n const side = edge.side as \"left\" | \"right\";\n const solved = solveEdge(scene, edge, owned.get(edge)!, H, Math.max(0, area.width), prevEdge(edge));\n const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area.width);\n const visible = owned.get(edge)!.filter((id) => !scene.items[id]!.closed);\n const dyn = edge.column === true && scene.rails?.[side] !== undefined && visible.length > 0;\n const forms = (id: string): readonly StackForm[] => formsOf(scene.items[id]!, \"column\");\n const setters = solved.free.items.filter((p) => p.kind !== \"menu\" && formSetsCross(forms(p.id)[p.form]!));\n const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => crossMinOf(forms(p.id)[p.form]!)))) : width;\n return {\n edge,\n side,\n solved,\n width,\n min,\n visible,\n dyn,\n hand: dyn && visible.every((id) => finite(scene.items[id]!.from, 0) >= 1),\n kept: visible.some((id) => scene.items[id]!.kept === true),\n age: Math.max(-Infinity, ...visible.map((id) => finite(scene.items[id]!.used, 0))),\n };\n });\n const cmin = scene.contentMin ? px(scene.contentMin.width) : undefined;\n const order = cols\n .filter((c) => c.dyn && !c.hand && c.width > 0)\n .sort((a, b) => Number(a.kept) - Number(b.kept) || a.age - b.age || finite(a.edge.ring, 0) - finite(b.edge.ring, 0) || (a.side === b.side ? 0 : a.side === \"left\" ? -1 : 1));\n // Under `previous`, the columns that were shrunk shrink first, in the order they did, so ages alone move nothing.\n const shrunkBefore = (previous?.notes ?? []).flatMap((n) => (n.code === \"column-shrunk\" ? [n.edge] : []));\n const rankOf = (c: Col): number => (shrunkBefore.includes(c.edge.id) ? shrunkBefore.indexOf(c.edge.id) : Infinity);\n const shrinkOrder = order.map((c, i) => ({ c, i })).sort((a, b) => (rankOf(a.c) === rankOf(b.c) ? a.i - b.i : rankOf(a.c) < rankOf(b.c) ? -1 : 1)).map((x) => x.c);\n const railW = (side: \"left\" | \"right\"): number => px(scene.rails?.[side]?.width);\n const evaluate = (auto: ReadonlySet<Col>) => {\n const openOn = (side: \"left\" | \"right\"): boolean => cols.some((c) => c.side === side && c.dyn && !c.hand && !auto.has(c) && c.width > 0);\n const riding = (c: Col): boolean => ride && c.hand && c.visible.length === 1 && openOn(c.side);\n const railed = (c: Col): boolean => c.dyn && (auto.has(c) || (c.hand && !riding(c)));\n const widths = new Map(cols.filter((c) => !railed(c) && !riding(c)).map((c) => [c, c.width]));\n const railSides = ([\"left\", \"right\"] as const).filter((s) => cols.some((c) => c.side === s && railed(c)));\n let used = 0;\n for (const w of widths.values()) used += w > 0 ? w + gutter : 0;\n for (const s of railSides) used += railW(s) + gutter;\n let excess = cmin === undefined ? -Infinity : used + cmin - area.width;\n for (const c of shrinkOrder) {\n if (excess <= EPS) break;\n const w = widths.get(c);\n if (w === undefined) continue;\n const take = Math.min(excess, w - c.min);\n if (take > 0) {\n widths.set(c, w - take);\n excess -= take;\n }\n }\n return { auto, widths, excess, railed, riding, railSides };\n };\n let auto = new Set<Col>();\n if (cmin !== undefined) {\n // Room that came back unfolds in the reverse of the order the columns folded in (the fold notes' order), one at a\n // time, stopping at the first that can't come back: never by age, so a press can't unfold anything.\n const unfold = (): void => {\n for (const c of [...auto].reverse()) {\n const fewer = new Set([...auto].filter((x) => x !== c));\n if (evaluate(fewer).excess <= EPS) auto = fewer;\n else break;\n }\n };\n if (previous) {\n // What gave way before stays folded, in the order it folded, while the content still fits without it coming back.\n const byId = new Map(order.map((c) => [c.edge.id, c]));\n // A column with a just-opened or `fresh` item is weighed anew.\n const anew = (c: Col): boolean => fresh.has(c.edge.id) || c.visible.some((id) => opened.has(id) || fresh.has(id));\n const was = previous.notes.flatMap((n) => ((n.code === \"column-folded\" || n.code === \"kept-folded\") && byId.has(n.edge) && !anew(byId.get(n.edge)!) ? [byId.get(n.edge)!] : []));\n auto = new Set(was);\n if (evaluate(auto).excess <= EPS) unfold();\n }\n // A need for more folds the next in give-way order.\n for (const c of order) {\n if (evaluate(auto).excess <= EPS) break;\n if (!auto.has(c)) auto = new Set([...auto, c]);\n }\n // A fold can make an earlier one needless (a second column into a rail the first already paid for): unfold to a\n // fixpoint, so solving again from this layout changes nothing.\n for (let size = -1; size !== auto.size; ) {\n size = auto.size;\n unfold();\n }\n }\n const g = evaluate(auto);\n for (const c of shrinkOrder) {\n const w = g.widths.get(c);\n if (w !== undefined && w < c.width - EPS) notes.push({ code: \"column-shrunk\", edge: c.edge.id, from: c.width, to: w });\n }\n // In the order they folded: `previous` reads it to unfold in reverse.\n for (const c of g.auto) notes.push({ code: c.kept ? \"kept-folded\" : \"column-folded\", edge: c.edge.id });\n\n let x0 = area.x;\n let x1 = area.x + area.width;\n for (const side of [\"left\", \"right\"] as const) {\n const mine = cols.filter((c) => c.side === side);\n const railed = mine.filter((c) => g.railed(c));\n const riders = mine.filter((c) => g.riding(c));\n const host = mine.find((c) => c.dyn && !c.hand && !g.auto.has(c) && c.width > 0);\n const riderBar = (c: Col): { id: string; form: number; f: StackForm | undefined; h: number } => {\n const id = c.visible[0]!;\n const forms = formsOf(scene.items[id]!, \"column\");\n const form = forms.length === 0 ? 0 : Math.min(Math.max(0, Math.floor(finite(scene.items[id]!.from, 0))), forms.length - 1);\n return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };\n };\n const ridersTop = riders.reduce((s, c) => s + riderBar(c).h, 0);\n let railRect: Rect | null = null;\n for (const c of mine) {\n if (!railRect && railed.length > 0 && c.edge.column === true) {\n const w = railW(side);\n if (side === \"left\") {\n railRect = rect(x0, area.y, w, H);\n x0 += w + gutter;\n } else {\n x1 -= w;\n railRect = rect(x1, area.y, w, H);\n x1 -= gutter;\n }\n }\n const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free };\n if (g.railed(c)) {\n edges[c.edge.id] = { ...base, rect: rect(railRect!.x, area.y, 0, H), folded: g.auto.has(c) ? \"auto\" : \"hand\" };\n continue;\n }\n if (g.riding(c)) continue;\n // Never wider than the room the edges outside it leave.\n const w = Math.min(g.widths.get(c)!, Math.max(0, x1 - x0));\n const top = c === host ? ridersTop : 0;\n let solved = c.solved;\n if (top > 0 || Math.abs(w - c.width) > EPS) {\n const forced: Edge = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };\n const { size: _s, ...plain } = forced;\n solved = solveEdge(scene, plain, owned.get(c.edge)!, H - top, w, prevEdge(c.edge));\n }\n let r: Rect;\n if (side === \"left\") {\n r = rect(x0, area.y + top, w, H - top);\n x0 += w > 0 ? w + gutter : 0;\n } else {\n x1 -= w;\n r = rect(x1, area.y + top, w, H - top);\n x1 -= w > 0 ? gutter : 0;\n }\n emit(c.edge, r, solved, w < c.width - EPS ? { shrunk: true } : {});\n }\n if (host && riders.length > 0) {\n const hr = edges[host.edge.id]!.rect;\n let y = area.y;\n for (const c of riders) {\n const b = riderBar(c);\n const at = rect(hr.x, y, hr.width, b.h);\n const it = scene.items[b.id]!;\n items[b.id] = { rect: at, kind: it.kind, form: b.form, formKind: b.f?.kind ?? \"header\", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: \"hand\" };\n edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: at, cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: \"hand\" };\n y += b.h;\n }\n }\n if (railRect) {\n const segments: { id: string; edge: string; rect: Rect }[] = [];\n let y = railRect.y;\n for (const c of railed) {\n for (const id of c.visible) {\n const it = scene.items[id]!;\n const forms = formsOf(it, \"column\");\n const ri = forms.findIndex((f) => f.kind === \"rail\");\n const form = ri >= 0 ? ri : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1));\n const h = ri >= 0 ? px(forms[ri]!.main.natural) : railRect.width;\n const at = rect(railRect.x, y, railRect.width, h);\n items[id] = { rect: at, kind: it.kind, form, formKind: \"rail\", edge: c.edge.id, zone: zoneOf(it), rail: side, folded: g.auto.has(c) ? \"auto\" : \"hand\" };\n segments.push({ id, edge: c.edge.id, rect: at });\n y += h;\n }\n }\n rails[side] = { rect: railRect, segments };\n }\n }\n return rect(x0, area.y, Math.max(0, x1 - x0), H);\n };\n\n const inset = scene.inset ?? {};\n let area = rect(stage.x + px(inset.left), stage.y + px(inset.top), Math.max(0, stage.width - px(inset.left) - px(inset.right)), Math.max(0, stage.height - px(inset.top) - px(inset.bottom)));\n const reserved = order.filter((e) => e.mode !== \"overlay\");\n for (const e of reserved) if (!isSide(e) && e.span !== \"between\") area = lay(e, area, true);\n area = laySides(reserved.filter(isSide), area);\n for (const e of reserved) if (!isSide(e) && e.span === \"between\") area = lay(e, area, true);\n const content = area;\n let over = content;\n for (const e of order) if (e.mode === \"overlay\") over = lay(e, over, true);\n if (scene.contentMin) {\n const minW = px(scene.contentMin.width);\n const minH = px(scene.contentMin.height);\n if (content.width < minW - EPS) notes.push({ code: \"content-narrow\", width: content.width, min: minW });\n const bars = order.filter((e) => e.mode === \"overlay\" && !isSide(e)).reduce((s, e) => s + (edges[e.id]?.cross ?? 0), 0);\n if (content.height - bars < minH - EPS) notes.push({ code: \"content-short\", height: content.height - bars, min: minH });\n }\n if (previous) {\n const was = previous.content;\n const moved = Math.abs(was.x - content.x) > EPS || Math.abs(was.y - content.y) > EPS || Math.abs(was.width - content.width) > EPS || Math.abs(was.height - content.height) > EPS;\n if (moved) notes.push({ code: \"content-changed\", from: was, to: content });\n }\n\n // Floats: clear of every docked item, every bar and the chrome.\n const avoid: Rect[] = [];\n for (const l of Object.values(items)) avoid.push(l.rect);\n for (const e of Object.values(edges)) {\n if (axisOf(e.side) === \"row\" && e.cross > 0) avoid.push(e.rect);\n if (e.menu) avoid.push(e.menu.rect);\n }\n for (const c of scene.chrome ?? []) avoid.push(c);\n const floats: string[] = [];\n for (const f of scene.floats) {\n if (!claim(f.id)) continue;\n const it = scene.items[f.id]!;\n if (it.closed) continue;\n const orient = f.orient === \"row\" ? \"row\" : \"column\";\n const forms = formsOf(it, orient);\n const from = forms.length === 0 ? 0 : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), forms.length - 1);\n const form = forms[from];\n let w = px(f.rect.width);\n let h = px(f.rect.height);\n if (from > 0 && form) {\n // Its bar: the form's natural length along its orient, the other size kept.\n if (orient === \"column\") h = px(form.main.natural);\n else w = px(form.main.natural);\n }\n const want = f.anchor ? anchored(content, w, h, f.anchor) : rect(finite(f.rect.x, stage.x), finite(f.rect.y, stage.y), w, h);\n const fit = fitFloat(want, stage, avoid);\n if (fit.clamped) notes.push({ code: \"float-clamped\", id: f.id });\n if (fit.snapped) notes.push({ code: \"float-moved\", id: f.id });\n if (fit.covers.length > 0) notes.push({ code: \"float-covers\", id: f.id });\n items[f.id] = { rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? \"open\", floating: true };\n floats.push(f.id);\n }\n return { items, edges, content, floats, rails, notes };\n}\n","/**\n * The scene's pure changes. Each returns a new scene and leaves the one it was given as it was; a change that can't\n * apply (an unknown item or edge, a fixed item, a kind the edge or the float layer doesn't take) returns the scene\n * given, the same object, so `after === before` says nothing changed.\n *\n * - `moveTo(scene, id, { edge, zone?, at })`: docks the item in that edge, before the `at`-th item of the zone (counting\n * the zone's items without it, closed ones included), or at the zone's end. The zone becomes the item's `align`.\n * `{ kind: \"column\", side, ring }` makes a new column from `scene.columns[side]` at that ring (`Infinity`: the side's\n * inner end, \"Move to › Dock left\"); `{ kind: \"rail\", side, ring }` does the same with the item folded by hand, so it\n * shows in the rail; `{ kind: \"float\", rect?, anchor? }` floats it. A dynamic column an item leaves empty is deleted\n * and its side's rings are closed up.\n * - `homeFor(scene, id, start)`: the place a start scene gives the item, for `moveTo`.\n * - `floatAt(scene, id, rect?, orient?)`: floats it on top at `rect` (its size becomes `floatSize`); with no rect, at\n * its `floatSize` (or the default size) anchored to the content's top-right corner.\n * - `fold(scene, id, on)`: folded by hand starts it at its second form (`from: 1`); unfolding clears `from`.\n * - `use(scene, id)`: the newest age. Under `previous` it reshapes nothing.\n * - `keep(scene, id, on)`, `open(scene, id)`, `close(scene, id)`.\n * - `raise(scene, id)`: a float to the top of the stack; no use, no reshape.\n * - `orient(scene, id, orient)`: a float's axis.\n * - `resize(scene, edge, size)`: the user's size across; a size that isn't a finite number clears it.\n */\nimport { clampInto, type Rect } from \"../geometry\";\nimport { DEFAULT_FLOAT_SIZE, zoneOf, type Edge, type FloatAnchor, type Orient, type Scene, type SceneFloat, type SceneItem, type Zone } from \"./model\";\n\n/** Where a docked item goes: before the `at`-th item of `zone` (default the item's own zone) in `edge`. */\nexport interface DockPlace {\n readonly kind?: \"gap\";\n readonly edge: string;\n readonly zone?: Zone;\n readonly at: number;\n}\n/** A new column on `side` at `ring` (the edges at that ring and inward move in one); `Infinity` is the side's inner end. */\nexport interface ColumnPlace {\n readonly kind: \"column\";\n readonly side: \"left\" | \"right\";\n readonly ring: number;\n}\n/** Docked folded: a new column at `ring` holding the item folded by hand, so it shows in the side's rail. */\nexport interface RailPlace {\n readonly kind: \"rail\";\n readonly side: \"left\" | \"right\";\n readonly ring: number;\n}\n/** Floating at `rect` (or, with none, at its last size anchored to the content). */\nexport interface FloatPlace {\n readonly kind: \"float\";\n readonly rect?: Rect;\n /** Following the content (only its size counts then). */\n readonly anchor?: FloatAnchor;\n}\nexport type Place = DockPlace | ColumnPlace | RailPlace | FloatPlace;\n\nconst withItem = (scene: Scene, item: SceneItem): Scene => ({ ...scene, items: { ...scene.items, [item.id]: item } });\nconst itemOf = (scene: Scene, id: string): SceneItem | undefined => (Object.hasOwn(scene.items, id) ? scene.items[id] : undefined);\n\n/** The side's edges with their rings closed up to 0, 1, 2… in their order (ring, then list order). */\nexport function closeRings(edges: readonly Edge[], sides: ReadonlySet<string>): Edge[] {\n const out = [...edges];\n for (const side of sides) {\n const idx = out.map((e, i) => ({ e, i })).filter((x) => x.e.side === side);\n idx.sort((a, b) => (a.e.ring === b.e.ring ? a.i - b.i : a.e.ring < b.e.ring ? -1 : 1));\n idx.forEach((x, ring) => {\n if (x.e.ring !== ring) out[x.i] = { ...x.e, ring };\n });\n }\n return out;\n}\n\n/** Dynamic columns left with no item are deleted, and their sides' rings closed up. */\nexport function prune(scene: Scene): Scene {\n const gone = scene.edges.filter((e) => e.column === true && e.items.length === 0);\n if (gone.length === 0) return scene;\n const sides = new Set(gone.map((e) => e.side));\n return { ...scene, edges: closeRings(scene.edges.filter((e) => !gone.includes(e)), sides) };\n}\n\n/** The scene with the item out of every edge and every float (a dynamic column it leaves empty is deleted). */\nexport function lift(scene: Scene, id: string): Scene {\n const inEdge = scene.edges.some((e) => e.items.includes(id));\n const inFloat = scene.floats.some((f) => f.id === id);\n if (!inEdge && !inFloat) return scene;\n return prune({\n ...scene,\n edges: inEdge ? scene.edges.map((e) => (e.items.includes(id) ? { ...e, items: e.items.filter((x) => x !== id) } : e)) : scene.edges,\n floats: inFloat ? scene.floats.filter((f) => f.id !== id) : scene.floats,\n });\n}\n\n/** A new column edge from the side's template, or null when the side has none or it doesn't take the kind. */\nfunction newColumn(scene: Scene, side: \"left\" | \"right\", kind: string, ring: number, items: readonly string[]): Edge | null {\n const t = scene.columns?.[side];\n if (!t || !t.accepts.includes(kind)) return null;\n const taken = new Set(scene.edges.map((e) => e.id));\n let n = 0;\n while (taken.has(`${side}-${n}`)) n++;\n return {\n id: `${side}-${n}`,\n side,\n ring,\n accepts: t.accepts,\n items,\n cross: t.cross,\n ...(t.gap !== undefined ? { gap: t.gap } : {}),\n ...(t.pad ? { pad: t.pad } : {}),\n ...(t.menu ? { menu: t.menu } : {}),\n column: true,\n };\n}\n\n/** `scene` with a new column holding `id` at `ring` on `side` (already lifted out). */\nfunction insertColumn(scene: Scene, id: string, side: \"left\" | \"right\", ring: number): Scene | null {\n const kind = scene.items[id]!.kind;\n const mine = scene.edges.filter((e) => e.side === side);\n const r = Math.max(0, Math.min(Number.isNaN(ring) ? Infinity : Math.floor(ring), mine.length === 0 ? 0 : Math.max(...mine.map((e) => e.ring)) + 1));\n const col = newColumn(scene, side, kind, r, [id]);\n if (!col) return null;\n const shifted = scene.edges.map((e) => (e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e));\n return { ...scene, edges: closeRings([...shifted, col], new Set([side])) };\n}\n\n/** The index in `edge.items` where the `at`-th item of `zone` is (or where the zone ends). */\nfunction insertIndex(scene: Scene, edge: Edge, zone: Zone, at: number): number {\n const rank = { start: 0, center: 1, end: 2 } as const;\n const inZone = edge.items.map((id, i) => ({ id, i })).filter((x) => zoneOf(itemOf(scene, x.id)) === zone);\n const k = Math.min(Math.max(0, Math.floor(Number.isFinite(at) ? at : inZone.length)), inZone.length);\n if (k < inZone.length) return inZone[k]!.i;\n if (inZone.length > 0) return inZone[inZone.length - 1]!.i + 1;\n // An empty zone: after the last item of an earlier zone, else before the first of a later one.\n let idx = 0;\n edge.items.forEach((id, i) => {\n if (rank[zoneOf(itemOf(scene, id))] < rank[zone]) idx = i + 1;\n });\n return idx;\n}\n\nexport function moveTo(scene: Scene, id: string, place: Place): Scene {\n const item = itemOf(scene, id);\n if (!item || item.fixed) return scene;\n if (place.kind === \"float\") {\n const out = floatAt(scene, id, place.rect);\n const anchor = place.anchor;\n if (!anchor || out === scene) return out;\n return { ...out, floats: out.floats.map((f) => (f.id === id ? { ...f, anchor } : f)) };\n }\n if (place.kind === \"column\" || place.kind === \"rail\") {\n if (place.kind === \"rail\" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;\n const { align: _a, ...plain } = item;\n const folded: SceneItem = place.kind === \"rail\" ? { ...plain, from: Math.max(1, plain.from ?? 0) } : plain;\n const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring);\n return made ?? scene;\n }\n const edge = scene.edges.find((e) => e.id === place.edge);\n if (!edge || !edge.accepts.includes(item.kind)) return scene;\n const zone = place.zone ?? zoneOf(item);\n const { align: _drop, ...rest } = item;\n const moved: SceneItem = zone === \"start\" ? rest : { ...rest, align: zone };\n const lifted = withItem(lift(scene, id), moved);\n const target = lifted.edges.find((e) => e.id === place.edge);\n // The item's own column, deleted when it was lifted out of it.\n if (!target) return scene;\n const k = insertIndex(lifted, target, zone, place.at);\n return { ...lifted, edges: lifted.edges.map((e) => (e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e)) };\n}\n\nexport function floatAt(scene: Scene, id: string, at?: Rect, orient?: Orient): Scene {\n const item = itemOf(scene, id);\n if (!item || item.fixed || !scene.floatKinds.includes(item.kind)) return scene;\n const was = scene.floats.find((f) => f.id === id);\n const o: Orient | undefined = orient ?? was?.orient;\n const size = item.floatSize ?? DEFAULT_FLOAT_SIZE;\n const float: SceneFloat = at\n ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...(o ? { orient: o } : {}) }\n : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: \"content-top-right\", ...(o ? { orient: o } : {}) };\n const next = at && at.width > 0 && at.height > 0 ? { ...item, floatSize: { width: at.width, height: at.height } } : item;\n const lifted = lift(withItem(scene, next), id);\n return { ...lifted, floats: [...lifted.floats, float] };\n}\n\nexport function fold(scene: Scene, id: string, on: boolean): Scene {\n const item = itemOf(scene, id);\n if (!item || item.fixed) return scene;\n if (on) return (item.from ?? 0) >= 1 ? scene : withItem(scene, { ...item, from: 1 });\n if (item.from === undefined) return scene;\n const { from: _f, ...rest } = item;\n return withItem(scene, rest);\n}\n\n/** The newest age in the scene, plus one. */\nexport const nextAge = (scene: Scene): number => Object.values(scene.items).reduce((m, it) => Math.max(m, Number.isFinite(it.used) ? it.used : 0), 0) + 1;\n\nexport function use(scene: Scene, id: string): Scene {\n const item = itemOf(scene, id);\n if (!item) return scene;\n return withItem(scene, { ...item, used: nextAge(scene) });\n}\n\nexport function keep(scene: Scene, id: string, on: boolean): Scene {\n const item = itemOf(scene, id);\n if (!item || !!item.kept === on) return scene;\n if (on) return withItem(scene, { ...item, kept: true });\n const { kept: _k, ...rest } = item;\n return withItem(scene, rest);\n}\n\nexport function open(scene: Scene, id: string): Scene {\n const item = itemOf(scene, id);\n if (!item || !item.closed) return scene;\n const { closed: _c, ...rest } = item;\n return withItem(scene, rest);\n}\n\nexport function close(scene: Scene, id: string): Scene {\n const item = itemOf(scene, id);\n if (!item || item.closed || item.fixed) return scene;\n return withItem(scene, { ...item, closed: true });\n}\n\nexport function raise(scene: Scene, id: string): Scene {\n const i = scene.floats.findIndex((f) => f.id === id);\n if (i < 0 || i === scene.floats.length - 1) return scene;\n return { ...scene, floats: [...scene.floats.slice(0, i), ...scene.floats.slice(i + 1), scene.floats[i]!] };\n}\n\nexport function orient(scene: Scene, id: string, to: Orient): Scene {\n const i = scene.floats.findIndex((f) => f.id === id);\n if (i < 0 || (scene.floats[i]!.orient ?? \"column\") === to) return scene;\n return { ...scene, floats: scene.floats.map((f, k) => (k === i ? { ...f, orient: to } : f)) };\n}\n\nexport function resize(scene: Scene, edgeId: string, size: number): Scene {\n const edge = scene.edges.find((e) => e.id === edgeId);\n if (!edge) return scene;\n if (!Number.isFinite(size)) {\n if (edge.size === undefined) return scene;\n const { size: _s, ...rest } = edge;\n return { ...scene, edges: scene.edges.map((e) => (e === edge ? rest : e)) };\n }\n return { ...scene, edges: scene.edges.map((e) => (e === edge ? { ...e, size } : e)) };\n}\n\n/**\n * The place `start` (a scene as it began: the host's start or reset scene) gives an item, for Dock, Put back and Reset\n * position: its zone and place in the same edge (before the first item that followed it there and is still there), a\n * new column at its ring when its column is gone, or its float rect (and anchor). Null when `start` places it nowhere\n * or in an edge `scene` no longer has that isn't a column. `moveTo(scene, id, place)` puts it there.\n */\nexport function homeFor(scene: Scene, id: string, start: Scene): Place | null {\n for (const e of start.edges) {\n const k = e.items.indexOf(id);\n if (k < 0) continue;\n const zone = zoneOf(itemOf(start, id) ?? itemOf(scene, id));\n const here = scene.edges.find((x) => x.id === e.id);\n if (here) {\n const now = here.items.filter((x) => x !== id && zoneOf(itemOf(scene, x)) === zone);\n const next = e.items.slice(k + 1).find((x) => now.includes(x));\n return { kind: \"gap\", edge: e.id, zone, at: next ? now.indexOf(next) : now.length };\n }\n if (e.column === true && (e.side === \"left\" || e.side === \"right\")) return { kind: \"column\", side: e.side, ring: e.ring };\n return null;\n }\n const f = start.floats.find((x) => x.id === id);\n if (f) return { kind: \"float\", rect: f.rect, ...(f.anchor ? { anchor: f.anchor } : {}) };\n return null;\n}\n\n/**\n * A float's rect moved (never resized) so that what `solve` draws of it lies in the stage: `drawn` is its drawn size (the\n * bar's when it is folded). As in `solve`, one drawn larger than the stage keeps its top-left corner on the stage's.\n */\nexport function clampFloat(r: Rect, stage: Rect, drawn: { readonly width: number; readonly height: number } = r): Rect {\n const at = clampInto({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);\n return { x: at.x, y: at.y, width: r.width, height: r.height };\n}\n\n/** The size `solve` draws a float at: its rect's, or with `from` over 0 its bar (that form's natural length along `orient`). */\nexport function drawnFloatSize(item: SceneItem, f: { readonly rect: Rect; readonly orient?: Orient }): { width: number; height: number } {\n const orient = f.orient === \"row\" ? \"row\" : \"column\";\n const forms = item.forms[orient] ?? [];\n const from = forms.length === 0 ? 0 : Math.min(Math.max(0, Math.floor(Number.isFinite(item.from) ? item.from! : 0)), forms.length - 1);\n const form = forms[from];\n const px = (v: number): number => (Number.isFinite(v) ? Math.max(0, v) : 0);\n if (from > 0 && form) return orient === \"column\" ? { width: px(f.rect.width), height: px(form.main.natural) } : { width: px(form.main.natural), height: px(f.rect.height) };\n return { width: px(f.rect.width), height: px(f.rect.height) };\n}\n","/**\n * The scene's stored form. `storeScene(scene)` gives plain JSON-safe data; `readScene(data, base)` reads it back over\n * `base` (the host's scene as it starts: its item definitions, edges, kinds and stage) and never throws.\n *\n * ```ts\n * interface StoredScene {\n * v: 1;\n * edges: { id: string; side: Side; ring: number; items: string[]; size?: number; column?: true }[];\n * floats: { id: string; x: number; y: number; width: number; height: number; orient?: \"row\" | \"column\"; anchor?: FloatAnchor }[];\n * items: Record<string, { used: number; kept?: true; from?: number; closed?: true; align?: \"center\" | \"end\"; floatSize?: { width: number; height: number } }>;\n * }\n * ```\n *\n * Nothing about kinds, forms or limits is stored: those are the host's (`base`). An edge is matched by its id: its\n * side, ring and limits come from `base`, its order of items and its `size` from the store. Dynamic columns\n * (`column: true`) are the store's: one `base` lacks is made from `base.columns[side]`, its ring is the stored one, and\n * columns left empty are deleted, the rings closed up. No float has a pinned field: one an old store has is listed and\n * ignored.\n *\n * Reading is lenient: anything but an object of version 1 gives `base` back with the reason in `error`. Inside one,\n * whatever can't be used is dropped and listed in `dropped` (an unknown edge `edge:<id>`, an unknown or repeated item,\n * an item an edge doesn't accept `edge:<edge>:<id>`, a fixed item in another edge than `base`'s `edge:<edge>:<id>`, a\n * float of a kind that doesn't float `float:<id>`, a bad field `item:<id>:<field>`, an unknown top-level field\n * `<field>`). A stored edge's order is kept exactly, fixed items where the store put them (in their own edge); a fixed\n * item the store lacks goes back to its base place (trailing ones last). An item the store places nowhere goes where\n * `base` has it, before a stored trailing run of fixed items.\n * A float's rect is clamped into the stage on read.\n */\nimport { rect, type Size } from \"../geometry\";\nimport { clampFloat, closeRings, drawnFloatSize, prune } from \"./changes\";\nimport { SIDES, type Edge, type FloatAnchor, type Orient, type Scene, type SceneFloat, type SceneItem, type Side } from \"./model\";\n\nexport interface StoredSceneEdge {\n readonly id: string;\n readonly side: Side;\n readonly ring: number;\n readonly items: readonly string[];\n readonly size?: number;\n /** A dynamic column: read back from `base.columns[side]` even when `base` doesn't have it. */\n readonly column?: true;\n}\n\nexport interface StoredSceneFloat {\n readonly id: string;\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n readonly orient?: Orient;\n readonly anchor?: FloatAnchor;\n}\n\nexport interface StoredSceneItem {\n readonly used: number;\n readonly kept?: true;\n readonly from?: number;\n readonly closed?: true;\n readonly align?: \"center\" | \"end\";\n readonly floatSize?: Size;\n}\n\nexport interface StoredScene {\n readonly v: 1;\n readonly edges: readonly StoredSceneEdge[];\n readonly floats: readonly StoredSceneFloat[];\n readonly items: Readonly<Record<string, StoredSceneItem>>;\n}\n\nexport interface SceneRead {\n readonly scene: Scene;\n /** What was left out, as listed in the module's docs. */\n readonly dropped: readonly string[];\n /** Set when nothing could be read: `scene` is `base`. */\n readonly error?: string;\n}\n\nconst ANCHORS: readonly FloatAnchor[] = [\"content-top-left\", \"content-top\", \"content-top-right\", \"content-right\", \"content-bottom-right\", \"content-bottom\", \"content-bottom-left\", \"content-left\"];\nconst isNum = (x: unknown): x is number => typeof x === \"number\" && Number.isFinite(x);\nconst isSize = (x: unknown): x is number => isNum(x) && x > 0;\nconst isObject = (x: unknown): x is Record<string, unknown> => typeof x === \"object\" && x !== null && !Array.isArray(x);\n/** Records with no prototype, so an id such as `constructor` is only a key; `__proto__` is refused. */\nconst record = <T>(): Record<string, T> => Object.create(null) as Record<string, T>;\n\nexport function storeScene(scene: Scene): StoredScene {\n const items = record<StoredSceneItem>();\n for (const [id, it] of Object.entries(scene.items)) {\n if (id === \"__proto__\") continue;\n items[id] = {\n used: isNum(it.used) ? it.used : 0,\n ...(it.kept ? { kept: true as const } : {}),\n ...(isNum(it.from) && it.from >= 1 ? { from: Math.floor(it.from) } : {}),\n ...(it.closed ? { closed: true as const } : {}),\n ...(it.align === \"center\" || it.align === \"end\" ? { align: it.align } : {}),\n ...(it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}),\n };\n }\n return {\n v: 1,\n edges: scene.edges.map((e) => ({ id: e.id, side: e.side, ring: e.ring, items: [...e.items], ...(isNum(e.size) ? { size: e.size } : {}), ...(e.column === true ? { column: true as const } : {}) })),\n floats: scene.floats\n .filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height))\n .map((f) => ({ id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...(f.orient ? { orient: f.orient } : {}), ...(f.anchor ? { anchor: f.anchor } : {}) })),\n items,\n };\n}\n\nexport function readScene(data: unknown, base: Scene): SceneRead {\n try {\n return read(data, base);\n } catch (e) {\n return { scene: base, dropped: [], error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };\n }\n}\n\nconst words = (v: unknown): string => (typeof v === \"number\" ? String(v) : typeof v === \"string\" ? JSON.stringify(v.length > 24 ? `${v.slice(0, 24)}…` : v) : typeof v);\n\n/**\n * The fixed items of `baseIds` that `stored` lacks, put back at their places: leading ones from the start, trailing ones\n * at the end. Fixed items the store has keep the place it gives them, so a stored order round-trips exactly.\n */\nexport function withFixed(baseIds: readonly string[], stored: readonly string[], isFixed: (id: string) => boolean): string[] {\n const out = [...stored];\n const missing = (id: string): boolean => isFixed(id) && !stored.includes(id);\n let tail = baseIds.length;\n while (tail > 0 && isFixed(baseIds[tail - 1]!)) tail--;\n baseIds.forEach((id, i) => {\n if (missing(id) && i < tail) out.splice(Math.min(i, out.length), 0, id);\n });\n return [...out, ...baseIds.slice(tail).filter(missing)];\n}\n\nfunction read(data: unknown, base: Scene): SceneRead {\n if (!isObject(data)) return { scene: base, dropped: [], error: \"not an object\" };\n if (data.v !== 1) return { scene: base, dropped: [], error: `unknown version ${words(data.v)} (this reads version 1)` };\n const dropped: string[] = [];\n const drop = (what: string): void => {\n if (!dropped.includes(what)) dropped.push(what);\n };\n for (const k of Object.keys(data)) if (![\"v\", \"edges\", \"floats\", \"items\"].includes(k)) drop(k);\n const known = (id: unknown): id is string => typeof id === \"string\" && id !== \"__proto__\" && Object.hasOwn(base.items, id);\n const isFixed = (id: string): boolean => known(id) && base.items[id]!.fixed === true;\n\n // The items' states.\n const items: Record<string, SceneItem> = { ...base.items };\n if (data.items !== undefined && !isObject(data.items)) drop(\"items\");\n else if (isObject(data.items)) {\n for (const id of Object.keys(data.items)) {\n const s = data.items[id];\n if (!known(id) || !isObject(s)) {\n drop(`item:${id}`);\n continue;\n }\n const b = base.items[id]!;\n const { kept: _k, from: _f, closed: _c, align: _a, floatSize: _s, ...plain } = b;\n let it: SceneItem = { ...plain, used: b.used };\n for (const k of Object.keys(s)) if (![\"used\", \"kept\", \"from\", \"closed\", \"align\", \"floatSize\"].includes(k)) drop(`item:${id}:${k}`);\n if (isNum(s.used)) it = { ...it, used: s.used };\n else if (s.used !== undefined) drop(`item:${id}:used`);\n if (s.kept === true) it = { ...it, kept: true };\n else if (s.kept !== undefined && s.kept !== false) drop(`item:${id}:kept`);\n if (isNum(s.from) && Number.isInteger(s.from) && s.from >= 1 && !b.fixed) it = { ...it, from: s.from };\n else if (s.from !== undefined) drop(`item:${id}:from`);\n if (b.fixed && b.from !== undefined) it = { ...it, from: b.from };\n if (s.closed === true && !b.fixed) it = { ...it, closed: true };\n else if (s.closed !== undefined && s.closed !== false) drop(`item:${id}:closed`);\n if (s.align === \"center\" || s.align === \"end\") it = { ...it, align: s.align };\n else if (s.align !== undefined && s.align !== \"start\") drop(`item:${id}:align`);\n if (b.fixed && b.align) it = { ...it, align: b.align };\n const fs = s.floatSize;\n if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) it = { ...it, floatSize: { width: fs.width, height: fs.height } };\n else if (fs !== undefined) drop(`item:${id}:floatSize`);\n items[id] = it;\n }\n }\n\n // Where they are: stored edges by id, then stored floats.\n const placed = new Set<string>();\n const order = new Map<string, string[]>();\n const sizes = new Map<string, number | undefined>();\n const made: Edge[] = [];\n const rings = new Map<string, number>();\n if (data.edges !== undefined && !Array.isArray(data.edges)) drop(\"edges\");\n for (const e of Array.isArray(data.edges) ? (data.edges as unknown[]) : []) {\n if (!isObject(e) || typeof e.id !== \"string\") {\n drop(\"an edge with no id\");\n continue;\n }\n let edge = base.edges.find((x) => x.id === e.id) ?? made.find((x) => x.id === e.id);\n if (!edge && e.column === true && (e.side === \"left\" || e.side === \"right\") && base.columns?.[e.side]) {\n // A column the user made: from its side's template.\n const t = base.columns[e.side]!;\n edge = { id: e.id, side: e.side, ring: isNum(e.ring) ? e.ring : Infinity, accepts: t.accepts, items: [], cross: t.cross, ...(t.gap !== undefined ? { gap: t.gap } : {}), ...(t.pad ? { pad: t.pad } : {}), ...(t.menu ? { menu: t.menu } : {}), column: true };\n made.push(edge);\n }\n if (!edge || order.has(edge.id)) {\n drop(`edge:${e.id}`);\n continue;\n }\n if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);\n if (e.side !== undefined && !SIDES.includes(e.side as Side)) drop(`edge:${e.id}:side`);\n const ids: string[] = [];\n for (const id of Array.isArray(e.items) ? (e.items as unknown[]) : []) {\n if (!known(id) || placed.has(id)) drop(`edge:${edge.id}:${String(id)}`);\n // A fixed item stays in the edge `base` has it in, at the place the store gives it there; elsewhere it is dropped.\n else if (isFixed(id)) {\n if (edge.items.includes(id) && base.edges.some((x) => x.id === edge.id)) {\n ids.push(id);\n placed.add(id);\n } else drop(`edge:${edge.id}:${id}`);\n }\n else if (!edge.accepts.includes(items[id]!.kind)) drop(`edge:${edge.id}:${id}`);\n else {\n ids.push(id);\n placed.add(id);\n }\n }\n order.set(edge.id, ids);\n if (isNum(e.size)) sizes.set(edge.id, e.size);\n else if (e.size !== undefined) drop(`edge:${edge.id}:size`);\n else sizes.set(edge.id, undefined);\n }\n const floats: SceneFloat[] = [];\n if (data.floats !== undefined && !Array.isArray(data.floats)) drop(\"floats\");\n for (const f of Array.isArray(data.floats) ? (data.floats as unknown[]) : []) {\n if (!isObject(f) || typeof f.id !== \"string\") {\n drop(\"a float with no id\");\n continue;\n }\n const id = f.id;\n if (!known(id) || placed.has(id) || isFixed(id) || !base.floatKinds.includes(items[id]!.kind) || !isNum(f.x) || !isNum(f.y) || !isSize(f.width) || !isSize(f.height)) {\n drop(`float:${id}`);\n continue;\n }\n for (const k of Object.keys(f)) if (k === \"pinned\") drop(`pinned:${id}`);\n else if (![\"id\", \"x\", \"y\", \"width\", \"height\", \"orient\", \"anchor\"].includes(k)) drop(`float:${id}:${k}`);\n const o = f.orient === \"row\" || f.orient === \"column\" ? f.orient : undefined;\n if (f.orient !== undefined && !o) drop(`float:${id}:orient`);\n const a = ANCHORS.includes(f.anchor as FloatAnchor) ? (f.anchor as FloatAnchor) : undefined;\n if (f.anchor !== undefined && !a) drop(`float:${id}:anchor`);\n placed.add(id);\n // Clamped by what solve draws (a folded float's bar), never cut: a reload lands where solve put it.\n const r = rect(f.x, f.y, f.width, f.height);\n const drawn = drawnFloatSize(items[id]!, { rect: r, ...(o ? { orient: o } : {}) });\n floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...(o ? { orient: o } : {}), ...(a ? { anchor: a } : {}) });\n }\n\n // Each base edge: its stored order exactly (fixed items where the store put them), its base items the store placed\n // nowhere before a stored trailing run of fixed items, and fixed items the store lacks at their base places.\n const edges: Edge[] = [...base.edges, ...made].map((edge) => {\n const stored = order.get(edge.id) ?? [];\n const rest = edge.items.filter((id) => !isFixed(id) && !placed.has(id));\n for (const id of rest) placed.add(id);\n let tail = stored.length;\n while (tail > 0 && isFixed(stored[tail - 1]!)) tail--;\n const listed = [...stored.slice(0, tail), ...rest, ...stored.slice(tail)];\n const items1 = withFixed(edge.items, listed, isFixed);\n const size = sizes.has(edge.id) ? sizes.get(edge.id) : edge.size;\n const { size: _s, ...plain } = edge;\n return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...(size !== undefined ? { size } : {}) };\n });\n // Base floats the store placed nowhere keep their base place.\n for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);\n // Empty columns go; the sides' rings close up.\n const scene = prune({ ...base, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? [\"left\", \"right\"] : [])), floats });\n return { scene, dropped };\n}\n","/**\n * `targets(scene, dragged, { previous, endReach, floatSize })`: every drop target for one dragged item, in the shape\n * `@n-uf/motion/drag` takes (`id`, `priority`, `hit`, `slot?`, `free?`). Each target's `after(point, grab)` is the scene\n * a release there commits and its layout, `solve(after.scene, { previous })`: the host draws every item from that layout\n * during the preview (C22), so the preview is the result by construction.\n *\n * - `gap:<edge>:<zone>:<at>` (priority 2): for every edge whose `accepts` lists the dragged item's kind (deny by\n * default, C25), a target before the `at`-th item of each zone (start, center, end) and at each zone's end, so an\n * empty center or end zone can be opened. Only where the item fits (C29): after the drop it isn't in the » menu, the\n * edge doesn't overflow, nothing in the edge is newly `too-wide`, every fixed item of the edge keeps its form and its\n * place (a growing one may give up its spare length), and its slot covers no chrome. The hit is the edge's stretch\n * between the neighbouring gaps (split halfway between their insertion lines), across the larger of the edge's\n * thickness before and after the drop, the first and last reaching `endReach` px past the edge's ends; it is cut\n * clear of the edge's fixed items and the chrome rects (a gap whose line lies inside one has no target). `marker`\n * is the insertion line after the drop, across the edge; `slot` the item's rect after the drop.\n * - `strip:<edge>` (2): an empty edge that accepts the kind: a strip `Edge.strip` px (default 24) deep along its side,\n * inside the content. `after` shows the edge holding the item.\n * - `float:<id>` (3, free): when `floatKinds` lists the kind. The hit covers the whole plane; the landing is the float\n * with the pointer holding it at `grab` (default its middle), in the stage and clear of the docked items, the bars\n * and the chrome. Its size: `options.floatSize`, else its float's size, else the item's `floatSize`, else the default.\n * - `column:<side>:<ring>` (2): a new column on each column line of a side whose `scene.columns[side]` takes the kind\n * (outside the outermost open column, between two, inside the innermost; on a side with none, at the content's\n * edge), `COLUMN_REACH` px each way, only where the new column shows open.\n * - `rail:<side>:<ring>` (1): docking folded into a side's rail (its rail and its template take the kind), before each\n * folded column's segments and after the last, or a strip `RAIL_EDGE` px deep at the side's outer edge when no rail\n * shows.\n * - `none:<i>` (1): over each `scene.blocked` rect. It takes the pointer, and a release there commits nothing.\n * - `home:<id>` (1): over a docked item's own rect (or its » entry); a floating item has none, so a move inside its own\n * rect is a float move. A release there commits nothing. A gap, column line or rail drop that\n * would put the item back where it is (the gap beside it, its own column's line, its own side's rail) keeps its id but\n * is a home too: place `home`, no slot, nothing committed.\n *\n * `stops(scene, id)` orders the same targets (no home, no none) for \"Move to ›\" and the arrow keys.\n *\n * A dropped item counts as just used (`use`). An unknown, fixed or closed item has no targets.\n */\nimport { rect, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Target } from \"../targets/target\";\nimport { floatAt, lift, moveTo, use, type ColumnPlace, type RailPlace } from \"./changes\";\nimport { DEFAULT_FLOAT_SIZE, DEFAULT_HIT_BAND, DEFAULT_STRIP, ZONES, axisOf, formsOf, zoneOf, type Edge, type Scene, type SceneLayout, type Zone } from \"./model\";\nimport { solve } from \"./solve\";\n\nexport type ScenePlace =\n | { readonly kind: \"gap\"; readonly edge: string; readonly zone: Zone; readonly at: number }\n | ColumnPlace\n | RailPlace\n | { readonly kind: \"float\" }\n | { readonly kind: \"home\" }\n | { readonly kind: \"none\" };\n\nexport interface SceneAfter {\n readonly scene: Scene;\n readonly layout: SceneLayout;\n}\n\nexport interface SceneTarget extends Target {\n /** The item dragged. */\n readonly item: string;\n readonly place: ScenePlace;\n /** Gaps and strips: the line where the item's leading edge lands, zero thick, across the edge after the drop. */\n readonly marker?: Rect;\n /** The scene a release here commits and its layout. Only a float's depends on the pointer. */\n after(point: Point, grab?: Point): SceneAfter;\n}\n\nexport interface SceneTargetOptions {\n /** The layout before the drag: every `after` is solved with it, as the drop will be. */\n readonly previous?: SceneLayout;\n /** How far the first and last gaps of an edge reach past its ends, px (default 0). */\n readonly endReach?: number;\n /** The float's size for the float target. */\n readonly floatSize?: Size;\n /** As `solve`'s: edge or item ids solved without `previous`, in every `after` too. */\n readonly fresh?: readonly string[];\n}\n\nconst EPS = 1e-6;\n/** A zone that covers any pointer the page can see. */\nexport const PLANE: Rect = rect(-1e9, -1e9, 2e9, 2e9);\n\nconst area = (r: Rect): number => Math.max(0, r.width) * Math.max(0, r.height);\nconst overlaps = (a: Rect, b: Rect): boolean => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS;\nconst contains = (r: Rect, p: Point): boolean => p.x >= r.x - EPS && p.x <= r.x + r.width + EPS && p.y >= r.y - EPS && p.y <= r.y + r.height + EPS;\n\n/**\n * `hit` with every blocker cut out: for each blocker it overlaps, the largest of the four parts beside the blocker that\n * still holds `keep`. Null when `keep` is inside a blocker or nothing is left.\n */\nexport function cutClear(hit: Rect, blockers: readonly Rect[], keep: Point): Rect | null {\n let h = hit;\n for (const b of blockers) {\n if (!overlaps(h, b)) continue;\n const right = h.x + h.width;\n const bottom = h.y + h.height;\n const parts = [\n rect(h.x, h.y, Math.min(right, b.x) - h.x, h.height),\n rect(Math.max(h.x, b.x + b.width), h.y, right - Math.max(h.x, b.x + b.width), h.height),\n rect(h.x, h.y, h.width, Math.min(bottom, b.y) - h.y),\n rect(h.x, Math.max(h.y, b.y + b.height), h.width, bottom - Math.max(h.y, b.y + b.height)),\n ].filter((p) => area(p) > EPS && contains(p, keep));\n if (parts.length === 0) return null;\n h = parts.reduce((a, p) => (area(p) > area(a) ? p : a));\n }\n return area(h) > EPS ? h : null;\n}\n\nexport function targets(scene: Scene, dragged: string, options: SceneTargetOptions = {}): SceneTarget[] {\n const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : undefined;\n if (!item || item.fixed || item.closed) return [];\n const prev = { ...(options.previous ? { previous: options.previous } : {}), ...(options.fresh ? { fresh: options.fresh } : {}) };\n const settle = (s: Scene): SceneAfter => ({ scene: s, layout: solve(s, prev) });\n const now = solve(scene, prev);\n const rest = lift(scene, dragged);\n const base = solve(rest, prev);\n const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach! : 0);\n const chrome = scene.chrome ?? [];\n // No hit covers a fixed item's reserved rect, nor chrome: fixed items of every edge (an end reach may run into the next\n // bar), where they are drawn now and where they are with the item lifted out. A growing fixed item (a title filling\n // its bar) reserves only its natural rect; the length it grew by is spare room where gaps may lie, and a drop there\n // shrinks it toward its natural size (to its `min` if the room needs it), so a group lifted out of a title bar can\n // always go back while the room allows.\n const fixedRects = (l: SceneLayout): Rect[] => Object.entries(l.items).filter(([, it]) => it.fixed).map(([id]) => reservedRect(scene, l, id));\n const blockers = [...fixedRects(now), ...fixedRects(base), ...chrome];\n const out: SceneTarget[] = [];\n\n const docked: SceneTarget[] = [];\n for (const edge of rest.edges) {\n if (!edge.accepts.includes(item.kind)) continue;\n docked.push(...edgeTargets(scene, rest, base, edge, dragged, reach, blockers, chrome, settle));\n }\n for (const side of [\"left\", \"right\"] as const) {\n if (scene.columns?.[side]?.accepts.includes(item.kind)) docked.push(...columnTargets(scene, rest, base, side, dragged, blockers, settle));\n if (scene.columns?.[side]?.accepts.includes(item.kind) && scene.rails?.[side]?.accepts.includes(item.kind)) docked.push(...railTargets(scene, rest, base, side, dragged, blockers, settle));\n }\n // A drop that puts the item back where it is (the gap beside it, its own column's line, its own rail) is its home: it\n // commits nothing and shows no slot.\n const here = placeKey(scene, dragged);\n const ownRail = now.items[dragged]?.rail;\n // C29 across the whole scene: a drop may not add an `overflow` or `too-wide` note to any edge, change any fixed item's\n // form, or squeeze one under its `main.min`, anywhere; nor land on chrome.\n const noteKey = (n: SceneLayout[\"notes\"][number]): string | null => (\"edge\" in n && (n.code === \"overflow\" || n.code === \"too-wide\") ? `${n.edge}:${n.code}:${\"id\" in n ? n.id : \"\"}` : null);\n const hadNotes = new Set(base.notes.map(noteKey).filter((k): k is string => k !== null));\n const sound = (after: SceneLayout): boolean => {\n if (after.notes.some((n) => { const k = noteKey(n); return k !== null && !hadNotes.has(k); })) return false;\n for (const [id, b] of Object.entries(base.items)) {\n if (!b.fixed) continue;\n const a = after.items[id];\n const e = a?.edge ? after.edges[a.edge] : undefined;\n if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;\n const f = formsOf(scene.items[id]!, axisOf(e.side))[a.form];\n const len = axisOf(e.side) === \"column\" ? a.rect.height : a.rect.width;\n if (f && len < f.main.min - 0.5) return false;\n }\n const me = after.items[dragged];\n if (!me) return true;\n // The slot never lies over chrome, nor over a fixed item's reserved (natural) rect after the drop.\n const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && id !== dragged).map(([id]) => reservedRect(scene, after, id));\n return !chrome.some((c) => overlaps(me.rect, c)) && !fixedAfter.some((f) => overlaps(me.rect, f));\n };\n for (const t of docked) {\n const p = t.place;\n const own = (p.kind === \"rail\" && p.side === ownRail) || placeKey(t.after({ x: 0, y: 0 }).scene, dragged) === here;\n if (own) out.push({ id: t.id, priority: t.priority, hit: t.hit, item: dragged, place: { kind: \"home\" }, after: () => ({ scene, layout: now }) });\n else if (sound(t.after({ x: 0, y: 0 }).layout)) out.push(t);\n }\n\n if (scene.floatKinds.includes(item.kind)) {\n const was = scene.floats.find((f) => f.id === dragged);\n const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : (item.floatSize ?? DEFAULT_FLOAT_SIZE));\n out.push({\n id: `float:${dragged}`,\n priority: 3,\n free: true,\n hit: PLANE,\n item: dragged,\n place: { kind: \"float\" },\n after(point, grab) {\n const g = grab ?? { x: size.width / 2, y: size.height / 2 };\n const raw = rect(point.x - g.x, point.y - g.y, size.width, size.height);\n const first = solve(use(floatAt(scene, dragged, raw), dragged), prev);\n const at = first.items[dragged]?.rect ?? raw;\n return settle(use(floatAt(scene, dragged, rect(at.x, at.y, size.width, size.height)), dragged));\n },\n });\n }\n\n (scene.blocked ?? []).forEach((b, i) => {\n out.push({ id: `none:${i}`, priority: 1, hit: rect(b.x, b.y, b.width, b.height), item: dragged, place: { kind: \"none\" }, after: () => ({ scene, layout: now }) });\n });\n\n // A docked item's own place is its home. A floating item has none: a move inside its own rect is a float move.\n const own = now.items[dragged];\n if (own && !own.floating) out.push({ id: `home:${dragged}`, priority: 1, hit: own.rect, item: dragged, place: { kind: \"home\" }, after: () => ({ scene, layout: now }) });\n return out;\n}\n\n/**\n * What a fixed item reserves in `l`: its drawn rect, or for a form that grows only its natural length, placed by its\n * zone (from its start, from its end in the end zone, centred in the centre zone). No hit or slot ever lies there, so a\n * host that draws \"no drop\" areas reads them from here.\n */\nexport function reservedRect(scene: Scene, l: SceneLayout, id: string): Rect {\n const it = l.items[id]!;\n const e = it.edge ? l.edges[it.edge] : undefined;\n const f = e ? formsOf(scene.items[id]!, axisOf(e.side))[it.form] : undefined;\n if (!e || !f?.main.grows) return it.rect;\n const column = axisOf(e.side) === \"column\";\n const len = column ? it.rect.height : it.rect.width;\n const keep = Math.min(len, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len));\n const shift = it.zone === \"end\" ? len - keep : it.zone === \"center\" ? (len - keep) / 2 : 0;\n return column ? rect(it.rect.x, it.rect.y + shift, it.rect.width, keep) : rect(it.rect.x + shift, it.rect.y, keep, it.rect.height);\n}\n\n/** Where things are, without ages or the ids of dynamic columns: two scenes with one key place every item alike. */\nfunction placeKey(s: Scene, id: string): string {\n const it = Object.hasOwn(s.items, id) ? s.items[id] : undefined;\n return JSON.stringify({\n edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? \"\" : e.id, e.items, e.size ?? null])).sort(),\n floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),\n from: it?.from ?? 0,\n align: it?.align ?? \"start\",\n });\n}\n\n/** How far a column line's hit reaches on each side of the line, px; how deep a side's edge takes a rail drop when it has no rail. */\nexport const COLUMN_REACH = 22;\nexport const RAIL_EDGE = 10;\n\n/** The open dynamic columns of a side in `base`, outer first, with their ring in `rest`. */\nfunction openColumns(rest: Scene, base: SceneLayout, side: \"left\" | \"right\"): { edge: Edge; r: Rect }[] {\n return rest.edges\n .filter((e) => e.side === side && e.column === true)\n .map((edge) => ({ edge, l: base.edges[edge.id] }))\n .filter((x) => x.l && !x.l.folded && !x.l.rides && x.l.cross > 0)\n .sort((a, b) => a.edge.ring - b.edge.ring)\n .map((x) => ({ edge: x.edge, r: x.l!.rect }));\n}\n\n/** The side's columns' stretch down the stage: the open columns', else the content's. */\nfunction sideSpan(base: SceneLayout, side: \"left\" | \"right\"): { y: number; height: number } {\n const own = Object.values(base.edges).filter((e) => e.side === side && e.rect.height > 0);\n const r = own[0]?.rect ?? base.content;\n return { y: r.y, height: r.height };\n}\n\n/**\n * `column:<side>:<ring>` (priority 2): a new column on every column line of a side (outside its outermost open column,\n * between two, inside the innermost; on a side with none, at the content's edge), when `scene.columns[side]` takes the\n * kind. The hit is `COLUMN_REACH` px on each side of the line, down the columns' stretch. Only where the new column\n * shows open.\n */\nfunction columnTargets(scene: Scene, rest: Scene, base: SceneLayout, side: \"left\" | \"right\", dragged: string, blockers: readonly Rect[], settle: (s: Scene) => SceneAfter): SceneTarget[] {\n const cols = openColumns(rest, base, side);\n const span = sideSpan(base, side);\n const mine = rest.edges.filter((e) => e.side === side);\n const inner = mine.length === 0 ? 0 : Math.max(...mine.map((e) => e.ring)) + 1;\n const lines: { x: number; ring: number }[] = [];\n const outerX = (r: Rect): number => (side === \"left\" ? r.x : r.x + r.width);\n const innerX = (r: Rect): number => (side === \"left\" ? r.x + r.width : r.x);\n cols.forEach((c) => lines.push({ x: outerX(c.r), ring: c.edge.ring }));\n if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1]!.r), ring: cols[cols.length - 1]!.edge.ring + 1 });\n else lines.push({ x: side === \"left\" ? base.content.x : base.content.x + base.content.width, ring: inner });\n const out: SceneTarget[] = [];\n for (const line of lines) {\n const place: ColumnPlace = { kind: \"column\", side, ring: line.ring };\n const result = settle(use(moveTo(scene, dragged, place), dragged));\n const me = result.layout.items[dragged];\n const el = me?.edge ? result.layout.edges[me.edge] : undefined;\n if (!me || !el || me.inMenu || el.folded || el.rides || result.scene === scene) continue;\n const keep = { x: line.x, y: span.y + span.height / 2 };\n const hit = cutClear(rect(line.x - COLUMN_REACH, span.y, 2 * COLUMN_REACH, span.height), blockers, keep);\n if (!hit) continue;\n out.push({ id: `column:${side}:${line.ring}`, priority: 2, hit, slot: me.rect, marker: rect(line.x, span.y, 0, span.height), item: dragged, place, after: () => result });\n }\n return out;\n}\n\n/**\n * `rail:<side>:<ring>` (priority 1): docking folded into the side's rail, when its rail and its column template take the\n * kind: before each folded column's segments and after the last (the rail split halfway between them), or, with no\n * rail shown, a strip `RAIL_EDGE` px deep at the side's outer edge. The drop makes a column at that ring with the item\n * folded by hand, so it lands as a segment.\n */\nfunction railTargets(scene: Scene, rest: Scene, base: SceneLayout, side: \"left\" | \"right\", dragged: string, blockers: readonly Rect[], settle: (s: Scene) => SceneAfter): SceneTarget[] {\n const rail = base.rails[side];\n const mine = rest.edges.filter((e) => e.side === side).sort((a, b) => a.ring - b.ring);\n const ringOf = (id: string): number => rest.edges.find((e) => e.id === id)?.ring ?? 0;\n const stops: { y: number; ring: number }[] = [];\n let zone: Rect;\n if (rail && rail.segments.length > 0) {\n zone = rail.rect;\n const groups: { edge: string; y0: number; y1: number }[] = [];\n for (const s of rail.segments) {\n const g = groups[groups.length - 1];\n if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;\n else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });\n }\n for (const g of groups) stops.push({ y: g.y0, ring: ringOf(g.edge) });\n const last = groups[groups.length - 1]!;\n stops.push({ y: last.y1, ring: ringOf(last.edge) + 1 });\n } else {\n const span = sideSpan(base, side);\n const firstCol = mine.find((e) => e.column === true);\n const outer = Object.values(base.edges).filter((e) => e.side === side && e.rect.height > 0);\n const x = side === \"left\" ? Math.min(base.content.x, ...outer.map((e) => e.rect.x)) : Math.max(base.content.x + base.content.width, ...outer.map((e) => e.rect.x + e.rect.width));\n zone = rect(side === \"left\" ? x : x - RAIL_EDGE, span.y, RAIL_EDGE, span.height);\n stops.push({ y: span.y, ring: firstCol ? firstCol.ring : mine.length === 0 ? 0 : mine[mine.length - 1]!.ring + 1 });\n }\n const out: SceneTarget[] = [];\n stops.forEach((s, i) => {\n const from = i === 0 ? zone.y : (stops[i - 1]!.y + s.y) / 2;\n const to = i === stops.length - 1 ? zone.y + zone.height : (s.y + stops[i + 1]!.y) / 2;\n if (to - from <= EPS) return;\n const place: RailPlace = { kind: \"rail\", side, ring: s.ring };\n const result = settle(use(moveTo(scene, dragged, place), dragged));\n const me = result.layout.items[dragged];\n if (!me || me.rail !== side || result.scene === scene) return;\n const hit = cutClear(rect(zone.x, from, zone.width, to - from), blockers, { x: zone.x + zone.width / 2, y: Math.min(Math.max(s.y, from), to) });\n if (!hit) return;\n out.push({ id: `rail:${side}:${s.ring}`, priority: 1, hit, slot: me.rect, marker: rect(zone.x, me.rect.y, zone.width, 0), item: dragged, place, after: () => result });\n });\n return out;\n}\n\nconst SIDE_RANK: Record<string, number> = { left: 0, top: 1, bottom: 2, right: 3 };\n\n/**\n * `stops(scene, id, options?)`: the places for \"Move to ›\" and the arrow keys, in reading order, from the same targets\n * (`home` and `none` left out): the left side outer to inner, the top bars, the bottom bars, the right side inner to\n * outer, floating last. Each stop is a target, so its `after` is the move.\n */\nexport function stops(scene: Scene, dragged: string, options: SceneTargetOptions = {}): SceneTarget[] {\n const list = targets(scene, dragged, options).filter((t) => t.place.kind !== \"home\" && t.place.kind !== \"none\");\n const sideOf = (t: SceneTarget): string => {\n const p = t.place;\n if (p.kind === \"float\") return \"float\";\n if (p.kind === \"column\" || p.kind === \"rail\") return p.side;\n if (p.kind === \"gap\") return scene.edges.find((e) => e.id === p.edge)?.side ?? \"float\";\n return \"float\";\n };\n const key = (t: SceneTarget): [number, number, number] => {\n const side = sideOf(t);\n const r = t.slot ?? t.hit;\n const cx = r.x + r.width / 2;\n const cy = r.y + r.height / 2;\n const rank = side === \"float\" ? 4 : SIDE_RANK[side]!;\n return side === \"left\" ? [rank, cx, cy] : side === \"right\" ? [rank, -cx, cy] : [rank, cy * (side === \"bottom\" ? -1 : 1), cx];\n };\n return list\n .map((t, i) => ({ t, i, k: key(t) }))\n .sort((a, b) => a.k[0] - b.k[0] || a.k[1] - b.k[1] || a.k[2] - b.k[2] || a.i - b.i)\n .map((x) => x.t);\n}\n\n/** One edge's gap or strip targets. `rest` is the scene with the dragged item lifted out and `base` its layout. */\nfunction edgeTargets(scene: Scene, rest: Scene, base: SceneLayout, edge: Edge, dragged: string, reach: number, blockers: readonly Rect[], chrome: readonly Rect[], settle: (s: Scene) => SceneAfter): SceneTarget[] {\n const el = base.edges[edge.id];\n // A folded or riding column takes drops through its side's rail and column lines, not gaps.\n if (!el || el.folded || el.rides) return [];\n const column = axisOf(edge.side) === \"column\";\n const restEdge = rest.edges.find((e) => e.id === edge.id)!;\n const fixedIds = restEdge.items.filter((id) => rest.items[id]?.fixed && base.items[id]?.edge === edge.id);\n const tooWideBefore = new Set(base.notes.flatMap((n) => (\"edge\" in n && n.edge === edge.id && n.code === \"too-wide\" ? [n.id] : [])));\n\n /** Whether a drop's layout leaves room for the item in this edge (C29). */\n const fits = (after: SceneLayout): boolean => {\n const me = after.items[dragged];\n if (!me || me.edge !== edge.id || me.inMenu) return false;\n for (const n of after.notes) {\n if (!(\"edge\" in n) || n.edge !== edge.id) continue;\n if (n.code === \"overflow\") return false;\n if (n.code === \"too-wide\" && !tooWideBefore.has(n.id)) return false;\n }\n for (const id of fixedIds) {\n const a = after.items[id];\n const b = base.items[id]!;\n if (!a || a.form !== b.form || a.formKind !== b.formKind || Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5) return false;\n }\n return !chrome.some((c) => overlaps(me.rect, c));\n };\n const markerOf = (after: SceneLayout): Rect => {\n const slot = after.items[dragged]!.rect;\n const e = after.edges[edge.id]!;\n return column ? rect(e.rect.x, slot.y, e.cross, 0) : rect(slot.x, e.rect.y, 0, e.cross);\n };\n const target = (id: string, place: Extract<ScenePlace, { kind: \"gap\" }>, hit: Rect, keep: Point, solved?: SceneAfter): SceneTarget | null => {\n const result = solved ?? settle(use(moveTo(scene, dragged, place), dragged));\n if (!fits(result.layout)) return null;\n const clear = cutClear(hit, blockers, keep);\n if (!clear) return null;\n return { id, priority: 2, hit: clear, slot: result.layout.items[dragged]!.rect, marker: markerOf(result.layout), item: dragged, place, after: () => result };\n };\n\n const drawn = base.edges[edge.id]!.stack.items.filter((p) => p.kind !== \"menu\").map((p) => p.id);\n if (drawn.length === 0 && !el.menu) {\n // An empty edge: one strip inside the content along its side.\n const depth = Math.max(0, Number.isFinite(edge.strip) ? edge.strip! : DEFAULT_STRIP);\n const r = el.rect;\n const hit =\n edge.side === \"left\"\n ? rect(r.x, r.y, depth, r.height)\n : edge.side === \"right\"\n ? rect(r.x + r.width - depth, r.y, depth, r.height)\n : edge.side === \"top\"\n ? rect(r.x, r.y, r.width, depth)\n : rect(r.x, r.y + r.height - depth, r.width, depth);\n const keep = { x: hit.x + hit.width / 2, y: hit.y + hit.height / 2 };\n const t = target(`strip:${edge.id}`, { kind: \"gap\", edge: edge.id, zone: \"start\", at: 0 }, hit, keep);\n return t ? [t] : [];\n }\n\n // Each gap's insertion line along the edge, in the layout without the dragged item.\n const main0 = column ? el.rect.y : el.rect.x;\n const length = column ? el.rect.height : el.rect.width;\n const at = (r: Rect): number => (column ? r.y : r.x);\n const len = (r: Rect): number => (column ? r.height : r.width);\n const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };\n const menuLen = el.menu ? len(el.menu.rect) : 0;\n const drawnOf = (z: Zone): Rect[] => restEdge.items.filter((id) => zoneOf(rest.items[id]) === z && base.items[id]?.edge === edge.id && !base.items[id]!.inMenu).map((id) => base.items[id]!.rect);\n const startEnd = ((): number => {\n const s = drawnOf(\"start\");\n return s.length ? at(s[s.length - 1]!) + len(s[s.length - 1]!) : main0 + pad.start;\n })();\n const endStart = ((): number => {\n const e = drawnOf(\"end\");\n return e.length ? at(e[0]!) : main0 + length - pad.end - menuLen;\n })();\n const empty: Record<Zone, number> = { start: main0 + pad.start, center: Math.min(Math.max(main0 + length / 2, startEnd), Math.max(startEnd, endStart)), end: main0 + length - pad.end - menuLen };\n const gaps: { zone: Zone; at: number; line: number }[] = [];\n for (const zone of ZONES) {\n const members = restEdge.items.filter((id) => zoneOf(rest.items[id]) === zone);\n for (let k = 0; k <= members.length; k++) {\n const next = members.slice(k).find((id) => base.items[id]?.edge === edge.id && !base.items[id]!.inMenu);\n const before = members\n .slice(0, k)\n .reverse()\n .find((id) => base.items[id]?.edge === edge.id && !base.items[id]!.inMenu);\n const line = next ? at(base.items[next]!.rect) : before ? at(base.items[before]!.rect) + len(base.items[before]!.rect) : empty[zone];\n gaps.push({ zone, at: k, line });\n }\n }\n // Gaps on one line are one place to the pointer: the first (in zone order) takes it.\n const sorted = gaps\n .map((g, i) => ({ ...g, i }))\n .sort((a, b) => a.line - b.line || a.i - b.i)\n .filter((g, i, all) => i === 0 || Math.abs(g.line - all[i - 1]!.line) > EPS);\n const out: SceneTarget[] = [];\n // `hitBand`: \"middle\" splits the edge halfway between the insertion lines (an item's halves belong to its gaps); a\n // number is a band that many px around each line, so the middle of an item is no gap. Columns default to a band.\n const bandOpt = edge.hitBand ?? (column ? DEFAULT_HIT_BAND : \"middle\");\n const band = bandOpt === \"middle\" ? Infinity : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND);\n sorted.forEach((g, i) => {\n const lo = i === 0 ? -Infinity : (sorted[i - 1]!.line + g.line) / 2;\n const hi = i === sorted.length - 1 ? Infinity : (g.line + sorted[i + 1]!.line) / 2;\n // Never into a neighbour's band; the first and last reach `endReach` past the edge's ends.\n let from = Math.max(lo, g.line - band / 2);\n let to = Math.min(hi, g.line + band / 2);\n if (i === 0) from = Math.min(from, main0 - reach);\n if (i === sorted.length - 1) to = Math.max(to, main0 + length + reach);\n // Past the edge's ends only as far as `endReach`.\n from = Math.max(from, main0 - reach);\n to = Math.min(to, main0 + length + reach);\n if (to - from <= EPS) return;\n const place = { kind: \"gap\" as const, edge: edge.id, zone: g.zone, at: g.at };\n // Across: from the edge's outer side, the larger of its thickness now and after the drop (known after the solve).\n const result = settle(use(moveTo(scene, dragged, place), dragged));\n const thick = Math.max(el.cross, result.layout.edges[edge.id]?.cross ?? 0);\n const r = el.rect;\n const hit = column\n ? rect(edge.side === \"left\" ? r.x : r.x + r.width - thick, from, thick, to - from)\n : rect(from, edge.side === \"top\" ? r.y : r.y + r.height - thick, to - from, thick);\n const line = Math.min(Math.max(g.line, from), to);\n const keep = column ? { x: hit.x + hit.width / 2, y: line } : { x: line, y: hit.y + hit.height / 2 };\n const t = target(`gap:${edge.id}:${g.zone}:${g.at}`, place, hit, keep, result);\n if (t) out.push(t);\n });\n return out;\n}\n"],"mappings":";;;;;;;;;;;AAeO,IAAM,QAAyB,CAAC,OAAO,SAAS,UAAU,MAAM;AAIhE,IAAM,QAAyB,CAAC,SAAS,UAAU,KAAK;AAuQxD,IAAM,gBAAgB;AAEtB,IAAM,mBAAmB;AAEzB,IAAM,qBAA2B,EAAE,OAAO,KAAK,QAAQ,IAAI;AAG3D,IAAM,SAAS,CAAC,SAAwB,SAAS,UAAU,SAAS,UAAU,WAAW;AACzF,IAAM,SAAS,CAAC,SAAuC,MAAM,UAAU,YAAY,MAAM,UAAU,QAAQ,KAAK,QAAQ;AACxH,IAAM,UAAU,CAAC,MAAiB,SAAuC,KAAK,MAAM,IAAI,KAAK,CAAC;;;AC5PrG,IAAM,MAAM;AACZ,IAAM,SAAS,CAAC,GAAuB,aAA8B,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,IAAI;AACvH,IAAM,KAAK,CAAC,MAAkC,KAAK,IAAI,GAAG,OAAO,GAAG,CAAC,CAAC;AAG/D,SAAS,SAAS,OAAgC;AACvD,QAAM,QAAQ,CAAC,MAAqB,EAAE,SAAS,UAAU,EAAE,SAAS,UAAU,IAAI,EAAE,SAAS,YAAY,IAAI;AAC7G,QAAM,WAAW,CAAC,MAAqB,EAAE,SAAS,SAAS,EAAE,SAAS,SAAS,IAAI;AACnF,SAAO,MACJ,IAAI,CAAC,GAAG,OAAO,EA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KAAK;AACnC,SAAK,KAAK,IAAI,IAAI,QAAQ,SAAS,KAAK;AACxC,QAAI,KAAK,QAAQA,KAAK;AACtB,UAAM,QAAQ,EAAE,MAAM,OAAgB,MAAM,KAAK,IAAI,MAAM,EAAE,MAAM,IAAI,EAAE,GAAG;AAE5E,UAAM,SAAS,OAAO,IAAI,OAAO,OAAO,SAAS,KAAK,GAAG,OAAO,CAAC;AACjE,UAAM,QAAQ,KAAK,IAAI,GAAG,OAAO,OAAO,OAAO,MAAM,KAAK,EAAE,GAAG,SAAS,CAAC;AACzE,UAAM,IAAI,GAAG;AACb,UAAM,MAAM,SACR,KAAK,KAAK,SAAS,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,OAAO,MAAM,OAAO,KAAK,IAAI,IAC/E,KAAK,MAAM,KAAK,SAAS,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,OAAO,KAAK,MAAM,KAAK;AACnF,UAAM,OAAO,KAAK,IAAI,KAAK,IAAI,EAAE,MAAM,IAAI,GAAG,EAAE;AAChD,UAAMC,QAAO,SAAS,EAAE,GAAG,IAAI,IAAI,IAAI,QAAQ,GAAG,GAAG,KAAK,IAAI,EAAE,GAAG,MAAM,GAAG,IAAI,IAAI,IAAI,SAAS,EAAE;AACnG,UAAM,IAAI,OAAO,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,IAAI,OAAO,KAAKA,OAAM,MAAM;AAC7E,QAAI,EAAG,KAAI,KAAK,CAAC;AAAA,EACnB,CAAC;AACD,SAAO;AACT;","names":["open","s","c","area","order","auto","w","orient","orient","px","EPS","keep","own","stops"]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/stack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as StackInput, F as FitOptions, b as StackFit, e as StackItem } from './model-CMH_27_g.js';
2
- export { C as CrossLimits, D as DEFAULT_MENU, f as DEFAULT_RAIL, G as GroupFormKind, M as MainSize, P as PanelFormKind, g as PlacedStackItem, h as StackAxis, S as StackForm, a as StackFormKind, i as StackMenu, c as StackNote, j as StackNoteCode, k as formSetsCross, w as withItem } from './model-CMH_27_g.js';
1
+ import { d as StackInput, F as FitOptions, c as StackFit, e as StackItem } from './model-irGEua8T.js';
2
+ export { C as CrossLimits, D as DEFAULT_MENU, f as DEFAULT_RAIL, G as GroupFormKind, M as MainSize, P as PanelFormKind, g as PlacedStackItem, h as StackAxis, a as StackForm, S as StackFormKind, i as StackMenu, b as StackNote, j as StackNoteCode, W as WrapSpec, k as formCrossMin, l as formFitsCross, m as formMain, n as formSetsCross, w as withItem, o as wrapCross, p as wrapLines, q as wrapRows } from './model-irGEua8T.js';
3
3
  import { R as Rect, P as Point, S as Size } from './geometry-mL-GTRti.js';
4
4
  import { T as Target } from './target-D3PiLg44.js';
5
5
 
package/dist/stack.js CHANGED
@@ -4,14 +4,20 @@ import {
4
4
  createStack,
5
5
  fitFloat,
6
6
  fitStack,
7
+ formCrossMin,
8
+ formFitsCross,
9
+ formMain,
7
10
  formSetsCross,
8
11
  readFloats,
9
12
  readStack,
10
13
  stackFloatTarget,
11
14
  storeFloats,
12
15
  storeStack,
13
- withItem
14
- } from "./chunk-RYFQKQPQ.js";
16
+ withItem,
17
+ wrapCross,
18
+ wrapLines,
19
+ wrapRows
20
+ } from "./chunk-RUITEOZ7.js";
15
21
  import {
16
22
  rect
17
23
  } from "./chunk-QMTNB2C3.js";
@@ -63,7 +69,7 @@ function fitsBeside(base, fit, dragged, fixed, axis, tooWideBefore) {
63
69
  const q = was.get(p.id);
64
70
  if (!item || !q || p.kind === "menu" || q.kind === "menu") continue;
65
71
  if (p.form !== q.form) return false;
66
- if (main(p.rect) < Math.max(0, item.forms[p.form].main.min) - 1e-6) return false;
72
+ if (main(p.rect) < formMain(item.forms[p.form], "min", fit.cross) - 1e-6) return false;
67
73
  if (across(p.rect) < across(q.rect) - 1e-6) return false;
68
74
  }
69
75
  return true;
@@ -114,6 +120,9 @@ export {
114
120
  createStack,
115
121
  fitFloat,
116
122
  fitStack,
123
+ formCrossMin,
124
+ formFitsCross,
125
+ formMain,
117
126
  formSetsCross,
118
127
  readFloats,
119
128
  readStack,
@@ -121,6 +130,9 @@ export {
121
130
  stackTargets,
122
131
  storeFloats,
123
132
  storeStack,
124
- withItem
133
+ withItem,
134
+ wrapCross,
135
+ wrapLines,
136
+ wrapRows
125
137
  };
126
138
  //# sourceMappingURL=stack.js.map
package/dist/stack.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/stack/targets.ts"],"sourcesContent":["/**\n * The drop targets for dragging an item into a stack, in the shape @n-uf/motion/drag takes. `stackTargets(input,\n * dragged)` gives one target for every gap of the stack without the dragged item (an item of the input with its id\n * is lifted out first, so a reorder within a stack works): before each item and after the last, so an empty stack has\n * one. An item with no forms has no place of its own, but its gaps count.\n *\n * - `id` `gap:<k>`, priority 2, `place` `{ kind: \"gap\", at: k }` (k counts the input's items, the dragged one lifted\n * out, including any with no forms; it is not an index into `fit.items`, which leaves those out: look the dragged\n * item up there by its id, as `slot` already does).\n * - `hit`: the gap's zone along the axis, the stack split at its items' middles, so it covers the gap and the padding\n * between its neighbours; the first and the last reach `options.endReach` px past the stack's ends (an item in the menu has no place of\n * its own: the gaps next to it split the stretch where the stack's drawn items end; with every item in the menu only\n * the last gap, \"at the end\", has any length, and the others are a point at the start). Across, it is the larger of\n * the stack's current size and the size the drop gives it, so the pointer over the preview is over the target.\n * - `fit`: the full `fitStack` of the stack with the dragged item inserted at k, and `input` the stack that was\n * solved. The preview is `slot`, the dragged item's rect in `fit`: exactly the rect it gets after the drop, because\n * the drop is that same solve. `marker` is the line where its leading edge lands: a rect with no thickness across\n * the stack's cross size (the app draws it with one).\n *\n * The dragged item counts as just used: it is newer than every item in the stack, so the others give way before it.\n * A group lands in the form that fits; a panel that would set a wider column makes room by that solve too. A dragged\n * item with no forms has no targets, nor has a `fixed` one (it is never dragged). A fixed item in the stack has no slot\n * inside it: the gaps before and after it stay, but the hit of a gap ends where the fixed item starts and the next one\n * begins where it ends, so no hit overlaps it. Nor has one the stack doesn't accept (`input.accepts`); `options.allows` leaves out\n * single gaps.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport type { Target } from \"../targets/target\";\nimport { fitStack } from \"./layout\";\nimport { withItem, type FitOptions, type PlacedStackItem, type StackFit, type StackInput, type StackItem } from \"./model\";\n\nexport interface StackTargetOptions {\n /**\n * How far the first gap's hit reaches before the stack's start and the last gap's past its end, px (default 0), so a\n * pointer just outside the bar still drops at an end. The marker and the preview don't move.\n */\n readonly endReach?: number;\n /**\n * The stack's fit before the drag, as `fitStack`'s `previous`: the preview of every gap keeps the other items' forms while\n * they still fit, so it is the fit the drop makes when the app solves with the same `previous`.\n */\n readonly previous?: StackFit;\n /**\n * Whether a gap takes the dragged item (default: every gap does). Called with the dragged item and the gap's `at`\n * (`place.at`: the gap before the k-th item of the input with the dragged one lifted out). A gap it refuses has no\n * target; the others keep their ids, places and hits. The stack's own `accepts` is asked first, for the whole stack.\n */\n readonly allows?: (dragged: StackItem, at: number) => boolean;\n /**\n * Offer a gap only where the dragged item fits beside the others (default false: every gap is offered, the dragged item\n * landing in the » menu or the stack overflowing if need be). With it a gap has no target when its fit puts the dragged\n * item into the menu, has an `overflow` note, has a `too-wide` note that the stack without the dragged item didn't have,\n * or squeezes a `fixed` item: it is in another form, shorter along the stack than its form's `main.min`, or narrower\n * across than before the drop. A fixed item may shrink down to its `main.min` to make room, so the room for the others\n * is the length less the fixed items' minimum sizes. The gaps left keep their ids, hits and fits. With no room anywhere\n * the result is `[]`.\n */\n readonly onlyFits?: boolean;\n}\n\nexport type StackPlace = { readonly kind: \"gap\"; readonly at: number };\n\nexport interface StackTarget extends Target {\n readonly priority: 2;\n /** The item dragged. */\n readonly item: string;\n readonly place: StackPlace;\n /** The line where the dragged item's leading edge lands. */\n readonly marker: Rect;\n /** The stack with the dragged item inserted: what a drop here makes. */\n readonly input: StackInput;\n /** Its fit: the preview and the drop are both its rect for the dragged item. */\n readonly fit: StackFit;\n}\n\n/**\n * Where each gap's zone runs along the axis: gap k from `from[k]` to `to[k]`. The stack is split at its items' middles,\n * so gap k reaches from the middle of item k - 1 to the middle of item k; `from[0]` is `reach` before the start, `to[n]`\n * `reach` past the length. A fixed item has no middle to split at: the gap before it ends where it starts and the gap\n * after it begins where it ends, so its own area is in no gap's zone.\n */\nfunction bounds(input: StackInput, fit: StackFit, reach: number): { from: number[]; to: number[] } {\n const column = input.axis === \"column\";\n const start = (r: Rect): number => (column ? r.y : r.x);\n const size = (r: Rect): number => (column ? r.height : r.width);\n const placed = new Map(fit.items.map((p) => [p.id, p]));\n // from[0], to[0], from[1], to[1], …, from[n], to[n], in the order along the stack.\n const c = [0];\n // Where the drawn items have ended so far: an item in the menu (or with no forms) sits there.\n let end = 0;\n let cap = fit.length;\n for (const it of input.items) {\n const p = placed.get(it.id);\n if (!p || p.kind === \"menu\") {\n c.push(end, end);\n continue;\n }\n const s = start(p.rect);\n const mid = s + size(p.rect) / 2;\n c.push(it.fixed ? s : mid, it.fixed ? s + size(p.rect) : mid);\n end = s + size(p.rect);\n // A fixed item that runs past the stack (an overflowing one) keeps its own area out of the zones.\n if (it.fixed) cap = Math.max(cap, end);\n }\n c.push(fit.length);\n // Monotone, whatever the sizes did (a stack that overflows).\n for (let i = 1; i < c.length; i++) c[i] = Math.min(Math.max(c[i]!, c[i - 1]!), cap);\n // The first and last gaps reach past the stack's ends (the last never starts before a fixed item ends).\n c[0] = 0 - reach;\n c[c.length - 1] = Math.max(fit.length + reach, c[c.length - 2]!);\n const from: number[] = [];\n const to: number[] = [];\n for (let k = 0; k <= input.items.length; k++) {\n from.push(c[2 * k]!);\n to.push(c[2 * k + 1]!);\n }\n return { from, to };\n}\n\n/**\n * Whether a drop's fit leaves room for the dragged item: it isn't in the » menu, the stack doesn't `overflow`, no item\n * is `too-wide` that wasn't before (the dragged one, or one the drop made too wide), and no fixed item is squeezed: it\n * keeps its form, is drawn at least as long along the stack as its form's `main.min` and at least as wide across as before\n * the drop. A fixed item may shrink down to its `main.min` to make room (a title that grows gives back what it took).\n */\nfunction fitsBeside(\n base: StackFit,\n fit: StackFit,\n dragged: PlacedStackItem,\n fixed: ReadonlyMap<string, StackItem>,\n axis: StackInput[\"axis\"],\n tooWideBefore: ReadonlySet<string>,\n): boolean {\n if (dragged.kind === \"menu\") return false;\n for (const n of fit.notes) {\n if (n.code === \"overflow\") return false;\n if (n.code === \"too-wide\" && !tooWideBefore.has(n.id)) return false;\n }\n const main = (r: Rect): number => (axis === \"column\" ? r.height : r.width);\n const across = (r: Rect): number => (axis === \"column\" ? r.width : r.height);\n const was = new Map(base.items.map((p) => [p.id, p]));\n for (const p of fit.items) {\n const item = fixed.get(p.id);\n const q = was.get(p.id);\n if (!item || !q || p.kind === \"menu\" || q.kind === \"menu\") continue;\n if (p.form !== q.form) return false;\n if (main(p.rect) < Math.max(0, item.forms[p.form]!.main.min) - 1e-6) return false;\n if (across(p.rect) < across(q.rect) - 1e-6) return false;\n }\n return true;\n}\n\nexport function stackTargets(input: StackInput, dragged: StackItem, options: StackTargetOptions = {}): StackTarget[] {\n if (dragged.forms.length === 0) return [];\n if (dragged.fixed) return [];\n if (input.accepts && !input.accepts(dragged)) return [];\n const rest: StackInput = { ...input, items: input.items.filter((it) => it.id !== dragged.id) };\n const fitOptions: FitOptions = options.previous ? { previous: options.previous } : {};\n const base = fitStack(rest, fitOptions);\n const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach! : 0);\n const b = bounds(rest, base, reach);\n const column = rest.axis === \"column\";\n const fixedItems = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));\n const tooWideBefore = new Set(base.notes.flatMap((n) => (n.code === \"too-wide\" ? [n.id] : [])));\n const newest = rest.items.reduce((m, it) => Math.max(m, it.used), dragged.used) + 1;\n const item: StackItem = { ...dragged, used: newest };\n const out: StackTarget[] = [];\n for (let k = 0; k <= rest.items.length; k++) {\n if (options.allows && !options.allows(dragged, k)) continue;\n const solved = withItem(rest, item, k);\n const fit = fitStack(solved, fitOptions);\n const placed = fit.items.find((p) => p.id === dragged.id)!;\n const slot = placed.rect;\n if (options.onlyFits && !fitsBeside(base, fit, placed, fixedItems, rest.axis, tooWideBefore)) continue;\n const from = b.from[k]!;\n const to = b.to[k]!;\n const across = Math.max(base.cross, fit.cross);\n out.push({\n id: `gap:${k}`,\n priority: 2,\n item: dragged.id,\n place: { kind: \"gap\", at: k },\n hit: column ? rect(0, from, across, to - from) : rect(from, 0, to - from, across),\n slot,\n // The line spans the stack's cross size (the drop's fit: the bar's height, the column's width).\n marker: column ? rect(0, slot.y, fit.cross, 0) : rect(slot.x, 0, 0, fit.cross),\n input: solved,\n fit,\n });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiFA,SAAS,OAAO,OAAmB,KAAe,OAAiD;AACjG,QAAM,SAAS,MAAM,SAAS;AAC9B,QAAM,QAAQ,CAAC,MAAqB,SAAS,EAAE,IAAI,EAAE;AACrD,QAAM,OAAO,CAAC,MAAqB,SAAS,EAAE,SAAS,EAAE;AACzD,QAAM,SAAS,IAAI,IAAI,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAEtD,QAAM,IAAI,CAAC,CAAC;AAEZ,MAAI,MAAM;AACV,MAAI,MAAM,IAAI;AACd,aAAW,MAAM,MAAM,OAAO;AAC5B,UAAM,IAAI,OAAO,IAAI,GAAG,EAAE;AAC1B,QAAI,CAAC,KAAK,EAAE,SAAS,QAAQ;AAC3B,QAAE,KAAK,KAAK,GAAG;AACf;AAAA,IACF;AACA,UAAM,IAAI,MAAM,EAAE,IAAI;AACtB,UAAM,MAAM,IAAI,KAAK,EAAE,IAAI,IAAI;AAC/B,MAAE,KAAK,GAAG,QAAQ,IAAI,KAAK,GAAG,QAAQ,IAAI,KAAK,EAAE,IAAI,IAAI,GAAG;AAC5D,UAAM,IAAI,KAAK,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AAI,IAAI;AAClF,QAAM,OAAkB,EAAE,GAAG,SAAS,MAAM,OAAO;AACnD,QAAM,MAAqB,CAAC;AAC5B,WAAS,IAAI,GAAG,KAAK,KAAK,MAAM,QAAQ,KAAK;AAC3C,QAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO,SAAS,CAAC,EAAG;AACnD,UAAM,SAAS,SAAS,MAAM,MAAM,CAAC;AACrC,UAAM,MAAM,SAAS,QAAQ,UAAU;AACvC,UAAM,SAAS,IAAI,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,QAAQ,EAAE;AACxD,UAAM,OAAO,OAAO;AACpB,QAAI,QAAQ,YAAY,CAAC,WAAW,MAAM,KAAK,QAAQ,YAAY,KAAK,MAAM,aAAa,EAAG;AAC9F,UAAM,OAAO,EAAE,KAAK,CAAC;AACrB,UAAM,KAAK,EAAE,GAAG,CAAC;AACjB,UAAM,SAAS,KAAK,IAAI,KAAK,OAAO,IAAI,KAAK;AAC7C,QAAI,KAAK;AAAA,MACP,IAAI,OAAO,CAAC;AAAA,MACZ,UAAU;AAAA,MACV,MAAM,QAAQ;AAAA,MACd,OAAO,EAAE,MAAM,OAAO,IAAI,EAAE;AAAA,MAC5B,KAAK,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,IAAI,IAAI,KAAK,MAAM,GAAG,KAAK,MAAM,MAAM;AAAA,MAChF;AAAA;AAAA,MAEA,QAAQ,SAAS,KAAK,GAAG,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,GAAG,GAAG,GAAG,IAAI,KAAK;AAAA,MAC7E,OAAO;AAAA,MACP;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/stack/targets.ts"],"sourcesContent":["/**\n * The drop targets for dragging an item into a stack, in the shape @n-uf/motion/drag takes. `stackTargets(input,\n * dragged)` gives one target for every gap of the stack without the dragged item (an item of the input with its id\n * is lifted out first, so a reorder within a stack works): before each item and after the last, so an empty stack has\n * one. An item with no forms has no place of its own, but its gaps count.\n *\n * - `id` `gap:<k>`, priority 2, `place` `{ kind: \"gap\", at: k }` (k counts the input's items, the dragged one lifted\n * out, including any with no forms; it is not an index into `fit.items`, which leaves those out: look the dragged\n * item up there by its id, as `slot` already does).\n * - `hit`: the gap's zone along the axis, the stack split at its items' middles, so it covers the gap and the padding\n * between its neighbours; the first and the last reach `options.endReach` px past the stack's ends (an item in the menu has no place of\n * its own: the gaps next to it split the stretch where the stack's drawn items end; with every item in the menu only\n * the last gap, \"at the end\", has any length, and the others are a point at the start). Across, it is the larger of\n * the stack's current size and the size the drop gives it, so the pointer over the preview is over the target.\n * - `fit`: the full `fitStack` of the stack with the dragged item inserted at k, and `input` the stack that was\n * solved. The preview is `slot`, the dragged item's rect in `fit`: exactly the rect it gets after the drop, because\n * the drop is that same solve. `marker` is the line where its leading edge lands: a rect with no thickness across\n * the stack's cross size (the app draws it with one).\n *\n * The dragged item counts as just used: it is newer than every item in the stack, so the others give way before it.\n * A group lands in the form that fits; a panel that would set a wider column makes room by that solve too. A dragged\n * item with no forms has no targets, nor has a `fixed` one (it is never dragged). A fixed item in the stack has no slot\n * inside it: the gaps before and after it stay, but the hit of a gap ends where the fixed item starts and the next one\n * begins where it ends, so no hit overlaps it. Nor has one the stack doesn't accept (`input.accepts`); `options.allows` leaves out\n * single gaps.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport type { Target } from \"../targets/target\";\nimport { fitStack } from \"./layout\";\nimport { formMain, withItem, type FitOptions, type PlacedStackItem, type StackFit, type StackInput, type StackItem } from \"./model\";\n\nexport interface StackTargetOptions {\n /**\n * How far the first gap's hit reaches before the stack's start and the last gap's past its end, px (default 0), so a\n * pointer just outside the bar still drops at an end. The marker and the preview don't move.\n */\n readonly endReach?: number;\n /**\n * The stack's fit before the drag, as `fitStack`'s `previous`: the preview of every gap keeps the other items' forms while\n * they still fit, so it is the fit the drop makes when the app solves with the same `previous`.\n */\n readonly previous?: StackFit;\n /**\n * Whether a gap takes the dragged item (default: every gap does). Called with the dragged item and the gap's `at`\n * (`place.at`: the gap before the k-th item of the input with the dragged one lifted out). A gap it refuses has no\n * target; the others keep their ids, places and hits. The stack's own `accepts` is asked first, for the whole stack.\n */\n readonly allows?: (dragged: StackItem, at: number) => boolean;\n /**\n * Offer a gap only where the dragged item fits beside the others (default false: every gap is offered, the dragged item\n * landing in the » menu or the stack overflowing if need be). With it a gap has no target when its fit puts the dragged\n * item into the menu, has an `overflow` note, has a `too-wide` note that the stack without the dragged item didn't have,\n * or squeezes a `fixed` item: it is in another form, shorter along the stack than its form's `main.min`, or narrower\n * across than before the drop. A fixed item may shrink down to its `main.min` to make room, so the room for the others\n * is the length less the fixed items' minimum sizes. The gaps left keep their ids, hits and fits. With no room anywhere\n * the result is `[]`.\n */\n readonly onlyFits?: boolean;\n}\n\nexport type StackPlace = { readonly kind: \"gap\"; readonly at: number };\n\nexport interface StackTarget extends Target {\n readonly priority: 2;\n /** The item dragged. */\n readonly item: string;\n readonly place: StackPlace;\n /** The line where the dragged item's leading edge lands. */\n readonly marker: Rect;\n /** The stack with the dragged item inserted: what a drop here makes. */\n readonly input: StackInput;\n /** Its fit: the preview and the drop are both its rect for the dragged item. */\n readonly fit: StackFit;\n}\n\n/**\n * Where each gap's zone runs along the axis: gap k from `from[k]` to `to[k]`. The stack is split at its items' middles,\n * so gap k reaches from the middle of item k - 1 to the middle of item k; `from[0]` is `reach` before the start, `to[n]`\n * `reach` past the length. A fixed item has no middle to split at: the gap before it ends where it starts and the gap\n * after it begins where it ends, so its own area is in no gap's zone.\n */\nfunction bounds(input: StackInput, fit: StackFit, reach: number): { from: number[]; to: number[] } {\n const column = input.axis === \"column\";\n const start = (r: Rect): number => (column ? r.y : r.x);\n const size = (r: Rect): number => (column ? r.height : r.width);\n const placed = new Map(fit.items.map((p) => [p.id, p]));\n // from[0], to[0], from[1], to[1], …, from[n], to[n], in the order along the stack.\n const c = [0];\n // Where the drawn items have ended so far: an item in the menu (or with no forms) sits there.\n let end = 0;\n let cap = fit.length;\n for (const it of input.items) {\n const p = placed.get(it.id);\n if (!p || p.kind === \"menu\") {\n c.push(end, end);\n continue;\n }\n const s = start(p.rect);\n const mid = s + size(p.rect) / 2;\n c.push(it.fixed ? s : mid, it.fixed ? s + size(p.rect) : mid);\n end = s + size(p.rect);\n // A fixed item that runs past the stack (an overflowing one) keeps its own area out of the zones.\n if (it.fixed) cap = Math.max(cap, end);\n }\n c.push(fit.length);\n // Monotone, whatever the sizes did (a stack that overflows).\n for (let i = 1; i < c.length; i++) c[i] = Math.min(Math.max(c[i]!, c[i - 1]!), cap);\n // The first and last gaps reach past the stack's ends (the last never starts before a fixed item ends).\n c[0] = 0 - reach;\n c[c.length - 1] = Math.max(fit.length + reach, c[c.length - 2]!);\n const from: number[] = [];\n const to: number[] = [];\n for (let k = 0; k <= input.items.length; k++) {\n from.push(c[2 * k]!);\n to.push(c[2 * k + 1]!);\n }\n return { from, to };\n}\n\n/**\n * Whether a drop's fit leaves room for the dragged item: it isn't in the » menu, the stack doesn't `overflow`, no item\n * is `too-wide` that wasn't before (the dragged one, or one the drop made too wide), and no fixed item is squeezed: it\n * keeps its form, is drawn at least as long along the stack as its form's `main.min` and at least as wide across as before\n * the drop. A fixed item may shrink down to its `main.min` to make room (a title that grows gives back what it took).\n */\nfunction fitsBeside(\n base: StackFit,\n fit: StackFit,\n dragged: PlacedStackItem,\n fixed: ReadonlyMap<string, StackItem>,\n axis: StackInput[\"axis\"],\n tooWideBefore: ReadonlySet<string>,\n): boolean {\n if (dragged.kind === \"menu\") return false;\n for (const n of fit.notes) {\n if (n.code === \"overflow\") return false;\n if (n.code === \"too-wide\" && !tooWideBefore.has(n.id)) return false;\n }\n const main = (r: Rect): number => (axis === \"column\" ? r.height : r.width);\n const across = (r: Rect): number => (axis === \"column\" ? r.width : r.height);\n const was = new Map(base.items.map((p) => [p.id, p]));\n for (const p of fit.items) {\n const item = fixed.get(p.id);\n const q = was.get(p.id);\n if (!item || !q || p.kind === \"menu\" || q.kind === \"menu\") continue;\n if (p.form !== q.form) return false;\n // Its least length: `main.min`, or a wrap form's rows at the stack's cross size.\n if (main(p.rect) < formMain(item.forms[p.form]!, \"min\", fit.cross) - 1e-6) return false;\n if (across(p.rect) < across(q.rect) - 1e-6) return false;\n }\n return true;\n}\n\nexport function stackTargets(input: StackInput, dragged: StackItem, options: StackTargetOptions = {}): StackTarget[] {\n if (dragged.forms.length === 0) return [];\n if (dragged.fixed) return [];\n if (input.accepts && !input.accepts(dragged)) return [];\n const rest: StackInput = { ...input, items: input.items.filter((it) => it.id !== dragged.id) };\n const fitOptions: FitOptions = options.previous ? { previous: options.previous } : {};\n const base = fitStack(rest, fitOptions);\n const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach! : 0);\n const b = bounds(rest, base, reach);\n const column = rest.axis === \"column\";\n const fixedItems = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));\n const tooWideBefore = new Set(base.notes.flatMap((n) => (n.code === \"too-wide\" ? [n.id] : [])));\n const newest = rest.items.reduce((m, it) => Math.max(m, it.used), dragged.used) + 1;\n const item: StackItem = { ...dragged, used: newest };\n const out: StackTarget[] = [];\n for (let k = 0; k <= rest.items.length; k++) {\n if (options.allows && !options.allows(dragged, k)) continue;\n const solved = withItem(rest, item, k);\n const fit = fitStack(solved, fitOptions);\n const placed = fit.items.find((p) => p.id === dragged.id)!;\n const slot = placed.rect;\n if (options.onlyFits && !fitsBeside(base, fit, placed, fixedItems, rest.axis, tooWideBefore)) continue;\n const from = b.from[k]!;\n const to = b.to[k]!;\n const across = Math.max(base.cross, fit.cross);\n out.push({\n id: `gap:${k}`,\n priority: 2,\n item: dragged.id,\n place: { kind: \"gap\", at: k },\n hit: column ? rect(0, from, across, to - from) : rect(from, 0, to - from, across),\n slot,\n // The line spans the stack's cross size (the drop's fit: the bar's height, the column's width).\n marker: column ? rect(0, slot.y, fit.cross, 0) : rect(slot.x, 0, 0, fit.cross),\n input: solved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