@n-uf/placement 26.11.24 → 26.11.25
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.
- package/CHANGELOG.md +74 -0
- package/README.md +66 -28
- package/dist/{chunk-LPMZ2FFR.js → chunk-3P6VOXA6.js} +2 -2
- package/dist/chunk-3P6VOXA6.js.map +1 -0
- package/dist/{chunk-CJA6LRHN.js → chunk-7ASCUAGV.js} +5 -7
- package/dist/chunk-7ASCUAGV.js.map +1 -0
- package/dist/{chunk-RL3QB5SM.js → chunk-KGZCYLQN.js} +10 -10
- package/dist/chunk-KGZCYLQN.js.map +1 -0
- package/dist/{chunk-2H3CSPEH.js → chunk-OYGOJWAX.js} +2 -2
- package/dist/{chunk-XUC5BU4N.js → chunk-SZKU7CRX.js} +575 -499
- package/dist/chunk-SZKU7CRX.js.map +1 -0
- package/dist/chunk-WM5FJ3IS.js +47 -0
- package/dist/chunk-WM5FJ3IS.js.map +1 -0
- package/dist/{constructions-VDK_mwmz.d.ts → constructions-DSEjvWMP.d.ts} +1 -1
- package/dist/desk.d.ts +3 -3
- package/dist/desk.js +3 -3
- package/dist/dock.d.ts +3 -3
- package/dist/dock.js +2 -2
- package/dist/geometry-CkZ6Fcfb.d.ts +48 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/dist/{model-DPTu2EtG.d.ts → model-mm16NrSX.d.ts} +1 -1
- package/dist/panels.d.ts +5 -4
- package/dist/panels.js +6 -5
- package/dist/scene-cases.d.ts +4 -4
- package/dist/scene-cases.js +15 -16
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +5 -39
- package/dist/scene.js +3 -3
- package/dist/stack.d.ts +4 -4
- package/dist/stack.js +2 -2
- package/dist/stack.js.map +1 -1
- package/dist/{target-D3PiLg44.d.ts → target-C-HJjPcz.d.ts} +1 -1
- package/dist/{targets-B6eLC-52.d.ts → targets-CBpO_LEy.d.ts} +4 -6
- package/dist/{targets-DwwIWPpN.d.ts → targets-CDR5Towj.d.ts} +74 -60
- package/dist/targets.d.ts +4 -4
- package/dist/targets.js +6 -7
- package/dist/targets.js.map +1 -1
- package/dist/toolbar.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-CJA6LRHN.js.map +0 -1
- package/dist/chunk-LPMZ2FFR.js.map +0 -1
- package/dist/chunk-QMTNB2C3.js +0 -17
- package/dist/chunk-QMTNB2C3.js.map +0 -1
- package/dist/chunk-RL3QB5SM.js.map +0 -1
- package/dist/chunk-XUC5BU4N.js.map +0 -1
- package/dist/geometry-mL-GTRti.d.ts +0 -28
- /package/dist/{chunk-2H3CSPEH.js.map → chunk-OYGOJWAX.js.map} +0 -0
|
@@ -5,11 +5,19 @@ import {
|
|
|
5
5
|
formMain,
|
|
6
6
|
formSetsCross,
|
|
7
7
|
wrapLines
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-KGZCYLQN.js";
|
|
9
9
|
import {
|
|
10
|
+
COLUMN_REACH,
|
|
11
|
+
EPS,
|
|
12
|
+
PLANE,
|
|
13
|
+
RAIL_EDGE,
|
|
14
|
+
area,
|
|
10
15
|
clampInto,
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
contains,
|
|
17
|
+
overlaps,
|
|
18
|
+
rect,
|
|
19
|
+
subtract
|
|
20
|
+
} from "./chunk-WM5FJ3IS.js";
|
|
13
21
|
|
|
14
22
|
// src/scene/model.ts
|
|
15
23
|
var SIDES = ["top", "right", "bottom", "left"];
|
|
@@ -70,7 +78,6 @@ function floatShape(item, f) {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
// src/scene/solve.ts
|
|
73
|
-
var EPS = 1e-6;
|
|
74
81
|
var finite = (x, fallback) => typeof x === "number" && Number.isFinite(x) ? x : fallback;
|
|
75
82
|
var px = (x) => Math.max(0, finite(x, 0));
|
|
76
83
|
function cutOrder(edges) {
|
|
@@ -78,6 +85,16 @@ function cutOrder(edges) {
|
|
|
78
85
|
const sideRank = (e) => e.side === "top" || e.side === "left" ? 0 : 1;
|
|
79
86
|
return edges.map((e, i) => ({ e, i })).sort((a, b) => phase(a.e) - phase(b.e) || sideRank(a.e) - sideRank(b.e) || finite(a.e.ring, 0) - finite(b.e.ring, 0) || a.i - b.i).map((x) => x.e);
|
|
80
87
|
}
|
|
88
|
+
function layKeys(scene) {
|
|
89
|
+
const isSide = (e) => e.side === "left" || e.side === "right";
|
|
90
|
+
const phase = (e) => e.mode === "overlay" ? 4 : isSide(e) ? 2 : e.span === "between" ? 3 : e.outsideInset === true ? 0 : 1;
|
|
91
|
+
return new Map(cutOrder(scene.edges).map((e, at) => [e.id, { phase: phase(e), side: e.side, at }]));
|
|
92
|
+
}
|
|
93
|
+
function pushes(a, b) {
|
|
94
|
+
if (a.phase === 4 || b.phase === 4) return false;
|
|
95
|
+
if (a.phase !== b.phase) return a.phase < b.phase;
|
|
96
|
+
return a.side === b.side && a.at < b.at;
|
|
97
|
+
}
|
|
81
98
|
var ZONE_RANK = { start: 0, center: 1, end: 2 };
|
|
82
99
|
function zoneSorted(scene, ids) {
|
|
83
100
|
return ids.map((id, i) => ({ id, i, z: ZONE_RANK[zoneOf(scene.items[id])] })).sort((a, b) => a.z - b.z || a.i - b.i).map((x) => x.id);
|
|
@@ -365,6 +382,7 @@ function solve(given, options = {}) {
|
|
|
365
382
|
return edge.side === "top" ? rect(area3.x, area3.y + thick, area3.width, area3.height - thick) : edge.side === "bottom" ? rect(area3.x, area3.y, area3.width, area3.height - thick) : edge.side === "left" ? rect(area3.x + thick, area3.y, area3.width - thick, area3.height) : rect(area3.x, area3.y, area3.width - thick, area3.height);
|
|
366
383
|
};
|
|
367
384
|
const rails = {};
|
|
385
|
+
const railPlaces = {};
|
|
368
386
|
const gutter = px(scene.gutter);
|
|
369
387
|
let columnRoom;
|
|
370
388
|
let outerArea = stage;
|
|
@@ -503,19 +521,23 @@ function solve(given, options = {}) {
|
|
|
503
521
|
let railRect = null;
|
|
504
522
|
let gap = px(side === "left" ? inset.left : inset.right);
|
|
505
523
|
let barLaid = false;
|
|
524
|
+
let railPlace = null;
|
|
525
|
+
const placeRail = () => {
|
|
526
|
+
const w = railW(side);
|
|
527
|
+
const lead = barLaid ? gap : 0;
|
|
528
|
+
return side === "left" ? rect(x0 - lead, area3.y, w, H) : rect(x1 + lead - w, area3.y, w, H);
|
|
529
|
+
};
|
|
506
530
|
for (const c of mine) {
|
|
507
|
-
if (!
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
x0 +=
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
x1 -= w2 - lead + after;
|
|
531
|
+
if (!railPlace && !outsideSideBar(c)) {
|
|
532
|
+
railPlace = placeRail();
|
|
533
|
+
if (railed.length > 0) {
|
|
534
|
+
railRect = railPlace;
|
|
535
|
+
const lead = barLaid ? gap : 0;
|
|
536
|
+
const after = barLaid ? Math.max(gap, gutter) : gutter;
|
|
537
|
+
if (side === "left") x0 += railPlace.width - lead + after;
|
|
538
|
+
else x1 -= railPlace.width - lead + after;
|
|
539
|
+
gap = after;
|
|
517
540
|
}
|
|
518
|
-
gap = after;
|
|
519
541
|
}
|
|
520
542
|
if (outsideSideBar(c)) barLaid = true;
|
|
521
543
|
const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free };
|
|
@@ -593,6 +615,7 @@ function solve(given, options = {}) {
|
|
|
593
615
|
}
|
|
594
616
|
rails[side] = { rect: railRect, segments };
|
|
595
617
|
}
|
|
618
|
+
if (scene.rails?.[side]) railPlaces[side] = railPlace ?? placeRail();
|
|
596
619
|
}
|
|
597
620
|
return rect(x0, area3.y, Math.max(0, x1 - x0), H);
|
|
598
621
|
};
|
|
@@ -658,7 +681,7 @@ function solve(given, options = {}) {
|
|
|
658
681
|
items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? "open", floating: true };
|
|
659
682
|
floats.push(f.id);
|
|
660
683
|
}
|
|
661
|
-
return { items, edges, content, floats, rails, ...columnRoom !== void 0 ? { columnRoom } : {}, notes };
|
|
684
|
+
return { items, edges, content, floats, rails, railPlaces, ...columnRoom !== void 0 ? { columnRoom } : {}, notes };
|
|
662
685
|
}
|
|
663
686
|
|
|
664
687
|
// src/scene/changes.ts
|
|
@@ -1056,145 +1079,376 @@ function read(data, base) {
|
|
|
1056
1079
|
}
|
|
1057
1080
|
|
|
1058
1081
|
// src/scene/targets.ts
|
|
1059
|
-
var ZONE_ORDER = { start: 0, center: 1, end: 2 };
|
|
1060
|
-
var EPS2 = 1e-6;
|
|
1061
|
-
var PLANE = rect(-1e9, -1e9, 2e9, 2e9);
|
|
1062
|
-
var area = (r) => Math.max(0, r.width) * Math.max(0, r.height);
|
|
1063
|
-
var overlaps = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS2 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS2;
|
|
1064
|
-
var contains = (r, p) => p.x >= r.x - EPS2 && p.x <= r.x + r.width + EPS2 && p.y >= r.y - EPS2 && p.y <= r.y + r.height + EPS2;
|
|
1065
1082
|
var RAIL_REACH = 24;
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
h = parts.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1080
|
-
}
|
|
1081
|
-
return area(h) > EPS2 ? h : null;
|
|
1083
|
+
var EDGE_KINDS = {
|
|
1084
|
+
bar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false },
|
|
1085
|
+
sideBar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false },
|
|
1086
|
+
column: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false },
|
|
1087
|
+
barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false },
|
|
1088
|
+
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 },
|
|
1089
|
+
railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false },
|
|
1090
|
+
columnLine: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true }
|
|
1091
|
+
};
|
|
1092
|
+
function edgeKindOf(scene, e) {
|
|
1093
|
+
if (e.compact) return "rail";
|
|
1094
|
+
if (e.side === "top" || e.side === "bottom") return e.span === "between" ? "barBetween" : "bar";
|
|
1095
|
+
return isSideBar(scene, e) ? "sideBar" : "column";
|
|
1082
1096
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
+
var opensEmpty = (scene, edge, kind) => EDGE_KINDS[edgeKindOf(scene, edge)].opens === "any" || zoneTakes(edge, "start", kind);
|
|
1098
|
+
function reservedRect(scene, l, id) {
|
|
1099
|
+
const it = l.items[id];
|
|
1100
|
+
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
1101
|
+
const f = e ? formsOf(scene.items[id], axisOf(e.side))[it.form] : void 0;
|
|
1102
|
+
if (!e || !f?.main.grows) return it.rect;
|
|
1103
|
+
const column = axisOf(e.side) === "column";
|
|
1104
|
+
const len = column ? it.rect.height : it.rect.width;
|
|
1105
|
+
const keep2 = Math.min(len, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len));
|
|
1106
|
+
const shift = it.zone === "end" ? len - keep2 : it.zone === "center" ? (len - keep2) / 2 : 0;
|
|
1107
|
+
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);
|
|
1108
|
+
}
|
|
1109
|
+
function placeKey(s, id) {
|
|
1110
|
+
const it = Object.hasOwn(s.items, id) ? s.items[id] : void 0;
|
|
1111
|
+
const byZone = (items) => ZONES.flatMap((z) => items.filter((x) => zoneOf(s.items[x]) === z));
|
|
1112
|
+
return JSON.stringify({
|
|
1113
|
+
edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? "" : e.id, byZone(e.items), e.size ?? null])).sort(),
|
|
1114
|
+
floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),
|
|
1115
|
+
from: it?.from ?? 0,
|
|
1116
|
+
align: it?.align ?? "start"
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
function slotAt(c, zone, line, id, place, lands, home = false) {
|
|
1120
|
+
const result = c.settle(use(moveTo(c.scene, c.dragged, place), c.dragged));
|
|
1121
|
+
const isHome = home || c.isHome(result);
|
|
1122
|
+
return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout) };
|
|
1123
|
+
}
|
|
1124
|
+
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 > EPS)), [...spans]);
|
|
1125
|
+
function zoneSpans(scene, base, edge, reach, probe) {
|
|
1126
|
+
const el = base.edges[edge.id];
|
|
1127
|
+
const column = axisOf(edge.side) === "column";
|
|
1128
|
+
const main0 = column ? el.rect.y : el.rect.x;
|
|
1129
|
+
const length = column ? el.rect.height : el.rect.width;
|
|
1130
|
+
if (EDGE_KINDS[edgeKindOf(scene, edge)].zoneExtent === "thirds")
|
|
1131
|
+
return ZONES.map((zone, k) => ({ zone, a: k === 0 ? main0 - reach : main0 + length * k / 3, b: k === 2 ? main0 + length + reach : main0 + length * (k + 1) / 3 }));
|
|
1132
|
+
const at = (r) => column ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1133
|
+
const declared = new Set(edge.zoneAccepts ? ZONES.filter((z) => edge.zoneAccepts[z] !== void 0) : ["start"]);
|
|
1134
|
+
const placed = /* @__PURE__ */ new Map();
|
|
1135
|
+
for (const [id, it] of Object.entries(base.items)) {
|
|
1136
|
+
if (it.edge !== edge.id || it.inMenu) continue;
|
|
1137
|
+
const z = zoneOf(scene.items[id]);
|
|
1138
|
+
const [a, b] = at(it.rect);
|
|
1139
|
+
const was = placed.get(z);
|
|
1140
|
+
placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
|
|
1141
|
+
declared.add(z);
|
|
1097
1142
|
}
|
|
1098
|
-
|
|
1143
|
+
const anchor = { start: main0, center: main0 + length / 2, end: main0 + length };
|
|
1144
|
+
const spans = ZONES.filter((z) => declared.has(z)).map((zone) => ({ zone, s: placed.get(zone) ?? probe(zone) ?? [anchor[zone], anchor[zone]] }));
|
|
1145
|
+
return spans.map(({ zone, s }, i) => ({
|
|
1146
|
+
zone,
|
|
1147
|
+
a: i === 0 ? main0 - reach : (spans[i - 1].s[1] + s[0]) / 2,
|
|
1148
|
+
b: i === spans.length - 1 ? main0 + length + reach : (s[1] + spans[i + 1].s[0]) / 2
|
|
1149
|
+
}));
|
|
1099
1150
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
const column = side === "
|
|
1107
|
-
const
|
|
1108
|
-
const
|
|
1109
|
-
const
|
|
1110
|
-
const
|
|
1111
|
-
const
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1151
|
+
function edgeSpec(c, edge) {
|
|
1152
|
+
const { scene, rest, now, base, dragged, kind } = c;
|
|
1153
|
+
const el = base.edges[edge.id];
|
|
1154
|
+
if (!el || el.folded || el.rides) return null;
|
|
1155
|
+
const edgeKind = edgeKindOf(rest, edge);
|
|
1156
|
+
const data = EDGE_KINDS[edgeKind];
|
|
1157
|
+
const column = axisOf(edge.side) === "column";
|
|
1158
|
+
const at = (r2) => column ? r2.y : r2.x;
|
|
1159
|
+
const len = (r2) => column ? r2.height : r2.width;
|
|
1160
|
+
const main0 = at(el.rect);
|
|
1161
|
+
const length = len(el.rect);
|
|
1162
|
+
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
1163
|
+
const accepts = edge.accepts.includes(kind);
|
|
1164
|
+
if (!accepts && (empty || area(el.rect) <= EPS)) return null;
|
|
1165
|
+
if (accepts && empty && !opensEmpty(rest, edge, kind)) return null;
|
|
1166
|
+
const ownNow = now.items[dragged];
|
|
1167
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && !ownNow.inMenu ? ownNow.rect : null;
|
|
1168
|
+
const restEdge = rest.edges.find((e) => e.id === edge.id);
|
|
1169
|
+
const slotId = (zone, at2) => restEdge.items.length === 0 ? `strip:${edge.id}:${zone}` : `gap:${edge.id}:${zone}:${at2}`;
|
|
1170
|
+
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);
|
|
1171
|
+
const lands = ({ layout: after }) => {
|
|
1172
|
+
const me = after.items[dragged];
|
|
1173
|
+
if (me.edge !== edge.id || me.inMenu) return false;
|
|
1174
|
+
if (titles.length === 0) return true;
|
|
1175
|
+
if (me.form !== 0) return false;
|
|
1176
|
+
return edge.items.every((id) => {
|
|
1177
|
+
const a = after.items[id];
|
|
1178
|
+
const b = base.items[id];
|
|
1179
|
+
if (!a || !b || b.edge !== edge.id || id === dragged) return true;
|
|
1180
|
+
if (!titles.includes(id)) return a.form === b.form && !!a.inMenu === !!b.inMenu;
|
|
1181
|
+
const f = formsOf(scene.items[id], axisOf(edge.side))[a.form];
|
|
1182
|
+
return !f || (column ? a.rect.height : a.rect.width) >= formMain(f, "natural", after.edges[edge.id].cross) - 0.5;
|
|
1183
|
+
});
|
|
1116
1184
|
};
|
|
1117
|
-
const
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
const
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
if (
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
if (a + keep2 <= mid + EPS2) h0 = Math.max(h0, a + keep2);
|
|
1147
|
-
else h1 = Math.min(h1, a);
|
|
1185
|
+
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
1186
|
+
const menuLen = el.menu ? len(el.menu.rect) : 0;
|
|
1187
|
+
const occupied = (id) => base.items[id]?.fixed ? reservedRect(scene, base, id) : base.items[id].rect;
|
|
1188
|
+
const shown = (id) => base.items[id]?.edge === edge.id && !base.items[id].inMenu;
|
|
1189
|
+
const drawnOf = (z) => restEdge.items.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
|
|
1190
|
+
const startEnd = (() => {
|
|
1191
|
+
const s = drawnOf("start");
|
|
1192
|
+
return s.length ? at(s[s.length - 1]) + len(s[s.length - 1]) : main0 + pad.start;
|
|
1193
|
+
})();
|
|
1194
|
+
const endStart = (() => {
|
|
1195
|
+
const e = drawnOf("end");
|
|
1196
|
+
return e.length ? at(e[0]) : main0 + length - pad.end - menuLen;
|
|
1197
|
+
})();
|
|
1198
|
+
const anchorLine = { start: main0 + pad.start, center: Math.min(Math.max(main0 + length / 2, startEnd), Math.max(startEnd, endStart)), end: main0 + length - pad.end - menuLen };
|
|
1199
|
+
const slots = [];
|
|
1200
|
+
for (const zone of ZONES) {
|
|
1201
|
+
if (!accepts || !zoneTakes(edge, zone, kind)) continue;
|
|
1202
|
+
const members = restEdge.items.filter((id) => zoneOf(rest.items[id]) === zone);
|
|
1203
|
+
for (let k = 0; k <= members.length; k++) {
|
|
1204
|
+
const next = members.slice(k).find(shown);
|
|
1205
|
+
const before = members.slice(0, k).reverse().find(shown);
|
|
1206
|
+
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];
|
|
1207
|
+
const s = slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands);
|
|
1208
|
+
const movesFixed = restEdge.items.some((id) => {
|
|
1209
|
+
const b = base.items[id];
|
|
1210
|
+
const a = s.result.layout.items[id];
|
|
1211
|
+
return !!b?.fixed && b.edge === edge.id && (!a || Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5);
|
|
1212
|
+
});
|
|
1213
|
+
if (!movesFixed) slots.push(s);
|
|
1148
1214
|
}
|
|
1149
1215
|
}
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
const
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1216
|
+
const spanOf = (r2) => [at(r2), at(r2) + len(r2)];
|
|
1217
|
+
const grows = (id) => !!formsOf(scene.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows;
|
|
1218
|
+
const reserved = Object.entries(base.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
|
|
1219
|
+
const zones = zoneSpans(rest, base, edge, c.reach, (zone) => {
|
|
1220
|
+
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
1221
|
+
const me = s?.result.layout.items[dragged];
|
|
1222
|
+
return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
|
|
1223
|
+
});
|
|
1224
|
+
const r = el.rect;
|
|
1225
|
+
const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
|
|
1226
|
+
const nowCross = now.edges[edge.id]?.cross ?? 0;
|
|
1227
|
+
const outer = edge.side === "left" ? r.x : edge.side === "right" ? r.x + r.width : edge.side === "top" ? r.y : r.y + r.height;
|
|
1228
|
+
const inward = (depth) => edge.side === "left" || edge.side === "top" ? [outer, outer + depth] : [outer - depth, outer];
|
|
1229
|
+
const across = (after) => inward((el.cross > 0 || nowCross > 0 ? Math.max(el.cross, nowCross, after?.edges[edge.id]?.cross ?? 0) : strip) + data.inward);
|
|
1230
|
+
const ownCross = ownNow?.edge === edge.id ? el.cross : Math.max(el.cross, nowCross);
|
|
1231
|
+
const drawn = ownCross > 0;
|
|
1232
|
+
const marker = (s) => {
|
|
1233
|
+
const slot = s.result.layout.items[dragged].rect;
|
|
1234
|
+
const e = s.result.layout.edges[edge.id];
|
|
1235
|
+
return column ? rect(e.rect.x, slot.y, e.cross, 0) : rect(slot.x, e.rect.y, 0, e.cross);
|
|
1236
|
+
};
|
|
1237
|
+
const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
|
|
1238
|
+
return {
|
|
1239
|
+
id: edge.id,
|
|
1240
|
+
key: edge.id,
|
|
1241
|
+
kind: edgeKind,
|
|
1242
|
+
lay: c.lay.get(edge.id),
|
|
1243
|
+
vertical: column,
|
|
1244
|
+
zones,
|
|
1245
|
+
slots,
|
|
1246
|
+
refuse: (zone) => takes(zone) ? "no-room" : accepts || area(el.rect) > EPS ? "not-accepted" : null,
|
|
1247
|
+
own: ownHere,
|
|
1248
|
+
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
1249
|
+
reserved,
|
|
1250
|
+
across,
|
|
1251
|
+
owned: inward(drawn ? ownCross : Math.min(strip, data.place)),
|
|
1252
|
+
ownedAlong: null,
|
|
1253
|
+
drawn,
|
|
1254
|
+
marker
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function tileEdge(c, spec, cuts, lost) {
|
|
1258
|
+
const data = EDGE_KINDS[spec.kind];
|
|
1259
|
+
const v = spec.vertical;
|
|
1260
|
+
const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
|
|
1261
|
+
const band = (a, b, after) => {
|
|
1262
|
+
const [c0, c1] = spec.across(after);
|
|
1263
|
+
return v ? rect(c0, a, c1 - c0, b - a) : rect(a, c0, b - a, c1 - c0);
|
|
1264
|
+
};
|
|
1265
|
+
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
1266
|
+
const tile = (zone, hit, more) => ({ edge: spec.id, key: spec.key, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
1267
|
+
const refused = (zone, hit, reason) => tile(zone, hit, { kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason });
|
|
1268
|
+
const reserved = spec.reserved;
|
|
1269
|
+
const split = (t) => {
|
|
1270
|
+
const h = t.hit;
|
|
1271
|
+
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
1272
|
+
const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
|
|
1273
|
+
const part = (a, b) => v ? rect(a, h.y, b - a, h.height) : rect(h.x, a, h.width, b - a);
|
|
1274
|
+
const beyond = less([[h0, h1]], [spec.owned]);
|
|
1275
|
+
if (beyond.length === 0) return [t];
|
|
1276
|
+
if (c1 - c0 <= EPS) return [{ ...t, order: data.overreach }];
|
|
1277
|
+
const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
|
|
1278
|
+
return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
|
|
1279
|
+
};
|
|
1280
|
+
const landing = (s) => s.result.layout.items[c.dragged]?.rect;
|
|
1281
|
+
const sameMove = (a, b) => {
|
|
1282
|
+
if (a.zone !== b.zone) return false;
|
|
1283
|
+
if (a.home && b.home) return true;
|
|
1284
|
+
const [p, q] = [landing(a), landing(b)];
|
|
1285
|
+
return Math.abs(a.line - b.line) < EPS && (!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);
|
|
1286
|
+
};
|
|
1287
|
+
const slots = spec.slots.filter((s, i) => !spec.slots.slice(0, i).some((o) => sameMove(o, s)));
|
|
1288
|
+
const out = [];
|
|
1289
|
+
for (const z of spec.zones) {
|
|
1290
|
+
const room = less([[z.a, z.b]], [...cuts, ...reserved]).filter(([a, b]) => b - a > EPS);
|
|
1291
|
+
if (room.length === 0) continue;
|
|
1292
|
+
const pieces = own ? less(room, [own]) : room;
|
|
1293
|
+
const mine = slots.filter((s) => s.zone === z.zone && !(spec.holds && s.home) && pieces.some(([a, b]) => b > s.line - data.reach + EPS && a < s.line + data.reach - EPS));
|
|
1294
|
+
const reason = spec.refuse(z.zone);
|
|
1295
|
+
for (const [pa, pb] of pieces) {
|
|
1296
|
+
const lines = mine.map((s) => s.line);
|
|
1297
|
+
const lo = Math.min(z.a, ...lines);
|
|
1298
|
+
const hi = Math.max(z.b, ...lines);
|
|
1299
|
+
const free = less([[z.a, z.b]], reserved);
|
|
1300
|
+
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
1301
|
+
const spread = (x) => {
|
|
1302
|
+
if (hi - lo <= EPS || freeLen <= EPS) return x;
|
|
1303
|
+
let d = (x - lo) / (hi - lo) * freeLen;
|
|
1304
|
+
for (const [a, b] of free) {
|
|
1305
|
+
if (d <= b - a + EPS) return a + Math.min(d, b - a);
|
|
1306
|
+
d -= b - a;
|
|
1307
|
+
}
|
|
1308
|
+
return free[free.length - 1][1];
|
|
1309
|
+
};
|
|
1310
|
+
const past = lines.some((x) => x < z.a - EPS || x > z.b + EPS);
|
|
1311
|
+
const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
|
|
1312
|
+
const proj = (x) => {
|
|
1313
|
+
const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
|
|
1314
|
+
const p = own ? nearer(q, own) : q;
|
|
1315
|
+
if (pieces.some(([a, b]) => p >= a - EPS && p <= b + EPS)) return p;
|
|
1316
|
+
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);
|
|
1317
|
+
};
|
|
1318
|
+
const inPiece = mine.filter((s) => proj(s.line) >= pa - EPS && proj(s.line) <= pb + EPS).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
|
|
1319
|
+
const projected = inPiece.map((s) => proj(s.line));
|
|
1320
|
+
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
|
|
1321
|
+
if (inPiece.length === 0) {
|
|
1322
|
+
const lone = reason === "no-room" && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
|
|
1323
|
+
const near = mine.length === 0 || mine.some((s) => pb > s.line - data.reach + EPS && pa < s.line + data.reach - EPS);
|
|
1324
|
+
if (reason && near) out.push(...split(refused(z.zone, band(pa, pb), lone ? "own-place" : reason)));
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
inPiece.forEach((s, i) => {
|
|
1328
|
+
const p = at[i];
|
|
1329
|
+
const a = Math.max(i === 0 ? pa : (at[i - 1] + p) / 2, p - data.reach);
|
|
1330
|
+
const b = Math.min(i === inPiece.length - 1 ? pb : (p + at[i + 1]) / 2, p + data.reach);
|
|
1331
|
+
if (b - a <= EPS) {
|
|
1332
|
+
if (s.ok) lost.push(s.id);
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
const line = Math.min(Math.max(p, a), b);
|
|
1336
|
+
const hit = band(a, b, s.result.layout);
|
|
1337
|
+
if (!s.ok) out.push(...split(refused(z.zone, hit, "no-room")));
|
|
1338
|
+
else if (s.home) out.push(...split(tile(z.zone, hit, { kind: "home", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: { kind: "home" } })));
|
|
1339
|
+
else out.push(...split(tile(z.zone, hit, { kind: "slot", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged].rect })));
|
|
1340
|
+
});
|
|
1159
1341
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1342
|
+
}
|
|
1343
|
+
if (own && spec.own) {
|
|
1344
|
+
const home = spec.slots.find((s) => s.home);
|
|
1345
|
+
const [a, b] = own;
|
|
1346
|
+
const h = band(a, b);
|
|
1347
|
+
const o = spec.own;
|
|
1348
|
+
const hit = v ? rect(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) : rect(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));
|
|
1349
|
+
out.push(tile(home?.zone ?? zoneOf(c.scene.items[c.dragged]), hit, { kind: "home", id: home ? home.id : `home:${c.dragged}`, order: 0, priority: home ? data.priority : 1, keep: null, place: { kind: "home" } }));
|
|
1350
|
+
}
|
|
1351
|
+
return out;
|
|
1352
|
+
}
|
|
1353
|
+
function columnLines(c, side) {
|
|
1354
|
+
const { rest, base, dragged } = c;
|
|
1355
|
+
const cols = rest.edges.filter((e) => e.side === side && e.column === true).map((edge) => ({ edge, l: base.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 }));
|
|
1356
|
+
const own = Object.values(base.edges).filter((e) => e.side === side && e.rect.height > 0);
|
|
1357
|
+
const span = own[0]?.rect ?? base.content;
|
|
1358
|
+
const rings = sideRings(rest.edges, side);
|
|
1359
|
+
const ringOf = (e) => rings.get(e.id) ?? e.ring;
|
|
1360
|
+
const lines = [];
|
|
1361
|
+
const outerX = (r) => side === "left" ? r.x : r.x + r.width;
|
|
1362
|
+
const innerX = (r) => side === "left" ? r.x + r.width : r.x;
|
|
1363
|
+
const atOf = (e) => c.lay.get(e.id)?.at ?? 0;
|
|
1364
|
+
cols.forEach((x) => lines.push({ x: outerX(x.r), ring: ringOf(x.edge), at: atOf(x.edge) - 0.5 }));
|
|
1365
|
+
if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1].r), ring: ringOf(cols[cols.length - 1].edge) + 1, at: atOf(cols[cols.length - 1].edge) + 0.5 });
|
|
1366
|
+
else lines.push({ x: side === "left" ? base.content.x : base.content.x + base.content.width, ring: rings.size, at: Math.max(-1, ...rest.edges.filter((e) => e.side === side).map(atOf)) + 0.5 });
|
|
1367
|
+
const lands = (r) => {
|
|
1368
|
+
const me = r.layout.items[dragged];
|
|
1369
|
+
const el = me.edge ? r.layout.edges[me.edge] : void 0;
|
|
1370
|
+
return !!el && !me.inMenu && !el.folded && !el.rides && r.scene !== c.scene;
|
|
1371
|
+
};
|
|
1372
|
+
const { reach, place } = EDGE_KINDS.columnLine;
|
|
1373
|
+
return lines.map((l) => ({
|
|
1374
|
+
id: `column:${side}`,
|
|
1375
|
+
key: `column:${side}:${l.ring}`,
|
|
1376
|
+
kind: "columnLine",
|
|
1377
|
+
lay: { phase: EDGE_KINDS.columnLine.phase, side, at: l.at },
|
|
1378
|
+
vertical: false,
|
|
1379
|
+
zones: [{ zone: "start", a: l.x - reach, b: l.x + reach }],
|
|
1380
|
+
slots: [slotAt(c, "start", l.x, `column:${side}:${l.ring}`, { kind: "column", side, ring: l.ring }, lands)],
|
|
1381
|
+
refuse: () => "no-room",
|
|
1382
|
+
own: null,
|
|
1383
|
+
holds: false,
|
|
1384
|
+
reserved: [],
|
|
1385
|
+
across: () => [span.y, span.y + span.height],
|
|
1386
|
+
owned: [span.y, span.y + span.height],
|
|
1387
|
+
ownedAlong: [l.x - place / 2, l.x + place / 2],
|
|
1388
|
+
drawn: false,
|
|
1389
|
+
marker: (s) => rect(s.line, span.y, 0, span.height)
|
|
1390
|
+
}));
|
|
1391
|
+
}
|
|
1392
|
+
function railStops(c, side) {
|
|
1393
|
+
const { rest, base, now, dragged } = c;
|
|
1394
|
+
const rail = base.rails[side];
|
|
1395
|
+
const placeRect = base.railPlaces[side];
|
|
1396
|
+
if (!placeRect) return null;
|
|
1397
|
+
const rings = sideRings(rest.edges, side);
|
|
1398
|
+
const mine = rest.edges.filter((e) => e.side === side).sort((a, b) => (rings.get(a.id) ?? 0) - (rings.get(b.id) ?? 0));
|
|
1399
|
+
const ringOf = (id) => rings.get(id) ?? 0;
|
|
1400
|
+
const stops2 = [];
|
|
1401
|
+
let zone;
|
|
1402
|
+
if (rail && rail.segments.length > 0) {
|
|
1403
|
+
zone = rail.rect;
|
|
1404
|
+
const groups = [];
|
|
1405
|
+
for (const s of rail.segments) {
|
|
1406
|
+
const g = groups[groups.length - 1];
|
|
1407
|
+
if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;
|
|
1408
|
+
else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });
|
|
1163
1409
|
}
|
|
1410
|
+
for (const g of groups) stops2.push({ y: g.y0, ring: ringOf(g.edge) });
|
|
1411
|
+
const last = groups[groups.length - 1];
|
|
1412
|
+
stops2.push({ y: last.y1, ring: ringOf(last.edge) + 1 });
|
|
1413
|
+
} else {
|
|
1414
|
+
const firstCol = mine.find((e) => e.column === true);
|
|
1415
|
+
zone = rect(side === "left" ? placeRect.x : placeRect.x + placeRect.width - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
|
|
1416
|
+
stops2.push({ y: placeRect.y, ring: firstCol ? ringOf(firstCol.id) : mine.length });
|
|
1164
1417
|
}
|
|
1165
|
-
|
|
1418
|
+
const ownRail = now.items[dragged]?.rail === side;
|
|
1419
|
+
const lands = (r) => r.layout.items[dragged].rail === side && r.scene !== c.scene;
|
|
1420
|
+
const at = zone;
|
|
1421
|
+
return {
|
|
1422
|
+
id: `rail:${side}`,
|
|
1423
|
+
key: `rail:${side}`,
|
|
1424
|
+
kind: "railStop",
|
|
1425
|
+
// The rail lies outside every edge on its side: laid first among them.
|
|
1426
|
+
lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
|
|
1427
|
+
vertical: true,
|
|
1428
|
+
zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
|
|
1429
|
+
slots: stops2.map((s) => slotAt(c, "start", s.y, `rail:${side}:${s.ring}`, { kind: "rail", side, ring: s.ring }, lands, ownRail)),
|
|
1430
|
+
refuse: () => "no-room",
|
|
1431
|
+
own: null,
|
|
1432
|
+
holds: false,
|
|
1433
|
+
reserved: [],
|
|
1434
|
+
across: () => [at.x, at.x + at.width],
|
|
1435
|
+
// A drawn rail owns its rect; where none shows, a thin band of its place at the side's outer boundary.
|
|
1436
|
+
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],
|
|
1437
|
+
ownedAlong: null,
|
|
1438
|
+
drawn: !!rail && rail.segments.length > 0,
|
|
1439
|
+
marker: (s) => rect(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
|
|
1440
|
+
};
|
|
1166
1441
|
}
|
|
1167
|
-
function
|
|
1442
|
+
function generate(scene, dragged, options) {
|
|
1168
1443
|
const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
|
|
1169
|
-
if (!item || item.fixed || item.closed) return [];
|
|
1444
|
+
if (!item || item.fixed || item.closed) return { targets: [], refusals: [], lost: [] };
|
|
1170
1445
|
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
1171
1446
|
const settle = (s) => ({ scene: s, layout: solve(s, prev) });
|
|
1172
1447
|
const now = solve(scene, prev);
|
|
1173
1448
|
const rest = lift(scene, dragged);
|
|
1174
1449
|
const base = solve(rest, prev);
|
|
1175
|
-
const reach = Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0);
|
|
1176
1450
|
const chrome = scene.chrome ?? [];
|
|
1177
|
-
const grows = (l, id) => {
|
|
1178
|
-
const it = l.items[id];
|
|
1179
|
-
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
1180
|
-
return !!e && !!formsOf(scene.items[id], axisOf(e.side))[it.form]?.main.grows;
|
|
1181
|
-
};
|
|
1182
|
-
const fixedRects = (l) => Object.entries(l.items).filter(([id, it]) => it.fixed && !grows(l, id)).map(([, it]) => it.rect);
|
|
1183
|
-
const blockers = [...fixedRects(now), ...fixedRects(base), ...chrome];
|
|
1184
|
-
const out = [];
|
|
1185
|
-
const docked = [];
|
|
1186
|
-
for (const edge of rest.edges) {
|
|
1187
|
-
if (!edge.accepts.includes(item.kind)) continue;
|
|
1188
|
-
docked.push(...edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chrome, settle));
|
|
1189
|
-
}
|
|
1190
|
-
for (const side of ["left", "right"]) {
|
|
1191
|
-
const template = scene.columns?.[side];
|
|
1192
|
-
if (!template || !zoneTakes(template, "start", item.kind)) continue;
|
|
1193
|
-
docked.push(...columnTargets(scene, rest, base, side, dragged, blockers, settle));
|
|
1194
|
-
if (scene.rails?.[side]?.accepts.includes(item.kind)) docked.push(...railTargets(scene, rest, base, side, dragged, blockers, settle));
|
|
1195
|
-
}
|
|
1196
1451
|
const here = placeKey(scene, dragged);
|
|
1197
|
-
const ownRail = now.items[dragged]?.rail;
|
|
1198
1452
|
const noteKey = (n) => "edge" in n && (n.code === "overflow" || n.code === "too-wide") ? `${n.edge}:${n.code}:${"id" in n ? n.id : ""}` : null;
|
|
1199
1453
|
const hadNotes = new Set(base.notes.map(noteKey).filter((k) => k !== null));
|
|
1200
1454
|
const sound = (after) => {
|
|
@@ -1216,72 +1470,195 @@ function targets(scene, dragged, options = {}) {
|
|
|
1216
1470
|
const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && id !== dragged).map(([id]) => reservedRect(scene, after, id));
|
|
1217
1471
|
return !chrome.some((c2) => overlaps(me.rect, c2)) && !fixedAfter.some((f) => overlaps(me.rect, f));
|
|
1218
1472
|
};
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
const edgeOfGap = (t) => t.place.kind === "gap" ? rest.edges.find((e) => e.id === t.place.edge) : void 0;
|
|
1227
|
-
const plainGapHits = out.filter((t) => t.id.startsWith("gap:") && !edgeOfGap(t)?.compact).map((t) => t.hit);
|
|
1228
|
-
for (let i = 0; i < out.length; i++) {
|
|
1229
|
-
const t = out[i];
|
|
1230
|
-
const e = edgeOfGap(t);
|
|
1231
|
-
if (!t.id.startsWith("gap:") || !e?.compact || !plainGapHits.some((h2) => overlaps(h2, t.hit))) continue;
|
|
1232
|
-
const h = t.hit;
|
|
1233
|
-
const core = e.side === "left" ? rect(h.x, h.y, h.width - RAIL_REACH, h.height) : e.side === "right" ? rect(h.x + RAIL_REACH, h.y, h.width - RAIL_REACH, h.height) : e.side === "top" ? rect(h.x, h.y, h.width, h.height - RAIL_REACH) : rect(h.x, h.y + RAIL_REACH, h.width, h.height - RAIL_REACH);
|
|
1234
|
-
out[i] = { ...t, hit: core };
|
|
1473
|
+
const c = { scene, rest, now, base, dragged, kind: item.kind, reach: Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0), settle, isHome: (r) => placeKey(r.scene, dragged) === here, sound, lay: layKeys(scene) };
|
|
1474
|
+
const specs = rest.edges.map((edge) => edgeSpec(c, edge));
|
|
1475
|
+
for (const side of ["left", "right"]) {
|
|
1476
|
+
const template = scene.columns?.[side];
|
|
1477
|
+
if (!template || !zoneTakes(template, "start", item.kind)) continue;
|
|
1478
|
+
specs.push(...columnLines(c, side));
|
|
1479
|
+
if (scene.rails?.[side]?.accepts.includes(item.kind)) specs.push(railStops(c, side));
|
|
1235
1480
|
}
|
|
1236
|
-
const
|
|
1237
|
-
const
|
|
1238
|
-
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
const
|
|
1245
|
-
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
if (!
|
|
1252
|
-
|
|
1481
|
+
const ownEdge = now.items[dragged]?.edge;
|
|
1482
|
+
const live = specs.filter((s) => s !== null);
|
|
1483
|
+
const bandOf = (s) => {
|
|
1484
|
+
const a = Math.min(...s.zones.map((z) => z.a));
|
|
1485
|
+
const b = Math.max(...s.zones.map((z) => z.b));
|
|
1486
|
+
return s.vertical ? rect(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);
|
|
1487
|
+
};
|
|
1488
|
+
const ownedRectOf = (s) => {
|
|
1489
|
+
const b = bandOf(s);
|
|
1490
|
+
if (!s.ownedAlong) return b;
|
|
1491
|
+
const [a0, a1] = s.ownedAlong;
|
|
1492
|
+
return s.vertical ? rect(b.x, a0, b.width, a1 - a0) : rect(a0, b.y, a1 - a0, b.height);
|
|
1493
|
+
};
|
|
1494
|
+
const ownRect = now.items[dragged];
|
|
1495
|
+
const homeRect = (() => {
|
|
1496
|
+
if (!ownRect || ownRect.floating || !ownEdge) return null;
|
|
1497
|
+
const o = ownRect.rect;
|
|
1498
|
+
const s = live.find((x) => x.id === ownEdge);
|
|
1499
|
+
if (!s || ownRect.inMenu) return o;
|
|
1500
|
+
const [c0, c1] = s.across();
|
|
1501
|
+
return s.vertical ? rect(Math.min(c0, o.x), o.y, Math.max(c1, o.x + o.width) - Math.min(c0, o.x), o.height) : rect(o.x, Math.min(c0, o.y), o.width, Math.max(c1, o.y + o.height) - Math.min(c0, o.y));
|
|
1502
|
+
})();
|
|
1503
|
+
const owners = [
|
|
1504
|
+
// Home first: its tile is its own, for every edge but its own (which tiles it as its own interval).
|
|
1505
|
+
...homeRect && ownEdge ? [{ id: ownEdge, key: ownEdge, rect: homeRect, lay: { phase: -1, side: "", at: -Infinity }, place: false }] : [],
|
|
1506
|
+
// Every edge the tiler reads: what it owns, drawn or a band of its place (a column line's band about its line).
|
|
1507
|
+
...live.map((s) => ({ id: s.id, key: s.key, rect: ownedRectOf(s), lay: s.lay, place: !s.drawn })).filter((o) => area(o.rect) > EPS),
|
|
1508
|
+
// Every drawn rect, with the item lifted and as it is now (the item's own edge only lifted): the edges the tiler
|
|
1509
|
+
// doesn't read (folded, riding, taking nothing) and the ones that move when the item lifts.
|
|
1510
|
+
...[...Object.entries(base.edges), ...Object.entries(now.edges).filter(([id]) => id !== ownEdge)].filter(([id, e]) => area(e.rect) > EPS && c.lay.has(id)).map(([id, e]) => ({ id, key: id, rect: e.rect, lay: c.lay.get(id), place: false }))
|
|
1511
|
+
];
|
|
1512
|
+
const wins = (o, s) => {
|
|
1513
|
+
if (o.key === s.key) return false;
|
|
1514
|
+
if (pushes(o.lay, s.lay)) return true;
|
|
1515
|
+
if (pushes(s.lay, o.lay)) return false;
|
|
1516
|
+
const place = !s.drawn;
|
|
1517
|
+
return o.place === place ? !place || o.lay.at < s.lay.at : !o.place;
|
|
1518
|
+
};
|
|
1519
|
+
const taken = new Map(
|
|
1520
|
+
live.map((s) => [
|
|
1521
|
+
s.key,
|
|
1522
|
+
[
|
|
1523
|
+
...owners.filter((o) => wins(o, s)).map((o) => o.rect),
|
|
1524
|
+
...EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.key !== s.key && !wins(o, s)).flatMap((o) => subtract(o.rect, ownedRectOf(s))) : []
|
|
1525
|
+
]
|
|
1526
|
+
])
|
|
1527
|
+
);
|
|
1528
|
+
const bodySpans = (id) => {
|
|
1529
|
+
const e = rest.edges.find((x) => x.id === id);
|
|
1530
|
+
const bandOpt = e?.hitBand ?? DEFAULT_HIT_BAND;
|
|
1531
|
+
if (!e || bandOpt === "middle") return [];
|
|
1532
|
+
const column = axisOf(e.side) === "column";
|
|
1533
|
+
const half = Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND) / 2;
|
|
1534
|
+
return Object.entries(base.items).filter(([iid, p]) => p.edge === id && p.formKind === "open" && iid !== dragged).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 > EPS);
|
|
1535
|
+
};
|
|
1536
|
+
const cutsOf = (s) => {
|
|
1537
|
+
const b = bandOf(s);
|
|
1538
|
+
const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1539
|
+
const across = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
1540
|
+
const rs = taken.get(s.key).filter((r) => overlaps(r, b));
|
|
1541
|
+
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);
|
|
1542
|
+
const owned = [];
|
|
1543
|
+
for (let k = 1; k < ends.length; k++) {
|
|
1544
|
+
const [u, w] = [ends[k - 1], ends[k]];
|
|
1545
|
+
const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across);
|
|
1546
|
+
if (w - u > EPS && less([across(b)], over).length === 0) owned.push([u, w]);
|
|
1547
|
+
}
|
|
1548
|
+
return [...owned, ...bodySpans(s.id)];
|
|
1549
|
+
};
|
|
1550
|
+
const lost = [];
|
|
1551
|
+
const tiles = live.flatMap((spec) => tileEdge(c, spec, cutsOf(spec), lost));
|
|
1552
|
+
const homeEdge = scene.edges.find((e) => e.id === ownRect?.edge);
|
|
1553
|
+
if (ownRect && homeEdge && !ownRect.floating && !tiles.some((t) => t.order === 0))
|
|
1554
|
+
tiles.push({ edge: homeEdge.id, key: homeEdge.id, edgeKind: edgeKindOf(scene, homeEdge), vertical: axisOf(homeEdge.side) === "column", zone: zoneOf(item), order: 0, kind: "home", id: `home:${dragged}`, priority: 1, place: { kind: "home" }, hit: ownRect.rect, keep: null });
|
|
1555
|
+
const grows = (l, id) => {
|
|
1556
|
+
const it = l.items[id];
|
|
1557
|
+
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
1558
|
+
return !!e && !!formsOf(scene.items[id], axisOf(e.side))[it.form]?.main.grows;
|
|
1559
|
+
};
|
|
1560
|
+
const solid = [.../* @__PURE__ */ new Set([now, base])].flatMap((l) => Object.entries(l.items).filter(([id, it]) => it.fixed && !grows(l, id)).map(([, it]) => it.rect));
|
|
1561
|
+
const bodies = (id) => {
|
|
1562
|
+
const e = rest.edges.find((x) => x.id === id);
|
|
1563
|
+
if (!e) return [];
|
|
1564
|
+
const column = axisOf(e.side) === "column";
|
|
1565
|
+
const across = (a, b) => column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9);
|
|
1566
|
+
const reserved = Object.entries(base.items).filter(([iid, p]) => p.edge === id && p.fixed && !p.inMenu && !grows(base, iid)).map(([, p]) => column ? across(p.rect.y, p.rect.y + p.rect.height) : across(p.rect.x, p.rect.x + p.rect.width));
|
|
1567
|
+
return [...reserved, ...bodySpans(id).map(([a, b]) => across(a, b))].filter((b) => area(b) > EPS);
|
|
1568
|
+
};
|
|
1569
|
+
const placed = [];
|
|
1570
|
+
const later = [];
|
|
1571
|
+
const clip = (r, cuts) => cuts.reduce((ps, cut) => ps.flatMap((p) => subtract(p, cut)), [r]);
|
|
1572
|
+
const landed = /* @__PURE__ */ new Map();
|
|
1573
|
+
const gone = /* @__PURE__ */ new Set();
|
|
1574
|
+
for (const t of [...tiles].sort((a, b) => a.order - b.order)) {
|
|
1575
|
+
if (t.order === 0) {
|
|
1576
|
+
placed.push(t);
|
|
1253
1577
|
continue;
|
|
1254
1578
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
if (!spans) continue;
|
|
1260
|
-
const [g0, g1] = vertical ? [g.y, g.y + g.height] : [g.x, g.x + g.width];
|
|
1261
|
-
if (g0 <= a0 + EPS2 && g1 > a0) a0 = Math.min(a1, g1);
|
|
1262
|
-
else if (g1 >= a1 - EPS2 && g0 < a1) a1 = Math.max(a0, g0);
|
|
1579
|
+
const data = EDGE_KINDS[t.edgeKind];
|
|
1580
|
+
if (data.virtual && t.kind === "refuse") {
|
|
1581
|
+
later.push(t);
|
|
1582
|
+
continue;
|
|
1263
1583
|
}
|
|
1264
|
-
if (
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1267
|
-
|
|
1584
|
+
if (t.kind === "reach") {
|
|
1585
|
+
const of = t.of;
|
|
1586
|
+
const pieces2 = clip(t.hit, [...placed.map((p) => p.hit), ...owners.filter((o) => o.key !== t.key).map((o) => o.rect), ...bodies(t.edge), ...solid, ...chrome]);
|
|
1587
|
+
const at = landed.get(of) ?? [];
|
|
1588
|
+
if (at.length === 0 && gone.has(of)) {
|
|
1589
|
+
const line = t.vertical ? of.keep.y : of.keep.x;
|
|
1590
|
+
const on = pieces2.filter((p) => t.vertical ? p.y <= line + EPS && line <= p.y + p.height + EPS : p.x <= line + EPS && line <= p.x + p.width + EPS);
|
|
1591
|
+
const kept2 = (on.length > 0 ? on : pieces2).reduce((a, p) => !a || area(p) > area(a) ? p : a, null);
|
|
1592
|
+
if (kept2) {
|
|
1593
|
+
placed.push({ ...of, hit: kept2 });
|
|
1594
|
+
gone.delete(of);
|
|
1595
|
+
}
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
for (const i of at) {
|
|
1599
|
+
const h = placed[i].hit;
|
|
1600
|
+
const joint = pieces2.find(
|
|
1601
|
+
(p) => t.vertical ? p.y <= h.y + EPS && p.y + p.height >= h.y + h.height - EPS && (Math.abs(p.x - h.x - h.width) < EPS || Math.abs(p.x + p.width - h.x) < EPS) : p.x <= h.x + EPS && p.x + p.width >= h.x + h.width - EPS && (Math.abs(p.y - h.y - h.height) < EPS || Math.abs(p.y + p.height - h.y) < EPS)
|
|
1602
|
+
);
|
|
1603
|
+
if (!joint) continue;
|
|
1604
|
+
const merged = t.vertical ? rect(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) : rect(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));
|
|
1605
|
+
placed[i] = { ...placed[i], hit: merged };
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
const cuts = [...placed.map((p) => p.hit), ...taken.get(t.key) ?? [], ...data.virtual ? [] : bodies(t.edge), ...solid, ...chrome];
|
|
1611
|
+
const pieces = clip(t.hit, cuts);
|
|
1612
|
+
if (pieces.length === 0) {
|
|
1613
|
+
if (t.kind !== "refuse") gone.add(t);
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
if (t.kind === "refuse") {
|
|
1617
|
+
landed.set(t, pieces.map((_, k) => placed.length + k));
|
|
1618
|
+
for (const p of pieces) placed.push({ ...t, hit: p });
|
|
1619
|
+
continue;
|
|
1620
|
+
}
|
|
1621
|
+
const held = t.keep ? pieces.filter((p) => contains(p, t.keep)) : [];
|
|
1622
|
+
const kept = (held.length > 0 ? held : pieces).reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1623
|
+
const sliver = (t.vertical ? kept.height : kept.width) < 1;
|
|
1624
|
+
if (!sliver) {
|
|
1625
|
+
landed.set(t, [placed.length]);
|
|
1626
|
+
placed.push({ ...t, hit: kept });
|
|
1268
1627
|
}
|
|
1628
|
+
for (const p of pieces) if (sliver || p !== kept) (data.virtual ? later : placed).push({ ...t, kind: "refuse", reason: "no-room", hit: p, keep: null });
|
|
1269
1629
|
}
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1630
|
+
for (const t of gone) lost.push(t.id);
|
|
1631
|
+
for (const t of later) for (const p of clip(t.hit, [...placed.map((q) => q.hit), ...solid, ...chrome])) placed.push({ ...t, hit: p });
|
|
1632
|
+
const targets2 = [];
|
|
1633
|
+
const refused = [];
|
|
1634
|
+
const homeAfter = () => ({ scene, layout: now });
|
|
1635
|
+
const keyOf = (t) => `refuse:${t.edge}:${t.zone}`;
|
|
1636
|
+
const pos = (t) => t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y];
|
|
1637
|
+
const rank = /* @__PURE__ */ new Map();
|
|
1638
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1639
|
+
for (const t of placed) if (t.kind === "refuse") byKey.set(keyOf(t), [...byKey.get(keyOf(t)) ?? [], t]);
|
|
1640
|
+
for (const group of byKey.values()) group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((t, n) => rank.set(t, n));
|
|
1641
|
+
let ownHome = null;
|
|
1642
|
+
for (const t of placed) {
|
|
1643
|
+
if (t.kind === "refuse") {
|
|
1644
|
+
const n = rank.get(t);
|
|
1645
|
+
refused.push({ id: n === 0 ? keyOf(t) : `${keyOf(t)}:${n}`, edge: t.edge, zone: t.zone, hit: t.hit, reason: t.reason });
|
|
1646
|
+
continue;
|
|
1278
1647
|
}
|
|
1648
|
+
if (t.kind === "home") {
|
|
1649
|
+
if (t.order === 0) ownHome = t.hit;
|
|
1650
|
+
if (t.id === `home:${dragged}`) continue;
|
|
1651
|
+
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
const result = t.result;
|
|
1655
|
+
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.slot ? { slot: t.slot } : {}, ...t.marker ? { marker: t.marker } : {}, item: dragged, place: t.place, after: () => result });
|
|
1279
1656
|
}
|
|
1280
1657
|
if (scene.floatKinds.includes(item.kind)) {
|
|
1281
1658
|
const was = scene.floats.find((f) => f.id === dragged);
|
|
1282
1659
|
const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
|
|
1283
1660
|
const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
|
|
1284
|
-
|
|
1661
|
+
targets2.push({
|
|
1285
1662
|
id: `float:${dragged}`,
|
|
1286
1663
|
priority: 3,
|
|
1287
1664
|
free: true,
|
|
@@ -1298,139 +1675,17 @@ function targets(scene, dragged, options = {}) {
|
|
|
1298
1675
|
});
|
|
1299
1676
|
}
|
|
1300
1677
|
(scene.blocked ?? []).forEach((b, i) => {
|
|
1301
|
-
|
|
1678
|
+
targets2.push({ id: `none:${i}`, priority: 1, hit: rect(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
|
|
1302
1679
|
});
|
|
1303
1680
|
const own = now.items[dragged];
|
|
1304
|
-
if (own && !own.floating)
|
|
1305
|
-
return
|
|
1306
|
-
}
|
|
1307
|
-
function reservedRect(scene, l, id) {
|
|
1308
|
-
const it = l.items[id];
|
|
1309
|
-
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
1310
|
-
const f = e ? formsOf(scene.items[id], axisOf(e.side))[it.form] : void 0;
|
|
1311
|
-
if (!e || !f?.main.grows) return it.rect;
|
|
1312
|
-
const column = axisOf(e.side) === "column";
|
|
1313
|
-
const len = column ? it.rect.height : it.rect.width;
|
|
1314
|
-
const keep2 = Math.min(len, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len));
|
|
1315
|
-
const shift = it.zone === "end" ? len - keep2 : it.zone === "center" ? (len - keep2) / 2 : 0;
|
|
1316
|
-
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);
|
|
1681
|
+
if (own && !own.floating) targets2.push({ id: `home:${dragged}`, priority: 1, hit: ownHome && !targets2.some((t) => t.place.kind === "home") ? ownHome : own.rect, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
1682
|
+
return { targets: targets2, refusals: refused, lost };
|
|
1317
1683
|
}
|
|
1318
|
-
function
|
|
1319
|
-
|
|
1320
|
-
return JSON.stringify({
|
|
1321
|
-
edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? "" : e.id, e.items, e.size ?? null])).sort(),
|
|
1322
|
-
floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),
|
|
1323
|
-
from: it?.from ?? 0,
|
|
1324
|
-
align: it?.align ?? "start"
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
var COLUMN_REACH = 22;
|
|
1328
|
-
var RAIL_EDGE = 10;
|
|
1329
|
-
function openColumns(rest, base, side) {
|
|
1330
|
-
return rest.edges.filter((e) => e.side === side && e.column === true).map((edge) => ({ edge, l: base.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 }));
|
|
1331
|
-
}
|
|
1332
|
-
function sideSpan(base, side) {
|
|
1333
|
-
const own = Object.values(base.edges).filter((e) => e.side === side && e.rect.height > 0);
|
|
1334
|
-
const r = own[0]?.rect ?? base.content;
|
|
1335
|
-
return { y: r.y, height: r.height };
|
|
1336
|
-
}
|
|
1337
|
-
function columnTargets(scene, rest, base, side, dragged, blockers, settle) {
|
|
1338
|
-
const cols = openColumns(rest, base, side);
|
|
1339
|
-
const span = sideSpan(base, side);
|
|
1340
|
-
const rings = sideRings(rest.edges, side);
|
|
1341
|
-
const ringOf = (e) => rings.get(e.id) ?? e.ring;
|
|
1342
|
-
const inner = rings.size;
|
|
1343
|
-
const lines = [];
|
|
1344
|
-
const outerX = (r) => side === "left" ? r.x : r.x + r.width;
|
|
1345
|
-
const innerX = (r) => side === "left" ? r.x + r.width : r.x;
|
|
1346
|
-
cols.forEach((c) => lines.push({ x: outerX(c.r), ring: ringOf(c.edge) }));
|
|
1347
|
-
if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1].r), ring: ringOf(cols[cols.length - 1].edge) + 1 });
|
|
1348
|
-
else lines.push({ x: side === "left" ? base.content.x : base.content.x + base.content.width, ring: inner });
|
|
1349
|
-
const out = [];
|
|
1350
|
-
for (const line of lines) {
|
|
1351
|
-
const place = { kind: "column", side, ring: line.ring };
|
|
1352
|
-
const result = settle(use(moveTo(scene, dragged, place), dragged));
|
|
1353
|
-
const me = result.layout.items[dragged];
|
|
1354
|
-
const el = me?.edge ? result.layout.edges[me.edge] : void 0;
|
|
1355
|
-
if (!me || !el || me.inMenu || el.folded || el.rides || result.scene === scene) continue;
|
|
1356
|
-
const keep2 = { x: line.x, y: span.y + span.height / 2 };
|
|
1357
|
-
const hit = cutClear(rect(line.x - COLUMN_REACH, span.y, 2 * COLUMN_REACH, span.height), blockers, keep2);
|
|
1358
|
-
if (!hit) continue;
|
|
1359
|
-
out.push({ id: `column:${side}:${line.ring}`, priority: 2, hit, slot: me.rect, marker: rect(line.x, span.y, 0, span.height), item: dragged, place, after: () => result });
|
|
1360
|
-
}
|
|
1361
|
-
return out;
|
|
1362
|
-
}
|
|
1363
|
-
function railTargets(scene, rest, base, side, dragged, blockers, settle) {
|
|
1364
|
-
const rail = base.rails[side];
|
|
1365
|
-
const rings = sideRings(rest.edges, side);
|
|
1366
|
-
const mine = rest.edges.filter((e) => e.side === side).sort((a, b) => (rings.get(a.id) ?? 0) - (rings.get(b.id) ?? 0));
|
|
1367
|
-
const ringOf = (id) => rings.get(id) ?? 0;
|
|
1368
|
-
const stops2 = [];
|
|
1369
|
-
let zone;
|
|
1370
|
-
if (rail && rail.segments.length > 0) {
|
|
1371
|
-
zone = rail.rect;
|
|
1372
|
-
const groups = [];
|
|
1373
|
-
for (const s of rail.segments) {
|
|
1374
|
-
const g = groups[groups.length - 1];
|
|
1375
|
-
if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;
|
|
1376
|
-
else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });
|
|
1377
|
-
}
|
|
1378
|
-
for (const g of groups) stops2.push({ y: g.y0, ring: ringOf(g.edge) });
|
|
1379
|
-
const last = groups[groups.length - 1];
|
|
1380
|
-
stops2.push({ y: last.y1, ring: ringOf(last.edge) + 1 });
|
|
1381
|
-
} else {
|
|
1382
|
-
const span = sideSpan(base, side);
|
|
1383
|
-
const firstCol = mine.find((e) => e.column === true);
|
|
1384
|
-
const bars = new Set(rest.edges.filter((e) => e.side === side && isOutsideSideBar(rest, e)).map((e) => e.id));
|
|
1385
|
-
const inner = Object.entries(base.edges).filter(([id, e]) => bars.has(id) && e.rect.height > 0 && e.rect.width > 0).map(([, e]) => side === "left" ? e.rect.x + e.rect.width : e.rect.x);
|
|
1386
|
-
const pad = Number.isFinite(rest.inset?.[side]) ? Math.max(0, rest.inset[side]) : 0;
|
|
1387
|
-
const x = inner.length > 0 ? side === "left" ? Math.max(...inner) : Math.min(...inner) : side === "left" ? rest.stage.x + pad : rest.stage.x + rest.stage.width - pad;
|
|
1388
|
-
zone = rect(side === "left" ? x : x - RAIL_EDGE, span.y, RAIL_EDGE, span.height);
|
|
1389
|
-
stops2.push({ y: span.y, ring: firstCol ? ringOf(firstCol.id) : mine.length });
|
|
1390
|
-
}
|
|
1391
|
-
const out = [];
|
|
1392
|
-
stops2.forEach((s, i) => {
|
|
1393
|
-
const from = i === 0 ? zone.y : (stops2[i - 1].y + s.y) / 2;
|
|
1394
|
-
const to = i === stops2.length - 1 ? zone.y + zone.height : (s.y + stops2[i + 1].y) / 2;
|
|
1395
|
-
if (to - from <= EPS2) return;
|
|
1396
|
-
const place = { kind: "rail", side, ring: s.ring };
|
|
1397
|
-
const result = settle(use(moveTo(scene, dragged, place), dragged));
|
|
1398
|
-
const me = result.layout.items[dragged];
|
|
1399
|
-
if (!me || me.rail !== side || result.scene === scene) return;
|
|
1400
|
-
const hit = cutClear(rect(zone.x, from, zone.width, to - from), blockers, { x: zone.x + zone.width / 2, y: Math.min(Math.max(s.y, from), to) });
|
|
1401
|
-
if (!hit) return;
|
|
1402
|
-
out.push({ id: `rail:${side}:${s.ring}`, priority: 1, hit, slot: me.rect, marker: rect(zone.x, me.rect.y, zone.width, 0), item: dragged, place, after: () => result });
|
|
1403
|
-
});
|
|
1404
|
-
return out;
|
|
1684
|
+
function targets(scene, dragged, options = {}) {
|
|
1685
|
+
return generate(scene, dragged, options).targets;
|
|
1405
1686
|
}
|
|
1406
1687
|
function refusals(scene, dragged, options = {}) {
|
|
1407
|
-
|
|
1408
|
-
if (!item || item.fixed || item.closed) return [];
|
|
1409
|
-
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
1410
|
-
const ts = targets(scene, dragged, options).filter((t) => !t.free);
|
|
1411
|
-
const base = solve(lift(scene, dragged), prev);
|
|
1412
|
-
const hits = ts.map((t) => t.hit);
|
|
1413
|
-
const out = [];
|
|
1414
|
-
const add = (edge, zone, hit, reason) => {
|
|
1415
|
-
const clear = cutAway(hit, hits);
|
|
1416
|
-
if (clear) out.push({ id: `refuse:${edge}:${zone}`, edge, zone, hit: clear, reason });
|
|
1417
|
-
};
|
|
1418
|
-
for (const e of scene.edges) {
|
|
1419
|
-
const r = base.edges[e.id]?.rect;
|
|
1420
|
-
if (!r || r.width <= EPS2 || r.height <= EPS2) continue;
|
|
1421
|
-
const bar = (e.side === "top" || e.side === "bottom") && !e.compact;
|
|
1422
|
-
if (!bar) {
|
|
1423
|
-
if (!e.accepts.includes(item.kind)) add(e.id, "start", r, "not-accepted");
|
|
1424
|
-
continue;
|
|
1425
|
-
}
|
|
1426
|
-
ZONES.forEach((zone, k) => {
|
|
1427
|
-
const third = rect(r.x + r.width * k / 3, r.y, r.width / 3, r.height);
|
|
1428
|
-
const mine = ts.some((t) => (t.place.kind === "gap" || t.place.kind === "home") && t.id.startsWith(`gap:${e.id}:`) && overlaps(t.hit, third));
|
|
1429
|
-
if (mine) return;
|
|
1430
|
-
add(e.id, zone, third, zoneTakes(e, zone, item.kind) ? "no-room" : "not-accepted");
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
1433
|
-
return out;
|
|
1688
|
+
return generate(scene, dragged, options).refusals;
|
|
1434
1689
|
}
|
|
1435
1690
|
var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
|
|
1436
1691
|
function stops(scene, dragged, options = {}) {
|
|
@@ -1452,185 +1707,6 @@ function stops(scene, dragged, options = {}) {
|
|
|
1452
1707
|
};
|
|
1453
1708
|
return list.map((t, i) => ({ t, i, k: key(t) })).sort((a, b) => a.k[0] - b.k[0] || a.k[1] - b.k[1] || a.k[2] - b.k[2] || a.i - b.i).map((x) => x.t);
|
|
1454
1709
|
}
|
|
1455
|
-
function edgeTargets(scene, rest, now, base, edge, dragged, reach, blockers, chrome, settle) {
|
|
1456
|
-
const el = base.edges[edge.id];
|
|
1457
|
-
if (!el || el.folded || el.rides) return [];
|
|
1458
|
-
const column = axisOf(edge.side) === "column";
|
|
1459
|
-
const restEdge = rest.edges.find((e) => e.id === edge.id);
|
|
1460
|
-
const fixedIds = restEdge.items.filter((id) => rest.items[id]?.fixed && base.items[id]?.edge === edge.id);
|
|
1461
|
-
const tooWideBefore = new Set(base.notes.flatMap((n) => "edge" in n && n.edge === edge.id && n.code === "too-wide" ? [n.id] : []));
|
|
1462
|
-
const thirds = !column && !edge.compact;
|
|
1463
|
-
const natural = (id, form) => {
|
|
1464
|
-
const f = formsOf(scene.items[id], "row")[form];
|
|
1465
|
-
return f ? formMain(f, "natural", el.cross) : 0;
|
|
1466
|
-
};
|
|
1467
|
-
const titles = thirds ? fixedIds.filter((id) => !!formsOf(scene.items[id], "row")[base.items[id].form]?.main.grows) : [];
|
|
1468
|
-
const titled = titles.length > 0;
|
|
1469
|
-
const fits = (after) => {
|
|
1470
|
-
const me = after.items[dragged];
|
|
1471
|
-
if (!me || me.edge !== edge.id || me.inMenu) return false;
|
|
1472
|
-
for (const n of after.notes) {
|
|
1473
|
-
if (!("edge" in n) || n.edge !== edge.id) continue;
|
|
1474
|
-
if (n.code === "overflow") return false;
|
|
1475
|
-
if (n.code === "too-wide" && !tooWideBefore.has(n.id)) return false;
|
|
1476
|
-
}
|
|
1477
|
-
for (const id of fixedIds) {
|
|
1478
|
-
const a = after.items[id];
|
|
1479
|
-
const b = base.items[id];
|
|
1480
|
-
if (!a || a.form !== b.form || a.formKind !== b.formKind || Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5) return false;
|
|
1481
|
-
}
|
|
1482
|
-
if (titled) {
|
|
1483
|
-
if (me.form !== 0) return false;
|
|
1484
|
-
for (const id of restEdge.items) {
|
|
1485
|
-
const a = after.items[id];
|
|
1486
|
-
const b = base.items[id];
|
|
1487
|
-
if (!a || !b || b.edge !== edge.id) continue;
|
|
1488
|
-
if (titles.includes(id) ? a.rect.width < natural(id, a.form) - 0.5 : a.form !== b.form || !!a.inMenu !== !!b.inMenu) return false;
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
return !chrome.some((c) => overlaps(me.rect, c));
|
|
1492
|
-
};
|
|
1493
|
-
const markerOf = (after) => {
|
|
1494
|
-
const slot = after.items[dragged].rect;
|
|
1495
|
-
const e = after.edges[edge.id];
|
|
1496
|
-
return column ? rect(e.rect.x, slot.y, e.cross, 0) : rect(slot.x, e.rect.y, 0, e.cross);
|
|
1497
|
-
};
|
|
1498
|
-
const ownNow = now.items[dragged]?.edge;
|
|
1499
|
-
const otherOf = (edges, skip) => Object.entries(edges).filter(([id, e]) => id !== edge.id && id !== skip && e.rect.width > EPS2 && e.rect.height > EPS2 && !(edge.compact && e.side === edge.side)).map(([, e]) => e.rect);
|
|
1500
|
-
const otherEdges = otherOf(base.edges);
|
|
1501
|
-
const nowEdges = otherOf(now.edges, ownNow);
|
|
1502
|
-
const own = el.rect;
|
|
1503
|
-
const trimOff = (h, others, k, besideOnly = false) => {
|
|
1504
|
-
let [a0, a1] = column ? [h.y, h.y + h.height] : [h.x, h.x + h.width];
|
|
1505
|
-
let [c0, c1] = column ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
1506
|
-
const km = column ? k.y : k.x;
|
|
1507
|
-
const kc = column ? k.x : k.y;
|
|
1508
|
-
const [w0, w1] = column ? [own.x, own.x + own.width] : [own.y, own.y + own.height];
|
|
1509
|
-
for (const o of others) {
|
|
1510
|
-
const [o0, o1] = column ? [o.y, o.y + o.height] : [o.x, o.x + o.width];
|
|
1511
|
-
const [p0, p1] = column ? [o.x, o.x + o.width] : [o.y, o.y + o.height];
|
|
1512
|
-
if (Math.min(a1, o1) - Math.max(a0, o0) <= EPS2 || Math.min(c1, p1) - Math.max(c0, p0) <= EPS2) continue;
|
|
1513
|
-
const across = !besideOnly && Math.min(w1, p1) - Math.max(w0, p0) > EPS2;
|
|
1514
|
-
if (!across) {
|
|
1515
|
-
if (p1 <= kc + EPS2) c0 = Math.max(c0, p1);
|
|
1516
|
-
else if (p0 >= kc - EPS2) c1 = Math.min(c1, p0);
|
|
1517
|
-
} else if (o1 <= km + EPS2) a0 = Math.max(a0, o1);
|
|
1518
|
-
else if (o0 >= km - EPS2) a1 = Math.min(a1, o0);
|
|
1519
|
-
}
|
|
1520
|
-
return column ? rect(c0, a0, Math.max(0, c1 - c0), Math.max(0, a1 - a0)) : rect(a0, c0, Math.max(0, a1 - a0), Math.max(0, c1 - c0));
|
|
1521
|
-
};
|
|
1522
|
-
const target = (id, place, hit, keep2, solved) => {
|
|
1523
|
-
const result = solved ?? settle(use(moveTo(scene, dragged, place), dragged));
|
|
1524
|
-
if (!fits(result.layout)) return null;
|
|
1525
|
-
const clear = cutClear(id.startsWith("gap:") ? trimOff(trimOff(hit, otherEdges, keep2), nowEdges, keep2, true) : hit, blockers, keep2);
|
|
1526
|
-
if (!clear) return null;
|
|
1527
|
-
return { id, priority: 2, hit: clear, slot: result.layout.items[dragged].rect, marker: markerOf(result.layout), item: dragged, place, after: () => result };
|
|
1528
|
-
};
|
|
1529
|
-
const drawn = base.edges[edge.id].stack.items.filter((p) => p.kind !== "menu").map((p) => p.id);
|
|
1530
|
-
if (drawn.length === 0 && !el.menu) {
|
|
1531
|
-
const depth = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
|
|
1532
|
-
const r = el.rect;
|
|
1533
|
-
const hit = edge.side === "left" ? rect(r.x, r.y, depth, r.height) : edge.side === "right" ? rect(r.x + r.width - depth, r.y, depth, r.height) : edge.side === "top" ? rect(r.x, r.y, r.width, depth) : rect(r.x, r.y + r.height - depth, r.width, depth);
|
|
1534
|
-
const keep2 = { x: hit.x + hit.width / 2, y: hit.y + hit.height / 2 };
|
|
1535
|
-
if (thirds) {
|
|
1536
|
-
const c = base.content;
|
|
1537
|
-
const x0 = Math.max(hit.x, c.x);
|
|
1538
|
-
const x1 = Math.min(hit.x + hit.width, c.x + c.width);
|
|
1539
|
-
if (x1 - x0 <= EPS2) return [];
|
|
1540
|
-
const w = (x1 - x0) / 3;
|
|
1541
|
-
const out2 = [];
|
|
1542
|
-
ZONES.forEach((zone, k) => {
|
|
1543
|
-
if (!zoneTakes(edge, zone, scene.items[dragged].kind)) return;
|
|
1544
|
-
const part = rect(x0 + k * w, hit.y, w, hit.height);
|
|
1545
|
-
const t2 = target(`strip:${edge.id}:${zone}`, { kind: "gap", edge: edge.id, zone, at: 0 }, part, { x: part.x + part.width / 2, y: part.y + part.height / 2 });
|
|
1546
|
-
if (t2) out2.push(t2);
|
|
1547
|
-
});
|
|
1548
|
-
return out2;
|
|
1549
|
-
}
|
|
1550
|
-
if (!zoneTakes(edge, "start", scene.items[dragged].kind)) return [];
|
|
1551
|
-
const t = target(`strip:${edge.id}`, { kind: "gap", edge: edge.id, zone: "start", at: 0 }, hit, keep2);
|
|
1552
|
-
return t ? [t] : [];
|
|
1553
|
-
}
|
|
1554
|
-
const main0 = column ? el.rect.y : el.rect.x;
|
|
1555
|
-
const length = column ? el.rect.height : el.rect.width;
|
|
1556
|
-
const at = (r) => column ? r.y : r.x;
|
|
1557
|
-
const len = (r) => column ? r.height : r.width;
|
|
1558
|
-
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
1559
|
-
const menuLen = el.menu ? len(el.menu.rect) : 0;
|
|
1560
|
-
const occupied = (id) => base.items[id]?.fixed ? reservedRect(scene, base, id) : base.items[id].rect;
|
|
1561
|
-
const drawnOf = (z) => restEdge.items.filter((id) => zoneOf(rest.items[id]) === z && base.items[id]?.edge === edge.id && !base.items[id].inMenu).map(occupied);
|
|
1562
|
-
const startEnd = (() => {
|
|
1563
|
-
const s = drawnOf("start");
|
|
1564
|
-
return s.length ? at(s[s.length - 1]) + len(s[s.length - 1]) : main0 + pad.start;
|
|
1565
|
-
})();
|
|
1566
|
-
const endStart = (() => {
|
|
1567
|
-
const e = drawnOf("end");
|
|
1568
|
-
return e.length ? at(e[0]) : main0 + length - pad.end - menuLen;
|
|
1569
|
-
})();
|
|
1570
|
-
const empty = { start: main0 + pad.start, center: Math.min(Math.max(main0 + length / 2, startEnd), Math.max(startEnd, endStart)), end: main0 + length - pad.end - menuLen };
|
|
1571
|
-
const gaps = [];
|
|
1572
|
-
for (const zone of zonesTaking(edge, scene.items[dragged].kind)) {
|
|
1573
|
-
const members = restEdge.items.filter((id) => zoneOf(rest.items[id]) === zone);
|
|
1574
|
-
for (let k = 0; k <= members.length; k++) {
|
|
1575
|
-
const next = members.slice(k).find((id) => base.items[id]?.edge === edge.id && !base.items[id].inMenu);
|
|
1576
|
-
const before = members.slice(0, k).reverse().find((id) => base.items[id]?.edge === edge.id && !base.items[id].inMenu);
|
|
1577
|
-
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : empty[zone];
|
|
1578
|
-
gaps.push({ zone, at: k, line });
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
const sorted = gaps.map((g, i) => ({ ...g, i })).sort((a, b) => (thirds ? ZONE_ORDER[a.zone] - ZONE_ORDER[b.zone] : 0) || a.line - b.line || a.i - b.i).filter((g, i, all) => i === 0 || thirds && g.zone !== all[i - 1].zone || Math.abs(g.line - all[i - 1].line) > EPS2);
|
|
1582
|
-
const out = [];
|
|
1583
|
-
const live = sorted.map((g) => {
|
|
1584
|
-
const place = { kind: "gap", edge: edge.id, zone: g.zone, at: g.at };
|
|
1585
|
-
return { ...g, place, result: settle(use(moveTo(scene, dragged, place), dragged)) };
|
|
1586
|
-
}).filter((g) => fits(g.result.layout));
|
|
1587
|
-
const bandOpt = edge.hitBand ?? DEFAULT_HIT_BAND;
|
|
1588
|
-
const band = bandOpt === "middle" ? Infinity : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND);
|
|
1589
|
-
const bodies = Number.isFinite(band) ? Object.values(base.items).filter((p) => p.edge === edge.id && p.formKind === "open").map((p) => ({ a: at(p.rect), b: at(p.rect) + len(p.rect) })) : [];
|
|
1590
|
-
const inward = edge.compact ? RAIL_REACH : 0;
|
|
1591
|
-
const solidSpans = fixedIds.filter((id) => !formsOf(scene.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows).map((id) => ({ a: at(base.items[id].rect), b: at(base.items[id].rect) + len(base.items[id].rect) }));
|
|
1592
|
-
live.forEach((g, i) => {
|
|
1593
|
-
let from = i === 0 ? -Infinity : (live[i - 1].line + g.line) / 2;
|
|
1594
|
-
let to = i === live.length - 1 ? Infinity : (g.line + live[i + 1].line) / 2;
|
|
1595
|
-
if (thirds) {
|
|
1596
|
-
const k = ZONE_ORDER[g.zone];
|
|
1597
|
-
const prev = live[i - 1]?.zone === g.zone ? live[i - 1] : void 0;
|
|
1598
|
-
const next = live[i + 1]?.zone === g.zone ? live[i + 1] : void 0;
|
|
1599
|
-
const a0 = main0 + length * k / 3;
|
|
1600
|
-
const b0 = main0 + length * (k + 1) / 3;
|
|
1601
|
-
const lines = live.filter((x) => x.zone === g.zone).map((x) => x.line);
|
|
1602
|
-
const first = Math.min(...lines);
|
|
1603
|
-
const last = Math.max(...lines);
|
|
1604
|
-
const a1 = Math.max(a0, ...solidSpans.filter((s) => s.b <= first + EPS2).map((s) => s.b));
|
|
1605
|
-
const b1 = Math.min(b0, ...solidSpans.filter((s) => s.a >= last - EPS2).map((s) => s.a));
|
|
1606
|
-
const [a, b] = b1 - a1 > EPS2 ? [a1, b1] : [a0, b0];
|
|
1607
|
-
const span0 = Math.min(a, ...lines);
|
|
1608
|
-
const span1 = Math.max(b, ...lines);
|
|
1609
|
-
const inThird = (x) => span1 - span0 > EPS2 ? a + (x - span0) / (span1 - span0) * (b - a) : x;
|
|
1610
|
-
const lo = k === 0 ? -Infinity : a0;
|
|
1611
|
-
const hi = k === 2 ? Infinity : b0;
|
|
1612
|
-
from = Math.max(lo, prev ? (inThird(prev.line) + inThird(g.line)) / 2 : lo);
|
|
1613
|
-
to = Math.min(hi, next ? (inThird(g.line) + inThird(next.line)) / 2 : hi);
|
|
1614
|
-
}
|
|
1615
|
-
for (const p of bodies) {
|
|
1616
|
-
if (p.b <= g.line + EPS2 && p.b > from) from = Math.max(from, p.b - band / 2);
|
|
1617
|
-
if (p.a >= g.line - EPS2 && p.a < to) to = Math.min(to, p.a + band / 2);
|
|
1618
|
-
}
|
|
1619
|
-
from = from <= main0 + pad.start + EPS2 ? main0 - reach : from;
|
|
1620
|
-
to = to >= main0 + length - pad.end - menuLen - EPS2 ? main0 + length + reach : to;
|
|
1621
|
-
from = Math.max(from, main0 - reach);
|
|
1622
|
-
to = Math.min(to, main0 + length + reach);
|
|
1623
|
-
if (to - from <= EPS2) return;
|
|
1624
|
-
const thick = Math.max(el.cross, g.result.layout.edges[edge.id]?.cross ?? 0) + inward;
|
|
1625
|
-
const r = el.rect;
|
|
1626
|
-
const hit = column ? rect(edge.side === "left" ? r.x : r.x + r.width - (thick - inward) - inward, from, thick, to - from) : rect(from, edge.side === "top" ? r.y : r.y + r.height - (thick - inward) - inward, to - from, thick);
|
|
1627
|
-
const line = Math.min(Math.max(g.line, from), to);
|
|
1628
|
-
const keep2 = column ? { x: r.x + r.width / 2, y: line } : { x: line, y: r.y + r.height / 2 };
|
|
1629
|
-
const t = target(`gap:${edge.id}:${g.zone}:${g.at}`, g.place, hit, keep2, g.result);
|
|
1630
|
-
if (t) out.push(t);
|
|
1631
|
-
});
|
|
1632
|
-
return out;
|
|
1633
|
-
}
|
|
1634
1710
|
|
|
1635
1711
|
export {
|
|
1636
1712
|
SIDES,
|
|
@@ -1661,9 +1737,9 @@ export {
|
|
|
1661
1737
|
dockHome,
|
|
1662
1738
|
storeScene,
|
|
1663
1739
|
readScene,
|
|
1664
|
-
targets,
|
|
1665
1740
|
reservedRect,
|
|
1741
|
+
targets,
|
|
1666
1742
|
refusals,
|
|
1667
1743
|
stops
|
|
1668
1744
|
};
|
|
1669
|
-
//# sourceMappingURL=chunk-
|
|
1745
|
+
//# sourceMappingURL=chunk-SZKU7CRX.js.map
|