@n-uf/placement 26.11.30 → 26.11.31

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,33 @@
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`: both packages carry the same version, and a release bumps both.
5
5
 
6
+ ## 26.11.31
7
+
8
+ - `./scene`, fixed: **a float that already covered a bar grew over it when resized.** `fitResize` stopped a growing edge
9
+ at the nearest obstacle beyond it, and skipped one the float already overlapped, so a float with no clear place at its
10
+ size (a short window, a tall `floatMin`) that lay 8 px over a toolbar went on over the bar, the chrome or a docked item
11
+ when its top, or any edge, was dragged outward. An edge that lies inside an obstacle now stays where it is drawn
12
+ (`"docked"`): a resize never covers more than the float did, and a float clear of everything stops at the obstacle, as
13
+ before. The property test covers both (no float overlaps a bar, chrome or docked item after `resize`; a covering one
14
+ covers no more).
15
+ - `./scene`, **an edge's items in order** (additive): `SceneEdgeLayout.items`, the ids the layout draws for the edge in its
16
+ stack order: the zones in order (start, center, end), then the order within each zone. An item in the » menu keeps its
17
+ place (`menu.items` names those), a rail tab is listed, a closed item is left out; a column folded into its rail or
18
+ riding lists its members in zone order. Nothing like it existed (`stack.items` is the solver's, in stack-local px and
19
+ not meant for hosts), so a host sorted rects; it no longer needs to. `mapLayout` in `./scene/cases` maps it with the
20
+ host's ids.
21
+ - `./scene`, **`stops()` is remembered per scene** (no API change): a scene is an immutable value, so the stops of an item
22
+ of one scene object with the same options are solved once; asking again (a menu redrawn, a kit asking on every render)
23
+ costs a lookup. A `WeakMap` keyed by the scene, then by item and options (by value, `previous` by identity). Each call
24
+ still returns a new array, over the same targets. A first call costs what it did (the solves are one per slot, and an
25
+ item's slots are its own, so a `stopsForAll` could share only the scene's own solve).
26
+ - `./scene`, **why an item is folded** (additive): `SceneItemLayout.foldedBy`, `"hand" | "auto"`, set from the scene's own
27
+ state, never inferred from rects. `"hand"`: the item's `from` is over 0 (`fold` sets it), whatever else gave way after;
28
+ `"auto"`: it gave way, a form below the one it started in, by length or width (a header, an icons form, a » menu entry, a
29
+ rail segment of a column folded by give-way; `"auto"` is the word `folded` already uses for give-way). Absent for an item
30
+ in its first form, a closed one, and the form an icons-only edge gives its items. A float is only ever `"hand"`. A host
31
+ shows "Expand" for `"hand"` only. `folded` still names the item's column.
32
+
6
33
  ## 26.11.30
7
34
 
8
35
  - `./scene`, fixed: **an occupied rail offered the same move twice.** With a side's tiles width-folded and an item dragged,
package/README.md CHANGED
@@ -803,6 +803,17 @@ wider than the room the cut leaves. Group forms in a column take their own width
803
803
  span it. Spare room goes to the forms that grow, so a column's open panels share its height through `grows` and equal
804
804
  naturals. A column where nothing sets the width is a rail: its items that have a `rail` form take it and are listed in
805
805
  `edges[id].tabs` (with `railShowsClosed`, closed items too, marked `closed`); the host draws tabs only from the layout.
806
+ `edges[id].items` lists the ids the layout draws for the edge in its stack order: the zones in order (start, center,
807
+ end), then the order within each zone. An item in the » menu keeps its place (`menu.items` names those), a rail tab is
808
+ listed, a closed item is left out, and a column folded into its rail or riding lists its members in zone order. A host
809
+ that needs the order reads it here instead of sorting rects (`stack.items` is the solver's own, in stack-local px).
810
+
811
+ **Why an item is folded.** `SceneItemLayout.foldedBy` says whether the user folded an item or it gave way, from the scene's
812
+ own state and never from rects: `"hand"` when the item's `from` is over 0 (`fold` sets it), whatever else gave way after;
813
+ `"auto"` when it gave way, a form below the one it started in, by length or width (a header, an icons form, a » menu
814
+ entry, a rail segment of a column folded by give-way). It is absent for an item in its first form, a closed one, and
815
+ the form an icons-only edge gives its items; a float is only ever `"hand"`. A host shows "Expand" for `"hand"` only, since
816
+ unfolding an item that gave way is not the user's to do. `folded` still names the item's column.
806
817
 
807
818
  **Rail titles.** A panel may declare two rail forms: its title (`{ kind: "rail", title: true }`, its `main` the length
808
819
  of its name and count turned along the rail, measured by the host) and then its tile (a plain `rail` form). In a rail
@@ -1008,7 +1019,9 @@ shrink below the size drawn now, as `solve` lays it) and `floatMax`, the float i
1008
1019
  growing edge at what floats are kept clear of (a bar, a docked item, the chrome; such a stop beats the minimum). It
1009
1020
  then lays the rect through the one clamp `solve` lays floats with, so `solve` lays the result exactly there. A float
1010
1021
  that already covers something (no clear place at its size) may move to a clear place once a resize opens one; the
1011
- preview is still the commit. It gives `{ rect, limits }`, `limits` naming what bound it:
1022
+ preview is still the commit. Such a float never grows over what it covers: a dragged edge that lies inside an obstacle
1023
+ stays where it is drawn (`"docked"`), so a resize never covers more than the float did, and a float clear of everything
1024
+ stops at the obstacle as before. It gives `{ rect, limits }`, `limits` naming what bound it:
1012
1025
  `"min"`, `"max"`, `"region"`, `"docked"`. It gives null for anything but a float drawn at a first form that grows (a
1013
1026
  panel's card): a toolbar group's size and a folded float's bar come from their forms. On commit (each move, or the
1014
1027
  release) `resize(scene, id, rect, moving)` stores that same rect as the float's rect and the item's `floatSize`, so the
@@ -1220,7 +1233,11 @@ overflows (or holds an item already too wide), a drop that adds no new note is a
1220
1233
  item that was already squeezed.
1221
1234
 
1222
1235
  `stops(scene, id)` gives the same targets, home and none left out, in reading order (the left side outer to inner, the
1223
- top bars, the bottom bars, the right side inner to outer, floating last) for "Move to ›" and the arrow keys.
1236
+ top bars, the bottom bars, the right side inner to outer, floating last) for "Move to ›" and the arrow keys. A scene is
1237
+ an immutable value, so `stops` remembers its answer per scene object: the stops of an item of one scene object with the
1238
+ same options (`previous` by identity) are solved once, and asking again (a menu redrawn, a host asking on every render)
1239
+ costs a lookup. Each call still returns a new array over the same targets. Pass a changed scene (a new object) to get
1240
+ fresh stops; mutating a scene in place is not supported.
1224
1241
 
1225
1242
  Each target's `after(point, grab)` is `{ scene, layout }`: the scene to commit (the item moved and just used) and
1226
1243
  `solve(scene, { previous })`. The host draws every item from `after.layout` during the preview and commits
@@ -96,6 +96,12 @@ function floatSizeOf(item, orient2 = floatOrientOf(item)) {
96
96
  if (main <= 0 || cross <= 0) return DEFAULT_FLOAT_SIZE;
97
97
  return orient2 === "row" ? { width: main, height: cross } : { width: cross, height: main };
98
98
  }
99
+ function foldedByOf(item, form, start) {
100
+ if (item.closed || form < 1) return void 0;
101
+ if (foldedByHand(item)) return "hand";
102
+ return start !== void 0 && form > start ? "auto" : void 0;
103
+ }
104
+ var foldedByHand = (item) => Number.isFinite(item.from) && Math.floor(item.from) >= 1;
99
105
  function pastWrap(forms, from) {
100
106
  for (let j = Math.max(0, Math.floor(from)); j < forms.length; j++) if (forms[j].kind !== "wrap" && !forms[j].wrap) return j;
101
107
  return void 0;
@@ -329,6 +335,7 @@ function emit(d, edge, r, solved, extra = {}) {
329
335
  const drawnRect = toStage(p.rect, inMenu ? void 0 : p.id);
330
336
  const f = formsOf(it, column ? "column" : "row")[p.form];
331
337
  const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? "column" : "row", stack.cross);
338
+ const foldedBy = foldedByOf(it, p.form, solved.starts.get(p.id));
332
339
  items[p.id] = {
333
340
  ...shape,
334
341
  hidden: inMenu ? [] : f?.hides ?? [],
@@ -342,6 +349,7 @@ function emit(d, edge, r, solved, extra = {}) {
342
349
  ...tabs.has(p.id) ? { tab: true } : {},
343
350
  ...tabs.has(p.id) && f?.title === true && (edge.side === "left" || edge.side === "right") ? { railTitle: edge.side } : {},
344
351
  ...solved.closedTabs.has(p.id) ? { closed: true } : {},
352
+ ...foldedBy ? { foldedBy } : {},
345
353
  ...it.fixed ? { fixed: true } : {}
346
354
  };
347
355
  }
@@ -352,6 +360,8 @@ function emit(d, edge, r, solved, extra = {}) {
352
360
  rect: r,
353
361
  cross: thick,
354
362
  menu: stack.menu ? { rect: toStage(stack.menu.rect), items: stack.menu.items } : null,
363
+ // The stack's items are in zone order, the order `emit` drew them in.
364
+ items: stack.items.map((p) => p.id),
355
365
  tabs: solved.tabs,
356
366
  stack,
357
367
  free: solved.free,
@@ -372,6 +382,7 @@ function hasSetter(fit, forms) {
372
382
  return fit.items.some((p) => p.kind !== "menu" && formSetsCross(forms(p.id)[p.form]));
373
383
  }
374
384
  var TRAY_RANK = 100;
385
+ var startsOf = (input) => new Map(input.items.map((i) => [i.id, i.from ?? 0]));
375
386
  function compactEdge(f) {
376
387
  const { scene, formsById } = f;
377
388
  const iconsAt = (id) => {
@@ -383,9 +394,9 @@ function compactEdge(f) {
383
394
  const leftOutIcons = f.ordered.filter((id) => !scene.items[id].closed && iconsAt(id) < 0);
384
395
  const compactInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(scene.items[id], formsById(id), iconsAt(id))) };
385
396
  const stack = fitStack(compactInput, f.previous ? { previous: f.previous.free } : {});
386
- return { stack, free: stack, tabs: [], closedTabs: /* @__PURE__ */ new Set(), input: compactInput, leftOutIcons };
397
+ return { stack, free: stack, tabs: [], closedTabs: /* @__PURE__ */ new Set(), input: compactInput, starts: startsOf(compactInput), leftOutIcons };
387
398
  }
388
- function railEdge(f, free, asStackItem) {
399
+ function railEdge(f, free, asStackItem, starts) {
389
400
  const { scene, edge, formsById } = f;
390
401
  const railIndex = (item, forms) => {
391
402
  if (item.fixed) return -1;
@@ -415,7 +426,7 @@ function railEdge(f, free, asStackItem) {
415
426
  const stack = fitStack(railInput, f.previous ? { previous: f.previous.stack } : {});
416
427
  const tabs = stack.items.filter((p) => p.kind === "rail").map((p) => p.id);
417
428
  const closedTabs = new Set(shown.filter((id) => scene.items[id].closed));
418
- return { stack, free, tabs, closedTabs, input: railInput, leftOut };
429
+ return { stack, free, tabs, closedTabs, input: railInput, starts, leftOut };
419
430
  }
420
431
  function solveEdge(scene, edge, ids, length, room, previous) {
421
432
  const axis = axisOf(edge.side);
@@ -458,8 +469,9 @@ function solveEdge(scene, edge, ids, length, room, previous) {
458
469
  const input = { ...base, items: open2.map(asStackItem) };
459
470
  const free = fitStack(input, previous ? { previous: previous.free } : {});
460
471
  const none = /* @__PURE__ */ new Set();
472
+ const starts = startsOf(input);
461
473
  if (column && !hasSetter(free, formsById)) {
462
- const rail = railEdge(frame, free, asStackItem);
474
+ const rail = railEdge(frame, free, asStackItem, starts);
463
475
  if (rail) return rail;
464
476
  }
465
477
  const size = edge.size;
@@ -470,10 +482,10 @@ function solveEdge(scene, edge, ids, length, room, previous) {
470
482
  if (Math.abs(s - free.cross) > EPS) {
471
483
  const sized = { ...input, cross: { ...cross, min: s, max: s } };
472
484
  const stack = fitStack(sized, previous ? { previous: previous.stack } : {});
473
- return { stack, free, tabs: [], closedTabs: none, input: sized };
485
+ return { stack, free, tabs: [], closedTabs: none, input: sized, starts };
474
486
  }
475
487
  }
476
- return { stack: free, free, tabs: [], closedTabs: none, input };
488
+ return { stack: free, free, tabs: [], closedTabs: none, input, starts };
477
489
  }
478
490
 
479
491
  // src/scene/solve/bars.ts
@@ -556,7 +568,8 @@ function layFloats(d, stage, content, inset) {
556
568
  if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
557
569
  if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
558
570
  if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
559
- items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), hidden: form?.hides ?? [], rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? "open", floating: true };
571
+ const foldedBy = foldedByOf(it, from);
572
+ items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), hidden: form?.hides ?? [], rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? "open", floating: true, ...foldedBy ? { foldedBy } : {} };
560
573
  floats.push(f.id);
561
574
  }
562
575
  return floats;
@@ -749,10 +762,10 @@ function layRiders(d, host, riders, top) {
749
762
  for (const b of bars) {
750
763
  const at = rect(hr.x, y, hr.width, b.h);
751
764
  const it = scene.items[b.id];
752
- items[b.id] = { rect: at, hidden: b.f?.hides ?? [], kind: it.kind, form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand" };
765
+ items[b.id] = { rect: at, hidden: b.f?.hides ?? [], kind: it.kind, form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand", foldedBy: "hand" };
753
766
  y += b.h;
754
767
  }
755
- edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: "hand" };
768
+ edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, items: bars.map((b) => b.id), tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: "hand" };
756
769
  }
757
770
  }
758
771
  function layRail(d, side, railRect, railed, g) {
@@ -794,7 +807,7 @@ function layRail(d, side, railRect, railed, g) {
794
807
  const form = p ? p.form : ri >= 0 ? ri : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1));
795
808
  const at = p ? rect(railRect.x, railRect.y + p.rect.y, railRect.width, p.rect.height) : rect(railRect.x, y, railRect.width, ri >= 0 ? px(forms[ri].main.natural) : railRect.width);
796
809
  const title = forms[form]?.title === true;
797
- items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand" };
810
+ items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand", foldedBy: foldedByHand(it) ? "hand" : "auto" };
798
811
  segments.push({ id, edge: c.edge.id, rect: at });
799
812
  y += at.height;
800
813
  }
@@ -851,7 +864,7 @@ function laySide(d, side, cols, g, area2, f, walk, upInset, tall) {
851
864
  }
852
865
  }
853
866
  if (outsideSideBar(c)) barLaid = true;
854
- const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free };
867
+ const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, items: zoneSorted(scene, c.visible), tabs: [], stack: c.solved.stack, free: c.solved.free };
855
868
  if (g.railed(c)) {
856
869
  edges[c.edge.id] = { ...base, rect: rect(railRect.x, area2.y, 0, H), folded: g.auto.has(c) ? "auto" : "hand" };
857
870
  continue;
@@ -946,8 +959,16 @@ function obstacleStop(drawn, obstacles, axis, drag, span) {
946
959
  for (const o of obstacles) {
947
960
  const [c0, c1] = across2(o);
948
961
  if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
949
- if (drag === "start" && lo(o) + len(o) <= lo(drawn) + EPS2) at = Math.max(at, lo(o) + len(o));
950
- if (drag === "end" && lo(o) >= lo(drawn) + len(drawn) - EPS2) at = Math.min(at, lo(o));
962
+ const begin = lo(o);
963
+ const finish = begin + len(o);
964
+ const edge = drag === "start" ? lo(drawn) : lo(drawn) + len(drawn);
965
+ if (drag === "start") {
966
+ if (finish <= edge + EPS2) at = Math.max(at, finish);
967
+ else if (begin < edge - TOUCH) at = edge;
968
+ } else {
969
+ if (begin >= edge - EPS2) at = Math.min(at, begin);
970
+ else if (finish > edge + TOUCH) at = edge;
971
+ }
951
972
  }
952
973
  return drag === "start" ? Math.min(at, lo(drawn)) : Math.max(at, lo(drawn) + len(drawn));
953
974
  }
@@ -2526,6 +2547,29 @@ function refusals(scene, dragged, options = {}) {
2526
2547
  }
2527
2548
  var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
2528
2549
  function stops(scene, dragged, options = {}) {
2550
+ const key = stopsKey(dragged, options);
2551
+ let memo = stopsMemo.get(scene);
2552
+ if (!memo) stopsMemo.set(scene, memo = /* @__PURE__ */ new Map());
2553
+ let list = memo.get(key);
2554
+ if (!list) {
2555
+ if (memo.size >= STOPS_PER_SCENE) memo.clear();
2556
+ memo.set(key, list = orderedStops(scene, dragged, options));
2557
+ }
2558
+ return [...list];
2559
+ }
2560
+ var stopsMemo = /* @__PURE__ */ new WeakMap();
2561
+ var STOPS_PER_SCENE = 512;
2562
+ var layoutIds = /* @__PURE__ */ new WeakMap();
2563
+ var nextLayoutId = 0;
2564
+ function stopsKey(dragged, o) {
2565
+ let prev = null;
2566
+ if (o.previous) {
2567
+ prev = layoutIds.get(o.previous) ?? nextLayoutId++;
2568
+ layoutIds.set(o.previous, prev);
2569
+ }
2570
+ return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);
2571
+ }
2572
+ function orderedStops(scene, dragged, options) {
2529
2573
  const list = targets(scene, dragged, options).filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
2530
2574
  const sideOf = (t) => {
2531
2575
  const p = t.place;
@@ -2590,4 +2634,4 @@ export {
2590
2634
  refusals,
2591
2635
  stops
2592
2636
  };
2593
- //# sourceMappingURL=chunk-5CSWQSH7.js.map
2637
+ //# sourceMappingURL=chunk-COK4YNMF.js.map