@n-uf/placement 26.11.23 → 26.11.25

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +72 -31
  3. package/dist/{chunk-LPMZ2FFR.js → chunk-3P6VOXA6.js} +2 -2
  4. package/dist/chunk-3P6VOXA6.js.map +1 -0
  5. package/dist/{chunk-CJA6LRHN.js → chunk-7ASCUAGV.js} +5 -7
  6. package/dist/chunk-7ASCUAGV.js.map +1 -0
  7. package/dist/{chunk-RL3QB5SM.js → chunk-KGZCYLQN.js} +10 -10
  8. package/dist/chunk-KGZCYLQN.js.map +1 -0
  9. package/dist/{chunk-2H3CSPEH.js → chunk-OYGOJWAX.js} +2 -2
  10. package/dist/{chunk-6WFVXHA3.js → chunk-SZKU7CRX.js} +582 -501
  11. package/dist/chunk-SZKU7CRX.js.map +1 -0
  12. package/dist/chunk-WM5FJ3IS.js +47 -0
  13. package/dist/chunk-WM5FJ3IS.js.map +1 -0
  14. package/dist/{constructions-VDK_mwmz.d.ts → constructions-DSEjvWMP.d.ts} +1 -1
  15. package/dist/desk.d.ts +3 -3
  16. package/dist/desk.js +3 -3
  17. package/dist/dock.d.ts +3 -3
  18. package/dist/dock.js +2 -2
  19. package/dist/geometry-CkZ6Fcfb.d.ts +48 -0
  20. package/dist/index.d.ts +3 -2
  21. package/dist/index.js +21 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/{model-DPTu2EtG.d.ts → model-mm16NrSX.d.ts} +1 -1
  24. package/dist/panels.d.ts +5 -4
  25. package/dist/panels.js +6 -5
  26. package/dist/scene-cases.d.ts +4 -4
  27. package/dist/scene-cases.js +15 -16
  28. package/dist/scene-cases.js.map +1 -1
  29. package/dist/scene.d.ts +5 -39
  30. package/dist/scene.js +5 -3
  31. package/dist/stack.d.ts +4 -4
  32. package/dist/stack.js +2 -2
  33. package/dist/stack.js.map +1 -1
  34. package/dist/{target-D3PiLg44.d.ts → target-C-HJjPcz.d.ts} +1 -1
  35. package/dist/{targets-B6eLC-52.d.ts → targets-CBpO_LEy.d.ts} +4 -6
  36. package/dist/{targets-DgmHP5PY.d.ts → targets-CDR5Towj.d.ts} +83 -65
  37. package/dist/targets.d.ts +4 -4
  38. package/dist/targets.js +6 -7
  39. package/dist/targets.js.map +1 -1
  40. package/dist/toolbar.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-6WFVXHA3.js.map +0 -1
  43. package/dist/chunk-CJA6LRHN.js.map +0 -1
  44. package/dist/chunk-LPMZ2FFR.js.map +0 -1
  45. package/dist/chunk-QMTNB2C3.js +0 -17
  46. package/dist/chunk-QMTNB2C3.js.map +0 -1
  47. package/dist/chunk-RL3QB5SM.js.map +0 -1
  48. package/dist/geometry-mL-GTRti.d.ts +0 -28
  49. /package/dist/{chunk-2H3CSPEH.js.map → chunk-OYGOJWAX.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/panels/model.ts","../src/panels/layout.ts","../src/panels/targets.ts"],"sourcesContent":["/**\n * The panels model: plain data and the pure changes on it.\n *\n * Panels have string ids. Each side holds full-height columns (outer edge first), each column one or more panels\n * top to bottom and its own width. Opt-in, the top and bottom edges hold a band each: its panels side by side, left to\n * right, sharing its width, at its own height. A panel may instead float, in page space (it moves with the page) or pinned in\n * view space (it stays put). A logical clock per panel (opened, used) is what give-way reads; every change here that\n * counts as a use moves it on. Nothing here reads a host clock: the next tick is one past the latest in the state.\n */\nimport type { Rect, Size } from \"../geometry\";\n\nexport type Side = \"left\" | \"right\";\nexport const SIDES: readonly Side[] = [\"left\", \"right\"];\n\n/** A band's edge: a horizontal dock along the stage's top or bottom (opt-in, `PanelsOptions.bands`). */\nexport type Edge = \"top\" | \"bottom\";\nexport const EDGES: readonly Edge[] = [\"top\", \"bottom\"];\n/** Where a panel may dock: a side's columns or an edge's band. */\nexport type Place = Side | Edge;\n\n/** A band's height limits and natural height when a def gives none. */\nexport const BAND_SIZE: { readonly min: number; readonly max: number; readonly natural: number } = { min: 120, max: 480, natural: 200 };\n\n/** How an edge's band lies: \"reserved\" shortens the pages, \"overlay\" lies over them; between the columns, or full width. */\nexport interface BandOption {\n readonly mode: \"reserved\" | \"overlay\";\n readonly span: \"between\" | \"full\";\n}\n\n/** Room kept clear along the pages' edges, px. */\nexport type Reserve = Readonly<Partial<Record<\"top\" | \"right\" | \"bottom\" | \"left\", number>>>;\n\n/**\n * What a consumer says about a panel: its width limits docked, its size limits floating, and where it may go. No\n * words: names and titles are the consumer's.\n */\nexport interface PanelDef {\n readonly id: string;\n /** A docked column's width limits and its natural width. */\n readonly width: { readonly min: number; readonly max: number; readonly natural: number };\n /**\n * Its height as a section of a stack column (opt-in): it gets its natural height, the column's last open section\n * takes the rest, and when the column is short sections fold to bars by give-way. Without it a section shares the\n * column's height equally with the others, as before.\n */\n readonly height?: { readonly min: number; readonly natural: number };\n /** A float's size limits and natural size (default: its natural width, 360 px tall, no smaller than 160 × 120). */\n readonly float?: { readonly min: Size; readonly natural: Size };\n /** Where it may dock (default: both sides, and every edge that has a band). */\n readonly sides?: readonly Place[];\n /** A band's height limits and natural height (default `BAND_SIZE`: min 120, max 480, natural 200). */\n readonly band?: { readonly min: number; readonly max: number; readonly natural: number };\n /** May it float (default: yes). */\n readonly floats?: boolean;\n}\n\n/**\n * A full-height column: its panels top to bottom, and its stored width (the layout clamps it to its panels' limits).\n * `show` \"tabs\" shows one panel at a time under a strip of tabs: `active` (default, or when `active` isn't one of\n * them: the first panel in the column that isn't closed).\n */\nexport interface Column {\n readonly panels: readonly string[];\n readonly width: number;\n readonly show?: \"stack\" | \"tabs\";\n readonly active?: string;\n}\n\n/** A floating panel: `rect` in page space, or in view space when `pinned`. */\nexport interface FloatAt {\n readonly id: string;\n readonly rect: Rect;\n readonly pinned?: boolean;\n}\n\n/** A band: its panels left to right, sharing its width, and its stored height (the layout clamps it to their limits). */\nexport interface Band {\n readonly panels: readonly string[];\n readonly height: number;\n}\n\n/** Logical times: when a panel was last opened, and last used (opened, focused, moved or unfolded). */\nexport interface Clock {\n readonly opened: number;\n readonly used: number;\n}\n\nexport interface PanelsState {\n /** Each side's columns, from the outer edge inward. */\n readonly sides: Readonly<Record<Side, readonly Column[]>>;\n /** Floating panels; a later one is on top. */\n readonly floats: readonly FloatAt[];\n /** Folded by hand (give-way never writes this). */\n readonly folded: readonly string[];\n /** Docked panels kept open: their columns give way last. */\n readonly kept: readonly string[];\n /** Not shown at all (they keep their place, for when they open again). */\n readonly closed: readonly string[];\n readonly clock: Readonly<Record<string, Clock>>;\n /** Each edge's band (absent: no band panels). An emptied band goes from the state. */\n readonly bands?: Readonly<Partial<Record<Edge, Band>>>;\n}\n\n/** The page's offset and scale in the view: a page point p shows at `x + p.x * scale`, `y + p.y * scale`. */\nexport interface View {\n readonly x: number;\n readonly y: number;\n readonly scale: number;\n}\nexport const IDENTITY_VIEW: View = { x: 0, y: 0, scale: 1 };\n\n/** Who gives way first: the oldest or the newest, by when they were last used or last opened. */\nexport interface GiveWay {\n readonly order: \"oldest\" | \"newest\";\n readonly by: \"used\" | \"opened\";\n}\n\nexport interface PanelsOptions {\n /** Default: `{ order: \"oldest\", by: \"used\" }`, so the panel used longest ago gives way first. */\n readonly giveWay: GiveWay;\n /** \"clamp\" keeps floats in the view at layout time; \"free\" never moves them. Default \"clamp\". */\n readonly floats: \"clamp\" | \"free\";\n /**\n * Where a column folded by hand goes (default \"rail\"): to its side's rail, or (\"ride\") as title bars on top of the\n * side's first open column, until every column on that side is folded. Give-way's folds always go to the rail.\n */\n readonly fold: \"rail\" | \"ride\";\n /** How much of a float wider than the view stays in it, px (default 48). */\n readonly floatVisible: number;\n /** The pages' minimum width (default 320). */\n readonly pagesMin: number;\n /** The page's offset and scale (default: identity). */\n readonly view: View;\n /**\n * A title bar's height: a panel folded in a column, a folded float, a riding column, and the part of a float the\n * clamp keeps in the view (default 28).\n */\n readonly bar: number;\n /** A rail's width (default 36). */\n readonly rail: number;\n /** A rail segment's height, and the gap above the first one (defaults 36 and 4). */\n readonly segment: number;\n readonly railInset: number;\n /** A tabbed column's strip height (default 28). */\n readonly tabs: number;\n /** Which edges have a band, and how it lies (default: none). */\n readonly bands: Readonly<Partial<Record<Edge, BandOption>>>;\n /** The pages' minimum height; only bands give way to it (default 240). */\n readonly pagesMinHeight: number;\n /** Room kept clear at the pages' edges for a toolbar the app draws, px (default: none). */\n readonly reserve: Reserve;\n}\n\nexport const DEFAULT_PANELS_OPTIONS: PanelsOptions = {\n giveWay: { order: \"oldest\", by: \"used\" },\n floats: \"clamp\",\n fold: \"rail\",\n floatVisible: 48,\n pagesMin: 320,\n view: IDENTITY_VIEW,\n bar: 28,\n rail: 36,\n segment: 36,\n railInset: 4,\n tabs: 28,\n bands: {},\n pagesMinHeight: 240,\n reserve: {},\n};\n\n/** A float's size when its def gives none: this tall, and never smaller than FLOAT_MIN. */\nexport const FLOAT_HEIGHT = 360;\nexport const FLOAT_MIN: Size = { width: 160, height: 120 };\n\n// --- reading the state ---------------------------------------------------------------------------------------------\n\nconst without = <T>(list: readonly T[], x: T): T[] => list.filter((y) => y !== x);\nconst withOnce = <T>(list: readonly T[], x: T): T[] => (list.includes(x) ? [...list] : [...list, x]);\n\n/** Where a panel is: a column (side and index), a band (edge and index, left to right), floating, or nowhere. */\nexport type Where =\n | { readonly kind: \"column\"; readonly side: Side; readonly index: number }\n | { readonly kind: \"band\"; readonly edge: Edge; readonly index: number }\n | { readonly kind: \"float\"; readonly float: FloatAt }\n | { readonly kind: \"none\" };\n\nexport function whereIs(state: PanelsState, id: string): Where {\n for (const side of SIDES) {\n const index = state.sides[side].findIndex((c) => c.panels.includes(id));\n if (index >= 0) return { kind: \"column\", side, index };\n }\n for (const edge of EDGES) {\n const index = state.bands?.[edge]?.panels.indexOf(id) ?? -1;\n if (index >= 0) return { kind: \"band\", edge, index };\n }\n const float = state.floats.find((f) => f.id === id);\n return float ? { kind: \"float\", float } : { kind: \"none\" };\n}\n\n/** One past the latest logical time in the state. */\nexport const tick = (state: PanelsState): number => Object.values(state.clock).reduce((m, c) => Math.max(m, c.opened, c.used), 0) + 1;\n\nconst bump = (state: PanelsState, id: string, opened: boolean): PanelsState => {\n const t = tick(state);\n const was = state.clock[id] ?? { opened: 0, used: 0 };\n return { ...state, clock: { ...state.clock, [id]: { opened: opened ? t : was.opened, used: t } } };\n};\n\nexport const defOf = (defs: readonly PanelDef[], id: string): PanelDef | undefined => defs.find((d) => d.id === id);\n\n/** A float's size limits and natural size from its def. */\nexport function floatSize(def: PanelDef | undefined): { min: Size; natural: Size } {\n if (def?.float) return { min: def.float.min, natural: def.float.natural };\n const width = Math.max(FLOAT_MIN.width, def?.width.natural ?? FLOAT_MIN.width);\n return { min: FLOAT_MIN, natural: { width, height: FLOAT_HEIGHT } };\n}\n\n/** A band's height limits and natural height from a def (`BAND_SIZE` when it gives none). */\nexport const bandSize = (def: PanelDef | undefined): { min: number; max: number; natural: number } => ({ ...(def?.band ?? BAND_SIZE) });\n\n/** A band's height as the layout takes it: its stored height clamped to its panels' limits (the largest min, the smallest max). */\nexport function bandHeight(defs: readonly PanelDef[] | undefined, band: Band): number {\n if (!defs) return band.height;\n const ds = band.panels.map((id) => bandSize(defOf(defs, id)));\n const lo = Math.max(0, ...ds.map((d) => d.min));\n const hi = Math.max(lo, Math.min(...ds.map((d) => d.max)));\n return Math.min(Math.max(Number.isFinite(band.height) ? band.height : lo, lo), hi);\n}\n\n/** The bands with `edge` set to `band`, or without it when null; no `bands` at all once none is left. */\nconst withBand = (state: PanelsState, edge: Edge, band: Band | null): PanelsState => {\n const { bands: _b, ...rest } = state;\n const bands: Partial<Record<Edge, Band>> = { ...state.bands };\n if (band && band.panels.length) bands[edge] = band;\n else delete bands[edge];\n return EDGES.some((e) => bands[e]) ? { ...rest, bands } : rest;\n};\n\n/**\n * A panel's own width, for a new column made for it: the width of the column it is in, clamped to its own limits;\n * in a band, floating or nowhere, its natural width.\n */\nexport function ownWidth(defs: readonly PanelDef[], state: PanelsState, id: string): number {\n const def = defOf(defs, id);\n const w = whereIs(state, id);\n const lo = def?.width.min ?? 0;\n const hi = Math.max(lo, def?.width.max ?? Infinity);\n if (w.kind === \"column\") return Math.min(Math.max(state.sides[w.side][w.index]!.width, lo), hi);\n return def?.width.natural ?? lo;\n}\n\n// --- building one --------------------------------------------------------------------------------------------------\n\nexport interface PanelsStart {\n /** Each side's columns from the outer edge inward, each a list of panel ids top to bottom. */\n readonly left?: readonly (readonly string[])[];\n readonly right?: readonly (readonly string[])[];\n /** Each edge's band, its panels left to right (it takes the tallest natural band height, within their limits). */\n readonly top?: readonly string[];\n readonly bottom?: readonly string[];\n /** Floating panels: where (page space, or view space when pinned); the size defaults to the def's natural size. */\n readonly floats?: readonly { readonly id: string; readonly x: number; readonly y: number; readonly width?: number; readonly height?: number; readonly pinned?: boolean }[];\n readonly folded?: readonly string[];\n readonly kept?: readonly string[];\n readonly closed?: readonly string[];\n}\n\n/**\n * A state from a plain start: each column as wide as the widest natural width of its panels (within their limits),\n * each float its natural size. The clock counts up in the order the panels are listed (left, right, top, bottom,\n * floats), so the last one listed is the newest.\n */\nexport function createPanels(defs: readonly PanelDef[], start: PanelsStart): PanelsState {\n const column = (ids: readonly string[]): Column => {\n const ds = ids.map((id) => defOf(defs, id));\n const lo = Math.max(0, ...ds.map((d) => d?.width.min ?? 0));\n const hi = Math.max(lo, Math.min(...ds.map((d) => d?.width.max ?? Infinity)));\n const natural = Math.max(0, ...ds.map((d) => d?.width.natural ?? 0));\n return { panels: [...ids], width: Math.min(Math.max(natural, lo), hi) };\n };\n const floats = (start.floats ?? []).map((f): FloatAt => {\n const n = floatSize(defOf(defs, f.id)).natural;\n return { id: f.id, rect: { x: f.x, y: f.y, width: f.width ?? n.width, height: f.height ?? n.height }, ...(f.pinned ? { pinned: true } : {}) };\n });\n const sides = { left: (start.left ?? []).map(column), right: (start.right ?? []).map(column) };\n const bands: Partial<Record<Edge, Band>> = {};\n for (const edge of EDGES) {\n const ids = start[edge] ?? [];\n if (!ids.length) continue;\n const natural = Math.max(0, ...ids.map((id) => bandSize(defOf(defs, id)).natural));\n bands[edge] = { panels: [...ids], height: bandHeight(defs, { panels: ids, height: natural }) };\n }\n const order = [...sides.left, ...sides.right]\n .flatMap((c) => c.panels)\n .concat(EDGES.flatMap((e) => bands[e]?.panels ?? []))\n .concat(floats.map((f) => f.id));\n const clock: Record<string, Clock> = {};\n order.forEach((id, i) => (clock[id] = { opened: i + 1, used: i + 1 }));\n const s: PanelsState = { sides, floats, folded: [...(start.folded ?? [])], kept: [...(start.kept ?? [])], closed: [...(start.closed ?? [])], clock };\n return EDGES.some((e) => bands[e]) ? { ...s, bands } : s;\n}\n\n// --- changes -------------------------------------------------------------------------------------------------------\n\n/**\n * The state with `id` taken out of its column (an emptied column goes), its band (an emptied band goes, and its height\n * is forgotten) or the floats. Nothing else changes.\n */\nexport function liftPanel(state: PanelsState, id: string): PanelsState {\n // A tabbed column whose active panel leaves shows its first panel again.\n const out = (c: Column): Column => {\n const { active: _a, ...rest } = c;\n return { ...(c.active === id ? rest : c), panels: without(c.panels, id) };\n };\n const lift = (cols: readonly Column[]): Column[] => cols.map(out).filter((c) => c.panels.length > 0);\n let s: PanelsState = { ...state, sides: { left: lift(state.sides.left), right: lift(state.sides.right) }, floats: state.floats.filter((f) => f.id !== id) };\n for (const edge of EDGES) {\n const b = s.bands?.[edge];\n if (b?.panels.includes(id)) s = withBand(s, edge, { ...b, panels: without(b.panels, id) });\n }\n return s;\n}\n\n/**\n * Open a panel: it shows again where it was, and it is the newest opened and used. A panel placed nowhere goes into\n * a new innermost column on `at.side`, `at.width` wide, or with `at.edge` at the right end of that edge's band (a new\n * band is `at.height` tall, default `BAND_SIZE.natural`; the layout clamps it); without `at` it stays placed nowhere.\n * In a tabbed column it becomes the tab that shows, as a drop into the column does.\n */\nexport function open(state: PanelsState, id: string, at?: { readonly side: Side; readonly width: number } | { readonly edge: Edge; readonly height?: number }): PanelsState {\n let s: PanelsState = { ...state, closed: without(state.closed, id) };\n if (at && whereIs(s, id).kind === \"none\") {\n if (\"edge\" in at) {\n const b = s.bands?.[at.edge];\n const panels = [...(b?.panels ?? []), id];\n // The band shows, as a drop into it does: a band folded by hand unfolds as a whole.\n s = withBand({ ...s, folded: s.folded.filter((x) => !panels.includes(x)) }, at.edge, { panels, height: b?.height ?? at.height ?? BAND_SIZE.natural });\n } else s = { ...s, sides: { ...s.sides, [at.side]: [...s.sides[at.side], { panels: [id], width: at.width }] } };\n }\n const w = whereIs(s, id);\n if (w.kind === \"column\" && s.sides[w.side][w.index]!.show === \"tabs\") s = { ...s, sides: { ...s.sides, [w.side]: s.sides[w.side].map((c, i) => (i === w.index ? { ...c, active: id } : c)) } };\n return bump(s, id, true);\n}\n\n/** Close a panel: it isn't shown, keeps its place, and is no longer kept open. */\nexport const close = (state: PanelsState, id: string): PanelsState => ({ ...state, closed: withOnce(state.closed, id), kept: without(state.kept, id) });\n\n/** Focus a panel: it is the newest used; a float comes to the top. */\nexport function focus(state: PanelsState, id: string): PanelsState {\n const f = state.floats.find((x) => x.id === id);\n const s = f ? { ...state, floats: [...state.floats.filter((x) => x !== f), f] } : state;\n return bump(s, id, false);\n}\n\n/**\n * Fold a panel to its title bar by hand, or unfold it (unfolding is a use). A band folds as a whole: on a band panel\n * all its panels go into `folded`, or (when every shown panel of the band is folded) all come out.\n */\nexport function toggleFold(state: PanelsState, id: string): PanelsState {\n const w = whereIs(state, id);\n if (w.kind === \"band\") {\n const ids = state.bands![w.edge]!.panels;\n // Folded as the layout sees it: every shown panel of the band is folded.\n const shown = ids.filter((x) => !state.closed.includes(x));\n if ((shown.length ? shown : ids).every((x) => state.folded.includes(x))) return bump({ ...state, folded: state.folded.filter((x) => !ids.includes(x)) }, id, false);\n return { ...state, folded: [...state.folded.filter((x) => !ids.includes(x)), ...ids] };\n }\n if (state.folded.includes(id)) return bump({ ...state, folded: without(state.folded, id) }, id, false);\n return { ...state, folded: [...state.folded, id] };\n}\n\n/** Keep a docked panel open (its column or band gives way last), or stop keeping it. A floating panel isn't kept. */\nexport function keep(state: PanelsState, id: string, on: boolean): PanelsState {\n if (!on) return { ...state, kept: without(state.kept, id) };\n const k = whereIs(state, id).kind;\n return k === \"column\" || k === \"band\" ? { ...state, kept: withOnce(state.kept, id) } : state;\n}\n\n/**\n * Dock a panel in the band on `edge`, at `index` (0 the leftmost; past the end, the rightmost). A new band takes the\n * panel's natural band height (with `defs`; else `BAND_SIZE.natural`). It shows (a band folded by hand unfolds), it is\n * the newest used, and it keeps whether it is kept open.\n */\nexport function dockBand(state: PanelsState, id: string, edge: Edge, index: number, defs?: readonly PanelDef[]): PanelsState {\n const s = liftPanel(state, id);\n const b = s.bands?.[edge];\n const panels = [...(b?.panels ?? [])];\n panels.splice(Math.max(0, Math.min(index, panels.length)), 0, id);\n const height = b?.height ?? bandSize(defs ? defOf(defs, id) : undefined).natural;\n const s1 = withBand(s, edge, { panels, height });\n return bump({ ...s1, folded: s1.folded.filter((x) => !panels.includes(x)), closed: without(s1.closed, id) }, id, false);\n}\n\n/** Store a band's height (the layout clamps it to its panels' limits). Resizing is a use, as for a column. */\nexport function resizeBand(state: PanelsState, edge: Edge, height: number): PanelsState {\n const b = state.bands?.[edge];\n if (!b || !Number.isFinite(height)) return state;\n const t = tick(state);\n const clock = { ...state.clock };\n for (const id of b.panels) clock[id] = { opened: clock[id]?.opened ?? 0, used: t };\n return { ...withBand(state, edge, { ...b, height: Math.max(0, height) }), clock };\n}\n\nexport interface DockOptions {\n /** Stack into the column at `index` (at its bottom) instead of making a new column there. */\n readonly into?: boolean;\n /**\n * With `into`: the panel goes before the column's member at this index (0 the top; past the end, or left out, the\n * bottom), counted once the panel is lifted out.\n */\n readonly at?: number;\n /**\n * A new column's width (default: the width of the column the panel leaves, else 0, which the layout clamps to the\n * minimum; from a band, pass `ownWidth` for its natural width, as the drop targets do).\n */\n readonly width?: number;\n}\n\n/**\n * Dock a panel on `side`: a new column at `index` (0 the outer edge; past the end, innermost), or with `into` in the\n * column at `index` (counted once the panel is lifted out), at its bottom or before the member `at`. It shows, it is\n * the newest used, and it keeps whether it is kept open.\n */\nexport function dock(state: PanelsState, id: string, side: Side, index: number, options: DockOptions = {}): PanelsState {\n const w = whereIs(state, id);\n const from = w.kind === \"column\" ? state.sides[w.side][w.index]!.width : 0;\n const s = liftPanel(state, id);\n const cols = [...s.sides[side]];\n // Into a column: at its bottom, or before the member `at`. Into a tabbed column it is also the tab that shows.\n if (options.into && cols[index]) {\n const panels = [...cols[index]!.panels];\n const at = typeof options.at === \"number\" && !Number.isNaN(options.at) ? Math.max(0, Math.min(Math.floor(options.at), panels.length)) : panels.length;\n panels.splice(at, 0, id);\n cols[index] = { ...cols[index]!, panels, ...(cols[index]!.show === \"tabs\" ? { active: id } : {}) };\n } else {\n const at = Math.max(0, Math.min(index, cols.length));\n cols.splice(at, 0, { panels: [id], width: options.width ?? from });\n }\n return bump({ ...s, sides: { ...s.sides, [side]: cols }, closed: without(s.closed, id) }, id, false);\n}\n\n/** Show a column's panels as tabs (one at a time under a strip), or as a stack again. */\nexport function showTabs(state: PanelsState, side: Side, index: number, on: boolean): PanelsState {\n const col = state.sides[side][index];\n if (!col) return state;\n const { show: _s, ...stack } = col;\n return { ...state, sides: { ...state.sides, [side]: state.sides[side].map((c, i) => (i === index ? (on ? { ...col, show: \"tabs\" as const } : stack) : c)) } };\n}\n\n/** Make a docked panel the one its column shows (its tab), and the newest used. */\nexport function activate(state: PanelsState, id: string): PanelsState {\n const w = whereIs(state, id);\n if (w.kind !== \"column\") return state;\n const sides = { ...state.sides, [w.side]: state.sides[w.side].map((c, i) => (i === w.index ? { ...c, active: id } : c)) };\n return bump({ ...state, sides }, id, false);\n}\n\n/**\n * Float a panel at `rect` (page space; view space when pinned). A float stays pinned or not unless `pinned` says;\n * a docked panel floats unpinned. It shows, it is the newest used and on top, and it is no longer kept open.\n */\nexport function float(state: PanelsState, id: string, rect: Rect, pinned?: boolean): PanelsState {\n const was = state.floats.find((f) => f.id === id);\n const on = pinned ?? !!was?.pinned;\n const s = liftPanel(state, id);\n const f: FloatAt = { id, rect: { ...rect }, ...(on ? { pinned: true } : {}) };\n return bump({ ...s, floats: [...s.floats, f], kept: without(s.kept, id), closed: without(s.closed, id) }, id, false);\n}\n\n/** A page-space rect in view space, and back. */\nexport const toView = (r: Rect, v: View): Rect => ({ ...r, x: v.x + r.x * v.scale, y: v.y + r.y * v.scale });\nexport const toPage = (r: Rect, v: View): Rect => ({ ...r, x: (r.x - v.x) / v.scale, y: (r.y - v.y) / v.scale });\n\n/**\n * Pin a float to the view, or unpin it to the page. `view` is where the page is now (default: identity): the float\n * doesn't jump, its rect is converted between the two spaces. A float's size is never scaled.\n *\n * `shown` is where the float shows now, in view space (the layout's placed rect for it). When given, its position is\n * converted instead of the stored one, so a float the clamp moved stays where it shows rather than jumping to its\n * stored place. The size stays the stored one: a float folded to a bar, or shrunk by the clamp, keeps its full size.\n */\nexport function pin(state: PanelsState, id: string, on: boolean, view: View = IDENTITY_VIEW, shown?: Rect): PanelsState {\n return {\n ...state,\n floats: state.floats.map((f): FloatAt => {\n if (f.id !== id || !!f.pinned === on) return f;\n // In view space: where it shows, else where it is stored; at its stored size.\n const seen = shown ? { ...f.rect, x: shown.x, y: shown.y } : f.pinned ? { ...f.rect } : toView(f.rect, view);\n return on ? { id, rect: seen, pinned: true } : { id, rect: toPage(seen, view) };\n }),\n };\n}\n\n/**\n * Store a column's width (the layout clamps it to its panels' limits). Resizing is a use: the column's panels are\n * the newest used, so give-way takes room from the other columns, not from the one being resized.\n */\nexport function resizeColumn(state: PanelsState, side: Side, index: number, width: number): PanelsState {\n const col = state.sides[side][index];\n if (!col || !Number.isFinite(width)) return state;\n const t = tick(state);\n const clock = { ...state.clock };\n for (const id of col.panels) clock[id] = { opened: clock[id]?.opened ?? 0, used: t };\n return { ...state, sides: { ...state.sides, [side]: state.sides[side].map((c, i) => (i === index ? { ...c, width: Math.max(0, width) } : c)) }, clock };\n}\n\n/** Store a float's rect (its own space). Resizing is a use. */\nexport function resizeFloat(state: PanelsState, id: string, rect: Rect): PanelsState {\n if (!state.floats.some((f) => f.id === id)) return state;\n return bump({ ...state, floats: state.floats.map((f) => (f.id === id ? { ...f, rect: { ...rect } } : f)) }, id, false);\n}\n\n/** A column's width as the layout takes it: its stored width clamped to its panels' limits (with `defs`). */\nexport function columnWidth(defs: readonly PanelDef[] | undefined, col: Column): number {\n if (!defs) return col.width;\n const ds = col.panels.map((id) => defOf(defs, id));\n const lo = Math.max(0, ...ds.map((d) => d?.width.min ?? 0));\n const hi = Math.max(lo, Math.min(...ds.map((d) => d?.width.max ?? Infinity)));\n return Math.min(Math.max(Number.isFinite(col.width) ? col.width : lo, lo), hi);\n}\n\n/**\n * Two states place the panels the same (columns, their panels and widths, floats and their rects; the clock aside).\n * With `defs`, widths compare as the layout takes them (clamped to the panels' limits), so a stored width past a\n * column's max is the same place as that max.\n */\nexport function samePlaces(a: PanelsState, b: PanelsState, defs?: readonly PanelDef[]): boolean {\n const cols = (s: PanelsState): string =>\n SIDES.map((side) =>\n s.sides[side]\n .map((c) => `${c.panels.join(\",\")}@${Math.round(columnWidth(defs, c))}${c.show === \"tabs\" ? `/tabs:${c.active ?? c.panels[0]}` : \"\"}`)\n .join(\"|\"),\n ).join(\"‖\");\n const fl = (s: PanelsState): string => s.floats.map((f) => `${f.id}@${Math.round(f.rect.x)},${Math.round(f.rect.y)},${Math.round(f.rect.width)},${Math.round(f.rect.height)}${f.pinned ? \"p\" : \"\"}`).join(\"|\");\n const bs = (s: PanelsState): string =>\n EDGES.map((e) => {\n const b = s.bands?.[e];\n return b ? `${b.panels.join(\",\")}@${Math.round(bandHeight(defs, b))}` : \"\";\n }).join(\"‖\");\n const set = (l: readonly string[]): string => [...l].sort().join(\",\");\n return cols(a) === cols(b) && bs(a) === bs(b) && fl(a) === fl(b) && set(a.folded) === set(b.folded) && set(a.kept) === set(b.kept) && set(a.closed) === set(b.closed);\n}\n","/**\n * `layoutPanels`: the panels' state, a stage and options in; geometry and structure out: every panel's rect, layer\n * and kind, the columns, the rails, the pages' rect, and coded notes on how it gave way. Pure: the same input always\n * lays out the same. How anything looks is the consumer's.\n *\n * - A column is full height and as wide as its stored width, clamped to its panels' limits. Inside it, a panel\n * folded by hand is a title bar (`options.bar` tall) and the open ones share the rest of the height equally.\n * - A column whose panels are all folded is railed: its panels become segments of its side's rail (one rail per\n * side, `options.rail` wide at the outer edge, segments in side order).\n * - With `options.fold` \"ride\", a column folded by hand on a side that still has an open column rides instead: its\n * panels become title bars stacked on top of the side's first open column (outer edge first), as wide as that\n * column, and its open panels share the rest of the height. The folded column keeps its stored place and width, and\n * the open columns lie as if it were gone. Only when every column on the side is folded does the side show its rail.\n * Give-way's folds always go to the rail.\n * - A float folded by hand is a title bar: its own x, y and width, `options.bar` tall, still a float (clamped as a\n * bar, `floating`); unfolding brings its full rect back, as the stored rect never changes.\n * - Give-way: when the open columns, the rails and `pagesMin` don't fit the stage width, columns shrink toward their\n * minimum, then whole columns fold to the rail, in the policy's order, until the pages fit. Columns holding a kept\n * panel come after every other column; if the pages still don't fit, they fold too (`kept-folded`). Folding by\n * give-way never writes `folded`, so a wider stage brings the column back.\n * - Floats: \"clamp\" keeps a float in the view at layout time (the state keeps the stored rect, so a larger view\n * brings it back where it was); \"free\" never moves one. A float's size is never scaled. A pinned float is in view\n * space and clamped against the view; an unpinned one has its position in page space, clamped so that its screen\n * rect at pan 0 fits the view, then moved by the view's offset and scale, so it scrolls with the page.\n */\n/*\n * Also (26.11.9):\n * - A tabbed column (`show` \"tabs\") draws a strip `options.tabs` tall on top (`PlacedColumn.strip`, each panel's\n * `tab` in it, panel order, equal widths); its active panel takes the rest and the others are hidden. With its\n * active panel folded it shows only the strip (the active panel is a \"bar\" there); with every panel folded it goes\n * to the rail (or rides) as a stack column does.\n * - Height give-way, opt-in by `PanelDef.height`: see `sectionHeights` in the layout (note `section-folded`).\n *\n * And (26.11.10), all opt-in by `options.bands` and `options.reserve`:\n * - Bands: a full-span band takes its height from the stage's top or bottom first, across the whole width; the\n * columns and rails lie in what is left. A between-span band runs between the innermost open column (or rail) on\n * each side. A \"reserved\" band shortens the pages; an \"overlay\" band lies over the pages (layer 5) and doesn't.\n * Its panels share its width equally, left to right (\"band\" rects); folded (by hand, or by give-way) it is one bar,\n * `options.bar` tall, and each panel a \"bar\" rect side by side.\n * - Height give-way: when the pages would be shorter than `pagesMinHeight` (counted after the top and bottom\n * reserves), reserved bands shrink toward their min, then fold to a bar, unkept before kept, in the policy's order,\n * bottom before top on a tie (`band-shrunk`, `band-folded`, `kept-folded` with `edge`); they leave the pages room\n * for the overlay bands' bars at least. Then the overlay bands give way the same way, together, until they leave\n * `pagesMinHeight` of the pages uncovered (so a top and a bottom one never meet). Give-way never writes `folded`.\n * Pages still short of the min (their rect's height, which overlay bands don't change): `pages-short`.\n * - Reserve: room kept clear along the pages' edges (`reserved`), inside the pages' area; the pages are what's left.\n * An overlay band lies next to the top or bottom reserve, on the pages' side, never over it; the left and right\n * reserves lie between the overlay bands.\n * - A band in the state on an edge the options don't enable: its panels are left out (`band-off`).\n */\nimport { clamp, rect, type Rect, type Size } from \"../geometry\";\nimport { DEFAULT_PANELS_OPTIONS, EDGES, SIDES, bandSize, defOf, floatSize, toView, type Edge, type PanelDef, type PanelsOptions, type PanelsState, type Side } from \"./model\";\n\n/**\n * Where a panel is, structurally: an open part of a column, an open part of a band, a folded title bar (in a column,\n * riding on one, in a folded band, or a folded float), a segment of a rail (the panel itself isn't laid out), or a\n * float.\n */\nexport type PanelKind = \"column\" | \"band\" | \"bar\" | \"segment\" | \"float\";\n\nexport interface PlacedPanel {\n /** Stage px; for a segment, the segment's rect in its rail. */\n readonly rect: Rect;\n readonly kind: PanelKind;\n /** Columns, rails and reserved bands 0, overlay bands 5, floats 10 and up (a later float on top). */\n readonly layer: number;\n /** Not drawn as a panel: in a rail (only its segment shows), or a tab that isn't showing (only its `tab`). */\n readonly hidden: boolean;\n /** Folded by hand (a bar, or a segment of a column folded by hand), or by give-way (a segment). */\n readonly folded: null | \"hand\" | \"auto\";\n /** Kept open. */\n readonly kept: boolean;\n /** A pinned float. */\n readonly pinned: boolean;\n /** It floats (open, or folded to a bar). */\n readonly floating: boolean;\n /** Docked: its side and column index (the state's). */\n readonly side?: Side;\n readonly column?: number;\n /** A riding bar: the index of the column it rides on (`options.fold` \"ride\"). */\n readonly rides?: number;\n /** In a tabbed column: its tab's rect in the strip (panel order, equal widths). */\n readonly tab?: Rect;\n /** A float the clamp moved or resized. */\n readonly clamped?: boolean;\n /** In a band: its edge and its index in the state's band (left to right). */\n readonly edge?: Edge;\n readonly index?: number;\n}\n\n/** A band as laid out. */\nexport interface PlacedBand {\n readonly edge: Edge;\n /** The band's rect (a bar when folded). */\n readonly rect: Rect;\n /** Its stored height clamped to its panels' limits, and those limits. */\n readonly height: number;\n readonly min: number;\n readonly max: number;\n /** null: open; \"hand\": its panels folded by hand; \"auto\": folded by give-way. */\n readonly folded: null | \"hand\" | \"auto\";\n /** Shrunk by give-way below its height. */\n readonly shrunk: boolean;\n /** It holds a kept panel. */\n readonly kept: boolean;\n readonly mode: \"reserved\" | \"overlay\";\n readonly span: \"between\" | \"full\";\n /** The shown panels, left to right. */\n readonly panels: readonly string[];\n}\n\n/** A reserve's edge. */\nexport type ReserveEdge = \"top\" | \"right\" | \"bottom\" | \"left\";\n\nexport interface PlacedColumn {\n readonly side: Side;\n /** The column's index in the state. */\n readonly index: number;\n /** Its rect (zero wide when railed). */\n readonly rect: Rect;\n /** Its stored width clamped to its panels' limits, and those limits. */\n readonly width: number;\n readonly min: number;\n readonly max: number;\n /** null: open; \"hand\": all its panels folded by hand; \"auto\": folded by give-way. */\n readonly folded: null | \"hand\" | \"auto\";\n /** Shrunk by give-way below its width. */\n readonly shrunk: boolean;\n /** It holds a kept panel. */\n readonly kept: boolean;\n /** The shown panels, top to bottom. */\n readonly panels: readonly string[];\n /** Riding: the index of the column its bars ride on; its rect is the bars'. */\n readonly rides?: number;\n /** How it shows its panels (default \"stack\"). */\n readonly show?: \"stack\" | \"tabs\";\n /** Tabbed and laid out: its strip of tabs, and the panel it shows. */\n readonly strip?: Rect;\n readonly active?: string;\n}\n\nexport interface PlacedRail {\n readonly side: Side;\n readonly rect: Rect;\n readonly segments: readonly { readonly id: string; readonly rect: Rect }[];\n}\n\nexport type PanelsNoteCode =\n | \"column-shrunk\"\n | \"column-folded\"\n | \"kept-folded\"\n | \"section-folded\"\n | \"pages-under-min\"\n | \"float-clamped\"\n | \"float-resized\"\n | \"band-shrunk\"\n | \"band-folded\"\n | \"band-off\"\n | \"pages-short\";\n\n/** One note on a layout: a code and its data. `kept-folded` carries `side` and `column` for a column, `edge` for a band. */\nexport type PanelsNote =\n | { readonly code: \"column-shrunk\"; readonly side: Side; readonly column: number; readonly items: readonly string[]; readonly from: number; readonly to: number }\n | { readonly code: \"column-folded\" | \"kept-folded\" | \"section-folded\"; readonly side: Side; readonly column: number; readonly items: readonly string[] }\n | { readonly code: \"pages-under-min\"; readonly width: number; readonly min: number }\n | { readonly code: \"float-clamped\" | \"float-resized\"; readonly items: readonly string[] }\n | { readonly code: \"band-shrunk\"; readonly edge: Edge; readonly items: readonly string[]; readonly from: number; readonly to: number }\n | { readonly code: \"band-folded\" | \"kept-folded\" | \"band-off\"; readonly edge: Edge; readonly items: readonly string[] }\n | { readonly code: \"pages-short\"; readonly height: number; readonly min: number };\n\nexport interface PanelsLayout {\n readonly items: Map<string, PlacedPanel>;\n /** The shown columns in side order (left outer → inner, then right outer → inner). */\n readonly columns: readonly PlacedColumn[];\n readonly rails: Partial<Record<Side, PlacedRail>>;\n readonly notes: readonly PanelsNote[];\n /** What is left for the documents. */\n readonly pages: Rect;\n /** The bands laid out (an enabled edge with shown panels). */\n readonly bands: Readonly<Partial<Record<Edge, PlacedBand>>>;\n /** The room kept clear along the pages' edges (an edge with a reserve over 0). */\n readonly reserved: Readonly<Partial<Record<ReserveEdge, Rect>>>;\n}\n\ninterface BandIn {\n readonly edge: Edge;\n readonly panels: readonly string[];\n /** Its index in the state's band, per shown panel. */\n readonly at: readonly number[];\n readonly min: number;\n readonly max: number;\n readonly height: number;\n readonly hand: boolean;\n readonly kept: boolean;\n readonly age: number;\n readonly mode: \"reserved\" | \"overlay\";\n readonly span: \"between\" | \"full\";\n}\n\ninterface Col {\n readonly side: Side;\n readonly index: number;\n readonly panels: readonly string[];\n readonly min: number;\n readonly max: number;\n readonly width: number;\n readonly hand: boolean;\n readonly kept: boolean;\n readonly age: number;\n readonly show?: \"stack\" | \"tabs\";\n /** Tabbed: the panel it shows (its stored one when shown, else its first). */\n readonly active?: string;\n}\n\n\n/** The order columns give way in: unkept before kept, then the policy (oldest or newest), outer first, left first. */\nexport function giveWayOrder<C extends { readonly side: Side; readonly index: number; readonly kept: boolean; readonly age: number }>(cols: readonly C[], order: \"oldest\" | \"newest\"): C[] {\n return [...cols].sort((a, b) => Number(a.kept) - Number(b.kept) || (order === \"oldest\" ? a.age - b.age : b.age - a.age) || a.index - b.index || SIDES.indexOf(a.side) - SIDES.indexOf(b.side));\n}\n\nexport function layoutPanels(defs: readonly PanelDef[], state: PanelsState, stage: Size, options: Partial<PanelsOptions> = {}): PanelsLayout {\n const opt: PanelsOptions = { ...DEFAULT_PANELS_OPTIONS, ...options };\n const W = stage.width;\n const H = stage.height;\n const closed = new Set(state.closed);\n const folded = new Set(state.folded);\n const kept = new Set(state.kept);\n const by = opt.giveWay.by;\n const ride = opt.fold === \"ride\";\n const px = (v: number | undefined): number => (typeof v === \"number\" && Number.isFinite(v) ? Math.max(0, v) : 0);\n // Options passed as undefined fall back to their defaults.\n const reserveOpt = opt.reserve ?? {};\n const bandOpts = opt.bands ?? {};\n const minH = typeof opt.pagesMinHeight === \"number\" ? opt.pagesMinHeight : DEFAULT_PANELS_OPTIONS.pagesMinHeight;\n const res = { top: px(reserveOpt.top), right: px(reserveOpt.right), bottom: px(reserveOpt.bottom), left: px(reserveOpt.left) };\n\n // The bands: an enabled edge with shown panels. One on an edge the options don't enable is left out.\n const bandsIn: BandIn[] = [];\n const offNotes: PanelsNote[] = [];\n for (const edge of EDGES) {\n const b = state.bands?.[edge];\n if (!b) continue;\n const panels = b.panels.filter((id) => !closed.has(id));\n if (panels.length === 0) continue;\n const o = bandOpts[edge];\n if (!o) {\n offNotes.push({ code: \"band-off\", edge, items: panels });\n continue;\n }\n const ds = panels.map((id) => bandSize(defOf(defs, id)));\n const min = Math.max(0, ...ds.map((d) => d.min));\n const max = Math.max(min, Math.min(...ds.map((d) => d.max)));\n const height = clamp(Number.isFinite(b.height) ? b.height : min, min, max);\n const age = Math.max(...panels.map((id) => state.clock[id]?.[by] ?? 0));\n bandsIn.push({ edge, panels, at: panels.map((id) => b.panels.indexOf(id)), min, max, height, hand: panels.every((id) => folded.has(id)), kept: panels.some((id) => kept.has(id)), age, mode: o.mode, span: o.span });\n }\n\n // Height give-way. The reserved bands and the top and bottom reserves leave the pages at least `pagesMinHeight`: fold\n // the fewest reserved bands in order that let them, shrinking the rest in order toward their min. Then the overlay\n // bands, together, leave that much of the pages they lie over uncovered.\n const bOrder = bandsIn\n .filter((b) => !b.hand)\n .sort((a, b) => Number(a.kept) - Number(b.kept) || (opt.giveWay.order === \"oldest\" ? a.age - b.age : b.age - a.age) || EDGES.indexOf(b.edge) - EDGES.indexOf(a.edge));\n const gh = { auto: new Set<BandIn>(), heights: new Map<BandIn, number>() };\n /** Fit `list` (in give-way order) into `room` px: fold the fewest in order, shrink the rest in order. */\n const fitH = (list: readonly BandIn[], room: number): void => {\n const order = bOrder.filter((b) => list.includes(b));\n const hands = list.length - order.length;\n const fit = (k: number): { auto: Set<BandIn>; heights: Map<BandIn, number>; excess: number } => {\n const auto = new Set(order.slice(0, k));\n const heights = new Map(order.filter((b) => !auto.has(b)).map((b) => [b, b.height]));\n let excess = [...heights.values()].reduce((a, b) => a + b, 0) + (hands + auto.size) * opt.bar - room;\n for (const b of order) {\n if (excess <= 0 || auto.has(b)) continue;\n const take = Math.min(excess, b.height - b.min);\n if (take > 0) {\n heights.set(b, b.height - take);\n excess -= take;\n }\n }\n return { auto, heights, excess };\n };\n let g = fit(0);\n for (let k = 1; g.excess > 0 && k <= order.length; k++) g = fit(k);\n for (const b of g.auto) gh.auto.add(b);\n for (const [b, h] of g.heights) gh.heights.set(b, h);\n };\n const reservedIn = bandsIn.filter((b) => b.mode === \"reserved\");\n const overlayIn = bandsIn.filter((b) => b.mode === \"overlay\");\n // The pages keep at least room for the overlay bands' bars, so a folded overlay band never reaches past them.\n fitH(reservedIn, H - res.top - res.bottom - Math.max(minH, overlayIn.length * opt.bar));\n const bandH = (b: BandIn | undefined): number => (b ? (gh.heights.get(b) ?? opt.bar) : 0);\n // The pages' height: what the reserves and the reserved bands leave.\n const pagesH = H - res.top - res.bottom - reservedIn.reduce((a, b) => a + bandH(b), 0);\n // The overlay bands together, so that a top and a bottom one never meet over the pages.\n fitH(overlayIn, pagesH - minH);\n const topB = bandsIn.find((b) => b.edge === \"top\");\n const botB = bandsIn.find((b) => b.edge === \"bottom\");\n const hT = bandH(topB);\n const hB = bandH(botB);\n // The columns' and rails' height: what the full-span bands (and, under an overlay one, its reserve) leave.\n const colTop = topB?.span === \"full\" ? (topB.mode === \"overlay\" ? res.top : 0) + hT : 0;\n const colBot = botB?.span === \"full\" ? H - (botB.mode === \"overlay\" ? res.bottom : 0) - hB : H;\n const CH = Math.max(0, colBot - colTop);\n\n // The shown columns.\n const cols: Col[] = [];\n for (const side of SIDES) {\n state.sides[side].forEach((c, index) => {\n const panels = c.panels.filter((id) => !closed.has(id));\n if (panels.length === 0) return;\n const ds = panels.map((id) => defOf(defs, id));\n const min = Math.max(0, ...ds.map((d) => d?.width.min ?? 0));\n const max = Math.max(min, Math.min(...ds.map((d) => d?.width.max ?? Infinity)));\n const width = clamp(Number.isFinite(c.width) ? c.width : min, min, max);\n const age = Math.max(...panels.map((id) => state.clock[id]?.[by] ?? 0));\n const tabs = c.show === \"tabs\" ? { show: \"tabs\" as const, active: c.active !== undefined && panels.includes(c.active) ? c.active : panels[0]! } : {};\n cols.push({ side, index, panels, min, max, width, hand: panels.every((id) => folded.has(id)), kept: panels.some((id) => kept.has(id)), age, ...tabs });\n });\n }\n\n /**\n * A stack column's sections, top to bottom, `room` px tall. Without a `height` def among its open sections they\n * share the room equally (bars `opt.bar` tall). With one: each gets its natural height and the last open one the rest\n * (never under its min; sections without a def share what is left). Short of room, open sections fold to bars by\n * give-way (policy order, kept last, never the last open one); their natural heights give way toward their mins\n * before the last one goes under its min.\n */\n const sectionHeights = (c: Col, room: number): Map<string, { height: number; folded: null | \"hand\" | \"auto\" }> => {\n const out = new Map<string, { height: number; folded: null | \"hand\" | \"auto\" }>();\n const open0 = c.panels.filter((id) => !folded.has(id));\n const hOf = (id: string) => defOf(defs, id)?.height;\n const auto = new Set<string>();\n if (open0.some((id) => hOf(id))) {\n const last = open0.at(-1)!;\n // A section without a def never goes under a bar's height: that is its min.\n const minOf = (id: string): number => hOf(id)?.min ?? opt.bar;\n const fits = (): boolean => (c.panels.length - open0.length + auto.size) * opt.bar + open0.filter((id) => !auto.has(id)).reduce((a, id) => a + minOf(id), 0) <= room;\n const rank = (ids: readonly string[]): string[] =>\n [...ids].sort((a, b) => {\n const age = (id: string): number => state.clock[id]?.[by] ?? 0;\n return Number(kept.has(a)) - Number(kept.has(b)) || (opt.giveWay.order === \"oldest\" ? age(a) - age(b) : age(b) - age(a)) || c.panels.indexOf(a) - c.panels.indexOf(b);\n });\n for (const id of rank(open0.filter((x) => x !== last))) {\n if (fits()) break;\n // Folding a section whose min is no more than a bar gains nothing: skip it.\n if (minOf(id) > opt.bar) auto.add(id);\n }\n const open = open0.filter((id) => !auto.has(id));\n const space = room - (c.panels.length - open.length) * opt.bar;\n const fixed = open.filter((id) => id !== last && hOf(id));\n const sharers = open.filter((id) => id === last || !hOf(id));\n const h = new Map(fixed.map((id) => [id, hOf(id)!.natural]));\n let rest = space - fixed.reduce((a, id) => a + h.get(id)!, 0);\n // The sharers (the last section and those without a def) need their mins: the fixed sections' natural heights\n // give way toward their mins first, in policy order.\n const need = sharers.reduce((a, id) => a + minOf(id), 0);\n for (const id of rank(fixed)) {\n if (rest >= need) break;\n const take = Math.min(need - rest, h.get(id)! - minOf(id));\n h.set(id, h.get(id)! - take);\n rest += take;\n }\n if (rest >= need) {\n // Equal shares, raised to each sharer's min where a share falls under it.\n let pool = [...sharers];\n let left = rest;\n for (;;) {\n const share = left / pool.length;\n const under = pool.filter((id) => minOf(id) > share);\n if (under.length === 0) {\n for (const id of pool) h.set(id, share);\n break;\n }\n for (const id of under) h.set(id, minOf(id));\n left -= under.reduce((a, id) => a + minOf(id), 0);\n pool = pool.filter((id) => !under.includes(id));\n }\n } else {\n // Short even for the mins: the last section first, the others share what is left.\n const lastH = Math.max(0, Math.min(minOf(last), rest));\n for (const id of sharers) h.set(id, id === last ? lastH : Math.max(0, rest - lastH) / (sharers.length - 1));\n }\n for (const id of c.panels) out.set(id, folded.has(id) ? { height: opt.bar, folded: \"hand\" } : auto.has(id) ? { height: opt.bar, folded: \"auto\" } : { height: Math.max(0, h.get(id)!), folded: null });\n return out;\n }\n const bars = c.panels.length - open0.length;\n const share = Math.max(0, (room - bars * opt.bar) / open0.length);\n for (const id of c.panels) out.set(id, folded.has(id) ? { height: opt.bar, folded: \"hand\" } : { height: share, folded: null });\n return out;\n };\n\n // Give-way: fold the fewest columns in order that let the pages fit, shrinking the rest in order toward their minimum.\n const order = giveWayOrder(\n cols.filter((c) => !c.hand),\n opt.giveWay.order,\n );\n const fit = (k: number): { auto: Set<Col>; widths: Map<Col, number>; excess: number } => {\n const auto = new Set(order.slice(0, k));\n // Riding, a side's hand-folded columns need no rail while one of its columns stays open.\n const open = (side: Side): boolean => cols.some((c) => c.side === side && !c.hand && !auto.has(c));\n const railed = (side: Side): boolean => cols.some((c) => c.side === side && (auto.has(c) || (c.hand && !(ride && open(side)))));\n const widths = new Map(order.filter((c) => !auto.has(c)).map((c) => [c, c.width]));\n let excess = [...widths.values()].reduce((a, b) => a + b, 0) + SIDES.filter(railed).length * opt.rail + opt.pagesMin + res.left + res.right - W;\n for (const c of order) {\n if (excess <= 0 || auto.has(c)) continue;\n const take = Math.min(excess, c.width - c.min);\n if (take > 0) {\n widths.set(c, c.width - take);\n excess -= take;\n }\n }\n return { auto, widths, excess };\n };\n let g = fit(0);\n for (let k = 1; g.excess > 0 && k <= order.length; k++) g = fit(k);\n\n const notes: PanelsNote[] = [];\n for (const c of order) {\n const w = g.widths.get(c);\n if (w !== undefined && w < c.width) notes.push({ code: \"column-shrunk\", side: c.side, column: c.index, items: c.panels, from: c.width, to: w });\n }\n for (const c of order) if (g.auto.has(c)) notes.push({ code: c.kept ? \"kept-folded\" : \"column-folded\", side: c.side, column: c.index, items: c.panels });\n\n // Positions: rails at the outer edges, open columns inward from them, the pages between.\n const items = new Map<string, PlacedPanel>();\n const placedCols: PlacedColumn[] = [];\n const rails: Partial<Record<Side, PlacedRail>> = {};\n let x0 = 0;\n let x1 = W;\n for (const side of SIDES) {\n const mine = cols.filter((c) => c.side === side);\n const open = mine.filter((c) => !c.hand && !g.auto.has(c));\n // Riding: the side's hand-folded columns, while it has an open column to ride on (the first, outer edge first).\n const host = ride ? open[0] : undefined;\n const riders = host ? mine.filter((c) => c.hand) : [];\n const inRail = mine.filter((c) => (c.hand && !riders.includes(c)) || g.auto.has(c));\n if (inRail.length) {\n const r = side === \"left\" ? rect(0, colTop, opt.rail, CH) : rect(W - opt.rail, colTop, opt.rail, CH);\n const segments = inRail.flatMap((c) => c.panels).map((id, i) => ({ id, rect: rect(r.x, colTop + opt.railInset + i * opt.segment, opt.rail, opt.segment) }));\n rails[side] = { side, rect: r, segments };\n for (const s of segments) {\n const c = inRail.find((x) => x.panels.includes(s.id))!;\n items.set(s.id, { rect: s.rect, kind: \"segment\", layer: 0, hidden: true, folded: c.hand ? \"hand\" : \"auto\", kept: kept.has(s.id), pinned: false, floating: false, side, column: c.index });\n }\n if (side === \"left\") x0 = opt.rail;\n else x1 = W - opt.rail;\n }\n // The open columns first (riding bars need their host's rect), then the folded ones in state order.\n const at = new Map<Col, Rect>();\n for (const c of mine) {\n const w = g.widths.get(c);\n if (w === undefined || riders.includes(c)) continue;\n if (side === \"left\") {\n at.set(c, rect(x0, colTop, w, CH));\n x0 += w;\n } else {\n x1 -= w;\n at.set(c, rect(x1, colTop, w, CH));\n }\n }\n const riding = riders.flatMap((c) => c.panels.map((id) => ({ id, c })));\n const top = riding.length * opt.bar;\n for (const c of mine) {\n const w = g.widths.get(c);\n const folded1 = c.hand ? \"hand\" : g.auto.has(c) ? \"auto\" : null;\n const base = { side, index: c.index, width: c.width, min: c.min, max: c.max, folded: folded1, kept: c.kept, panels: c.panels } as const;\n if (riders.includes(c)) {\n const hr = at.get(host!)!;\n const first = riding.findIndex((x) => x.c === c);\n c.panels.forEach((id, i) =>\n items.set(id, { rect: rect(hr.x, colTop + (first + i) * opt.bar, hr.width, opt.bar), kind: \"bar\", layer: 0, hidden: false, folded: \"hand\", kept: kept.has(id), pinned: false, floating: false, side, column: c.index, rides: host!.index }),\n );\n placedCols.push({ ...base, rect: rect(hr.x, colTop + first * opt.bar, hr.width, c.panels.length * opt.bar), shrunk: false, rides: host!.index });\n continue;\n }\n const r = at.get(c) ?? rect(side === \"left\" ? x0 : x1, colTop, 0, CH);\n // The host shares what the riding bars leave.\n const y0 = colTop + (c === host ? top : 0);\n const tabbed = c.show === \"tabs\";\n const strip = rect(r.x, y0, r.width, opt.tabs);\n const shown = tabbed && w !== undefined ? { strip, active: c.active! } : {};\n placedCols.push({ ...base, rect: r, shrunk: w !== undefined && w < c.width, ...(tabbed ? { show: \"tabs\" as const } : {}), ...shown });\n if (w === undefined) continue;\n const panel = (id: string, to: Rect, kind: PanelKind, f: null | \"hand\" | \"auto\", more: { tab?: Rect; hidden?: boolean } = {}): void => {\n items.set(id, { rect: to, kind, layer: 0, hidden: more.hidden ?? false, folded: f, kept: kept.has(id), pinned: false, floating: false, side, column: c.index, ...(more.tab ? { tab: more.tab } : {}) });\n };\n if (tabbed) {\n // One panel shows under the strip; the others are its hidden tabs. Its active panel folded: only the strip.\n const body = rect(r.x, y0 + opt.tabs, r.width, Math.max(0, colBot - y0 - opt.tabs));\n const shade = folded.has(c.active!);\n const tw = r.width / c.panels.length;\n c.panels.forEach((id, i) => {\n const tab = rect(r.x + i * tw, y0, tw, opt.tabs);\n if (id === c.active) panel(id, shade ? strip : body, shade ? \"bar\" : \"column\", shade ? \"hand\" : null, { tab });\n else panel(id, body, \"column\", folded.has(id) ? \"hand\" : null, { tab, hidden: true });\n });\n continue;\n }\n const hs = sectionHeights(c, colBot - y0);\n let y = y0;\n for (const id of c.panels) {\n const s = hs.get(id)!;\n panel(id, rect(r.x, y, r.width, s.height), s.folded ? \"bar\" : \"column\", s.folded);\n y += s.height;\n }\n for (const id of c.panels) if (hs.get(id)!.folded === \"auto\") notes.push({ code: \"section-folded\", side, column: c.index, items: [id] });\n }\n }\n\n // The bands' notes, in give-way order.\n for (const b of bOrder) {\n const h = gh.heights.get(b);\n if (h !== undefined && h < b.height) notes.push({ code: \"band-shrunk\", edge: b.edge, items: b.panels, from: b.height, to: h });\n }\n for (const b of bOrder) if (gh.auto.has(b)) notes.push({ code: b.kept ? \"kept-folded\" : \"band-folded\", edge: b.edge, items: b.panels });\n\n // The pages' outer edges: a reserved band shortens them, an overlay band doesn't. Then the reserve comes off them:\n // an overlay band lies next to the top or bottom reserve, on the pages' side (never over it), and the left and right\n // reserves lie between the overlay bands.\n const pw = Math.max(0, x1 - x0);\n const pTop = topB?.mode === \"reserved\" ? hT : 0;\n const pBot = botB?.mode === \"reserved\" ? H - hB : H;\n const reserved: Partial<Record<ReserveEdge, Rect>> = {};\n const iTop = pTop + res.top + (topB?.mode === \"overlay\" ? hT : 0);\n const iBot = pBot - res.bottom - (botB?.mode === \"overlay\" ? hB : 0);\n if (res.top > 0) reserved.top = rect(x0, pTop, pw, res.top);\n if (res.right > 0) reserved.right = rect(x0 + pw - res.right, iTop, res.right, Math.max(0, iBot - iTop));\n if (res.bottom > 0) reserved.bottom = rect(x0, pBot - res.bottom, pw, res.bottom);\n if (res.left > 0) reserved.left = rect(x0, iTop, res.left, Math.max(0, iBot - iTop));\n const pages = rect(x0 + res.left, pTop + res.top, Math.max(0, pw - res.left - res.right), Math.max(0, pBot - res.bottom - pTop - res.top));\n if (pages.width < opt.pagesMin) notes.push({ code: \"pages-under-min\", width: pages.width, min: opt.pagesMin });\n // Short: the pages' rect itself (overlay bands don't shorten it; how far one covers the pages is its own\n // band-shrunk or band-folded note).\n if ((bandsIn.length || res.top + res.bottom > 0) && pages.height < minH - 1e-9) notes.push({ code: \"pages-short\", height: pages.height, min: minH });\n\n // The bands' rects and their panels: equal shares of the width, left to right; folded, one bar.\n const bands: Partial<Record<Edge, PlacedBand>> = {};\n for (const b of bandsIn) {\n const h = bandH(b);\n const full = b.span === \"full\";\n const over = b.mode === \"overlay\";\n const y = b.edge === \"top\" ? (over ? res.top : 0) : over ? H - res.bottom - h : H - h;\n const r = full ? rect(0, y, W, h) : rect(x0, y, pw, h);\n const f: null | \"hand\" | \"auto\" = b.hand ? \"hand\" : gh.auto.has(b) ? \"auto\" : null;\n const hh = gh.heights.get(b);\n bands[b.edge] = { edge: b.edge, rect: r, height: b.height, min: b.min, max: b.max, folded: f, shrunk: hh !== undefined && hh < b.height, kept: b.kept, mode: b.mode, span: b.span, panels: b.panels };\n const share = r.width / b.panels.length;\n b.panels.forEach((id, i) =>\n items.set(id, { rect: rect(r.x + i * share, r.y, share, h), kind: f ? \"bar\" : \"band\", layer: over ? 5 : 0, hidden: false, folded: f, kept: kept.has(id), pinned: false, floating: false, edge: b.edge, index: b.at[i]! }),\n );\n }\n\n // Floats, clamped unless free. A float's size is screen px in both spaces (never scaled); only an unpinned float's\n // position is in page space. The clamp keeps the SCREEN rect in the view: a pinned float where it is, an unpinned\n // one as it shows at pan 0, so it still scrolls with the page. In page units (k = the scale, 1 when pinned) a\n // screen interval [lo, hi] is [lo / k, hi / k].\n state.floats.forEach((f, i) => {\n if (closed.has(f.id)) return;\n // Folded by hand: a title bar at its own place and width (the stored rect keeps its height).\n const shaded = folded.has(f.id);\n const at = shaded ? { ...f.rect, height: opt.bar } : f.rect;\n const k = f.pinned ? 1 : opt.view.scale;\n const r = { ...at };\n if (opt.floats === \"clamp\") {\n const lim = floatSize(defOf(defs, f.id)).min;\n r.width = Math.max(lim.width, Math.min(r.width, W));\n if (!shaded) r.height = Math.max(lim.height, Math.min(r.height, H));\n if (r.width !== at.width || r.height !== at.height) notes.push({ code: \"float-resized\", items: [f.id] });\n // Fits: wholly in the view. Too big even at its minimum: its title bar stays in, and `floatVisible` px of its width.\n r.x = r.width <= W ? clamp(r.x, 0, (W - r.width) / k) : clamp(r.x, (opt.floatVisible - r.width) / k, (W - opt.floatVisible) / k);\n r.y = r.height <= H ? clamp(r.y, 0, (H - r.height) / k) : clamp(r.y, 0, (H - opt.bar) / k);\n if (r.x !== at.x || r.y !== at.y) notes.push({ code: \"float-clamped\", items: [f.id] });\n }\n const clamped = r.x !== at.x || r.y !== at.y || r.width !== at.width || r.height !== at.height;\n items.set(f.id, {\n rect: f.pinned ? r : toView(r, opt.view),\n kind: shaded ? \"bar\" : \"float\",\n layer: 10 + i,\n hidden: false,\n folded: shaded ? \"hand\" : null,\n kept: false,\n pinned: !!f.pinned,\n floating: true,\n ...(clamped ? { clamped: true } : {}),\n });\n });\n\n notes.push(...offNotes);\n return { items, columns: placedCols, rails, notes, pages, bands, reserved };\n}\n","/**\n * The drop targets for dragging a panel, in the shape @n-uf/motion/drag takes (`{ id, priority, hit, slot?, free? }`),\n * worked out from the state with the panel lifted out:\n *\n * - `column:<side>:<i>` (priority 2): a band across the line between two columns (or a side's edge): a new column\n * there, as wide as the panel's own width.\n * - `into:<side>:<i>` (2): a column's area: the panel stacks at its bottom.\n * - `into:<side>:<i>:<k>` (2), opt-in (`stackSlots`): before the stacked column's member k. The column's area is split\n * at its members' middles: the top half of member k (and the lower half of the one above) goes before k, and\n * `into:<side>:<i>` keeps only what lies below the last member's middle. `marker` is the line where the panel's top\n * lands after the drop, for the app to draw. k counts closed members too (they keep their place in the column's\n * list); only the members shown get slots. A tabbed column keeps its one `into` target.\n * - `rail:<side>` (1): the side's rail, or its outer edge: the panel docks folded.\n * - `float` (3, free): anywhere; it floats where it is let go, kept in the view as the float option says.\n * - `band:<edge>:<i>` (2), for each edge with a band (`options.bands`): the slots between a band's panels and at both\n * ends (the band's area split at its panels' middles). `band:<edge>` (2): an empty enabled edge, a strip `2 × bar`\n * tall along it inside the pages' area.\n *\n * A place the panel may not take (its def's `sides` and `floats`, and `allows`) is no target, and neither is its own\n * place (a drop there changes nothing). Targets carry a structured `place`, never words: the consumer names them.\n */\nimport { COLUMN_REACH, RAIL_EDGE, rect, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Target } from \"../target\";\nimport { layoutPanels, type PanelsLayout } from \"./layout\";\nimport { DEFAULT_PANELS_OPTIONS, EDGES, SIDES, defOf, dock, dockBand, float, floatSize, liftPanel, ownWidth, samePlaces, toPage, whereIs, type Edge, type PanelDef, type PanelsOptions, type PanelsState, type Side } from \"./model\";\n\n/** Where a drop puts a panel. `index` is a column (or band panel) index in the state with the panel lifted out. */\nexport type PanelPlace =\n | { readonly kind: \"column\"; readonly side: Side; readonly index: number }\n | {\n readonly kind: \"into\";\n readonly side: Side;\n readonly index: number;\n /** Before the column's member at this index (in the state with the panel lifted out); left out: at its bottom. */\n readonly at?: number;\n }\n | { readonly kind: \"rail\"; readonly side: Side }\n | { readonly kind: \"band\"; readonly edge: Edge; readonly index: number }\n | { readonly kind: \"float\" };\n\nexport interface PanelTarget extends Target {\n /** The panel dragged. */\n readonly panel: string;\n readonly place: PanelPlace;\n /** Its rank in reading order (left to right across the stage, floating last). */\n readonly order: number;\n /** The state a drop here makes, with the pointer at `p` holding the panel at `grab` from its top-left corner. */\n readonly make: (p: Point, grab: Point) => PanelsState;\n /**\n * With `stackSlots`, on `into` targets of a stacked column: the line where the panel's top lands after the drop (the\n * column re-shares its height, so this is the drop's layout, not today's gap), as a rect zero tall and as wide as\n * the column. `panelDrop(...).slot` is the whole rect.\n */\n readonly marker?: Rect;\n}\n\nexport interface PanelTargetInput {\n readonly defs: readonly PanelDef[];\n /** The state as it is, the panel still in its place. */\n readonly state: PanelsState;\n readonly id: string;\n readonly stage: Size;\n readonly options?: Partial<PanelsOptions>;\n /** Places the panel may go beyond its def's rules (default: all of them). */\n readonly allows?: (id: string, place: PanelPlace) => boolean;\n /** Drops into a stacked column may go before any of its members (`into` targets with `at`); default: the bottom only. */\n readonly stackSlots?: boolean;\n}\n\n/** How far a column band reaches on each side of its line, and how wide a side takes a rail drop with no rail: the root's. */\nexport { COLUMN_REACH, RAIL_EDGE };\n\n/**\n * A place's rank in reading order: the left side outer to inner, the right side inner to outer, then the top band and\n * the bottom band left to right, floating last.\n */\nexport function placeRank(place: PanelPlace): number {\n switch (place.kind) {\n case \"float\":\n return 3000;\n case \"band\":\n return (place.edge === \"top\" ? 2000 : 2500) + Math.min(place.index, 499);\n case \"rail\":\n return place.side === \"left\" ? 0 : 1999;\n case \"column\":\n return place.side === \"left\" ? 1 + 2 * place.index : 1998 - 2 * place.index;\n case \"into\": {\n const base = place.side === \"left\" ? 2 + 2 * place.index : 1997 - 2 * place.index;\n // Before a member: top to bottom, ahead of the column's bottom.\n return place.at === undefined ? base : base - 0.5 + Math.min(Math.max(0, place.at), 499) / 1000;\n }\n }\n}\n\n/**\n * Where a panel is now, as a place (a float, a column of its own, or stacked in one); null when placed nowhere. With\n * `stackSlots`, a panel stacked in a column says its position there as `at` (a tabbed column's panel never does).\n */\nexport function homePlace(state: PanelsState, id: string, options: { readonly stackSlots?: boolean } = {}): PanelPlace | null {\n const w = whereIs(state, id);\n if (w.kind === \"float\") return { kind: \"float\" };\n if (w.kind === \"none\") return null;\n if (w.kind === \"band\") return { kind: \"band\", edge: w.edge, index: w.index };\n const col = state.sides[w.side][w.index]!;\n if (col.panels.length === 1) return { kind: \"column\", side: w.side, index: w.index };\n return options.stackSlots && col.show !== \"tabs\" ? { kind: \"into\", side: w.side, index: w.index, at: col.panels.indexOf(id) } : { kind: \"into\", side: w.side, index: w.index };\n}\n\nconst cut = (x0: number, x1: number, lo: number, hi: number): [number, number] => [Math.max(x0, lo), Math.min(x1, hi)];\n\n/** The targets for dragging `input.id`, in reading order. */\nexport function panelTargets(input: PanelTargetInput): PanelTarget[] {\n const { defs, state, id, stage } = input;\n const opt: PanelsOptions = { ...DEFAULT_PANELS_OPTIONS, ...input.options };\n const def = defOf(defs, id);\n const s0 = liftPanel(state, id);\n const l0 = layoutPanels(defs, s0, stage, opt);\n const width = ownWidth(defs, state, id);\n const W = stage.width;\n const H = stage.height;\n const R = COLUMN_REACH;\n // Options passed as undefined fall back to their defaults.\n const bandOpts = opt.bands ?? {};\n const reserve = opt.reserve ?? {};\n const px = (v: number | undefined): number => (typeof v === \"number\" && Number.isFinite(v) ? Math.max(0, v) : 0);\n const out: PanelTarget[] = [];\n const idOf = (place: PanelPlace): string => {\n switch (place.kind) {\n case \"float\":\n return \"float\";\n case \"rail\":\n return `rail:${place.side}`;\n case \"band\":\n return s0.bands?.[place.edge] ? `band:${place.edge}:${place.index}` : `band:${place.edge}`;\n case \"into\":\n return place.at === undefined ? `into:${place.side}:${place.index}` : `into:${place.side}:${place.index}:${place.at}`;\n default:\n return `${place.kind}:${place.side}:${place.index}`;\n }\n };\n const add = (place: PanelPlace, priority: 1 | 2 | 3, hit: Rect, make: PanelTarget[\"make\"], free = false, marker?: Rect): void => {\n if (hit.width <= 0 || hit.height <= 0) return;\n if (input.allows && !input.allows(id, place)) return;\n // Its own place: a drop there changes nothing, so it is no target (the drag's home covers it).\n // Widths compare as laid out: a stored width past the column's limits is the same place as the limit.\n if (place.kind !== \"float\" && samePlaces(make({ x: 0, y: 0 }, { x: 0, y: 0 }), state, defs)) return;\n out.push({ id: idOf(place), priority, hit, panel: id, place, order: placeRank(place), make, ...(free ? { free: true } : {}), ...(marker ? { marker } : {}) });\n };\n\n // The columns' height: what the full-span bands leave (the whole stage without them).\n const fullTop = l0.bands.top?.span === \"full\" ? l0.bands.top.rect : null;\n const fullBot = l0.bands.bottom?.span === \"full\" ? l0.bands.bottom.rect : null;\n const top = fullTop ? fullTop.y + fullTop.height : 0;\n const CH = Math.max(0, (fullBot ? fullBot.y : H) - top);\n\n for (const side of SIDES) {\n if (def?.sides && !def.sides.includes(side)) continue;\n const left = side === \"left\";\n const rail = l0.rails[side];\n const edge = rail ? rail.rect.width : RAIL_EDGE;\n // The rail (or the bare edge): dock folded, as the outermost column.\n const railHit = rail ? rail.rect : left ? rect(0, top, RAIL_EDGE, CH) : rect(W - RAIL_EDGE, top, RAIL_EDGE, CH);\n add({ kind: \"rail\", side }, 1, railHit, () => {\n const s = dock(state, id, side, 0, { width });\n return { ...s, folded: [...s.folded.filter((x) => x !== id), id] };\n });\n // The lines between the open columns, outer to inner, and each column's area.\n const open = l0.columns.filter((c) => c.side === side && c.folded === null);\n const lo = left ? edge : 0;\n const hi = left ? W : W - edge;\n const band = (x: number, outer: boolean, i: number): void => {\n // The outermost line reaches inward only: outward is the rail's.\n const [a, b] = outer ? (left ? cut(x, x + 2 * R, lo, hi) : cut(x - 2 * R, x, lo, hi)) : cut(x - R, x + R, lo, hi);\n add({ kind: \"column\", side, index: i }, 2, rect(a, top, b - a, CH), () => dock(state, id, side, i, { width }));\n };\n // No open column: the line where a new one would start, the stage side of the pages' reserve.\n if (open.length === 0) band(left ? l0.pages.x - px(reserve.left) : l0.pages.x + l0.pages.width + px(reserve.right), true, s0.sides[side].length);\n open.forEach((c, k) => {\n band(left ? c.rect.x : c.rect.x + c.rect.width, k === 0, c.index);\n const col = s0.sides[side][c.index]!;\n const into = () => dock(state, id, side, c.index, { into: true });\n // The members shown, top to bottom, as laid out (a stacked column only; each a section or a title bar). A closed\n // member stays in the column's list but isn't laid out: `at` counts it, so a drop keeps it where it was.\n const members =\n input.stackSlots && col.show !== \"tabs\"\n ? col.panels.flatMap((p, at) => {\n const r = l0.items.get(p)?.rect;\n return r ? [{ at, rect: r }] : [];\n })\n : [];\n if (members.length === 0) {\n add({ kind: \"into\", side, index: c.index }, 2, c.rect, into);\n return;\n }\n const mid = (r: Rect): number => r.y + r.height / 2;\n // Where the panel's top lands after the drop (the column re-shares its height), as a line across the column.\n const marker = (make: () => PanelsState): Rect => {\n const r = layoutPanels(defs, make(), stage, opt).items.get(id)?.rect;\n return rect(c.rect.x, r ? r.y : c.rect.y, c.rect.width, 0);\n };\n const bottom = c.rect.y + c.rect.height;\n members.forEach(({ at, rect: r }, k) => {\n const prev = members[k - 1];\n const y0 = prev ? mid(prev.rect) : c.rect.y;\n const make = () => dock(state, id, side, c.index, { into: true, at });\n add({ kind: \"into\", side, index: c.index, at }, 2, rect(c.rect.x, y0, c.rect.width, mid(r) - y0), make, false, marker(make));\n });\n const last = members.at(-1)!.rect;\n add({ kind: \"into\", side, index: c.index }, 2, rect(c.rect.x, mid(last), c.rect.width, bottom - mid(last)), into, false, marker(into));\n });\n const last = open.at(-1);\n if (last) band(left ? last.rect.x + last.rect.width : last.rect.x, false, last.index + 1);\n }\n\n // The bands: a slot between each two panels and at both ends, the band's area split at its panels' middles; an\n // empty enabled edge, a strip along it inside the pages.\n const home = whereIs(state, id);\n for (const e of EDGES) {\n if (!bandOpts[e] || (def?.sides && !def.sides.includes(e))) continue;\n const pb = l0.bands[e];\n const list = s0.bands?.[e]?.panels ?? [];\n const make = (i: number) => () => dockBand(state, id, e, i, defs);\n if (!pb) {\n // The panel's own band, emptied by lifting it: a drop there would only make the same band again (at its natural\n // height, not the one stored), so it is the drag's home, not a target.\n if (home.kind === \"band\" && home.edge === e && !s0.bands?.[e]) continue;\n const p = l0.pages;\n const h = Math.min(2 * opt.bar, p.height);\n add({ kind: \"band\", edge: e, index: list.length }, 2, rect(p.x, e === \"top\" ? p.y : p.y + p.height - h, p.width, h), make(list.length));\n continue;\n }\n const m = pb.panels.length;\n const share = pb.rect.width / m;\n for (let k = 0; k <= m; k++) {\n const i = k < m ? list.indexOf(pb.panels[k]!) : list.length;\n const a = pb.rect.x + Math.max(0, k - 0.5) * share;\n const b = pb.rect.x + Math.min(m, k + 0.5) * share;\n add({ kind: \"band\", edge: e, index: i }, 2, rect(a, pb.rect.y, b - a, pb.rect.height), make(i));\n }\n }\n\n if (def?.floats !== false) {\n const was = state.floats.find((f) => f.id === id);\n const size = was ? { width: was.rect.width, height: was.rect.height } : floatSize(def).natural;\n const pinned = !!was?.pinned;\n add(\n { kind: \"float\" },\n 3,\n rect(0, 0, W, H),\n (p, grab) => {\n // Let go at p (view space); stored where it shows once the float option has had its say.\n const at = rect(p.x - grab.x, p.y - grab.y, size.width, size.height);\n const s = float(state, id, pinned ? at : toPage(at, opt.view), pinned);\n const laid = layoutPanels(defs, s, stage, opt).items.get(id)!.rect;\n // A folded float shows as a bar: it moves to where the bar shows and keeps its full size for unfolding.\n const shown = s.folded.includes(id) ? { ...laid, width: at.width, height: at.height } : laid;\n return float(state, id, pinned ? shown : toPage(shown, opt.view), pinned);\n },\n true,\n );\n }\n return out.sort((a, b) => a.order - b.order);\n}\n\n/** A target's drop, laid out: where the panel lands. */\nexport interface PanelDrop {\n readonly target: string;\n readonly place: PanelPlace;\n /** Same key, same place (a float's key carries where it lands). */\n readonly key: string;\n readonly state: PanelsState;\n readonly layout: PanelsLayout;\n /** Where the panel lands (its rail segment when it docks folded). */\n readonly slot: Rect;\n /** It lands in a rail. */\n readonly hidden: boolean;\n /** It floats where it is let go: no room is made for it. */\n readonly free: boolean;\n}\n\n/** The drop on `target` with the pointer at `p` holding the panel at `grab`, laid out. */\nexport function panelDrop(input: PanelTargetInput, target: PanelTarget, p: Point, grab: Point): PanelDrop {\n const opt: PanelsOptions = { ...DEFAULT_PANELS_OPTIONS, ...input.options };\n const state = target.make(p, grab);\n const layout = layoutPanels(input.defs, state, input.stage, opt);\n const placed = layout.items.get(input.id)!;\n const key = target.free ? `float:${Math.round(placed.rect.x)},${Math.round(placed.rect.y)}` : target.id;\n return { target: target.id, place: target.place, key, state, layout, slot: placed.rect, hidden: placed.hidden, free: !!target.free };\n}\n\n// --- keyboard stops ------------------------------------------------------------------------------------------------\n\nexport interface PanelStop {\n /** The target's id (\"home\" for the panel's own place). */\n readonly id: string;\n readonly place: PanelPlace;\n /** The state a move here makes (the current one for home). */\n readonly state: PanelsState;\n readonly home: boolean;\n}\n\nexport interface PanelStopsOptions {\n /** The panel's own place (`homePlace`) and the state as it is: a stop of its own in its reading-order position. */\n readonly home?: { readonly place: PanelPlace; readonly state: PanelsState };\n /** Floating as a stop at the end (default: left out); `at` and `grab` as for a drop (default: the stage's middle, the corner). */\n readonly floats?: boolean | { readonly at: Point; readonly grab?: Point };\n}\n\n/** The panel's places in reading order, for the arrow keys and a \"Move to\" menu (`keyboardStops` calls this). */\nexport function panelStops(targets: readonly PanelTarget[], options: PanelStopsOptions = {}): PanelStop[] {\n const stops: (PanelStop & { order: number })[] = [];\n for (const t of targets) {\n if (t.place.kind === \"float\") {\n if (!options.floats) continue;\n const at = options.floats === true ? { x: t.hit.x + t.hit.width / 2, y: t.hit.y + t.hit.height / 2 } : options.floats.at;\n const grab = options.floats === true ? { x: 0, y: 0 } : (options.floats.grab ?? { x: 0, y: 0 });\n stops.push({ id: t.id, place: t.place, state: t.make(at, grab), home: false, order: t.order });\n continue;\n }\n stops.push({ id: t.id, place: t.place, state: t.make({ x: 0, y: 0 }, { x: 0, y: 0 }), home: false, order: t.order });\n }\n const h = options.home;\n // A float's home sits with the floats: last, after any float stop. A home that says its position in a column sits at\n // that position among the column's slots.\n const after = h?.place.kind === \"float\" ? 1 : h?.place.kind === \"into\" && h.place.at !== undefined ? 0.0005 : 0.5;\n if (h) stops.push({ id: \"home\", place: h.place, state: h.state, home: true, order: placeRank(h.place) + after });\n return stops.sort((a, b) => a.order - b.order).map(({ order: _order, ...s }) => s);\n}\n"],"mappings":";;;;;;;;AAYO,IAAM,QAAyB,CAAC,QAAQ,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KAAK,IAAI,IAAI,GAAG,MAAM,OAAO,OAAO,EAAE,MAAM,CAAC;AAC7F;AAAA,IACF;AACA,UAAM,KAAK,EAAE,IAAI,EAAE,IAAI,OAAO,EAAE,OAAO,OAAO,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,GAAG,MAAM,OAAO,OAAO,EAAE,MAAM,CAAC;AAAA,EACrH;AACA,QAAM,IAAI,QAAQ;AAGlB,QAAM,QAAQ,GAAG,MAAM,SAAS,UAAU,IAAI,GAAG,MAAM,SAAS,UAAU,EAAE,MAAM,OAAO,SAAY,OAAS;AAC9G,MAAI,EAAG,OAAM,KAAK,EAAE,IAAI,QAAQ,OAAO,EAAE,OAAO,OAAO,EAAE,OAAO,MAAM,MAAM,OAAO,UAAU,EAAE,KAAK,IAAI,MAAM,CAAC;AAC/G,SAAO,MAAM,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,OAAO,QAAQ,GAAG,EAAE,MAAM,CAAC;AACnF;","names":["float","rect","f","b","order","fit","g","open","share","open","k","last"]}
@@ -1,7 +1,11 @@
1
1
  import {
2
+ EPS,
3
+ PLANE,
2
4
  clampInto,
5
+ overlap,
6
+ overlaps,
3
7
  rect
4
- } from "./chunk-QMTNB2C3.js";
8
+ } from "./chunk-WM5FJ3IS.js";
5
9
 
6
10
  // src/stack/model.ts
7
11
  var nonNeg = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
@@ -102,7 +106,6 @@ function withItem(input, item, at) {
102
106
  }
103
107
 
104
108
  // src/stack/layout.ts
105
- var EPS = 1e-6;
106
109
  var isMenu = (f) => f.kind === "menu";
107
110
  var GROUP_KINDS = /* @__PURE__ */ new Set(["row", "stacked", "wrap", "icons", "fold"]);
108
111
  var finite2 = (x, fallback = 0) => Number.isFinite(x) ? x : fallback;
@@ -477,8 +480,6 @@ function read(data, known) {
477
480
  // src/stack/floats.ts
478
481
  var EPS2 = 1e-3;
479
482
  var finite3 = (x, fallback) => Number.isFinite(x) ? x : fallback;
480
- var overlaps = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS2 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS2;
481
- var shared = (a, b) => Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
482
483
  var clean = (r, at) => rect(finite3(r.x, at.x), finite3(r.y, at.y), Math.max(0, finite3(r.width, 0)), Math.max(0, finite3(r.height, 0)));
483
484
  var WORK = 3e6;
484
485
  var COVERED_PLACES = 2048;
@@ -542,10 +543,10 @@ function fitFloat(want, stage, avoid = []) {
542
543
  const near = [];
543
544
  avoid.forEach((a, index) => {
544
545
  const at = clean(a, area);
545
- if (at.width > EPS2 && at.height > EPS2 && overlaps(at, reach)) near.push({ at, index });
546
+ if (at.width > EPS2 && at.height > EPS2 && overlaps(at, reach, EPS2)) near.push({ at, index });
546
547
  });
547
- const under = (cand) => near.filter((n) => overlaps(cand, n.at)).map((n) => n.index);
548
- const blocked = (cand) => near.some((n) => overlaps(cand, n.at));
548
+ const under = (cand) => near.filter((n) => overlaps(cand, n.at, EPS2)).map((n) => n.index);
549
+ const blocked = (cand) => near.some((n) => overlaps(cand, n.at, EPS2));
549
550
  if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };
550
551
  const lo = (v, from, to) => Math.min(Math.max(v, from), Math.max(from, to));
551
552
  const xs = [inside.x, area.x, area.x + area.width - r.width];
@@ -599,13 +600,12 @@ function fitFloat(want, stage, avoid = []) {
599
600
  for (const p of byDistance(px, py, inside.x, inside.y)) {
600
601
  if (tried++ >= COVERED_PLACES) break;
601
602
  const cand = rect(p.x, p.y, r.width, r.height);
602
- const left = near.reduce((s, n) => s + shared(cand, n.at), 0);
603
+ const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);
603
604
  if (!best || left < best.left - EPS2) best = { rect: cand, left, far: p.far, hits: under(cand) };
604
605
  }
605
606
  const out = best ?? { rect: inside, far: 0, hits: under(inside) };
606
607
  return { rect: out.rect, clamped, snapped: out.far > EPS2, covers: out.hits, searchCapped };
607
608
  }
608
- var PLANE = rect(-1e9, -1e9, 2e9, 2e9);
609
609
  function stackFloatTarget(input) {
610
610
  const { stage, size } = input;
611
611
  const avoid = input.avoid ?? [];
@@ -708,4 +708,4 @@ export {
708
708
  storeFloats,
709
709
  readFloats
710
710
  };
711
- //# sourceMappingURL=chunk-RL3QB5SM.js.map
711
+ //# sourceMappingURL=chunk-KGZCYLQN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stack/model.ts","../src/stack/layout.ts","../src/stack/store.ts","../src/stack/floats.ts"],"sourcesContent":["/**\n * The edge stack's shapes. A stack is the items along one edge of a stage: a column (vertical, a side region) or a\n * row (horizontal, a bar). An item is a panel or a control group; it declares its forms, largest first, and the\n * solver (`fitStack`) picks one per item. Plain data in and out: no words, no time, no DOM.\n *\n * The form kinds are structural labels the app draws by; the solver reads only `menu` (a form with no room of its own)\n * and, for the cross size, `open`. Panel and group kinds may be mixed on one item.\n */\nimport type { Rect } from \"../geometry\";\n\n/** `\"column\"` runs the stack down (its main size is a height, its cross size a width); `\"row\"` runs it across. */\nexport type StackAxis = \"column\" | \"row\";\n\n/** How a panel draws: open (header and body), a header only, a rail icon, or an entry in the » menu. */\nexport type PanelFormKind = \"open\" | \"header\" | \"rail\" | \"menu\";\n/**\n * How a control group draws: a row of words, the words stacked, `wrap` (the words in rows that wrap to the cross size\n * the item gets; its length follows from {@link StackForm.wrap}), icons only, `fold` (the group's handle with its own »,\n * in line at its place and with its own length) or an entry in the shared » menu.\n */\nexport type GroupFormKind = \"row\" | \"stacked\" | \"wrap\" | \"icons\" | \"fold\" | \"menu\";\n\n/**\n * Words that wrap: their widths in order, the row height, the gap between words on a row (default 0) and the lead (the\n * grip's cell at the start of row one, default 0). The words wrap in their own box beside the lead, a hanging indent:\n * every row starts after it, so the grip never has a row of its own. Words flow onto a row while they fit; with two\n * words or more, every row but the last must hold at least two, or the form doesn't fit that cross size.\n */\nexport interface WrapSpec {\n readonly widths: readonly number[];\n readonly row: number;\n readonly gap?: number;\n readonly lead?: number;\n}\nexport type StackFormKind = PanelFormKind | GroupFormKind;\n\n/** Along the stack: `min` is the least it can be drawn, `natural` what it asks for; `grows` takes spare length. */\nexport interface MainSize {\n readonly min: number;\n readonly natural: number;\n readonly grows?: boolean;\n}\n\n/** One way to draw an item. A `menu` form takes no room in the stack (the » entry stands for it). */\nexport interface StackForm {\n readonly kind: StackFormKind;\n readonly main: MainSize;\n /**\n * Across the stack: `natural` is what this form asks for (it sets the stack's cross size when `setsCross`); `min`\n * is the least it can be drawn across (default `natural`). A form that doesn't set the cross size takes its next\n * form only when its `min` is over the stack's cross size, so a header stays in a column an open panel made\n * narrow when it has a small `min`.\n */\n readonly cross: { readonly natural: number; readonly min?: number };\n /**\n * Whether this form sets the stack's cross size (the column's width, the bar's height). Default: true for a\n * panel's `open`, false for everything else (a group never sets a column's width).\n */\n readonly setsCross?: boolean;\n /**\n * Give-way order (default 0). When the stack is too long, the step taken is the one into the lowest-ranked next\n * form across all items (the form the item would take, not the one it leaves); ties go unkept before kept, then the\n * item used longest ago, then the later in the stack. A pinned primary's last forms get a higher rank, so every\n * other group collapses before it does.\n */\n readonly rank?: number;\n /**\n * A form whose length depends on the cross size it gets (meant for a column of words). With it, `main` and `cross` are\n * computed and the given ones ignored: the rows are laid once the stack's cross size is known (beside the lead, a\n * hanging indent), and `main.min` and `main.natural` are rows × `row`. It fits a cross size only when no row but the\n * last holds a single word (`formFitsCross`); below that it is too wide and takes its next form, and `cross.min` is the\n * narrowest cross where it fits (`formCrossMin`). Its one-row width (lead, words and gaps) counts as `cross.natural` only\n * with `setsCross: true`; such a setter is clamped to the stack's limits like any setter and, without `strictCross`,\n * never goes to its next form. Give-way, fits, `previous` and growth use the computed length; under `ownCross` the item\n * is drawn as wide as its rows need. A word group needs an `icons` form after it: vertical places skip `wrap` forms.\n */\n readonly wrap?: WrapSpec;\n /**\n * A grip at the form's start along the stack, this long (an icons strip's horizontal grip on top). The scene reports\n * its rect; a `wrap` form's grip is its lead cell instead.\n */\n readonly grip?: number;\n}\n\nconst nonNeg = (x: number | undefined): number => (typeof x === \"number\" && Number.isFinite(x) ? Math.max(0, x) : 0);\n\n/**\n * The least a form can be drawn across the stack: its `cross.min` (default its `natural`), or for a `wrap` form the\n * narrowest cross size at which its rows fit (no single word on a row but the last). The scene's size clamp and column\n * shrink read it too.\n */\nexport function formCrossMin(f: StackForm): number {\n if (f.wrap) return wrapCross(f.wrap).min;\n const v = f.cross.min ?? f.cross.natural;\n return Number.isFinite(v) ? v : 0;\n}\n\n/** A form's length along the stack: its `main` size, or for a `wrap` form its rows at cross size `cross` times the row height. */\nexport function formMain(f: StackForm, which: \"min\" | \"natural\", cross: number): number {\n if (f.kind === \"menu\") return 0;\n if (f.wrap) return wrapRows(f.wrap, cross).rows * nonNeg(f.wrap.row);\n return nonNeg(f.main[which]);\n}\n\n/**\n * Whether a `wrap` form fits cross size `cross`: every word fits beside the lead, and no row but the last holds a single\n * word. True for any other form (their `cross.min` decides).\n */\nexport function formFitsCross(f: StackForm, cross: number): boolean {\n if (!f.wrap) return true;\n const widest = Math.max(0, ...f.wrap.widths.map(nonNeg));\n return cross + 1e-6 >= nonNeg(f.wrap.lead) + widest && wrapLines(f.wrap, cross).fits;\n}\n\n/** The widths a row can take: the lead and a run of neighbouring words, narrowest first. */\nfunction rowWidths(spec: WrapSpec): number[] {\n const gap = nonNeg(spec.gap);\n const lead = nonNeg(spec.lead);\n const widths = spec.widths.map(nonNeg);\n const out: number[] = [];\n for (let i = 0; i < widths.length; i++) {\n let run = 0;\n for (let j = i; j < widths.length; j++) {\n run += widths[j]! + (j > i ? gap : 0);\n out.push(lead + run);\n }\n }\n return out.sort((a, b) => a - b);\n}\n\n/**\n * A wrap form's rows at cross size `cross`: the word indexes per row, how wide the widest row is (the lead included),\n * and whether the form fits (with two words or more, no row but the last holds a single word). Greedy rows can leave a\n * single word on a row at one width and not at a narrower one, so when the rows at `cross` don't fit they are laid at\n * the widest narrower width that fits: a form that fits a cross size fits every wider one, and widening never turns\n * its words into icons.\n */\nexport function wrapLines(spec: WrapSpec, cross: number): { lines: number[][]; width: number; fits: boolean } {\n const g = greedyLines(spec, cross);\n if (g.fits) return g;\n const narrower = rowWidths(spec).filter((c) => c <= cross + 1e-6);\n for (let i = narrower.length - 1; i >= 0; i--) {\n const h = greedyLines(spec, narrower[i]!);\n if (h.fits) return h;\n }\n return g;\n}\n\n/** Rows laid greedily at cross size `cross`: each takes words while they fit, and always takes one. */\nfunction greedyLines(spec: WrapSpec, cross: number): { lines: number[][]; width: number; fits: boolean } {\n const gap = nonNeg(spec.gap);\n const lead = nonNeg(spec.lead);\n const widths = spec.widths.map(nonNeg);\n if (widths.length === 0) return { lines: [], width: lead, fits: true };\n // A hanging indent: every row starts after the lead; a row takes words while they fit, and always takes one.\n const box = cross - lead;\n const lines: number[][] = [[]];\n let x = 0;\n let widest = 0;\n widths.forEach((w, i) => {\n const row = lines[lines.length - 1]!;\n if (row.length > 0 && x + gap + w > box + 1e-6) {\n widest = Math.max(widest, x);\n lines.push([i]);\n x = w;\n } else {\n x = row.length > 0 ? x + gap + w : w;\n row.push(i);\n }\n });\n widest = Math.max(widest, x);\n const fits = widths.length < 2 || lines.slice(0, -1).every((l) => l.length >= 2);\n return { lines, width: lead + widest, fits };\n}\n\n/** A wrap form's rows at cross size `cross`: how many, how wide the widest is, and whether it fits. */\nexport function wrapRows(spec: WrapSpec, cross: number): { rows: number; width: number; fits: boolean } {\n const w = wrapLines(spec, cross);\n return { rows: Math.max(1, w.lines.length), width: w.width, fits: w.fits };\n}\n\n/**\n * A wrap form's one-row width, and the narrowest cross size at which it fits: its rows hold no single word on a row but\n * the last (with one word, the lead and that word). Looked for among the widths a row can take (the lead and a run of\n * words), the narrowest that fits.\n */\nexport function wrapCross(spec: WrapSpec): { natural: number; min: number } {\n const gap = nonNeg(spec.gap);\n const lead = nonNeg(spec.lead);\n const widths = spec.widths.map(nonNeg);\n const natural = lead + widths.reduce((s, w) => s + w, 0) + Math.max(0, widths.length - 1) * gap;\n if (widths.length < 2) return { natural, min: natural };\n // The narrowest cross where some width no wider fits (`wrapLines` lays the rows there) and every word fits beside the lead.\n const first = rowWidths(spec).find((c) => greedyLines(spec, c).fits) ?? natural;\n const min = Math.max(lead + Math.max(...widths), first);\n return { natural, min };\n}\n\nexport interface StackItem {\n readonly id: string;\n /** Largest first. The solver starts at `from` and steps down one at a time. An item with none is left out. */\n readonly forms: readonly StackForm[];\n /** How recently it was used: the smaller, the longer ago, the sooner it gives way. */\n readonly used: number;\n /** Kept: gives way after every item that isn't. */\n readonly kept?: boolean;\n /**\n * The first form the item may take, an index into `forms` (default 0; a panel folded by hand starts at its header).\n * The solver never goes above it. `form` in the result and in the notes are indexes into `forms`, not into what is\n * left after `from`.\n */\n readonly from?: number;\n /**\n * A fixed item is a reserved room, such as the title and the window controls of a title bar. It never gives way:\n * it keeps its first allowed form (`forms[from]`) whatever the length or the cross size, so it is never in the » menu\n * unless that is the form it starts in, and it doesn't take part in `previous`'s growing back. It counts toward the\n * length like any item (the others give way around it, and a stack too short for it overflows). It is never dragged:\n * `stackTargets` gives no target for it. And no drop slot is inside it: the gaps before and after it stay, but its\n * own area is in no gap's `hit`. Whether it may sit among others (or first, or last) is the host's; placement lays out\n * the items it is given.\n */\n readonly fixed?: boolean;\n}\n\n/** The cross size a stack may take. With no form setting it, the stack is a `rail` wide (default {@link DEFAULT_RAIL}). */\nexport interface CrossLimits {\n readonly min: number;\n readonly max: number;\n readonly rail?: number;\n}\n\nexport interface StackInput {\n readonly axis: StackAxis;\n /** The stack's length along the axis. */\n readonly length: number;\n readonly cross: CrossLimits;\n /** In order, from the start of the stack. */\n readonly items: readonly StackItem[];\n /** The » menu entry's size along the stack, taken only while an item is in the menu (default {@link DEFAULT_MENU}). */\n readonly menu?: { readonly main: number };\n /**\n * The space between neighbouring drawn items, px (default 0). The » entry is a neighbour of the last drawn item. It\n * counts toward the length and the rects include it, so an app draws at the solver's rects.\n */\n readonly gap?: number;\n /** Space before the first item and after the last (or after the » entry), px (default 0 each). Counts toward the length. */\n readonly pad?: { readonly start?: number; readonly end?: number };\n /**\n * Strict cross sizes (default false): a form is never drawn thinner than its `cross.min` (default its `natural`), so a\n * form that sets the cross size and has a `cross.min` over `cross.max` steps down to its next form (never into the\n * menu: with only the menu left it keeps its last drawn form and a `too-wide` note says so). Without it such a form is\n * only clamped to `cross.max`, as it always was.\n */\n readonly strictCross?: boolean;\n /**\n * Which items this stack takes (default: every item). `stackTargets` gives no target for a dragged item it doesn't\n * accept: an empty list, so a toolbar-only stack takes no panel and a panel-only one no group. What an item's kind is\n * stays the host's: placement only calls this, on the dragged item, and `fitStack` never does (items already in the\n * stack are laid out as given).\n */\n readonly accepts?: (item: StackItem) => boolean;\n /**\n * Groups take their own size across (default false: every item spans the stack's cross size). With it, an item whose\n * current form is a group kind (`row`, `stacked`, `wrap`, `icons`, `fold`; a `wrap` form as wide as its rows need) is drawn `cross.natural` across, clamped to the\n * stack's cross size, from the stack's start edge across (the left of a column, the top of a bar), so a group in a\n * side column is as wide as its own form asks, not as the column. Panel kinds (`open`, `header`, `rail`) and the »\n * entry still span it: every open panel and header fills the column. The kind decides, not `setsCross`, which still\n * decides the stack's cross size as before: a group's form that sets it (words in a column: `stacked` with\n * `setsCross: true`) widens the column to the widest such group but is drawn at its own width. The stack's cross\n * size, the forms, the notes and the lengths are as without it; only the rects of group forms are narrower, and\n * `stackTargets`' hits and markers still span the stack.\n */\n readonly ownCross?: boolean;\n}\n\n/** The width of a stack nothing open holds, px. */\nexport const DEFAULT_RAIL = 30;\n/** The » menu entry's size along the stack, px. */\nexport const DEFAULT_MENU = 28;\n\nconst finite = (x: number, fallback: number): number => (Number.isFinite(x) ? x : fallback);\n\n/**\n * The cross limits with a non-number replaced: `min` and `rail` that aren't finite become 0 and the default rail, a\n * `max` that is NaN becomes no limit (Infinity is one already), and `max` is never under `min`.\n */\nexport function limitsOf(input: StackInput): { readonly min: number; readonly max: number; readonly rail: number } {\n const min = Math.max(0, finite(input.cross.min, 0));\n const max = Number.isNaN(input.cross.max) ? Infinity : input.cross.max;\n return { min, max: Math.max(min, max), rail: Math.max(0, finite(input.cross.rail ?? DEFAULT_RAIL, DEFAULT_RAIL)) };\n}\nexport const menuMain = (input: StackInput): number => Math.max(0, finite(input.menu?.main ?? DEFAULT_MENU, DEFAULT_MENU));\n\n/** The gap and padding with a non-number or a negative one replaced by 0. */\nexport function spacingOf(input: StackInput): { readonly gap: number; readonly start: number; readonly end: number } {\n const px = (x: number | undefined): number => Math.max(0, finite(x ?? 0, 0));\n return { gap: px(input.gap), start: px(input.pad?.start), end: px(input.pad?.end) };\n}\n\n/** Whether a form sets the stack's cross size: its own say, else true for a panel's `open`. */\nexport const formSetsCross = (f: StackForm): boolean => f.setsCross ?? f.kind === \"open\";\n\n/** `input` with `item` inserted at index `at` (clamped to the items' range). */\nexport function withItem(input: StackInput, item: StackItem, at: number): StackInput {\n const k = Math.min(Math.max(0, Math.floor(at)), input.items.length);\n return { ...input, items: [...input.items.slice(0, k), item, ...input.items.slice(k)] };\n}\n\n/** An item drawn: the form it took, its kind and its rect (stack-local px). One in the menu has the menu entry's rect. */\nexport interface PlacedStackItem {\n readonly id: string;\n /** Index into the item's `forms`. */\n readonly form: number;\n readonly kind: StackFormKind;\n readonly rect: Rect;\n}\n\nexport interface StackMenu {\n /** The » entry's rect. */\n readonly rect: Rect;\n /** The items in it, in the stack's order: exactly the items whose kind is `menu`. */\n readonly items: readonly string[];\n}\n\n/**\n * Why a stack looks as it does:\n * - `form-down`: an item took a smaller form than the one it started in (`from`, an index into its forms), by length\n * or by cross size.\n * - `to-menu`: an item is in the » menu.\n * - `too-wide`: an item's form doesn't set the cross size and its `cross.min` is over the stack's, or (with `strictCross`)\n * it does and its `cross.min` is over the limits' `max`. Cross size never puts an item in the menu, so it keeps its last drawn form\n * and the app clips it.\n * - `no-forms`: an item with no forms, left out of `items`.\n * - `overflow`: no item can give more way and the stack is still `over` px too long (forms that don't end in a `menu`\n * form can't give more; neither can a stack where going into the menu would only make it longer).\n */\nexport type StackNote =\n | { readonly code: \"form-down\"; readonly id: string; readonly from: number; readonly to: number }\n | { readonly code: \"to-menu\"; readonly id: string }\n | { readonly code: \"too-wide\"; readonly id: string }\n | { readonly code: \"no-forms\"; readonly id: string }\n | { readonly code: \"overflow\"; readonly over: number };\nexport type StackNoteCode = StackNote[\"code\"];\n\nexport interface StackFit {\n readonly axis: StackAxis;\n readonly length: number;\n /** The stack's size across: the widest `open` (clamped to the limits), or the rail. */\n readonly cross: number;\n /** One per input item that has forms, in order. */\n readonly items: readonly PlacedStackItem[];\n /** The » entry, or null while no item is in the menu. */\n readonly menu: StackMenu | null;\n /** `no-forms` first, then `form-down` per item in the order they gave way, `to-menu`, `too-wide`, and `overflow`. */\n readonly notes: readonly StackNote[];\n /**\n * The length the chosen forms need at least: their smallest sizes, the » entry, the gaps and the padding. Over `length`\n * only when the stack overflows. `fitStack`'s `previous` reads it to tell room coming back from a change of ages.\n */\n readonly need?: number;\n /**\n * The give-way history: every step down from the items' starting forms to the forms chosen, in the order taken (items\n * that went into the » menu together share a `batch`). `fitStack`'s `previous` carries it on, and room coming back\n * undoes it from the last step: growing back is exactly the reverse of giving way.\n */\n readonly steps?: readonly StackStep[];\n}\n\n/** One give-way step: item `id` went from form `from` to form `to`; steps sharing a `batch` were taken together. */\nexport interface StackStep {\n readonly id: string;\n readonly from: number;\n readonly to: number;\n readonly batch?: number;\n}\n\n/** What `fitStack` and `stackTargets` take besides the input. */\nexport interface FitOptions {\n /**\n * The fit the stack had before. While the forms it chose still fit, they are kept: a change of `used` ages alone (a press\n * on a header) reshapes nothing. Ages decide only who gives way anew (the length shrank, an item was added or opened),\n * and room that came back is used, but growing never re-ranks: the fresh fit is taken when the stack got wider across;\n * otherwise room comes back by undoing the give-way history (`StackFit.steps`, carried on from fit to fit) from its\n * last step: a batch that went into the » menu together comes out together, an item goes back to the nearest earlier\n * form the stack fits with (the last item out of the menu takes the » entry with it), and the first step that can't\n * be undone stops all growth. Growing back is exactly the reverse of giving way, the menu included: at every length\n * the way back holds what the way down held, whatever presses changed the ages since; an item made `kept` after its\n * step comes back in step order, it doesn't jump ahead. A `previous` without a history\n * (built by hand, or by an older version) grows the old way: a fresh fit that is a pure gain, else the item that gave\n * way most recently (highest rank, then `kept`, the newest used, the earlier in the stack) first, menu items out only\n * while that keeps the order.\n * One px of room moves nothing. Results under `previous` depend on history: a shrink then a grow may end at another\n * arrangement than a fresh solve of the same input, and more room never undoes a growth along successive solves.\n * Growing back is meant for stacks of up to about 50 items (60 small menu items take about 9 ms; the cost grows with\n * about the cube of the count). Items it doesn't know start from their largest form; an item whose `from` went down\n * since (a panel opened), or whose form at the kept index is of another kind, starts over. A form that was only\n * re-measured keeps its place: smaller, it frees room that grows the kept forms; larger, it gives way from the kept\n * forms.\n *\n * Not covered: a lowered `cross.min` (or any change of the forms' cross sizes) doesn't bring a form back under\n * `previous`. After changing cross sizes, solve once without `previous`.\n */\n readonly previous?: StackFit;\n}\n","/**\n * `fitStack`: which form each item of a stack takes, and where it goes.\n *\n * 1. Every item starts in its largest form it may take (`forms[from]`, default the first).\n * 2. The stack's cross size is the largest `cross.natural` among the items whose form sets it (an open panel's, by\n * default), clamped to the limits; with none, the rail width.\n * 3. Cross-fit: an item whose form doesn't set the cross size and whose `cross.min` is over it steps down until it\n * fits (a group never sets a column's width, so a group alone becomes a rail of icons); so does one whose form does\n * set it but whose `cross.min` is over the limits' `max`, with `strictCross` (an open panel in a thin bar becomes a\n * header; without the option it is only clamped). Cross size never steps an item into the menu: when only the menu is left it keeps its last drawn form and a `too-wide` note\n * says so.\n * 4. Give-way: while the smallest sizes (`main.min`, plus the gaps and the padding) don't fit the length, one item\n * steps down. Each item's next step goes to the first later form that shortens the stack (a smaller total: the\n * form's `main.min`, the » entry when the form is the menu, the gaps gained or lost); forms that don't are skipped,\n * and an item with none stays. Of those steps the one into the lowest `rank` is taken; ties go unkept before kept,\n * then the item used longest ago, then the later in the stack. A `menu` form takes no room; the » entry does, while\n * any item is in it. The first item into the menu opens the entry: when it is stuck (no shorter form but the\n * menu) and alone is shorter than the entry, the stuck items go in as one batch, in give-way order, as few as\n * together shorten the stack; if all of them together don't, they stay. A `fold` form is an ordinary form with its\n * own length. Steps 2 to 4 repeat until nothing changes: a panel folding can narrow the column, which asks more of\n * the groups.\n * 5. The room the items leave goes to the forms that grow, shared by their natural sizes. With none, the items keep\n * their natural sizes from the start of the stack. Between the minimum and natural sizes every item shrinks by the\n * same share of what it can give.\n *\n * A `fixed` item takes part in none of steps 1 to 4: it keeps its first allowed form, counts toward the length, and the\n * others give way around it. In step 5 it shrinks and grows like any item.\n *\n * With `ownCross`, an item in a group form (`row`, `stacked`, `wrap`, `icons`, `fold`) is drawn at its own `cross.natural`\n * (clamped to the stack's cross size) from the start edge instead of across the whole stack; a panel form (`open`,\n * `header`, `rail`) still spans it. Nothing else changes.\n *\n * `gap` sits between neighbouring drawn items (the » entry is one), `pad` before the first and after the last; both\n * count toward the length and the rects include them, so an app draws at the rects.\n *\n * The solver has no open or closed state: it lays out the items it is given, and a consumer closes a panel by not\n * passing it (or by starting it at a later form with `from`). An item with no forms is left out (`no-forms`). Pure:\n * same input, same fit.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport { formCrossMin, formFitsCross, formMain, formSetsCross, limitsOf, menuMain, spacingOf, wrapCross, wrapRows, type FitOptions, type PlacedStackItem, type StackFit, type StackForm, type StackInput, type StackItem, type StackMenu, type StackNote, type StackStep } from \"./model\";\nconst isMenu = (f: StackForm): boolean => f.kind === \"menu\";\n/** The form kinds of a control group; `ownCross` draws these at their own size across. */\nconst GROUP_KINDS: ReadonlySet<string> = new Set([\"row\", \"stacked\", \"wrap\", \"icons\", \"fold\"]);\nconst finite = (x: number, fallback = 0): number => (Number.isFinite(x) ? x : fallback);\n/** A form's length along the stack; a `wrap` form's is its rows at cross size `cross` times the row height. */\nconst mainOf = formMain;\n/** The least a form can be drawn across the stack (a `wrap` form: the narrowest cross its rows fit). */\nconst crossMin = formCrossMin;\n/** What a form asks for across (a `wrap` form: its one-row width). */\nconst crossNatural = (f: StackForm): number => (f.wrap ? wrapCross(f.wrap).natural : finite(f.cross.natural));\n\nconst rankOf = (f: StackForm): number => finite(f.rank ?? 0);\n\n/**\n * The item that gives way next, among those with a step (`to[i]`, the form it would take, or -1): the lowest rank of the\n * form it steps into, unkept before kept, used longest ago, the later in the stack on a tie.\n */\nfunction victim(items: readonly StackItem[], to: readonly number[]): number {\n let best = -1;\n for (let i = 0; i < items.length; i++) {\n if (to[i]! < 0 || items[i]!.fixed) continue;\n if (best < 0) {\n best = i;\n continue;\n }\n const a = items[i]!;\n const b = items[best]!;\n const ra = rankOf(a.forms[to[i]!]!);\n const rb = rankOf(b.forms[to[best]!]!);\n const ka = a.kept ? 1 : 0;\n const kb = b.kept ? 1 : 0;\n if (ra !== rb ? ra < rb : ka !== kb ? ka < kb : a.used !== b.used ? a.used < b.used : true) best = i;\n }\n return best;\n}\n\n/**\n * `fitStack(input, options?)`. With `options.previous` (the fit the stack had before) the forms it chose are kept while\n * they still fit: the solve starts from them instead of from every item's largest form, so a change of ages alone\n * (a press on a header) reshapes nothing, and ages decide only who gives way anew when the length shrank or an item\n * was added or opened. Room that came back is used, but growing never re-ranks. When the stack got wider across (a wider\n * limit lets a panel open wider, and the forms that stepped down for the old width may come back) the fresh fit is\n * taken. When the forms kept leave more spare length than they did (the length grew, a gap or a size shrank; `need` is\n * what each fit says its forms need) room comes back by undoing the give-way history (`steps`, carried on from fit to\n * fit) from its last step, a batch into the » menu together, an item to the nearest earlier form that fits; the first\n * step that can't be undone stops all growth. So growing back is exactly the reverse of giving way: at every length the\n * way back holds what the way down held. A `previous` without a history (built by hand, or by an older version) grows\n * the old way: a fresh fit that is a pure gain over the kept one, else the item that gave way most recently by its\n * rank, `kept` and age first, one at a time, menu items out only when that keeps the order. A `previous` with no `need`\n * (one an app built by hand) is no help and the fresh fit is returned.\n */\nexport function fitStack(input: StackInput, options: FitOptions = {}): StackFit {\n const fresh = solve(input);\n const previous = options.previous;\n if (!previous || previous.need === undefined) return fresh;\n const seed = { need: 0 };\n const kept = solve(input, previous, seed);\n if (kept.cross > previous.cross + EPS) return fresh;\n const moreLength = Math.max(0, kept.length) - seed.need > previous.length - previous.need + EPS;\n if (!moreLength) return kept;\n // With the give-way history, room comes back by undoing it from the last step (exactly the reverse); without one (a\n // previous fit built by hand, or by an older version), a fresh fit that is a pure gain is taken.\n const gain = !previous.steps && fresh.items.every((p, i) => p.form <= kept.items[i]!.form) && fresh.items.some((p, i) => p.form < kept.items[i]!.form);\n return gain ? fresh : solve(input, previous, { need: 0 }, true);\n}\n\n/**\n * `seed.need` (when given) is told the length the forms taken from `previous` need under this input, before any step.\n * With `grow` the forms taken from `previous` grow back while the stack still fits, in the reverse of give-way order.\n */\nfunction solve(input: StackInput, previous?: StackFit, seed?: { need: number }, grow = false): StackFit {\n const length = Math.max(0, finite(input.length));\n const lim = limitsOf(input);\n const items = input.items.filter((it) => it.forms.length > 0);\n const start = items.map((it) => Math.min(Math.max(0, Math.floor(finite(it.from ?? 0))), it.forms.length - 1));\n const at = [...start];\n if (previous) {\n // An item the previous fit had keeps its form while `from` still allows it and the form at that index is still of the\n // same kind; one whose `from` went down since (a panel opened) starts over, and so does a new one or one whose forms\n // changed. Where an item started then is its first `form-down` note's `from`, or the form it had when it never moved.\n const had = new Map(previous.items.map((p) => [p.id, p]));\n const began = new Map<string, number>();\n for (const n of previous.notes) if (n.code === \"form-down\" && !began.has(n.id)) began.set(n.id, n.from);\n items.forEach((it, i) => {\n const p = had.get(it.id);\n if (it.fixed || !p || p.form < start[i]! || p.form >= it.forms.length || start[i]! < (began.get(it.id) ?? p.form)) return;\n const f = it.forms[p.form]!;\n // The size isn't compared: a form re-measured (a badge gained a digit) is still the form it was. A smaller one\n // frees room, which the fresh fit takes (`need`), a larger one gives way from the kept forms.\n if (f.kind === p.kind) at[i] = p.form;\n });\n }\n const form = (i: number): StackForm => items[i]!.forms[at[i]!]!;\n const idx = items.map((_, i) => i);\n\n // The give-way history: carried on from `previous` for the items whose steps still lead from their start to the form\n // they keep, then every step taken here. Room coming back undoes it from the last step.\n const hist: StackStep[] = [];\n const withHistory = new Set<string>();\n let batches = 0;\n if (previous?.steps) {\n const byId = new Map(items.map((it, i) => [it.id, i]));\n const ends = new Map<string, number>();\n const good = new Set<string>(items.map((it) => it.id));\n for (const s of previous.steps) {\n const i = byId.get(s.id);\n if (i === undefined) continue;\n if (s.from !== (ends.get(s.id) ?? start[i]!)) good.delete(s.id);\n ends.set(s.id, s.to);\n }\n items.forEach((it, i) => {\n if ((ends.get(it.id) ?? start[i]!) !== at[i]) good.delete(it.id);\n });\n for (const s of previous.steps) if (good.has(s.id) && byId.has(s.id)) hist.push(s);\n for (const s of hist) {\n withHistory.add(s.id);\n if (s.batch !== undefined) batches = Math.max(batches, s.batch + 1);\n }\n }\n const firstStep: number[] = [];\n const menuOrder: number[] = [];\n const step = (i: number, j: number, batch?: number): void => {\n if (!firstStep.includes(i)) firstStep.push(i);\n hist.push({ id: items[i]!.id, from: at[i]!, to: j, ...(batch !== undefined ? { batch } : {}) });\n withHistory.add(items[i]!.id);\n at[i] = j;\n if (isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);\n };\n // Items kept from the previous fit give way (and entered the menu) in the order its notes say, then the rest by place.\n const named = (code: \"form-down\" | \"to-menu\"): number[] => (previous ? previous.notes.filter((n) => n.code === code).map((n) => items.findIndex((it) => it.id === (n as { id: string }).id)) : []);\n for (const i of [...named(\"form-down\"), ...idx]) if (i >= 0 && at[i]! > start[i]! && !firstStep.includes(i)) firstStep.push(i);\n // An item that starts in the menu is in it from the start.\n for (const i of [...named(\"to-menu\"), ...idx]) if (i >= 0 && isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);\n\n const crossOf = (): number => {\n const setters = idx.filter((i) => !isMenu(form(i)) && formSetsCross(form(i)));\n if (setters.length === 0) return lim.rail;\n const want = Math.max(...setters.map((i) => crossNatural(form(i))));\n return Math.min(Math.max(want, lim.min), lim.max);\n };\n const inMenu = (): boolean => idx.some((i) => isMenu(form(i)));\n const sp = spacingOf(input);\n /** The gaps between `slots` neighbours: the drawn items, and the » entry while any item is in it. */\n const gapsOf = (): number => {\n const slots = idx.filter((i) => !isMenu(form(i))).length + (inMenu() ? 1 : 0);\n return slots > 1 ? (slots - 1) * sp.gap : 0;\n };\n /** The shortest the stack can be drawn now: the smallest sizes, the » entry, the gaps and the padding. */\n const minSum = (): number => {\n // A wrap form's length follows the cross size the forms make now.\n const c = items.some((it) => it.forms.some((f) => f.wrap)) ? crossOf() : 0;\n return idx.reduce((s, i) => s + mainOf(form(i), \"min\", c), 0) + (inMenu() ? menuMain(input) : 0) + gapsOf() + sp.start + sp.end;\n };\n /** The form item `i` would step to: the first later one that shortens the stack, else -1 (it stays). */\n const stepTo = (i: number): number => {\n const from = at[i]!;\n const base = minSum();\n let found = -1;\n for (let j = from + 1; j < items[i]!.forms.length && found < 0; j++) {\n at[i] = j;\n if (minSum() < base - EPS) found = j;\n }\n at[i] = from;\n return found;\n };\n /** The first menu form after item `i`'s current one, or -1. */\n const menuFormAfter = (i: number): number => {\n for (let j = at[i]! + 1; j < items[i]!.forms.length; j++) if (isMenu(items[i]!.forms[j]!)) return j;\n return -1;\n };\n /**\n * The items to step into the menu together, as [item, form] pairs in give-way order: the fewest from `pool` (the form\n * each would take, -1 for an item not in it) that together shorten the stack, entry and gaps counted. Null when even\n * all of them don't.\n */\n const menuBatch = (pool: readonly number[]): [number, number][] | null => {\n const saved = [...at];\n const base = minSum();\n const left = [...pool];\n const batch: [number, number][] = [];\n let found = false;\n for (let b = victim(items, left); b >= 0 && !found; b = victim(items, left)) {\n batch.push([b, left[b]!]);\n at[b] = left[b]!;\n left[b] = -1;\n found = minSum() < base - EPS;\n }\n at.splice(0, at.length, ...saved);\n return found ? batch : null;\n };\n const canStep = (i: number): boolean => at[i]! + 1 < items[i]!.forms.length;\n const tooWide = (i: number, cross: number): boolean => {\n const f = form(i);\n if (isMenu(f)) return false;\n // A form that sets the cross size is clamped to `max`, as it always was; only with `strictCross` is it never drawn\n // thinner than its `cross.min`, and steps down when that is over `max`.\n if (formSetsCross(f)) return input.strictCross === true && crossMin(f) > lim.max + EPS;\n // A wrap form fits only where its rows do (no single word on a row but the last): checked at this cross itself.\n if (f.wrap) return !formFitsCross(f, cross);\n return crossMin(f) > cross + EPS;\n };\n\n if (seed) seed.need = minSum();\n if (grow) {\n // Room came back and the kept forms fit: they grow back one at a time, the reverse of how they gave way (the form an\n // item is in now was stepped into at its rank, so the highest rank first, then `kept`, the newest used, the earlier\n // in the stack). An item goes back to the nearest earlier form the stack still fits with, the cross size unchanged:\n // a larger form is what counts, not a longer stack (the last item leaving the menu takes the » entry with it).\n const comesBefore = (a: number, b: number): boolean => {\n const ra = rankOf(items[a]!.forms[at[a]!]!);\n const rb = rankOf(items[b]!.forms[at[b]!]!);\n const ka = items[a]!.kept ? 1 : 0;\n const kb = items[b]!.kept ? 1 : 0;\n return ra !== rb ? ra > rb : ka !== kb ? ka > kb : items[a]!.used !== items[b]!.used ? items[a]!.used > items[b]!.used : a < b;\n };\n // With the give-way history: undo it from the last step (a batch into the menu comes out together) while the stack\n // still fits; the first step that can't be undone stops all growth. Exactly the reverse of giving way.\n const index = new Map(items.map((it, i) => [it.id, i]));\n let stuck = false;\n const undoes = (n: number, c0: number): boolean => {\n const group = hist.slice(hist.length - n);\n const changed = [...new Set(group.map((s) => index.get(s.id)!))];\n const was = changed.map((i) => at[i]!);\n for (const s of [...group].reverse()) at[index.get(s.id)!] = s.from;\n if (minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0))) return true;\n changed.forEach((i, k) => (at[i] = was[k]!));\n return false;\n };\n while (hist.length > 0) {\n const c0 = crossOf();\n const last = hist[hist.length - 1]!;\n let n = 1;\n if (last.batch !== undefined) while (n < hist.length && hist[hist.length - 1 - n]!.batch === last.batch) n++;\n // An item goes back to the nearest earlier form the stack fits with: when undoing its last step doesn't fit, its\n // steps just before it (in a row at the end of the history) are undone with it.\n let took = 0;\n for (let m = n; m <= hist.length && took === 0; m++) {\n if (m > n && (last.batch !== undefined || hist[hist.length - m]!.id !== last.id)) break;\n if (undoes(m, c0)) took = m;\n }\n if (took === 0) {\n stuck = true;\n break;\n }\n hist.length -= took;\n }\n // Without a history (a previous fit built by hand, or items whose steps it lost): the items next in the reverse of\n // give-way order. Strictly as a stack: only the item next in that order may grow. When it can't, growth stops; no\n // item behind it jumps the queue (a leading group never opens while a trailing one that gave way after it stays\n // folded).\n for (;;) {\n if (stuck) break;\n const c0 = crossOf();\n const fitsWith = (changed: readonly number[]): boolean => minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0));\n const queue = idx.filter((i) => !items[i]!.fixed && at[i]! > start[i]! && !withHistory.has(items[i]!.id)).sort((a, b) => (comesBefore(a, b) ? -1 : 1));\n const next = queue[0];\n if (next === undefined) break;\n const cur = at[next]!;\n let to = -1;\n for (let k = cur - 1; k >= start[next]! && to < 0; k--) {\n at[next] = k;\n if (fitsWith([next])) to = k;\n }\n at[next] = cur;\n if (to >= 0) {\n at[next] = to;\n continue;\n }\n // The next item can't grow alone. Items in the menu may still come out, the fewest in the same order that fit\n // (together when only their leaving together removes the » entry), but only while that keeps the order: an item\n // leaves the menu only with every menu item ahead of it, only for a form no fewer steps down from its start than\n // every item ahead of it that isn't in the menu (the items that opened the entry went in together, after the others\n // had stepped down as far as they could), and never ahead of an item whose step down ranked higher than its own\n // step into the menu (that step came after it: room returns to the most recent give-way first). Steps count from\n // each item's `from`.\n const inside: number[] = [];\n for (const [q, i] of queue.entries()) {\n if (!isMenu(form(i))) continue;\n const ahead = queue.slice(0, q);\n if (!ahead.every((j) => isMenu(form(j)) || (at[i]! - 1 - start[i]! >= at[j]! - start[j]! && rankOf(form(i)) >= rankOf(form(j))))) break;\n inside.push(i);\n }\n let out = false;\n for (let n = 1; n <= inside.length && !out; n++) {\n const group = inside.slice(0, n);\n const was = group.map((i) => at[i]!);\n for (const i of group) at[i] = at[i]! - 1;\n if (fitsWith(group)) out = true;\n else group.forEach((i, k) => (at[i] = was[k]!));\n }\n if (!out) break;\n }\n }\n let cross = crossOf();\n let overflow = 0;\n // Every pass steps at least one item one form (by cross size or by length), so twice the forms is more than enough.\n const guard = 2 * items.reduce((s, it) => s + it.forms.length, 0) + 2;\n for (let n = 0; n <= guard; n++) {\n cross = crossOf();\n // Too wide for the stack: step down, but never into the menu (that is the length's call).\n let stepped = false;\n for (const i of idx) {\n if (!items[i]!.fixed && tooWide(i, cross) && canStep(i) && !isMenu(items[i]!.forms[at[i]! + 1]!)) {\n step(i, at[i]! + 1);\n stepped = true;\n }\n }\n if (stepped) continue;\n const over = minSum() - length;\n if (over <= EPS) break;\n // A fixed item never gives way: it has no step.\n const to = idx.map((i) => (items[i]!.fixed ? -1 : stepTo(i)));\n // Items that can't shorten the stack on their own but have the menu ahead: while the » entry doesn't exist, the\n // first one in costs the entry, so they go in together or not at all.\n const pool = idx.map((i) => (to[i]! < 0 && !inMenu() && !items[i]!.fixed ? menuFormAfter(i) : -1));\n const v = victim(\n items,\n idx.map((i) => (to[i]! >= 0 ? to[i]! : pool[i]!)),\n );\n if (v >= 0 && to[v]! < 0) {\n const batch = menuBatch(pool);\n if (batch) {\n const id = batches++;\n for (const [i, j] of batch) step(i, j, id);\n continue;\n }\n }\n const w = v >= 0 && to[v]! >= 0 ? v : victim(items, to);\n if (w < 0) {\n overflow = items.length > 0 ? over : 0;\n break;\n }\n step(w, to[w]!);\n }\n cross = crossOf();\n\n // Sizes along the stack.\n const menuSize = inMenu() ? menuMain(input) : 0;\n const avail = Math.max(0, length - sp.start - sp.end - gapsOf() - menuSize);\n const drawn = idx.filter((i) => !isMenu(form(i)));\n const min = (i: number): number => mainOf(form(i), \"min\", cross);\n const nat = (i: number): number => Math.max(min(i), mainOf(form(i), \"natural\", cross));\n const sumMin = drawn.reduce((s, i) => s + min(i), 0);\n const sumNat = drawn.reduce((s, i) => s + nat(i), 0);\n const size = new Map<number, number>();\n if (sumNat <= avail + EPS) {\n const growers = drawn.filter((i) => form(i).main.grows);\n const spare = Math.max(0, avail - sumNat);\n const weight = growers.reduce((s, i) => s + nat(i), 0);\n for (const i of drawn) {\n const share = growers.includes(i) ? (weight > EPS ? nat(i) / weight : 1 / growers.length) : 0;\n size.set(i, nat(i) + spare * share);\n }\n } else {\n const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;\n for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);\n }\n\n const rectAt = (from: number, main: number, across = cross): Rect => (input.axis === \"column\" ? { x: 0, y: from, width: across, height: main } : { x: from, y: 0, width: main, height: across });\n /**\n * The size across an item is drawn: the stack's, or with `ownCross` and a group form (`row`, `stacked`, `wrap`, `icons`, `fold`),\n * its own `cross.natural` (clamped to the stack's), from the start edge. The kind decides, not `setsCross`: a group's\n * form that sets the cross size (a column of words) widens the column but is drawn at its own width, and a panel's form\n * (`open`, `header`, `rail`) and the » entry fill the stack.\n */\n const acrossOf = (i: number): number => {\n const f = form(i);\n if (input.ownCross !== true || !GROUP_KINDS.has(f.kind)) return cross;\n // A wrap form is as wide as its rows need at the stack's cross size.\n if (f.wrap) return Math.min(cross, wrapRows(f.wrap, cross).width);\n return Math.min(cross, Math.max(0, finite(f.cross.natural, cross)));\n };\n const rects = new Map<number, Rect>();\n let cursor = sp.start;\n for (const i of drawn) {\n const s = size.get(i)!;\n rects.set(i, rectAt(cursor, s, acrossOf(i)));\n cursor += s + sp.gap;\n }\n // The » entry sits at the end of the stack, after the padding, or right after the last item when room is short.\n const menuRect = rectAt(Math.max(drawn.length > 0 ? cursor : sp.start, length - sp.end - menuSize), menuSize);\n const inside = idx.filter((i) => isMenu(form(i)));\n const menu: StackMenu | null = inside.length > 0 ? { rect: menuRect, items: inside.map((i) => items[i]!.id) } : null;\n\n const placed: PlacedStackItem[] = idx.map((i) => ({ id: items[i]!.id, form: at[i]!, kind: form(i).kind, rect: isMenu(form(i)) ? menuRect : rects.get(i)! }));\n\n const notes: StackNote[] = [];\n for (const it of input.items) if (it.forms.length === 0) notes.push({ code: \"no-forms\", id: it.id });\n for (const i of firstStep) if (at[i]! > start[i]!) notes.push({ code: \"form-down\", id: items[i]!.id, from: start[i]!, to: at[i]! });\n for (const i of menuOrder) if (isMenu(form(i))) notes.push({ code: \"to-menu\", id: items[i]!.id });\n for (const i of idx) if (tooWide(i, cross)) notes.push({ code: \"too-wide\", id: items[i]!.id });\n if (overflow > EPS) notes.push({ code: \"overflow\", over: overflow });\n return { axis: input.axis, length, cross, items: placed, menu, notes, need: minSum(), steps: hist };\n}\n","/**\n * The stack's stored form: `storeStack(state)` gives plain JSON-safe data (`{ v: 1, order, kept, closed, used, forms\n * }`); `readStack(data, known?)` reads parsed data back and never throws. Anything but an object of version 1 is\n * `{ ok: false, error }`. Inside one it is lenient, as the panels' reader is: an id that isn't a string, is repeated\n * or (with `known`) isn't one the consumer has is dropped and listed in `dropped`; a `kept`, `closed`, `used` or\n * `forms` entry for an id that isn't in `order` is dropped; a form that isn't a whole number from 1 up is dropped;\n * the key `__proto__` in `forms` is dropped (the other keys, `constructor` and `prototype` included, are ids like any\n * other: `forms` is an object with no prototype, written and read); a field this version doesn't know is skipped and\n * reported as `\"<field>\"`. An item the consumer has that the stored order lacks is no error: the consumer places it.\n *\n * - `kept`: items kept open (they give way last).\n * - `closed`: items the user closed; their place in `order` is kept for when they open.\n * - `used`: the use order, oldest to newest, so a reload restores who gives way first (an item's `used` is its index in\n * it; one the list lacks is older than all). An id listed twice counts at its last place: the newest use wins.\n * - `forms`: the user's chosen form per item, the index of the largest form it may take (`StackItem.from`). 0, the\n * first, is not stored.\n */\n\nexport interface StackState {\n /** The items' order along the stack. */\n readonly order: readonly string[];\n /** Items kept open: they give way last. */\n readonly kept: readonly string[];\n /** Items the user closed. */\n readonly closed: readonly string[];\n /** The use order, oldest first. */\n readonly used: readonly string[];\n /** The form index the user chose per item (only those that chose one; absent means the first). */\n readonly forms: Readonly<Record<string, number>>;\n}\n\nexport interface StoredStack {\n readonly v: 1;\n readonly order: string[];\n readonly kept: string[];\n readonly closed: string[];\n readonly used: string[];\n readonly forms: Record<string, number>;\n}\n\nexport type StackRead = { readonly ok: true; readonly state: StackState; readonly dropped: readonly string[] } | { readonly ok: false; readonly error: string };\n\n/** A state with these items in this order, none kept or closed, used in that order, every form the first. */\nexport const createStack = (order: readonly string[]): StackState => ({ order: [...order], kept: [], closed: [], used: [...order], forms: {} });\n\nconst isForm = (f: unknown): f is number => typeof f === \"number\" && Number.isInteger(f) && f >= 1;\n/** Ids that are in `order`, each once, at the first place it was listed. */\nconst uniq = (ids: readonly string[], order: readonly string[]): string[] => [...new Set(ids)].filter((id) => order.includes(id));\n/** Ids that are in `order`, each once, at the last place it was listed (the newest use wins). */\nconst uniqLast = (ids: readonly string[], order: readonly string[]): string[] => ids.filter((id, i) => order.includes(id) && ids.lastIndexOf(id) === i);\n/** Forms live in an object with no prototype, so no key (`constructor`, `prototype`) is more than a key; only `__proto__` is refused. */\nconst noForms = (): Record<string, number> => Object.create(null) as Record<string, number>;\n\nexport function storeStack(state: StackState): StoredStack {\n const forms = noForms();\n for (const id of state.order) {\n const f = state.forms[id];\n if (id !== \"__proto__\" && Object.hasOwn(state.forms, id) && isForm(f)) forms[id] = f;\n }\n return { v: 1, order: [...state.order], kept: uniq(state.kept, state.order), closed: uniq(state.closed, state.order), used: uniqLast(state.used, state.order), forms };\n}\n\nconst isObject = (x: unknown): x is Record<string, unknown> => typeof x === \"object\" && x !== null && !Array.isArray(x);\n\nexport function readStack(data: unknown, known?: readonly string[]): StackRead {\n try {\n return read(data, known);\n } catch (e) {\n // A getter that throws, a proxy: still no throw.\n return { ok: false, error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };\n }\n}\n\n/** A stored version in words for an error (a string is quoted and cut); shared with the floats' reader, not exported from the entry. */\nexport const versionWords = (v: unknown): string => (typeof v === \"number\" ? String(v) : typeof v === \"string\" ? JSON.stringify(v.length > 24 ? `${v.slice(0, 24)}…` : v) : typeof v);\n\nfunction read(data: unknown, known?: readonly string[]): StackRead {\n if (!isObject(data)) return { ok: false, error: \"not an object\" };\n if (data.v !== 1) return { ok: false, error: `unknown version ${versionWords(data.v)} (this reads version 1)` };\n if (!Array.isArray(data.order)) return { ok: false, error: \"order is missing\" };\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\", \"order\", \"kept\", \"closed\", \"used\", \"forms\"].includes(k)) drop(k);\n const order: string[] = [];\n for (const x of data.order as unknown[]) {\n if (typeof x !== \"string\") drop(`a ${typeof x} where an id goes`);\n else if ((known && !known.includes(x)) || order.includes(x)) drop(x);\n else order.push(x);\n }\n // A list of ids that are in `order`, each once: at the first place it was listed, or for `used` the last (the newest use wins).\n const list = (key: \"kept\" | \"closed\" | \"used\"): string[] => {\n const out: string[] = [];\n const x = data[key];\n if (x === undefined) return out;\n if (!Array.isArray(x)) {\n drop(key);\n return out;\n }\n for (const id of x as unknown[]) {\n if (typeof id === \"string\" && order.includes(id)) {\n if (key === \"used\" && out.includes(id)) out.splice(out.indexOf(id), 1);\n if (!out.includes(id)) out.push(id);\n } else drop(typeof id === \"string\" ? `${key}:${id}` : `a ${typeof id} in ${key}`);\n }\n return out;\n };\n const kept = list(\"kept\");\n const closed = list(\"closed\");\n const used = list(\"used\");\n const forms = noForms();\n if (data.forms !== undefined) {\n if (!isObject(data.forms)) drop(\"forms\");\n else {\n for (const id of Object.keys(data.forms)) {\n const f = data.forms[id];\n if (id === \"__proto__\" || !Object.hasOwn(data.forms, id) || !order.includes(id) || !isForm(f)) drop(`forms:${id}`);\n else forms[id] = f;\n }\n }\n }\n return { ok: true, state: { order, kept, closed, used, forms }, dropped };\n}\n","/**\n * Floats for the edge stack: an item that isn't docked lies above the pages in the stage's own px (view space), so the\n * pages scrolling under it never move it. A float has no pinned flag: there is one kind of float, and it is in view\n * space. Pure, like the rest of `./stack`.\n *\n * - `fitFloat(rect, stage, avoid)`: the rect a float gets. It is moved (never resized) to lie inside the stage, then\n * beside whatever docked content it would cover: the nearest place inside the stage that is clear of every `avoid`\n * rect (the docked items' rects, in the same px). One larger than the stage keeps its top-left corner on the\n * stage's; if no clear place exists the float stays where it covers the least and `covers` says which rects.\n * A clear place is found whenever one exists: the x's are tried nearest first and, for each, the blocked stretches of\n * y are merged and skipped, so no clear place is missed however many places lie between. Cost (measured in a test\n * run on a laptop): about 100 docked rects 0.1 ms, 300 a few ms even when no place is clear (6 ms median, 15 ms\n * worst), 1,000 about 17 ms; a safety net stops the clear search after 3 million rect tests and says so in\n * `searchCapped`; a stage with no clear place looks at the 2,048 nearest places for the least covered.\n * - `stackFloatTarget(input)`: a drop target in the shape `@n-uf/motion/drag` takes, free (no room is made for it),\n * `kind` `\"float\"`, id `float:<item>`, whose `hit` covers the whole plane, so a pointer past the stage's edge still\n * hits it (a float drop never cancels), at priority 3 so a docked stack's gaps win where they are. `make(point,\n * grab)` is the one answer for the preview and the drop: the float's rect with the pointer holding it at `grab`,\n * clamped and clear of the docked content.\n * - `storeFloats` / `readFloats`: the stored form, `{ v: 1, floats: [{ id, x, y, width, height }] }`, in stacking\n * order (the last is on top). It writes no `pinned`; one an old store has is read, ignored and listed.\n */\nimport { PLANE, clampInto, overlap, overlaps, rect, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Target } from \"../target\";\nimport { versionWords } from \"./store\";\n\n/** A float: the item's id and its rect in view space (the stage's px). */\nexport interface StackFloat {\n readonly id: string;\n readonly rect: Rect;\n}\n\nexport interface FloatFit {\n /** The float's rect: inside the stage and clear of the docked content where a clear place exists. */\n readonly rect: Rect;\n /** It was moved to lie inside the stage. */\n readonly clamped: boolean;\n /** It was moved beside the docked content it would have covered. */\n readonly snapped: boolean;\n /**\n * Indexes into `avoid` of the rects it still covers. Empty whenever a clear place was found, which is whenever one\n * exists (unless `searchCapped`); not empty only when the stage has no clear place for the float, and then it stays\n * where it covers the least among the 2,048 nearest candidate places.\n */\n readonly covers: readonly number[];\n /** The safety net on the clear search was hit (thousands of rects): the place found may not be the nearest, or a clear place may exist that was not found. Normally false. */\n readonly searchCapped: boolean;\n}\n\n/** How far floats compare loosely: a float's px are rounded, so a thousandth is touching. */\nconst EPS = 1e-3;\nconst finite = (x: number, fallback: number): number => (Number.isFinite(x) ? x : fallback);\n\n/** `r` with a non-number replaced and no negative size. */\nconst clean = (r: Rect, at: Rect): Rect => rect(finite(r.x, at.x), finite(r.y, at.y), Math.max(0, finite(r.width, 0)), Math.max(0, finite(r.height, 0)));\n\n/** A safety net on the clear search, in rect tests (only thousands of rects reach it), and the places the least-covered search looks at. */\nconst WORK = 3_000_000;\nconst COVERED_PLACES = 2048;\n\ntype Triple = [number, number, number];\n\n/** A binary min-heap of `[index, index, distance]` triples, by distance then indexes (a fixed order). */\nclass Nearest {\n private readonly h: Triple[] = [];\n private less(a: Triple, b: Triple): boolean {\n return a[2] !== b[2] ? a[2] < b[2] : a[0] !== b[0] ? a[0] < b[0] : a[1] < b[1];\n }\n get size(): number {\n return this.h.length;\n }\n push(t: Triple): void {\n const h = this.h;\n let i = h.push(t) - 1;\n while (i > 0) {\n const p = (i - 1) >> 1;\n if (!this.less(h[i]!, h[p]!)) break;\n [h[i], h[p]] = [h[p]!, h[i]!];\n i = p;\n }\n }\n pop(): Triple {\n const h = this.h;\n const top = h[0]!;\n const last = h.pop()!;\n if (h.length > 0) {\n h[0] = last;\n let i = 0;\n for (;;) {\n const l = 2 * i + 1;\n const r = l + 1;\n let m = i;\n if (l < h.length && this.less(h[l]!, h[m]!)) m = l;\n if (r < h.length && this.less(h[r]!, h[m]!)) m = r;\n if (m === i) break;\n [h[i], h[m]] = [h[m]!, h[i]!];\n i = m;\n }\n }\n return top;\n }\n}\n\n/** The places `xs` crossed with `ys`, nearest to `(fx, fy)` first (Euclidean), without building the cross product. */\nfunction* byDistance(xs: readonly number[], ys: readonly number[], fx: number, fy: number): Generator<{ x: number; y: number; far: number }> {\n const sx = [...xs].sort((a, b) => Math.abs(a - fx) - Math.abs(b - fx) || a - b);\n const sy = [...ys].sort((a, b) => Math.abs(a - fy) - Math.abs(b - fy) || a - b);\n const q = new Nearest();\n const d = (i: number, j: number): number => Math.hypot(sx[i]! - fx, sy[j]! - fy);\n // Each x starts at its nearest y; popping a place pushes the same x's next y.\n if (sy.length > 0) for (let i = 0; i < sx.length; i++) q.push([i, 0, d(i, 0)]);\n while (q.size > 0) {\n const [i, j, far] = q.pop();\n yield { x: sx[i]!, y: sy[j]!, far };\n if (j + 1 < sy.length) q.push([i, j + 1, d(i, j + 1)]);\n }\n}\n\nexport function fitFloat(want: Rect, stage: Rect, avoid: readonly Rect[] = []): FloatFit {\n const area = clean(stage, rect(0, 0, 0, 0));\n const r = clean(want, area);\n const inside = clampInto(r, area);\n // Compared with what was asked, so a position that wasn't a number (and was replaced) counts as moved.\n const clamped = inside.x !== want.x || inside.y !== want.y;\n // Only rects that can touch the float wherever the stage lets it be: its reach.\n const reach = rect(area.x, area.y, Math.max(area.width, r.width), Math.max(area.height, r.height));\n const near: { at: Rect; index: number }[] = [];\n avoid.forEach((a, index) => {\n const at = clean(a, area);\n if (at.width > EPS && at.height > EPS && overlaps(at, reach, EPS)) near.push({ at, index });\n });\n const under = (cand: Rect): number[] => near.filter((n) => overlaps(cand, n.at, EPS)).map((n) => n.index);\n const blocked = (cand: Rect): boolean => near.some((n) => overlaps(cand, n.at, EPS));\n if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };\n\n // The places to look at: every x that puts the float against an edge of the stage or of a rect (or where it is),\n // crossed with every y that does; a clear place exists if one does at all, as a float slid against edges.\n const lo = (v: number, from: number, to: number): number => Math.min(Math.max(v, from), Math.max(from, to));\n const xs = [inside.x, area.x, area.x + area.width - r.width];\n const ys = [inside.y, area.y, area.y + area.height - r.height];\n for (const { at } of near) {\n xs.push(at.x - r.width, at.x + at.width);\n ys.push(at.y - r.height, at.y + at.height);\n }\n const places = (list: number[], from: number, size: number, extent: number): number[] => [...new Set(list.map((v) => lo(v, from, from + extent - size)))];\n const px = places(xs, area.x, r.width, area.width);\n const py = places(ys, area.y, r.height, area.height);\n // Nearest clear place: the x's nearest first; for each, the rects that overlap that x block open stretches of y, and\n // the nearest clear y is the wanted one if it is clear, else the end of the stretch it is in (the stretches are\n // merged, so a whole blocked run is skipped at once). A later x can't beat a clear place at least as far as its x\n // alone, so the search stops there. `WORK` bounds the rect tests as a safety net.\n const ylo = area.y;\n const yhi = Math.max(area.y, area.y + area.height - r.height);\n const byX = [...px].sort((a, b) => Math.abs(a - inside.x) - Math.abs(b - inside.x) || a - b);\n let clear: { x: number; y: number; far: number } | null = null;\n let work = 0;\n let searchCapped = false;\n for (const x of byX) {\n const dx = Math.abs(x - inside.x);\n if (clear && dx >= clear.far) break;\n work += near.length + 1;\n if (work > WORK) {\n searchCapped = true;\n break;\n }\n const stretches: [number, number][] = [];\n for (const { at } of near) {\n if (Math.min(x + r.width, at.x + at.width) - Math.max(x, at.x) > EPS) stretches.push([at.y - r.height, at.y + at.height]);\n }\n stretches.sort((a, b) => a[0] - b[0]);\n // The clear y's are the closed gaps between the merged open stretches, within the stage.\n let cursor = ylo;\n let bestY: number | null = null;\n const gap = (from: number, to: number): void => {\n if (from > to) return;\n const y = Math.min(Math.max(inside.y, from), to);\n if (bestY === null || Math.abs(y - inside.y) < Math.abs(bestY - inside.y)) bestY = y;\n };\n for (const [a, b] of stretches) {\n gap(cursor, Math.min(a, yhi));\n cursor = Math.max(cursor, b);\n if (cursor > yhi) break;\n }\n if (cursor <= yhi) gap(cursor, yhi);\n if (bestY === null) continue;\n const far = Math.hypot(dx, bestY - inside.y);\n if (!clear || far < clear.far) clear = { x, y: bestY, far };\n }\n if (clear) return { rect: rect(clear.x, clear.y, r.width, r.height), clamped, snapped: clear.far > EPS, covers: [], searchCapped };\n // None is clear: the nearest places that cover the least.\n let best: { rect: Rect; left: number; far: number; hits: number[] } | null = null;\n let tried = 0;\n for (const p of byDistance(px, py, inside.x, inside.y)) {\n if (tried++ >= COVERED_PLACES) break;\n const cand = rect(p.x, p.y, r.width, r.height);\n const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);\n if (!best || left < best.left - EPS) best = { rect: cand, left, far: p.far, hits: under(cand) };\n }\n const out = best ?? { rect: inside, far: 0, hits: under(inside) };\n return { rect: out.rect, clamped, snapped: out.far > EPS, covers: out.hits, searchCapped };\n}\n\n// --- the drop target ---------------------------------------------------------------------------------------------\n\n/** What a float drop makes: the same answer for the preview and for the release. */\nexport interface FloatDrop {\n /** The float's rect in view space. */\n readonly rect: Rect;\n readonly fit: FloatFit;\n}\n\nexport interface StackFloatTargetInput {\n /** The item dragged. */\n readonly id: string;\n /** The stage, in view space. */\n readonly stage: Rect;\n /** The float's size: it is never resized. */\n readonly size: Size;\n /** The docked content to stay clear of: the docked items' rects (and the » entries'), in view space. */\n readonly avoid?: readonly Rect[];\n /** What the target is called (default \"Float here\"). */\n readonly label?: string;\n}\n\nexport interface FloatTarget extends Target {\n /** What kind of place it is, for a consumer that holds targets of several kinds. */\n readonly kind: \"float\";\n readonly priority: 3;\n readonly free: true;\n /** The item dragged. */\n readonly item: string;\n /**\n * The drop with the pointer at `point` holding the float at `grab` (its offset from the float's top-left corner,\n * default the middle): `rect` is the preview and the landing, clamped into the stage and clear of the docked content.\n */\n make(point: Point, grab?: Point): FloatDrop;\n}\n\n\nexport function stackFloatTarget(input: StackFloatTargetInput): FloatTarget {\n const { stage, size } = input;\n const avoid = input.avoid ?? [];\n const w = Math.max(0, finite(size.width, 0));\n const h = Math.max(0, finite(size.height, 0));\n return {\n // Not \"float\": `./desk` has a target of that id, and a consumer may hold both.\n id: `float:${input.id}`,\n kind: \"float\",\n priority: 3,\n free: true,\n hit: PLANE,\n label: input.label ?? \"Float here\",\n item: input.id,\n make(point, grab) {\n const g = grab ?? { x: w / 2, y: h / 2 };\n const fit = fitFloat(rect(point.x - g.x, point.y - g.y, w, h), stage, avoid);\n return { rect: fit.rect, fit };\n },\n };\n}\n\n// --- the stored form ---------------------------------------------------------------------------------------------\n\nexport interface StoredFloats {\n readonly v: 1;\n readonly floats: { id: string; x: number; y: number; width: number; height: number }[];\n}\n\nexport type FloatsRead = { readonly ok: true; readonly floats: StackFloat[]; readonly dropped: readonly string[] } | { readonly ok: false; readonly error: string };\n\nconst isSize = (n: unknown): n is number => typeof n === \"number\" && Number.isFinite(n) && n > 0;\nconst isAt = (n: unknown): n is number => typeof n === \"number\" && Number.isFinite(n);\n\n/**\n * The floats as plain JSON-safe data, in the order given (the stacking order, the last on top). Never a `pinned`.\n * What it can't read back is left out, silently: a float whose position isn't a finite number or whose size isn't over\n * 0 (a zero-size float), and an earlier entry of a repeated id (the last readable entry of an id is the one on top,\n * so it stays, at its own place in the order).\n */\nexport function storeFloats(floats: readonly StackFloat[]): StoredFloats {\n const last = new Map<string, number>();\n floats.forEach((f, i) => {\n const r = f.rect;\n if (isAt(r.x) && isAt(r.y) && isSize(r.width) && isSize(r.height)) last.set(f.id, i);\n });\n const out: StoredFloats[\"floats\"] = [];\n floats.forEach((f, i) => {\n if (last.get(f.id) === i) out.push({ id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height });\n });\n return { v: 1, floats: out };\n}\n\nconst isObject = (x: unknown): x is Record<string, unknown> => typeof x === \"object\" && x !== null && !Array.isArray(x);\nconst FIELDS = [\"id\", \"x\", \"y\", \"width\", \"height\"];\n\n/**\n * Reads parsed data back; never throws. Anything but an object of version 1 with a `floats` array is `{ ok: false,\n * error }`. Inside one it is lenient: a float that isn't an object, has no string id, isn't one the\n * consumer has (with `known`) or has a position or size that isn't a finite number (a size over 0) is dropped and\n * listed in `dropped` as `float:<id>` (or `a <type> where a float goes`); a top-level field this version doesn't\n * know is listed as `\"<field>\"`, and so is a float's own (`float:<id>:<field>`) while the float itself is kept.\n * A `pinned` key (an old store's flag, whatever its value) is ignored: the float loads as a plain float, in view\n * space as stored, and `pinned:<id>` is listed. A repeated id keeps its last readable entry (the list is in stacking\n * order, the last on top); the earlier ones are dropped and listed as `float:<id>`.\n */\nexport function readFloats(data: unknown, known?: readonly string[]): FloatsRead {\n try {\n return read(data, known);\n } catch (e) {\n // A getter that throws, a proxy: still no throw.\n return { ok: false, error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };\n }\n}\n\nfunction read(data: unknown, known?: readonly string[]): FloatsRead {\n if (!isObject(data)) return { ok: false, error: \"not an object\" };\n if (data.v !== 1) return { ok: false, error: `unknown version ${versionWords(data.v)} (this reads version 1)` };\n if (!Array.isArray(data.floats)) return { ok: false, error: \"floats is missing\" };\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 (k !== \"v\" && k !== \"floats\") drop(k);\n const floats: StackFloat[] = [];\n for (const x of data.floats as unknown[]) {\n if (!isObject(x)) {\n drop(`a ${x === null ? \"null\" : Array.isArray(x) ? \"list\" : typeof x} where a float goes`);\n continue;\n }\n const id = x.id;\n if (typeof id !== \"string\") {\n drop(\"a float with no id\");\n continue;\n }\n if ((known && !known.includes(id)) || !isAt(x.x) || !isAt(x.y) || !isSize(x.width) || !isSize(x.height)) {\n drop(`float:${id}`);\n continue;\n }\n for (const k of Object.keys(x)) {\n if (k === \"pinned\") drop(`pinned:${id}`);\n else if (!FIELDS.includes(k)) drop(`float:${id}:${k}`);\n }\n // A repeated id: the last readable entry is the one on top (the list is in stacking order), the earlier is dropped.\n const before = floats.findIndex((f) => f.id === id);\n if (before >=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