@n-uf/placement 26.11.24 → 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 +74 -0
  2. package/README.md +66 -28
  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-XUC5BU4N.js → chunk-SZKU7CRX.js} +575 -499
  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 +3 -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-DwwIWPpN.d.ts → targets-CDR5Towj.d.ts} +74 -60
  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-CJA6LRHN.js.map +0 -1
  43. package/dist/chunk-LPMZ2FFR.js.map +0 -1
  44. package/dist/chunk-QMTNB2C3.js +0 -17
  45. package/dist/chunk-QMTNB2C3.js.map +0 -1
  46. package/dist/chunk-RL3QB5SM.js.map +0 -1
  47. package/dist/chunk-XUC5BU4N.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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/dock/model.ts","../src/dock/arrange.ts","../src/dock/parts.ts"],"sourcesContent":["/**\n * The desk's model: panels and documents, the options, the state every construction keeps, and what a layout\n * returns (a placed rect per item). The panels themselves (their titles and natural heights) come from the\n * consumer as a catalog; see `createDesk`.\n */\nimport type { Rect, Size } from \"../geometry\";\n\nexport type Side = \"left\" | \"right\";\n\n/** Gaps and sizes, in stage px. */\nexport const G = 6;\n/** A toolbar bar's height (the pill is 4 px thinner). */\nexport const BAR = 34;\n/** A rail's width. */\nexport const RAIL = 34;\n/** A folded section's (or a shaded palette's) height: its title bar. */\nexport const TITLE = 22;\n/** A tab row's height (navigator sides and drawers). */\nexport const TABS = 28;\n/** The smallest a tiled document may be where a construction promises it (the tiling tree, the strip). */\nexport const DOC_MIN: Size = { width: 240, height: 160 };\n\n/** Items are keyed \"panel:<id>\" and \"doc:<id>\". */\nexport const panelKey = (id: number): string => `panel:${id}`;\nexport const docKey = (id: number): string => `doc:${id}`;\nexport const isPanelKey = (key: string): boolean => key.startsWith(\"panel:\");\nexport const isDocKey = (key: string): boolean => key.startsWith(\"doc:\");\nexport const idOf = (key: string): number => Number(key.slice(key.indexOf(\":\") + 1));\n\n/** A tool panel: its title and the height its content needs (its natural height, title bar included). */\nexport interface PanelSpec {\n readonly id: number;\n readonly title: string;\n readonly natural: number;\n}\n\n/** Where the panels start. Unset parts follow from the sides (see `createDesk`). */\nexport interface DeskStart {\n readonly left: readonly number[];\n readonly right: readonly number[];\n readonly bottom: readonly number[];\n readonly active?: { readonly left: number | null; readonly right: number | null };\n readonly tree?: DeskState[\"tree\"];\n readonly cols?: DeskState[\"cols\"];\n readonly stacks?: DeskState[\"stacks\"];\n}\n\n/** What a desk is made of: its panels, its documents' titles and where the panels start. */\nexport interface DeskSpec {\n readonly panels: readonly PanelSpec[];\n /** A document's title (default \"Document <id>\"). */\n readonly docTitle?: (id: number) => string;\n readonly start: DeskStart;\n /** The panels in the order they were opened (default: as listed); the tiling tree floats the newest first. */\n readonly opened?: readonly number[];\n}\n\n/** The catalog every part reads: a panel's natural height, an item's title and age. */\nexport interface Catalog {\n readonly panelIds: readonly number[];\n readonly natural: (id: number) => number;\n /** An item's title by key (\"panel:<id>\", \"doc:<id>\"); any other key is its own title. */\n readonly title: (key: string) => string;\n /** An item's age: higher is newer (panels in the order they were opened, then the documents). */\n readonly born: (key: string) => number;\n readonly start: Required<DeskStart>;\n}\n\n/** The catalog for a spec (unset start parts filled in). */\nexport function catalogOf(spec: DeskSpec): Catalog {\n const byId = new Map(spec.panels.map((p) => [p.id, p]));\n const opened = spec.opened ?? spec.panels.map((p) => p.id);\n const docTitle = spec.docTitle ?? ((id: number) => `Document ${id}`);\n const { left, right, bottom } = spec.start;\n const rest = [...right, ...bottom];\n const start: Required<DeskStart> = {\n left,\n right,\n bottom,\n active: spec.start.active ?? { left: left[0] ?? null, right: right.at(-1) ?? null },\n tree: spec.start.tree ?? { L: left.map(panelKey), R: rest.map(panelKey), C: [] },\n cols: spec.start.cols ?? [left.map(panelKey), rest.map(panelKey)].filter((c) => c.length > 0),\n stacks: spec.start.stacks ?? { left, right: rest },\n };\n return {\n panelIds: spec.panels.map((p) => p.id),\n natural: (id) => byId.get(id)?.natural ?? TITLE,\n title: (key) => (isPanelKey(key) ? (byId.get(idOf(key))?.title ?? key) : isDocKey(key) ? docTitle(idOf(key)) : key),\n born: (key) => (isDocKey(key) ? 1000 + idOf(key) : opened.indexOf(idOf(key)) + 1),\n start,\n };\n}\n\n/** Where the toolbar floats (top or bottom) and whether the documents keep a band clear for it; the bottom dock's mode. */\nexport interface Options {\n readonly toolbar: \"top\" | \"bottom\";\n readonly toolbarSpace: \"reserved\" | \"overlay\";\n readonly bottom: \"reserved\" | \"overlay\" | \"off\";\n /** The pill's width when its contents need more than the default; unset: the default. */\n readonly toolbarWidth?: number;\n /** The pill holds nothing: it takes no space and isn't shown. */\n readonly toolbarHidden?: boolean;\n}\nexport const DEFAULT_OPTIONS: Options = { toolbar: \"top\", toolbarSpace: \"reserved\", bottom: \"reserved\" };\n\n/** A panel placed freely (torn off, or a palette out of its stack): its top-left corner, null for the default spot. */\nexport interface Free {\n readonly id: number;\n readonly at: { readonly x: number; readonly y: number } | null;\n}\n\n/**\n * Everything any construction keeps. Each construction has its own copy (its own arrangement) and reads only what\n * it uses; the open documents are the same in all of them.\n */\nexport interface DeskState {\n /** Open document ids, in open order. */\n readonly docs: readonly number[];\n readonly focus: number | null;\n /** Panel ids, least recently used first: what folds or shades first when height runs out. */\n readonly recent: readonly number[];\n /** Sections folded (palettes shaded) by hand. */\n readonly folded: readonly number[];\n /** Docks, navigator sides and drawers: the panels on each side, top to bottom (tabs: left to right). */\n readonly left: readonly number[];\n readonly right: readonly number[];\n /** The bottom dock's panels (edge docks only). */\n readonly bottom: readonly number[];\n /** Docks or drawers folded to their rail by hand. */\n readonly closed: readonly Side[];\n /** The side opened last by hand: when width runs out it folds last. */\n readonly opened: Side | null;\n /** The panel showing on each side (navigator, drawers). */\n readonly active: { readonly left: number | null; readonly right: number | null };\n /** Panels torn off a dock, floating (edge docks + tear-off). */\n readonly torn: readonly Free[];\n /** The tiling tree: item keys in the left column, the right column and the centre (dwindle order). */\n readonly tree: { readonly L: readonly string[]; readonly R: readonly string[]; readonly C: readonly string[] };\n /** The scrolling strip: its columns, left to right, each a list of item keys top to bottom. */\n readonly cols: readonly (readonly string[])[];\n /** The strip scrolled by hand, or null: it scrolls to the focus. */\n readonly stripScroll: number | null;\n /** Palettes: the corner stacks, top to bottom, and the ones placed anywhere. */\n readonly stacks: { readonly left: readonly number[]; readonly right: readonly number[] };\n readonly free: readonly Free[];\n}\n\n/** How an item is drawn. */\nexport type Look =\n | \"pill\" // the toolbar floating as a rounded pill\n | \"bar\" // the toolbar as a bar across the top\n | \"section\" // a panel open in a dock\n | \"header\" // a section folded (or a palette shaded) to its title bar\n | \"float\" // a panel floating over the documents\n | \"palette\" // a floating panel that reserves its footprint\n | \"tile\" // a panel tiled like a document\n | \"bare\" // a panel under a tab row: no title bar of its own\n | \"doc\"\n | \"rail\"\n | \"tabs\"\n | \"track\"\n | \"thumb\";\n\n/** Stacking layers, bottom to top. */\nexport const LAYER = { doc: 1, dock: 2, palette: 3, overlay: 4, float: 5, toolbar: 6 } as const;\n\n/** One item as a layout places it. */\nexport interface Placed {\n readonly rect: Rect;\n readonly look: Look;\n readonly layer: number;\n /** Folded away (into a rail, behind a tab): it goes to `rect`, hidden. */\n readonly hidden?: boolean;\n /** Never laid out below this (where the construction promises it). */\n readonly min?: Partial<Size>;\n /** It may lie outside the stage (the strip scrolls). */\n readonly offStage?: boolean;\n /** A rail's icons or a tab row's tabs (panel ids), and the active tab. */\n readonly icons?: readonly number[];\n readonly tabs?: readonly number[];\n readonly active?: number | null;\n /** Drawn with an accent outline (the bottom dock). */\n readonly accent?: boolean;\n /** Drawn with a shadow (it floats over something). */\n readonly shadow?: boolean;\n}\n\n/**\n * How a layout gave way (or what it is worth knowing about it):\n *\n * - `bottom-folded`: the bottom dock folded to its header; `dock-folded`: a side dock folded to its rail (`side`);\n * - `sections-folded`: sections folded to their headers by themselves, least recently used first;\n * - `torn-floating`: panels torn off a dock float (`items`); `torn-shaded`: some shade because they don't fit;\n * - `columns-railed`: the tiling tree's side columns are folded to rails (`side` when only one);\n * - `tiles-float`: tiles that broke a minimum float, newest first (`items`);\n * - `tabs-folded`: a tabbed side folded to icon tabs (`side`); `drawer-over`: a drawer slides over the\n * documents (`side`);\n * - `column-split`: a strip column split in two (`items`); `strip-scrolls`: the strip is wider than the stage;\n * - `stacks-merged`: both palette stacks share one corner; `palettes-shaded`: palettes shaded to title bars;\n * - `palettes-cover`, `docs-room`: how much of the documents palettes cover, and how much room they leave.\n */\nexport type NoteCode =\n | \"bottom-folded\"\n | \"dock-folded\"\n | \"sections-folded\"\n | \"torn-floating\"\n | \"torn-shaded\"\n | \"columns-railed\"\n | \"tiles-float\"\n | \"tabs-folded\"\n | \"drawer-over\"\n | \"column-split\"\n | \"strip-scrolls\"\n | \"stacks-merged\"\n | \"palettes-shaded\"\n | \"palettes-cover\"\n | \"docs-room\";\n\n/**\n * One note on a layout. `code` (and `side`, `items` where they apply) is the contract; `text` says it in English for\n * people, and its wording may change in any release.\n */\nexport interface Note {\n readonly code: NoteCode;\n readonly text: string;\n readonly side?: Side;\n /** The item keys it is about. */\n readonly items?: readonly string[];\n}\n\n/** Where everything is (\"toolbar\", \"panel:<id>\", \"doc:<id>\", \"rail:<side>\", \"tabs:<side>\", \"track\", \"thumb\"), and how it gave way. */\nexport interface Layout {\n readonly items: ReadonlyMap<string, Placed>;\n readonly notes: readonly Note[];\n}\n\n// --- state changes -------------------------------------------------------------------------------------------------\n\n/** The arrangement a catalog starts from, with these documents open (none by default). */\nexport function startState(cat: Catalog, docs: readonly number[] = []): DeskState {\n const st = cat.start;\n const base: DeskState = {\n docs: [],\n focus: null,\n recent: [...cat.panelIds],\n folded: [],\n left: [...st.left],\n right: [...st.right],\n bottom: [...st.bottom],\n closed: [],\n opened: null,\n active: st.active,\n torn: [],\n tree: st.tree,\n cols: st.cols,\n stripScroll: null,\n stacks: st.stacks,\n free: [],\n };\n return withDocs(base, docs, docs.at(-1) ?? null);\n}\n\n/**\n * The same state with these documents open: new ones join the tiling tree's centre (the first one at its front)\n * and get a strip column of their own after the last document column; closed ones leave both.\n */\nexport function withDocs(s: DeskState, docs: readonly number[], focus: number | null): DeskState {\n const keys = docs.map(docKey);\n const gone = (k: string): boolean => isDocKey(k) && !keys.includes(k);\n let C = s.tree.C.filter((k) => !gone(k));\n let cols = s.cols.map((c) => c.filter((k) => !gone(k))).filter((c) => c.length > 0);\n const has = (k: string): boolean => [...s.tree.L, ...s.tree.R, ...C].includes(k);\n for (const k of keys) {\n if (!has(k)) C = C.some(isDocKey) || C.length === 0 ? [...C, k] : [k, ...C];\n if (!cols.some((c) => c.includes(k))) {\n const lastDoc = cols.map((c) => c.some(isDocKey)).lastIndexOf(true);\n const at = lastDoc >= 0 ? lastDoc + 1 : Math.min(1, cols.length);\n cols = [...cols.slice(0, at), [k], ...cols.slice(at)];\n }\n }\n const L = s.tree.L.filter((k) => !gone(k));\n const R = s.tree.R.filter((k) => !gone(k));\n const f = focus !== null && docs.includes(focus) ? focus : (docs.at(-1) ?? null);\n // A new focus: the strip scrolls to it again.\n return { ...s, docs: [...docs], focus: f, tree: { L, R, C }, cols, stripScroll: f === s.focus ? s.stripScroll : null };\n}\n\n/** Panel `id` was used: it is the last to fold when height runs out. */\nexport const touch = (s: DeskState, id: number): DeskState => ({ ...s, recent: [...s.recent.filter((x) => x !== id), id] });\n\n/** Fold or unfold a section (shade or unshade a palette) by hand; unfolding is a use. */\nexport function toggleFold(s: DeskState, id: number): DeskState {\n const folded = s.folded.includes(id);\n const next = { ...s, folded: folded ? s.folded.filter((x) => x !== id) : [...s.folded, id] };\n return folded ? touch(next, id) : next;\n}\n\n/** Fold a dock (or drawer) to its rail by hand, or open it again (then it folds last when width runs out). */\nexport function toggleClosed(s: DeskState, side: Side): DeskState {\n const closed = s.closed.includes(side);\n return closed ? { ...s, closed: s.closed.filter((x) => x !== side), opened: side } : { ...s, closed: [...s.closed, side] };\n}\n\n/** Show panel `id` on its side (navigator, drawers). */\nexport const withActive = (s: DeskState, side: Side, id: number): DeskState => touch({ ...s, active: { ...s.active, [side]: id } }, id);\n\n/** The state with `key` lifted out of wherever it is (before a drop puts it somewhere). */\nexport function liftOut(s: DeskState, key: string): DeskState {\n const dropK = (l: readonly string[]): string[] => l.filter((k) => k !== key);\n const base: DeskState = { ...s, tree: { L: dropK(s.tree.L), R: dropK(s.tree.R), C: dropK(s.tree.C) }, cols: s.cols.map(dropK).filter((c) => c.length > 0) };\n if (!isPanelKey(key)) return base;\n const id = idOf(key);\n const drop = (l: readonly number[]): number[] => l.filter((x) => x !== id);\n return {\n ...base,\n left: drop(s.left),\n right: drop(s.right),\n bottom: drop(s.bottom),\n torn: s.torn.filter((f) => f.id !== id),\n free: s.free.filter((f) => f.id !== id),\n stacks: { left: drop(s.stacks.left), right: drop(s.stacks.right) },\n active: { left: s.active.left === id ? null : s.active.left, right: s.active.right === id ? null : s.active.right },\n };\n}\n","/**\n * The arrangers the desk constructions build on, internal to `./dock`: master and stack for the documents, dwindle\n * for the tiling tree's centre, stacked columns at natural heights, and the minimum-size give-way (the newest tile\n * that breaks a minimum floats). A public `./tiling` will come from a merge with a full split-tree model; these stay\n * the dock's own until then.\n */\nimport type { Rect, Size } from \"../geometry\";\n\n/**\n * Master and stack: the first id takes the left part (`ratio` of the width less the gap), the rest stack on the\n * right in equal rows. One id takes the whole area.\n */\nexport function masterStack<K>(ids: readonly K[], area: Rect, gap: number, ratio = 0.5): Map<K, Rect> {\n const out = new Map<K, Rect>();\n if (ids.length === 0) return out;\n if (ids.length === 1) {\n out.set(ids[0]!, { ...area });\n return out;\n }\n const mw = (area.width - gap) * ratio;\n out.set(ids[0]!, { x: area.x, y: area.y, width: mw, height: area.height });\n const k = ids.length - 1;\n const sh = (area.height - gap * (k - 1)) / k;\n ids.slice(1).forEach((id, i) => out.set(id, { x: area.x + mw + gap, y: area.y + i * (sh + gap), width: area.width - mw - gap, height: sh }));\n return out;\n}\n\n/** Dwindle over an order: each tile but the last splits the space left in two along its longer side. */\nexport function dwindle(area: Rect, n: number, gap: number): Rect[] {\n const out: Rect[] = [];\n let cur = { ...area };\n for (let i = 0; i < n; i++) {\n if (i === n - 1) {\n out.push(cur);\n break;\n }\n if (cur.width >= cur.height) {\n const w = (cur.width - gap) / 2;\n out.push({ x: cur.x, y: cur.y, width: w, height: cur.height });\n cur = { x: cur.x + w + gap, y: cur.y, width: w, height: cur.height };\n } else {\n const h = (cur.height - gap) / 2;\n out.push({ x: cur.x, y: cur.y, width: cur.width, height: h });\n cur = { x: cur.x, y: cur.y + h + gap, width: cur.width, height: h };\n }\n }\n return out;\n}\n\n/**\n * Heights for a column of items stacked in `avail` with gaps: each at its minimum (its natural height), the last\n * taking the rest. When the minimums don't fit, an even share instead, so the ones that break their minimum show.\n */\nexport function columnHeights(avail: number, mins: readonly number[], gap: number): number[] {\n const room = avail - gap * (mins.length - 1);\n const need = mins.reduce((a, b) => a + b, 0);\n if (need > room) return mins.map(() => room / mins.length);\n return mins.map((m, i) => (i === mins.length - 1 ? room - need + m : m));\n}\n\n/**\n * Lengths for items sharing `avail`: each gets at least its minimum, the rest of the room is shared in proportion\n * to the minimums (when the minimums don't fit, each gets its minimum).\n */\nexport function share(avail: number, mins: readonly number[]): number[] {\n const need = mins.reduce((a, b) => a + b, 0);\n const spare = Math.max(0, avail - need);\n return mins.map((m) => m + (need > 0 ? (spare * m) / need : spare / mins.length));\n}\n\n/**\n * The minimum-size give-way: while a tile is laid out below its minimum, the newest tile (highest `age`) floats and\n * the rest are laid out again. Stops when every tile keeps its minimum or one tile is left. `layout` lays out the\n * kept keys; the result says which are kept (in their order) and which float (newest first).\n */\nexport function giveWay<K>(keys: readonly K[], layout: (kept: readonly K[]) => ReadonlyMap<K, Rect>, min: (key: K) => Size, age: (key: K) => number): { kept: K[]; floats: K[] } {\n let kept = [...keys];\n const floats: K[] = [];\n for (;;) {\n const res = layout(kept);\n const broken = [...res].some(([k, r]) => r.width < min(k).width - 0.5 || r.height < min(k).height - 0.5);\n if (!broken || kept.length <= 1) return { kept, floats };\n const newest = kept.reduce((a, b) => (age(b) > age(a) ? b : a));\n kept = kept.filter((k) => k !== newest);\n floats.push(newest);\n }\n}\n","/**\n * The parts the desk constructions are built from, each pure: the toolbar pill, the documents' tiles, natural-height\n * sections (the last open one takes the rest; the least recently used fold to headers), rails, the edge docks'\n * geometry, the tiling tree's columns, the scrolling strip, tabbed sides and floating palettes.\n */\nimport { clampInto, rect, type Rect, type Size } from \"../geometry\";\nimport { columnHeights, dwindle, giveWay, masterStack } from \"./arrange\";\nimport { BAR, DOC_MIN, G, LAYER, RAIL, TABS, TITLE, docKey, idOf, isDocKey, panelKey, type Catalog, type DeskState, type Note, type Options, type Placed, type Side } from \"./model\";\n\nexport type Out = Map<string, Placed>;\n\nexport const plural = (n: number, one: string, many: string): string => `${n} ${n > 1 ? many : one}`;\n\n// --- the toolbar pill and the documents ----------------------------------------------------------------------------\n\n/** The shortest a pill gets (unless there is less room than that). */\nexport const PILL_MIN = 60;\n\n/**\n * The toolbar pill, floating at the top or the bottom of the band [y0, y1] above a region `cx`..`cx + cw`; returns\n * the pill and the band left for the documents (reserved: they keep clear of it; overlay: it floats over them).\n */\nexport function pill(opt: Options, cx: number, cw: number, y0: number, y1: number): { placed: Placed; top: number; bottom: number } {\n const pw = Math.max(PILL_MIN, Math.min(opt.toolbarWidth ?? 320, cw - 24));\n const ph = BAR - 4;\n const atTop = opt.toolbar === \"top\";\n // A hidden pill keeps no band clear, as if it floated.\n const overlay = opt.toolbarSpace === \"overlay\" || !!opt.toolbarHidden;\n return {\n placed: { rect: rect(cx + cw / 2 - pw / 2, atTop ? y0 + G : y1 - G - ph, pw, ph), look: \"pill\", layer: LAYER.toolbar, shadow: overlay, ...(opt.toolbarHidden ? { hidden: true } : {}) },\n top: atTop && !overlay ? y0 + BAR + 2 * G : y0 + G,\n bottom: !atTop && !overlay ? y1 - BAR - 2 * G : y1 - G,\n };\n}\n\n/** The toolbar as a bar across the top of the stage. */\nexport const bar = (W: number): Placed => ({ rect: rect(0, 0, W, BAR), look: \"bar\", layer: LAYER.toolbar });\n\n/** The documents in `r`, master and stack: the first takes 56 % of the width, the rest stack on the right. */\nexport function tiles(out: Out, r: Rect, ids: readonly number[], min?: Size): void {\n for (const [id, rr] of masterStack(ids, r, G, 0.56)) out.set(docKey(id), { rect: rr, look: \"doc\", layer: LAYER.doc, ...(min ? { min } : {}) });\n}\n\n// --- sections and rails --------------------------------------------------------------------------------------------\n\n/**\n * The ones of `ids` to fold, least recently used first, until what stays open fits `avail`. An accordion keeps one\n * section open whatever (`keepOne`); a palette stack shades even its last palette rather than run off the stage.\n */\nexport function lruFold(s: DeskState, ids: readonly number[], avail: number, open: (id: number) => number, closed: number, keepOne = true): number[] {\n const byHand = ids.filter((id) => s.folded.includes(id));\n const auto: number[] = [];\n const isOpen = (id: number): boolean => !byHand.includes(id) && !auto.includes(id);\n const need = (): number => ids.reduce((sum, id) => sum + (isOpen(id) ? open(id) : closed), 0) + G * (ids.length - 1);\n const order = [...s.recent].filter((id) => ids.includes(id));\n for (const id of order) {\n if (need() <= avail || (keepOne && ids.filter(isOpen).length <= 1)) break;\n if (isOpen(id)) auto.push(id);\n }\n return [...byHand, ...auto];\n}\n\n/**\n * Natural-height sections in x, y, w, h: each open section takes its natural height and the last open one takes\n * the rest; the least recently used fold to headers until the open ones fit. Returns how many folded by themselves.\n */\nexport function accordion(cat: Catalog, out: Out, s: DeskState, x: number, y: number, w: number, h: number, ids: readonly number[]): number {\n const folded = lruFold(s, ids, h, cat.natural, TITLE);\n const open = ids.filter((id) => !folded.includes(id));\n const room = h - G * (ids.length - 1) - TITLE * (ids.length - open.length);\n const last = open.at(-1);\n const rest = room - open.reduce((sum, id) => sum + (id === last ? 0 : cat.natural(id)), 0);\n let cy = y;\n for (const id of ids) {\n const i = open.indexOf(id);\n const n = cat.natural(id);\n const hh = i < 0 ? TITLE : id === last ? Math.max(n, rest) : n;\n out.set(panelKey(id), { rect: rect(x, cy, w, hh), look: i >= 0 ? \"section\" : \"header\", layer: LAYER.dock, ...(i >= 0 ? { min: { height: n } } : {}) });\n cy += hh + G;\n }\n return folded.filter((id) => !s.folded.includes(id)).length;\n}\n\n/** A rail of icons at x, y; the rect of its icon `i`. */\nexport const railIcon = (x: number, y: number, i: number): Rect => rect(x + 6, y + 10 + i * 32, RAIL - 12, 24);\n\n/** A rail (a column whose panels are all folded) at x, y, h: one icon per panel. */\nexport function rail(out: Out, side: Side, x: number, y: number, h: number, ids: readonly number[], hidden = false): void {\n out.set(`rail:${side}`, { rect: rect(x, y, RAIL, h), look: \"rail\", layer: LAYER.dock, icons: ids, ...(hidden ? { hidden } : {}) });\n}\n\n/** Panels folded into a rail: hidden, each at its icon at `w` × its natural height. */\nexport function intoRail(cat: Catalog, out: Out, x: number, y: number, w: number, ids: readonly number[], side: Side): void {\n ids.forEach((id, i) => {\n const icon = railIcon(x, y, i);\n out.set(panelKey(id), { rect: rect(side === \"left\" ? icon.x : icon.x + icon.width - w, icon.y, w, cat.natural(id)), look: \"section\", layer: LAYER.dock, hidden: true });\n });\n}\n\n// --- edge docks ----------------------------------------------------------------------------------------------------\n\n/**\n * The dock width (rail excluded, its sections 240 px wide after the gap) and the narrowest the documents may get\n * before a dock folds.\n */\nexport const DOCK = 246;\nexport const WORK_MIN = 380;\n/** The bottom dock's height when open, and the most of the stage's height it takes. */\nexport const BOTTOM = 190;\nexport const BOTTOM_SHARE = 0.36;\n\n/** What the edge docks put where: shared by their layouts and their drop targets. */\nexport interface DockGeometry {\n /** The side docks' height (less the bottom dock's in full-width mode). */\n readonly h: number;\n /** The bottom dock's height (its header's when folded; 0 when off). */\n readonly bh: number;\n readonly lOpen: boolean;\n readonly rOpen: boolean;\n /** The right dock's panels (the bottom dock's join them when it is off). */\n readonly right: readonly number[];\n readonly bottomOn: boolean;\n readonly bottomRect: Rect | null;\n /** The documents' band, left to right. */\n readonly x0: number;\n readonly x1: number;\n}\n\n/**\n * The edge docks' give-way: the bottom dock folds to its header when the stage is short, and a whole side dock\n * folds to its rail when the documents would get narrower than WORK_MIN (the right one first, unless it was opened\n * last by hand). `mode`: the bottom dock between the side docks, or across the full width under them.\n */\nexport function dockGeometry(cat: Catalog, s: DeskState, size: Size, opt: Options, mode: \"between\" | \"full\", notes: Note[] = []): DockGeometry {\n const { width: W, height: H } = size;\n const bottomOn = opt.bottom !== \"off\" && s.bottom.length > 0;\n const right = bottomOn ? s.right : [...s.right, ...s.bottom];\n const bottomFolded = bottomOn && (H < 480 || s.bottom.every((id) => s.folded.includes(id)));\n // Open, it is BOTTOM tall, never more than BOTTOM_SHARE of the stage (but never below what its panels need).\n const bh = !bottomOn ? 0 : bottomFolded ? TITLE : Math.max(...s.bottom.map(cat.natural), Math.min(BOTTOM, BOTTOM_SHARE * H));\n if (bottomOn && H < 480) notes.push({ code: \"bottom-folded\", text: \"bottom dock folded to its header\" });\n const full = mode === \"full\";\n const h = full && bottomOn ? H - bh - G : H;\n let lOpen = s.left.length > 0 && !s.closed.includes(\"left\");\n let rOpen = right.length > 0 && !s.closed.includes(\"right\");\n const work = (): number => W - 2 * RAIL - (lOpen ? DOCK : 0) - (rOpen ? DOCK : 0) - 2 * G;\n for (const side of s.opened === \"right\" ? ([\"left\", \"right\"] as const) : ([\"right\", \"left\"] as const)) {\n if (work() >= WORK_MIN) break;\n if (side === \"right\" && rOpen) {\n rOpen = false;\n notes.push({ code: \"dock-folded\", side: \"right\", text: \"right dock folded to its rail\" });\n } else if (side === \"left\" && lOpen) {\n lOpen = false;\n notes.push({ code: \"dock-folded\", side: \"left\", text: \"left dock folded to its rail\" });\n }\n }\n const x0 = RAIL + (lOpen ? DOCK : 0) + G;\n const x1 = W - RAIL - (rOpen ? DOCK : 0) - G;\n const bottomRect = bottomOn ? (full ? rect(G, H - G - bh, W - 2 * G, bh) : rect(x0, H - G - bh, x1 - x0, bh)) : null;\n return { h, bh, lOpen, rOpen, right, bottomOn, bottomRect, x0, x1 };\n}\n\n/** The width of a torn-off panel (its height is its natural height). */\nexport const TORN_W = 200;\n\n// --- the tiling tree -----------------------------------------------------------------------------------------------\n\n/** The smallest a tile may be: a document's minimum, or a panel at its natural height. */\nexport const tileMin = (cat: Catalog, key: string): Size => (isDocKey(key) ? DOC_MIN : { width: 150, height: cat.natural(idOf(key)) });\n/** A side column's width. */\nexport const TREE_COLUMN = 180;\n\n/** The tree's tiles laid out (no floating): the left and right columns, the centre by dwindle. */\nexport function treeTiles(cat: Catalog, tree: DeskState[\"tree\"], area: Rect): Map<string, Rect> {\n const res = new Map<string, Rect>();\n let x0 = area.x;\n let x1 = area.x + area.width;\n // A side column's tiles take their natural height, the last one the rest.\n const column = (list: readonly string[], x: number): void => {\n const heights = columnHeights(area.height, list.map((k) => tileMin(cat, k).height), G);\n let y = area.y;\n list.forEach((k, i) => {\n res.set(k, rect(x, y, TREE_COLUMN, heights[i]!));\n y += heights[i]! + G;\n });\n };\n if (tree.L.length) {\n column(tree.L, x0);\n x0 += TREE_COLUMN + G;\n }\n if (tree.R.length) {\n column(tree.R, x1 - TREE_COLUMN);\n x1 -= TREE_COLUMN + G;\n }\n dwindle(rect(x0, area.y, x1 - x0, area.height), tree.C.length, G).forEach((r, i) => res.set(tree.C[i]!, r));\n return res;\n}\n\n/** The sides of the tree whose column is folded to a rail at the stage's edge (closed by hand, or at a narrow start). */\nexport const treeRails = (s: DeskState): { readonly left: boolean; readonly right: boolean } => ({\n left: s.closed.includes(\"left\") && s.tree.L.length > 0,\n right: s.closed.includes(\"right\") && s.tree.R.length > 0,\n});\n\n/** The area the tree tiles: the stage under the bar, less the rails of folded columns. */\nexport const treeArea = (size: Size, s?: DeskState): Rect => {\n const r = s ? treeRails(s) : { left: false, right: false };\n const x0 = r.left ? RAIL + G : G;\n const x1 = size.width - (r.right ? RAIL + G : G);\n return rect(x0, BAR + G, x1 - x0, size.height - BAR - 2 * G);\n};\n\n/** The tree as tiled: a column folded to its rail tiles nothing. */\nexport const treeShown = (s: DeskState): DeskState[\"tree\"] => {\n const r = treeRails(s);\n return { L: r.left ? [] : s.tree.L, R: r.right ? [] : s.tree.R, C: s.tree.C };\n};\n\n/** Which tiles float: the newest tile that breaks a minimum floats, then the tree is laid out again. */\nexport function treeFloats(cat: Catalog, tree: DeskState[\"tree\"], area: Rect): { tree: DeskState[\"tree\"]; floats: string[] } {\n const only = (kept: readonly string[]): DeskState[\"tree\"] => ({ L: tree.L.filter((k) => kept.includes(k)), R: tree.R.filter((k) => kept.includes(k)), C: tree.C.filter((k) => kept.includes(k)) });\n const { kept, floats } = giveWay(\n [...tree.L, ...tree.R, ...tree.C],\n (k) => treeTiles(cat, only(k), area),\n (k) => tileMin(cat, k),\n cat.born,\n );\n return { tree: only(kept), floats };\n}\n\n// --- tabbed sides --------------------------------------------------------------------------------------------------\n\n/**\n * One side with tabs: the tab row on top, the active panel under it, the others hidden behind it. `float` puts\n * them over the documents (a drawer that slides over).\n */\nexport function tabbed(out: Out, side: Side, ids: readonly number[], active: number | null, x: number, y: number, w: number, h: number, float: boolean): void {\n const shown = active !== null && ids.includes(active) ? active : (ids[0] ?? null);\n out.set(`tabs:${side}`, { rect: rect(x, y, w, TABS), look: \"tabs\", layer: float ? LAYER.float : LAYER.dock, tabs: ids, active: shown, ...(float ? { shadow: true } : {}) });\n for (const id of ids) {\n const r = rect(x, y + TABS, w, h - TABS);\n out.set(panelKey(id), { rect: r, look: \"bare\", layer: float ? LAYER.float : LAYER.dock, ...(id === shown ? {} : { hidden: true }), ...(float ? { shadow: true } : {}) });\n }\n}\n\n/** A side folded to its rail: the tab row and the panels hidden into it. */\nexport function tabbedIntoRail(cat: Catalog, out: Out, side: Side, ids: readonly number[], x: number, y: number, w: number): void {\n out.set(`tabs:${side}`, { rect: rect(side === \"left\" ? x : x + RAIL - w, y, w, TABS), look: \"tabs\", layer: LAYER.dock, tabs: ids, active: null, hidden: true });\n intoRail(cat, out, x, y, w, ids, side);\n}\n\n/** Below these widths a drawer slides over the documents instead of pushing them. */\nexport const DRAWER_DOCK = { left: 760, right: 1040 } as const;\n\n// --- the scrolling strip -------------------------------------------------------------------------------------------\n\nexport const STRIP_PANEL_W = 180;\nexport const stripDocW = (W: number): number => Math.max(360, Math.min(520, W * 0.5));\nexport const stripMin = (cat: Catalog, k: string): number => (isDocKey(k) ? DOC_MIN.height : cat.natural(idOf(k)));\n\n/** The strip's columns as laid out: a column whose minimums don't fit the height splits in two, recursively. */\nexport function stripColumns(cat: Catalog, cols: readonly (readonly string[])[], h: number, notes: Note[] = []): string[][] {\n const split = (keys: readonly string[]): string[][] => {\n const need = keys.reduce((sum, k) => sum + stripMin(cat, k), 0) + G * (keys.length - 1);\n if (need <= h || keys.length === 1) return [[...keys]];\n const half = Math.ceil(keys.length / 2);\n notes.push({ code: \"column-split\", items: [...keys], text: `${keys.map(cat.title).join(\" + \")} split into two columns` });\n return [...split(keys.slice(0, half)), ...split(keys.slice(half))];\n };\n return cols.flatMap(split);\n}\n\nexport interface StripGeometry {\n readonly cols: string[][];\n /** Each column's left edge on the stage (scroll applied) and width. */\n readonly xs: number[];\n readonly widths: number[];\n readonly y: number;\n readonly h: number;\n /** The whole strip's width, and how far it is scrolled. */\n readonly total: number;\n readonly scroll: number;\n}\n\n/** The strip's columns and scroll: scrolled by hand, else to centre the focused document's column. */\nexport function stripGeometry(cat: Catalog, s: DeskState, size: Size, notes: Note[] = []): StripGeometry {\n const { width: W, height: H } = size;\n const y = BAR + G;\n const h = H - BAR - 2 * G;\n const cols = stripColumns(cat, s.cols, h, notes);\n const widths = cols.map((c) => (c.some(isDocKey) ? stripDocW(W) : STRIP_PANEL_W));\n const total = widths.reduce((a, b) => a + b, 0) + G * (cols.length + 1);\n const want = s.focus !== null ? docKey(s.focus) : null;\n let fi = cols.findIndex((c) => want !== null && c.includes(want));\n if (fi < 0) fi = cols.findIndex((c) => c.some(isDocKey));\n const xsAbs: number[] = [];\n let x = G;\n for (const w of widths) {\n xsAbs.push(x);\n x += w + G;\n }\n const focusX = fi >= 0 ? xsAbs[fi]! + widths[fi]! / 2 : 0;\n const scroll = Math.max(0, Math.min(total - W, s.stripScroll ?? focusX - W / 2));\n return { cols, xs: xsAbs.map((v) => v - scroll), widths, y, h, total, scroll };\n}\n\n// --- floating palettes ---------------------------------------------------------------------------------------------\n\nexport const paletteWidth = (W: number): number => Math.min(200, Math.max(140, W * 0.22));\n/** Narrower than this, both stacks share the right corner. */\nexport const PALETTE_NARROW = 640;\n/** The margin palettes keep from the area's edges when they float over the documents. */\nexport const OVER_MARGIN = 14;\n\n/**\n * Palettes at their natural size, stacked in the top corners of `area` (`m` in from its edges), and the free ones\n * where they were put; a stack too tall for the area shades its least recently used palettes to their title bars.\n */\nexport function palettes(cat: Catalog, s: DeskState, area: Rect, W: number, m: number, notes: Note[] = []): Map<number, { rect: Rect; shaded: boolean }> {\n const pw = paletteWidth(W);\n const avail = area.height - 2 * m;\n const narrow = W < PALETTE_NARROW;\n const stacks = narrow ? [[...s.stacks.left, ...s.stacks.right]] : [s.stacks.left, s.stacks.right];\n if (narrow && s.stacks.left.length && s.stacks.right.length) notes.push({ code: \"stacks-merged\", text: \"both stacks share the right corner\" });\n const out = new Map<number, { rect: Rect; shaded: boolean }>();\n let shaded = 0;\n stacks.forEach((ids, si) => {\n const folded = lruFold(s, ids, avail, cat.natural, TITLE, false);\n shaded += folded.filter((id) => !s.folded.includes(id)).length;\n const x = narrow || si === 1 ? area.x + area.width - m - pw : area.x + m;\n let y = area.y + m;\n for (const id of ids) {\n const h = folded.includes(id) ? TITLE : cat.natural(id);\n out.set(id, { rect: rect(x, y, pw, h), shaded: folded.includes(id) });\n y += h + G;\n }\n });\n for (const f of s.free) {\n const shade = s.folded.includes(f.id);\n const at = f.at ?? { x: area.x + m, y: area.y + m };\n out.set(f.id, { rect: clampInto(rect(at.x, at.y, pw, shade ? TITLE : cat.natural(f.id)), area), shaded: shade });\n }\n if (shaded) notes.push({ code: \"palettes-shaded\", text: `${plural(shaded, \"palette\", \"palettes\")} shaded to ${shaded > 1 ? \"title bars\" : \"a title bar\"}` });\n return out;\n}\n\n/** The stage area palettes and documents share (below or above the pill when it keeps its band). */\nexport function paletteArea(size: Size, opt: Options): { area: Rect } {\n const p = pill(opt, G, size.width - 2 * G, 0, size.height);\n return { area: rect(G, p.top, size.width - 2 * G, p.bottom - p.top) };\n}\n\n/**\n * A floating pill among palettes: in a stretch of its band that no palette crosses, so it never covers one. Of the\n * stretches wide enough for a full-width pill (its minimum plus margins), the one nearest the centre; with none, the\n * widest, the pill shrunk to fit it.\n */\nexport function pillBetween(opt: Options, size: Size, blocks: readonly Rect[]): Placed {\n const band = pill(opt, G, size.width - 2 * G, 0, size.height).placed.rect;\n const spans = blocks\n .filter((r) => r.y < band.y + band.height && r.y + r.height > band.y)\n .map((r) => [r.x - G, r.x + r.width + G] as const)\n .sort((a, b) => a[0] - b[0]);\n const stretches: [number, number][] = [];\n let x = G;\n for (const [b0, b1] of spans) {\n if (b0 > x) stretches.push([x, b0]);\n x = Math.max(x, b1);\n }\n if (size.width - G > x) stretches.push([x, size.width - G]);\n const roomy = stretches.filter(([a, b]) => b - a >= PILL_MIN + 24);\n const mid = size.width / 2;\n const pick =\n roomy.sort((p, q) => Math.abs((p[0] + p[1]) / 2 - mid) - Math.abs((q[0] + q[1]) / 2 - mid))[0] ??\n stretches.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))[0] ??\n ([G, G] as [number, number]);\n const placed = pill(opt, pick[0], pick[1] - pick[0], 0, size.height).placed;\n const room = pick[1] - pick[0];\n // Too little room for even the shortest pill: it shrinks to the room rather than cover a palette.\n return placed.rect.width <= room ? placed : { ...placed, rect: { ...placed.rect, x: pick[0], width: Math.max(0, room) } };\n}\n\n/** The documents' band between the palettes on the left half and those on the right half. */\nexport function aroundDocs(pals: ReadonlyMap<number, { rect: Rect }>, area: Rect): Rect {\n const mid = area.x + area.width / 2;\n const rects = [...pals.values()].map((p) => p.rect);\n const left = rects.filter((r) => r.x + r.width / 2 < mid);\n const right = rects.filter((r) => r.x + r.width / 2 >= mid);\n const x0 = left.length ? Math.max(...left.map((r) => r.x + r.width)) + G : area.x;\n const x1 = right.length ? Math.min(...right.map((r) => r.x)) - G : area.x + area.width;\n return rect(x0, area.y, Math.max(0, x1 - x0), area.height);\n}\n"],"mappings":";;;;;;AAUO,IAAM,IAAI;AAEV,IAAM,MAAM;AAEZ,IAAM,OAAO;AAEb,IAAM,QAAQ;AAEd,IAAM,OAAO;AAEb,IAAM,UAAgB,EAAE,OAAO,KAAK,QAAQ,IAAI;AAGhD,IAAM,WAAW,CAAC,OAAuB,SAAS,EAAE;AACpD,IAAM,SAAS,CAAC,OAAuB,OAAO,EAAE;AAChD,IAAM,aAAa,CAAC,QAAyB,IAAI,WAAW,QAAQ;AACpE,IAAM,WAAW,CAAC,QAAyB,IAAI,WAAW,MAAM;AAChE,IAAM,OAAO,CAAC,QAAwB,OAAO,IAAI,MAAM,IAAI,QAAQ,GAAG,IAAI,CAAC,CAAC;AA0C5E,SAAS,UAAU,MAAyB;AACjD,QAAM,OAAO,IAAI,IAAI,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACtD,QAAM,SAAS,KAAK,UAAU,KAAK,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE;AACzD,QAAM,WAAW,KAAK,aAAa,CAAC,OAAe,YAAY,EAAE;AACjE,QAAM,EAAE,MAAM,OAAO,OAAO,IAAI,KAAK;AACrC,QAAM,OAAO,CAAC,GAAG,OAAO,GAAG,MAAM;AACjC,QAAM,QAA6B;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,KAAK,MAAM,UAAU,EAAE,MAAM,KAAK,CAAC,KAAK,MAAM,OAAO,MAAM,GAAG,EAAE,KAAK,KAAK;AAAA,IAClF,MAAM,KAAK,MAAM,QAAQ,EA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M,MAAM,KAAK,IAAI,KAAK,QAAQ;AAClC,QAAM,QAAQ,CAAC,GAAG,KAAK,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI;AAClD,QAAM,OAAO,MAAM,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,IAAI,GAAG;AACxD,QAAM,QAAQ,MAAM,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,GAAG;AAC1D,QAAM,KAAK,KAAK,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK;AAChF,QAAM,KAAK,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,IAAI,KAAK,IAAI,KAAK;AACjF,SAAO,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,EAAE,GAAG,KAAK,MAAM;AAC3D;","names":["kept"]}
@@ -1,17 +0,0 @@
1
- // src/geometry.ts
2
- var rect = (x, y, width, height) => ({ x, y, width, height });
3
- var overlap = (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));
4
- var clampInto = (r, area) => ({
5
- ...r,
6
- x: Math.min(Math.max(r.x, area.x), Math.max(area.x, area.x + area.width - r.width)),
7
- y: Math.min(Math.max(r.y, area.y), Math.max(area.y, area.y + area.height - r.height))
8
- });
9
- var centre = (r) => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });
10
-
11
- export {
12
- rect,
13
- overlap,
14
- clampInto,
15
- centre
16
- };
17
- //# sourceMappingURL=chunk-QMTNB2C3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/geometry.ts"],"sourcesContent":["/**\n * The shapes every entry shares. Plain data: a rect is a top-left corner and a size, in whatever px the consumer\n * lays out in (stage, window or host coordinates). The same shape as @n-uf/motion's, so the two compose without\n * either importing the other.\n */\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport interface Size {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Point {\n readonly x: number;\n readonly y: number;\n}\n\nexport const rect = (x: number, y: number, width: number, height: number): Rect => ({ x, y, width, height });\n\n/** The area two rects share (0 when apart). */\nexport const overlap = (a: Rect, b: Rect): number =>\n 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));\n\n/** `r` moved (not resized) to lie inside `area`; one larger than the area keeps its top-left corner on the area's. */\nexport const clampInto = (r: Rect, area: Rect): Rect => ({\n ...r,\n x: Math.min(Math.max(r.x, area.x), Math.max(area.x, area.x + area.width - r.width)),\n y: Math.min(Math.max(r.y, area.y), Math.max(area.y, area.y + area.height - r.height)),\n});\n\n/** The centre of a rect. */\nexport const centre = (r: Rect): Point => ({ x: r.x + r.width / 2, y: r.y + r.height / 2 });\n"],"mappings":";AAuBO,IAAM,OAAO,CAAC,GAAW,GAAW,OAAe,YAA0B,EAAE,GAAG,GAAG,OAAO,OAAO;AAGnG,IAAM,UAAU,CAAC,GAAS,MAC/B,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;AAG/I,IAAM,YAAY,CAAC,GAAS,UAAsB;AAAA,EACvD,GAAG;AAAA,EACH,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,KAAK,QAAQ,EAAE,KAAK,CAAC;AAAA,EAClF,GAAG,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,KAAK,SAAS,EAAE,MAAM,CAAC;AACtF;AAGO,IAAM,SAAS,CAAC,OAAoB,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,GAAG,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE;","names":[]}
@@ -1 +0,0 @@
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 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\";\n\nconst EPS = 1e-6;\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 { clampInto, rect, type Point, type Rect, type Size } from \"../geometry\";\nimport type { Target } from \"../targets/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\nconst EPS = 1e-3;\nconst finite = (x: number, fallback: number): number => (Number.isFinite(x) ? x : fallback);\n\n/** Whether two rects share an area (touching edges don't). */\nconst overlaps = (a: Rect, b: Rect): boolean => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS;\nconst shared = (a: Rect, b: Rect): number =>\n 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));\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)) near.push({ at, index });\n });\n const under = (cand: Rect): number[] => near.filter((n) => overlaps(cand, n.at)).map((n) => n.index);\n const blocked = (cand: Rect): boolean => near.some((n) => overlaps(cand, n.at));\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 + shared(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/** A zone that covers any pointer the page can see: large and finite (an infinite rect has no far edge to compare). */\nconst PLANE = rect(-1e9, -1e9, 2e9, 2e9);\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 >= 0) {\n floats.splice(before, 1);\n drop(`float:${id}`);\n }\n floats.push({ id, rect: rect(x.x, x.y, x.width, x.height) });\n }\n return { ok: true, floats, dropped };\n}\n"],"mappings":";;;;;;AAoFA,IAAM,SAAS,CAAC,MAAmC,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC,IAAI;AAO3G,SAAS,aAAa,GAAsB;AACjD,MAAI,EAAE,KAAM,QAAO,UAAU,EAAE,IAAI,EAAE;AACrC,QAAM,IAAI,EAAE,MAAM,OAAO,EAAE,MAAM;AACjC,SAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AAGO,SAAS,SAAS,GAAc,OAA0B,OAAuB;AACtF,MAAI,EAAE,SAAS,OAAQ,QAAO;AAC9B,MAAI,EAAE,KAAM,QAAO,SAAS,EAAE,MAAM,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AACnE,SAAO,OAAO,EAAE,KAAK,KAAK,CAAC;AAC7B;AAMO,SAAS,cAAc,GAAc,OAAwB;AAClE,MAAI,CAAC,EAAE,KAAM,QAAO;AACpB,QAAM,SAAS,KAAK,IAAI,GAAG,GAAG,EAAE,KAAK,OAAO,IAAI,MAAM,CAAC;AACvD,SAAO,QAAQ,QAAQ,OAAO,EAAE,KAAK,IAAI,IAAI,UAAU,UAAU,EAAE,MAAM,KAAK,EAAE;AAClF;AAGA,SAAS,UAAU,MAA0B;AAC3C,QAAM,MAAM,OAAO,KAAK,GAAG;AAC3B,QAAM,OAAO,OAAO,KAAK,IAAI;AAC7B,QAAM,SAAS,KAAK,OAAO,IAAI,MAAM;AACrC,QAAM,MAAgB,CAAC;AACvB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK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