@n-uf/placement 26.11.38 → 26.11.40

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,39 @@
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.40
7
+
8
+ - `./scene`, **a drop names a zone only where the edge offers a choice** (behavior change). A gap drop, a strip, or
9
+ `moveTo` with `zone` sets the item's `align` only when more than one zone of that edge takes its kind (`namesZone`,
10
+ new). On a one-zone edge, such as a rail that takes groups at its start only, the item docks in that zone and keeps
11
+ its own `align`. So a group from a bar's end zone, dropped on such a rail while it is drawn and lent back to the bar
12
+ through `showIn` once the rail is hidden, lies in the bar's end zone again, not its start. A rail whose zones all
13
+ take the kind (no `zoneAccepts`) still offers the choice, and a drop on it sets the zone; a host that wants its rail
14
+ to keep the groups' own zones declares `zoneAccepts: { start: [kind] }` on it. That declaration also changes the
15
+ rail's targets: its center and end gaps for that kind go, and those thirds give `not-accepted` refusals instead.
16
+ Layouts, targets and refusals are otherwise as before; only stored `align` after a drop into a one-zone edge changes.
17
+
18
+ ## 26.11.39
19
+
20
+ - `./scene/cases`, **conformance row C17 requires the scene's own rail drop.** C17 now carries
21
+ `requires: { railDrop: "scene" }`, so a host that lays its own rail strips skips it, as it does the other rows whose
22
+ pixels depend on the scene's rail drop strips.
23
+
24
+ - `./scene`, **an item's zone is its own** (behavior change). A move sets `align` only when the drop names a zone (a
25
+ gap in a zone, a zone's slot, `moveTo` with `zone`); a rail, a new column, home, `dockHome` (the start scene's
26
+ `align`) and `moveTo` with no `zone` keep it. Before, a move to a rail stored the rail's start zone, so a group from a
27
+ bar's end zone, docked on a rail and later lent back to that bar through `showIn`, landed in its start cluster. An
28
+ item lies in its own zone where its edge takes it there, else in the first zone that does (`zoneIn`), one rule for
29
+ every edge and for lent items; its stored `align` is unchanged. Scenes whose items all lie in zones their edges take
30
+ lay out, target and store exactly as before. An item stored in a zone its edge doesn't take (a group with no `align`
31
+ in a column whose start zone takes only panels) now lies in the first zone that takes it, the column's tray, where it
32
+ lay among the panels before; `zoneExtents` and the gaps count it there. For a host this shows when it adds
33
+ `zoneAccepts` (a tray or deck) to a column whose stored scenes already hold groups with no `align`: on upgrade those
34
+ groups move from the start cluster to the tray at the column's foot, and that column's gap ids change
35
+ (`gap:<col>:end:0` appears). The stored scene is unchanged by reading and storing it. To know where an item lies, read
36
+ `SceneItemLayout.zone`, not `scene.items[id].align`, since the two can now differ; a host that wants to rewrite its
37
+ stored scenes can set each item's `align` to `zoneIn(edge, item)` (exported).
38
+
6
39
  ## 26.11.38
7
40
 
8
41
  - `./scene`, **`Edge.showIn`** (additive): a hidden edge that names another, static edge lends it its items, which lay
package/README.md CHANGED
@@ -872,9 +872,21 @@ Hits, clicks, drags and `after()` work as for the tile, at the title's length.
872
872
  `Edge.size` is the user's size across, clamped to the widest open setter's `cross.min` (and the edge's `cross.min`) at
873
873
  least and `cross.max` at most; `resize` sets it.
874
874
 
875
- **Zones.** An item's `align` (`start`, the default, `center` or `end`) is its zone in its edge. Give-way is as without
876
- zones (it sums the minimum sizes); when room is spare, start items pack from the start, end items from the end (before
877
- the » entry) and center items sit on the edge's middle, moved only as far as they must to stay between the other two.
875
+ **Zones.** An item's `align` (`start`, the default, `center` or `end`) is its zone, a fact of the item, not of the
876
+ edge it lies in. It lies in that zone where its edge takes its kind there (`Edge.zoneAccepts`), else in the first zone
877
+ that does (`zoneIn`, one rule for every edge and for the items a hidden edge lends through `showIn`); its stored
878
+ `align` stays as it was, so it is back in its own zone on an edge that takes it there. A move sets `align` only when the
879
+ drop names a zone: a gap in a zone, a zone's slot, `moveTo` with `zone`, on an edge that offers a choice (`namesZone`:
880
+ more than one of its zones takes the kind). On a one-zone edge, such as a rail that takes groups at its start only, the
881
+ zone a drop gives is no choice: the item docks there and keeps its own, so a group from a bar's end zone moved onto
882
+ that rail goes back to the bar's end zone when the rail is hidden and lends it back (`showIn`), or when it is moved
883
+ there with no zone. An edge with no `zoneAccepts` takes every kind in every zone, so it offers the choice; declaring
884
+ `zoneAccepts: { start: [kind] }` makes it a one-zone edge for that kind, which also removes its center and end gaps for
885
+ the kind and refuses those thirds (`not-accepted`). A move whose zone is implied keeps it: a rail,
886
+ a new column, home and `dockHome` (which takes the start scene's `align` back), `moveTo` with no `zone`. Give-way is as
887
+ without zones (it sums the minimum sizes); when room is spare, start items pack from the start, end items from the end
888
+ (before the » entry) and center items sit on the edge's middle, moved only as far as they must to stay between the
889
+ other two.
878
890
 
879
891
  **Bar alignment zones.** A horizontal bar picks the zone of a drop by thirds of its length: a pointer in the left third
880
892
  is over the leading zone (`start`), in the middle third over the center zone, in the right third over the trailing zone
@@ -59,42 +59,59 @@ function railColumnOf(scene, side, kind) {
59
59
  if (scene.rails?.[side]) return void 0;
60
60
  return scene.edges.filter((e) => e.side === side && !e.compact && e.hidden !== true && zoneTakes(e, "start", kind)).reduce((m, e) => !m || e.ring < m.ring ? e : m, void 0);
61
61
  }
62
+ function zoneIn(edge, item) {
63
+ const own = zoneOf(item);
64
+ if (item.fixed || zoneTakes(edge, own, item.kind)) return own;
65
+ return zonesTaking(edge, item.kind)[0] ?? own;
66
+ }
67
+ var namesZone = (edge, kind) => zonesTaking(edge, kind).length > 1;
62
68
  var showInOf = (scene, e) => {
63
69
  if (e.hidden !== true || e.showIn === void 0) return void 0;
64
70
  const to = scene.edges.find((x) => x.id === e.showIn);
65
71
  return to && to !== e && to.hidden !== true && to.column !== true ? to : void 0;
66
72
  };
67
73
  function viewOf(scene) {
68
- if (!scene.edges.some((e) => e.hidden === true)) return { view: scene, lent: /* @__PURE__ */ new Map(), ignored: [] };
69
74
  const lent = /* @__PURE__ */ new Map();
70
75
  const ignored = [];
71
76
  const added = /* @__PURE__ */ new Map();
72
- const items = { ...scene.items };
73
- for (const e of scene.edges) {
74
- if (e.hidden !== true || e.showIn === void 0) continue;
75
- const to = showInOf(scene, e);
76
- if (!to) {
77
- ignored.push(e.id);
78
- continue;
77
+ const hidden = scene.edges.some((e) => e.hidden === true);
78
+ if (hidden) {
79
+ for (const e of scene.edges) {
80
+ if (e.hidden !== true || e.showIn === void 0) continue;
81
+ const to = showInOf(scene, e);
82
+ if (!to) {
83
+ ignored.push(e.id);
84
+ continue;
85
+ }
86
+ for (const id of e.items) {
87
+ const item = Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
88
+ if (!item || item.fixed || lent.has(id) || to.items.includes(id) || !edgeTakes(to, item.kind)) continue;
89
+ lent.set(id, e.id);
90
+ added.set(to.id, [...added.get(to.id) ?? [], id]);
91
+ }
79
92
  }
93
+ }
94
+ const edges = hidden ? scene.edges.filter((e) => e.hidden !== true).map((e) => added.has(e.id) ? { ...e, items: [...e.items, ...added.get(e.id)] } : e) : scene.edges;
95
+ const rezoned = /* @__PURE__ */ new Set();
96
+ let items;
97
+ for (const e of edges) {
80
98
  for (const id of e.items) {
81
99
  const item = Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
82
- if (!item || item.fixed || lent.has(id) || to.items.includes(id) || !edgeTakes(to, item.kind)) continue;
83
- lent.set(id, e.id);
84
- added.set(to.id, [...added.get(to.id) ?? [], id]);
85
- if (!zoneTakes(to, zoneOf(item), item.kind)) {
86
- const zone = zonesTaking(to, item.kind)[0];
87
- const { align: _a, ...plain } = item;
88
- items[id] = zone === "start" ? plain : { ...plain, align: zone };
89
- }
100
+ if (!item) continue;
101
+ const zone = zoneIn(e, item);
102
+ if (zone === zoneOf(item)) continue;
103
+ const { align: _a, ...plain } = item;
104
+ items ??= { ...scene.items };
105
+ items[id] = zone === "start" ? plain : { ...plain, align: zone };
106
+ rezoned.add(id);
90
107
  }
91
108
  }
92
- const edges = scene.edges.filter((e) => e.hidden !== true).map((e) => added.has(e.id) ? { ...e, items: [...e.items, ...added.get(e.id)] } : e);
93
- return { view: { ...scene, edges, ...lent.size > 0 ? { items } : {} }, lent, ignored };
109
+ if (!hidden && !items) return { view: scene, lent, ignored, rezoned };
110
+ return { view: { ...scene, edges, ...items ? { items } : {} }, lent, ignored, rezoned };
94
111
  }
95
112
  var inHiddenEdge = (scene, id) => scene.edges.some((e) => e.hidden === true && e.items.includes(id));
96
- function withHiddenOf(scene, shown, lent = /* @__PURE__ */ new Map(), moved, zoned = false) {
97
- if (shown === scene || !scene.edges.some((e) => e.hidden === true)) return shown;
113
+ function withHiddenOf(scene, shown, lent = /* @__PURE__ */ new Map(), moved, zoned = false, rezoned = /* @__PURE__ */ new Set()) {
114
+ if (shown === scene) return shown;
98
115
  const back = [...lent.keys()].filter((id) => id !== moved);
99
116
  const edges = shown.edges.filter((e) => e.hidden !== true).map((e) => back.some((id) => e.items.includes(id)) ? { ...e, items: e.items.filter((id) => !back.includes(id)) } : e);
100
117
  scene.edges.forEach((e, i) => {
@@ -103,15 +120,14 @@ function withHiddenOf(scene, shown, lent = /* @__PURE__ */ new Map(), moved, zon
103
120
  edges.splice(Math.min(i, edges.length), 0, own);
104
121
  });
105
122
  const items = back.length > 0 ? { ...shown.items, ...Object.fromEntries(back.map((id) => [id, scene.items[id]])) } : { ...shown.items };
106
- if (moved !== void 0 && lent.has(moved) && !zoned) {
107
- const was = scene.items[moved];
108
- const now = items[moved];
109
- const edge = edges.find((e) => e.hidden !== true && e.items.includes(moved));
110
- const zone = !edge || zoneTakes(edge, zoneOf(was), was.kind) ? zoneOf(was) : zoneOf(now);
111
- if (zone !== zoneOf(now) || !edge && now.align !== was.align) {
112
- const { align: _a, ...plain } = now;
113
- items[moved] = !edge ? was.align === void 0 ? plain : { ...plain, align: was.align } : zone === "start" ? plain : { ...plain, align: zone };
114
- }
123
+ const keep2 = new Set([...rezoned].filter((id) => !back.includes(id) && !(id === moved && zoned)));
124
+ if (moved !== void 0 && !zoned) keep2.add(moved);
125
+ for (const id of keep2) {
126
+ const was = Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
127
+ const now = Object.hasOwn(items, id) ? items[id] : void 0;
128
+ if (!was || !now || now.align === was.align) continue;
129
+ const { align: _a, ...plain } = now;
130
+ items[id] = was.align === void 0 ? plain : { ...plain, align: was.align };
115
131
  }
116
132
  const ringBefore = new Map(scene.edges.filter((e) => e.hidden !== true).map((e) => [e.id, e.ring]));
117
133
  for (const side of new Set(scene.edges.filter((e) => e.hidden === true).map((e) => e.side))) {
@@ -1351,22 +1367,22 @@ function insertColumn(scene0, id, side, ring, others) {
1351
1367
  const col = newColumn(scene, side, kind, r, [id], others);
1352
1368
  if (!col) return null;
1353
1369
  if (!zoneTakes(col, "start", kind)) return null;
1354
- const item = scene.items[id];
1355
- const zone = zoneTakes(col, zoneOf(item), kind) ? zoneOf(item) : zonesTaking(col, kind)[0] ?? "start";
1356
- const { align: _a, ...plain } = item;
1357
- const placed = withItem(scene, zone === "start" ? plain : { ...plain, align: zone });
1358
- const shifted = placed.edges.map((e) => e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e);
1359
- return { ...placed, edges: closeRings([...shifted, col], /* @__PURE__ */ new Set([side])) };
1370
+ const shifted = scene.edges.map((e) => e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e);
1371
+ return { ...scene, edges: closeRings([...shifted, col], /* @__PURE__ */ new Set([side])) };
1360
1372
  }
1373
+ var zoneAt = (scene, edge, id) => {
1374
+ const it = itemOf(scene, id);
1375
+ return it ? zoneIn(edge, it) : "start";
1376
+ };
1361
1377
  function insertIndex(scene, edge, zone, at) {
1362
1378
  const rank = { start: 0, center: 1, end: 2 };
1363
- const inZone = edge.items.map((id, i) => ({ id, i })).filter((x) => zoneOf(itemOf(scene, x.id)) === zone);
1379
+ const inZone = edge.items.map((id, i) => ({ id, i })).filter((x) => zoneAt(scene, edge, x.id) === zone);
1364
1380
  const k = Math.min(Math.max(0, Math.floor(Number.isFinite(at) ? at : inZone.length)), inZone.length);
1365
1381
  if (k < inZone.length) return inZone[k].i;
1366
1382
  if (inZone.length > 0) return inZone[inZone.length - 1].i + 1;
1367
1383
  let idx = 0;
1368
1384
  edge.items.forEach((id, i) => {
1369
- if (rank[zoneOf(itemOf(scene, id))] < rank[zone]) idx = i + 1;
1385
+ if (rank[zoneAt(scene, edge, id)] < rank[zone]) idx = i + 1;
1370
1386
  });
1371
1387
  return idx;
1372
1388
  }
@@ -1384,7 +1400,7 @@ function moveAmong(scene, id, place, others) {
1384
1400
  }
1385
1401
  const railColumn = place.kind === "rail" ? railColumnOf(scene, place.side, item.kind) : void 0;
1386
1402
  if (railColumn) {
1387
- const docked = moveAmong(scene, id, { edge: railColumn.id, zone: "start", at: Infinity }, others);
1403
+ const docked = moveAmong(scene, id, { edge: railColumn.id, at: Infinity }, others);
1388
1404
  return docked === scene ? scene : withItem(docked, { ...docked.items[id], from: Math.max(1, item.from ?? 0) });
1389
1405
  }
1390
1406
  if (place.kind === "column" || place.kind === "rail") {
@@ -1395,10 +1411,10 @@ function moveAmong(scene, id, place, others) {
1395
1411
  }
1396
1412
  const edge = scene.edges.find((e) => e.id === place.edge);
1397
1413
  if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return scene;
1398
- const zone = place.zone ?? (zoneTakes(edge, zoneOf(item), item.kind) ? zoneOf(item) : zonesTaking(edge, item.kind)[0]);
1399
- if (!zone || !zoneTakes(edge, zone, item.kind)) return scene;
1414
+ const zone = place.zone ?? zoneIn(edge, item);
1415
+ if (!zoneTakes(edge, zone, item.kind)) return scene;
1400
1416
  const { align: _drop, ...rest } = item;
1401
- const moved = zone === "start" ? rest : { ...rest, align: zone };
1417
+ const moved = place.zone === void 0 || !namesZone(edge, item.kind) ? item : zone === "start" ? rest : { ...rest, align: zone };
1402
1418
  const lifted = withItem(lift(scene, id), moved);
1403
1419
  const target = lifted.edges.find((e) => e.id === place.edge);
1404
1420
  if (!target) return scene;
@@ -1506,11 +1522,12 @@ function homeFor(scene, id, start) {
1506
1522
  for (const e of start.edges) {
1507
1523
  const k = e.items.indexOf(id);
1508
1524
  if (k < 0) continue;
1509
- const zone = zoneOf(itemOf(start, id) ?? itemOf(scene, id));
1525
+ const own = itemOf(start, id) ?? itemOf(scene, id);
1510
1526
  const found = scene.edges.find((x) => x.id === e.id);
1511
1527
  const here = found && (e.column !== true || found.items.some((x) => e.items.includes(x))) ? found : void 0;
1512
1528
  if (here) {
1513
- const now = here.items.filter((x) => x !== id && zoneOf(itemOf(scene, x)) === zone);
1529
+ const zone = own ? zoneIn(here, own) : "start";
1530
+ const now = here.items.filter((x) => x !== id && zoneAt(scene, here, x) === zone);
1514
1531
  const next = e.items.slice(k + 1).find((x) => now.includes(x));
1515
1532
  return { kind: "gap", edge: e.id, zone, at: next ? now.indexOf(next) : now.length };
1516
1533
  }
@@ -1527,10 +1544,18 @@ function dockHome(scene, id, start) {
1527
1544
  const moved = moveTo(scene, id, place);
1528
1545
  const item = itemOf(moved, id);
1529
1546
  if (!item) return scene;
1530
- const from = itemOf(start, id)?.from;
1531
- if (item.from === from) return moved;
1532
- const { from: _f, ...plain } = item;
1533
- return withItem(moved, from === void 0 ? plain : { ...plain, from });
1547
+ const was = itemOf(start, id);
1548
+ const from = was?.from;
1549
+ let out = item;
1550
+ if (was && out.align !== was.align) {
1551
+ const { align: _a, ...plain } = out;
1552
+ out = was.align === void 0 ? plain : { ...plain, align: was.align };
1553
+ }
1554
+ if (out.from !== from) {
1555
+ const { from: _f, ...plain } = out;
1556
+ out = from === void 0 ? plain : { ...plain, from };
1557
+ }
1558
+ return out === item ? moved : withItem(moved, out);
1534
1559
  }
1535
1560
  function clampFloat(r, stage, drawn = r) {
1536
1561
  const at = clampInto({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);
@@ -1849,7 +1874,7 @@ function zoneSpans(scene, seen, edge, reach, probe) {
1849
1874
  const placed = /* @__PURE__ */ new Map();
1850
1875
  for (const [id, it] of Object.entries(seen.items)) {
1851
1876
  if (it.edge !== edge.id || it.inMenu) continue;
1852
- const z = zoneOf(scene.items[id]);
1877
+ const z = it.zone ?? zoneOf(scene.items[id]);
1853
1878
  const [a, b] = at(thirds && it.fixed ? reservedRect(scene, seen, id) : it.rect);
1854
1879
  const was = placed.get(z);
1855
1880
  placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
@@ -2962,7 +2987,7 @@ function alongOfSlots(s, tiles) {
2962
2987
  }
2963
2988
  function generate(scene, dragged, options) {
2964
2989
  checkEdgeIds(scene);
2965
- const { view: shown, lent } = viewOf(scene);
2990
+ const { view: shown, lent, rezoned } = viewOf(scene);
2966
2991
  if (shown === scene) return generateShown(scene, dragged, options, []);
2967
2992
  if (inHiddenEdge(scene, dragged) && !lent.has(dragged)) return { targets: [], refusals: [], lost: [] };
2968
2993
  const hidden = scene.edges.filter((e) => e.hidden === true);
@@ -2976,13 +3001,13 @@ function generate(scene, dragged, options) {
2976
3001
  after: (point, grab) => {
2977
3002
  const a = t.after(point, grab);
2978
3003
  if (a.scene === shown) return { scene, layout: showsIn ? solve(scene, prev) : a.layout };
2979
- const moved = lent.has(dragged) ? dragged : void 0;
2980
- const zoned = t.place.kind === "gap" || t.place.kind === "rail" && !!railColumnOf(shown, t.place.side, scene.items[dragged].kind);
2981
- const back = withHiddenOf(scene, a.scene, lent, moved, zoned);
3004
+ const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
3005
+ const named = !!on && namesZone(on, scene.items[dragged].kind);
3006
+ const back = withHiddenOf(scene, a.scene, lent, dragged, named, rezoned);
2982
3007
  const restored = showsIn ? prune(back) : back;
2983
3008
  const ringOf = new Map(a.scene.edges.map((e) => [e.id, e.ring]));
2984
3009
  const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
2985
- const layout = renumbered || showsIn ? solve(restored, prev) : a.layout;
3010
+ const layout = renumbered || showsIn || rezoned.size > 0 ? solve(restored, prev) : a.layout;
2986
3011
  return { scene: restored, layout };
2987
3012
  }
2988
3013
  }))
@@ -3123,6 +3148,8 @@ export {
3123
3148
  zonesTaking,
3124
3149
  edgeTakes,
3125
3150
  railModeOf,
3151
+ zoneIn,
3152
+ namesZone,
3126
3153
  isOutsideSideBar,
3127
3154
  isSideBar,
3128
3155
  floatOrientOf,
@@ -3157,4 +3184,4 @@ export {
3157
3184
  refusalTargets,
3158
3185
  stops
3159
3186
  };
3160
- //# sourceMappingURL=chunk-GWZ5BPIN.js.map
3187
+ //# sourceMappingURL=chunk-PADZWK3H.js.map