@n-uf/placement 26.11.54 → 26.11.55

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 CHANGED
@@ -3,6 +3,80 @@
3
3
  Versions are calendar versions, `YY.M.R` (year, month of the release, counter within the month), shared with
4
4
  `@n-uf/motion` and `@n-uf/docking`: the packages carry the same version, and a release bumps them all.
5
5
 
6
+ Unreleased entries live in `changes/` until a release joins them.
7
+
8
+ ## 26.11.55
9
+
10
+ - `./tiling`, **added: canSplitPane, dropFits, paneRegion's paneCenter option, master clamps, Rect**, for a host with its own
11
+ projected layout. `canSplitPane(target, side, { min, gap?, handle? })` is the room rule (along the split `2 * min`
12
+ plus the gutter, across it `min`, for the rect of a pane) and `dropFits(projected, dragged, at, area, { min, side })`
13
+ the fit rule (both panes at least `min` in a layout the host already projected) (`SplitRoomOptions`,
14
+ `DropFitsOptions`); `canDropOnPane` is now exactly the two in turn, with the same verdicts and reasons.
15
+ `paneRegion` takes a center the host measured as `options.paneCenter` (a `PaneCenter`), the same region for the same
16
+ center. `masterRatio` and `masterCount`, the clamps `masterStack` applies, and the `Rect` type (the root's) are
17
+ exported.
18
+ - `./tiling`, **behavior change: the gap rule**. A split of extent `W` at ratio `r` with a gutter `g` now puts the
19
+ middle of the gutter at `W * r`: the first side is `max(0, W * r - g / 2)` long, the second starts at
20
+ `start + W * r + g / 2` and is `max(0, W * (1 - r) - g / 2)` long. It replaces `(W - g) * r`. At ratio 0.5 both rules
21
+ agree (to the last bits), at any other ratio a split with a gap lays out differently. The promise that the second
22
+ side never starts past the rect's end goes: no size is ever negative, and a split with no room may start its second
23
+ side up to half a gutter past the end. Order layouts (`columns`, `grid`) keep their rule.
24
+ - `./tiling`, **fixed: a ratio or gap that is not finite**. A NaN or infinite `ratio` gave NaN rects; it is now 0.5.
25
+ A NaN `gap` did too; `layoutSplit` now treats a negative or non-finite `gap` (and `handle`) as 0.
26
+ - `./tiling`, **`masterStack` count and side**: `count` (rounded, within 1 to n, default 1) and `side` (`"left"` by
27
+ default, `"right"`, `"top"`, `"bottom"`). Left and right make the areas columns of stacked panes, top and bottom
28
+ rows of panes side by side, right and bottom put the stack first in space, and with no stack the panes fill the area
29
+ along the side's cross axis. Its `ratio` is now clamped to 0.05..0.95 (not finite: 0.5), and a negative or non-finite
30
+ `gap` is 0. With the defaults the rects are the earlier ones, to the last bits of the stack's width. The two live in
31
+ `MasterOptions`; the order layouts and `orderTargets` take `OrderOptions` (`TileOptions` and `MasterOptions`), and a
32
+ split tree's options do not accept them.
33
+ - `./tiling`, **gutters, split ids and `layoutSplitTree`**: `TileOptions.handle` (px, default 0) is the extra room a
34
+ split's divider takes beside the gap, so a split's gutter is its gap plus the handle. A split may carry its own
35
+ `gap` (the handle stays global) and an `id`. `layoutSplitTree(tree, area, options)` gives `{ panes, splits }`, and for
36
+ each split with an `id` its `rect`, `axis`, `ratio` in effect and `divider` (`SplitLayout`, `SplitGeometry`);
37
+ `layoutSplit` is its `panes`.
38
+ - `./tiling`, **master splits**: a split with `master: { count?, side? }` lays its subtree out flat, its panes in
39
+ order through `masterStack` by its ratio and gap (never the handle). The splits under it are not laid out or
40
+ reported.
41
+ - `./tiling`, **floors and fixed lengths**: the layout options `floor(child, axis, split)` (`{ min, net? }`, the least
42
+ length along the split; the ratio is clamped to keep it within 0.05..0.95 unless a side says `net: false`, and is
43
+ 0.5 where both floors cannot fit), `fixed(child, axis)` (`{ length, keep? }`, a length along the split: the first
44
+ that fits takes it and the other side fills the rest; with `keep` on both, each keeps its own) and
45
+ `fixedAcross(child, axis)` (a length across the split) (`SplitOptions`, `MinLength`, `FixedLength`). With none of
46
+ them a layout is as before.
47
+ - `./tiling`, **`canDropOnPane(tree, dragged, at, region, area, options)`**: `{ ok, reason? }` whether a drop leaves
48
+ room: a side needs `2 * min` plus the gutter along the split and `min` across, in the layout without the dragged
49
+ pane, and both panes at least `min` wide and high in the layout the drop makes (`DropOptions`, `DropVerdict`).
50
+ - `./tiling`, **`neighbor(rects, from, direction)`**: the nearest pane in a direction from a map of rects, by the
51
+ distance between centers (a candidate's center strictly on that side; the lowest score wins, ties to the first)
52
+ (`Direction`).
53
+ - `./stack`, **asked lengths and dividers**: `StackItem.lengths` (`{ column?, row? }`, px along the stack, per axis) is read
54
+ in place of the `main.natural` of a growing form, the least staying its `main.min`, and `dividers(input, fit)`,
55
+ `resizeBetween`, `resetBetween` and `resetLengths` trade length between the nearest open growing items (a collapsed
56
+ item between two open ones gives one divider, on its far edge; `StackDivider`, `StackLengths`). Additive: a stack that
57
+ declares no length is laid out exactly as before.
58
+ - `./stack`, **a divider drag writes the pair's lengths only, in ask units**: `resizeBetween` writes `lengths` for the
59
+ two items of the dragged pair and for no other item, so a bystander moved to another stack is laid out as an item nobody
60
+ resized. A length in `lengths` is in ask units, not drawn px; with room to spare a drawn size is the ask times the shared scale, or
61
+ its least when that is more, so the pair's ask is its drawn size over that scale (short of room,
62
+ `least + (drawn - least) / share`), which leaves the scale and every other drawn size as they were. A collapsed item no
63
+ longer gets a length from a drag of its neighbors: reopened, it keeps its proportion unless an end of the pair is held
64
+ at its least (its ask under the least and its share of the column too); then it gives up that end's excess in
65
+ proportion. An item nobody sized asks its natural, so when that changes it re-shares the column with the sized ones,
66
+ which keep their proportion to one another, not their px. `resetBetween` writes the pair only, too. An end dragged to its
67
+ least asks `least / scale`, under its least, and is still drawn at it.
68
+ - `./stack`, **behavior change: a length under its least now reads as a weight with room**. The least is a floor on the
69
+ drawn size, not on the ask: with room to spare, an item whose share of the length (its ask times the scale) would be
70
+ under its least is drawn at its least and the others share the rest in proportion to their asks. Before, a length under
71
+ the least was read as the least. Short of room an ask under the least still reads as the least. A length of 0 (or under
72
+ `EPS`) is no length: the item asks its natural, so an item a stored state holds at 0 (dragged fully shut when its least
73
+ is 0) opens at its natural when that state is read again. A stack that declares no length, or none under its least, is laid out
74
+ exactly as before.
75
+ - Docs only: **the design page names the three places the solver reads a form's `kind`** (`menu`, the group kinds for
76
+ `ownCross`, and kind equality under `previous`), says the root's `Target` carries the docking model's drag fields as
77
+ plain data, and says `fitFloat` finds a clear place unless its search is capped (`FloatFit.searchCapped`). No
78
+ behavior, type or export change.
79
+
6
80
  ## 26.11.54
7
81
 
8
82
  Breaking. Placement is the general layer: one edge, one area, one popup. The window's docking model leaves for its own
package/README.md CHANGED
@@ -20,7 +20,7 @@ npm i @n-uf/placement
20
20
  | Entry | What it gives |
21
21
  |---|---|
22
22
  | `@n-uf/placement/stack` | One edge: the cut of the stage into bands (`cutEdges`), the fit of its items (`fitStack`) in the form vocabulary every item declares its forms in (`StackForm`, with the flags `body`, `folded`, `compact`), its drop places (`stackGaps`) and the float fit (`fitFloat`). |
23
- | `@n-uf/placement/tiling` | Panes that divide an area. Order layouts (`masterStack`, `columns`, `grid`), the split tree (`layoutSplit`, `dropOnPane`) and their drop targets. |
23
+ | `@n-uf/placement/tiling` | Panes that divide an area. Order layouts (`masterStack`, `columns`, `grid`), the split tree (`layoutSplit`, `layoutSplitTree`, with gaps, handles, floors and fixed lengths, `dropOnPane`, `canDropOnPane`), `neighbor` and the drop targets. |
24
24
  | `@n-uf/placement/popup` | A popup positioned as Wayland's xdg-positioner does (`positionPopup`). |
25
25
  | `@n-uf/placement` | The shared shapes (`Rect`, `Size`, `Point`), the geometry and the `Target` shape. |
26
26
 
@@ -58,6 +58,17 @@ console.log(layoutSplit(after, area).get("c")); // { x: 400, y: 0, width: 400, h
58
58
  console.log(paneTargets(layoutSplit(tree, area)).map((t) => t.id)); // [ 'pane:a', 'pane:b' ]
59
59
  ```
60
60
 
61
+ A split puts the middle of its gutter (its gap plus its handle) at its ratio. `layoutSplitTree` also reports the box, ratio and divider of each split that has an `id`. The `floor`, `fixed` and `fixedAcross` options read a host's minimums and fixed lengths, `canDropOnPane` says whether a drop leaves room, and `neighbor` finds the nearest pane in a direction.
62
+
63
+ ```ts
64
+ import { layoutSplitTree } from "@n-uf/placement/tiling";
65
+
66
+ const split = { id: "main", a: { pane: "a" }, b: { pane: "b" }, axis: "x" as const, ratio: 0.3 };
67
+ const { panes, splits } = layoutSplitTree(split, { x: 0, y: 0, width: 1000, height: 600 }, { gap: 6, handle: 4 });
68
+ console.log(panes.get("a")?.width, panes.get("b")?.x); // 295 305
69
+ console.log(splits.get("main")?.divider); // { x: 295, y: 0, width: 10, height: 600 }
70
+ ```
71
+
61
72
  ## Documentation
62
73
 
63
74
  - [Design page](https://github.com/n-uf/motion/blob/main/docs/placement.md): the concept, the rules a consumer relies on, and the SDK entry by entry.
package/dist/stack.d.ts CHANGED
@@ -202,6 +202,15 @@ declare function wrapCross(spec: WrapSpec): {
202
202
  natural: number;
203
203
  min: number;
204
204
  };
205
+ /**
206
+ * 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
207
+ * runs down, `row` by one that runs across, so an item that moves to a stack of the other axis never reads a length
208
+ * meant for this one.
209
+ */
210
+ interface StackLengths {
211
+ readonly column?: number;
212
+ readonly row?: number;
213
+ }
205
214
  interface StackItem {
206
215
  readonly id: string;
207
216
  /** Largest first. The solver starts at `from` and steps down one at a time. An item with none is left out. */
@@ -225,6 +234,19 @@ interface StackItem {
225
234
  * first, or last) is the host's; placement lays out the items it is given.
226
235
  */
227
236
  readonly fixed?: boolean;
237
+ /**
238
+ * The length asked for along the stack (default none). While the item is in a form that grows (`main.grows`; a `wrap`
239
+ * 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
240
+ * `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
241
+ * 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
242
+ * lengths (one whose share would be under its least is drawn at its least, the others share the rest), short of length
243
+ * they interpolate between their least (an ask under it reads as the least) and their length, so a stack too short for
244
+ * 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
245
+ * stack of the other axis. A stack whose items declare none is laid out exactly as before. What gives way and in
246
+ * 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
247
+ * shared scale, or its least when that is more. `resizeBetween` and `resetBetween` write it for the pair only; `resetLengths` clears it.
248
+ */
249
+ readonly lengths?: StackLengths;
228
250
  }
229
251
  /** The cross size a stack may take. With no form setting it, the stack is a `rail` wide (default {@link DEFAULT_RAIL}). */
230
252
  interface CrossLimits {
@@ -501,6 +523,69 @@ interface ControlLadder {
501
523
  /** `spec`'s forms: the row ladder, and the column ladder when `spec.column` is given. Pure. */
502
524
  declare function controlLadder(spec: ControlLadderSpec): ControlLadder;
503
525
 
526
+ /**
527
+ * Stacked items that share a draggable divider: one makes its neighbor longer and the other shorter by the same
528
+ * amount, and nothing else in the stack moves. A divider's state is the asked length of the items on both sides
529
+ * (`StackItem.lengths`), which `fitStack` reads in place of a growing form's natural; these are the functions that read and
530
+ * write it. Pure: a state in, a state out (the same object when nothing changed).
531
+ *
532
+ * A growing item is one drawn in a form that grows (`main.grows`, not in the » menu): the items that share spare length,
533
+ * and so the items whose length is written. The two ends of a divider are neighboring growing items, neither `fixed` nor a
534
+ * `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
535
+ * 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
536
+ * the chain: there is no divider across it.
537
+ */
538
+
539
+ /** One divider: between the open growing items `before` and `after` (ids), drawn at `rect`. */
540
+ interface StackDivider {
541
+ readonly before: string;
542
+ readonly after: string;
543
+ /**
544
+ * The strip the divider sits on, stack-local: it starts where the last item drawn before `after` ends (the far edge of
545
+ * the last collapsed item between the two, or of `before`), and is as thick as the gap to `after` (0 with no gap).
546
+ * Across, it is `before`'s extent. A host draws its grab zone around it.
547
+ */
548
+ readonly rect: Rect;
549
+ /**
550
+ * How far the divider may move each way, px along the stack (`min` ≤ 0 ≤ `max`): the delta `resizeBetween` takes, a
551
+ * negative one moving it toward `before`. Where either end reaches its least.
552
+ */
553
+ readonly range: {
554
+ readonly min: number;
555
+ readonly max: number;
556
+ };
557
+ }
558
+ /**
559
+ * The dividers of a stack laid out as `fit`, one per pair of neighboring growing items that are both ends, in the stack's
560
+ * order. A collapsed item has none of its own; where collapsed items sit between two open ones there is one divider
561
+ * 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
562
+ * `wrap` form) has none and ends the chain.
563
+ */
564
+ declare function dividers(input: StackInput, fit: StackFit): StackDivider[];
565
+ /**
566
+ * Move the divider between the open growing items `before` and `after` by `delta` px along the stack: `before` gets
567
+ * longer by `delta` and `after` shorter (a negative `delta` the other way), so the stack's total is the same and only the
568
+ * two move. It writes the length of the two only, in ask units (see `written`), so nothing else shifts and the others
569
+ * stay as they were, sized or not. Neither goes
570
+ * under its least: `delta` is clamped to the divider's `range`, no item collapses and none is pushed. Returns the same
571
+ * object when nothing changes (not neighbors, an unknown id, a `delta` that isn't a number, or one clamped to 0).
572
+ * `options.previous` is the fit the stack had, as for `fitStack`.
573
+ */
574
+ declare function resizeBetween(input: StackInput, before: string, after: string, delta: number, options?: FitOptions): StackInput;
575
+ /**
576
+ * Give the two items of a divider back the split they would be drawn at if both asked for their natural, their combined
577
+ * drawn length kept and nothing else moving: in proportion to their naturals (their forms' `main.natural`, the least at
578
+ * most) with room for both, and `least + (natural - least) * s` with one shared `s` when short, as `fitStack` shares a
579
+ * short length. The double-click action. Returns the same object when the two are at that split already (a pair nobody
580
+ * resized always is, in every regime), or are not neighbors. Like a drag it writes the lengths of the two only.
581
+ */
582
+ declare function resetBetween(input: StackInput, before: string, after: string, options?: FitOptions): StackInput;
583
+ /**
584
+ * `input` with every asked length of the stack's axis deleted, back to the split a stack with none has. An item's length
585
+ * for the other axis stays. Returns the same object when no item had one.
586
+ */
587
+ declare function resetLengths(input: StackInput): StackInput;
588
+
504
589
  /**
505
590
  * `stackGaps(input, item)`: one edge's drop places for `item`, fit only. Every gap of the stack without the item (an
506
591
  * item of the input with its id is lifted out first, so a reorder within the stack works) is one entry, in order: before
@@ -578,4 +663,4 @@ interface FloatFit {
578
663
  }
579
664
  declare function fitFloat(want: Rect, stage: Rect, avoid?: readonly Rect[]): FloatFit;
580
665
 
581
- export { type BandSide, type ControlLadder, type ControlLadderSpec, type CrossLimits, DEFAULT_MENU, DEFAULT_RAIL, type EdgeBand, type EdgeCut, type FitOptions, type FloatFit, type GroupFormKind, type LadderControl, type MainSize, type PanelFormKind, type PlacedStackItem, type StackAxis, type StackFit, type StackForm, type StackFormKind, type StackGap, type StackGapOptions, type StackGapRefusal, type StackInput, type StackItem, type StackMenu, type StackNote, type StackNoteCode, type StackStep, type WrapSpec, controlLadder, cutEdges, fitFloat, fitStack, formBody, formCompact, formCrossMin, formFitsCross, formFolded, formMain, formSetsCross, stackGaps, withItem, wrapCross, wrapLines, wrapRows };
666
+ export { type BandSide, type ControlLadder, type ControlLadderSpec, type CrossLimits, DEFAULT_MENU, DEFAULT_RAIL, type EdgeBand, type EdgeCut, type FitOptions, type FloatFit, 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, formMain, formSetsCross, resetBetween, resetLengths, resizeBetween, stackGaps, withItem, wrapCross, wrapLines, wrapRows };
package/dist/stack.js CHANGED
@@ -145,6 +145,11 @@ var formBody = (f) => f.body ?? f.kind === "open";
145
145
  var formFolded = (f) => f.folded ?? (f.kind === "header" || f.kind === "fold");
146
146
  var formCompact = (f) => f.compact ?? f.kind === "icons";
147
147
  var formSetsCross = (f) => f.setsCross ?? formBody(f);
148
+ function askedLength(item, form, axis) {
149
+ const v = item.lengths?.[axis];
150
+ if (v === void 0 || !Number.isFinite(v) || v <= EPS) return void 0;
151
+ return form.kind !== "menu" && form.main.grows === true ? v : void 0;
152
+ }
148
153
  function withItem(input, item, at) {
149
154
  const k = Math.min(Math.max(0, Math.floor(at)), input.items.length);
150
155
  return { ...input, items: [...input.items.slice(0, k), item, ...input.items.slice(k)] };
@@ -436,20 +441,46 @@ function solve(input, previous, seed, grow = false) {
436
441
  const avail = Math.max(0, length - sp.start - sp.end - gapsOf() - menuSize);
437
442
  const drawn = idx.filter((i) => !isMenu(form(i)));
438
443
  const min = (i) => mainOf(form(i), hold && holds(i) ? "natural" : "min", cross);
439
- const nat = (i) => Math.max(min(i), mainOf(form(i), "natural", cross));
444
+ const nat = (i) => Math.max(min(i), askedLength(items[i], form(i), input.axis) ?? mainOf(form(i), "natural", cross));
440
445
  const sumMin = drawn.reduce((s, i) => s + min(i), 0);
441
446
  const sumNat = drawn.reduce((s, i) => s + nat(i), 0);
442
447
  const size = /* @__PURE__ */ new Map();
448
+ let tight = 1;
449
+ let scale = 1;
443
450
  if (sumNat <= avail + EPS) {
444
- const growers = drawn.filter((i) => form(i).main.grows);
451
+ const growers2 = drawn.filter((i) => form(i).main.grows);
445
452
  const spare = Math.max(0, avail - sumNat);
446
- const weight = growers.reduce((s, i) => s + nat(i), 0);
453
+ const weight = growers2.reduce((s, i) => s + nat(i), 0);
454
+ if (weight > EPS) scale = 1 + spare / weight;
447
455
  for (const i of drawn) {
448
- const share = growers.includes(i) ? weight > EPS ? nat(i) / weight : 1 / growers.length : 0;
456
+ const share = growers2.includes(i) ? weight > EPS ? nat(i) / weight : 1 / growers2.length : 0;
449
457
  size.set(i, nat(i) + spare * share);
450
458
  }
459
+ const ask = (i) => askedLength(items[i], form(i), input.axis) ?? nat(i);
460
+ if (weight > EPS && growers2.some((i) => ask(i) < min(i))) {
461
+ const pinned = /* @__PURE__ */ new Set();
462
+ const room = avail - drawn.reduce((s2, i) => growers2.includes(i) ? s2 : s2 + nat(i), 0);
463
+ let s = scale;
464
+ for (; ; ) {
465
+ const free = growers2.filter((i) => !pinned.has(i));
466
+ const weights = free.reduce((sum, i) => sum + ask(i), 0);
467
+ if (weights <= EPS) {
468
+ for (const i of free) pinned.add(i);
469
+ break;
470
+ }
471
+ s = (room - [...pinned].reduce((sum, i) => sum + min(i), 0)) / weights;
472
+ const under = free.filter((i) => ask(i) * s < min(i));
473
+ if (under.length === 0) break;
474
+ for (const i of under) pinned.add(i);
475
+ }
476
+ if (pinned.size < growers2.length) {
477
+ scale = s;
478
+ for (const i of growers2) size.set(i, pinned.has(i) ? min(i) : ask(i) * s);
479
+ }
480
+ }
451
481
  } else {
452
482
  const t = avail > sumMin && sumNat > sumMin ? (avail - sumMin) / (sumNat - sumMin) : 0;
483
+ tight = t;
453
484
  for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);
454
485
  }
455
486
  const rectAt = (from, main, across = cross) => input.axis === "column" ? { x: 0, y: from, width: across, height: main } : { x: from, y: 0, width: main, height: across };
@@ -476,8 +507,12 @@ function solve(input, previous, seed, grow = false) {
476
507
  for (const i of menuOrder) if (isMenu(form(i))) notes.push({ code: "to-menu", id: items[i].id });
477
508
  for (const i of idx) if (tooWide(i, cross)) notes.push({ code: "too-wide", id: items[i].id });
478
509
  if (overflow > EPS) notes.push({ code: "overflow", over: overflow });
479
- return { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };
510
+ const fit = { axis: input.axis, length, cross, items: placed, menu, notes, need: minSumWith(false), steps: hist };
511
+ sizes.set(fit, { tight, scale, least: new Map(drawn.map((i) => [items[i].id, min(i)])) });
512
+ return fit;
480
513
  }
514
+ var sizes = /* @__PURE__ */ new WeakMap();
515
+ var sizesOf = (fit) => sizes.get(fit);
481
516
 
482
517
  // src/stack/ladder.ts
483
518
  var nonNeg2 = (x) => typeof x === "number" && Number.isFinite(x) ? Math.max(0, x) : 0;
@@ -524,6 +559,109 @@ function controlLadder(spec) {
524
559
  return { row, ...column ? { column } : {} };
525
560
  }
526
561
 
562
+ // src/stack/divide.ts
563
+ var mainOf2 = (r, axis) => axis === "column" ? r.height : r.width;
564
+ var startOf = (r, axis) => axis === "column" ? r.y : r.x;
565
+ function growers(input, fit) {
566
+ const byId = new Map(input.items.map((it) => [it.id, it]));
567
+ const known = sizesOf(fit);
568
+ const out = [];
569
+ fit.items.forEach((p, at) => {
570
+ const item = byId.get(p.id);
571
+ const f = item?.forms[p.form];
572
+ if (!item || !f || p.kind === "menu" || f.kind === "menu" || f.main.grows !== true) return;
573
+ const least = known?.least.get(p.id) ?? formMain(f, "min", fit.cross);
574
+ out.push({ id: p.id, end: item.fixed !== true && !f.wrap, least, natural: Math.max(least, formMain(f, "natural", fit.cross)), drawn: mainOf2(p.rect, fit.axis), at });
575
+ });
576
+ return out;
577
+ }
578
+ function pair(all, before, after) {
579
+ const i = all.findIndex((g) => g.id === before);
580
+ const next = all[i + 1];
581
+ return i >= 0 && next !== void 0 && next.id === after && all[i].end && next.end ? [all[i], next] : null;
582
+ }
583
+ function written(input, fit, all, to) {
584
+ const known = sizesOf(fit);
585
+ const tight = known?.tight;
586
+ const share = tight !== void 0 && tight > EPS && tight < 1 ? tight : 1;
587
+ const scale = known?.scale ?? 1;
588
+ const byId = new Map(all.map((g) => [g.id, g]));
589
+ const ask = (g, drawn) => scale > 1 + EPS ? drawn / scale : g.least + (drawn - g.least) / share;
590
+ let changed = false;
591
+ const items = input.items.map((it) => {
592
+ const drawn = to.get(it.id);
593
+ if (drawn === void 0) return it;
594
+ const length = Math.max(ask(byId.get(it.id), drawn), 2 * EPS);
595
+ const was = it.lengths?.[input.axis];
596
+ if (was !== void 0 && was > EPS && Math.abs(was - length) <= EPS) return it;
597
+ changed = true;
598
+ return { ...it, lengths: { ...it.lengths, [input.axis]: length } };
599
+ });
600
+ return changed ? { ...input, items } : input;
601
+ }
602
+ function trade(input, before, after, options, to) {
603
+ const fit = fitStack(input, options);
604
+ const all = growers(input, fit);
605
+ const ends = pair(all, before, after);
606
+ if (!ends) return input;
607
+ const [b, a] = ends;
608
+ const first = to(b, a);
609
+ if (Math.abs(first - b.drawn) <= EPS) return input;
610
+ return written(
611
+ input,
612
+ fit,
613
+ all,
614
+ /* @__PURE__ */ new Map([
615
+ [b.id, first],
616
+ [a.id, b.drawn + a.drawn - first]
617
+ ])
618
+ );
619
+ }
620
+ function dividers(input, fit) {
621
+ const all = growers(input, fit);
622
+ const out = [];
623
+ for (let k = 0; k + 1 < all.length; k++) {
624
+ const b = all[k];
625
+ const a = all[k + 1];
626
+ if (!b.end || !a.end) continue;
627
+ let prev = a.at - 1;
628
+ while (prev > b.at && fit.items[prev].kind === "menu") prev--;
629
+ const last = fit.items[prev].rect;
630
+ const from = startOf(last, fit.axis) + mainOf2(last, fit.axis);
631
+ const thick = Math.max(0, startOf(fit.items[a.at].rect, fit.axis) - from);
632
+ const across = fit.items[b.at].rect;
633
+ const rect2 = fit.axis === "column" ? { x: across.x, y: from, width: across.width, height: thick } : { x: from, y: across.y, width: thick, height: across.height };
634
+ out.push({ before: b.id, after: a.id, rect: rect2, range: { min: 0 - Math.max(0, b.drawn - b.least), max: Math.max(0, a.drawn - a.least) } });
635
+ }
636
+ return out;
637
+ }
638
+ function resizeBetween(input, before, after, delta, options = {}) {
639
+ if (!Number.isFinite(delta)) return input;
640
+ 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)));
641
+ }
642
+ function resetBetween(input, before, after, options = {}) {
643
+ return trade(input, before, after, options, (b, a) => {
644
+ const both = b.drawn + a.drawn;
645
+ const natural = b.natural + a.natural;
646
+ const least = b.least + a.least;
647
+ let want;
648
+ if (both >= natural - EPS) want = natural > EPS ? both * b.natural / natural : both / 2;
649
+ else want = b.least + (b.natural - b.least) * (natural - least > EPS ? (both - least) / (natural - least) : 0);
650
+ return Math.min(Math.max(want, b.least), Math.max(b.least, both - a.least));
651
+ });
652
+ }
653
+ function resetLengths(input) {
654
+ let changed = false;
655
+ const items = input.items.map((it) => {
656
+ if (it.lengths?.[input.axis] === void 0) return it;
657
+ changed = true;
658
+ const { [input.axis]: _dropped, ...rest } = it.lengths;
659
+ const { lengths: _lengths, ...bare } = it;
660
+ return Object.keys(rest).length > 0 ? { ...bare, lengths: rest } : bare;
661
+ });
662
+ return changed ? { ...input, items } : input;
663
+ }
664
+
527
665
  // src/stack/gaps.ts
528
666
  function refusalOf(base, fit, dragged, fixed, axis, tooWideBefore) {
529
667
  if (dragged.kind === "menu") return "to-menu";
@@ -699,6 +837,7 @@ export {
699
837
  DEFAULT_RAIL,
700
838
  controlLadder,
701
839
  cutEdges,
840
+ dividers,
702
841
  fitFloat,
703
842
  fitStack,
704
843
  formBody,
@@ -708,6 +847,9 @@ export {
708
847
  formFolded,
709
848
  formMain,
710
849
  formSetsCross,
850
+ resetBetween,
851
+ resetLengths,
852
+ resizeBetween,
711
853
  stackGaps,
712
854
  withItem,
713
855
  wrapCross,