@n-uf/placement 26.11.64 → 26.12.1
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 +65 -0
- package/dist/stack.d.ts +18 -6
- package/dist/stack.js +61 -21
- package/dist/stack.js.map +1 -1
- package/dist/tiling.d.ts +122 -29
- package/dist/tiling.js +192 -68
- package/dist/tiling.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,71 @@ 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.1
|
|
9
|
+
|
|
10
|
+
No changes in `@n-uf/placement`. Released in step with `@n-uf/motion` and `@n-uf/docking`, which share the version.
|
|
11
|
+
|
|
12
|
+
## 26.12.0
|
|
13
|
+
|
|
14
|
+
- **Changed (breaking, behavior):** `fitStack`: a stack that doesn't fit (the `overflow` note) is now drawn inside its length, so a drawn size can be
|
|
15
|
+
under its form's `main.min`: the item is *squeezed*. The length the stack lacks (the note's `over`) comes off in one
|
|
16
|
+
order:
|
|
17
|
+
1. the fixed items whose form grows (such as a title), in proportion to their `main.min`;
|
|
18
|
+
2. the other fixed items, one at a time, in the give-way order: the lowest `rank` of the form each is in first, then
|
|
19
|
+
unkept before `kept`, then the item used longest ago, then the later in the stack;
|
|
20
|
+
3. the items that take steps (movable ones, and fixed ones with `stepping`), the growing ones first, then the others
|
|
21
|
+
one at a time in the same order (of two alike in rank and `kept`, the one used longer ago is at 0 before the
|
|
22
|
+
other yields).
|
|
23
|
+
|
|
24
|
+
The gaps and padding keep their sizes, and the » entry stays whole at the end, before the end padding. Before, every
|
|
25
|
+
drawn item kept its `main.min`, and the last items and the » entry ran past the end of the stack. Forms, notes, `need`
|
|
26
|
+
and every fit without `overflow` are unchanged. **A host must now clip or ellipsize each item to its rect**, since a
|
|
27
|
+
squeezed rect is shorter than the item's content.
|
|
28
|
+
- `fitStack`: a stack shorter than its padding, gaps and » entry together (its items then all at 0) gives up the gaps
|
|
29
|
+
first, then the padding. The entry is cut to the length only when the length is under the entry's own size.
|
|
30
|
+
- `resizeBetween` and `resetBetween` leave a squeezed stack as it is: they return the same object and write no length.
|
|
31
|
+
|
|
32
|
+
### What a split needs
|
|
33
|
+
|
|
34
|
+
- **Changed (breaking, behavior): a floor is a landed length.** A side whose floor is F lands at F or more wherever
|
|
35
|
+
its split's needs and gutter fit the extent, and no net raises a need past that. Before, a side reported at F landed
|
|
36
|
+
up to half a gutter short of it. `SplitGeometry.ratio` is the ratio in effect, so the divider of a clamped split
|
|
37
|
+
moves by up to half a gutter.
|
|
38
|
+
- **Changed (breaking, behavior): a nested split's floor is what its panes need.** A side that is a split with an axis
|
|
39
|
+
needs both its sides and its gutter along that axis (where a ratio decides it with its net on, room for the net's
|
|
40
|
+
5 % as well, so its parent never squeezes it at its need), and the larger of its sides across it, down to each
|
|
41
|
+
pane's floor; a floor the host reports for the split itself counts where it is larger. `floor(child, axis, split)` is asked
|
|
42
|
+
of every node this reads, at most once per node, axis and split in a layout, `split` being the nearest split above
|
|
43
|
+
the child that runs along `axis`; where no split above a node runs along `axis`, nothing is asked and its own floor
|
|
44
|
+
is 0. A master split, and a split that takes its axis from its box, report their own floor and are not looked into.
|
|
45
|
+
- **Changed (breaking, behavior): a fixed length is taken as far as its box allows.** Along a split it takes at most
|
|
46
|
+
the extent less the gutter and its sibling's need, and comes back pixel by pixel with the room; it no longer falls
|
|
47
|
+
back to the stored ratio when it doesn't fit. Where the first side's length is not usable (0, negative, not finite),
|
|
48
|
+
the second side's is tested the same way; before, it was never read. Across a split, a length larger than the
|
|
49
|
+
split's box takes the box; it used to make the pane larger than its box.
|
|
50
|
+
- **Changed (breaking, behavior): `keep` means exact.** A kept length is cut only by its box (the extent less the
|
|
51
|
+
gutter), whatever its sibling needs; it decides its split over a fixed length that is not kept, first or second;
|
|
52
|
+
and it is its pane's need. Before, `keep` only mattered where both sides kept a length; two kept lengths that don't
|
|
53
|
+
fit now end at the split's end instead of running past it.
|
|
54
|
+
- **Changed (breaking, behavior): a split that doesn't fit is squeezed.** Where its needs and its gutter don't fit its
|
|
55
|
+
extent, both sides share the room in proportion to their needs, instead of the ratio going to 0.5. A side with no
|
|
56
|
+
floor then gets nothing, unless the net is on. Where the extent is shorter than the gutter, both sides are 0 long
|
|
57
|
+
and the second starts at the split's end. The rule that counted a room under 1 px as 1 px is gone.
|
|
58
|
+
- **Changed (breaking, behavior): the net is a need.** Where it is on (neither side's floor says `net: false`) and a
|
|
59
|
+
ratio decides the split, each side needs at least 5 % of the extent less half the gutter: the 0.05..0.95 bound while
|
|
60
|
+
the needs fit. Where a need is larger, the split is squeezed, so the larger side is no longer capped at 95 %. A split
|
|
61
|
+
a fixed length decides has no net.
|
|
62
|
+
- Without `floor` and without fixed lengths, a split lays out exactly as before.
|
|
63
|
+
- **Added: `decideSplit` and `splitNeed` in `./tiling`.** `decideSplit(extent, gutter, ratio, a, b)` is one split's
|
|
64
|
+
decision, the one the layout makes: both sides' lengths, the ratio in effect and the step that decided (`no-room`,
|
|
65
|
+
`kept`, `fixed`, `ratio`, `squeezed`). `splitNeed(tree, axis, options)` is the least length a tree lands at along an
|
|
66
|
+
axis, laid out alone: at an area that long no split is squeezed, the net on or off, except a split node to which
|
|
67
|
+
the host gives its own fixed, kept or across length shorter than its need (that length is taken as it is, the
|
|
68
|
+
splits inside it along that axis are squeezed at any size, and its panes may land under their floors).
|
|
69
|
+
`SplitGeometry` gains `step` and `needs` (the split's two side needs, what a host passes to `decideSplit`; null
|
|
70
|
+
without `floor` and for a master split).
|
|
71
|
+
- `dropFits` holds `min` to within `EPS`, so a pane that lands exactly at a floor equal to `min` passes.
|
|
72
|
+
|
|
8
73
|
## 26.11.64
|
|
9
74
|
|
|
10
75
|
- Root: `distance(r, p)`, how far a point lies from a rect (0 inside or on its edge, else the straight line to its
|
package/dist/stack.d.ts
CHANGED
|
@@ -76,7 +76,10 @@ interface WrapSpec {
|
|
|
76
76
|
readonly lead?: number;
|
|
77
77
|
}
|
|
78
78
|
type StackFormKind = PanelFormKind | GroupFormKind;
|
|
79
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Along the stack: `min` is the least it is drawn while the stack fits (a stack that doesn't, the `overflow` note, draws
|
|
81
|
+
* its items squeezed, under it: see `fitStack`), `natural` what it asks for; `grows` takes spare length.
|
|
82
|
+
*/
|
|
80
83
|
interface MainSize {
|
|
81
84
|
readonly min: number;
|
|
82
85
|
readonly natural: number;
|
|
@@ -259,8 +262,9 @@ interface StackItem {
|
|
|
259
262
|
* A fixed item is a reserved room, such as the title and the window controls of a title bar. It never gives way:
|
|
260
263
|
* it keeps its first allowed form (`forms[from]`) whatever the length or the cross size, so it is never in the » menu
|
|
261
264
|
* unless that is the form it starts in, and it doesn't take part in `previous`'s growing back. It counts toward the
|
|
262
|
-
* length like any item (the others give way around it, and a stack too short for it overflows
|
|
263
|
-
*
|
|
265
|
+
* length like any item (the others give way around it, and a stack too short for it overflows and draws it squeezed,
|
|
266
|
+
* under its least, before any item that takes steps: "never gives way" means it never leaves its form). It is never
|
|
267
|
+
* dropped: `stackGaps` refuses every gap for it, and a drop beside it never squeezes it. Whether it may sit among others (or
|
|
264
268
|
* first, or last) is the host's; placement lays out the items it is given. With `stepping` it keeps only the reserved
|
|
265
269
|
* place and takes its steps like any item.
|
|
266
270
|
*/
|
|
@@ -360,7 +364,11 @@ declare const formCompact: (f: StackForm) => boolean;
|
|
|
360
364
|
declare const formSetsCross: (f: StackForm) => boolean;
|
|
361
365
|
/** `input` with `item` inserted at index `at` (clamped to the items' range). */
|
|
362
366
|
declare function withItem(input: StackInput, item: StackItem, at: number): StackInput;
|
|
363
|
-
/**
|
|
367
|
+
/**
|
|
368
|
+
* An item drawn: the form it took, its kind and its rect (stack-local px), always inside the stack's length. One in the
|
|
369
|
+
* 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`
|
|
370
|
+
* (squeezed), down to 0, so a host clips or ellipsizes each item to its rect; a rect of no length has no hit area.
|
|
371
|
+
*/
|
|
364
372
|
interface PlacedStackItem {
|
|
365
373
|
readonly id: string;
|
|
366
374
|
/** Index into the item's `forms`. */
|
|
@@ -369,7 +377,10 @@ interface PlacedStackItem {
|
|
|
369
377
|
readonly rect: Rect;
|
|
370
378
|
}
|
|
371
379
|
interface StackMenu {
|
|
372
|
-
/**
|
|
380
|
+
/**
|
|
381
|
+
* The » entry's rect, inside the stack: at its end, before the end padding (squeezed, it starts at
|
|
382
|
+
* `length - pad.end - menu.main` while the padding is whole), and cut only when the length is under its size.
|
|
383
|
+
*/
|
|
373
384
|
readonly rect: Rect;
|
|
374
385
|
/** The items in it, in the stack's order: exactly the items in a menu form (`StackForm.menu`). */
|
|
375
386
|
readonly items: readonly string[];
|
|
@@ -384,7 +395,8 @@ interface StackMenu {
|
|
|
384
395
|
* and the app clips it.
|
|
385
396
|
* - `no-forms`: an item with no forms, left out of `items`.
|
|
386
397
|
* - `overflow`: no item can give more way and the stack is still `over` px too long (forms that don't end in a `menu`
|
|
387
|
-
* form can't give more; neither can a stack where going into the menu would only make it longer).
|
|
398
|
+
* form can't give more; neither can a stack where going into the menu would only make it longer). The stack is then
|
|
399
|
+
* drawn squeezed, inside its length, and `over` is what its items, then its gaps, padding and » entry gave up.
|
|
388
400
|
*/
|
|
389
401
|
type StackNote = {
|
|
390
402
|
readonly code: "form-down";
|
package/dist/stack.js
CHANGED
|
@@ -167,21 +167,21 @@ var mainOf = formMain;
|
|
|
167
167
|
var crossMin = formCrossMin;
|
|
168
168
|
var crossNatural = (f) => f.wrap ? wrapCross(f.wrap).natural : finite2(f.cross.natural);
|
|
169
169
|
var rankOf = (f) => finite2(f.rank ?? 0);
|
|
170
|
+
function givesWayBefore(items, a, ra, b, rb) {
|
|
171
|
+
if (ra !== rb) return ra - rb;
|
|
172
|
+
const ka = items[a].kept ? 1 : 0;
|
|
173
|
+
const kb = items[b].kept ? 1 : 0;
|
|
174
|
+
if (ka !== kb) return ka - kb;
|
|
175
|
+
const ua = items[a].used;
|
|
176
|
+
const ub = items[b].used;
|
|
177
|
+
if (ua !== ub) return ua < ub ? -1 : 1;
|
|
178
|
+
return b - a;
|
|
179
|
+
}
|
|
170
180
|
function victim(items, to) {
|
|
171
181
|
let best = -1;
|
|
172
182
|
for (let i = 0; i < items.length; i++) {
|
|
173
183
|
if (to[i] < 0 || !itemSteps(items[i])) continue;
|
|
174
|
-
if (best < 0)
|
|
175
|
-
best = i;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const a = items[i];
|
|
179
|
-
const b = items[best];
|
|
180
|
-
const ra = rankOf(a.forms[to[i]]);
|
|
181
|
-
const rb = rankOf(b.forms[to[best]]);
|
|
182
|
-
const ka = a.kept ? 1 : 0;
|
|
183
|
-
const kb = b.kept ? 1 : 0;
|
|
184
|
-
if (ra !== rb ? ra < rb : ka !== kb ? ka < kb : a.used !== b.used ? a.used < b.used : true) best = i;
|
|
184
|
+
if (best < 0 || givesWayBefore(items, i, rankOf(items[i].forms[to[i]]), best, rankOf(items[best].forms[to[best]])) < 0) best = i;
|
|
185
185
|
}
|
|
186
186
|
return best;
|
|
187
187
|
}
|
|
@@ -320,13 +320,7 @@ function solve(input, previous, seed, grow = false) {
|
|
|
320
320
|
};
|
|
321
321
|
if (seed) seed.need = minSumWith(false);
|
|
322
322
|
if (grow) {
|
|
323
|
-
const comesBefore = (a, b) =>
|
|
324
|
-
const ra = rankOf(items[a].forms[at[a]]);
|
|
325
|
-
const rb = rankOf(items[b].forms[at[b]]);
|
|
326
|
-
const ka = items[a].kept ? 1 : 0;
|
|
327
|
-
const kb = items[b].kept ? 1 : 0;
|
|
328
|
-
return ra !== rb ? ra > rb : ka !== kb ? ka > kb : items[a].used !== items[b].used ? items[a].used > items[b].used : a < b;
|
|
329
|
-
};
|
|
323
|
+
const comesBefore = (a, b) => givesWayBefore(items, b, rankOf(items[b].forms[at[b]]), a, rankOf(items[a].forms[at[a]])) < 0;
|
|
330
324
|
const index = new Map(items.map((it, i) => [it.id, i]));
|
|
331
325
|
let stuck = false;
|
|
332
326
|
const undoes = (n, c0) => {
|
|
@@ -487,6 +481,51 @@ function solve(input, previous, seed, grow = false) {
|
|
|
487
481
|
tight = t;
|
|
488
482
|
for (const i of drawn) size.set(i, min(i) + (nat(i) - min(i)) * t);
|
|
489
483
|
}
|
|
484
|
+
let gap = sp.gap;
|
|
485
|
+
let padStart = sp.start;
|
|
486
|
+
let padEnd = sp.end;
|
|
487
|
+
let entry = menuSize;
|
|
488
|
+
let short = overflow > EPS ? overflow : 0;
|
|
489
|
+
if (short > 0) {
|
|
490
|
+
tight = 0;
|
|
491
|
+
const share = (group) => {
|
|
492
|
+
const have = group.reduce((s, i) => s + size.get(i), 0);
|
|
493
|
+
if (short <= 0 || have <= EPS) return;
|
|
494
|
+
const take = Math.min(short, have);
|
|
495
|
+
for (const i of group) size.set(i, size.get(i) * (1 - take / have));
|
|
496
|
+
short -= take;
|
|
497
|
+
};
|
|
498
|
+
const oneByOne = (group) => {
|
|
499
|
+
const order = [...group].sort((a, b) => givesWayBefore(items, a, rankOf(form(a)), b, rankOf(form(b))));
|
|
500
|
+
for (const i of order) {
|
|
501
|
+
if (short <= 0) return;
|
|
502
|
+
const take = Math.min(short, size.get(i));
|
|
503
|
+
size.set(i, size.get(i) - take);
|
|
504
|
+
short -= take;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const grows = (i) => form(i).main.grows === true;
|
|
508
|
+
const reserved = drawn.filter((i) => !itemSteps(items[i]));
|
|
509
|
+
const movable = drawn.filter((i) => itemSteps(items[i]));
|
|
510
|
+
share(reserved.filter(grows));
|
|
511
|
+
oneByOne(reserved.filter((i) => !grows(i)));
|
|
512
|
+
share(movable.filter(grows));
|
|
513
|
+
oneByOne(movable.filter((i) => !grows(i)));
|
|
514
|
+
const gaps = Math.max(0, drawn.length + (inMenu() ? 1 : 0) - 1);
|
|
515
|
+
if (short > 0 && gaps > 0 && gap > 0) {
|
|
516
|
+
const take = Math.min(short, gaps * gap);
|
|
517
|
+
gap -= take / gaps;
|
|
518
|
+
short -= take;
|
|
519
|
+
}
|
|
520
|
+
if (short > 0 && padStart + padEnd > 0) {
|
|
521
|
+
const pads = padStart + padEnd;
|
|
522
|
+
const take = Math.min(short, pads);
|
|
523
|
+
padStart -= take * padStart / pads;
|
|
524
|
+
padEnd -= take * padEnd / pads;
|
|
525
|
+
short -= take;
|
|
526
|
+
}
|
|
527
|
+
if (short > 0 && inMenu()) entry = Math.max(0, entry - short);
|
|
528
|
+
}
|
|
490
529
|
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 };
|
|
491
530
|
const acrossOf = (i) => {
|
|
492
531
|
const f = form(i);
|
|
@@ -495,13 +534,13 @@ function solve(input, previous, seed, grow = false) {
|
|
|
495
534
|
return Math.min(cross, Math.max(0, finite2(f.cross.natural, cross)));
|
|
496
535
|
};
|
|
497
536
|
const rects = /* @__PURE__ */ new Map();
|
|
498
|
-
let cursor =
|
|
537
|
+
let cursor = padStart;
|
|
499
538
|
for (const i of drawn) {
|
|
500
539
|
const s = size.get(i);
|
|
501
540
|
rects.set(i, rectAt(cursor, s, acrossOf(i)));
|
|
502
|
-
cursor += s +
|
|
541
|
+
cursor += s + gap;
|
|
503
542
|
}
|
|
504
|
-
const menuRect = rectAt(Math.max(drawn.length > 0 ? cursor : sp.start, length - sp.end - menuSize), menuSize);
|
|
543
|
+
const menuRect = overflow > EPS ? rectAt(length - padEnd - entry, entry) : rectAt(Math.max(drawn.length > 0 ? cursor : sp.start, length - sp.end - menuSize), menuSize);
|
|
505
544
|
const inside = idx.filter((i) => isMenu(form(i)));
|
|
506
545
|
const menu = inside.length > 0 ? { rect: menuRect, items: inside.map((i) => items[i].id) } : null;
|
|
507
546
|
const placed = idx.map((i) => ({ id: items[i].id, form: at[i], kind: form(i).kind, rect: isMenu(form(i)) ? menuRect : rects.get(i) }));
|
|
@@ -605,6 +644,7 @@ function written(input, fit, all, to) {
|
|
|
605
644
|
}
|
|
606
645
|
function trade(input, before, after, options, to) {
|
|
607
646
|
const fit = fitStack(input, options);
|
|
647
|
+
if (fit.notes.some((n) => n.code === "overflow")) return input;
|
|
608
648
|
const all = growers(input, fit);
|
|
609
649
|
const ends = pair(all, before, after);
|
|
610
650
|
if (!ends) return input;
|