@n-uf/placement 26.11.50 → 26.11.52

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.
@@ -198,15 +198,32 @@ var floatOrientOf = (item) => {
198
198
  for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
199
199
  return "column";
200
200
  };
201
- function floatSizeOf(item, orient2 = floatOrientOf(item)) {
202
- if (item.floatSize) return item.floatSize;
201
+ var sized = (s) => !!s && Number.isFinite(s.width) && Number.isFinite(s.height) && s.width > 0 && s.height > 0;
202
+ var declaresFloatSizes = (item) => item.floatSizes !== void 0 && item.floatSizes !== null;
203
+ function naturalFloatSize(item, orient2) {
203
204
  const f = formsOf(item, orient2)[0];
204
- if (!f || f.main.grows) return DEFAULT_FLOAT_SIZE;
205
+ if (!f || f.main.grows) return void 0;
205
206
  const main = Number.isFinite(f.main.natural) ? Math.max(0, f.main.natural) : 0;
206
207
  const cross = Number.isFinite(f.cross.natural) ? Math.max(0, f.cross.natural) : 0;
207
- if (main <= 0 || cross <= 0) return DEFAULT_FLOAT_SIZE;
208
+ if (main <= 0 || cross <= 0) return void 0;
208
209
  return orient2 === "row" ? { width: main, height: cross } : { width: cross, height: main };
209
210
  }
211
+ function floatSizesOf(item, floatOrient = floatOrientOf(item)) {
212
+ const out = {};
213
+ if (sized(item.floatSize)) out[floatOrient] = item.floatSize;
214
+ for (const o of ["row", "column"]) {
215
+ const s = item.floatSizes?.[o];
216
+ if (sized(s)) out[o] = s;
217
+ }
218
+ return out.row || out.column ? out : void 0;
219
+ }
220
+ function floatSizeOf(item, orient2 = floatOrientOf(item), floatOrient = floatOrientOf(item)) {
221
+ if (!declaresFloatSizes(item)) return sized(item.floatSize) ? item.floatSize : naturalFloatSize(item, orient2) ?? DEFAULT_FLOAT_SIZE;
222
+ const own = item.floatSizes?.[orient2];
223
+ if (sized(own)) return own;
224
+ if (sized(item.floatSize) && orient2 === floatOrient) return item.floatSize;
225
+ return naturalFloatSize(item, orient2) ?? DEFAULT_FLOAT_SIZE;
226
+ }
210
227
  function foldedByOf(item, forms, form, start, edge) {
211
228
  if (item.closed || form < 1) return void 0;
212
229
  if (startOf(item, forms, edge) > 0) return "hand";
@@ -261,7 +278,7 @@ function floatShape(item, f) {
261
278
  const fm = forms[form];
262
279
  if (orient2 === "column" && forms.slice(0, form + 1).some(isWrap)) return { form, width: px2(fm.cross.natural), height: px2(fm.main.natural) };
263
280
  if (form > 0) return orient2 === "column" ? { form, width: w, height: px2(fm.main.natural) } : { form, width: px2(fm.main.natural), height: h };
264
- return { form, width: w, height: h };
281
+ return { form, ...fm.main.grows || !declaresFloatSizes(item) ? { width: w, height: h } : floatSizeOf(item, orient2, f.orient ?? floatOrientOf(item)) };
265
282
  }
266
283
 
267
284
  // src/scene/targets/ids.ts
@@ -559,6 +576,7 @@ function emit(d, edge, r, solved, extra = {}) {
559
576
  hidden: inMenu ? [] : f?.hides ?? [],
560
577
  rect: drawnRect,
561
578
  kind: it.kind,
579
+ axis: column ? "column" : "row",
562
580
  form: p.form,
563
581
  formKind: p.kind,
564
582
  edge: edge.id,
@@ -715,9 +733,9 @@ function solveEdge(scene, edge, ids, length, room, previous) {
715
733
  const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(formsById(p.id)[p.form])));
716
734
  const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
717
735
  if (Math.abs(s - free.cross) > EPS) {
718
- const sized = { ...input, cross: { ...cross, min: s, max: s } };
719
- const stack = fitStack(sized, previous ? { previous: previous.stack } : {});
720
- return { stack, free, tabs: [], closedTabs: none, input: sized, starts };
736
+ const sized2 = { ...input, cross: { ...cross, min: s, max: s } };
737
+ const stack = fitStack(sized2, previous ? { previous: previous.stack } : {});
738
+ return { stack, free, tabs: [], closedTabs: none, input: sized2, starts };
721
739
  }
722
740
  }
723
741
  return { stack: free, free, tabs: [], closedTabs: none, input, starts };
@@ -850,7 +868,7 @@ function layFloats(d, stage, content, inset) {
850
868
  if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
851
869
  if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
852
870
  const foldedBy = foldedByOf(it, formsOf(it, fo), from);
853
- 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 } : {} };
871
+ items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), hidden: form?.hides ?? [], rect: fit.rect, kind: it.kind, axis: fo, form: from, formKind: form?.kind ?? "open", floating: true, ...foldedBy ? { foldedBy } : {} };
854
872
  floats.push(f.id);
855
873
  }
856
874
  return floats;
@@ -1049,7 +1067,7 @@ function layRiders(d, host, riders, top) {
1049
1067
  for (const b of bars) {
1050
1068
  const at = rect(hr.x, y, hr.width, b.h);
1051
1069
  const it = scene.items[b.id];
1052
- 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" };
1070
+ items[b.id] = { rect: at, hidden: b.f?.hides ?? [], kind: it.kind, axis: "column", form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand", foldedBy: "hand" };
1053
1071
  y += b.h;
1054
1072
  }
1055
1073
  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" };
@@ -1094,7 +1112,7 @@ function layRail(d, side, railRect, railed, g) {
1094
1112
  const form = p ? p.form : ri >= 0 ? ri : forms.length === 0 ? 0 : startOf(it, forms);
1095
1113
  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);
1096
1114
  const title = forms[form]?.title === true;
1097
- 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: startOf(it, forms) > 0 ? "hand" : "auto" };
1115
+ items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, axis: "column", form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand", foldedBy: startOf(it, forms) > 0 ? "hand" : "auto" };
1098
1116
  segments.push({ id, edge: c.edge.id, rect: at });
1099
1117
  y += at.height;
1100
1118
  }
@@ -1511,15 +1529,22 @@ function floatAt(scene, id, at, orient2) {
1511
1529
  if (!item || item.fixed || !scene.floatKinds.includes(item.kind)) return scene;
1512
1530
  const was = scene.floats.find((f) => f.id === id);
1513
1531
  const o = orient2 ?? was?.orient;
1514
- const size = floatSizeOf(item, o ?? floatOrientOf(item));
1532
+ const fo = o ?? floatOrientOf(item);
1533
+ const size = floatSizeOf(item, fo, was?.orient ?? floatOrientOf(item));
1515
1534
  const since = was ? was.since : nextSince(scene);
1516
1535
  const seq = since !== void 0 ? { since } : {};
1517
1536
  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 };
1518
1537
  const { space: _space, ...unspaced } = item;
1519
- const next = at && at.width > 0 && at.height > 0 ? { ...unspaced, floatSize: { width: at.width, height: at.height } } : unspaced;
1538
+ const set = at && at.width > 0 && at.height > 0 ? { orient: fo, size: { width: at.width, height: at.height } } : void 0;
1539
+ const next = set || declaresFloatSizes(item) ? withFloatSizes(unspaced, was?.orient ?? floatOrientOf(item), set) : unspaced;
1520
1540
  const lifted = withItem(lift(scene, id), next);
1521
1541
  return { ...lifted, floats: [...lifted.floats, float] };
1522
1542
  }
1543
+ function withFloatSizes(item, floatOrient, set) {
1544
+ const { floatSize: _legacy, floatSizes: _sizes, ...rest } = item;
1545
+ const sizes = { ...floatSizesOf(item, floatOrient), ...set ? { [set.orient]: set.size } : {} };
1546
+ return sizes.row || sizes.column ? { ...rest, floatSizes: sizes } : rest;
1547
+ }
1523
1548
  function canFold(scene, id) {
1524
1549
  const item = itemOf(scene, id);
1525
1550
  if (!item || item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id))) return false;
@@ -1566,10 +1591,18 @@ function raise(scene, id) {
1566
1591
  return { ...scene, floats: [...scene.floats.slice(0, i), ...scene.floats.slice(i + 1), scene.floats[i]] };
1567
1592
  }
1568
1593
  function orient(scene, id, to) {
1569
- const i = scene.floats.findIndex((f) => f.id === id);
1594
+ const i = scene.floats.findIndex((f2) => f2.id === id);
1570
1595
  const item = scene.items[id];
1571
- if (i < 0 || !item || (scene.floats[i].orient ?? floatOrientOf(item)) === to) return scene;
1572
- return { ...scene, floats: scene.floats.map((f, k) => k === i ? { ...f, orient: to } : f) };
1596
+ const f = scene.floats[i];
1597
+ if (!f || !item) return scene;
1598
+ const from = f.orient ?? floatOrientOf(item);
1599
+ if (from === to) return scene;
1600
+ if (!declaresFloatSizes(item)) return { ...scene, floats: scene.floats.map((g, k) => k === i ? { ...g, orient: to } : g) };
1601
+ const grows = formsOf(item, from)[0]?.main.grows === true;
1602
+ const kept = withFloatSizes(item, from, grows && f.rect.width > 0 && f.rect.height > 0 ? { orient: from, size: { width: f.rect.width, height: f.rect.height } } : void 0);
1603
+ const size = drawnFloatSize(kept, { rect: { ...f.rect, ...floatSizeOf(kept, to, from) }, orient: to });
1604
+ const turned = { ...f, rect: { x: f.rect.x, y: f.rect.y, width: size.width, height: size.height }, orient: to };
1605
+ return withItem({ ...scene, floats: scene.floats.map((g, k) => k === i ? turned : g) }, kept);
1573
1606
  }
1574
1607
  function resize(scene, id, size, moving = { right: true, bottom: true }) {
1575
1608
  if (typeof size === "number") return resizeEdge(scene, id, size);
@@ -1579,7 +1612,8 @@ function resize(scene, id, size, moving = { right: true, bottom: true }) {
1579
1612
  if (!fit || i < 0 || !item) return scene;
1580
1613
  const { anchor: _a, ...plain } = scene.floats[i];
1581
1614
  const float = { ...plain, rect: fit.rect };
1582
- return withItem({ ...scene, floats: scene.floats.map((g, k) => k === i ? float : g) }, { ...item, floatSize: { width: fit.rect.width, height: fit.rect.height } });
1615
+ const fo = float.orient ?? floatOrientOf(item);
1616
+ return withItem({ ...scene, floats: scene.floats.map((g, k) => k === i ? float : g) }, withFloatSizes(item, fo, { orient: fo, size: { width: fit.rect.width, height: fit.rect.height } }));
1583
1617
  }
1584
1618
  function resizeEdge(scene, edgeId, size) {
1585
1619
  const edge = scene.edges.find((e) => e.id === edgeId);
@@ -1681,10 +1715,19 @@ function railModesOf(v, drop) {
1681
1715
  }
1682
1716
  return Object.keys(out).length > 0 ? out : null;
1683
1717
  }
1718
+ function floatSizesStored(it) {
1719
+ const out = {};
1720
+ for (const o of ["row", "column"]) {
1721
+ const s = it.floatSizes?.[o];
1722
+ if (s && isSize(s.width) && isSize(s.height)) out[o] = { width: s.width, height: s.height };
1723
+ }
1724
+ return out.row || out.column ? out : void 0;
1725
+ }
1684
1726
  function storeScene(scene) {
1685
1727
  const items = record();
1686
1728
  for (const [id, it] of Object.entries(scene.items)) {
1687
1729
  if (id === "__proto__") continue;
1730
+ const sizes = floatSizesStored(it);
1688
1731
  items[id] = {
1689
1732
  used: isNum(it.used) ? it.used : 0,
1690
1733
  ...it.kept ? { kept: true } : {},
@@ -1692,7 +1735,8 @@ function storeScene(scene) {
1692
1735
  ...it.closed ? { closed: true } : {},
1693
1736
  ...it.align === "center" || it.align === "end" ? { align: it.align } : {},
1694
1737
  ...isNum(it.space) && it.space > 0 ? { space: it.space } : {},
1695
- ...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}
1738
+ ...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {},
1739
+ ...sizes ? { floatSizes: sizes } : {}
1696
1740
  };
1697
1741
  }
1698
1742
  const modes = railModesOf(scene.railModes);
@@ -1739,6 +1783,7 @@ function read(data, base) {
1739
1783
  const known = (id) => typeof id === "string" && id !== "__proto__" && Object.hasOwn(base.items, id);
1740
1784
  const isFixed = (id) => known(id) && base.items[id].fixed === true;
1741
1785
  const items = { ...base.items };
1786
+ const legacy = /* @__PURE__ */ new Set();
1742
1787
  if (data.items !== void 0 && !isObject(data.items)) drop("items");
1743
1788
  else if (isObject(data.items)) {
1744
1789
  for (const id of Object.keys(data.items)) {
@@ -1748,9 +1793,9 @@ function read(data, base) {
1748
1793
  continue;
1749
1794
  }
1750
1795
  const b = base.items[id];
1751
- const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSize: _s, ...plain } = b;
1796
+ const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSize: _s, floatSizes: _ss, ...plain } = b;
1752
1797
  let it = { ...plain, used: b.used };
1753
- for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
1798
+ for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize", "floatSizes"].includes(k)) drop(`item:${id}:${k}`);
1754
1799
  if (isNum(s.used)) it = { ...it, used: s.used };
1755
1800
  else if (s.used !== void 0) drop(`item:${id}:used`);
1756
1801
  if (s.kept === true) it = { ...it, kept: true };
@@ -1767,8 +1812,20 @@ function read(data, base) {
1767
1812
  if (isNum(s.space) && s.space > 0 && !b.fixed) it = { ...it, space: s.space };
1768
1813
  else if (s.space !== void 0) drop(`item:${id}:space`);
1769
1814
  const fs = s.floatSize;
1770
- if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) it = { ...it, floatSize: { width: fs.width, height: fs.height } };
1771
- else if (fs !== void 0) drop(`item:${id}:floatSize`);
1815
+ if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) {
1816
+ it = { ...it, floatSize: { width: fs.width, height: fs.height } };
1817
+ legacy.add(id);
1818
+ } else if (fs !== void 0) drop(`item:${id}:floatSize`);
1819
+ const sizes2 = s.floatSizes;
1820
+ if (isObject(sizes2)) {
1821
+ const own = {};
1822
+ for (const k of Object.keys(sizes2)) {
1823
+ const v = sizes2[k];
1824
+ if ((k === "row" || k === "column") && isObject(v) && isSize(v.width) && isSize(v.height)) own[k] = { width: v.width, height: v.height };
1825
+ else drop(`item:${id}:floatSizes:${k}`);
1826
+ }
1827
+ if (own.row || own.column) it = { ...it, floatSizes: own };
1828
+ } else if (sizes2 !== void 0) drop(`item:${id}:floatSizes`);
1772
1829
  items[id] = it;
1773
1830
  }
1774
1831
  }
@@ -1869,6 +1926,7 @@ function read(data, base) {
1869
1926
  return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...size !== void 0 ? { size } : {} };
1870
1927
  });
1871
1928
  for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);
1929
+ for (const id of Object.keys(items)) if ((legacy.has(id) || items[id].floatSize !== void 0) && declaresFloatSizes(items[id])) items[id] = withFloatSizes(items[id], floats.find((f) => f.id === id)?.orient ?? floatOrientOf(items[id]));
1872
1930
  let scene = prune({ ...base, ...railModes ? { railModes } : {}, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
1873
1931
  for (const [id, side] of moves) scene = setSide(scene, id, side);
1874
1932
  return { scene, dropped };
@@ -2057,10 +2115,12 @@ function edgeSlots(c, edge, accepts) {
2057
2115
  const fromAnchor = (zone === "start" ? members : zone === "end" ? [...members].reverse() : []).filter((id) => fixedHere(id) || shown(id));
2058
2116
  const firstMovable = fromAnchor.findIndex((id) => !fixedHere(id));
2059
2117
  const anchored2 = new Set(firstMovable < 0 ? fromAnchor : fromAnchor.slice(0, firstMovable));
2060
- const isProtected = (id) => fixedHere(id) && (zone === "center" || zoneOf(rest.items[id]) !== zone || anchored2.has(id));
2118
+ const pushable = (id) => fixedHere(id) && scene.items[id]?.pushable === true;
2119
+ const isProtected = (id) => fixedHere(id) && (zone === "center" || zoneOf(rest.items[id]) !== zone || anchored2.has(id) && !pushable(id));
2061
2120
  for (let k = 0; k <= members.length; k++) {
2062
2121
  const next = members.slice(k).find(shown);
2063
2122
  const before = members.slice(0, k).reverse().find(shown);
2123
+ if (before && next && pushable(before) && pushable(next)) continue;
2064
2124
  const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len2(occupied(before)) : anchorLine[zone];
2065
2125
  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 };
2066
2126
  const movesFixed = members0.some((id) => {
@@ -2074,6 +2134,11 @@ function edgeSlots(c, edge, accepts) {
2074
2134
  }
2075
2135
  return slots;
2076
2136
  }
2137
+ function thickerThan(forms, cross) {
2138
+ const shown = forms.filter((f) => f.kind !== "menu");
2139
+ return shown.length > 0 && shown.every((f) => !formSetsCross(f) && formCrossMin(f) > cross + EPS);
2140
+ }
2141
+ var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
2077
2142
  function edgeSpec(c, edge) {
2078
2143
  const { scene, rest, now, dragged, kind } = c;
2079
2144
  const el = now.edges[edge.id];
@@ -2115,6 +2180,7 @@ function edgeSpec(c, edge) {
2115
2180
  return column ? rect(e.rect.x, slot.y, e.cross, 0) : rect(slot.x, e.rect.y, 0, e.cross);
2116
2181
  };
2117
2182
  const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
2183
+ const tooThick = thickerThan(formsOf(scene.items[dragged], axisOf(edge.side)), el.stack.cross);
2118
2184
  return {
2119
2185
  id: edge.id,
2120
2186
  edge,
@@ -2123,7 +2189,7 @@ function edgeSpec(c, edge) {
2123
2189
  vertical: column,
2124
2190
  zones,
2125
2191
  slots,
2126
- refuse: (zone) => takes(zone) ? "no-room" : accepts || area(el.rect) > EPS ? "not-accepted" : null,
2192
+ refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area(el.rect) > EPS ? "not-accepted" : null,
2127
2193
  own: ownHere,
2128
2194
  holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
2129
2195
  reserved,
@@ -2456,7 +2522,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2456
2522
  for (const [pa, pb] of pieces) {
2457
2523
  const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
2458
2524
  if (inPiece.length === 0) {
2459
- const lone = reason === "no-room" && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
2525
+ const lone = (reason === "no-room" || reason === "too-thick") && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
2460
2526
  const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS && pa < s.line + data.reach - EPS);
2461
2527
  const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
2462
2528
  if (joins.length > 0) {
@@ -2497,7 +2563,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2497
2563
  for (const [u, w] of less([[a, b]], faced)) {
2498
2564
  const line = Math.min(Math.max(p, u), w);
2499
2565
  const hit = band(u, w, s.result.layout);
2500
- if (!s.ok) out.push(...refused(z.zone, hit, "no-room"));
2566
+ if (!s.ok) out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
2501
2567
  else out.push(...split(tile(z.zone, hit, { kind: "slot", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged].rect })));
2502
2568
  }
2503
2569
  });
@@ -2596,7 +2662,7 @@ function clipTiles(tiles, own, chrome, lost) {
2596
2662
  return;
2597
2663
  }
2598
2664
  const solidPieces = pieces.filter((p) => p.width >= 1 && p.height >= 1);
2599
- for (const p of pieces) if (!solidPieces.includes(p)) (data.virtual ? later : refused).push({ ...t, kind: "refuse", reason: "no-room", hit: p, keep: null });
2665
+ for (const p of pieces) if (!solidPieces.includes(p)) (data.virtual ? later : refused).push({ ...t, kind: "refuse", reason: t.spec ? roomReason(t.spec, t.zone) : "no-room", hit: p, keep: null });
2600
2666
  if (solidPieces.length === 0) return;
2601
2667
  landed.set(t, [placed.length]);
2602
2668
  placed.push(withPieces(t, solidPieces));
@@ -2665,6 +2731,8 @@ function columnLines(c, side, railLands) {
2665
2731
  const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
2666
2732
  return { line, zone: span2(railFirst ? band0 : windowEdge, line + dir * reach), owned: span2(band0, band0 + dir * edgePlace) };
2667
2733
  };
2734
+ const most = scene.columns?.[side]?.cross.max;
2735
+ const tooThick = most !== void 0 && thickerThan(formsOf(scene.items[dragged], "column"), most);
2668
2736
  return lines.map((l, i) => {
2669
2737
  const p = placeOf(l, i);
2670
2738
  return {
@@ -2675,7 +2743,7 @@ function columnLines(c, side, railLands) {
2675
2743
  vertical: false,
2676
2744
  zones: [{ zone: "start", a: Math.max(p.zone[0], stage.x), b: Math.min(p.zone[1], stage.x + stage.width) }],
2677
2745
  slots: [slotAt(c, "start", p.line, targetId({ kind: "column", side, ring: l.ring }), { kind: "column", side, ring: l.ring }, lands)],
2678
- refuse: () => "no-room",
2746
+ refuse: () => tooThick ? "too-thick" : "no-room",
2679
2747
  own: null,
2680
2748
  holds: false,
2681
2749
  reserved: [],
@@ -2745,6 +2813,8 @@ function railStops(c, side) {
2745
2813
  const arriving = scene.foldedColumnDrop === "end" && !ownRail;
2746
2814
  const end = arriving && shown ? railEnd(c, side, rail.segments, at.y + at.height) : null;
2747
2815
  if (arriving && (shown ? !end : !isHandFolded(scene, dragged))) return null;
2816
+ const width = scene.rails?.[side]?.width;
2817
+ const tooThick = width !== void 0 && thickerThan(formsOf(scene.items[dragged], "column"), width);
2748
2818
  return {
2749
2819
  id: virtualEdgeId("rail", side),
2750
2820
  edge: null,
@@ -2754,7 +2824,7 @@ function railStops(c, side) {
2754
2824
  vertical: true,
2755
2825
  zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
2756
2826
  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)),
2757
- refuse: () => "no-room",
2827
+ refuse: () => tooThick ? "too-thick" : "no-room",
2758
2828
  own: null,
2759
2829
  holds: false,
2760
2830
  reserved: [],
@@ -3202,7 +3272,8 @@ function generateShown(scene, dragged, options, hidden) {
3202
3272
  if (scene.floatKinds.includes(item.kind)) {
3203
3273
  const was = scene.floats.find((f) => f.id === dragged);
3204
3274
  const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
3205
- const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
3275
+ const wasOrient = was?.orient ?? floatOrientOf(item);
3276
+ const size = options.floatSize ?? (was && wasOrient === fo ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo, wasOrient));
3206
3277
  targets2.push({
3207
3278
  id: targetId({ kind: "float", item: dragged }),
3208
3279
  priority: 3,
@@ -3327,12 +3398,38 @@ function neighbors(after, edge, dragged, axis) {
3327
3398
  const at = me ? mid(me.rect, axis) : 0;
3328
3399
  return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
3329
3400
  }
3401
+ function givesWay(now, after, lane, side, extent) {
3402
+ if (!now) return null;
3403
+ if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
3404
+ const [p0, p1] = extent(now.rect);
3405
+ const [q0, q1] = extent(after.rect);
3406
+ if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
3407
+ return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
3408
+ }
3409
+ function liftedLayout(scene, dragged, options) {
3410
+ return solve(lift(scene, dragged), options.previous ? { previous: options.previous } : {});
3411
+ }
3330
3412
  function othersKey(layout, dragged) {
3331
3413
  return Object.keys(layout.items).filter((id) => id !== dragged).sort().map((id) => {
3332
3414
  const it = layout.items[id];
3333
3415
  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)}`;
3334
3416
  }).join(";");
3335
3417
  }
3418
+ function clipAtDrawn(band, axis, cuts) {
3419
+ let a = lo(band, axis);
3420
+ let b = a + len(band, axis);
3421
+ const center = (a + b) / 2;
3422
+ const x = axis === "x" ? "y" : "x";
3423
+ const line = lo(band, x) + len(band, x) / 2;
3424
+ for (const c of cuts) {
3425
+ if (!(lo(c, x) < line - EPS && line < lo(c, x) + len(c, x) - EPS)) continue;
3426
+ const c0 = lo(c, axis);
3427
+ const c1 = c0 + len(c, axis);
3428
+ if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
3429
+ else b = Math.min(b, c0);
3430
+ }
3431
+ return b - a > EPS ? along(band, axis, a, b) : band;
3432
+ }
3336
3433
  var memo = /* @__PURE__ */ new WeakMap();
3337
3434
  var previousIds = /* @__PURE__ */ new WeakMap();
3338
3435
  var nextPrevious = 1;
@@ -3358,12 +3455,20 @@ function lanes(scene, dragged, options = {}) {
3358
3455
  const held = list.find((r) => r.id === options.spot);
3359
3456
  const rebuilt = base.lanes.map((l) => {
3360
3457
  const raws = base.raws.get(l.id);
3361
- if (!raws) return l;
3362
- const again = laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, l.id === heldLane && !held.slide);
3363
- if (!again) return l;
3364
- return l.id === heldLane ? again : { ...l, marks: again.marks };
3458
+ if (!raws) return asDrawn(l);
3459
+ const again = l.id === heldLane ? heldLaneIn(l.id, raws, held, base, dragged) : laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, false, true);
3460
+ if (!again) return asDrawn(l);
3461
+ return l.id === heldLane ? again : { ...asDrawn(l), marks: again.marks };
3365
3462
  });
3366
- return { ...base.regions, lanes: rebuilt.map((l) => settle(l, held.layout, scene, dragged, rebuilt, options.emptyLanes)) };
3463
+ return { ...base.regions, lanes: rebuilt.map((l) => settle(l, held.layout, scene, dragged, rebuilt, options.emptyLanes, base.raws.get(l.id) ? laneRectOver(base.raws.get(l.id), held.layout, base.seen, base.marking).rect : l.rect)) };
3464
+ }
3465
+ function asDrawn(l) {
3466
+ if (!l.entry && !l.corners) return l;
3467
+ const { entry: _entry, corners: _corners, ...rest } = l;
3468
+ return rest;
3469
+ }
3470
+ function heldLaneIn(id, raws, held, base, dragged) {
3471
+ return laneFrom(id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(id), base.share, base.marking, !held.slide, true);
3367
3472
  }
3368
3473
  function build(scene, dragged, options) {
3369
3474
  const seen = solve(scene, options.previous ? { previous: options.previous } : {});
@@ -3399,12 +3504,13 @@ function build(scene, dragged, options) {
3399
3504
  raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: strip ?? t.hit, ...strip ? { strip: true } : {} });
3400
3505
  }
3401
3506
  }
3507
+ const lifted = liftedLayout(scene, dragged, options);
3402
3508
  if (options.stretchPositions !== "pitched") {
3403
- const { spots, absorbed } = slidingSpots(scene, dragged, options, seen, raws, pitch > 0 ? pitch : SPOT_PITCH);
3509
+ const { spots, absorbed } = slidingSpots(scene, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH);
3404
3510
  for (let i = raws.length - 1; i >= 0; i--) if (absorbed.has(raws[i])) raws.splice(i, 1);
3405
3511
  raws.push(...spots);
3406
- } else if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, raws, pitch));
3407
- raws.push(...takeoverSpots(scene, dragged, options, seen, raws, pitch > 0 ? pitch : SPOT_PITCH));
3512
+ } else if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, lifted, raws, pitch));
3513
+ raws.push(...takeoverSpots(scene, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH));
3408
3514
  const byLane = /* @__PURE__ */ new Map();
3409
3515
  for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
3410
3516
  const halves = new Set(scene.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
@@ -3414,14 +3520,17 @@ function build(scene, dragged, options) {
3414
3520
  const main = scene.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
3415
3521
  return main?.grows ? main.natural : void 0;
3416
3522
  },
3417
- gap: (edge) => nonNeg(scene.edges.find((e) => e.id === edge)?.gap)
3523
+ gap: (edge) => nonNeg(scene.edges.find((e) => e.id === edge)?.gap),
3524
+ lifted,
3525
+ crossing: (edge, over) => scene.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over.edges[e.id]?.cross ?? 0) > EPS && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over.edges[e.id].rect)
3418
3526
  };
3419
3527
  const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS ? 0.5 : clamp(g / size, 0, 1);
3420
3528
  const w = own?.rect.width ?? 0;
3421
3529
  const h = own?.rect.height ?? 0;
3422
3530
  const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
3423
3531
  const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
3424
- const laneList = built.map((l) => settle(l, seen, scene, dragged, built, options.emptyLanes));
3532
+ const settled = built.map((l) => settle(l, seen, scene, dragged, built, options.emptyLanes));
3533
+ const laneList = options.emptyLanes === "edge" ? settled : predict(settled, byLane, { seen, refusals: rs, halves, share, marking }, scene, dragged, built, options.emptyLanes);
3425
3534
  const onLanes = new Set(laneList.map((l) => l.id));
3426
3535
  const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS && r.rect.height > EPS ? [r.rect] : []);
3427
3536
  const blocked = [
@@ -3452,25 +3561,40 @@ function build(scene, dragged, options) {
3452
3561
  }
3453
3562
  };
3454
3563
  }
3455
- function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, heldHere = false) {
3456
- if (list.length === 0) return null;
3564
+ function laneRectOver(list, over, seen, marking) {
3457
3565
  const first = list[0];
3458
3566
  const axis = first.axis;
3459
- const edgeLayout = first.edge ? seen.edges[first.edge] : void 0;
3567
+ const edgeLayout = first.edge ? over.edges[first.edge] : void 0;
3460
3568
  const band = list.map((r) => r.landing).reduce(hull2);
3461
- let laneRect;
3462
- if (edgeLayout && edgeLayout.cross > EPS) laneRect = edgeLayout.rect;
3463
- 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);
3464
- else if (list.every((r) => r.strip)) laneRect = list.map((r) => r.hit).reduce(hull2);
3465
- else laneRect = list.map((r) => r.hit).reduce(hull2, band);
3569
+ if (!edgeLayout) return { rect: list.every((r) => r.strip) ? list.map((r) => r.hit).reduce(hull2) : list.map((r) => r.hit).reduce(hull2, band) };
3570
+ const drawnHere = edgeLayout.cross > EPS;
3571
+ const whole = drawnHere ? edgeLayout.rect : axis === "x" ? rect(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3572
+ const emptyAsSeen = (seen.edges[first.edge]?.cross ?? 0) <= EPS;
3573
+ const clipped = emptyAsSeen ? clipAtDrawn(whole, axis, marking.crossing(first.edge, seen)) : whole;
3574
+ return drawnHere ? { rect: clipped } : { rect: clipped, band: whole };
3575
+ }
3576
+ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, heldHere = false, spotHeld = false) {
3577
+ if (list.length === 0) return null;
3578
+ const first = list[0];
3579
+ const axis = first.axis;
3580
+ const { rect: laneRect, band: markBand } = laneRectOver(list, seen, seen, marking);
3466
3581
  const firstOf = (r) => r.slide?.first ?? r.landing;
3467
3582
  const lastOf = (r) => r.slide?.last ?? r.landing;
3468
3583
  const sorted = [...list].sort((a, b) => mid(firstOf(a), axis) - mid(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0));
3469
3584
  const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
3470
3585
  const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
3471
- const unique = sorted.filter((x, i) => !nearHome(x) && !sorted.slice(0, i).some((y) => !x.slide && !y.slide && sameRect(y.landing, x.landing) || y.id === x.id));
3586
+ const unique = [];
3587
+ for (const x of sorted) {
3588
+ if (nearHome(x)) continue;
3589
+ const k = unique.findIndex((y) => !x.slide && !y.slide && sameRect(y.landing, x.landing) || y.id === x.id);
3590
+ if (k < 0) unique.push(x);
3591
+ else if (x.home && !unique[k].home && !unique.some((y) => y.id === x.id && y !== unique[k])) unique[k] = x;
3592
+ }
3472
3593
  const start = lo(laneRect, axis);
3473
3594
  const end = start + len(laneRect, axis);
3595
+ const whole = markBand ?? laneRect;
3596
+ const bandStart = lo(whole, axis);
3597
+ const bandEnd = bandStart + len(whole, axis);
3474
3598
  const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
3475
3599
  const held = halves ? 0.5 : share[axis];
3476
3600
  const cuts = [];
@@ -3486,11 +3610,16 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3486
3610
  const slack = Math.max(0, marking.pitch) / 2;
3487
3611
  const atGrab = clamp(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
3488
3612
  const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
3489
- cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? start), start, end));
3613
+ cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
3490
3614
  }
3491
- const spots = unique.map((x, i) => ({
3615
+ const spots = unique.flatMap((x, i) => {
3616
+ const a = i === 0 ? bandStart : cuts[i - 1];
3617
+ const b = i === unique.length - 1 ? bandEnd : cuts[i];
3618
+ const along2 = [clamp(a, start, end), clamp(b, start, end)];
3619
+ return along2[1] - along2[0] > EPS || b - a <= EPS || x.home ? [{ x, along: along2 }] : [];
3620
+ }).map(({ x, along: along2 }) => ({
3492
3621
  id: x.id,
3493
- along: [i === 0 ? start : cuts[i - 1], i === unique.length - 1 ? end : cuts[i]],
3622
+ along: along2,
3494
3623
  landing: x.landing,
3495
3624
  target: x.target,
3496
3625
  ...x.home ? { home: true } : {},
@@ -3502,14 +3631,14 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3502
3631
  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) : [];
3503
3632
  const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
3504
3633
  const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
3505
- const markRect = drawnEdge && drawnEdge.cross > EPS ? drawnEdge.rect : laneRect;
3634
+ const markRect = drawnEdge && drawnEdge.cross > EPS ? drawnEdge.rect : markBand ?? laneRect;
3506
3635
  const marked = first.edge ? onEdge(drawn, first.edge, heldHere ? "" : dragged, axis).map((o) => {
3507
3636
  const n = o.id === dragged || halves ? void 0 : marking.natural(o.id, axis);
3508
3637
  return n !== void 0 && n < len(o.r, axis) ? { ...o, r: along(o.r, axis, lo(o.r, axis), lo(o.r, axis) + n) } : o;
3509
3638
  }) : [];
3510
3639
  const landings = /* @__PURE__ */ new Map();
3511
3640
  if (!halves) {
3512
- for (const x of unique) if (!x.pitched && !x.home && !x.slide && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
3641
+ for (const x of unique) if (!x.pitched && !x.home && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
3513
3642
  }
3514
3643
  const extent = (iid, r) => {
3515
3644
  const n = halves ? void 0 : marking.natural(iid, axis);
@@ -3519,7 +3648,9 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3519
3648
  besideMin: halves || marking.pitch <= 0 ? itemLen : marking.pitch,
3520
3649
  gap: marking.gap(first.edge),
3521
3650
  landingOf: (pair) => landings.get(pair),
3522
- extent
3651
+ // Judged against the layout the marks are drawn in; with a spot held, against the layout as seen with the held
3652
+ // item lifted (in the spot's own a neighbor has already stepped down or moved).
3653
+ givesWay: (iid, side, after) => givesWay((spotHeld ? marking.lifted : drawn).items[iid], after.items[iid], id, side, (r) => extent(iid, r))
3523
3654
  }) : virtualMarks(id, unique, drawn.items[dragged]);
3524
3655
  return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
3525
3656
  }
@@ -3530,6 +3661,10 @@ var HATCH_END = 8;
3530
3661
  var HATCH_EDGE = 8;
3531
3662
  function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
3532
3663
  const { besideMin } = more;
3664
+ const hatches = (pair, a, b, p, q, gl, gr) => {
3665
+ if (gl && Math.abs(p - a) < EPS) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
3666
+ if (gr && Math.abs(q - b) < EPS) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
3667
+ };
3533
3668
  const heldAt = items.find((o) => o.id === held);
3534
3669
  const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
3535
3670
  const out = [];
@@ -3547,33 +3682,18 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3547
3682
  const named = `${left}|${right}`;
3548
3683
  const beside = ends[i + 1].id === held ? "before" : ends[i].id === held ? "after" : null;
3549
3684
  const min = beside ? Math.min(itemLen, besideMin) : itemLen;
3685
+ const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
3686
+ const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
3687
+ const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
3550
3688
  if (b - a < min - EPS) {
3551
- const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) && b - a >= besideMin - EPS ? more.landingOf(pair) : void 0;
3552
- if (spot) {
3553
- const own = (iid) => {
3554
- const it = spot.layout.items[iid];
3555
- return it && !it.inMenu && !it.floating && it.edge === lane ? more.extent(iid, it.rect) : null;
3556
- };
3557
- let gl = left !== "^" && (() => {
3558
- const o = own(left);
3559
- return !o || a - o[1] > 0.5;
3560
- })();
3561
- let gr = right !== "$" && (() => {
3562
- const o = own(right);
3563
- return !o || o[0] - b > 0.5;
3564
- })();
3565
- if (!gl && !gr) {
3566
- if (right !== "$") gr = true;
3567
- else if (left !== "^") gl = true;
3568
- }
3689
+ if (spot && b - a >= besideMin - EPS) {
3569
3690
  let ps = [[a, b]];
3570
3691
  for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
3571
3692
  if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
3572
3693
  ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS);
3573
3694
  ps.forEach(([p, q], k2) => {
3574
3695
  out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
3575
- if (gl && Math.abs(p - a) < EPS) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)) });
3576
- if (gr && Math.abs(q - b) < EPS) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q) });
3696
+ hatches(pair, a, b, p, q, gl, gr);
3577
3697
  });
3578
3698
  if (ps.length > 0) continue;
3579
3699
  }
@@ -3588,6 +3708,7 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3588
3708
  if (q - p < min - EPS) continue;
3589
3709
  const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
3590
3710
  out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
3711
+ hatches(pair, a, b, p, q, gl, gr);
3591
3712
  }
3592
3713
  }
3593
3714
  return out;
@@ -3600,7 +3721,20 @@ function virtualMarks(lane, spots, held) {
3600
3721
  return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect(x, l.y, 0, l.height) };
3601
3722
  });
3602
3723
  }
3603
- function settle(l, drawn, scene, dragged, all, emptyLanes = "real") {
3724
+ function inLane(l, r) {
3725
+ const marks = l.marks.flatMap((m) => {
3726
+ const x0 = Math.max(m.rect.x, r.x);
3727
+ const y0 = Math.max(m.rect.y, r.y);
3728
+ const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
3729
+ const y1 = Math.min(m.rect.y + m.rect.height, r.y + r.height);
3730
+ if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS && y1 - y0 >= m.rect.height - EPS ? [m] : [];
3731
+ if (x1 - x0 <= EPS || y1 - y0 <= EPS) return [];
3732
+ return x1 - x0 >= m.rect.width - EPS && y1 - y0 >= m.rect.height - EPS ? [m] : [{ ...m, rect: rect(x0, y0, x1 - x0, y1 - y0) }];
3733
+ });
3734
+ return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
3735
+ }
3736
+ function settle(lane, drawn, scene, dragged, all, emptyLanes = "real", within = lane.rect) {
3737
+ const l = inLane(lane, within);
3604
3738
  const edgeOf = (id) => scene.edges.find((e) => e.id === id);
3605
3739
  const isDrawn = (id) => !!edgeOf(id) && (drawn.edges[id]?.cross ?? 0) > EPS;
3606
3740
  const across2 = (side) => side === "top" || side === "bottom" ? "x" : "y";
@@ -3621,17 +3755,7 @@ function settle(l, drawn, scene, dragged, all, emptyLanes = "real") {
3621
3755
  };
3622
3756
  const stays = empty ? Object.entries(drawn.items).filter(([id, it]) => id !== dragged && it.edge !== l.id && barOrRail(it.edge) && !it.floating && !it.inMenu && it.rect.width > EPS && it.rect.height > EPS).map(([, it]) => it.rect) : [];
3623
3757
  if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps3(m.rect, s)))))) return l;
3624
- const span = (r) => [lo(r, l.axis), lo(r, l.axis) + len(r, l.axis)];
3625
- const crosses = (r, c) => l.axis === "x" ? c.y < r.y + r.height - EPS && r.y < c.y + c.height - EPS : c.x < r.x + r.width - EPS && r.x < c.x + c.width - EPS;
3626
- const cut2 = (r, cs) => {
3627
- let ps = [span(r)];
3628
- for (const c of cs) {
3629
- if (!crosses(r, c)) continue;
3630
- const [c0, c1] = span(c);
3631
- ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS);
3632
- }
3633
- return ps;
3634
- };
3758
+ const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
3635
3759
  const marks = [];
3636
3760
  for (const m of l.marks) {
3637
3761
  const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
@@ -3660,11 +3784,59 @@ function settle(l, drawn, scene, dragged, all, emptyLanes = "real") {
3660
3784
  }
3661
3785
  return { ...l, marks };
3662
3786
  }
3787
+ function piecesLess(r, axis, cs) {
3788
+ const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
3789
+ const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS && r.y < c.y + c.height - EPS : c.x < r.x + r.width - EPS && r.x < c.x + c.width - EPS;
3790
+ let ps = [span(r)];
3791
+ for (const c of cs) {
3792
+ if (!crosses(c)) continue;
3793
+ const [c0, c1] = span(c);
3794
+ ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS);
3795
+ }
3796
+ return ps;
3797
+ }
3798
+ function marksLess(marks, axis, cs) {
3799
+ return marks.flatMap((m) => {
3800
+ const over = cs.filter((c) => overlaps3(m.rect, c));
3801
+ if (over.length === 0) return [m];
3802
+ const kept = piecesLess(m.rect, axis, over);
3803
+ if (m.kind === "line") return kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS ? [m] : [];
3804
+ return kept.map(([p, q], i) => ({ ...m, id: i ? `${m.id}~c${i}` : m.id, rect: along(m.rect, axis, p, q) }));
3805
+ });
3806
+ }
3807
+ function predict(settled, byLane, base, scene, dragged, built, emptyLanes) {
3808
+ const whole = /* @__PURE__ */ new Map();
3809
+ for (const l of settled) {
3810
+ const raws = byLane.get(l.id);
3811
+ if (!raws || l.spots.length !== 1 || !scene.edges.some((e) => e.id === l.id) || (base.seen.edges[l.id]?.cross ?? 0) > EPS) continue;
3812
+ const held = raws.find((r) => r.id === l.spots[0].id);
3813
+ if (!held || (held.layout.edges[l.id]?.cross ?? 0) <= EPS) continue;
3814
+ const again = heldLaneIn(l.id, raws, held, base, dragged);
3815
+ if (again) whole.set(l.id, settle(again, held.layout, scene, dragged, built, emptyLanes, laneRectOver(raws, held.layout, base.seen, base.marking).rect).marks);
3816
+ }
3817
+ if (whole.size === 0) return [...settled];
3818
+ const order = [...settled].filter((l) => whole.has(l.id)).sort((a, b) => a.axis === b.axis ? 0 : a.axis === "x" ? -1 : 1);
3819
+ const final = new Map(settled.filter((l) => !whole.has(l.id)).map((l) => [l.id, l.marks]));
3820
+ const meets = /* @__PURE__ */ new Map();
3821
+ for (const l of order) {
3822
+ const mine = whole.get(l.id);
3823
+ const others = [...final].filter(([id, ms]) => id !== l.id && ms.some((m) => mine.some((x) => overlaps3(x.rect, m.rect))));
3824
+ meets.set(l.id, others.map(([id]) => id));
3825
+ final.set(l.id, marksLess(mine, l.axis, others.flatMap(([, ms]) => ms.map((m) => m.rect))));
3826
+ }
3827
+ return settled.map((l) => {
3828
+ const marks = final.get(l.id);
3829
+ const mine = whole.get(l.id);
3830
+ if (!mine) return l;
3831
+ const corners = meets.get(l.id);
3832
+ return corners.length > 0 ? { ...l, marks, entry: mine, corners } : { ...l, marks };
3833
+ });
3834
+ }
3663
3835
  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;
3664
- function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
3836
+ function pitchedSpots(scene, dragged, options, seen, lifted, raws, pitch) {
3665
3837
  const out = [];
3666
- stretches(scene, dragged, options, seen, raws, (run) => {
3667
- const { e, axis, w, gap, middle } = run;
3838
+ stretches(scene, dragged, options, seen, lifted, raws, (run) => {
3839
+ const { e, axis, gap, middle } = run;
3668
3840
  const taken = run.mine.map((r) => r.landing);
3669
3841
  const emit3 = (zone, at, space, x0, flush) => {
3670
3842
  const hit = landsAt(scene, dragged, run, { edge: e.id, zone, at, space }, x0);
@@ -3683,7 +3855,7 @@ function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
3683
3855
  out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
3684
3856
  return true;
3685
3857
  };
3686
- return ({ a, b, zones, atOf, spaceAt, before, after }) => {
3858
+ return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
3687
3859
  const end = (x0, order, flush) => {
3688
3860
  for (const zone of order) if (spaceAt(zone, x0) >= -EPS && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
3689
3861
  };
@@ -3699,10 +3871,10 @@ function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
3699
3871
  });
3700
3872
  return out;
3701
3873
  }
3702
- function stretches(scene, dragged, options, seen, raws, visit) {
3874
+ function stretches(scene, dragged, options, seen, lifted, raws, visit) {
3703
3875
  if (!scene.items[dragged]) return;
3704
3876
  const prev = options.previous ? { previous: options.previous } : {};
3705
- const base = solve(lift(scene, dragged), prev);
3877
+ const base = lifted;
3706
3878
  for (const e of scene.edges) {
3707
3879
  const bar = e.side === "top" || e.side === "bottom";
3708
3880
  if (!bar && !e.compact) continue;
@@ -3712,8 +3884,6 @@ function stretches(scene, dragged, options, seen, raws, visit) {
3712
3884
  if (mine.length === 0 || !drawn) continue;
3713
3885
  const gap = nonNeg(e.gap);
3714
3886
  const others = onEdge(base, e.id, dragged, axis);
3715
- const edgeStart = lo(drawn.rect, axis) + nonNeg(e.pad?.start);
3716
- const edgeEnd = lo(drawn.rect, axis) + len(drawn.rect, axis) - nonNeg(e.pad?.end);
3717
3887
  const zoneOf2 = (o) => o.zone ?? "start";
3718
3888
  const w = len(mine[0].landing, axis);
3719
3889
  const each = visit({ e, axis, w, gap, middle: mid(drawn.rect, axis), mine, fixed: others.filter((o) => scene.items[o.id]?.fixed), prev });
@@ -3721,20 +3891,52 @@ function stretches(scene, dragged, options, seen, raws, visit) {
3721
3891
  const main = o ? scene.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
3722
3892
  return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
3723
3893
  };
3894
+ const ends = (l, before, after) => {
3895
+ const at = (o) => {
3896
+ const it = l.items[o.id];
3897
+ return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
3898
+ };
3899
+ const rb = before ? at(before) : void 0;
3900
+ const ra = after ? at(after) : void 0;
3901
+ if (rb === null || ra === null) return null;
3902
+ const el = l.edges[e.id]?.rect ?? drawn.rect;
3903
+ return {
3904
+ a: before && rb ? lo(rb, axis) + len(rb, axis) - slack({ ...before, r: rb }) + gap : lo(el, axis) + nonNeg(e.pad?.start),
3905
+ // (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
3906
+ b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
3907
+ };
3908
+ };
3724
3909
  for (let i = 0; i <= others.length; i++) {
3725
3910
  const before = others[i - 1];
3726
3911
  const after = others[i];
3727
- const a = before ? lo(before.r, axis) + len(before.r, axis) - slack(before) + gap : edgeStart;
3728
- const b = after ? lo(after.r, axis) - gap : edgeEnd;
3729
3912
  const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
3730
- each({ before, after, a, b, zones, atOf: (zone) => others.slice(0, i).filter((o) => zoneOf2(o) === zone).length, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + w) });
3913
+ const atOf = (zone) => others.slice(0, i).filter((o) => zoneOf2(o) === zone).length;
3914
+ const probe = (() => {
3915
+ const zone = zones[0];
3916
+ if (!zone) return null;
3917
+ const next = moveTo(scene, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
3918
+ if (next === scene) return null;
3919
+ const l = solve(next, prev);
3920
+ const landed = l.items[dragged];
3921
+ if (!landed || landed.inMenu || landed.edge !== e.id) return null;
3922
+ const n = neighbors(l, e.id, dragged, axis);
3923
+ if (n.before !== (before?.id ?? "^") || n.next !== (after?.id ?? "$")) return null;
3924
+ const r = ends(l, before, after);
3925
+ return r && { ...r, w: len(landed.rect, axis), layout: l };
3926
+ })();
3927
+ const seenEnds = ends(base, before, after);
3928
+ const pushed = (o, side) => !!o && !!probe && givesWay(base.items[o.id], probe.layout.items[o.id], e.id, side, (r) => [lo(r, axis), lo(r, axis) + len(r, axis) - slack({ ...o, r })]) === "moves";
3929
+ const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : seenEnds.a;
3930
+ const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : seenEnds.b;
3931
+ const wi = probe?.w ?? w;
3932
+ each({ before, after, a, b, w: wi, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + wi) });
3731
3933
  }
3732
3934
  }
3733
3935
  }
3734
- function takeoverSpots(scene, dragged, options, seen, raws, pitch) {
3936
+ function takeoverSpots(scene, dragged, options, seen, lifted, raws, pitch) {
3735
3937
  const out = [];
3736
- stretches(scene, dragged, options, seen, raws, (run) => {
3737
- const { e, axis, w } = run;
3938
+ stretches(scene, dragged, options, seen, lifted, raws, (run) => {
3939
+ const { e, axis } = run;
3738
3940
  const taken = [...run.mine.map((r) => r.landing)];
3739
3941
  const emit3 = (zone, at, space, x0, nb) => {
3740
3942
  const hit = landsAt(scene, dragged, run, { edge: e.id, zone, at, space }, x0);
@@ -3748,7 +3950,7 @@ function takeoverSpots(scene, dragged, options, seen, raws, pitch) {
3748
3950
  const target = { id: `pitch:${e.id}:${zone}:${at}:in:${nb}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
3749
3951
  out.push({ lane: e.id, edge: e.id, axis, id: `${e.id}/${zone}/${n.before}|${n.next}@in:${nb}`, ...n, landing: landed.rect, layout, target, hit: landed.rect });
3750
3952
  };
3751
- return ({ zones, atOf, spaceAt, before, after }) => {
3953
+ return ({ w, zones, atOf, spaceAt, before, after }) => {
3752
3954
  const zoneOf2 = (id) => scene.items[id]?.align ?? "start";
3753
3955
  if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !scene.items[after.id]?.fixed) {
3754
3956
  const x0 = lo(after.r, axis);
@@ -3775,15 +3977,15 @@ function landsAt(scene, dragged, run, place, x0) {
3775
3977
  })) return null;
3776
3978
  return { next, layout };
3777
3979
  }
3778
- function slidingSpots(scene, dragged, options, seen, raws, sample) {
3980
+ function slidingSpots(scene, dragged, options, seen, lifted, raws, sample) {
3779
3981
  const spots = [];
3780
3982
  const absorbed = /* @__PURE__ */ new Set();
3781
3983
  const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
3782
3984
  const own = seen.items[dragged];
3783
3985
  const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
3784
- stretches(scene, dragged, options, seen, raws, (run) => ({ a, b, zones, atOf, spaceAt, before, after }) => {
3785
- const { e, axis, w, middle, mine } = run;
3786
- if (zones.length === 0 || b - w < a - EPS) return;
3986
+ stretches(scene, dragged, options, seen, lifted, raws, (run) => ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
3987
+ const { e, axis, middle, mine } = run;
3988
+ if (zones.length === 0) return;
3787
3989
  {
3788
3990
  const land = (x0) => {
3789
3991
  const near = x0 + w / 2 < middle ? "start" : "end";
@@ -3806,6 +4008,29 @@ function slidingSpots(scene, dragged, options, seen, raws, sample) {
3806
4008
  const to = ok.at(-1).x0;
3807
4009
  const bId = before?.id ?? "^";
3808
4010
  const nId = after?.id ?? "$";
4011
+ if (to - from < STEP) {
4012
+ if (mine.some((r) => !r.slide && Math.abs(lo(r.landing, axis) - from) <= 1)) return;
4013
+ const firstZone = (() => {
4014
+ for (const zone3 of zones) {
4015
+ const space = spaceAt(zone3, from);
4016
+ if (space < -EPS) continue;
4017
+ const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
4018
+ const hit = landsAt(scene, dragged, run, place2, from);
4019
+ if (hit) return { place: place2, result: { scene: hit.next, layout: hit.layout } };
4020
+ }
4021
+ return null;
4022
+ })();
4023
+ const { place, result } = firstZone ?? ok[0].hit;
4024
+ const landed = result.layout.items[dragged].rect;
4025
+ const n = neighbors(result.layout, e.id, dragged, axis);
4026
+ const zone2 = place.zone;
4027
+ const isHome = ownEdge === e.id && !!own && Math.abs(lo(own.rect, axis) - lo(landed, axis)) <= 1 && Math.abs(len(own.rect, axis) - len(landed, axis)) <= 1;
4028
+ const target2 = { id: `pitch:${e.id}:${zone2}:${place.at}:${Math.round(place.space ?? 0)}`, priority: 2, hit: landed, slot: landed, item: dragged, place: { kind: "gap", edge: e.id, zone: zone2, at: place.at }, after: () => result };
4029
+ const plain = `${e.id}/${zone2}/${n.before}|${n.next}`;
4030
+ const id = mine.some((r) => r.id === plain) ? `${plain}@${Math.round((place.space ?? 0) / sample)}` : plain;
4031
+ spots.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed, layout: result.layout, target: target2, hit: landed, ...isHome ? { home: true } : {} });
4032
+ return;
4033
+ }
3809
4034
  const inside = mine.filter((r) => !r.slide && r.before === bId && r.next === nId && Math.abs(len(r.landing, axis) - w) <= 1 && lo(r.landing, axis) >= from - 1 && lo(r.landing, axis) <= to + 1);
3810
4035
  for (const r of inside) absorbed.add(r);
3811
4036
  const homeRaw = inside.find((r) => r.home);
@@ -3913,6 +4138,7 @@ export {
3913
4138
  isSideBar,
3914
4139
  isSideColumn,
3915
4140
  floatOrientOf,
4141
+ declaresFloatSizes,
3916
4142
  floatSizeOf,
3917
4143
  targetId,
3918
4144
  parseTargetId,
@@ -3949,4 +4175,4 @@ export {
3949
4175
  HATCH_END,
3950
4176
  HATCH_EDGE
3951
4177
  };
3952
- //# sourceMappingURL=chunk-NM4ADJC2.js.map
4178
+ //# sourceMappingURL=chunk-67D32MZ4.js.map