@n-uf/placement 26.11.27 → 26.11.29

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.
@@ -5,7 +5,7 @@ import {
5
5
  formMain,
6
6
  formSetsCross,
7
7
  wrapLines
8
- } from "./chunk-IHU6IOZH.js";
8
+ } from "./chunk-3RRCKN74.js";
9
9
  import {
10
10
  COLUMN_REACH,
11
11
  EPS,
@@ -22,6 +22,10 @@ import {
22
22
  // src/scene/model.ts
23
23
  var SIDES = ["top", "right", "bottom", "left"];
24
24
  var ZONES = ["start", "center", "end"];
25
+ var RAIL_MODES = ["titles", "icons"];
26
+ var RAIL_VISIBILITIES = ["whileDragging", "always", "never"];
27
+ var RAIL_STRIP_MIN = 24;
28
+ var DEFAULT_RAIL_MAGNET = 6;
25
29
  var DEFAULT_STRIP = 24;
26
30
  var DEFAULT_HIT_BAND = 24;
27
31
  var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
@@ -44,7 +48,25 @@ var columnFromTemplate = (t, id, side, ring, items) => ({
44
48
  ...t.hitBand !== void 0 ? { hitBand: t.hitBand } : {},
45
49
  column: true
46
50
  });
51
+ var railModeOf = (scene, side) => side === "left" || side === "right" ? scene.railModes?.[side] === "icons" ? "icons" : "titles" : "icons";
47
52
  var axisOf = (side) => side === "left" || side === "right" ? "column" : "row";
53
+ function railColumnOf(scene, side, kind) {
54
+ if (scene.rails?.[side]) return void 0;
55
+ return scene.edges.filter((e) => e.side === side && !e.compact && zoneTakes(e, "start", kind)).reduce((m, e) => !m || e.ring < m.ring ? e : m, void 0);
56
+ }
57
+ function railPolicyOf(scene, kind) {
58
+ const p = Object.hasOwn(scene.railDrop ?? {}, kind) ? scene.railDrop[kind] : void 0;
59
+ if (!p) return null;
60
+ const visibility = p.railVisibility === "always" || p.railVisibility === "never" ? p.railVisibility : "whileDragging";
61
+ const width = p.railStripWidth;
62
+ if (visibility === "never" || width !== void 0 && !(Number.isFinite(width) && width > 0)) return null;
63
+ return {
64
+ railStripWidth: width === void 0 ? null : Math.max(RAIL_STRIP_MIN, width),
65
+ railVisibility: visibility,
66
+ magnet: Number.isFinite(p.magnet) ? Math.max(0, p.magnet) : DEFAULT_RAIL_MAGNET,
67
+ floatNearEdge: p.floatNearEdge !== false
68
+ };
69
+ }
48
70
  var zoneOf = (item) => item?.align === "center" || item?.align === "end" ? item.align : "start";
49
71
  var formsOf = (item, axis) => item.forms[axis] ?? [];
50
72
  var PANEL_FORMS = /* @__PURE__ */ new Set(["open", "header", "rail"]);
@@ -318,6 +340,7 @@ function emit(d, edge, r, solved, extra = {}) {
318
340
  zone: zoneOf(it),
319
341
  ...inMenu ? { inMenu: true } : {},
320
342
  ...tabs.has(p.id) ? { tab: true } : {},
343
+ ...tabs.has(p.id) && f?.title === true && (edge.side === "left" || edge.side === "right") ? { railTitle: edge.side } : {},
321
344
  ...solved.closedTabs.has(p.id) ? { closed: true } : {},
322
345
  ...it.fixed ? { fixed: true } : {}
323
346
  };
@@ -380,6 +403,8 @@ function railEdge(f, free, asStackItem) {
380
403
  if (!anyRail) return null;
381
404
  const railInput = {
382
405
  ...f.base,
406
+ // The side's rail mode: a title rail form is offered only while the side shows titles.
407
+ ...railModeOf(scene, edge.side) === "titles" ? { titles: true } : {},
383
408
  items: shown.map((id) => {
384
409
  const it = scene.items[id];
385
410
  const j = railIndex(it, formsById(id));
@@ -733,21 +758,47 @@ function layRiders(d, host, riders, top) {
733
758
  function layRail(d, side, railRect, railed, g) {
734
759
  const { scene, items } = d;
735
760
  const segments = [];
761
+ const members = railed.flatMap((c) => zoneSorted(scene, c.visible).map((id) => ({ id, c })));
762
+ const formsById = (id) => formsOf(scene.items[id], "column");
763
+ const tileOf = (id) => formsById(id).findIndex((f) => f.kind === "rail" && f.title !== true);
764
+ const titleOf = (id) => {
765
+ const t = tileOf(id);
766
+ return t > 0 && formsById(id)[t - 1].kind === "rail" && formsById(id)[t - 1].title === true ? t - 1 : -1;
767
+ };
768
+ const titles = railModeOf(scene, side) === "titles" && members.some((m) => titleOf(m.id) >= 0) && members.every((m) => tileOf(m.id) >= 0);
769
+ let fit;
770
+ if (titles) {
771
+ const input = {
772
+ axis: "column",
773
+ length: railRect.height,
774
+ cross: { min: railRect.width, max: railRect.width, rail: railRect.width },
775
+ titles: true,
776
+ items: members.map(({ id }) => {
777
+ const it = scene.items[id];
778
+ const p = finite(it.priority ?? 0, 0);
779
+ const forms = formsById(id).slice(0, tileOf(id) + 1).map((f) => p === 0 ? f : { ...f, rank: finite(f.rank ?? 0, 0) + p });
780
+ return { id, forms, used: finite(it.used, 0), ...it.kept ? { kept: true } : {}, from: titleOf(id) >= 0 ? titleOf(id) : tileOf(id) };
781
+ })
782
+ };
783
+ const fresh = members.some((m) => d.fresh.has(m.id) || d.fresh.has(m.c.edge.id));
784
+ const previous = d.previous && !fresh ? d.previous.rails[side]?.stack : void 0;
785
+ fit = fitStack(input, previous ? { previous } : {});
786
+ }
787
+ const placed = new Map(fit?.items.map((p) => [p.id, p]) ?? []);
736
788
  let y = railRect.y;
737
- for (const c of railed) {
738
- for (const id of zoneSorted(scene, c.visible)) {
739
- const it = scene.items[id];
740
- const forms = formsOf(it, "column");
741
- const ri = forms.findIndex((f) => f.kind === "rail");
742
- const form = ri >= 0 ? ri : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1));
743
- const h = ri >= 0 ? px(forms[ri].main.natural) : railRect.width;
744
- const at = rect(railRect.x, y, railRect.width, h);
745
- items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, folded: g.auto.has(c) ? "auto" : "hand" };
746
- segments.push({ id, edge: c.edge.id, rect: at });
747
- y += h;
748
- }
789
+ for (const { id, c } of members) {
790
+ const it = scene.items[id];
791
+ const forms = formsById(id);
792
+ const ri = tileOf(id);
793
+ const p = placed.get(id);
794
+ const form = p ? p.form : ri >= 0 ? ri : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1));
795
+ const at = p ? rect(railRect.x, railRect.y + p.rect.y, railRect.width, p.rect.height) : rect(railRect.x, y, railRect.width, ri >= 0 ? px(forms[ri].main.natural) : railRect.width);
796
+ const title = forms[form]?.title === true;
797
+ items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand" };
798
+ segments.push({ id, edge: c.edge.id, rect: at });
799
+ y += at.height;
749
800
  }
750
- d.rails[side] = { rect: railRect, segments };
801
+ d.rails[side] = { rect: railRect, segments, ...fit ? { stack: fit } : {} };
751
802
  }
752
803
 
753
804
  // src/scene/solve/sides.ts
@@ -890,10 +941,10 @@ function obstacleStop(drawn, obstacles, axis, drag, span) {
890
941
  if (!drawn || !drag) return none;
891
942
  const lo = (r) => axis === "x" ? r.x : r.y;
892
943
  const len = (r) => axis === "x" ? r.width : r.height;
893
- const across = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
944
+ const across2 = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
894
945
  let at = none;
895
946
  for (const o of obstacles) {
896
- const [c0, c1] = across(o);
947
+ const [c0, c1] = across2(o);
897
948
  if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
898
949
  if (drag === "start" && lo(o) + len(o) <= lo(drawn) + EPS2) at = Math.max(at, lo(o) + len(o));
899
950
  if (drag === "end" && lo(o) >= lo(drawn) + len(drawn) - EPS2) at = Math.min(at, lo(o));
@@ -1051,6 +1102,11 @@ function moveTo(scene, id, place) {
1051
1102
  if (!anchor || out === scene) return out;
1052
1103
  return { ...out, floats: out.floats.map((f) => f.id === id ? { ...f, anchor } : f) };
1053
1104
  }
1105
+ const railColumn = place.kind === "rail" ? railColumnOf(scene, place.side, item.kind) : void 0;
1106
+ if (railColumn) {
1107
+ const docked = moveTo(scene, id, { edge: railColumn.id, zone: "start", at: Infinity });
1108
+ return docked === scene ? scene : withItem(docked, { ...docked.items[id], from: Math.max(1, item.from ?? 0) });
1109
+ }
1054
1110
  if (place.kind === "column" || place.kind === "rail") {
1055
1111
  if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
1056
1112
  const folded = place.kind === "rail" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;
@@ -1143,6 +1199,10 @@ function resizeEdge(scene, edgeId, size) {
1143
1199
  }
1144
1200
  return { ...scene, edges: scene.edges.map((e) => e === edge ? { ...e, size } : e) };
1145
1201
  }
1202
+ function setRailMode(scene, side, mode) {
1203
+ if (side !== "left" && side !== "right" || !RAIL_MODES.includes(mode) || railModeOf(scene, side) === mode) return scene;
1204
+ return { ...scene, railModes: { ...scene.railModes, [side]: mode } };
1205
+ }
1146
1206
  function setSide(scene, edgeId, side) {
1147
1207
  const edge = scene.edges.find((e) => e.id === edgeId);
1148
1208
  if (!edge || edge.side === side || axisOf(edge.side) !== axisOf(side)) return scene;
@@ -1195,6 +1255,20 @@ var isNum = (x) => typeof x === "number" && Number.isFinite(x);
1195
1255
  var isSize = (x) => isNum(x) && x > 0;
1196
1256
  var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
1197
1257
  var record = () => /* @__PURE__ */ Object.create(null);
1258
+ function railModesOf(v, drop) {
1259
+ if (v === void 0) return null;
1260
+ if (!isObject(v)) {
1261
+ drop?.("railModes");
1262
+ return null;
1263
+ }
1264
+ const out = {};
1265
+ for (const k of Object.keys(v)) {
1266
+ const m = v[k];
1267
+ if ((k === "left" || k === "right") && RAIL_MODES.includes(m)) out[k] = m;
1268
+ else drop?.(`railModes:${k}`);
1269
+ }
1270
+ return Object.keys(out).length > 0 ? out : null;
1271
+ }
1198
1272
  function storeScene(scene) {
1199
1273
  const items = record();
1200
1274
  for (const [id, it] of Object.entries(scene.items)) {
@@ -1208,11 +1282,13 @@ function storeScene(scene) {
1208
1282
  ...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}
1209
1283
  };
1210
1284
  }
1285
+ const modes = railModesOf(scene.railModes);
1211
1286
  return {
1212
1287
  v: 1,
1213
1288
  edges: scene.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 } : {} })),
1214
1289
  floats: scene.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) => ({ id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...f.anchor ? { anchor: f.anchor } : {} })),
1215
- items
1290
+ items,
1291
+ ...modes ? { railModes: modes } : {}
1216
1292
  };
1217
1293
  }
1218
1294
  function readScene(data, base) {
@@ -1241,7 +1317,9 @@ function read(data, base) {
1241
1317
  const drop = (what) => {
1242
1318
  if (!dropped.includes(what)) dropped.push(what);
1243
1319
  };
1244
- for (const k of Object.keys(data)) if (!["v", "edges", "floats", "items"].includes(k)) drop(k);
1320
+ for (const k of Object.keys(data)) if (!["v", "edges", "floats", "items", "railModes"].includes(k)) drop(k);
1321
+ const storedModes = railModesOf(data.railModes, drop);
1322
+ const railModes = storedModes ? { ...base.railModes, ...storedModes } : base.railModes;
1245
1323
  const known = (id) => typeof id === "string" && id !== "__proto__" && Object.hasOwn(base.items, id);
1246
1324
  const isFixed = (id) => known(id) && base.items[id].fixed === true;
1247
1325
  const items = { ...base.items };
@@ -1370,7 +1448,7 @@ function read(data, base) {
1370
1448
  return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...size !== void 0 ? { size } : {} };
1371
1449
  });
1372
1450
  for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);
1373
- let scene = prune({ ...base, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
1451
+ let scene = prune({ ...base, ...railModes ? { railModes } : {}, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
1374
1452
  for (const [id, side] of moves) scene = setSide(scene, id, side);
1375
1453
  return { scene, dropped };
1376
1454
  }
@@ -1433,10 +1511,10 @@ function reservedRect(scene, l, id) {
1433
1511
  const shift = it.zone === "end" ? len - keep2 : it.zone === "center" ? (len - keep2) / 2 : 0;
1434
1512
  return column ? rect(it.rect.x, it.rect.y + shift, it.rect.width, keep2) : rect(it.rect.x + shift, it.rect.y, keep2, it.rect.height);
1435
1513
  }
1436
- function slotAt(c, zone, line, id, place, lands, home = false) {
1514
+ function slotAt(c, zone, line, id, place, lands2, home = false) {
1437
1515
  const result = c.settle(use(moveTo(c.scene, c.dragged, place), c.dragged));
1438
1516
  const isHome = home || c.isHome(result);
1439
- return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout) };
1517
+ return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands2(result) && c.sound(result.layout) };
1440
1518
  }
1441
1519
  function distinctSlots(c, slots) {
1442
1520
  const landing = (s) => s.result.layout.items[c.dragged]?.rect;
@@ -1497,7 +1575,7 @@ function edgeSlots(c, edge, accepts) {
1497
1575
  const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
1498
1576
  const firstKind = formsOf(scene.items[dragged], axisOf(edge.side))[0]?.kind;
1499
1577
  const titles = edge.items.filter((id) => base.items[id]?.edge === edge.id && base.items[id].fixed && !!formsOf(scene.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows);
1500
- const lands = ({ layout: after }) => {
1578
+ const lands2 = ({ layout: after }) => {
1501
1579
  const me = after.items[dragged];
1502
1580
  if (me.edge !== edge.id || me.inMenu) return false;
1503
1581
  if (titles.length === 0) return true;
@@ -1537,7 +1615,7 @@ function edgeSlots(c, edge, accepts) {
1537
1615
  const next = members.slice(k).find(shown);
1538
1616
  const before = members.slice(0, k).reverse().find(shown);
1539
1617
  const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];
1540
- const s = { ...slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands), order: before0 + members.slice(0, k).filter(aimed).length };
1618
+ const s = { ...slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands2), order: before0 + members.slice(0, k).filter(aimed).length };
1541
1619
  const movesFixed = members0.some((id) => {
1542
1620
  const b = base.items[id];
1543
1621
  const a = s.result.layout.items[id];
@@ -1577,7 +1655,7 @@ function edgeSpec(c, edge) {
1577
1655
  const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
1578
1656
  const outer = edge.side === "left" ? r.x : edge.side === "right" ? r.x + r.width : edge.side === "top" ? r.y : r.y + r.height;
1579
1657
  const inward = (depth) => edge.side === "left" || edge.side === "top" ? [outer, outer + depth] : [outer - depth, outer];
1580
- const across = (after) => inward((el.cross > 0 ? Math.max(el.cross, after?.edges[edge.id]?.cross ?? 0) : strip) + data.inward);
1658
+ const across2 = (after) => inward((el.cross > 0 ? Math.max(el.cross, after?.edges[edge.id]?.cross ?? 0) : strip) + data.inward);
1581
1659
  const drawn = el.cross > 0;
1582
1660
  const marker = (s) => {
1583
1661
  const slot = s.result.layout.items[dragged].rect;
@@ -1598,7 +1676,7 @@ function edgeSpec(c, edge) {
1598
1676
  holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
1599
1677
  reserved,
1600
1678
  cards,
1601
- across,
1679
+ across: across2,
1602
1680
  owned: inward(drawn ? el.cross : Math.min(strip, data.place)),
1603
1681
  ownedAlong: null,
1604
1682
  drawn,
@@ -1758,14 +1836,14 @@ function ownership(c, live, alongOf) {
1758
1836
  const roomOf = (s) => {
1759
1837
  const b = bandOf(s);
1760
1838
  const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
1761
- const across = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
1839
+ const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
1762
1840
  const rs = taken.get(s).filter((r) => overlaps(r, b));
1763
1841
  const ends = [.../* @__PURE__ */ new Set([...along(b), ...rs.flatMap(along)])].filter((x) => x >= along(b)[0] && x <= along(b)[1]).sort((p, q) => p - q);
1764
1842
  const owned = [];
1765
1843
  for (let k = 1; k < ends.length; k++) {
1766
1844
  const [u, w] = [ends[k - 1], ends[k]];
1767
- const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across);
1768
- if (w - u > EPS && less([across(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
1845
+ const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across2);
1846
+ if (w - u > EPS && less([across2(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
1769
1847
  }
1770
1848
  const half = s.edge ? halfBandOf(s.edge) : null;
1771
1849
  const raw = bodySpans(s.edge);
@@ -1796,9 +1874,9 @@ function ownership(c, live, alongOf) {
1796
1874
  const e = s.edge;
1797
1875
  if (!e) return [];
1798
1876
  const column = axisOf(e.side) === "column";
1799
- const across = (a, b) => column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9);
1800
- const reserved = Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid)).map(([, p]) => column ? across(p.rect.y, p.rect.y + p.rect.height) : across(p.rect.x, p.rect.x + p.rect.width));
1801
- return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across(a, b))].filter((b) => area(b) > EPS);
1877
+ const across2 = (a, b) => column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9);
1878
+ 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));
1879
+ return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area(b) > EPS);
1802
1880
  };
1803
1881
  const drawnBySpec = /* @__PURE__ */ new Map();
1804
1882
  const drawnBesides = (s) => {
@@ -2005,7 +2083,7 @@ function clipTiles(tiles, own, chrome, lost) {
2005
2083
  return;
2006
2084
  }
2007
2085
  const yields = t.kind === "refuse" ? besides(t) : [];
2008
- const cuts = [...placed.flatMap(coverOf), ...(t.spec && taken.get(t.spec)) ?? [], ...yields, ...data.virtual ? [] : bodiesOf(t), ...solid, ...chrome];
2086
+ const cuts = [...placed.flatMap(coverOf), ...(t.spec && taken.get(t.spec)) ?? [], ...yields, ...data.virtual || t.kind === "refuse" ? [] : bodiesOf(t), ...solid, ...chrome];
2009
2087
  const pieces = clip(t.hit, cuts);
2010
2088
  if (pieces.length === 0) {
2011
2089
  if (t.kind !== "refuse") gone.add(t);
@@ -2046,7 +2124,7 @@ function railOuter(c, side) {
2046
2124
  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 + EPS : e.rect.x >= placeOuter - EPS));
2047
2125
  return barOutside ? placeOuter : windowEdge;
2048
2126
  }
2049
- function columnLines(c, side) {
2127
+ function columnLines(c, side, railLands) {
2050
2128
  const { scene, now, dragged } = c;
2051
2129
  const cols = scene.edges.filter((e) => e.side === side && e.column === true).map((edge) => ({ edge, l: now.edges[edge.id] })).filter((x) => x.l && !x.l.folded && !x.l.rides && x.l.cross > 0).sort((a, b) => a.edge.ring - b.edge.ring).map((x) => ({ edge: x.edge, r: x.l.rect }));
2052
2130
  const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);
@@ -2059,7 +2137,7 @@ function columnLines(c, side) {
2059
2137
  cols.forEach((x) => lines.push({ x: outerX(x.r), ring: rings.before(x.edge), at: atOf(x.edge) - 0.5 }));
2060
2138
  if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1].r), ring: rings.after(cols[cols.length - 1].edge), at: atOf(cols[cols.length - 1].edge) + 0.5 });
2061
2139
  else lines.push({ x: side === "left" ? now.content.x : now.content.x + now.content.width, ring: rings.count, at: Math.max(-1, ...scene.edges.filter((e) => e.side === side).map(atOf)) + 0.5 });
2062
- const lands = (r) => {
2140
+ const lands2 = (r) => {
2063
2141
  const me = r.layout.items[dragged];
2064
2142
  const el = me.edge ? r.layout.edges[me.edge] : void 0;
2065
2143
  return !!el && !me.inMenu && !el.folded && !el.rides && r.scene !== c.scene;
@@ -2067,11 +2145,11 @@ function columnLines(c, side) {
2067
2145
  const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
2068
2146
  const stage = c.scene.stage;
2069
2147
  const dir = side === "left" ? 1 : -1;
2070
- const outside = (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 + EPS : e.rect.x >= x - EPS));
2071
- const railFirst = !!c.scene.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
2148
+ 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 + EPS : e.rect.x >= x - EPS));
2149
+ const railFirst = railLands && !!c.scene.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
2072
2150
  const placeOf = (l, i) => {
2073
2151
  const atEdge = side === "left" ? l.x <= stage.x + EPS : l.x >= stage.x + stage.width - EPS;
2074
- if (i > 0 || outside(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };
2152
+ 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] };
2075
2153
  const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
2076
2154
  const boundary = clamp(l.x, stage.x, stage.x + stage.width);
2077
2155
  const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
@@ -2088,7 +2166,7 @@ function columnLines(c, side) {
2088
2166
  lay: { phase: EDGE_KINDS.columnLine.phase, side, at: l.at },
2089
2167
  vertical: false,
2090
2168
  zones: [{ zone: "start", a: Math.max(p.zone[0], stage.x), b: Math.min(p.zone[1], stage.x + stage.width) }],
2091
- slots: [slotAt(c, "start", p.line, targetId({ kind: "column", side, ring: l.ring }), { kind: "column", side, ring: l.ring }, lands)],
2169
+ slots: [slotAt(c, "start", p.line, targetId({ kind: "column", side, ring: l.ring }), { kind: "column", side, ring: l.ring }, lands2)],
2092
2170
  refuse: () => "no-room",
2093
2171
  own: null,
2094
2172
  holds: false,
@@ -2140,7 +2218,7 @@ function railStops(c, side) {
2140
2218
  stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
2141
2219
  }
2142
2220
  const ownRail = now.items[dragged]?.rail === side;
2143
- const lands = (r) => r.layout.items[dragged].rail === side && r.scene !== c.scene;
2221
+ const lands2 = (r) => r.layout.items[dragged].rail === side && r.scene !== c.scene;
2144
2222
  const at = zone;
2145
2223
  return {
2146
2224
  id: virtualEdgeId("rail", side),
@@ -2150,7 +2228,7 @@ function railStops(c, side) {
2150
2228
  lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
2151
2229
  vertical: true,
2152
2230
  zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
2153
- slots: stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
2231
+ slots: stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands2, ownRail)),
2154
2232
  refuse: () => "no-room",
2155
2233
  own: null,
2156
2234
  holds: false,
@@ -2165,6 +2243,147 @@ function railStops(c, side) {
2165
2243
  };
2166
2244
  }
2167
2245
 
2246
+ // src/scene/targets/rail-strip.ts
2247
+ var across = (side, outer, width) => side === "left" ? [outer, width] : [outer - width, width];
2248
+ function lands(c, result, side) {
2249
+ const me = result.layout.items[c.dragged];
2250
+ if (!me || me.floating || me.inMenu || (result.scene.items[c.dragged]?.from ?? 0) < 1 || c.isHome(result) || !c.sound(result.layout)) return false;
2251
+ const sideOf = (edgeId) => edgeId ? result.layout.edges[edgeId]?.side : void 0;
2252
+ return me.rail === side || sideOf(me.rides) === side || sideOf(me.edge) === side;
2253
+ }
2254
+ function columnStrip(c, side, policy) {
2255
+ const edge = railColumnOf(c.scene, side, c.kind);
2256
+ if (!edge) return null;
2257
+ const own = c.now.items[c.dragged];
2258
+ if (own?.edge === edge.id && (c.scene.items[c.dragged]?.from ?? 0) >= 1) return null;
2259
+ const place = { kind: "rail", side, ring: edge.ring };
2260
+ const moved = moveTo(c.scene, c.dragged, place);
2261
+ if (moved === c.scene) return null;
2262
+ const result = c.settle(use(moved, c.dragged));
2263
+ const el = result.layout.edges[edge.id];
2264
+ if (!el || el.rect.width <= EPS || !lands(c, result, side)) return null;
2265
+ const r = el.rect;
2266
+ const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
2267
+ const [x, w] = across(side, side === "left" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));
2268
+ return { side, rect: rect(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
2269
+ }
2270
+ function declaredStrip(c, side, policy) {
2271
+ const template = c.scene.columns?.[side];
2272
+ const spec = c.scene.rails?.[side];
2273
+ if (!template || !spec || !zoneTakes(template, "start", c.kind) || !spec.accepts.includes(c.kind)) return null;
2274
+ const stops2 = railStops(c, side);
2275
+ const slots = (stops2?.slots ?? []).filter((s) => !s.home && s.place.kind === "rail" && lands(c, s.result, side)).sort((a2, b2) => a2.line - b2.line);
2276
+ if (!stops2 || slots.length === 0) return null;
2277
+ const a = Math.min(...stops2.zones.map((z) => z.a));
2278
+ const b = Math.max(...stops2.zones.map((z) => z.b));
2279
+ const drawn = c.now.rails[side];
2280
+ const outer = drawn && drawn.segments.length > 0 ? side === "left" ? drawn.rect.x : drawn.rect.x + drawn.rect.width : railOuter(c, side);
2281
+ const [x, w] = across(side, outer, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, spec.width));
2282
+ const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
2283
+ return {
2284
+ side,
2285
+ rect: rect(x, a, w, b - a),
2286
+ slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
2287
+ };
2288
+ }
2289
+ var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => overlaps(p, s) ? subtract(p, s) : [p]), [...pieces]).filter((p) => p.width >= 1 && p.height >= 1);
2290
+ var largest2 = (rs) => rs.reduce((m, r) => r.width * r.height > m.width * m.height ? r : m);
2291
+ 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);
2292
+ function withRailStrips(c, targets2, refusals2) {
2293
+ const policy = railPolicyOf(c.scene, c.kind);
2294
+ const strips = policy ? ["left", "right"].map((side) => c.scene.rails?.[side] ? declaredStrip(c, side, policy) : columnStrip(c, side, policy)).filter((s) => s !== null) : [];
2295
+ if (!policy || strips.length === 0) return { targets: [...targets2], refusals: [...refusals2], strips: [] };
2296
+ const sides = new Set(strips.map((s) => s.side));
2297
+ const rects = strips.map((s) => s.rect);
2298
+ const out = [];
2299
+ for (const t of targets2) {
2300
+ if (t.place.kind === "rail" && sides.has(t.place.side)) continue;
2301
+ if (t.free || t.place.kind === "none") {
2302
+ out.push(t.free && !policy.floatNearEdge ? clearOfStrips(t, c.dragged, rects) : t);
2303
+ continue;
2304
+ }
2305
+ const was = t.hits ?? [t.hit];
2306
+ const pieces = outside(was, rects);
2307
+ if (pieces.length === 0) {
2308
+ const moved = t.id.startsWith("strip:") ? insideStrips(t.hit, strips) : null;
2309
+ if (moved) out.push({ ...withoutHits(t), hit: moved });
2310
+ continue;
2311
+ }
2312
+ if (sameRects(pieces, was)) {
2313
+ out.push(t);
2314
+ continue;
2315
+ }
2316
+ out.push({ ...withoutHits(t), hit: largest2(pieces), ...pieces.length > 1 ? { hits: pieces } : {} });
2317
+ }
2318
+ const refused = [];
2319
+ const railEdges = new Set([...sides].map((side) => virtualEdgeId("rail", side)));
2320
+ for (const r of refusals2) {
2321
+ if (railEdges.has(r.edge)) continue;
2322
+ const pieces = outside([r.hit], rects);
2323
+ if (pieces.length) refused.push(pieces.length === 1 && sameRects(pieces, [r.hit]) ? r : { ...r, hit: largest2(pieces) });
2324
+ }
2325
+ const vertical = (r) => {
2326
+ const side = c.scene.edges.find((e) => e.id === r.edge)?.side;
2327
+ return side ? side === "left" || side === "right" : r.edge === virtualEdgeId("rail", "left") || r.edge === virtualEdgeId("rail", "right");
2328
+ };
2329
+ const pos = (r) => vertical(r) ? [r.hit.y, r.hit.x] : [r.hit.x, r.hit.y];
2330
+ const groups = /* @__PURE__ */ new Map();
2331
+ for (const r of refused) groups.set(`${r.edge}
2332
+ ${r.zone}`, [...groups.get(`${r.edge}
2333
+ ${r.zone}`) ?? [], r]);
2334
+ const numbered = /* @__PURE__ */ new Map();
2335
+ for (const group of groups.values())
2336
+ 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 })));
2337
+ const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
2338
+ for (const s of strips) {
2339
+ const grown = s.side === "left" ? rect(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
2340
+ for (const sl of s.slots) {
2341
+ const [a, b] = sl.along;
2342
+ const slot = sl.result.layout.items[c.dragged].rect;
2343
+ const result = sl.result;
2344
+ out.push({
2345
+ id: sl.id,
2346
+ priority: 1,
2347
+ hit: rect(s.rect.x, a, s.rect.width, b - a),
2348
+ armedHit: rect(grown.x, a, grown.width, b - a),
2349
+ arm: "dwell",
2350
+ strip: s.rect,
2351
+ slot,
2352
+ item: c.dragged,
2353
+ place: sl.place,
2354
+ after: () => result
2355
+ });
2356
+ }
2357
+ }
2358
+ return { targets: out, refusals: renumbered, strips: rects };
2359
+ }
2360
+ var withoutHits = (t) => {
2361
+ const { hits: _pieces, ...rest } = t;
2362
+ return rest;
2363
+ };
2364
+ function insideStrips(r, strips) {
2365
+ const s = strips.find((x) => overlaps(x.rect, r));
2366
+ if (!s) return null;
2367
+ return s.side === "left" ? rect(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect(s.rect.x - r.width, r.y, r.width, r.height);
2368
+ }
2369
+ function clearOfStrips(t, dragged, strips) {
2370
+ return {
2371
+ ...t,
2372
+ after(point, grab) {
2373
+ const first = t.after(point, grab);
2374
+ const at = first.layout.items[dragged]?.rect;
2375
+ if (!at) return first;
2376
+ let dx = 0;
2377
+ for (const s of strips) {
2378
+ const r = rect(at.x + dx, at.y, at.width, at.height);
2379
+ if (!overlaps(r, s)) continue;
2380
+ dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
2381
+ }
2382
+ return dx === 0 ? first : t.after({ x: at.x + dx + (grab?.x ?? at.width / 2), y: point.y }, grab);
2383
+ }
2384
+ };
2385
+ }
2386
+
2168
2387
  // src/scene/targets.ts
2169
2388
  function specsOf(c, kind) {
2170
2389
  const { scene } = c;
@@ -2172,8 +2391,9 @@ function specsOf(c, kind) {
2172
2391
  for (const side of ["left", "right"]) {
2173
2392
  const template = scene.columns?.[side];
2174
2393
  if (!template || !zoneTakes(template, "start", kind)) continue;
2175
- specs.push(...columnLines(c, side));
2176
- if (scene.rails?.[side]?.accepts.includes(kind)) specs.push(railStops(c, side));
2394
+ const rail = scene.rails?.[side]?.accepts.includes(kind) ? railStops(c, side) : null;
2395
+ specs.push(...columnLines(c, side, !!rail?.slots.some((s) => s.ok)));
2396
+ specs.push(rail);
2177
2397
  }
2178
2398
  return specs.filter((s) => s !== null);
2179
2399
  }
@@ -2273,8 +2493,22 @@ function generate(scene, dragged, options) {
2273
2493
  (scene.blocked ?? []).forEach((b, i) => {
2274
2494
  targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
2275
2495
  });
2276
- if (ownRect && !ownRect.floating) targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit: ownHome ?? ownRect.rect, item: dragged, place: { kind: "home" }, after: homeAfter });
2277
- return { targets: targets2, refusals: refused, lost: [...new Set(lost)].filter((id) => !targets2.some((t) => t.id === id)) };
2496
+ const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
2497
+ const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
2498
+ if (sameAsHome.length) targets2.splice(0, targets2.length, ...targets2.filter((t) => !sameAsHome.includes(t)));
2499
+ const homeSlot = targets2.findIndex((t) => t.place.kind === "home");
2500
+ if (homeSlot >= 0 && homePieces.length) {
2501
+ const t = targets2[homeSlot];
2502
+ targets2[homeSlot] = { ...t, hits: [...t.hits ?? [t.hit], ...homePieces] };
2503
+ }
2504
+ if (ownRect && !ownRect.floating) {
2505
+ const hit = ownHome ?? ownRect.rect;
2506
+ const pieces = homeSlot < 0 && homePieces.length ? { hits: [hit, ...homePieces] } : {};
2507
+ targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit, ...pieces, item: dragged, place: { kind: "home" }, after: homeAfter });
2508
+ }
2509
+ const lostIds = [...new Set(lost)].filter((id) => !targets2.some((t) => t.id === id));
2510
+ const layered = withRailStrips(c, targets2, refused);
2511
+ return { targets: layered.targets, refusals: layered.refusals, lost: lostIds };
2278
2512
  }
2279
2513
  function targets(scene, dragged, options = {}) {
2280
2514
  return generate(scene, dragged, options).targets;
@@ -2306,11 +2540,16 @@ function stops(scene, dragged, options = {}) {
2306
2540
  export {
2307
2541
  SIDES,
2308
2542
  ZONES,
2543
+ RAIL_MODES,
2544
+ RAIL_VISIBILITIES,
2545
+ RAIL_STRIP_MIN,
2546
+ DEFAULT_RAIL_MAGNET,
2309
2547
  DEFAULT_STRIP,
2310
2548
  DEFAULT_HIT_BAND,
2311
2549
  DEFAULT_FLOAT_SIZE,
2312
2550
  zoneTakes,
2313
2551
  zonesTaking,
2552
+ railModeOf,
2314
2553
  isOutsideSideBar,
2315
2554
  isSideBar,
2316
2555
  floatOrientOf,
@@ -2332,6 +2571,7 @@ export {
2332
2571
  raise,
2333
2572
  orient,
2334
2573
  resize,
2574
+ setRailMode,
2335
2575
  setSide,
2336
2576
  homeFor,
2337
2577
  dockHome,
@@ -2342,4 +2582,4 @@ export {
2342
2582
  refusals,
2343
2583
  stops
2344
2584
  };
2345
- //# sourceMappingURL=chunk-3GIUOVQH.js.map
2585
+ //# sourceMappingURL=chunk-PC5UHBW4.js.map