@n-uf/docking 26.11.57 → 26.11.59

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.
@@ -13,7 +13,7 @@ var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
13
13
 
14
14
  // src/helpers.ts
15
15
  import { clampInto } from "@n-uf/placement";
16
- import { formFolded } from "@n-uf/placement/stack";
16
+ import { formBody, formFolded, formMenu } from "@n-uf/placement/stack";
17
17
  var insetPx = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
18
18
  function floatRegion(state, lifted) {
19
19
  const floating = new Set(state.floats.map((f) => f.id));
@@ -168,7 +168,7 @@ var zoneOf = (item) => item?.align === "center" || item?.align === "end" ? item.
168
168
  var formsOf = (item, axis) => item.forms[axis] ?? [];
169
169
  var controlsOf = (f) => ({ hidden: f?.hides ?? [], ...f?.tiers ? { tiers: f.tiers } : {} });
170
170
  var PANEL_FORMS = /* @__PURE__ */ new Set(["open", "header", "rail"]);
171
- var isDockingPanel = (item) => !item.closed && !item.fixed && PANEL_FORMS.has(formsOf(item, "column")[0]?.kind ?? "");
171
+ var isDockingPanel = (item) => !item.closed && !item.fixed && (item.countsAsDocked ?? PANEL_FORMS.has(formsOf(item, "column")[0]?.kind ?? ""));
172
172
  function isOutsideSideBar(state, e) {
173
173
  return e.outsideInset === true && isSideBar(state, e);
174
174
  }
@@ -181,6 +181,31 @@ function isSideBar(state, e) {
181
181
  return !e.accepts.some((k) => panelKinds.includes(k));
182
182
  }
183
183
  var isSideColumn = (state, e) => (e.side === "left" || e.side === "right") && !e.compact && e.accepts.length > 0 && !isSideBar(state, e);
184
+ var keepsLengths = (state, e) => e.compact === true || e.side === "top" || e.side === "bottom" || isSideBar(state, e);
185
+ function growsOnBar(state, e, id, form) {
186
+ const it = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
187
+ if (!it || it.fixed || !keepsLengths(state, e)) return false;
188
+ const f = formsOf(it, axisOf(e.side))[form];
189
+ return !!f && f.main.grows === true && !formMenu(f);
190
+ }
191
+ function withoutBarGrowth(state, only) {
192
+ let items;
193
+ const view = only !== void 0 ? placingOf(state, only) : viewOf(state).view;
194
+ for (const e of view.edges) {
195
+ if (e.hidden === true || !keepsLengths(view, e)) continue;
196
+ const axis = axisOf(e.side);
197
+ for (const id of e.items) {
198
+ if (only !== void 0 && id !== only) continue;
199
+ const it = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
200
+ const forms = it?.forms[axis];
201
+ if (!it || it.fixed || !forms?.some((f) => f.main.grows === true)) continue;
202
+ const plain = forms.map((f) => f.main.grows === true ? { ...f, main: { min: f.main.min, natural: f.main.natural } } : f);
203
+ items ??= { ...state.items };
204
+ items[id] = { ...it, forms: { ...it.forms, [axis]: plain } };
205
+ }
206
+ }
207
+ return items ? { ...state, items } : state;
208
+ }
184
209
  var floatOrientOf = (item) => {
185
210
  if (item.floatOrient === "row" || item.floatOrient === "column") return item.floatOrient;
186
211
  for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
@@ -188,9 +213,10 @@ var floatOrientOf = (item) => {
188
213
  };
189
214
  var sized = (s) => !!s && Number.isFinite(s.width) && Number.isFinite(s.height) && s.width > 0 && s.height > 0;
190
215
  var declaresFloatSizes = (item) => item.floatSizes !== void 0 && item.floatSizes !== null;
216
+ var sizedByHand = (f) => !!f && f.main.grows === true && formBody(f);
191
217
  function naturalFloatSize(item, orient) {
192
218
  const f = formsOf(item, orient)[0];
193
- if (!f || f.main.grows) return void 0;
219
+ if (!f || sizedByHand(f)) return void 0;
194
220
  const main = Number.isFinite(f.main.natural) ? Math.max(0, f.main.natural) : 0;
195
221
  const cross = Number.isFinite(f.cross.natural) ? Math.max(0, f.cross.natural) : 0;
196
222
  if (main <= 0 || cross <= 0) return void 0;
@@ -263,7 +289,7 @@ function floatShape(item, f) {
263
289
  const fm = forms[form];
264
290
  if (orient === "column" && forms.slice(0, form + 1).some(isWrap)) return { form, width: px2(fm.cross.natural), height: px2(fm.main.natural) };
265
291
  if (form > 0) return orient === "column" ? { form, width: w, height: px2(fm.main.natural) } : { form, width: px2(fm.main.natural), height: h };
266
- return { form, ...fm.main.grows || !declaresFloatSizes(item) ? { width: w, height: h } : floatSizeOf(item, orient) };
292
+ return { form, ...sizedByHand(fm) || !declaresFloatSizes(item) ? { width: w, height: h } : floatSizeOf(item, orient) };
267
293
  }
268
294
 
269
295
  // src/solve.ts
@@ -435,7 +461,7 @@ import { cutEdges } from "@n-uf/placement/stack";
435
461
 
436
462
  // src/solve/draft.ts
437
463
  import { EPS as EPS2, rect } from "@n-uf/placement";
438
- import { formMain, itemSteps, wrapLines } from "@n-uf/placement/stack";
464
+ import { formMain, formMenu as formMenu2, itemSteps, wrapLines } from "@n-uf/placement/stack";
439
465
  function createDraft(given, options, caps = /* @__PURE__ */ new Map()) {
440
466
  const previous = options.previous;
441
467
  const opened = /* @__PURE__ */ new Set();
@@ -484,7 +510,7 @@ function shapeOf(f, r, axis, cross) {
484
510
  if (!g) return {};
485
511
  return { grip: axis === "column" ? rect(r.x, r.y, r.width, Math.min(g, r.height)) : rect(r.x, r.y, Math.min(g, r.width), r.height) };
486
512
  }
487
- function zoneStarts(state, fit, input) {
513
+ function zoneStarts(state, edge, fit, input) {
488
514
  const column = fit.axis === "column";
489
515
  const at = (r) => column ? r.y : r.x;
490
516
  const out = /* @__PURE__ */ new Map();
@@ -509,6 +535,19 @@ function zoneStarts(state, fit, input) {
509
535
  return !itemSteps(it) && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS2;
510
536
  });
511
537
  if (title) lengths.set(title.id, formMain(formsOf(state.items[title.id], "row")[title.form], "natural", fit.cross));
538
+ const growers = drawn.filter((p) => growsOnBar(state, edge, p.id, p.form));
539
+ const growth = /* @__PURE__ */ new Map();
540
+ if (growers.length > 0) {
541
+ for (const p of drawn) {
542
+ const f = formsOf(state.items[p.id], column ? "column" : "row")[p.form];
543
+ if (!f || formMenu2(f) || f.main.grows !== true) continue;
544
+ const n = formMain(f, "natural", fit.cross);
545
+ if (len2(p) > n + EPS2) {
546
+ growth.set(p.id, len2(p) - n);
547
+ lengths.set(p.id, n);
548
+ }
549
+ }
550
+ }
512
551
  const used = drawn.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, drawn.length - 1) * gap;
513
552
  const spare = fit.length - start - end - menu - used;
514
553
  if (spare <= EPS2) return { starts: out, lengths };
@@ -530,14 +569,44 @@ function zoneStarts(state, fit, input) {
530
569
  }
531
570
  };
532
571
  const spaced = (ps) => total(ps) + ps.reduce((sum, p) => sum + room(p), 0);
533
- lay(s, start, true);
534
- const endStart = fit.length - end - menu - spaced(e);
535
- lay(e, endStart, false);
536
- const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
537
- const hi = endStart - (e.length > 0 ? gap : 0);
538
- const mid2 = (fit.length - total(c)) / 2;
539
- const clear = mid2 >= lo2 - EPS2 && mid2 + total(c) <= hi + EPS2;
540
- lay(c, title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid2, hi - total(c))), false);
572
+ const barEnd = fit.length - end - menu;
573
+ const layZones = (centerAt) => {
574
+ lay(s, start, true);
575
+ const endStart = barEnd - spaced(e);
576
+ lay(e, endStart, false);
577
+ const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
578
+ const hi = endStart - (e.length > 0 ? gap : 0);
579
+ const mid3 = (fit.length - total(c)) / 2;
580
+ const clear = mid3 >= lo2 - EPS2 && mid3 + total(c) <= hi + EPS2;
581
+ const cAt = centerAt ?? (title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid3, hi - total(c))));
582
+ lay(c, cAt, false);
583
+ const spans2 = [
584
+ { ps: s, a: start, b: start + spaced(s) },
585
+ { ps: c, a: cAt, b: cAt + total(c) },
586
+ { ps: e, a: endStart, b: endStart + spaced(e) }
587
+ ];
588
+ return spans2.filter((z) => z.ps.length > 0);
589
+ };
590
+ const spans = layZones();
591
+ if (growers.length > 0) {
592
+ const mine = new Set(growers.map((p) => p.id));
593
+ const add = /* @__PURE__ */ new Map();
594
+ const give = (free, beside) => {
595
+ const takers = beside.filter((p) => mine.has(p.id));
596
+ if (free <= EPS2 || takers.length === 0) return;
597
+ const weights = takers.map((p) => growth.get(p.id) ?? 0);
598
+ const sum = weights.reduce((t, w) => t + w, 0);
599
+ takers.forEach((p, k) => add.set(p.id, (add.get(p.id) ?? 0) + free * (sum > EPS2 ? weights[k] / sum : 1 / takers.length)));
600
+ };
601
+ give(spans[0].a - start, spans[0].ps);
602
+ for (let k = 0; k + 1 < spans.length; k++) give(spans[k + 1].a - spans[k].b - gap, [...spans[k].ps, ...spans[k + 1].ps]);
603
+ give(barEnd - spans[spans.length - 1].b, spans[spans.length - 1].ps);
604
+ if (add.size > 0) {
605
+ for (const [id, v] of add) lengths.set(id, lengths.get(id) + v);
606
+ const middle = spans.find((z) => z.ps === c);
607
+ layZones(middle && !c.some((p) => add.has(p.id)) ? middle.a : void 0);
608
+ }
609
+ }
541
610
  if (title && s[s.length - 1] === title) {
542
611
  const next = [...c, ...e].map((p) => out.get(p.id));
543
612
  const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
@@ -550,7 +619,7 @@ function emit(d, edge, r, solved, extra = {}) {
550
619
  const column = axisOf(edge.side) === "column";
551
620
  const { stack } = solved;
552
621
  const thick = column ? r.width : r.height;
553
- const { starts, lengths } = zoneStarts(state, stack, solved.input);
622
+ const { starts, lengths } = zoneStarts(state, edge, stack, solved.input);
554
623
  const toStage = (l, id) => {
555
624
  const s = id !== void 0 ? starts.get(id) : void 0;
556
625
  const n = id !== void 0 ? lengths.get(id) : void 0;
@@ -604,7 +673,7 @@ function emit(d, edge, r, solved, extra = {}) {
604
673
 
605
674
  // src/solve/edge.ts
606
675
  import { EPS as EPS3 } from "@n-uf/placement";
607
- import { fitStack, formCompact, formCrossMin as formCrossMin2, formMenu, formSetsCross as formSetsCross2, itemSteps as itemSteps2 } from "@n-uf/placement/stack";
676
+ import { fitStack, formCompact, formCrossMin as formCrossMin2, formMenu as formMenu3, formSetsCross as formSetsCross2, itemSteps as itemSteps2 } from "@n-uf/placement/stack";
608
677
  var stackItemOf = (item, forms, edge, from) => ({
609
678
  id: item.id,
610
679
  forms,
@@ -619,7 +688,7 @@ var stackItemOf = (item, forms, edge, from) => ({
619
688
  var inputs = /* @__PURE__ */ new WeakMap();
620
689
  var inputOf = (stack) => inputs.get(stack);
621
690
  function hasSetter(fit, forms) {
622
- return fit.items.some((p) => !formMenu(forms(p.id)[p.form]) && formSetsCross2(forms(p.id)[p.form]));
691
+ return fit.items.some((p) => !formMenu3(forms(p.id)[p.form]) && formSetsCross2(forms(p.id)[p.form]));
623
692
  }
624
693
  var TRAY_RANK = 100;
625
694
  var startsOf = (input) => new Map(input.items.map((i) => [i.id, i.from ?? 0]));
@@ -725,7 +794,7 @@ function solveEdgeStack(state, edge, ids, length, room, previous) {
725
794
  const items = input.items.map((it) => {
726
795
  const from = it.from ?? 0;
727
796
  if (!itemSteps2(it) || fits(it.forms[from])) return it;
728
- const j = it.forms.findIndex((f, k) => k > from && !formMenu(f) && fits(f));
797
+ const j = it.forms.findIndex((f, k) => k > from && !formMenu3(f) && fits(f));
729
798
  if (j < 0) return it;
730
799
  moved = true;
731
800
  return { ...it, from: j };
@@ -737,7 +806,7 @@ function solveEdgeStack(state, edge, ids, length, room, previous) {
737
806
  }
738
807
  const size = edge.size;
739
808
  if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
740
- const setters = free.items.filter((p) => !formMenu(formsById(p.id)[p.form]) && formSetsCross2(formsById(p.id)[p.form]));
809
+ const setters = free.items.filter((p) => !formMenu3(formsById(p.id)[p.form]) && formSetsCross2(formsById(p.id)[p.form]));
741
810
  const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin2(formsById(p.id)[p.form])));
742
811
  const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
743
812
  if (Math.abs(s - free.cross) > EPS3) {
@@ -800,7 +869,7 @@ function clearSize(region, avoid) {
800
869
  const span = (axis) => {
801
870
  const lo2 = axis === "y" ? region.y : region.x;
802
871
  const hi = lo2 + (axis === "y" ? region.height : region.width);
803
- const mid2 = (lo2 + hi) / 2;
872
+ const mid3 = (lo2 + hi) / 2;
804
873
  let a = lo2;
805
874
  let b = hi;
806
875
  for (const r of avoid) {
@@ -808,7 +877,7 @@ function clearSize(region, avoid) {
808
877
  const s = axis === "y" ? r.y : r.x;
809
878
  const e = s + (axis === "y" ? r.height : r.width);
810
879
  if (!whole || e <= lo2 || s >= hi) continue;
811
- if (s + e <= 2 * mid2) a = Math.max(a, e);
880
+ if (s + e <= 2 * mid3) a = Math.max(a, e);
812
881
  else b = Math.min(b, s);
813
882
  }
814
883
  return Math.max(0, b - a);
@@ -980,7 +1049,7 @@ import { EPS as EPS8, rect as rect6 } from "@n-uf/placement";
980
1049
 
981
1050
  // src/solve/columns.ts
982
1051
  import { EPS as EPS7 } from "@n-uf/placement";
983
- import { formCrossMin as formCrossMin3, formMenu as formMenu2, formSetsCross as formSetsCross3 } from "@n-uf/placement/stack";
1052
+ import { formCrossMin as formCrossMin3, formMenu as formMenu4, formSetsCross as formSetsCross3 } from "@n-uf/placement/stack";
984
1053
  var isChrome = (state, c) => !c.dyn && isSideBar(state, c.edge);
985
1054
  function columnsOf(d, sideEdges, area9, tall) {
986
1055
  const { state } = d;
@@ -991,7 +1060,7 @@ function columnsOf(d, sideEdges, area9, tall) {
991
1060
  const visible = d.owned.get(edge).filter((id) => !state.items[id].closed);
992
1061
  const dyn = (edge.column === true || edge.giveWay === true) && state.rails?.[side] !== void 0 && visible.length > 0;
993
1062
  const forms = (id) => formsOf(state.items[id], "column");
994
- const setters = solved.free.items.filter((p) => !formMenu2(forms(p.id)[p.form]) && formSetsCross3(forms(p.id)[p.form]));
1063
+ const setters = solved.free.items.filter((p) => !formMenu4(forms(p.id)[p.form]) && formSetsCross3(forms(p.id)[p.form]));
995
1064
  const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin3(forms(p.id)[p.form])))) : width;
996
1065
  return {
997
1066
  edge,
@@ -1470,13 +1539,13 @@ function fitAxis(start, length, b, drag, hit) {
1470
1539
  }
1471
1540
  return [a, to - a];
1472
1541
  }
1473
- function fitResize(state, id, rect20, moving) {
1542
+ function fitResize(state, id, rect21, moving) {
1474
1543
  const f = state.floats.find((x2) => x2.id === id);
1475
1544
  const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
1476
1545
  if (!f || !item || item.fixed) return null;
1477
1546
  const fo = f.orient ?? floatOrientOf(item);
1478
1547
  const form = formsOf(item, fo)[0];
1479
- if (floatShape(item, f).form !== 0 || form && !form.main.grows) return null;
1548
+ if (floatShape(item, f).form !== 0 || form && !sizedByHand(form)) return null;
1480
1549
  const l = solve(state);
1481
1550
  const drawn = l.items[id]?.rect;
1482
1551
  if (!drawn) return null;
@@ -1488,8 +1557,8 @@ function fitResize(state, id, rect20, moving) {
1488
1557
  const { rects: obstacles, docked } = floatObstacles(state, l, id);
1489
1558
  const hit = /* @__PURE__ */ new Set();
1490
1559
  const stops2 = f.stays ? obstacles.slice(docked) : obstacles;
1491
- const [x, width] = fitAxis(rect20.x, rect20.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, stops2, "x", dragX ?? "end", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);
1492
- const [y, height] = fitAxis(rect20.y, rect20.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, stops2, "y", dragY ?? "end", [x, x + width]) }, dragY, hit);
1560
+ const [x, width] = fitAxis(rect21.x, rect21.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, stops2, "x", dragX ?? "end", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);
1561
+ const [y, height] = fitAxis(rect21.y, rect21.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, stops2, "y", dragY ?? "end", [x, x + width]) }, dragY, hit);
1493
1562
  const { anchor: _a, ...plain } = f;
1494
1563
  const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, state.stage, [], docked).fit.rect;
1495
1564
  if (Math.abs(placed.x - x) > EPS9 || Math.abs(placed.y - y) > EPS9) hit.add("docked");
@@ -1751,14 +1820,14 @@ function orientFloat(state, id, to) {
1751
1820
  const from = f.orient ?? floatOrientOf(item);
1752
1821
  if (from === to) return state;
1753
1822
  if (!declaresFloatSizes(item)) return { ...state, floats: state.floats.map((g, k) => k === i ? { ...g, orient: to } : g) };
1754
- const grows = formsOf(item, from)[0]?.main.grows === true;
1823
+ const grows = sizedByHand(formsOf(item, from)[0]);
1755
1824
  const kept = withFloatSizes(item, grows && f.rect.width > 0 && f.rect.height > 0 ? { orient: from, size: { width: f.rect.width, height: f.rect.height } } : void 0);
1756
1825
  const size = drawnFloatSize(kept, { rect: { ...f.rect, ...floatSizeOf(kept, to) }, orient: to });
1757
1826
  const turned = { ...f, rect: { x: f.rect.x, y: f.rect.y, width: size.width, height: size.height }, orient: to };
1758
1827
  return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? turned : g) }, kept);
1759
1828
  }
1760
- function resizeFloat(state, floatId, rect20, moving = { right: true, bottom: true }) {
1761
- const fit = fitResize(state, floatId, rect20, moving);
1829
+ function resizeFloat(state, floatId, rect21, moving = { right: true, bottom: true }) {
1830
+ const fit = fitResize(state, floatId, rect21, moving);
1762
1831
  const i = state.floats.findIndex((f) => f.id === floatId);
1763
1832
  const item = itemOf(state, floatId);
1764
1833
  if (!fit || i < 0 || !item) return state;
@@ -2114,7 +2183,7 @@ function read(data, base) {
2114
2183
  }
2115
2184
 
2116
2185
  // src/targets.ts
2117
- import { EPS as EPS20, PLANE, area as area6, clamp as clamp2, contains, overlaps as overlaps7, rect as rect18 } from "@n-uf/placement";
2186
+ import { EPS as EPS22, PLANE, area as area6, clamp as clamp3, contains, overlaps as overlaps7, rect as rect19 } from "@n-uf/placement";
2118
2187
 
2119
2188
  // src/targets/anchor.ts
2120
2189
  import { EPS as EPS11, area, rect as rect10, subtract } from "@n-uf/placement";
@@ -2145,9 +2214,63 @@ function anchorTargets(state, dragged, options) {
2145
2214
  return { targets: targets2, refusals: [], lost: [] };
2146
2215
  }
2147
2216
 
2217
+ // src/aim.ts
2218
+ import { EPS as EPS12, clamp } from "@n-uf/placement";
2219
+ var SPOT_PITCH = 40;
2220
+ var SNAP_DISTANCE = 8;
2221
+ var lo = (r, axis) => axis === "x" ? r.x : r.y;
2222
+ var len = (r, axis) => axis === "x" ? r.width : r.height;
2223
+ function zoneIn2(layout, id) {
2224
+ return (id === void 0 ? void 0 : layout.items[id]?.zone) ?? "start";
2225
+ }
2226
+ function cutsByHalves(edge) {
2227
+ return (edge.side === "left" || edge.side === "right") && !edge.compact;
2228
+ }
2229
+ function aimSlack(pitch) {
2230
+ return Math.max(0, pitch === void 0 || !Number.isFinite(pitch) ? SPOT_PITCH : pitch) / 2;
2231
+ }
2232
+ function grabShare(own, grab) {
2233
+ const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS12 ? 0.5 : clamp(g / size, 0, 1);
2234
+ const w = own?.width ?? 0;
2235
+ const h = own?.height ?? 0;
2236
+ return { x: w >= h ? shareOf(grab?.x, w) : 0.5, y: h > w ? shareOf(grab?.y, h) : 0.5 };
2237
+ }
2238
+ function aimCut(a, b, axis, held, slack, shared) {
2239
+ if (shared) return lo(shared, axis) + len(shared, axis) / 2;
2240
+ const aEnd = lo(a, axis) + len(a, axis);
2241
+ const bStart = lo(b, axis);
2242
+ const across2 = (aEnd + bStart) / 2;
2243
+ if (!(bStart < aEnd - EPS12)) return across2;
2244
+ const s = Math.max(0, slack);
2245
+ return clamp(across2 + (held - 0.5) * (len(a, axis) + len(b, axis)) / 2, bStart - s, aEnd + s);
2246
+ }
2247
+ function crossFreeCuts(n, cut2, pinned, min = -Infinity, max = Infinity) {
2248
+ const active = Array.from({ length: n }, (_, i) => i);
2249
+ for (let changed = true; changed; ) {
2250
+ changed = false;
2251
+ for (let k = 1; k + 1 < active.length; k++) {
2252
+ const [p, q, r] = [active[k - 1], active[k], active[k + 1]];
2253
+ if (!pinned(q) && cut2(q, r) < cut2(p, q) - EPS12) {
2254
+ active.splice(k, 1);
2255
+ changed = true;
2256
+ break;
2257
+ }
2258
+ }
2259
+ }
2260
+ const kept = [];
2261
+ for (let k = 0; k + 1 < active.length; k++) kept.push(clamp(Math.max(cut2(active[k], active[k + 1]), kept[k - 1] ?? min), min, max));
2262
+ return Array.from({ length: Math.max(0, n - 1) }, (_, i) => kept[active.findIndex((j) => j > i) - 1]);
2263
+ }
2264
+ function rangeTries(a, b, w, sample) {
2265
+ const tries = [a];
2266
+ for (let x0 = a + sample; x0 < b - w - EPS12; x0 += sample) tries.push(x0);
2267
+ if (b - w > a + EPS12) tries.push(b - w);
2268
+ return tries;
2269
+ }
2270
+
2148
2271
  // src/targets/edges.ts
2149
- import { EPS as EPS12, area as area2, rect as rect11 } from "@n-uf/placement";
2150
- import { formCrossMin as formCrossMin4, formMenu as formMenu3, formSetsCross as formSetsCross4, itemSteps as itemSteps3 } from "@n-uf/placement/stack";
2272
+ import { EPS as EPS13, area as area2, rect as rect11 } from "@n-uf/placement";
2273
+ import { formCrossMin as formCrossMin4, formMenu as formMenu5, formSetsCross as formSetsCross4, itemSteps as itemSteps3 } from "@n-uf/placement/stack";
2151
2274
 
2152
2275
  // src/targets/kinds.ts
2153
2276
  var COLUMN_REACH = 22;
@@ -2183,6 +2306,14 @@ function reservedRect(state, l, id) {
2183
2306
  const shift = it.zone === "end" ? len2 - keep : it.zone === "center" ? (len2 - keep) / 2 : 0;
2184
2307
  return column ? rect11(it.rect.x, it.rect.y + shift, it.rect.width, keep) : rect11(it.rect.x + shift, it.rect.y, keep, it.rect.height);
2185
2308
  }
2309
+ function landedLayout(state, l, dragged, prev) {
2310
+ const it = l.items[dragged];
2311
+ if (!it || it.fixed || it.inMenu || it.floating || !it.edge) return l;
2312
+ const e = state.edges.find((x) => x.id === it.edge);
2313
+ if (!e || !growsOnBar(state, e, dragged, it.form)) return l;
2314
+ return solve(withoutBarGrowth(state, dragged), prev);
2315
+ }
2316
+ var solveLanded = (state, dragged, prev) => solve(withoutBarGrowth(state, dragged), prev);
2186
2317
  function slotAt(c, zone, line, id, place, lands, home = false) {
2187
2318
  const result = c.settle(markUsed(moveAmong(c.state, c.dragged, place, c.others), c.dragged));
2188
2319
  const isHome = home || c.isHome(result);
@@ -2194,7 +2325,7 @@ function distinctSlots(c, slots) {
2194
2325
  if (a.zone !== b.zone) return false;
2195
2326
  if (a.home && b.home) return true;
2196
2327
  const [p, q] = [landing(a), landing(b)];
2197
- const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS12;
2328
+ const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS13;
2198
2329
  return sameLine && (!p || !q ? p === q : Math.abs(p.x - q.x) + Math.abs(p.y - q.y) + Math.abs(p.width - q.width) + Math.abs(p.height - q.height) < 0.01);
2199
2330
  };
2200
2331
  const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
@@ -2271,7 +2402,7 @@ function edgeSlots(c, edge, accepts) {
2271
2402
  };
2272
2403
  const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
2273
2404
  const menuLen = el.menu ? len2(el.menu.rect) : 0;
2274
- const occupied = (id) => now.items[id]?.fixed ? reservedRect(state, now, id) : now.items[id].rect;
2405
+ const occupied = (id) => c.room.items[id]?.fixed ? reservedRect(state, c.room, id) : c.room.items[id].rect;
2275
2406
  const shown = (id) => now.items[id]?.edge === edge.id && !now.items[id].inMenu;
2276
2407
  const drawnOf2 = (z) => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
2277
2408
  const startEnd = (() => {
@@ -2320,8 +2451,8 @@ function edgeSlots(c, edge, accepts) {
2320
2451
  return slots;
2321
2452
  }
2322
2453
  function thickerThan(forms, cross) {
2323
- const shown = forms.filter((f) => !formMenu3(f));
2324
- return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS12);
2454
+ const shown = forms.filter((f) => !formMenu5(f));
2455
+ return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS13);
2325
2456
  }
2326
2457
  var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
2327
2458
  function edgeSpec(c, edge, as) {
@@ -2335,18 +2466,18 @@ function edgeSpec(c, edge, as) {
2335
2466
  const len2 = (r2) => column ? r2.height : r2.width;
2336
2467
  const empty = el.stack.items.every((p) => el.stack.menu?.items.includes(p.id)) && !el.menu;
2337
2468
  const accepts = edgeTakes(edge, kind);
2338
- if (!accepts && (empty || area2(el.rect) <= EPS12)) return null;
2469
+ if (!accepts && (empty || area2(el.rect) <= EPS13)) return null;
2339
2470
  if (accepts && empty && !opensEmpty(state, edge, kind)) return null;
2340
- const ownNow = now.items[dragged];
2341
- const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS12 ? ownNow.rect : null;
2471
+ const ownNow = c.room.items[dragged];
2472
+ const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS13 ? ownNow.rect : null;
2342
2473
  const oneEnd = state.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
2343
2474
  const allSlots = edgeSlots(c, edge, accepts);
2344
2475
  const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
2345
2476
  const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
2346
2477
  const grows = (id) => !!formsOf(state.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
2347
2478
  const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
2348
- const cards = Object.entries(now.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) > EPS12).map(([, p]) => spanOf(p.rect));
2349
- const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(state, now, edge, c.reach, (zone) => {
2479
+ const cards = Object.entries(c.room.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) > EPS13).map(([, p]) => spanOf(p.rect));
2480
+ const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(state, c.room, edge, c.reach, (zone) => {
2350
2481
  const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
2351
2482
  const me = s?.result.layout.items[dragged];
2352
2483
  return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
@@ -2374,7 +2505,7 @@ function edgeSpec(c, edge, as) {
2374
2505
  vertical: column,
2375
2506
  zones,
2376
2507
  slots,
2377
- refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS12 ? "not-accepted" : null,
2508
+ refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS13 ? "not-accepted" : null,
2378
2509
  own: ownHere,
2379
2510
  holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
2380
2511
  reserved,
@@ -2440,11 +2571,15 @@ function soundness(state, base, dragged) {
2440
2571
  return !onChrome && !fixedAfter.some((f) => overlaps2(me.rect, f));
2441
2572
  };
2442
2573
  }
2574
+ function roomOf2(state, now, prev) {
2575
+ const plain = withoutBarGrowth(state);
2576
+ return plain === state ? now : solve(plain, prev);
2577
+ }
2443
2578
  function context(state, dragged, options, others = []) {
2444
2579
  const item = Object.hasOwn(state.items, dragged) ? state.items[dragged] : void 0;
2445
2580
  if (!item || item.fixed || item.closed) return null;
2446
2581
  const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
2447
- const settle2 = (s) => ({ state: s, layout: solve(s, prev) });
2582
+ const settle2 = (s) => ({ state: s, layout: solveLanded(s, dragged, prev) });
2448
2583
  const now = solve(state, prev);
2449
2584
  const rest = liftItem(state, dragged);
2450
2585
  const base = solve(rest, prev);
@@ -2454,6 +2589,8 @@ function context(state, dragged, options, others = []) {
2454
2589
  others,
2455
2590
  rest,
2456
2591
  now,
2592
+ room: roomOf2(state, now, prev),
2593
+ prev,
2457
2594
  base,
2458
2595
  dragged,
2459
2596
  kind: item.kind,
@@ -2461,31 +2598,35 @@ function context(state, dragged, options, others = []) {
2461
2598
  settle: settle2,
2462
2599
  isHome: (r) => placeKey(r.state, dragged) === here,
2463
2600
  sound: soundness(state, base, dragged),
2464
- lay: layKeys(state)
2601
+ lay: layKeys(state),
2602
+ // (Held, a movable grower is its natural length, as `lanes()` reads the grab: `landedLayout`.)
2603
+ share: grabShare(landedLayout(state, now, dragged, prev).items[dragged]?.rect, options.grab),
2604
+ slack: aimSlack(options.pitch),
2605
+ slideRanges: /* @__PURE__ */ new Map()
2465
2606
  };
2466
2607
  return { c, item, prev };
2467
2608
  }
2468
2609
 
2469
- // src/targets/ownership.ts
2470
- import { EPS as EPS15, area as area3, overlaps as overlaps3, rect as rect13, subtract as subtract2 } from "@n-uf/placement";
2471
- import { formBody, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
2472
-
2473
2610
  // src/targets/meet.ts
2474
- import { EPS as EPS13, rect as rect12 } from "@n-uf/placement";
2611
+ import { EPS as EPS14, rect as rect12 } from "@n-uf/placement";
2475
2612
  function meet(a, b) {
2476
2613
  const x = Math.max(a.x, b.x);
2477
2614
  const y = Math.max(a.y, b.y);
2478
2615
  const w = Math.min(a.x + a.width, b.x + b.width) - x;
2479
2616
  const h = Math.min(a.y + a.height, b.y + b.height) - y;
2480
- return w > EPS13 && h > EPS13 ? rect12(x, y, w, h) : null;
2617
+ return w > EPS14 && h > EPS14 ? rect12(x, y, w, h) : null;
2481
2618
  }
2482
2619
 
2620
+ // src/targets/ownership.ts
2621
+ import { EPS as EPS16, area as area3, overlaps as overlaps3, rect as rect13, subtract as subtract2 } from "@n-uf/placement";
2622
+ import { formBody as formBody2, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
2623
+
2483
2624
  // src/targets/model.ts
2484
- import { EPS as EPS14 } from "@n-uf/placement";
2485
- var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u > EPS14)), [...spans]);
2625
+ import { EPS as EPS15 } from "@n-uf/placement";
2626
+ var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u > EPS15)), [...spans]);
2486
2627
 
2487
2628
  // src/targets/ownership.ts
2488
- var isBody = (f) => !!f && formBody(f);
2629
+ var isBody = (f) => !!f && formBody2(f);
2489
2630
  var bandOf = (s) => {
2490
2631
  const a = Math.min(...s.zones.map((z) => z.a));
2491
2632
  const b = Math.max(...s.zones.map((z) => z.b));
@@ -2504,10 +2645,10 @@ function ownedRectsOf(s, along2) {
2504
2645
  return along2.map(([a, b]) => s.vertical ? rect13(o.x, a, o.width, b - a) : rect13(a, o.y, b - a, o.height));
2505
2646
  }
2506
2647
  function drawnOf(c, live) {
2507
- const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS15 && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
2648
+ const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS16 && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
2508
2649
  const rails = ["left", "right"].flatMap((side) => {
2509
2650
  const rail = c.now.rails[side];
2510
- if (!rail || rail.segments.length === 0 || area3(rail.rect) <= EPS15) return [];
2651
+ if (!rail || rail.segments.length === 0 || area3(rail.rect) <= EPS16) return [];
2511
2652
  const spec = live.find((s) => s.kind === "railStop" && s.lay.side === side) ?? null;
2512
2653
  const lay = spec?.lay ?? { phase: EDGE_KINDS.railStop.phase, side, at: -1 };
2513
2654
  const me = c.now.items[c.dragged];
@@ -2529,7 +2670,7 @@ function homeRectOf(c, ownSpec) {
2529
2670
  if (!ownSpec) {
2530
2671
  const e = c.now.edges[own.edge];
2531
2672
  const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
2532
- return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS15 ? hull3(o, e.rect) : o;
2673
+ return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS16 ? hull3(o, e.rect) : o;
2533
2674
  }
2534
2675
  const [c0, c1] = ownSpec.across();
2535
2676
  return ownSpec.vertical ? hull3(o, rect13(c0, o.y, c1 - c0, o.height)) : hull3(o, rect13(o.x, c0, o.width, c1 - c0));
@@ -2549,7 +2690,7 @@ function ownersOf(c, live, drawn, alongOf) {
2549
2690
  if (!s.thinOwned) return rects.map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }));
2550
2691
  const thin = (r) => s.vertical ? rect13(Math.max(r.x, s.thinOwned[0]), r.y, Math.min(r.x + r.width, s.thinOwned[1]) - Math.max(r.x, s.thinOwned[0]), r.height) : rect13(r.x, Math.max(r.y, s.thinOwned[0]), r.width, Math.min(r.y + r.height, s.thinOwned[1]) - Math.max(r.y, s.thinOwned[0]));
2551
2692
  return rects.flatMap((r) => [{ spec: s, rect: thin(r), lay: s.lay, place: true }, ...subtract2(r, thin(r)).map((d) => ({ spec: s, rect: d, lay: s.lay, place: true, deep: true }))]);
2552
- }).filter((o) => area3(o.rect) > EPS15),
2693
+ }).filter((o) => area3(o.rect) > EPS16),
2553
2694
  // Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
2554
2695
  ...drawn.map((d) => ({ ...d, place: false }))
2555
2696
  ];
@@ -2575,7 +2716,7 @@ function ownership(c, live, alongOf, aloneOf) {
2575
2716
  const e = s.edge ? now.edges[s.id] : void 0;
2576
2717
  if (!e) return null;
2577
2718
  const span = s.vertical ? [e.rect.y, e.rect.y + e.rect.height] : [e.rect.x, e.rect.x + e.rect.width];
2578
- return span[1] - span[0] > EPS15 ? span : null;
2719
+ return span[1] - span[0] > EPS16 ? span : null;
2579
2720
  };
2580
2721
  const pastEnds = (s, r) => {
2581
2722
  const ends = endsOf(s);
@@ -2627,15 +2768,15 @@ function ownership(c, live, alongOf, aloneOf) {
2627
2768
  const half = e ? halfBandOf(e) : null;
2628
2769
  if (!e || half === null) return [];
2629
2770
  const column = axisOf(e.side) === "column";
2630
- return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && iid !== dragged && isBody(formsOf(state.items[iid], axisOf(e.side))[p.form])).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS15);
2771
+ return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && iid !== dragged && isBody(formsOf(state.items[iid], axisOf(e.side))[p.form])).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS16);
2631
2772
  };
2632
2773
  const rooms = /* @__PURE__ */ new Map();
2633
2774
  const cutsOf = (s) => {
2634
2775
  let room = rooms.get(s);
2635
- if (!room) rooms.set(s, room = roomOf2(s));
2776
+ if (!room) rooms.set(s, room = roomOf3(s));
2636
2777
  return room;
2637
2778
  };
2638
- const roomOf2 = (s) => {
2779
+ const roomOf3 = (s) => {
2639
2780
  const b = bandOf(s);
2640
2781
  const along2 = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
2641
2782
  const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
@@ -2644,23 +2785,23 @@ function ownership(c, live, alongOf, aloneOf) {
2644
2785
  const owned = [];
2645
2786
  for (let k = 1; k < ends.length; k++) {
2646
2787
  const [u, w] = [ends[k - 1], ends[k]];
2647
- const over2 = rs.filter((r) => along2(r)[0] <= u + EPS15 && along2(r)[1] >= w - EPS15).map(across2);
2648
- if (w - u > EPS15 && less([across2(b)], over2).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
2788
+ const over2 = rs.filter((r) => along2(r)[0] <= u + EPS16 && along2(r)[1] >= w - EPS16).map(across2);
2789
+ if (w - u > EPS16 && less([across2(b)], over2).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
2649
2790
  }
2650
2791
  const half = s.edge ? halfBandOf(s.edge) : null;
2651
2792
  const raw = bodySpans(s.edge);
2652
2793
  if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
2653
2794
  const merged = owned.reduce((m, [u, w]) => {
2654
2795
  const last = m[m.length - 1];
2655
- if (last && u <= last[1] + EPS15) last[1] = Math.max(last[1], w);
2796
+ if (last && u <= last[1] + EPS16) last[1] = Math.max(last[1], w);
2656
2797
  else m.push([u, w]);
2657
2798
  return m;
2658
2799
  }, []);
2659
2800
  const [lo2, hi] = endsOf(s) ?? along2(b);
2660
2801
  const placed = (p) => {
2661
- const cut2 = merged.find(([u, w]) => p >= u - EPS15 && p <= w + EPS15);
2802
+ const cut2 = merged.find(([u, w]) => p >= u - EPS16 && p <= w + EPS16);
2662
2803
  if (!cut2) return p;
2663
- const sides = [...cut2[0] > lo2 + EPS15 ? [cut2[0]] : [], ...cut2[1] < hi - EPS15 ? [cut2[1]] : []];
2804
+ const sides = [...cut2[0] > lo2 + EPS16 ? [cut2[0]] : [], ...cut2[1] < hi - EPS16 ? [cut2[1]] : []];
2664
2805
  return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
2665
2806
  };
2666
2807
  const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
@@ -2678,7 +2819,7 @@ function ownership(c, live, alongOf, aloneOf) {
2678
2819
  const column = axisOf(e.side) === "column";
2679
2820
  const across2 = (a, b) => column ? rect13(-1e9, a, 2e9, b - a) : rect13(a, -1e9, b - a, 2e9);
2680
2821
  const reserved = Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid)).map(([, p]) => column ? across2(p.rect.y, p.rect.y + p.rect.height) : across2(p.rect.x, p.rect.x + p.rect.width));
2681
- return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS15);
2822
+ return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS16);
2682
2823
  };
2683
2824
  const drawnBySpec = /* @__PURE__ */ new Map();
2684
2825
  const drawnBesides = (s) => {
@@ -2690,13 +2831,138 @@ function ownership(c, live, alongOf, aloneOf) {
2690
2831
  }
2691
2832
 
2692
2833
  // src/targets/tiles.ts
2693
- import { EPS as EPS16, area as area4, overlaps as overlaps4, rect as rect14, subtract as subtract3 } from "@n-uf/placement";
2834
+ import { EPS as EPS18, area as area4, overlaps as overlaps4, rect as rect15, subtract as subtract3 } from "@n-uf/placement";
2835
+
2836
+ // src/slide.ts
2837
+ import { EPS as EPS17, rect as rect14 } from "@n-uf/placement";
2838
+ import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
2839
+ var mid = (r, axis) => lo(r, axis) + len(r, axis) / 2;
2840
+ var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
2841
+ function onEdge(l, edge, dragged, axis) {
2842
+ return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS17 && it.rect.height > EPS17).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
2843
+ }
2844
+ function neighbors(after, edge, dragged, axis) {
2845
+ const me = after.items[dragged];
2846
+ const others = onEdge(after, edge, dragged, axis);
2847
+ const at = me ? mid(me.rect, axis) : 0;
2848
+ return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
2849
+ }
2850
+ function givesWay(now, after, lane, side, extent) {
2851
+ if (!now) return null;
2852
+ if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
2853
+ const [p0, p1] = extent(now.rect);
2854
+ const [q0, q1] = extent(after.rect);
2855
+ if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
2856
+ return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
2857
+ }
2858
+ function slackOf(state, id, axis, r) {
2859
+ const main = state.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
2860
+ return main?.grows ? Math.max(0, len(r, axis) - main.natural) : 0;
2861
+ }
2862
+ function placeOf(se, l) {
2863
+ const counts = (id) => !(se.state.items[id]?.fixed && itemSteps6(se.state.items[id]));
2864
+ const shown = Object.entries(l.items).filter(([id, it]) => counts(id) && it.edge === se.e.id && !it.inMenu && !it.floating && it.rect.width > EPS17 && it.rect.height > EPS17).sort(([, p], [, q]) => lo(p.rect, se.axis) - lo(q.rect, se.axis)).map(([id]) => id);
2865
+ const menu = Object.entries(l.items).filter(([id, it]) => counts(id) && it.inMenu && it.edge === se.e.id).map(([id]) => id).sort();
2866
+ return `${shown.join(" ")} \xBB ${menu.join(" ")}`;
2867
+ }
2868
+ function endsIn(se, l, before, after) {
2869
+ const { e, axis } = se;
2870
+ const at = (id) => {
2871
+ const it = l.items[id];
2872
+ return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
2873
+ };
2874
+ const rb = before ? at(before) : void 0;
2875
+ const ra = after ? at(after) : void 0;
2876
+ if (rb === null || ra === null) return null;
2877
+ const el = l.edges[e.id]?.rect ?? se.drawn;
2878
+ const gap = nonNeg(e.gap);
2879
+ return {
2880
+ a: before && rb ? lo(rb, axis) + len(rb, axis) - slackOf(se.state, before, axis, rb) + gap : lo(el, axis) + nonNeg(e.pad?.start),
2881
+ // (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
2882
+ b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
2883
+ };
2884
+ }
2885
+ function slideRoom(se, before, after, preceding, w) {
2886
+ const { state, dragged, e, axis } = se;
2887
+ const zoneOf2 = (id) => zoneIn2(se.base, id);
2888
+ const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
2889
+ const atOf = (zone) => preceding.filter((id) => zoneOf2(id) === zone).length;
2890
+ const probe = (() => {
2891
+ const zone = zones[0];
2892
+ if (!zone) return null;
2893
+ const moved = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
2894
+ if (moved === state) return null;
2895
+ const l = solveLanded(markUsed(moved, dragged), dragged, se.prev);
2896
+ const landed = l.items[dragged];
2897
+ if (!landed || landed.inMenu || landed.edge !== e.id) return null;
2898
+ const n = neighbors(l, e.id, dragged, axis);
2899
+ if (n.before !== (before ?? "^") || n.next !== (after ?? "$")) return null;
2900
+ const r = endsIn(se, l, before, after);
2901
+ return r && { ...r, w: len(landed.rect, axis), layout: l };
2902
+ })();
2903
+ const seen = endsIn(se, se.base, before, after);
2904
+ const width = probe?.w ?? w;
2905
+ if (!probe && !seen || width === void 0) return null;
2906
+ const pushed = (id, side) => !!id && !!probe && givesWay(se.base.items[id], probe.layout.items[id], e.id, side, (r) => [lo(r, axis), lo(r, axis) + len(r, axis) - slackOf(state, id, axis, r)]) === "moves";
2907
+ const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : (seen ?? probe).a;
2908
+ const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : (seen ?? probe).b;
2909
+ return { before, after, a, b, w: width, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + width), ...probe ? { place: placeOf(se, probe.layout) } : {} };
2910
+ }
2911
+ function landsAt(se, place, x0) {
2912
+ const { state, dragged, axis } = se;
2913
+ const moved = moveTo(state, dragged, place);
2914
+ if (moved === state) return null;
2915
+ const next = markUsed(moved, dragged);
2916
+ const layout = solveLanded(next, dragged, se.prev);
2917
+ const landed = layout.items[dragged];
2918
+ if (!landed || landed.inMenu || landed.edge !== se.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
2919
+ const kept = (f) => {
2920
+ const it = layout.items[f.id];
2921
+ if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
2922
+ return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
2923
+ };
2924
+ if (!se.fixed.every(kept)) return null;
2925
+ return { next, layout };
2926
+ }
2927
+ function slideLand(se, room, x0) {
2928
+ const near = x0 + room.w / 2 < se.middle ? "start" : "end";
2929
+ for (const zone of [near, near === "start" ? "end" : "start"]) {
2930
+ if (!room.zones.includes(zone)) continue;
2931
+ const space = room.spaceAt(zone, x0);
2932
+ if (space < -EPS17) continue;
2933
+ const place = { edge: se.e.id, zone, at: room.atOf(zone), space: Math.max(0, space) };
2934
+ const hit = landsAt(se, place, x0);
2935
+ if (hit && (room.place === void 0 || placeOf(se, hit.layout) === room.place)) return { place, result: { state: hit.next, layout: hit.layout } };
2936
+ }
2937
+ return null;
2938
+ }
2939
+ function slideRange(se, room, sample) {
2940
+ const memo2 = /* @__PURE__ */ new Map();
2941
+ const land = (x0) => {
2942
+ if (!memo2.has(x0)) memo2.set(x0, slideLand(se, room, x0));
2943
+ return memo2.get(x0);
2944
+ };
2945
+ const tries = rangeTries(room.a, room.b, room.w, sample);
2946
+ const from = tries.find((x0) => !!land(x0));
2947
+ if (from === void 0) return null;
2948
+ const to = [...tries].reverse().find((x0) => x0 <= from || !!land(x0));
2949
+ const start = land(from);
2950
+ const shape = start.result.layout.items[se.dragged].rect;
2951
+ const at = (x0) => se.axis === "x" ? rect14(x0, shape.y, room.w, shape.height) : rect14(shape.x, x0, shape.width, room.w);
2952
+ const nearest = (x0) => {
2953
+ const order = tries.map((t, i) => ({ t, i })).sort((p, q) => Math.abs(p.t - x0) - Math.abs(q.t - x0) || p.i - q.i);
2954
+ return land(order.find(({ t }) => !!land(t)).t);
2955
+ };
2956
+ return { from, to, first: at(from), last: at(to), at, start, land, nearest };
2957
+ }
2958
+
2959
+ // src/targets/tiles.ts
2694
2960
  function tilerOf(spec) {
2695
2961
  const data = EDGE_KINDS[spec.kind];
2696
2962
  const v = spec.vertical;
2697
2963
  const band = (a, b, after) => {
2698
2964
  const [c0, c1] = spec.across(after);
2699
- return v ? rect14(c0, a, c1 - c0, b - a) : rect14(a, c0, b - a, c1 - c0);
2965
+ return v ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
2700
2966
  };
2701
2967
  const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
2702
2968
  const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
@@ -2704,10 +2970,10 @@ function tilerOf(spec) {
2704
2970
  const h = t.hit;
2705
2971
  const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
2706
2972
  const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
2707
- const part = (a, b) => v ? rect14(a, h.y, b - a, h.height) : rect14(h.x, a, h.width, b - a);
2973
+ const part = (a, b) => v ? rect15(a, h.y, b - a, h.height) : rect15(h.x, a, h.width, b - a);
2708
2974
  const beyond = less([[h0, h1]], [spec.owned]);
2709
2975
  if (beyond.length === 0) return [t];
2710
- if (c1 - c0 <= EPS16) return [{ ...t, order: data.overreach }];
2976
+ if (c1 - c0 <= EPS18) return [{ ...t, order: data.overreach }];
2711
2977
  const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
2712
2978
  return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
2713
2979
  };
@@ -2721,7 +2987,7 @@ function wholeRefusal(c, spec) {
2721
2987
  const data = EDGE_KINDS[spec.kind];
2722
2988
  return { edge: spec.id, spec, edgeKind: spec.kind, vertical: spec.vertical, zone: "start", hit, kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason: "not-accepted", whole: true };
2723
2989
  }
2724
- var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS16);
2990
+ var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS18);
2725
2991
  function linesIn(spec, z, mine, pieces, [pa, pb], own) {
2726
2992
  const reserved = spec.reserved;
2727
2993
  const lines = mine.map((s) => s.line);
@@ -2730,53 +2996,54 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
2730
2996
  const free = less([[z.a, z.b]], reserved);
2731
2997
  const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
2732
2998
  const spread = (x) => {
2733
- if (hi - lo2 <= EPS16 || freeLen <= EPS16) return x;
2999
+ if (hi - lo2 <= EPS18 || freeLen <= EPS18) return x;
2734
3000
  let d = (x - lo2) / (hi - lo2) * freeLen;
2735
3001
  for (const [a, b] of free) {
2736
- if (d <= b - a + EPS16) return a + Math.min(d, b - a);
3002
+ if (d <= b - a + EPS18) return a + Math.min(d, b - a);
2737
3003
  d -= b - a;
2738
3004
  }
2739
3005
  return free[free.length - 1][1];
2740
3006
  };
2741
- const past = lines.some((x) => x < z.a - EPS16 || x > z.b + EPS16);
3007
+ const past = lines.some((x) => x < z.a - EPS18 || x > z.b + EPS18);
2742
3008
  const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
2743
3009
  const proj = (x) => {
2744
3010
  const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
2745
3011
  const p = own ? nearer(q, own) : q;
2746
- if (pieces.some(([a, b]) => p >= a - EPS16 && p <= b + EPS16)) return p;
3012
+ if (pieces.some(([a, b]) => p >= a - EPS18 && p <= b + EPS18)) return p;
2747
3013
  return pieces.map(([a, b]) => Math.min(Math.max(p, a), b)).reduce((m, y) => Math.abs(y - p) < Math.abs(m - p) ? y : m);
2748
3014
  };
2749
- const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS16 || Math.abs(s.line - own[1]) < EPS16);
2750
- const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS16 && s.line <= pb + EPS16 : proj(s.line) >= pa - EPS16 && proj(s.line) <= pb + EPS16).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
3015
+ const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS18 || Math.abs(s.line - own[1]) < EPS18);
3016
+ const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS18 && s.line <= pb + EPS18 : proj(s.line) >= pa - EPS18 && proj(s.line) <= pb + EPS18).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
2751
3017
  const projected = inPiece.map((s) => proj(s.line));
2752
- const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS16) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
3018
+ const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS18) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
2753
3019
  return { inPiece, at };
2754
3020
  }
2755
3021
  function reachStrips(c, spec, room, ends) {
2756
- const inEdge = (s) => !!ends && s[0] < ends[1] - EPS16 && s[1] > ends[0] + EPS16;
3022
+ const inEdge = (s) => !!ends && s[0] < ends[1] - EPS18 && s[1] > ends[0] + EPS18;
2757
3023
  const pieces = room.filter(inEdge);
2758
3024
  if (!ends || pieces.length === 0) return { pieces: [...room], before: [], after: [] };
2759
3025
  const [c0, c1] = spec.across();
2760
- const bandOf2 = (a, b) => spec.vertical ? rect14(c0, a, c1 - c0, b - a) : rect14(a, c0, b - a, c1 - c0);
3026
+ const bandOf2 = (a, b) => spec.vertical ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
2761
3027
  const across2 = c.state.edges.filter((e) => axisOf(e.side) === "column" !== spec.vertical).map((e) => c.now.edges[e.id]);
2762
- const drawnBetween = (a, b) => b - a > EPS16 && across2.some((e) => !!e && e.cross > EPS16 && area4(e.rect) > EPS16 && overlaps4(e.rect, bandOf2(a, b)));
3028
+ const drawnBetween = (a, b) => b - a > EPS18 && across2.some((e) => !!e && e.cross > EPS18 && area4(e.rect) > EPS18 && overlaps4(e.rect, bandOf2(a, b)));
2763
3029
  const first = pieces[0][0];
2764
3030
  const last = pieces[pieces.length - 1][1];
2765
3031
  return {
2766
3032
  pieces,
2767
- before: room.filter((s) => s[1] <= ends[0] + EPS16 && !drawnBetween(s[1], first)),
2768
- after: room.filter((s) => s[0] >= ends[1] - EPS16 && !drawnBetween(last, s[0]))
3033
+ before: room.filter((s) => s[1] <= ends[0] + EPS18 && !drawnBetween(s[1], first)),
3034
+ after: room.filter((s) => s[0] >= ends[1] - EPS18 && !drawnBetween(last, s[0]))
2769
3035
  };
2770
3036
  }
2771
- function tileEdge(c, spec, { cuts, bodies }, lost) {
3037
+ function tileEdge(c, spec, { cuts, bodies }, lost, slides) {
2772
3038
  const whole = wholeRefusal(c, spec);
2773
3039
  if (whole) return [whole];
2774
3040
  const data = EDGE_KINDS[spec.kind];
2775
3041
  const v = spec.vertical;
3042
+ const halves = !spec.edge || cutsByHalves(spec.edge);
2776
3043
  const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
2777
3044
  const { band, keepAt, tile, split } = tilerOf(spec);
2778
3045
  const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
2779
- const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS16 ? v ? rect14(-1e9, drawn.y, 2e9, drawn.height) : rect14(drawn.x, -1e9, drawn.width, 2e9) : null;
3046
+ const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS18 ? v ? rect15(-1e9, drawn.y, 2e9, drawn.height) : rect15(drawn.x, -1e9, drawn.width, 2e9) : null;
2780
3047
  const refused = (zone, hit, reason) => {
2781
3048
  const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
2782
3049
  const shown = inEdge && meet(inEdge, c.state.stage);
@@ -2785,27 +3052,52 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2785
3052
  const slots = distinctSlots(c, spec.slots);
2786
3053
  const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
2787
3054
  const last = acc[acc.length - 1];
2788
- if (last && a <= last[1] + EPS16) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
3055
+ if (last && a <= last[1] + EPS18) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
2789
3056
  else acc.push([a, b]);
2790
3057
  return acc;
2791
3058
  }, []);
2792
- const wedged = (line) => runs.some(([a, b]) => line > a + EPS16 && line < b - EPS16);
3059
+ const wedged = (line) => runs.some(([a, b]) => line > a + EPS18 && line < b - EPS18);
2793
3060
  const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
2794
3061
  const ends = alongLimit && drawn ? v ? [drawn.y, drawn.y + drawn.height] : [drawn.x, drawn.x + drawn.width] : null;
2795
3062
  const out = [];
3063
+ const slotSpans = [];
3064
+ let ownKept = null;
3065
+ const ownRect = landedLayout(c.state, c.now, c.dragged, c.prev).items[c.dragged]?.rect ?? spec.own ?? void 0;
3066
+ const movesOthers = (s) => Object.entries(c.base.items).some(([id, it]) => {
3067
+ if (id === c.dragged || it.edge !== spec.id || it.inMenu) return false;
3068
+ const now = s.result.layout.items[id];
3069
+ return !now || Math.abs(now.rect.x - it.rect.x) > 0.5 || Math.abs(now.rect.y - it.rect.y) > 0.5;
3070
+ });
3071
+ const axis = v ? "y" : "x";
3072
+ const span = (r) => v ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
3073
+ const orderIn = (l) => Object.entries(l.items).filter(([, it]) => it.edge === spec.id && !it.inMenu && !it.floating && area4(it.rect) > EPS18).sort(([, p], [, q]) => span(p.rect)[0] - span(q.rect)[0]).map(([id]) => id).join(" ");
3074
+ const homeOrder = orderIn(c.now);
3075
+ const nearHome = (s) => {
3076
+ if (halves || s.home || !spec.own || !ownRect || c.now.items[c.dragged]?.inMenu) return false;
3077
+ const l = s.result.layout.items[c.dragged]?.rect;
3078
+ return !!l && Math.abs((v ? l.y : l.x) - (v ? ownRect.y : ownRect.x)) < c.slack && movesOthers(s) && orderIn(s.result.layout) !== homeOrder;
3079
+ };
3080
+ const landingOf = (s) => s.home || nearHome(s) ? ownRect : s.result.layout.items[c.dragged]?.rect;
3081
+ const orders = /* @__PURE__ */ new Map();
3082
+ const orderOf = (s) => {
3083
+ let k = orders.get(s);
3084
+ if (k === void 0) orders.set(s, k = s.home || nearHome(s) ? homeOrder : orderIn(s.result.layout));
3085
+ return k;
3086
+ };
3087
+ const stretchesOf = [];
2796
3088
  for (const z of spec.zones) {
2797
- const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS16);
3089
+ const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS18);
2798
3090
  const { pieces, before, after } = reachStrips(c, spec, own ? less(room, [own]) : room, ends);
2799
3091
  if (!hasRoom(pieces, bodies)) continue;
2800
3092
  const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
2801
- const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS16 && a < s.line + data.reach - EPS16));
3093
+ const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS18 && a < s.line + data.reach - EPS18));
2802
3094
  const reason = spec.refuse(z.zone);
2803
3095
  for (const [k, [pa, pb]] of pieces.entries()) {
2804
3096
  const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
2805
3097
  const stripsOf = (i) => [...k === 0 && i === 0 ? before : [], ...k === pieces.length - 1 && i === inPiece.length - 1 ? after : []];
2806
3098
  if (inPiece.length === 0) {
2807
3099
  const lone = (reason === "no-room" || reason === "too-thick") && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
2808
- const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS16 && pa < s.line + data.reach - EPS16);
3100
+ const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS18 && pa < s.line + data.reach - EPS18);
2809
3101
  const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
2810
3102
  if (joins.length > 0) {
2811
3103
  const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
@@ -2816,47 +3108,144 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2816
3108
  if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? "own-place" : reason));
2817
3109
  continue;
2818
3110
  }
2819
- const meet2 = (i) => {
3111
+ const meets = [];
3112
+ for (let i = 1; i < inPiece.length; i++) {
2820
3113
  const [lo2, hi] = [at[i - 1], at[i]];
2821
- const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS16 && w <= inPiece[i].line + EPS16);
2822
- const mid2 = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
2823
- return mid2 > lo2 + EPS16 && mid2 < hi - EPS16 ? mid2 : (lo2 + hi) / 2;
2824
- };
3114
+ const between = spec.cards.filter(([u2, w2]) => u2 >= inPiece[i - 1].line - EPS18 && w2 <= inPiece[i].line + EPS18);
3115
+ const la = landingOf(inPiece[i - 1]);
3116
+ const lb = landingOf(inPiece[i]);
3117
+ const [u, w] = between[0] ?? [NaN, NaN];
3118
+ const mid3 = between.length === 1 ? aimCut(la ?? rect15(0, 0, 0, 0), lb ?? rect15(0, 0, 0, 0), v ? "y" : "x", 0.5, 0, v ? rect15(0, u, 0, w - u) : rect15(u, 0, w - u, 0)) : NaN;
3119
+ meets[i] = mid3 > lo2 + EPS18 && mid3 < hi - EPS18 ? mid3 : (lo2 + hi) / 2;
3120
+ }
3121
+ const meet2 = (i) => meets[i];
2825
3122
  inPiece.forEach((s, i) => {
2826
3123
  const p = at[i];
2827
3124
  const lim = data.virtual ? Infinity : data.reach;
2828
- const a = Math.max(i === 0 ? pa : meet2(i), p - lim);
2829
- const b = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
2830
- if (b - a <= EPS16) {
2831
- if (s.ok && !s.home) lost.push(s.id);
2832
- return;
2833
- }
2834
- if (!hasRoom([[a, b]], bodies)) return;
2835
- const homeTile = (id, u, w, line) => {
2836
- const hit = band(u, w, s.home ? s.result.layout : void 0);
2837
- return tile(z.zone, hit, { kind: "home", id, order: data.layer, priority: spec.homePriority ?? data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: "home" } });
3125
+ const a0 = Math.max(i === 0 ? pa : meet2(i), p - lim);
3126
+ const b0 = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
3127
+ stretchesOf.push({ s, a: a0, b: b0, make: (a, b) => makeTiles(a, b) });
3128
+ const makeTiles = (a, b) => {
3129
+ if (b - a <= EPS18) {
3130
+ if (s.ok && !s.home) lost.push(s.id);
3131
+ return;
3132
+ }
3133
+ if (!hasRoom([[a, b]], bodies)) return;
3134
+ const homeTile = (id, u, w, line) => {
3135
+ const hit = band(u, w, s.home ? s.result.layout : void 0);
3136
+ return tile(z.zone, hit, { kind: "home", id, order: data.layer, priority: spec.homePriority ?? data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: "home" } });
3137
+ };
3138
+ if (s.home || nearHome(s)) {
3139
+ for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.home ? s.id : homeSlot?.id ?? s.id, u, w, p)));
3140
+ return;
3141
+ }
3142
+ const faced = halves && homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS18 && u < b - EPS18) : [];
3143
+ for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
3144
+ for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
3145
+ const line = Math.min(Math.max(p, u), w);
3146
+ const hit = band(u, w, s.result.layout);
3147
+ if (!s.ok) {
3148
+ out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
3149
+ continue;
3150
+ }
3151
+ slotSpans.push([u, w]);
3152
+ 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 })));
3153
+ }
2838
3154
  };
2839
- if (s.home) {
2840
- for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.id, u, w, p)));
2841
- return;
2842
- }
2843
- const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS16 && u < b - EPS16) : [];
2844
- for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
2845
- for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
2846
- const line = Math.min(Math.max(p, u), w);
2847
- const hit = band(u, w, s.result.layout);
2848
- if (!s.ok) out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
2849
- 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 })));
2850
- }
2851
3155
  });
2852
3156
  }
2853
3157
  }
2854
- if (own && spec.own) {
3158
+ if (!halves) {
3159
+ const ownStretch = own && homeSlot ? [{ s: homeSlot, a: own[0], b: own[1], make: () => void 0 }] : [];
3160
+ const all = [...stretchesOf, ...ownStretch];
3161
+ const neighborsIn = (order) => {
3162
+ const ids = order.split(" ");
3163
+ const k = ids.indexOf(c.dragged);
3164
+ return k < 0 ? null : { ...k > 0 ? { before: ids[k - 1] } : {}, ...k + 1 < ids.length ? { after: ids[k + 1] } : {} };
3165
+ };
3166
+ const edgeRect = c.base.edges[spec.id]?.rect ?? drawn;
3167
+ const slideEdge = spec.edge && edgeRect ? { state: c.state, dragged: c.dragged, e: spec.edge, axis, base: c.base, drawn: edgeRect, middle: (span(edgeRect)[0] + span(edgeRect)[1]) / 2, fixed: onEdge(c.base, spec.id, c.dragged, axis).filter((o) => c.state.items[o.id]?.fixed), prev: c.prev } : null;
3168
+ const ranges = /* @__PURE__ */ new Map();
3169
+ const rangeOf = (order) => {
3170
+ if (ranges.has(order)) return ranges.get(order);
3171
+ const key = `${spec.id} ${order}`;
3172
+ const known = c.slideRanges.get(key);
3173
+ const r = known !== void 0 ? known : (() => {
3174
+ const n = neighborsIn(order);
3175
+ const ids = order.split(" ");
3176
+ const room = n && slideEdge ? slideRoom(slideEdge, n.before, n.after, ids.slice(0, ids.indexOf(c.dragged))) : null;
3177
+ const range = room && slideEdge ? slideRange(slideEdge, room, c.slack > 0 ? 2 * c.slack : SPOT_PITCH) : null;
3178
+ return room && range && range.to - range.from >= 1 ? { before: n?.before, after: n?.after, from: range.from, to: range.to, w: room.w, first: range.first, last: range.last } : null;
3179
+ })();
3180
+ c.slideRanges.set(key, r);
3181
+ ranges.set(order, r);
3182
+ if (r && slides) slides.push({ edge: spec.id, ...r });
3183
+ return r;
3184
+ };
3185
+ const rangeFor = (s) => {
3186
+ const l = landingOf(s);
3187
+ const r = l ? rangeOf(orderOf(s)) : null;
3188
+ const [l0, l1] = l ? span(l) : [NaN, NaN];
3189
+ return r && Math.abs(l1 - l0 - r.w) <= 1 && l0 >= r.from - 1 && l0 <= r.to + 1 ? r : null;
3190
+ };
3191
+ const firstOf = (s) => rangeFor(s)?.first ?? landingOf(s);
3192
+ const lastOf = (s) => rangeFor(s)?.last ?? landingOf(s);
3193
+ const mid3 = (r) => (span(r)[0] + span(r)[1]) / 2;
3194
+ const besideZone = (s) => {
3195
+ const before = neighborsIn(orderOf(s))?.before;
3196
+ return s.place.kind === "gap" && s.place.zone === zoneIn2(c.base, before) ? 0 : 1;
3197
+ };
3198
+ const inMenu = !!c.now.items[c.dragged]?.inMenu;
3199
+ const lands = all.filter((r) => (r.s.ok || r.s.home) && !!landingOf(r.s) && !(inMenu && r.s.home));
3200
+ const sorted = [...lands].sort((p, q) => mid3(firstOf(p.s)) - mid3(firstOf(q.s)) || (p.s.home ? -1 : q.s.home ? 1 : 0) || besideZone(p.s) - besideZone(q.s) || p.a - q.a);
3201
+ const sameAt = (p, q) => span(landingOf(p)).every((x, n) => Math.abs(x - span(landingOf(q))[n]) < 0.5);
3202
+ const runs2 = [];
3203
+ const dropped = [];
3204
+ for (const r of sorted) {
3205
+ const last = runs2.at(-1);
3206
+ if (last && orderOf(last[0].s) === orderOf(r.s)) {
3207
+ last.push(r);
3208
+ continue;
3209
+ }
3210
+ if (runs2.some((run) => run.some((x) => !rangeFor(x.s) && !rangeFor(r.s) && sameAt(x.s, r.s)))) dropped.push(r);
3211
+ else runs2.push([r]);
3212
+ }
3213
+ const facing = (run, end) => run.map((r) => end ? lastOf(r.s) : firstOf(r.s)).reduce((m, x) => end ? span(x)[1] > span(m)[1] ? x : m : span(x)[0] < span(m)[0] ? x : m);
3214
+ const cutOf = (p, q) => aimCut(facing(p, true), facing(q, false), axis, c.share[axis], c.slack);
3215
+ const bandStart = ends?.[0] ?? -Infinity;
3216
+ const bandEnd = ends?.[1] ?? Infinity;
3217
+ const cuts2 = crossFreeCuts(runs2.length, (i, j) => cutOf(runs2[i], runs2[j]), (i) => runs2[i].some((x) => x.s.home), bandStart, bandEnd);
3218
+ const spans = [];
3219
+ runs2.forEach((run, i) => {
3220
+ const cp = i > 0 ? cuts2[i - 1] : Math.min(...run.map((r) => r.a));
3221
+ const cn = i + 1 < runs2.length ? cuts2[i] : Math.max(...run.map((r) => r.b));
3222
+ for (const r of run) [r.a, r.b] = [Math.min(Math.max(r.a, cp), cn), Math.max(Math.min(r.b, cn), cp)];
3223
+ const held = run.filter((r) => r.b - r.a > EPS18).sort((p, q) => p.a - q.a);
3224
+ if (held.length === 0) {
3225
+ const one = run.find((r) => !ownStretch.includes(r)) ?? run[0];
3226
+ [one.a, one.b] = [cp, Math.max(cp, cn)];
3227
+ } else {
3228
+ held[0].a = cp;
3229
+ held.at(-1).b = Math.max(cp, cn);
3230
+ }
3231
+ if (cn - cp > EPS18) spans.push([cp, cn]);
3232
+ });
3233
+ for (const r of dropped) r.a = r.b;
3234
+ for (const r of lands) if (r.s.ok && !r.s.home) lost.push(r.s.id);
3235
+ if (ownStretch[0]) ownKept = ownStretch[0].b - ownStretch[0].a > EPS18 ? [[ownStretch[0].a, ownStretch[0].b]] : [];
3236
+ for (const r of all.filter((x) => !lands.includes(x))) {
3237
+ const left = less([[r.a, r.b]], spans).filter(([u, w]) => w - u > EPS18);
3238
+ [r.a, r.b] = left.length ? left.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : [r.a, r.a];
3239
+ }
3240
+ }
3241
+ for (const r of stretchesOf) r.make(r.a, r.b);
3242
+ if (own && spec.own && (ownKept === null || ownKept.length > 0)) {
2855
3243
  const home = spec.slots.find((s) => s.home);
2856
- const [a, b] = own;
3244
+ const kept = ownKept ?? (halves ? [] : less([own], slotSpans).filter(([u, w]) => w - u > EPS18));
3245
+ const [a, b] = kept.length > 0 ? kept.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : own;
2857
3246
  const h = band(a, b);
2858
3247
  const o = spec.own;
2859
- const hit = v ? rect14(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect14(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));
3248
+ const hit = v ? rect15(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect15(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));
2860
3249
  out.push(tile(home?.zone ?? zoneOf(c.state.items[c.dragged]), hit, { kind: "home", id: home ? home.id : targetId({ kind: "home", item: c.dragged }), order: 0, priority: home ? data.priority : 1, keep: null, place: { kind: "home" } }));
2861
3250
  }
2862
3251
  return out;
@@ -2874,7 +3263,7 @@ function placeReach(t, pieces, placed, landed, gone) {
2874
3263
  if (at.length === 0 && gone.has(of)) {
2875
3264
  const line = t.vertical ? of.keep.y : of.keep.x;
2876
3265
  const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
2877
- const on = whole.filter((p) => t.vertical ? p.y <= line + EPS16 && line <= p.y + p.height + EPS16 : p.x <= line + EPS16 && line <= p.x + p.width + EPS16);
3266
+ const on = whole.filter((p) => t.vertical ? p.y <= line + EPS18 && line <= p.y + p.height + EPS18 : p.x <= line + EPS18 && line <= p.x + p.width + EPS18);
2878
3267
  const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area4(p) > area4(a) ? p : a, null);
2879
3268
  if (kept) {
2880
3269
  placed.push({ ...of, hit: kept });
@@ -2887,10 +3276,10 @@ function placeReach(t, pieces, placed, landed, gone) {
2887
3276
  for (let k = 0; k < cover.length; k++) {
2888
3277
  const h = cover[k];
2889
3278
  const joint = pieces.find(
2890
- (p) => t.vertical ? p.y <= h.y + EPS16 && p.y + p.height >= h.y + h.height - EPS16 && (Math.abs(p.x - h.x - h.width) < EPS16 || Math.abs(p.x + p.width - h.x) < EPS16) : p.x <= h.x + EPS16 && p.x + p.width >= h.x + h.width - EPS16 && (Math.abs(p.y - h.y - h.height) < EPS16 || Math.abs(p.y + p.height - h.y) < EPS16)
3279
+ (p) => t.vertical ? p.y <= h.y + EPS18 && p.y + p.height >= h.y + h.height - EPS18 && (Math.abs(p.x - h.x - h.width) < EPS18 || Math.abs(p.x + p.width - h.x) < EPS18) : p.x <= h.x + EPS18 && p.x + p.width >= h.x + h.width - EPS18 && (Math.abs(p.y - h.y - h.height) < EPS18 || Math.abs(p.y + p.height - h.y) < EPS18)
2891
3280
  );
2892
3281
  if (!joint) continue;
2893
- const merged = t.vertical ? rect14(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height) : rect14(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));
3282
+ const merged = t.vertical ? rect15(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height) : rect15(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));
2894
3283
  placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
2895
3284
  return;
2896
3285
  }
@@ -2958,10 +3347,10 @@ function clipTiles(tiles, own, chrome, lost) {
2958
3347
  }
2959
3348
 
2960
3349
  // src/targets/rail-strip.ts
2961
- import { EPS as EPS18, overlaps as overlaps5, rect as rect16, subtract as subtract4 } from "@n-uf/placement";
3350
+ import { EPS as EPS20, overlaps as overlaps5, rect as rect17, subtract as subtract4 } from "@n-uf/placement";
2962
3351
 
2963
3352
  // src/targets/virtual.ts
2964
- import { EPS as EPS17, clamp, rect as rect15 } from "@n-uf/placement";
3353
+ import { EPS as EPS19, clamp as clamp2, rect as rect16 } from "@n-uf/placement";
2965
3354
  function ringsOf(c, side) {
2966
3355
  const seen = sideRings(c.state.edges, side);
2967
3356
  const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
@@ -2974,7 +3363,7 @@ function railOuter(c, side) {
2974
3363
  const windowEdge = side === "left" ? state.stage.x : state.stage.x + state.stage.width;
2975
3364
  if (!place) return windowEdge;
2976
3365
  const placeOuter = side === "left" ? place.x : place.x + place.width;
2977
- const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter + EPS17 : e.rect.x >= placeOuter - EPS17));
3366
+ const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter + EPS19 : e.rect.x >= placeOuter - EPS19));
2978
3367
  return barOutside ? placeOuter : windowEdge;
2979
3368
  }
2980
3369
  function collapsesAt(c, result, side) {
@@ -3005,13 +3394,13 @@ function columnLines(c, side, railLands) {
3005
3394
  const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
3006
3395
  const stage = c.state.stage;
3007
3396
  const dir = side === "left" ? 1 : -1;
3008
- const outside2 = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x + EPS17 : e.rect.x >= x - EPS17));
3397
+ const outside2 = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x + EPS19 : e.rect.x >= x - EPS19));
3009
3398
  const railFirst = railLands && !!c.state.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
3010
- const placeOf = (l, i) => {
3011
- const atEdge = side === "left" ? l.x <= stage.x + EPS17 : l.x >= stage.x + stage.width - EPS17;
3399
+ const placeOf2 = (l, i) => {
3400
+ const atEdge = side === "left" ? l.x <= stage.x + EPS19 : l.x >= stage.x + stage.width - EPS19;
3012
3401
  if (i > 0 || outside2(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };
3013
3402
  const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
3014
- const boundary = clamp(l.x, stage.x, stage.x + stage.width);
3403
+ const boundary = clamp2(l.x, stage.x, stage.x + stage.width);
3015
3404
  const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
3016
3405
  const line = band0 + dir * edgePlace / 2;
3017
3406
  const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
@@ -3020,7 +3409,7 @@ function columnLines(c, side, railLands) {
3020
3409
  const most = state.columns?.[side]?.cross.max;
3021
3410
  const tooThick = most !== void 0 && thickerThan(formsOf(state.items[dragged], "column"), most);
3022
3411
  return lines.map((l, i) => {
3023
- const p = placeOf(l, i);
3412
+ const p = placeOf2(l, i);
3024
3413
  return {
3025
3414
  id: virtualEdgeId("column", side),
3026
3415
  edge: null,
@@ -3039,7 +3428,7 @@ function columnLines(c, side, railLands) {
3039
3428
  ownedAlong: p.owned,
3040
3429
  drawn: false,
3041
3430
  // Where the new column's edge lands: the line itself, inside the stage.
3042
- marker: () => rect15(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
3431
+ marker: () => rect16(clamp2(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
3043
3432
  };
3044
3433
  });
3045
3434
  }
@@ -3066,7 +3455,7 @@ function ownColumnRun(c, side, rail) {
3066
3455
  const tiles = shown.segments.filter((s) => s.edge === edge.id).map((s) => s.rect);
3067
3456
  if (tiles.length === 0) return null;
3068
3457
  const top = Math.min(...tiles.map((r) => r.y));
3069
- const spec = railColumnSpec(c, edge, rect15(shown.rect.x, top, shown.rect.width, Math.max(...tiles.map((r) => r.y + r.height)) - top));
3458
+ const spec = railColumnSpec(c, edge, rect16(shown.rect.x, top, shown.rect.width, Math.max(...tiles.map((r) => r.y + r.height)) - top));
3070
3459
  if (!spec) return null;
3071
3460
  const stays = ({ layout }) => layout.items[dragged]?.rail === side && layout.items[dragged]?.edge === edge.id;
3072
3461
  return { ...spec, own: null, holds: false, homePriority: EDGE_KINDS.railStop.priority, slots: spec.slots.map((s) => s.home ? { ...s, id: homeId } : { ...s, ok: s.ok && stays(s.result) }) };
@@ -3104,7 +3493,7 @@ function railStops(c, side) {
3104
3493
  } else {
3105
3494
  const firstCol = mine.find((e) => e.column === true);
3106
3495
  const outer = railOuter(c, side);
3107
- zone = rect15(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
3496
+ zone = rect16(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
3108
3497
  stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
3109
3498
  }
3110
3499
  const ownRail = now.items[dragged]?.rail === side;
@@ -3135,7 +3524,7 @@ function railStops(c, side) {
3135
3524
  owned: rail && rail.segments.length > 0 ? [at.x, at.x + at.width] : side === "left" ? [at.x, at.x + Math.min(at.width, EDGE_KINDS.railStop.place)] : [at.x + at.width - Math.min(at.width, EDGE_KINDS.railStop.place), at.x + at.width],
3136
3525
  ownedAlong: null,
3137
3526
  drawn: !!rail && rail.segments.length > 0,
3138
- marker: (s) => rect15(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
3527
+ marker: (s) => rect16(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
3139
3528
  };
3140
3529
  }
3141
3530
 
@@ -3151,11 +3540,11 @@ function columnStrip(c, side, policy) {
3151
3540
  if (moved === c.state) return null;
3152
3541
  const result = c.settle(markUsed(moved, c.dragged));
3153
3542
  const el = result.layout.edges[edge.id];
3154
- if (!el || el.rect.width <= EPS18 || !collapsesAt(c, result, side)) return null;
3543
+ if (!el || el.rect.width <= EPS20 || !collapsesAt(c, result, side)) return null;
3155
3544
  const r = el.rect;
3156
3545
  const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
3157
3546
  const [x, w] = across(side, side === "left" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));
3158
- return { side, rect: rect16(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
3547
+ return { side, rect: rect17(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
3159
3548
  }
3160
3549
  function declaredStrip(c, side, policy) {
3161
3550
  const template = c.state.columns?.[side];
@@ -3172,7 +3561,7 @@ function declaredStrip(c, side, policy) {
3172
3561
  const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
3173
3562
  return {
3174
3563
  side,
3175
- rect: rect16(x, a, w, b - a),
3564
+ rect: rect17(x, a, w, b - a),
3176
3565
  slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
3177
3566
  };
3178
3567
  }
@@ -3257,7 +3646,7 @@ ${r.zone}`) ?? [], r]);
3257
3646
  group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((r, n) => numbered.set(r, targetId({ kind: "refuse", edge: r.edge, zone: r.zone, n })));
3258
3647
  const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
3259
3648
  for (const s of strips) {
3260
- const grown = s.side === "left" ? rect16(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect16(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
3649
+ const grown = s.side === "left" ? rect17(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect17(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
3261
3650
  for (const sl of s.slots) {
3262
3651
  const [a, b] = sl.along;
3263
3652
  const slot = sl.result.layout.items[c.dragged].rect;
@@ -3265,8 +3654,8 @@ ${r.zone}`) ?? [], r]);
3265
3654
  out.push({
3266
3655
  id: sl.id,
3267
3656
  priority: 1,
3268
- hit: rect16(s.rect.x, a, s.rect.width, b - a),
3269
- armedHit: rect16(grown.x, a, grown.width, b - a),
3657
+ hit: rect17(s.rect.x, a, s.rect.width, b - a),
3658
+ armedHit: rect17(grown.x, a, grown.width, b - a),
3270
3659
  arm: "dwell",
3271
3660
  // Armed, its room opens at once: a host that draws only a marker reads that from this one flag, as for any target.
3272
3661
  opensRoom: true,
@@ -3287,7 +3676,7 @@ var withoutHits = (t) => {
3287
3676
  function insideStrips(r, strips) {
3288
3677
  const s = strips.find((x) => overlaps5(x.rect, r));
3289
3678
  if (!s) return null;
3290
- return s.side === "left" ? rect16(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect16(s.rect.x - r.width, r.y, r.width, r.height);
3679
+ return s.side === "left" ? rect17(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect17(s.rect.x - r.width, r.y, r.width, r.height);
3291
3680
  }
3292
3681
  function clearOfStrips(t, dragged, strips) {
3293
3682
  return {
@@ -3298,7 +3687,7 @@ function clearOfStrips(t, dragged, strips) {
3298
3687
  if (!at) return first;
3299
3688
  let dx = 0;
3300
3689
  for (const s of strips) {
3301
- const r = rect16(at.x + dx, at.y, at.width, at.height);
3690
+ const r = rect17(at.x + dx, at.y, at.width, at.height);
3302
3691
  if (!overlaps5(r, s)) continue;
3303
3692
  dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
3304
3693
  }
@@ -3308,7 +3697,7 @@ function clearOfStrips(t, dragged, strips) {
3308
3697
  }
3309
3698
 
3310
3699
  // src/targets/min-hit.ts
3311
- import { EPS as EPS19, area as area5, rect as rect17, subtract as subtract5 } from "@n-uf/placement";
3700
+ import { EPS as EPS21, area as area5, rect as rect18, subtract as subtract5 } from "@n-uf/placement";
3312
3701
  function kindOf(c, t) {
3313
3702
  const p = parseTargetId(t.id);
3314
3703
  if (!p) return null;
@@ -3321,8 +3710,8 @@ function kindOf(c, t) {
3321
3710
  return null;
3322
3711
  }
3323
3712
  var largest3 = (ps) => ps.reduce((a, p) => area5(p) > area5(a) ? p : a);
3324
- var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS19 && Math.max(r.width, r.height) >= m.along - EPS19;
3325
- var overlaps6 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS19 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS19;
3713
+ var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS21 && Math.max(r.width, r.height) >= m.along - EPS21;
3714
+ var overlaps6 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS21 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS21;
3326
3715
  var cut = (ps, g) => ps.flatMap((p) => subtract5(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
3327
3716
  var piecesOf = (t) => t.hits ?? [t.hit];
3328
3717
  var withPieces2 = (t, ps) => {
@@ -3330,22 +3719,22 @@ var withPieces2 = (t, ps) => {
3330
3719
  return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
3331
3720
  };
3332
3721
  function growths(r, axis, d) {
3333
- const [lo2, hi] = axis === "x" ? [rect17(r.x - d, r.y, d, r.height), rect17(r.x + r.width, r.y, d, r.height)] : [rect17(r.x, r.y - d, r.width, d), rect17(r.x, r.y + r.height, r.width, d)];
3722
+ const [lo2, hi] = axis === "x" ? [rect18(r.x - d, r.y, d, r.height), rect18(r.x + r.width, r.y, d, r.height)] : [rect18(r.x, r.y - d, r.width, d), rect18(r.x, r.y + r.height, r.width, d)];
3334
3723
  const h = d / 2;
3335
- const halves = axis === "x" ? [rect17(r.x - h, r.y, h, r.height), rect17(r.x + r.width, r.y, h, r.height)] : [rect17(r.x, r.y - h, r.width, h), rect17(r.x, r.y + r.height, r.width, h)];
3724
+ const halves = axis === "x" ? [rect18(r.x - h, r.y, h, r.height), rect18(r.x + r.width, r.y, h, r.height)] : [rect18(r.x, r.y - h, r.width, h), rect18(r.x, r.y + r.height, r.width, h)];
3336
3725
  return [[lo2], [hi], halves];
3337
3726
  }
3338
3727
  var union = (a, gs) => {
3339
3728
  const x0 = Math.min(a.x, ...gs.map((g) => g.x));
3340
3729
  const y0 = Math.min(a.y, ...gs.map((g) => g.y));
3341
- return rect17(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);
3730
+ return rect18(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);
3342
3731
  };
3343
3732
  function mayGrow(c, targets2, i, grow, minOf, zone, away) {
3344
3733
  const s = c.state.stage;
3345
3734
  for (const g of grow) {
3346
- if (g.x < s.x - EPS19 || g.y < s.y - EPS19 || g.x + g.width > s.x + s.width + EPS19 || g.y + g.height > s.y + s.height + EPS19) return false;
3735
+ if (g.x < s.x - EPS21 || g.y < s.y - EPS21 || g.x + g.width > s.x + s.width + EPS21 || g.y + g.height > s.y + s.height + EPS21) return false;
3347
3736
  if ([...keepClearFor(c.state, c.now, "targets"), ...away].some((r) => overlaps6(r, g))) return false;
3348
- if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS19)) return false;
3737
+ if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS21)) return false;
3349
3738
  }
3350
3739
  return targets2.every((o, j) => {
3351
3740
  if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps6(p, g)))) return true;
@@ -3360,7 +3749,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
3360
3749
  let best = null;
3361
3750
  for (const [side] of growths(l, axis, d)) {
3362
3751
  const g = side;
3363
- const strip = (a, b) => axis === "x" ? rect17(g.x, a, g.width, b - a) : rect17(a, g.y, b - a, g.height);
3752
+ const strip = (a, b) => axis === "x" ? rect18(g.x, a, g.width, b - a) : rect18(a, g.y, b - a, g.height);
3364
3753
  const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
3365
3754
  for (const o of targets2)
3366
3755
  for (const p of piecesOf(o))
@@ -3380,7 +3769,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
3380
3769
  }
3381
3770
  if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
3382
3771
  for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
3383
- if (b - a < m.along - EPS19) break;
3772
+ if (b - a < m.along - EPS21) break;
3384
3773
  const r = strip(a, b);
3385
3774
  if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area5(r) > area5(best))) best = r;
3386
3775
  break;
@@ -3395,7 +3784,7 @@ function withMinHit(c, targets2, refusals2, zones) {
3395
3784
  const k = kindOf(c, t);
3396
3785
  return k ? EDGE_KINDS[k].minHit : null;
3397
3786
  };
3398
- const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS19 && e.rect.height > EPS19);
3787
+ const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS21 && e.rect.height > EPS21);
3399
3788
  for (let i = 0; i < out.length; i++) {
3400
3789
  const t = out[i];
3401
3790
  const m = minOf(t);
@@ -3412,7 +3801,7 @@ function withMinHit(c, targets2, refusals2, zones) {
3412
3801
  const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
3413
3802
  const size = axis === "x" ? l.width : l.height;
3414
3803
  const d = (step === "across" ? m.across : m.along) - size;
3415
- if (d <= EPS19) continue;
3804
+ if (d <= EPS21) continue;
3416
3805
  let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
3417
3806
  if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
3418
3807
  if (!grow) continue;
@@ -3423,7 +3812,7 @@ function withMinHit(c, targets2, refusals2, zones) {
3423
3812
  out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
3424
3813
  }
3425
3814
  const g0 = grow[0];
3426
- const span = axis === "x" ? rect17(l.x, g0.y, l.width, g0.height) : rect17(g0.x, l.y, g0.width, l.height);
3815
+ const span = axis === "x" ? rect18(l.x, g0.y, l.width, g0.height) : rect18(g0.x, l.y, g0.width, l.height);
3427
3816
  const grown = union(span, grow);
3428
3817
  const others = piecesOf(out[i]).filter((p) => p !== l);
3429
3818
  out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
@@ -3452,7 +3841,7 @@ function emit2(c, placed) {
3452
3841
  const homeId = targetId({ kind: "home", item: dragged });
3453
3842
  const targets2 = [];
3454
3843
  const refused = [];
3455
- const homeAfter = () => ({ state, layout: now });
3844
+ const homeAfter = () => ({ state, layout: landedLayout(state, now, dragged, c.prev) });
3456
3845
  const pos = (t) => t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y];
3457
3846
  const rank = /* @__PURE__ */ new Map();
3458
3847
  const edgeOf = (t) => t.spec?.edge ? t.spec : t.edge;
@@ -3464,12 +3853,16 @@ function emit2(c, placed) {
3464
3853
  }
3465
3854
  for (const zones of byZone.values()) for (const group of zones.values()) group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((t, n) => rank.set(t, n));
3466
3855
  let ownHome = null;
3856
+ let ownSlot = null;
3857
+ const homeTiles = [];
3467
3858
  for (const t of placed) {
3468
3859
  if (t.kind === "refuse") {
3469
3860
  const n = rank.get(t);
3470
3861
  refused.push({ id: targetId({ kind: "refuse", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, reason: t.reason });
3471
3862
  continue;
3472
3863
  }
3864
+ if (t.kind === "home" && t.order === 0 && t.id !== homeId) ownSlot = t.hit;
3865
+ else if (t.kind === "home" && t.id !== homeId) homeTiles.push(t.hit);
3473
3866
  if (t.kind === "home" && t.id === homeId) {
3474
3867
  if (t.order === 0) ownHome = t.hit;
3475
3868
  continue;
@@ -3491,27 +3884,36 @@ function emit2(c, placed) {
3491
3884
  const room = t.slot && slotOverMoved(now, base, result.layout, t.slot, dragged, t.edge) ? { opensRoom: true, ...atEdge ? { roomHold: EDGE_ROOM_HOLD } : {}, ...thickens ? { roomHit: hull(t.hit, t.slot) } : {} } : {};
3492
3885
  targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, ...t.slot ? { slot: t.slot } : {}, ...t.marker ? { marker: t.marker } : {}, ...room, item: dragged, place: t.place, after: () => result });
3493
3886
  }
3887
+ if (!ownHome && ownSlot) {
3888
+ const o = now.items[dragged]?.rect;
3889
+ ownHome = (o ? meet(o, ownSlot) : null) ?? ownSlot;
3890
+ } else if (!ownHome && homeTiles.length > 0) {
3891
+ const o = now.items[dragged]?.rect;
3892
+ const largest4 = (rs) => rs.reduce((m, r) => area6(r) > area6(m) ? r : m);
3893
+ const met = o ? homeTiles.flatMap((h) => meet(o, h) ?? []) : [];
3894
+ ownHome = largest4(met.length > 0 ? met : homeTiles);
3895
+ }
3494
3896
  return { targets: targets2, refused, ownHome };
3495
3897
  }
3496
3898
  function hull(a, b) {
3497
3899
  const x = Math.min(a.x, b.x);
3498
3900
  const y = Math.min(a.y, b.y);
3499
- return rect18(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3901
+ return rect19(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3500
3902
  }
3501
3903
  var thicknessChanges = (now, after) => {
3502
3904
  const a = now.content;
3503
3905
  const b = after.content;
3504
- return Math.abs(b.x - a.x) > EPS20 || Math.abs(b.y - a.y) > EPS20 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS20 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS20;
3906
+ return Math.abs(b.x - a.x) > EPS22 || Math.abs(b.y - a.y) > EPS22 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS22 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS22;
3505
3907
  };
3506
3908
  var WINDOW_EDGE_KINDS = /* @__PURE__ */ new Set(["rail", "railStop", "sideBar", "columnLine"]);
3507
- var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS20 || r.x + r.width >= stage.x + stage.width - EPS20);
3909
+ var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS22 || r.x + r.width >= stage.x + stage.width - EPS22);
3508
3910
  function slotOverMoved(now, lifted, after, slot, dragged, onto) {
3509
3911
  const from = now.items[dragged]?.edge;
3510
3912
  return Object.entries(now.items).some(([id, was]) => {
3511
3913
  if (!overlaps7(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
3512
3914
  const r = after.items[id]?.rect;
3513
3915
  const start = (from !== void 0 && was.edge === from ? lifted.items[id]?.rect : void 0) ?? was.rect;
3514
- return !!r && (Math.abs(r.x - start.x) > EPS20 || Math.abs(r.y - start.y) > EPS20 || Math.abs(r.width - start.width) > EPS20 || Math.abs(r.height - start.height) > EPS20);
3916
+ return !!r && (Math.abs(r.x - start.x) > EPS22 || Math.abs(r.y - start.y) > EPS22 || Math.abs(r.width - start.width) > EPS22 || Math.abs(r.height - start.height) > EPS22);
3515
3917
  });
3516
3918
  }
3517
3919
  function aloneRects(tiles) {
@@ -3536,24 +3938,22 @@ function generate(state, dragged, options) {
3536
3938
  const g = generateShown(shown, dragged, options, hidden);
3537
3939
  const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
3538
3940
  const showsIn = hidden.some((e) => e.showIn !== void 0);
3539
- return {
3540
- ...g,
3541
- targets: g.targets.map((t) => ({
3542
- ...t,
3543
- after: (point, grab) => {
3544
- const a = t.after(point, grab);
3545
- if (a.state === shown) return { state, layout: showsIn ? solve(state, prev) : a.layout };
3546
- const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
3547
- const named = !!on && namesZone(on, state.items[dragged].kind);
3548
- const back = withHiddenOf(state, a.state, lent, dragged, named, rezoned);
3549
- const restored = showsIn ? prune(back) : back;
3550
- const ringOf = new Map(a.state.edges.map((e) => [e.id, e.ring]));
3551
- const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
3552
- const layout = renumbered || showsIn || rezoned.size > 0 ? solve(restored, prev) : a.layout;
3553
- return { state: restored, layout };
3554
- }
3555
- }))
3556
- };
3941
+ const wrap = (t) => ({
3942
+ ...t,
3943
+ after: (point, grab) => {
3944
+ const a = t.after(point, grab);
3945
+ if (a.state === shown) return { state, layout: showsIn ? solveLanded(state, dragged, prev) : a.layout };
3946
+ const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
3947
+ const named = !!on && namesZone(on, state.items[dragged].kind);
3948
+ const back = withHiddenOf(state, a.state, lent, dragged, named, rezoned);
3949
+ const restored = showsIn ? prune(back) : back;
3950
+ const ringOf = new Map(a.state.edges.map((e) => [e.id, e.ring]));
3951
+ const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
3952
+ const layout = renumbered || showsIn || rezoned.size > 0 ? solveLanded(restored, dragged, prev) : a.layout;
3953
+ return { state: restored, layout };
3954
+ }
3955
+ });
3956
+ return { ...g, targets: g.targets.map(wrap), ...g.places ? { places: g.places.map(wrap) } : {} };
3557
3957
  }
3558
3958
  function generateShown(state, dragged, options, hidden) {
3559
3959
  if (Object.hasOwn(state.items, dragged) && state.items[dragged].fixed) return anchorTargets(state, dragged, options);
@@ -3566,20 +3966,25 @@ function generateShown(state, dragged, options, hidden) {
3566
3966
  const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
3567
3967
  const own = ownership(c, live, (s) => along2.get(s), (s) => aloneRects(alone.get(s)));
3568
3968
  const lost = [];
3569
- const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
3969
+ const slides = [];
3970
+ const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost, slides));
3570
3971
  const ownRect = now.items[dragged];
3571
3972
  const homeEdge = state.edges.find((e) => e.id === ownRect?.edge);
3572
3973
  const homeHit = homeRectOf(c, null);
3573
- if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
3974
+ if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0 || t.kind === "home" && t.edge === homeEdge.id && !!t.spec?.edge && !cutsByHalves(t.spec.edge)))
3574
3975
  tiles.push({ edge: homeEdge.id, spec: null, edgeKind: edgeKindOf(state, homeEdge), vertical: axisOf(homeEdge.side) === "column", zone: zoneOf(item), order: 0, kind: "home", id: targetId({ kind: "home", item: dragged }), priority: 1, place: { kind: "home" }, hit: homeHit, keep: null });
3575
3976
  const placed = clipTiles(tiles, own, keepClearFor(state, now, "targets"), lost);
3576
3977
  const { targets: targets2, refused, ownHome } = emit2(c, placed);
3577
- const homeAfter = () => ({ state, layout: now });
3978
+ const homeAfter = () => ({ state, layout: landedLayout(state, now, dragged, c.prev) });
3578
3979
  if (state.floatKinds.includes(item.kind)) {
3579
3980
  const was = state.floats.find((f) => f.id === dragged);
3580
3981
  const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
3581
3982
  const wasOrient = was?.orient ?? floatOrientOf(item);
3582
3983
  const size = options.floatSize ?? (was && wasOrient === fo ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
3984
+ const seenOwn = now.items[dragged];
3985
+ const seenEdge = seenOwn?.edge ? state.edges.find((e) => e.id === seenOwn.edge) : void 0;
3986
+ const grown = seenOwn && seenEdge && growsOnBar(state, seenEdge, dragged, seenOwn.form) && seenOwn.rect.width > 0 && seenOwn.rect.height > 0 ? seenOwn.rect : null;
3987
+ const handOf = (g) => g && grown ? { x: clamp3(g.x / grown.width, 0, 1) * size.width, y: clamp3(g.y / grown.height, 0, 1) * size.height } : g;
3583
3988
  targets2.push({
3584
3989
  id: targetId({ kind: "float", item: dragged }),
3585
3990
  priority: 3,
@@ -3590,17 +3995,17 @@ function generateShown(state, dragged, options, hidden) {
3590
3995
  item: dragged,
3591
3996
  place: { kind: "float" },
3592
3997
  after(point, grab) {
3593
- const g = grab ?? { x: size.width / 2, y: size.height / 2 };
3594
- const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect18(point.x - g.x, point.y - g.y, size.width, size.height);
3998
+ const g = handOf(grab) ?? { x: size.width / 2, y: size.height / 2 };
3999
+ const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect19(point.x - g.x, point.y - g.y, size.width, size.height);
3595
4000
  const first = solve(markUsed(floatAt(state, dragged, raw, options.floatOrient), dragged), prev);
3596
4001
  const fitted = first.items[dragged]?.rect;
3597
4002
  const at = fitted ?? raw;
3598
4003
  const placed2 = (x, y, stays) => {
3599
- const s = floatAt(state, dragged, rect18(x, y, size.width, size.height), options.floatOrient);
4004
+ const s = floatAt(state, dragged, rect19(x, y, size.width, size.height), options.floatOrient);
3600
4005
  return c.settle(markUsed(stays ? { ...s, floats: s.floats.map((f) => f.id === dragged ? { ...f, stays: true } : f) } : s, dragged));
3601
4006
  };
3602
4007
  const hand = heldRect(state, dragged, fitted ?? size, point, g);
3603
- const on = { x: clamp2(point.x, hand.x, hand.x + hand.width), y: clamp2(point.y, hand.y, hand.y + hand.height) };
4008
+ const on = { x: clamp3(point.x, hand.x, hand.x + hand.width), y: clamp3(point.y, hand.y, hand.y + hand.height) };
3604
4009
  const clear = !first.notes.some((n) => n.code === "float-covers" && n.id === dragged);
3605
4010
  if (!fitted || clear && contains(fitted, on)) return placed2(at.x, at.y, false);
3606
4011
  const left = placed2(hand.x, hand.y, true);
@@ -3611,7 +4016,7 @@ function generateShown(state, dragged, options, hidden) {
3611
4016
  });
3612
4017
  }
3613
4018
  (state.blocked ?? []).forEach((b, i) => {
3614
- targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect18(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
4019
+ targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect19(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
3615
4020
  });
3616
4021
  const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
3617
4022
  const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
@@ -3632,15 +4037,22 @@ function generateShown(state, dragged, options, hidden) {
3632
4037
  for (const t of [...alone.values()].flat()) if (t.kind !== "refuse" && t.id) zones.set(t.id, [...zones.get(t.id) ?? [], t.hit]);
3633
4038
  const bounds = stageOf(state);
3634
4039
  const held = withMinHit(c, layered.targets, layered.refusals, zones).map((t) => t.roomHit && t.slot ? { ...t, roomHit: hull(t.hit, t.slot) } : t);
3635
- return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones };
4040
+ const lostSet = new Set(lostIds);
4041
+ const places = live.flatMap(
4042
+ (spec) => spec.slots.filter((s) => lostSet.has(s.id) && s.ok && !s.home && s.place.kind === "gap" && !!s.result.layout.items[dragged]).map((s) => {
4043
+ const landed = s.result.layout.items[dragged].rect;
4044
+ return { id: s.id, priority: EDGE_KINDS[spec.kind].priority, hit: landed, slot: landed, marker: spec.marker(s), item: dragged, place: s.place, after: () => s.result };
4045
+ })
4046
+ ).filter((t, i, all) => all.findIndex((x) => x.id === t.id) === i);
4047
+ return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones, slides, ...places.length ? { places } : {} };
3636
4048
  }
3637
- var stageOf = (state) => rect18(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
4049
+ var stageOf = (state) => rect19(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
3638
4050
  function targets(state, dragged, options = {}) {
3639
4051
  return generate(state, dragged, options).targets;
3640
4052
  }
3641
4053
  function targetsAndRefusals(state, dragged, options = {}) {
3642
4054
  const g = generate(state, dragged, options);
3643
- return { targets: g.targets, refusals: g.refusals };
4055
+ return { targets: g.targets, refusals: g.refusals, places: g.places ?? [] };
3644
4056
  }
3645
4057
  function refusals(state, dragged, options = {}) {
3646
4058
  return generate(state, dragged, options).refusals;
@@ -3670,10 +4082,11 @@ function stopsKey(dragged, o) {
3670
4082
  prev = layoutIds.get(o.previous) ?? nextLayoutId++;
3671
4083
  layoutIds.set(o.previous, prev);
3672
4084
  }
3673
- return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);
4085
+ return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null, o.grab ? [o.grab.x, o.grab.y] : null, o.pitch ?? null]);
3674
4086
  }
3675
4087
  function orderedStops(state, dragged, options) {
3676
- const list = targets(state, dragged, options).filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
4088
+ const g = generate(state, dragged, options);
4089
+ const list = [...g.targets, ...g.places ?? []].filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
3677
4090
  const sideOf = (t) => {
3678
4091
  const p = t.place;
3679
4092
  if (p.kind === "float") return "float";
@@ -3689,43 +4102,27 @@ function orderedStops(state, dragged, options) {
3689
4102
  const rank = side === "float" ? 4 : SIDE_RANK[side];
3690
4103
  return side === "left" ? [rank, cx, cy] : side === "right" ? [rank, -cx, cy] : [rank, cy * (side === "bottom" ? -1 : 1), cx];
3691
4104
  };
3692
- 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);
4105
+ const ZONE_RANK2 = { start: 0, center: 1, end: 2 };
4106
+ const inEdge = (a, b) => {
4107
+ const p = a.place;
4108
+ const q = b.place;
4109
+ return p.kind === "gap" && q.kind === "gap" && p.edge === q.edge ? ZONE_RANK2[p.zone] - ZONE_RANK2[q.zone] || p.at - q.at : 0;
4110
+ };
4111
+ 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] || inEdge(a.t, b.t) || a.i - b.i).map((x) => x.t);
3693
4112
  }
3694
4113
 
3695
4114
  // src/lanes.ts
3696
- import { EPS as EPS21, area as area7, clamp as clamp3, rect as rect19, subtract as subtract6 } from "@n-uf/placement";
3697
- import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
3698
- var SPOT_PITCH = 40;
3699
- var SNAP_DISTANCE = 8;
4115
+ import { EPS as EPS23, area as area7, clamp as clamp4, rect as rect20, subtract as subtract6 } from "@n-uf/placement";
3700
4116
  var STEP = 1;
3701
- var mid = (r, axis) => axis === "x" ? r.x + r.width / 2 : r.y + r.height / 2;
3702
- var lo = (r, axis) => axis === "x" ? r.x : r.y;
3703
- var len = (r, axis) => axis === "x" ? r.width : r.height;
4117
+ var mid2 = (r, axis) => lo(r, axis) + len(r, axis) / 2;
3704
4118
  var hull2 = (a, b) => {
3705
4119
  const x = Math.min(a.x, b.x);
3706
4120
  const y = Math.min(a.y, b.y);
3707
- return rect19(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
4121
+ return rect20(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3708
4122
  };
3709
- var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
4123
+ var nonNeg2 = (v) => Number.isFinite(v) && v > 0 ? v : 0;
3710
4124
  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;
3711
4125
  var ORIGIN = { x: 0, y: 0 };
3712
- function onEdge(l, edge, dragged, axis) {
3713
- return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS21 && it.rect.height > EPS21).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
3714
- }
3715
- function neighbors(after, edge, dragged, axis) {
3716
- const me = after.items[dragged];
3717
- const others = onEdge(after, edge, dragged, axis);
3718
- const at = me ? mid(me.rect, axis) : 0;
3719
- return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
3720
- }
3721
- function givesWay(now, after, lane, side, extent) {
3722
- if (!now) return null;
3723
- if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
3724
- const [p0, p1] = extent(now.rect);
3725
- const [q0, q1] = extent(after.rect);
3726
- if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
3727
- return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
3728
- }
3729
4126
  function liftedLayout(state, dragged, options) {
3730
4127
  return solve(liftItem(state, dragged), options.previous ? { previous: options.previous } : {});
3731
4128
  }
@@ -3742,13 +4139,13 @@ function clipAtDrawn(band, axis, cuts) {
3742
4139
  const x = axis === "x" ? "y" : "x";
3743
4140
  const line = lo(band, x) + len(band, x) / 2;
3744
4141
  for (const c of cuts) {
3745
- if (!(lo(c, x) < line - EPS21 && line < lo(c, x) + len(c, x) - EPS21)) continue;
4142
+ if (!(lo(c, x) < line - EPS23 && line < lo(c, x) + len(c, x) - EPS23)) continue;
3746
4143
  const c0 = lo(c, axis);
3747
4144
  const c1 = c0 + len(c, axis);
3748
4145
  if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
3749
4146
  else b = Math.min(b, c0);
3750
4147
  }
3751
- return b - a > EPS21 ? along(band, axis, a, b) : band;
4148
+ return b - a > EPS23 ? along(band, axis, a, b) : band;
3752
4149
  }
3753
4150
  var memo = /* @__PURE__ */ new WeakMap();
3754
4151
  var previousIds = /* @__PURE__ */ new WeakMap();
@@ -3807,8 +4204,8 @@ function rawSpot(base, id) {
3807
4204
  }
3808
4205
  function build(state, dragged, options) {
3809
4206
  const seen = solve(state, options.previous ? { previous: options.previous } : {});
3810
- const { targets: ts, refusals: rs } = targetsAndRefusals(state, dragged, options);
3811
- const own = seen.items[dragged];
4207
+ const { targets: ts, refusals: rs, places } = targetsAndRefusals(state, dragged, options);
4208
+ const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
3812
4209
  const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
3813
4210
  const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
3814
4211
  const raws = [];
@@ -3817,7 +4214,7 @@ function build(state, dragged, options) {
3817
4214
  return e && axisOf(e.side) === "column" ? "y" : "x";
3818
4215
  };
3819
4216
  const columnKey = (side, ring) => state.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
3820
- for (const t of ts) {
4217
+ for (const t of [...ts, ...places]) {
3821
4218
  if (t.free) continue;
3822
4219
  const p = t.place;
3823
4220
  if (p.kind === "gap" || p.kind === "home" && ownEdge) {
@@ -3848,26 +4245,24 @@ function build(state, dragged, options) {
3848
4245
  raws.push(...takeoverSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH));
3849
4246
  const byLane = /* @__PURE__ */ new Map();
3850
4247
  for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
3851
- const halves = new Set(state.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
4248
+ const halves = new Set(state.edges.filter(cutsByHalves).map((e) => e.id));
3852
4249
  const marking = {
3853
4250
  pitch,
3854
4251
  natural: (id, axis) => {
3855
- const main = state.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
3856
- return main?.grows ? main.natural : void 0;
4252
+ const it = state.items[id];
4253
+ const main = it?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
4254
+ return it?.fixed && main?.grows ? main.natural : void 0;
3857
4255
  },
3858
- gap: (edge) => nonNeg(state.edges.find((e) => e.id === edge)?.gap),
3859
- crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) > EPS21 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over2.edges[e.id].rect)
4256
+ gap: (edge) => nonNeg2(state.edges.find((e) => e.id === edge)?.gap),
4257
+ crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) > EPS23 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over2.edges[e.id].rect)
3860
4258
  };
3861
- const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS21 ? 0.5 : clamp3(g / size, 0, 1);
3862
- const w = own?.rect.width ?? 0;
3863
- const h = own?.rect.height ?? 0;
3864
- const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
4259
+ const share = grabShare(own?.rect, options.grab);
3865
4260
  const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
3866
4261
  const laneList = newColumnsGiveWay(built.map((l) => settle(l, seen, state, dragged, built, options.emptyLanes)), (l) => l.id, state).map((l) => clearOfRail(l, seen, byLane.get(l.id)));
3867
4262
  const onLanes = new Set(laneList.map((l) => l.id));
3868
- const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS21 && r.rect.height > EPS21 ? [r.rect] : []);
4263
+ const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS23 && r.rect.height > EPS23 ? [r.rect] : []);
3869
4264
  const blocked = [
3870
- ...Object.values(seen.edges).filter((e) => e.cross > EPS21).map((e) => e.rect),
4265
+ ...Object.values(seen.edges).filter((e) => e.cross > EPS23).map((e) => e.rect),
3871
4266
  ...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
3872
4267
  ...keepClearFor(state, seen, "targets"),
3873
4268
  ...rails,
@@ -3914,7 +4309,7 @@ function laneRectOver(list, over2, marking) {
3914
4309
  if (!edgeLayout) return { rect: list.every((r) => r.strip) ? list.map((r) => r.hit).reduce(hull2) : list.map((r) => r.hit).reduce(hull2, band) };
3915
4310
  const drawnAt = drawnRect(over2, first.edge);
3916
4311
  if (drawnAt) return { rect: drawnAt };
3917
- const whole = axis === "x" ? rect19(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect19(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
4312
+ const whole = axis === "x" ? rect20(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect20(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3918
4313
  return { rect: clipAtDrawn(whole, axis, marking.crossing(first.edge, over2)), band: whole };
3919
4314
  }
3920
4315
  function drawnIn(layout, id) {
@@ -3923,7 +4318,7 @@ function drawnIn(layout, id) {
3923
4318
  function drawnRect(layout, id) {
3924
4319
  const e = layout.edges[id];
3925
4320
  if (!e) return void 0;
3926
- if (e.cross > EPS21) return e.rect;
4321
+ if (e.cross > EPS23) return e.rect;
3927
4322
  if (!e.folded) return void 0;
3928
4323
  const run = Object.values(layout.rails).flatMap((r) => r?.segments.filter((g) => g.edge === id).map((g) => g.rect) ?? []);
3929
4324
  return run.length > 0 ? run.reduce(hull2) : void 0;
@@ -3935,7 +4330,8 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
3935
4330
  const { rect: laneRect, band: markBand } = laneRectOver(list, seen, marking);
3936
4331
  const firstOf = (r) => r.slide?.first ?? r.landing;
3937
4332
  const lastOf = (r) => r.slide?.last ?? r.landing;
3938
- const sorted = [...list].sort((a, b) => mid(firstOf(a), axis) - mid(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0));
4333
+ const besideZone = (r) => r.target.place.kind === "gap" && r.target.place.zone === zoneIn2(seen, r.before) ? 0 : 1;
4334
+ const sorted = [...list].sort((a, b) => mid2(firstOf(a), axis) - mid2(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0) || besideZone(a) - besideZone(b));
3939
4335
  const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
3940
4336
  const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
3941
4337
  const unique = [];
@@ -3952,38 +4348,30 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
3952
4348
  const bandEnd = bandStart + len(whole, axis);
3953
4349
  const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
3954
4350
  const held = halves ? 0.5 : share[axis];
3955
- const cuts = [];
3956
- for (let i = 0; i + 1 < unique.length; i++) {
3957
- const a = unique[i];
3958
- const b = unique[i + 1];
4351
+ const cutOf = (a, b) => {
3959
4352
  const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
3960
- const aLanding = lastOf(a);
3961
- const bLanding = firstOf(b);
3962
- const aEnd = lo(aLanding, axis) + len(aLanding, axis);
3963
- const across2 = (aEnd + lo(bLanding, axis)) / 2;
3964
- const overlap = lo(bLanding, axis) < aEnd - EPS21;
3965
- const slack = Math.max(0, marking.pitch) / 2;
3966
- const atGrab = clamp3(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
3967
- const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
3968
- cuts.push(clamp3(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
3969
- }
4353
+ return aimCut(lastOf(a), firstOf(b), axis, held, aimSlack(marking.pitch), shared);
4354
+ };
4355
+ const cuts = crossFreeCuts(unique.length, (i, j) => cutOf(unique[i], unique[j]), (i) => halves || !!unique[i].home, bandStart, bandEnd);
3970
4356
  const spots = unique.flatMap((x, i) => {
3971
4357
  const a = i === 0 ? bandStart : cuts[i - 1];
3972
4358
  const b = i === unique.length - 1 ? bandEnd : cuts[i];
3973
- const along2 = [clamp3(a, start, end), clamp3(b, start, end)];
3974
- return along2[1] - along2[0] > EPS21 || b - a <= EPS21 || x.home ? [{ x, along: along2 }] : [];
4359
+ const along2 = [clamp4(a, start, end), clamp4(b, start, end)];
4360
+ return along2[1] - along2[0] > EPS23 || b - a <= EPS23 || x.home ? [{ x, along: along2 }] : [];
3975
4361
  }).map(({ x, along: along2 }) => ({
3976
4362
  id: x.id,
3977
4363
  along: along2,
3978
4364
  landing: x.landing,
3979
- target: x.target,
4365
+ // A sliding spot's target holds the pointer over its stretch only (its range of landings runs past the cuts either
4366
+ // side, over the neighbors' stretches).
4367
+ target: x.slide && along2[1] - along2[0] > EPS23 ? { ...x.target, hit: axis === "x" ? rect20(along2[0], x.target.hit.y, along2[1] - along2[0], x.target.hit.height) : rect20(x.target.hit.x, along2[0], x.target.hit.width, along2[1] - along2[0]) } : x.target,
3980
4368
  ...x.home ? { home: true } : {},
3981
4369
  ...x.pitched ? { pitched: true } : {},
3982
4370
  ...x.slide ? { slide: { from: x.slide.from, to: x.slide.to, snaps: x.slide.snaps, snapDistance: x.slide.snapDistance, step: x.slide.step } } : {},
3983
4371
  others: othersKey(x.layout, dragged)
3984
4372
  }));
3985
4373
  const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
3986
- const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp3(lo(h, axis), start, end), clamp3(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS21) : [];
4374
+ const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp4(lo(h, axis), start, end), clamp4(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS23) : [];
3987
4375
  const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
3988
4376
  const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
3989
4377
  const markRect = (first.edge ? drawnRect(drawn, first.edge) : void 0) ?? laneRectOver(list, drawn, marking).band ?? markBand ?? laneRect;
@@ -4008,7 +4396,7 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
4008
4396
  }) : virtualMarks(id, unique, drawn.items[dragged]);
4009
4397
  return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
4010
4398
  }
4011
- var along = (r, axis, a, b) => axis === "x" ? rect19(a, r.y, b - a, r.height) : rect19(r.x, a, r.width, b - a);
4399
+ var along = (r, axis, a, b) => axis === "x" ? rect20(a, r.y, b - a, r.height) : rect20(r.x, a, r.width, b - a);
4012
4400
  var LINE2 = 2;
4013
4401
  var MIN_BOX = 8;
4014
4402
  var HATCH_END = 8;
@@ -4016,8 +4404,8 @@ var HATCH_EDGE = 8;
4016
4404
  function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
4017
4405
  const { besideMin } = more;
4018
4406
  const hatches = (pair, a, b, p, q, gl, gr) => {
4019
- if (gl && Math.abs(p - a) < EPS21) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
4020
- if (gr && Math.abs(q - b) < EPS21) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
4407
+ if (gl && Math.abs(p - a) < EPS23) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
4408
+ if (gr && Math.abs(q - b) < EPS23) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
4021
4409
  };
4022
4410
  const heldAt = items.find((o) => o.id === held);
4023
4411
  const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
@@ -4027,10 +4415,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
4027
4415
  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 }];
4028
4416
  const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
4029
4417
  for (let i = 0; i + 1 < ends.length; i++) {
4030
- const a = clamp3(ends[i].b, start, end);
4031
- const b = clamp3(ends[i + 1].a, start, end);
4418
+ const a = clamp4(ends[i].b, start, end);
4419
+ const b = clamp4(ends[i + 1].a, start, end);
4032
4420
  const pair = `${ends[i].id}|${ends[i + 1].id}`;
4033
- if (ends[i + 1].a < start - EPS21 || ends[i].b > end + EPS21 || !lands(pair)) continue;
4421
+ if (ends[i + 1].a < start - EPS23 || ends[i].b > end + EPS23 || !lands(pair)) continue;
4034
4422
  const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
4035
4423
  const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
4036
4424
  const named = `${left}|${right}`;
@@ -4039,12 +4427,12 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
4039
4427
  const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
4040
4428
  const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
4041
4429
  const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
4042
- if (b - a < min - EPS21) {
4043
- if (spot && b - a >= besideMin - EPS21) {
4430
+ if (b - a < min - EPS23) {
4431
+ if (spot && b - a >= besideMin - EPS23) {
4044
4432
  let ps = [[a, b]];
4045
4433
  for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
4046
4434
  if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
4047
- ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS21);
4435
+ ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS23);
4048
4436
  ps.forEach(([p, q], k2) => {
4049
4437
  out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
4050
4438
  hatches(pair, a, b, p, q, gl, gr);
@@ -4056,10 +4444,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
4056
4444
  continue;
4057
4445
  }
4058
4446
  let pieces = [[a, b]];
4059
- 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 > EPS21);
4447
+ 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 > EPS23);
4060
4448
  let k = 0;
4061
4449
  for (const [p, q] of pieces) {
4062
- if (q - p < min - EPS21) continue;
4450
+ if (q - p < min - EPS23) continue;
4063
4451
  const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
4064
4452
  out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
4065
4453
  hatches(pair, a, b, p, q, gl, gr);
@@ -4071,8 +4459,8 @@ function virtualMarks(lane, spots, held) {
4071
4459
  return spots.map((s) => {
4072
4460
  const l = s.landing;
4073
4461
  if (!held || held.floating || !overlaps8(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
4074
- const x = mid(held.rect, "x") < mid(l, "x") ? l.x + l.width : l.x;
4075
- return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect19(x, l.y, 0, l.height) };
4462
+ const x = mid2(held.rect, "x") < mid2(l, "x") ? l.x + l.width : l.x;
4463
+ return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect20(x, l.y, 0, l.height) };
4076
4464
  });
4077
4465
  }
4078
4466
  function inLane(l, r) {
@@ -4081,9 +4469,9 @@ function inLane(l, r) {
4081
4469
  const y0 = Math.max(m.rect.y, r.y);
4082
4470
  const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
4083
4471
  const y1 = Math.min(m.rect.y + m.rect.height, r.y + r.height);
4084
- if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS21 && y1 - y0 >= m.rect.height - EPS21 ? [m] : [];
4085
- if (x1 - x0 <= EPS21 || y1 - y0 <= EPS21) return [];
4086
- return x1 - x0 >= m.rect.width - EPS21 && y1 - y0 >= m.rect.height - EPS21 ? [m] : [{ ...m, rect: rect19(x0, y0, x1 - x0, y1 - y0) }];
4472
+ if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS23 && y1 - y0 >= m.rect.height - EPS23 ? [m] : [];
4473
+ if (x1 - x0 <= EPS23 || y1 - y0 <= EPS23) return [];
4474
+ return x1 - x0 >= m.rect.width - EPS23 && y1 - y0 >= m.rect.height - EPS23 ? [m] : [{ ...m, rect: rect20(x0, y0, x1 - x0, y1 - y0) }];
4087
4475
  });
4088
4476
  return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
4089
4477
  }
@@ -4107,14 +4495,14 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
4107
4495
  const e = edge ? edgeOf(edge) : void 0;
4108
4496
  return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
4109
4497
  };
4110
- 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 > EPS21 && it.rect.height > EPS21).map(([, it]) => it.rect) : [];
4498
+ 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 > EPS23 && it.rect.height > EPS23).map(([, it]) => it.rect) : [];
4111
4499
  if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps8(m.rect, s)))))) return l;
4112
4500
  const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
4113
4501
  const marks = [];
4114
4502
  for (const m of l.marks) {
4115
4503
  const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
4116
4504
  if (m.kind === "line") {
4117
- if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS21) marks.push(m);
4505
+ if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS23) marks.push(m);
4118
4506
  continue;
4119
4507
  }
4120
4508
  kept.forEach(([p, q], i) => {
@@ -4127,11 +4515,11 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
4127
4515
  if (l.axis === "y") {
4128
4516
  const outerRight = side === "right" ? true : side === "left" ? false : Math.abs(piece.x + piece.width - (st.x + st.width)) <= Math.abs(piece.x - st.x);
4129
4517
  const t = Math.min(HATCH_EDGE, piece.width);
4130
- r = rect19(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
4518
+ r = rect20(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
4131
4519
  } else {
4132
4520
  const outerBottom = side === "bottom" ? true : side === "top" ? false : Math.abs(piece.y + piece.height - (st.y + st.height)) <= Math.abs(piece.y - st.y);
4133
4521
  const t = Math.min(HATCH_EDGE, piece.height);
4134
- r = rect19(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
4522
+ r = rect20(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
4135
4523
  }
4136
4524
  marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
4137
4525
  });
@@ -4140,12 +4528,12 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
4140
4528
  }
4141
4529
  function piecesLess(r, axis, cs) {
4142
4530
  const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
4143
- const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS21 && r.y < c.y + c.height - EPS21 : c.x < r.x + r.width - EPS21 && r.x < c.x + c.width - EPS21;
4531
+ const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS23 && r.y < c.y + c.height - EPS23 : c.x < r.x + r.width - EPS23 && r.x < c.x + c.width - EPS23;
4144
4532
  let ps = [span(r)];
4145
4533
  for (const c of cs) {
4146
4534
  if (!crosses(c)) continue;
4147
4535
  const [c0, c1] = span(c);
4148
- ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS21);
4536
+ ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS23);
4149
4537
  }
4150
4538
  return ps;
4151
4539
  }
@@ -4156,18 +4544,18 @@ function marksLess(marks, axis, cs, options = {}) {
4156
4544
  const over2 = cs.filter((c) => overlaps8(m.rect, c));
4157
4545
  if (over2.length === 0) return [m];
4158
4546
  const kept = piecesLess(m.rect, axis, over2);
4159
- if (m.kind === "line") return (options.lines === "covered" ? kept.length > 0 : kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS21) ? [m] : [];
4547
+ if (m.kind === "line") return (options.lines === "covered" ? kept.length > 0 : kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS23) ? [m] : [];
4160
4548
  return kept.filter(([p, q]) => m.kind !== "box" || q - p > minBox).map(([p, q], i) => ({ ...m, id: i ? `${m.id}${suffix}${i}` : m.id, rect: along(m.rect, axis, p, q) }));
4161
4549
  });
4162
4550
  }
4163
- var overlaps8 = (a, b) => a.x < b.x + b.width - EPS21 && b.x < a.x + a.width - EPS21 && a.y < b.y + b.height - EPS21 && b.y < a.y + a.height - EPS21;
4551
+ var overlaps8 = (a, b) => a.x < b.x + b.width - EPS23 && b.x < a.x + a.width - EPS23 && a.y < b.y + b.height - EPS23 && b.y < a.y + a.height - EPS23;
4164
4552
  function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
4165
4553
  const out = [];
4166
4554
  stretches(state, dragged, options, seen, lifted, raws, (run) => {
4167
4555
  const { e, axis, gap, middle } = run;
4168
4556
  const taken = run.mine.map((r) => r.landing);
4169
4557
  const emit3 = (zone, at, space, x0, flush) => {
4170
- const hit = landsAt(state, dragged, run, { edge: e.id, zone, at, space }, x0);
4558
+ const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
4171
4559
  if (!hit) return false;
4172
4560
  const { next, layout } = hit;
4173
4561
  const landed = layout.items[dragged];
@@ -4185,12 +4573,12 @@ function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
4185
4573
  };
4186
4574
  return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
4187
4575
  const end = (x0, order, flush) => {
4188
- for (const zone of order) if (spaceAt(zone, x0) >= -EPS21 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
4576
+ for (const zone of order) if (spaceAt(zone, x0) >= -EPS23 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
4189
4577
  };
4190
4578
  end(a, zones, before?.id ?? "^");
4191
- if (b - w > a + EPS21) end(b - w, [...zones].reverse(), after?.id ?? "$");
4579
+ if (b - w > a + EPS23) end(b - w, [...zones].reverse(), after?.id ?? "$");
4192
4580
  if (b - a < w + pitch) return;
4193
- for (let x0 = a + pitch; x0 + w <= b - pitch + EPS21; x0 += pitch) {
4581
+ for (let x0 = a + pitch; x0 + w <= b - pitch + EPS23; x0 += pitch) {
4194
4582
  const zone = x0 + w / 2 < middle ? "start" : "end";
4195
4583
  if (!zones.includes(zone)) continue;
4196
4584
  emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
@@ -4210,54 +4598,15 @@ function stretches(state, dragged, options, seen, lifted, raws, visit) {
4210
4598
  const mine = raws.filter((r) => r.edge === e.id);
4211
4599
  const drawn = base.edges[e.id] ?? seen.edges[e.id];
4212
4600
  if (mine.length === 0 || !drawn) continue;
4213
- const gap = nonNeg(e.gap);
4214
4601
  const others = onEdge(base, e.id, dragged, axis);
4215
- const zoneOf2 = (o) => o.zone ?? "start";
4602
+ const run = { state, dragged, e, axis, base, drawn: drawn.rect, gap: nonNeg2(e.gap), middle: mid2(drawn.rect, axis), mine, fixed: others.filter((o) => state.items[o.id]?.fixed), prev };
4603
+ const each = visit(run);
4216
4604
  const w = len(mine[0].landing, axis);
4217
- const each = visit({ e, axis, w, gap, middle: mid(drawn.rect, axis), mine, fixed: others.filter((o) => state.items[o.id]?.fixed), prev });
4218
- const slack = (o) => {
4219
- const main = o ? state.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
4220
- return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
4221
- };
4222
- const ends = (l, before, after) => {
4223
- const at = (o) => {
4224
- const it = l.items[o.id];
4225
- return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
4226
- };
4227
- const rb = before ? at(before) : void 0;
4228
- const ra = after ? at(after) : void 0;
4229
- if (rb === null || ra === null) return null;
4230
- const el = l.edges[e.id]?.rect ?? drawn.rect;
4231
- return {
4232
- a: before && rb ? lo(rb, axis) + len(rb, axis) - slack({ ...before, r: rb }) + gap : lo(el, axis) + nonNeg(e.pad?.start),
4233
- // (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
4234
- b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
4235
- };
4236
- };
4237
4605
  for (let i = 0; i <= others.length; i++) {
4238
4606
  const before = others[i - 1];
4239
4607
  const after = others[i];
4240
- const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
4241
- const atOf = (zone) => others.slice(0, i).filter((o) => zoneOf2(o) === zone).length;
4242
- const probe = (() => {
4243
- const zone = zones[0];
4244
- if (!zone) return null;
4245
- const next = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
4246
- if (next === state) return null;
4247
- const l = solve(next, prev);
4248
- const landed = l.items[dragged];
4249
- if (!landed || landed.inMenu || landed.edge !== e.id) return null;
4250
- const n = neighbors(l, e.id, dragged, axis);
4251
- if (n.before !== (before?.id ?? "^") || n.next !== (after?.id ?? "$")) return null;
4252
- const r = ends(l, before, after);
4253
- return r && { ...r, w: len(landed.rect, axis), layout: l };
4254
- })();
4255
- const seenEnds = ends(base, before, after);
4256
- 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";
4257
- const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : seenEnds.a;
4258
- const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : seenEnds.b;
4259
- const wi = probe?.w ?? w;
4260
- each({ before, after, a, b, w: wi, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + wi) });
4608
+ const room = slideRoom(run, before?.id, after?.id, others.slice(0, i).map((o) => o.id), w);
4609
+ if (room) each({ ...room, before, after, room });
4261
4610
  }
4262
4611
  }
4263
4612
  }
@@ -4267,7 +4616,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
4267
4616
  const { e, axis } = run;
4268
4617
  const taken = [...run.mine.map((r) => r.landing)];
4269
4618
  const emit3 = (zone, at, space, x0, nb) => {
4270
- const hit = landsAt(state, dragged, run, { edge: e.id, zone, at, space }, x0);
4619
+ const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
4271
4620
  if (!hit) return;
4272
4621
  const { next, layout } = hit;
4273
4622
  const landed = layout.items[dragged];
@@ -4279,7 +4628,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
4279
4628
  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 });
4280
4629
  };
4281
4630
  return ({ w, zones, atOf, spaceAt, before, after }) => {
4282
- const zoneOf2 = (id) => state.items[id]?.align ?? "start";
4631
+ const zoneOf2 = (id) => zoneIn2(run.base, id);
4283
4632
  if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !state.items[after.id]?.fixed) {
4284
4633
  const x0 = lo(after.r, axis);
4285
4634
  emit3("start", atOf("start"), Math.max(0, spaceAt("start", x0)), x0, after.id);
@@ -4292,50 +4641,19 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
4292
4641
  });
4293
4642
  return out;
4294
4643
  }
4295
- function landsAt(state, dragged, run, place, x0) {
4296
- const next = moveTo(state, dragged, place);
4297
- if (next === state) return null;
4298
- const layout = solve(next, run.prev);
4299
- const landed = layout.items[dragged];
4300
- const { axis } = run;
4301
- if (!landed || landed.inMenu || landed.edge !== run.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
4302
- const kept = (f) => {
4303
- const it = layout.items[f.id];
4304
- if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
4305
- return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
4306
- };
4307
- if (!run.fixed.every(kept)) return null;
4308
- return { next, layout };
4309
- }
4310
4644
  function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4311
4645
  const spots = [];
4312
4646
  const absorbed = /* @__PURE__ */ new Set();
4313
4647
  const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
4314
- const own = seen.items[dragged];
4648
+ const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
4315
4649
  const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
4316
- stretches(state, dragged, options, seen, lifted, raws, (run) => ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
4317
- const { e, axis, middle, mine } = run;
4650
+ stretches(state, dragged, options, seen, lifted, raws, (run) => ({ w, zones, atOf, spaceAt, before, after, room }) => {
4651
+ const { e, axis, mine } = run;
4318
4652
  if (zones.length === 0) return;
4319
4653
  {
4320
- const land = (x0) => {
4321
- const near = x0 + w / 2 < middle ? "start" : "end";
4322
- for (const zone2 of [near, near === "start" ? "end" : "start"]) {
4323
- if (!zones.includes(zone2)) continue;
4324
- const space = spaceAt(zone2, x0);
4325
- if (space < -EPS21) continue;
4326
- const place = { edge: e.id, zone: zone2, at: atOf(zone2), space: Math.max(0, space) };
4327
- const hit = landsAt(state, dragged, run, place, x0);
4328
- if (hit) return { place, result: { state: hit.next, layout: hit.layout } };
4329
- }
4330
- return null;
4331
- };
4332
- const tries = [a];
4333
- for (let x0 = a + sample; x0 < b - w - EPS21; x0 += sample) tries.push(x0);
4334
- if (b - w > a + EPS21) tries.push(b - w);
4335
- const ok = tries.map((x0) => ({ x0, hit: land(x0) })).filter((t) => t.hit);
4336
- if (ok.length === 0) return;
4337
- const from = ok[0].x0;
4338
- const to = ok.at(-1).x0;
4654
+ const range = slideRange(run, room, sample);
4655
+ if (!range) return;
4656
+ const { from, to, land } = range;
4339
4657
  const bId = before?.id ?? "^";
4340
4658
  const nId = after?.id ?? "$";
4341
4659
  if (to - from < STEP) {
@@ -4343,14 +4661,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4343
4661
  const firstZone = (() => {
4344
4662
  for (const zone3 of zones) {
4345
4663
  const space = spaceAt(zone3, from);
4346
- if (space < -EPS21) continue;
4664
+ if (space < -EPS23) continue;
4347
4665
  const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
4348
- const hit = landsAt(state, dragged, run, place2, from);
4666
+ const hit = landsAt(run, place2, from);
4349
4667
  if (hit) return { place: place2, result: { state: hit.next, layout: hit.layout } };
4350
4668
  }
4351
4669
  return null;
4352
4670
  })();
4353
- const { place, result } = firstZone ?? ok[0].hit;
4671
+ const { place, result } = firstZone ?? range.start;
4354
4672
  const landed = result.layout.items[dragged].rect;
4355
4673
  const n = neighbors(result.layout, e.id, dragged, axis);
4356
4674
  const zone2 = place.zone;
@@ -4372,13 +4690,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4372
4690
  };
4373
4691
  put(from);
4374
4692
  put(to);
4375
- for (const r of [...inside].sort((p, q) => p.home ? -1 : q.home ? 1 : 0)) put(lo(r.landing, axis), r);
4693
+ const beforeZone = zoneIn2(run.base, before?.id);
4694
+ const rank = (r) => r.home ? 0 : r.target.place.kind === "gap" && r.target.place.zone === beforeZone ? 1 : 2;
4695
+ for (const r of [...inside].sort((p, q) => rank(p) - rank(q))) put(lo(r.landing, axis), r);
4376
4696
  const homeAt = homeRaw ? lo(homeRaw.landing, axis) : void 0;
4377
4697
  const kept = points.filter((p) => homeAt === void 0 || Math.abs(p.at - homeAt) < 1e-6 || Math.abs(p.at - homeAt) > 2 * snapDistance).sort((p, q) => p.at - q.at);
4378
4698
  const snaps = kept.map((p) => p.at);
4379
4699
  const dockAt = (x0) => kept.find((p) => Math.abs(p.at - x0) < 1e-6)?.raw;
4380
- const shape = ok[0].hit.result.layout.items[dragged].rect;
4381
- const at = (x0) => along(shape, axis, x0, x0 + w);
4700
+ const { at } = range;
4382
4701
  const snapped = (x0) => {
4383
4702
  let best = x0;
4384
4703
  let d = Infinity;
@@ -4386,9 +4705,9 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4386
4705
  return best;
4387
4706
  };
4388
4707
  const startAt = (raw) => {
4389
- const c = clamp3(raw, from, to);
4708
+ const c = clamp4(raw, from, to);
4390
4709
  const s = snapped(c);
4391
- return snaps.includes(s) ? s : clamp3(Math.round(c / STEP) * STEP, from, to);
4710
+ return snaps.includes(s) ? s : clamp4(Math.round(c / STEP) * STEP, from, to);
4392
4711
  };
4393
4712
  const results = /* @__PURE__ */ new Map();
4394
4713
  const commitAt = (x0) => {
@@ -4396,11 +4715,11 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4396
4715
  const k = `${r ? "dock " : ""}${Math.round(x0 * 1e3) / 1e3}`;
4397
4716
  const known = results.get(k);
4398
4717
  if (known) return known;
4399
- const result = r ? r.target.after(ORIGIN, ORIGIN) : land(x0)?.result ?? ok.reduce((p, q) => Math.abs(q.x0 - x0) < Math.abs(p.x0 - x0) ? q : p).hit.result;
4718
+ const result = r ? r.target.after(ORIGIN, ORIGIN) : (land(x0) ?? range.nearest(x0)).result;
4400
4719
  results.set(k, result);
4401
4720
  return result;
4402
4721
  };
4403
- const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp3(lo(own.rect, axis), from, to)) : from;
4722
+ const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp4(lo(own.rect, axis), from, to)) : from;
4404
4723
  const restResult = commitAt(rest);
4405
4724
  const ownZone = own?.zone;
4406
4725
  const restPlace = (() => {
@@ -4420,7 +4739,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4420
4739
  place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
4421
4740
  after: (point, grab) => {
4422
4741
  const g = grab ? grab[long] : ownLen / 2;
4423
- const share = axis === long && ownLen > EPS21 && Number.isFinite(g) ? clamp3(g / ownLen, 0, 1) : 0.5;
4742
+ const share = axis === long && ownLen > EPS23 && Number.isFinite(g) ? clamp4(g / ownLen, 0, 1) : 0.5;
4424
4743
  return commitAt(startAt((axis === "x" ? point.x : point.y) - share * w));
4425
4744
  }
4426
4745
  };
@@ -4437,6 +4756,8 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4437
4756
  target,
4438
4757
  hit: target.hit,
4439
4758
  ...homeRaw ? { home: true } : {},
4759
+ // Its stretch of the lane is cut from its range's end landings, where its drop lands at the hand: a range that runs
4760
+ // into a growing neighbor's slack (the room the drop makes; the neighbor gives way) cuts from there too.
4440
4761
  slide: { from, to, snaps, snapDistance, step: STEP, first: at(from), last: at(to) }
4441
4762
  });
4442
4763
  }
@@ -4445,20 +4766,20 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4445
4766
  }
4446
4767
 
4447
4768
  // src/drag.ts
4448
- import { EPS as EPS22, area as area8, overlaps as overlaps9, subtract as subtract7 } from "@n-uf/placement";
4769
+ import { EPS as EPS24, area as area8, overlaps as overlaps9, subtract as subtract7 } from "@n-uf/placement";
4449
4770
  var MIN_PIECE = 8;
4450
4771
  function trimmedBy(marks, cs) {
4451
4772
  if (cs.length === 0) return [...marks];
4452
4773
  return marks.flatMap((m) => {
4453
4774
  const r = m.rect;
4454
- if (r.width <= EPS22 || r.height <= EPS22) {
4455
- const across2 = r.height <= EPS22;
4775
+ if (r.width <= EPS24 || r.height <= EPS24) {
4776
+ const across2 = r.height <= EPS24;
4456
4777
  const at = across2 ? r.y : r.x;
4457
4778
  let pieces2 = [across2 ? [r.x, r.x + r.width] : [r.y, r.y + r.height]];
4458
4779
  let touched = false;
4459
4780
  for (const c of cs) {
4460
4781
  const [lo2, hi] = across2 ? [c.y, c.y + c.height] : [c.x, c.x + c.width];
4461
- if (!(at > lo2 + EPS22 && at < hi - EPS22)) continue;
4782
+ if (!(at > lo2 + EPS24 && at < hi - EPS24)) continue;
4462
4783
  const [a, b] = across2 ? [c.x, c.x + c.width] : [c.y, c.y + c.height];
4463
4784
  pieces2 = pieces2.flatMap(([s2, e2]) => {
4464
4785
  if (b <= s2 || a >= e2) return [[s2, e2]];
@@ -4470,7 +4791,7 @@ function trimmedBy(marks, cs) {
4470
4791
  const kept = pieces2.filter(([s2, e2]) => e2 - s2 >= 1);
4471
4792
  if (kept.length === 0) return [];
4472
4793
  const [s, e] = kept.reduce((x, y) => y[1] - y[0] > x[1] - x[0] ? y : x);
4473
- if (Math.abs(s - (across2 ? r.x : r.y)) < EPS22 && Math.abs(e - s - (across2 ? r.width : r.height)) < EPS22) return [m];
4794
+ if (Math.abs(s - (across2 ? r.x : r.y)) < EPS24 && Math.abs(e - s - (across2 ? r.width : r.height)) < EPS24) return [m];
4474
4795
  return [{ ...m, rect: across2 ? { x: s, y: r.y, width: e - s, height: r.height } : { x: r.x, y: s, width: r.width, height: e - s } }];
4475
4796
  }
4476
4797
  const over2 = cs.filter((c) => overlaps9(m.rect, c));
@@ -4564,7 +4885,7 @@ function dockDrag(state, dragged, options = {}) {
4564
4885
  shown.push(near);
4565
4886
  }
4566
4887
  const drawnStays = [
4567
- ...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) > EPS22).map((e) => screen.layout.edges[e.id].rect),
4888
+ ...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) > EPS24).map((e) => screen.layout.edges[e.id].rect),
4568
4889
  ...Object.values(screen.layout.rails).flatMap((r) => r?.segments.filter((g) => g.id !== dragged).map((g) => g.rect) ?? [])
4569
4890
  ];
4570
4891
  const onScreen = [...shown.filter((s) => !s.created && s !== near).flatMap((s) => s.marks.map((m) => m.rect)), ...drawnStays, ...screen.landing ? [screen.landing] : []];
@@ -4640,15 +4961,15 @@ export {
4640
4961
  dockHome,
4641
4962
  storeDockState,
4642
4963
  readDockState,
4964
+ SPOT_PITCH,
4643
4965
  reservedRect,
4644
4966
  targets,
4645
4967
  refusals,
4646
4968
  refusalTargets,
4647
4969
  stops,
4648
- SPOT_PITCH,
4649
4970
  lanes,
4650
4971
  HATCH_END,
4651
4972
  HATCH_EDGE,
4652
4973
  dockDrag
4653
4974
  };
4654
- //# sourceMappingURL=chunk-JBKUC72Z.js.map
4975
+ //# sourceMappingURL=chunk-Y3RK6BQT.js.map