@n-uf/placement 26.12.3 → 26.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/stack.d.ts +34 -15
- package/dist/stack.js +40 -22
- package/dist/stack.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ Versions are calendar versions, `YY.M.R` (year, month of the release, counter wi
|
|
|
5
5
|
|
|
6
6
|
Unreleased entries live in `changes/` until a release joins them.
|
|
7
7
|
|
|
8
|
+
## 26.12.4
|
|
9
|
+
|
|
10
|
+
- **Changed (breaking):** a form pinned by adding 1000 to its rank moves that pin to `level` (`StackForm.level`, a
|
|
11
|
+
whole number 0 or more). Such a form still orders the same on a bar, but in a column drawn as a rail it now counts as
|
|
12
|
+
a rank of 1000 or more, so panel tiles go into the » after it steps, not before. The give-way order reads the level
|
|
13
|
+
first, then the rank, everywhere: giving way, a batch into the » (which never takes a step into a higher level while
|
|
14
|
+
a lower one is open), growing back and the squeeze, so a priority can no longer carry a step past a pin.
|
|
15
|
+
`controlLadder`'s `keep` now sets `level` on the partial folds, `fold`, `menu` and the column's menu, and its ranks
|
|
16
|
+
are the same at every `keep`. `RANK_LEVEL` is removed. A rank may be any finite number, negative included, and ranks
|
|
17
|
+
are relative. See docs/decisions/0021-a-pin-is-a-forms-level.md.
|
|
18
|
+
- **Changed (breaking, behavior):** a bar with a growing title and a pinned group now shrinks the title before the
|
|
19
|
+
pinned group hides a control. While a title holds its natural length, steps are taken only at the lowest open level,
|
|
20
|
+
the title's shrink counted at its own level, so a title given a level shrinks after every step of a lower level,
|
|
21
|
+
whatever its kind; the pinned group's tier steps (level 0) still shorten its controls before the title shrinks.
|
|
22
|
+
Before, the pinned group's partial folds, being `row` steps, were taken while the title kept its natural length.
|
|
23
|
+
- **Added:** `formLevel` and `formRank`, the one reading of a form's level (a whole number, 0 or more; anything else
|
|
24
|
+
0) and rank (any finite number; anything else 0).
|
|
25
|
+
- **Added:** `StackStep.held`, set on a stack with a growing fixed item (a title): whether it still held its natural
|
|
26
|
+
length when the step was taken. A history without it (from an older version) is read by each step's kind: a step to
|
|
27
|
+
a form of the same kind was taken while the title held.
|
|
28
|
+
- **Fixed:** growing back beside a title is the exact reverse of giving way. A step taken after the title shrank came
|
|
29
|
+
back only with the title at its natural length, so growth could stall, and a step into the » that opened only after
|
|
30
|
+
the title shrank could leave items in the » with room to spare. Each step now comes back under the hold it was taken
|
|
31
|
+
with, and a fit whose history has a step taken after the title's shrink starts with the title shrunk, as a fresh fit
|
|
32
|
+
has it.
|
|
33
|
+
- **Fixed:** a batch into the » of a lower level than a title's now comes before the title shrinks, like every other
|
|
34
|
+
step of a lower level.
|
|
35
|
+
|
|
8
36
|
## 26.12.3
|
|
9
37
|
|
|
10
38
|
- **Changed (breaking, behavior):** `decideSplit` and `layoutSplit`: a fixed length that is not kept is now held
|
package/dist/stack.d.ts
CHANGED
|
@@ -118,12 +118,21 @@ interface StackForm {
|
|
|
118
118
|
/** Icons only. Default: true for the kind `icons`. A window model's compact (icons-only) edge takes it. */
|
|
119
119
|
readonly compact?: boolean;
|
|
120
120
|
/**
|
|
121
|
-
* Give-way order (default 0)
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
121
|
+
* Give-way order within the form's `level` (default 0): any finite number, negative included; anything else reads 0
|
|
122
|
+
* (`formRank`). When the stack is too long, the step taken is the one into the next form of the lowest level, then of
|
|
123
|
+
* the lowest rank, across all items (the form the item would take, not the one it leaves); ties go unkept before kept,
|
|
124
|
+
* then the item used longest ago, then the later in the stack. Adding one number to every rank of a stack changes
|
|
125
|
+
* nothing.
|
|
125
126
|
*/
|
|
126
127
|
readonly rank?: number;
|
|
128
|
+
/**
|
|
129
|
+
* The form's level (default 0): a whole number, 0 or more; anything else reads 0 (`formLevel`). A level comes before
|
|
130
|
+
* the rank in the order: every step into a form of a lower level is taken before any step into a form of a higher
|
|
131
|
+
* level, whatever their ranks. It is a pin: `controlLadder` sets it from `keep` on a pinned group's partial folds, fold
|
|
132
|
+
* and menu, so every group of a lower level gives way entirely before the pinned one folds a control. Room coming back
|
|
133
|
+
* reads the same order backwards.
|
|
134
|
+
*/
|
|
135
|
+
readonly level?: number;
|
|
127
136
|
/**
|
|
128
137
|
* A form whose length depends on the cross size it gets (meant for a column of words). With it, `main` and `cross` are
|
|
129
138
|
* computed and the given ones ignored: the rows are laid once the stack's cross size is known (beside the lead, a
|
|
@@ -189,6 +198,10 @@ declare const itemSteps: (item: {
|
|
|
189
198
|
readonly fixed?: boolean;
|
|
190
199
|
readonly stepping?: boolean;
|
|
191
200
|
}) => boolean;
|
|
201
|
+
/** A form's rank as the solver reads it: `rank` when it is a finite number, else 0. */
|
|
202
|
+
declare const formRank: (f: StackForm) => number;
|
|
203
|
+
/** A form's level as the solver reads it: `level` when it is a whole number, 0 or more, else 0. */
|
|
204
|
+
declare const formLevel: (f: StackForm) => number;
|
|
192
205
|
/** Whether a form has no room of its own, the » entry standing for it (`menu`, default: the kind `menu`). */
|
|
193
206
|
declare const formMenu: (f: StackForm) => boolean;
|
|
194
207
|
/** Whether a form is drawn at its own size across under `ownCross` (`ownCross`, default: the group kinds). */
|
|
@@ -446,6 +459,13 @@ interface StackStep {
|
|
|
446
459
|
readonly from: number;
|
|
447
460
|
readonly to: number;
|
|
448
461
|
readonly batch?: number;
|
|
462
|
+
/**
|
|
463
|
+
* Set on a stack with a growing fixed item (a title): `true` when the step was taken while it held its natural length,
|
|
464
|
+
* `false` when it came after its shrink. Growing back undoes a step under the same hold, and a fit whose history still
|
|
465
|
+
* holds a step taken after the shrink starts with the title shrunk. Without it (a history from an older version) the
|
|
466
|
+
* step's level and kind stand in.
|
|
467
|
+
*/
|
|
468
|
+
readonly held?: boolean;
|
|
449
469
|
}
|
|
450
470
|
/** What `fitStack` takes besides the input. */
|
|
451
471
|
interface FitOptions {
|
|
@@ -488,7 +508,7 @@ interface FitOptions {
|
|
|
488
508
|
* step that can't be undone stops all growth. So growing back is exactly the reverse of giving way: at every length the
|
|
489
509
|
* way back holds what the way down held. A `previous` without a history (built by hand, or by an older version) grows
|
|
490
510
|
* 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
|
|
491
|
-
* rank, `kept` and age first, one at a time, menu items out only when that keeps the order. A `previous` with no `need`
|
|
511
|
+
* level, rank, `kept` and age first, one at a time, menu items out only when that keeps the order. A `previous` with no `need`
|
|
492
512
|
* (one an app built by hand) is no help and the fresh fit is returned.
|
|
493
513
|
*/
|
|
494
514
|
declare function fitStack(input: StackInput, options?: FitOptions): StackFit;
|
|
@@ -525,6 +545,9 @@ declare function fitStack(input: StackInput, options?: FitOptions): StackFit;
|
|
|
525
545
|
* Ranks are spaced by step type in fixed bands whatever a group's tier count: tier steps in [100, 400), partial folds
|
|
526
546
|
* 400 + k / n, fold 500, menu 600. So the same-tier steps of several groups interleave, and a partial fold never comes
|
|
527
547
|
* before another group's tier step, even when the groups have different tier counts.
|
|
548
|
+
*
|
|
549
|
+
* A pin (`keep`) is a level, not a rank: the pinned group's partial folds, fold and menu carry `level: keep`, so they come
|
|
550
|
+
* after every step of a lower level, and their ranks stay the same.
|
|
528
551
|
*/
|
|
529
552
|
|
|
530
553
|
/** One control of a group: an id and its length along the stack per tier. */
|
|
@@ -562,8 +585,11 @@ interface ControlLadderSpec {
|
|
|
562
585
|
readonly cross?: number;
|
|
563
586
|
};
|
|
564
587
|
/**
|
|
565
|
-
* A pinned primary's level (default 0
|
|
566
|
-
*
|
|
588
|
+
* A pinned primary's level (default 0; a whole number, 0 or more, anything else reads 0, as `StackForm.level`): its
|
|
589
|
+
* partial folds, fold and menu (and the column's menu) carry it as their `level`, so every group of a lower level gives
|
|
590
|
+
* way entirely before it folds a control, and a growing title of a lower level shrinks first, whatever the ranks and
|
|
591
|
+
* priorities. Tier steps and the first row stay at level 0 (they shorten its controls before a title shrinks), and the
|
|
592
|
+
* ranks are the same at every level.
|
|
567
593
|
*/
|
|
568
594
|
readonly keep?: number;
|
|
569
595
|
}
|
|
@@ -572,13 +598,6 @@ interface ControlLadder {
|
|
|
572
598
|
readonly row: readonly StackForm[];
|
|
573
599
|
readonly column?: readonly StackForm[];
|
|
574
600
|
}
|
|
575
|
-
/**
|
|
576
|
-
* One level of give-way ranks: a pin (`ControlLadderSpec.keep`) raises a group's later forms by this much per level, so a
|
|
577
|
-
* form's rank is its level times `RANK_LEVEL` plus its rank within the level (`rank % RANK_LEVEL`, under `RANK_LEVEL`).
|
|
578
|
-
* A consumer that ranks a step of its own after "every shorter drawn form" of a stack reads the forms' ranks within their
|
|
579
|
-
* level, so a pin moves its own item and nothing else.
|
|
580
|
-
*/
|
|
581
|
-
declare const RANK_LEVEL = 1000;
|
|
582
601
|
/** `spec`'s forms: the row ladder, and the column ladder when `spec.column` is given. Pure. */
|
|
583
602
|
declare function controlLadder(spec: ControlLadderSpec): ControlLadder;
|
|
584
603
|
|
|
@@ -733,4 +752,4 @@ interface FloatFitOptions {
|
|
|
733
752
|
}
|
|
734
753
|
declare function fitFloat(want: Rect, stage: Rect, avoid?: readonly Rect[], options?: FloatFitOptions): FloatFit;
|
|
735
754
|
|
|
736
|
-
export { type ControlLadder, type ControlLadderSpec, type CrossLimits, DEFAULT_MENU, DEFAULT_RAIL, type EdgeBand, type EdgeCut, type FitOptions, type FloatFit, type FloatFitOptions, type GroupFormKind, type LadderControl, type MainSize, type PanelFormKind, type PlacedStackItem,
|
|
755
|
+
export { type ControlLadder, type ControlLadderSpec, type CrossLimits, DEFAULT_MENU, DEFAULT_RAIL, type EdgeBand, type EdgeCut, type FitOptions, type FloatFit, type FloatFitOptions, type GroupFormKind, type LadderControl, type MainSize, type PanelFormKind, type PlacedStackItem, type StackAxis, type StackDivider, type StackFit, type StackForm, type StackFormKind, type StackGap, type StackGapOptions, type StackGapRefusal, type StackInput, type StackItem, type StackLengths, type StackMenu, type StackNote, type StackNoteCode, type StackStep, type WrapSpec, controlLadder, cutEdges, dividers, fitFloat, fitStack, formBody, formCompact, formCrossMin, formFitsCross, formFolded, formLevel, formMain, formMenu, formOwnCross, formRank, formSetsCross, formStepGroup, itemSteps, resetBetween, resetLengths, resizeBetween, stackGaps, withItem, wrapCross, wrapLines, wrapRows };
|
package/dist/stack.js
CHANGED
|
@@ -51,6 +51,8 @@ function cutEdges(stage, bands) {
|
|
|
51
51
|
|
|
52
52
|
// src/stack/model.ts
|
|
53
53
|
var itemSteps = (item) => item.fixed !== true || item.stepping === true;
|
|
54
|
+
var formRank = (f) => typeof f.rank === "number" && Number.isFinite(f.rank) ? f.rank : 0;
|
|
55
|
+
var formLevel = (f) => typeof f.level === "number" && Number.isInteger(f.level) && f.level > 0 ? f.level : 0;
|
|
54
56
|
var formMenu = (f) => f.menu ?? f.kind === "menu";
|
|
55
57
|
var formOwnCross = (f) => f.ownCross ?? GROUP_KINDS.has(f.kind);
|
|
56
58
|
var formStepGroup = (f) => f.stepGroup ?? f.kind;
|
|
@@ -166,9 +168,10 @@ var finite2 = (x, fallback = 0) => Number.isFinite(x) ? x : fallback;
|
|
|
166
168
|
var mainOf = formMain;
|
|
167
169
|
var crossMin = formCrossMin;
|
|
168
170
|
var crossNatural = (f) => f.wrap ? wrapCross(f.wrap).natural : finite2(f.cross.natural);
|
|
169
|
-
var
|
|
170
|
-
function givesWayBefore(items, a,
|
|
171
|
-
|
|
171
|
+
var formOrder = (fa, fb) => formLevel(fa) - formLevel(fb) || formRank(fa) - formRank(fb);
|
|
172
|
+
function givesWayBefore(items, a, fa, b, fb) {
|
|
173
|
+
const order = formOrder(fa, fb);
|
|
174
|
+
if (order !== 0) return order;
|
|
172
175
|
const ka = items[a].kept ? 1 : 0;
|
|
173
176
|
const kb = items[b].kept ? 1 : 0;
|
|
174
177
|
if (ka !== kb) return ka - kb;
|
|
@@ -181,7 +184,7 @@ function victim(items, to) {
|
|
|
181
184
|
let best = -1;
|
|
182
185
|
for (let i = 0; i < items.length; i++) {
|
|
183
186
|
if (to[i] < 0 || !itemSteps(items[i])) continue;
|
|
184
|
-
if (best < 0 || givesWayBefore(items, i,
|
|
187
|
+
if (best < 0 || givesWayBefore(items, i, items[i].forms[to[i]], best, items[best].forms[to[best]]) < 0) best = i;
|
|
185
188
|
}
|
|
186
189
|
return best;
|
|
187
190
|
}
|
|
@@ -247,7 +250,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
247
250
|
const menuOrder = [];
|
|
248
251
|
const step = (i, j, batch) => {
|
|
249
252
|
if (!firstStep.includes(i)) firstStep.push(i);
|
|
250
|
-
hist.push({ id: items[i].id, from: at[i], to: j, ...batch !== void 0 ? { batch } : {} });
|
|
253
|
+
hist.push({ id: items[i].id, from: at[i], to: j, ...batch !== void 0 ? { batch } : {}, ...idx.some(holds) ? { held: hold } : {} });
|
|
251
254
|
withHistory.add(items[i].id);
|
|
252
255
|
at[i] = j;
|
|
253
256
|
if (isMenu(form(i)) && !menuOrder.includes(i)) menuOrder.push(i);
|
|
@@ -269,6 +272,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
269
272
|
};
|
|
270
273
|
const holds = (i) => !itemSteps(items[i]) && form(i).main.grows === true;
|
|
271
274
|
let hold = idx.some(holds);
|
|
275
|
+
const holdLevel = () => idx.reduce((m, i) => holds(i) ? Math.min(m, formLevel(form(i))) : m, Infinity);
|
|
272
276
|
const minSumWith = (held) => {
|
|
273
277
|
const c = items.some((it) => it.forms.some((f) => f.wrap)) ? crossOf() : 0;
|
|
274
278
|
return idx.reduce((s, i) => s + mainOf(form(i), held && holds(i) ? "natural" : "min", c), 0) + (inMenu() ? menuMain(input) : 0) + gapsOf() + sp.start + sp.end;
|
|
@@ -320,7 +324,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
320
324
|
};
|
|
321
325
|
if (seed) seed.need = minSumWith(false);
|
|
322
326
|
if (grow) {
|
|
323
|
-
const comesBefore = (a, b) => givesWayBefore(items, b,
|
|
327
|
+
const comesBefore = (a, b) => givesWayBefore(items, b, items[b].forms[at[b]], a, items[a].forms[at[a]]) < 0;
|
|
324
328
|
const index = new Map(items.map((it, i) => [it.id, i]));
|
|
325
329
|
let stuck = false;
|
|
326
330
|
const undoes = (n, c0) => {
|
|
@@ -328,7 +332,8 @@ function solve(input, previous, seed, grow = false) {
|
|
|
328
332
|
const changed = [...new Set(group.map((s) => index.get(s.id)))];
|
|
329
333
|
const was = changed.map((i) => at[i]);
|
|
330
334
|
const forms = (s) => items[index.get(s.id)].forms;
|
|
331
|
-
|
|
335
|
+
const held = (s) => s.held ?? formStepGroup(forms(s)[s.from]) === formStepGroup(forms(s)[s.to]);
|
|
336
|
+
hold = group.every(held) && idx.some(holds);
|
|
332
337
|
for (const s of [...group].reverse()) at[index.get(s.id)] = s.from;
|
|
333
338
|
if (minSum() <= length + EPS && crossOf() === c0 && changed.every((j) => !tooWide(j, c0))) return true;
|
|
334
339
|
changed.forEach((i, k) => at[i] = was[k]);
|
|
@@ -374,7 +379,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
374
379
|
for (const [q, i] of queue.entries()) {
|
|
375
380
|
if (!isMenu(form(i))) continue;
|
|
376
381
|
const ahead = queue.slice(0, q);
|
|
377
|
-
if (!ahead.every((j) => isMenu(form(j)) || at[i] - 1 - start[i] >= at[j] - start[j] &&
|
|
382
|
+
if (!ahead.every((j) => isMenu(form(j)) || at[i] - 1 - start[i] >= at[j] - start[j] && formOrder(form(i), form(j)) >= 0)) break;
|
|
378
383
|
inside2.push(i);
|
|
379
384
|
}
|
|
380
385
|
let out = false;
|
|
@@ -388,7 +393,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
388
393
|
if (!out) break;
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
|
-
hold = idx.some(holds);
|
|
396
|
+
hold = idx.some(holds) && !hist.some((s) => s.held === false);
|
|
392
397
|
let cross = crossOf();
|
|
393
398
|
let overflow = 0;
|
|
394
399
|
const guard = 2 * items.reduce((s, it) => s + it.forms.length, 0) + 2;
|
|
@@ -406,13 +411,24 @@ function solve(input, previous, seed, grow = false) {
|
|
|
406
411
|
if (over <= EPS) break;
|
|
407
412
|
const to = idx.map((i) => itemSteps(items[i]) ? stepTo(i) : -1);
|
|
408
413
|
if (hold) {
|
|
414
|
+
const low = idx.reduce((m, i) => to[i] >= 0 ? Math.min(m, formLevel(items[i].forms[to[i]])) : m, holdLevel());
|
|
409
415
|
const variant = victim(
|
|
410
416
|
items,
|
|
411
|
-
idx.map((i) => to[i] >= 0 && sameKind(i, to[i]) ? to[i] : -1)
|
|
417
|
+
idx.map((i) => to[i] >= 0 && sameKind(i, to[i]) && formLevel(items[i].forms[to[i]]) <= low ? to[i] : -1)
|
|
412
418
|
);
|
|
413
|
-
if (variant >= 0)
|
|
414
|
-
|
|
415
|
-
|
|
419
|
+
if (variant >= 0) {
|
|
420
|
+
step(variant, to[variant]);
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const top = holdLevel();
|
|
424
|
+
const below = idx.map((i) => {
|
|
425
|
+
const j = to[i] < 0 && !inMenu() && itemSteps(items[i]) ? menuFormAfter(i) : -1;
|
|
426
|
+
return j >= 0 && formLevel(items[i].forms[j]) < top ? j : -1;
|
|
427
|
+
});
|
|
428
|
+
if (low >= top && menuBatch(below) === null) {
|
|
429
|
+
hold = false;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
416
432
|
}
|
|
417
433
|
const pool = idx.map((i) => to[i] < 0 && !inMenu() && itemSteps(items[i]) ? menuFormAfter(i) : -1);
|
|
418
434
|
const v = victim(
|
|
@@ -420,7 +436,8 @@ function solve(input, previous, seed, grow = false) {
|
|
|
420
436
|
idx.map((i) => to[i] >= 0 ? to[i] : pool[i])
|
|
421
437
|
);
|
|
422
438
|
if (v >= 0 && to[v] < 0) {
|
|
423
|
-
const
|
|
439
|
+
const open = idx.reduce((m, i) => to[i] >= 0 && itemSteps(items[i]) ? Math.min(m, formLevel(items[i].forms[to[i]])) : m, Infinity);
|
|
440
|
+
const batch = menuBatch(pool.map((j, i) => j >= 0 && formLevel(items[i].forms[j]) <= open ? j : -1));
|
|
424
441
|
if (batch) {
|
|
425
442
|
const id = batches++;
|
|
426
443
|
for (const [i, j] of batch) step(i, j, id);
|
|
@@ -496,7 +513,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
496
513
|
short -= take;
|
|
497
514
|
};
|
|
498
515
|
const oneByOne = (group) => {
|
|
499
|
-
const order = [...group].sort((a, b) => givesWayBefore(items, a,
|
|
516
|
+
const order = [...group].sort((a, b) => givesWayBefore(items, a, form(a), b, form(b)));
|
|
500
517
|
for (const i of order) {
|
|
501
518
|
if (short <= 0) return;
|
|
502
519
|
const take = Math.min(short, size.get(i));
|
|
@@ -560,16 +577,16 @@ var sizesOf = (fit) => sizes.get(fit);
|
|
|
560
577
|
// src/stack/ladder.ts
|
|
561
578
|
var nonNeg2 = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
|
|
562
579
|
var RANK_TIER = 100;
|
|
563
|
-
var RANK_LEVEL = 1e3;
|
|
564
580
|
function controlLadder(spec) {
|
|
565
|
-
const
|
|
581
|
+
const level = formLevel({ kind: "row", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...spec.keep !== void 0 ? { level: spec.keep } : {} });
|
|
582
|
+
const pin = level > 0 ? { level } : {};
|
|
566
583
|
const cross = nonNeg2(spec.cross);
|
|
567
584
|
const grip = nonNeg2(spec.grip);
|
|
568
585
|
const gap = nonNeg2(spec.gap);
|
|
569
586
|
const more = nonNeg2(spec.more);
|
|
570
587
|
const column = spec.column ? [
|
|
571
588
|
{ kind: "icons", main: { min: nonNeg2(spec.column.icons), natural: nonNeg2(spec.column.icons) }, cross: { natural: nonNeg2(spec.column.cross ?? spec.cross) }, ...grip > 0 ? { grip } : {} },
|
|
572
|
-
{ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...
|
|
589
|
+
{ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...pin }
|
|
573
590
|
] : void 0;
|
|
574
591
|
const controls = spec.controls;
|
|
575
592
|
const n = controls.length;
|
|
@@ -595,10 +612,10 @@ function controlLadder(spec) {
|
|
|
595
612
|
for (let k = 1; k < n; k++) {
|
|
596
613
|
const hidden = new Set(order.slice(0, k));
|
|
597
614
|
const shown = all.filter((i) => !hidden.has(i));
|
|
598
|
-
row.push(form(rowLength(shown, more), { kind: "row", rank: 4 * RANK_TIER + k / n
|
|
615
|
+
row.push(form(rowLength(shown, more), { kind: "row", rank: 4 * RANK_TIER + k / n, ...pin, hides: ids(hidden), tiers: tiersOf(shown) }));
|
|
599
616
|
}
|
|
600
|
-
row.push(form(grip + more, { kind: "fold", rank: 5 * RANK_TIER
|
|
601
|
-
row.push({ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, rank: 6 * RANK_TIER
|
|
617
|
+
row.push(form(grip + more, { kind: "fold", rank: 5 * RANK_TIER, ...pin, hides: ids(new Set(all)) }));
|
|
618
|
+
row.push({ kind: "menu", main: { min: 0, natural: 0 }, cross: { natural: 0 }, rank: 6 * RANK_TIER, ...pin });
|
|
602
619
|
return { row, ...column ? { column } : {} };
|
|
603
620
|
}
|
|
604
621
|
|
|
@@ -882,7 +899,6 @@ function fitFloat(want, stage, avoid = [], options = {}) {
|
|
|
882
899
|
export {
|
|
883
900
|
DEFAULT_MENU,
|
|
884
901
|
DEFAULT_RAIL,
|
|
885
|
-
RANK_LEVEL,
|
|
886
902
|
controlLadder,
|
|
887
903
|
cutEdges,
|
|
888
904
|
dividers,
|
|
@@ -893,9 +909,11 @@ export {
|
|
|
893
909
|
formCrossMin,
|
|
894
910
|
formFitsCross,
|
|
895
911
|
formFolded,
|
|
912
|
+
formLevel,
|
|
896
913
|
formMain,
|
|
897
914
|
formMenu,
|
|
898
915
|
formOwnCross,
|
|
916
|
+
formRank,
|
|
899
917
|
formSetsCross,
|
|
900
918
|
formStepGroup,
|
|
901
919
|
itemSteps,
|
package/dist/stack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stack/cut.ts","../src/stack/model.ts","../src/stack/layout.ts","../src/stack/ladder.ts","../src/stack/divide.ts","../src/stack/gaps.ts","../src/stack/float-fit.ts"],"sourcesContent":["/**\n * `cutEdges(stage, bands)`: the stage cut into bands along its sides, in list order. Each band takes its `size` across\n * at its side of what the bands before it left, so the order decides the corners: a top band cut before a left one runs\n * across the whole width and the left one starts below it; cut after it, the left one runs the whole height. Pure: no\n * edges, items or forms, only rects.\n *\n * - A `reserve` band (the default) shortens the leftover: what follows is cut from what it leaves.\n * - An `over` band lies over the leftover without shortening it. The `over` bands are cut after every reserved band,\n * whatever the list order, from the final leftover less the `over` bands before them, so each lies inside the\n * leftover, two on one side lie side by side, and the leftover stays whole.\n * - A band is never thicker than the room left across it (a negative or missing size is 0). `gap` is space after it,\n * taken only when the band takes some room, and never more than the room left. A stage of negative size is cut as\n * one of size 0.\n *\n * Returns each band's rect by id and the leftover rect (`rest`). Band ids are unique: a repeat throws.\n *\n * See docs/placement.md, Entry: stack.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\n\n/** One band of the cut. */\nexport interface EdgeBand {\n readonly id: string;\n readonly side: Side;\n /** Its size across (a top band's height, a left band's width), px. */\n readonly size: number;\n /** Space after it before the next band on that side, px (default 0); taken only when the band takes some room. */\n readonly gap?: number;\n /** `\"reserve\"` (default) shortens the leftover; `\"over\"` lies over it. */\n readonly mode?: \"reserve\" | \"over\";\n}\n\n/** The cut: each band's rect by id, and what is left. */\nexport interface EdgeCut {\n readonly bands: Readonly<Record<string, Rect>>;\n readonly rest: Rect;\n}\n\nconst px = (x: number | undefined): number => (typeof x === \"number\" && Number.isFinite(x) ? Math.max(0, x) : 0);\n\n/** `band` laid at its side of `area`: its rect, and `area` less it (and its gap). */\nfunction cutBand(area: Rect, band: EdgeBand): { readonly rect: Rect; readonly rest: Rect } {\n const across = band.side === \"top\" || band.side === \"bottom\" ? area.height : area.width;\n const room = Math.max(0, across);\n const thick = Math.min(px(band.size), room);\n const gap = thick > 0 ? Math.min(px(band.gap), room - thick) : 0;\n const take = thick + gap;\n switch (band.side) {\n case \"top\":\n return { rect: rect(area.x, area.y, area.width, thick), rest: rect(area.x, area.y + take, area.width, area.height - take) };\n case \"bottom\":\n return { rect: rect(area.x, area.y + area.height - thick, area.width, thick), rest: rect(area.x, area.y, area.width, area.height - take) };\n case \"left\":\n return { rect: rect(area.x, area.y, thick, area.height), rest: rect(area.x + take, area.y, area.width - take, area.height) };\n case \"right\":\n return { rect: rect(area.x + area.width - thick, area.y, thick, area.height), rest: rect(area.x, area.y, area.width - take, area.height) };\n }\n}\n\nexport function cutEdges(stage: Rect, bands: readonly EdgeBand[]): EdgeCut {\n const seen = new Set<string>();\n for (const b of bands) {\n if (seen.has(b.id)) throw new Error(`cutEdges: band id \"${b.id}\" is given twice`);\n seen.add(b.id);\n }\n const out: Record<string, Rect> = {};\n // A stage of negative size is cut as one of size 0, so every rect has a size of 0 or more.\n let rest = rect(stage.x, stage.y, px(stage.width), px(stage.height));\n for (const b of bands) {\n if (b.mode === \"over\") continue;\n const c = cutBand(rest, b);\n out[b.id] = c.rect;\n rest = c.rest;\n }\n // The over bands come after every reserved one, whatever the list order: each lies inside the final leftover.\n let over = rest;\n for (const b of bands) {\n if (b.mode !== \"over\") continue;\n const c = cutBand(over, b);\n out[b.id] = c.rect;\n over = c.rest;\n }\n return { bands: out, rest };\n}\n","/**\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 * A form's kind is the host's label, the name it draws by. What a solver reads is said by fields: `setsCross` (it sets\n * the stack's cross size), `body` (it shows its body: what `open` stands for), `folded` (it shows only its bar: what\n * `header` and `fold` stand for), `compact` (icons only: what `icons` stands for), `menu` (no room of its own: the »\n * entry stands for it), `ownCross` (drawn at its own size across under the stack's `ownCross`: what the group kinds\n * `row`, `stacked`, `wrap`, `icons`, `fold` stand for), `stepGroup` (the variants the title rule steps first: default the\n * kind), `title`, `wrap` and `hides`. Each flag defaults from the kind, so forms that leave them out read as before; the\n * solver reads no kind but through them (a kept fit's form at the same index is matched by its kind, a label compared,\n * never read). Panel and group kinds may be mixed on one item.\n */\nimport { EPS, 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/**\n * Along the stack: `min` is the least it is drawn while the stack fits (a stack that doesn't, the `overflow` note, draws\n * its items squeezed, under it: see `fitStack`), `natural` what it asks for; `grows` takes spare length.\n */\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 * It shows its body: an open panel. Default: true for the kind `open`. It sets the cross size unless `setsCross` says\n * otherwise, and a window model reads it as the item being open.\n */\n readonly body?: boolean;\n /**\n * It shows only its bar: a panel folded to its header, a group folded to its grip and ». Default: true for the kinds\n * `header` and `fold`. A window model reads it as folded: a hand fold takes the first such form, and a float in it\n * keeps its bar's height.\n */\n readonly folded?: boolean;\n /** Icons only. Default: true for the kind `icons`. A window model's compact (icons-only) edge takes it. */\n readonly compact?: 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). A window model (`@n-uf/docking`)\n * reports its rect; a `wrap` form's grip is its lead cell instead.\n */\n readonly grip?: number;\n /**\n * The control ids this form leaves out, against the item's first form: a compact variant of a toolbar (a row form\n * between the full row and its wrap, smaller, its \"+N\" cell counted in its size) hides some controls a \"+N\" control\n * reaches. Any form may set it (a wrap, icons or menu form too). The ladder reads it nowhere: a variant is a form like\n * any other, taken in order, giving way and coming back by the usual rules. `@n-uf/docking` reports the chosen form's ids\n * as `hidden`.\n */\n readonly hides?: readonly string[];\n /**\n * Each shown control's tier, by control id (0 the longest), set by `controlLadder` on every row form it generates (not\n * on `fold` and `menu`): a host draws each control at its tier from it, with no knowledge of the ladder's order. It is\n * always a valid index into the control's own `tiers` (a control with fewer tiers than the group stays on its last; a\n * control with no tiers reports 0). A\n * hand-written form leaves it out. `@n-uf/docking` reports the chosen form's as the item layout's `tiers`.\n */\n readonly tiers?: Readonly<Record<string, number>>;\n /**\n * A `rail` form that draws the item's title along the rail (its name and count, turned to run along it) instead of\n * its tile. Put it just before the item's tile `rail` form: in a rail the two are steps on the ladder, the title giving\n * way to the tile by the usual rules and coming back in exact reverse. Its `main` is the title's length along the rail,\n * measured by the host. A stack offers it only with `StackInput.titles`; otherwise it is passed over like a form that\n * isn't there (never started in, stepped into or grown back to). `@n-uf/docking` offers it in a rail whose side shows\n * titles (`DockState.railModes`, default `\"titles\"`) and reports the side it reads from (`DockItemLayout.railTitle`).\n */\n readonly title?: boolean;\n /**\n * It has no room of its own: the » entry stands for it while the item is in it. Default: true for the kind `menu`. A\n * stack's » menu holds exactly the items in such a form (`StackMenu.items`).\n */\n readonly menu?: boolean;\n /**\n * Under `StackInput.ownCross`, it is drawn at its own `cross.natural` (clamped to the stack's cross size; a `wrap` form\n * as wide as its rows need) from the start edge, instead of across the whole stack. Default: true for the group kinds\n * (`row`, `stacked`, `wrap`, `icons`, `fold`), false for the panel kinds and a menu form. Without `ownCross` it is\n * never read.\n */\n readonly ownCross?: boolean;\n /**\n * The step group it belongs to: forms of one item with the same key are variants of one form (a toolbar's full row and\n * its compact rows). The title rule reads it: while a growing item that takes no steps holds its natural length, only\n * steps within a step group are taken (`StackItem.fixed`). Default: the form's kind.\n */\n readonly stepGroup?: string;\n}\n\n/** Whether an item takes give-way steps: a movable one, or a fixed one with `stepping`. */\nexport const itemSteps = (item: { readonly fixed?: boolean; readonly stepping?: boolean }): boolean => item.fixed !== true || item.stepping === true;\n\n/** Whether a form has no room of its own, the » entry standing for it (`menu`, default: the kind `menu`). */\nexport const formMenu = (f: StackForm): boolean => f.menu ?? f.kind === \"menu\";\n/** Whether a form is drawn at its own size across under `ownCross` (`ownCross`, default: the group kinds). */\nexport const formOwnCross = (f: StackForm): boolean => f.ownCross ?? GROUP_KINDS.has(f.kind);\n/** A form's step group (`stepGroup`, default: its kind). */\nexport const formStepGroup = (f: StackForm): string => f.stepGroup ?? f.kind;\n/** The form kinds of a control group: the default of `ownCross`. */\nconst GROUP_KINDS: ReadonlySet<string> = new Set([\"row\", \"stacked\", \"wrap\", \"icons\", \"fold\"]);\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). A window model's size clamp and\n * column 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 (formMenu(f)) 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 neighboring 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\n/**\n * The length a person asked an item to have, px along a stack, per axis: a flex basis. `column` is read by a stack that\n * runs down, `row` by one that runs across, so an item that moves to a stack of the other axis never reads a length\n * meant for this one.\n */\nexport interface StackLengths {\n readonly column?: number;\n readonly row?: number;\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 and draws it squeezed,\n * under its least, before any item that takes steps: \"never gives way\" means it never leaves its form). It is never\n * dropped: `stackGaps` refuses every gap for it, and a drop beside it never squeezes it. Whether it may sit among others (or\n * first, or last) is the host's; placement lays out the items it is given. With `stepping` it keeps only the reserved\n * place and takes its steps like any item.\n */\n readonly fixed?: boolean;\n /**\n * A fixed item that still takes steps (default false; read only with `fixed`): it keeps its reserved place (never\n * dropped: `stackGaps` refuses every gap for it) but steps through its forms, into the » menu too, gives way by the\n * usual order and grows back in exact reverse: its fit is a movable item's with the same forms, `used` and `kept`. It\n * never holds for the title rule (that is a growing item that takes no steps); to have it shorten last, make it `kept`\n * or rank its forms. A drop beside it may step it, as it may a movable item, but never squeezes it under its form's\n * `main.min`.\n */\n readonly stepping?: boolean;\n /**\n * The length asked for along the stack (default none). While the item is in a form that grows (`main.grows`; a `wrap`\n * form that grows shares spare length too), the solver reads it, for the stack's axis, in place of that form's `main.natural`; the form's\n * `main.min` stays the least, a floor on the drawn size and not on the ask, and a value that isn't a finite number over\n * 0 is no asked length (a 0 asks nothing: the item reads its natural). There is no new formula: with spare length the sized items share it in proportion to their\n * lengths (one whose share would be under its least is drawn at its least, the others share the rest), short of length\n * they interpolate between their least (an ask under it reads as the least) and their length, so a stack too short for\n * all of them still trades room between them. A form that doesn't grow ignores it (the length is kept for when the item grows again), and so does a\n * stack of the other axis. A stack whose items declare none is laid out exactly as before. What gives way and in\n * which order never reads it. It is in ask units, not drawn px: with room to spare a drawn size is the ask times the\n * shared scale, or its least when that is more. `resizeBetween` and `resetBetween` write it for the pair only; `resetLengths` clears it.\n */\n readonly lengths?: StackLengths;\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 neighboring drawn items, px (default 0). The » entry is a neighbor 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). `stackGaps` refuses every gap for an item it doesn't accept, so\n * 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.\n */\n readonly ownCross?: boolean;\n /**\n * Offer the forms marked `title` (default false: they are passed over, so a stack without it lays out as if they\n * weren't declared). A rail showing titles sets it.\n */\n readonly titles?: 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 shows its body (`body`, default: the kind `open`). */\nexport const formBody = (f: StackForm): boolean => f.body ?? f.kind === \"open\";\n/** Whether a form shows only its bar (`folded`, default: the kinds `header` and `fold`). */\nexport const formFolded = (f: StackForm): boolean => f.folded ?? (f.kind === \"header\" || f.kind === \"fold\");\n/** Whether a form is icons only (`compact`, default: the kind `icons`). */\nexport const formCompact = (f: StackForm): boolean => f.compact ?? f.kind === \"icons\";\n\n/** Whether a form sets the stack's cross size: its own say, else whether it shows its body. */\nexport const formSetsCross = (f: StackForm): boolean => f.setsCross ?? formBody(f);\n\n/**\n * The length item `item` asks for along an `axis` stack while it is in `form`, or undefined: it asks for none, the\n * value isn't a finite number over 0 (a length of 0, or under `EPS`, is no length: the item reads its natural), or the\n * form doesn't grow (a form with no `main.grows`, the menu). A `wrap` form that grows reads it like any growing form: it\n * shares spare length, so its length is one a divider drag writes.\n */\nexport function askedLength(item: StackItem, form: StackForm, axis: StackAxis): number | undefined {\n const v = item.lengths?.[axis];\n if (v === undefined || !Number.isFinite(v) || v <= EPS) return undefined;\n return !formMenu(form) && form.main.grows === true ? v : undefined;\n}\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/**\n * An item drawn: the form it took, its kind and its rect (stack-local px), always inside the stack's length. One in the\n * menu has the menu entry's rect. In a fit with the `overflow` note the rect can be shorter than the form's `main.min`\n * (squeezed), down to 0, so a host clips or ellipsizes each item to its rect; a rect of no length has no hit area.\n */\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 /**\n * The » entry's rect, inside the stack: at its end, before the end padding (squeezed, it starts at\n * `length - pad.end - menu.main` while the padding is whole), and cut only when the length is under its size.\n */\n readonly rect: Rect;\n /** The items in it, in the stack's order: exactly the items in a menu form (`StackForm.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). The stack is then\n * drawn squeezed, inside its length, and `over` is what its items, then its gaps, padding and » entry gave up.\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` takes 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. A growing form whose item asks for a length (`StackItem.lengths`, for the stack's\n * axis) is read at that length in place of its natural size, nothing else changes. With room, an ask is a weight and the\n * least a floor on the drawn size: a form whose share would be under its least is drawn at its least, the others share the rest.\n * 6. Squeezed: when no item can give more way and the stack is still too long (the `overflow` note, `over` px), the\n * stack is still drawn inside its length. Every drawn item starts at its least, and `over` comes off in one order,\n * each rung down to 0 before the next: (1) the items that take no steps (`itemSteps` false) whose form grows share\n * it, in proportion to their least; (2) the other items that take no steps, one at a time; (3) the items that take\n * steps, those whose form grows sharing first, then the others one at a time; (4) the gaps, all alike; (5) the\n * padding, in proportion; (6) the » entry, cut to the length. \"One at a time\" is the give-way order of step 4, every\n * key of it, read at the form the item is in: the lowest `rank` first, unkept before kept, the item used longest ago,\n * and only then the later in the stack (read for fixed items too: alike in all three, they go from the end). Nothing\n * the user can act on goes out of reach while something else can still yield, and at most one rigid item is ever\n * partly cut. A 0-long item keeps its gap; the »\n * entry stays whole while the length allows it, at `length - pad.end - entry` while the padding is whole. A host\n * clips each item to its rect. A fit without `overflow` is never squeezed.\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. A fixed item with `stepping` takes every step\n * like an item that isn't fixed: the solver reads \"takes no steps\" (`itemSteps`), never `fixed` itself.\n *\n * With `ownCross`, an item in a form drawn at its own size (`StackForm.ownCross`; default the group kinds `row`, `stacked`,\n * `wrap`, `icons`, `fold`) is drawn at its own `cross.natural` (clamped to the stack's cross size) from the start edge\n * instead of across the whole stack; any other form (by default a panel's `open`, `header`, `rail`) still spans it.\n * Nothing else changes. The solver reads a form's kind through its flags only (`menu`, `ownCross`, `stepGroup`), each\n * defaulting from the kind; a kept fit's form is matched at its index by its kind, a label compared and never read.\n *\n * `gap` sits between neighboring drawn items (the » entry is one), `pad` before the first and after the last; both\n * count toward the length and the rects include them, so an app draws at the rects.\n *\n * The solver has no open or closed state: it lays out the items it is given, and a consumer closes a panel by not\n * passing it (or by starting it at a later form with `from`). An item with no forms is left out (`no-forms`). Pure:\n * same input, same fit.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport { askedLength, formCrossMin, formFitsCross, formMain, formMenu, formOwnCross, formSetsCross, formStepGroup, itemSteps, limitsOf, menuMain, spacingOf, wrapCross, wrapRows, type FitOptions, type PlacedStackItem, type StackFit, type StackForm, type StackInput, type StackItem, type StackMenu, type StackNote, type StackStep } from \"./model\";\nconst isMenu = formMenu;\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 give-way order, the one comparator every order of the solver reads: negative when item `a` (at index `a`, its form\n * ranked `ra`) gives way before item `b`. The lower rank first (of the form that counts: the one an item steps into\n * while it gives way, the one it is in when it is squeezed or grows back), then unkept before kept, then the item used\n * longest ago, and only then the later in the stack. Every key is read for every item, fixed ones too: an item with no\n * `kept` is unkept, and items alike in rank, `kept` and `used` (fixed parts a host gives one age) go from the end\n * backward. Growing back reads it the other way round.\n */\nfunction givesWayBefore(items: readonly StackItem[], a: number, ra: number, b: number, rb: number): number {\n if (ra !== rb) return ra - rb;\n const ka = items[a]!.kept ? 1 : 0;\n const kb = items[b]!.kept ? 1 : 0;\n if (ka !== kb) return ka - kb;\n const ua = items[a]!.used;\n const ub = items[b]!.used;\n // (as the step order always read it: an age that isn't a number never puts its item first)\n if (ua !== ub) return ua < ub ? -1 : 1;\n return b - a;\n}\n\n/**\n * The item that gives way next, among those with a step (`to[i]`, the form it would take, or -1): first in the give-way\n * order by the rank of the form it steps into.\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 || !itemSteps(items[i]!)) continue;\n if (best < 0 || givesWayBefore(items, i, rankOf(items[i]!.forms[to[i]!]!), best, rankOf(items[best]!.forms[to[best]!]!)) < 0) 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 // A `title` form is offered only with `input.titles`; otherwise it is passed over like a form that isn't there.\n const offered = (f: StackForm): boolean => f.title !== true || input.titles === true;\n /** The first form at or after `j` that is offered (`j` itself when none is: an item keeps a form to draw). */\n const offeredFrom = (it: StackItem, j: number): number => {\n for (let k = j; k < it.forms.length; k++) if (offered(it.forms[k]!)) return k;\n return j;\n };\n const start = items.map((it) => offeredFrom(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 (!itemSteps(it) || !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 && offered(f)) 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` neighbors: 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 /**\n * A fixed item whose form grows (a title) holds its natural length while the other items can still step to a form of\n * the kind they are in (a toolbar's compact variants: row to a smaller row): its shrink below natural is a give-way\n * step that ranks after every such step and before every step that changes a form's kind (icons, fold, the menu).\n * `hold` is on while those steps come first.\n */\n const holds = (i: number): boolean => !itemSteps(items[i]!) && form(i).main.grows === true;\n let hold = idx.some(holds);\n /** The shortest the stack can be drawn now: the smallest sizes, the » entry, the gaps and the padding. */\n const minSumWith = (held: boolean): 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), held && holds(i) ? \"natural\" : \"min\", c), 0) + (inMenu() ? menuMain(input) : 0) + gapsOf() + sp.start + sp.end;\n };\n const minSum = (): number => minSumWith(hold);\n /** Whether stepping item `i` to form `j` keeps its form's step group (a compact variant of the form it is in). */\n const sameKind = (i: number, j: number): boolean => formStepGroup(items[i]!.forms[j]!) === formStepGroup(form(i));\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 if (!offered(items[i]!.forms[j]!)) continue;\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 /** The next offered form after item `i`'s current one, or -1. */\n const nextOffered = (i: number): number => {\n for (let j = at[i]! + 1; j < items[i]!.forms.length; j++) if (offered(items[i]!.forms[j]!)) return j;\n return -1;\n };\n const canStep = (i: number): boolean => nextOffered(i) >= 0;\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 // What the forms need at least, every growing fixed item at its minimum (the measure room coming back is read by).\n if (seed) seed.need = minSumWith(false);\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 give-way order backwards: the highest rank first, then `kept`,\n // the newest used, the earlier in the stack). An item goes back to the nearest earlier form the stack still fits\n // with, the cross size unchanged: a larger form is what counts, not a longer stack (the last item leaving the menu\n // takes the » entry with it).\n const comesBefore = (a: number, b: number): boolean => givesWayBefore(items, b, rankOf(items[b]!.forms[at[b]!]!), a, rankOf(items[a]!.forms[at[a]!]!)) < 0;\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 // A step to a form of the same kind (a compact variant) was taken while the growing fixed items held their natural\n // length: it comes back only when they still do. Every other step came after their shrink.\n const forms = (s: StackStep) => items[index.get(s.id)!]!.forms;\n hold = group.every((s) => formStepGroup(forms(s)[s.from]!) === formStepGroup(forms(s)[s.to]!)) && idx.some(holds);\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 hold = false;\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) => itemSteps(items[i]!) && 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 if (!offered(items[next]!.forms[k]!)) continue;\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 hold = idx.some(holds);\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 (itemSteps(items[i]!) && tooWide(i, cross) && canStep(i) && !isMenu(items[i]!.forms[nextOffered(i)]!)) {\n step(i, nextOffered(i));\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), unless it is `stepping`.\n const to = idx.map((i) => (itemSteps(items[i]!) ? stepTo(i) : -1));\n if (hold) {\n // First the steps that keep a form's kind (compact variants), the growing fixed items at their natural length;\n // with none left, they may shrink (`hold` off) and the other steps follow.\n const variant = victim(\n items,\n idx.map((i) => (to[i]! >= 0 && sameKind(i, to[i]!) ? to[i]! : -1)),\n );\n if (variant >= 0) step(variant, to[variant]!);\n else hold = false;\n continue;\n }\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() && itemSteps(items[i]!) ? 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 // While the growing fixed items still hold (the forms fit with them at their natural length), the others take the\n // shortage first: a held item's least is its natural length.\n const min = (i: number): number => mainOf(form(i), hold && holds(i) ? \"natural\" : \"min\", cross);\n // What a growing form asks for: its item's asked length (`StackItem.lengths`) when it has one, else the form's natural.\n const nat = (i: number): number => Math.max(min(i), askedLength(items[i]!, form(i), input.axis) ?? 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 // The share of the way from the least to the asked sizes the items are drawn at: 1 with room enough for all.\n let tight = 1;\n // How much longer than it asks a growing form is drawn with spare length: 1 + spare / weight.\n let scale = 1;\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 if (weight > EPS) scale = 1 + spare / weight;\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 // An ask is a weight, and the least a floor on the drawn size: a form asking for less than its least is drawn at its\n // least, and the others share what is left in proportion to their asks (the scale is the one that fills the length).\n const ask = (i: number): number => askedLength(items[i]!, form(i), input.axis) ?? nat(i);\n if (weight > EPS && growers.some((i) => ask(i) < min(i))) {\n const pinned = new Set<number>();\n const room = avail - drawn.reduce((s, i) => (growers.includes(i) ? s : s + nat(i)), 0);\n let s = scale;\n for (;;) {\n const free = growers.filter((i) => !pinned.has(i));\n const weights = free.reduce((sum, i) => sum + ask(i), 0);\n if (weights <= EPS) {\n for (const i of free) pinned.add(i);\n break;\n }\n s = (room - [...pinned].reduce((sum, i) => sum + min(i), 0)) / weights;\n const under = free.filter((i) => ask(i) * s < min(i));\n if (under.length === 0) break;\n for (const i of under) pinned.add(i);\n }\n if (pinned.size < growers.length) {\n scale = s;\n for (const i of growers) size.set(i, pinned.has(i) ? min(i) : ask(i) * s);\n }\n }\n } else {\n const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;\n tight = t;\n for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);\n }\n\n // Squeezed: a stack that still doesn't fit (`overflow`, every drawn item at its least) is drawn inside its length all the\n // same. What it lacks comes off in one order, each rung to 0 before the next (step 6 above).\n let gap = sp.gap;\n let padStart = sp.start;\n let padEnd = sp.end;\n let entry = menuSize;\n let short = overflow > EPS ? overflow : 0;\n if (short > 0) {\n // (Drawn under their least, the items are none of the way toward their asks: whichever branch shared the sizes.)\n tight = 0;\n /** Elastic parts share the loss, in proportion to their least (drawn at it now): an item at 0 has nothing to give. */\n const share = (group: readonly number[]): void => {\n const have = group.reduce((s, i) => s + size.get(i)!, 0);\n if (short <= 0 || have <= EPS) return;\n const take = Math.min(short, have);\n for (const i of group) size.set(i, size.get(i)! * (1 - take / have));\n short -= take;\n };\n /** Rigid parts take it one at a time, in the give-way order by the rank of the form each is in. */\n const oneByOne = (group: readonly number[]): void => {\n const order = [...group].sort((a, b) => givesWayBefore(items, a, rankOf(form(a)), b, rankOf(form(b))));\n for (const i of order) {\n if (short <= 0) return;\n const take = Math.min(short, size.get(i)!);\n size.set(i, size.get(i)! - take);\n short -= take;\n }\n };\n const grows = (i: number): boolean => form(i).main.grows === true;\n // Nothing the user can act on goes out of reach while something else can yield: the items that take no steps (the\n // host's reserved room) first, then the items that take steps; the spacing after them, the » entry last.\n const reserved = drawn.filter((i) => !itemSteps(items[i]!));\n const movable = drawn.filter((i) => itemSteps(items[i]!));\n share(reserved.filter(grows));\n oneByOne(reserved.filter((i) => !grows(i)));\n share(movable.filter(grows));\n oneByOne(movable.filter((i) => !grows(i)));\n // The gaps between the drawn items and the » entry (one slot while any item is in the menu).\n const gaps = Math.max(0, drawn.length + (inMenu() ? 1 : 0) - 1);\n if (short > 0 && gaps > 0 && gap > 0) {\n const take = Math.min(short, gaps * gap);\n gap -= take / gaps;\n short -= take;\n }\n if (short > 0 && padStart + padEnd > 0) {\n const pads = padStart + padEnd;\n const take = Math.min(short, pads);\n padStart -= (take * padStart) / pads;\n padEnd -= (take * padEnd) / pads;\n short -= take;\n }\n if (short > 0 && inMenu()) entry = Math.max(0, entry - short);\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 form drawn at its own size (`StackForm.ownCross`,\n * default the group kinds `row`, `stacked`, `wrap`, `icons`, `fold`), its own `cross.natural` (clamped to the stack's),\n * from the start edge. That flag decides, not `setsCross`: a group's form that sets the cross size (a column of words)\n * widens the column but is drawn at its own width, and a panel's form (`open`, `header`, `rail`) and the » entry fill\n * the stack.\n */\n const acrossOf = (i: number): number => {\n const f = form(i);\n if (input.ownCross !== true || !formOwnCross(f)) 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 = padStart;\n for (const i of drawn) {\n const s = size.get(i)!;\n rects.set(i, rectAt(cursor, s, acrossOf(i)));\n cursor += s + gap;\n }\n // The » entry sits at the end of the stack, before the end padding. Squeezed, the items end exactly there; otherwise\n // they end at or before it (by float noise, after: so the cursor counts, and a fit that fits is as it always was).\n const menuRect = overflow > EPS ? rectAt(length - padEnd - entry, entry) : 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 const fit: StackFit = { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };\n sizes.set(fit, { tight, scale, least: new Map(drawn.map((i) => [items[i]!.id, min(i)])) });\n return fit;\n}\n\n/** What `solve` knew about the sizes of a fit and the fit doesn't say. */\nexport interface FitSizes {\n /** How far from the least to the asked sizes the items were drawn: 1 with room for all of them, less when short, 0 squeezed. */\n readonly tight: number;\n /** How much longer than it asks each growing form was drawn: 1 + spare / weight with spare length, else 1. */\n readonly scale: number;\n /**\n * The least each drawn item could take as the sizes were shared (a held growing fixed item's is its natural). A squeezed\n * item (the `overflow` note) is drawn under it.\n */\n readonly least: ReadonlyMap<string, number>;\n}\n/** The sizes of each fit `solve` made, kept off the fit itself so a fit is exactly what it was. */\nconst sizes = new WeakMap<StackFit, FitSizes>();\n/**\n * What `fitStack` knew about how it shared the length: `undefined` for a fit it didn't make. A divider drag reads it to\n * write lengths that reproduce the drawn sizes exactly.\n */\nexport const sizesOf = (fit: StackFit): FitSizes | undefined => sizes.get(fit);\n","/**\n * `controlLadder`: a control group's forms, generated from its controls.\n *\n * A host that hand-writes a group's forms gives a few coarse steps (a row, icons, a fold). A host that declares what the\n * group holds (its controls, each with its lengths per tier) gets the fine ladder instead, so a bar runs short control\n * by control and not group by group. Nothing here is a solver rule: the result is an ordinary `StackForm[]` with `rank`\n * and `hides` set, and `fitStack` takes it like any other (the lowest-ranked next form across all items, its tie-breaks,\n * the way back by `previous`).\n *\n * The ladder, in order, for `n` controls and `T` tiers (a tier is one length per control, longest first):\n * 1. The first form: every control at tier 0, a `row`.\n * 2. The tier steps, one control at a time in fold order: the control that folds first takes tier 1, then the next, then\n * the first takes tier 2, and so on to tier `T - 1` for all. Each is a `row` with every control shown. Step `i`\n * (0-based, within tier `t`) has rank `100 * t + i / n` for tiers 1 and 2, so groups of different sizes level within\n * a tier; tiers 3 and later share the band from 300 in tier order, rank `300 + (t - 3 + i / n) / (T - 3)`, so the\n * ranks strictly increase along the group and stay under 400 for any `T`.\n * 3. The partial folds, at the last tier: for `k = 1 … n - 1`, a `row` that hides the first `k` controls in fold order\n * (`hides` lists them) and shows a `more` cell for them. Rank `400 + k / n`: the group with the fewest hidden controls\n * folds next.\n * 4. `fold` (the grip and the `more` cell in line, `hides` every control), rank 500, then `menu`, rank 600.\n *\n * Every row form carries `tiers`, each shown control's tier index (`StackForm.tiers`; `fold` and `menu` have none), so a\n * host draws a control from the form the layout chose, with no knowledge of this order.\n *\n * Every form is always emitted, even when it is no shorter than the one before: the solver passes over a form that\n * doesn't shorten the stack, and the shape (`n * T + 2` forms, `0` with no controls) depends on the control and tier\n * counts alone, so a form index stays valid when a length changes. When the control set itself changes, solve the group\n * fresh (no `previous`).\n *\n * Ranks are spaced by step type in fixed bands whatever a group's tier count: tier steps in [100, 400), partial folds\n * 400 + k / n, fold 500, menu 600. So the same-tier steps of several groups interleave, and a partial fold never comes\n * before another group's tier step, even when the groups have different tier counts.\n */\nimport type { StackForm } from \"./model\";\n\n/** One control of a group: an id and its length along the stack per tier. */\nexport interface LadderControl {\n readonly id: string;\n /**\n * Its lengths per tier, longest first, in the host's order of presentation (full, shorter, shortest). A tier the\n * control doesn't list keeps its last length; a control with none is 0 long. A group's tier count is its longest list.\n */\n readonly tiers: readonly number[];\n /**\n * Folds before the controls with a lower number (default: its index, so the last control folds first). Ties go to the\n * later control. The same order sets which control a tier step shortens first.\n */\n readonly foldOrder?: number;\n}\n\n/** A control group, declared by its controls. All lengths are along the stack, px. */\nexport interface ControlLadderSpec {\n /** In drawing order. */\n readonly controls: readonly LadderControl[];\n /** Between two neighboring controls (default 0). The grip and the `more` cell are the cells' own widths, with no gap. */\n readonly gap?: number;\n /** The grip cell at the group's start (default 0); every form but the menu carries it as `StackForm.grip`. */\n readonly grip?: number;\n /** The group's own » cell, drawn once any control is hidden. */\n readonly more: number;\n /** The group's thickness across the stack (a bar's height). */\n readonly cross: number;\n /**\n * The group's form in a column (a rail): an `icons` strip `icons` long, then the menu. `cross` is its width (default\n * the group's `cross`). Without it the group has no column forms.\n */\n readonly column?: { readonly icons: number; readonly cross?: number };\n /**\n * A pinned primary's level (default 0): its partial folds, fold and menu rank `keep * 1000` higher, so every group of a\n * lower level gives way entirely before it folds a control. Tier steps are unchanged.\n */\n readonly keep?: number;\n}\n\n/** A group's forms along a bar (`row`) and, when declared, down a column; assignable to `@n-uf/docking`'s `DockItem.forms`. */\nexport interface ControlLadder {\n readonly row: readonly StackForm[];\n readonly column?: readonly StackForm[];\n}\n\nconst nonNeg = (x: number | undefined): number => (typeof x === \"number\" && Number.isFinite(x) ? Math.max(0, x) : 0);\nconst RANK_TIER = 100;\n/**\n * One level of give-way ranks: a pin (`ControlLadderSpec.keep`) raises a group's later forms by this much per level, so a\n * form's rank is its level times `RANK_LEVEL` plus its rank within the level (`rank % RANK_LEVEL`, under `RANK_LEVEL`).\n * A consumer that ranks a step of its own after \"every shorter drawn form\" of a stack reads the forms' ranks within their\n * level, so a pin moves its own item and nothing else.\n */\nexport const RANK_LEVEL = 1000;\n\n/** `spec`'s forms: the row ladder, and the column ladder when `spec.column` is given. Pure. */\nexport function controlLadder(spec: ControlLadderSpec): ControlLadder {\n const keep = Math.max(0, Number.isFinite(spec.keep) ? spec.keep! : 0) * RANK_LEVEL;\n const cross = nonNeg(spec.cross);\n const grip = nonNeg(spec.grip);\n const gap = nonNeg(spec.gap);\n const more = nonNeg(spec.more);\n const column: StackForm[] | undefined = spec.column\n ? [\n { kind: \"icons\", main: { min: nonNeg(spec.column.icons), natural: nonNeg(spec.column.icons) }, cross: { natural: nonNeg(spec.column.cross ?? spec.cross) }, ...(grip > 0 ? { grip } : {}) },\n { kind: \"menu\", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...(keep > 0 ? { rank: keep } : {}) },\n ]\n : undefined;\n\n const controls = spec.controls;\n const n = controls.length;\n if (n === 0) return { row: [], ...(column ? { column } : {}) };\n const tierCount = Math.max(1, ...controls.map((c) => c.tiers.length));\n const length = (c: LadderControl, tier: number): number => nonNeg(c.tiers[Math.min(tier, c.tiers.length - 1)]);\n /** The control indexes in fold order: the first folds (and is shortened) first. */\n const order = controls\n .map((c, index) => ({ index, key: typeof c.foldOrder === \"number\" && Number.isFinite(c.foldOrder) ? c.foldOrder : index }))\n .sort((a, b) => b.key - a.key || b.index - a.index)\n .map((o) => o.index);\n const ids = (hidden: ReadonlySet<number>): string[] => controls.filter((_, i) => hidden.has(i)).map((c) => c.id);\n const form = (main: number, extra: Partial<StackForm> & Pick<StackForm, \"kind\">): StackForm => ({ main: { min: main, natural: main }, cross: { natural: cross }, ...(grip > 0 ? { grip } : {}), ...extra });\n /** Tiers 1 and 2 own a band each; every later tier shares the band from 300, in tier order, always under 400. */\n const tierRank = (t: number, i: number): number => (t <= 2 ? RANK_TIER * t + i / n : 3 * RANK_TIER + (t - 3 + i / n) / (tierCount - 3));\n\n const row: StackForm[] = [];\n // The tier of every control now; the row's length with the controls in `shown`.\n const at = controls.map(() => 0);\n const rowLength = (shown: readonly number[], extra: number): number => shown.reduce((s, i) => s + length(controls[i]!, at[i]!), 0) + Math.max(0, shown.length - 1) * gap + grip + extra;\n const all = controls.map((_, i) => i);\n /** `StackForm.tiers` for the controls in `shown`: the tier each has now, held to its own list, so always a valid index into it. */\n const tiersOf = (shown: readonly number[]): Readonly<Record<string, number>> => Object.fromEntries(shown.map((i) => [controls[i]!.id, Math.min(at[i]!, Math.max(0, controls[i]!.tiers.length - 1))]));\n row.push(form(rowLength(all, 0), { kind: \"row\", tiers: tiersOf(all) }));\n for (let t = 1; t < tierCount; t++) {\n for (let i = 0; i < n; i++) {\n at[order[i]!] = t;\n row.push(form(rowLength(all, 0), { kind: \"row\", rank: tierRank(t, i), tiers: tiersOf(all) }));\n }\n }\n for (let k = 1; k < n; k++) {\n const hidden = new Set(order.slice(0, k));\n const shown = all.filter((i) => !hidden.has(i));\n row.push(form(rowLength(shown, more), { kind: \"row\", rank: 4 * RANK_TIER + k / n + keep, hides: ids(hidden), tiers: tiersOf(shown) }));\n }\n row.push(form(grip + more, { kind: \"fold\", rank: 5 * RANK_TIER + keep, hides: ids(new Set(all)) }));\n row.push({ kind: \"menu\", main: { min: 0, natural: 0 }, cross: { natural: 0 }, rank: 6 * RANK_TIER + keep });\n return { row, ...(column ? { column } : {}) };\n}\n","/**\n * Stacked items that share a draggable divider: one makes its neighbor longer and the other shorter by the same\n * amount, and nothing else in the stack moves. A divider's state is the asked length of the items on both sides\n * (`StackItem.lengths`), which `fitStack` reads in place of a growing form's natural; these are the functions that read and\n * write it. Pure: a state in, a state out (the same object when nothing changed).\n *\n * A growing item is one drawn in a form that grows (`main.grows`, not in the » menu): the items that share spare length,\n * and so the items whose length is written. The two ends of a divider are neighboring growing items, neither `fixed` nor a\n * `wrap` form. A header, a rail icon, a group or a folded item between them isn't growing, so it has no divider of its own\n * and doesn't kill the divider across it; a growing item that is not an end (a fixed one, a `wrap` form that grows) ends\n * the chain: there is no divider across it.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport { fitStack, sizesOf } from \"./layout\";\nimport { formMain, formMenu, type FitOptions, type StackAxis, type StackFit, type StackInput } from \"./model\";\n\n/** One divider: between the open growing items `before` and `after` (ids), drawn at `rect`. */\nexport interface StackDivider {\n readonly before: string;\n readonly after: string;\n /**\n * The strip the divider sits on, stack-local: it starts where the last item drawn before `after` ends (the far edge of\n * the last collapsed item between the two, or of `before`), and is as thick as the gap to `after` (0 with no gap).\n * Across, it is `before`'s extent. A host draws its grab zone around it.\n */\n readonly rect: Rect;\n /**\n * How far the divider may move each way, px along the stack (`min` ≤ 0 ≤ `max`): the delta `resizeBetween` takes, a\n * negative one moving it toward `before`. Where either end reaches its least.\n */\n readonly range: { readonly min: number; readonly max: number };\n}\n\ninterface Grower {\n readonly id: string;\n /** Whether it may be an end of a divider: not `fixed` and not a `wrap` form. */\n readonly end: boolean;\n /** The least it takes as the length was shared. */\n readonly least: number;\n /** What its form asks for by itself, the least at most. */\n readonly natural: number;\n /** How long it is drawn. */\n readonly drawn: number;\n /** Its place in `fit.items`. */\n readonly at: number;\n}\n\nconst mainOf = (r: Rect, axis: StackAxis): number => (axis === \"column\" ? r.height : r.width);\nconst startOf = (r: Rect, axis: StackAxis): number => (axis === \"column\" ? r.y : r.x);\n\n/** The items drawn in a form that grows, in the stack's order. */\nfunction growers(input: StackInput, fit: StackFit): Grower[] {\n const byId = new Map(input.items.map((it) => [it.id, it]));\n const known = sizesOf(fit);\n const out: Grower[] = [];\n fit.items.forEach((p, at) => {\n const item = byId.get(p.id);\n const f = item?.forms[p.form];\n if (!item || !f || formMenu(f) || f.main.grows !== true) return;\n const least = known?.least.get(p.id) ?? formMain(f, \"min\", fit.cross);\n out.push({ id: p.id, end: item.fixed !== true && !f.wrap, least, natural: Math.max(least, formMain(f, \"natural\", fit.cross)), drawn: mainOf(p.rect, fit.axis), at });\n });\n return out;\n}\n\n/** The two items of a divider, when `before` and `after` are neighboring growing items, both ends, in that order. */\nfunction pair(all: readonly Grower[], before: string, after: string): [Grower, Grower] | null {\n const i = all.findIndex((g) => g.id === before);\n const next = all[i + 1];\n return i >= 0 && next !== undefined && next.id === after && all[i]!.end && next.end ? [all[i]!, next] : null;\n}\n\n/**\n * `input` with the length of each item of the pair written so the stack is laid out as drawn (the pair given moved to\n * `to`) and nothing but the pair moves. A length is an ask, not a drawn size: with spare length a growing form is drawn\n * `scale` times its ask, so the ask written is the drawn size over `scale`; short of length the items are drawn part of\n * the way from their least to their ask (`tight`), so it is `least + (drawn - least) / tight`. An ask is a weight and the\n * least a floor on the drawn size, so with spare length an end drawn at its least asks for `least / scale`, under its\n * least, and is still drawn at its least. The pair's drawn sizes add up to what they did and every other item draws as it\n * did, so the scale is the same and no other item needs a length: a bystander keeps whatever it had, which is none when\n * nobody sized it, and travels to another stack as the item it is. Items already at their length stay the same objects.\n */\nfunction written(input: StackInput, fit: StackFit, all: readonly Grower[], to: ReadonlyMap<string, number>): StackInput {\n const known = sizesOf(fit);\n const tight = known?.tight;\n const share = tight !== undefined && tight > EPS && tight < 1 ? tight : 1;\n const scale = known?.scale ?? 1;\n const byId = new Map(all.map((g) => [g.id, g]));\n const ask = (g: Grower, drawn: number): number => (scale > 1 + EPS ? drawn / scale : g.least + (drawn - g.least) / share);\n let changed = false;\n const items = input.items.map((it) => {\n const drawn = to.get(it.id);\n if (drawn === undefined) return it;\n // A length of 0 is no length (the item would read its natural), so an end whose least is 0 asks a hair over it.\n const length = Math.max(ask(byId.get(it.id)!, drawn), 2 * EPS);\n const was = it.lengths?.[input.axis];\n if (was !== undefined && was > EPS && Math.abs(was - length) <= EPS) return it;\n changed = true;\n return { ...it, lengths: { ...it.lengths, [input.axis]: length } };\n });\n return changed ? { ...input, items } : input;\n}\n\n/**\n * The two items of the divider between `before` and `after` redrawn: `to(b, a)` is the length `before` is to be drawn at\n * (`after` takes the rest of their combined length). The same object when they aren't neighbors or `before` stays, and\n * while the stack is squeezed (`overflow`): no length is free to trade, and an ask written then would change the shares\n * once the stack grows. (A divider of a squeezed stack has no range either: every drawn item starts at its least and\n * only loses length from there, so `drawn - least` is never above 0.)\n */\nfunction trade(input: StackInput, before: string, after: string, options: FitOptions, to: (b: Grower, a: Grower) => number): StackInput {\n const fit = fitStack(input, options);\n if (fit.notes.some((n) => n.code === \"overflow\")) return input;\n const all = growers(input, fit);\n const ends = pair(all, before, after);\n if (!ends) return input;\n const [b, a] = ends;\n const first = to(b, a);\n if (Math.abs(first - b.drawn) <= EPS) return input;\n return written(\n input,\n fit,\n all,\n new Map([\n [b.id, first],\n [a.id, b.drawn + a.drawn - first],\n ]),\n );\n}\n\n/**\n * The dividers of a stack laid out as `fit`, one per pair of neighboring growing items that are both ends, in the stack's\n * order. A collapsed item has none of its own; where collapsed items sit between two open ones there is one divider\n * between the open ones, on the far edge of the last collapsed one. A growing item that isn't an end (a fixed one, a\n * `wrap` form) has none and ends the chain.\n */\nexport function dividers(input: StackInput, fit: StackFit): StackDivider[] {\n const all = growers(input, fit);\n const out: StackDivider[] = [];\n for (let k = 0; k + 1 < all.length; k++) {\n const b = all[k]!;\n const a = all[k + 1]!;\n if (!b.end || !a.end) continue;\n // The last item drawn before `after`: the divider sits on its far edge.\n let prev = a.at - 1;\n while (prev > b.at && fit.menu?.items.includes(fit.items[prev]!.id)) prev--;\n const last = fit.items[prev]!.rect;\n const from = startOf(last, fit.axis) + mainOf(last, fit.axis);\n const thick = Math.max(0, startOf(fit.items[a.at]!.rect, fit.axis) - from);\n const across = fit.items[b.at]!.rect;\n const rect: Rect = fit.axis === \"column\" ? { x: across.x, y: from, width: across.width, height: thick } : { x: from, y: across.y, width: thick, height: across.height };\n out.push({ before: b.id, after: a.id, rect, range: { min: 0 - Math.max(0, b.drawn - b.least), max: Math.max(0, a.drawn - a.least) } });\n }\n return out;\n}\n\n/**\n * Move the divider between the open growing items `before` and `after` by `delta` px along the stack: `before` gets\n * longer by `delta` and `after` shorter (a negative `delta` the other way), so the stack's total is the same and only the\n * two move. It writes the length of the two only, in ask units (see `written`), so nothing else shifts and the others\n * stay as they were, sized or not. Neither goes\n * under its least: `delta` is clamped to the divider's `range`, no item collapses and none is pushed. Returns the same\n * object when nothing changes (not neighbors, an unknown id, a `delta` that isn't a number, or one clamped to 0).\n * `options.previous` is the fit the stack had, as for `fitStack`.\n */\nexport function resizeBetween(input: StackInput, before: string, after: string, delta: number, options: FitOptions = {}): StackInput {\n if (!Number.isFinite(delta)) return input;\n return trade(input, before, after, options, (b, a) => b.drawn + Math.min(Math.max(delta, 0 - Math.max(0, b.drawn - b.least)), Math.max(0, a.drawn - a.least)));\n}\n\n/**\n * Give the two items of a divider back the split they would be drawn at if both asked for their natural, their combined\n * drawn length kept and nothing else moving: in proportion to their naturals (their forms' `main.natural`, the least at\n * most) with room for both, and `least + (natural - least) * s` with one shared `s` when short, as `fitStack` shares a\n * short length. The double-click action. Returns the same object when the two are at that split already (a pair nobody\n * resized always is, in every regime), or are not neighbors. Like a drag it writes the lengths of the two only.\n */\nexport function resetBetween(input: StackInput, before: string, after: string, options: FitOptions = {}): StackInput {\n return trade(input, before, after, options, (b, a) => {\n const both = b.drawn + a.drawn;\n const natural = b.natural + a.natural;\n const least = b.least + a.least;\n let want: number;\n if (both >= natural - EPS) want = natural > EPS ? (both * b.natural) / natural : both / 2;\n else want = b.least + (b.natural - b.least) * (natural - least > EPS ? (both - least) / (natural - least) : 0);\n return Math.min(Math.max(want, b.least), Math.max(b.least, both - a.least));\n });\n}\n\n/**\n * `input` with every asked length of the stack's axis deleted, back to the split a stack with none has. An item's length\n * for the other axis stays. Returns the same object when no item had one.\n */\nexport function resetLengths(input: StackInput): StackInput {\n let changed = false;\n const items = input.items.map((it) => {\n if (it.lengths?.[input.axis] === undefined) return it;\n changed = true;\n const { [input.axis]: _dropped, ...rest } = it.lengths;\n const { lengths: _lengths, ...bare } = it;\n return Object.keys(rest).length > 0 ? { ...bare, lengths: rest } : bare;\n });\n return changed ? { ...input, items } : input;\n}\n","/**\n * `stackGaps(input, item)`: one edge's drop places for `item`, fit only. Every gap of the stack without the item (an\n * item of the input with its id is lifted out first, so a reorder within the stack works) is one entry, in order: before\n * each item and after the last, so an empty stack has one. A gap where the item fits beside the others gives the stack\n * after the drop (`input`) and its fit (`fit`), with the item's rect there (`slot`): the drop is that same solve. A gap\n * where it doesn't fit is a refusal with its reason.\n *\n * The item counts as just used: it is newer than every item in the stack, so the others give way before it. It fits a\n * gap when the drop's fit doesn't put it in the » menu, has no `overflow`, makes no item `too-wide` that wasn't before,\n * and squeezes no `fixed` item (it keeps its form, is drawn at least its form's `main.min` along the stack and at least\n * as wide across as before). A fixed item may shrink down to its `main.min` to make room; one with `stepping` may also\n * step to a later form, as a movable item may.\n *\n * Reasons: `no-forms` (the item has none), `fixed` (a fixed item is never dropped), `not-accepted` (`input.accepts`\n * refuses it), `not-allowed` (`options.allows` refuses the gap), `to-menu`, `overflow`, `too-wide` and `squeezes-fixed`.\n * The first three refuse every gap. Pure: no hit zones, no time; where the pointer is is the host's.\n *\n * See docs/placement.md, Entry: stack.\n */\nimport type { Rect } from \"../geometry\";\nimport { fitStack } from \"./layout\";\nimport { formMain, itemSteps, withItem, type FitOptions, type PlacedStackItem, type StackFit, type StackInput, type StackItem } from \"./model\";\n\n/** Why a gap doesn't take the item. */\nexport type StackGapRefusal = \"no-forms\" | \"fixed\" | \"not-accepted\" | \"not-allowed\" | \"to-menu\" | \"overflow\" | \"too-wide\" | \"squeezes-fixed\";\n\n/** One gap: before the `at`-th item of the stack without the dragged one (`at` = their count: after the last). */\nexport type StackGap =\n | {\n readonly at: number;\n readonly fits: true;\n /** The stack with the item inserted at `at`: what the drop makes. */\n readonly input: StackInput;\n /** Its fit: the layout after the drop. */\n readonly fit: StackFit;\n /** The item's rect in `fit` (stack-local px). */\n readonly slot: Rect;\n }\n | { readonly at: number; readonly fits: false; readonly reason: StackGapRefusal };\n\nexport interface StackGapOptions {\n /** The stack's fit before the drag, as `fitStack`'s `previous`: each gap's fit keeps the others' forms while they still fit. */\n readonly previous?: StackFit;\n /** Whether a gap takes the item (default: every gap does), asked with the item and the gap's `at`. */\n readonly allows?: (item: StackItem, at: number) => boolean;\n}\n\n/** Why a drop's fit leaves no room for the item, or null when it fits beside the others. */\nfunction refusalOf(base: StackFit, fit: StackFit, dragged: PlacedStackItem, fixed: ReadonlyMap<string, StackItem>, axis: StackInput[\"axis\"], tooWideBefore: ReadonlySet<string>): StackGapRefusal | null {\n const inMenu = new Set(fit.menu?.items ?? []);\n const wasInMenu = new Set(base.menu?.items ?? []);\n if (inMenu.has(dragged.id)) return \"to-menu\";\n for (const n of fit.notes) {\n if (n.code === \"overflow\") return \"overflow\";\n if (n.code === \"too-wide\" && !tooWideBefore.has(n.id)) return \"too-wide\";\n }\n const main = (r: Rect): number => (axis === \"column\" ? r.height : r.width);\n const across = (r: Rect): number => (axis === \"column\" ? r.width : r.height);\n const was = new Map(base.items.map((p) => [p.id, p]));\n for (const p of fit.items) {\n const item = fixed.get(p.id);\n const q = was.get(p.id);\n if (!item || !q || inMenu.has(p.id) || wasInMenu.has(q.id)) continue;\n // A fixed item that takes steps (`stepping`) may step for a drop, as a movable item may; in the form it takes it is\n // still never squeezed.\n if (p.form !== q.form && !itemSteps(item)) return \"squeezes-fixed\";\n if (main(p.rect) < formMain(item.forms[p.form]!, \"min\", fit.cross) - 1e-6) return \"squeezes-fixed\";\n if (p.form === q.form && across(p.rect) < across(q.rect) - 1e-6) return \"squeezes-fixed\";\n }\n return null;\n}\n\nexport function stackGaps(input: StackInput, item: StackItem, options: StackGapOptions = {}): StackGap[] {\n const rest: StackInput = { ...input, items: input.items.filter((it) => it.id !== item.id) };\n const ats = Array.from({ length: rest.items.length + 1 }, (_, k) => k);\n const whole: StackGapRefusal | null = item.forms.length === 0 ? \"no-forms\" : item.fixed ? \"fixed\" : input.accepts && !input.accepts(item) ? \"not-accepted\" : null;\n if (whole) return ats.map((at) => ({ at, fits: false, reason: whole }));\n const fitOptions: FitOptions = options.previous ? { previous: options.previous } : {};\n const base = fitStack(rest, fitOptions);\n const fixed = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));\n const tooWideBefore = new Set(base.notes.flatMap((n) => (n.code === \"too-wide\" ? [n.id] : [])));\n const newest = rest.items.reduce((m, it) => Math.max(m, it.used), item.used) + 1;\n const held: StackItem = { ...item, used: newest };\n return ats.map((at): StackGap => {\n if (options.allows && !options.allows(item, at)) return { at, fits: false, reason: \"not-allowed\" };\n const solved = withItem(rest, held, at);\n const fit = fitStack(solved, fitOptions);\n const placed = fit.items.find((p) => p.id === item.id)!;\n const reason = refusalOf(base, fit, placed, fixed, rest.axis, tooWideBefore);\n return reason ? { at, fits: false, reason } : { at, fits: true, input: solved, fit, slot: placed.rect };\n });\n}\n","/**\n * `fitFloat(rect, stage, avoid)`: the rect a float gets. It is moved (never resized) to lie inside the stage, then beside\n * whatever docked content it would cover: the nearest place inside the stage that is clear of every `avoid` rect (the\n * docked items' rects, in the same px). One larger than the stage keeps its top-left corner on the stage's; if no clear\n * place exists the float stays where it covers the least and `covers` says which rects.\n *\n * A clear place is found whenever one exists: the x's are tried nearest first and, for each, the blocked stretches of y\n * are merged and skipped, so no clear place is missed however many places lie between. Cost (measured in a test run on\n * a laptop): about 100 docked rects 0.1 ms, 300 a few ms even when no place is clear (6 ms median, 15 ms worst), 1,000\n * about 17 ms; a safety net stops the clear search after 3 million rect tests and says so in `searchCapped`; a stage\n * with no clear place looks at the 2,048 nearest places for the least covered.\n *\n * With `{ stay: true }` it is only moved inside the stage: it lies where it is asked, and `covers` says which `avoid`\n * rects it covers there (a float a person left over content on purpose).\n *\n * A window model fits its floats with it.\n */\nimport { clampInto, overlap, overlaps, rect, type Rect } from \"../geometry\";\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\nexport interface FloatFitOptions {\n /**\n * Only moved inside the stage, never beside what it covers: `rect` is the asked rect clamped into the stage, `snapped`\n * is false and `covers` lists every `avoid` rect it covers there. Default false.\n */\n readonly stay?: boolean;\n}\n\n/** How far floats compare loosely: a float's px are rounded, so a thousandth is touching. */\nconst EPS = 1e-3;\nconst finite = (x: number, fallback: number): number => (Number.isFinite(x) ? x : fallback);\n\n/** `r` with a non-number replaced and no negative size. */\nconst clean = (r: Rect, at: Rect): Rect => rect(finite(r.x, at.x), finite(r.y, at.y), Math.max(0, finite(r.width, 0)), Math.max(0, finite(r.height, 0)));\n\n/** A safety net on the clear search, in rect tests (only thousands of rects reach it), and the places the least-covered search looks at. */\nconst WORK = 3_000_000;\nconst COVERED_PLACES = 2048;\n\ntype Triple = [number, number, number];\n\n/** A binary min-heap of `[index, index, distance]` triples, by distance then indexes (a fixed order). */\nclass Nearest {\n private readonly h: Triple[] = [];\n private less(a: Triple, b: Triple): boolean {\n return a[2] !== b[2] ? a[2] < b[2] : a[0] !== b[0] ? a[0] < b[0] : a[1] < b[1];\n }\n get size(): number {\n return this.h.length;\n }\n push(t: Triple): void {\n const h = this.h;\n let i = h.push(t) - 1;\n while (i > 0) {\n const p = (i - 1) >> 1;\n if (!this.less(h[i]!, h[p]!)) break;\n [h[i], h[p]] = [h[p]!, h[i]!];\n i = p;\n }\n }\n pop(): Triple {\n const h = this.h;\n const top = h[0]!;\n const last = h.pop()!;\n if (h.length > 0) {\n h[0] = last;\n let i = 0;\n for (;;) {\n const l = 2 * i + 1;\n const r = l + 1;\n let m = i;\n if (l < h.length && this.less(h[l]!, h[m]!)) m = l;\n if (r < h.length && this.less(h[r]!, h[m]!)) m = r;\n if (m === i) break;\n [h[i], h[m]] = [h[m]!, h[i]!];\n i = m;\n }\n }\n return top;\n }\n}\n\n/** The places `xs` crossed with `ys`, nearest to `(fx, fy)` first (Euclidean), without building the cross product. */\nfunction* byDistance(xs: readonly number[], ys: readonly number[], fx: number, fy: number): Generator<{ x: number; y: number; far: number }> {\n const sx = [...xs].sort((a, b) => Math.abs(a - fx) - Math.abs(b - fx) || a - b);\n const sy = [...ys].sort((a, b) => Math.abs(a - fy) - Math.abs(b - fy) || a - b);\n const q = new Nearest();\n const d = (i: number, j: number): number => Math.hypot(sx[i]! - fx, sy[j]! - fy);\n // Each x starts at its nearest y; popping a place pushes the same x's next y.\n if (sy.length > 0) for (let i = 0; i < sx.length; i++) q.push([i, 0, d(i, 0)]);\n while (q.size > 0) {\n const [i, j, far] = q.pop();\n yield { x: sx[i]!, y: sy[j]!, far };\n if (j + 1 < sy.length) q.push([i, j + 1, d(i, j + 1)]);\n }\n}\n\nexport function fitFloat(want: Rect, stage: Rect, avoid: readonly Rect[] = [], options: FloatFitOptions = {}): FloatFit {\n const area = clean(stage, rect(0, 0, 0, 0));\n const r = clean(want, area);\n const inside = clampInto(r, area);\n // Compared with what was asked, so a position that wasn't a number (and was replaced) counts as moved.\n const clamped = inside.x !== want.x || inside.y !== want.y;\n // Only rects that can touch the float wherever the stage lets it be: its reach.\n const reach = rect(area.x, area.y, Math.max(area.width, r.width), Math.max(area.height, r.height));\n const near: { at: Rect; index: number }[] = [];\n avoid.forEach((a, index) => {\n const at = clean(a, area);\n if (at.width > EPS && at.height > EPS && overlaps(at, reach, EPS)) near.push({ at, index });\n });\n const under = (cand: Rect): number[] => near.filter((n) => overlaps(cand, n.at, EPS)).map((n) => n.index);\n const blocked = (cand: Rect): boolean => near.some((n) => overlaps(cand, n.at, EPS));\n if (options.stay) return { rect: inside, clamped, snapped: false, covers: under(inside), searchCapped: false };\n if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };\n\n // The places to look at: every x that puts the float against an edge of the stage or of a rect (or where it is),\n // crossed with every y that does; a clear place exists if one does at all, as a float slid against edges.\n const lo = (v: number, from: number, to: number): number => Math.min(Math.max(v, from), Math.max(from, to));\n const xs = [inside.x, area.x, area.x + area.width - r.width];\n const ys = [inside.y, area.y, area.y + area.height - r.height];\n for (const { at } of near) {\n xs.push(at.x - r.width, at.x + at.width);\n ys.push(at.y - r.height, at.y + at.height);\n }\n const places = (list: number[], from: number, size: number, extent: number): number[] => [...new Set(list.map((v) => lo(v, from, from + extent - size)))];\n const px = places(xs, area.x, r.width, area.width);\n const py = places(ys, area.y, r.height, area.height);\n // Nearest clear place: the x's nearest first; for each, the rects that overlap that x block open stretches of y, and\n // the nearest clear y is the wanted one if it is clear, else the end of the stretch it is in (the stretches are\n // merged, so a whole blocked run is skipped at once). A later x can't beat a clear place at least as far as its x\n // alone, so the search stops there. `WORK` bounds the rect tests as a safety net.\n const ylo = area.y;\n const yhi = Math.max(area.y, area.y + area.height - r.height);\n const byX = [...px].sort((a, b) => Math.abs(a - inside.x) - Math.abs(b - inside.x) || a - b);\n let clear: { x: number; y: number; far: number } | null = null;\n let work = 0;\n let searchCapped = false;\n for (const x of byX) {\n const dx = Math.abs(x - inside.x);\n if (clear && dx >= clear.far) break;\n work += near.length + 1;\n if (work > WORK) {\n searchCapped = true;\n break;\n }\n const stretches: [number, number][] = [];\n for (const { at } of near) {\n if (Math.min(x + r.width, at.x + at.width) - Math.max(x, at.x) > EPS) stretches.push([at.y - r.height, at.y + at.height]);\n }\n stretches.sort((a, b) => a[0] - b[0]);\n // The clear y's are the closed gaps between the merged open stretches, within the stage.\n let cursor = ylo;\n let bestY: number | null = null;\n const gap = (from: number, to: number): void => {\n if (from > to) return;\n const y = Math.min(Math.max(inside.y, from), to);\n if (bestY === null || Math.abs(y - inside.y) < Math.abs(bestY - inside.y)) bestY = y;\n };\n for (const [a, b] of stretches) {\n gap(cursor, Math.min(a, yhi));\n cursor = Math.max(cursor, b);\n if (cursor > yhi) break;\n }\n if (cursor <= yhi) gap(cursor, yhi);\n if (bestY === null) continue;\n const far = Math.hypot(dx, bestY - inside.y);\n if (!clear || far < clear.far) clear = { x, y: bestY, far };\n }\n if (clear) return { rect: rect(clear.x, clear.y, r.width, r.height), clamped, snapped: clear.far > EPS, covers: [], searchCapped };\n // None is clear: the nearest places that cover the least.\n let best: { rect: Rect; left: number; far: number; hits: number[] } | null = null;\n let tried = 0;\n for (const p of byDistance(px, py, inside.x, inside.y)) {\n if (tried++ >= COVERED_PLACES) break;\n const cand = rect(p.x, p.y, r.width, r.height);\n const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);\n if (!best || left < best.left - EPS) best = { rect: cand, left, far: p.far, hits: under(cand) };\n }\n const out = best ?? { rect: inside, far: 0, hits: under(inside) };\n return { rect: out.rect, clamped, snapped: out.far > EPS, covers: out.hits, searchCapped };\n}\n"],"mappings":";;;;;;;;;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onNeg","mainOf","rect","EPS","finite","px"]}
|
|
1
|
+
{"version":3,"sources":["../src/stack/cut.ts","../src/stack/model.ts","../src/stack/layout.ts","../src/stack/ladder.ts","../src/stack/divide.ts","../src/stack/gaps.ts","../src/stack/float-fit.ts"],"sourcesContent":["/**\n * `cutEdges(stage, bands)`: the stage cut into bands along its sides, in list order. Each band takes its `size` across\n * at its side of what the bands before it left, so the order decides the corners: a top band cut before a left one runs\n * across the whole width and the left one starts below it; cut after it, the left one runs the whole height. Pure: no\n * edges, items or forms, only rects.\n *\n * - A `reserve` band (the default) shortens the leftover: what follows is cut from what it leaves.\n * - An `over` band lies over the leftover without shortening it. The `over` bands are cut after every reserved band,\n * whatever the list order, from the final leftover less the `over` bands before them, so each lies inside the\n * leftover, two on one side lie side by side, and the leftover stays whole.\n * - A band is never thicker than the room left across it (a negative or missing size is 0). `gap` is space after it,\n * taken only when the band takes some room, and never more than the room left. A stage of negative size is cut as\n * one of size 0.\n *\n * Returns each band's rect by id and the leftover rect (`rest`). Band ids are unique: a repeat throws.\n *\n * See docs/placement.md, Entry: stack.\n */\nimport { rect, type Rect } from \"../geometry\";\nimport type { Side } from \"../side\";\n\n/** One band of the cut. */\nexport interface EdgeBand {\n readonly id: string;\n readonly side: Side;\n /** Its size across (a top band's height, a left band's width), px. */\n readonly size: number;\n /** Space after it before the next band on that side, px (default 0); taken only when the band takes some room. */\n readonly gap?: number;\n /** `\"reserve\"` (default) shortens the leftover; `\"over\"` lies over it. */\n readonly mode?: \"reserve\" | \"over\";\n}\n\n/** The cut: each band's rect by id, and what is left. */\nexport interface EdgeCut {\n readonly bands: Readonly<Record<string, Rect>>;\n readonly rest: Rect;\n}\n\nconst px = (x: number | undefined): number => (typeof x === \"number\" && Number.isFinite(x) ? Math.max(0, x) : 0);\n\n/** `band` laid at its side of `area`: its rect, and `area` less it (and its gap). */\nfunction cutBand(area: Rect, band: EdgeBand): { readonly rect: Rect; readonly rest: Rect } {\n const across = band.side === \"top\" || band.side === \"bottom\" ? area.height : area.width;\n const room = Math.max(0, across);\n const thick = Math.min(px(band.size), room);\n const gap = thick > 0 ? Math.min(px(band.gap), room - thick) : 0;\n const take = thick + gap;\n switch (band.side) {\n case \"top\":\n return { rect: rect(area.x, area.y, area.width, thick), rest: rect(area.x, area.y + take, area.width, area.height - take) };\n case \"bottom\":\n return { rect: rect(area.x, area.y + area.height - thick, area.width, thick), rest: rect(area.x, area.y, area.width, area.height - take) };\n case \"left\":\n return { rect: rect(area.x, area.y, thick, area.height), rest: rect(area.x + take, area.y, area.width - take, area.height) };\n case \"right\":\n return { rect: rect(area.x + area.width - thick, area.y, thick, area.height), rest: rect(area.x, area.y, area.width - take, area.height) };\n }\n}\n\nexport function cutEdges(stage: Rect, bands: readonly EdgeBand[]): EdgeCut {\n const seen = new Set<string>();\n for (const b of bands) {\n if (seen.has(b.id)) throw new Error(`cutEdges: band id \"${b.id}\" is given twice`);\n seen.add(b.id);\n }\n const out: Record<string, Rect> = {};\n // A stage of negative size is cut as one of size 0, so every rect has a size of 0 or more.\n let rest = rect(stage.x, stage.y, px(stage.width), px(stage.height));\n for (const b of bands) {\n if (b.mode === \"over\") continue;\n const c = cutBand(rest, b);\n out[b.id] = c.rect;\n rest = c.rest;\n }\n // The over bands come after every reserved one, whatever the list order: each lies inside the final leftover.\n let over = rest;\n for (const b of bands) {\n if (b.mode !== \"over\") continue;\n const c = cutBand(over, b);\n out[b.id] = c.rect;\n over = c.rest;\n }\n return { bands: out, rest };\n}\n","/**\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 * A form's kind is the host's label, the name it draws by. What a solver reads is said by fields: `setsCross` (it sets\n * the stack's cross size), `body` (it shows its body: what `open` stands for), `folded` (it shows only its bar: what\n * `header` and `fold` stand for), `compact` (icons only: what `icons` stands for), `menu` (no room of its own: the »\n * entry stands for it), `ownCross` (drawn at its own size across under the stack's `ownCross`: what the group kinds\n * `row`, `stacked`, `wrap`, `icons`, `fold` stand for), `stepGroup` (the variants the title rule steps first: default the\n * kind), `title`, `wrap` and `hides`. Each flag defaults from the kind, so forms that leave them out read as before; the\n * solver reads no kind but through them (a kept fit's form at the same index is matched by its kind, a label compared,\n * never read). Panel and group kinds may be mixed on one item.\n */\nimport { EPS, 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/**\n * Along the stack: `min` is the least it is drawn while the stack fits (a stack that doesn't, the `overflow` note, draws\n * its items squeezed, under it: see `fitStack`), `natural` what it asks for; `grows` takes spare length.\n */\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 * It shows its body: an open panel. Default: true for the kind `open`. It sets the cross size unless `setsCross` says\n * otherwise, and a window model reads it as the item being open.\n */\n readonly body?: boolean;\n /**\n * It shows only its bar: a panel folded to its header, a group folded to its grip and ». Default: true for the kinds\n * `header` and `fold`. A window model reads it as folded: a hand fold takes the first such form, and a float in it\n * keeps its bar's height.\n */\n readonly folded?: boolean;\n /** Icons only. Default: true for the kind `icons`. A window model's compact (icons-only) edge takes it. */\n readonly compact?: boolean;\n /**\n * Give-way order within the form's `level` (default 0): any finite number, negative included; anything else reads 0\n * (`formRank`). When the stack is too long, the step taken is the one into the next form of the lowest level, then of\n * the lowest rank, across all items (the form the item would take, not the one it leaves); ties go unkept before kept,\n * then the item used longest ago, then the later in the stack. Adding one number to every rank of a stack changes\n * nothing.\n */\n readonly rank?: number;\n /**\n * The form's level (default 0): a whole number, 0 or more; anything else reads 0 (`formLevel`). A level comes before\n * the rank in the order: every step into a form of a lower level is taken before any step into a form of a higher\n * level, whatever their ranks. It is a pin: `controlLadder` sets it from `keep` on a pinned group's partial folds, fold\n * and menu, so every group of a lower level gives way entirely before the pinned one folds a control. Room coming back\n * reads the same order backwards.\n */\n readonly level?: 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). A window model (`@n-uf/docking`)\n * reports its rect; a `wrap` form's grip is its lead cell instead.\n */\n readonly grip?: number;\n /**\n * The control ids this form leaves out, against the item's first form: a compact variant of a toolbar (a row form\n * between the full row and its wrap, smaller, its \"+N\" cell counted in its size) hides some controls a \"+N\" control\n * reaches. Any form may set it (a wrap, icons or menu form too). The ladder reads it nowhere: a variant is a form like\n * any other, taken in order, giving way and coming back by the usual rules. `@n-uf/docking` reports the chosen form's ids\n * as `hidden`.\n */\n readonly hides?: readonly string[];\n /**\n * Each shown control's tier, by control id (0 the longest), set by `controlLadder` on every row form it generates (not\n * on `fold` and `menu`): a host draws each control at its tier from it, with no knowledge of the ladder's order. It is\n * always a valid index into the control's own `tiers` (a control with fewer tiers than the group stays on its last; a\n * control with no tiers reports 0). A\n * hand-written form leaves it out. `@n-uf/docking` reports the chosen form's as the item layout's `tiers`.\n */\n readonly tiers?: Readonly<Record<string, number>>;\n /**\n * A `rail` form that draws the item's title along the rail (its name and count, turned to run along it) instead of\n * its tile. Put it just before the item's tile `rail` form: in a rail the two are steps on the ladder, the title giving\n * way to the tile by the usual rules and coming back in exact reverse. Its `main` is the title's length along the rail,\n * measured by the host. A stack offers it only with `StackInput.titles`; otherwise it is passed over like a form that\n * isn't there (never started in, stepped into or grown back to). `@n-uf/docking` offers it in a rail whose side shows\n * titles (`DockState.railModes`, default `\"titles\"`) and reports the side it reads from (`DockItemLayout.railTitle`).\n */\n readonly title?: boolean;\n /**\n * It has no room of its own: the » entry stands for it while the item is in it. Default: true for the kind `menu`. A\n * stack's » menu holds exactly the items in such a form (`StackMenu.items`).\n */\n readonly menu?: boolean;\n /**\n * Under `StackInput.ownCross`, it is drawn at its own `cross.natural` (clamped to the stack's cross size; a `wrap` form\n * as wide as its rows need) from the start edge, instead of across the whole stack. Default: true for the group kinds\n * (`row`, `stacked`, `wrap`, `icons`, `fold`), false for the panel kinds and a menu form. Without `ownCross` it is\n * never read.\n */\n readonly ownCross?: boolean;\n /**\n * The step group it belongs to: forms of one item with the same key are variants of one form (a toolbar's full row and\n * its compact rows). The title rule reads it: while a growing item that takes no steps holds its natural length, only\n * steps within a step group are taken (`StackItem.fixed`). Default: the form's kind.\n */\n readonly stepGroup?: string;\n}\n\n/** Whether an item takes give-way steps: a movable one, or a fixed one with `stepping`. */\nexport const itemSteps = (item: { readonly fixed?: boolean; readonly stepping?: boolean }): boolean => item.fixed !== true || item.stepping === true;\n\n/** A form's rank as the solver reads it: `rank` when it is a finite number, else 0. */\nexport const formRank = (f: StackForm): number => (typeof f.rank === \"number\" && Number.isFinite(f.rank) ? f.rank : 0);\n/** A form's level as the solver reads it: `level` when it is a whole number, 0 or more, else 0. */\nexport const formLevel = (f: StackForm): number => (typeof f.level === \"number\" && Number.isInteger(f.level) && f.level > 0 ? f.level : 0);\n\n/** Whether a form has no room of its own, the » entry standing for it (`menu`, default: the kind `menu`). */\nexport const formMenu = (f: StackForm): boolean => f.menu ?? f.kind === \"menu\";\n/** Whether a form is drawn at its own size across under `ownCross` (`ownCross`, default: the group kinds). */\nexport const formOwnCross = (f: StackForm): boolean => f.ownCross ?? GROUP_KINDS.has(f.kind);\n/** A form's step group (`stepGroup`, default: its kind). */\nexport const formStepGroup = (f: StackForm): string => f.stepGroup ?? f.kind;\n/** The form kinds of a control group: the default of `ownCross`. */\nconst GROUP_KINDS: ReadonlySet<string> = new Set([\"row\", \"stacked\", \"wrap\", \"icons\", \"fold\"]);\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). A window model's size clamp and\n * column 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 (formMenu(f)) 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 neighboring 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\n/**\n * The length a person asked an item to have, px along a stack, per axis: a flex basis. `column` is read by a stack that\n * runs down, `row` by one that runs across, so an item that moves to a stack of the other axis never reads a length\n * meant for this one.\n */\nexport interface StackLengths {\n readonly column?: number;\n readonly row?: number;\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 and draws it squeezed,\n * under its least, before any item that takes steps: \"never gives way\" means it never leaves its form). It is never\n * dropped: `stackGaps` refuses every gap for it, and a drop beside it never squeezes it. Whether it may sit among others (or\n * first, or last) is the host's; placement lays out the items it is given. With `stepping` it keeps only the reserved\n * place and takes its steps like any item.\n */\n readonly fixed?: boolean;\n /**\n * A fixed item that still takes steps (default false; read only with `fixed`): it keeps its reserved place (never\n * dropped: `stackGaps` refuses every gap for it) but steps through its forms, into the » menu too, gives way by the\n * usual order and grows back in exact reverse: its fit is a movable item's with the same forms, `used` and `kept`. It\n * never holds for the title rule (that is a growing item that takes no steps); to have it shorten last, make it `kept`\n * or rank its forms. A drop beside it may step it, as it may a movable item, but never squeezes it under its form's\n * `main.min`.\n */\n readonly stepping?: boolean;\n /**\n * The length asked for along the stack (default none). While the item is in a form that grows (`main.grows`; a `wrap`\n * form that grows shares spare length too), the solver reads it, for the stack's axis, in place of that form's `main.natural`; the form's\n * `main.min` stays the least, a floor on the drawn size and not on the ask, and a value that isn't a finite number over\n * 0 is no asked length (a 0 asks nothing: the item reads its natural). There is no new formula: with spare length the sized items share it in proportion to their\n * lengths (one whose share would be under its least is drawn at its least, the others share the rest), short of length\n * they interpolate between their least (an ask under it reads as the least) and their length, so a stack too short for\n * all of them still trades room between them. A form that doesn't grow ignores it (the length is kept for when the item grows again), and so does a\n * stack of the other axis. A stack whose items declare none is laid out exactly as before. What gives way and in\n * which order never reads it. It is in ask units, not drawn px: with room to spare a drawn size is the ask times the\n * shared scale, or its least when that is more. `resizeBetween` and `resetBetween` write it for the pair only; `resetLengths` clears it.\n */\n readonly lengths?: StackLengths;\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 neighboring drawn items, px (default 0). The » entry is a neighbor 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). `stackGaps` refuses every gap for an item it doesn't accept, so\n * 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.\n */\n readonly ownCross?: boolean;\n /**\n * Offer the forms marked `title` (default false: they are passed over, so a stack without it lays out as if they\n * weren't declared). A rail showing titles sets it.\n */\n readonly titles?: 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 shows its body (`body`, default: the kind `open`). */\nexport const formBody = (f: StackForm): boolean => f.body ?? f.kind === \"open\";\n/** Whether a form shows only its bar (`folded`, default: the kinds `header` and `fold`). */\nexport const formFolded = (f: StackForm): boolean => f.folded ?? (f.kind === \"header\" || f.kind === \"fold\");\n/** Whether a form is icons only (`compact`, default: the kind `icons`). */\nexport const formCompact = (f: StackForm): boolean => f.compact ?? f.kind === \"icons\";\n\n/** Whether a form sets the stack's cross size: its own say, else whether it shows its body. */\nexport const formSetsCross = (f: StackForm): boolean => f.setsCross ?? formBody(f);\n\n/**\n * The length item `item` asks for along an `axis` stack while it is in `form`, or undefined: it asks for none, the\n * value isn't a finite number over 0 (a length of 0, or under `EPS`, is no length: the item reads its natural), or the\n * form doesn't grow (a form with no `main.grows`, the menu). A `wrap` form that grows reads it like any growing form: it\n * shares spare length, so its length is one a divider drag writes.\n */\nexport function askedLength(item: StackItem, form: StackForm, axis: StackAxis): number | undefined {\n const v = item.lengths?.[axis];\n if (v === undefined || !Number.isFinite(v) || v <= EPS) return undefined;\n return !formMenu(form) && form.main.grows === true ? v : undefined;\n}\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/**\n * An item drawn: the form it took, its kind and its rect (stack-local px), always inside the stack's length. One in the\n * menu has the menu entry's rect. In a fit with the `overflow` note the rect can be shorter than the form's `main.min`\n * (squeezed), down to 0, so a host clips or ellipsizes each item to its rect; a rect of no length has no hit area.\n */\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 /**\n * The » entry's rect, inside the stack: at its end, before the end padding (squeezed, it starts at\n * `length - pad.end - menu.main` while the padding is whole), and cut only when the length is under its size.\n */\n readonly rect: Rect;\n /** The items in it, in the stack's order: exactly the items in a menu form (`StackForm.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). The stack is then\n * drawn squeezed, inside its length, and `over` is what its items, then its gaps, padding and » entry gave up.\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 * Set on a stack with a growing fixed item (a title): `true` when the step was taken while it held its natural length,\n * `false` when it came after its shrink. Growing back undoes a step under the same hold, and a fit whose history still\n * holds a step taken after the shrink starts with the title shrunk. Without it (a history from an older version) the\n * step's level and kind stand in.\n */\n readonly held?: boolean;\n}\n\n/** What `fitStack` takes 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 `level`, then the lowest `rank`, is taken; ties\n * go unkept before kept, then the item used longest ago, then the later in the stack. A `menu` form takes no room;\n * the » entry does, while any item is in it. The first item into the menu opens the entry: when it is stuck (no\n * shorter form but the menu) and alone is shorter than the entry, the stuck items go in as one batch, in give-way\n * order, as few as together shorten the stack, never one whose menu form is of a higher level than another item's\n * open step; 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. A growing form whose item asks for a length (`StackItem.lengths`, for the stack's\n * axis) is read at that length in place of its natural size, nothing else changes. With room, an ask is a weight and the\n * least a floor on the drawn size: a form whose share would be under its least is drawn at its least, the others share the rest.\n * 6. Squeezed: when no item can give more way and the stack is still too long (the `overflow` note, `over` px), the\n * stack is still drawn inside its length. Every drawn item starts at its least, and `over` comes off in one order,\n * each rung down to 0 before the next: (1) the items that take no steps (`itemSteps` false) whose form grows share\n * it, in proportion to their least; (2) the other items that take no steps, one at a time; (3) the items that take\n * steps, those whose form grows sharing first, then the others one at a time; (4) the gaps, all alike; (5) the\n * padding, in proportion; (6) the » entry, cut to the length. \"One at a time\" is the give-way order of step 4, every\n * key of it, read at the form the item is in: the lowest `level`, then `rank`, first, unkept before kept, the item used longest ago,\n * and only then the later in the stack (read for fixed items too: alike in all three, they go from the end). Nothing\n * the user can act on goes out of reach while something else can still yield, and at most one rigid item is ever\n * partly cut. A 0-long item keeps its gap; the »\n * entry stays whole while the length allows it, at `length - pad.end - entry` while the padding is whole. A host\n * clips each item to its rect. A fit without `overflow` is never squeezed.\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. A fixed item with `stepping` takes every step\n * like an item that isn't fixed: the solver reads \"takes no steps\" (`itemSteps`), never `fixed` itself.\n *\n * With `ownCross`, an item in a form drawn at its own size (`StackForm.ownCross`; default the group kinds `row`, `stacked`,\n * `wrap`, `icons`, `fold`) is drawn at its own `cross.natural` (clamped to the stack's cross size) from the start edge\n * instead of across the whole stack; any other form (by default a panel's `open`, `header`, `rail`) still spans it.\n * Nothing else changes. The solver reads a form's kind through its flags only (`menu`, `ownCross`, `stepGroup`), each\n * defaulting from the kind; a kept fit's form is matched at its index by its kind, a label compared and never read.\n *\n * `gap` sits between neighboring drawn items (the » entry is one), `pad` before the first and after the last; both\n * count toward the length and the rects include them, so an app draws at the rects.\n *\n * The solver has no open or closed state: it lays out the items it is given, and a consumer closes a panel by not\n * passing it (or by starting it at a later form with `from`). An item with no forms is left out (`no-forms`). Pure:\n * same input, same fit.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport { askedLength, formCrossMin, formFitsCross, formLevel, formMain, formMenu, formOwnCross, formRank, formSetsCross, formStepGroup, itemSteps, limitsOf, menuMain, spacingOf, wrapCross, wrapRows, type FitOptions, type PlacedStackItem, type StackFit, type StackForm, type StackInput, type StackItem, type StackMenu, type StackNote, type StackStep } from \"./model\";\nconst isMenu = formMenu;\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\n/** Two forms in the give-way order by level, then rank: negative when a step into `fa` comes before one into `fb`. */\nconst formOrder = (fa: StackForm, fb: StackForm): number => formLevel(fa) - formLevel(fb) || formRank(fa) - formRank(fb);\n\n/**\n * The give-way order, the one comparator every order of the solver reads: negative when item `a` (at index `a`, in or\n * stepping into form `fa`) gives way before item `b`. The lower level first, then the lower rank (of the form that\n * counts: the one an item steps into while it gives way, the one it is in when it is squeezed or grows back), then\n * unkept before kept, then the item used longest ago, and only then the later in the stack. Every key is read for every\n * item, fixed ones too: an item with no `kept` is unkept, and items alike in level, rank, `kept` and `used` (fixed parts\n * a host gives one age) go from the end backward. Growing back reads it the other way round.\n */\nfunction givesWayBefore(items: readonly StackItem[], a: number, fa: StackForm, b: number, fb: StackForm): number {\n const order = formOrder(fa, fb);\n if (order !== 0) return order;\n const ka = items[a]!.kept ? 1 : 0;\n const kb = items[b]!.kept ? 1 : 0;\n if (ka !== kb) return ka - kb;\n const ua = items[a]!.used;\n const ub = items[b]!.used;\n // (as the step order always read it: an age that isn't a number never puts its item first)\n if (ua !== ub) return ua < ub ? -1 : 1;\n return b - a;\n}\n\n/**\n * The item that gives way next, among those with a step (`to[i]`, the form it would take, or -1): first in the give-way\n * order by the level and rank of the form it steps into.\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 || !itemSteps(items[i]!)) continue;\n if (best < 0 || givesWayBefore(items, i, items[i]!.forms[to[i]!]!, best, items[best]!.forms[to[best]!]!) < 0) 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 * level, 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 // A `title` form is offered only with `input.titles`; otherwise it is passed over like a form that isn't there.\n const offered = (f: StackForm): boolean => f.title !== true || input.titles === true;\n /** The first form at or after `j` that is offered (`j` itself when none is: an item keeps a form to draw). */\n const offeredFrom = (it: StackItem, j: number): number => {\n for (let k = j; k < it.forms.length; k++) if (offered(it.forms[k]!)) return k;\n return j;\n };\n const start = items.map((it) => offeredFrom(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 (!itemSteps(it) || !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 && offered(f)) 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 } : {}), ...(idx.some(holds) ? { held: hold } : {}) });\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` neighbors: 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 /**\n * A fixed item whose form grows (a title) holds its natural length while the other items can still take a step of a\n * lower level than its form's, or step to a form of the kind they are in (a toolbar's compact variants: row to a\n * smaller row) at its level: its shrink below natural is a give-way step of its form's level that ranks after every\n * such step and before every step of its level that changes a form's kind (icons, fold, the menu) and every step of a\n * higher level. `hold` is on while those steps come first.\n */\n const holds = (i: number): boolean => !itemSteps(items[i]!) && form(i).main.grows === true;\n let hold = idx.some(holds);\n /** The level of the title's shrink: the lowest level of a holding item's form (none: no level caps the hold). */\n const holdLevel = (): number => idx.reduce((m, i) => (holds(i) ? Math.min(m, formLevel(form(i))) : m), Infinity);\n /** The shortest the stack can be drawn now: the smallest sizes, the » entry, the gaps and the padding. */\n const minSumWith = (held: boolean): 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), held && holds(i) ? \"natural\" : \"min\", c), 0) + (inMenu() ? menuMain(input) : 0) + gapsOf() + sp.start + sp.end;\n };\n const minSum = (): number => minSumWith(hold);\n /** Whether stepping item `i` to form `j` keeps its form's step group (a compact variant of the form it is in). */\n const sameKind = (i: number, j: number): boolean => formStepGroup(items[i]!.forms[j]!) === formStepGroup(form(i));\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 if (!offered(items[i]!.forms[j]!)) continue;\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 /** The next offered form after item `i`'s current one, or -1. */\n const nextOffered = (i: number): number => {\n for (let j = at[i]! + 1; j < items[i]!.forms.length; j++) if (offered(items[i]!.forms[j]!)) return j;\n return -1;\n };\n const canStep = (i: number): boolean => nextOffered(i) >= 0;\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 // What the forms need at least, every growing fixed item at its minimum (the measure room coming back is read by).\n if (seed) seed.need = minSumWith(false);\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 level and rank, so the give-way order backwards: the highest level, then\n // the highest rank first, then `kept`,\n // the newest used, the earlier in the stack). An item goes back to the nearest earlier form the stack still fits\n // with, the cross size unchanged: a larger form is what counts, not a longer stack (the last item leaving the menu\n // takes the » entry with it).\n const comesBefore = (a: number, b: number): boolean => givesWayBefore(items, b, items[b]!.forms[at[b]!]!, a, items[a]!.forms[at[a]!]!) < 0;\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 // A step taken while the growing fixed items held their natural length (its `held`) comes back only when they still\n // do; a step taken after their shrink, with them at their least. A step from an older history (no levels then, and\n // no `held`) is read as that version did: a step to a form of the same kind (a compact variant) was held.\n const forms = (s: StackStep) => items[index.get(s.id)!]!.forms;\n const held = (s: StackStep): boolean => s.held ?? formStepGroup(forms(s)[s.from]!) === formStepGroup(forms(s)[s.to]!);\n hold = group.every(held) && idx.some(holds);\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 hold = false;\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) => itemSteps(items[i]!) && 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 if (!offered(items[next]!.forms[k]!)) continue;\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]! && formOrder(form(i), form(j)) >= 0))) 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 // The title holds unless the history it keeps has a step taken after its shrink: then it has shrunk already, and the\n // steps go on from there, as they did on the way down.\n hold = idx.some(holds) && !hist.some((s) => s.held === false);\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 (itemSteps(items[i]!) && tooWide(i, cross) && canStep(i) && !isMenu(items[i]!.forms[nextOffered(i)]!)) {\n step(i, nextOffered(i));\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), unless it is `stepping`.\n const to = idx.map((i) => (itemSteps(items[i]!) ? stepTo(i) : -1));\n if (hold) {\n // First the steps that keep a form's kind (compact variants) at the lowest open level, the title's shrink counted\n // at its own level, the growing fixed items at their natural length; with none left, they may shrink (`hold` off)\n // and the other steps follow. So a step of a higher level (a pinned group's) comes only after the title shrank.\n const low = idx.reduce((m, i) => (to[i]! >= 0 ? Math.min(m, formLevel(items[i]!.forms[to[i]!]!)) : m), holdLevel());\n const variant = victim(\n items,\n idx.map((i) => (to[i]! >= 0 && sameKind(i, to[i]!) && formLevel(items[i]!.forms[to[i]!]!) <= low ? to[i]! : -1)),\n );\n if (variant >= 0) {\n step(variant, to[variant]!);\n continue;\n }\n // A step of a lower level than the title's shrink comes before it whatever its kind, a batch into the » included:\n // it is taken below, the title still held. With none, the title may shrink.\n const top = holdLevel();\n const below = idx.map((i) => {\n const j = to[i]! < 0 && !inMenu() && itemSteps(items[i]!) ? menuFormAfter(i) : -1;\n return j >= 0 && formLevel(items[i]!.forms[j]!) < top ? j : -1;\n });\n if (low >= top && menuBatch(below) === null) {\n hold = false;\n continue;\n }\n }\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() && itemSteps(items[i]!) ? 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 // (a batch never takes a step into a level above an open step's: a stuck item of a higher level joins it only while\n // no other item has a step of a lower level left, the batch's own level first by the give-way order)\n const open = idx.reduce((m, i) => (to[i]! >= 0 && itemSteps(items[i]!) ? Math.min(m, formLevel(items[i]!.forms[to[i]!]!)) : m), Infinity);\n const batch = menuBatch(pool.map((j, i) => (j >= 0 && formLevel(items[i]!.forms[j]!) <= open ? j : -1)));\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 // While the growing fixed items still hold (the forms fit with them at their natural length), the others take the\n // shortage first: a held item's least is its natural length.\n const min = (i: number): number => mainOf(form(i), hold && holds(i) ? \"natural\" : \"min\", cross);\n // What a growing form asks for: its item's asked length (`StackItem.lengths`) when it has one, else the form's natural.\n const nat = (i: number): number => Math.max(min(i), askedLength(items[i]!, form(i), input.axis) ?? 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 // The share of the way from the least to the asked sizes the items are drawn at: 1 with room enough for all.\n let tight = 1;\n // How much longer than it asks a growing form is drawn with spare length: 1 + spare / weight.\n let scale = 1;\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 if (weight > EPS) scale = 1 + spare / weight;\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 // An ask is a weight, and the least a floor on the drawn size: a form asking for less than its least is drawn at its\n // least, and the others share what is left in proportion to their asks (the scale is the one that fills the length).\n const ask = (i: number): number => askedLength(items[i]!, form(i), input.axis) ?? nat(i);\n if (weight > EPS && growers.some((i) => ask(i) < min(i))) {\n const pinned = new Set<number>();\n const room = avail - drawn.reduce((s, i) => (growers.includes(i) ? s : s + nat(i)), 0);\n let s = scale;\n for (;;) {\n const free = growers.filter((i) => !pinned.has(i));\n const weights = free.reduce((sum, i) => sum + ask(i), 0);\n if (weights <= EPS) {\n for (const i of free) pinned.add(i);\n break;\n }\n s = (room - [...pinned].reduce((sum, i) => sum + min(i), 0)) / weights;\n const under = free.filter((i) => ask(i) * s < min(i));\n if (under.length === 0) break;\n for (const i of under) pinned.add(i);\n }\n if (pinned.size < growers.length) {\n scale = s;\n for (const i of growers) size.set(i, pinned.has(i) ? min(i) : ask(i) * s);\n }\n }\n } else {\n const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;\n tight = t;\n for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);\n }\n\n // Squeezed: a stack that still doesn't fit (`overflow`, every drawn item at its least) is drawn inside its length all the\n // same. What it lacks comes off in one order, each rung to 0 before the next (step 6 above).\n let gap = sp.gap;\n let padStart = sp.start;\n let padEnd = sp.end;\n let entry = menuSize;\n let short = overflow > EPS ? overflow : 0;\n if (short > 0) {\n // (Drawn under their least, the items are none of the way toward their asks: whichever branch shared the sizes.)\n tight = 0;\n /** Elastic parts share the loss, in proportion to their least (drawn at it now): an item at 0 has nothing to give. */\n const share = (group: readonly number[]): void => {\n const have = group.reduce((s, i) => s + size.get(i)!, 0);\n if (short <= 0 || have <= EPS) return;\n const take = Math.min(short, have);\n for (const i of group) size.set(i, size.get(i)! * (1 - take / have));\n short -= take;\n };\n /** Rigid parts take it one at a time, in the give-way order by the level and rank of the form each is in. */\n const oneByOne = (group: readonly number[]): void => {\n const order = [...group].sort((a, b) => givesWayBefore(items, a, form(a), b, form(b)));\n for (const i of order) {\n if (short <= 0) return;\n const take = Math.min(short, size.get(i)!);\n size.set(i, size.get(i)! - take);\n short -= take;\n }\n };\n const grows = (i: number): boolean => form(i).main.grows === true;\n // Nothing the user can act on goes out of reach while something else can yield: the items that take no steps (the\n // host's reserved room) first, then the items that take steps; the spacing after them, the » entry last.\n const reserved = drawn.filter((i) => !itemSteps(items[i]!));\n const movable = drawn.filter((i) => itemSteps(items[i]!));\n share(reserved.filter(grows));\n oneByOne(reserved.filter((i) => !grows(i)));\n share(movable.filter(grows));\n oneByOne(movable.filter((i) => !grows(i)));\n // The gaps between the drawn items and the » entry (one slot while any item is in the menu).\n const gaps = Math.max(0, drawn.length + (inMenu() ? 1 : 0) - 1);\n if (short > 0 && gaps > 0 && gap > 0) {\n const take = Math.min(short, gaps * gap);\n gap -= take / gaps;\n short -= take;\n }\n if (short > 0 && padStart + padEnd > 0) {\n const pads = padStart + padEnd;\n const take = Math.min(short, pads);\n padStart -= (take * padStart) / pads;\n padEnd -= (take * padEnd) / pads;\n short -= take;\n }\n if (short > 0 && inMenu()) entry = Math.max(0, entry - short);\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 form drawn at its own size (`StackForm.ownCross`,\n * default the group kinds `row`, `stacked`, `wrap`, `icons`, `fold`), its own `cross.natural` (clamped to the stack's),\n * from the start edge. That flag decides, not `setsCross`: a group's form that sets the cross size (a column of words)\n * widens the column but is drawn at its own width, and a panel's form (`open`, `header`, `rail`) and the » entry fill\n * the stack.\n */\n const acrossOf = (i: number): number => {\n const f = form(i);\n if (input.ownCross !== true || !formOwnCross(f)) 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 = padStart;\n for (const i of drawn) {\n const s = size.get(i)!;\n rects.set(i, rectAt(cursor, s, acrossOf(i)));\n cursor += s + gap;\n }\n // The » entry sits at the end of the stack, before the end padding. Squeezed, the items end exactly there; otherwise\n // they end at or before it (by float noise, after: so the cursor counts, and a fit that fits is as it always was).\n const menuRect = overflow > EPS ? rectAt(length - padEnd - entry, entry) : 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 const fit: StackFit = { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };\n sizes.set(fit, { tight, scale, least: new Map(drawn.map((i) => [items[i]!.id, min(i)])) });\n return fit;\n}\n\n/** What `solve` knew about the sizes of a fit and the fit doesn't say. */\nexport interface FitSizes {\n /** How far from the least to the asked sizes the items were drawn: 1 with room for all of them, less when short, 0 squeezed. */\n readonly tight: number;\n /** How much longer than it asks each growing form was drawn: 1 + spare / weight with spare length, else 1. */\n readonly scale: number;\n /**\n * The least each drawn item could take as the sizes were shared (a held growing fixed item's is its natural). A squeezed\n * item (the `overflow` note) is drawn under it.\n */\n readonly least: ReadonlyMap<string, number>;\n}\n/** The sizes of each fit `solve` made, kept off the fit itself so a fit is exactly what it was. */\nconst sizes = new WeakMap<StackFit, FitSizes>();\n/**\n * What `fitStack` knew about how it shared the length: `undefined` for a fit it didn't make. A divider drag reads it to\n * write lengths that reproduce the drawn sizes exactly.\n */\nexport const sizesOf = (fit: StackFit): FitSizes | undefined => sizes.get(fit);\n","/**\n * `controlLadder`: a control group's forms, generated from its controls.\n *\n * A host that hand-writes a group's forms gives a few coarse steps (a row, icons, a fold). A host that declares what the\n * group holds (its controls, each with its lengths per tier) gets the fine ladder instead, so a bar runs short control\n * by control and not group by group. Nothing here is a solver rule: the result is an ordinary `StackForm[]` with `rank`\n * and `hides` set, and `fitStack` takes it like any other (the lowest-ranked next form across all items, its tie-breaks,\n * the way back by `previous`).\n *\n * The ladder, in order, for `n` controls and `T` tiers (a tier is one length per control, longest first):\n * 1. The first form: every control at tier 0, a `row`.\n * 2. The tier steps, one control at a time in fold order: the control that folds first takes tier 1, then the next, then\n * the first takes tier 2, and so on to tier `T - 1` for all. Each is a `row` with every control shown. Step `i`\n * (0-based, within tier `t`) has rank `100 * t + i / n` for tiers 1 and 2, so groups of different sizes level within\n * a tier; tiers 3 and later share the band from 300 in tier order, rank `300 + (t - 3 + i / n) / (T - 3)`, so the\n * ranks strictly increase along the group and stay under 400 for any `T`.\n * 3. The partial folds, at the last tier: for `k = 1 … n - 1`, a `row` that hides the first `k` controls in fold order\n * (`hides` lists them) and shows a `more` cell for them. Rank `400 + k / n`: the group with the fewest hidden controls\n * folds next.\n * 4. `fold` (the grip and the `more` cell in line, `hides` every control), rank 500, then `menu`, rank 600.\n *\n * Every row form carries `tiers`, each shown control's tier index (`StackForm.tiers`; `fold` and `menu` have none), so a\n * host draws a control from the form the layout chose, with no knowledge of this order.\n *\n * Every form is always emitted, even when it is no shorter than the one before: the solver passes over a form that\n * doesn't shorten the stack, and the shape (`n * T + 2` forms, `0` with no controls) depends on the control and tier\n * counts alone, so a form index stays valid when a length changes. When the control set itself changes, solve the group\n * fresh (no `previous`).\n *\n * Ranks are spaced by step type in fixed bands whatever a group's tier count: tier steps in [100, 400), partial folds\n * 400 + k / n, fold 500, menu 600. So the same-tier steps of several groups interleave, and a partial fold never comes\n * before another group's tier step, even when the groups have different tier counts.\n *\n * A pin (`keep`) is a level, not a rank: the pinned group's partial folds, fold and menu carry `level: keep`, so they come\n * after every step of a lower level, and their ranks stay the same.\n */\nimport { formLevel, type StackForm } from \"./model\";\n\n/** One control of a group: an id and its length along the stack per tier. */\nexport interface LadderControl {\n readonly id: string;\n /**\n * Its lengths per tier, longest first, in the host's order of presentation (full, shorter, shortest). A tier the\n * control doesn't list keeps its last length; a control with none is 0 long. A group's tier count is its longest list.\n */\n readonly tiers: readonly number[];\n /**\n * Folds before the controls with a lower number (default: its index, so the last control folds first). Ties go to the\n * later control. The same order sets which control a tier step shortens first.\n */\n readonly foldOrder?: number;\n}\n\n/** A control group, declared by its controls. All lengths are along the stack, px. */\nexport interface ControlLadderSpec {\n /** In drawing order. */\n readonly controls: readonly LadderControl[];\n /** Between two neighboring controls (default 0). The grip and the `more` cell are the cells' own widths, with no gap. */\n readonly gap?: number;\n /** The grip cell at the group's start (default 0); every form but the menu carries it as `StackForm.grip`. */\n readonly grip?: number;\n /** The group's own » cell, drawn once any control is hidden. */\n readonly more: number;\n /** The group's thickness across the stack (a bar's height). */\n readonly cross: number;\n /**\n * The group's form in a column (a rail): an `icons` strip `icons` long, then the menu. `cross` is its width (default\n * the group's `cross`). Without it the group has no column forms.\n */\n readonly column?: { readonly icons: number; readonly cross?: number };\n /**\n * A pinned primary's level (default 0; a whole number, 0 or more, anything else reads 0, as `StackForm.level`): its\n * partial folds, fold and menu (and the column's menu) carry it as their `level`, so every group of a lower level gives\n * way entirely before it folds a control, and a growing title of a lower level shrinks first, whatever the ranks and\n * priorities. Tier steps and the first row stay at level 0 (they shorten its controls before a title shrinks), and the\n * ranks are the same at every level.\n */\n readonly keep?: number;\n}\n\n/** A group's forms along a bar (`row`) and, when declared, down a column; assignable to `@n-uf/docking`'s `DockItem.forms`. */\nexport interface ControlLadder {\n readonly row: readonly StackForm[];\n readonly column?: readonly StackForm[];\n}\n\nconst nonNeg = (x: number | undefined): number => (typeof x === \"number\" && Number.isFinite(x) ? Math.max(0, x) : 0);\nconst RANK_TIER = 100;\n\n/** `spec`'s forms: the row ladder, and the column ladder when `spec.column` is given. Pure. */\nexport function controlLadder(spec: ControlLadderSpec): ControlLadder {\n // The pin, read as a form's level is, and set only on the forms it lifts: a ladder with no pin carries no `level`.\n const level = formLevel({ kind: \"row\", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...(spec.keep !== undefined ? { level: spec.keep } : {}) });\n const pin: Pick<StackForm, \"level\"> = level > 0 ? { level } : {};\n const cross = nonNeg(spec.cross);\n const grip = nonNeg(spec.grip);\n const gap = nonNeg(spec.gap);\n const more = nonNeg(spec.more);\n const column: StackForm[] | undefined = spec.column\n ? [\n { kind: \"icons\", main: { min: nonNeg(spec.column.icons), natural: nonNeg(spec.column.icons) }, cross: { natural: nonNeg(spec.column.cross ?? spec.cross) }, ...(grip > 0 ? { grip } : {}) },\n { kind: \"menu\", main: { min: 0, natural: 0 }, cross: { natural: 0 }, ...pin },\n ]\n : undefined;\n\n const controls = spec.controls;\n const n = controls.length;\n if (n === 0) return { row: [], ...(column ? { column } : {}) };\n const tierCount = Math.max(1, ...controls.map((c) => c.tiers.length));\n const length = (c: LadderControl, tier: number): number => nonNeg(c.tiers[Math.min(tier, c.tiers.length - 1)]);\n /** The control indexes in fold order: the first folds (and is shortened) first. */\n const order = controls\n .map((c, index) => ({ index, key: typeof c.foldOrder === \"number\" && Number.isFinite(c.foldOrder) ? c.foldOrder : index }))\n .sort((a, b) => b.key - a.key || b.index - a.index)\n .map((o) => o.index);\n const ids = (hidden: ReadonlySet<number>): string[] => controls.filter((_, i) => hidden.has(i)).map((c) => c.id);\n const form = (main: number, extra: Partial<StackForm> & Pick<StackForm, \"kind\">): StackForm => ({ main: { min: main, natural: main }, cross: { natural: cross }, ...(grip > 0 ? { grip } : {}), ...extra });\n /** Tiers 1 and 2 own a band each; every later tier shares the band from 300, in tier order, always under 400. */\n const tierRank = (t: number, i: number): number => (t <= 2 ? RANK_TIER * t + i / n : 3 * RANK_TIER + (t - 3 + i / n) / (tierCount - 3));\n\n const row: StackForm[] = [];\n // The tier of every control now; the row's length with the controls in `shown`.\n const at = controls.map(() => 0);\n const rowLength = (shown: readonly number[], extra: number): number => shown.reduce((s, i) => s + length(controls[i]!, at[i]!), 0) + Math.max(0, shown.length - 1) * gap + grip + extra;\n const all = controls.map((_, i) => i);\n /** `StackForm.tiers` for the controls in `shown`: the tier each has now, held to its own list, so always a valid index into it. */\n const tiersOf = (shown: readonly number[]): Readonly<Record<string, number>> => Object.fromEntries(shown.map((i) => [controls[i]!.id, Math.min(at[i]!, Math.max(0, controls[i]!.tiers.length - 1))]));\n row.push(form(rowLength(all, 0), { kind: \"row\", tiers: tiersOf(all) }));\n for (let t = 1; t < tierCount; t++) {\n for (let i = 0; i < n; i++) {\n at[order[i]!] = t;\n row.push(form(rowLength(all, 0), { kind: \"row\", rank: tierRank(t, i), tiers: tiersOf(all) }));\n }\n }\n for (let k = 1; k < n; k++) {\n const hidden = new Set(order.slice(0, k));\n const shown = all.filter((i) => !hidden.has(i));\n row.push(form(rowLength(shown, more), { kind: \"row\", rank: 4 * RANK_TIER + k / n, ...pin, hides: ids(hidden), tiers: tiersOf(shown) }));\n }\n row.push(form(grip + more, { kind: \"fold\", rank: 5 * RANK_TIER, ...pin, hides: ids(new Set(all)) }));\n row.push({ kind: \"menu\", main: { min: 0, natural: 0 }, cross: { natural: 0 }, rank: 6 * RANK_TIER, ...pin });\n return { row, ...(column ? { column } : {}) };\n}\n","/**\n * Stacked items that share a draggable divider: one makes its neighbor longer and the other shorter by the same\n * amount, and nothing else in the stack moves. A divider's state is the asked length of the items on both sides\n * (`StackItem.lengths`), which `fitStack` reads in place of a growing form's natural; these are the functions that read and\n * write it. Pure: a state in, a state out (the same object when nothing changed).\n *\n * A growing item is one drawn in a form that grows (`main.grows`, not in the » menu): the items that share spare length,\n * and so the items whose length is written. The two ends of a divider are neighboring growing items, neither `fixed` nor a\n * `wrap` form. A header, a rail icon, a group or a folded item between them isn't growing, so it has no divider of its own\n * and doesn't kill the divider across it; a growing item that is not an end (a fixed one, a `wrap` form that grows) ends\n * the chain: there is no divider across it.\n */\nimport { EPS, type Rect } from \"../geometry\";\nimport { fitStack, sizesOf } from \"./layout\";\nimport { formMain, formMenu, type FitOptions, type StackAxis, type StackFit, type StackInput } from \"./model\";\n\n/** One divider: between the open growing items `before` and `after` (ids), drawn at `rect`. */\nexport interface StackDivider {\n readonly before: string;\n readonly after: string;\n /**\n * The strip the divider sits on, stack-local: it starts where the last item drawn before `after` ends (the far edge of\n * the last collapsed item between the two, or of `before`), and is as thick as the gap to `after` (0 with no gap).\n * Across, it is `before`'s extent. A host draws its grab zone around it.\n */\n readonly rect: Rect;\n /**\n * How far the divider may move each way, px along the stack (`min` ≤ 0 ≤ `max`): the delta `resizeBetween` takes, a\n * negative one moving it toward `before`. Where either end reaches its least.\n */\n readonly range: { readonly min: number; readonly max: number };\n}\n\ninterface Grower {\n readonly id: string;\n /** Whether it may be an end of a divider: not `fixed` and not a `wrap` form. */\n readonly end: boolean;\n /** The least it takes as the length was shared. */\n readonly least: number;\n /** What its form asks for by itself, the least at most. */\n readonly natural: number;\n /** How long it is drawn. */\n readonly drawn: number;\n /** Its place in `fit.items`. */\n readonly at: number;\n}\n\nconst mainOf = (r: Rect, axis: StackAxis): number => (axis === \"column\" ? r.height : r.width);\nconst startOf = (r: Rect, axis: StackAxis): number => (axis === \"column\" ? r.y : r.x);\n\n/** The items drawn in a form that grows, in the stack's order. */\nfunction growers(input: StackInput, fit: StackFit): Grower[] {\n const byId = new Map(input.items.map((it) => [it.id, it]));\n const known = sizesOf(fit);\n const out: Grower[] = [];\n fit.items.forEach((p, at) => {\n const item = byId.get(p.id);\n const f = item?.forms[p.form];\n if (!item || !f || formMenu(f) || f.main.grows !== true) return;\n const least = known?.least.get(p.id) ?? formMain(f, \"min\", fit.cross);\n out.push({ id: p.id, end: item.fixed !== true && !f.wrap, least, natural: Math.max(least, formMain(f, \"natural\", fit.cross)), drawn: mainOf(p.rect, fit.axis), at });\n });\n return out;\n}\n\n/** The two items of a divider, when `before` and `after` are neighboring growing items, both ends, in that order. */\nfunction pair(all: readonly Grower[], before: string, after: string): [Grower, Grower] | null {\n const i = all.findIndex((g) => g.id === before);\n const next = all[i + 1];\n return i >= 0 && next !== undefined && next.id === after && all[i]!.end && next.end ? [all[i]!, next] : null;\n}\n\n/**\n * `input` with the length of each item of the pair written so the stack is laid out as drawn (the pair given moved to\n * `to`) and nothing but the pair moves. A length is an ask, not a drawn size: with spare length a growing form is drawn\n * `scale` times its ask, so the ask written is the drawn size over `scale`; short of length the items are drawn part of\n * the way from their least to their ask (`tight`), so it is `least + (drawn - least) / tight`. An ask is a weight and the\n * least a floor on the drawn size, so with spare length an end drawn at its least asks for `least / scale`, under its\n * least, and is still drawn at its least. The pair's drawn sizes add up to what they did and every other item draws as it\n * did, so the scale is the same and no other item needs a length: a bystander keeps whatever it had, which is none when\n * nobody sized it, and travels to another stack as the item it is. Items already at their length stay the same objects.\n */\nfunction written(input: StackInput, fit: StackFit, all: readonly Grower[], to: ReadonlyMap<string, number>): StackInput {\n const known = sizesOf(fit);\n const tight = known?.tight;\n const share = tight !== undefined && tight > EPS && tight < 1 ? tight : 1;\n const scale = known?.scale ?? 1;\n const byId = new Map(all.map((g) => [g.id, g]));\n const ask = (g: Grower, drawn: number): number => (scale > 1 + EPS ? drawn / scale : g.least + (drawn - g.least) / share);\n let changed = false;\n const items = input.items.map((it) => {\n const drawn = to.get(it.id);\n if (drawn === undefined) return it;\n // A length of 0 is no length (the item would read its natural), so an end whose least is 0 asks a hair over it.\n const length = Math.max(ask(byId.get(it.id)!, drawn), 2 * EPS);\n const was = it.lengths?.[input.axis];\n if (was !== undefined && was > EPS && Math.abs(was - length) <= EPS) return it;\n changed = true;\n return { ...it, lengths: { ...it.lengths, [input.axis]: length } };\n });\n return changed ? { ...input, items } : input;\n}\n\n/**\n * The two items of the divider between `before` and `after` redrawn: `to(b, a)` is the length `before` is to be drawn at\n * (`after` takes the rest of their combined length). The same object when they aren't neighbors or `before` stays, and\n * while the stack is squeezed (`overflow`): no length is free to trade, and an ask written then would change the shares\n * once the stack grows. (A divider of a squeezed stack has no range either: every drawn item starts at its least and\n * only loses length from there, so `drawn - least` is never above 0.)\n */\nfunction trade(input: StackInput, before: string, after: string, options: FitOptions, to: (b: Grower, a: Grower) => number): StackInput {\n const fit = fitStack(input, options);\n if (fit.notes.some((n) => n.code === \"overflow\")) return input;\n const all = growers(input, fit);\n const ends = pair(all, before, after);\n if (!ends) return input;\n const [b, a] = ends;\n const first = to(b, a);\n if (Math.abs(first - b.drawn) <= EPS) return input;\n return written(\n input,\n fit,\n all,\n new Map([\n [b.id, first],\n [a.id, b.drawn + a.drawn - first],\n ]),\n );\n}\n\n/**\n * The dividers of a stack laid out as `fit`, one per pair of neighboring growing items that are both ends, in the stack's\n * order. A collapsed item has none of its own; where collapsed items sit between two open ones there is one divider\n * between the open ones, on the far edge of the last collapsed one. A growing item that isn't an end (a fixed one, a\n * `wrap` form) has none and ends the chain.\n */\nexport function dividers(input: StackInput, fit: StackFit): StackDivider[] {\n const all = growers(input, fit);\n const out: StackDivider[] = [];\n for (let k = 0; k + 1 < all.length; k++) {\n const b = all[k]!;\n const a = all[k + 1]!;\n if (!b.end || !a.end) continue;\n // The last item drawn before `after`: the divider sits on its far edge.\n let prev = a.at - 1;\n while (prev > b.at && fit.menu?.items.includes(fit.items[prev]!.id)) prev--;\n const last = fit.items[prev]!.rect;\n const from = startOf(last, fit.axis) + mainOf(last, fit.axis);\n const thick = Math.max(0, startOf(fit.items[a.at]!.rect, fit.axis) - from);\n const across = fit.items[b.at]!.rect;\n const rect: Rect = fit.axis === \"column\" ? { x: across.x, y: from, width: across.width, height: thick } : { x: from, y: across.y, width: thick, height: across.height };\n out.push({ before: b.id, after: a.id, rect, range: { min: 0 - Math.max(0, b.drawn - b.least), max: Math.max(0, a.drawn - a.least) } });\n }\n return out;\n}\n\n/**\n * Move the divider between the open growing items `before` and `after` by `delta` px along the stack: `before` gets\n * longer by `delta` and `after` shorter (a negative `delta` the other way), so the stack's total is the same and only the\n * two move. It writes the length of the two only, in ask units (see `written`), so nothing else shifts and the others\n * stay as they were, sized or not. Neither goes\n * under its least: `delta` is clamped to the divider's `range`, no item collapses and none is pushed. Returns the same\n * object when nothing changes (not neighbors, an unknown id, a `delta` that isn't a number, or one clamped to 0).\n * `options.previous` is the fit the stack had, as for `fitStack`.\n */\nexport function resizeBetween(input: StackInput, before: string, after: string, delta: number, options: FitOptions = {}): StackInput {\n if (!Number.isFinite(delta)) return input;\n return trade(input, before, after, options, (b, a) => b.drawn + Math.min(Math.max(delta, 0 - Math.max(0, b.drawn - b.least)), Math.max(0, a.drawn - a.least)));\n}\n\n/**\n * Give the two items of a divider back the split they would be drawn at if both asked for their natural, their combined\n * drawn length kept and nothing else moving: in proportion to their naturals (their forms' `main.natural`, the least at\n * most) with room for both, and `least + (natural - least) * s` with one shared `s` when short, as `fitStack` shares a\n * short length. The double-click action. Returns the same object when the two are at that split already (a pair nobody\n * resized always is, in every regime), or are not neighbors. Like a drag it writes the lengths of the two only.\n */\nexport function resetBetween(input: StackInput, before: string, after: string, options: FitOptions = {}): StackInput {\n return trade(input, before, after, options, (b, a) => {\n const both = b.drawn + a.drawn;\n const natural = b.natural + a.natural;\n const least = b.least + a.least;\n let want: number;\n if (both >= natural - EPS) want = natural > EPS ? (both * b.natural) / natural : both / 2;\n else want = b.least + (b.natural - b.least) * (natural - least > EPS ? (both - least) / (natural - least) : 0);\n return Math.min(Math.max(want, b.least), Math.max(b.least, both - a.least));\n });\n}\n\n/**\n * `input` with every asked length of the stack's axis deleted, back to the split a stack with none has. An item's length\n * for the other axis stays. Returns the same object when no item had one.\n */\nexport function resetLengths(input: StackInput): StackInput {\n let changed = false;\n const items = input.items.map((it) => {\n if (it.lengths?.[input.axis] === undefined) return it;\n changed = true;\n const { [input.axis]: _dropped, ...rest } = it.lengths;\n const { lengths: _lengths, ...bare } = it;\n return Object.keys(rest).length > 0 ? { ...bare, lengths: rest } : bare;\n });\n return changed ? { ...input, items } : input;\n}\n","/**\n * `stackGaps(input, item)`: one edge's drop places for `item`, fit only. Every gap of the stack without the item (an\n * item of the input with its id is lifted out first, so a reorder within the stack works) is one entry, in order: before\n * each item and after the last, so an empty stack has one. A gap where the item fits beside the others gives the stack\n * after the drop (`input`) and its fit (`fit`), with the item's rect there (`slot`): the drop is that same solve. A gap\n * where it doesn't fit is a refusal with its reason.\n *\n * The item counts as just used: it is newer than every item in the stack, so the others give way before it. It fits a\n * gap when the drop's fit doesn't put it in the » menu, has no `overflow`, makes no item `too-wide` that wasn't before,\n * and squeezes no `fixed` item (it keeps its form, is drawn at least its form's `main.min` along the stack and at least\n * as wide across as before). A fixed item may shrink down to its `main.min` to make room; one with `stepping` may also\n * step to a later form, as a movable item may.\n *\n * Reasons: `no-forms` (the item has none), `fixed` (a fixed item is never dropped), `not-accepted` (`input.accepts`\n * refuses it), `not-allowed` (`options.allows` refuses the gap), `to-menu`, `overflow`, `too-wide` and `squeezes-fixed`.\n * The first three refuse every gap. Pure: no hit zones, no time; where the pointer is is the host's.\n *\n * See docs/placement.md, Entry: stack.\n */\nimport type { Rect } from \"../geometry\";\nimport { fitStack } from \"./layout\";\nimport { formMain, itemSteps, withItem, type FitOptions, type PlacedStackItem, type StackFit, type StackInput, type StackItem } from \"./model\";\n\n/** Why a gap doesn't take the item. */\nexport type StackGapRefusal = \"no-forms\" | \"fixed\" | \"not-accepted\" | \"not-allowed\" | \"to-menu\" | \"overflow\" | \"too-wide\" | \"squeezes-fixed\";\n\n/** One gap: before the `at`-th item of the stack without the dragged one (`at` = their count: after the last). */\nexport type StackGap =\n | {\n readonly at: number;\n readonly fits: true;\n /** The stack with the item inserted at `at`: what the drop makes. */\n readonly input: StackInput;\n /** Its fit: the layout after the drop. */\n readonly fit: StackFit;\n /** The item's rect in `fit` (stack-local px). */\n readonly slot: Rect;\n }\n | { readonly at: number; readonly fits: false; readonly reason: StackGapRefusal };\n\nexport interface StackGapOptions {\n /** The stack's fit before the drag, as `fitStack`'s `previous`: each gap's fit keeps the others' forms while they still fit. */\n readonly previous?: StackFit;\n /** Whether a gap takes the item (default: every gap does), asked with the item and the gap's `at`. */\n readonly allows?: (item: StackItem, at: number) => boolean;\n}\n\n/** Why a drop's fit leaves no room for the item, or null when it fits beside the others. */\nfunction refusalOf(base: StackFit, fit: StackFit, dragged: PlacedStackItem, fixed: ReadonlyMap<string, StackItem>, axis: StackInput[\"axis\"], tooWideBefore: ReadonlySet<string>): StackGapRefusal | null {\n const inMenu = new Set(fit.menu?.items ?? []);\n const wasInMenu = new Set(base.menu?.items ?? []);\n if (inMenu.has(dragged.id)) return \"to-menu\";\n for (const n of fit.notes) {\n if (n.code === \"overflow\") return \"overflow\";\n if (n.code === \"too-wide\" && !tooWideBefore.has(n.id)) return \"too-wide\";\n }\n const main = (r: Rect): number => (axis === \"column\" ? r.height : r.width);\n const across = (r: Rect): number => (axis === \"column\" ? r.width : r.height);\n const was = new Map(base.items.map((p) => [p.id, p]));\n for (const p of fit.items) {\n const item = fixed.get(p.id);\n const q = was.get(p.id);\n if (!item || !q || inMenu.has(p.id) || wasInMenu.has(q.id)) continue;\n // A fixed item that takes steps (`stepping`) may step for a drop, as a movable item may; in the form it takes it is\n // still never squeezed.\n if (p.form !== q.form && !itemSteps(item)) return \"squeezes-fixed\";\n if (main(p.rect) < formMain(item.forms[p.form]!, \"min\", fit.cross) - 1e-6) return \"squeezes-fixed\";\n if (p.form === q.form && across(p.rect) < across(q.rect) - 1e-6) return \"squeezes-fixed\";\n }\n return null;\n}\n\nexport function stackGaps(input: StackInput, item: StackItem, options: StackGapOptions = {}): StackGap[] {\n const rest: StackInput = { ...input, items: input.items.filter((it) => it.id !== item.id) };\n const ats = Array.from({ length: rest.items.length + 1 }, (_, k) => k);\n const whole: StackGapRefusal | null = item.forms.length === 0 ? \"no-forms\" : item.fixed ? \"fixed\" : input.accepts && !input.accepts(item) ? \"not-accepted\" : null;\n if (whole) return ats.map((at) => ({ at, fits: false, reason: whole }));\n const fitOptions: FitOptions = options.previous ? { previous: options.previous } : {};\n const base = fitStack(rest, fitOptions);\n const fixed = new Map(rest.items.filter((it) => it.fixed).map((it) => [it.id, it]));\n const tooWideBefore = new Set(base.notes.flatMap((n) => (n.code === \"too-wide\" ? [n.id] : [])));\n const newest = rest.items.reduce((m, it) => Math.max(m, it.used), item.used) + 1;\n const held: StackItem = { ...item, used: newest };\n return ats.map((at): StackGap => {\n if (options.allows && !options.allows(item, at)) return { at, fits: false, reason: \"not-allowed\" };\n const solved = withItem(rest, held, at);\n const fit = fitStack(solved, fitOptions);\n const placed = fit.items.find((p) => p.id === item.id)!;\n const reason = refusalOf(base, fit, placed, fixed, rest.axis, tooWideBefore);\n return reason ? { at, fits: false, reason } : { at, fits: true, input: solved, fit, slot: placed.rect };\n });\n}\n","/**\n * `fitFloat(rect, stage, avoid)`: the rect a float gets. It is moved (never resized) to lie inside the stage, then beside\n * whatever docked content it would cover: the nearest place inside the stage that is clear of every `avoid` rect (the\n * docked items' rects, in the same px). One larger than the stage keeps its top-left corner on the stage's; if no clear\n * place exists the float stays where it covers the least and `covers` says which rects.\n *\n * A clear place is found whenever one exists: the x's are tried nearest first and, for each, the blocked stretches of y\n * are merged and skipped, so no clear place is missed however many places lie between. Cost (measured in a test run on\n * a laptop): about 100 docked rects 0.1 ms, 300 a few ms even when no place is clear (6 ms median, 15 ms worst), 1,000\n * about 17 ms; a safety net stops the clear search after 3 million rect tests and says so in `searchCapped`; a stage\n * with no clear place looks at the 2,048 nearest places for the least covered.\n *\n * With `{ stay: true }` it is only moved inside the stage: it lies where it is asked, and `covers` says which `avoid`\n * rects it covers there (a float a person left over content on purpose).\n *\n * A window model fits its floats with it.\n */\nimport { clampInto, overlap, overlaps, rect, type Rect } from \"../geometry\";\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\nexport interface FloatFitOptions {\n /**\n * Only moved inside the stage, never beside what it covers: `rect` is the asked rect clamped into the stage, `snapped`\n * is false and `covers` lists every `avoid` rect it covers there. Default false.\n */\n readonly stay?: boolean;\n}\n\n/** How far floats compare loosely: a float's px are rounded, so a thousandth is touching. */\nconst EPS = 1e-3;\nconst finite = (x: number, fallback: number): number => (Number.isFinite(x) ? x : fallback);\n\n/** `r` with a non-number replaced and no negative size. */\nconst clean = (r: Rect, at: Rect): Rect => rect(finite(r.x, at.x), finite(r.y, at.y), Math.max(0, finite(r.width, 0)), Math.max(0, finite(r.height, 0)));\n\n/** A safety net on the clear search, in rect tests (only thousands of rects reach it), and the places the least-covered search looks at. */\nconst WORK = 3_000_000;\nconst COVERED_PLACES = 2048;\n\ntype Triple = [number, number, number];\n\n/** A binary min-heap of `[index, index, distance]` triples, by distance then indexes (a fixed order). */\nclass Nearest {\n private readonly h: Triple[] = [];\n private less(a: Triple, b: Triple): boolean {\n return a[2] !== b[2] ? a[2] < b[2] : a[0] !== b[0] ? a[0] < b[0] : a[1] < b[1];\n }\n get size(): number {\n return this.h.length;\n }\n push(t: Triple): void {\n const h = this.h;\n let i = h.push(t) - 1;\n while (i > 0) {\n const p = (i - 1) >> 1;\n if (!this.less(h[i]!, h[p]!)) break;\n [h[i], h[p]] = [h[p]!, h[i]!];\n i = p;\n }\n }\n pop(): Triple {\n const h = this.h;\n const top = h[0]!;\n const last = h.pop()!;\n if (h.length > 0) {\n h[0] = last;\n let i = 0;\n for (;;) {\n const l = 2 * i + 1;\n const r = l + 1;\n let m = i;\n if (l < h.length && this.less(h[l]!, h[m]!)) m = l;\n if (r < h.length && this.less(h[r]!, h[m]!)) m = r;\n if (m === i) break;\n [h[i], h[m]] = [h[m]!, h[i]!];\n i = m;\n }\n }\n return top;\n }\n}\n\n/** The places `xs` crossed with `ys`, nearest to `(fx, fy)` first (Euclidean), without building the cross product. */\nfunction* byDistance(xs: readonly number[], ys: readonly number[], fx: number, fy: number): Generator<{ x: number; y: number; far: number }> {\n const sx = [...xs].sort((a, b) => Math.abs(a - fx) - Math.abs(b - fx) || a - b);\n const sy = [...ys].sort((a, b) => Math.abs(a - fy) - Math.abs(b - fy) || a - b);\n const q = new Nearest();\n const d = (i: number, j: number): number => Math.hypot(sx[i]! - fx, sy[j]! - fy);\n // Each x starts at its nearest y; popping a place pushes the same x's next y.\n if (sy.length > 0) for (let i = 0; i < sx.length; i++) q.push([i, 0, d(i, 0)]);\n while (q.size > 0) {\n const [i, j, far] = q.pop();\n yield { x: sx[i]!, y: sy[j]!, far };\n if (j + 1 < sy.length) q.push([i, j + 1, d(i, j + 1)]);\n }\n}\n\nexport function fitFloat(want: Rect, stage: Rect, avoid: readonly Rect[] = [], options: FloatFitOptions = {}): FloatFit {\n const area = clean(stage, rect(0, 0, 0, 0));\n const r = clean(want, area);\n const inside = clampInto(r, area);\n // Compared with what was asked, so a position that wasn't a number (and was replaced) counts as moved.\n const clamped = inside.x !== want.x || inside.y !== want.y;\n // Only rects that can touch the float wherever the stage lets it be: its reach.\n const reach = rect(area.x, area.y, Math.max(area.width, r.width), Math.max(area.height, r.height));\n const near: { at: Rect; index: number }[] = [];\n avoid.forEach((a, index) => {\n const at = clean(a, area);\n if (at.width > EPS && at.height > EPS && overlaps(at, reach, EPS)) near.push({ at, index });\n });\n const under = (cand: Rect): number[] => near.filter((n) => overlaps(cand, n.at, EPS)).map((n) => n.index);\n const blocked = (cand: Rect): boolean => near.some((n) => overlaps(cand, n.at, EPS));\n if (options.stay) return { rect: inside, clamped, snapped: false, covers: under(inside), searchCapped: false };\n if (!blocked(inside)) return { rect: inside, clamped, snapped: false, covers: [], searchCapped: false };\n\n // The places to look at: every x that puts the float against an edge of the stage or of a rect (or where it is),\n // crossed with every y that does; a clear place exists if one does at all, as a float slid against edges.\n const lo = (v: number, from: number, to: number): number => Math.min(Math.max(v, from), Math.max(from, to));\n const xs = [inside.x, area.x, area.x + area.width - r.width];\n const ys = [inside.y, area.y, area.y + area.height - r.height];\n for (const { at } of near) {\n xs.push(at.x - r.width, at.x + at.width);\n ys.push(at.y - r.height, at.y + at.height);\n }\n const places = (list: number[], from: number, size: number, extent: number): number[] => [...new Set(list.map((v) => lo(v, from, from + extent - size)))];\n const px = places(xs, area.x, r.width, area.width);\n const py = places(ys, area.y, r.height, area.height);\n // Nearest clear place: the x's nearest first; for each, the rects that overlap that x block open stretches of y, and\n // the nearest clear y is the wanted one if it is clear, else the end of the stretch it is in (the stretches are\n // merged, so a whole blocked run is skipped at once). A later x can't beat a clear place at least as far as its x\n // alone, so the search stops there. `WORK` bounds the rect tests as a safety net.\n const ylo = area.y;\n const yhi = Math.max(area.y, area.y + area.height - r.height);\n const byX = [...px].sort((a, b) => Math.abs(a - inside.x) - Math.abs(b - inside.x) || a - b);\n let clear: { x: number; y: number; far: number } | null = null;\n let work = 0;\n let searchCapped = false;\n for (const x of byX) {\n const dx = Math.abs(x - inside.x);\n if (clear && dx >= clear.far) break;\n work += near.length + 1;\n if (work > WORK) {\n searchCapped = true;\n break;\n }\n const stretches: [number, number][] = [];\n for (const { at } of near) {\n if (Math.min(x + r.width, at.x + at.width) - Math.max(x, at.x) > EPS) stretches.push([at.y - r.height, at.y + at.height]);\n }\n stretches.sort((a, b) => a[0] - b[0]);\n // The clear y's are the closed gaps between the merged open stretches, within the stage.\n let cursor = ylo;\n let bestY: number | null = null;\n const gap = (from: number, to: number): void => {\n if (from > to) return;\n const y = Math.min(Math.max(inside.y, from), to);\n if (bestY === null || Math.abs(y - inside.y) < Math.abs(bestY - inside.y)) bestY = y;\n };\n for (const [a, b] of stretches) {\n gap(cursor, Math.min(a, yhi));\n cursor = Math.max(cursor, b);\n if (cursor > yhi) break;\n }\n if (cursor <= yhi) gap(cursor, yhi);\n if (bestY === null) continue;\n const far = Math.hypot(dx, bestY - inside.y);\n if (!clear || far < clear.far) clear = { x, y: bestY, far };\n }\n if (clear) return { rect: rect(clear.x, clear.y, r.width, r.height), clamped, snapped: clear.far > EPS, covers: [], searchCapped };\n // None is clear: the nearest places that cover the least.\n let best: { rect: Rect; left: number; far: number; hits: number[] } | null = null;\n let tried = 0;\n for (const p of byDistance(px, py, inside.x, inside.y)) {\n if (tried++ >= COVERED_PLACES) break;\n const cand = rect(p.x, p.y, r.width, r.height);\n const left = near.reduce((s, n) => s + overlap(cand, n.at), 0);\n if (!best || left < best.left - EPS) best = { rect: cand, left, far: p.far, hits: under(cand) };\n }\n const out = best ?? { rect: inside, far: 0, hits: under(inside) };\n return { rect: out.rect, clamped, snapped: out.far > EPS, covers: out.hits, searchCapped };\n}\n"],"mappings":";;;;;;;;;AAuCA,IAAM,KAAK,CAAC,MAAmC,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,KAAK,IAAI,GAAG,CAAC,IAAI;AAG9G,SAAS,QAAQ,MAAY,MAA8D;AACzF,QAAM,SAAS,KAAK,SAAS,SAAS,KAAK,SAAS,WAAW,KAAK,SAAS,KAAK;AAClF,QAAM,OAAO,KAAK,IAAI,GAAG,MAAM;AAC/B,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,IAAI;AAC1C,QAAM,MAAM,QAAQ,IAAI,KAAK,IAAI,GAAG,KAAK,GAAG,GAAG,OAAO,KAAK,IAAI;AAC/D,QAAM,OAAO,QAAQ;AACrB,UAAQ,KAAK,MAAM;AAAA,IACjB,KAAK;AACH,aAAO,EAAE,MAAM,KAAK,KAAK,GAAG,KAA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AAA,IACpB;AACA,QAAI,UAAU,IAAK,KAAI,QAAQ,GAAG;AAClC,QAAI,UAAU,KAAM;AACpB,UAAM,MAAM,KAAK,MAAM,IAAI,QAAQ,OAAO,CAAC;AAC3C,QAAI,CAAC,SAAS,MAAM,MAAM,IAAK,SAAQ,EAAE,GAAG,GAAG,OAAO,IAAI;AAAA,EAC5D;AACA,MAAI,MAAO,QAAO,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,SAAS,MAAM,MAAMA,MAAK,QAAQ,CAAC,GAAG,aAAa;AAEjI,MAAI,OAAyE;AAC7E,MAAI,QAAQ;AACZ,aAAW,KAAK,WAAWE,KAAI,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG;AACtD,QAAI,WAAW,eAAgB;AAC/B,UAAM,OAAO,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;AAC7C,UAAM,OAAO,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,QAAQ,MAAM,EAAE,EAAE,GAAG,CAAC;AAC7D,QAAI,CAAC,QAAQ,OAAO,KAAK,OAAOF,KAAK,QAAO,EAAE,MAAM,MAAM,MAAM,KAAK,EAAE,KAAK,MAAM,MAAM,IAAI,EAAE;AAAA,EAChG;AACA,QAAM,MAAM,QAAQ,EAAE,MAAM,QAAQ,KAAK,GAAG,MAAM,MAAM,MAAM,EAAE;AAChE,SAAO,EAAE,MAAM,IAAI,MAAM,SAAS,SAAS,IAAI,MAAMA,MAAK,QAAQ,IAAI,MAAM,aAAa;AAC3F;","names":["px","finite","cross","inside","growers","s","nonNeg","mainOf","rect","EPS","finite","px"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n-uf/placement",
|
|
3
|
-
"version": "26.12.
|
|
3
|
+
"version": "26.12.4",
|
|
4
4
|
"description": "Where things fit: the stage cut into edge bands, the items along one edge fitted with their forms, one edge's drop places, floats kept clear, panes tiled and popups positioned. Pure geometry in, rects out. No DOM, no framework, no motion.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layout",
|