@n-uf/docking 26.11.54 → 26.11.56

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.
@@ -429,7 +429,7 @@ import { cutEdges } from "@n-uf/placement/stack";
429
429
 
430
430
  // src/solve/draft.ts
431
431
  import { EPS as EPS2, rect } from "@n-uf/placement";
432
- import { formMain, wrapLines } from "@n-uf/placement/stack";
432
+ import { formMain, itemSteps, wrapLines } from "@n-uf/placement/stack";
433
433
  function createDraft(given, options, caps = /* @__PURE__ */ new Map()) {
434
434
  const previous = options.previous;
435
435
  const opened = /* @__PURE__ */ new Set();
@@ -483,7 +483,7 @@ function zoneStarts(state, fit, input) {
483
483
  const at = (r) => column ? r.y : r.x;
484
484
  const out = /* @__PURE__ */ new Map();
485
485
  const lengths = /* @__PURE__ */ new Map();
486
- const drawn = fit.items.filter((p) => p.kind !== "menu");
486
+ const drawn = fit.items.filter((p) => !fit.menu?.items.includes(p.id));
487
487
  for (const p of drawn) {
488
488
  out.set(p.id, at(p.rect));
489
489
  lengths.set(p.id, column ? p.rect.height : p.rect.width);
@@ -500,7 +500,7 @@ function zoneStarts(state, fit, input) {
500
500
  const title = column ? void 0 : s.find((p) => {
501
501
  const it = state.items[p.id];
502
502
  const f = formsOf(it, "row")[p.form];
503
- return it.fixed && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS2;
503
+ return !itemSteps(it) && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS2;
504
504
  });
505
505
  if (title) lengths.set(title.id, formMain(formsOf(state.items[title.id], "row")[title.form], "natural", fit.cross));
506
506
  const used = drawn.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, drawn.length - 1) * gap;
@@ -557,15 +557,15 @@ function emit(d, edge, r, solved, extra = {}) {
557
557
  for (const id of solved.leftOutIcons ?? []) notes.push({ code: "no-icons-form", edge: edge.id, id });
558
558
  for (const p of stack.items) {
559
559
  const it = state.items[p.id];
560
- const inMenu = p.kind === "menu";
561
- const drawnRect = toStage(p.rect, inMenu ? void 0 : p.id);
560
+ const inMenu = !!stack.menu?.items.includes(p.id);
561
+ const drawnRect2 = toStage(p.rect, inMenu ? void 0 : p.id);
562
562
  const f = formsOf(it, column ? "column" : "row")[p.form];
563
- const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? "column" : "row", stack.cross);
563
+ const shape = inMenu ? {} : shapeOf(f, drawnRect2, column ? "column" : "row", stack.cross);
564
564
  const foldedBy = foldedByOf(it, formsOf(it, column ? "column" : "row"), p.form, solved.starts.get(p.id), edge);
565
565
  items[p.id] = {
566
566
  ...shape,
567
567
  ...controlsOf(inMenu ? void 0 : f),
568
- rect: drawnRect,
568
+ rect: drawnRect2,
569
569
  kind: it.kind,
570
570
  axis: column ? "column" : "row",
571
571
  form: p.form,
@@ -598,7 +598,7 @@ function emit(d, edge, r, solved, extra = {}) {
598
598
 
599
599
  // src/solve/edge.ts
600
600
  import { EPS as EPS3 } from "@n-uf/placement";
601
- import { fitStack, formCompact, formCrossMin as formCrossMin2, formSetsCross as formSetsCross2 } from "@n-uf/placement/stack";
601
+ import { fitStack, formCompact, formCrossMin as formCrossMin2, formMenu, formSetsCross as formSetsCross2, itemSteps as itemSteps2 } from "@n-uf/placement/stack";
602
602
  var stackItemOf = (item, forms, edge, from) => ({
603
603
  id: item.id,
604
604
  forms,
@@ -606,10 +606,14 @@ var stackItemOf = (item, forms, edge, from) => ({
606
606
  ...item.kept ? { kept: true } : {},
607
607
  // Where its ladder starts: as asked, else its hand fold resolved on this axis (`startOf`: its folded form).
608
608
  ...from !== void 0 ? { from } : startOf(item, forms, edge) > 0 ? { from: startOf(item, forms, edge) } : {},
609
- ...item.fixed ? { fixed: true } : {}
609
+ ...item.fixed ? { fixed: true } : {},
610
+ ...item.fixed && item.stepping ? { stepping: true } : {},
611
+ ...item.lengths ? { lengths: item.lengths } : {}
610
612
  });
613
+ var inputs = /* @__PURE__ */ new WeakMap();
614
+ var inputOf = (stack) => inputs.get(stack);
611
615
  function hasSetter(fit, forms) {
612
- return fit.items.some((p) => p.kind !== "menu" && formSetsCross2(forms(p.id)[p.form]));
616
+ return fit.items.some((p) => !formMenu(forms(p.id)[p.form]) && formSetsCross2(forms(p.id)[p.form]));
613
617
  }
614
618
  var TRAY_RANK = 100;
615
619
  var startsOf = (input) => new Map(input.items.map((i) => [i.id, i.from ?? 0]));
@@ -629,7 +633,7 @@ function compactEdge(f) {
629
633
  function railEdge(f, free, asStackItem, starts) {
630
634
  const { state, edge, formsById } = f;
631
635
  const railIndex = (item, forms) => {
632
- if (item.fixed) return -1;
636
+ if (!itemSteps2(item)) return -1;
633
637
  for (let j = startOf(item, forms, edge); j < forms.length; j++) if (forms[j].kind === "rail") return j;
634
638
  return -1;
635
639
  };
@@ -659,6 +663,11 @@ function railEdge(f, free, asStackItem, starts) {
659
663
  return { stack, free, tabs, closedTabs, input: railInput, starts, leftOut };
660
664
  }
661
665
  function solveEdge(state, edge, ids, length, room, previous) {
666
+ const solved = solveEdgeStack(state, edge, ids, length, room, previous);
667
+ inputs.set(solved.stack, solved.input);
668
+ return solved;
669
+ }
670
+ function solveEdgeStack(state, edge, ids, length, room, previous) {
662
671
  const axis = axisOf(edge.side);
663
672
  const column = axis === "column";
664
673
  const ordered = zoneSorted(state, ids);
@@ -709,8 +718,8 @@ function solveEdge(state, edge, ids, length, room, previous) {
709
718
  let moved = false;
710
719
  const items = input.items.map((it) => {
711
720
  const from = it.from ?? 0;
712
- if (it.fixed || fits(it.forms[from])) return it;
713
- const j = it.forms.findIndex((f, k) => k > from && f.kind !== "menu" && fits(f));
721
+ if (!itemSteps2(it) || fits(it.forms[from])) return it;
722
+ const j = it.forms.findIndex((f, k) => k > from && !formMenu(f) && fits(f));
714
723
  if (j < 0) return it;
715
724
  moved = true;
716
725
  return { ...it, from: j };
@@ -722,7 +731,7 @@ function solveEdge(state, edge, ids, length, room, previous) {
722
731
  }
723
732
  const size = edge.size;
724
733
  if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
725
- const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross2(formsById(p.id)[p.form]));
734
+ const setters = free.items.filter((p) => !formMenu(formsById(p.id)[p.form]) && formSetsCross2(formsById(p.id)[p.form]));
726
735
  const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin2(formsById(p.id)[p.form])));
727
736
  const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
728
737
  if (Math.abs(s - free.cross) > EPS3) {
@@ -735,20 +744,20 @@ function solveEdge(state, edge, ids, length, room, previous) {
735
744
  }
736
745
 
737
746
  // src/solve/bars.ts
738
- function cutEdge(d, edge, area7, cut2) {
747
+ function cutEdge(d, edge, area8, cut2) {
739
748
  const column = axisOf(edge.side) === "column";
740
- const length = column ? area7.height : area7.width;
741
- const room = Math.max(0, column ? area7.width : area7.height);
749
+ const length = column ? area8.height : area8.width;
750
+ const room = Math.max(0, column ? area8.width : area8.height);
742
751
  const cap = d.caps.get(edge.id);
743
752
  const solvedAs = cap === void 0 ? edge : { ...edge, cross: { ...edge.cross, max: Math.min(edge.cross.max, cap) } };
744
753
  const solved = solveEdge(d.state, solvedAs, d.owned.get(edge), length, room, d.prevEdge(edge));
745
- const band = cutEdges(area7, [{ id: edge.id, side: edge.side, size: solved.stack.items.length === 0 ? 0 : solved.stack.cross }]);
754
+ const band = cutEdges(area8, [{ id: edge.id, side: edge.side, size: solved.stack.items.length === 0 ? 0 : solved.stack.cross }]);
746
755
  emit(d, edge, band.bands[edge.id], solved);
747
- return cut2 ? band.rest : area7;
756
+ return cut2 ? band.rest : area8;
748
757
  }
749
758
 
750
759
  // src/solve/floats.ts
751
- import { EPS as EPS4, rect as rect2 } from "@n-uf/placement";
760
+ import { EPS as EPS4, clampInto as clampInto2, overlaps, rect as rect2 } from "@n-uf/placement";
752
761
  import { fitFloat, formFolded as formFolded2 } from "@n-uf/placement/stack";
753
762
  var sinceOf = (f) => isSince(f.since) ? f.since : 0;
754
763
  function anchored(content, w, h, given) {
@@ -805,7 +814,26 @@ function fitBeside(want, region, avoid, earlier) {
805
814
  const both = fitFloat(want, region, [...avoid, ...earlier]);
806
815
  return both.covers.length === 0 ? both : fitFloat(want, region, avoid);
807
816
  }
808
- function placeFloat(item, f, region, avoid, content, stage, earlier = []) {
817
+ function clearOfWalls(r, region, walls) {
818
+ const under = (c) => walls.filter((w) => overlaps(c, w, 1e-3));
819
+ if (under(r).length === 0) return r;
820
+ const pushes2 = (c) => under(c).flatMap(
821
+ (w) => [rect2(w.x - c.width, c.y, c.width, c.height), rect2(w.x + w.width, c.y, c.width, c.height), rect2(c.x, w.y - c.height, c.width, c.height), rect2(c.x, w.y + w.height, c.width, c.height)].map((m) => clampInto2(m, region))
822
+ );
823
+ const far = (c) => Math.abs(c.x - r.x) + Math.abs(c.y - r.y);
824
+ let best = null;
825
+ for (const a of pushes2(r))
826
+ for (const c of under(a).length === 0 ? [a] : pushes2(a)) if (under(c).length === 0 && (!best || far(c) < far(best) - 1e-9)) best = c;
827
+ return best;
828
+ }
829
+ function fitStays(want, region, avoid, docked) {
830
+ const walls = avoid.slice(docked).filter((w) => w.width > 0 && w.height > 0);
831
+ const inside = clampInto2(want, region);
832
+ const kept = clearOfWalls(inside, region, walls) ?? fitFloat(want, region, walls).rect;
833
+ const over2 = fitFloat(kept, region, avoid, { stay: true });
834
+ return { rect: kept, clamped: kept.x !== want.x || kept.y !== want.y, snapped: false, covers: over2.covers, searchCapped: false };
835
+ }
836
+ function placeFloat(item, f, region, avoid, content, stage, earlier = [], docked = 0) {
809
837
  const shape = floatShape(item, f);
810
838
  const from = shape.form;
811
839
  const fo = f.orient ?? floatOrientOf(item);
@@ -817,7 +845,7 @@ function placeFloat(item, f, region, avoid, content, stage, earlier = []) {
817
845
  const folded = !!form && formFolded2(form);
818
846
  const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, clear.height, cap.height));
819
847
  const want = f.anchor ? anchored(content, w, h, f.anchor) : rect2(finite(f.rect.x, stage.x), finite(f.rect.y, stage.y), w, h);
820
- const fit0 = f.anchor ? fitBeside(want, region, avoid, earlier) : fitFloat(want, region, avoid);
848
+ const fit0 = f.anchor ? fitBeside(want, region, avoid, earlier) : f.stays ? fitStays(want, region, avoid, docked) : fitFloat(want, region, avoid);
821
849
  const fit = w > region.width + EPS4 ? { ...fit0, rect: rect2(region.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
822
850
  return { from, fo, form, fit };
823
851
  }
@@ -825,6 +853,7 @@ function layFloats(d, stage, content, inset) {
825
853
  const { state, notes, items, edges } = d;
826
854
  const avoid = [];
827
855
  for (const l of Object.values(items)) avoid.push(l.rect);
856
+ const docked = avoid.length;
828
857
  for (const e of Object.values(edges)) {
829
858
  if (axisOf(e.side) === "row" && e.cross > 0) avoid.push(e.rect);
830
859
  if (e.menu) avoid.push(e.menu.rect);
@@ -842,13 +871,16 @@ function layFloats(d, stage, content, inset) {
842
871
  }
843
872
  const placed = /* @__PURE__ */ new Map();
844
873
  const place = (f, earlier = []) => {
845
- placed.set(f.id, placeFloat(state.items[f.id], f, floatRegion2, avoid, content, stage, earlier));
874
+ placed.set(f.id, placeFloat(state.items[f.id], f, floatRegion2, avoid, content, stage, earlier, docked));
846
875
  };
847
876
  const live = drawn.filter((f) => !noForm.has(f.id));
848
- for (const f of live) if (!f.anchor) place(f);
849
- const own = [...placed.values()].map((p) => p.fit.rect);
877
+ const own = live.filter((f) => !f.anchor);
878
+ for (const f of own) place(f);
850
879
  const anchored2 = live.filter((f) => f.anchor).sort((a, b) => sinceOf(a) - sinceOf(b) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
851
- anchored2.forEach((f, i) => place(f, [...own, ...anchored2.slice(0, i).map((a) => placed.get(a.id).fit.rect)]));
880
+ anchored2.forEach((f, i) => {
881
+ const before = own.filter((o) => sinceOf(o) < sinceOf(f)).map((o) => placed.get(o.id).fit.rect);
882
+ place(f, [...before, ...anchored2.slice(0, i).map((a) => placed.get(a.id).fit.rect)]);
883
+ });
852
884
  const floats = [];
853
885
  for (const f of drawn) {
854
886
  if (noForm.has(f.id)) {
@@ -876,9 +908,9 @@ function insetOf(d) {
876
908
  return { inset, docked };
877
909
  }
878
910
  var insideInset = (outer, inset) => rect3(outer.x + px(inset.left), outer.y + px(inset.top), Math.max(0, outer.width - px(inset.left) - px(inset.right)), Math.max(0, outer.height - px(inset.top) - px(inset.bottom)));
879
- function insetReach(area7, f) {
880
- const up = area7.y <= f.outer.y + px(f.inset.top) + EPS5 ? px(f.inset.top) : 0;
881
- const down = area7.y + area7.height >= f.outer.y + f.outer.height - px(f.inset.bottom) - EPS5 ? px(f.inset.bottom) : 0;
911
+ function insetReach(area8, f) {
912
+ const up = area8.y <= f.outer.y + px(f.inset.top) + EPS5 ? px(f.inset.top) : 0;
913
+ const down = area8.y + area8.height >= f.outer.y + f.outer.height - px(f.inset.bottom) - EPS5 ? px(f.inset.bottom) : 0;
882
914
  return { up, down };
883
915
  }
884
916
 
@@ -905,18 +937,18 @@ import { EPS as EPS8, rect as rect5 } from "@n-uf/placement";
905
937
 
906
938
  // src/solve/columns.ts
907
939
  import { EPS as EPS7 } from "@n-uf/placement";
908
- import { formCrossMin as formCrossMin3, formSetsCross as formSetsCross3 } from "@n-uf/placement/stack";
940
+ import { formCrossMin as formCrossMin3, formMenu as formMenu2, formSetsCross as formSetsCross3 } from "@n-uf/placement/stack";
909
941
  var isChrome = (state, c) => !c.dyn && isSideBar(state, c.edge);
910
- function columnsOf(d, sideEdges, area7, tall) {
942
+ function columnsOf(d, sideEdges, area8, tall) {
911
943
  const { state } = d;
912
944
  return sideEdges.map((edge) => {
913
945
  const side = edge.side;
914
- const solved = solveEdge(state, edge, d.owned.get(edge), tall(edge), Math.max(0, area7.width), d.prevEdge(edge));
915
- const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area7.width);
946
+ const solved = solveEdge(state, edge, d.owned.get(edge), tall(edge), Math.max(0, area8.width), d.prevEdge(edge));
947
+ const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area8.width);
916
948
  const visible = d.owned.get(edge).filter((id) => !state.items[id].closed);
917
949
  const dyn = (edge.column === true || edge.giveWay === true) && state.rails?.[side] !== void 0 && visible.length > 0;
918
950
  const forms = (id) => formsOf(state.items[id], "column");
919
- const setters = solved.free.items.filter((p) => p.kind !== "menu" && formSetsCross3(forms(p.id)[p.form]));
951
+ const setters = solved.free.items.filter((p) => !formMenu2(forms(p.id)[p.form]) && formSetsCross3(forms(p.id)[p.form]));
920
952
  const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin3(forms(p.id)[p.form])))) : width;
921
953
  return {
922
954
  edge,
@@ -932,7 +964,7 @@ function columnsOf(d, sideEdges, area7, tall) {
932
964
  };
933
965
  });
934
966
  }
935
- function giveWay(d, cols, area7, gutter) {
967
+ function giveWay(d, cols, area8, gutter) {
936
968
  const { state, previous, fresh, opened } = d;
937
969
  const ride = state.handFold === "ride";
938
970
  const cmin = state.contentMin ? px(state.contentMin.width) : void 0;
@@ -954,7 +986,7 @@ function giveWay(d, cols, area7, gutter) {
954
986
  let used = 0;
955
987
  for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : gutter) : 0;
956
988
  for (const s of railSides) used += railW(s) + gutter;
957
- let excess = cmin === void 0 ? -Infinity : floor === void 0 ? used + cmin - area7.width : Math.max(used - chrome + cmin, used + floor) - area7.width;
989
+ let excess = cmin === void 0 ? -Infinity : floor === void 0 ? used + cmin - area8.width : Math.max(used - chrome + cmin, used + floor) - area8.width;
958
990
  for (const c of shrinkOrder) {
959
991
  if (excess <= EPS7) break;
960
992
  const w = widths.get(c);
@@ -994,7 +1026,7 @@ function giveWay(d, cols, area7, gutter) {
994
1026
  }
995
1027
  return evaluate(auto);
996
1028
  }
997
- function columnRoom(d, cols, area7, f) {
1029
+ function columnRoom(d, cols, area8, f) {
998
1030
  const { state } = d;
999
1031
  const cmin = state.contentMin ? px(state.contentMin.width) : void 0;
1000
1032
  const openMin = (ids, least) => Math.max(
@@ -1015,7 +1047,7 @@ function columnRoom(d, cols, area7, f) {
1015
1047
  if (cmin === void 0 || colMins.length === 0) return;
1016
1048
  const allBars = cols.filter((c) => c.width > 0 && isChrome(state, c)).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : f.gutter), 0);
1017
1049
  const bars = d.chromeAllowance === void 0 ? allBars : allBars - Math.min(allBars, d.chromeAllowance);
1018
- const width = area7.width - bars - (state.insetWhen === "docked" && !f.docked ? px(state.inset?.left) + px(state.inset?.right) : 0);
1050
+ const width = area8.width - bars - (state.insetWhen === "docked" && !f.docked ? px(state.inset?.left) + px(state.inset?.right) : 0);
1019
1051
  const need = cmin + Math.min(...colMins) + f.gutter;
1020
1052
  d.columnRoom = width >= need - EPS7;
1021
1053
  if (!d.columnRoom) d.notes.push({ code: "no-column-room", width, need });
@@ -1122,26 +1154,26 @@ function layRail(d, side, railRect, railed, g) {
1122
1154
  }
1123
1155
 
1124
1156
  // src/solve/sides.ts
1125
- function laySides(d, sideEdges, area7, f) {
1126
- const H = area7.height;
1127
- const reach = insetReach(area7, f);
1157
+ function laySides(d, sideEdges, area8, f) {
1158
+ const H = area8.height;
1159
+ const reach = insetReach(area8, f);
1128
1160
  const tall = (edge) => H + (edge.outsideInset === true ? reach.up + reach.down : 0);
1129
- const cols = columnsOf(d, sideEdges, area7, tall);
1130
- const g = giveWay(d, cols, area7, f.gutter);
1131
- columnRoom(d, cols, area7, f);
1161
+ const cols = columnsOf(d, sideEdges, area8, tall);
1162
+ const g = giveWay(d, cols, area8, f.gutter);
1163
+ columnRoom(d, cols, area8, f);
1132
1164
  giveWayNotes(d, g, cols);
1133
- const walk = { x0: area7.x, x1: area7.x + area7.width };
1134
- for (const side of ["left", "right"]) laySide(d, side, cols, g, area7, f, walk, reach.up, tall);
1135
- return rect5(walk.x0, area7.y, Math.max(0, walk.x1 - walk.x0), H);
1165
+ const walk = { x0: area8.x, x1: area8.x + area8.width };
1166
+ for (const side of ["left", "right"]) laySide(d, side, cols, g, area8, f, walk, reach.up, tall);
1167
+ return rect5(walk.x0, area8.y, Math.max(0, walk.x1 - walk.x0), H);
1136
1168
  }
1137
1169
  function forced(d, c, length, w) {
1138
1170
  const edge = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };
1139
1171
  const { size: _s, ...plain } = edge;
1140
1172
  return solveEdge(d.state, plain, d.owned.get(c.edge), length, w, d.prevEdge(c.edge));
1141
1173
  }
1142
- function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
1174
+ function laySide(d, side, cols, g, area8, f, walk, upInset, tall) {
1143
1175
  const { state, edges } = d;
1144
- const H = area7.height;
1176
+ const H = area8.height;
1145
1177
  const outsideSideBar = (c) => c.width > 0 && isOutsideSideBar(state, c.edge) && !g.railed(c) && !g.riding(c);
1146
1178
  const all = cols.filter((c) => c.side === side);
1147
1179
  const mine = [...all.filter(outsideSideBar), ...all.filter((c) => !outsideSideBar(c))];
@@ -1156,7 +1188,7 @@ function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
1156
1188
  let railPlace = null;
1157
1189
  const placeRail = () => {
1158
1190
  const lead = barLaid ? gap : 0;
1159
- return side === "left" ? rect5(walk.x0 - lead, area7.y, railW, H) : rect5(walk.x1 + lead - railW, area7.y, railW, H);
1191
+ return side === "left" ? rect5(walk.x0 - lead, area8.y, railW, H) : rect5(walk.x1 + lead - railW, area8.y, railW, H);
1160
1192
  };
1161
1193
  for (const c of mine) {
1162
1194
  if (!railPlace && !outsideSideBar(c)) {
@@ -1173,7 +1205,7 @@ function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
1173
1205
  if (outsideSideBar(c)) barLaid = true;
1174
1206
  const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, items: zoneSorted(state, c.visible), tabs: [], stack: c.solved.stack, free: c.solved.free };
1175
1207
  if (g.railed(c)) {
1176
- edges[c.edge.id] = { ...base, rect: rect5(railRect.x, area7.y, 0, H), folded: g.auto.has(c) ? "auto" : "hand" };
1208
+ edges[c.edge.id] = { ...base, rect: rect5(railRect.x, area8.y, 0, H), folded: g.auto.has(c) ? "auto" : "hand" };
1177
1209
  continue;
1178
1210
  }
1179
1211
  if (g.riding(c)) continue;
@@ -1182,7 +1214,7 @@ function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
1182
1214
  let solved = top > 0 || Math.abs(w - c.width) > EPS8 ? forced(d, c, H - top, w) : c.solved;
1183
1215
  let r;
1184
1216
  if (c.edge.outsideInset === true) {
1185
- const y0 = area7.y - upInset;
1217
+ const y0 = area8.y - upInset;
1186
1218
  const h = tall(c.edge);
1187
1219
  if (side === "left") {
1188
1220
  r = rect5(walk.x0 - gap, y0, w, h);
@@ -1193,24 +1225,31 @@ function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
1193
1225
  }
1194
1226
  if (Math.abs(h - H) > EPS8 || Math.abs(w - c.width) > EPS8) solved = forced(d, c, h, w);
1195
1227
  } else if (side === "left") {
1196
- r = rect5(walk.x0, area7.y + top, w, H - top);
1228
+ r = rect5(walk.x0, area8.y + top, w, H - top);
1197
1229
  walk.x0 += w > 0 ? w + f.gutter : 0;
1198
1230
  if (w > 0) gap = f.gutter;
1199
1231
  } else {
1200
1232
  walk.x1 -= w;
1201
- r = rect5(walk.x1, area7.y + top, w, H - top);
1233
+ r = rect5(walk.x1, area8.y + top, w, H - top);
1202
1234
  walk.x1 -= w > 0 ? f.gutter : 0;
1203
1235
  if (w > 0) gap = f.gutter;
1204
1236
  }
1205
1237
  emit(d, c.edge, r, solved, w < c.width - EPS8 ? { shrunk: true } : {});
1206
1238
  }
1207
- if (host && riders.length > 0) layRiders(d, host, riders, area7.y);
1239
+ if (host && riders.length > 0) layRiders(d, host, riders, area8.y);
1208
1240
  if (railRect) layRail(d, side, railRect, railed, g);
1209
1241
  if (state.rails?.[side]) d.railPlaces[side] = railPlace ?? placeRail();
1210
1242
  }
1211
1243
 
1212
1244
  // src/solve.ts
1245
+ var solvedFrom = /* @__PURE__ */ new WeakMap();
1246
+ var stateOf = (layout) => solvedFrom.get(layout);
1213
1247
  function solve(given, options = {}) {
1248
+ const layout = solveState(given, options);
1249
+ solvedFrom.set(layout, given);
1250
+ return layout;
1251
+ }
1252
+ function solveState(given, options) {
1214
1253
  checkEdgeIds(given);
1215
1254
  const { view: shown, ignored } = viewOf(given);
1216
1255
  const lay = (caps, gave = []) => layOut(shown, options, caps, gave);
@@ -1219,7 +1258,7 @@ function solve(given, options = {}) {
1219
1258
  const l = way ? lay(way.caps, way.notes) : first;
1220
1259
  return ignored.length === 0 ? l : { ...l, notes: [...l.notes, ...ignored.map((edge) => ({ code: "show-in-ignored", edge }))] };
1221
1260
  }
1222
- var withHeightOf = (area7, over) => rect6(over.x, area7.y, over.width, area7.height);
1261
+ var withHeightOf = (area8, over2) => rect6(over2.x, area8.y, over2.width, area8.height);
1223
1262
  function layOut(given, options, caps, gave) {
1224
1263
  const d = createDraft(given, options, caps);
1225
1264
  const { state, order } = d;
@@ -1229,19 +1268,19 @@ function layOut(given, options, caps, gave) {
1229
1268
  const outsideBar = (e) => !isSide(e) && e.span !== "between" && e.outsideInset === true;
1230
1269
  let outer = stage;
1231
1270
  for (const e of reserved) if (outsideBar(e)) outer = cutEdge(d, e, outer, true);
1232
- let area7 = insideInset(outer, inset);
1233
- for (const e of reserved) if (!isSide(e) && e.span !== "between" && !outsideBar(e)) area7 = cutEdge(d, e, area7, true);
1234
- const wide = area7;
1235
- area7 = laySides(d, reserved.filter(isSide), area7, { inset, gutter: px(state.gutter), docked, outer });
1236
- for (const e of reserved) if (!isSide(e) && e.span === "between") area7 = cutEdge(d, e, area7, true);
1237
- const content = area7;
1238
- let over = content;
1271
+ let area8 = insideInset(outer, inset);
1272
+ for (const e of reserved) if (!isSide(e) && e.span !== "between" && !outsideBar(e)) area8 = cutEdge(d, e, area8, true);
1273
+ const wide = area8;
1274
+ area8 = laySides(d, reserved.filter(isSide), area8, { inset, gutter: px(state.gutter), docked, outer });
1275
+ for (const e of reserved) if (!isSide(e) && e.span === "between") area8 = cutEdge(d, e, area8, true);
1276
+ const content = area8;
1277
+ let over2 = content;
1239
1278
  for (const e of order) {
1240
1279
  if (e.mode !== "overlay") continue;
1241
- if (isSide(e) || e.span !== "full") over = cutEdge(d, e, over, true);
1280
+ if (isSide(e) || e.span !== "full") over2 = cutEdge(d, e, over2, true);
1242
1281
  else {
1243
1282
  const across2 = e.outsideInset === true ? outer : wide;
1244
- over = withHeightOf(cutEdge(d, e, rect6(across2.x, over.y, across2.width, over.height), true), over);
1283
+ over2 = withHeightOf(cutEdge(d, e, rect6(across2.x, over2.y, across2.width, over2.height), true), over2);
1245
1284
  }
1246
1285
  }
1247
1286
  for (const n of gave) {
@@ -1254,8 +1293,57 @@ function layOut(given, options, caps, gave) {
1254
1293
  return { items, edges, content, floats, rails, railPlaces, ...columnRoom2 !== void 0 ? { columnRoom: columnRoom2 } : {}, notes };
1255
1294
  }
1256
1295
 
1296
+ // src/dividers.ts
1297
+ import { rect as rect7 } from "@n-uf/placement";
1298
+ import { dividers as stackDividers, resetBetween as stackReset, resizeBetween as stackResize } from "@n-uf/placement/stack";
1299
+ var laid = (state, layout) => layout && stateOf(layout) === state && Object.values(layout.edges).every((e) => inputOf(e.stack) !== void 0) ? layout : solve(state);
1300
+ function dividers(state, layout) {
1301
+ const lay = laid(state, layout);
1302
+ const out = [];
1303
+ for (const [edge, e] of Object.entries(lay.edges)) {
1304
+ const input = inputOf(e.stack);
1305
+ if (!input) continue;
1306
+ for (const d of stackDividers(input, e.stack)) out.push({ edge, before: d.before, after: d.after, rect: rect7(e.rect.x + d.rect.x, e.rect.y + d.rect.y, d.rect.width, d.rect.height), range: d.range });
1307
+ }
1308
+ return out;
1309
+ }
1310
+ function over(state, layout, before, after, run) {
1311
+ const lay = laid(state, layout);
1312
+ const edge = lay.items[before]?.edge;
1313
+ const e = edge !== void 0 && lay.items[after]?.edge === edge ? lay.edges[edge] : void 0;
1314
+ const input = e && inputOf(e.stack);
1315
+ if (!e || !input) return state;
1316
+ const next = run(input, e.stack);
1317
+ if (next === input) return state;
1318
+ const was = new Map(input.items.map((it) => [it.id, it.lengths]));
1319
+ const items = { ...state.items };
1320
+ for (const it of next.items) if (it.lengths !== was.get(it.id) && items[it.id]) items[it.id] = { ...items[it.id], lengths: it.lengths };
1321
+ return { ...state, items };
1322
+ }
1323
+ function resizeBetween(state, before, after, delta, options = {}) {
1324
+ return over(state, options.layout, before, after, (input, fit) => stackResize(input, before, after, delta, { previous: fit }));
1325
+ }
1326
+ function resetBetween(state, before, after, options = {}) {
1327
+ return over(state, options.layout, before, after, (input, fit) => stackReset(input, before, after, { previous: fit }));
1328
+ }
1329
+ function resetLengths(state, edgeId) {
1330
+ const edge = state.edges.find((e) => e.id === edgeId);
1331
+ if (!edge) return state;
1332
+ const axis = axisOf(edge.side);
1333
+ let items;
1334
+ for (const id of edge.items) {
1335
+ const it = state.items[id];
1336
+ if (it?.lengths?.[axis] === void 0) continue;
1337
+ const { [axis]: _dropped, ...rest } = it.lengths;
1338
+ const { lengths: _lengths, ...bare } = it;
1339
+ items ??= { ...state.items };
1340
+ items[id] = Object.keys(rest).length > 0 ? { ...bare, lengths: rest } : bare;
1341
+ }
1342
+ return items ? { ...state, items } : state;
1343
+ }
1344
+
1257
1345
  // src/changes.ts
1258
- import { clampInto as clampInto2 } from "@n-uf/placement";
1346
+ import { clampInto as clampInto3 } from "@n-uf/placement";
1259
1347
 
1260
1348
  // src/float-resize.ts
1261
1349
  var LIMITS = ["min", "max", "region", "docked"];
@@ -1263,14 +1351,16 @@ var EPS9 = 0.5;
1263
1351
  var TOUCH = 1e-3;
1264
1352
  var fin = (v, d) => Number.isFinite(v) ? v : d;
1265
1353
  function floatObstacles(state, l, id) {
1266
- const out = [];
1267
- for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);
1354
+ const some = (r) => r.width > 0 && r.height > 0;
1355
+ const rects = [];
1356
+ for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating && some(p.rect)) rects.push(p.rect);
1357
+ const docked = rects.length;
1268
1358
  for (const e of Object.values(l.edges)) {
1269
- if (axisOf(e.side) === "row" && e.cross > 0) out.push(e.rect);
1270
- if (e.menu) out.push(e.menu.rect);
1359
+ if (axisOf(e.side) === "row" && e.cross > 0) rects.push(e.rect);
1360
+ if (e.menu) rects.push(e.menu.rect);
1271
1361
  }
1272
- for (const c of keepClearFor(state, "floats")) out.push(c);
1273
- return out.filter((r) => r.width > 0 && r.height > 0);
1362
+ for (const c of keepClearFor(state, "floats")) rects.push(c);
1363
+ return { rects: rects.filter(some), docked };
1274
1364
  }
1275
1365
  function obstacleStop(drawn, obstacles, axis, drag, span) {
1276
1366
  const none = drag === "start" ? -Infinity : Infinity;
@@ -1336,7 +1426,7 @@ function fitAxis(start, length, b, drag, hit) {
1336
1426
  }
1337
1427
  return [a, to - a];
1338
1428
  }
1339
- function fitResize(state, id, rect18, moving) {
1429
+ function fitResize(state, id, rect19, moving) {
1340
1430
  const f = state.floats.find((x2) => x2.id === id);
1341
1431
  const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
1342
1432
  if (!f || !item || item.fixed) return null;
@@ -1351,12 +1441,13 @@ function fitResize(state, id, rect18, moving) {
1351
1441
  const region = floatRegion(state);
1352
1442
  const dragX = moving.left ? "start" : moving.right ? "end" : null;
1353
1443
  const dragY = moving.top ? "start" : moving.bottom ? "end" : null;
1354
- const obstacles = floatObstacles(state, l, id);
1444
+ const { rects: obstacles, docked } = floatObstacles(state, l, id);
1355
1445
  const hit = /* @__PURE__ */ new Set();
1356
- const [x, width] = fitAxis(rect18.x, rect18.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, obstacles, "x", dragX ?? "end", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);
1357
- const [y, height] = fitAxis(rect18.y, rect18.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, obstacles, "y", dragY ?? "end", [x, x + width]) }, dragY, hit);
1446
+ const stops2 = f.stays ? obstacles.slice(docked) : obstacles;
1447
+ const [x, width] = fitAxis(rect19.x, rect19.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);
1448
+ const [y, height] = fitAxis(rect19.y, rect19.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);
1358
1449
  const { anchor: _a, ...plain } = f;
1359
- const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, state.stage).fit.rect;
1450
+ const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, state.stage, [], docked).fit.rect;
1360
1451
  if (Math.abs(placed.x - x) > EPS9 || Math.abs(placed.y - y) > EPS9) hit.add("docked");
1361
1452
  if (Math.abs(placed.width - width) > EPS9 || Math.abs(placed.height - height) > EPS9) hit.add("min");
1362
1453
  return { rect: placed, limits: LIMITS.filter((k) => hit.has(k)) };
@@ -1489,8 +1580,9 @@ function moveAmong(state, id, place, others) {
1489
1580
  if (place.kind === "float") {
1490
1581
  const out = floatAt(state, id, place.rect);
1491
1582
  const anchor = place.anchor;
1492
- if (!anchor || out === state) return out;
1493
- return { ...out, floats: out.floats.map((f) => f.id === id ? { ...f, anchor } : f) };
1583
+ const stays = place.stays === true && !anchor && !!place.rect;
1584
+ if (!anchor && !stays || out === state) return out;
1585
+ return { ...out, floats: out.floats.map((f) => f.id === id ? anchor ? { ...f, anchor } : { ...f, stays: true } : f) };
1494
1586
  }
1495
1587
  const railColumn = place.kind === "rail" ? railColumnOf(state, place.side, item.kind) : void 0;
1496
1588
  if (railColumn) {
@@ -1529,6 +1621,18 @@ function nextSince(state) {
1529
1621
  const most = state.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
1530
1622
  return Math.min(most + 1, Number.MAX_SAFE_INTEGER);
1531
1623
  }
1624
+ var anchoredDrawn = /* @__PURE__ */ new WeakMap();
1625
+ function overAnchored(state, id, r) {
1626
+ if (!state.floats.some((f) => f.anchor && f.id !== id)) return false;
1627
+ let drawn = anchoredDrawn.get(state);
1628
+ if (!drawn) {
1629
+ const l = solve(state);
1630
+ drawn = state.floats.filter((f) => f.anchor && l.items[f.id]?.floating).map((f) => ({ id: f.id, rect: l.items[f.id].rect }));
1631
+ anchoredDrawn.set(state, drawn);
1632
+ }
1633
+ const touch = 1e-3;
1634
+ return drawn.some((d) => d.id !== id && Math.min(r.x + r.width, d.rect.x + d.rect.width) - Math.max(r.x, d.rect.x) > touch && Math.min(r.y + r.height, d.rect.y + d.rect.height) - Math.max(r.y, d.rect.y) > touch);
1635
+ }
1532
1636
  function floatAt(state, id, at, orient) {
1533
1637
  const item = itemOf(state, id);
1534
1638
  if (!item || item.fixed || !state.floatKinds.includes(item.kind)) return state;
@@ -1536,7 +1640,7 @@ function floatAt(state, id, at, orient) {
1536
1640
  const o = orient ?? was?.orient;
1537
1641
  const fo = o ?? floatOrientOf(item);
1538
1642
  const size = floatSizeOf(item, fo);
1539
- const since = was ? was.since : nextSince(state);
1643
+ const since = was && !(at && overAnchored(state, id, at)) ? was.since : nextSince(state);
1540
1644
  const seq = since !== void 0 ? { since } : {};
1541
1645
  const float = at ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...o ? { orient: o } : {}, ...seq } : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: "content-top-right", ...o ? { orient: o } : {}, ...seq };
1542
1646
  const { space: _space, ...unspaced } = item;
@@ -1609,13 +1713,14 @@ function orientFloat(state, id, to) {
1609
1713
  const turned = { ...f, rect: { x: f.rect.x, y: f.rect.y, width: size.width, height: size.height }, orient: to };
1610
1714
  return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? turned : g) }, kept);
1611
1715
  }
1612
- function resizeFloat(state, floatId, rect18, moving = { right: true, bottom: true }) {
1613
- const fit = fitResize(state, floatId, rect18, moving);
1716
+ function resizeFloat(state, floatId, rect19, moving = { right: true, bottom: true }) {
1717
+ const fit = fitResize(state, floatId, rect19, moving);
1614
1718
  const i = state.floats.findIndex((f) => f.id === floatId);
1615
1719
  const item = itemOf(state, floatId);
1616
1720
  if (!fit || i < 0 || !item) return state;
1617
1721
  const { anchor: _a, ...plain } = state.floats[i];
1618
- const float = { ...plain, rect: fit.rect };
1722
+ const renew = overAnchored(state, floatId, fit.rect);
1723
+ const float = renew ? { ...plain, rect: fit.rect, since: nextSince(state) } : { ...plain, rect: fit.rect };
1619
1724
  const fo = float.orient ?? floatOrientOf(item);
1620
1725
  return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? float : g) }, withFloatSizes(item, { orient: fo, size: { width: fit.rect.width, height: fit.rect.height } }));
1621
1726
  }
@@ -1657,7 +1762,7 @@ function homeFor(state, id, start) {
1657
1762
  return null;
1658
1763
  }
1659
1764
  const f = start.floats.find((x) => x.id === id);
1660
- if (f) return { kind: "float", rect: f.rect, ...f.anchor ? { anchor: f.anchor } : {} };
1765
+ if (f) return { kind: "float", rect: f.rect, ...f.anchor ? { anchor: f.anchor } : f.stays ? { stays: true } : {} };
1661
1766
  return null;
1662
1767
  }
1663
1768
  function dockHome(state, id, start) {
@@ -1680,7 +1785,7 @@ function dockHome(state, id, start) {
1680
1785
  return out === item ? moved : withItem(moved, out);
1681
1786
  }
1682
1787
  function clampFloat(r, stage, drawn = r) {
1683
- const at = clampInto2({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);
1788
+ const at = clampInto3({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);
1684
1789
  return { x: at.x, y: at.y, width: r.width, height: r.height };
1685
1790
  }
1686
1791
  function drawnFloatSize(item, f) {
@@ -1689,7 +1794,7 @@ function drawnFloatSize(item, f) {
1689
1794
  }
1690
1795
 
1691
1796
  // src/store.ts
1692
- import { rect as rect7 } from "@n-uf/placement";
1797
+ import { EPS as EPS10, rect as rect8 } from "@n-uf/placement";
1693
1798
  var isNum = (x) => typeof x === "number" && Number.isFinite(x);
1694
1799
  var isSize = (x) => isNum(x) && x > 0;
1695
1800
  var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
@@ -1728,11 +1833,20 @@ function floatSizesStored(it) {
1728
1833
  }
1729
1834
  return out.row || out.column ? out : void 0;
1730
1835
  }
1836
+ function lengthStored(it) {
1837
+ const out = {};
1838
+ for (const o of ["column", "row"]) {
1839
+ const v = it.lengths?.[o];
1840
+ if (isNum(v) && v > EPS10) out[o] = v;
1841
+ }
1842
+ return out.column !== void 0 || out.row !== void 0 ? out : void 0;
1843
+ }
1731
1844
  function storeDockState(state) {
1732
1845
  const items = record();
1733
1846
  for (const [id, it] of Object.entries(state.items)) {
1734
1847
  if (id === "__proto__") continue;
1735
1848
  const sizes = floatSizesStored(it);
1849
+ const asked = lengthStored(it);
1736
1850
  items[id] = {
1737
1851
  used: isNum(it.used) ? it.used : 0,
1738
1852
  ...it.kept ? { kept: true } : {},
@@ -1740,6 +1854,7 @@ function storeDockState(state) {
1740
1854
  ...it.closed ? { closed: true } : {},
1741
1855
  ...it.align === "center" || it.align === "end" ? { align: it.align } : {},
1742
1856
  ...isNum(it.space) && it.space > 0 ? { space: it.space } : {},
1857
+ ...asked ? { lengths: asked } : {},
1743
1858
  ...sizes ? { floatSizes: sizes } : {}
1744
1859
  };
1745
1860
  }
@@ -1749,7 +1864,7 @@ function storeDockState(state) {
1749
1864
  edges: state.edges.map((e) => ({ id: e.id, side: e.side, ring: e.ring, items: [...e.items], ...isNum(e.size) ? { size: e.size } : {}, ...e.column === true ? { column: true } : {} })),
1750
1865
  floats: state.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) => {
1751
1866
  const anchor = anchorOf(f.anchor);
1752
- return { id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...anchor ? { anchor } : {}, ...isSince(f.since) ? { since: f.since } : {} };
1867
+ return { id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...anchor ? { anchor } : {}, ...isSince(f.since) ? { since: f.since } : {}, ...f.stays === true && !anchor ? { stays: true } : {} };
1753
1868
  }),
1754
1869
  items,
1755
1870
  ...modes ? { railModes: modes } : {}
@@ -1797,9 +1912,9 @@ function read(data, base) {
1797
1912
  continue;
1798
1913
  }
1799
1914
  const b = base.items[id];
1800
- const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSizes: _ss, ...plain } = b;
1915
+ const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, lengths: _len, floatSizes: _ss, ...plain } = b;
1801
1916
  let it = { ...plain, used: b.used };
1802
- for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize", "floatSizes"].includes(k)) drop(`item:${id}:${k}`);
1917
+ for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "lengths", "floatSize", "floatSizes"].includes(k)) drop(`item:${id}:${k}`);
1803
1918
  if (isNum(s.used)) it = { ...it, used: s.used };
1804
1919
  else if (s.used !== void 0) drop(`item:${id}:used`);
1805
1920
  if (s.kept === true) it = { ...it, kept: true };
@@ -1815,6 +1930,15 @@ function read(data, base) {
1815
1930
  if (b.fixed && b.align) it = { ...it, align: b.align };
1816
1931
  if (isNum(s.space) && s.space > 0 && !b.fixed) it = { ...it, space: s.space };
1817
1932
  else if (s.space !== void 0) drop(`item:${id}:space`);
1933
+ if (isObject(s.lengths)) {
1934
+ const asked = {};
1935
+ for (const k of Object.keys(s.lengths)) {
1936
+ const v = s.lengths[k];
1937
+ if ((k === "column" || k === "row") && isNum(v) && v > EPS10) asked[k] = v;
1938
+ else drop(`item:${id}:lengths:${k}`);
1939
+ }
1940
+ if (asked.column !== void 0 || asked.row !== void 0) it = { ...it, lengths: asked };
1941
+ } else if (s.lengths !== void 0) drop(`item:${id}:lengths`);
1818
1942
  const fs = s.floatSize;
1819
1943
  if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) legacy.set(id, { width: fs.width, height: fs.height });
1820
1944
  else if (fs !== void 0) drop(`item:${id}:floatSize`);
@@ -1904,16 +2028,18 @@ function read(data, base) {
1904
2028
  continue;
1905
2029
  }
1906
2030
  for (const k of Object.keys(f)) if (k === "pinned") drop(`pinned:${id}`);
1907
- else if (!["id", "x", "y", "width", "height", "orient", "anchor", "since"].includes(k)) drop(`float:${id}:${k}`);
2031
+ else if (!["id", "x", "y", "width", "height", "orient", "anchor", "since", "stays"].includes(k)) drop(`float:${id}:${k}`);
1908
2032
  const o = f.orient === "row" || f.orient === "column" ? f.orient : void 0;
1909
2033
  if (f.orient !== void 0 && !o) drop(`float:${id}:orient`);
1910
2034
  const a = anchorOf(f.anchor, (what) => drop(`float:${id}:anchor${what}`));
1911
2035
  const since = isSince(f.since) ? f.since : void 0;
1912
2036
  if (f.since !== void 0 && since === void 0) drop(`float:${id}:since`);
2037
+ const stays = f.stays === true && !a;
2038
+ if (f.stays !== void 0 && !stays) drop(`float:${id}:stays`);
1913
2039
  placed.add(id);
1914
- const r = rect7(f.x, f.y, f.width, f.height);
2040
+ const r = rect8(f.x, f.y, f.width, f.height);
1915
2041
  const drawn = drawnFloatSize(items[id], { rect: r, ...o ? { orient: o } : {} });
1916
- floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {}, ...since !== void 0 ? { since } : {} });
2042
+ floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {}, ...since !== void 0 ? { since } : {}, ...stays ? { stays: true } : {} });
1917
2043
  }
1918
2044
  const edges = [...base.edges, ...made].map((edge) => {
1919
2045
  const stored = order.get(edge.id) ?? [];
@@ -1944,10 +2070,10 @@ function read(data, base) {
1944
2070
  }
1945
2071
 
1946
2072
  // src/targets.ts
1947
- import { EPS as EPS19, PLANE, area as area6, overlaps as overlaps6, rect as rect16 } from "@n-uf/placement";
2073
+ import { EPS as EPS20, PLANE, area as area6, clamp as clamp2, contains, overlaps as overlaps7, rect as rect17 } from "@n-uf/placement";
1948
2074
 
1949
2075
  // src/targets/anchor.ts
1950
- import { EPS as EPS10, area, rect as rect8, subtract } from "@n-uf/placement";
2076
+ import { EPS as EPS11, area, rect as rect9, subtract } from "@n-uf/placement";
1951
2077
  var OTHER = { left: "right", right: "left", top: "bottom", bottom: "top" };
1952
2078
  function anchorTargets(state, dragged, options) {
1953
2079
  const none = { targets: [], refusals: [], lost: [] };
@@ -1963,8 +2089,8 @@ function anchorTargets(state, dragged, options) {
1963
2089
  const layout = solve(moved, prev);
1964
2090
  const placed = layout.edges[edge.id]?.rect;
1965
2091
  const slot = layout.items[dragged]?.rect;
1966
- if (placed && slot && area(placed) > EPS10) {
1967
- const pieces = keepClearFor(state, "targets").reduce((ps, c) => ps.flatMap((p) => subtract(p, rect8(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);
2092
+ if (placed && slot && area(placed) > EPS11) {
2093
+ const pieces = keepClearFor(state, "targets").reduce((ps, c) => ps.flatMap((p) => subtract(p, rect9(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);
1968
2094
  if (pieces.length > 0) {
1969
2095
  const hit = pieces.reduce((a, p) => area(p) > area(a) ? p : a);
1970
2096
  const result = { state: moved, layout };
@@ -1976,8 +2102,8 @@ function anchorTargets(state, dragged, options) {
1976
2102
  }
1977
2103
 
1978
2104
  // src/targets/edges.ts
1979
- import { EPS as EPS11, area as area2, rect as rect9 } from "@n-uf/placement";
1980
- import { formCrossMin as formCrossMin4, formMain as formMain2, formSetsCross as formSetsCross4 } from "@n-uf/placement/stack";
2105
+ import { EPS as EPS12, area as area2, rect as rect10 } from "@n-uf/placement";
2106
+ import { formCrossMin as formCrossMin4, formMenu as formMenu3, formSetsCross as formSetsCross4, itemSteps as itemSteps3 } from "@n-uf/placement/stack";
1981
2107
 
1982
2108
  // src/targets/kinds.ts
1983
2109
  var COLUMN_REACH = 22;
@@ -1991,6 +2117,7 @@ var EDGE_KINDS = {
1991
2117
  barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
1992
2118
  rail: { zoneExtent: "thirds", opens: "any", inward: RAIL_REACH, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 14, overreach: 34, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
1993
2119
  railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false, minHit: MIN_HIT },
2120
+ railColumn: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 8, overreach: 38, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
1994
2121
  columnLine: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, edgePlace: DEFAULT_HIT_BAND, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true, minHit: MIN_HIT }
1995
2122
  };
1996
2123
  function edgeKindOf(state, e) {
@@ -2010,7 +2137,7 @@ function reservedRect(state, l, id) {
2010
2137
  const len2 = column ? it.rect.height : it.rect.width;
2011
2138
  const keep = Math.min(len2, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len2));
2012
2139
  const shift = it.zone === "end" ? len2 - keep : it.zone === "center" ? (len2 - keep) / 2 : 0;
2013
- return column ? rect9(it.rect.x, it.rect.y + shift, it.rect.width, keep) : rect9(it.rect.x + shift, it.rect.y, keep, it.rect.height);
2140
+ return column ? rect10(it.rect.x, it.rect.y + shift, it.rect.width, keep) : rect10(it.rect.x + shift, it.rect.y, keep, it.rect.height);
2014
2141
  }
2015
2142
  function slotAt(c, zone, line, id, place, lands, home = false) {
2016
2143
  const result = c.settle(markUsed(moveAmong(c.state, c.dragged, place, c.others), c.dragged));
@@ -2023,7 +2150,7 @@ function distinctSlots(c, slots) {
2023
2150
  if (a.zone !== b.zone) return false;
2024
2151
  if (a.home && b.home) return true;
2025
2152
  const [p, q] = [landing(a), landing(b)];
2026
- const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS11;
2153
+ const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS12;
2027
2154
  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);
2028
2155
  };
2029
2156
  const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
@@ -2094,21 +2221,9 @@ function edgeSlots(c, edge, accepts) {
2094
2221
  const length = len2(el.rect);
2095
2222
  const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];
2096
2223
  const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
2097
- const firstKind = formsOf(state.items[dragged], axisOf(edge.side))[0]?.kind;
2098
- const titles = edge.items.filter((id) => base.items[id]?.edge === edge.id && base.items[id].fixed && !!formsOf(state.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows);
2099
2224
  const lands = ({ layout: after }) => {
2100
2225
  const me = after.items[dragged];
2101
- if (me.edge !== edge.id || me.inMenu) return false;
2102
- if (titles.length === 0) return true;
2103
- if (formsOf(state.items[dragged], axisOf(edge.side))[me.form]?.kind !== firstKind) return false;
2104
- return edge.items.every((id) => {
2105
- const a = after.items[id];
2106
- const b = base.items[id];
2107
- if (!a || !b || b.edge !== edge.id || id === dragged) return true;
2108
- if (!titles.includes(id)) return a.form === b.form && !!a.inMenu === !!b.inMenu;
2109
- const f = formsOf(state.items[id], axisOf(edge.side))[a.form];
2110
- return !f || (column ? a.rect.height : a.rect.width) >= formMain2(f, "natural", after.edges[edge.id].cross) - 0.5;
2111
- });
2226
+ return me.edge === edge.id && !me.inMenu;
2112
2227
  };
2113
2228
  const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
2114
2229
  const menuLen = el.menu ? len2(el.menu.rect) : 0;
@@ -2148,7 +2263,12 @@ function edgeSlots(c, edge, accepts) {
2148
2263
  const b = base.items[id];
2149
2264
  const a = s.result.layout.items[id];
2150
2265
  if (fixedHere(id) && !a) return true;
2151
- return isProtected(id) && (Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5);
2266
+ if (!isProtected(id)) return false;
2267
+ if (itemSteps3(state.items[id]) && (a.inMenu || b.inMenu)) {
2268
+ const i = members.indexOf(id);
2269
+ return i >= 0 && anchored2.has(id) && (zone === "end" ? k > i : k <= i);
2270
+ }
2271
+ return Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5;
2152
2272
  });
2153
2273
  if (!movesFixed) slots.push(s);
2154
2274
  }
@@ -2156,32 +2276,32 @@ function edgeSlots(c, edge, accepts) {
2156
2276
  return slots;
2157
2277
  }
2158
2278
  function thickerThan(forms, cross) {
2159
- const shown = forms.filter((f) => f.kind !== "menu");
2160
- return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS11);
2279
+ const shown = forms.filter((f) => !formMenu3(f));
2280
+ return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS12);
2161
2281
  }
2162
2282
  var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
2163
- function edgeSpec(c, edge) {
2283
+ function edgeSpec(c, edge, as) {
2164
2284
  const { state, rest, now, dragged, kind } = c;
2165
2285
  const el = now.edges[edge.id];
2166
2286
  if (!el || el.folded || el.rides || !rest.edges.some((e) => e.id === edge.id)) return null;
2167
- const edgeKind = edgeKindOf(state, edge);
2287
+ const edgeKind = as ?? edgeKindOf(state, edge);
2168
2288
  const data = EDGE_KINDS[edgeKind];
2169
2289
  const column = axisOf(edge.side) === "column";
2170
2290
  const at = (r2) => column ? r2.y : r2.x;
2171
2291
  const len2 = (r2) => column ? r2.height : r2.width;
2172
- const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
2292
+ const empty = el.stack.items.every((p) => el.stack.menu?.items.includes(p.id)) && !el.menu;
2173
2293
  const accepts = edgeTakes(edge, kind);
2174
- if (!accepts && (empty || area2(el.rect) <= EPS11)) return null;
2294
+ if (!accepts && (empty || area2(el.rect) <= EPS12)) return null;
2175
2295
  if (accepts && empty && !opensEmpty(state, edge, kind)) return null;
2176
2296
  const ownNow = now.items[dragged];
2177
- const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS11 ? ownNow.rect : null;
2297
+ const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS12 ? ownNow.rect : null;
2178
2298
  const oneEnd = state.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
2179
2299
  const allSlots = edgeSlots(c, edge, accepts);
2180
2300
  const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
2181
2301
  const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
2182
2302
  const grows = (id) => !!formsOf(state.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
2183
2303
  const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
2184
- const cards = Object.entries(now.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) > EPS11).map(([, p]) => spanOf(p.rect));
2304
+ 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));
2185
2305
  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) => {
2186
2306
  const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
2187
2307
  const me = s?.result.layout.items[dragged];
@@ -2198,7 +2318,7 @@ function edgeSpec(c, edge) {
2198
2318
  const marker = (s) => {
2199
2319
  const slot = s.result.layout.items[dragged].rect;
2200
2320
  const e = s.result.layout.edges[edge.id];
2201
- return column ? rect9(e.rect.x, slot.y, e.cross, 0) : rect9(slot.x, e.rect.y, 0, e.cross);
2321
+ return column ? rect10(e.rect.x, slot.y, e.cross, 0) : rect10(slot.x, e.rect.y, 0, e.cross);
2202
2322
  };
2203
2323
  const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
2204
2324
  const tooThick = thickerThan(formsOf(state.items[dragged], axisOf(edge.side)), el.stack.cross);
@@ -2210,7 +2330,7 @@ function edgeSpec(c, edge) {
2210
2330
  vertical: column,
2211
2331
  zones,
2212
2332
  slots,
2213
- refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS11 ? "not-accepted" : null,
2333
+ refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS12 ? "not-accepted" : null,
2214
2334
  own: ownHere,
2215
2335
  holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
2216
2336
  reserved,
@@ -2223,10 +2343,20 @@ function edgeSpec(c, edge) {
2223
2343
  marker
2224
2344
  };
2225
2345
  }
2346
+ function railColumnSpec(c, edge, run) {
2347
+ const el = c.now.edges[edge.id];
2348
+ if (!el) return null;
2349
+ const { folded: _folded, ...shown } = el;
2350
+ const seen = { ...c, reach: 0, now: { ...c.now, edges: { ...c.now.edges, [edge.id]: { ...shown, rect: run, cross: run.width } } } };
2351
+ const spec = edgeSpec(seen, edge, "railColumn");
2352
+ if (!spec) return null;
2353
+ const across2 = [run.x, run.x + run.width];
2354
+ return { ...spec, across: () => across2, owned: across2 };
2355
+ }
2226
2356
 
2227
2357
  // src/targets/filter.ts
2228
- import { overlaps } from "@n-uf/placement";
2229
- import { formMain as formMain3 } from "@n-uf/placement/stack";
2358
+ import { overlaps as overlaps2 } from "@n-uf/placement";
2359
+ import { formMain as formMain2, itemSteps as itemSteps4 } from "@n-uf/placement/stack";
2230
2360
  function placeKey(s, id) {
2231
2361
  const it = Object.hasOwn(s.items, id) ? s.items[id] : void 0;
2232
2362
  const byZone = (items) => ZONES.flatMap((z) => items.filter((x) => zoneOf(s.items[x]) === z));
@@ -2250,15 +2380,19 @@ function soundness(state, base, dragged) {
2250
2380
  if (!b.fixed) continue;
2251
2381
  const a = after.items[id];
2252
2382
  const e = a?.edge ? after.edges[a.edge] : void 0;
2253
- if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;
2383
+ if (!a || !e) return false;
2384
+ const steps = itemSteps4(state.items[id]);
2385
+ if (!steps && (a.form !== b.form || a.formKind !== b.formKind)) return false;
2386
+ if (a.inMenu) continue;
2254
2387
  const f = formsOf(state.items[id], axisOf(e.side))[a.form];
2255
2388
  const len2 = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
2256
- if (f && len2 < formMain3(f, "min", e.cross) - 0.5) return false;
2389
+ const holds = !steps && f?.main.grows === true;
2390
+ if (f && len2 < formMain2(f, holds ? "natural" : "min", e.cross) - 0.5) return false;
2257
2391
  }
2258
2392
  const me = after.items[dragged];
2259
2393
  if (!me) return true;
2260
- const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && id !== dragged).map(([id]) => reservedRect(state, after, id));
2261
- return !chrome.some((c) => overlaps(me.rect, c)) && !fixedAfter.some((f) => overlaps(me.rect, f));
2394
+ const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && !(it.inMenu && itemSteps4(state.items[id])) && id !== dragged).map(([id]) => reservedRect(state, after, id));
2395
+ return !chrome.some((c) => overlaps2(me.rect, c)) && !fixedAfter.some((f) => overlaps2(me.rect, f));
2262
2396
  };
2263
2397
  }
2264
2398
  function context(state, dragged, options, others = []) {
@@ -2288,58 +2422,72 @@ function context(state, dragged, options, others = []) {
2288
2422
  }
2289
2423
 
2290
2424
  // src/targets/ownership.ts
2291
- import { EPS as EPS14, area as area3, overlaps as overlaps2, rect as rect11, subtract as subtract2 } from "@n-uf/placement";
2292
- import { formBody } from "@n-uf/placement/stack";
2425
+ import { EPS as EPS15, area as area3, overlaps as overlaps3, rect as rect12, subtract as subtract2 } from "@n-uf/placement";
2426
+ import { formBody, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
2293
2427
 
2294
2428
  // src/targets/meet.ts
2295
- import { EPS as EPS12, rect as rect10 } from "@n-uf/placement";
2429
+ import { EPS as EPS13, rect as rect11 } from "@n-uf/placement";
2296
2430
  function meet(a, b) {
2297
2431
  const x = Math.max(a.x, b.x);
2298
2432
  const y = Math.max(a.y, b.y);
2299
2433
  const w = Math.min(a.x + a.width, b.x + b.width) - x;
2300
2434
  const h = Math.min(a.y + a.height, b.y + b.height) - y;
2301
- return w > EPS12 && h > EPS12 ? rect10(x, y, w, h) : null;
2435
+ return w > EPS13 && h > EPS13 ? rect11(x, y, w, h) : null;
2302
2436
  }
2303
2437
 
2304
2438
  // src/targets/model.ts
2305
- import { EPS as EPS13 } from "@n-uf/placement";
2306
- 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 > EPS13)), [...spans]);
2439
+ import { EPS as EPS14 } from "@n-uf/placement";
2440
+ 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]);
2307
2441
 
2308
2442
  // src/targets/ownership.ts
2309
2443
  var isBody = (f) => !!f && formBody(f);
2310
2444
  var bandOf = (s) => {
2311
2445
  const a = Math.min(...s.zones.map((z) => z.a));
2312
2446
  const b = Math.max(...s.zones.map((z) => z.b));
2313
- return s.vertical ? rect11(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect11(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);
2447
+ return s.vertical ? rect12(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect12(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);
2314
2448
  };
2315
2449
  var ownedRectOf = (s) => {
2316
2450
  const b = bandOf(s);
2317
2451
  if (!s.ownedAlong) return b;
2318
2452
  const [a0, a1] = s.ownedAlong;
2319
- return s.vertical ? rect11(b.x, a0, b.width, a1 - a0) : rect11(a0, b.y, a1 - a0, b.height);
2453
+ return s.vertical ? rect12(b.x, a0, b.width, a1 - a0) : rect12(a0, b.y, a1 - a0, b.height);
2320
2454
  };
2321
2455
  function ownedRectsOf(s, along2) {
2322
2456
  if (along2.length === 0) return [];
2323
2457
  const o = ownedRectOf(s);
2324
2458
  if (s.ownedAlong) return [o];
2325
- return along2.map(([a, b]) => s.vertical ? rect11(o.x, a, o.width, b - a) : rect11(a, o.y, b - a, o.height));
2459
+ return along2.map(([a, b]) => s.vertical ? rect12(o.x, a, o.width, b - a) : rect12(a, o.y, b - a, o.height));
2326
2460
  }
2327
2461
  function drawnOf(c, live) {
2328
- return Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS14 && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
2462
+ 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) }));
2463
+ const rails = ["left", "right"].flatMap((side) => {
2464
+ const rail = c.now.rails[side];
2465
+ if (!rail || rail.segments.length === 0 || area3(rail.rect) <= EPS15) return [];
2466
+ const spec = live.find((s) => s.kind === "railStop" && s.lay.side === side) ?? null;
2467
+ const lay = spec?.lay ?? { phase: EDGE_KINDS.railStop.phase, side, at: -1 };
2468
+ const me = c.now.items[c.dragged];
2469
+ const run = me?.rail === side ? rail.segments.filter((g) => g.edge === me.edge).map((g) => g.rect) : [];
2470
+ if (run.length === 0) return [{ spec, rect: rail.rect, lay }];
2471
+ const top = Math.min(...run.map((r) => r.y));
2472
+ const own = rect12(rail.rect.x, top, rail.rect.width, Math.max(...run.map((r) => r.y + r.height)) - top);
2473
+ const column = live.find((s) => s.kind === "railColumn" && s.edge?.id === me.edge);
2474
+ return [...subtract2(rail.rect, own).map((r) => ({ spec, rect: r, lay })), ...column ? [{ spec: column, rect: own, lay: column.lay }] : []];
2475
+ });
2476
+ return [...edges, ...rails];
2329
2477
  }
2330
2478
  function homeRectOf(c, ownSpec) {
2331
2479
  const own = c.now.items[c.dragged];
2332
2480
  if (!own || own.floating || !own.edge) return null;
2333
2481
  const o = own.rect;
2334
- const hull3 = (a, b) => rect11(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));
2482
+ const hull3 = (a, b) => rect12(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));
2335
2483
  if (own.inMenu) return o;
2336
2484
  if (!ownSpec) {
2337
2485
  const e = c.now.edges[own.edge];
2338
2486
  const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
2339
- return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS14 ? hull3(o, e.rect) : o;
2487
+ return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS15 ? hull3(o, e.rect) : o;
2340
2488
  }
2341
2489
  const [c0, c1] = ownSpec.across();
2342
- return ownSpec.vertical ? hull3(o, rect11(c0, o.y, c1 - c0, o.height)) : hull3(o, rect11(o.x, c0, o.width, c1 - c0));
2490
+ return ownSpec.vertical ? hull3(o, rect12(c0, o.y, c1 - c0, o.height)) : hull3(o, rect12(o.x, c0, o.width, c1 - c0));
2343
2491
  }
2344
2492
  function ownersOf(c, live, drawn, alongOf) {
2345
2493
  const ownEdge = c.now.items[c.dragged]?.edge;
@@ -2354,9 +2502,9 @@ function ownersOf(c, live, drawn, alongOf) {
2354
2502
  ...live.flatMap((s) => {
2355
2503
  const rects = ownedRectsOf(s, alongOf(s));
2356
2504
  if (!s.thinOwned) return rects.map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }));
2357
- const thin = (r) => s.vertical ? rect11(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) : rect11(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]));
2505
+ const thin = (r) => s.vertical ? rect12(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) : rect12(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]));
2358
2506
  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 }))]);
2359
- }).filter((o) => area3(o.rect) > EPS14),
2507
+ }).filter((o) => area3(o.rect) > EPS15),
2360
2508
  // Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
2361
2509
  ...drawn.map((d) => ({ ...d, place: false }))
2362
2510
  ];
@@ -2372,29 +2520,29 @@ function ownership(c, live, alongOf) {
2372
2520
  const place = !s.drawn;
2373
2521
  return o.place === place ? !place || o.lay.at < s.lay.at : !o.place;
2374
2522
  };
2375
- const takingRects = (s) => s.drawn ? s.zones.filter((z) => s.slots.some((sl) => sl.ok && sl.zone === z.zone)).map((z) => s.vertical ? rect11(s.owned[0], z.a, s.owned[1] - s.owned[0], z.b - z.a) : rect11(z.a, s.owned[0], z.b - z.a, s.owned[1] - s.owned[0])) : [];
2523
+ const takingRects = (s) => s.drawn ? s.zones.filter((z) => s.slots.some((sl) => sl.ok && sl.zone === z.zone)).map((z) => s.vertical ? rect12(s.owned[0], z.a, s.owned[1] - s.owned[0], z.b - z.a) : rect12(z.a, s.owned[0], z.b - z.a, s.owned[1] - s.owned[0])) : [];
2376
2524
  const thinRectOf = (s) => {
2377
2525
  const b = bandOf(s);
2378
2526
  const [t0, t1] = s.thinOwned;
2379
- return s.vertical ? rect11(t0, b.y, t1 - t0, b.height) : rect11(b.x, t0, b.width, t1 - t0);
2527
+ return s.vertical ? rect12(t0, b.y, t1 - t0, b.height) : rect12(b.x, t0, b.width, t1 - t0);
2380
2528
  };
2381
2529
  const endsOf = (s) => {
2382
2530
  const e = s.edge ? now.edges[s.id] : void 0;
2383
2531
  if (!e || EDGE_KINDS[s.kind].virtual) return null;
2384
2532
  const span = s.vertical ? [e.rect.y, e.rect.y + e.rect.height] : [e.rect.x, e.rect.x + e.rect.width];
2385
- return span[1] - span[0] > EPS14 ? span : null;
2533
+ return span[1] - span[0] > EPS15 ? span : null;
2386
2534
  };
2387
2535
  const pastEnds = (s, r) => {
2388
2536
  const ends = endsOf(s);
2389
2537
  if (!ends) return [];
2390
2538
  const [lo2, hi] = s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
2391
- return less([[lo2, hi]], [ends]).map(([u, w]) => s.vertical ? rect11(r.x, u, r.width, w - u) : rect11(u, r.y, w - u, r.height));
2539
+ return less([[lo2, hi]], [ends]).map(([u, w]) => s.vertical ? rect12(r.x, u, r.width, w - u) : rect12(u, r.y, w - u, r.height));
2392
2540
  };
2393
2541
  const ownSpanOf = (s) => {
2394
2542
  const ends = endsOf(s);
2395
2543
  if (!ends) return null;
2396
2544
  const [o0, o1] = s.owned;
2397
- return s.vertical ? rect11(o0, ends[0], o1 - o0, ends[1] - ends[0]) : rect11(ends[0], o0, ends[1] - ends[0], o1 - o0);
2545
+ return s.vertical ? rect12(o0, ends[0], o1 - o0, ends[1] - ends[0]) : rect12(ends[0], o0, ends[1] - ends[0], o1 - o0);
2398
2546
  };
2399
2547
  const reachLess = (o, r, s) => {
2400
2548
  const span = ownSpanOf(s);
@@ -2428,7 +2576,7 @@ function ownership(c, live, alongOf) {
2428
2576
  const half = e ? halfBandOf(e) : null;
2429
2577
  if (!e || half === null) return [];
2430
2578
  const column = axisOf(e.side) === "column";
2431
- 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 > EPS14);
2579
+ 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);
2432
2580
  };
2433
2581
  const rooms = /* @__PURE__ */ new Map();
2434
2582
  const cutsOf = (s) => {
@@ -2440,28 +2588,28 @@ function ownership(c, live, alongOf) {
2440
2588
  const b = bandOf(s);
2441
2589
  const along2 = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
2442
2590
  const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
2443
- const rs = taken.get(s).filter((r) => overlaps2(r, b));
2591
+ const rs = taken.get(s).filter((r) => overlaps3(r, b));
2444
2592
  const ends = [.../* @__PURE__ */ new Set([...along2(b), ...rs.flatMap(along2)])].filter((x) => x >= along2(b)[0] && x <= along2(b)[1]).sort((p, q) => p - q);
2445
2593
  const owned = [];
2446
2594
  for (let k = 1; k < ends.length; k++) {
2447
2595
  const [u, w] = [ends[k - 1], ends[k]];
2448
- const over = rs.filter((r) => along2(r)[0] <= u + EPS14 && along2(r)[1] >= w - EPS14).map(across2);
2449
- if (w - u > EPS14 && less([across2(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
2596
+ const over2 = rs.filter((r) => along2(r)[0] <= u + EPS15 && along2(r)[1] >= w - EPS15).map(across2);
2597
+ if (w - u > EPS15 && less([across2(b)], over2).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
2450
2598
  }
2451
2599
  const half = s.edge ? halfBandOf(s.edge) : null;
2452
2600
  const raw = bodySpans(s.edge);
2453
2601
  if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
2454
2602
  const merged = owned.reduce((m, [u, w]) => {
2455
2603
  const last = m[m.length - 1];
2456
- if (last && u <= last[1] + EPS14) last[1] = Math.max(last[1], w);
2604
+ if (last && u <= last[1] + EPS15) last[1] = Math.max(last[1], w);
2457
2605
  else m.push([u, w]);
2458
2606
  return m;
2459
2607
  }, []);
2460
2608
  const [lo2, hi] = endsOf(s) ?? along2(b);
2461
2609
  const placed = (p) => {
2462
- const cut2 = merged.find(([u, w]) => p >= u - EPS14 && p <= w + EPS14);
2610
+ const cut2 = merged.find(([u, w]) => p >= u - EPS15 && p <= w + EPS15);
2463
2611
  if (!cut2) return p;
2464
- const sides = [...cut2[0] > lo2 + EPS14 ? [cut2[0]] : [], ...cut2[1] < hi - EPS14 ? [cut2[1]] : []];
2612
+ const sides = [...cut2[0] > lo2 + EPS15 ? [cut2[0]] : [], ...cut2[1] < hi - EPS15 ? [cut2[1]] : []];
2465
2613
  return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
2466
2614
  };
2467
2615
  const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
@@ -2472,14 +2620,14 @@ function ownership(c, live, alongOf) {
2472
2620
  const e = it.edge ? now.edges[it.edge] : void 0;
2473
2621
  return !!e && !!formsOf(state.items[id], axisOf(e.side))[it.form]?.main.grows;
2474
2622
  };
2475
- const solid = Object.entries(now.items).filter(([id, it]) => it.fixed && !grows(id)).map(([, it]) => it.rect);
2623
+ const solid = Object.entries(now.items).filter(([id, it]) => it.fixed && !grows(id) && !(it.inMenu && itemSteps5(state.items[id]))).map(([, it]) => it.rect);
2476
2624
  const bodies = (s) => {
2477
2625
  const e = s.edge;
2478
2626
  if (!e) return [];
2479
2627
  const column = axisOf(e.side) === "column";
2480
- const across2 = (a, b) => column ? rect11(-1e9, a, 2e9, b - a) : rect11(a, -1e9, b - a, 2e9);
2628
+ const across2 = (a, b) => column ? rect12(-1e9, a, 2e9, b - a) : rect12(a, -1e9, b - a, 2e9);
2481
2629
  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));
2482
- return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS14);
2630
+ return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS15);
2483
2631
  };
2484
2632
  const drawnBySpec = /* @__PURE__ */ new Map();
2485
2633
  const drawnBesides = (s) => {
@@ -2491,13 +2639,13 @@ function ownership(c, live, alongOf) {
2491
2639
  }
2492
2640
 
2493
2641
  // src/targets/tiles.ts
2494
- import { EPS as EPS15, area as area4, overlaps as overlaps3, rect as rect12, subtract as subtract3 } from "@n-uf/placement";
2642
+ import { EPS as EPS16, area as area4, overlaps as overlaps4, rect as rect13, subtract as subtract3 } from "@n-uf/placement";
2495
2643
  function tilerOf(spec) {
2496
2644
  const data = EDGE_KINDS[spec.kind];
2497
2645
  const v = spec.vertical;
2498
2646
  const band = (a, b, after) => {
2499
2647
  const [c0, c1] = spec.across(after);
2500
- return v ? rect12(c0, a, c1 - c0, b - a) : rect12(a, c0, b - a, c1 - c0);
2648
+ return v ? rect13(c0, a, c1 - c0, b - a) : rect13(a, c0, b - a, c1 - c0);
2501
2649
  };
2502
2650
  const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
2503
2651
  const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
@@ -2505,10 +2653,10 @@ function tilerOf(spec) {
2505
2653
  const h = t.hit;
2506
2654
  const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
2507
2655
  const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
2508
- const part = (a, b) => v ? rect12(a, h.y, b - a, h.height) : rect12(h.x, a, h.width, b - a);
2656
+ const part = (a, b) => v ? rect13(a, h.y, b - a, h.height) : rect13(h.x, a, h.width, b - a);
2509
2657
  const beyond = less([[h0, h1]], [spec.owned]);
2510
2658
  if (beyond.length === 0) return [t];
2511
- if (c1 - c0 <= EPS15) return [{ ...t, order: data.overreach }];
2659
+ if (c1 - c0 <= EPS16) return [{ ...t, order: data.overreach }];
2512
2660
  const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
2513
2661
  return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
2514
2662
  };
@@ -2522,7 +2670,7 @@ function wholeRefusal(c, spec) {
2522
2670
  const data = EDGE_KINDS[spec.kind];
2523
2671
  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 };
2524
2672
  }
2525
- var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS15);
2673
+ var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS16);
2526
2674
  function linesIn(spec, z, mine, pieces, [pa, pb], own) {
2527
2675
  const reserved = spec.reserved;
2528
2676
  const lines = mine.map((s) => s.line);
@@ -2531,42 +2679,42 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
2531
2679
  const free = less([[z.a, z.b]], reserved);
2532
2680
  const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
2533
2681
  const spread = (x) => {
2534
- if (hi - lo2 <= EPS15 || freeLen <= EPS15) return x;
2682
+ if (hi - lo2 <= EPS16 || freeLen <= EPS16) return x;
2535
2683
  let d = (x - lo2) / (hi - lo2) * freeLen;
2536
2684
  for (const [a, b] of free) {
2537
- if (d <= b - a + EPS15) return a + Math.min(d, b - a);
2685
+ if (d <= b - a + EPS16) return a + Math.min(d, b - a);
2538
2686
  d -= b - a;
2539
2687
  }
2540
2688
  return free[free.length - 1][1];
2541
2689
  };
2542
- const past = lines.some((x) => x < z.a - EPS15 || x > z.b + EPS15);
2690
+ const past = lines.some((x) => x < z.a - EPS16 || x > z.b + EPS16);
2543
2691
  const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
2544
2692
  const proj = (x) => {
2545
2693
  const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
2546
2694
  const p = own ? nearer(q, own) : q;
2547
- if (pieces.some(([a, b]) => p >= a - EPS15 && p <= b + EPS15)) return p;
2695
+ if (pieces.some(([a, b]) => p >= a - EPS16 && p <= b + EPS16)) return p;
2548
2696
  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);
2549
2697
  };
2550
- const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS15 || Math.abs(s.line - own[1]) < EPS15);
2551
- const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS15 && s.line <= pb + EPS15 : proj(s.line) >= pa - EPS15 && proj(s.line) <= pb + EPS15).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
2698
+ const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS16 || Math.abs(s.line - own[1]) < EPS16);
2699
+ 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);
2552
2700
  const projected = inPiece.map((s) => proj(s.line));
2553
- const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS15) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
2701
+ 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;
2554
2702
  return { inPiece, at };
2555
2703
  }
2556
2704
  function reachStrips(c, spec, room, ends) {
2557
- const inEdge = (s) => !!ends && s[0] < ends[1] - EPS15 && s[1] > ends[0] + EPS15;
2705
+ const inEdge = (s) => !!ends && s[0] < ends[1] - EPS16 && s[1] > ends[0] + EPS16;
2558
2706
  const pieces = room.filter(inEdge);
2559
2707
  if (!ends || pieces.length === 0) return { pieces: [...room], before: [], after: [] };
2560
2708
  const [c0, c1] = spec.across();
2561
- const bandOf2 = (a, b) => spec.vertical ? rect12(c0, a, c1 - c0, b - a) : rect12(a, c0, b - a, c1 - c0);
2709
+ const bandOf2 = (a, b) => spec.vertical ? rect13(c0, a, c1 - c0, b - a) : rect13(a, c0, b - a, c1 - c0);
2562
2710
  const across2 = c.state.edges.filter((e) => axisOf(e.side) === "column" !== spec.vertical).map((e) => c.now.edges[e.id]);
2563
- const drawnBetween = (a, b) => b - a > EPS15 && across2.some((e) => !!e && e.cross > EPS15 && area4(e.rect) > EPS15 && overlaps3(e.rect, bandOf2(a, b)));
2711
+ const drawnBetween = (a, b) => b - a > EPS16 && across2.some((e) => !!e && e.cross > EPS16 && area4(e.rect) > EPS16 && overlaps4(e.rect, bandOf2(a, b)));
2564
2712
  const first = pieces[0][0];
2565
2713
  const last = pieces[pieces.length - 1][1];
2566
2714
  return {
2567
2715
  pieces,
2568
- before: room.filter((s) => s[1] <= ends[0] + EPS15 && !drawnBetween(s[1], first)),
2569
- after: room.filter((s) => s[0] >= ends[1] - EPS15 && !drawnBetween(last, s[0]))
2716
+ before: room.filter((s) => s[1] <= ends[0] + EPS16 && !drawnBetween(s[1], first)),
2717
+ after: room.filter((s) => s[0] >= ends[1] - EPS16 && !drawnBetween(last, s[0]))
2570
2718
  };
2571
2719
  }
2572
2720
  function tileEdge(c, spec, { cuts, bodies }, lost) {
@@ -2577,7 +2725,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2577
2725
  const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
2578
2726
  const { band, keepAt, tile, split } = tilerOf(spec);
2579
2727
  const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
2580
- const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS15 ? v ? rect12(-1e9, drawn.y, 2e9, drawn.height) : rect12(drawn.x, -1e9, drawn.width, 2e9) : null;
2728
+ const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS16 ? v ? rect13(-1e9, drawn.y, 2e9, drawn.height) : rect13(drawn.x, -1e9, drawn.width, 2e9) : null;
2581
2729
  const refused = (zone, hit, reason) => {
2582
2730
  const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
2583
2731
  const shown = inEdge && meet(inEdge, c.state.stage);
@@ -2586,27 +2734,27 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2586
2734
  const slots = distinctSlots(c, spec.slots);
2587
2735
  const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
2588
2736
  const last = acc[acc.length - 1];
2589
- if (last && a <= last[1] + EPS15) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
2737
+ if (last && a <= last[1] + EPS16) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
2590
2738
  else acc.push([a, b]);
2591
2739
  return acc;
2592
2740
  }, []);
2593
- const wedged = (line) => runs.some(([a, b]) => line > a + EPS15 && line < b - EPS15);
2741
+ const wedged = (line) => runs.some(([a, b]) => line > a + EPS16 && line < b - EPS16);
2594
2742
  const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
2595
2743
  const ends = alongLimit && drawn ? v ? [drawn.y, drawn.y + drawn.height] : [drawn.x, drawn.x + drawn.width] : null;
2596
2744
  const out = [];
2597
2745
  for (const z of spec.zones) {
2598
- const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS15);
2746
+ const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS16);
2599
2747
  const { pieces, before, after } = reachStrips(c, spec, own ? less(room, [own]) : room, ends);
2600
2748
  if (!hasRoom(pieces, bodies)) continue;
2601
2749
  const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
2602
- const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS15 && a < s.line + data.reach - EPS15));
2750
+ 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));
2603
2751
  const reason = spec.refuse(z.zone);
2604
2752
  for (const [k, [pa, pb]] of pieces.entries()) {
2605
2753
  const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
2606
2754
  const stripsOf = (i) => [...k === 0 && i === 0 ? before : [], ...k === pieces.length - 1 && i === inPiece.length - 1 ? after : []];
2607
2755
  if (inPiece.length === 0) {
2608
2756
  const lone = (reason === "no-room" || reason === "too-thick") && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
2609
- const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS15 && pa < s.line + data.reach - EPS15);
2757
+ const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS16 && pa < s.line + data.reach - EPS16);
2610
2758
  const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
2611
2759
  if (joins.length > 0) {
2612
2760
  const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
@@ -2619,29 +2767,29 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2619
2767
  }
2620
2768
  const meet2 = (i) => {
2621
2769
  const [lo2, hi] = [at[i - 1], at[i]];
2622
- const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS15 && w <= inPiece[i].line + EPS15);
2770
+ const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS16 && w <= inPiece[i].line + EPS16);
2623
2771
  const mid2 = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
2624
- return mid2 > lo2 + EPS15 && mid2 < hi - EPS15 ? mid2 : (lo2 + hi) / 2;
2772
+ return mid2 > lo2 + EPS16 && mid2 < hi - EPS16 ? mid2 : (lo2 + hi) / 2;
2625
2773
  };
2626
2774
  inPiece.forEach((s, i) => {
2627
2775
  const p = at[i];
2628
2776
  const lim = data.virtual ? Infinity : data.reach;
2629
2777
  const a = Math.max(i === 0 ? pa : meet2(i), p - lim);
2630
2778
  const b = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
2631
- if (b - a <= EPS15) {
2779
+ if (b - a <= EPS16) {
2632
2780
  if (s.ok && !s.home) lost.push(s.id);
2633
2781
  return;
2634
2782
  }
2635
2783
  if (!hasRoom([[a, b]], bodies)) return;
2636
2784
  const homeTile = (id, u, w, line) => {
2637
2785
  const hit = band(u, w, s.home ? s.result.layout : void 0);
2638
- return tile(z.zone, hit, { kind: "home", id, order: data.layer, priority: data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: "home" } });
2786
+ 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" } });
2639
2787
  };
2640
2788
  if (s.home) {
2641
2789
  for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.id, u, w, p)));
2642
2790
  return;
2643
2791
  }
2644
- const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS15 && u < b - EPS15) : [];
2792
+ const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS16 && u < b - EPS16) : [];
2645
2793
  for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
2646
2794
  for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
2647
2795
  const line = Math.min(Math.max(p, u), w);
@@ -2657,7 +2805,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
2657
2805
  const [a, b] = own;
2658
2806
  const h = band(a, b);
2659
2807
  const o = spec.own;
2660
- const hit = v ? rect12(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) : rect12(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));
2808
+ const hit = v ? rect13(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) : rect13(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));
2661
2809
  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" } }));
2662
2810
  }
2663
2811
  return out;
@@ -2675,7 +2823,7 @@ function placeReach(t, pieces, placed, landed, gone) {
2675
2823
  if (at.length === 0 && gone.has(of)) {
2676
2824
  const line = t.vertical ? of.keep.y : of.keep.x;
2677
2825
  const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
2678
- const on = whole.filter((p) => t.vertical ? p.y <= line + EPS15 && line <= p.y + p.height + EPS15 : p.x <= line + EPS15 && line <= p.x + p.width + EPS15);
2826
+ 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);
2679
2827
  const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area4(p) > area4(a) ? p : a, null);
2680
2828
  if (kept) {
2681
2829
  placed.push({ ...of, hit: kept });
@@ -2688,10 +2836,10 @@ function placeReach(t, pieces, placed, landed, gone) {
2688
2836
  for (let k = 0; k < cover.length; k++) {
2689
2837
  const h = cover[k];
2690
2838
  const joint = pieces.find(
2691
- (p) => t.vertical ? p.y <= h.y + EPS15 && p.y + p.height >= h.y + h.height - EPS15 && (Math.abs(p.x - h.x - h.width) < EPS15 || Math.abs(p.x + p.width - h.x) < EPS15) : p.x <= h.x + EPS15 && p.x + p.width >= h.x + h.width - EPS15 && (Math.abs(p.y - h.y - h.height) < EPS15 || Math.abs(p.y + p.height - h.y) < EPS15)
2839
+ (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)
2692
2840
  );
2693
2841
  if (!joint) continue;
2694
- const merged = t.vertical ? rect12(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) : rect12(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));
2842
+ const merged = t.vertical ? rect13(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) : rect13(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));
2695
2843
  placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
2696
2844
  return;
2697
2845
  }
@@ -2759,10 +2907,10 @@ function clipTiles(tiles, own, chrome, lost) {
2759
2907
  }
2760
2908
 
2761
2909
  // src/targets/rail-strip.ts
2762
- import { EPS as EPS17, overlaps as overlaps4, rect as rect14, subtract as subtract4 } from "@n-uf/placement";
2910
+ import { EPS as EPS18, overlaps as overlaps5, rect as rect15, subtract as subtract4 } from "@n-uf/placement";
2763
2911
 
2764
2912
  // src/targets/virtual.ts
2765
- import { EPS as EPS16, clamp, rect as rect13 } from "@n-uf/placement";
2913
+ import { EPS as EPS17, clamp, rect as rect14 } from "@n-uf/placement";
2766
2914
  function ringsOf(c, side) {
2767
2915
  const seen = sideRings(c.state.edges, side);
2768
2916
  const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
@@ -2775,7 +2923,7 @@ function railOuter(c, side) {
2775
2923
  const windowEdge = side === "left" ? state.stage.x : state.stage.x + state.stage.width;
2776
2924
  if (!place) return windowEdge;
2777
2925
  const placeOuter = side === "left" ? place.x : place.x + place.width;
2778
- 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 + EPS16 : e.rect.x >= placeOuter - EPS16));
2926
+ 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));
2779
2927
  return barOutside ? placeOuter : windowEdge;
2780
2928
  }
2781
2929
  function collapsesAt(c, result, side) {
@@ -2806,10 +2954,10 @@ function columnLines(c, side, railLands) {
2806
2954
  const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
2807
2955
  const stage = c.state.stage;
2808
2956
  const dir = side === "left" ? 1 : -1;
2809
- 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 + EPS16 : e.rect.x >= x - EPS16));
2957
+ 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));
2810
2958
  const railFirst = railLands && !!c.state.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
2811
2959
  const placeOf = (l, i) => {
2812
- const atEdge = side === "left" ? l.x <= stage.x + EPS16 : l.x >= stage.x + stage.width - EPS16;
2960
+ const atEdge = side === "left" ? l.x <= stage.x + EPS17 : l.x >= stage.x + stage.width - EPS17;
2813
2961
  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] };
2814
2962
  const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
2815
2963
  const boundary = clamp(l.x, stage.x, stage.x + stage.width);
@@ -2840,7 +2988,7 @@ function columnLines(c, side, railLands) {
2840
2988
  ownedAlong: p.owned,
2841
2989
  drawn: false,
2842
2990
  // Where the new column's edge lands: the line itself, inside the stage.
2843
- marker: () => rect13(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
2991
+ marker: () => rect14(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
2844
2992
  };
2845
2993
  });
2846
2994
  }
@@ -2857,6 +3005,21 @@ function railEnd(c, side, segments, y) {
2857
3005
  };
2858
3006
  return slotAt(c, "start", y, targetId(place), place, lands);
2859
3007
  }
3008
+ function ownColumnRun(c, side, rail) {
3009
+ const { state, now, dragged } = c;
3010
+ const me = now.items[dragged];
3011
+ const shown = now.rails[side];
3012
+ const edge = me?.rail === side ? state.edges.find((e) => e.id === me.edge) : void 0;
3013
+ const homeId = rail.slots.find((s) => s.home)?.id;
3014
+ if (!shown || !edge || homeId === void 0) return null;
3015
+ const tiles = shown.segments.filter((s) => s.edge === edge.id).map((s) => s.rect);
3016
+ if (tiles.length === 0) return null;
3017
+ const top = Math.min(...tiles.map((r) => r.y));
3018
+ const spec = railColumnSpec(c, edge, rect14(shown.rect.x, top, shown.rect.width, Math.max(...tiles.map((r) => r.y + r.height)) - top));
3019
+ if (!spec) return null;
3020
+ const stays = ({ layout }) => layout.items[dragged]?.rail === side && layout.items[dragged]?.edge === edge.id;
3021
+ 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) }) };
3022
+ }
2860
3023
  function railStops(c, side) {
2861
3024
  const { state, now, dragged } = c;
2862
3025
  const rail = now.rails[side];
@@ -2890,7 +3053,7 @@ function railStops(c, side) {
2890
3053
  } else {
2891
3054
  const firstCol = mine.find((e) => e.column === true);
2892
3055
  const outer = railOuter(c, side);
2893
- zone = rect13(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
3056
+ zone = rect14(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
2894
3057
  stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
2895
3058
  }
2896
3059
  const ownRail = now.items[dragged]?.rail === side;
@@ -2921,7 +3084,7 @@ function railStops(c, side) {
2921
3084
  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],
2922
3085
  ownedAlong: null,
2923
3086
  drawn: !!rail && rail.segments.length > 0,
2924
- marker: (s) => rect13(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
3087
+ marker: (s) => rect14(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
2925
3088
  };
2926
3089
  }
2927
3090
 
@@ -2937,11 +3100,11 @@ function columnStrip(c, side, policy) {
2937
3100
  if (moved === c.state) return null;
2938
3101
  const result = c.settle(markUsed(moved, c.dragged));
2939
3102
  const el = result.layout.edges[edge.id];
2940
- if (!el || el.rect.width <= EPS17 || !collapsesAt(c, result, side)) return null;
3103
+ if (!el || el.rect.width <= EPS18 || !collapsesAt(c, result, side)) return null;
2941
3104
  const r = el.rect;
2942
3105
  const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
2943
3106
  const [x, w] = across(side, side === "left" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));
2944
- return { side, rect: rect14(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
3107
+ return { side, rect: rect15(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
2945
3108
  }
2946
3109
  function declaredStrip(c, side, policy) {
2947
3110
  const template = c.state.columns?.[side];
@@ -2958,11 +3121,11 @@ function declaredStrip(c, side, policy) {
2958
3121
  const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
2959
3122
  return {
2960
3123
  side,
2961
- rect: rect14(x, a, w, b - a),
3124
+ rect: rect15(x, a, w, b - a),
2962
3125
  slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
2963
3126
  };
2964
3127
  }
2965
- var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => overlaps4(p, s) ? subtract4(p, s) : [p]), [...pieces]).filter((p) => p.width >= 1 && p.height >= 1);
3128
+ var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => overlaps5(p, s) ? subtract4(p, s) : [p]), [...pieces]).filter((p) => p.width >= 1 && p.height >= 1);
2966
3129
  var largest2 = (rs) => rs.reduce((m, r) => r.width * r.height > m.width * m.height ? r : m);
2967
3130
  var sameRects = (a, b) => a.length === b.length && a.every((r, i) => r.x === b[i].x && r.y === b[i].y && r.width === b[i].width && r.height === b[i].height);
2968
3131
  function withRailStrips(c, targets2, refusals2) {
@@ -3043,7 +3206,7 @@ ${r.zone}`) ?? [], r]);
3043
3206
  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 })));
3044
3207
  const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
3045
3208
  for (const s of strips) {
3046
- const grown = s.side === "left" ? rect14(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect14(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
3209
+ const grown = s.side === "left" ? rect15(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect15(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
3047
3210
  for (const sl of s.slots) {
3048
3211
  const [a, b] = sl.along;
3049
3212
  const slot = sl.result.layout.items[c.dragged].rect;
@@ -3051,8 +3214,8 @@ ${r.zone}`) ?? [], r]);
3051
3214
  out.push({
3052
3215
  id: sl.id,
3053
3216
  priority: 1,
3054
- hit: rect14(s.rect.x, a, s.rect.width, b - a),
3055
- armedHit: rect14(grown.x, a, grown.width, b - a),
3217
+ hit: rect15(s.rect.x, a, s.rect.width, b - a),
3218
+ armedHit: rect15(grown.x, a, grown.width, b - a),
3056
3219
  arm: "dwell",
3057
3220
  // Armed, its room opens at once: a host that draws only a marker reads that from this one flag, as for any target.
3058
3221
  opensRoom: true,
@@ -3071,9 +3234,9 @@ var withoutHits = (t) => {
3071
3234
  return rest;
3072
3235
  };
3073
3236
  function insideStrips(r, strips) {
3074
- const s = strips.find((x) => overlaps4(x.rect, r));
3237
+ const s = strips.find((x) => overlaps5(x.rect, r));
3075
3238
  if (!s) return null;
3076
- return s.side === "left" ? rect14(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect14(s.rect.x - r.width, r.y, r.width, r.height);
3239
+ return s.side === "left" ? rect15(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect15(s.rect.x - r.width, r.y, r.width, r.height);
3077
3240
  }
3078
3241
  function clearOfStrips(t, dragged, strips) {
3079
3242
  return {
@@ -3084,8 +3247,8 @@ function clearOfStrips(t, dragged, strips) {
3084
3247
  if (!at) return first;
3085
3248
  let dx = 0;
3086
3249
  for (const s of strips) {
3087
- const r = rect14(at.x + dx, at.y, at.width, at.height);
3088
- if (!overlaps4(r, s)) continue;
3250
+ const r = rect15(at.x + dx, at.y, at.width, at.height);
3251
+ if (!overlaps5(r, s)) continue;
3089
3252
  dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
3090
3253
  }
3091
3254
  return dx === 0 ? first : t.after({ x: at.x + dx + (grab?.x ?? at.width / 2), y: point.y }, grab);
@@ -3094,7 +3257,7 @@ function clearOfStrips(t, dragged, strips) {
3094
3257
  }
3095
3258
 
3096
3259
  // src/targets/min-hit.ts
3097
- import { EPS as EPS18, area as area5, rect as rect15, subtract as subtract5 } from "@n-uf/placement";
3260
+ import { EPS as EPS19, area as area5, rect as rect16, subtract as subtract5 } from "@n-uf/placement";
3098
3261
  function kindOf(c, t) {
3099
3262
  const p = parseTargetId(t.id);
3100
3263
  if (!p) return null;
@@ -3107,8 +3270,8 @@ function kindOf(c, t) {
3107
3270
  return null;
3108
3271
  }
3109
3272
  var largest3 = (ps) => ps.reduce((a, p) => area5(p) > area5(a) ? p : a);
3110
- var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS18 && Math.max(r.width, r.height) >= m.along - EPS18;
3111
- var overlaps5 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS18 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS18;
3273
+ var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS19 && Math.max(r.width, r.height) >= m.along - EPS19;
3274
+ 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;
3112
3275
  var cut = (ps, g) => ps.flatMap((p) => subtract5(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
3113
3276
  var piecesOf = (t) => t.hits ?? [t.hit];
3114
3277
  var withPieces2 = (t, ps) => {
@@ -3116,25 +3279,25 @@ var withPieces2 = (t, ps) => {
3116
3279
  return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
3117
3280
  };
3118
3281
  function growths(r, axis, d) {
3119
- const [lo2, hi] = axis === "x" ? [rect15(r.x - d, r.y, d, r.height), rect15(r.x + r.width, r.y, d, r.height)] : [rect15(r.x, r.y - d, r.width, d), rect15(r.x, r.y + r.height, r.width, d)];
3282
+ const [lo2, hi] = axis === "x" ? [rect16(r.x - d, r.y, d, r.height), rect16(r.x + r.width, r.y, d, r.height)] : [rect16(r.x, r.y - d, r.width, d), rect16(r.x, r.y + r.height, r.width, d)];
3120
3283
  const h = d / 2;
3121
- const halves = axis === "x" ? [rect15(r.x - h, r.y, h, r.height), rect15(r.x + r.width, r.y, h, r.height)] : [rect15(r.x, r.y - h, r.width, h), rect15(r.x, r.y + r.height, r.width, h)];
3284
+ const halves = axis === "x" ? [rect16(r.x - h, r.y, h, r.height), rect16(r.x + r.width, r.y, h, r.height)] : [rect16(r.x, r.y - h, r.width, h), rect16(r.x, r.y + r.height, r.width, h)];
3122
3285
  return [[lo2], [hi], halves];
3123
3286
  }
3124
3287
  var union = (a, gs) => {
3125
3288
  const x0 = Math.min(a.x, ...gs.map((g) => g.x));
3126
3289
  const y0 = Math.min(a.y, ...gs.map((g) => g.y));
3127
- return rect15(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);
3290
+ return rect16(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);
3128
3291
  };
3129
3292
  function mayGrow(c, targets2, i, grow, minOf, zone, away) {
3130
3293
  const s = c.state.stage;
3131
3294
  for (const g of grow) {
3132
- if (g.x < s.x - EPS18 || g.y < s.y - EPS18 || g.x + g.width > s.x + s.width + EPS18 || g.y + g.height > s.y + s.height + EPS18) return false;
3133
- if ([...keepClearFor(c.state, "targets"), ...away].some((r) => overlaps5(r, g))) return false;
3134
- if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS18)) return false;
3295
+ 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;
3296
+ if ([...keepClearFor(c.state, "targets"), ...away].some((r) => overlaps6(r, g))) return false;
3297
+ if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS19)) return false;
3135
3298
  }
3136
3299
  return targets2.every((o, j) => {
3137
- if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps5(p, g)))) return true;
3300
+ if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps6(p, g)))) return true;
3138
3301
  if (o.place.kind === "home" || o.place.kind === "none" || o.strip) return false;
3139
3302
  const m = minOf(o);
3140
3303
  const left = grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]);
@@ -3146,11 +3309,11 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
3146
3309
  let best = null;
3147
3310
  for (const [side] of growths(l, axis, d)) {
3148
3311
  const g = side;
3149
- const strip = (a, b) => axis === "x" ? rect15(g.x, a, g.width, b - a) : rect15(a, g.y, b - a, g.height);
3312
+ const strip = (a, b) => axis === "x" ? rect16(g.x, a, g.width, b - a) : rect16(a, g.y, b - a, g.height);
3150
3313
  const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
3151
3314
  for (const o of targets2)
3152
3315
  for (const p of piecesOf(o))
3153
- if (overlaps5(p, g)) {
3316
+ if (overlaps6(p, g)) {
3154
3317
  for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along2[0] && v < along2[1]) cuts.add(v);
3155
3318
  }
3156
3319
  const marks = [...cuts].sort((a, b) => a - b);
@@ -3166,7 +3329,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
3166
3329
  }
3167
3330
  if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
3168
3331
  for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
3169
- if (b - a < m.along - EPS18) break;
3332
+ if (b - a < m.along - EPS19) break;
3170
3333
  const r = strip(a, b);
3171
3334
  if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area5(r) > area5(best))) best = r;
3172
3335
  break;
@@ -3181,7 +3344,7 @@ function withMinHit(c, targets2, refusals2, zones) {
3181
3344
  const k = kindOf(c, t);
3182
3345
  return k ? EDGE_KINDS[k].minHit : null;
3183
3346
  };
3184
- const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS18 && e.rect.height > EPS18);
3347
+ const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS19 && e.rect.height > EPS19);
3185
3348
  for (let i = 0; i < out.length; i++) {
3186
3349
  const t = out[i];
3187
3350
  const m = minOf(t);
@@ -3198,18 +3361,18 @@ function withMinHit(c, targets2, refusals2, zones) {
3198
3361
  const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
3199
3362
  const size = axis === "x" ? l.width : l.height;
3200
3363
  const d = (step === "across" ? m.across : m.along) - size;
3201
- if (d <= EPS18) continue;
3364
+ if (d <= EPS19) continue;
3202
3365
  let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
3203
3366
  if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
3204
3367
  if (!grow) continue;
3205
3368
  for (let j = 0; j < out.length; j++) {
3206
3369
  if (j === i || out[j].free) continue;
3207
3370
  const o = out[j];
3208
- if (!piecesOf(o).some((p) => grow.some((g) => overlaps5(p, g)))) continue;
3371
+ if (!piecesOf(o).some((p) => grow.some((g) => overlaps6(p, g)))) continue;
3209
3372
  out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
3210
3373
  }
3211
3374
  const g0 = grow[0];
3212
- const span = axis === "x" ? rect15(l.x, g0.y, l.width, g0.height) : rect15(g0.x, l.y, g0.width, l.height);
3375
+ const span = axis === "x" ? rect16(l.x, g0.y, l.width, g0.height) : rect16(g0.x, l.y, g0.width, l.height);
3213
3376
  const grown = union(span, grow);
3214
3377
  const others = piecesOf(out[i]).filter((p) => p !== l);
3215
3378
  out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
@@ -3229,6 +3392,7 @@ function specsOf(c, kind) {
3229
3392
  const rail = state.rails?.[side]?.accepts.includes(kind) ? railStops(c, side) : null;
3230
3393
  specs.push(...columnLines(c, side, !!rail?.slots.some((s) => s.ok)));
3231
3394
  specs.push(rail);
3395
+ if (rail) specs.push(ownColumnRun(c, side, rail));
3232
3396
  }
3233
3397
  return specs.filter((s) => s !== null);
3234
3398
  }
@@ -3281,22 +3445,22 @@ function emit2(c, placed) {
3281
3445
  function hull(a, b) {
3282
3446
  const x = Math.min(a.x, b.x);
3283
3447
  const y = Math.min(a.y, b.y);
3284
- return rect16(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3448
+ return rect17(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3285
3449
  }
3286
3450
  var thicknessChanges = (now, after) => {
3287
3451
  const a = now.content;
3288
3452
  const b = after.content;
3289
- return Math.abs(b.x - a.x) > EPS19 || Math.abs(b.y - a.y) > EPS19 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS19 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS19;
3453
+ 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;
3290
3454
  };
3291
3455
  var WINDOW_EDGE_KINDS = /* @__PURE__ */ new Set(["rail", "railStop", "sideBar", "columnLine"]);
3292
- var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS19 || r.x + r.width >= stage.x + stage.width - EPS19);
3456
+ var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS20 || r.x + r.width >= stage.x + stage.width - EPS20);
3293
3457
  function slotOverMoved(now, lifted, after, slot, dragged, onto) {
3294
3458
  const from = now.items[dragged]?.edge;
3295
3459
  return Object.entries(now.items).some(([id, was]) => {
3296
- if (!overlaps6(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
3460
+ if (!overlaps7(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
3297
3461
  const r = after.items[id]?.rect;
3298
3462
  const start = (from !== void 0 && was.edge === from ? lifted.items[id]?.rect : void 0) ?? was.rect;
3299
- return !!r && (Math.abs(r.x - start.x) > EPS19 || Math.abs(r.y - start.y) > EPS19 || Math.abs(r.width - start.width) > EPS19 || Math.abs(r.height - start.height) > EPS19);
3463
+ 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);
3300
3464
  });
3301
3465
  }
3302
3466
  function alongOfSlots(s, tiles) {
@@ -3373,15 +3537,27 @@ function generateShown(state, dragged, options, hidden) {
3373
3537
  place: { kind: "float" },
3374
3538
  after(point, grab) {
3375
3539
  const g = grab ?? { x: size.width / 2, y: size.height / 2 };
3376
- const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect16(point.x - g.x, point.y - g.y, size.width, size.height);
3540
+ const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect17(point.x - g.x, point.y - g.y, size.width, size.height);
3377
3541
  const first = solve(markUsed(floatAt(state, dragged, raw, options.floatOrient), dragged), prev);
3378
- const at = first.items[dragged]?.rect ?? raw;
3379
- return c.settle(markUsed(floatAt(state, dragged, rect16(at.x, at.y, size.width, size.height), options.floatOrient), dragged));
3542
+ const fitted = first.items[dragged]?.rect;
3543
+ const at = fitted ?? raw;
3544
+ const placed2 = (x, y, stays) => {
3545
+ const s = floatAt(state, dragged, rect17(x, y, size.width, size.height), options.floatOrient);
3546
+ return c.settle(markUsed(stays ? { ...s, floats: s.floats.map((f) => f.id === dragged ? { ...f, stays: true } : f) } : s, dragged));
3547
+ };
3548
+ const hand = heldRect(state, dragged, fitted ?? size, point, g);
3549
+ const on = { x: clamp2(point.x, hand.x, hand.x + hand.width), y: clamp2(point.y, hand.y, hand.y + hand.height) };
3550
+ const clear = !first.notes.some((n) => n.code === "float-covers" && n.id === dragged);
3551
+ if (!fitted || clear && contains(fitted, on)) return placed2(at.x, at.y, false);
3552
+ const left = placed2(hand.x, hand.y, true);
3553
+ const covers = left.layout.notes.some((n) => n.code === "float-covers" && n.id === dragged);
3554
+ const kept = left.layout.items[dragged]?.rect ?? hand;
3555
+ return covers ? left : placed2(kept.x, kept.y, false);
3380
3556
  }
3381
3557
  });
3382
3558
  }
3383
3559
  (state.blocked ?? []).forEach((b, i) => {
3384
- targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect16(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
3560
+ targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect17(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
3385
3561
  });
3386
3562
  const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
3387
3563
  const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
@@ -3404,7 +3580,7 @@ function generateShown(state, dragged, options, hidden) {
3404
3580
  const held = withMinHit(c, layered.targets, layered.refusals, zones).map((t) => t.roomHit && t.slot ? { ...t, roomHit: hull(t.hit, t.slot) } : t);
3405
3581
  return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones };
3406
3582
  }
3407
- var stageOf = (state) => rect16(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
3583
+ var stageOf = (state) => rect17(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
3408
3584
  function targets(state, dragged, options = {}) {
3409
3585
  return generate(state, dragged, options).targets;
3410
3586
  }
@@ -3463,7 +3639,8 @@ function orderedStops(state, dragged, options) {
3463
3639
  }
3464
3640
 
3465
3641
  // src/lanes.ts
3466
- import { EPS as EPS20, clamp as clamp2, rect as rect17 } from "@n-uf/placement";
3642
+ import { EPS as EPS21, area as area7, clamp as clamp3, rect as rect18, subtract as subtract6 } from "@n-uf/placement";
3643
+ import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
3467
3644
  var SPOT_PITCH = 40;
3468
3645
  var SNAP_DISTANCE = 8;
3469
3646
  var STEP = 1;
@@ -3473,13 +3650,13 @@ var len = (r, axis) => axis === "x" ? r.width : r.height;
3473
3650
  var hull2 = (a, b) => {
3474
3651
  const x = Math.min(a.x, b.x);
3475
3652
  const y = Math.min(a.y, b.y);
3476
- return rect17(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
3653
+ 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);
3477
3654
  };
3478
3655
  var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
3479
3656
  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;
3480
3657
  var ORIGIN = { x: 0, y: 0 };
3481
3658
  function onEdge(l, edge, dragged, axis) {
3482
- return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS20 && it.rect.height > EPS20).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
3659
+ 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));
3483
3660
  }
3484
3661
  function neighbors(after, edge, dragged, axis) {
3485
3662
  const me = after.items[dragged];
@@ -3511,19 +3688,19 @@ function clipAtDrawn(band, axis, cuts) {
3511
3688
  const x = axis === "x" ? "y" : "x";
3512
3689
  const line = lo(band, x) + len(band, x) / 2;
3513
3690
  for (const c of cuts) {
3514
- if (!(lo(c, x) < line - EPS20 && line < lo(c, x) + len(c, x) - EPS20)) continue;
3691
+ if (!(lo(c, x) < line - EPS21 && line < lo(c, x) + len(c, x) - EPS21)) continue;
3515
3692
  const c0 = lo(c, axis);
3516
3693
  const c1 = c0 + len(c, axis);
3517
3694
  if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
3518
3695
  else b = Math.min(b, c0);
3519
3696
  }
3520
- return b - a > EPS20 ? along(band, axis, a, b) : band;
3697
+ return b - a > EPS21 ? along(band, axis, a, b) : band;
3521
3698
  }
3522
3699
  var memo = /* @__PURE__ */ new WeakMap();
3523
3700
  var previousIds = /* @__PURE__ */ new WeakMap();
3524
3701
  var nextPrevious = 1;
3525
3702
  function keyOf(dragged, o) {
3526
- const { previous, spot: _spot, ...rest } = o;
3703
+ const { previous, ...rest } = o;
3527
3704
  let p = 0;
3528
3705
  if (previous) {
3529
3706
  if (!previousIds.has(previous)) previousIds.set(previous, nextPrevious++);
@@ -3532,40 +3709,47 @@ function keyOf(dragged, o) {
3532
3709
  return `${dragged}\0${p}\0${JSON.stringify(rest)}`;
3533
3710
  }
3534
3711
  function lanes(state, dragged, options = {}) {
3712
+ const base = baseOf(state, dragged, options);
3713
+ return { ...base.regions, lanes: base.lanes };
3714
+ }
3715
+ function baseOf(state, dragged, options = {}) {
3535
3716
  const key = keyOf(dragged, options);
3536
3717
  let perState = memo.get(state);
3537
3718
  if (!perState) memo.set(state, perState = /* @__PURE__ */ new Map());
3538
3719
  let base = perState.get(key);
3539
3720
  if (!base) perState.set(key, base = build(state, dragged, options));
3540
- if (!options.spot) return { ...base.regions, lanes: base.lanes };
3541
- const found = [...base.raws].find(([, rs]) => rs.some((r) => r.id === options.spot));
3542
- if (!found) return { ...base.regions, lanes: base.lanes };
3543
- const [heldLane, list] = found;
3544
- const held = list.find((r) => r.id === options.spot);
3545
- const rebuilt = base.lanes.map((l) => {
3721
+ return base;
3722
+ }
3723
+ function marksIn(base, state, dragged, layout, held, emptyLanes) {
3724
+ const heldEdge = held ? layout.items[dragged] : void 0;
3725
+ const on = heldEdge && !heldEdge.floating && !heldEdge.inMenu ? heldEdge.edge : void 0;
3726
+ const built = base.lanes.flatMap((l) => {
3546
3727
  const raws = base.raws.get(l.id);
3547
- if (!raws) return asDrawn(l);
3548
- const again = l.id === heldLane ? heldLaneIn(l.id, raws, held, base, dragged) : laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, false, true);
3549
- if (!again) return asDrawn(l);
3550
- return l.id === heldLane ? again : { ...asDrawn(l), marks: again.marks };
3728
+ const again = raws ? laneFrom(l.id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, l.id === on, l.id === on && held === "slide" ? MIN_BOX : void 0) : null;
3729
+ return again ? [{ lane: again, over: laneRectOver(raws, layout, base.marking).rect }] : [];
3551
3730
  });
3552
- const drawn = rebuilt.map((l) => settle(l, held.layout, state, dragged, rebuilt, options.emptyLanes, base.raws.get(l.id) ? laneRectOver(base.raws.get(l.id), held.layout, base.seen, base.marking).rect : l.rect));
3553
- const heldMarks = drawn.find((l) => l.id === heldLane)?.marks.map((m) => m.rect) ?? [];
3554
- return {
3555
- ...base.regions,
3556
- lanes: drawn.map((l, i) => {
3557
- if (l.id === heldLane || !base.predicted.has(l.id)) return l;
3558
- return { ...l, marks: marksLess(base.lanes[i].marks, l.axis, heldMarks) };
3559
- })
3560
- };
3731
+ const over2 = built.map(({ lane, over: r }) => ({ ...lane, rect: r }));
3732
+ const settled = built.map(({ lane, over: r }) => {
3733
+ const s = settle(lane, layout, state, dragged, over2, emptyLanes, r);
3734
+ return { lane: s.id, axis: s.axis, marks: s.marks };
3735
+ });
3736
+ return newColumnsGiveWay(settled, (s) => s.lane, state);
3561
3737
  }
3562
- function asDrawn(l) {
3563
- if (!l.entry && !l.corners) return l;
3564
- const { entry: _entry, corners: _corners, ...rest } = l;
3565
- return rest;
3738
+ function newColumnsGiveWay(ls, idOf, state) {
3739
+ const hasEdge = (id) => state.edges.some((e) => e.id === id);
3740
+ const laid2 = ls.filter((l) => hasEdge(idOf(l))).flatMap((l) => l.marks.filter((m) => m.kind !== "line").map((m) => m.rect));
3741
+ return ls.map((l) => hasEdge(idOf(l)) ? l : { ...l, marks: marksLess(l.marks, l.axis, laid2) });
3742
+ }
3743
+ function spotsIn(base, id, layout, dragged) {
3744
+ const raws = base.raws.get(id);
3745
+ return raws ? laneFrom(id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(id), base.share, base.marking)?.spots ?? null : null;
3566
3746
  }
3567
- function heldLaneIn(id, raws, held, base, dragged) {
3568
- return laneFrom(id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(id), base.share, base.marking, !held.slide, true);
3747
+ function rawSpot(base, id) {
3748
+ for (const [lane, list] of base.raws) {
3749
+ const r = list.find((x) => x.id === id);
3750
+ if (r) return { lane, target: r.target, layout: r.layout, ...r.home ? { home: true } : {}, ...r.slide ? { slide: true } : {} };
3751
+ }
3752
+ return null;
3569
3753
  }
3570
3754
  function build(state, dragged, options) {
3571
3755
  const seen = solve(state, options.previous ? { previous: options.previous } : {});
@@ -3618,24 +3802,24 @@ function build(state, dragged, options) {
3618
3802
  return main?.grows ? main.natural : void 0;
3619
3803
  },
3620
3804
  gap: (edge) => nonNeg(state.edges.find((e) => e.id === edge)?.gap),
3621
- lifted,
3622
- crossing: (edge, over) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over.edges[e.id]?.cross ?? 0) > EPS20 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over.edges[e.id].rect)
3805
+ 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)
3623
3806
  };
3624
- const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS20 ? 0.5 : clamp2(g / size, 0, 1);
3807
+ const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS21 ? 0.5 : clamp3(g / size, 0, 1);
3625
3808
  const w = own?.rect.width ?? 0;
3626
3809
  const h = own?.rect.height ?? 0;
3627
3810
  const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
3628
3811
  const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
3629
- const settled = built.map((l) => settle(l, seen, state, dragged, built, options.emptyLanes));
3630
- const laneList = options.emptyLanes === "edge" ? settled : predict(settled, byLane, { seen, refusals: rs, halves, share, marking }, state, dragged, built, options.emptyLanes);
3631
- const predicted = new Set(laneList.filter((l, i) => l !== settled[i]).map((l) => l.id));
3812
+ 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)));
3632
3813
  const onLanes = new Set(laneList.map((l) => l.id));
3633
- const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS20 && r.rect.height > EPS20 ? [r.rect] : []);
3814
+ const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS21 && r.rect.height > EPS21 ? [r.rect] : []);
3634
3815
  const blocked = [
3635
- ...Object.values(seen.edges).filter((e) => e.cross > EPS20).map((e) => e.rect),
3816
+ ...Object.values(seen.edges).filter((e) => e.cross > EPS21).map((e) => e.rect),
3636
3817
  ...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
3637
3818
  ...keepClearFor(state, "targets"),
3638
3819
  ...rails,
3820
+ // A held tile's own rail: every stop is home's in `targets()`, with the new-column lines about its folded column
3821
+ // joined to it (the strip beside the rail). A home place takes no float, so it is blocked as `targets()` has it.
3822
+ ...own?.rail ? ts.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "rail").flatMap((t) => t.hits ?? [t.hit]) : [],
3639
3823
  // Spots where a release cancels (`DockState.blocked`): no float lands there.
3640
3824
  ...state.blocked ?? []
3641
3825
  ];
@@ -3647,7 +3831,6 @@ function build(state, dragged, options) {
3647
3831
  halves,
3648
3832
  share,
3649
3833
  marking,
3650
- predicted,
3651
3834
  regions: {
3652
3835
  refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
3653
3836
  content: floatRegion(state, dragged),
@@ -3660,23 +3843,42 @@ function build(state, dragged, options) {
3660
3843
  }
3661
3844
  };
3662
3845
  }
3663
- function laneRectOver(list, over, seen, marking) {
3846
+ function clearOfRail(lane, seen, raws) {
3847
+ const place = raws?.[0]?.target.place;
3848
+ const rail = place?.kind === "column" ? seen.rails[place.side] : void 0;
3849
+ if (!rail || rail.segments.length === 0) return lane;
3850
+ const pieces = subtract6(lane.rect, rail.rect);
3851
+ if (pieces.length === 0) return lane;
3852
+ const largest4 = pieces.reduce((m, p) => area7(p) > area7(m) ? p : m);
3853
+ return largest4 === lane.rect ? lane : { ...lane, rect: largest4 };
3854
+ }
3855
+ function laneRectOver(list, over2, marking) {
3664
3856
  const first = list[0];
3665
3857
  const axis = first.axis;
3666
- const edgeLayout = first.edge ? over.edges[first.edge] : void 0;
3858
+ const edgeLayout = first.edge ? over2.edges[first.edge] : void 0;
3667
3859
  const band = list.map((r) => r.landing).reduce(hull2);
3668
3860
  if (!edgeLayout) return { rect: list.every((r) => r.strip) ? list.map((r) => r.hit).reduce(hull2) : list.map((r) => r.hit).reduce(hull2, band) };
3669
- const drawnHere = edgeLayout.cross > EPS20;
3670
- const whole = drawnHere ? edgeLayout.rect : axis === "x" ? rect17(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect17(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3671
- const emptyAsSeen = (seen.edges[first.edge]?.cross ?? 0) <= EPS20;
3672
- const clipped = emptyAsSeen ? clipAtDrawn(whole, axis, marking.crossing(first.edge, seen)) : whole;
3673
- return drawnHere ? { rect: clipped } : { rect: clipped, band: whole };
3674
- }
3675
- function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, heldHere = false, spotHeld = false) {
3861
+ const drawnAt = drawnRect(over2, first.edge);
3862
+ if (drawnAt) return { rect: drawnAt };
3863
+ const whole = axis === "x" ? rect18(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect18(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
3864
+ return { rect: clipAtDrawn(whole, axis, marking.crossing(first.edge, over2)), band: whole };
3865
+ }
3866
+ function drawnIn(layout, id) {
3867
+ return drawnRect(layout, id) !== void 0;
3868
+ }
3869
+ function drawnRect(layout, id) {
3870
+ const e = layout.edges[id];
3871
+ if (!e) return void 0;
3872
+ if (e.cross > EPS21) return e.rect;
3873
+ if (!e.folded) return void 0;
3874
+ const run = Object.values(layout.rails).flatMap((r) => r?.segments.filter((g) => g.edge === id).map((g) => g.rect) ?? []);
3875
+ return run.length > 0 ? run.reduce(hull2) : void 0;
3876
+ }
3877
+ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, showsHeld = false, besideFloor) {
3676
3878
  if (list.length === 0) return null;
3677
3879
  const first = list[0];
3678
3880
  const axis = first.axis;
3679
- const { rect: laneRect, band: markBand } = laneRectOver(list, seen, seen, marking);
3881
+ const { rect: laneRect, band: markBand } = laneRectOver(list, seen, marking);
3680
3882
  const firstOf = (r) => r.slide?.first ?? r.landing;
3681
3883
  const lastOf = (r) => r.slide?.last ?? r.landing;
3682
3884
  const sorted = [...list].sort((a, b) => mid(firstOf(a), axis) - mid(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0));
@@ -3705,17 +3907,17 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3705
3907
  const bLanding = firstOf(b);
3706
3908
  const aEnd = lo(aLanding, axis) + len(aLanding, axis);
3707
3909
  const across2 = (aEnd + lo(bLanding, axis)) / 2;
3708
- const overlap = lo(bLanding, axis) < aEnd - EPS20;
3910
+ const overlap = lo(bLanding, axis) < aEnd - EPS21;
3709
3911
  const slack = Math.max(0, marking.pitch) / 2;
3710
- const atGrab = clamp2(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
3912
+ const atGrab = clamp3(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
3711
3913
  const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
3712
- cuts.push(clamp2(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
3914
+ cuts.push(clamp3(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
3713
3915
  }
3714
3916
  const spots = unique.flatMap((x, i) => {
3715
3917
  const a = i === 0 ? bandStart : cuts[i - 1];
3716
3918
  const b = i === unique.length - 1 ? bandEnd : cuts[i];
3717
- const along2 = [clamp2(a, start, end), clamp2(b, start, end)];
3718
- return along2[1] - along2[0] > EPS20 || b - a <= EPS20 || x.home ? [{ x, along: along2 }] : [];
3919
+ const along2 = [clamp3(a, start, end), clamp3(b, start, end)];
3920
+ return along2[1] - along2[0] > EPS21 || b - a <= EPS21 || x.home ? [{ x, along: along2 }] : [];
3719
3921
  }).map(({ x, along: along2 }) => ({
3720
3922
  id: x.id,
3721
3923
  along: along2,
@@ -3727,11 +3929,11 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3727
3929
  others: othersKey(x.layout, dragged)
3728
3930
  }));
3729
3931
  const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
3730
- const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp2(lo(h, axis), start, end), clamp2(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS20) : [];
3932
+ 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) : [];
3731
3933
  const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
3732
3934
  const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
3733
- const markRect = drawnEdge && drawnEdge.cross > EPS20 ? drawnEdge.rect : markBand ?? laneRect;
3734
- const marked = first.edge ? onEdge(drawn, first.edge, heldHere ? "" : dragged, axis).map((o) => {
3935
+ const markRect = (first.edge ? drawnRect(drawn, first.edge) : void 0) ?? laneRectOver(list, drawn, marking).band ?? markBand ?? laneRect;
3936
+ const marked = first.edge ? onEdge(drawn, first.edge, showsHeld ? "" : dragged, axis).map((o) => {
3735
3937
  const n = o.id === dragged || halves ? void 0 : marking.natural(o.id, axis);
3736
3938
  return n !== void 0 && n < len(o.r, axis) ? { ...o, r: along(o.r, axis, lo(o.r, axis), lo(o.r, axis) + n) } : o;
3737
3939
  }) : [];
@@ -3743,17 +3945,16 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
3743
3945
  const n = halves ? void 0 : marking.natural(iid, axis);
3744
3946
  return [lo(r, axis), lo(r, axis) + (n !== void 0 && n < len(r, axis) ? n : len(r, axis))];
3745
3947
  };
3746
- const marks = first.edge ? edgeMarks(id, markRect, axis, marked, refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged, {
3747
- besideMin: halves || marking.pitch <= 0 ? itemLen : marking.pitch,
3948
+ const marks = first.edge && !drawnEdge ? [] : first.edge ? edgeMarks(id, markRect, axis, marked, refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged, {
3949
+ besideMin: besideFloor ?? (halves || marking.pitch <= 0 ? itemLen : marking.pitch),
3748
3950
  gap: marking.gap(first.edge),
3749
3951
  landingOf: (pair) => landings.get(pair),
3750
- // Judged against the layout the marks are drawn in; with a spot held, against the layout as seen with the held
3751
- // item lifted (in the spot's own a neighbor has already stepped down or moved).
3752
- givesWay: (iid, side, after) => givesWay((spotHeld ? marking.lifted : drawn).items[iid], after.items[iid], id, side, (r) => extent(iid, r))
3952
+ // Judged against the layout the marks are drawn in: one layout, the screen's.
3953
+ givesWay: (iid, side, after) => givesWay(drawn.items[iid], after.items[iid], id, side, (r) => extent(iid, r))
3753
3954
  }) : virtualMarks(id, unique, drawn.items[dragged]);
3754
3955
  return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
3755
3956
  }
3756
- var along = (r, axis, a, b) => axis === "x" ? rect17(a, r.y, b - a, r.height) : rect17(r.x, a, r.width, b - a);
3957
+ var along = (r, axis, a, b) => axis === "x" ? rect18(a, r.y, b - a, r.height) : rect18(r.x, a, r.width, b - a);
3757
3958
  var LINE2 = 2;
3758
3959
  var MIN_BOX = 8;
3759
3960
  var HATCH_END = 8;
@@ -3761,8 +3962,8 @@ var HATCH_EDGE = 8;
3761
3962
  function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
3762
3963
  const { besideMin } = more;
3763
3964
  const hatches = (pair, a, b, p, q, gl, gr) => {
3764
- if (gl && Math.abs(p - a) < EPS20) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
3765
- if (gr && Math.abs(q - b) < EPS20) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
3965
+ 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 });
3966
+ 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 });
3766
3967
  };
3767
3968
  const heldAt = items.find((o) => o.id === held);
3768
3969
  const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
@@ -3772,10 +3973,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3772
3973
  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 }];
3773
3974
  const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
3774
3975
  for (let i = 0; i + 1 < ends.length; i++) {
3775
- const a = clamp2(ends[i].b, start, end);
3776
- const b = clamp2(ends[i + 1].a, start, end);
3976
+ const a = clamp3(ends[i].b, start, end);
3977
+ const b = clamp3(ends[i + 1].a, start, end);
3777
3978
  const pair = `${ends[i].id}|${ends[i + 1].id}`;
3778
- if (ends[i + 1].a < start - EPS20 || ends[i].b > end + EPS20 || !lands(pair)) continue;
3979
+ if (ends[i + 1].a < start - EPS21 || ends[i].b > end + EPS21 || !lands(pair)) continue;
3779
3980
  const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
3780
3981
  const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
3781
3982
  const named = `${left}|${right}`;
@@ -3784,12 +3985,12 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3784
3985
  const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
3785
3986
  const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
3786
3987
  const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
3787
- if (b - a < min - EPS20) {
3788
- if (spot && b - a >= besideMin - EPS20) {
3988
+ if (b - a < min - EPS21) {
3989
+ if (spot && b - a >= besideMin - EPS21) {
3789
3990
  let ps = [[a, b]];
3790
3991
  for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
3791
3992
  if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
3792
- ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS20);
3993
+ ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS21);
3793
3994
  ps.forEach(([p, q], k2) => {
3794
3995
  out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
3795
3996
  hatches(pair, a, b, p, q, gl, gr);
@@ -3801,10 +4002,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3801
4002
  continue;
3802
4003
  }
3803
4004
  let pieces = [[a, b]];
3804
- 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 > EPS20);
4005
+ 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);
3805
4006
  let k = 0;
3806
4007
  for (const [p, q] of pieces) {
3807
- if (q - p < min - EPS20) continue;
4008
+ if (q - p < min - EPS21) continue;
3808
4009
  const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
3809
4010
  out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
3810
4011
  hatches(pair, a, b, p, q, gl, gr);
@@ -3815,9 +4016,9 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
3815
4016
  function virtualMarks(lane, spots, held) {
3816
4017
  return spots.map((s) => {
3817
4018
  const l = s.landing;
3818
- if (!held || held.floating || !overlaps7(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
4019
+ if (!held || held.floating || !overlaps8(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
3819
4020
  const x = mid(held.rect, "x") < mid(l, "x") ? l.x + l.width : l.x;
3820
- return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect17(x, l.y, 0, l.height) };
4021
+ return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect18(x, l.y, 0, l.height) };
3821
4022
  });
3822
4023
  }
3823
4024
  function inLane(l, r) {
@@ -3826,22 +4027,22 @@ function inLane(l, r) {
3826
4027
  const y0 = Math.max(m.rect.y, r.y);
3827
4028
  const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
3828
4029
  const y1 = Math.min(m.rect.y + m.rect.height, r.y + r.height);
3829
- if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS20 && y1 - y0 >= m.rect.height - EPS20 ? [m] : [];
3830
- if (x1 - x0 <= EPS20 || y1 - y0 <= EPS20) return [];
3831
- return x1 - x0 >= m.rect.width - EPS20 && y1 - y0 >= m.rect.height - EPS20 ? [m] : [{ ...m, rect: rect17(x0, y0, x1 - x0, y1 - y0) }];
4030
+ if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS21 && y1 - y0 >= m.rect.height - EPS21 ? [m] : [];
4031
+ if (x1 - x0 <= EPS21 || y1 - y0 <= EPS21) return [];
4032
+ return x1 - x0 >= m.rect.width - EPS21 && y1 - y0 >= m.rect.height - EPS21 ? [m] : [{ ...m, rect: rect18(x0, y0, x1 - x0, y1 - y0) }];
3832
4033
  });
3833
4034
  return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
3834
4035
  }
3835
4036
  function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within = lane.rect) {
3836
4037
  const l = inLane(lane, within);
3837
4038
  const edgeOf = (id) => state.edges.find((e) => e.id === id);
3838
- const isDrawn = (id) => !!edgeOf(id) && (drawn.edges[id]?.cross ?? 0) > EPS20;
4039
+ const isDrawn = (id) => !!edgeOf(id) && drawnIn(drawn, id);
3839
4040
  const across2 = (side) => side === "top" || side === "bottom" ? "x" : "y";
3840
4041
  const cuts = [];
3841
4042
  if (!isDrawn(l.id)) {
3842
4043
  for (const e of state.edges) {
3843
- const de = drawn.edges[e.id];
3844
- if (e.id !== l.id && de && de.cross > EPS20 && across2(e.side) !== l.axis) cuts.push(de.rect);
4044
+ const de = e.id !== l.id && across2(e.side) !== l.axis ? drawnRect(drawn, e.id) : void 0;
4045
+ if (de) cuts.push(de);
3845
4046
  }
3846
4047
  if (l.axis === "y") {
3847
4048
  for (const o of all) if (o.id !== l.id && o.axis === "x" && !isDrawn(o.id)) cuts.push(o.rect);
@@ -3852,14 +4053,14 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
3852
4053
  const e = edge ? edgeOf(edge) : void 0;
3853
4054
  return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
3854
4055
  };
3855
- 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 > EPS20 && it.rect.height > EPS20).map(([, it]) => it.rect) : [];
3856
- if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps7(m.rect, s)))))) return l;
4056
+ 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) : [];
4057
+ if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps8(m.rect, s)))))) return l;
3857
4058
  const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
3858
4059
  const marks = [];
3859
4060
  for (const m of l.marks) {
3860
4061
  const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
3861
4062
  if (m.kind === "line") {
3862
- if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS20) marks.push(m);
4063
+ if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS21) marks.push(m);
3863
4064
  continue;
3864
4065
  }
3865
4066
  kept.forEach(([p, q], i) => {
@@ -3872,11 +4073,11 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
3872
4073
  if (l.axis === "y") {
3873
4074
  const outerRight = side === "right" ? true : side === "left" ? false : Math.abs(piece.x + piece.width - (st.x + st.width)) <= Math.abs(piece.x - st.x);
3874
4075
  const t = Math.min(HATCH_EDGE, piece.width);
3875
- r = rect17(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
4076
+ r = rect18(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
3876
4077
  } else {
3877
4078
  const outerBottom = side === "bottom" ? true : side === "top" ? false : Math.abs(piece.y + piece.height - (st.y + st.height)) <= Math.abs(piece.y - st.y);
3878
4079
  const t = Math.min(HATCH_EDGE, piece.height);
3879
- r = rect17(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
4080
+ r = rect18(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
3880
4081
  }
3881
4082
  marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
3882
4083
  });
@@ -3885,55 +4086,27 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
3885
4086
  }
3886
4087
  function piecesLess(r, axis, cs) {
3887
4088
  const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
3888
- const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS20 && r.y < c.y + c.height - EPS20 : c.x < r.x + r.width - EPS20 && r.x < c.x + c.width - EPS20;
4089
+ 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;
3889
4090
  let ps = [span(r)];
3890
4091
  for (const c of cs) {
3891
4092
  if (!crosses(c)) continue;
3892
4093
  const [c0, c1] = span(c);
3893
- ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS20);
4094
+ ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS21);
3894
4095
  }
3895
4096
  return ps;
3896
4097
  }
3897
- function marksLess(marks, axis, cs) {
4098
+ function marksLess(marks, axis, cs, options = {}) {
4099
+ const suffix = options.suffix ?? "~c";
4100
+ const minBox = options.minBox ?? 0;
3898
4101
  return marks.flatMap((m) => {
3899
- const over = cs.filter((c) => overlaps7(m.rect, c));
3900
- if (over.length === 0) return [m];
3901
- const kept = piecesLess(m.rect, axis, over);
3902
- if (m.kind === "line") return kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS20 ? [m] : [];
3903
- return kept.map(([p, q], i) => ({ ...m, id: i ? `${m.id}~c${i}` : m.id, rect: along(m.rect, axis, p, q) }));
3904
- });
3905
- }
3906
- function predict(settled, byLane, base, state, dragged, built, emptyLanes) {
3907
- const whole = /* @__PURE__ */ new Map();
3908
- for (const l of settled) {
3909
- const raws = byLane.get(l.id);
3910
- if (!raws || l.spots.length !== 1 || !state.edges.some((e) => e.id === l.id) || (base.seen.edges[l.id]?.cross ?? 0) > EPS20) continue;
3911
- const held = raws.find((r) => r.id === l.spots[0].id);
3912
- if (!held || (held.layout.edges[l.id]?.cross ?? 0) <= EPS20) continue;
3913
- const again = heldLaneIn(l.id, raws, held, base, dragged);
3914
- if (!again) continue;
3915
- const after = settle(again, held.layout, state, dragged, built, emptyLanes, laneRectOver(raws, held.layout, base.seen, base.marking).rect).marks;
3916
- whole.set(l.id, after.length === 0 && l.marks.length > 0 ? l.marks : after);
3917
- }
3918
- if (whole.size === 0) return [...settled];
3919
- const order = [...settled].filter((l) => whole.has(l.id)).sort((a, b) => a.axis === b.axis ? 0 : a.axis === "x" ? -1 : 1);
3920
- const final = new Map(settled.filter((l) => !whole.has(l.id)).map((l) => [l.id, l.marks]));
3921
- const meets = /* @__PURE__ */ new Map();
3922
- for (const l of order) {
3923
- const mine = whole.get(l.id);
3924
- const others = [...final].filter(([id, ms]) => id !== l.id && ms.some((m) => mine.some((x) => overlaps7(x.rect, m.rect))));
3925
- meets.set(l.id, others.map(([id]) => id));
3926
- final.set(l.id, marksLess(mine, l.axis, others.flatMap(([, ms]) => ms.map((m) => m.rect))));
3927
- }
3928
- return settled.map((l) => {
3929
- const marks = final.get(l.id);
3930
- const mine = whole.get(l.id);
3931
- if (!mine) return l;
3932
- const corners = meets.get(l.id);
3933
- return corners.length > 0 ? { ...l, marks, entry: mine, corners } : { ...l, marks };
4102
+ const over2 = cs.filter((c) => overlaps8(m.rect, c));
4103
+ if (over2.length === 0) return [m];
4104
+ const kept = piecesLess(m.rect, axis, over2);
4105
+ 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] : [];
4106
+ 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) }));
3934
4107
  });
3935
4108
  }
3936
- var overlaps7 = (a, b) => a.x < b.x + b.width - EPS20 && b.x < a.x + a.width - EPS20 && a.y < b.y + b.height - EPS20 && b.y < a.y + a.height - EPS20;
4109
+ 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;
3937
4110
  function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
3938
4111
  const out = [];
3939
4112
  stretches(state, dragged, options, seen, lifted, raws, (run) => {
@@ -3958,12 +4131,12 @@ function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
3958
4131
  };
3959
4132
  return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
3960
4133
  const end = (x0, order, flush) => {
3961
- for (const zone of order) if (spaceAt(zone, x0) >= -EPS20 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
4134
+ for (const zone of order) if (spaceAt(zone, x0) >= -EPS21 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
3962
4135
  };
3963
4136
  end(a, zones, before?.id ?? "^");
3964
- if (b - w > a + EPS20) end(b - w, [...zones].reverse(), after?.id ?? "$");
4137
+ if (b - w > a + EPS21) end(b - w, [...zones].reverse(), after?.id ?? "$");
3965
4138
  if (b - a < w + pitch) return;
3966
- for (let x0 = a + pitch; x0 + w <= b - pitch + EPS20; x0 += pitch) {
4139
+ for (let x0 = a + pitch; x0 + w <= b - pitch + EPS21; x0 += pitch) {
3967
4140
  const zone = x0 + w / 2 < middle ? "start" : "end";
3968
4141
  if (!zones.includes(zone)) continue;
3969
4142
  emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
@@ -4072,10 +4245,12 @@ function landsAt(state, dragged, run, place, x0) {
4072
4245
  const landed = layout.items[dragged];
4073
4246
  const { axis } = run;
4074
4247
  if (!landed || landed.inMenu || landed.edge !== run.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
4075
- if (run.fixed.some((f) => {
4076
- const r = layout.items[f.id]?.rect;
4077
- return !r || Math.abs(lo(r, axis) - lo(f.r, axis)) > 1;
4078
- })) return null;
4248
+ const kept = (f) => {
4249
+ const it = layout.items[f.id];
4250
+ if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
4251
+ return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
4252
+ };
4253
+ if (!run.fixed.every(kept)) return null;
4079
4254
  return { next, layout };
4080
4255
  }
4081
4256
  function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
@@ -4093,7 +4268,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4093
4268
  for (const zone2 of [near, near === "start" ? "end" : "start"]) {
4094
4269
  if (!zones.includes(zone2)) continue;
4095
4270
  const space = spaceAt(zone2, x0);
4096
- if (space < -EPS20) continue;
4271
+ if (space < -EPS21) continue;
4097
4272
  const place = { edge: e.id, zone: zone2, at: atOf(zone2), space: Math.max(0, space) };
4098
4273
  const hit = landsAt(state, dragged, run, place, x0);
4099
4274
  if (hit) return { place, result: { state: hit.next, layout: hit.layout } };
@@ -4101,8 +4276,8 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4101
4276
  return null;
4102
4277
  };
4103
4278
  const tries = [a];
4104
- for (let x0 = a + sample; x0 < b - w - EPS20; x0 += sample) tries.push(x0);
4105
- if (b - w > a + EPS20) tries.push(b - w);
4279
+ for (let x0 = a + sample; x0 < b - w - EPS21; x0 += sample) tries.push(x0);
4280
+ if (b - w > a + EPS21) tries.push(b - w);
4106
4281
  const ok = tries.map((x0) => ({ x0, hit: land(x0) })).filter((t) => t.hit);
4107
4282
  if (ok.length === 0) return;
4108
4283
  const from = ok[0].x0;
@@ -4114,7 +4289,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4114
4289
  const firstZone = (() => {
4115
4290
  for (const zone3 of zones) {
4116
4291
  const space = spaceAt(zone3, from);
4117
- if (space < -EPS20) continue;
4292
+ if (space < -EPS21) continue;
4118
4293
  const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
4119
4294
  const hit = landsAt(state, dragged, run, place2, from);
4120
4295
  if (hit) return { place: place2, result: { state: hit.next, layout: hit.layout } };
@@ -4157,9 +4332,9 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4157
4332
  return best;
4158
4333
  };
4159
4334
  const startAt = (raw) => {
4160
- const c = clamp2(raw, from, to);
4335
+ const c = clamp3(raw, from, to);
4161
4336
  const s = snapped(c);
4162
- return snaps.includes(s) ? s : clamp2(Math.round(c / STEP) * STEP, from, to);
4337
+ return snaps.includes(s) ? s : clamp3(Math.round(c / STEP) * STEP, from, to);
4163
4338
  };
4164
4339
  const results = /* @__PURE__ */ new Map();
4165
4340
  const commitAt = (x0) => {
@@ -4171,7 +4346,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4171
4346
  results.set(k, result);
4172
4347
  return result;
4173
4348
  };
4174
- const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp2(lo(own.rect, axis), from, to)) : from;
4349
+ const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp3(lo(own.rect, axis), from, to)) : from;
4175
4350
  const restResult = commitAt(rest);
4176
4351
  const ownZone = own?.zone;
4177
4352
  const restPlace = (() => {
@@ -4191,7 +4366,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4191
4366
  place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
4192
4367
  after: (point, grab) => {
4193
4368
  const g = grab ? grab[long] : ownLen / 2;
4194
- const share = axis === long && ownLen > EPS20 && Number.isFinite(g) ? clamp2(g / ownLen, 0, 1) : 0.5;
4369
+ const share = axis === long && ownLen > EPS21 && Number.isFinite(g) ? clamp3(g / ownLen, 0, 1) : 0.5;
4195
4370
  return commitAt(startAt((axis === "x" ? point.x : point.y) - share * w));
4196
4371
  }
4197
4372
  };
@@ -4215,6 +4390,110 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
4215
4390
  return { spots, absorbed };
4216
4391
  }
4217
4392
 
4393
+ // src/drag.ts
4394
+ import { EPS as EPS22 } from "@n-uf/placement";
4395
+ var MIN_PIECE = 8;
4396
+ var ORIGIN2 = { x: 0, y: 0 };
4397
+ function dockDrag(state, dragged, options = {}) {
4398
+ const base = baseOf(state, dragged, options);
4399
+ const regions = { ...base.regions, lanes: base.lanes };
4400
+ const grab = options.grab;
4401
+ const byResult = /* @__PURE__ */ new WeakMap();
4402
+ const fixed = /* @__PURE__ */ new Map();
4403
+ const axisOf2 = new Map(base.lanes.map((l) => [l.id, l.axis]));
4404
+ const flat = (ls) => ls.flatMap((l) => l.marks.map((m) => ({ ...m, lane: l.lane })));
4405
+ const rest = { state, layout: base.seen, landing: null, marks: flat(base.lanes.map((l) => ({ lane: l.id, axis: l.axis, marks: l.marks }))) };
4406
+ let lastFloat = null;
4407
+ const of = (result, spot) => {
4408
+ const known = byResult.get(result);
4409
+ if (known) return known;
4410
+ const it = result.layout.items[dragged];
4411
+ const landing = it && !it.inMenu && (spot ? !it.floating : it.floating) ? it.rect : null;
4412
+ const spots = spot ? spotsIn(base, spot.lane, result.layout, dragged) : null;
4413
+ const out = { ...result, landing, marks: flat(marksIn(base, state, dragged, result.layout, spot ? spot.slide ? "slide" : "spot" : false, options.emptyLanes)), ...spots ? { spots } : {} };
4414
+ byResult.set(result, out);
4415
+ return out;
4416
+ };
4417
+ const after = (held) => {
4418
+ if (!held) return rest;
4419
+ if (held.kind === "float") {
4420
+ const float = base.regions.float;
4421
+ if (!float) return rest;
4422
+ if (lastFloat && lastFloat.x === held.point.x && lastFloat.y === held.point.y) return lastFloat.after;
4423
+ const a2 = of(float.after(held.point, grab), null);
4424
+ lastFloat = { x: held.point.x, y: held.point.y, after: a2 };
4425
+ return a2;
4426
+ }
4427
+ const raw = rawSpot(base, held.spot);
4428
+ if (!raw) return rest;
4429
+ if (raw.slide) return of(raw.target.after(held.point, grab), raw);
4430
+ let a = fixed.get(held.spot);
4431
+ if (!a) fixed.set(held.spot, a = of(raw.target.after(ORIGIN2, ORIGIN2), raw));
4432
+ return a;
4433
+ };
4434
+ const createdMemo = /* @__PURE__ */ new Map();
4435
+ const created = (lane) => {
4436
+ if (createdMemo.has(lane)) return createdMemo.get(lane);
4437
+ const l = base.lanes.find((x) => x.id === lane);
4438
+ const raw = l && options.emptyLanes !== "edge" && l.spots.length === 1 && state.edges.some((e) => e.id === lane) ? rawSpot(base, l.spots[0].id) : null;
4439
+ const out = raw && drawnIn(raw.layout, lane) ? flat(marksIn(base, state, dragged, raw.layout, false, options.emptyLanes)).filter((m) => m.lane === lane) : null;
4440
+ createdMemo.set(lane, out && out.length > 0 ? out : null);
4441
+ return createdMemo.get(lane);
4442
+ };
4443
+ const landingOf = (held) => after(held).landing;
4444
+ const spotsOf = (spot) => {
4445
+ const raw = rawSpot(base, spot);
4446
+ return raw && !raw.slide ? after({ kind: "spot", spot, point: ORIGIN2 }).spots ?? null : raw ? spotsIn(base, raw.lane, raw.layout, dragged) : null;
4447
+ };
4448
+ const screenOf = (frame) => {
4449
+ const held = after(frame.held);
4450
+ if (frame.room || held === rest) return held;
4451
+ return held.landing ? { ...rest, landing: held.landing } : rest;
4452
+ };
4453
+ const shownLayout = (frame) => screenOf(frame).layout;
4454
+ const guides = (frame) => {
4455
+ if (frame.guides.length === 0) return [];
4456
+ const held = after(frame.held);
4457
+ const screen = screenOf(frame);
4458
+ let near = null;
4459
+ const shown = [];
4460
+ const drawnThere = (id) => drawnIn(screen.layout, id);
4461
+ for (const g of frame.guides) {
4462
+ const mine = after(g.held);
4463
+ if (mine === held) {
4464
+ const own2 = screen.marks.filter((m) => m.lane === g.lane);
4465
+ const edgeless = !state.edges.some((e) => e.id === g.lane);
4466
+ const made2 = edgeless ? own2 : !drawnThere(g.lane) ? created(g.lane) : null;
4467
+ shown.push(made2 ? { lane: g.lane, marks: made2, created: true } : { lane: g.lane, marks: own2 });
4468
+ continue;
4469
+ }
4470
+ const onScreen2 = drawnThere(g.lane);
4471
+ const axis2 = axisOf2.get(g.lane) ?? "x";
4472
+ const own = screen.marks.filter((m) => m.lane === g.lane);
4473
+ const marks = onScreen2 ? mine.landing ? marksLess(own, axis2, [mine.landing], { suffix: "~l", minBox: MIN_PIECE, lines: "covered" }) : own : mine.marks.filter((m) => m.lane === g.lane);
4474
+ near = { lane: g.lane, marks };
4475
+ shown.push(near);
4476
+ }
4477
+ const drawnStays = [
4478
+ ...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),
4479
+ ...Object.values(screen.layout.rails).flatMap((r) => r?.segments.filter((g) => g.id !== dragged).map((g) => g.rect) ?? [])
4480
+ ];
4481
+ const onScreen = [...shown.filter((s) => !s.created && s !== near).flatMap((s) => s.marks.map((m) => m.rect)), ...drawnStays, ...screen.landing ? [screen.landing] : []];
4482
+ const axis = (id) => axisOf2.get(id) ?? "x";
4483
+ const made = shown.filter((s) => s.created).sort((a, b) => axis(a.lane) === axis(b.lane) ? 0 : axis(a.lane) === "x" ? -1 : 1);
4484
+ const kept = [];
4485
+ for (const s of made) {
4486
+ s.marks = marksLess(s.marks, axis(s.lane), [...onScreen, ...kept]);
4487
+ kept.push(...s.marks.map((m) => m.rect));
4488
+ }
4489
+ if (!near) return shown.flatMap((s) => s.marks);
4490
+ const cut2 = near.marks.map((m) => m.rect);
4491
+ return shown.flatMap((s) => s === near ? s.marks : marksLess(s.marks, axis(s.lane), cut2));
4492
+ };
4493
+ const home = base.lanes.flatMap((l) => l.spots.filter((s) => s.home).map((s) => ({ lane: l.id, spot: s.id })))[0];
4494
+ return { regions, ...home ? { home } : {}, after, landingOf, spotsOf, shown: shownLayout, guides };
4495
+ }
4496
+
4218
4497
  export {
4219
4498
  SIDES,
4220
4499
  ZONES,
@@ -4246,6 +4525,10 @@ export {
4246
4525
  virtualEdgeId,
4247
4526
  placeTargetId,
4248
4527
  solve,
4528
+ dividers,
4529
+ resizeBetween,
4530
+ resetBetween,
4531
+ resetLengths,
4249
4532
  fitResize,
4250
4533
  mergeSideColumns,
4251
4534
  liftItem,
@@ -4275,6 +4558,7 @@ export {
4275
4558
  SPOT_PITCH,
4276
4559
  lanes,
4277
4560
  HATCH_END,
4278
- HATCH_EDGE
4561
+ HATCH_EDGE,
4562
+ dockDrag
4279
4563
  };
4280
- //# sourceMappingURL=chunk-KGNFLHSC.js.map
4564
+ //# sourceMappingURL=chunk-FSNFXRYM.js.map