@n-uf/placement 26.11.44 → 26.11.46

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.
@@ -33,6 +33,15 @@ var DEFAULT_HIT_BAND = 24;
33
33
  var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
34
34
 
35
35
  // src/scene/helpers.ts
36
+ var insetPx = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
37
+ function floatRegion(scene, lifted) {
38
+ const floating = new Set(scene.floats.map((f) => f.id));
39
+ const docked = scene.edges.some((e) => (e.side === "left" || e.side === "right") && e.accepts.length > 0 && e.items.some((id) => id !== lifted && !floating.has(id) && !!scene.items[id] && isDockingPanel(scene.items[id])));
40
+ const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
41
+ const { stage } = scene;
42
+ return { x: stage.x + insetPx(inset.left), y: stage.y, width: Math.max(0, stage.width - insetPx(inset.left) - insetPx(inset.right)), height: stage.height };
43
+ }
44
+ var heldRect = (scene, id, size, pointer, grab) => clampInto({ x: pointer.x - grab.x, y: pointer.y - grab.y, width: size.width, height: size.height }, floatRegion(scene, id));
36
45
  var anchorName = (anchor) => typeof anchor === "string" ? anchor : anchor.at;
37
46
  var isSince = (x) => typeof x === "number" && x >= 0 && x <= Number.MAX_SAFE_INTEGER;
38
47
  var zonesOf = (edge) => {
@@ -183,6 +192,7 @@ function isSideBar(scene, e) {
183
192
  const panelKinds = [...template?.accepts ?? [], ...rail?.accepts ?? []];
184
193
  return !e.accepts.some((k) => panelKinds.includes(k));
185
194
  }
195
+ var isSideColumn = (scene, e) => (e.side === "left" || e.side === "right") && !e.compact && e.accepts.length > 0 && !isSideBar(scene, e);
186
196
  var floatOrientOf = (item) => {
187
197
  if (item.floatOrient === "row" || item.floatOrient === "column") return item.floatOrient;
188
198
  for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
@@ -470,7 +480,7 @@ function zoneStarts(scene, fit, input) {
470
480
  out.set(p.id, at(p.rect));
471
481
  lengths.set(p.id, column ? p.rect.height : p.rect.width);
472
482
  }
473
- const len = (p) => lengths.get(p.id);
483
+ const len2 = (p) => lengths.get(p.id);
474
484
  const gap = px(input.gap);
475
485
  const start = px(input.pad?.start);
476
486
  const end = px(input.pad?.end);
@@ -482,32 +492,42 @@ function zoneStarts(scene, fit, input) {
482
492
  const title = column ? void 0 : s.find((p) => {
483
493
  const it = scene.items[p.id];
484
494
  const f = formsOf(it, "row")[p.form];
485
- return it.fixed && f?.main.grows && len(p) > formMain(f, "natural", fit.cross) + EPS;
495
+ return it.fixed && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS;
486
496
  });
487
497
  if (title) lengths.set(title.id, formMain(formsOf(scene.items[title.id], "row")[title.form], "natural", fit.cross));
488
- const used = drawn.reduce((sum, p) => sum + len(p), 0) + Math.max(0, drawn.length - 1) * gap;
498
+ const used = drawn.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, drawn.length - 1) * gap;
489
499
  const spare = fit.length - start - end - menu - used;
490
500
  if (spare <= EPS) return { starts: out, lengths };
491
- const total = (ps) => ps.reduce((sum, p) => sum + len(p), 0) + Math.max(0, ps.length - 1) * gap;
492
- const lay = (ps, from) => {
501
+ const spaceOf = (p) => {
502
+ const v = scene.items[p.id]?.space;
503
+ return Number.isFinite(v) && v > 0 ? v : 0;
504
+ };
505
+ const spacing = new Set([...s, ...e].map((p) => p.id));
506
+ const asked = [...s, ...e].reduce((sum, p) => sum + spaceOf(p), 0);
507
+ const share = asked > spare ? spare / asked : 1;
508
+ const room = (p) => spacing.has(p.id) ? spaceOf(p) * share : 0;
509
+ const total = (ps) => ps.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, ps.length - 1) * gap;
510
+ const lay = (ps, from, lead) => {
493
511
  let x = from;
494
512
  for (const p of ps) {
513
+ if (lead) x += room(p);
495
514
  out.set(p.id, x);
496
- x += len(p) + gap;
515
+ x += len2(p) + gap + (lead ? 0 : room(p));
497
516
  }
498
517
  };
499
- lay(s, start);
500
- const endStart = fit.length - end - menu - total(e);
501
- lay(e, endStart);
502
- const lo = start + total(s) + (s.length > 0 ? gap : 0);
518
+ const spaced = (ps) => total(ps) + ps.reduce((sum, p) => sum + room(p), 0);
519
+ lay(s, start, true);
520
+ const endStart = fit.length - end - menu - spaced(e);
521
+ lay(e, endStart, false);
522
+ const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
503
523
  const hi = endStart - (e.length > 0 ? gap : 0);
504
- const mid = (fit.length - total(c)) / 2;
505
- const clear = mid >= lo - EPS && mid + total(c) <= hi + EPS;
506
- lay(c, title && !clear ? Math.max(lo, (lo + hi - total(c)) / 2) : Math.max(lo, Math.min(mid, hi - total(c))));
524
+ const mid2 = (fit.length - total(c)) / 2;
525
+ const clear = mid2 >= lo2 - EPS && mid2 + total(c) <= hi + EPS;
526
+ lay(c, title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid2, hi - total(c))), false);
507
527
  if (title && s[s.length - 1] === title) {
508
528
  const next = [...c, ...e].map((p) => out.get(p.id));
509
529
  const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
510
- lengths.set(title.id, Math.max(len(title), until - out.get(title.id)));
530
+ lengths.set(title.id, Math.max(len2(title), until - out.get(title.id)));
511
531
  }
512
532
  return { starts: out, lengths };
513
533
  }
@@ -692,8 +712,8 @@ function solveEdge(scene, edge, ids, length, room, previous) {
692
712
  const size = edge.size;
693
713
  if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
694
714
  const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross(formsById(p.id)[p.form]));
695
- const lo = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(formsById(p.id)[p.form])));
696
- const s = Math.min(Math.max(size, lo), Math.max(lo, maxOf), room);
715
+ const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(formsById(p.id)[p.form])));
716
+ const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
697
717
  if (Math.abs(s - free.cross) > EPS) {
698
718
  const sized = { ...input, cross: { ...cross, min: s, max: s } };
699
719
  const stack = fitStack(sized, previous ? { previous: previous.stack } : {});
@@ -752,17 +772,17 @@ function floatFloor(item, form, orient2, size) {
752
772
  }
753
773
  function clearSize(region, avoid) {
754
774
  const span = (axis) => {
755
- const lo = axis === "y" ? region.y : region.x;
756
- const hi = lo + (axis === "y" ? region.height : region.width);
757
- const mid = (lo + hi) / 2;
758
- let a = lo;
775
+ const lo2 = axis === "y" ? region.y : region.x;
776
+ const hi = lo2 + (axis === "y" ? region.height : region.width);
777
+ const mid2 = (lo2 + hi) / 2;
778
+ let a = lo2;
759
779
  let b = hi;
760
780
  for (const r of avoid) {
761
781
  const whole = axis === "y" ? r.x <= region.x + EPS && r.x + r.width >= region.x + region.width - EPS : r.y <= region.y + EPS && r.y + r.height >= region.y + region.height - EPS;
762
782
  const s = axis === "y" ? r.y : r.x;
763
783
  const e = s + (axis === "y" ? r.height : r.width);
764
- if (!whole || e <= lo || s >= hi) continue;
765
- if (s + e <= 2 * mid) a = Math.max(a, e);
784
+ if (!whole || e <= lo2 || s >= hi) continue;
785
+ if (s + e <= 2 * mid2) a = Math.max(a, e);
766
786
  else b = Math.min(b, s);
767
787
  }
768
788
  return Math.max(0, b - a);
@@ -1219,14 +1239,6 @@ var LIMITS = ["min", "max", "region", "docked"];
1219
1239
  var EPS2 = 0.5;
1220
1240
  var TOUCH = 1e-3;
1221
1241
  var fin = (v, d) => Number.isFinite(v) ? v : d;
1222
- var nonNeg = (v) => Math.max(0, fin(v, 0));
1223
- function floatRegion(scene) {
1224
- const floating = new Set(scene.floats.map((f) => f.id));
1225
- const docked = scene.edges.some((e) => (e.side === "left" || e.side === "right") && e.accepts.length > 0 && e.items.some((id) => !floating.has(id) && !!scene.items[id] && isDockingPanel(scene.items[id])));
1226
- const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
1227
- const { stage } = scene;
1228
- return { x: stage.x + nonNeg(inset.left), y: stage.y, width: Math.max(0, stage.width - nonNeg(inset.left) - nonNeg(inset.right)), height: stage.height };
1229
- }
1230
1242
  function floatObstacles(scene, l, id) {
1231
1243
  const out = [];
1232
1244
  for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);
@@ -1240,16 +1252,16 @@ function floatObstacles(scene, l, id) {
1240
1252
  function obstacleStop(drawn, obstacles, axis, drag, span) {
1241
1253
  const none = drag === "start" ? -Infinity : Infinity;
1242
1254
  if (!drawn || !drag) return none;
1243
- const lo = (r) => axis === "x" ? r.x : r.y;
1244
- const len = (r) => axis === "x" ? r.width : r.height;
1255
+ const lo2 = (r) => axis === "x" ? r.x : r.y;
1256
+ const len2 = (r) => axis === "x" ? r.width : r.height;
1245
1257
  const across2 = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
1246
1258
  let at = none;
1247
1259
  for (const o of obstacles) {
1248
1260
  const [c0, c1] = across2(o);
1249
1261
  if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
1250
- const begin = lo(o);
1251
- const finish = begin + len(o);
1252
- const edge = drag === "start" ? lo(drawn) : lo(drawn) + len(drawn);
1262
+ const begin = lo2(o);
1263
+ const finish = begin + len2(o);
1264
+ const edge = drag === "start" ? lo2(drawn) : lo2(drawn) + len2(drawn);
1253
1265
  if (drag === "start") {
1254
1266
  if (finish <= edge + EPS2) at = Math.max(at, finish);
1255
1267
  else if (begin < edge - TOUCH) at = edge;
@@ -1258,25 +1270,25 @@ function obstacleStop(drawn, obstacles, axis, drag, span) {
1258
1270
  else if (finish > edge + TOUCH) at = edge;
1259
1271
  }
1260
1272
  }
1261
- return drag === "start" ? Math.min(at, lo(drawn)) : Math.max(at, lo(drawn) + len(drawn));
1273
+ return drag === "start" ? Math.min(at, lo2(drawn)) : Math.max(at, lo2(drawn) + len2(drawn));
1262
1274
  }
1263
1275
  function fitAxis(start, length, b, drag, hit) {
1264
- const { min, lo, hi, stop } = b;
1276
+ const { min, lo: lo2, hi, stop } = b;
1265
1277
  const max = Math.max(min, b.max);
1266
1278
  const raw = fin(length, min);
1267
- if (min >= hi - lo) {
1279
+ if (min >= hi - lo2) {
1268
1280
  hit.add("region");
1269
- return [lo, min];
1281
+ return [lo2, min];
1270
1282
  }
1271
1283
  const bind = (cands, pick) => {
1272
1284
  const at = cands.reduce((m, [v]) => pick(m, v), cands[0][0]);
1273
1285
  return [at, cands.filter(([v]) => Math.abs(v - at) <= EPS2).map(([, k]) => k)];
1274
1286
  };
1275
1287
  if (drag === "start") {
1276
- const asked2 = fin(start, lo) + raw;
1277
- const end = Math.min(hi, Math.max(lo + min, asked2));
1288
+ const asked2 = fin(start, lo2) + raw;
1289
+ const end = Math.min(hi, Math.max(lo2 + min, asked2));
1278
1290
  if (Math.abs(end - asked2) > EPS2) hit.add("region");
1279
- const [down, why2] = bind([[end - max, "max"], [lo, "region"], [stop, "docked"]], Math.max);
1291
+ const [down, why2] = bind([[end - max, "max"], [lo2, "region"], [stop, "docked"]], Math.max);
1280
1292
  let from = end - raw;
1281
1293
  if (from > end - min) {
1282
1294
  from = end - min;
@@ -1287,8 +1299,8 @@ function fitAxis(start, length, b, drag, hit) {
1287
1299
  }
1288
1300
  return [from, end - from];
1289
1301
  }
1290
- const asked = fin(start, lo);
1291
- const a = Math.max(lo, Math.min(hi - min, asked));
1302
+ const asked = fin(start, lo2);
1303
+ const a = Math.max(lo2, Math.min(hi - min, asked));
1292
1304
  if (Math.abs(a - asked) > EPS2) hit.add("region");
1293
1305
  const [up, why] = bind([[a + max, "max"], [hi, "region"], [stop, "docked"]], Math.min);
1294
1306
  let to = a + raw;
@@ -1347,6 +1359,19 @@ function prune(scene) {
1347
1359
  const sides = new Set(gone.map((e) => e.side));
1348
1360
  return { ...scene, edges: closeRings(scene.edges.filter((e) => !gone.includes(e)), sides) };
1349
1361
  }
1362
+ function mergeSideColumns(scene) {
1363
+ let edges = [...scene.edges];
1364
+ const sides = /* @__PURE__ */ new Set();
1365
+ for (const side of ["left", "right"]) {
1366
+ const cols = edges.filter((e) => e.side === side && isSideColumn(scene, e)).sort((a, b) => a.ring - b.ring);
1367
+ if (cols.length < 2) continue;
1368
+ const [keep2, ...rest] = cols;
1369
+ const merged = { ...keep2, items: [...keep2.items, ...rest.flatMap((e) => e.items)] };
1370
+ edges = edges.filter((e) => !rest.includes(e)).map((e) => e === keep2 ? merged : e);
1371
+ sides.add(side);
1372
+ }
1373
+ return sides.size === 0 ? scene : { ...scene, edges: closeRings(edges, sides) };
1374
+ }
1350
1375
  function lift(scene, id) {
1351
1376
  const inEdge = scene.edges.some((e) => e.items.includes(id));
1352
1377
  const inFloat = scene.floats.some((f) => f.id === id);
@@ -1421,7 +1446,8 @@ function moveAmong(scene, id, place, others) {
1421
1446
  }
1422
1447
  if (place.kind === "column" || place.kind === "rail") {
1423
1448
  if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
1424
- const folded = place.kind === "rail" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;
1449
+ const { space: _space2, ...unspaced2 } = item;
1450
+ const folded = place.kind === "rail" ? { ...unspaced2, from: Math.max(1, item.from ?? 0) } : unspaced2;
1425
1451
  const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring, others);
1426
1452
  return made ?? scene;
1427
1453
  }
@@ -1429,13 +1455,21 @@ function moveAmong(scene, id, place, others) {
1429
1455
  if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return scene;
1430
1456
  const zone = place.zone ?? zoneIn(edge, item);
1431
1457
  if (!zoneTakes(edge, zone, item.kind)) return scene;
1432
- const { align: _drop, ...rest } = item;
1433
- const moved = place.zone === void 0 || !namesZone(edge, item.kind) ? item : zone === "start" ? rest : { ...rest, align: zone };
1458
+ const { space: _space, ...unspaced } = item;
1459
+ const { align: _drop, ...rest } = unspaced;
1460
+ const kept = Number.isFinite(place.space) && place.space > 0 ? { space: place.space } : {};
1461
+ const moved = { ...place.zone === void 0 || !namesZone(edge, item.kind) ? unspaced : zone === "start" ? rest : { ...rest, align: zone }, ...kept };
1434
1462
  const lifted = withItem(lift(scene, id), moved);
1435
1463
  const target = lifted.edges.find((e) => e.id === place.edge);
1436
1464
  if (!target) return scene;
1437
1465
  const k = insertIndex(lifted, target, zone, place.at);
1438
- return { ...lifted, edges: lifted.edges.map((e) => e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e) };
1466
+ const placed = { ...lifted, edges: lifted.edges.map((e) => e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e) };
1467
+ if (place.space !== void 0) return placed;
1468
+ const nb = zone === "start" ? target.items[k] : zone === "end" ? target.items[k - 1] : void 0;
1469
+ const nbItem = nb !== void 0 ? placed.items[nb] : void 0;
1470
+ if (!nbItem || !(nbItem.space > 0) || zoneIn(target, nbItem) !== zone) return placed;
1471
+ const { space: given, ...bare } = nbItem;
1472
+ return { ...placed, items: { ...placed.items, [nb]: bare, [id]: { ...placed.items[id], space: given } } };
1439
1473
  }
1440
1474
  function nextSince(scene) {
1441
1475
  const most = scene.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
@@ -1450,7 +1484,8 @@ function floatAt(scene, id, at, orient2) {
1450
1484
  const since = was ? was.since : nextSince(scene);
1451
1485
  const seq = since !== void 0 ? { since } : {};
1452
1486
  const float = at ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...o ? { orient: o } : {}, ...seq } : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: "content-top-right", ...o ? { orient: o } : {}, ...seq };
1453
- const next = at && at.width > 0 && at.height > 0 ? { ...item, floatSize: { width: at.width, height: at.height } } : item;
1487
+ const { space: _space, ...unspaced } = item;
1488
+ const next = at && at.width > 0 && at.height > 0 ? { ...unspaced, floatSize: { width: at.width, height: at.height } } : unspaced;
1454
1489
  const lifted = lift(withItem(scene, next), id);
1455
1490
  return { ...lifted, floats: [...lifted.floats, float] };
1456
1491
  }
@@ -1625,6 +1660,7 @@ function storeScene(scene) {
1625
1660
  ...isNum(it.from) && it.from >= 1 ? { from: Math.floor(it.from) } : {},
1626
1661
  ...it.closed ? { closed: true } : {},
1627
1662
  ...it.align === "center" || it.align === "end" ? { align: it.align } : {},
1663
+ ...isNum(it.space) && it.space > 0 ? { space: it.space } : {},
1628
1664
  ...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}
1629
1665
  };
1630
1666
  }
@@ -1681,9 +1717,9 @@ function read(data, base) {
1681
1717
  continue;
1682
1718
  }
1683
1719
  const b = base.items[id];
1684
- const { kept: _k, from: _f, closed: _c, align: _a, floatSize: _s, ...plain } = b;
1720
+ const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSize: _s, ...plain } = b;
1685
1721
  let it = { ...plain, used: b.used };
1686
- for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
1722
+ for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
1687
1723
  if (isNum(s.used)) it = { ...it, used: s.used };
1688
1724
  else if (s.used !== void 0) drop(`item:${id}:used`);
1689
1725
  if (s.kept === true) it = { ...it, kept: true };
@@ -1697,6 +1733,8 @@ function read(data, base) {
1697
1733
  if (s.align === "center" || s.align === "end") it = { ...it, align: s.align };
1698
1734
  else if (s.align !== void 0 && s.align !== "start") drop(`item:${id}:align`);
1699
1735
  if (b.fixed && b.align) it = { ...it, align: b.align };
1736
+ if (isNum(s.space) && s.space > 0 && !b.fixed) it = { ...it, space: s.space };
1737
+ else if (s.space !== void 0) drop(`item:${id}:space`);
1700
1738
  const fs = s.floatSize;
1701
1739
  if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) it = { ...it, floatSize: { width: fs.width, height: fs.height } };
1702
1740
  else if (fs !== void 0) drop(`item:${id}:floatSize`);
@@ -1859,9 +1897,9 @@ function reservedRect(scene, l, id) {
1859
1897
  const f = e ? formsOf(scene.items[id], axisOf(e.side))[it.form] : void 0;
1860
1898
  if (!e || !f?.main.grows) return it.rect;
1861
1899
  const column = axisOf(e.side) === "column";
1862
- const len = column ? it.rect.height : it.rect.width;
1863
- const keep2 = Math.min(len, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len));
1864
- const shift = it.zone === "end" ? len - keep2 : it.zone === "center" ? (len - keep2) / 2 : 0;
1900
+ const len2 = column ? it.rect.height : it.rect.width;
1901
+ const keep2 = Math.min(len2, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len2));
1902
+ const shift = it.zone === "end" ? len2 - keep2 : it.zone === "center" ? (len2 - keep2) / 2 : 0;
1865
1903
  return column ? rect(it.rect.x, it.rect.y + shift, it.rect.width, keep2) : rect(it.rect.x + shift, it.rect.y, keep2, it.rect.height);
1866
1904
  }
1867
1905
  function slotAt(c, zone, line, id, place, lands, home = false) {
@@ -1898,7 +1936,7 @@ function zoneSpans(scene, seen, edge, reach, probe) {
1898
1936
  placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
1899
1937
  declared.add(z);
1900
1938
  }
1901
- const lo = (z) => placed.get(z)?.[0] ?? Infinity;
1939
+ const lo2 = (z) => placed.get(z)?.[0] ?? Infinity;
1902
1940
  const hi = (z) => placed.get(z)?.[1] ?? -Infinity;
1903
1941
  if (edge.zones !== void 0) {
1904
1942
  const has = zonesOf(edge);
@@ -1906,15 +1944,22 @@ function zoneSpans(scene, seen, edge, reach, probe) {
1906
1944
  return has.map((zone, i) => {
1907
1945
  const last = i === has.length - 1;
1908
1946
  const mark = main0 + length * (i + 1) / has.length;
1909
- const b = last ? main0 + length + reach : Math.max(prev, Math.min(Math.max(mark, ...has.slice(0, i + 1).map(hi)), ...has.slice(i + 1).map(lo)));
1947
+ const b = last ? main0 + length + reach : Math.max(prev, Math.min(Math.max(mark, ...has.slice(0, i + 1).map(hi)), ...has.slice(i + 1).map(lo2)));
1910
1948
  const span = { zone, a: prev, b };
1911
1949
  prev = b;
1912
1950
  return span;
1913
1951
  });
1914
1952
  }
1915
1953
  if (thirds) {
1916
- const b1 = Math.min(Math.max(main0 + length / 3, hi("start")), lo("center"), lo("end"));
1917
- const b2 = Math.max(Math.min(main0 + 2 * length / 3, lo("end")), hi("center"), hi("start"), b1);
1954
+ const nearest = scene.barZones === "nearest";
1955
+ const landing = (z, side) => placed.has(z) ? side === "after" ? [hi(z), hi(z)] : [lo2(z), lo2(z)] : probe(z);
1956
+ const between = (l, r, fallback) => {
1957
+ const a = landing(l, "after");
1958
+ const b = landing(r, "before");
1959
+ return nearest && a && b ? (a[1] + b[0]) / 2 : fallback;
1960
+ };
1961
+ const b1 = Math.min(Math.max(between("start", "center", main0 + length / 3), hi("start")), lo2("center"), lo2("end"));
1962
+ const b2 = Math.max(Math.min(between("center", "end", main0 + 2 * length / 3), lo2("end")), hi("center"), hi("start"), b1);
1918
1963
  return [
1919
1964
  { zone: "start", a: main0 - reach, b: b1 },
1920
1965
  { zone: "center", a: b1, b: b2 },
@@ -1934,9 +1979,9 @@ function edgeSlots(c, edge, accepts) {
1934
1979
  const el = now.edges[edge.id];
1935
1980
  const column = axisOf(edge.side) === "column";
1936
1981
  const at = (r) => column ? r.y : r.x;
1937
- const len = (r) => column ? r.height : r.width;
1982
+ const len2 = (r) => column ? r.height : r.width;
1938
1983
  const main0 = at(el.rect);
1939
- const length = len(el.rect);
1984
+ const length = len2(el.rect);
1940
1985
  const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];
1941
1986
  const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
1942
1987
  const firstKind = formsOf(scene.items[dragged], axisOf(edge.side))[0]?.kind;
@@ -1956,13 +2001,13 @@ function edgeSlots(c, edge, accepts) {
1956
2001
  });
1957
2002
  };
1958
2003
  const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
1959
- const menuLen = el.menu ? len(el.menu.rect) : 0;
2004
+ const menuLen = el.menu ? len2(el.menu.rect) : 0;
1960
2005
  const occupied = (id) => now.items[id]?.fixed ? reservedRect(scene, now, id) : now.items[id].rect;
1961
2006
  const shown = (id) => now.items[id]?.edge === edge.id && !now.items[id].inMenu;
1962
2007
  const drawnOf2 = (z) => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
1963
2008
  const startEnd = (() => {
1964
2009
  const s = drawnOf2("start");
1965
- return s.length ? at(s[s.length - 1]) + len(s[s.length - 1]) : main0 + pad.start;
2010
+ return s.length ? at(s[s.length - 1]) + len2(s[s.length - 1]) : main0 + pad.start;
1966
2011
  })();
1967
2012
  const endStart = (() => {
1968
2013
  const e = drawnOf2("end");
@@ -1985,7 +2030,7 @@ function edgeSlots(c, edge, accepts) {
1985
2030
  for (let k = 0; k <= members.length; k++) {
1986
2031
  const next = members.slice(k).find(shown);
1987
2032
  const before = members.slice(0, k).reverse().find(shown);
1988
- const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];
2033
+ const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len2(occupied(before)) : anchorLine[zone];
1989
2034
  const s = { ...slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands), order: before0 + members.slice(0, k).filter(aimed).length };
1990
2035
  const movesFixed = members0.some((id) => {
1991
2036
  const b = base.items[id];
@@ -2006,19 +2051,21 @@ function edgeSpec(c, edge) {
2006
2051
  const data = EDGE_KINDS[edgeKind];
2007
2052
  const column = axisOf(edge.side) === "column";
2008
2053
  const at = (r2) => column ? r2.y : r2.x;
2009
- const len = (r2) => column ? r2.height : r2.width;
2054
+ const len2 = (r2) => column ? r2.height : r2.width;
2010
2055
  const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
2011
2056
  const accepts = edgeTakes(edge, kind);
2012
2057
  if (!accepts && (empty || area(el.rect) <= EPS)) return null;
2013
2058
  if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;
2014
2059
  const ownNow = now.items[dragged];
2015
2060
  const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area(ownNow.rect) > EPS ? ownNow.rect : null;
2016
- const slots = edgeSlots(c, edge, accepts);
2017
- const spanOf = (r2) => [at(r2), at(r2) + len(r2)];
2061
+ const oneEnd = scene.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
2062
+ const allSlots = edgeSlots(c, edge, accepts);
2063
+ const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
2064
+ const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
2018
2065
  const grows = (id) => !!formsOf(scene.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
2019
2066
  const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
2020
2067
  const cards = Object.entries(now.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area(p.rect) > EPS).map(([, p]) => spanOf(p.rect));
2021
- const zones = zoneSpans(scene, now, edge, c.reach, (zone) => {
2068
+ const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(scene, now, edge, c.reach, (zone) => {
2022
2069
  const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
2023
2070
  const me = s?.result.layout.items[dragged];
2024
2071
  return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
@@ -2085,8 +2132,8 @@ function soundness(scene, base, dragged) {
2085
2132
  const e = a?.edge ? after.edges[a.edge] : void 0;
2086
2133
  if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;
2087
2134
  const f = formsOf(scene.items[id], axisOf(e.side))[a.form];
2088
- const len = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
2089
- if (f && len < formMain(f, "min", e.cross) - 0.5) return false;
2135
+ const len2 = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
2136
+ if (f && len2 < formMain(f, "min", e.cross) - 0.5) return false;
2090
2137
  }
2091
2138
  const me = after.items[dragged];
2092
2139
  if (!me) return true;
@@ -2135,11 +2182,11 @@ var ownedRectOf = (s) => {
2135
2182
  const [a0, a1] = s.ownedAlong;
2136
2183
  return s.vertical ? rect(b.x, a0, b.width, a1 - a0) : rect(a0, b.y, a1 - a0, b.height);
2137
2184
  };
2138
- function ownedRectsOf(s, along) {
2139
- if (along.length === 0) return [];
2185
+ function ownedRectsOf(s, along2) {
2186
+ if (along2.length === 0) return [];
2140
2187
  const o = ownedRectOf(s);
2141
2188
  if (s.ownedAlong) return [o];
2142
- return along.map(([a, b]) => s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height));
2189
+ return along2.map(([a, b]) => s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height));
2143
2190
  }
2144
2191
  function drawnOf(c, live) {
2145
2192
  return Object.entries(c.now.edges).filter(([id, e]) => area(e.rect) > EPS && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
@@ -2148,15 +2195,15 @@ function homeRectOf(c, ownSpec) {
2148
2195
  const own = c.now.items[c.dragged];
2149
2196
  if (!own || own.floating || !own.edge) return null;
2150
2197
  const o = own.rect;
2151
- const hull2 = (a, b) => rect(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));
2198
+ const hull3 = (a, b) => rect(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));
2152
2199
  if (own.inMenu) return o;
2153
2200
  if (!ownSpec) {
2154
2201
  const e = c.now.edges[own.edge];
2155
2202
  const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
2156
- return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ? hull2(o, e.rect) : o;
2203
+ return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ? hull3(o, e.rect) : o;
2157
2204
  }
2158
2205
  const [c0, c1] = ownSpec.across();
2159
- return ownSpec.vertical ? hull2(o, rect(c0, o.y, c1 - c0, o.height)) : hull2(o, rect(o.x, c0, o.width, c1 - c0));
2206
+ return ownSpec.vertical ? hull3(o, rect(c0, o.y, c1 - c0, o.height)) : hull3(o, rect(o.x, c0, o.width, c1 - c0));
2160
2207
  }
2161
2208
  function ownersOf(c, live, drawn, alongOf) {
2162
2209
  const ownEdge = c.now.items[c.dragged]?.edge;
@@ -2223,14 +2270,14 @@ function ownership(c, live, alongOf) {
2223
2270
  };
2224
2271
  const roomOf2 = (s) => {
2225
2272
  const b = bandOf(s);
2226
- const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
2273
+ const along2 = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
2227
2274
  const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
2228
2275
  const rs = taken.get(s).filter((r) => overlaps(r, b));
2229
- const ends = [.../* @__PURE__ */ new Set([...along(b), ...rs.flatMap(along)])].filter((x) => x >= along(b)[0] && x <= along(b)[1]).sort((p, q) => p - q);
2276
+ const ends = [.../* @__PURE__ */ new Set([...along2(b), ...rs.flatMap(along2)])].filter((x) => x >= along2(b)[0] && x <= along2(b)[1]).sort((p, q) => p - q);
2230
2277
  const owned = [];
2231
2278
  for (let k = 1; k < ends.length; k++) {
2232
2279
  const [u, w] = [ends[k - 1], ends[k]];
2233
- const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across2);
2280
+ const over = rs.filter((r) => along2(r)[0] <= u + EPS && along2(r)[1] >= w - EPS).map(across2);
2234
2281
  if (w - u > EPS && less([across2(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
2235
2282
  }
2236
2283
  const half = s.edge ? halfBandOf(s.edge) : null;
@@ -2242,11 +2289,11 @@ function ownership(c, live, alongOf) {
2242
2289
  else m.push([u, w]);
2243
2290
  return m;
2244
2291
  }, []);
2245
- const [lo, hi] = along(b);
2292
+ const [lo2, hi] = along2(b);
2246
2293
  const placed = (p) => {
2247
2294
  const cut2 = merged.find(([u, w]) => p >= u - EPS && p <= w + EPS);
2248
2295
  if (!cut2) return p;
2249
- const sides = [...cut2[0] > lo + EPS ? [cut2[0]] : [], ...cut2[1] < hi - EPS ? [cut2[1]] : []];
2296
+ const sides = [...cut2[0] > lo2 + EPS ? [cut2[0]] : [], ...cut2[1] < hi - EPS ? [cut2[1]] : []];
2250
2297
  return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
2251
2298
  };
2252
2299
  const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
@@ -2317,13 +2364,13 @@ var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS);
2317
2364
  function linesIn(spec, z, mine, pieces, [pa, pb], own) {
2318
2365
  const reserved = spec.reserved;
2319
2366
  const lines = mine.map((s) => s.line);
2320
- const lo = Math.min(z.a, ...lines);
2367
+ const lo2 = Math.min(z.a, ...lines);
2321
2368
  const hi = Math.max(z.b, ...lines);
2322
2369
  const free = less([[z.a, z.b]], reserved);
2323
2370
  const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
2324
2371
  const spread = (x) => {
2325
- if (hi - lo <= EPS || freeLen <= EPS) return x;
2326
- let d = (x - lo) / (hi - lo) * freeLen;
2372
+ if (hi - lo2 <= EPS || freeLen <= EPS) return x;
2373
+ let d = (x - lo2) / (hi - lo2) * freeLen;
2327
2374
  for (const [a, b] of free) {
2328
2375
  if (d <= b - a + EPS) return a + Math.min(d, b - a);
2329
2376
  d -= b - a;
@@ -2391,10 +2438,10 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2391
2438
  continue;
2392
2439
  }
2393
2440
  const meet2 = (i) => {
2394
- const [lo, hi] = [at[i - 1], at[i]];
2441
+ const [lo2, hi] = [at[i - 1], at[i]];
2395
2442
  const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS && w <= inPiece[i].line + EPS);
2396
- const mid = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
2397
- return mid > lo + EPS && mid < hi - EPS ? mid : (lo + hi) / 2;
2443
+ const mid2 = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
2444
+ return mid2 > lo2 + EPS && mid2 < hi - EPS ? mid2 : (lo2 + hi) / 2;
2398
2445
  };
2399
2446
  inPiece.forEach((s, i) => {
2400
2447
  const p = at[i];
@@ -2555,6 +2602,7 @@ function collapsesAt(c, result, side) {
2555
2602
  }
2556
2603
  function columnLines(c, side, railLands) {
2557
2604
  const { scene, now, dragged } = c;
2605
+ if (scene.sideColumns === "one" && c.rest.edges.some((e) => e.side === side && e.items.length > 0 && isSideColumn(c.rest, e))) return [];
2558
2606
  const cols = scene.edges.filter((e) => e.side === side && e.column === true).map((edge) => ({ edge, l: now.edges[edge.id] })).filter((x) => x.l && !x.l.folded && !x.l.rides && x.l.cross > 0).sort((a, b) => a.edge.ring - b.edge.ring).map((x) => ({ edge: x.edge, r: x.l.rect }));
2559
2607
  const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);
2560
2608
  const span = own[0]?.rect ?? now.content;
@@ -2610,6 +2658,19 @@ function columnLines(c, side, railLands) {
2610
2658
  };
2611
2659
  });
2612
2660
  }
2661
+ function railEnd(c, side, segments, y) {
2662
+ const { scene, rest, dragged } = c;
2663
+ const edge = [...segments].reverse().map((s) => rest.edges.find((e) => e.id === s.edge)).find((e) => !!e);
2664
+ if (!edge) return null;
2665
+ const at = edge.items.filter((id) => zoneOf(rest.items[id]) === "start").length;
2666
+ const place = { kind: "gap", edge: edge.id, zone: "start", at };
2667
+ const collapsed = isHandFolded(scene, dragged);
2668
+ const lands = ({ layout }) => {
2669
+ const me = layout.items[dragged];
2670
+ return !me.inMenu && (collapsed ? me.rail === side : me.edge === edge.id && !me.rail && !me.rides && !layout.edges[edge.id]?.folded);
2671
+ };
2672
+ return slotAt(c, "start", y, targetId(place), place, lands);
2673
+ }
2613
2674
  function railStops(c, side) {
2614
2675
  const { scene, now, dragged } = c;
2615
2676
  const rail = now.rails[side];
@@ -2650,6 +2711,9 @@ function railStops(c, side) {
2650
2711
  const shown = !!rail && rail.segments.length > 0;
2651
2712
  const lands = (r) => shown ? collapsesAt(c, r, side) : r.layout.items[dragged].rail === side && r.scene !== c.scene;
2652
2713
  const at = zone;
2714
+ const arriving = scene.foldedColumnDrop === "end" && !ownRail;
2715
+ const end = arriving && shown ? railEnd(c, side, rail.segments, at.y + at.height) : null;
2716
+ if (arriving && (shown ? !end : !isHandFolded(scene, dragged))) return null;
2653
2717
  return {
2654
2718
  id: virtualEdgeId("rail", side),
2655
2719
  edge: null,
@@ -2658,7 +2722,7 @@ function railStops(c, side) {
2658
2722
  lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
2659
2723
  vertical: true,
2660
2724
  zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
2661
- slots: stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
2725
+ slots: end ? [end] : stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
2662
2726
  refuse: () => "no-room",
2663
2727
  own: null,
2664
2728
  holds: false,
@@ -2714,7 +2778,7 @@ var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => o
2714
2778
  var largest2 = (rs) => rs.reduce((m, r) => r.width * r.height > m.width * m.height ? r : m);
2715
2779
  var sameRects = (a, b) => a.length === b.length && a.every((r, i) => r.x === b[i].x && r.y === b[i].y && r.width === b[i].width && r.height === b[i].height);
2716
2780
  function withRailStrips(c, targets2, refusals2) {
2717
- const policy = railPolicyOf(c.scene, c.kind);
2781
+ const policy = c.scene.foldedColumnDrop === "end" ? null : railPolicyOf(c.scene, c.kind);
2718
2782
  const strips = policy ? ["left", "right"].map((side) => c.scene.rails?.[side] ? declaredStrip(c, side, policy) : columnStrip(c, side, policy)).filter((s) => s !== null) : [];
2719
2783
  if (!policy || strips.length === 0) return { targets: [...targets2], refusals: [...refusals2], strips: [] };
2720
2784
  const sides = new Set(strips.map((s) => s.side));
@@ -2863,10 +2927,10 @@ var withPieces2 = (t, ps) => {
2863
2927
  return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
2864
2928
  };
2865
2929
  function growths(r, axis, d) {
2866
- const [lo, hi] = axis === "x" ? [rect(r.x - d, r.y, d, r.height), rect(r.x + r.width, r.y, d, r.height)] : [rect(r.x, r.y - d, r.width, d), rect(r.x, r.y + r.height, r.width, d)];
2930
+ const [lo2, hi] = axis === "x" ? [rect(r.x - d, r.y, d, r.height), rect(r.x + r.width, r.y, d, r.height)] : [rect(r.x, r.y - d, r.width, d), rect(r.x, r.y + r.height, r.width, d)];
2867
2931
  const h = d / 2;
2868
2932
  const halves = axis === "x" ? [rect(r.x - h, r.y, h, r.height), rect(r.x + r.width, r.y, h, r.height)] : [rect(r.x, r.y - h, r.width, h), rect(r.x, r.y + r.height, r.width, h)];
2869
- return [[lo], [hi], halves];
2933
+ return [[lo2], [hi], halves];
2870
2934
  }
2871
2935
  var union = (a, gs) => {
2872
2936
  const x0 = Math.min(a.x, ...gs.map((g) => g.x));
@@ -2889,16 +2953,16 @@ function mayGrow(c, targets2, i, grow, minOf, zone, away) {
2889
2953
  });
2890
2954
  }
2891
2955
  function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
2892
- const along = axis === "x" ? [l.y, l.y + l.height] : [l.x, l.x + l.width];
2956
+ const along2 = axis === "x" ? [l.y, l.y + l.height] : [l.x, l.x + l.width];
2893
2957
  let best = null;
2894
2958
  for (const [side] of growths(l, axis, d)) {
2895
2959
  const g = side;
2896
2960
  const strip = (a, b) => axis === "x" ? rect(g.x, a, g.width, b - a) : rect(a, g.y, b - a, g.height);
2897
- const cuts = /* @__PURE__ */ new Set([along[0], along[1]]);
2961
+ const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
2898
2962
  for (const o of targets2)
2899
2963
  for (const p of piecesOf(o))
2900
2964
  if (overlaps2(p, g)) {
2901
- for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along[0] && v < along[1]) cuts.add(v);
2965
+ for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along2[0] && v < along2[1]) cuts.add(v);
2902
2966
  }
2903
2967
  const marks = [...cuts].sort((a, b) => a - b);
2904
2968
  let runStart = null;
@@ -3092,8 +3156,8 @@ function generateShown(scene, dragged, options, hidden) {
3092
3156
  const { now } = c;
3093
3157
  const live = specsOf(c, item.kind);
3094
3158
  const alone = new Map(live.map((s) => [s, tileEdge(c, s, { cuts: [], bodies: [] }, [])]));
3095
- const along = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
3096
- const own = ownership(c, live, (s) => along.get(s));
3159
+ const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
3160
+ const own = ownership(c, live, (s) => along2.get(s));
3097
3161
  const lost = [];
3098
3162
  const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
3099
3163
  const ownRect = now.items[dragged];
@@ -3119,7 +3183,7 @@ function generateShown(scene, dragged, options, hidden) {
3119
3183
  place: { kind: "float" },
3120
3184
  after(point, grab) {
3121
3185
  const g = grab ?? { x: size.width / 2, y: size.height / 2 };
3122
- const raw = rect(point.x - g.x, point.y - g.y, size.width, size.height);
3186
+ const raw = options.floatFromHeld ? heldRect(scene, dragged, size, point, g) : rect(point.x - g.x, point.y - g.y, size.width, size.height);
3123
3187
  const first = solve(use(floatAt(scene, dragged, raw, options.floatOrient), dragged), prev);
3124
3188
  const at = first.items[dragged]?.rect ?? raw;
3125
3189
  return c.settle(use(floatAt(scene, dragged, rect(at.x, at.y, size.width, size.height), options.floatOrient), dragged));
@@ -3154,6 +3218,10 @@ var stageOf = (scene) => rect(scene.stage.x, scene.stage.y, scene.stage.width, s
3154
3218
  function targets(scene, dragged, options = {}) {
3155
3219
  return generate(scene, dragged, options).targets;
3156
3220
  }
3221
+ function targetsAndRefusals(scene, dragged, options = {}) {
3222
+ const g = generate(scene, dragged, options);
3223
+ return { targets: g.targets, refusals: g.refusals };
3224
+ }
3157
3225
  function refusals(scene, dragged, options = {}) {
3158
3226
  return generate(scene, dragged, options).refusals;
3159
3227
  }
@@ -3163,12 +3231,12 @@ function refusalTargets(list) {
3163
3231
  var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
3164
3232
  function stops(scene, dragged, options = {}) {
3165
3233
  const key = stopsKey(dragged, options);
3166
- let memo = stopsMemo.get(scene);
3167
- if (!memo) stopsMemo.set(scene, memo = /* @__PURE__ */ new Map());
3168
- let list = memo.get(key);
3234
+ let memo2 = stopsMemo.get(scene);
3235
+ if (!memo2) stopsMemo.set(scene, memo2 = /* @__PURE__ */ new Map());
3236
+ let list = memo2.get(key);
3169
3237
  if (!list) {
3170
- if (memo.size >= STOPS_PER_SCENE) memo.clear();
3171
- memo.set(key, list = orderedStops(scene, dragged, options));
3238
+ if (memo2.size >= STOPS_PER_SCENE) memo2.clear();
3239
+ memo2.set(key, list = orderedStops(scene, dragged, options));
3172
3240
  }
3173
3241
  return [...list];
3174
3242
  }
@@ -3204,6 +3272,276 @@ function orderedStops(scene, dragged, options) {
3204
3272
  return list.map((t, i) => ({ t, i, k: key(t) })).sort((a, b) => a.k[0] - b.k[0] || a.k[1] - b.k[1] || a.k[2] - b.k[2] || a.i - b.i).map((x) => x.t);
3205
3273
  }
3206
3274
 
3275
+ // src/scene/lanes.ts
3276
+ var SPOT_PITCH = 40;
3277
+ var mid = (r, axis) => axis === "x" ? r.x + r.width / 2 : r.y + r.height / 2;
3278
+ var lo = (r, axis) => axis === "x" ? r.x : r.y;
3279
+ var len = (r, axis) => axis === "x" ? r.width : r.height;
3280
+ var hull2 = (a, b) => {
3281
+ const x = Math.min(a.x, b.x);
3282
+ const y = Math.min(a.y, b.y);
3283
+ return rect(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3284
+ };
3285
+ var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
3286
+ var sameRect = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.5;
3287
+ var ORIGIN = { x: 0, y: 0 };
3288
+ function onEdge(l, edge, dragged, axis) {
3289
+ return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS && it.rect.height > EPS).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
3290
+ }
3291
+ function neighbors(after, edge, dragged, axis) {
3292
+ const me = after.items[dragged];
3293
+ const others = onEdge(after, edge, dragged, axis);
3294
+ const at = me ? mid(me.rect, axis) : 0;
3295
+ return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
3296
+ }
3297
+ function othersKey(layout, dragged) {
3298
+ return Object.keys(layout.items).filter((id) => id !== dragged).sort().map((id) => {
3299
+ const it = layout.items[id];
3300
+ return it.inMenu ? `${id}:m` : `${id}:${Math.round(it.rect.x)},${Math.round(it.rect.y)},${Math.round(it.rect.width)},${Math.round(it.rect.height)}`;
3301
+ }).join(";");
3302
+ }
3303
+ var memo = /* @__PURE__ */ new WeakMap();
3304
+ var previousIds = /* @__PURE__ */ new WeakMap();
3305
+ var nextPrevious = 1;
3306
+ function keyOf(dragged, o) {
3307
+ const { previous, spot: _spot, ...rest } = o;
3308
+ let p = 0;
3309
+ if (previous) {
3310
+ if (!previousIds.has(previous)) previousIds.set(previous, nextPrevious++);
3311
+ p = previousIds.get(previous);
3312
+ }
3313
+ return `${dragged}\0${p}\0${JSON.stringify(rest)}`;
3314
+ }
3315
+ function lanes(scene, dragged, options = {}) {
3316
+ const key = keyOf(dragged, options);
3317
+ let perScene = memo.get(scene);
3318
+ if (!perScene) memo.set(scene, perScene = /* @__PURE__ */ new Map());
3319
+ let base = perScene.get(key);
3320
+ if (!base) perScene.set(key, base = build(scene, dragged, options));
3321
+ if (!options.spot) return { ...base.regions, lanes: base.lanes };
3322
+ const found = [...base.raws].find(([, rs]) => rs.some((r) => r.id === options.spot));
3323
+ if (!found) return { ...base.regions, lanes: base.lanes };
3324
+ const [heldLane, list] = found;
3325
+ const held = list.find((r) => r.id === options.spot);
3326
+ const lane = laneFrom(heldLane, list, held.layout, base.seen, dragged, base.refusals, base.halves.has(heldLane), base.share);
3327
+ return { ...base.regions, lanes: base.lanes.map((l) => l.id === heldLane && lane ? lane : l) };
3328
+ }
3329
+ function build(scene, dragged, options) {
3330
+ const seen = solve(scene, options.previous ? { previous: options.previous } : {});
3331
+ const { targets: ts, refusals: rs } = targetsAndRefusals(scene, dragged, options);
3332
+ const own = seen.items[dragged];
3333
+ const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
3334
+ const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
3335
+ const raws = [];
3336
+ const axisOfEdge = (id) => {
3337
+ const e = scene.edges.find((x) => x.id === id);
3338
+ return e && axisOf(e.side) === "column" ? "y" : "x";
3339
+ };
3340
+ const columnKey = (side, ring) => scene.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
3341
+ for (const t of ts) {
3342
+ if (t.free) continue;
3343
+ const p = t.place;
3344
+ if (p.kind === "gap" || p.kind === "home" && ownEdge) {
3345
+ const edge = p.kind === "gap" ? p.edge : ownEdge;
3346
+ const axis = axisOfEdge(edge);
3347
+ const layout = p.kind === "home" ? seen : t.after(ORIGIN, ORIGIN).layout;
3348
+ const landing = p.kind === "home" ? own.rect : layout.items[dragged]?.rect;
3349
+ if (!landing) continue;
3350
+ const zone = p.kind === "gap" ? p.zone : own?.zone ?? "start";
3351
+ const n = neighbors(layout, edge, dragged, axis);
3352
+ const id = n.before === "^" && n.next === "$" ? `${edge}/${zone}` : `${edge}/${zone}/${n.before}|${n.next}`;
3353
+ raws.push({ lane: edge, edge, axis, id, ...n, landing, layout, target: t, hit: t.hit, ...p.kind === "home" ? { home: true } : {} });
3354
+ } else if (p.kind === "column" || p.kind === "rail") {
3355
+ const layout = t.after(ORIGIN, ORIGIN).layout;
3356
+ const landing = layout.items[dragged]?.rect;
3357
+ if (!landing) continue;
3358
+ const lane = p.kind === "column" ? `column:${p.side}:${columnKey(p.side, p.ring)}` : `rail:${p.side}`;
3359
+ raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: t.hit });
3360
+ }
3361
+ }
3362
+ if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, raws, pitch));
3363
+ const byLane = /* @__PURE__ */ new Map();
3364
+ for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
3365
+ const halves = new Set(scene.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
3366
+ const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS ? 0.5 : clamp(g / size, 0, 1);
3367
+ const w = own?.rect.width ?? 0;
3368
+ const h = own?.rect.height ?? 0;
3369
+ const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
3370
+ const laneList = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share)).filter((l) => !!l);
3371
+ const onLanes = new Set(laneList.map((l) => l.id));
3372
+ const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS && r.rect.height > EPS ? [r.rect] : []);
3373
+ const blocked = [
3374
+ ...Object.values(seen.edges).filter((e) => e.cross > EPS).map((e) => e.rect),
3375
+ ...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
3376
+ ...chromeFor(scene, "targets"),
3377
+ ...rails,
3378
+ // Spots where a release cancels (`Scene.blocked`): no float lands there.
3379
+ ...scene.blocked ?? []
3380
+ ];
3381
+ return {
3382
+ raws: byLane,
3383
+ lanes: laneList,
3384
+ seen,
3385
+ refusals: rs,
3386
+ halves,
3387
+ share,
3388
+ regions: {
3389
+ refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
3390
+ content: seen.content,
3391
+ blocked,
3392
+ stage: scene.stage,
3393
+ floatRegion: floatRegion(scene, dragged),
3394
+ item: own ? { width: own.rect.width, height: own.rect.height } : { width: 0, height: 0 },
3395
+ float: ts.find((t) => t.free) ?? null,
3396
+ refusals: rs
3397
+ }
3398
+ };
3399
+ }
3400
+ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share) {
3401
+ if (list.length === 0) return null;
3402
+ const first = list[0];
3403
+ const axis = first.axis;
3404
+ const edgeLayout = first.edge ? seen.edges[first.edge] : void 0;
3405
+ const band = list.map((r) => r.landing).reduce(hull2);
3406
+ let laneRect;
3407
+ if (edgeLayout && edgeLayout.cross > EPS) laneRect = edgeLayout.rect;
3408
+ else if (edgeLayout) laneRect = axis === "x" ? rect(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3409
+ else laneRect = list.map((r) => r.hit).reduce(hull2, band);
3410
+ const sorted = [...list].sort((a, b) => mid(a.landing, axis) - mid(b.landing, axis) || (a.home ? -1 : b.home ? 1 : 0));
3411
+ const unique = sorted.filter((x, i) => !sorted.slice(0, i).some((y) => sameRect(y.landing, x.landing) || y.id === x.id));
3412
+ const start = lo(laneRect, axis);
3413
+ const end = start + len(laneRect, axis);
3414
+ const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
3415
+ const held = halves ? 0.5 : share[axis];
3416
+ const cuts = [];
3417
+ for (let i = 0; i + 1 < unique.length; i++) {
3418
+ const a = unique[i];
3419
+ const b = unique[i + 1];
3420
+ const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
3421
+ const raw = shared ? mid(shared, axis) : (lo(a.landing, axis) + len(a.landing, axis) + lo(b.landing, axis)) / 2 + (held - 0.5) * (len(a.landing, axis) + len(b.landing, axis)) / 2;
3422
+ cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? start), start, end));
3423
+ }
3424
+ const spots = unique.map((x, i) => ({
3425
+ id: x.id,
3426
+ along: [i === 0 ? start : cuts[i - 1], i === unique.length - 1 ? end : cuts[i]],
3427
+ landing: x.landing,
3428
+ target: x.target,
3429
+ ...x.home ? { home: true } : {},
3430
+ ...x.pitched ? { pitched: true } : {},
3431
+ others: othersKey(x.layout, dragged)
3432
+ }));
3433
+ const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
3434
+ const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp(lo(h, axis), start, end), clamp(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS) : [];
3435
+ const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
3436
+ const marks = first.edge ? edgeMarks(id, laneRect, axis, onEdge(drawn, first.edge, "", axis), refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged) : virtualMarks(id, unique, drawn.items[dragged]);
3437
+ return { id, rect: laneRect, axis, spots, refused, marks };
3438
+ }
3439
+ var along = (r, axis, a, b) => axis === "x" ? rect(a, r.y, b - a, r.height) : rect(r.x, a, r.width, b - a);
3440
+ var LINE2 = 2;
3441
+ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held) {
3442
+ const out = [];
3443
+ const start = lo(laneRect, axis);
3444
+ const end = start + len(laneRect, axis);
3445
+ const ends = [{ id: "^", a: start, b: start }, ...items.map((o) => ({ id: o.id, a: lo(o.r, axis), b: lo(o.r, axis) + len(o.r, axis) })), { id: "$", a: end, b: end }];
3446
+ const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
3447
+ for (let i = 0; i + 1 < ends.length; i++) {
3448
+ const a = clamp(ends[i].b, start, end);
3449
+ const b = clamp(ends[i + 1].a, start, end);
3450
+ const pair = `${ends[i].id}|${ends[i + 1].id}`;
3451
+ if (ends[i + 1].a < start - EPS || ends[i].b > end + EPS || !lands(pair)) continue;
3452
+ const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
3453
+ const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
3454
+ const named = `${left}|${right}`;
3455
+ if (b - a < itemLen - EPS) {
3456
+ const t = Math.max(0, Math.min(LINE2, b - a)) / 2;
3457
+ if (items.length > 0 && named === pair && !isRefused2((a + b) / 2)) out.push({ id: `${lane}/line/${pair}`, kind: "line", rect: along(laneRect, axis, (a + b) / 2 - t, (a + b) / 2 + t) });
3458
+ continue;
3459
+ }
3460
+ let pieces = [[a, b]];
3461
+ for (const f of refused) pieces = pieces.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]).filter(([p, q]) => q - p > EPS);
3462
+ let k = 0;
3463
+ for (const [p, q] of pieces) {
3464
+ if (q - p < itemLen - EPS) continue;
3465
+ const base = `${lane}/box/${named}${k++ ? `#${k - 1}` : ""}`;
3466
+ out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
3467
+ }
3468
+ }
3469
+ return out;
3470
+ }
3471
+ function virtualMarks(lane, spots, held) {
3472
+ return spots.map((s) => {
3473
+ const l = s.landing;
3474
+ if (!held || held.floating || !overlaps3(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
3475
+ const x = mid(held.rect, "x") < mid(l, "x") ? l.x + l.width : l.x;
3476
+ return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect(x, l.y, 0, l.height) };
3477
+ });
3478
+ }
3479
+ var overlaps3 = (a, b) => a.x < b.x + b.width - EPS && b.x < a.x + a.width - EPS && a.y < b.y + b.height - EPS && b.y < a.y + a.height - EPS;
3480
+ function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
3481
+ const out = [];
3482
+ if (!scene.items[dragged]) return out;
3483
+ const prev = options.previous ? { previous: options.previous } : {};
3484
+ for (const e of scene.edges) {
3485
+ const bar = e.side === "top" || e.side === "bottom";
3486
+ if (!bar && !e.compact) continue;
3487
+ const axis = bar ? "x" : "y";
3488
+ const mine = raws.filter((r) => r.edge === e.id);
3489
+ const drawn = seen.edges[e.id];
3490
+ if (mine.length === 0 || !drawn) continue;
3491
+ const w = len(mine[0].landing, axis);
3492
+ const gap = nonNeg(e.gap);
3493
+ const others = onEdge(seen, e.id, dragged, axis);
3494
+ const edgeStart = lo(drawn.rect, axis) + nonNeg(e.pad?.start);
3495
+ const edgeEnd = lo(drawn.rect, axis) + len(drawn.rect, axis) - nonNeg(e.pad?.end);
3496
+ const middle = mid(drawn.rect, axis);
3497
+ const zoneOf2 = (o) => o.zone ?? "start";
3498
+ const taken = mine.map((r) => r.landing);
3499
+ const emit3 = (zone, at, space, x0) => {
3500
+ const place = { edge: e.id, zone, at, space };
3501
+ const next = moveTo(scene, dragged, place);
3502
+ if (next === scene) return;
3503
+ const layout = solve(next, prev);
3504
+ const landed = layout.items[dragged];
3505
+ if (!landed || landed.inMenu || landed.edge !== e.id || x0 !== void 0 && Math.abs(lo(landed.rect, axis) - x0) > 1) return;
3506
+ if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return;
3507
+ taken.push(landed.rect);
3508
+ const result = { scene: next, layout };
3509
+ const target = { id: `pitch:${e.id}:${zone}:${at}:${Math.round(space)}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
3510
+ const n = neighbors(layout, e.id, dragged, axis);
3511
+ const id = `${e.id}/${zone}/${n.before}|${n.next}@${Math.round(space / pitch)}`;
3512
+ out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
3513
+ };
3514
+ const spaced = (o) => !!o && (scene.items[o.id]?.space ?? 0) > 0;
3515
+ const own = scene.items[dragged];
3516
+ if (own && (own.space ?? 0) > 0 && seen.items[dragged]?.edge === e.id) {
3517
+ const zone = zoneIn(e, own);
3518
+ if (zone === "start") emit3("start", 0, 0);
3519
+ else if (zone === "end") emit3("end", others.filter((o) => zoneOf2(o) === "end").length, 0);
3520
+ }
3521
+ const slack = (o) => {
3522
+ const main = o ? scene.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
3523
+ return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
3524
+ };
3525
+ for (let i = 0; i <= others.length; i++) {
3526
+ const before = others[i - 1];
3527
+ const after = others[i];
3528
+ const a = before ? lo(before.r, axis) + len(before.r, axis) - slack(before) + gap : edgeStart;
3529
+ const b = after ? lo(after.r, axis) - gap : edgeEnd;
3530
+ if (spaced(after) && zoneOf2(after) === "start" && (!before || zoneOf2(before) === "start")) emit3("start", others.filter((o) => zoneOf2(o) === "start" && lo(o.r, axis) < lo(after.r, axis)).length, 0);
3531
+ if (spaced(before) && zoneOf2(before) === "end" && (!after || zoneOf2(after) === "end")) emit3("end", others.filter((o) => zoneOf2(o) === "end" && lo(o.r, axis) <= lo(before.r, axis)).length, 0);
3532
+ if (b - a < w + pitch) continue;
3533
+ for (let x0 = a + pitch; x0 + w <= b - pitch + EPS; x0 += pitch) {
3534
+ const toStart = x0 + w / 2 < middle;
3535
+ if (toStart && before && zoneOf2(before) !== "start") continue;
3536
+ if (!toStart && after && zoneOf2(after) !== "end") continue;
3537
+ const zone = toStart ? "start" : "end";
3538
+ emit3(zone, others.filter((o) => zoneOf2(o) === zone && lo(o.r, axis) < x0).length, toStart ? x0 - a : b - (x0 + w), x0);
3539
+ }
3540
+ }
3541
+ }
3542
+ return out;
3543
+ }
3544
+
3207
3545
  export {
3208
3546
  SIDES,
3209
3547
  ZONES,
@@ -3216,6 +3554,7 @@ export {
3216
3554
  DEFAULT_STRIP,
3217
3555
  DEFAULT_HIT_BAND,
3218
3556
  DEFAULT_FLOAT_SIZE,
3557
+ heldRect,
3219
3558
  anchorName,
3220
3559
  zoneTakes,
3221
3560
  zonesTaking,
@@ -3225,6 +3564,7 @@ export {
3225
3564
  namesZone,
3226
3565
  isOutsideSideBar,
3227
3566
  isSideBar,
3567
+ isSideColumn,
3228
3568
  floatOrientOf,
3229
3569
  floatSizeOf,
3230
3570
  targetId,
@@ -3233,6 +3573,7 @@ export {
3233
3573
  placeTargetId,
3234
3574
  solve,
3235
3575
  fitResize,
3576
+ mergeSideColumns,
3236
3577
  lift,
3237
3578
  moveTo,
3238
3579
  floatAt,
@@ -3255,6 +3596,8 @@ export {
3255
3596
  targets,
3256
3597
  refusals,
3257
3598
  refusalTargets,
3258
- stops
3599
+ stops,
3600
+ SPOT_PITCH,
3601
+ lanes
3259
3602
  };
3260
- //# sourceMappingURL=chunk-32BGJAJA.js.map
3603
+ //# sourceMappingURL=chunk-A4DQQX7W.js.map