@n-uf/placement 26.11.38 → 26.11.40
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/CHANGELOG.md +33 -0
- package/README.md +15 -3
- package/dist/{chunk-GWZ5BPIN.js → chunk-PADZWK3H.js} +81 -54
- package/dist/chunk-PADZWK3H.js.map +1 -0
- package/dist/{model-bUSbHw8v.d.ts → model-YDXCs2N_.d.ts} +9 -2
- package/dist/scene-cases.d.ts +1 -1
- package/dist/scene-cases.js +2 -1
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +19 -3
- package/dist/scene.js +5 -1
- package/package.json +2 -2
- package/dist/chunk-GWZ5BPIN.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/scene/model.ts","../src/scene/helpers.ts","../src/scene/targets/ids.ts","../src/scene/solve/order.ts","../src/scene/solve/bar-giveway.ts","../src/scene/solve/draft.ts","../src/scene/solve/edge.ts","../src/scene/solve/bars.ts","../src/scene/solve/floats.ts","../src/scene/solve/insets.ts","../src/scene/solve/notes.ts","../src/scene/solve/columns.ts","../src/scene/solve/rails.ts","../src/scene/solve/sides.ts","../src/scene/solve.ts","../src/scene/float-resize.ts","../src/scene/changes.ts","../src/scene/store.ts","../src/scene/targets/anchor.ts","../src/scene/targets/kinds.ts","../src/scene/targets/edges.ts","../src/scene/targets/filter.ts","../src/scene/targets/model.ts","../src/scene/targets/ownership.ts","../src/scene/targets/tiles.ts","../src/scene/targets/virtual.ts","../src/scene/targets/rail-strip.ts","../src/scene/targets/min-hit.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 * What the shapes tell on their own (an edge's axis, an item's zone and forms, how it floats) is in `./helpers`.\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, centered 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\";\nexport const FLOAT_ANCHORS: readonly FloatAnchor[] = [\"content-top-left\", \"content-top\", \"content-top-right\", \"content-right\", \"content-bottom-right\", \"content-bottom\", \"content-bottom-left\", \"content-left\"];\n\n/**\n * An anchor with an offset: flush with `at`'s side or corner of the content, then `dx` px to the right and `dy` px down\n * (negative: left, up; default 0). It still follows the content, so a host stores \"the top-right corner, 12 px down\"\n * rather than a pixel position.\n */\nexport interface FloatAnchorOffset {\n readonly at: FloatAnchor;\n readonly dx?: number;\n readonly dy?: number;\n}\n\n/** Where an anchored float sits: an anchor's name, or one with an offset. */\nexport type FloatAnchorAt = FloatAnchor | FloatAnchorOffset;\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 * Folded by hand when 1 or more (`fold` sets it to 1; default unset): it starts at its first folded form (a panel's\n * `header`, a group's `fold`) among the forms of the axis it lies along, never one step down the ladder, and give-way\n * steps down from there. A stored value past that form keeps its place (a scene stored with a later form). With no\n * folded form on that axis it draws unfolded (`canFold`). A float folded by hand is drawn as its bar: that form's\n * 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 /**\n * Its zone (default start): the item's own, not its edge's. It lies there where its edge takes its kind there, else in\n * the first zone that does (`zoneIn`). Only a drop that names a zone (a gap in a zone, `moveTo` with `zone`) on an edge\n * offering a choice (`namesZone`: more than one of its zones takes the kind) sets it.\n */\n readonly align?: Zone;\n /**\n * Its give-way priority in its edge (default: the edge's `priority`, else 0). When an edge runs short, items step down\n * their forms (row, wrap in a column, icons, then the edge's » menu) lowest priority first, ties to the one used longest\n * ago; room coming back brings them up in the exact reverse order, each to its remembered form. It adds to every one\n * of its forms' `rank` (`./stack`), so a host may still rank single forms. Give the controls that must stay out of the\n * menu the highest priority.\n */\n readonly priority?: number;\n /**\n * Its size as a float: `floatAt` with no rect uses it, and a float drop sets it. Without it, a float takes its first\n * form's natural size along its orient (`floatSizeOf`), or `DEFAULT_FLOAT_SIZE` when that form grows (a panel's card).\n */\n readonly floatSize?: Size;\n /**\n * Which of its forms it uses as a float when the float names no `orient` (`floatOrientOf`). Default: the axis of its\n * first form, the first of `forms.row` / `forms.column` it declares (a group declared row first floats as a row).\n */\n readonly floatOrient?: Orient;\n /**\n * The least a float of it is shrunk to: a float larger than the region floats lie in is laid out at\n * `max(floatMin, min(its size, the region))` each way. A floor wider than the region keeps it at the region's left\n * edge; one taller than the stage keeps it at the stage's top and runs past its bottom. A folded float (its header\n * form) keeps its height. Without it, a shrink stops at the form's own minimums.\n */\n readonly floatMin?: Size;\n /**\n * The most a float of it is laid out at, each way (optional, the same shape as `floatMin`, never under it): a larger\n * float rect is drawn at this size, its top-left corner kept (a folded float keeps its bar's height), and `fitResize`\n * stops a resize here (`\"max\"`).\n */\n readonly floatMax?: 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. An overlay bar (`mode: \"overlay\"`) lies over the content, between\n * the columns, unless it sets `span: \"full\"` by name: then it runs across the full bars' width, over the side columns\n * too. Left out on an overlay bar, it means the content's width, as it always has.\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 /**\n * An icons-only edge (a thin rail of vertical toolbars along a window side): its items take only their `icons` form\n * (and the » menu after it), stacked, each grip the divider. An item with no `icons` form is left out\n * (`no-icons-form`).\n */\n readonly compact?: boolean;\n /**\n * The kinds each zone takes, narrowing `accepts`: with it, a zone not listed takes nothing. A panel column with\n * `{ start: [\"panel\"], end: [\"group\"] }` has its panels at the top and a tray of toolbars at its foot (the end zone, one\n * toolbar per row): a toolbar in the tray takes only its `wrap` or `icons` form (never the menu), and the panels give\n * way first. An empty edge offers each third of its strip only to the kinds that third's zone takes (the others are\n * refusals). A group never opens such a column on its own: an empty side column offers its strip only to the kinds\n * its start zone takes (a panel gets its top third; a group none, the rail's instead).\n */\n readonly zoneAccepts?: ZoneAccepts;\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. The gaps always split the edge halfway between neighboring insertion lines, so\n * free space and short items (a toolbar, a closed or folded panel) are covered end to end. A number: over an open\n * item's body only (a panel), the hit narrows to a band that many px around the line, so the middle of a panel is no\n * gap and the pointer falls through to the float target, or to none. `\"middle\"`: no band, so panels are split too.\n * Default {@link DEFAULT_HIT_BAND}.\n */\n readonly hitBand?: number | \"middle\";\n /**\n * `\"side\"`: a static edge whose fixed item (an anchor: page thumbnails) the user may drag to the other side of the\n * edge's axis. `targets` then offers that item one target, `side:<other side>`, over the place the edge takes there\n * (`setSide`); its own place is home. Left out, a fixed item has no targets.\n */\n readonly moves?: \"side\";\n /**\n * `true`: the user may fold this edge's fixed items (an anchor) by hand, like a panel: `fold(scene, id, true)` shows\n * it in its rail form, `fold(scene, id, false)` reopens it, and `storeScene` / `readScene` keep it folded. Left out,\n * `fold` leaves a fixed item as it is.\n */\n readonly foldable?: boolean;\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`, `menu`, `zoneAccepts` and `hitBand` come from `Scene.columns[side]` when the changes make it;\n * with no `hitBand` of its own it reads the template's.\n */\n readonly column?: boolean;\n /**\n * An anchor edge (a left or right edge that takes nothing, holding a fixed item such as a thumbnail strip) lies outside\n * `Scene.inset` and the gutter: at the window's side, the inset after it, toward the content. A full top or bottom bar\n * with it lies at the window's edge, full width, the inset after it; the side edges then run between such bars (an\n * anchor through the inset beside them). On a left or right side, from the window's side inward: its toolbar bars\n * with it (`isOutsideSideBar`), the side's rail, its anchors, the inset, the columns.\n */\n readonly outsideInset?: boolean;\n /**\n * A static left or right edge that gives way like a dynamic column: it shrinks toward its minimum, then folds whole\n * into its side's rail, in give-way order with the columns (its items' ages). It is never deleted.\n *\n * On a top or bottom bar (reserved or overlay), it gives way by height: while the content is shorter than\n * `contentMin.height` (overlay bars counted), such bars shrink across toward their minimum (`cross.min`, and each\n * open item's form's `cross.min`), then fold, their items stepping to the next form that fits across (a panel's\n * title bar), unkept before kept, the oldest newest use first, the outer first (`bar-shrunk`, `bar-folded`). Room\n * coming back undoes it in reverse. A bar never draws an item thinner across than its form's `cross.min`.\n */\n readonly giveWay?: boolean;\n /**\n * The default give-way priority of its items (`SceneItem.priority` wins; default 0): a title bar given a lower one has\n * its toolbars step down before an item moved in from another bar would.\n */\n readonly priority?: number;\n /**\n * Hidden: kept in the scene with its items, but not in the window (a bar a host doesn't draw, a rail it has turned\n * off). View state: the host decides it each time it builds the scene, and the store never writes it. A hidden edge\n * takes no room, and everything else lays out exactly as if it weren't in the scene; `solve` leaves it and its items\n * out of the layout (no `edges[id]`, no `items[id]`, as for an item placed nowhere), so nothing reads a rect of it.\n * Its items take no part in give-way or folds. It has no targets and no refusals for any kind, no keyboard stops, and\n * its items have none either (dragging one gives nothing); `moveTo` into it is refused as into an edge that doesn't\n * take the kind. Its items stay in it, and `storeScene` / `readScene` keep them. A column a drop makes never takes a\n * hidden edge's id; where a drop makes or removes a column on its side, the side is numbered again with the hidden\n * edge back at its own place. Side columns, rails and bars alike. With `showIn`, its items show elsewhere instead.\n */\n readonly hidden?: boolean;\n /**\n * Where a hidden edge's items show while it is hidden: the id of another static edge, shown. Its items are laid out, targeted\n * and stopped as if they sat in that edge after its own items (`solve` reports them there), each that edge takes the\n * kind of, in its own zone where that edge takes it there, else in the first that does; a fixed item, or one whose\n * kind that edge takes nowhere, is left out as without `showIn`. They stay in the hidden edge in the scene: a drop that\n * commits a move of one takes it out, to the drop's place; its home, and any drop of another item, leaves them where\n * they are. A moved item keeps its stored zone, unless the drop names one (a gap). `canFold`, `fold` and the hand\n * fold read a lent item along the edge it is drawn in. View state like `hidden`: the store never writes it. Naming the\n * edge itself, no edge, another hidden edge or a dynamic column (`column: true`: drops make and delete those) is\n * ignored (`show-in-ignored`). No effect on an edge that isn't hidden.\n */\n readonly showIn?: string;\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 /** The kinds each zone takes in the columns made from it (`Edge.zoneAccepts`). */\n readonly zoneAccepts?: ZoneAccepts;\n /**\n * How a gap's hit runs over the open panels of the columns made from it (`Edge.hitBand`): a band that many px about\n * each line, or `\"middle\"` (a drop on a panel's upper or lower half means the gap before or after it). Default\n * {@link DEFAULT_HIT_BAND}.\n */\n readonly hitBand?: number | \"middle\";\n}\n\n/** Per zone, the kinds it takes. */\nexport type ZoneAccepts = Readonly<Partial<Record<Zone, readonly Kind[]>>>;\n\n/** How a side's rails show their items: their titles while they fit (the default), or their tiles only. */\nexport type RailMode = \"titles\" | \"icons\";\nexport const RAIL_MODES: readonly RailMode[] = [\"titles\", \"icons\"];\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\n/** When a host draws a side's rail drop strip: while an item of the kind is held (the default), always, or never. */\nexport type RailVisibility = \"whileDragging\" | \"always\" | \"never\";\nexport const RAIL_VISIBILITIES: readonly RailVisibility[] = [\"whileDragging\", \"always\", \"never\"];\n\n/** The least width of a rail drop strip, px: a target at the window's edge stays easy to hit (Fitts's law). */\nexport const RAIL_STRIP_MIN = 24;\n/** How far an armed rail drop strip grows inward by default, px, so a hand that wobbles once armed keeps it. */\nexport const DEFAULT_RAIL_MAGNET = 6;\n\n/**\n * How an item of one kind drops into a side's rail (`Scene.railDrop[kind]`): the geometry of its drop strip. Each kind\n * has its own; a kind with none keeps the rail targets as they were (immediate, no strip).\n *\n * With a policy, each side whose rail can take the kind shows one drop strip at the window's side, at the rail's real\n * width, even while the rail is empty: its targets are `rail:<side>:<ring>` with `arm: \"dwell\"` (spring-loading: the\n * drag intent arms them on a dwell), `armedHit` (the strip grown by `magnet`) and `strip` (the rect to draw). The strip\n * owns its rect: a drop there is the rail's once armed, the float's before. The side's rail is `Scene.rails[side]`\n * where the scene declares one, else the side's outermost column that takes the kind in its start zone (\"the column\n * drawn as a rail\"): a drop there docks the item in it as a collapsed header, a rail tile once nothing in it sets its\n * width. The strip means \"collapse it at this side\": the drop is `moveTo` that side's rail, and lands wherever the\n * scene shows a collapsed panel there (a rail tile, a rider bar under `handFold: \"ride\"`, a header); the slot is that.\n */\nexport interface RailDropPolicy {\n /**\n * The strip's width, px, from the window's side inward (default: the rail's drawn width). At least\n * {@link RAIL_STRIP_MIN}; 0 turns the kind's rail docking off.\n */\n readonly railStripWidth?: number;\n /** When the host draws the strip (default `\"whileDragging\"`); `\"never\"` turns the kind's rail docking off. */\n readonly railVisibility?: RailVisibility;\n /**\n * How far the strip grows inward once armed, px (default {@link DEFAULT_RAIL_MAGNET}): the armed target's band\n * (`armedHit`). Moving out past its outer edge disarms it, and re-entering the strip needs a new full dwell.\n */\n readonly magnet?: number;\n /** Whether a float may sit inside the strip's area (default true); false keeps a float's rect clear of every strip. */\n readonly floatNearEdge?: boolean;\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 (with an offset, `{ at, dx?, dy? }`) until a drop gives it a real rect. */\n readonly anchor?: FloatAnchorAt;\n /** Which of the item's forms it uses (default: the item's `floatOrientOf`). */\n readonly orient?: Orient;\n /**\n * When it was floated, as a sequence: `floatAt` and `moveTo(…, { kind: \"float\" })` give a newly floated item one more\n * than the largest `since` among the scene's floats (1 when there are none); moving a float that already floats,\n * `raise`, `use` and `resize` keep it. Among anchored floats the earlier (smaller `since`, missing counting as 0, then\n * the smaller id) wins the place both want.\n */\n readonly since?: number;\n}\n\n/**\n * A rect the scene keeps clear of, and who keeps clear: `\"all\"` (the default) for floats and drop targets alike (a\n * slot or a target's landing never lies on it), `\"floats\"` for floats alone: their placement, drops, opening, a\n * window resize and a resize by hand keep clear of it, while the edges, give-way and every docked target ignore it (a\n * spine the host draws over a column).\n */\nexport type SceneChrome = Rect & { readonly for?: \"all\" | \"floats\" };\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 /**\n * Rects the scene keeps clear of (a title the host draws itself, a status line): by default floats and drop targets\n * both; an entry with `for: \"floats\"` (a spine drawn over a column) only floats. See {@link SceneChrome}.\n */\n readonly chrome?: readonly SceneChrome[];\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 * Per side (left, right): how its rails show their items (default `\"titles\"`). It covers every rail on the side: a\n * column drawn as a rail (nothing in it sets its width) and the side's rail strip (`rails`). `\"titles\"` offers the\n * items' title rail forms (`StackForm.title`), each stepping down to its tile by the ladder when the rail runs short;\n * `\"icons\"` passes them over, so every item shows its tile. An item with no title form shows its tile either way. A\n * side needs no `rails` entry to have a mode: a column drawn as a rail reads it too. `storeScene` keeps it.\n */\n readonly railModes?: Partial<Record<\"left\" | \"right\", RailMode>>;\n /**\n * Per item kind: how it drops into a side's rail ({@link RailDropPolicy}), keyed by the scene's own kind strings.\n * Tuning one kind never changes another; a kind left out keeps the rail targets it had.\n */\n readonly railDrop?: Readonly<Partial<Record<Kind, RailDropPolicy>>>;\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 column folded by hand shows (default `\"bar\"`): `\"bar\"` sends it to its side's rail; `\"ride\"` draws each of its\n * members as a title bar over the first open column of its side (stacked, in zone order), at that column's width,\n * taking no width of their own.\n */\n readonly handFold?: \"bar\" | \"ride\";\n /**\n * Space kept clear inside the stage's edges, px (default 0 each). Floats are clamped into the stage less its left and\n * right (the stage's full height), and shrunk to fit that region when larger.\n */\n readonly inset?: { readonly top?: number; readonly right?: number; readonly bottom?: number; readonly left?: number };\n /**\n * When `inset` applies (default `\"always\"`): `\"docked\"` keeps it only while a panel is docked beside the content (an\n * open panel column or a rail showing panels: a left or right edge that takes something, with an item that isn't\n * closed or fixed and whose first column form is `open`, `header` or `rail`). Bars, toolbar groups and an anchor\n * never count, wherever they sit; with no panel there, the content is the whole stage.\n */\n readonly insetWhen?: \"always\" | \"docked\";\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 /**\n * Drawn in its title rail form (`StackForm.title`) on a rail of this side: a column drawn as a rail or the side's rail\n * strip. The host turns the title to run along the rail and reads it toward the content: on the left from bottom to\n * top (turned −90°), on the right from top to bottom (+90°), the count at the title's end.\n */\n readonly railTitle?: \"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 * Why this item is drawn smaller than its first form, read from the scene's own state, never inferred from the rects:\n * `\"hand\"` when it is folded by hand (`SceneItem.from` over 0, which `fold` sets), `\"auto\"` when it gave way (a form\n * below the one it started in, by length or width, a » menu entry included: the same word `folded` uses for a column\n * folded by give-way). Absent when the item shows its first form, is closed, or lies in an icons-only edge in the form\n * that edge gives it. By hand wins: a hand-folded item that gave way further is `\"hand\"`, since expanding it\n * (`fold(scene, id, false)`) is the user's to do, so a host shows \"Expand\" for `\"hand\"` only. A float is only ever\n * folded by hand. `folded` is about the item's column; this one is about the item.\n */\n readonly foldedBy?: \"hand\" | \"auto\";\n /** A `wrap` form: the word indexes per row (the words wrap beside the grip, a hanging indent). */\n readonly rows?: readonly (readonly number[])[];\n /** Its grip: a `wrap` form's lead cell at the start of row one, or a form's `grip` strip (an icons strip's, on top). */\n readonly grip?: Rect;\n /**\n * The control ids the form it took leaves out (`StackForm.hides`), empty when it hides none or sits in a » menu: a host\n * draws a \"+N\" control with them. `form` already names the variant.\n */\n readonly hidden: readonly string[];\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 /**\n * Its items in the edge's order: the zones in order (start, center, end), then the order within each zone, the order\n * `solve` lays them in. Exactly the ids `SceneLayout.items` draws for this edge (`SceneItemLayout.edge`): an item in the\n * » menu keeps its place (`menu.items` names those, so a host wanting the docked ones filters them out), a rail tab is\n * listed, and a closed item is left out (unless it shows as a rail tab). A column folded into its rail or riding lists\n * its members in zone order. Never sort rects to learn it.\n */\n readonly items: readonly string[];\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 size across it asks for: a column's width, a bar's height (`Edge.giveWay`). */\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 * The segments' fit along the rail, in rail-local px, while any of them offers a title form (titles step down to\n * tiles by the ladder and come back in exact reverse): `solve`'s `previous` reads it; a host needs it not.\n */\n readonly stack?: StackFit;\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 * - `bar-shrunk`, `bar-folded`: give-way by `contentMin.height`, in give-way order: a top or bottom bar with `giveWay`\n * shrank across (`from`, `to`), or its items stepped to the next form that fits (a panel's title bar);\n * - `content-narrow`, `content-short`: the content is still under `contentMin` (overlay bars count against the height).\n * - `no-column-room`: not even one column at its minimum fits beside `contentMin.width` (`layout.columnRoom` false):\n * `width` is the room the stage leaves, `need` the content's minimum plus that column and its gutter.\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 * - `no-vertical-form`: an item left out of a vertical place (a rail, a vertical float) because only `wrap` forms are\n * left to it (vertical means icons: give a word group an `icons` form).\n * - `show-in-ignored`: a hidden edge's `showIn` names the edge itself, no edge, another hidden edge or a dynamic\n * column; its items are left out as if it named none.\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: \"bar-shrunk\"; readonly edge: string; readonly from: number; readonly to: number }\n | { readonly code: \"bar-folded\"; readonly edge: string }\n | { readonly code: \"no-column-room\"; readonly width: number; readonly need: number }\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 }\n | { readonly code: \"no-vertical-form\"; readonly id: string; readonly edge?: string }\n | { readonly code: \"no-icons-form\"; readonly id: string; readonly edge: string }\n | { readonly code: \"show-in-ignored\"; readonly edge: string };\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). Hosts draw these. */\n readonly rails: Readonly<Partial<Record<\"left\" | \"right\", SceneRailLayout>>>;\n /**\n * Where each side's rail lies, or would lie were one shown, for every side that has a rail (`Scene.rails`), drawn or\n * not: the place a drop into the rail lands (`targets` reads it). Hosts draw `rails`, never `railPlaces`.\n */\n readonly railPlaces: Readonly<Partial<Record<\"left\" | \"right\", Rect>>>;\n /**\n * With `contentMin` and a dynamic column (or, before any exists, a `columns` template): whether one column at its\n * minimum fits beside the content's minimum (`false` with a `no-column-room` note). Anchors and rails don't count:\n * every column can fold into its rail. A host shows its narrow fallback (one panel over the content) while it is `false`.\n */\n readonly columnRoom?: boolean;\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. Opened beside items that stayed open in its edge, it\n * counts as the newest (its largest form while it fits; the others give way by the usual rules) and its column is\n * weighed anew. A closed item is not a removed one: opened into an edge whose items were all closed, it comes back as\n * it was, with its age, and its column's folds (kept while it was closed) apply again.\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 gap's hit over an open item's body (a panel): a band this many px around the 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 * What the scene's shapes (`./model`) tell on their own: which zones of an edge take a kind, an edge's axis, an item's\n * zone and forms, whether a side edge is a toolbar bar, and how an item floats (its orient, size and form). Pure.\n */\nimport type { Rect, Size } from \"../geometry\";\nimport type { StackForm } from \"../stack\";\nimport { DEFAULT_FLOAT_SIZE, DEFAULT_HIT_BAND, DEFAULT_RAIL_MAGNET, RAIL_STRIP_MIN, ZONES, type ColumnTemplate, type Edge, type FloatAnchor, type FloatAnchorAt, type Kind, type Orient, type RailMode, type RailVisibility, type Scene, type SceneItem, type Side, type Zone, type ZoneAccepts } from \"./model\";\n\n/** The name of a float's anchor, with or without an offset: `\"content-top-right\"` for `{ at: \"content-top-right\", dy: 12 }`. */\nexport const anchorName = (anchor: FloatAnchorAt): FloatAnchor => (typeof anchor === \"string\" ? anchor : anchor.at);\n\n/**\n * Whether `x` is a usable `SceneFloat.since`: a number from 0 to `Number.MAX_SAFE_INTEGER`. Past that, one more is the\n * same number, so new floats would tie.\n */\nexport const isSince = (x: unknown): x is number => typeof x === \"number\" && x >= 0 && x <= Number.MAX_SAFE_INTEGER;\n\n/** Whether `edge` takes kind `kind` in `zone`: its `accepts`, narrowed by `zoneAccepts` when given (a zone not listed takes nothing). */\nexport const zoneTakes = (edge: { readonly accepts: readonly Kind[]; readonly zoneAccepts?: ZoneAccepts }, zone: Zone, kind: Kind): boolean =>\n edge.accepts.includes(kind) && (edge.zoneAccepts === undefined || !!edge.zoneAccepts[zone]?.includes(kind));\n\n/** The zones of `edge` that take `kind`, in order. */\nexport const zonesTaking = (edge: { readonly accepts: readonly Kind[]; readonly zoneAccepts?: ZoneAccepts }, kind: Kind): Zone[] => ZONES.filter((z) => zoneTakes(edge, z, kind));\n\n/**\n * Whether `edge` takes `kind` anywhere: its `accepts` lists it and at least one of its zones takes it (`zoneTakes`). An\n * edge whose zones take nothing for the kind (`zoneAccepts: {}`) takes it nowhere, exactly as one whose `accepts` lacks\n * it: the one test drop targets and refusals ask. The stored form and `readScene` keep reading `accepts` itself.\n */\nexport const edgeTakes = (edge: { readonly accepts: readonly Kind[]; readonly zoneAccepts?: ZoneAccepts }, kind: Kind): boolean => zonesTaking(edge, kind).length > 0;\n\n/**\n * How a gap's hit runs over `edge`'s open panels (`Edge.hitBand`): its own, else, for a dynamic column, its side's\n * template's (`ColumnTemplate.hitBand`), else {@link DEFAULT_HIT_BAND}.\n */\nexport const hitBandOf = (scene: Scene, edge: Edge): number | \"middle\" =>\n edge.hitBand ?? (edge.column === true && (edge.side === \"left\" || edge.side === \"right\") ? scene.columns?.[edge.side]?.hitBand : undefined) ?? DEFAULT_HIT_BAND;\n\n/**\n * A dynamic column made from its side's template: every column the scene makes (a drop on a column line, `moveTo` a new\n * column, `dockHome`, a stored column `readScene` reads back) is made here, so each takes every template field\n * (`accepts`, `cross`, `gap`, `pad`, `menu`, `zoneAccepts`, `hitBand`).\n */\nexport const columnFromTemplate = (t: ColumnTemplate, id: string, side: \"left\" | \"right\", ring: number, items: readonly string[]): Edge => ({\n id,\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 ...(t.zoneAccepts ? { zoneAccepts: t.zoneAccepts } : {}),\n ...(t.hitBand !== undefined ? { hitBand: t.hitBand } : {}),\n column: true,\n});\n\n/** How the rails of `side` show their items (`Scene.railModes`, default `\"titles\"`); top and bottom have no rails. */\nexport const railModeOf = (scene: Scene, side: Side): RailMode => (side === \"left\" || side === \"right\" ? (scene.railModes?.[side] === \"icons\" ? \"icons\" : \"titles\") : \"icons\");\n\n/** The axis an edge's stack runs along. */\nexport const axisOf = (side: Side): Orient => (side === \"left\" || side === \"right\" ? \"column\" : \"row\");\n\n/**\n * The chrome rects `who` keeps clear of (`SceneChrome`): floats keep clear of every entry; drop targets, slots and\n * landings only of those for `\"all\"` (the default), never of a floats-only one.\n */\nexport const chromeFor = (scene: Scene, who: \"floats\" | \"targets\"): Rect[] =>\n (scene.chrome ?? []).filter((c) => who === \"floats\" || c.for !== \"floats\").map((c) => ({ x: c.x, y: c.y, width: c.width, height: c.height }));\n\n/**\n * The side's rail where the scene declares none (`Scene.rails[side]`): its outermost column that takes `kind` in its\n * start zone (not an icons-only edge), which shows as a rail once nothing in it sets its width. Undefined where the side\n * has a declared rail, or no such column.\n */\nexport function railColumnOf(scene: Scene, side: \"left\" | \"right\", kind: Kind): Edge | undefined {\n if (scene.rails?.[side]) return undefined;\n return scene.edges\n .filter((e) => e.side === side && !e.compact && e.hidden !== true && zoneTakes(e, \"start\", kind))\n .reduce<Edge | undefined>((m, e) => (!m || e.ring < m.ring ? e : m), undefined);\n}\n\n/** The scene as the window shows it, and what it lent: see `viewOf`. */\nexport interface SceneView {\n /** The scene the window shows: no hidden edge; the items a hidden edge lends at the end of the edge it shows them in. */\n readonly view: Scene;\n /** Each lent item's hidden edge, by item id. */\n readonly lent: ReadonlyMap<string, string>;\n /** Hidden edges whose `showIn` is ignored: it names the edge itself, no edge, another hidden edge or a dynamic column. */\n readonly ignored: readonly string[];\n /** The items the view shows in a zone other than their own (`zoneIn`): their stored `align` is not where they lie. */\n readonly rezoned: ReadonlySet<string>;\n}\n\n/**\n * The zone `item` lies in on `edge`: its own (`align`) where the edge takes its kind there, else the first zone that\n * does. A fixed item, or one the edge takes nowhere, lies in its own. The item's zone is its own fact, not the edge's:\n * this is where it is laid out and targeted, while its stored `align` stays as it was, so it is back in its own zone\n * on an edge that takes it there.\n */\nexport function zoneIn(edge: Edge, item: SceneItem): Zone {\n const own = zoneOf(item);\n if (item.fixed || zoneTakes(edge, own, item.kind)) return own;\n return zonesTaking(edge, item.kind)[0] ?? own;\n}\n\n/**\n * Whether a drop on `edge` names a zone for `kind`: the edge offers a choice, more than one of its zones taking the\n * kind. Only then does the zone a drop gives become the item's `align`; on a one-zone edge (a rail that takes the kind\n * at its start only) the item keeps its own, and lies in that one zone there (`zoneIn`).\n */\nexport const namesZone = (edge: { readonly accepts: readonly Kind[]; readonly zoneAccepts?: ZoneAccepts }, kind: Kind): boolean => zonesTaking(edge, kind).length > 1;\n\n/**\n * Whether a hidden edge's `showIn` names an edge it can lend its items to: another static edge of the scene, not\n * hidden. A dynamic column (`column: true`) never is: drops make and delete those.\n */\nconst showInOf = (scene: Scene, e: Edge): Edge | undefined => {\n if (e.hidden !== true || e.showIn === undefined) return undefined;\n const to = scene.edges.find((x) => x.id === e.showIn);\n return to && to !== e && to.hidden !== true && to.column !== true ? to : undefined;\n};\n\n/**\n * The scene as the window shows it (`Edge.hidden`, `Edge.showIn`): its hidden edges left out, and the items of a hidden\n * edge that names `showIn` lent to that edge, after its own items, each that edge takes the kind of (`edgeTakes`; a\n * fixed item never). Every docked item, lent or not, lies in the zone `zoneIn` gives it: its own where its edge takes\n * it there, else the first zone that does (the view's `align`; the stored one is unchanged). The same object when nothing\n * is hidden and every item lies in its own zone.\n */\nexport function viewOf(scene: Scene): SceneView {\n const lent = new Map<string, string>();\n const ignored: string[] = [];\n const added = new Map<string, string[]>();\n const hidden = scene.edges.some((e) => e.hidden === true);\n if (hidden) {\n for (const e of scene.edges) {\n if (e.hidden !== true || e.showIn === undefined) continue;\n const to = showInOf(scene, e);\n if (!to) {\n ignored.push(e.id);\n continue;\n }\n for (const id of e.items) {\n const item = Object.hasOwn(scene.items, id) ? scene.items[id] : undefined;\n if (!item || item.fixed || lent.has(id) || to.items.includes(id) || !edgeTakes(to, item.kind)) continue;\n lent.set(id, e.id);\n added.set(to.id, [...(added.get(to.id) ?? []), id]);\n }\n }\n }\n const edges = hidden ? scene.edges.filter((e) => e.hidden !== true).map((e) => (added.has(e.id) ? { ...e, items: [...e.items, ...added.get(e.id)!] } : e)) : scene.edges;\n // Each docked item in the zone it lies in.\n const rezoned = new Set<string>();\n let items: Record<string, SceneItem> | undefined;\n for (const e of edges) {\n for (const id of e.items) {\n const item = Object.hasOwn(scene.items, id) ? scene.items[id] : undefined;\n if (!item) continue;\n const zone = zoneIn(e, item);\n if (zone === zoneOf(item)) continue;\n const { align: _a, ...plain } = item;\n items ??= { ...scene.items };\n items[id] = zone === \"start\" ? plain : { ...plain, align: zone };\n rezoned.add(id);\n }\n }\n if (!hidden && !items) return { view: scene, lent, ignored, rezoned };\n return { view: { ...scene, edges, ...(items ? { items } : {}) }, lent, ignored, rezoned };\n}\n\n/** Whether item `id` lies in a hidden edge. */\nexport const inHiddenEdge = (scene: Scene, id: string): boolean => scene.edges.some((e) => e.hidden === true && e.items.includes(id));\n\n/**\n * `shown`, a scene made from `viewOf(scene).view` (a drop's result), with `scene`'s hidden edges put back where they\n * stood in its edge list, holding their items. The items they lent go back to them, as they were, unless `moved` is\n * one of them: the item a drop committed somewhere, which keeps its new place and leaves its hidden edge. On a side whose\n * shown edges are those it had, nothing is renumbered. On a side where a column was made or removed, each hidden edge\n * goes back by its own ring, before the first shown edge that lay further in than it did, and the side is numbered again\n * from 0 in that order.\n *\n * Every item the view laid out in a zone other than its own (`rezoned`) keeps its stored `align`; so does `moved`, the\n * item a drop committed, unless the drop named a zone (`zoned`: a gap in an edge), whose zone it then takes.\n */\nexport function withHiddenOf(scene: Scene, shown: Scene, lent: ReadonlyMap<string, string> = new Map(), moved?: string, zoned = false, rezoned: ReadonlySet<string> = new Set()): Scene {\n if (shown === scene) return shown;\n // The lent items that stay lent: out of the edges they were shown in, back into their hidden edges.\n const back = [...lent.keys()].filter((id) => id !== moved);\n const edges = shown.edges.filter((e) => e.hidden !== true).map((e) => (back.some((id) => e.items.includes(id)) ? { ...e, items: e.items.filter((id) => !back.includes(id)) } : e));\n scene.edges.forEach((e, i) => {\n if (e.hidden !== true) return;\n const own = moved !== undefined && lent.get(moved) === e.id ? { ...e, items: e.items.filter((id) => id !== moved) } : e;\n edges.splice(Math.min(i, edges.length), 0, own);\n });\n const items: Record<string, SceneItem> = back.length > 0 ? { ...shown.items, ...Object.fromEntries(back.map((id) => [id, scene.items[id]!])) } : { ...shown.items };\n // The item's zone is its own fact: only a drop that names a zone changes it.\n const keep = new Set([...rezoned].filter((id) => !back.includes(id) && !(id === moved && zoned)));\n if (moved !== undefined && !zoned) keep.add(moved);\n for (const id of keep) {\n const was = Object.hasOwn(scene.items, id) ? scene.items[id] : undefined;\n const now = Object.hasOwn(items, id) ? items[id] : undefined;\n if (!was || !now || now.align === was.align) continue;\n const { align: _a, ...plain } = now;\n items[id] = was.align === undefined ? plain : { ...plain, align: was.align };\n }\n const ringBefore = new Map(scene.edges.filter((e) => e.hidden !== true).map((e) => [e.id, e.ring]));\n for (const side of new Set(scene.edges.filter((e) => e.hidden === true).map((e) => e.side))) {\n const was = scene.edges.filter((e) => e.side === side && e.hidden !== true).map((e) => e.id).sort();\n const now = edges.filter((e) => e.side === side && e.hidden !== true);\n if (now.length === was.length && now.every((e) => was.includes(e.id))) continue;\n const order = [...now].sort((a, b) => a.ring - b.ring || edges.indexOf(a) - edges.indexOf(b));\n for (const h of edges.filter((e) => e.side === side && e.hidden === true).sort((a, b) => a.ring - b.ring)) {\n const k = order.findIndex((e) => e.hidden !== true && (ringBefore.get(e.id) ?? -Infinity) > h.ring);\n order.splice(k < 0 ? order.length : k, 0, h);\n }\n order.forEach((e, ring) => {\n if (e.ring !== ring) edges[edges.indexOf(e)] = { ...e, ring };\n });\n }\n return { ...shown, edges, items };\n}\n\n/** A kind's rail drop policy with its defaults, or null where it has none or it is turned off (width 0, `\"never\"`). */\nexport function railPolicyOf(scene: Scene, kind: Kind): { readonly railStripWidth: number | null; readonly railVisibility: RailVisibility; readonly magnet: number; readonly floatNearEdge: boolean } | null {\n const p = Object.hasOwn(scene.railDrop ?? {}, kind) ? scene.railDrop![kind] : undefined;\n if (!p) return null;\n const visibility: RailVisibility = p.railVisibility === \"always\" || p.railVisibility === \"never\" ? p.railVisibility : \"whileDragging\";\n const width = p.railStripWidth;\n if (visibility === \"never\" || (width !== undefined && !(Number.isFinite(width) && width > 0))) return null;\n return {\n railStripWidth: width === undefined ? null : Math.max(RAIL_STRIP_MIN, width),\n railVisibility: visibility,\n magnet: Number.isFinite(p.magnet) ? Math.max(0, p.magnet!) : DEFAULT_RAIL_MAGNET,\n floatNearEdge: p.floatNearEdge !== false,\n };\n}\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\nconst PANEL_FORMS: ReadonlySet<string> = new Set([\"open\", \"header\", \"rail\"]);\n/** A panel that counts as docked for `insetWhen: \"docked\"`: not closed, not fixed, its first column form a panel's (open, header or rail). */\nexport const isDockingPanel = (item: SceneItem): boolean => !item.closed && !item.fixed && PANEL_FORMS.has(formsOf(item, \"column\")[0]?.kind ?? \"\");\n\n/**\n * A left or right toolbar bar outside the inset (`isSideBar` with `outsideInset`). It lies outermost on its side,\n * before the side's rail.\n */\nexport function isOutsideSideBar(scene: Scene, e: Edge): boolean {\n return e.outsideInset === true && isSideBar(scene, e);\n}\n\n/**\n * A left or right toolbar bar: told from a column edge by its kinds, it takes something and nothing the side's columns\n * or its rail take (`Scene.columns[side].accepts`, `Scene.rails[side].accepts`); an anchor takes nothing. A side with\n * neither a column template nor a rail has nothing to tell them apart by, so no edge there is a bar.\n */\nexport function isSideBar(scene: Scene, e: Edge): boolean {\n if ((e.side !== \"left\" && e.side !== \"right\") || e.column === true || e.accepts.length === 0) return false;\n const template = scene.columns?.[e.side];\n const rail = scene.rails?.[e.side];\n if (!template && !rail) return false;\n const panelKinds = [...(template?.accepts ?? []), ...(rail?.accepts ?? [])];\n return !e.accepts.some((k) => panelKinds.includes(k));\n}\n\n/**\n * The orient a float of `item` takes when it names none: its `floatOrient`, else the axis of its first form (the first\n * of `forms.row` / `forms.column` it declares with any form), else column.\n */\nexport const floatOrientOf = (item: SceneItem): Orient => {\n if (item.floatOrient === \"row\" || item.floatOrient === \"column\") return item.floatOrient;\n for (const k of Object.keys(item.forms)) if ((k === \"row\" || k === \"column\") && formsOf(item, k).length > 0) return k;\n return \"column\";\n};\n\n/**\n * A float's size when nothing gives one: the item's `floatSize`, else its first form's natural size along `orient`\n * (default `floatOrientOf`), else `DEFAULT_FLOAT_SIZE` when that form grows (a panel's card has no natural float length)\n * or the item has no form there.\n */\nexport function floatSizeOf(item: SceneItem, orient: Orient = floatOrientOf(item)): Size {\n if (item.floatSize) return item.floatSize;\n const f = formsOf(item, orient)[0];\n if (!f || f.main.grows) return DEFAULT_FLOAT_SIZE;\n const main = Number.isFinite(f.main.natural) ? Math.max(0, f.main.natural) : 0;\n const cross = Number.isFinite(f.cross.natural) ? Math.max(0, f.cross.natural) : 0;\n if (main <= 0 || cross <= 0) return DEFAULT_FLOAT_SIZE;\n return orient === \"row\" ? { width: main, height: cross } : { width: cross, height: main };\n}\n\n/**\n * Why `item`, drawn in form `form` of `forms` (the forms of the axis it lies along), counts as folded\n * (`SceneItemLayout.foldedBy`): `\"hand\"` when it is folded by hand and that axis has a folded form (`startOf` over 0),\n * else `\"auto\"` when `form` lies below `start`, the form it started in (it gave way), else undefined. A closed item, or\n * one in its first form, is never folded. Leave `start` out where nothing gives way (a float).\n */\nexport function foldedByOf(item: SceneItem, forms: readonly StackForm[], form: number, start?: number, edge?: Edge): \"hand\" | \"auto\" | undefined {\n if (item.closed || form < 1) return undefined;\n if (startOf(item, forms, edge) > 0) return \"hand\";\n return start !== undefined && form > start ? \"auto\" : undefined;\n}\n\n/** Whether `item` is folded by hand: its `from` is 1 or more (`fold(scene, id, true)` sets it). */\nconst foldedByHand = (item: SceneItem): boolean => Number.isFinite(item.from) && Math.floor(item.from!) >= 1;\n\n/**\n * Whether `item`, lying on `edge`, folds to its `rail` tile when it has no header or fold: a fixed item on a `foldable`\n * edge (a thumbnail anchor, whose column draws as a rail once it folds). The one rule `solve`, `canFold` and `fold` share.\n */\nconst foldsToRail = (item: SceneItem, edge: Edge | undefined): boolean => !!item.fixed && edge?.foldable === true;\n\n/**\n * The index of the form a hand fold puts `item` in, among `forms`: a panel's `header` (its title bar) or a group's\n * `fold` (its grip and »), the first of either; where it `foldsToRail` on `edge` and has neither, its first `rail` tile.\n * -1 when there is none: a hand fold means nothing on this axis.\n */\nexport function foldedIndex(item: SceneItem, forms: readonly StackForm[], edge?: Edge): number {\n const bar = forms.findIndex((f) => f.kind === \"header\" || f.kind === \"fold\");\n return bar >= 0 || !foldsToRail(item, edge) ? bar : forms.findIndex((f) => f.kind === \"rail\");\n}\n\n/**\n * Where `item`'s ladder starts among `forms`, the forms of the axis it lies along (on `edge`, when docked). Not folded\n * by hand: its first form. Folded by hand (`from` 1 or more): its folded form there (`foldedIndex`), or `from` itself\n * where a stored scene put it further down; with no folded form there, its first form (a hand fold means nothing).\n * Give-way steps down from there.\n */\nexport function startOf(item: SceneItem, forms: readonly StackForm[], edge?: Edge): number {\n if (!foldedByHand(item)) return 0;\n const folded = foldedIndex(item, forms, edge);\n return folded < 0 ? 0 : Math.min(Math.max(folded, Math.floor(item.from!)), forms.length - 1);\n}\n\n/**\n * The scene as it places item `id`: the window's (`viewOf`) when a hidden edge lends it to another edge, so its edge is\n * the one `solve` draws it in; else `scene` itself.\n */\nexport function placingOf(scene: Scene, id: string): Scene {\n if (!scene.edges.some((e) => e.hidden === true && e.showIn !== undefined && e.items.includes(id))) return scene;\n const { view, lent } = viewOf(scene);\n return lent.has(id) ? view : scene;\n}\n\n/** The axes item `id` lies along: its edge's (the one it is drawn in, when lent), its float's orient; both when it lies nowhere. */\nexport function axesOf(given: Scene, id: string): Orient[] {\n const scene = placingOf(given, id);\n const item = scene.items[id];\n const edge = scene.edges.find((e) => e.items.includes(id));\n if (edge) return [axisOf(edge.side)];\n const float = scene.floats.find((f) => f.id === id);\n return float && item ? [float.orient ?? floatOrientOf(item)] : [\"row\", \"column\"];\n}\n\n/**\n * Whether item `id` is folded by hand where it lies, as `solve` draws it: its `from` is 1 or more and it has a folded\n * form on the axis it lies along (`startOf` over 0). A stored `from` with no folded form there is no fold. Every reader\n * of the hand fold asks this, never `from` itself.\n */\nexport function isHandFolded(given: Scene, id: string): boolean {\n const scene = placingOf(given, id);\n const item = Object.hasOwn(given.items, id) ? given.items[id] : undefined;\n const edge = scene.edges.find((e) => e.items.includes(id));\n return !!item && axesOf(scene, id).some((a) => startOf(item, formsOf(item, a), edge) > 0);\n}\n\n/** The first form at or after `from` that isn't a `wrap` form (vertical means icons), or undefined when none is. */\nexport function pastWrap(forms: readonly StackForm[], from: number): number | undefined {\n for (let j = Math.max(0, Math.floor(from)); j < forms.length; j++) if (forms[j]!.kind !== \"wrap\" && !forms[j]!.wrap) return j;\n return undefined;\n}\n\n/**\n * How `solve` draws a float: the form it takes (an index into its `orient`'s forms) and its size. A vertical float\n * (`orient: \"column\"`) skips `wrap` forms, which apply only in a column edge: any form it takes after a skipped `wrap`\n * form (its icons) is drawn at that form's natural size, whatever its `from`. An item with only `wrap` forms left has no\n * form there (`none`: `solve` leaves it out with a `no-vertical-form` note), so a word group needs an `icons` form.\n * Otherwise a float with `from` over 0 is its bar (that form's natural length along its orient, its other size kept), and\n * one at its first form is its rect's size.\n */\nexport function floatShape(item: SceneItem, f: { readonly rect: Rect; readonly orient?: Orient }): { form: number; width: number; height: number; none?: true } {\n const orient = f.orient ?? floatOrientOf(item);\n const forms = formsOf(item, orient);\n const px = (v: number): number => (Number.isFinite(v) ? Math.max(0, v) : 0);\n const w = px(f.rect.width);\n const h = px(f.rect.height);\n if (forms.length === 0) return { form: 0, width: w, height: h };\n const asked = startOf(item, forms);\n const isWrap = (x: StackForm): boolean => x.kind === \"wrap\" || !!x.wrap;\n const skipped = orient === \"column\" ? pastWrap(forms, asked) : asked;\n if (skipped === undefined) return { form: asked, width: w, height: h, none: true };\n const form = skipped;\n const fm = forms[form]!;\n if (orient === \"column\" && forms.slice(0, form + 1).some(isWrap)) return { form, width: px(fm.cross.natural), height: px(fm.main.natural) };\n if (form > 0) return orient === \"column\" ? { form, width: w, height: px(fm.main.natural) } : { form, width: px(fm.main.natural), height: h };\n return { form, width: w, height: h };\n}\n","/**\n * The one id scheme of the Scene's targets and refusals: every id `targets`, `refusals` and `stops` give is built here,\n * and a host reads one back with `parseTargetId` instead of splitting strings.\n *\n * | Id | What it names | Priority |\n * |---|---|---|\n * | `gap:<edge>:<zone>:<at>` | a slot before the `at`-th item of an edge's zone | 2 |\n * | `strip:<edge>:<zone>` | a zone's one slot on an edge with no members at all | 2 |\n * | `column:<side>:<ring>` | a new column on a side's column line | 2 |\n * | `rail:<side>:<ring>` | docking folded into a side's rail | 1 |\n * | `side:<side>` | a fixed anchor's edge moved to the other side of its axis (`Edge.moves: \"side\"`) | 2 |\n * | `home:<item>` | the item's own place (a release there puts it back) | 1 |\n * | `float:<item>` | floating anywhere | 3 |\n * | `none:<i>` | the `i`-th `blocked` rect | 1 |\n * | `refuse:<edge>:<zone>[:<n>]` | a refusal; `:<n>` from a zone's second refused tile on, by where it lies | — |\n *\n * An edge id may hold `:` (the zone and the numbers are read from the right). The virtual edges a refusal can name are\n * `column:<side>` (a side's column lines) and `rail:<side>` (its rail): `virtualEdgeId`.\n */\nimport type { Scene, Side, Zone } from \"../model\";\n\ntype ColumnSide = \"left\" | \"right\";\n\n/** A `ScenePlace`, as much of it as an id reads (this module imports no more of the scene, so `solve` may use it). */\ntype PlaceLike =\n | { readonly kind: \"gap\"; readonly edge: string; readonly zone: Zone; readonly at: number }\n | { readonly kind: \"column\" | \"rail\"; readonly side: ColumnSide; readonly ring: number }\n | { readonly kind: \"side\"; readonly side: Side }\n | { readonly kind: \"float\" | \"home\" | \"none\" };\n\n/** A target or refusal id, read. */\nexport type TargetIdParts =\n | { readonly kind: \"gap\"; readonly edge: string; readonly zone: Zone; readonly at: number }\n | { readonly kind: \"strip\"; readonly edge: string; readonly zone: Zone }\n | { readonly kind: \"column\" | \"rail\"; readonly side: ColumnSide; readonly ring: number }\n | { readonly kind: \"side\"; readonly side: Side }\n | { readonly kind: \"home\" | \"float\"; readonly item: string }\n | { readonly kind: \"none\"; readonly index: number }\n | { readonly kind: \"refuse\"; readonly edge: string; readonly zone: Zone; readonly n: number };\n\n/** The id of the target or refusal `parts` names. */\nexport function targetId(parts: TargetIdParts): string {\n switch (parts.kind) {\n case \"gap\":\n return `gap:${parts.edge}:${parts.zone}:${parts.at}`;\n case \"strip\":\n return `strip:${parts.edge}:${parts.zone}`;\n case \"column\":\n case \"rail\":\n return `${parts.kind}:${parts.side}:${parts.ring}`;\n case \"side\":\n return `side:${parts.side}`;\n case \"home\":\n case \"float\":\n return `${parts.kind}:${parts.item}`;\n case \"none\":\n return `none:${parts.index}`;\n case \"refuse\":\n return parts.n === 0 ? `refuse:${parts.edge}:${parts.zone}` : `refuse:${parts.edge}:${parts.zone}:${parts.n}`;\n }\n}\n\nconst ZONE = \"(start|center|end)\";\nconst INT = \"(-?\\\\d+)\";\nconst GAP = new RegExp(`^gap:(.+):${ZONE}:${INT}$`);\nconst STRIP = new RegExp(`^strip:(.+):${ZONE}$`);\nconst LINE = new RegExp(`^(column|rail):(left|right):${INT}$`);\nconst SIDE = /^side:(left|right|top|bottom)$/;\nconst ITEM = /^(home|float):(.+)$/;\nconst NONE = new RegExp(`^none:${INT}$`);\nconst REFUSE = new RegExp(`^refuse:(.+):${ZONE}(?::${INT})?$`);\n\n/** What `id` names, or null when it is no id of the scheme. `targetId(parseTargetId(id)!) === id` for every id it reads. */\nexport function parseTargetId(id: string): TargetIdParts | null {\n let m: RegExpExecArray | null;\n if ((m = GAP.exec(id))) return { kind: \"gap\", edge: m[1]!, zone: m[2] as Zone, at: Number(m[3]) };\n if ((m = STRIP.exec(id))) return { kind: \"strip\", edge: m[1]!, zone: m[2] as Zone };\n if ((m = LINE.exec(id))) return { kind: m[1] as \"column\" | \"rail\", side: m[2] as ColumnSide, ring: Number(m[3]) };\n if ((m = SIDE.exec(id))) return { kind: \"side\", side: m[1] as Side };\n if ((m = ITEM.exec(id))) return { kind: m[1] as \"home\" | \"float\", item: m[2]! };\n if ((m = NONE.exec(id))) return { kind: \"none\", index: Number(m[1]) };\n if ((m = REFUSE.exec(id))) return { kind: \"refuse\", edge: m[1]!, zone: m[2] as Zone, n: m[3] === undefined ? 0 : Number(m[3]) };\n return null;\n}\n\n/** The id of a side's virtual edge: its column lines (`column:<side>`) or its rail (`rail:<side>`), as a refusal names it. */\nexport const virtualEdgeId = (kind: \"column\" | \"rail\", side: ColumnSide): string => `${kind}:${side}`;\n\n/** The edge ids that name a side's virtual edges: no real edge may take one. */\nconst RESERVED_EDGE_IDS = new Set(([\"column\", \"rail\"] as const).flatMap((k) => ([\"left\", \"right\"] as const).map((s) => virtualEdgeId(k, s))));\nexport const isReservedEdgeId = (id: string): boolean => RESERVED_EDGE_IDS.has(id);\n\n/** Throws when a real edge of `scene` takes a virtual edge's id (`column:<side>`, `rail:<side>`); `solve`, `targets` and `readScene` check it. */\nexport function checkEdgeIds(scene: Scene): void {\n for (const e of scene.edges) {\n if (isReservedEdgeId(e.id)) throw new Error(`placement: the edge id \"${e.id}\" is reserved for a side's virtual edge (column:<side>, rail:<side>); name the edge otherwise`);\n }\n}\n\n/**\n * The id `targets` gives the target at `place` for `item`, or null for a place with no fixed id (`none`). A gap's id is\n * its `gap:` one; on an edge with no members its slot is `strip:<edge>:<zone>`.\n */\nexport function placeTargetId(place: PlaceLike, item: string): string | null {\n switch (place.kind) {\n case \"gap\":\n return targetId(place);\n case \"column\":\n case \"rail\":\n return targetId(place);\n case \"side\":\n return targetId({ kind: \"side\", side: place.side });\n case \"float\":\n case \"home\":\n return targetId({ kind: place.kind, item });\n default:\n return null;\n }\n}\n","/**\n * The order `solve` lays edges in, and the small number helpers every phase shares. Internal to the scene: `targets`\n * ranks the space each edge owns by the same order (`layKeys`, `pushes`).\n */\nimport { zoneOf } from \"../helpers\";\nimport type { Edge, Scene, Zone } from \"../model\";\n\nexport const finite = (x: number | undefined, fallback: number): number => (typeof x === \"number\" && Number.isFinite(x) ? x : fallback);\nexport const px = (x: number | undefined): number => Math.max(0, finite(x, 0));\n\n/** A left or right edge. */\nexport const isSide = (e: Edge): boolean => e.side === \"left\" || e.side === \"right\";\n\n/** What give-way weighs an edge by: whether an item of it is kept, its newest use, its ring. */\nexport interface GiveWayRank {\n readonly kept: boolean;\n readonly age: number;\n readonly edge: Edge;\n}\n\n/**\n * The give-way order, for columns by width and bars by height alike: unkept before kept, the one whose newest use is\n * oldest first, the outer first. Ties stay as they are (a sort keeps them in order).\n */\nexport const giveWayOrder = (a: GiveWayRank, b: GiveWayRank): number =>\n Number(a.kept) - Number(b.kept) || a.age - b.age || finite(a.edge.ring, 0) - finite(b.edge.ring, 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\n/**\n * Where `solve` lays an edge in its laying order: `phase` 0 full bars outside the inset, 1 the other full bars, 2 the\n * sides, 3 the `between` bars, 4 overlay edges (laid over the content, pushing nothing); `at`, its place in the cut\n * order. Internal to the scene: `targets` ranks the space each edge owns by it.\n */\nexport interface LayKey {\n readonly phase: number;\n readonly side: string;\n readonly at: number;\n}\n\n/** Each edge's `LayKey`. */\nexport function layKeys(scene: Scene): Map<string, LayKey> {\n const phase = (e: Edge): number => (e.mode === \"overlay\" ? 4 : isSide(e) ? 2 : e.span === \"between\" ? 3 : e.outsideInset === true ? 0 : 1);\n return new Map(cutOrder(scene.edges).map((e, at) => [e.id, { phase: phase(e), side: e.side, at }]));\n}\n\n/**\n * Whether the edge laid at `a` takes its space before the edge at `b` can, so that filling `a` pushes `b`: a reserved\n * edge of an earlier phase, or one laid before it on the same side (the outer ring). Edges laid independently (the two\n * sides, top and bottom, any overlay edge) push neither way.\n */\nexport function pushes(a: LayKey, b: LayKey): boolean {\n if (a.phase === 4 || b.phase === 4) return false;\n if (a.phase !== b.phase) return a.phase < b.phase;\n return a.side === b.side && a.at < b.at;\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","/**\n * Bars by height: while the content is shorter than `contentMin.height` (overlay bars counted), the top and bottom bars\n * with `giveWay` shrink across toward their minimum, then fold (their items step to the next form that fits across), in\n * give-way order (`giveWayOrder`: unkept before kept, the oldest newest use first, the outer first). It answers with a\n * cap per bar, which `solve` lays the scene out again under (`cutEdge` solves each bar at its cap), and the notes.\n * Stateless: room coming back undoes it in reverse.\n */\nimport { EPS } from \"../../geometry\";\nimport { formCrossMin, formSetsCross } from \"../../stack\";\nimport { formsOf } from \"../helpers\";\nimport type { Edge, Scene, SceneLayout, SceneNote } from \"../model\";\nimport { cutOrder, finite, giveWayOrder, isSide, px, type GiveWayRank } from \"./order\";\n\n/** How far under a bar's thinnest open form a fold's cap lies, so every such form steps down. */\nconst UNDER = 0.5;\n\n/** The content's height less the overlay bars over it. */\nfunction roomOf(scene: Scene, l: SceneLayout): number {\n const bars = scene.edges.filter((e) => e.mode === \"overlay\" && !isSide(e)).reduce((s, e) => s + (l.edges[e.id]?.cross ?? 0), 0);\n return l.content.height - bars;\n}\n\n/** The items a bar draws that set its size across, with their forms' least size across. */\nfunction settersOf(scene: Scene, l: SceneLayout, edge: Edge): number[] {\n return (l.edges[edge.id]?.items ?? []).flatMap((id) => {\n const at = l.items[id];\n const item = scene.items[id];\n if (!at || !item || at.inMenu) return [];\n const f = formsOf(item, \"row\")[at.form];\n return f && formSetsCross(f) ? [formCrossMin(f)] : [];\n });\n}\n\n/**\n * The caps and notes of height give-way for `scene`, from its first layout `first`; `lay` lays it out under caps. Null\n * when nothing gives way.\n */\nexport function barGiveWay(\n scene: Scene,\n first: SceneLayout,\n lay: (caps: ReadonlyMap<string, number>) => SceneLayout,\n): { caps: Map<string, number>; notes: SceneNote[] } | null {\n if (!scene.contentMin) return null;\n const minH = px(scene.contentMin.height);\n const shortOf = (l: SceneLayout): number => minH - roomOf(scene, l);\n if (shortOf(first) <= EPS) return null;\n const rankOf = (edge: Edge): GiveWayRank => {\n const items = (first.edges[edge.id]?.items ?? []).filter((id) => scene.items[id] !== undefined);\n return {\n edge,\n kept: items.some((id) => scene.items[id]!.kept === true),\n age: Math.max(-Infinity, ...items.map((id) => finite(scene.items[id]!.used, 0))),\n };\n };\n const bars = cutOrder(scene.edges)\n .filter((e) => !isSide(e) && e.giveWay === true && (first.edges[e.id]?.cross ?? 0) > EPS)\n .map(rankOf)\n .sort(giveWayOrder)\n .map((r) => r.edge);\n if (bars.length === 0) return null;\n /** Fold caps, by edge id: under the bar's thinnest open form, so its items step down. */\n const folds = new Map<string, number>();\n /** The shrink caps, with `folds` folded, from the layout `l` they make: each bar toward its minimum, in order. */\n const shrinkFrom = (l: SceneLayout): { caps: Map<string, number>; notes: SceneNote[]; left: number } => {\n const caps = new Map(folds);\n const notes: SceneNote[] = [];\n let left = shortOf(l);\n for (const e of bars) {\n if (left <= EPS) break;\n if (folds.has(e.id)) continue;\n const cross = l.edges[e.id]?.cross ?? 0;\n const min = Math.max(px(e.cross.min), ...settersOf(scene, l, e));\n const cut = Math.min(left, cross - min);\n if (cut <= EPS) continue;\n caps.set(e.id, cross - cut);\n notes.push({ code: \"bar-shrunk\", edge: e.id, from: cross, to: cross - cut });\n left -= cut;\n }\n return { caps, notes, left };\n };\n let base = first;\n let way = shrinkFrom(base);\n // Still short with every bar at its minimum: fold the bars, one at a time in the same order, each fold re-weighing\n // the shrinks of the rest, until the content fits.\n for (const e of bars) {\n if (way.left <= EPS) break;\n const setters = settersOf(scene, first, e);\n if (setters.length === 0) continue;\n folds.set(e.id, Math.min(...setters) - UNDER);\n const l = lay(folds);\n if ((l.edges[e.id]?.cross ?? 0) >= (base.edges[e.id]?.cross ?? 0) - EPS) {\n // Nothing of it could step down: it keeps its size.\n folds.delete(e.id);\n continue;\n }\n base = l;\n way = shrinkFrom(base);\n }\n if (way.caps.size === 0) return null;\n return { caps: way.caps, notes: [...way.notes, ...[...folds.keys()].map((edge): SceneNote => ({ code: \"bar-folded\", edge }))] };\n}\n","/**\n * The layout as `solve` builds it, phase by phase: who owns which item, the notes, and every item and edge drawn so\n * far. `emit` draws one solved edge into it: its items placed by zone, their shapes, its notes and its edge layout.\n */\nimport { EPS, rect, type Rect } from \"../../geometry\";\nimport { formMain, wrapLines, type StackFit, type StackForm, type StackInput } from \"../../stack\";\nimport { axisOf, foldedByOf, formsOf, zoneOf } from \"../helpers\";\nimport type { Edge, Scene, SceneEdgeLayout, SceneItemLayout, SceneLayout, SceneNote, SceneRailLayout, SolveOptions, Zone } from \"../model\";\nimport type { EdgeSolve } from \"./edge\";\nimport { cutOrder, finite, px } from \"./order\";\n\nexport interface Draft {\n /** The scene as solved: an item that has just opened counts as the newest. */\n readonly scene: Scene;\n readonly previous: SceneLayout | undefined;\n /** Items docked now that were closed or absent in `previous`. */\n readonly opened: ReadonlySet<string>;\n /** `SolveOptions.fresh`. */\n readonly fresh: ReadonlySet<string>;\n /** The edges in cut order. */\n readonly order: readonly Edge[];\n /** Each edge's items, the first place in cut order winning. */\n readonly owned: ReadonlyMap<Edge, string[]>;\n /** Claims an item for one place: false (with a note) when it is unknown or placed already. */\n readonly claim: (id: string) => boolean;\n /** The edge's layout before, or none when it (or an item in it) is `fresh`. */\n readonly prevEdge: (edge: Edge) => SceneEdgeLayout | undefined;\n readonly notes: SceneNote[];\n readonly items: Record<string, SceneItemLayout>;\n readonly edges: Record<string, SceneEdgeLayout>;\n readonly rails: Partial<Record<\"left\" | \"right\", SceneRailLayout>>;\n readonly railPlaces: Partial<Record<\"left\" | \"right\", Rect>>;\n columnRoom?: boolean;\n /** Height give-way: the most a top or bottom bar that gives way may be across, by edge id. */\n readonly caps: ReadonlyMap<string, number>;\n}\n\n/**\n * A new draft of `given`: an item docked now that was closed or absent in `previous` counts as the newest. `caps` are\n * height give-way's caps on bars, by edge id.\n */\nexport function createDraft(given: Scene, options: SolveOptions, caps: ReadonlyMap<string, number> = new Map()): Draft {\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 // A closed item is not a removed one. One that opens into an edge where items stayed open is a request to show it: it\n // counts as the newest there. One that opens into an edge whose items were all closed comes back as it was, with its\n // age (its edge's give-way, kept while it was closed, applies again). Opened together, the newest keep their order\n // among themselves, the one used longer ago still the older.\n const stayedOpen = (e: Scene[\"edges\"][number]): boolean => e.items.some((id) => !opened.has(id) && Object.hasOwn(given.items, id) && !given.items[id]!.closed && !given.items[id]!.fixed);\n const newest = Object.values(given.items).reduce((m, it) => Math.max(m, finite(it.used, 0)), 0) + 1;\n const byAge = [...opened]\n .filter((id) => given.edges.some((e) => e.items.includes(id) && stayedOpen(e)))\n .sort((a, b) => finite(given.items[a]!.used, 0) - finite(given.items[b]!.used, 0) || (a < b ? -1 : 1));\n const scene: Scene = byAge.length === 0 ? given : { ...given, items: { ...given.items, ...Object.fromEntries(byAge.map((id, k) => [id, { ...given.items[id]!, used: newest + k }])) } };\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 order = cutOrder(scene.edges);\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 return { scene, previous, opened, fresh, order, owned, claim, prevEdge, notes, items: {}, edges: {}, rails: {}, railPlaces: {}, caps };\n}\n\n/**\n * What a drawn item reports of its shape: a `wrap` form's rows (word indexes per row, at the edge's cross size `cross`)\n * and its grip (the lead cell at the start of row one); a form with `grip` (an icons strip) its grip at its start along\n * the axis (a horizontal strip on top in a column).\n */\nexport function shapeOf(f: StackForm | undefined, r: Rect, axis: \"column\" | \"row\", cross: number): { rows?: number[][]; grip?: Rect } {\n if (!f) return {};\n if (f.wrap) {\n const lead = Math.max(0, finite(f.wrap.lead ?? 0, 0));\n const row = Math.max(0, finite(f.wrap.row, 0));\n return { rows: wrapLines(f.wrap, cross).lines, grip: rect(r.x, r.y, lead, Math.min(row, r.height)) };\n }\n const g = typeof f.grip === \"number\" && Number.isFinite(f.grip) && f.grip > 0 ? f.grip : 0;\n if (!g) return {};\n return { grip: axis === \"column\" ? rect(r.x, r.y, r.width, Math.min(g, r.height)) : rect(r.x, r.y, Math.min(g, r.width), r.height) };\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 centered between. Returns the main-axis start per id.\n */\nfunction zoneStarts(scene: Scene, fit: StackFit, input: StackInput): { starts: Map<string, number>; lengths: Map<string, number> } {\n const column = fit.axis === \"column\";\n const at = (r: Rect): number => (column ? r.y : r.x);\n const out = new Map<string, number>();\n const lengths = new Map<string, number>();\n const drawn = fit.items.filter((p) => p.kind !== \"menu\");\n for (const p of drawn) {\n out.set(p.id, at(p.rect));\n lengths.set(p.id, column ? p.rect.height : p.rect.width);\n }\n const len = (p: { id: string }): number => lengths.get(p.id)!;\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 ? (column ? fit.menu.rect.height : fit.menu.rect.width) + (drawn.length > 0 ? gap : 0) : 0;\n const zone = (z: Zone) => drawn.filter((p) => zoneOf(scene.items[p.id]) === z);\n const s = zone(\"start\");\n const c = zone(\"center\");\n const e = zone(\"end\");\n /**\n * A bar's title (a fixed item that grows, in the start zone): the zones are laid with it at its natural length, so\n * a toolbar right after it sits right after its natural rect (leading), and the title then takes the room up to the\n * next item only when nothing follows it in its zone.\n */\n const title = column\n ? undefined\n : s.find((p) => {\n const it = scene.items[p.id]!;\n const f = formsOf(it, \"row\")[p.form];\n return it.fixed && f?.main.grows && len(p) > formMain(f, \"natural\", fit.cross) + EPS;\n });\n if (title) lengths.set(title.id, formMain(formsOf(scene.items[title.id]!, \"row\")[title.form]!, \"natural\", fit.cross));\n const used = drawn.reduce((sum, p) => sum + len(p), 0) + Math.max(0, drawn.length - 1) * gap;\n const spare = fit.length - start - end - menu - used;\n if (spare <= EPS) return { starts: out, lengths };\n const total = (ps: readonly { id: string }[]): number => ps.reduce((sum, p) => sum + len(p), 0) + Math.max(0, ps.length - 1) * gap;\n const lay = (ps: readonly { id: string }[], from: number): void => {\n let x = from;\n for (const p of ps) {\n out.set(p.id, x);\n x += len(p) + gap;\n }\n };\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 // Centered on the edge's middle (so a centered readout stays put while the other zones change), kept between them; in\n // a title bar, where the middle isn't clear of the title and the trailing items, centered in the free span instead.\n const mid = (fit.length - total(c)) / 2;\n const clear = mid >= lo - EPS && mid + total(c) <= hi + EPS;\n lay(c, title && !clear ? Math.max(lo, (lo + hi - total(c)) / 2) : Math.max(lo, Math.min(mid, hi - total(c))));\n if (title && s[s.length - 1] === title) {\n // Nothing after the title in its zone: it grows into the room up to the next item.\n const next = [...c, ...e].map((p) => out.get(p.id)!);\n const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;\n lengths.set(title.id, Math.max(len(title), until - out.get(title.id)!));\n }\n return { starts: out, lengths };\n}\n\n/** Draws an edge's stack at `r` (its stage rect): its items, notes and edge layout. */\nexport function emit(d: Draft, edge: Edge, r: Rect, solved: EdgeSolve, extra: Partial<SceneEdgeLayout> = {}): void {\n const { scene, notes, items, edges } = d;\n const column = axisOf(edge.side) === \"column\";\n const { stack } = solved;\n const thick = column ? r.width : r.height;\n const { starts, lengths } = zoneStarts(scene, stack, solved.input);\n const toStage = (l: Rect, id?: string): Rect => {\n const s = id !== undefined ? starts.get(id) : undefined;\n const n = id !== undefined ? lengths.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, column ? l.width : (n ?? l.width), column ? (n ?? l.height) : l.height);\n };\n const tabs = new Set(solved.tabs);\n for (const id of solved.leftOut ?? []) notes.push({ code: \"no-vertical-form\", edge: edge.id, id });\n for (const id of solved.leftOutIcons ?? []) notes.push({ code: \"no-icons-form\", edge: edge.id, id });\n for (const p of stack.items) {\n const it = scene.items[p.id]!;\n const inMenu = p.kind === \"menu\";\n const drawnRect = toStage(p.rect, inMenu ? undefined : p.id);\n const f = formsOf(it, column ? \"column\" : \"row\")[p.form];\n const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? \"column\" : \"row\", stack.cross);\n const foldedBy = foldedByOf(it, formsOf(it, column ? \"column\" : \"row\"), p.form, solved.starts.get(p.id), edge);\n items[p.id] = {\n ...shape,\n hidden: inMenu ? [] : (f?.hides ?? []),\n rect: drawnRect,\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 ...(tabs.has(p.id) && f?.title === true && (edge.side === \"left\" || edge.side === \"right\") ? { railTitle: edge.side } : {}),\n ...(solved.closedTabs.has(p.id) ? { closed: true } : {}),\n ...(foldedBy ? { foldedBy } : {}),\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 // The stack's items are in zone order, the order `emit` drew them in.\n items: stack.items.map((p) => p.id),\n tabs: solved.tabs,\n stack,\n free: solved.free,\n ...extra,\n };\n}\n","/**\n * One edge as a stack (`fitStack`): its free fit, then, for a column, its rail (nothing in it sets the width) or the\n * user's size. A compact edge is icons only.\n */\nimport { EPS } from \"../../geometry\";\nimport { fitStack, formCrossMin, formSetsCross, type StackFit, type StackForm, type StackInput, type StackItem } from \"../../stack\";\nimport { axisOf, formsOf, pastWrap, railModeOf, startOf, zoneOf } from \"../helpers\";\nimport type { Edge, Scene, SceneEdgeLayout, SceneItem } from \"../model\";\nimport { finite, px, zoneSorted } from \"./order\";\n\nconst stackItemOf =(item: SceneItem, forms: readonly StackForm[], edge: Edge, from?: number): StackItem => ({\n id: item.id,\n forms,\n used: finite(item.used, 0),\n ...(item.kept ? { kept: true } : {}),\n // Where its ladder starts: as asked, else its hand fold resolved on this axis (`startOf`: its folded form).\n ...(from !== undefined ? { from } : startOf(item, forms, edge) > 0 ? { from: startOf(item, forms, edge) } : {}),\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\nexport interface EdgeSolve {\n readonly stack: StackFit;\n readonly free: StackFit;\n readonly tabs: readonly string[];\n readonly closedTabs: ReadonlySet<string>;\n readonly input: StackInput;\n /** The form each open item started in (its stack item's `from` in the free fit): one drawn below it gave way. */\n readonly starts: ReadonlyMap<string, number>;\n /** Items left out of a rail: they have only `wrap` forms left (`no-vertical-form`). */\n readonly leftOut?: readonly string[];\n /** Items left out of a compact edge: they have no `icons` form (`no-icons-form`). */\n readonly leftOutIcons?: readonly string[];\n}\n\n/** How far a tray toolbar's steps rank after the panels' (its forms' `rank` plus this). */\nconst TRAY_RANK = 100;\n\n/** What every way of solving one edge shares: its items in zone order, their forms with priority, the stack's base. */\ninterface EdgeFrame {\n readonly scene: Scene;\n readonly edge: Edge;\n readonly column: boolean;\n readonly ordered: readonly string[];\n readonly formsById: (id: string) => readonly StackForm[];\n readonly base: Omit<StackInput, \"items\">;\n readonly previous: SceneEdgeLayout | undefined;\n}\n\n/** The form each item of `input` starts in. */\nconst startsOf = (input: StackInput): ReadonlyMap<string, number> => new Map(input.items.map((i) => [i.id, i.from ?? 0]));\n\n/** An icons-only edge: each item starts at its icons form (the » menu may follow); one without is left out. */\nfunction compactEdge(f: EdgeFrame): EdgeSolve {\n const { scene, edge, formsById } = f;\n const iconsAt = (id: string): number => {\n const forms = formsById(id);\n for (let j = startOf(scene.items[id]!, forms, edge); j < forms.length; j++) if (forms[j]!.kind === \"icons\") return j;\n return forms.findIndex((x) => x.kind === \"icons\");\n };\n const shown = f.ordered.filter((id) => !scene.items[id]!.closed && iconsAt(id) >= 0);\n const leftOutIcons = f.ordered.filter((id) => !scene.items[id]!.closed && iconsAt(id) < 0);\n const compactInput: StackInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(scene.items[id]!, formsById(id), edge, iconsAt(id))) };\n const stack = fitStack(compactInput, f.previous ? { previous: f.previous.free } : {});\n return { stack, free: stack, tabs: [], closedTabs: new Set(), input: compactInput, starts: startsOf(compactInput), leftOutIcons };\n}\n\n/**\n * A rail (a column in which nothing sets the width): the items with a rail form take it (closed ones too, with\n * `railShowsClosed`); null when no item shown has one.\n */\nfunction railEdge(f: EdgeFrame, free: StackFit, asStackItem: (id: string) => StackItem, starts: ReadonlyMap<string, number>): EdgeSolve | null {\n const { scene, edge, formsById } = f;\n const railIndex = (item: SceneItem, forms: readonly StackForm[]): number => {\n if (item.fixed) return -1;\n for (let j = startOf(item, forms, edge); j < forms.length; j++) if (forms[j]!.kind === \"rail\") return j;\n return -1;\n };\n // Vertical means icons: an item with only `wrap` forms left has no form for a rail, and is left out (noted).\n const wrapOnly = (id: string): boolean => railIndex(scene.items[id]!, formsById(id)) < 0 && pastWrap(formsById(id), startOf(scene.items[id]!, formsById(id), edge)) === undefined;\n const shown = f.ordered.filter((id) => {\n const it = scene.items[id]!;\n if (!it.closed && wrapOnly(id)) return false;\n return !it.closed || (edge.railShowsClosed === true && railIndex(it, formsById(id)) >= 0);\n });\n const leftOut = f.ordered.filter((id) => !scene.items[id]!.closed && wrapOnly(id));\n const anyRail = shown.some((id) => railIndex(scene.items[id]!, formsById(id)) >= 0);\n if (!anyRail) return null;\n const railInput: StackInput = {\n ...f.base,\n // The side's rail mode: a title rail form is offered only while the side shows titles.\n ...(railModeOf(scene, edge.side) === \"titles\" ? { titles: true } : {}),\n items: shown.map((id) => {\n const it = scene.items[id]!;\n const j = railIndex(it, formsById(id));\n // Vertical means icons: in a rail a group skips its `wrap` forms (a tray toolbar keeps its tray forms, no menu).\n const forms = asStackItem(id).forms;\n return stackItemOf(it, forms, edge, j >= 0 ? j : pastWrap(forms, startOf(it, forms, edge)));\n }),\n };\n const stack = fitStack(railInput, f.previous ? { previous: f.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, starts, leftOut };\n}\n\n/** One edge's stack along `length`: the free fit, then the rail or the user's size. */\nexport function 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 // An item's give-way priority (its own, else its edge's default) adds to its forms' `rank`: lower steps down first.\n const priorityOf = (id: string): number => finite(scene.items[id]!.priority ?? edge.priority ?? 0, 0);\n const formsById = (id: string): readonly StackForm[] => {\n const forms = formsOf(scene.items[id]!, axis);\n const p = priorityOf(id);\n return p === 0 ? forms : forms.map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + p }));\n };\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 frame: EdgeFrame = { scene, edge, column, ordered, formsById, base, previous };\n if (edge.compact) return compactEdge(frame);\n const open = ordered.filter((id) => !scene.items[id]!.closed);\n /**\n * A toolbar in a column's tray (the end zone, when `zoneAccepts` lists it) takes only its `wrap` or `icons` form, never\n * the menu, and its steps rank after every other item's, so the panels above give way first.\n */\n const asStackItem = (id: string): StackItem => {\n const it = scene.items[id]!;\n const forms = formsById(id);\n if (!column || !edge.zoneAccepts?.end || zoneOf(it) !== \"end\") return stackItemOf(it, forms, edge);\n const tray = (f: StackForm): boolean => f.kind === \"wrap\" || f.kind === \"icons\" || !!f.wrap;\n let first = -1;\n for (let j = startOf(it, forms, edge); j < forms.length && first < 0; j++) if (tray(forms[j]!)) first = j;\n let last = -1;\n forms.forEach((f, j) => {\n if (tray(f)) last = j;\n });\n if (first < 0) return stackItemOf(it, forms, edge);\n return stackItemOf(it, forms.slice(0, last + 1).map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + TRAY_RANK })), edge, first);\n };\n const input: StackInput = { ...base, items: open.map(asStackItem) };\n const free = fitStack(input, previous ? { previous: previous.free } : {});\n const none = new Set<string>();\n // The forms the items started in, before the rail or the user's size re-solved them: what gave way is read against these.\n const starts = startsOf(input);\n if (column && !hasSetter(free, formsById)) {\n const rail = railEdge(frame, free, asStackItem, starts);\n if (rail) return rail;\n }\n // A bar that gives way (a top or bottom edge with `giveWay`) never draws an item thinner across than its form allows:\n // under its height give-way's cap, such an item starts at its next form that fits (a panel's title bar), counted as\n // given way against the form it started in.\n if (!column && edge.giveWay === true) {\n const fits = (f: StackForm): boolean => !formSetsCross(f) || formCrossMin(f) <= cross.max + EPS;\n let moved = false;\n const items = input.items.map((it): StackItem => {\n const from = it.from ?? 0;\n if (it.fixed || fits(it.forms[from]!)) return it;\n const j = it.forms.findIndex((f, k) => k > from && f.kind !== \"menu\" && fits(f));\n if (j < 0) return it;\n moved = true;\n return { ...it, from: j };\n });\n if (moved) {\n const folded: StackInput = { ...input, items };\n return { stack: fitStack(folded), free, tabs: [], closedTabs: none, input: folded, starts };\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) => formCrossMin(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, starts };\n }\n }\n return { stack: free, free, tabs: [], closedTabs: none, input, starts };\n}\n","/**\n * The cut of one edge laid by itself (the full and `between` bars, and every overlay edge): its stack along the area's\n * length, drawn at the area's side as thick as the stack, the area less that thickness after it. A bar that gave way by\n * height (`bar-giveway`) is solved at its cap.\n */\nimport { rect, type Rect } from \"../../geometry\";\nimport { axisOf } from \"../helpers\";\nimport type { Edge } from \"../model\";\nimport { emit, type Draft } from \"./draft\";\nimport { solveEdge } from \"./edge\";\n\n/** Lays `edge` at its side of `area`; returns what is left of `area` (all of it when `cut` is false). */\nexport function cutEdge(d: Draft, 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 // Height give-way's cap, when it shrank or folded this bar.\n const cap = d.caps.get(edge.id);\n const solvedAs = cap === undefined ? edge : { ...edge, cross: { ...edge.cross, max: Math.min(edge.cross.max, cap) } };\n const solved = solveEdge(d.scene, solvedAs, d.owned.get(edge)!, length, room, d.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(d, 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 * The floats: fitted inside the stage less the inset at its left and right, clear of every docked item (fixed ones and\n * » entries included), every bar and the chrome rects (`fitFloat`). An anchored float sits flush with that side or\n * corner of `content` first, then clear of every float with a rect of its own and of the anchored floats floated before\n * it (smaller `since`, then smaller id) too, where room exists (`fitBeside`); the stacking order plays no part. A float\n * with `from` over 0 is its bar: its form's natural length along its `orient`, its other size kept.\n */\nimport { fitFloat, type FloatFit } from \"../../float-fit\";\nimport { EPS, rect, type Rect, type Size } from \"../../geometry\";\nimport type { StackForm } from \"../../stack\";\nimport { anchorName, axisOf, chromeFor, floatOrientOf, floatShape, foldedByOf, formsOf, isSince } from \"../helpers\";\nimport type { FloatAnchor, FloatAnchorAt, Orient, SceneFloat, SceneItem } from \"../model\";\nimport { shapeOf, type Draft } from \"./draft\";\nimport type { Inset } from \"./insets\";\nimport { finite, px } from \"./order\";\n\n/** When a float was floated, for the order among anchored floats: its `since`, a missing or unusable one 0. */\nconst sinceOf = (f: SceneFloat): number => (isSince(f.since) ? f.since : 0);\n\n/** A float's rect flush with `content`'s side or corner, moved by the anchor's offset (`dx` right, `dy` down). */\nfunction anchored(content: Rect, w: number, h: number, given: FloatAnchorAt): Rect {\n const anchor = anchorName(given);\n const dx = typeof given === \"string\" ? 0 : finite(given.dx ?? 0, 0);\n const dy = typeof given === \"string\" ? 0 : finite(given.dy ?? 0, 0);\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 + dx, y + dy, w, h);\n}\n\n/** The floor a float of `item` is laid out at: its `floatMin`, else its form's own minimums, which only stop a shrink. */\nexport function floatFloor(item: SceneItem, form: StackForm | undefined, orient: Orient, size: Size): Size {\n const row = orient === \"row\";\n // The form's own minimums only stop a shrink (a float asked smaller keeps its size); `floatMin` is laid out as given.\n return {\n width: item.floatMin ? px(item.floatMin.width) : Math.min(size.width, px(row ? form?.main.min : form?.cross.min)),\n height: item.floatMin ? px(item.floatMin.height) : Math.min(size.height, px(row ? form?.cross.min : form?.main.min)),\n };\n}\n\n/**\n * The room `region` leaves a float along each axis, clear of what spans it whole: down it, the region less the bars and\n * chrome across its full width at its top and bottom; across it, less what runs its full height at its left and right.\n * What spans only part of it is no limit on the size (a float fits beside it).\n */\nfunction clearSize(region: Rect, avoid: readonly Rect[]): Size {\n const span = (axis: \"x\" | \"y\"): number => {\n const lo = axis === \"y\" ? region.y : region.x;\n const hi = lo + (axis === \"y\" ? region.height : region.width);\n const mid = (lo + hi) / 2;\n let a = lo;\n let b = hi;\n for (const r of avoid) {\n // Across the region whole, the other way.\n const whole = axis === \"y\" ? r.x <= region.x + EPS && r.x + r.width >= region.x + region.width - EPS : r.y <= region.y + EPS && r.y + r.height >= region.y + region.height - EPS;\n const s = axis === \"y\" ? r.y : r.x;\n const e = s + (axis === \"y\" ? r.height : r.width);\n if (!whole || e <= lo || s >= hi) continue;\n if (s + e <= 2 * mid) a = Math.max(a, e);\n else b = Math.min(b, s);\n }\n return Math.max(0, b - a);\n };\n return { width: span(\"x\"), height: span(\"y\") };\n}\n\n/**\n * An anchored float's fit: `fitFloat` clear of `avoid` and of `earlier` (the floats that win over it), the same nearest\n * clear place it finds beside docked items. Where no place is clear of both, it is `fitFloat` clear of `avoid` alone, as\n * if `earlier` were not there: a float may cover an earlier float, never a docked item it could have stayed clear of.\n * With no earlier floats it is exactly `fitFloat(want, region, avoid)`.\n */\nfunction fitBeside(want: Rect, region: Rect, avoid: readonly Rect[], earlier: readonly Rect[]): FloatFit {\n if (earlier.length === 0) return fitFloat(want, region, avoid);\n const both = fitFloat(want, region, [...avoid, ...earlier]);\n return both.covers.length === 0 ? both : fitFloat(want, region, avoid);\n}\n\n/**\n * Where one float of `item` lies, as `solve` lays it (and `fitResize` previews it): its form and size, then `fitFloat`\n * into `region`, clear of `avoid`. Its size is clamped to the room `region` leaves clear of the bars and chrome across\n * it (`clearSize`), never under its floor: only a floor larger than that room covers. The one clamp for a float's rect;\n * `shape.none` is the caller's to handle first. An anchored float is also kept clear of `earlier` (the floats that win\n * over it) where room exists (`fitBeside`); a float with a rect of its own ignores `earlier`.\n */\nexport function placeFloat(item: SceneItem, f: Pick<SceneFloat, \"rect\" | \"orient\" | \"anchor\">, region: Rect, avoid: readonly Rect[], content: Rect, stage: Rect, earlier: readonly Rect[] = []): { from: number; fo: Orient; form: StackForm | undefined; fit: FloatFit } {\n const shape = floatShape(item, f);\n const from = shape.form;\n // Its orient: the float's, else the item's (`floatOrientOf`: a toolbar group floats as a row).\n const fo = f.orient ?? floatOrientOf(item);\n const form = formsOf(item, fo)[from];\n // Into that region; a float larger than it is shrunk to fit it, never under its floor. A folded float (its bar) keeps\n // its height. Wider than the region at its floor, it keeps the floor and lies at the region's left edge.\n const floor = floatFloor(item, form, fo, shape);\n // `floatMax` caps it (never under the floor).\n const cap = { width: Number.isFinite(item.floatMax?.width) ? item.floatMax!.width : Infinity, height: Number.isFinite(item.floatMax?.height) ? item.floatMax!.height : Infinity };\n const clear = clearSize(region, avoid);\n const w = Math.max(floor.width, Math.min(shape.width, clear.width, cap.width));\n // A float folded by hand is its bar (a panel's `header`, a group's `fold`): it keeps the bar's own height. Any other\n // form (its first, or a later one a stored scene names) fits the region.\n const folded = form?.kind === \"header\" || form?.kind === \"fold\";\n const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, clear.height, cap.height));\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 fit0 = f.anchor ? fitBeside(want, region, avoid, earlier) : fitFloat(want, region, avoid);\n const fit = w > region.width + EPS ? { ...fit0, rect: rect(region.x, fit0.rect.y, w, fit0.rect.height) } : fit0;\n return { from, fo, form, fit };\n}\n\n/** Lays every float of the scene that isn't placed already; returns their ids in stacking order. */\nexport function layFloats(d: Draft, stage: Rect, content: Rect, inset: Inset): string[] {\n const { scene, notes, items, edges } = d;\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 chromeFor(scene, \"floats\")) avoid.push(c);\n // Floats lie within the stage less the inset at its left and right (the sides the columns pad), the stage's full height.\n const floatRegion = rect(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);\n // The floats drawn, in stacking order; a note for one with no vertical form, in that order too.\n const drawn: SceneFloat[] = [];\n const noForm = new Set<string>();\n for (const f of scene.floats) {\n if (!d.claim(f.id)) continue;\n const it = scene.items[f.id]!;\n if (it.closed) continue;\n // Vertical means icons: an item with only `wrap` forms left has no form for a vertical float.\n if (floatShape(it, f).none) noForm.add(f.id);\n drawn.push(f);\n }\n // Where each lies, apart from the stacking order (so `raise` reshapes nothing): a float with its own rect first, clear\n // of what floats are kept clear of; then the anchored ones, earliest floated first (`since`, then id), each clear of\n // every float with its own rect and of the anchored ones floated before it too, where room exists (`fitBeside`).\n const placed = new Map<string, ReturnType<typeof placeFloat>>();\n const place = (f: SceneFloat, earlier: readonly Rect[] = []): void => {\n placed.set(f.id, placeFloat(scene.items[f.id]!, f, floatRegion, avoid, content, stage, earlier));\n };\n const live = drawn.filter((f) => !noForm.has(f.id));\n for (const f of live) if (!f.anchor) place(f);\n const own = [...placed.values()].map((p) => p.fit.rect);\n const anchored = live.filter((f) => f.anchor).sort((a, b) => sinceOf(a) - sinceOf(b) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));\n anchored.forEach((f, i) => place(f, [...own, ...anchored.slice(0, i).map((a) => placed.get(a.id)!.fit.rect)]));\n const floats: string[] = [];\n for (const f of drawn) {\n if (noForm.has(f.id)) {\n notes.push({ code: \"no-vertical-form\", id: f.id });\n continue;\n }\n const it = scene.items[f.id]!;\n const { from, fo, form, fit } = placed.get(f.id)!;\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 // A float never gives way: it is folded by hand or not at all.\n const foldedBy = foldedByOf(it, formsOf(it, fo), from);\n items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), hidden: form?.hides ?? [], rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? \"open\", floating: true, ...(foldedBy ? { foldedBy } : {}) };\n floats.push(f.id);\n }\n return floats;\n}\n","/**\n * The inset: the space kept clear inside the stage's edges, or none with `insetWhen: \"docked\"` while no panel is docked\n * beside the content. `Frame` carries it, with the gutter and the area the outside bars leave, to the side phase.\n */\nimport { EPS, rect, type Rect } from \"../../geometry\";\nimport { isDockingPanel } from \"../helpers\";\nimport type { Scene } from \"../model\";\nimport type { Draft } from \"./draft\";\nimport { isSide, px } from \"./order\";\n\nexport type Inset = NonNullable<Scene[\"inset\"]>;\n\n/** What the side phase reads of the window around it. */\nexport interface Frame {\n /** The inset in force. */\n readonly inset: Inset;\n /** The space after each side edge and rail that takes room. */\n readonly gutter: number;\n /** Whether a panel is docked beside the content (`insetWhen: \"docked\"`). */\n readonly docked: boolean;\n /** The stage less the full bars outside the inset. */\n readonly outer: Rect;\n}\n\n/**\n * The inset, or none with `insetWhen: \"docked\"` while nothing is docked beside the content: only a panel counts, in a\n * column or a rail (an item there, not closed, whose first column form is a panel's: open, header or rail). Bars,\n * toolbar groups and an anchor (it takes nothing) never do, wherever they sit.\n */\nexport function insetOf(d: Draft): { inset: Inset; docked: boolean } {\n const { scene } = d;\n const docked = d.order.some((e) => isSide(e) && e.accepts.length > 0 && d.owned.get(e)!.some((id) => isDockingPanel(scene.items[id]!)));\n const inset = scene.insetWhen === \"docked\" && !docked ? {} : (scene.inset ?? {});\n return { inset, docked };\n}\n\n/** `outer` less the inset on every side. */\nexport const insideInset = (outer: Rect, inset: Inset): Rect =>\n rect(outer.x + px(inset.left), outer.y + px(inset.top), Math.max(0, outer.width - px(inset.left) - px(inset.right)), Math.max(0, outer.height - px(inset.top) - px(inset.bottom)));\n\n/**\n * How far an edge outside the inset (an anchor) runs into the inset above and below `area`, where no reserved bar lies\n * on that side (a bar there keeps it below or above the bar). Outside bars lie beyond the inset already: measured from\n * what they leave.\n */\nexport function insetReach(area: Rect, f: Frame): { up: number; down: number } {\n const up = area.y <= f.outer.y + px(f.inset.top) + EPS ? px(f.inset.top) : 0;\n const down = area.y + area.height >= f.outer.y + f.outer.height - px(f.inset.bottom) - EPS ? px(f.inset.bottom) : 0;\n return { up, down };\n}\n","/** The notes about the content itself: narrower or shorter than `contentMin`, moved since `previous`. */\nimport { EPS, type Rect } from \"../../geometry\";\nimport type { Draft } from \"./draft\";\nimport { isSide, px } from \"./order\";\n\nexport function contentNotes(d: Draft, content: Rect): void {\n const { scene, notes, previous } = d;\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 // Overlay bars lie over the content: what they cover isn't the content's height.\n const bars = d.order.filter((e) => e.mode === \"overlay\" && !isSide(e)).reduce((s, e) => s + (d.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","/**\n * Column give-way: while the content is narrower than `contentMin.width` (after the inset and a gutter after each side\n * edge and rail), dynamic columns shrink toward their minimum, then fold whole into their side's rail, unkept before\n * kept, the oldest newest use first, the outer first, the left first. Under `previous`, what gave way stays so while\n * the content still fits, and room coming back unfolds in the reverse of give-way order.\n */\nimport { EPS, type Rect } from \"../../geometry\";\nimport { formCrossMin, formSetsCross, type StackForm } from \"../../stack\";\nimport { formsOf, isSideBar, startOf } from \"../helpers\";\nimport type { Edge, SceneNote } from \"../model\";\nimport type { Draft } from \"./draft\";\nimport { solveEdge, type EdgeSolve } from \"./edge\";\nimport type { Frame } from \"./insets\";\nimport { finite, giveWayOrder, px } from \"./order\";\n\n/** One left or right edge as give-way weighs it. */\nexport 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\n/** Give-way's answer: the columns folded by it (in fold order), each other column's width, and how they show. */\nexport interface GiveWay {\n readonly auto: ReadonlySet<Col>;\n readonly widths: ReadonlyMap<Col, number>;\n readonly excess: number;\n /** In the side's rail: folded by give-way, or by hand and not riding. */\n readonly railed: (c: Col) => boolean;\n /** Riding as title bars over the side's first open column (`handFold: \"ride\"`). */\n readonly riding: (c: Col) => boolean;\n /** The columns in shrink order. */\n readonly shrinkOrder: readonly Col[];\n}\n\n/** The side edges solved at the area's height (`tall`: an edge outside the inset runs into it). */\nexport function columnsOf(d: Draft, sideEdges: readonly Edge[], area: Rect, tall: (edge: Edge) => number): Col[] {\n const { scene } = d;\n return sideEdges.map((edge) => {\n const side = edge.side as \"left\" | \"right\";\n const solved = solveEdge(scene, edge, d.owned.get(edge)!, tall(edge), Math.max(0, area.width), d.prevEdge(edge));\n const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area.width);\n const visible = d.owned.get(edge)!.filter((id) => !scene.items[id]!.closed);\n // A dynamic column, or a static edge that gives way like one (`giveWay`).\n const dyn = (edge.column === true || edge.giveWay === 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) => formCrossMin(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 && edge.column === true && visible.every((id) => startOf(scene.items[id]!, formsOf(scene.items[id]!, \"column\")) > 0),\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}\n\n/** Which columns fold and how wide the rest are, in `area` (`gutter` after each column and rail). */\nexport function giveWay(d: Draft, cols: readonly Col[], area: Rect, gutter: number): GiveWay {\n const { scene, previous, fresh, opened } = d;\n const ride = scene.handFold === \"ride\";\n const cmin = scene.contentMin ? px(scene.contentMin.width) : undefined;\n const foldOrder = cols\n .filter((c) => c.dyn && !c.hand && c.width > 0)\n .sort((a, b) => giveWayOrder(a, b) || (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 = foldOrder.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>): GiveWay => {\n // Riders ride over an open panel column (never an anchor), every member of a hand-folded column a bar.\n const openOn = (side: \"left\" | \"right\"): boolean => cols.some((c) => c.side === side && c.dyn && c.edge.column === true && !c.hand && !auto.has(c) && c.width > 0);\n const riding = (c: Col): boolean => ride && c.hand && 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 // An edge outside the inset has no gutter after it (the inset is there).\n for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : 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, shrinkOrder };\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(foldOrder.map((c) => [c.edge.id, c]));\n // A column with a `fresh` item (or itself `fresh`) is weighed anew, and so is one an item opens into beside items\n // already open there (a request to show it). A column whose items were all closed and open again is not: a closed\n // item is not a removed one, and its column's give-way, kept while it was closed, applies again.\n const anew = (c: Col): boolean =>\n fresh.has(c.edge.id) || c.visible.some((id) => fresh.has(id)) || (c.visible.some((id) => opened.has(id)) && c.visible.some((id) => !opened.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 foldOrder) {\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 return evaluate(auto);\n}\n\n/**\n * Whether one panel column at its minimum fits beside the content's minimum: a host's narrow fallback (the sheet)\n * reads it (`columnRoom`, with a `no-column-room` note when not). Anchors and rails don't count: every column, an anchor\n * included, can fold into its rail. A side toolbar bar with an item does: it never folds.\n * With no column edge yet (every panel floating), a side's column template says how narrow its column could be: its\n * `cross.min`, or more where the items it takes need more (their form's least width), as a column holding them would.\n * The question is hypothetical (could one column open?), so it is answered as if that column were open: a column\n * folded whole by hand counts at its open minimum, and the floating items a template takes at their open forms.\n * Every column edge with an item counts, whether its side has a rail or not.\n */\nexport function columnRoom(d: Draft, cols: readonly Col[], area: Rect, f: Frame): void {\n const { scene } = d;\n const cmin = scene.contentMin ? px(scene.contentMin.width) : undefined;\n const openMin = (ids: readonly string[], least: number): number =>\n Math.max(\n least,\n ...ids.map((id) => {\n const form = formsOf(scene.items[id]!, \"column\")[0];\n return form && formSetsCross(form) ? formCrossMin(form) : 0;\n }),\n );\n const open = cols.filter((c) => c.edge.column === true && c.visible.length > 0).map((c) => (c.hand ? openMin(c.visible, px(c.edge.cross.min)) : c.min));\n const templates = ([\"left\", \"right\"] as const).flatMap((s) => {\n const t = scene.columns?.[s];\n if (!t) return [];\n const takes = Object.values(scene.items).filter((it) => !it.fixed && !it.closed && t.accepts.includes(it.kind));\n return [openMin(takes.map((it) => it.id), px(t.cross.min))];\n });\n const colMins = open.length > 0 ? open : templates;\n if (cmin === undefined || colMins.length === 0) return;\n // A side toolbar bar never folds: one that lays out an item takes its width (and the gutter after it, unless it\n // lies outside the inset, which the area already leaves out) from the room a column could have.\n const bars = cols.filter((c) => c.width > 0 && !c.dyn && isSideBar(scene, c.edge)).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : f.gutter), 0);\n // With `insetWhen: \"docked\"` and nothing docked now, the column that opens brings the inset with it.\n const width = area.width - bars - (scene.insetWhen === \"docked\" && !f.docked ? px(scene.inset?.left) + px(scene.inset?.right) : 0);\n const need = cmin + Math.min(...colMins) + f.gutter;\n d.columnRoom = width >= need - EPS;\n if (!d.columnRoom) d.notes.push({ code: \"no-column-room\", width, need });\n}\n\n/**\n * The give-way notes: each column shrunk, then each folded, in the order they folded (`previous` unfolds in reverse). A\n * column whose items are all closed keeps its notes from `previous`, at their place in that order: a closed item is not\n * a removed one, and its column's give-way applies again when it opens.\n */\nexport function giveWayNotes(d: Draft, g: GiveWay, cols: readonly Col[]): void {\n const { scene, previous } = d;\n const dormant = new Set(cols.filter((c) => c.visible.length === 0 && (c.edge.column === true || c.edge.giveWay === true) && scene.rails?.[c.side] !== undefined).map((c) => c.edge.id));\n const before = previous?.notes ?? [];\n const shrunk = new Map<string, SceneNote>();\n for (const c of g.shrinkOrder) {\n const w = g.widths.get(c);\n if (w !== undefined && w < c.width - EPS) shrunk.set(c.edge.id, { code: \"column-shrunk\", edge: c.edge.id, from: c.width, to: w });\n }\n const folded = new Map<string, SceneNote>([...g.auto].map((c) => [c.edge.id, { code: c.kept ? \"kept-folded\" : \"column-folded\", edge: c.edge.id }]));\n // Kept notes go where they were in `previous`'s order; the others after them, in their own order.\n const merge = (now: Map<string, SceneNote>, kept: (n: SceneNote) => boolean): void => {\n const order: SceneNote[] = [];\n for (const n of before) {\n const edge = kept(n) && \"edge\" in n ? n.edge : undefined;\n if (edge === undefined) continue;\n if (dormant.has(edge)) order.push(n);\n else if (now.has(edge)) {\n order.push(now.get(edge)!);\n now.delete(edge);\n }\n }\n d.notes.push(...order, ...now.values());\n };\n // A shrink is no history to keep: a column shrinks again by the usual order when it opens.\n d.notes.push(...shrunk.values());\n merge(folded, (n) => n.code === \"column-folded\" || n.code === \"kept-folded\");\n}\n","/**\n * Where folded columns go: the side's rail (each folded column's members as rail segments, in ring order) or, with\n * `handFold: \"ride\"`, title bars riding over the side's first open column.\n */\nimport { rect, type Rect } from \"../../geometry\";\nimport { fitStack, type StackFit, type StackForm, type StackInput } from \"../../stack\";\nimport { formsOf, railModeOf, startOf, zoneOf } from \"../helpers\";\nimport type { Col, GiveWay } from \"./columns\";\nimport type { Draft } from \"./draft\";\nimport { finite, px, zoneSorted } from \"./order\";\n\n/** A riding column's bars: each member's folded form, in zone order. */\nfunction riderBars(d: Draft, c: Col): { id: string; form: number; f: StackForm | undefined; h: number }[] {\n const { scene } = d;\n return zoneSorted(scene, c.visible).map((id) => {\n const forms = formsOf(scene.items[id]!, \"column\");\n const form = forms.length === 0 ? 0 : startOf(scene.items[id]!, forms);\n return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };\n });\n}\n\n/** How tall the riders' bars are together: the room the host column leaves them on top. */\nexport const ridersHeight = (d: Draft, riders: readonly Col[]): number => riders.reduce((s, c) => s + riderBars(d, c).reduce((t, b) => t + b.h, 0), 0);\n\n/** Lays the riders' bars over the host column `host` (laid already), from `top` down. */\nexport function layRiders(d: Draft, host: Col, riders: readonly Col[], top: number): void {\n const { scene, items, edges } = d;\n const hr = edges[host.edge.id]!.rect;\n let y = top;\n for (const c of riders) {\n const bars = riderBars(d, c);\n const y0 = y;\n for (const b of bars) {\n const at = rect(hr.x, y, hr.width, b.h);\n const it = scene.items[b.id]!;\n items[b.id] = { rect: at, hidden: b.f?.hides ?? [], kind: it.kind, form: b.form, formKind: b.f?.kind ?? \"header\", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: \"hand\", foldedBy: \"hand\" };\n y += b.h;\n }\n edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, items: bars.map((b) => b.id), tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: \"hand\" };\n }\n}\n\n/** Lays the side's rail at `railRect`: each railed column's members as segments, in zone order, ring by ring. */\nexport function layRail(d: Draft, side: \"left\" | \"right\", railRect: Rect, railed: readonly Col[], g: GiveWay): void {\n const { scene, items } = d;\n const segments: { id: string; edge: string; rect: Rect }[] = [];\n // In zone order, as each column itself shows them (start, center, end), ring by ring.\n const members = railed.flatMap((c) => zoneSorted(scene, c.visible).map((id) => ({ id, c })));\n const formsById = (id: string): readonly StackForm[] => formsOf(scene.items[id]!, \"column\");\n // An item's tile: its rail form that isn't a title (`StackForm.title`); its title, the rail form just before it.\n const tileOf = (id: string): number => formsById(id).findIndex((f) => f.kind === \"rail\" && f.title !== true);\n const titleOf = (id: string): number => {\n const t = tileOf(id);\n return t > 0 && formsById(id)[t - 1]!.kind === \"rail\" && formsById(id)[t - 1]!.title === true ? t - 1 : -1;\n };\n // With titles shown and offered, the segments are a stack along the rail: title then tile, by the ladder, and back in\n // exact reverse (`stack` carries the history). Every member needs a tile for that; otherwise each takes its tile.\n const titles = railModeOf(scene, side) === \"titles\" && members.some((m) => titleOf(m.id) >= 0) && members.every((m) => tileOf(m.id) >= 0);\n let fit: StackFit | undefined;\n if (titles) {\n const input: StackInput = {\n axis: \"column\",\n length: railRect.height,\n cross: { min: railRect.width, max: railRect.width, rail: railRect.width },\n titles: true,\n items: members.map(({ id }) => {\n const it = scene.items[id]!;\n const p = finite(it.priority ?? 0, 0);\n // Its rail forms only (no » menu in a rail strip); its priority adds to their ranks.\n const forms = formsById(id).slice(0, tileOf(id) + 1).map((f) => (p === 0 ? f : { ...f, rank: finite(f.rank ?? 0, 0) + p }));\n return { id, forms, used: finite(it.used, 0), ...(it.kept ? { kept: true } : {}), from: titleOf(id) >= 0 ? titleOf(id) : tileOf(id) };\n }),\n };\n // Solved afresh when a member or its column is `fresh`.\n const fresh = members.some((m) => d.fresh.has(m.id) || d.fresh.has(m.c.edge.id));\n const previous = d.previous && !fresh ? d.previous.rails[side]?.stack : undefined;\n fit = fitStack(input, previous ? { previous } : {});\n }\n const placed = new Map(fit?.items.map((p) => [p.id, p]) ?? []);\n let y = railRect.y;\n for (const { id, c } of members) {\n const it = scene.items[id]!;\n const forms = formsById(id);\n const ri = tileOf(id);\n const p = placed.get(id);\n const form = p ? p.form : ri >= 0 ? ri : forms.length === 0 ? 0 : startOf(it, forms);\n const at = p ? rect(railRect.x, railRect.y + p.rect.y, railRect.width, p.rect.height) : rect(railRect.x, y, railRect.width, ri >= 0 ? px(forms[ri]!.main.natural) : railRect.width);\n const title = forms[form]?.title === true;\n items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: \"rail\", edge: c.edge.id, zone: zoneOf(it), rail: side, ...(title ? { railTitle: side } : {}), folded: g.auto.has(c) ? \"auto\" : \"hand\", foldedBy: startOf(it, forms) > 0 ? \"hand\" : \"auto\" };\n segments.push({ id, edge: c.edge.id, rect: at });\n y += at.height;\n }\n d.rails[side] = { rect: railRect, segments, ...(fit ? { stack: fit } : {}) };\n}\n","/**\n * The reserved left and right edges, ring by ring, with column give-way (`./columns`). From the window's side inward:\n * the side's bars outside the inset (toolbar bars, `isOutsideSideBar`), the side's rail, the static column edges outside\n * the inset (anchors), the inset, then the columns, a gutter after each. Folded columns go to the rail or ride\n * (`./rails`).\n */\nimport { EPS, rect, type Rect } from \"../../geometry\";\nimport { isOutsideSideBar } from \"../helpers\";\nimport type { Edge } from \"../model\";\nimport { columnRoom, columnsOf, giveWay, giveWayNotes, type Col, type GiveWay } from \"./columns\";\nimport { emit, type Draft } from \"./draft\";\nimport { solveEdge, type EdgeSolve } from \"./edge\";\nimport { insetReach, type Frame } from \"./insets\";\nimport { finite, px, zoneSorted } from \"./order\";\nimport { layRail, layRiders, ridersHeight } from \"./rails\";\n\n/** The side phase's running state across one side: the content's left and right so far, and the gap before the next edge. */\ninterface Walk {\n x0: number;\n x1: number;\n}\n\n/** The side edges laid in `area`; returns the area they leave. */\nexport function laySides(d: Draft, sideEdges: readonly Edge[], area: Rect, f: Frame): Rect {\n const H = area.height;\n const reach = insetReach(area, f);\n const tall = (edge: Edge): number => H + (edge.outsideInset === true ? reach.up + reach.down : 0);\n const cols = columnsOf(d, sideEdges, area, tall);\n const g = giveWay(d, cols, area, f.gutter);\n columnRoom(d, cols, area, f);\n giveWayNotes(d, g, cols);\n const walk: Walk = { x0: area.x, x1: area.x + area.width };\n for (const side of [\"left\", \"right\"] as const) laySide(d, side, cols, g, area, f, walk, reach.up, tall);\n return rect(walk.x0, area.y, Math.max(0, walk.x1 - walk.x0), H);\n}\n\n/** `c`'s edge re-solved at width `w` and length `length` (its user's size dropped). */\nfunction forced(d: Draft, c: Col, length: number, w: number): EdgeSolve {\n const edge: Edge = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };\n const { size: _s, ...plain } = edge;\n return solveEdge(d.scene, plain, d.owned.get(c.edge)!, length, w, d.prevEdge(c.edge));\n}\n\n/** One side, from the window's side inward: its outside bars, its rail, its anchors, the inset, its columns. */\nfunction laySide(d: Draft, side: \"left\" | \"right\", cols: readonly Col[], g: GiveWay, area: Rect, f: Frame, walk: Walk, upInset: number, tall: (edge: Edge) => number): void {\n const { scene, edges } = d;\n const H = area.height;\n // Only while it lays out an item: an empty (or all closed) bar draws as nothing, so it changes no order either.\n const outsideSideBar = (c: Col): boolean => c.width > 0 && isOutsideSideBar(scene, c.edge) && !g.railed(c) && !g.riding(c);\n const all = cols.filter((c) => c.side === side);\n const mine = [...all.filter(outsideSideBar), ...all.filter((c) => !outsideSideBar(c))];\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.edge.column === true && !c.hand && !g.auto.has(c) && c.width > 0);\n const ridersTop = ridersHeight(d, riders);\n const railW = px(scene.rails?.[side]?.width);\n let railRect: Rect | null = null;\n // The gap just outside the next edge: the inset at the window's side, then a gutter. An edge outside the inset\n // (an anchor) lies before that gap, which then follows it.\n let gap = px(side === \"left\" ? f.inset.left : f.inset.right);\n /** Whether one of the side's outside bars is laid already (the rail then lies flush after it). */\n let barLaid = false;\n /** Where the side's rail lies, or would lie were one shown (`railPlaces`). */\n let railPlace: Rect | null = null;\n const placeRail = (): Rect => {\n const lead = barLaid ? gap : 0;\n return side === \"left\" ? rect(walk.x0 - lead, area.y, railW, H) : rect(walk.x1 + lead - railW, area.y, railW, H);\n };\n for (const c of mine) {\n // The side's rail is its outermost panel edge; an anchor lies flush inside it. After the side's outside bars it\n // lies outside the inset too, flush after them, the inset (at least a gutter) then following it and the anchor.\n // With no such bar it lies at the window's side inside the inset, a gutter after it (the hosts' rows).\n if (!railPlace && !outsideSideBar(c)) {\n railPlace = placeRail();\n if (railed.length > 0) {\n railRect = railPlace;\n const lead = barLaid ? gap : 0;\n const after = barLaid ? Math.max(gap, f.gutter) : f.gutter;\n if (side === \"left\") walk.x0 += railPlace.width - lead + after;\n else walk.x1 -= railPlace.width - lead + after;\n gap = after;\n }\n }\n if (outsideSideBar(c)) barLaid = true;\n // A folded column's members are drawn as rail segments, in zone order (`layRail`).\n const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, items: zoneSorted(scene, c.visible), 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, walk.x1 - walk.x0));\n const top = c === host ? ridersTop : 0;\n let solved = top > 0 || Math.abs(w - c.width) > EPS ? forced(d, c, H - top, w) : c.solved;\n let r: Rect;\n if (c.edge.outsideInset === true) {\n // Outside the inset: at the stage's side, full height; the inset (not a gutter) follows it.\n const y0 = area.y - upInset;\n const h = tall(c.edge);\n if (side === \"left\") {\n r = rect(walk.x0 - gap, y0, w, h);\n walk.x0 += w;\n } else {\n r = rect(walk.x1 + gap - w, y0, w, h);\n walk.x1 -= w;\n }\n if (Math.abs(h - H) > EPS || Math.abs(w - c.width) > EPS) solved = forced(d, c, h, w);\n } else if (side === \"left\") {\n r = rect(walk.x0, area.y + top, w, H - top);\n walk.x0 += w > 0 ? w + f.gutter : 0;\n if (w > 0) gap = f.gutter;\n } else {\n walk.x1 -= w;\n r = rect(walk.x1, area.y + top, w, H - top);\n walk.x1 -= w > 0 ? f.gutter : 0;\n if (w > 0) gap = f.gutter;\n }\n emit(d, c.edge, r, solved, w < c.width - EPS ? { shrunk: true } : {});\n }\n if (host && riders.length > 0) layRiders(d, host, riders, area.y);\n if (railRect) layRail(d, side, railRect, railed, g);\n // A side that can have a rail: where it lies, or would lie (after every outside bar when the side has nothing else).\n if (scene.rails?.[side]) d.railPlaces[side] = railPlace ?? placeRail();\n}\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; an overlay bar\n * with `span: \"full\"` set by name runs across the full bars' width, over the columns too, at the content's top or\n * bottom.\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 centered 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, and\n * keeps clear of every float with a rect of its own and of the anchored floats floated before it (`since`, then id)\n * too, where room exists; the stacking order plays no part, so `raise` reshapes nothing. 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 * 7. **Bars by height** (`Edge.giveWay` on a top or bottom bar): while the content is shorter than `contentMin.height`\n * (overlay bars counted), those bars shrink across toward their minimum, then fold one by one to their items' next\n * form that fits across; the scene is laid out again under the caps this gives each bar (`barGiveWay`).\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 *\n * The phases live in `./solve/`: `order` (the laying order), `edge` (one edge's stack), `draft` (drawing an edge),\n * `bars`, `bar-giveway` (bars by height), `insets`, `sides`, `columns` (give-way), `rails` (folded columns), `floats`\n * and `notes`.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport { viewOf } from \"./helpers\";\nimport { checkEdgeIds } from \"./targets/ids\";\nimport type { Scene, SceneLayout, SceneNote, SolveOptions } from \"./model\";\nimport { barGiveWay } from \"./solve/bar-giveway\";\nimport { cutEdge } from \"./solve/bars\";\nimport { createDraft } from \"./solve/draft\";\nimport { layFloats } from \"./solve/floats\";\nimport { insetOf, insideInset } from \"./solve/insets\";\nimport { contentNotes } from \"./solve/notes\";\nimport { finite, isSide, px } from \"./solve/order\";\nimport { laySides } from \"./solve/sides\";\n\nexport { layKeys, pushes, type LayKey } from \"./solve/order\";\n\nexport function solve(given: Scene, options: SolveOptions = {}): SceneLayout {\n checkEdgeIds(given);\n // A hidden edge is not part of the window: the layout is the shown scene's, its items placed nowhere, or in the edge\n // its `showIn` names.\n const { view: shown, ignored } = viewOf(given);\n const lay = (caps: ReadonlyMap<string, number>, gave: readonly SceneNote[] = []): SceneLayout => layOut(shown, options, caps, gave);\n const first = lay(new Map());\n const way = barGiveWay(shown, first, lay);\n const l = way ? lay(way.caps, way.notes) : first;\n return ignored.length === 0 ? l : { ...l, notes: [...l.notes, ...ignored.map((edge): SceneNote => ({ code: \"show-in-ignored\", edge }))] };\n}\n\n/** `area`'s top and height on `over`'s left and width. */\nconst withHeightOf = (area: Rect, over: Rect): Rect => rect(over.x, area.y, over.width, area.height);\n\n/** One pass of the layout under height give-way's `caps`, its notes (`gave`) before the content's. */\nfunction layOut(given: Scene, options: SolveOptions, caps: ReadonlyMap<string, number>, gave: readonly SceneNote[]): SceneLayout {\n const d = createDraft(given, options, caps);\n const { scene, order } = d;\n const stage = rect(finite(scene.stage.x, 0), finite(scene.stage.y, 0), px(scene.stage.width), px(scene.stage.height));\n const { inset, docked } = insetOf(d);\n const reserved = order.filter((e) => e.mode !== \"overlay\");\n // A full top or bottom bar outside the inset lies at the window's edge, full width; the inset follows it.\n const outsideBar = (e: (typeof order)[number]): boolean => !isSide(e) && e.span !== \"between\" && e.outsideInset === true;\n let outer = stage;\n for (const e of reserved) if (outsideBar(e)) outer = cutEdge(d, e, outer, true);\n let area = insideInset(outer, inset);\n for (const e of reserved) if (!isSide(e) && e.span !== \"between\" && !outsideBar(e)) area = cutEdge(d, e, area, true);\n // The width the full bars run across, before the columns: an overlay bar with `span: \"full\"` lies over the columns too.\n const wide = area;\n area = laySides(d, reserved.filter(isSide), area, { inset, gutter: px(scene.gutter), docked, outer });\n for (const e of reserved) if (!isSide(e) && e.span === \"between\") area = cutEdge(d, e, area, true);\n const content = area;\n let over = content;\n for (const e of order) {\n if (e.mode !== \"overlay\") continue;\n // An overlay bar lies over the content unless it asks for the full width by name: one with no `span` keeps the\n // content's width, as it always has.\n if (isSide(e) || e.span !== \"full\") over = cutEdge(d, e, over, true);\n // `span: \"full\"`: across the full bars' width (the window's, with `outsideInset`), over the content's height left so\n // far.\n else {\n const across = e.outsideInset === true ? outer : wide;\n over = withHeightOf(cutEdge(d, e, rect(across.x, over.y, across.width, over.height), true), over);\n }\n }\n for (const n of gave) {\n d.notes.push(n);\n if (n.code === \"bar-shrunk\" && d.edges[n.edge]) d.edges[n.edge] = { ...d.edges[n.edge]!, shrunk: true };\n }\n contentNotes(d, content);\n const floats = layFloats(d, stage, content, inset);\n const { items, edges, rails, railPlaces, columnRoom, notes } = d;\n return { items, edges, content, floats, rails, railPlaces, ...(columnRoom !== undefined ? { columnRoom } : {}), notes };\n}\n","/**\n * `fitResize(scene, id, rect, moving)`: the rect a float takes when the user drags some of its edges, clamped in one\n * pass (no iteration) and with the limits that bound it. Hosts call it on every pointer move for the preview; the\n * scene change `resize(scene, id, rect, moving)` commits the same rect, so the preview is the commit.\n *\n * It is not `fitFloat`: that one moves a float (never resizes it) to a clear place; this one resizes it with the edges\n * not dragged kept put, and stops a dragged edge before anything `fitFloat` would move it off, so `solve` lays the\n * result exactly where it is asked.\n */\nimport type { Rect } from \"../geometry\";\nimport { axisOf, chromeFor, floatOrientOf, floatShape, formsOf, isDockingPanel } from \"./helpers\";\nimport type { Scene, SceneLayout } from \"./model\";\nimport { solve } from \"./solve\";\nimport { floatFloor, placeFloat } from \"./solve/floats\";\n\n/** The edges of a float a resize drags; the others stay put. Left beats right, top beats bottom, when both are set. */\nexport interface ResizeEdges {\n readonly left?: boolean;\n readonly right?: boolean;\n readonly top?: boolean;\n readonly bottom?: boolean;\n}\n\n/**\n * Why a resized float isn't the rect asked for: `\"min\"` its least size (`floatMin`, else its open form's minimums),\n * `\"max\"` its `floatMax`, `\"region\"` the region floats lie in (the stage less the inset at its left and right, its full\n * height), `\"docked\"` what floats are kept clear of (a bar, a docked item, the chrome).\n */\nexport type ResizeLimit = \"min\" | \"max\" | \"region\" | \"docked\";\n\nexport interface FloatResize {\n /** The float's rect: what `resize` stores and `solve` draws. */\n readonly rect: Rect;\n /** The limits that bound it, in this order: min, max, region, docked. Empty when it is the rect asked for. */\n readonly limits: readonly ResizeLimit[];\n}\n\nconst LIMITS: readonly ResizeLimit[] = [\"min\", \"max\", \"region\", \"docked\"];\nconst EPS = 0.5;\n/** How far `fitFloat` reads two rects as touching rather than overlapping (its own tolerance). */\nconst TOUCH = 1e-3;\nconst fin = (v: number | undefined, d: number): number => (Number.isFinite(v) ? v! : d);\nconst nonNeg = (v: number | undefined): number => Math.max(0, fin(v, 0));\n\n/**\n * The region floats lie in, as `solve` lays them: the stage less the inset at its left and right (none with\n * `insetWhen: \"docked\"` while no panel is docked beside the content), the stage's full height.\n */\nfunction floatRegion(scene: Scene): Rect {\n const floating = new Set(scene.floats.map((f) => f.id));\n const docked = scene.edges.some((e) => (e.side === \"left\" || e.side === \"right\") && e.accepts.length > 0 && e.items.some((id) => !floating.has(id) && !!scene.items[id] && isDockingPanel(scene.items[id]!)));\n const inset = scene.insetWhen === \"docked\" && !docked ? {} : (scene.inset ?? {});\n const { stage } = scene;\n return { x: stage.x + nonNeg(inset.left), y: stage.y, width: Math.max(0, stage.width - nonNeg(inset.left) - nonNeg(inset.right)), height: stage.height };\n}\n\n/** What `solve` keeps floats clear of, as laid out now: docked items (» entries included), bars and their » menus, the chrome. */\nfunction floatObstacles(scene: Scene, l: SceneLayout, id: string): Rect[] {\n const out: Rect[] = [];\n for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);\n for (const e of Object.values(l.edges)) {\n if (axisOf(e.side) === \"row\" && e.cross > 0) out.push(e.rect);\n if (e.menu) out.push(e.menu.rect);\n }\n for (const c of chromeFor(scene, \"floats\")) out.push(c);\n return out.filter((r) => r.width > 0 && r.height > 0);\n}\n\n/**\n * Where the dragged edge of `drawn` along `axis` stops: the nearest obstacle beyond it on that side that lies across\n * `span` (the float's extent on the other axis). An obstacle the float already overlaps (it covers the edge: no clear\n * place existed at the float's size) keeps the edge where it is drawn: growing would cover it more.\n */\nfunction obstacleStop(drawn: Rect | undefined, obstacles: readonly Rect[], axis: \"x\" | \"y\", drag: \"start\" | \"end\" | null, span: readonly [number, number]): number {\n const none = drag === \"start\" ? -Infinity : Infinity;\n if (!drawn || !drag) return none;\n const lo = (r: Rect): number => (axis === \"x\" ? r.x : r.y);\n const len = (r: Rect): number => (axis === \"x\" ? r.width : r.height);\n const across = (r: Rect): [number, number] => (axis === \"x\" ? [r.y, r.y + r.height] : [r.x, r.x + r.width]);\n let at = none;\n for (const o of obstacles) {\n const [c0, c1] = across(o);\n // Across, as tight as `fitFloat` tells touching from covering: an obstacle a fraction of a px across it still stops it.\n if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;\n const begin = lo(o);\n const finish = begin + len(o);\n const edge = drag === \"start\" ? lo(drawn) : lo(drawn) + len(drawn);\n if (drag === \"start\") {\n if (finish <= edge + EPS) at = Math.max(at, finish);\n // Straddling the edge: the float already covers it (no clear place at its size), and growing past the edge would\n // cover it more, so the edge stays where it is drawn.\n else if (begin < edge - TOUCH) at = edge;\n } else {\n if (begin >= edge - EPS) at = Math.min(at, begin);\n else if (finish > edge + TOUCH) at = edge;\n }\n }\n // It stops growth only: never inside where the edge is drawn now (an obstacle it touches within a fraction of a px).\n return drag === \"start\" ? Math.min(at, lo(drawn)) : Math.max(at, lo(drawn) + len(drawn));\n}\n\n/** One axis: `[start, length]` asked; the bounds; which edge is dragged. The limits that bind go into `hit`. */\nfunction fitAxis(start: number, length: number, b: { min: number; max: number; lo: number; hi: number; stop: number }, drag: \"start\" | \"end\" | null, hit: Set<ResizeLimit>): [number, number] {\n const { min, lo, hi, stop } = b;\n const max = Math.max(min, b.max);\n const raw = fin(length, min);\n // A floor larger than the region: the floor, at the region's start (as `solve` lays it).\n if (min >= hi - lo) {\n hit.add(\"region\");\n return [lo, min];\n }\n // The bound a dragged edge reaches first, with every limit that sits there.\n const bind = (cands: [number, ResizeLimit][], pick: (a: number, b: number) => number): [number, ResizeLimit[]] => {\n const at = cands.reduce((m, [v]) => pick(m, v), cands[0]![0]);\n return [at, cands.filter(([v]) => Math.abs(v - at) <= EPS).map(([, k]) => k)];\n };\n if (drag === \"start\") {\n // The end is kept (moved into the region only when it lies outside it).\n const asked = fin(start, lo) + raw;\n const end = Math.min(hi, Math.max(lo + min, asked));\n if (Math.abs(end - asked) > EPS) hit.add(\"region\");\n const [down, why] = bind([[end - max, \"max\"], [lo, \"region\"], [stop, \"docked\"]], Math.max);\n let from = end - raw;\n if (from > end - min) {\n from = end - min;\n hit.add(\"min\");\n } else if (from < down - TOUCH) {\n // What floats are kept clear of beats the minimum (`solve` keeps a float asked smaller at its size).\n from = why.includes(\"docked\") ? Math.min(down, end) : Math.min(down, end - min);\n for (const k of from === down ? why : ([\"min\"] as ResizeLimit[])) hit.add(k);\n }\n return [from, end - from];\n }\n // The start is kept (moved into the region only when it lies outside it); an axis not dragged keeps its start too.\n const asked = fin(start, lo);\n const a = Math.max(lo, Math.min(hi - min, asked));\n if (Math.abs(a - asked) > EPS) hit.add(\"region\");\n const [up, why] = bind([[a + max, \"max\"], [hi, \"region\"], [stop, \"docked\"]], Math.min);\n let to = a + raw;\n if (to < a + min) {\n to = a + min;\n hit.add(\"min\");\n } else if (to > up + TOUCH) {\n to = why.includes(\"docked\") ? Math.max(up, a) : Math.max(up, a + min);\n for (const k of to === up ? why : ([\"min\"] as ResizeLimit[])) hit.add(k);\n }\n return [a, to - a];\n}\n\n/**\n * The rect float `id` takes for a resize: `rect` is the rect asked for in stage px (the float as drawn, with the\n * `moving` edges where the pointer put them). In one pass: the edges not moving stay put; the size is at least the\n * item's `floatMin` (else its open form's minimums, which only stop a shrink below the size drawn now, as `solve` lays\n * it) and at most its `floatMax`; the float stays in the region floats lie in; every growing edge (a moving one, or the\n * end of an axis not moving) stops at what floats are kept clear of, as drawn now (across first, over its height now;\n * then along, over its new width), and such a stop beats the minimum. The rect is then laid by the one clamp `solve`\n * lays floats with, so `solve(resize(...))` draws exactly this rect. A float that already covers something (no clear\n * place at its size) may move to a clear place once a resize opens one; the preview is still the commit, and\n * `\"docked\"` says so. Such a float never grows over what it covers: a dragged edge that lies inside an obstacle stays\n * where it is drawn (`\"docked\"`), so a resize never covers more than the float did. `limits` says which of these bound it.\n *\n * Null for anything but a float drawn at its first form when that form grows (a panel's card): a toolbar group's size\n * comes from its forms, and so does a folded float's bar. Pure: it solves the scene once, for what is drawn now.\n */\nexport function fitResize(scene: Scene, id: string, rect: Rect, moving: ResizeEdges): FloatResize | null {\n const f = scene.floats.find((x) => x.id === id);\n const item = Object.hasOwn(scene.items, id) ? scene.items[id] : undefined;\n if (!f || !item || item.fixed) return null;\n const fo = f.orient ?? floatOrientOf(item);\n const form = formsOf(item, fo)[0];\n if (floatShape(item, f).form !== 0 || (form && !form.main.grows)) return null;\n const l = solve(scene);\n const drawn = l.items[id]?.rect;\n if (!drawn) return null;\n // `solve`'s floor: `floatMin` as given, else the form's minimums, which only stop a shrink below the size drawn now.\n const min = floatFloor(item, form, fo, drawn);\n const max = { width: fin(item.floatMax?.width, Infinity), height: fin(item.floatMax?.height, Infinity) };\n const region = floatRegion(scene);\n const dragX = moving.left ? \"start\" : moving.right ? \"end\" : null;\n const dragY = moving.top ? \"start\" : moving.bottom ? \"end\" : null;\n const obstacles = floatObstacles(scene, l, id);\n const hit = new Set<ResizeLimit>();\n // Every growing edge stops at what floats are kept clear of: a dragged one, and the end of an axis not dragged.\n const [x, width] = fitAxis(rect.x, rect.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, obstacles, \"x\", dragX ?? \"end\", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);\n const [y, height] = fitAxis(rect.y, rect.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, obstacles, \"y\", dragY ?? \"end\", [x, x + width]) }, dragY, hit);\n // The one clamp `solve` lays floats with: what it gives is what the commit draws.\n const { anchor: _a, ...plain } = f;\n const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, scene.stage).fit.rect;\n if (Math.abs(placed.x - x) > EPS || Math.abs(placed.y - y) > EPS) hit.add(\"docked\");\n if (Math.abs(placed.width - width) > EPS || Math.abs(placed.height - height) > EPS) hit.add(\"min\");\n return { rect: placed, limits: LIMITS.filter((k) => hit.has(k)) };\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. A zone named becomes the item's `align`\n * where the edge offers a choice (`namesZone`: more than one zone takes the kind); on a one-zone edge, or with none\n * named, the item keeps its own and docks in the zone it lies in there (`zoneIn`: its own where the edge takes it\n * there, else the first that does). A new column, a rail and `dockHome` name none either: the item's zone is its own.\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 (on a side with no declared rail, `Scene.rails`, its rail is its outermost column that takes the\n * kind, \"the column drawn as a rail\": the item docks at the end of its start zone as a collapsed header, folded by\n * hand, a rail tile once nothing there sets the width); `{ 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 `floatSizeOf` size anchored to the content's top-right corner: its `floatSize`, else its form's natural size\n * along its orient (the float's, `orient`, else `floatOrientOf`), else the default size.\n * - `fold(scene, id, on)`: folded by hand (`from: 1`) draws it in its folded form on the axis it lies along (a panel's\n * `header`, a group's `fold`), and give-way steps down from there; unfolding clears `from`. Where it has no folded\n * form (`canFold` false), folding changes nothing.\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 * `resize(scene, id, rect, moving?)`: a float resized by hand, at `fitResize`'s rect (./float-resize).\n */\nimport { clampInto, type Rect } from \"../geometry\";\nimport { fitResize, type ResizeEdges } from \"./float-resize\";\nimport { axesOf, axisOf, columnFromTemplate, floatOrientOf, placingOf, floatShape, floatSizeOf, foldedIndex, formsOf, isHandFolded, isSince, namesZone, railColumnOf, railModeOf, zoneIn, zoneTakes } from \"./helpers\";\nimport { RAIL_MODES, type Edge, type FloatAnchorAt, type Orient, type RailMode, type Scene, type SceneFloat, type SceneItem, type Side, 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), at an anchor's name or `{ at, dx?, dy? }`. */\n readonly anchor?: FloatAnchorAt;\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/**\n * A new column edge from the side's template, or null when the side has none or it doesn't take the kind. Its id is\n * chosen against the scene's edges and `others`: edges kept out of `scene` (its hidden ones, when `scene` is what the\n * window shows), so it never repeats an id the stored scene has.\n */\nfunction newColumn(scene: Scene, side: \"left\" | \"right\", kind: string, ring: number, items: readonly string[], others: readonly Edge[]): Edge | null {\n const t = scene.columns?.[side];\n if (!t || !t.accepts.includes(kind)) return null;\n const taken = new Set([...scene.edges, ...others].map((e) => e.id));\n let n = 0;\n while (taken.has(`${side}-${n}`)) n++;\n return columnFromTemplate(t, `${side}-${n}`, side, ring, items);\n}\n\n/**\n * The rings of a side's edges as they lie, outer first, 0 up with no ties (by ring, then by their order in the scene):\n * the numbers column and rail places count in.\n */\nexport function sideRings(edges: readonly Edge[], side: string): Map<string, number> {\n return new Map(closeRings(edges, new Set([side])).filter((e) => e.side === side).map((e) => [e.id, e.ring]));\n}\n\n/** The first ring a new column may take on `side`: inside every static edge outer to the side's dynamic columns. */\nfunction columnFloor(edges: readonly Edge[], side: string): number {\n const mine = edges.filter((e) => e.side === side).sort((a, b) => a.ring - b.ring);\n let n = 0;\n while (n < mine.length && mine[n]!.column !== true) n++;\n // With no dynamic column, every static edge on the side is outer to the new one.\n return n;\n}\n\n/**\n * `scene` with a new column holding `id` at `ring` on `side` (already lifted out). The side's rings are made distinct\n * first; static edges keep their place, so a new column goes no further out than just inside the static edges outer to\n * the side's dynamic columns (a bar or an anchor at the window edge stays there).\n */\nfunction insertColumn(scene0: Scene, id: string, side: \"left\" | \"right\", ring: number, others: readonly Edge[]): Scene | null {\n const scene: Scene = { ...scene0, edges: closeRings(scene0.edges, new Set([side])) };\n const kind = scene.items[id]!.kind;\n const mine = scene.edges.filter((e) => e.side === side);\n const floor = columnFloor(scene.edges, side);\n const r = Math.max(floor, 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], others);\n if (!col) return null;\n // A kind never opens a column on its own unless the column's start zone takes it (a group never opens a panel column\n // whose tray is its end zone).\n if (!zoneTakes(col, \"start\", kind)) return null;\n // The item keeps its own zone (`align`): it lies in it where the new column takes it there, else in the first zone\n // that does (`zoneIn`), as in any edge.\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 zone item `id` lies in on `edge` (`zoneIn`); its own when it is unknown. */\nconst zoneAt = (scene: Scene, edge: Edge, id: string): Zone => {\n const it = itemOf(scene, id);\n return it ? zoneIn(edge, it) : \"start\";\n};\n\n/** The index in `edge.items` where the `at`-th item of `zone` is (or where the zone ends), by the zones items lie in. */\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) => zoneAt(scene, edge, 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[zoneAt(scene, edge, id)] < rank[zone]) idx = i + 1;\n });\n return idx;\n}\n\nexport function moveTo(scene: Scene, id: string, place: Place): Scene {\n return moveAmong(scene, id, place, []);\n}\n\n/**\n * `moveTo`, with `others`: edges kept out of `scene` that a new column's id must not repeat. A drop's result is made on\n * the scene the window shows (its hidden edges left out), and its hidden edges are passed here.\n */\nexport function moveAmong(scene: Scene, id: string, place: Place, others: readonly Edge[]): 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 // A side with no declared rail: its rail is its outermost column that takes the kind (`railColumnOf`), the item docked\n // at the end of the zone it lies in there (its own where the column takes it there, else the first), folded by hand.\n // The rail names no zone: the item keeps its own.\n const railColumn = place.kind === \"rail\" ? railColumnOf(scene, place.side, item.kind) : undefined;\n if (railColumn) {\n const docked = moveAmong(scene, id, { edge: railColumn.id, at: Infinity }, others);\n return docked === scene ? scene : withItem(docked, { ...docked.items[id]!, from: Math.max(1, item.from ?? 0) });\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 // Its zone goes with it: `insertColumn` keeps it where the new column takes the kind there.\n const folded: SceneItem = place.kind === \"rail\" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;\n const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring, others);\n return made ?? scene;\n }\n const edge = scene.edges.find((e) => e.id === place.edge);\n // A hidden edge takes nothing, as one that doesn't take the kind.\n if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return scene;\n // The zone asked for, else the one it lies in there (`zoneIn`: its own, or the first that takes its kind), must take\n // the kind (`zoneAccepts`). The item's zone is its own fact: a zone asked for becomes its `align` only where the edge\n // offers a choice (`namesZone`: more than one of its zones takes the kind). On a one-zone edge (a rail that takes the\n // kind at its start only) it docks in that zone and keeps its own.\n const zone = place.zone ?? zoneIn(edge, item);\n if (!zoneTakes(edge, zone, item.kind)) return scene;\n const { align: _drop, ...rest } = item;\n const moved: SceneItem = place.zone === undefined || !namesZone(edge, item.kind) ? item : 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\n/**\n * One more than the largest `since` among the scene's floats (a missing or unusable one counts as 0); 1 when there are\n * none. Never past `Number.MAX_SAFE_INTEGER`.\n */\nfunction nextSince(scene: Scene): number {\n const most = scene.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);\n return Math.min(most + 1, Number.MAX_SAFE_INTEGER);\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 = floatSizeOf(item, o ?? floatOrientOf(item));\n // A float moved keeps its `since`; one newly floated comes after every float there.\n const since = was ? was.since : nextSince(scene);\n const seq = since !== undefined ? { since } : {};\n const float: SceneFloat = at\n ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...(o ? { orient: o } : {}), ...seq }\n : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: \"content-top-right\", ...(o ? { orient: o } : {}), ...seq };\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\n/**\n * Whether a hand fold of `id` means anything where it lies now: it has a folded form (a panel's `header`, a group's\n * `fold`; a fixed item on a `foldable` edge, a thumbnail anchor, its `rail` tile) among the forms of the axis it lies\n * along (its edge's, its float's orient; either when it lies nowhere). Where it is false, `fold(on)` changes nothing: a\n * host leaves the grip's double-click off. An item folded by hand can always be unfolded.\n */\nexport function canFold(scene: Scene, id: string): boolean {\n const item = itemOf(scene, id);\n if (!item || (item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id)))) return false;\n // A lent item folds as it is drawn: along the edge it shows in (`placingOf`).\n const edge = placingOf(scene, id).edges.find((e) => e.items.includes(id));\n return axesOf(scene, id).some((a) => foldedIndex(item, formsOf(item, a), edge) >= 0);\n}\n\nexport function fold(scene: Scene, id: string, on: boolean): Scene {\n const item = itemOf(scene, id);\n // A fixed item folds only on an edge that allows it (`Edge.foldable`).\n if (!item || (item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id)))) return scene;\n // Folded by hand (`from: 1`): solve draws it in its folded form on the axis it lies along (`startOf`), never one\n // step down the ladder. With no folded form there, a hand fold is nothing.\n if (on) return isHandFolded(scene, id) || !canFold(scene, id) ? 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. */\nconst 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 const item = scene.items[id];\n if (i < 0 || !item || (scene.floats[i]!.orient ?? floatOrientOf(item)) === to) return scene;\n return { ...scene, floats: scene.floats.map((f, k) => (k === i ? { ...f, orient: to } : f)) };\n}\n\n/**\n * The user's size across an edge (`size` a number; one that isn't finite clears it). Or, with a rect, a float resized\n * by hand: the rect `fitResize(scene, floatId, rect, moving)` gives (default `moving`: right and bottom), so a host's\n * preview from `fitResize` is what this commits. The float keeps its stacking order and orient, loses its anchor, and\n * the size becomes the item's `floatSize` (stored with the scene). The scene given back where `fitResize` refuses (a\n * toolbar group, a folded float, anything not floating).\n */\nexport function resize(scene: Scene, edgeId: string, size: number): Scene;\nexport function resize(scene: Scene, floatId: string, rect: Rect, moving?: ResizeEdges): Scene;\nexport function resize(scene: Scene, id: string, size: number | Rect, moving: ResizeEdges = { right: true, bottom: true }): Scene {\n if (typeof size === \"number\") return resizeEdge(scene, id, size);\n const fit = fitResize(scene, id, size, moving);\n const i = scene.floats.findIndex((f) => f.id === id);\n const item = itemOf(scene, id);\n if (!fit || i < 0 || !item) return scene;\n const { anchor: _a, ...plain } = scene.floats[i]!;\n const float: SceneFloat = { ...plain, rect: fit.rect };\n return withItem({ ...scene, floats: scene.floats.map((g, k) => (k === i ? float : g)) }, { ...item, floatSize: { width: fit.rect.width, height: fit.rect.height } });\n}\n\nfunction resizeEdge(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 side's rails show their items as `mode` (`Scene.railModes`): their titles while they fit, or their tiles only.\n * Unchanged for a side other than left or right, an unknown mode, or the mode the side has already.\n */\nexport function setRailMode(scene: Scene, side: \"left\" | \"right\", mode: RailMode): Scene {\n if ((side !== \"left\" && side !== \"right\") || !RAIL_MODES.includes(mode) || railModeOf(scene, side) === mode) return scene;\n return { ...scene, railModes: { ...scene.railModes, [side]: mode } };\n}\n\n/**\n * The edge moved to the other side of its axis (left ⇄ right, top ⇄ bottom), as its side's outermost edge: ring 0, before\n * that side's other edges (whose rings close up behind it; the side it left closes up too). Its items, size and options\n * go with it. Unchanged for an unknown edge, the side it is on, or a side across its axis. Like every change it does not\n * tick the use clock: a host that moves an edge by hand calls `use()` on its items afterwards, as a drop does.\n */\nexport function setSide(scene: Scene, edgeId: string, side: Side): Scene {\n const edge = scene.edges.find((e) => e.id === edgeId);\n if (!edge || edge.side === side || axisOf(edge.side) !== axisOf(side)) return scene;\n const moved: Edge = { ...edge, side, ring: 0 };\n const others = scene.edges.filter((e) => e !== edge).map((e) => (e.side === side ? { ...e, ring: e.ring + 1 } : e));\n return { ...scene, edges: closeRings([moved, ...others], new Set([edge.side, side])) };\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 (a column under the same id that holds none of the start column's\n * items is another column), 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 own = itemOf(start, id) ?? itemOf(scene, id);\n // A dynamic column's id is reused once it is pruned: the edge under that id is home only while it still holds one of\n // the start column's items (the item itself, or another). Static edges match by id.\n const found = scene.edges.find((x) => x.id === e.id);\n const here = found && (e.column !== true || found.items.some((x) => e.items.includes(x))) ? found : undefined;\n if (here) {\n // The zone it lies in there, by its start `align` (`zoneIn`); the others by where they lie.\n const zone = own ? zoneIn(here, own) : \"start\";\n const now = here.items.filter((x) => x !== id && zoneAt(scene, here, 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 // Its ring as the start scene's side lay (no ties); `insertColumn` keeps it inside the static edges outer to it.\n if (e.column === true && (e.side === \"left\" || e.side === \"right\")) return { kind: \"column\", side: e.side, ring: sideRings(start.edges, e.side).get(e.id) ?? 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 * Dock, Put back and Reset position: the item where `start` (the loaded scene) has it, fold included. It goes to\n * `homeFor`'s place and takes `start`'s `from` (unfolded when `start` has none), so a \"Move to › rail\" (which folds it)\n * followed by Dock brings it back open. The scene given back unchanged when `start` places it nowhere.\n */\nexport function dockHome(scene: Scene, id: string, start: Scene): Scene {\n const place = homeFor(scene, id, start);\n if (!place) return scene;\n // An item already at its home place (the only item of its own column, which `moveTo` can't re-dock into) keeps its\n // place and still takes the start fold.\n const moved = moveTo(scene, id, place);\n const item = itemOf(moved, id);\n if (!item) return scene;\n // Home names no zone of its own: the item takes `start`'s zone (`align`) back, as its fold.\n const was = itemOf(start, id);\n const from = was?.from;\n let out = item;\n if (was && out.align !== was.align) {\n const { align: _a, ...plain } = out;\n out = was.align === undefined ? plain : { ...plain, align: was.align };\n }\n if (out.from !== from) {\n const { from: _f, ...plain } = out;\n out = from === undefined ? plain : { ...plain, from };\n }\n return out === item ? moved : withItem(moved, out);\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 (`floatShape`): its rect's, its bar's when folded, its icons' when vertical. */\nexport function drawnFloatSize(item: SceneItem, f: { readonly rect: Rect; readonly orient?: Orient }): { width: number; height: number } {\n const s = floatShape(item, f);\n return { width: s.width, height: s.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 | { at: FloatAnchor; dx?: number; dy?: number }; since?: number }[];\n * items: Record<string, { used: number; kept?: true; from?: number; closed?: true; align?: \"center\" | \"end\"; floatSize?: { width: number; height: number } }>;\n * railModes?: { left?: \"titles\" | \"icons\"; right?: \"titles\" | \"icons\" };\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; a static edge stored on\n * the other side of its axis is moved there (`setSide`, as its side's outermost edge). 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. `Edge.hidden` is view state, not stored: the host decides it\n * each time it builds the scene (from the window's width, say). A hidden edge's items are stored like any edge's;\n * `hidden` itself is not written, and read back it comes from `base` only (a stored `hidden` is ignored and listed as\n * `edge:<id>:hidden`). `Edge.showIn` is the same: never written, from `base` only, a stored one listed as\n * `edge:<id>:showIn`; the items a hidden edge lends are stored in it, as they are. No float has a pinned field: one\n * an old store has is listed and 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; its anchor, with any offset, is kept as stored (an anchored float\n * lies by its anchor, so the clamp never turns it into a pixel position). An unusable anchor is dropped\n * (`float:<id>:anchor`), and so is a bad offset field (`float:<id>:anchor:dx`, `float:<id>:anchor:<field>`). A float's\n * `since` is kept as stored; one that isn't a number from 0 to `Number.MAX_SAFE_INTEGER` is dropped (`float:<id>:since`).\n */\nimport { rect, type Size } from \"../geometry\";\nimport { clampFloat, closeRings, drawnFloatSize, prune, setSide } from \"./changes\";\nimport { axisOf, columnFromTemplate, isSince } from \"./helpers\";\nimport { checkEdgeIds, isReservedEdgeId } from \"./targets/ids\";\nimport { FLOAT_ANCHORS, RAIL_MODES, SIDES, type Edge, type FloatAnchor, type FloatAnchorAt, type Orient, type RailMode, 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 /** An anchor's name, or `{ at, dx?, dy? }`: an anchor with an offset in px. */\n readonly anchor?: FloatAnchorAt;\n /** When it was floated (`SceneFloat.since`). */\n readonly since?: number;\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 /** Per side, how its rails show their items (`Scene.railModes`), when the scene sets one. */\n readonly railModes?: Readonly<Partial<Record<\"left\" | \"right\", RailMode>>>;\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 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);\nconst isAnchor = (x: unknown): x is FloatAnchor => FLOAT_ANCHORS.includes(x as FloatAnchor);\n\n/**\n * The float anchor in `v`, as plain data: a name, or `{ at, dx?, dy? }` with its finite offsets; undefined when there is\n * none or it can't be used. `drop` hears what is left out: `\"\"` for the whole anchor (an unknown name, an offset with no\n * valid `at`), `\":dx\"` / `\":dy\"` for an offset that isn't a number, `\":<field>\"` for an unknown field.\n */\nfunction anchorOf(v: unknown, drop?: (what: string) => void): FloatAnchorAt | undefined {\n if (v === undefined) return undefined;\n if (isAnchor(v)) return v;\n if (!isObject(v) || !isAnchor(v.at)) {\n drop?.(\"\");\n return undefined;\n }\n for (const k of Object.keys(v)) if (k !== \"at\" && k !== \"dx\" && k !== \"dy\") drop?.(`:${k}`);\n for (const k of [\"dx\", \"dy\"] as const) if (v[k] !== undefined && !isNum(v[k])) drop?.(`:${k}`);\n return { at: v.at, ...(isNum(v.dx) ? { dx: v.dx } : {}), ...(isNum(v.dy) ? { dy: v.dy } : {}) };\n}\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\n/** The valid rail modes of `v` (left and right only), or null when it has none. */\nfunction railModesOf(v: unknown, drop?: (what: string) => void): Partial<Record<\"left\" | \"right\", RailMode>> | null {\n if (v === undefined) return null;\n if (!isObject(v)) {\n drop?.(\"railModes\");\n return null;\n }\n const out: Partial<Record<\"left\" | \"right\", RailMode>> = {};\n for (const k of Object.keys(v)) {\n const m = v[k];\n if ((k === \"left\" || k === \"right\") && RAIL_MODES.includes(m as RailMode)) out[k] = m as RailMode;\n else drop?.(`railModes:${k}`);\n }\n return Object.keys(out).length > 0 ? out : null;\n}\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 const modes = railModesOf(scene.railModes);\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) => {\n const anchor = anchorOf(f.anchor);\n return { id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...(f.orient ? { orient: f.orient } : {}), ...(anchor ? { anchor } : {}), ...(isSince(f.since) ? { since: f.since } : {}) };\n }),\n items,\n ...(modes ? { railModes: modes } : {}),\n };\n}\n\nexport function readScene(data: unknown, base: Scene): SceneRead {\n checkEdgeIds(base);\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 */\nfunction 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\", \"railModes\"].includes(k)) drop(k);\n // The rail modes: the store's per side, over `base`'s.\n const storedModes = railModesOf(data.railModes, drop);\n const railModes = storedModes ? { ...base.railModes, ...storedModes } : base.railModes;\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 // A fixed item keeps `base`'s fold, but on an edge that lets the user fold it (`Edge.foldable`).\n const byHand = !b.fixed || base.edges.some((e) => e.foldable === true && e.items.includes(id));\n if (isNum(s.from) && Number.isInteger(s.from) && s.from >= 1 && byHand) it = { ...it, from: s.from };\n else if (s.from !== undefined) drop(`item:${id}:from`);\n if (!byHand && 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 const moves = new Map<string, Side>();\n const anchorMoves = new Map<string, Side>();\n const anchorSizes = 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 // An anchor (a fixed item) listed in an entry other than its own edge's: the entry says where and how big the\n // anchor's edge is (a store that kept the anchor inside a side edge). Its own static edge goes to that side and\n // takes that size; the anchor stays in it. An anchor's edge takes nothing (`accepts: []`); a fixed item of an edge\n // that takes items (a title in its title bar) listed elsewhere is dropped, as before.\n const listed = Array.isArray(e.items) ? (e.items as unknown[]) : [];\n const anchorEdges = base.edges.filter((b) => b.column !== true && b.accepts.length === 0 && b.id !== edge?.id && b.items.some((id) => isFixed(id) && listed.includes(id)));\n for (const b of anchorEdges) {\n const side = SIDES.includes(e.side as Side) ? (e.side as Side) : edge?.side;\n if (side && side !== b.side && axisOf(side) === axisOf(b.side)) anchorMoves.set(b.id, side);\n if (isNum(e.size)) anchorSizes.set(b.id, e.size);\n }\n const describesAnchor = anchorEdges.length > 0;\n if (!edge && describesAnchor) continue;\n // A stored column under a virtual edge's id (`column:<side>`, `rail:<side>`) is dropped, never made.\n if (!edge && e.column === true && (e.side === \"left\" || e.side === \"right\") && base.columns?.[e.side] && !isReservedEdgeId(e.id)) {\n // A column the user made: from its side's template.\n edge = columnFromTemplate(base.columns[e.side]!, e.id, e.side, isNum(e.ring) ? e.ring : Infinity, []);\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 // `hidden` and `showIn` are the host's view state, from `base`: a stored one is ignored.\n if (e.hidden !== undefined) drop(`edge:${edge.id}:hidden`);\n if (e.showIn !== undefined) drop(`edge:${edge.id}:showIn`);\n if (e.side !== undefined && !SIDES.includes(e.side as Side)) drop(`edge:${e.id}:side`);\n else if (!describesAnchor && edge.column !== true && typeof e.side === \"string\" && e.side !== edge.side && axisOf(e.side as Side) === axisOf(edge.side)) moves.set(edge.id, e.side as 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 if (!anchorEdges.some((b) => b.items.includes(id))) 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 // The size of an entry that describes an anchor is the anchor's edge's.\n if (describesAnchor) {\n if (!sizes.has(edge.id)) sizes.set(edge.id, edge.size);\n } else 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 for (const [id, side] of anchorMoves) moves.set(id, side);\n for (const [id, size] of anchorSizes) sizes.set(id, size);\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\", \"since\"].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 = anchorOf(f.anchor, (what) => drop(`float:${id}:anchor${what}`));\n const since = isSince(f.since) ? f.since : undefined;\n if (f.since !== undefined && since === undefined) drop(`float:${id}:since`);\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 } : {}), ...(since !== undefined ? { since } : {}) });\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 let scene = prune({ ...base, ...(railModes ? { railModes } : {}), items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? [\"left\", \"right\"] : [])), floats });\n for (const [id, side] of moves) scene = setSide(scene, id, side);\n return { scene, dropped };\n}\n","/**\n * A fixed item's targets. A fixed item never takes a gap; on an edge that `moves: \"side\"` (an anchor: page thumbnails)\n * it has one target, `side:<other side>`, over the place its edge takes on the other side of its axis, and its own\n * place is home.\n */\nimport { EPS, area, rect, subtract, type Rect } from \"../../geometry\";\nimport { setSide, use } from \"../changes\";\nimport { chromeFor } from \"../helpers\";\nimport type { Scene, Side } from \"../model\";\nimport { solve } from \"../solve\";\nimport { targetId } from \"./ids\";\nimport type { Generated, SceneAfter, SceneTarget, SceneTargetOptions } from \"./model\";\n\nconst OTHER: Record<Side, Side> = { left: \"right\", right: \"left\", top: \"bottom\", bottom: \"top\" };\n\n/**\n * The anchor's targets. The `side:` target's hit is where its edge lies once moved (`setSide`, then `use`, solved): on\n * the other side the edge is the outermost, so it owns that place over the side's columns (the bars laid before the\n * sides already bound it), clear of the chrome. Its `after` is that drop, so the preview is the landing.\n */\nexport function anchorTargets(scene: Scene, dragged: string, options: SceneTargetOptions): Generated {\n const none: Generated = { targets: [], refusals: [], lost: [] };\n const prev = { ...(options.previous ? { previous: options.previous } : {}), ...(options.fresh ? { fresh: options.fresh } : {}) };\n const now = solve(scene, prev);\n const me = now.items[dragged];\n const edge = me?.edge ? scene.edges.find((e) => e.id === me.edge) : undefined;\n if (!me || !edge || edge.moves !== \"side\" || me.floating) return none;\n const homeAfter = (): SceneAfter => ({ scene, layout: now });\n const targets: SceneTarget[] = [];\n const side = OTHER[edge.side];\n const moved = use(setSide(scene, edge.id, side), dragged);\n const layout = solve(moved, prev);\n const placed = layout.edges[edge.id]?.rect;\n const slot = layout.items[dragged]?.rect;\n if (placed && slot && area(placed) > EPS) {\n const pieces = chromeFor(scene, \"targets\").reduce<Rect[]>((ps, c) => ps.flatMap((p) => subtract(p, rect(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);\n if (pieces.length > 0) {\n const hit = pieces.reduce((a, p) => (area(p) > area(a) ? p : a));\n const result: SceneAfter = { scene: moved, layout };\n targets.push({ id: targetId({ kind: \"side\", side }), priority: 2, hit, ...(pieces.length > 1 ? { hits: pieces } : {}), slot, item: dragged, place: { kind: \"side\", edge: edge.id, side }, after: () => result });\n }\n }\n targets.push({ id: targetId({ kind: \"home\", item: dragged }), priority: 1, hit: me.rect, item: dragged, place: { kind: \"home\" }, after: homeAfter });\n return { targets, refusals: [], lost: [] };\n}\n","/** The edge kinds and their data (`EDGE_KINDS`): the only place target generation tells edges apart. */\nimport { COLUMN_REACH } from \"../../geometry\";\nimport { isSideBar, zoneTakes } from \"../helpers\";\nimport { DEFAULT_HIT_BAND, type Edge, type Scene } from \"../model\";\n\n/** How far a compact rail's hits reach inward past the rail, px. */\nconst RAIL_REACH = 24;\n\n/** The least a target's largest piece keeps where the space beside it can be spared: 12 px across by 24 px along. */\nconst MIN_HIT = { across: 12, along: 24 } as const;\n\n/**\n * The edge kinds and their data, the only place target generation tells them apart, the virtual edges (the column\n * lines across a side, the stops down its rail) among them.\n * - `zoneExtent`: `thirds` where items keep their length and the zones only align them, `solved` where items fill the\n * edge (each zone's extent is the span the solver gives it), `whole` for an edge of one zone.\n * - `opens`: through which zones an empty edge opens: `any` zone that takes the kind, or only its `start` zone.\n * - `inward`: how far hits reach inward past the edge's thickness (overreach, below).\n * - Space ownership, one ordering: **owned > virtual > overreach**. A drawn edge owns its current rect; an empty edge\n * owns only `place` px of its strip, at the boundary where it would appear (the side's rail likewise, where it lies\n * or would lie, `railPlaces`). Owned rects rank in the order `solve` lays edges out (`layKeys`, `pushes`): an edge\n * laid first, whose filling pushes the other, wins; between edges laid independently a drawn rect wins over an empty\n * edge's band. `layer` orders the owned tiles where they meet. The virtual edges (the column lines) come next and get\n * only space no edge owns. `overreach` orders the parts of tiles past their owned rect (the depth after a drop, an\n * empty strip past its band, a compact rail's inward reach), which yield to the virtual edges and to every other\n * edge's owned rect.\n * - `phase`: the laying phase it ranks in (`LayKey.phase`), for the kinds `solve` doesn't lay itself: the rail and a\n * column line rank among the sides (phase 2), where the rail or a new column would be laid; null for the edges\n * `solve` lays (their phase is `layKeys`'s).\n * - `priority`: its targets' priority. `reach`: how far a slot's tile reaches each way from its line, px.\n * - `edgePlace` (column lines): the band the outermost line owns where it can't be centered on its line, at the side's\n * outer boundary: laid inward, right after the rail stop's `RAIL_EDGE` px.\n * - `virtual`: an edge that owns nothing (the column lines). Its refused stretches take only what every other tile\n * leaves.\n * - `minHit`: the least its targets' largest piece keeps (`MIN_HIT`), taken from the space beside it where that can be\n * spared (`./min-hit`).\n */\nexport const EDGE_KINDS = {\n bar: { zoneExtent: \"thirds\", opens: \"any\", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },\n sideBar: { zoneExtent: \"thirds\", opens: \"any\", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },\n column: { zoneExtent: \"solved\", opens: \"start\", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },\n barBetween: { zoneExtent: \"thirds\", opens: \"any\", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },\n rail: { zoneExtent: \"thirds\", opens: \"any\", inward: RAIL_REACH, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 14, overreach: 34, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },\n railStop: { zoneExtent: \"whole\", opens: \"any\", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false, minHit: MIN_HIT },\n columnLine: { zoneExtent: \"whole\", opens: \"any\", inward: 0, place: DEFAULT_HIT_BAND / 2, edgePlace: DEFAULT_HIT_BAND, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true, minHit: MIN_HIT },\n} as const satisfies Record<\n string,\n {\n readonly zoneExtent: \"thirds\" | \"solved\" | \"whole\";\n readonly opens: \"any\" | \"start\";\n readonly inward: number;\n readonly place: number;\n readonly edgePlace?: number;\n readonly layer: number;\n readonly phase: number | null;\n readonly overreach: number;\n readonly priority: 1 | 2;\n readonly reach: number;\n readonly virtual: boolean;\n readonly minHit: { readonly across: number; readonly along: number };\n }\n>;\nexport type EdgeKind = keyof typeof EDGE_KINDS;\n\n/** Which of `EDGE_KINDS` an edge is. */\nexport function edgeKindOf(scene: Scene, e: Edge): EdgeKind {\n if (e.compact) return \"rail\";\n if (e.side === \"top\" || e.side === \"bottom\") return e.span === \"between\" ? \"barBetween\" : \"bar\";\n return isSideBar(scene, e) ? \"sideBar\" : \"column\";\n}\n\n/**\n * Whether an empty `edge` opens to `kind`: an edge opens only through its start zone, so a kind never makes a column of\n * its own where the start zone takes another kind (a group never makes a column of one toolbar: a tray column's tray is\n * its end zone). Edges whose zones only align (bars, rails, side bars) open through any zone that takes the kind.\n */\nexport const opensEmpty = (scene: Scene, edge: Edge, kind: string): boolean => EDGE_KINDS[edgeKindOf(scene, edge)].opens === \"any\" || zoneTakes(edge, \"start\", kind);\n","/**\n * Generation, the real edges: each edge's zones and their extents, its slots (insertion lines, each with the drop it\n * makes, settled), its reserved stretches and its band across, as the tiler reads them (`EdgeSpec`).\n */\nimport { EPS, area, rect, type Rect } from \"../../geometry\";\nimport { formMain } from \"../../stack\";\nimport { moveAmong, moveTo, use } from \"../changes\";\nimport { axisOf, edgeTakes, formsOf, zoneOf, zoneTakes } from \"../helpers\";\nimport { DEFAULT_STRIP, ZONES, type Edge, type Scene, type SceneLayout, type Zone } from \"../model\";\nimport { solve } from \"../solve\";\nimport { targetId } from \"./ids\";\nimport { EDGE_KINDS, edgeKindOf, opensEmpty } from \"./kinds\";\nimport type { Ctx, EdgeSpec, SceneAfter, SceneTargetOptions, Slot, Span } from \"./model\";\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, centered in the center 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/** A slot for `place` on `line`: its drop, settled; home when it puts the item back (or `home`); `lands`, its edge's rule. */\nexport function slotAt(c: Ctx, zone: Zone, line: number, id: string, place: Slot[\"place\"], lands: (r: SceneAfter) => boolean, home = false): Slot {\n const result = c.settle(use(moveAmong(c.scene, c.dragged, place, c.others), c.dragged));\n const isHome = home || c.isHome(result);\n return { zone, line, id, place, result, home: isHome, ok: isHome || (!!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout)) };\n}\n\n/**\n * Slots that are the same move are one slot: one line and one landing, or both home (both put the item back, wherever\n * their lines lie). Home keeps it where one of them is home (beside a closed member the item lands where it is); else\n * the first (the lowest `at`).\n */\nexport function distinctSlots(c: Ctx, slots: readonly Slot[]): Slot[] {\n const landing = (s: Slot): Rect | undefined => s.result.layout.items[c.dragged]?.rect;\n const sameMove = (a: Slot, b: Slot): boolean => {\n if (a.zone !== b.zone) return false;\n if (a.home && b.home) return true;\n const [p, q] = [landing(a), landing(b)];\n // Two rail stops that land the same (a rider bar at the top, whichever tile's line it was taken from) are one move,\n // wherever their lines lie; other slots are the same move only on one line.\n const sameLine = (a.place.kind === \"rail\" && b.place.kind === \"rail\") || Math.abs(a.line - b.line) < EPS;\n return sameLine && (!p || !q ? p === q : Math.abs(p.x - q.x) + Math.abs(p.y - q.y) + Math.abs(p.width - q.width) + Math.abs(p.height - q.height) < 0.01);\n };\n const wins = (o: Slot, j: number, s: Slot, i: number): boolean => (o.home !== s.home ? o.home : j < i);\n return slots.filter((s, i) => !slots.some((o, j) => j !== i && sameMove(o, s) && wins(o, j, s, i)));\n}\n\n/**\n * The zones of `edge` with their extents along it, for a drag of `kind` (`EDGE_KINDS[...].zoneExtent`). `probe(zone)`:\n * the span an empty zone takes once it holds the item (a `solved` edge's empty zone), or null (then a point at the\n * zone's anchor). The outer extents reach `reach` past the edge's ends. `seen`: the layout as the user sees it.\n *\n * Thirds hold the cards seen in them: a zone's extent reaches over every card of its zone (a fixed item's reserved\n * rect, a title's text), its neighbor's starting past it, so a point over a card is that card's zone.\n */\nfunction zoneSpans(scene: Scene, seen: SceneLayout, edge: Edge, reach: number, probe: (z: Zone) => Span | null): { zone: Zone; a: number; b: number }[] {\n const el = seen.edges[edge.id]!;\n const column = axisOf(edge.side) === \"column\";\n const main0 = column ? el.rect.y : el.rect.x;\n const length = column ? el.rect.height : el.rect.width;\n const thirds = EDGE_KINDS[edgeKindOf(scene, edge)].zoneExtent === \"thirds\";\n const at = (r: Rect): Span => (column ? [r.y, r.y + r.height] : [r.x, r.x + r.width]);\n const declared = new Set<Zone>(edge.zoneAccepts ? ZONES.filter((z) => edge.zoneAccepts![z] !== undefined) : [\"start\"]);\n // Each zone's seen cards, end to end.\n const placed = new Map<Zone, Span>();\n for (const [id, it] of Object.entries(seen.items)) {\n if (it.edge !== edge.id || it.inMenu) continue;\n // The zone it is laid out in (`zoneIn`: its own wherever the edge takes it there).\n const z = it.zone ?? zoneOf(scene.items[id]);\n const [a, b] = at(thirds && it.fixed ? reservedRect(scene, seen, id) : it.rect);\n const was = placed.get(z);\n placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);\n declared.add(z);\n }\n if (thirds) {\n const lo = (z: Zone): number => placed.get(z)?.[0] ?? Infinity;\n const hi = (z: Zone): number => placed.get(z)?.[1] ?? -Infinity;\n const b1 = Math.min(Math.max(main0 + length / 3, hi(\"start\")), lo(\"center\"), lo(\"end\"));\n const b2 = Math.max(Math.min(main0 + (2 * length) / 3, lo(\"end\")), hi(\"center\"), hi(\"start\"), b1);\n return [\n { zone: \"start\", a: main0 - reach, b: b1 },\n { zone: \"center\", a: b1, b: b2 },\n { zone: \"end\", a: b2, b: main0 + length + reach },\n ];\n }\n // Where items fill the edge: the zones it declares (or its one zone), each where the solver puts its items.\n const anchor: Record<Zone, number> = { start: main0, center: main0 + length / 2, end: main0 + length };\n const spans = ZONES.filter((z) => declared.has(z)).map((zone) => ({ zone, s: placed.get(zone) ?? probe(zone) ?? ([anchor[zone], anchor[zone]] as Span) }));\n return spans.map(({ zone, s }, i) => ({\n zone,\n a: i === 0 ? main0 - reach : (spans[i - 1]!.s[1] + s[0]) / 2,\n b: i === spans.length - 1 ? main0 + length + reach : (s[1] + spans[i + 1]!.s[0]) / 2,\n }));\n}\n\n/**\n * `zoneExtents(scene, dragged, edgeId, options?)`: the zones of an edge and their extents along it, as the targets of a\n * drag of `dragged` tile them (the edge's rect as the user sees it, the item in place). For a test or a host that\n * shows the zones.\n */\nexport function zoneExtents(scene: Scene, dragged: string, edgeId: string, options: SceneTargetOptions = {}): { zone: Zone; a: number; b: number }[] {\n const prev = { ...(options.previous ? { previous: options.previous } : {}), ...(options.fresh ? { fresh: options.fresh } : {}) };\n const seen = solve(scene, prev);\n const edge = scene.edges.find((e) => e.id === edgeId);\n if (!edge || !seen.edges[edgeId]) return [];\n const column = axisOf(edge.side) === \"column\";\n const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach! : 0);\n return zoneSpans(scene, seen, edge, reach, (zone) => {\n if (!zoneTakes(edge, zone, scene.items[dragged]?.kind ?? \"\")) return null;\n const l = solve(use(moveTo(scene, dragged, { kind: \"gap\", edge: edgeId, zone, at: 0 }), dragged), prev);\n const me = l.items[dragged];\n return me && me.edge === edgeId && me.zone === zone ? (column ? [me.rect.y, me.rect.y + me.rect.height] : [me.rect.x, me.rect.x + me.rect.width]) : null;\n });\n}\n\n/**\n * An edge's slots: each zone's insertion lines, in the seen geometry (the item in place; its own place is an interval,\n * home's). A slot counts its place among the edge's members with the item lifted (`at`); its drop is solved. What an\n * item takes of the edge for its lines: its rect, or a growing fixed item's natural rect (a title's text), so the\n * length it grew by is free room. A place that would move a protected fixed item of the edge is no slot. Protected: a\n * fixed item in the slot's zone's anchored fixed run (the fixed members contiguous from the zone's anchor with no\n * movable member between: the start zone's from its first member, the end zone's from its last), any fixed item of the\n * center zone, and any fixed item of another zone. A fixed item behind a movable one in the slot's own zone is placed\n * by that movable's size, so a drop there may push it.\n */\nfunction edgeSlots(c: Ctx, edge: Edge, accepts: boolean): Slot[] {\n const { scene, rest, now, base, dragged, kind } = c;\n const el = now.edges[edge.id]!;\n const column = axisOf(edge.side) === \"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 main0 = at(el.rect);\n const length = len(el.rect);\n // The edge's members with the item lifted, the places a gap counts.\n const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];\n // `strip:<edge>:<zone>` names a slot only on an edge with no members at all (a zone there has one slot); every other\n // slot, beside closed members or the item's own place too, is named by its gap, so no two slots share an id.\n const slotId = (zone: Zone, k: number): string => targetId(members0.length === 0 ? { kind: \"strip\", edge: edge.id, zone } : { kind: \"gap\", edge: edge.id, zone, at: k });\n // Where a drop lands on this edge: in it, shown (no » entry); on a title bar (a fixed item that grows), in a form of its\n // first form's kind (the full row or one of its compact variants, read from the forms, not from their index), the\n // title at its natural width and nothing else changing form or going into the menu.\n const firstKind = formsOf(scene.items[dragged]!, axisOf(edge.side))[0]?.kind;\n const titles = edge.items.filter((id) => base.items[id]?.edge === edge.id && base.items[id]!.fixed && !!formsOf(scene.items[id]!, axisOf(edge.side))[base.items[id]!.form]?.main.grows);\n const lands = ({ layout: after }: SceneAfter): boolean => {\n const me = after.items[dragged]!;\n if (me.edge !== edge.id || me.inMenu) return false;\n if (titles.length === 0) return true;\n if (formsOf(scene.items[dragged]!, axisOf(edge.side))[me.form]?.kind !== firstKind) return false;\n return edge.items.every((id) => {\n const a = after.items[id];\n const b = base.items[id];\n if (!a || !b || b.edge !== edge.id || id === dragged) return true;\n if (!titles.includes(id)) return a.form === b.form && !!a.inMenu === !!b.inMenu;\n const f = formsOf(scene.items[id]!, axisOf(edge.side))[a.form];\n return !f || (column ? a.rect.height : a.rect.width) >= formMain(f, \"natural\", after.edges[edge.id]!.cross) - 0.5;\n });\n };\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 occupied = (id: string): Rect => (now.items[id]?.fixed ? reservedRect(scene, now, id) : now.items[id]!.rect);\n const shown = (id: string): boolean => now.items[id]?.edge === edge.id && !now.items[id]!.inMenu;\n const drawnOf = (z: Zone): Rect[] => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);\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 anchorLine: 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 slots: Slot[] = [];\n // A slot's order: how many of the edge's shown items (fixed ones aside) lie before it, the item taken out.\n const aimed = (id: string): boolean => shown(id) && !now.items[id]!.fixed;\n let earlier = 0;\n for (const zone of ZONES) {\n const members = members0.filter((id) => zoneOf(rest.items[id]) === zone);\n const before0 = earlier;\n earlier += members.filter(aimed).length;\n if (!accepts || !zoneTakes(edge, zone, kind)) continue;\n // The zone's anchored fixed run, read from its anchor (the start zone's first member, the end zone's last) up to its\n // first shown movable member. The center zone has none: every fixed item there keeps the geometric test.\n const fixedHere = (id: string): boolean => !!base.items[id]?.fixed && base.items[id]!.edge === edge.id;\n const fromAnchor = (zone === \"start\" ? members : zone === \"end\" ? [...members].reverse() : []).filter((id) => fixedHere(id) || shown(id));\n const firstMovable = fromAnchor.findIndex((id) => !fixedHere(id));\n const anchored = new Set(firstMovable < 0 ? fromAnchor : fromAnchor.slice(0, firstMovable));\n const isProtected = (id: string): boolean => fixedHere(id) && (zone === \"center\" || zoneOf(rest.items[id]) !== zone || anchored.has(id));\n for (let k = 0; k <= members.length; k++) {\n const next = members.slice(k).find(shown);\n const before = members.slice(0, k).reverse().find(shown);\n const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];\n const s = { ...slotAt(c, zone, line, slotId(zone, k), { kind: \"gap\", edge: edge.id, zone, at: k }, lands), order: before0 + members.slice(0, k).filter(aimed).length };\n // A place that would move a protected fixed item (before a title, after the window controls) is no slot: it keeps\n // its place, so no drop ever lands there. A fixed item behind a movable one in this zone may be pushed.\n const movesFixed = members0.some((id) => {\n const b = base.items[id];\n const a = s.result.layout.items[id];\n // (Pushed is not gone: a drop that would take any fixed item out of the layout is no slot either.)\n if (fixedHere(id) && !a) return true;\n return isProtected(id) && (Math.abs(a!.rect.x - b!.rect.x) > 0.5 || Math.abs(a!.rect.y - b!.rect.y) > 0.5);\n });\n if (!movesFixed) slots.push(s);\n }\n }\n return slots;\n}\n\n/**\n * A real edge as the tiler reads it, in the seen geometry, or null where it offers nothing (home's own rect is added\n * on its own). An edge the lift deletes (the item's own column, or a dynamic column left empty) has no place a drop\n * counts in: the item's own collapses into home.\n */\nexport function edgeSpec(c: Ctx, edge: Edge): EdgeSpec | null {\n const { scene, rest, now, dragged, kind } = c;\n const el = now.edges[edge.id];\n // A folded or riding column takes drops through its side's rail and column lines, not here.\n if (!el || el.folded || el.rides || !rest.edges.some((e) => e.id === edge.id)) return null;\n const edgeKind = edgeKindOf(scene, edge);\n const data = EDGE_KINDS[edgeKind];\n const column = axisOf(edge.side) === \"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 empty = el.stack.items.every((p) => p.kind === \"menu\") && !el.menu;\n // Whether it takes the kind at all: listed in `accepts` and taken by at least one zone. An edge whose zones take\n // nothing for it (`zoneAccepts: {}`, a rail the host doesn't draw) is one that doesn't accept it.\n const accepts = edgeTakes(edge, kind);\n // An edge that takes the kind nowhere and draws nothing has nothing to say; an empty edge opens only as it may.\n if (!accepts && (empty || area(el.rect) <= EPS)) return null;\n if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;\n // The item's own rect, where it is seen in this edge (in its » menu, the » entry): home's, whatever else the edge\n // offers.\n const ownNow = now.items[dragged];\n const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area(ownNow.rect) > EPS ? ownNow.rect : null;\n const slots = edgeSlots(c, edge, accepts);\n const spanOf = (r: Rect): Span => [at(r), at(r) + len(r)];\n // The edge's reserved rects along it (its fixed items; a growing one's natural rect): no slot's tile lies there.\n // A growing one (a title) is not: its text is a stretch of the gap just after it.\n const grows = (id: string): boolean => !!formsOf(scene.items[id]!, axisOf(edge.side))[now.items[id]!.form]?.main.grows;\n const reserved: Span[] = Object.entries(now.items)\n .filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id))\n .map(([, p]) => spanOf(p.rect));\n const cards: Span[] = Object.entries(now.items)\n .filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area(p.rect) > EPS)\n .map(([, p]) => spanOf(p.rect));\n const zones =zoneSpans(scene, now, edge, c.reach, (zone) => {\n const s = slots.find((x) => x.zone === zone && x.place.kind === \"gap\" && x.place.at === 0);\n const me = s?.result.layout.items[dragged];\n return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;\n });\n\n // Across: the band from the edge's outer side, as deep as the edge (seen or after the drop) or an empty edge's strip.\n const r = el.rect;\n const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip! : DEFAULT_STRIP);\n const outer = edge.side === \"left\" ? r.x : edge.side === \"right\" ? r.x + r.width : edge.side === \"top\" ? r.y : r.y + r.height;\n const inward = (depth: number): Span => (edge.side === \"left\" || edge.side === \"top\" ? [outer, outer + depth] : [outer - depth, outer]);\n const across = (after?: SceneLayout): Span => inward((el.cross > 0 ? Math.max(el.cross, after?.edges[edge.id]?.cross ?? 0) : strip) + data.inward);\n // What it owns: its seen thickness; an edge not drawn (empty, or one that shows only once the item lifts) owns only a\n // thin band of its place, at its boundary.\n const drawn = el.cross > 0;\n const marker = (s: Slot): Rect => {\n const slot = s.result.layout.items[dragged]!.rect;\n const e = s.result.layout.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 takes = (zone: Zone): boolean => accepts && zoneTakes(edge, zone, kind);\n return {\n id: edge.id,\n edge,\n kind: edgeKind,\n lay: c.lay.get(edge.id)!,\n vertical: column,\n zones,\n slots,\n refuse: (zone) => (takes(zone) ? \"no-room\" : accepts || area(el.rect) > EPS ? \"not-accepted\" : null),\n own: ownHere,\n holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,\n reserved,\n cards,\n across,\n owned: inward(drawn ? el.cross : Math.min(strip, data.place)),\n ownedAlong: null,\n drawn,\n marker,\n };\n}\n","/**\n * The filter a drop passes, and the context every generator shares: the scene now and with the item lifted, how a drop\n * settles, when a drop puts the item back (home), and filter (ii), whether a drop's layout fits the window.\n */\nimport { overlaps } from \"../../geometry\";\nimport { formMain } from \"../../stack\";\nimport { lift, prune } from \"../changes\";\nimport { axisOf, chromeFor, formsOf, isHandFolded, zoneOf } from \"../helpers\";\nimport { ZONES, type Edge, type Scene, type SceneItem, type SceneLayout, type SolveOptions } from \"../model\";\nimport { layKeys, solve } from \"../solve\";\nimport { reservedRect } from \"./edges\";\nimport type { Ctx, SceneAfter, SceneTargetOptions } from \"./model\";\n\n/**\n * Where things are, without ages or the ids of dynamic columns: two scenes with one key place every item alike. An\n * edge's items count by zone (start, center, end), in their order within it: the list's order across zones places\n * nothing.\n */\nfunction placeKey(s: Scene, id: string): string {\n const it = Object.hasOwn(s.items, id) ? s.items[id] : undefined;\n const byZone = (items: readonly string[]): string[] => ZONES.flatMap((z) => items.filter((x) => zoneOf(s.items[x]) === z));\n return JSON.stringify({\n edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? \"\" : e.id, byZone(e.items), e.size ?? null])).sort(),\n floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),\n folded: isHandFolded(s, id),\n align: it?.align ?? \"start\",\n });\n}\n\n/**\n * Filter (ii), fit: a drop may not add an `overflow` or `too-wide` note anywhere, change a fixed item's form or least\n * length, nor lie over chrome or a fixed item's reserved rect (C29). Each edge adds where a drop on it lands (`lands`).\n */\nfunction soundness(scene: Scene, base: SceneLayout, dragged: string): (after: SceneLayout) => boolean {\n const chrome = chromeFor(scene, \"targets\");\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 return (after) => {\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 < formMain(f, \"min\", e.cross) - 0.5) return false;\n }\n const me = after.items[dragged];\n if (!me) return true;\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}\n\n/**\n * A drag's context: null for an unknown, fixed or closed item (it has no targets). `others`: edges kept out of `scene`\n * (its hidden ones) that a drop's new column must not repeat the ids of.\n */\nexport function context(scene: Scene, dragged: string, options: SceneTargetOptions, others: readonly Edge[] = []): { c: Ctx; item: SceneItem; prev: SolveOptions } | null {\n const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : undefined;\n if (!item || item.fixed || item.closed) return null;\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 // Every drop prunes the dynamic columns left empty: the place the item is in now counts without them too.\n const here = placeKey(prune(scene), dragged);\n const c: Ctx = {\n scene,\n others,\n rest,\n now,\n base,\n dragged,\n kind: item.kind,\n reach: Math.max(0, Number.isFinite(options.endReach) ? options.endReach! : 0),\n settle,\n isHome: (r) => placeKey(r.scene, dragged) === here,\n sound: soundness(scene, base, dragged),\n lay: layKeys(scene),\n };\n return { c, item, prev };\n}\n","/**\n * The targets' shapes: the public ones (`SceneTarget`, `SceneRefusal`, `ScenePlace`, …) and the tiler's own (an edge\n * as the tiler reads it, its slots and tiles, the context every generator shares).\n */\nimport { EPS, type Point, type Rect, type Size } from \"../../geometry\";\nimport type { Target } from \"../../target\";\nimport type { ColumnPlace, RailPlace } from \"../changes\";\nimport type { Edge, Orient, Scene, SceneLayout, Side, Zone } from \"../model\";\nimport type { LayKey } from \"../solve\";\nimport type { EdgeKind } from \"./kinds\";\n\nexport type ScenePlace =\n | { readonly kind: \"gap\"; readonly edge: string; readonly zone: Zone; readonly at: number }\n | ColumnPlace\n | RailPlace\n | { readonly kind: \"side\"; readonly edge: string; readonly side: Side }\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 /** A rail target under a kind's `Scene.railDrop` policy: the side's whole drop strip, for the host to draw. */\n readonly strip?: 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 /** The float's orient for the float target (default: its float's, else the item's `floatOrientOf`). */\n readonly floatOrient?: Orient;\n /** As `solve`'s: edge or item ids solved without `previous`, in every `after` too. */\n readonly fresh?: readonly string[];\n}\n\n/** Where a drop of the dragged item is refused: a host shows \"no room here\" at the pointer, with no slot anywhere. */\nexport interface SceneRefusal {\n /**\n * `refuse:<edge>:<zone>`, with `:<n>` after it for a zone's second refused tile and on, numbered by where they lie\n * along the edge (then across it), so an id is stable from one frame to the next.\n */\n readonly id: string;\n readonly edge: string;\n readonly zone: Zone;\n /**\n * Where the pointer means it, never over a target's hit and never past the stage. An edge that takes the kind in no\n * zone gives one refusal (`n = 0`, zone `start`): its drawn rect, fixed items included, less what targets own. A\n * refused zone of an edge that takes the kind elsewhere: the refused slot's tile, inside the edge's ends.\n */\n readonly hit: Rect;\n /**\n * A wholly refused edge left in pieces by what targets own (a target in the middle of a bar): every piece, each at\n * least 1 px each way, `hit` the largest. Absent when the refusal is one rect. The pointer is in the refusal when it is\n * in any piece.\n */\n readonly hits?: readonly Rect[];\n /**\n * `no-room`: the zone takes the kind, but the drop there doesn't fit (a title bar at the title's natural width, say).\n * `own-place`: the stretch beside an item alone in its zone: there is room, but the zone's only place is the item's\n * own (a release there puts it back). `not-accepted`: the edge or zone doesn't take the kind.\n */\n readonly reason: \"no-room\" | \"own-place\" | \"not-accepted\";\n /**\n * The stage: the refusal holds only points strictly inside it (`Target.bounds`), so a pointer a host clamps exactly\n * onto the window's edge is never in it. Set by `refusals()`; `refusalTargets` passes it on.\n */\n readonly bounds?: Rect;\n}\n\n/** One tile before clipping: a slot's, home's, or a refused slot's. */\nexport interface Tile {\n readonly edge: string;\n /** The edge it tiles, or null for home's own rect where no edge tiles it (its » entry). */\n readonly spec: EdgeSpec | null;\n /** Its edge's kind, set by the edge's description (a virtual edge's too): never read from an edge's id. */\n readonly edgeKind: EdgeKind;\n /** Its edge runs along y. */\n readonly vertical: boolean;\n readonly zone: Zone;\n /** Clipping precedence: lower first. */\n readonly order: number;\n /** `reach`: the overreach of the tile `of` (its part past its edge's owned rect), clipped after the virtual edges. */\n readonly kind: \"slot\" | \"home\" | \"refuse\" | \"reach\";\n readonly of?: Tile;\n readonly id: string;\n readonly priority: 1 | 2 | 3;\n readonly place?: ScenePlace;\n readonly result?: SceneAfter;\n readonly reason?: SceneRefusal[\"reason\"];\n /**\n * The one refusal of an edge that takes the kind in no zone: its drawn rect in the stage, fixed items included. Only\n * what targets own is cut from it.\n */\n readonly whole?: boolean;\n readonly hit: Rect;\n /** A slot's tile left in pieces by clipping: every piece (`hit` the largest). */\n readonly hits?: readonly Rect[];\n /** The point the tile must keep through clipping (on its slot's line), or null for a refusal (its largest part). */\n readonly keep: Point | null;\n readonly marker?: Rect;\n readonly slot?: Rect;\n}\n\n/** What one drag can do: its targets and its refusals, from one generation. */\nexport interface Generated {\n readonly targets: SceneTarget[];\n readonly refusals: SceneRefusal[];\n /** Slots the filter kept, with room in their zone, that end with no hit (none, by the property check). */\n readonly lost: string[];\n /** Each docked target's zone by id: its tiles with its edge tiled on its own (what it may grow to its minimum in). */\n readonly zones?: ReadonlyMap<string, readonly Rect[]>;\n}\n\n/** The context every edge's generator shares. */\nexport interface Ctx {\n readonly scene: Scene;\n /** Edges kept out of `scene` (its hidden ones): a drop's new column never repeats their ids (`moveAmong`). */\n readonly others: readonly Edge[];\n /** The scene with the item lifted: what a place counts in (a gap's `at`, a column's or rail's `ring`). */\n readonly rest: Scene;\n /** The seen geometry: the committed layout, the item in place. Every tile lies in it. */\n readonly now: SceneLayout;\n /** The layout with the item lifted: read only by the landing rules (fit, a title's natural width, fixed items). */\n readonly base: SceneLayout;\n readonly dragged: string;\n readonly kind: string;\n readonly reach: number;\n readonly settle: (s: Scene) => SceneAfter;\n readonly isHome: (r: SceneAfter) => boolean;\n /** Whether a drop's layout fits the window (filter ii): what every edge checks; its own landing rule comes on top. */\n readonly sound: (after: SceneLayout) => boolean;\n /** Where `solve` lays each edge of the scene out. */\n readonly lay: ReadonlyMap<string, LayKey>;\n}\n\n/** A slot: an insertion line along an edge and the drop it makes. */\nexport interface Slot {\n readonly zone: Zone;\n /** Its line along the edge. */\n readonly line: number;\n readonly id: string;\n readonly place: Extract<ScenePlace, { kind: \"gap\" }> | ColumnPlace | RailPlace;\n readonly result: SceneAfter;\n /** A drop here puts the item back where it is. */\n readonly home: boolean;\n /** It passes the filter: home, or the item lands where the slot aims and the window fits. */\n readonly ok: boolean;\n /**\n * A real edge's slot: its place in the order of the edge's shown items, the item taken out (how many of them, across\n * every zone, lie before it). Slots of one order are the same aim, whatever their zone.\n */\n readonly order?: number;\n}\n\n/** `[a, b]` along an edge. */\nexport type Span = readonly [number, number];\n\n/**\n * What an edge's zones lose along it: `cuts`, what other edges own across its whole depth (no room); `bodies`, its\n * panel bodies (no drop place, but the tiles run across them and clipping takes them out).\n */\nexport interface Room {\n readonly cuts: readonly Span[];\n readonly bodies: readonly Span[];\n}\n\n/** Spans along an edge less other spans along it. */\nexport const less = (spans: readonly Span[], away: readonly Span[]): Span[] =>\n away.reduce<Span[]>((acc, [ra, rb]) => acc.flatMap(([a, b]) => (rb <= a || ra >= b ? [[a, b] as Span] : ([[a, Math.max(a, ra)], [Math.min(b, rb), b]] as Span[]).filter(([u, w]) => w - u > EPS))), [...spans]);\n\n/**\n * One edge as the tiler reads it, a real edge or a virtual one alike: its kind (`EDGE_KINDS`), its axis, its zones'\n * extents along it, its slots, the item's own rect on it (its interval along the edge is home's tile), the spans no\n * tile takes, its band across and its markers.\n */\nexport interface EdgeSpec {\n /** The edge id its targets and refusals name (a side's column lines share one, one spec per line). */\n readonly id: string;\n /** The scene's edge, or null for a virtual edge. */\n readonly edge: Edge | null;\n readonly kind: EdgeKind;\n /** Where `solve` lays it out (`layKeys`): what it owns ranks by this. */\n readonly lay: LayKey;\n /** It runs along y (side edges, the rail), not x (bars, the column lines). */\n readonly vertical: boolean;\n readonly zones: readonly { readonly zone: Zone; readonly a: number; readonly b: number }[];\n readonly slots: readonly Slot[];\n /** Why a stretch of `zone` with no slot is refused, or null where it is no drop place at all. */\n readonly refuse: (zone: Zone) => SceneRefusal[\"reason\"] | null;\n /** The item's own rect on this edge, or null. */\n readonly own: Rect | null;\n /** The item lies on this edge now (drawn, or in its » menu): its home slot gets no tile, home is only its own rect. */\n readonly holds: boolean;\n readonly reserved: readonly Span[];\n /**\n * The seen spans of the edge's shown items other than the dragged one (fixed items aside), the items a pointer aims\n * at: tiles split at their midpoints, their leading half before them, their trailing half after them.\n */\n readonly cards: readonly Span[];\n /** The band across, `[from, to]`, as deep as the edge is seen or after `after`. */\n readonly across: (after?: SceneLayout) => Span;\n /** The part of the band across it owns: its seen thickness, or an undrawn edge's thin band at its boundary. */\n readonly owned: Span;\n /** Along it, what it owns, where that is less than its zones (a column line's band about its line); else null. */\n readonly ownedAlong: Span | null;\n /** It is drawn in the seen geometry; else what it owns is a band of its place (where it lands once filled). */\n readonly drawn: boolean;\n /** A slot's marker: the zero-thick line where the item's leading edge lands. */\n readonly marker: (s: Slot) => Rect;\n}\n","/**\n * Space ownership (filter iii), in the seen geometry: the committed layout, the item in place, the one the user sees.\n * A stretch is owned by what the user sees there; if the owner has no slot there, it refuses. A drawn edge owns its\n * seen rect (the item's own edge too: its own interval is home's); an edge not drawn (empty, or one that shows only\n * once the item lifts) owns a thin band of its place at its boundary, along its surviving slots' tiles only; the\n * rail likewise. Owned rects rank in the order `solve` lays edges out: one laid before another and pushing it when\n * filled wins (outer before inner, full bars before the sides they push, the rail before its side); between edges laid\n * independently a drawn rect wins over an empty edge's band, two drawn rects yield to each other, and of two bands the\n * one laid first wins. Home's tile is owned before all. A virtual edge owns nothing and yields to every owner.\n */\nimport { EPS, area, overlaps, rect, subtract, type Rect } from \"../../geometry\";\nimport { axisOf, formsOf, hitBandOf } from \"../helpers\";\nimport { DEFAULT_HIT_BAND, type Edge } from \"../model\";\nimport { pushes, type LayKey } from \"../solve\";\nimport { EDGE_KINDS } from \"./kinds\";\nimport { less, type Ctx, type EdgeSpec, type Room, type Span } from \"./model\";\n\ninterface Owner {\n /** The edge it is, as the tiler reads it; null for an edge the tiler doesn't read (folded, riding, taking nothing). */\n readonly spec: EdgeSpec | null;\n readonly rect: Rect;\n readonly lay: LayKey;\n readonly place: boolean;\n}\n\n/** What clipping reads of ownership. */\nexport interface Ownership {\n readonly owners: readonly Owner[];\n /** Per spec: the rects it yields (the owners that win over it; for a virtual edge, every other owner too). */\n readonly taken: ReadonlyMap<EdgeSpec, readonly Rect[]>;\n /** A zone's room lost to the owners that win over its edge across its whole depth (`cuts`), and its panel bodies. */\n readonly cutsOf: (s: EdgeSpec) => Room;\n /** The panel bodies and reserved rects of an edge, each cut across its whole band (none for a virtual edge). */\n readonly bodies: (s: EdgeSpec) => Rect[];\n /** The fixed items that don't grow, where they are seen. */\n readonly solid: readonly Rect[];\n /**\n * Every edge's seen rect but `s`'s. A refusal owns nothing, so it yields to them: a stretch is owned by what the user\n * sees there.\n */\n readonly drawnBesides: (s: EdgeSpec) => readonly Rect[];\n}\n\nconst bandOf = (s: EdgeSpec): Rect => {\n const a = Math.min(...s.zones.map((z) => z.a));\n const b = Math.max(...s.zones.map((z) => z.b));\n return s.vertical ? rect(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);\n};\n\n/** What it owns: its band, limited along it where it owns less than its zones (a column line's place). */\nconst ownedRectOf = (s: EdgeSpec): Rect => {\n const b = bandOf(s);\n if (!s.ownedAlong) return b;\n const [a0, a1] = s.ownedAlong;\n return s.vertical ? rect(b.x, a0, b.width, a1 - a0) : rect(a0, b.y, a1 - a0, b.height);\n};\n\n/**\n * What an edge owns against the others: its owned rect along the stretches its surviving slots tile, `along` (from the\n * edge tiled on its own, before any other edge cuts it). A stretch with no slot of its own, a refused slot's, a zone\n * whose every slot the filter removes, and home's (owned on its own) own nothing; its drawn rect still counts, as\n * every drawn rect does.\n */\nfunction ownedRectsOf(s: EdgeSpec, along: readonly Span[]): Rect[] {\n if (along.length === 0) return [];\n const o = ownedRectOf(s);\n if (s.ownedAlong) return [o];\n return along.map(([a, b]) => (s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height)));\n}\n\n/** Every edge's seen rect, with the spec the tiler reads it by (null for an edge it doesn't read). */\nfunction drawnOf(c: Ctx, live: readonly EdgeSpec[]): { spec: EdgeSpec | null; rect: Rect; lay: LayKey }[] {\n return Object.entries(c.now.edges)\n .filter(([id, e]) => area(e.rect) > EPS && c.lay.has(id))\n .map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id)! }));\n}\n\n/**\n * Home's tile: the item's own rect and, along it, its edge's band (the own interval across the band). Where the lift\n * deletes its edge (the item alone in its column), the edge collapses into home: its whole seen rect. Null for a\n * floating item.\n */\nexport function homeRectOf(c: Ctx, ownSpec: EdgeSpec | null): Rect | null {\n const own = c.now.items[c.dragged];\n if (!own || own.floating || !own.edge) return null;\n const o = own.rect;\n const hull = (a: Rect, b: Rect): Rect => rect(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));\n if (own.inMenu) return o;\n if (!ownSpec) {\n const e = c.now.edges[own.edge];\n const vanishes = !c.rest.edges.some((x) => x.id === own.edge);\n return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ? hull(o, e.rect) : o;\n }\n const [c0, c1] = ownSpec.across();\n return ownSpec.vertical ? hull(o, rect(c0, o.y, c1 - c0, o.height)) : hull(o, rect(o.x, c0, o.width, c1 - c0));\n}\n\n/** Every owner: home first, then each edge the tiler reads, then every drawn rect. */\nfunction ownersOf(c: Ctx, live: readonly EdgeSpec[], drawn: ReturnType<typeof drawnOf>, alongOf: (s: EdgeSpec) => readonly Span[]): Owner[] {\n const ownEdge = c.now.items[c.dragged]?.edge;\n const ownSpec = (ownEdge && live.find((s) => s.edge?.id === ownEdge)) || null;\n const homeRect = homeRectOf(c, ownSpec);\n return [\n // Home first: its tile is its own, for every edge but its own (which tiles it as its own interval).\n ...(homeRect ? [{ spec: ownSpec, rect: homeRect, lay: { phase: -1, side: \"\", at: -Infinity }, place: false }] : []),\n // Every edge the tiler reads, along each zone with a slot the filter keeps: what it owns, drawn or a band of its\n // place (a column line's band about its line). A zone whose every slot is refused owns nothing against the others\n // (its drawn rect still counts, below).\n ...live.flatMap((s) => ownedRectsOf(s, alongOf(s)).map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }))).filter((o) => area(o.rect) > EPS),\n // Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.\n ...drawn.map((d) => ({ ...d, place: false })),\n ];\n}\n\n/**\n * `alongOf(spec)`: the stretches along each edge its surviving slots tile, from the edge tiled on its own (see\n * `ownedRectsOf`).\n */\nexport function ownership(c: Ctx, live: readonly EdgeSpec[], alongOf: (s: EdgeSpec) => readonly Span[]): Ownership {\n const { scene, now, dragged } = c;\n const drawn = drawnOf(c, live);\n const owners = ownersOf(c, live, drawn, alongOf);\n const wins = (o: Owner, s: EdgeSpec): boolean => {\n if (o.spec === s) return false;\n if (pushes(o.lay, s.lay)) return true;\n if (pushes(s.lay, o.lay)) return false;\n const place = !s.drawn;\n return o.place === place ? !place || o.lay.at < s.lay.at : !o.place;\n };\n // What each edge yields: the owners that win over it; a virtual edge (a column line) also every other owner's rect\n // outside its own band, where its tile is overreach.\n const taken = new Map<EdgeSpec, readonly Rect[]>(\n live.map((s) => [\n s,\n [\n ...owners.filter((o) => wins(o, s)).map((o) => o.rect),\n ...(EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.spec !== s && !wins(o, s)).flatMap((o) => subtract(o.rect, ownedRectOf(s))) : []),\n ],\n ]),\n );\n // Half the hit band of an edge's panels, or null where they are split in halves (`hitBand: \"middle\"`, no body).\n const halfBandOf = (e: Edge): number | null => {\n const bandOpt = hitBandOf(scene, e);\n return bandOpt === \"middle\" ? null : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND) / 2;\n };\n // Panel bodies (an open item's), but for `hitBand / 2` at each end: no drop place of their edge.\n const bodySpans = (e: Edge | null): Span[] => {\n const half = e ? halfBandOf(e) : null;\n if (!e || half === null) return [];\n const column = axisOf(e.side) === \"column\";\n return Object.entries(now.items)\n .filter(([iid, p]) => p.edge === e.id && p.formKind === \"open\" && iid !== dragged)\n .map(([, p]): Span => (column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]))\n .filter(([a, b]) => b - a > EPS);\n };\n // A zone's room: less the stretches where the owners that win over its edge together hold the edge's whole depth (a\n // thinner owner, an empty rail's band over a column, clips its tiles instead). Under 1 px of depth left is none: a\n // sub-pixel strip between two owners (an empty bar's zones, split where the bar's thirds fall) is no room, so no slot\n // lands its tile there. Panel bodies are no drop place, but they don't split the room: the tiles run across them and\n // clipping takes them out (`bodies`), so a card's band beside the item's own place meets the nearest slot past it.\n // A body cuts only beyond half a band of each slot's line, the line where the room puts it: a line under another\n // edge's owned band (the first gap of a column under an empty bar's place band) lies at that band's far side, and its\n // half band reaches into the body from there.\n const rooms = new Map<EdgeSpec, Room>();\n const cutsOf = (s: EdgeSpec): Room => {\n let room = rooms.get(s);\n if (!room) rooms.set(s, (room = roomOf(s)));\n return room;\n };\n const roomOf = (s: EdgeSpec): Room => {\n const b = bandOf(s);\n const along = (r: Rect): Span => (s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width]);\n const across = (r: Rect): Span => (s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height]);\n const rs = taken.get(s)!.filter((r) => overlaps(r, b));\n const ends = [...new Set([...along(b), ...rs.flatMap(along)])].filter((x) => x >= along(b)[0] && x <= along(b)[1]).sort((p, q) => p - q);\n const owned: Span[] = [];\n for (let k = 1; k < ends.length; k++) {\n const [u, w] = [ends[k - 1]!, ends[k]!];\n const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across);\n if (w - u > EPS && less([across(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);\n }\n const half = s.edge ? halfBandOf(s.edge) : null;\n const raw = bodySpans(s.edge);\n if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };\n const merged = owned.reduce<[number, number][]>((m, [u, w]) => {\n const last = m[m.length - 1];\n if (last && u <= last[1] + EPS) last[1] = Math.max(last[1], w);\n else m.push([u, w]);\n return m;\n }, []);\n const [lo, hi] = along(b);\n const placed = (p: number): number => {\n const cut = merged.find(([u, w]) => p >= u - EPS && p <= w + EPS);\n if (!cut) return p;\n const sides = [...(cut[0] > lo + EPS ? [cut[0]] : []), ...(cut[1] < hi - EPS ? [cut[1]] : [])];\n return sides.length === 0 ? p : sides.reduce((m, x) => (Math.abs(x - p) < Math.abs(m - p) ? x : m));\n };\n const bands = s.slots.map((sl): Span => [placed(sl.line) - half, placed(sl.line) + half]);\n return { cuts: owned, bodies: less(raw, bands) };\n };\n const grows = (id: string): boolean => {\n const it = now.items[id]!;\n const e = it.edge ? now.edges[it.edge] : undefined;\n return !!e && !!formsOf(scene.items[id]!, axisOf(e.side))[it.form]?.main.grows;\n };\n const solid = Object.entries(now.items).filter(([id, it]) => it.fixed && !grows(id)).map(([, it]) => it.rect);\n // Panel bodies (an open item's), but for `hitBand / 2` at each end, aren't drop places of their edge.\n // Nor are its fixed items' reserved rects (a growing title's natural rect): each cut across the edge's whole band.\n const bodies = (s: EdgeSpec): Rect[] => {\n const e = s.edge;\n if (!e) return [];\n const column = axisOf(e.side) === \"column\";\n const across = (a: number, b: number): Rect => (column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9));\n const reserved = Object.entries(now.items)\n .filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid))\n .map(([, p]) => (column ? across(p.rect.y, p.rect.y + p.rect.height) : across(p.rect.x, p.rect.x + p.rect.width)));\n return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across(a, b))].filter((b) => area(b) > EPS);\n };\n const drawnBySpec = new Map<EdgeSpec, Rect[]>();\n const drawnBesides = (s: EdgeSpec): Rect[] => {\n let rs = drawnBySpec.get(s);\n if (!rs) drawnBySpec.set(s, (rs = drawn.filter((d) => d.spec !== s).map((d) => d.rect)));\n return rs;\n };\n return { owners, taken, cutsOf, bodies, solid, drawnBesides };\n}\n","/**\n * Tiles: each edge's zones split into its slots' tiles (`tileEdge`), then clipped in precedence order (`clipTiles`):\n * each clear of the tiles before it, of what outranks its edge, of the fixed items that don't grow and of the chrome.\n */\nimport { EPS, area, rect, subtract, type Point, type Rect } from \"../../geometry\";\nimport { zoneOf } from \"../helpers\";\nimport { ZONES, type SceneLayout, type Zone } from \"../model\";\nimport { distinctSlots } from \"./edges\";\nimport { targetId } from \"./ids\";\nimport { EDGE_KINDS } from \"./kinds\";\nimport { less, type Ctx, type EdgeSpec, type Room, type SceneRefusal, type Slot, type Span, type Tile } from \"./model\";\nimport type { Ownership } from \"./ownership\";\n\n/** How one edge makes its tiles: its band, the point a tile keeps, and a tile's split into owned part and overreach. */\ninterface Tiler {\n readonly band: (a: number, b: number, after?: SceneLayout) => Rect;\n readonly keepAt: (line: number, h: Rect) => Point;\n readonly tile: (zone: Zone, hit: Rect, more: Pick<Tile, \"kind\" | \"id\" | \"order\" | \"priority\" | \"keep\"> & Partial<Tile>) => Tile;\n readonly split: (t: Tile) => Tile[];\n}\n\nfunction tilerOf(spec: EdgeSpec): Tiler {\n const data = EDGE_KINDS[spec.kind];\n const v = spec.vertical;\n const band = (a: number, b: number, after?: SceneLayout): Rect => {\n const [c0, c1] = spec.across(after);\n return v ? rect(c0, a, c1 - c0, b - a) : rect(a, c0, b - a, c1 - c0);\n };\n // The point a tile keeps through clipping: on its line, in the middle of its band across.\n const keepAt = (line: number, h: Rect): Point => (v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 });\n const tile: Tiler[\"tile\"] = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });\n // A tile's part across that its edge owns, and the rest, its overreach: clipped after the virtual edges, then joined\n // back where it still meets the owned part whole.\n const split = (t: Tile): Tile[] => {\n const h = t.hit;\n const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];\n const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];\n const part = (a: number, b: number): Rect => (v ? rect(a, h.y, b - a, h.height) : rect(h.x, a, h.width, b - a));\n const beyond = less([[h0, h1]], [spec.owned]);\n if (beyond.length === 0) return [t];\n if (c1 - c0 <= EPS) return [{ ...t, order: data.overreach }];\n const core: Tile = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };\n return [core, ...beyond.map(([a, b]): Tile => ({ ...t, kind: \"reach\", of: core, order: data.overreach, hit: part(a, b), keep: null }))];\n };\n return { band, keepAt, tile, split };\n}\n\n/** The part two rects share, or null when it has no area. */\nfunction meet(a: Rect, b: Rect): Rect | null {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n const w = Math.min(a.x + a.width, b.x + b.width) - x;\n const h = Math.min(a.y + a.height, b.y + b.height) - y;\n return w > EPS && h > EPS ? rect(x, y, w, h) : null;\n}\n\n/**\n * An edge that takes the dragged kind in no zone refuses it outright: one refusal (`refuse:<edge>:start`, `n = 0`) over\n * the edge's drawn rect (`SceneLayout.edges[id].rect`, fixed items included), in the stage. Clipping cuts only what the\n * targets own from it, and a rail drop strip still takes its own rect. Null for any other edge (a zone that takes the\n * kind, an edge not drawn, the item's own edge).\n */\nfunction wholeRefusal(c: Ctx, spec: EdgeSpec): Tile | null {\n if (!spec.edge || spec.own || spec.holds || ZONES.some((z) => spec.refuse(z) !== \"not-accepted\")) return null;\n const drawn = c.now.edges[spec.id]?.rect;\n const hit = drawn ? meet(drawn, c.scene.stage) : null;\n if (!hit) return null;\n const data = EDGE_KINDS[spec.kind];\n return { edge: spec.id, spec, edgeKind: spec.kind, vertical: spec.vertical, zone: \"start\", hit, kind: \"refuse\", id: \"\", order: data.layer, priority: data.priority, keep: null, reason: \"not-accepted\", whole: true };\n}\n\n/** Whether `spans` keep any length past `away`. */\nconst hasRoom = (spans: readonly Span[], away: readonly Span[]): boolean => less(spans, away).some(([a, b]) => b - a > EPS);\n\n/** Where each slot's line lies in one free piece of a zone: projected into it, or spread in order when lines collide. */\nfunction linesIn(spec: EdgeSpec, z: { a: number; b: number }, mine: readonly Slot[], pieces: readonly Span[], [pa, pb]: Span, own: Span | null): { inPiece: Slot[]; at: number[] } {\n const reserved = spec.reserved;\n // Lines spread into the zone's extent less its reserved rects when they lie past it: their share of the span the lines\n // and the extent cover, laid along the extent's free pieces end to end.\n const lines = mine.map((s) => s.line);\n const lo = Math.min(z.a, ...lines);\n const hi = Math.max(z.b, ...lines);\n const free = less([[z.a, z.b]], reserved);\n const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);\n const spread = (x: number): number => {\n if (hi - lo <= EPS || freeLen <= EPS) return x;\n let d = ((x - lo) / (hi - lo)) * freeLen;\n for (const [a, b] of free) {\n if (d <= b - a + EPS) return a + Math.min(d, b - a);\n d -= b - a;\n }\n return free[free.length - 1]![1];\n };\n // A line inside the own interval (an empty zone's anchor under the item) goes to the interval's nearer end. Lines\n // inside the extent stay where they are, one inside a reserved rect going to its nearer end.\n const past = lines.some((x) => x < z.a - EPS || x > z.b + EPS);\n const nearer = (p: number, [a, b]: Span): number => (p > a && p < b ? (p - a < b - p ? a : b) : p);\n // A line left outside the zone's pieces (under what another edge owns) goes to the nearest point of one.\n const proj = (x: number): number => {\n const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);\n const p = own ? nearer(q, own) : q;\n if (pieces.some(([a, b]) => p >= a - EPS && p <= b + EPS)) return p;\n return pieces.map(([a, b]) => Math.min(Math.max(p, a), b)).reduce((m, y) => (Math.abs(y - p) < Math.abs(m - p) ? y : m));\n };\n // Home's lines are the own interval's ends: each is a line only in the piece it bounds, never projected into another\n // (where it would fall on the other end's point and spread the piece's lines evenly).\n const ownEnd = (s: Slot): boolean => !!own && s.home && (Math.abs(s.line - own[0]) < EPS || Math.abs(s.line - own[1]) < EPS);\n const inPiece = mine\n .filter((s) => (ownEnd(s) ? s.line >= pa - EPS && s.line <= pb + EPS : proj(s.line) >= pa - EPS && proj(s.line) <= pb + EPS))\n .sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);\n // Where projection lays two different moves on one point (lines under the item's home or another edge's), the piece's\n // lines are laid out in their order along it instead, one share each.\n const projected = inPiece.map((s) => proj(s.line));\n const at = projected.some((p, i) => i > 0 && p - projected[i - 1]! <= EPS) ? inPiece.map((_, i) => pa + ((i + 0.5) * (pb - pa)) / inPiece.length) : projected;\n return { inPiece, at };\n}\n\n/**\n * One edge's tiles, every kind alike: each zone's extent less the item's own interval, split halfway between its slots'\n * lines (projected into it), a slot's tile reaching at most its kind's `reach` from its line. A stretch with no slot is\n * refused (`spec.refuse`), a slot the filter removed is refused over its own tile, and the own interval is home's\n * (across, the edge's band and the own rect), named after the home slot when there is one. Where the item has no rect\n * on the edge, home's tile is its slot's.\n */\nexport function tileEdge(c: Ctx, spec: EdgeSpec, { cuts, bodies }: Room, lost: string[]): Tile[] {\n const whole = wholeRefusal(c, spec);\n if (whole) return [whole];\n const data = EDGE_KINDS[spec.kind];\n const v = spec.vertical;\n const own: Span | null = spec.own ? (v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width]) : null;\n const { band, keepAt, tile, split } = tilerOf(spec);\n // A zone's refusal keeps its slot's geometry, but never past the edge's ends (no `endReach`) nor past the stage.\n const drawn = spec.edge ? c.now.edges[spec.id]?.rect : undefined;\n const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS ? (v ? rect(-1e9, drawn.y, 2e9, drawn.height) : rect(drawn.x, -1e9, drawn.width, 2e9)) : null;\n const refused = (zone: Zone, hit: Rect, reason: SceneRefusal[\"reason\"]): Tile[] => {\n const inEdge = alongLimit ? meet(hit, alongLimit) : hit;\n const shown = inEdge && meet(inEdge, c.scene.stage);\n return shown ? split(tile(zone, shown, { kind: \"refuse\", id: \"\", order: data.layer, priority: data.priority, keep: null, reason })) : [];\n };\n const slots = distinctSlots(c, spec.slots);\n // The edge's reserved spans merged where they touch: a line strictly inside one is wedged between fixed items.\n const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce<Span[]>((acc, [a, b]) => {\n const last = acc[acc.length - 1];\n if (last && a <= last[1] + EPS) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];\n else acc.push([a, b]);\n return acc;\n }, []);\n const wedged = (line: number): boolean => runs.some(([a, b]) => line > a + EPS && line < b - EPS);\n // Home's slot where the item lies on this edge: its order is the aim that puts the item back.\n const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== undefined) : undefined;\n const out: Tile[] = [];\n for (const z of spec.zones) {\n // The zone's extent less its reserved rects and what other edges own: a zone left with nothing has no slot.\n const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS);\n // Less the own interval, which home owns: a zone wholly under the item's own place has no room left either.\n const pieces = own ? less(room, [own]) : room;\n // Panel bodies don't split the pieces (the tiles run across them, clipping takes them out), but a zone whose room\n // is all bodies has no drop place.\n if (!hasRoom(pieces, bodies)) continue;\n // A slot with no room within its kind's reach of its line isn't offered.\n // On the item's own edge the home slot's line is the own interval itself: it lies at both of its ends, so the gaps\n // right beside the item (the same move as home) are home's. In its » menu the item has no interval: home is only\n // its entry.\n const lined = slots.flatMap((s) => (spec.holds && s.home ? (own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : []) : [s]));\n // A slot whose line lies between two fixed items (inside a run of reserved spans, not at its ends) has no place a\n // pointer can aim at: a drop there would push fixed items the pointer never sees apart. It gets no tile, so its\n // order's stretch beside the run stays with the slot at the run's end (the card's leading half is \"before it\").\n const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS && a < s.line + data.reach - EPS));\n const reason = spec.refuse(z.zone);\n for (const [pa, pb] of pieces) {\n const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);\n if (inPiece.length === 0) {\n // A stretch of a zone with no slot of its own is refused: home is only over the item's own place, and no stretch\n // is handed to another zone's slot. Beside a lone item (the zone's only slot is home) there is room, but no\n // place other than its own: `own-place`.\n // A stretch out of every slot's reach is no part of this edge.\n const lone = reason === \"no-room\" && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);\n // (A virtual edge's zone is its slot's reach already: all of it is near.)\n const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS && pa < s.line + data.reach - EPS);\n // A virtual edge's stretch cut off from its line by another edge's owned band (the rail stop between a column\n // line and the window's inset) is still that line's: there is room and a slot, so it is no refusal. It joins the\n // nearest fitting slot of the zone as one more piece of its tile (the zone's extent already bounds it).\n const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];\n if (joins.length > 0) {\n const s = joins.reduce((m, x) => (Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m));\n const hit = band(pa, pb, s.result.layout);\n out.push(...split(tile(z.zone, hit, { kind: \"slot\", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(Math.min(Math.max(s.line, pa), pb), hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged]!.rect })));\n continue;\n }\n if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? \"own-place\" : reason));\n continue;\n }\n // Where two neighboring slots meet: at the midpoint of the item between their lines (the one item a pointer\n // aims at there: its leading half is the place before it, its trailing half the place after it), else halfway\n // between the lines.\n // (The item lies between the lines as seen, before projection: a line past the piece, under another edge's band,\n // still bounds it.)\n const meet = (i: number): number => {\n const [lo, hi] = [at[i - 1]!, at[i]!];\n const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1]!.line - EPS && w <= inPiece[i]!.line + EPS);\n const mid = between.length === 1 ? (between[0]![0] + between[0]![1]) / 2 : NaN;\n return mid > lo + EPS && mid < hi - EPS ? mid : (lo + hi) / 2;\n };\n inPiece.forEach((s, i) => {\n // The meeting points with the neighboring slots, the piece's ends at its ends (the own interval's ends are one),\n // and no further from its line than the kind's reach (a virtual edge's zone is that reach already: an outermost\n // column line's zone runs from the window's edge, past where the line's reach would end).\n const p = at[i]!;\n const lim = data.virtual ? Infinity : data.reach;\n const a = Math.max(i === 0 ? pa : meet(i), p - lim);\n const b = Math.min(i === inPiece.length - 1 ? pb : meet(i + 1), p + lim);\n if (b - a <= EPS) {\n if (s.ok && !s.home) lost.push(s.id);\n return;\n }\n // A tile wholly over panel bodies has no drop place: the slot has no room here, so it isn't offered.\n if (!hasRoom([[a, b]], bodies)) return;\n const homeTile = (id: string, u: number, w: number, line: number): Tile => {\n const hit = band(u, w, s.home ? s.result.layout : undefined);\n return tile(z.zone, hit, { kind: \"home\", id, order: data.layer, priority: data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: \"home\" } });\n };\n if (s.home) {\n out.push(...split(homeTile(s.id, a, b, p)));\n return;\n }\n // A slot of home's order in another zone is the same aim as home over the items it faces: their halves are\n // home's; the rest of its tile, the free stretch beside them, is its own (the item re-aligned, its order kept).\n const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS && u < b - EPS) : [];\n for (const [u, w] of faced) out.push(...split(homeTile(homeSlot!.id, Math.max(u, a), Math.min(w, b), p)));\n for (const [u, w] of less([[a, b]], faced)) {\n const line = Math.min(Math.max(p, u), w);\n const hit = band(u, w, s.result.layout);\n if (!s.ok) out.push(...refused(z.zone, hit, \"no-room\"));\n else out.push(...split(tile(z.zone, hit, { kind: \"slot\", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged]!.rect })));\n }\n });\n }\n }\n if (own && spec.own) {\n const home = spec.slots.find((s) => s.home);\n // Across the edge's band and the own rect where it lies now: home's wherever the lift moves things (nothing clips\n // it). A slot's id and priority; `home:<id>` (1) when no slot is home.\n const [a, b] = own;\n const h = band(a, b);\n const o = spec.own;\n const hit = v ? rect(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));\n out.push(tile(home?.zone ?? zoneOf(c.scene.items[c.dragged]), hit, { kind: \"home\", id: home ? home.id : targetId({ kind: \"home\", item: c.dragged }), order: 0, priority: home ? data.priority : 1, keep: null, place: { kind: \"home\" } }));\n }\n return out;\n}\n\nconst clip = (r: Rect, cuts: readonly Rect[]): Rect[] => cuts.reduce<Rect[]>((ps, cut) => ps.flatMap((p) => subtract(p, cut)), [r]);\n/** Every rect a placed tile covers: its pieces, else its hit. */\nconst coverOf = (t: Tile): readonly Rect[] => t.hits ?? [t.hit];\nconst largest = (ps: readonly Rect[]): Rect => ps.reduce((a, p) => (area(p) > area(a) ? p : a));\n/** `t` with these pieces: `hit` the largest, `hits` all of them when there is more than one. */\nconst withPieces = (t: Tile, ps: readonly Rect[]): Tile => {\n const { hits: _h, ...rest } = t;\n return { ...rest, hit: largest(ps), ...(ps.length > 1 ? { hits: ps } : {}) };\n};\n\n/** An overreach tile `t` placed: joined to its owned part where it meets that part whole, or standing in for it. */\nfunction placeReach(t: Tile, pieces: readonly Rect[], placed: Tile[], landed: ReadonlyMap<Tile, number[]>, gone: Set<Tile>): void {\n const of = t.of!;\n const at = landed.get(of) ?? [];\n if (at.length === 0 && gone.has(of)) {\n // Its owned part went whole: the overreach stands in for it, the piece on its line (else its largest).\n const line = t.vertical ? of.keep!.y : of.keep!.x;\n const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);\n const on = whole.filter((p) => (t.vertical ? p.y <= line + EPS && line <= p.y + p.height + EPS : p.x <= line + EPS && line <= p.x + p.width + EPS));\n const kept = (on.length > 0 ? on : whole).reduce<Rect | null>((a, p) => (!a || area(p) > area(a) ? p : a), null);\n if (kept) {\n placed.push({ ...of, hit: kept });\n gone.delete(of);\n }\n return;\n }\n for (const i of at) {\n // Joined to the first piece of the owned part it meets along that piece's whole length.\n const cover = coverOf(placed[i]!);\n for (let k = 0; k < cover.length; k++) {\n const h = cover[k]!;\n const joint = pieces.find((p) =>\n t.vertical\n ? p.y <= h.y + EPS && p.y + p.height >= h.y + h.height - EPS && (Math.abs(p.x - h.x - h.width) < EPS || Math.abs(p.x + p.width - h.x) < EPS)\n : p.x <= h.x + EPS && p.x + p.width >= h.x + h.width - EPS && (Math.abs(p.y - h.y - h.height) < EPS || Math.abs(p.y + p.height - h.y) < EPS),\n );\n if (!joint) continue;\n const merged = t.vertical\n ? rect(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height)\n : rect(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));\n placed[i] = cover.length > 1 ? withPieces(placed[i]!, cover.map((r, j) => (j === k ? merged : r))) : { ...placed[i]!, hit: merged };\n return;\n }\n }\n}\n\n/** A refused tile, or the overreach of one. */\nconst isRefused = (t: Tile): boolean => t.kind === \"refuse\" || (t.kind === \"reach\" && t.of!.kind === \"refuse\");\n\n/**\n * Filter (iii), clipping in precedence order: each tile clear of the ones before it, of the other edges' seen rects, of\n * the fixed items that don't grow and of the chrome. Returns the tiles placed;\n * slots whose every part went are added to `lost`.\n *\n * A slot the filter removed owns nothing against other edges: every surviving tile is placed first, in precedence\n * order, and the refused tiles (with their overreach and the clipped-off pieces of slots) then take what is left, in\n * the same order. Within its own edge a refusal keeps its tile: an edge's tiles never overlap each other.\n */\nexport function clipTiles(tiles: readonly Tile[], own: Ownership, chrome: readonly Rect[], lost: string[]): Tile[] {\n const { owners, taken, bodies, solid } = own;\n /** Every other edge's owned rects: what a refusal (which owns nothing) and an overreach yield to. */\n const bySpec = new Map<EdgeSpec | null, Rect[]>();\n const others = (t: Tile): Rect[] => {\n let rs = bySpec.get(t.spec);\n if (!rs) bySpec.set(t.spec, (rs = owners.filter((o) => o.spec !== t.spec).map((o) => o.rect)));\n return rs;\n };\n const besides = (t: Tile): readonly Rect[] => (t.spec ? own.drawnBesides(t.spec) : []);\n const bodiesOf = (t: Tile): Rect[] => (t.spec ? bodies(t.spec) : []);\n const placed: Tile[] = [];\n // A virtual edge's refused stretches (its refused slots, its slots' clipped-off pieces) come after every other tile:\n // they take only what no tile takes, never a real edge's room.\n const later: Tile[] = [];\n // A real edge's refused stretches, placed once every surviving tile is.\n const refused: Tile[] = tiles.filter(isRefused);\n // Where each owned part landed in `placed` (its overreach joins it there), and the slots whose owned part went whole.\n const landed = new Map<Tile, number[]>();\n const gone = new Set<Tile>();\n const place = (t: Tile): void => {\n // Home's tile is the item's own place: nothing clips it.\n if (t.order === 0) {\n placed.push(t);\n return;\n }\n // A wholly refused edge: its drawn rect less only what is placed (the targets, and refusals placed before it), one\n // refusal with every piece of 1 px and more each way (`hits`, `hit` the largest): a target in the middle of a bar\n // leaves the refusal on both sides of it.\n if (t.whole) {\n const pieces = clip(t.hit, placed.flatMap(coverOf)).filter((p) => p.width >= 1 && p.height >= 1);\n if (pieces.length > 0) placed.push(withPieces(t, pieces));\n return;\n }\n const data = EDGE_KINDS[t.edgeKind];\n if (data.virtual && t.kind === \"refuse\") {\n later.push(t);\n return;\n }\n if (t.kind === \"reach\") {\n // Overreach: what the virtual edges and every other edge's owned rect leave, joined to its owned part where it\n // meets that part along the part's whole length. The rest is nobody's (the float's).\n placeReach(t, clip(t.hit, [...placed.flatMap(coverOf), ...others(t), ...bodiesOf(t), ...solid, ...chrome]), placed, landed, gone);\n return;\n }\n // An owned part: clear of the tiles before it, of the owners that win over its edge, its panel bodies, solid items\n // and chrome. A virtual edge's tile: clear of the tiles before it and of every owner. A refusal owns nothing: it\n // yields to every other edge's owned rect too.\n const yields = t.kind === \"refuse\" ? besides(t) : [];\n // Panel bodies are no drop places: they cut slots' tiles, never refusals (an edge that takes nothing, a thumbnail\n // strip, refuses its whole seen rect).\n const cuts = [...placed.flatMap(coverOf), ...((t.spec && taken.get(t.spec)) ?? []), ...yields, ...(data.virtual || t.kind === \"refuse\" ? [] : bodiesOf(t)), ...solid, ...chrome];\n const pieces = clip(t.hit, cuts);\n if (pieces.length === 0) {\n if (t.kind !== \"refuse\") gone.add(t);\n return;\n }\n if (t.kind === \"refuse\") {\n landed.set(t, pieces.map((_, k) => placed.length + k));\n for (const p of pieces) placed.push({ ...t, hit: p });\n return;\n }\n // Clipping changes a slot's shape, never who owns the stretch: whatever is left of its tile stays the slot's, every\n // piece (`hits`, `hit` the largest), so clipping never leaves a hole the float fills nor a refusal in the slot's room.\n // No sliver, after ownership: a piece under 1 px either way is no part of a target (it is refused), and a slot left\n // with no other piece is no target. Under 1 px is no room (as in a zone's room), so the slot isn't lost: its line\n // lay where its neighbors left it no place.\n const solidPieces = pieces.filter((p) => p.width >= 1 && p.height >= 1);\n for (const p of pieces) if (!solidPieces.includes(p)) (data.virtual ? later : refused).push({ ...t, kind: \"refuse\", reason: \"no-room\", hit: p, keep: null });\n if (solidPieces.length === 0) return;\n landed.set(t, [placed.length]);\n placed.push(withPieces(t, solidPieces));\n };\n const byOrder = (a: Tile, b: Tile): number => a.order - b.order;\n for (const t of tiles.filter((x) => !isRefused(x)).sort(byOrder)) place(t);\n for (const t of refused.sort(byOrder)) place(t);\n // Home is never lost: its own rect carries it.\n for (const t of gone) if (t.kind !== \"home\") lost.push(t.id);\n for (const t of later) for (const p of clip(t.hit, [...placed.flatMap(coverOf), ...besides(t), ...solid, ...chrome])) placed.push({ ...t, hit: p });\n return placed;\n}\n","/**\n * Generation, the virtual edges of a side: its column lines (a new column on each, along x) and its rail (docking\n * folded into it, along y), tiled as every edge is.\n */\nimport { EPS, RAIL_EDGE, clamp, rect, type Rect } from \"../../geometry\";\nimport { sideRings } from \"../changes\";\nimport { isHandFolded } from \"../helpers\";\nimport type { Edge } from \"../model\";\nimport { slotAt } from \"./edges\";\nimport { targetId, virtualEdgeId } from \"./ids\";\nimport { EDGE_KINDS } from \"./kinds\";\nimport type { Ctx, EdgeSpec, SceneAfter, Span } from \"./model\";\n\n/**\n * A side's rings as a place counts them, with the item lifted, for lines that lie in the seen geometry: `before(e)`,\n * just outside the seen edge `e`; `after(e)`, just inside it. The item's own column, which the lift deletes, counts\n * no ring: both lines about it are one place (home's).\n */\nfunction ringsOf(c: Ctx, side: \"left\" | \"right\"): { before: (e: Edge) => number; after: (e: Edge) => number; count: number } {\n const seen = sideRings(c.scene.edges, side);\n const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);\n const at = (e: Edge): number => seen.get(e.id) ?? e.ring;\n return { before: (e) => kept.filter((r) => r < at(e)).length, after: (e) => kept.filter((r) => r <= at(e)).length, count: kept.length };\n}\n\n/**\n * Where the side's undrawn rail stop starts, across: the window's edge (an inset's strip included), or, with drawn edges\n * of the side lying outside the rail's place (its outside bars), the rail place's outer side, flush after them.\n */\nexport function railOuter(c: Ctx, side: \"left\" | \"right\"): number {\n const { now, scene } = c;\n const place = now.railPlaces[side];\n const windowEdge = side === \"left\" ? scene.stage.x : scene.stage.x + scene.stage.width;\n if (!place) return windowEdge;\n const placeOuter = side === \"left\" ? place.x : place.x + place.width;\n const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === \"left\" ? e.rect.x + e.rect.width <= placeOuter + EPS : e.rect.x >= placeOuter - EPS));\n return barOutside ? placeOuter : windowEdge;\n}\n\n/**\n * The one rule for \"collapse it at this side\": whether a drop's result has the item folded by hand and drawn at `side`,\n * wherever the scene's `handFold` shows a collapsed panel there (a tile in a rail, a rider bar over the side's first\n * open column, a header in its column); not home, and the window fits. The rail strip and an occupied rail's stops\n * both land by it.\n */\nexport function collapsesAt(c: Ctx, result: SceneAfter, side: \"left\" | \"right\"): boolean {\n const me = result.layout.items[c.dragged];\n if (!me || me.floating || me.inMenu || !isHandFolded(result.scene, c.dragged) || c.isHome(result) || !c.sound(result.layout)) return false;\n const sideOf = (edgeId: string | undefined): string | undefined => (edgeId ? result.layout.edges[edgeId]?.side : undefined);\n return me.rail === side || sideOf(me.rides) === side || sideOf(me.edge) === side;\n}\n\n/**\n * The side's column lines as an edge (virtual, along x): a slot on each line for a new column there, tiled as every\n * edge is (its kind's `reach` each way at most), down the columns' stretch. The lines lie where the user sees the\n * columns; each counts its ring with the item lifted.\n */\nexport function columnLines(c: Ctx, side: \"left\" | \"right\", railLands: boolean): EdgeSpec[] {\n const { scene, now, dragged } = c;\n const cols = scene.edges\n .filter((e) => e.side === side && e.column === true)\n .map((edge) => ({ edge, l: now.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 const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);\n const span = own[0]?.rect ?? now.content;\n // Rings as the side's edges lie (no ties): a static edge outer to the columns keeps its place.\n const rings = ringsOf(c, side);\n // Each line with the place a new column there would take in `solve`'s laying order: just before the column it lies\n // outside of (which it would push), just after the innermost (or every edge of the side, with no column).\n const lines: { x: number; ring: number; at: 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 const atOf = (e: Edge): number => c.lay.get(e.id)?.at ?? 0;\n cols.forEach((x) => lines.push({ x: outerX(x.r), ring: rings.before(x.edge), at: atOf(x.edge) - 0.5 }));\n if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1]!.r), ring: rings.after(cols[cols.length - 1]!.edge), at: atOf(cols[cols.length - 1]!.edge) + 0.5 });\n else lines.push({ x: side === \"left\" ? now.content.x : now.content.x + now.content.width, ring: rings.count, at: Math.max(-1, ...scene.edges.filter((e) => e.side === side).map(atOf)) + 0.5 });\n // A new column lands where it shows open.\n const lands = (r: SceneAfter): boolean => {\n const me = r.layout.items[dragged]!;\n const el = me.edge ? r.layout.edges[me.edge] : undefined;\n return !!el && !me.inMenu && !el.folded && !el.rides && r.scene !== c.scene;\n };\n const { reach, place, edgePlace } = EDGE_KINDS.columnLine;\n // No column line's zone lies past the stage. The outermost line, with no drawn edge outside it, at the window's edge\n // (a flush window) or where the rail stop lies (the side's outer boundary): its band can't be centered there, half of\n // it past the stage or under the rail stop. It is laid inward instead, its zone running from the window's edge (an\n // inset's strip included): the rail stop keeps `RAIL_EDGE` px at the boundary (where an undrawn rail would land), the\n // line's band of `edgePlace` px follows it inward, and its tile reaches `reach` px on from the band's middle.\n const stage = c.scene.stage;\n const dir = side === \"left\" ? 1 : -1;\n const outside = (x: number): boolean =>\n Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === \"left\" ? e.rect.x + e.rect.width <= x + EPS : e.rect.x >= x - EPS));\n // The rail stop takes its place only when one of its slots lands (`railLands`): a virtual edge with no landing slot\n // owns nothing, so the line is laid from the window's edge then (a panel that would ride over an open column).\n const railFirst = railLands && !!c.scene.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);\n const placeOf = (l: { x: number }, i: number): { line: number; zone: Span; owned: Span } => {\n const atEdge = side === \"left\" ? l.x <= stage.x + EPS : l.x >= stage.x + stage.width - EPS;\n if (i > 0 || outside(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };\n const windowEdge = side === \"left\" ? stage.x : stage.x + stage.width;\n const boundary = clamp(l.x, stage.x, stage.x + stage.width);\n // With the rail first, its stop holds the outer `RAIL_EDGE` px from the side's outer edge (the window's, an inset's\n // strip included): the line's zone and band start where the stop ends. Without one, from the window's edge.\n const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;\n const line = band0 + (dir * edgePlace) / 2;\n const span2 = (a: number, b: number): Span => [Math.min(a, b), Math.max(a, b)];\n return { line, zone: span2(railFirst ? band0 : windowEdge, line + dir * reach), owned: span2(band0, band0 + dir * edgePlace) };\n };\n // One spec per line: a new column's place, owning a band of `place` px about its line (ranked where that column would\n // be laid), its slot's tile reaching `reach` each way past it as overreach.\n return lines.map((l, i) => {\n const p = placeOf(l, i);\n return {\n id: virtualEdgeId(\"column\", side),\n edge: null,\n kind: \"columnLine\" as const,\n lay: { phase: EDGE_KINDS.columnLine.phase, side, at: l.at },\n vertical: false,\n zones: [{ zone: \"start\" as const, a: Math.max(p.zone[0], stage.x), b: Math.min(p.zone[1], stage.x + stage.width) }],\n slots: [slotAt(c, \"start\", p.line, targetId({ kind: \"column\", side, ring: l.ring }), { kind: \"column\", side, ring: l.ring }, lands)],\n refuse: () => \"no-room\" as const,\n own: null,\n holds: false,\n reserved: [],\n cards: [],\n across: (): Span => [span.y, span.y + span.height],\n owned: [span.y, span.y + span.height] as Span,\n ownedAlong: p.owned,\n drawn: false,\n // Where the new column's edge lands: the line itself, inside the stage.\n marker: () => rect(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height),\n };\n });\n}\n\n/**\n * The side's rail as an edge (virtual, along y): a slot before each folded column's segments and after the last, or,\n * with no rail shown, one slot `RAIL_EDGE` px deep where the rail lands (`railPlaces`); tiled as every edge is. The\n * stops lie where the user sees the rail; each counts its ring with the item lifted.\n */\nexport function railStops(c: Ctx, side: \"left\" | \"right\"): EdgeSpec | null {\n const { scene, now, dragged } = c;\n const rail = now.rails[side];\n const placeRect = now.railPlaces[side];\n if (!placeRect) return null;\n const rings = ringsOf(c, side);\n const seenRings = sideRings(scene.edges, side);\n const mine = scene.edges.filter((e) => e.side === side).sort((a, b) => (seenRings.get(a.id) ?? 0) - (seenRings.get(b.id) ?? 0));\n const edgeOf = (id: string): Edge | undefined => mine.find((e) => e.id === id);\n const ringBefore = (id: string): number => {\n const e = edgeOf(id);\n return e ? rings.before(e) : 0;\n };\n const ringAfter = (id: string): number => {\n const e = edgeOf(id);\n return e ? rings.after(e) : 1;\n };\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: ringBefore(g.edge) });\n const last = groups[groups.length - 1]!;\n stops.push({ y: last.y1, ring: ringAfter(last.edge) });\n } else {\n const firstCol = mine.find((e) => e.column === true);\n // The outer `RAIL_EDGE` px from the side's outer edge: the window's (an inset's strip included), or flush after the\n // side's outside bars.\n const outer = railOuter(c, side);\n zone = rect(side === \"left\" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);\n stops.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });\n }\n // Every stop is home while the item is folded here already. A rail that shows (occupied) offers its stops wherever the\n // item ends up collapsed at this side (`collapsesAt`: its tile, or a rider bar when the lifted item's column reopens\n // over it). With no rail shown, a stop is only the item folded into the rail: a thin band that would otherwise take\n // the side's edge from the column line for a panel that rides.\n const ownRail = now.items[dragged]?.rail === side;\n const shown = !!rail && rail.segments.length > 0;\n const lands = (r: SceneAfter): boolean => (shown ? collapsesAt(c, r, side) : r.layout.items[dragged]!.rail === side && r.scene !== c.scene);\n const at = zone;\n return {\n id: virtualEdgeId(\"rail\", side),\n edge: null,\n kind: \"railStop\",\n // The rail lies outside every edge on its side: laid first among them.\n lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },\n vertical: true,\n zones: [{ zone: \"start\", a: at.y, b: at.y + at.height }],\n slots: stops.map((s) => slotAt(c, \"start\", s.y, targetId({ kind: \"rail\", side, ring: s.ring }), { kind: \"rail\", side, ring: s.ring }, lands, ownRail)),\n refuse: () => \"no-room\",\n own: null,\n holds: false,\n reserved: [],\n cards: [],\n across: () => [at.x, at.x + at.width],\n // A drawn rail owns its rect; where none shows, a thin band of its place at the side's outer boundary.\n owned: rail && rail.segments.length > 0 ? [at.x, at.x + at.width] : side === \"left\" ? [at.x, at.x + Math.min(at.width, EDGE_KINDS.railStop.place)] : [at.x + at.width - Math.min(at.width, EDGE_KINDS.railStop.place), at.x + at.width],\n ownedAlong: null,\n drawn: !!rail && rail.segments.length > 0,\n marker: (s) => rect(at.x, s.result.layout.items[dragged]!.rect.y, at.width, 0),\n };\n}\n","/**\n * The rail drop strips (`Scene.railDrop`): for a kind with a policy, each side whose rail can take it gets one drop\n * strip at the window's side, at the rail's width (`railStripWidth`), even while the rail is empty. Its targets,\n * `rail:<side>:<ring>`, are spring-loaded (`arm: \"dwell\"`), grow by `magnet` once armed (`armedHit`) and carry the\n * strip to draw (`strip`). The strip owns its rect: every other target and refusal of the drag gives it up (home's\n * too: an item alone in its column reaches its side's rail through the strip), so a drop there is the rail's once armed\n * and the float's before. A target the strip covers whole isn't offered: over the rail, the kind collapses into it.\n *\n * The side's rail is one concept: `Scene.rails[side]` where the scene declares one (the strip split along it at its\n * stops, `railStops`), else the side's outermost column that takes the kind in its start zone (`railColumnOf`). The\n * strip means \"collapse it at this side\": its drop is `moveTo` that side's rail, landing wherever the scene's hand fold\n * shows a collapsed panel there (a rail tile, a rider bar over the side's open column, a header in its column).\n */\nimport { EPS, overlaps, rect, subtract, type Point, type Rect } from \"../../geometry\";\nimport { moveAmong, use, type RailPlace } from \"../changes\";\nimport { isHandFolded, railColumnOf, railPolicyOf, zoneTakes } from \"../helpers\";\nimport { RAIL_STRIP_MIN } from \"../model\";\nimport { targetId, virtualEdgeId } from \"./ids\";\nimport type { Ctx, SceneAfter, SceneRefusal, SceneTarget } from \"./model\";\nimport { collapsesAt, railOuter, railStops } from \"./virtual\";\n\ntype Policy = NonNullable<ReturnType<typeof railPolicyOf>>;\n\n/** One side's strip and its slots along it, each with its stretch and its drop. */\ninterface Strip {\n readonly side: \"left\" | \"right\";\n readonly rect: Rect;\n readonly slots: readonly { readonly id: string; readonly place: RailPlace; readonly along: readonly [number, number]; readonly result: SceneAfter }[];\n}\n\n/** The strip's x and width: `width` px from the side's outer boundary `outer`, inward. */\nconst across = (side: \"left\" | \"right\", outer: number, width: number): [number, number] => (side === \"left\" ? [outer, width] : [outer - width, width]);\n\n\n/** A side with no declared rail: its rail column, the item docked in it collapsed (`moveTo` its rail). */\nfunction columnStrip(c: Ctx, side: \"left\" | \"right\", policy: Policy): Strip | null {\n const edge = railColumnOf(c.scene, side, c.kind);\n if (!edge) return null;\n const own = c.now.items[c.dragged];\n // Already collapsed in this column: every drop into it is home.\n if (own?.edge === edge.id && isHandFolded(c.scene, c.dragged)) return null;\n const place: RailPlace = { kind: \"rail\", side, ring: edge.ring };\n const moved = moveAmong(c.scene, c.dragged, place, c.others);\n if (moved === c.scene) return null;\n const result = c.settle(use(moved, c.dragged));\n const el = result.layout.edges[edge.id];\n if (!el || el.rect.width <= EPS || !collapsesAt(c, result, side)) return null;\n const r = el.rect;\n // The rail's width: the column's drawn as a rail (a tile there), else the width it takes as one.\n const railWidth = result.layout.items[c.dragged]!.tab ? r.width : (edge.cross.rail ?? 30);\n const [x, w] = across(side, side === \"left\" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));\n return { side, rect: rect(x, r.y, w, r.height), slots: [{ id: targetId({ kind: \"rail\", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };\n}\n\n/** A side with a declared rail (`Scene.rails`): its stops (`railStops`), the strip split halfway between them. */\nfunction declaredStrip(c: Ctx, side: \"left\" | \"right\", policy: Policy): Strip | null {\n const template = c.scene.columns?.[side];\n const spec = c.scene.rails?.[side];\n if (!template || !spec || !zoneTakes(template, \"start\", c.kind) || !spec.accepts.includes(c.kind)) return null;\n const stops = railStops(c, side);\n // A stop's drop collapses the item at this side wherever the scene's `handFold` shows it (in the rail, or riding over\n // the side's open column): the strip means \"collapse it here\", whether a rail is drawn now or not.\n const slots = (stops?.slots ?? []).filter((s) => !s.home && s.place.kind === \"rail\" && collapsesAt(c, s.result, side)).sort((a, b) => a.line - b.line);\n if (!stops || slots.length === 0) return null;\n const a = Math.min(...stops.zones.map((z) => z.a));\n const b = Math.max(...stops.zones.map((z) => z.b));\n const drawn = c.now.rails[side];\n const outer = drawn && drawn.segments.length > 0 ? (side === \"left\" ? drawn.rect.x : drawn.rect.x + drawn.rect.width) : railOuter(c, side);\n const [x, w] = across(side, outer, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, spec.width));\n const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i]!.line + s.line) / 2), b];\n return {\n side,\n rect: rect(x, a, w, b - a),\n slots: slots.map((s, i) => ({ id: s.id, place: s.place as RailPlace, along: [cuts[i]!, cuts[i + 1]!] as const, result: s.result })),\n };\n}\n\n/** Pieces of `pieces` left once every strip is taken out; under 1 px either way is no piece. */\nconst outside = (pieces: readonly Rect[], strips: readonly Rect[]): Rect[] =>\n strips.reduce<Rect[]>((acc, s) => acc.flatMap((p) => (overlaps(p, s) ? subtract(p, s) : [p])), [...pieces]).filter((p) => p.width >= 1 && p.height >= 1);\nconst largest = (rs: readonly Rect[]): Rect => rs.reduce((m, r) => (r.width * r.height > m.width * m.height ? r : m));\nconst sameRects = (a: readonly Rect[], b: readonly Rect[]): boolean => a.length === b.length && a.every((r, i) => r.x === b[i]!.x && r.y === b[i]!.y && r.width === b[i]!.width && r.height === b[i]!.height);\n\n/**\n * The drag's targets and refusals with the kind's rail drop strips laid over them (unchanged for a kind with no policy),\n * and the strips.\n */\nexport function withRailStrips(c: Ctx, targets: readonly SceneTarget[], refusals: readonly SceneRefusal[]): { targets: SceneTarget[]; refusals: SceneRefusal[]; strips: Rect[] } {\n const policy = railPolicyOf(c.scene, c.kind);\n const strips = policy ? ([\"left\", \"right\"] as const).map((side) => (c.scene.rails?.[side] ? declaredStrip(c, side, policy) : columnStrip(c, side, policy))).filter((s): s is Strip => s !== null) : [];\n if (!policy || strips.length === 0) return { targets: [...targets], refusals: [...refusals], strips: [] };\n const sides = new Set(strips.map((s) => s.side));\n const rects = strips.map((s) => s.rect);\n const out: SceneTarget[] = [];\n /** The new-outermost-column lines moved inside a strip, by side: the inner columns' gaps there give them up. */\n const lines: { side: \"left\" | \"right\"; pieces: Rect[] }[] = [];\n for (const t of targets) {\n // The rail's own tiled stops give way to its strip.\n if (t.place.kind === \"rail\" && sides.has(t.place.side)) continue;\n if (t.free || t.place.kind === \"none\") {\n out.push(t.free && !policy.floatNearEdge ? clearOfStrips(t, c.dragged, rects) : t);\n continue;\n }\n const was = t.hits ?? [t.hit];\n const pieces = outside(was, rects);\n if (pieces.length === 0) {\n // An empty edge's drop strip under the rail's (an empty column, where the side's rail would be too), or the line for\n // a new outermost column on an occupied side (flush, the strip owns the window's edge), moves just inside it: the\n // rail lies outermost, the column opens from beside it, and the column's own gaps lie after.\n let moved = t.id.startsWith(\"strip:\") || t.place.kind === \"column\" ? insideStrips(t.hit, strips) : null;\n let movedPieces: Rect[] = moved ? [moved] : [];\n if (moved && t.place.kind === \"column\") {\n // It keeps the band it owns: a column line beats the inner column it would push, card halves included (ranked\n // by the laying order of the new column it stands for). Moved inside the strip, it gives way only to home, a\n // blocked rect and the other column lines; the inner columns' gaps and refusals on its side give it up below\n // (`lines`), so it is never cut away.\n const others = targets.filter((x) => x !== t && (x.place.kind === \"home\" || x.place.kind === \"column\" || (x.place.kind === \"none\" && !x.free))).flatMap((x) => x.hits ?? [x.hit]);\n movedPieces = outside([moved], others);\n moved = movedPieces.length ? largest(movedPieces) : null;\n if (moved) lines.push({ side: t.place.side, pieces: movedPieces });\n }\n if (moved) out.push({ ...withoutHits(t), hit: moved, ...(movedPieces.length > 1 ? { hits: movedPieces } : {}) });\n continue;\n }\n if (sameRects(pieces, was)) {\n out.push(t);\n continue;\n }\n out.push({ ...withoutHits(t), hit: largest(pieces), ...(pieces.length > 1 ? { hits: pieces } : {}) });\n }\n // The inner columns' gaps (and refusals) on a moved line's side stop short of it: the line owns its band.\n const columnSide = (edge: string): \"left\" | \"right\" | null => {\n const e = c.scene.edges.find((x) => x.id === edge);\n return e?.column && (e.side === \"left\" || e.side === \"right\") ? e.side : null;\n };\n const lineCut = (edge: string): Rect[] => lines.filter((l) => l.side === columnSide(edge)).flatMap((l) => l.pieces);\n for (let i = 0; i < out.length; i++) {\n const t = out[i]!;\n if (t.place.kind !== \"gap\") continue;\n const cut = lineCut(t.place.edge);\n if (!cut.length) continue;\n const was = t.hits ?? [t.hit];\n const pieces = outside(was, cut);\n if (sameRects(pieces, was)) continue;\n if (pieces.length === 0) out.splice(i--, 1);\n else out[i] = { ...withoutHits(t), hit: largest(pieces), ...(pieces.length > 1 ? { hits: pieces } : {}) };\n }\n const refused: SceneRefusal[] = [];\n // The rail's own refusals go with its stops: the strip offers only the stops that take the drop.\n const railEdges = new Set([...sides].map((side) => virtualEdgeId(\"rail\", side)));\n for (const r of refusals) {\n if (railEdges.has(r.edge)) continue;\n const was = r.hits ?? [r.hit];\n const pieces = outside(was, [...rects, ...lineCut(r.edge)]);\n if (!pieces.length || sameRects(pieces, was)) {\n if (pieces.length) refused.push(r);\n continue;\n }\n // A refusal in pieces (a wholly refused edge) keeps every piece of 1 px and more; any other keeps its largest.\n const kept = r.hits ? pieces.filter((p) => p.width >= 1 && p.height >= 1) : [largest(pieces)];\n const { hits: _h, ...one } = r;\n if (kept.length) refused.push({ ...one, hit: largest(kept), ...(kept.length > 1 ? { hits: kept } : {}) });\n }\n // A zone's refusals stay numbered by where they lie along the edge (then across it), as cut.\n const vertical = (r: SceneRefusal): boolean => {\n const side = c.scene.edges.find((e) => e.id === r.edge)?.side;\n // A virtual edge: the rail runs down, the column lines across.\n return side ? side === \"left\" || side === \"right\" : r.edge === virtualEdgeId(\"rail\", \"left\") || r.edge === virtualEdgeId(\"rail\", \"right\");\n };\n const pos = (r: SceneRefusal): [number, number] => (vertical(r) ? [r.hit.y, r.hit.x] : [r.hit.x, r.hit.y]);\n const groups = new Map<string, SceneRefusal[]>();\n for (const r of refused) groups.set(`${r.edge}\\n${r.zone}`, [...(groups.get(`${r.edge}\\n${r.zone}`) ?? []), r]);\n const numbered = new Map<SceneRefusal, string>();\n for (const group of groups.values())\n group\n .sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1])\n .forEach((r, n) => numbered.set(r, targetId({ kind: \"refuse\", edge: r.edge, zone: r.zone, n })));\n const renumbered = refused.map((r) => (numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r)! }));\n for (const s of strips) {\n const grown = s.side === \"left\" ? rect(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);\n for (const sl of s.slots) {\n const [a, b] = sl.along;\n const slot = sl.result.layout.items[c.dragged]!.rect;\n const result = sl.result;\n out.push({\n id: sl.id,\n priority: 1,\n hit: rect(s.rect.x, a, s.rect.width, b - a),\n armedHit: rect(grown.x, a, grown.width, b - a),\n arm: \"dwell\",\n strip: s.rect,\n slot,\n item: c.dragged,\n place: sl.place,\n after: () => result,\n });\n }\n }\n return { targets: out, refusals: renumbered, strips: rects };\n}\n\nconst withoutHits = (t: SceneTarget): SceneTarget => {\n const { hits: _pieces, ...rest } = t;\n return rest;\n};\n\n/** `r` moved inward just past the strip of its side that covers it, or null when none does. */\nfunction insideStrips(r: Rect, strips: readonly Strip[]): Rect | null {\n const s = strips.find((x) => overlaps(x.rect, r));\n if (!s) return null;\n return s.side === \"left\" ? rect(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect(s.rect.x - r.width, r.y, r.width, r.height);\n}\n\n/** The float target with its landing kept clear of every strip (`floatNearEdge: false`): pushed inward past it. */\nfunction clearOfStrips(t: SceneTarget, dragged: string, strips: readonly Rect[]): SceneTarget {\n return {\n ...t,\n after(point: Point, grab?: Point): SceneAfter {\n const first = t.after(point, grab);\n const at = first.layout.items[dragged]?.rect;\n if (!at) return first;\n let dx = 0;\n for (const s of strips) {\n const r = rect(at.x + dx, at.y, at.width, at.height);\n if (!overlaps(r, s)) continue;\n // A strip at the left pushes it right, one at the right pushes it left.\n dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);\n }\n // The pointer that puts the float's left edge where it lands, moved past the strips (the landing may be clamped).\n return dx === 0 ? first : t.after({ x: at.x + dx + (grab?.x ?? at.width / 2), y: point.y }, grab);\n },\n };\n}\n","/**\n * The least a target's hit keeps, so a pointer can reach it (`EDGE_KINDS[kind].minHit`: 12 px across, its narrow\n * side, by 24 px along, its long side). Clipping lays the virtual edges' tiles last, from what the others leave, so a\n * column line beside a rail strip can be left a sliver. After every tile is placed, a target whose largest piece is\n * under its minimum grows into what is beside it, as far as the minimum needs:\n * - only inside its own zone (its tiles with its edge tiled on its own: a column line's band, a gap's tile);\n * - from space no target holds (the float's), and from a target that keeps its own minimum after the cut (the\n * lowest-ranked owner's surplus);\n * - never over home, a drop strip, a `none` rect, a refusal, the chrome or past the stage, and (but for a column line,\n * whose band lies across the columns by design) never over another drawn edge: those don't give way.\n * Where nothing can spare the space the target stays as it is: still a stop, still in \"Move to\".\n */\nimport { EPS, area, rect, subtract, type Rect } from \"../../geometry\";\nimport { chromeFor } from \"../helpers\";\nimport type { Ctx, SceneRefusal, SceneTarget } from \"./model\";\nimport { parseTargetId } from \"./ids\";\nimport { EDGE_KINDS, edgeKindOf, type EdgeKind } from \"./kinds\";\n\n/** A hit's least size: its narrow side `across`, its long side `along`, px. */\ninterface MinHit {\n readonly across: number;\n readonly along: number;\n}\n\n/** The kind whose `minHit` a target keeps: its edge's, a column line's or a rail stop's. */\nfunction kindOf(c: Ctx, t: SceneTarget): EdgeKind | null {\n const p = parseTargetId(t.id);\n if (!p) return null;\n if (p.kind === \"column\") return \"columnLine\";\n if (p.kind === \"rail\") return \"railStop\";\n if (p.kind === \"gap\" || p.kind === \"strip\") {\n const e = c.scene.edges.find((x) => x.id === p.edge);\n return e ? edgeKindOf(c.scene, e) : null;\n }\n return null;\n}\n\nconst largest = (ps: readonly Rect[]): Rect => ps.reduce((a, p) => (area(p) > area(a) ? p : a));\n/** Whether `r` keeps `m`: its narrow side at least `across`, its long side at least `along`. */\nconst keepsMinHit = (r: Rect, m: MinHit): boolean => Math.min(r.width, r.height) >= m.across - EPS && Math.max(r.width, r.height) >= m.along - EPS;\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 cut = (ps: readonly Rect[], g: Rect): Rect[] => ps.flatMap((p) => subtract(p, g)).filter((p) => p.width >= 1 && p.height >= 1);\nconst piecesOf = (t: { readonly hit: Rect; readonly hits?: readonly Rect[] }): readonly Rect[] => t.hits ?? [t.hit];\nconst withPieces = <T extends { readonly hit: Rect; readonly hits?: readonly Rect[] }>(t: T, ps: readonly Rect[]): T => {\n const { hits: _h, ...rest } = t;\n return { ...rest, hit: largest(ps), ...(ps.length > 1 ? { hits: ps } : {}) } as T;\n};\n\n/** The ways `r` can grow by `d` on one axis: all on one side, all on the other, or half on each. */\nfunction growths(r: Rect, axis: \"x\" | \"y\", d: number): Rect[][] {\n const [lo, hi] = axis === \"x\" ? [rect(r.x - d, r.y, d, r.height), rect(r.x + r.width, r.y, d, r.height)] : [rect(r.x, r.y - d, r.width, d), rect(r.x, r.y + r.height, r.width, d)];\n const h = d / 2;\n const halves = axis === \"x\" ? [rect(r.x - h, r.y, h, r.height), rect(r.x + r.width, r.y, h, r.height)] : [rect(r.x, r.y - h, r.width, h), rect(r.x, r.y + r.height, r.width, h)];\n return [[lo], [hi], halves];\n}\n\nconst union = (a: Rect, gs: readonly Rect[]): Rect => {\n const x0 = Math.min(a.x, ...gs.map((g) => g.x));\n const y0 = Math.min(a.y, ...gs.map((g) => g.y));\n return rect(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);\n};\n\n/**\n * Whether `grow` may be taken for target `i` of `targets`: inside the stage, clear of the chrome and of every target\n * that doesn't give way, and every other target it covers keeping its own minimum after the cut.\n */\nfunction mayGrow(c: Ctx, targets: readonly SceneTarget[], i: number, grow: readonly Rect[], minOf: (t: SceneTarget) => MinHit | null, zone: readonly Rect[], away: readonly Rect[]): boolean {\n const s = c.scene.stage;\n for (const g of grow) {\n if (g.x < s.x - EPS || g.y < s.y - EPS || g.x + g.width > s.x + s.width + EPS || g.y + g.height > s.y + s.height + EPS) return false;\n if ([...chromeFor(c.scene, \"targets\"), ...away].some((r) => overlaps(r, g))) return false;\n // Only within its own zone: the tile it had before clipping (its reach included), never past it.\n if (zone.reduce<Rect[]>((ps, z) => ps.flatMap((p) => subtract(p, z)), [g]).some((p) => area(p) > EPS)) return false;\n }\n return targets.every((o, j) => {\n if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps(p, g)))) return true;\n // Home, a drop strip and a `none` rect keep their space.\n if (o.place.kind === \"home\" || o.place.kind === \"none\" || o.strip) return false;\n const m = minOf(o);\n const left = grow.reduce<Rect[]>((ps, g) => cut(ps, g), [...piecesOf(o)]);\n return !!m && left.length > 0 && keepsMinHit(largest(left), m);\n });\n}\n\n/**\n * Growth across over part of `l`'s length: the strip beside it on one side cut where something keeps its space, the\n * longest run left (at least `m.along` long) taken, checked again as a whole. Null when no side has such a run.\n */\nfunction partialGrowth(c: Ctx, targets: readonly SceneTarget[], i: number, l: Rect, axis: \"x\" | \"y\", d: number, m: MinHit, minOf: (t: SceneTarget) => MinHit | null, zone: readonly Rect[], away: readonly Rect[]): Rect[] | null {\n const along = axis === \"x\" ? ([l.y, l.y + l.height] as const) : ([l.x, l.x + l.width] as const);\n let best: Rect | null = null;\n for (const [side] of growths(l, axis, d)) {\n const g = side!;\n const strip = (a: number, b: number): Rect => (axis === \"x\" ? rect(g.x, a, g.width, b - a) : rect(a, g.y, b - a, g.height));\n // Where along the strip something lies: the seams the strip is cut at.\n const cuts = new Set<number>([along[0], along[1]]);\n for (const o of targets)\n for (const p of piecesOf(o))\n if (overlaps(p, g)) for (const v of axis === \"x\" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along[0] && v < along[1]) cuts.add(v);\n const marks = [...cuts].sort((a, b) => a - b);\n let runStart: number | null = null;\n const runs: [number, number][] = [];\n for (let k = 0; k < marks.length - 1; k++) {\n const ok = mayGrow(c, targets, i, [strip(marks[k]!, marks[k + 1]!)], minOf, zone, away);\n if (ok && runStart === null) runStart = marks[k]!;\n if (!ok && runStart !== null) {\n runs.push([runStart, marks[k]!]);\n runStart = null;\n }\n }\n if (runStart !== null) runs.push([runStart, marks[marks.length - 1]!]);\n for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {\n if (b - a < m.along - EPS) break;\n const r = strip(a, b);\n if (mayGrow(c, targets, i, [r], minOf, zone, away) && (!best || area(r) > area(best))) best = r;\n break;\n }\n }\n return best ? [best] : null;\n}\n\n/**\n * Every target grown to its kind's minimum where the space beside it can be spared, within its own zone (`zones`, by\n * id: its tiles with its edge tiled on its own, its reach included). A refusal keeps its space (it is a drawn edge's\n * or a zone's \"No room here\"), and a target of a real edge never grows over another drawn edge: only a column line,\n * whose band lies across the columns about it by design, may.\n */\nexport function withMinHit(c: Ctx, targets: readonly SceneTarget[], refusals: readonly SceneRefusal[], zones: ReadonlyMap<string, readonly Rect[]>): SceneTarget[] {\n const out = [...targets];\n const refused = refusals.flatMap(piecesOf);\n const minOf = (t: SceneTarget): MinHit | null => {\n const k = kindOf(c, t);\n return k ? EDGE_KINDS[k].minHit : null;\n };\n const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS && e.rect.height > EPS);\n for (let i = 0; i < out.length; i++) {\n const t = out[i]!;\n const m = minOf(t);\n const zone = zones.get(t.id);\n if (!m || !zone || t.free || t.strip || t.place.kind === \"home\" || t.place.kind === \"none\") continue;\n const ownEdge = t.place.kind === \"gap\" ? t.place.edge : (parseTargetId(t.id) as { edge?: string } | null)?.edge;\n // A virtual edge's band lies across the edges about it by design (`EDGE_KINDS[kind].virtual`): only it may grow\n // over another drawn edge.\n const k = kindOf(c, t);\n const away = [...refused, ...(k && EDGE_KINDS[k].virtual ? [] : drawn.filter(([id]) => id !== ownEdge).map(([, e]) => e.rect))];\n let l = largest(piecesOf(t));\n if (keepsMinHit(l, m)) continue;\n // The narrow side to `across`, then the long side to `along`, each where the space can be spared.\n const steps: (\"across\" | \"along\")[] = [\"across\", \"along\"];\n for (const step of steps) {\n const narrowX = l.width <= l.height;\n const axis: \"x\" | \"y\" = step === \"across\" ? (narrowX ? \"x\" : \"y\") : narrowX ? \"y\" : \"x\";\n const size = axis === \"x\" ? l.width : l.height;\n const d = (step === \"across\" ? m.across : m.along) - size;\n if (d <= EPS) continue;\n // The whole length first; across, failing that, the longest stretch of it whose side can be spared (as long as\n // the minimum along): a home band beside the line's end keeps its space, the rest of the line grows.\n let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));\n if (!grow && step === \"across\") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? undefined;\n if (!grow) continue;\n for (let j = 0; j < out.length; j++) {\n if (j === i || out[j]!.free) continue;\n const o = out[j]!;\n if (!piecesOf(o).some((p) => grow.some((g) => overlaps(p, g)))) continue;\n out[j] = withPieces(o, grow.reduce<Rect[]>((ps, g) => cut(ps, g), [...piecesOf(o)]));\n }\n // The grown piece: `l` widened over the stretch grown along (all of it, or the part that could be spared). Its\n // other pieces, and what is left of `l`, give that piece up, so no two of its pieces overlap.\n const g0 = grow[0]!;\n const span = axis === \"x\" ? rect(l.x, g0.y, l.width, g0.height) : rect(g0.x, l.y, g0.width, l.height);\n const grown = union(span, grow);\n const others = piecesOf(out[i]!).filter((p) => p !== l);\n out[i] = withPieces(out[i]!, [...cut([...others, l], grown), grown]);\n l = largest(piecesOf(out[i]!));\n }\n }\n return out;\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 * One model makes every docked target and refusal: **edge → zones → slots → tiles**, then one ordered\n * filter.\n *\n * - **Edges.** Every edge, empty or occupied, and two virtual edges per side: the column lines and the rail.\n * - **Zones.** Each edge's start, center and end zones have an extent along it. Where items keep their length and the\n * zones only align them (bars, compact rails, side toolbar bars) the extents are the edge's thirds; where items fill\n * the edge (panel columns) a zone's extent is the span the solver gives it: a plain column is one zone, a tray column\n * its panels' span and its tray's (`EDGE_KINDS`, the only data keyed on the kind of edge). The outer extents reach\n * `endReach` past the edge's ends.\n * - **The seen geometry.** Every tile is laid in one layout: the committed one, the item in place, as the user sees it\n * (lines, zone extents, ownership, bands). A place counts in the scene with the item lifted (a gap's `at`, a column's\n * or rail's `ring`); its `after` is the solved drop. An edge the lift deletes offers nothing: the item's own column\n * collapses into home. A zone where items keep their length reaches over the cards seen in it.\n * - **Slots.** A zone's insertion lines (`gap:<edge>:<zone>:<at>`; on an edge with no members at all a zone has one,\n * `strip:<edge>:<zone>`). The item's own place is an interval, its own rect along the edge (its » entry in the menu):\n * home. The home slot's line lies at both ends of it, so the gaps right beside it are home's (the same move).\n * - **Tiles.** A zone's extent split halfway between its slots' lines (lines that lie past the extent are spread into\n * it); the own interval keeps exactly its length. Panel bodies don't split the tiling: clipping takes them out, and a\n * slot whose tile is all body has no room. Across: the edge's thickness (the larger of seen and after the drop), an\n * empty edge's strip depth (`Edge.strip`, default 24, inward), a compact rail's `RAIL_REACH` further inward.\n * - **Filter**, in order: (i) the edge and zone take the kind (`accepts`, `zoneAccepts`), and an empty side column opens\n * only through its start zone; (ii) the drop fits (C29: no » entry, no new overflow or `too-wide`, every fixed item\n * keeps its form, place and least length, a title bar's title its natural width with the toolbar in its first form;\n * the slot covers no chrome or reserved rect). A slot (i) or (ii) removes is a refusal over its own tile, with that\n * reason (`refusals()`). (iii) Space ownership and clipping (`EDGE_KINDS`): owned > virtual > overreach. A zone's\n * room loses its reserved rects and what edges ranked before it own (in `solve`'s laying order); a zone with no room,\n * or a slot with none in reach, isn't offered. Each tile's owned part is cut clear of the tiles before it, of what\n * outranks its edge, of its panel bodies, of every fixed item that doesn't grow and of the chrome; clipping changes a\n * slot's shape, never who owns it, so every piece left is the slot's (`hits`, `hit` the largest); then the virtual\n * edges take what no edge owns; then each overreach takes what is left and joins its owned part where it meets it\n * whole. Refused places own nothing: they take what the surviving tiles and the other edges' seen rects leave. A\n * stretch is owned by what the user sees there; if the owner has no slot there, it refuses. Slots that are the same\n * move are one (home's, where one of them is home). (iv) `blocked` rects are `none:<i>`.\n *\n * Ids: `gap:<edge>:<zone>:<at>` (priority 2), `strip:<edge>:<zone>` (2), `column:<side>:<ring>` (2), `rail:<side>:<ring>`\n * (1), `none:<i>` (1), `float:<id>` (3, free). A slot that would put the item back where it is keeps its id with place\n * `home` (no slot, nothing committed); `home:<id>` (1) is emitted too, over the same tile (its own rect when no slot is\n * its home), for hosts that read it. A floating item has no home: a move inside its own rect is a float move.\n *\n * - `column:<side>:<ring>`: 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), up to `COLUMN_REACH` px each way (two lines nearer than that meet halfway), only where the new column shows\n * open (elsewhere refused).\n * - `rail:<side>:<ring>`: 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, with no rail shown, the outer `RAIL_EDGE` px from the side's\n * outer edge (the window's, an inset's strip included; flush after the side's outside bars), landing where the rail\n * lands (`SceneLayout.railPlaces`). The outermost column line's zone starts where it ends. For a kind with a rail\n * drop policy (`Scene.railDrop`), the side's rail is a drop strip instead, spring-loaded, owning its rect\n * (`./targets/rail-strip`); on a side with no declared rail, its rail is its outermost column that takes the kind,\n * drawn as a rail once the item docks in it folded.\n * - `float:<id>`: when `floatKinds` lists the kind, the whole plane: the landing is the float with the pointer holding\n * it at `grab` (default its middle), in the stage and clear of the docked items, the bars and the chrome. Its orient:\n * `options.floatOrient`, else its float's, else the item's (`floatOrientOf`). Its size: `options.floatSize`, else its\n * float's size, else `floatSizeOf`.\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 or closed item has no targets; a fixed item has none either,\n * but on an edge that `moves: \"side\"` (an anchor): `side:<other side>` (2), over the place its edge takes there\n * (`setSide`), and `home:<id>` over its own rect (`./targets/anchor`).\n *\n * The phases live in `./targets/`: `kinds` (`EDGE_KINDS`), `model` (the shapes), `filter` (the drag's context and\n * filter ii), `edges` and `virtual` (generation), `ownership` and `tiles` (filter iii and clipping).\n */\nimport { PLANE, area, rect, type Rect } from \"../geometry\";\nimport type { Target } from \"../target\";\nimport { floatAt, prune, use } from \"./changes\";\nimport { axisOf, chromeFor, floatOrientOf, floatSizeOf, inHiddenEdge, namesZone, viewOf, withHiddenOf, zoneOf, zoneTakes } from \"./helpers\";\nimport type { Edge, Orient, Scene, SceneLayout, Zone } from \"./model\";\nimport { solve } from \"./solve\";\nimport { anchorTargets } from \"./targets/anchor\";\nimport { edgeSpec } from \"./targets/edges\";\nimport { context } from \"./targets/filter\";\nimport { checkEdgeIds, parseTargetId, targetId } from \"./targets/ids\";\nimport { edgeKindOf } from \"./targets/kinds\";\nimport type { Ctx, EdgeSpec, Generated, SceneAfter, SceneRefusal, SceneTarget, SceneTargetOptions, Span, Tile } from \"./targets/model\";\nimport { homeRectOf, ownership } from \"./targets/ownership\";\nimport { clipTiles, tileEdge } from \"./targets/tiles\";\nimport { withRailStrips } from \"./targets/rail-strip\";\nimport { withMinHit } from \"./targets/min-hit\";\nimport { columnLines, railStops } from \"./targets/virtual\";\n\nexport { reservedRect, zoneExtents } from \"./targets/edges\";\nexport { parseTargetId, placeTargetId, targetId, virtualEdgeId, type TargetIdParts } from \"./targets/ids\";\nexport { opensEmpty } from \"./targets/kinds\";\nexport type { SceneAfter, ScenePlace, SceneRefusal, SceneTarget, SceneTargetOptions } from \"./targets/model\";\n\n/**\n * The edges as the tiler reads them: every real edge, then each side's column lines and rail, only for kinds the side's\n * template opens with (its start zone).\n */\nfunction specsOf(c: Ctx, kind: string): EdgeSpec[] {\n const { scene } = c;\n const specs: (EdgeSpec | null)[] = scene.edges.map((edge) => edgeSpec(c, edge));\n for (const side of [\"left\", \"right\"] as const) {\n const template = scene.columns?.[side];\n if (!template || !zoneTakes(template, \"start\", kind)) continue;\n const rail = scene.rails?.[side]?.accepts.includes(kind) ? railStops(c, side) : null;\n // The rail stop keeps its place at the side's boundary only when one of its slots lands (home's counts).\n specs.push(...columnLines(c, side, !!rail?.slots.some((s) => s.ok)));\n specs.push(rail);\n }\n return specs.filter((s): s is EdgeSpec => s !== null);\n}\n\n/** The placed tiles as targets and refusals; a zone's refusals numbered by where they lie along the edge. */\nfunction emit(c: Ctx, placed: readonly Tile[]): { targets: SceneTarget[]; refused: SceneRefusal[]; ownHome: Rect | null } {\n const { scene, now, dragged } = c;\n const homeId = targetId({ kind: \"home\", item: dragged });\n const targets: SceneTarget[] = [];\n const refused: SceneRefusal[] = [];\n const homeAfter = (): SceneAfter => ({ scene, layout: now });\n // A zone's refusals are numbered by where they lie along the edge (then across it), not by clipping order, so a\n // refusal keeps its id from one frame to the next. A side's column lines are one edge (one spec per line).\n const pos = (t: Tile): [number, number] => (t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y]);\n const rank = new Map<Tile, number>();\n const edgeOf = (t: Tile): EdgeSpec | string => (t.spec?.edge ? t.spec : t.edge);\n const byZone = new Map<EdgeSpec | string, Map<Zone, Tile[]>>();\n for (const t of placed) {\n if (t.kind !== \"refuse\") continue;\n const zones = byZone.get(edgeOf(t)) ?? new Map<Zone, Tile[]>();\n byZone.set(edgeOf(t), zones.set(t.zone, [...(zones.get(t.zone) ?? []), t]));\n }\n for (const zones of byZone.values()) for (const group of zones.values()) group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((t, n) => rank.set(t, n));\n let ownHome: Rect | null = null;\n for (const t of placed) {\n if (t.kind === \"refuse\") {\n const n = rank.get(t)!;\n refused.push({ id: targetId({ kind: \"refuse\", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, ...(t.hits ? { hits: t.hits } : {}), reason: t.reason! });\n continue;\n }\n // Home's own tile when no slot names it: `home:<id>` covers it (below).\n if (t.kind === \"home\" && t.id === homeId) {\n if (t.order === 0) ownHome = t.hit;\n continue;\n }\n // A slot whose tile came in more than one piece (a virtual edge's stretch cut off from its line; the two column\n // lines about the item's own column, one place) is one target: its pieces in `hits`, `hit` the largest.\n const first = targets.findIndex((x) => x.id === t.id);\n if (first >= 0) {\n const was = targets[first]!;\n const pieces = [...(was.hits ?? [was.hit]), ...(t.hits ?? [t.hit])];\n targets[first] = { ...was, hit: pieces.reduce((m, p) => (area(p) > area(m) ? p : m)), hits: pieces };\n continue;\n }\n if (t.kind === \"home\") {\n targets.push({ id: t.id, priority: t.priority, hit: t.hit, ...(t.hits ? { hits: t.hits } : {}), item: dragged, place: { kind: \"home\" }, after: homeAfter });\n continue;\n }\n const result = t.result!;\n targets.push({ id: t.id, priority: t.priority, hit: t.hit, ...(t.hits ? { hits: t.hits } : {}), ...(t.slot ? { slot: t.slot } : {}), ...(t.marker ? { marker: t.marker } : {}), item: dragged, place: t.place!, after: () => result });\n }\n return { targets, refused, ownHome };\n}\n\n/** The stretches along an edge its slot tiles cover (home's and refusals' aside), merged where they meet. */\nfunction alongOfSlots(s: EdgeSpec, tiles: readonly Tile[]): Span[] {\n const spans = tiles\n .filter((t) => t.kind === \"slot\")\n .map((t): Span => (s.vertical ? [t.hit.y, t.hit.y + t.hit.height] : [t.hit.x, t.hit.x + t.hit.width]))\n .sort((a, b) => a[0] - b[0]);\n const out: [number, number][] = [];\n for (const [a, b] of spans) {\n const last = out[out.length - 1];\n if (last && a <= last[1] + 1e-6) last[1] = Math.max(last[1], b);\n else out.push([a, b]);\n }\n return out;\n}\n\n/**\n * The targets of the scene the window shows: its hidden edges (`Edge.hidden`) left out, so they have no targets or\n * refusals and their items none either. A new column's id is chosen against the hidden edges too (`moveAmong`). Each\n * target's result keeps the hidden edges as they were; a target that commits nothing (home, `none`) gives back `scene`\n * itself. Where a result renumbered a side's rings around them (a column made or removed beside a hidden one), its\n * layout is solved again, so it is still the result.\n *\n * Items a hidden edge lends (`Edge.showIn`) are dragged as items of the edge they show in. A drop that commits a move of\n * one takes it out of its hidden edge, to the drop's place; every other result gives the lent items back to their\n * hidden edges (and its layout is solved again, where they lent themselves to the result's edges in another order).\n *\n * The targets are made on the scene as laid out, each item in the zone it lies in (`zoneIn`). Every result gives each\n * item its own zone back, the dragged one too unless the drop named a zone (a gap), and is solved again.\n */\nfunction generate(scene: Scene, dragged: string, options: SceneTargetOptions): Generated {\n checkEdgeIds(scene);\n const { view: shown, lent, rezoned } = viewOf(scene);\n if (shown === scene) return generateShown(scene, dragged, options, []);\n if (inHiddenEdge(scene, dragged) && !lent.has(dragged)) return { targets: [], refusals: [], lost: [] };\n const hidden = scene.edges.filter((e) => e.hidden === true);\n const g = generateShown(shown, dragged, options, hidden);\n const prev = { ...(options.previous ? { previous: options.previous } : {}), ...(options.fresh ? { fresh: options.fresh } : {}) };\n // With a `showIn`, each result is solved itself: its lent items given back, the edge they showed in maybe gone with\n // the drop, and `solve`'s notes on a `showIn` it ignores.\n const showsIn = hidden.some((e) => e.showIn !== undefined);\n return {\n ...g,\n targets: g.targets.map((t) => ({\n ...t,\n after: (point, grab) => {\n const a = t.after(point, grab);\n // Nothing committed: the scene as it was, the same object.\n if (a.scene === shown) return { scene, layout: showsIn ? solve(scene, prev) : a.layout };\n // Only a drop that names a zone (a gap in a zone of an edge offering a choice, `namesZone`) sets the item's zone;\n // every other move keeps its own.\n const on = t.place.kind === \"gap\" ? shown.edges.find((e) => t.place.kind === \"gap\" && e.id === t.place.edge) : undefined;\n const named = !!on && namesZone(on, scene.items[dragged]!.kind);\n const back = withHiddenOf(scene, a.scene, lent, dragged, named, rezoned);\n // A safety net for the stored scene: a dynamic column left empty (a hidden one whose last item a drop moved out)\n // goes, as in any change, its side's rings closed up. Lent items never sit in a dynamic column (`viewOf`).\n const restored = showsIn ? prune(back) : back;\n const ringOf = new Map(a.scene.edges.map((e) => [e.id, e.ring]));\n const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);\n // Where items lie in zones not their own, the result lays them out again from their own zones.\n const layout = renumbered || showsIn || rezoned.size > 0 ? solve(restored, prev) : a.layout;\n return { scene: restored, layout };\n },\n })),\n };\n}\n\nfunction generateShown(scene: Scene, dragged: string, options: SceneTargetOptions, hidden: readonly Edge[]): Generated {\n // A fixed item takes no gap: on an edge that `moves: \"side\"` it has its `side:` target and home.\n if (Object.hasOwn(scene.items, dragged) && scene.items[dragged]!.fixed) return anchorTargets(scene, dragged, options);\n const ctx = context(scene, dragged, options, hidden);\n if (!ctx) return { targets: [], refusals: [], lost: [] };\n const { c, item, prev } = ctx;\n const { now } = c;\n const live = specsOf(c, item.kind);\n // Ownership is ranked among what survives the filter: each edge tiled on its own first, an edge owning its band only\n // along its surviving slots' tiles (a refused stretch owns nothing).\n const alone = new Map(live.map((s) => [s, tileEdge(c, s, { cuts: [], bodies: [] }, [])]));\n const along = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s)!)]));\n const own = ownership(c, live, (s) => along.get(s)!);\n const lost: string[] = [];\n const tiles: Tile[] = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));\n // The item's own place is home's even where no edge tiles it: its » entry, or its column, which the lift deletes\n // (the whole column collapses into home).\n const ownRect = now.items[dragged];\n const homeEdge = scene.edges.find((e) => e.id === ownRect?.edge);\n const homeHit = homeRectOf(c, null);\n if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))\n tiles.push({ edge: homeEdge.id, spec: null, edgeKind: edgeKindOf(scene, homeEdge), vertical: axisOf(homeEdge.side) === \"column\", zone: zoneOf(item), order: 0, kind: \"home\", id: targetId({ kind: \"home\", item: dragged }), priority: 1, place: { kind: \"home\" }, hit: homeHit, keep: null });\n const placed = clipTiles(tiles, own, chromeFor(scene, \"targets\"), lost);\n const { targets, refused, ownHome } = emit(c, placed);\n const homeAfter = (): SceneAfter => ({ scene, layout: now });\n\n if (scene.floatKinds.includes(item.kind)) {\n const was = scene.floats.find((f) => f.id === dragged);\n const fo: Orient = options.floatOrient ?? was?.orient ?? floatOrientOf(item);\n const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));\n targets.push({\n id: targetId({ kind: \"float\", item: dragged }),\n priority: 3,\n free: true,\n hit: PLANE,\n // Over the whole plane, but only strictly inside the stage: its edge belongs to the targets drawn against it.\n bounds: stageOf(scene),\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, options.floatOrient), dragged), prev);\n const at = first.items[dragged]?.rect ?? raw;\n return c.settle(use(floatAt(scene, dragged, rect(at.x, at.y, size.width, size.height), options.floatOrient), dragged));\n },\n });\n }\n\n // Filter (iv): `blocked` rects take the pointer and commit nothing.\n (scene.blocked ?? []).forEach((b, i) => {\n targets.push({ id: targetId({ kind: \"none\", index: i }), priority: 1, hit: rect(b.x, b.y, b.width, b.height), item: dragged, place: { kind: \"none\" }, after: homeAfter });\n });\n\n // `home:<id>`, for hosts that read it: over the item's own rect, inside home's tile (all of it when no slot names it).\n // A new column holding the item alone where its own column is (a column line beside it, as the lift counts rings) is\n // the same move as home: its pieces are home's, under home's id, never a target of their own (a sliver beside home).\n const sameAsHome = targets.filter((t) => t.place.kind === \"home\" && parseTargetId(t.id)?.kind === \"column\");\n const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);\n if (sameAsHome.length) targets.splice(0, targets.length, ...targets.filter((t) => !sameAsHome.includes(t)));\n // They join home's slot where one is home (a gap of its edge), else `home:<id>`.\n const homeSlot = targets.findIndex((t) => t.place.kind === \"home\");\n if (homeSlot >= 0 && homePieces.length) {\n const t = targets[homeSlot]!;\n targets[homeSlot] = { ...t, hits: [...(t.hits ?? [t.hit]), ...homePieces] };\n }\n if (ownRect && !ownRect.floating) {\n const hit = ownHome ?? ownRect.rect;\n const pieces = homeSlot < 0 && homePieces.length ? { hits: [hit, ...homePieces] } : {};\n targets.push({ id: targetId({ kind: \"home\", item: dragged }), priority: 1, hit, ...pieces, item: dragged, place: { kind: \"home\" }, after: homeAfter });\n }\n // A slot is lost only where no target carries its id (two lines of one move, about the item's own column, are one).\n const lostIds = [...new Set(lost)].filter((id) => !targets.some((t) => t.id === id));\n // The kind's rail drop strips (`Scene.railDrop`), laid over the rest: each owns its rect.\n const layered = withRailStrips(c, targets, refused);\n // Every target keeps a reachable minimum where the space beside it can be spared (`EDGE_KINDS[kind].minHit`).\n // A target's zone: its tiles with its edge tiled on its own (before any other edge owns a part), its overreach\n // included. It grows to its minimum only inside that.\n const zones = new Map<string, Rect[]>();\n for (const t of [...alone.values()].flat()) if (t.kind !== \"refuse\" && t.id) zones.set(t.id, [...(zones.get(t.id) ?? []), t.hit]);\n // A refusal holds only points strictly inside the stage: its edge belongs to the targets drawn against it.\n const bounds = stageOf(scene);\n return { targets: withMinHit(c, layered.targets, layered.refusals, zones), refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones };\n}\n\n/** The stage as a plain rect (a target's or a refusal's `bounds`). */\nconst stageOf = (scene: Scene): Rect => rect(scene.stage.x, scene.stage.y, scene.stage.width, scene.stage.height);\n\nexport function targets(scene: Scene, dragged: string, options: SceneTargetOptions = {}): SceneTarget[] {\n return generate(scene, dragged, options).targets;\n}\n\n/**\n * `refusals(scene, dragged, options?)`: the places a drop of `dragged` is refused, so a host can say so at the pointer\n * (a tint and \"No room here\") instead of showing a slot elsewhere: each slot the filter removed, over its own tile,\n * `not-accepted` where the edge or zone doesn't take the kind, `no-room` where the drop wouldn't fit. An edge that takes\n * the kind in no zone is one refusal over its drawn rect (fixed items included) less what targets own; every refusal\n * lies in the stage, a zone's inside its edge's ends. A release over a refusal commits nothing: the item goes home.\n */\nexport function refusals(scene: Scene, dragged: string, options: SceneTargetOptions = {}): SceneRefusal[] {\n return generate(scene, dragged, options).refusals;\n}\n\n/**\n * A refusal in the pick's shape: `refuse: true`, which ranks it at `REFUSAL_RANK` (after every target of priority 1 and\n * 2, so a target wins wherever the two meet or overlap, before the float). Its `priority` is 2 for a pick rule that\n * doesn't know refusals.\n */\nexport interface SceneRefusalTarget extends Target {\n readonly refuse: true;\n readonly refusal: SceneRefusal;\n}\n\n/**\n * `refusalTargets(refusals)`: each refusal as a target for `@n-uf/motion/drag`'s drag intent (`refuse: true`, its\n * pieces as `hits`). Pass them with the targets: the intent never holds or shows one, a release over one lands nowhere,\n * and the frame's `refused` says which the pointer is over (`refused.refusal` is the `SceneRefusal`).\n */\nexport function refusalTargets(list: readonly SceneRefusal[]): SceneRefusalTarget[] {\n return list.map((r) => ({ id: r.id, priority: 2, hit: r.hit, ...(r.hits ? { hits: r.hits } : {}), ...(r.bounds ? { bounds: r.bounds } : {}), refuse: true, refusal: r }));\n}\n\n/**\n * `targetZones(scene, dragged, options?)`: each docked target's zone by id, the space it may grow to its minimum hit in\n * (its tiles with its edge tiled on its own). For the property check.\n */\nexport function targetZones(scene: Scene, dragged: string, options: SceneTargetOptions = {}): ReadonlyMap<string, readonly Rect[]> {\n return generate(scene, dragged, options).zones ?? new Map();\n}\n\n/**\n * `lostSlots(scene, dragged, options?)`: the ids of slots the filter kept, with room in their zone, that clipping left\n * with no hit. None: the property check holds it at zero.\n */\nexport function lostSlots(scene: Scene, dragged: string, options: SceneTargetOptions = {}): string[] {\n return generate(scene, dragged, options).lost;\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 *\n * Remembered per scene: a scene is an immutable value (every change returns a new one), so the stops of one item of one\n * scene with the same options are solved once, and asking again (a menu redrawn, every group's list on each render) costs\n * nothing until the scene is another object. The options count by value, `previous` by identity. The list is yours: a\n * new array each call, over the same targets.\n */\nexport function stops(scene: Scene, dragged: string, options: SceneTargetOptions = {}): SceneTarget[] {\n const key = stopsKey(dragged, options);\n let memo = stopsMemo.get(scene);\n if (!memo) stopsMemo.set(scene, (memo = new Map()));\n let list = memo.get(key);\n if (!list) {\n // A scene asked about with many different options never holds more than this many lists.\n if (memo.size >= STOPS_PER_SCENE) memo.clear();\n memo.set(key, (list = orderedStops(scene, dragged, options)));\n }\n return [...list];\n}\n\n/** What `stops` has solved, by scene object, then by item and options. */\nconst stopsMemo = new WeakMap<Scene, Map<string, readonly SceneTarget[]>>();\nconst STOPS_PER_SCENE = 512;\nconst layoutIds = new WeakMap<SceneLayout, number>();\nlet nextLayoutId = 0;\n\n/** The item and options as one string: the options by value, `previous` by the identity of its layout. */\nfunction stopsKey(dragged: string, o: SceneTargetOptions): string {\n let prev: number | null = null;\n if (o.previous) {\n prev = layoutIds.get(o.previous) ?? nextLayoutId++;\n layoutIds.set(o.previous, prev);\n }\n return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);\n}\n\nfunction orderedStops(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\" || p.kind === \"side\") 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBO,IAAM,QAAyB,CAAC,OAAO,SAAS,UAAU,MAAM;AAIhE,IAAM,QAAyB,CAAC,SAAS,UAAU,KAAK;AAYxD,IAAM,gBAAwC,CAAC,oBAAoB,eAAe,qBAAqB,iBAAiB,wBAAwB,kBAAkB,uBAAuB,cAAc;AAyOvM,IAAM,aAAkC,CAAC,UAAU,OAAO;AAY1D,IAAM,oBAA+C,CAAC,iBAAiB,UAAU,OAAO;AAGxF,IAAM,iBAAiB;AAEvB,IAAM,sBAAsB;AAmS5B,IAAM,gBAAgB;AAEtB,IAAM,mBAAmB;AAEzB,IAAM,qBAA2B,EAAE,OAAO,KAAK,QAAQ,IAAI;;;ACxjB3D,IAAM,aAAa,CAAC,WAAwC,OAAO,WAAW,WAAW,SAAS,OAAO;AAMzG,IAAM,UAAU,CAAC,MAA4B,OAAO,MAAM,YAAY,KAAK,KAAK,KAAK,OAAO;AAG5F,IAAM,YAAY,CAAC,MAAiF,MAAY,SACrH,KAAK,QAAQ,SAAS,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IAAI,UAAU,IAAI;AAClD,WAAO,SAAS,SAAS,CAAC,MAAM,IAAI,EAAE,IAAI,SAAS,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,MAAM,SAAS,WAAW,KAAK,IAAI,EAAE;AAAA,EAC7H;AACA,SAAO,KACJ,IAAI,CAAC,GAAG,OAAO,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,EAAE,EACnC,KAAK,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,EACjF,IAAI,CAAC,MAAM,EAAE,CAAC;AACnB;","names":["keep","orient","px","cut","open","area","cut","orient","floatRegion","anchored","area","area","auto","open","area","area","across","columnRoom","EPS","across","asked","why","rect","x","orient","targets","keep","drawnOf","anchored","r","across","roomOf","across","cut","meet","cut","pieces","outside","stops","stops","a","b","largest","targets","refusals","cut","largest","overlaps","withPieces","targets","refusals","emit","targets"]}
|