@n-uf/docking 0.0.0-stage → 26.11.54
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 +98 -0
- package/LICENSE +129 -0
- package/README.md +96 -2
- package/dist/chunk-KGNFLHSC.js +4280 -0
- package/dist/chunk-KGNFLHSC.js.map +1 -0
- package/dist/index.d.ts +283 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/lanes-CGg4iMPw.d.ts +1327 -0
- package/dist/testing.d.ts +820 -0
- package/dist/testing.js +3091 -0
- package/dist/testing.js.map +1 -0
- package/package.json +72 -3
|
@@ -0,0 +1,4280 @@
|
|
|
1
|
+
// src/model.ts
|
|
2
|
+
var SIDES = ["top", "right", "bottom", "left"];
|
|
3
|
+
var ZONES = ["start", "center", "end"];
|
|
4
|
+
var FLOAT_ANCHORS = ["content-top-left", "content-top", "content-top-right", "content-right", "content-bottom-right", "content-bottom", "content-bottom-left", "content-left"];
|
|
5
|
+
var RAIL_MODES = ["titles", "icons"];
|
|
6
|
+
var RAIL_VISIBILITIES = ["whileDragging", "always", "never"];
|
|
7
|
+
var RAIL_STRIP_MIN = 24;
|
|
8
|
+
var DEFAULT_RAIL_MAGNET = 6;
|
|
9
|
+
var EDGE_ROOM_HOLD = 0;
|
|
10
|
+
var DEFAULT_STRIP = 24;
|
|
11
|
+
var DEFAULT_HIT_BAND = 24;
|
|
12
|
+
var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
|
|
13
|
+
|
|
14
|
+
// src/helpers.ts
|
|
15
|
+
import { clampInto } from "@n-uf/placement";
|
|
16
|
+
import { formFolded } from "@n-uf/placement/stack";
|
|
17
|
+
var insetPx = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
|
|
18
|
+
function floatRegion(state, lifted) {
|
|
19
|
+
const floating = new Set(state.floats.map((f) => f.id));
|
|
20
|
+
const docked = state.edges.some((e) => (e.side === "left" || e.side === "right") && e.accepts.length > 0 && e.items.some((id) => id !== lifted && !floating.has(id) && !!state.items[id] && isDockingPanel(state.items[id])));
|
|
21
|
+
const inset = state.insetWhen === "docked" && !docked ? {} : state.inset ?? {};
|
|
22
|
+
const { stage } = state;
|
|
23
|
+
return { x: stage.x + insetPx(inset.left), y: stage.y, width: Math.max(0, stage.width - insetPx(inset.left) - insetPx(inset.right)), height: stage.height };
|
|
24
|
+
}
|
|
25
|
+
var heldRect = (state, id, size, pointer, grab) => clampInto({ x: pointer.x - grab.x, y: pointer.y - grab.y, width: size.width, height: size.height }, floatRegion(state, id));
|
|
26
|
+
var anchorName = (anchor) => typeof anchor === "string" ? anchor : anchor.at;
|
|
27
|
+
var isSince = (x) => typeof x === "number" && x >= 0 && x <= Number.MAX_SAFE_INTEGER;
|
|
28
|
+
var zonesOf = (edge) => {
|
|
29
|
+
if (edge.zones === void 0) return ZONES;
|
|
30
|
+
const has = ZONES.filter((z) => edge.zones.includes(z));
|
|
31
|
+
return has.length > 0 ? has : ZONES;
|
|
32
|
+
};
|
|
33
|
+
var zoneTakes = (edge, zone, kind) => edge.accepts.includes(kind) && (edge.zones === void 0 || zonesOf(edge).includes(zone)) && (edge.zoneAccepts === void 0 || !!edge.zoneAccepts[zone]?.includes(kind));
|
|
34
|
+
var zonesTaking = (edge, kind) => ZONES.filter((z) => zoneTakes(edge, z, kind));
|
|
35
|
+
var edgeTakes = (edge, kind) => zonesTaking(edge, kind).length > 0;
|
|
36
|
+
var hitBandOf = (state, edge) => edge.hitBand ?? (edge.column === true && (edge.side === "left" || edge.side === "right") ? state.columns?.[edge.side]?.hitBand : void 0) ?? DEFAULT_HIT_BAND;
|
|
37
|
+
var columnFromTemplate = (t, id, side, ring, items) => ({
|
|
38
|
+
id,
|
|
39
|
+
side,
|
|
40
|
+
ring,
|
|
41
|
+
accepts: t.accepts,
|
|
42
|
+
items,
|
|
43
|
+
cross: t.cross,
|
|
44
|
+
...t.gap !== void 0 ? { gap: t.gap } : {},
|
|
45
|
+
...t.pad ? { pad: t.pad } : {},
|
|
46
|
+
...t.menu ? { menu: t.menu } : {},
|
|
47
|
+
...t.zoneAccepts ? { zoneAccepts: t.zoneAccepts } : {},
|
|
48
|
+
...t.hitBand !== void 0 ? { hitBand: t.hitBand } : {},
|
|
49
|
+
column: true
|
|
50
|
+
});
|
|
51
|
+
var railModeOf = (state, side) => side === "left" || side === "right" ? state.railModes?.[side] === "icons" ? "icons" : "titles" : "icons";
|
|
52
|
+
var axisOf = (side) => side === "left" || side === "right" ? "column" : "row";
|
|
53
|
+
var keepClearFor = (state, who) => (state.keepClear ?? []).filter((c) => who === "floats" || c.for !== "floats").map((c) => ({ x: c.x, y: c.y, width: c.width, height: c.height }));
|
|
54
|
+
function railColumnOf(state, side, kind) {
|
|
55
|
+
if (state.rails?.[side]) return void 0;
|
|
56
|
+
return state.edges.filter((e) => e.side === side && !e.compact && e.hidden !== true && zoneTakes(e, "start", kind)).reduce((m, e) => !m || e.ring < m.ring ? e : m, void 0);
|
|
57
|
+
}
|
|
58
|
+
function zoneIn(edge, item) {
|
|
59
|
+
const own = zoneOf(item);
|
|
60
|
+
if (item.fixed) {
|
|
61
|
+
const has = zonesOf(edge);
|
|
62
|
+
return has.includes(own) ? own : has[0] ?? own;
|
|
63
|
+
}
|
|
64
|
+
if (zoneTakes(edge, own, item.kind)) return own;
|
|
65
|
+
return zonesTaking(edge, item.kind)[0] ?? own;
|
|
66
|
+
}
|
|
67
|
+
var namesZone = (edge, kind) => zonesTaking(edge, kind).length > 1;
|
|
68
|
+
var showInOf = (state, e) => {
|
|
69
|
+
if (e.hidden !== true || e.showIn === void 0) return void 0;
|
|
70
|
+
const to = state.edges.find((x) => x.id === e.showIn);
|
|
71
|
+
return to && to !== e && to.hidden !== true && to.column !== true ? to : void 0;
|
|
72
|
+
};
|
|
73
|
+
function viewOf(state) {
|
|
74
|
+
const lent = /* @__PURE__ */ new Map();
|
|
75
|
+
const ignored = [];
|
|
76
|
+
const added = /* @__PURE__ */ new Map();
|
|
77
|
+
const hidden = state.edges.some((e) => e.hidden === true);
|
|
78
|
+
if (hidden) {
|
|
79
|
+
for (const e of state.edges) {
|
|
80
|
+
if (e.hidden !== true || e.showIn === void 0) continue;
|
|
81
|
+
const to = showInOf(state, e);
|
|
82
|
+
if (!to) {
|
|
83
|
+
ignored.push(e.id);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
for (const id of e.items) {
|
|
87
|
+
const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
88
|
+
if (!item || item.fixed || lent.has(id) || to.items.includes(id) || !edgeTakes(to, item.kind)) continue;
|
|
89
|
+
lent.set(id, e.id);
|
|
90
|
+
added.set(to.id, [...added.get(to.id) ?? [], id]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const edges = hidden ? state.edges.filter((e) => e.hidden !== true).map((e) => added.has(e.id) ? { ...e, items: [...e.items, ...added.get(e.id)] } : e) : state.edges;
|
|
95
|
+
const rezoned = /* @__PURE__ */ new Set();
|
|
96
|
+
let items;
|
|
97
|
+
for (const e of edges) {
|
|
98
|
+
for (const id of e.items) {
|
|
99
|
+
const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
100
|
+
if (!item) continue;
|
|
101
|
+
const zone = zoneIn(e, item);
|
|
102
|
+
if (zone === zoneOf(item)) continue;
|
|
103
|
+
const { align: _a, ...plain } = item;
|
|
104
|
+
items ??= { ...state.items };
|
|
105
|
+
items[id] = zone === "start" ? plain : { ...plain, align: zone };
|
|
106
|
+
rezoned.add(id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!hidden && !items) return { view: state, lent, ignored, rezoned };
|
|
110
|
+
return { view: { ...state, edges, ...items ? { items } : {} }, lent, ignored, rezoned };
|
|
111
|
+
}
|
|
112
|
+
var inHiddenEdge = (state, id) => state.edges.some((e) => e.hidden === true && e.items.includes(id));
|
|
113
|
+
function withHiddenOf(state, shown, lent = /* @__PURE__ */ new Map(), moved, zoned = false, rezoned = /* @__PURE__ */ new Set()) {
|
|
114
|
+
if (shown === state) return shown;
|
|
115
|
+
const back = [...lent.keys()].filter((id) => id !== moved);
|
|
116
|
+
const edges = shown.edges.filter((e) => e.hidden !== true).map((e) => back.some((id) => e.items.includes(id)) ? { ...e, items: e.items.filter((id) => !back.includes(id)) } : e);
|
|
117
|
+
state.edges.forEach((e, i) => {
|
|
118
|
+
if (e.hidden !== true) return;
|
|
119
|
+
const own = moved !== void 0 && lent.get(moved) === e.id ? { ...e, items: e.items.filter((id) => id !== moved) } : e;
|
|
120
|
+
edges.splice(Math.min(i, edges.length), 0, own);
|
|
121
|
+
});
|
|
122
|
+
const items = back.length > 0 ? { ...shown.items, ...Object.fromEntries(back.map((id) => [id, state.items[id]])) } : { ...shown.items };
|
|
123
|
+
const keep = new Set([...rezoned].filter((id) => !back.includes(id) && !(id === moved && zoned)));
|
|
124
|
+
if (moved !== void 0 && !zoned) keep.add(moved);
|
|
125
|
+
for (const id of keep) {
|
|
126
|
+
const was = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
127
|
+
const now = Object.hasOwn(items, id) ? items[id] : void 0;
|
|
128
|
+
if (!was || !now || now.align === was.align) continue;
|
|
129
|
+
const { align: _a, ...plain } = now;
|
|
130
|
+
items[id] = was.align === void 0 ? plain : { ...plain, align: was.align };
|
|
131
|
+
}
|
|
132
|
+
const ringBefore = new Map(state.edges.filter((e) => e.hidden !== true).map((e) => [e.id, e.ring]));
|
|
133
|
+
for (const side of new Set(state.edges.filter((e) => e.hidden === true).map((e) => e.side))) {
|
|
134
|
+
const was = state.edges.filter((e) => e.side === side && e.hidden !== true).map((e) => e.id).sort();
|
|
135
|
+
const now = edges.filter((e) => e.side === side && e.hidden !== true);
|
|
136
|
+
if (now.length === was.length && now.every((e) => was.includes(e.id))) continue;
|
|
137
|
+
const order = [...now].sort((a, b) => a.ring - b.ring || edges.indexOf(a) - edges.indexOf(b));
|
|
138
|
+
for (const h of edges.filter((e) => e.side === side && e.hidden === true).sort((a, b) => a.ring - b.ring)) {
|
|
139
|
+
const k = order.findIndex((e) => e.hidden !== true && (ringBefore.get(e.id) ?? -Infinity) > h.ring);
|
|
140
|
+
order.splice(k < 0 ? order.length : k, 0, h);
|
|
141
|
+
}
|
|
142
|
+
order.forEach((e, ring) => {
|
|
143
|
+
if (e.ring !== ring) edges[edges.indexOf(e)] = { ...e, ring };
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return { ...shown, edges, items };
|
|
147
|
+
}
|
|
148
|
+
function railPolicyOf(state, kind) {
|
|
149
|
+
const p = Object.hasOwn(state.railDrop ?? {}, kind) ? state.railDrop[kind] : void 0;
|
|
150
|
+
if (!p) return null;
|
|
151
|
+
const visibility = p.railVisibility === "always" || p.railVisibility === "never" ? p.railVisibility : "whileDragging";
|
|
152
|
+
const width = p.railStripWidth;
|
|
153
|
+
if (visibility === "never" || width !== void 0 && !(Number.isFinite(width) && width > 0)) return null;
|
|
154
|
+
return {
|
|
155
|
+
railStripWidth: width === void 0 ? null : Math.max(RAIL_STRIP_MIN, width),
|
|
156
|
+
railVisibility: visibility,
|
|
157
|
+
magnet: Number.isFinite(p.magnet) ? Math.max(0, p.magnet) : DEFAULT_RAIL_MAGNET,
|
|
158
|
+
floatNearEdge: p.floatNearEdge !== false
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
var zoneOf = (item) => item?.align === "center" || item?.align === "end" ? item.align : "start";
|
|
162
|
+
var formsOf = (item, axis) => item.forms[axis] ?? [];
|
|
163
|
+
var controlsOf = (f) => ({ hidden: f?.hides ?? [], ...f?.tiers ? { tiers: f.tiers } : {} });
|
|
164
|
+
var PANEL_FORMS = /* @__PURE__ */ new Set(["open", "header", "rail"]);
|
|
165
|
+
var isDockingPanel = (item) => !item.closed && !item.fixed && PANEL_FORMS.has(formsOf(item, "column")[0]?.kind ?? "");
|
|
166
|
+
function isOutsideSideBar(state, e) {
|
|
167
|
+
return e.outsideInset === true && isSideBar(state, e);
|
|
168
|
+
}
|
|
169
|
+
function isSideBar(state, e) {
|
|
170
|
+
if (e.side !== "left" && e.side !== "right" || e.column === true || e.accepts.length === 0) return false;
|
|
171
|
+
const template = state.columns?.[e.side];
|
|
172
|
+
const rail = state.rails?.[e.side];
|
|
173
|
+
if (!template && !rail) return false;
|
|
174
|
+
const panelKinds = [...template?.accepts ?? [], ...rail?.accepts ?? []];
|
|
175
|
+
return !e.accepts.some((k) => panelKinds.includes(k));
|
|
176
|
+
}
|
|
177
|
+
var isSideColumn = (state, e) => (e.side === "left" || e.side === "right") && !e.compact && e.accepts.length > 0 && !isSideBar(state, e);
|
|
178
|
+
var floatOrientOf = (item) => {
|
|
179
|
+
if (item.floatOrient === "row" || item.floatOrient === "column") return item.floatOrient;
|
|
180
|
+
for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
|
|
181
|
+
return "column";
|
|
182
|
+
};
|
|
183
|
+
var sized = (s) => !!s && Number.isFinite(s.width) && Number.isFinite(s.height) && s.width > 0 && s.height > 0;
|
|
184
|
+
var declaresFloatSizes = (item) => item.floatSizes !== void 0 && item.floatSizes !== null;
|
|
185
|
+
function naturalFloatSize(item, orient) {
|
|
186
|
+
const f = formsOf(item, orient)[0];
|
|
187
|
+
if (!f || f.main.grows) return void 0;
|
|
188
|
+
const main = Number.isFinite(f.main.natural) ? Math.max(0, f.main.natural) : 0;
|
|
189
|
+
const cross = Number.isFinite(f.cross.natural) ? Math.max(0, f.cross.natural) : 0;
|
|
190
|
+
if (main <= 0 || cross <= 0) return void 0;
|
|
191
|
+
return orient === "row" ? { width: main, height: cross } : { width: cross, height: main };
|
|
192
|
+
}
|
|
193
|
+
function floatSizesOf(item) {
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const o of ["row", "column"]) {
|
|
196
|
+
const s = item.floatSizes?.[o];
|
|
197
|
+
if (sized(s)) out[o] = s;
|
|
198
|
+
}
|
|
199
|
+
return out.row || out.column ? out : void 0;
|
|
200
|
+
}
|
|
201
|
+
function floatSizeOf(item, orient = floatOrientOf(item)) {
|
|
202
|
+
const own = item.floatSizes?.[orient];
|
|
203
|
+
if (sized(own)) return own;
|
|
204
|
+
return naturalFloatSize(item, orient) ?? DEFAULT_FLOAT_SIZE;
|
|
205
|
+
}
|
|
206
|
+
function foldedByOf(item, forms, form, start, edge) {
|
|
207
|
+
if (item.closed || form < 1) return void 0;
|
|
208
|
+
if (startOf(item, forms, edge) > 0) return "hand";
|
|
209
|
+
return start !== void 0 && form > start ? "auto" : void 0;
|
|
210
|
+
}
|
|
211
|
+
var foldedByHand = (item) => Number.isFinite(item.from) && Math.floor(item.from) >= 1;
|
|
212
|
+
var foldsToRail = (item, edge) => !!item.fixed && edge?.foldable === true;
|
|
213
|
+
function foldedIndex(item, forms, edge) {
|
|
214
|
+
const bar = forms.findIndex(formFolded);
|
|
215
|
+
return bar >= 0 || !foldsToRail(item, edge) ? bar : forms.findIndex((f) => f.kind === "rail");
|
|
216
|
+
}
|
|
217
|
+
function startOf(item, forms, edge) {
|
|
218
|
+
if (!foldedByHand(item)) return 0;
|
|
219
|
+
const folded = foldedIndex(item, forms, edge);
|
|
220
|
+
return folded < 0 ? 0 : Math.min(Math.max(folded, Math.floor(item.from)), forms.length - 1);
|
|
221
|
+
}
|
|
222
|
+
function placingOf(state, id) {
|
|
223
|
+
if (!state.edges.some((e) => e.hidden === true && e.showIn !== void 0 && e.items.includes(id))) return state;
|
|
224
|
+
const { view, lent } = viewOf(state);
|
|
225
|
+
return lent.has(id) ? view : state;
|
|
226
|
+
}
|
|
227
|
+
function axesOf(given, id) {
|
|
228
|
+
const state = placingOf(given, id);
|
|
229
|
+
const item = state.items[id];
|
|
230
|
+
const edge = state.edges.find((e) => e.items.includes(id));
|
|
231
|
+
if (edge) return [axisOf(edge.side)];
|
|
232
|
+
const float = state.floats.find((f) => f.id === id);
|
|
233
|
+
return float && item ? [float.orient ?? floatOrientOf(item)] : ["row", "column"];
|
|
234
|
+
}
|
|
235
|
+
function isHandFolded(given, id) {
|
|
236
|
+
const state = placingOf(given, id);
|
|
237
|
+
const item = Object.hasOwn(given.items, id) ? given.items[id] : void 0;
|
|
238
|
+
const edge = state.edges.find((e) => e.items.includes(id));
|
|
239
|
+
return !!item && axesOf(state, id).some((a) => startOf(item, formsOf(item, a), edge) > 0);
|
|
240
|
+
}
|
|
241
|
+
function pastWrap(forms, from) {
|
|
242
|
+
for (let j = Math.max(0, Math.floor(from)); j < forms.length; j++) if (forms[j].kind !== "wrap" && !forms[j].wrap) return j;
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
function floatShape(item, f) {
|
|
246
|
+
const orient = f.orient ?? floatOrientOf(item);
|
|
247
|
+
const forms = formsOf(item, orient);
|
|
248
|
+
const px2 = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
|
|
249
|
+
const w = px2(f.rect.width);
|
|
250
|
+
const h = px2(f.rect.height);
|
|
251
|
+
if (forms.length === 0) return { form: 0, width: w, height: h };
|
|
252
|
+
const asked = startOf(item, forms);
|
|
253
|
+
const isWrap = (x) => x.kind === "wrap" || !!x.wrap;
|
|
254
|
+
const skipped = orient === "column" ? pastWrap(forms, asked) : asked;
|
|
255
|
+
if (skipped === void 0) return { form: asked, width: w, height: h, none: true };
|
|
256
|
+
const form = skipped;
|
|
257
|
+
const fm = forms[form];
|
|
258
|
+
if (orient === "column" && forms.slice(0, form + 1).some(isWrap)) return { form, width: px2(fm.cross.natural), height: px2(fm.main.natural) };
|
|
259
|
+
if (form > 0) return orient === "column" ? { form, width: w, height: px2(fm.main.natural) } : { form, width: px2(fm.main.natural), height: h };
|
|
260
|
+
return { form, ...fm.main.grows || !declaresFloatSizes(item) ? { width: w, height: h } : floatSizeOf(item, orient) };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// src/solve.ts
|
|
264
|
+
import { rect as rect6 } from "@n-uf/placement";
|
|
265
|
+
|
|
266
|
+
// src/targets/ids.ts
|
|
267
|
+
function targetId(parts) {
|
|
268
|
+
switch (parts.kind) {
|
|
269
|
+
case "gap":
|
|
270
|
+
return `gap:${parts.edge}:${parts.zone}:${parts.at}`;
|
|
271
|
+
case "strip":
|
|
272
|
+
return `strip:${parts.edge}:${parts.zone}`;
|
|
273
|
+
case "column":
|
|
274
|
+
case "rail":
|
|
275
|
+
return `${parts.kind}:${parts.side}:${parts.ring}`;
|
|
276
|
+
case "side":
|
|
277
|
+
return `side:${parts.side}`;
|
|
278
|
+
case "home":
|
|
279
|
+
case "float":
|
|
280
|
+
return `${parts.kind}:${parts.item}`;
|
|
281
|
+
case "none":
|
|
282
|
+
return `none:${parts.index}`;
|
|
283
|
+
case "refuse":
|
|
284
|
+
return parts.n === 0 ? `refuse:${parts.edge}:${parts.zone}` : `refuse:${parts.edge}:${parts.zone}:${parts.n}`;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
var ZONE = "(start|center|end)";
|
|
288
|
+
var INT = "(-?\\d+)";
|
|
289
|
+
var GAP = new RegExp(`^gap:(.+):${ZONE}:${INT}$`);
|
|
290
|
+
var STRIP = new RegExp(`^strip:(.+):${ZONE}$`);
|
|
291
|
+
var LINE = new RegExp(`^(column|rail):(left|right):${INT}$`);
|
|
292
|
+
var SIDE = /^side:(left|right|top|bottom)$/;
|
|
293
|
+
var ITEM = /^(home|float):(.+)$/;
|
|
294
|
+
var NONE = new RegExp(`^none:${INT}$`);
|
|
295
|
+
var REFUSE = new RegExp(`^refuse:(.+):${ZONE}(?::${INT})?$`);
|
|
296
|
+
function parseTargetId(id) {
|
|
297
|
+
let m;
|
|
298
|
+
if (m = GAP.exec(id)) return { kind: "gap", edge: m[1], zone: m[2], at: Number(m[3]) };
|
|
299
|
+
if (m = STRIP.exec(id)) return { kind: "strip", edge: m[1], zone: m[2] };
|
|
300
|
+
if (m = LINE.exec(id)) return { kind: m[1], side: m[2], ring: Number(m[3]) };
|
|
301
|
+
if (m = SIDE.exec(id)) return { kind: "side", side: m[1] };
|
|
302
|
+
if (m = ITEM.exec(id)) return { kind: m[1], item: m[2] };
|
|
303
|
+
if (m = NONE.exec(id)) return { kind: "none", index: Number(m[1]) };
|
|
304
|
+
if (m = REFUSE.exec(id)) return { kind: "refuse", edge: m[1], zone: m[2], n: m[3] === void 0 ? 0 : Number(m[3]) };
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
var virtualEdgeId = (kind, side) => `${kind}:${side}`;
|
|
308
|
+
var RESERVED_EDGE_IDS = new Set(["column", "rail"].flatMap((k) => ["left", "right"].map((s) => virtualEdgeId(k, s))));
|
|
309
|
+
var isReservedEdgeId = (id) => RESERVED_EDGE_IDS.has(id);
|
|
310
|
+
function checkEdgeIds(state) {
|
|
311
|
+
for (const e of state.edges) {
|
|
312
|
+
if (isReservedEdgeId(e.id)) throw new Error(`docking: the edge id "${e.id}" is reserved for a side's virtual edge (column:<side>, rail:<side>); name the edge otherwise`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function placeTargetId(place, item) {
|
|
316
|
+
switch (place.kind) {
|
|
317
|
+
case "gap":
|
|
318
|
+
return targetId(place);
|
|
319
|
+
case "column":
|
|
320
|
+
case "rail":
|
|
321
|
+
return targetId(place);
|
|
322
|
+
case "side":
|
|
323
|
+
return targetId({ kind: "side", side: place.side });
|
|
324
|
+
case "float":
|
|
325
|
+
case "home":
|
|
326
|
+
return targetId({ kind: place.kind, item });
|
|
327
|
+
default:
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/solve/bar-giveway.ts
|
|
333
|
+
import { EPS } from "@n-uf/placement";
|
|
334
|
+
import { formCrossMin, formSetsCross } from "@n-uf/placement/stack";
|
|
335
|
+
|
|
336
|
+
// src/solve/order.ts
|
|
337
|
+
var finite = (x, fallback) => typeof x === "number" && Number.isFinite(x) ? x : fallback;
|
|
338
|
+
var px = (x) => Math.max(0, finite(x, 0));
|
|
339
|
+
var isSide = (e) => e.side === "left" || e.side === "right";
|
|
340
|
+
var giveWayOrder = (a, b) => Number(a.kept) - Number(b.kept) || a.age - b.age || finite(a.edge.ring, 0) - finite(b.edge.ring, 0);
|
|
341
|
+
function cutOrder(edges) {
|
|
342
|
+
const phase = (e) => e.side === "left" || e.side === "right" ? 1 : e.span === "between" ? 2 : 0;
|
|
343
|
+
const sideRank = (e) => e.side === "top" || e.side === "left" ? 0 : 1;
|
|
344
|
+
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);
|
|
345
|
+
}
|
|
346
|
+
function layKeys(state) {
|
|
347
|
+
const phase = (e) => e.mode === "overlay" ? 4 : isSide(e) ? 2 : e.span === "between" ? 3 : e.outsideInset === true ? 0 : 1;
|
|
348
|
+
return new Map(cutOrder(state.edges).map((e, at) => [e.id, { phase: phase(e), side: e.side, at }]));
|
|
349
|
+
}
|
|
350
|
+
function pushes(a, b) {
|
|
351
|
+
if (a.phase === 4 || b.phase === 4) return false;
|
|
352
|
+
if (a.phase !== b.phase) return a.phase < b.phase;
|
|
353
|
+
return a.side === b.side && a.at < b.at;
|
|
354
|
+
}
|
|
355
|
+
var ZONE_RANK = { start: 0, center: 1, end: 2 };
|
|
356
|
+
function zoneSorted(state, ids) {
|
|
357
|
+
return ids.map((id, i) => ({ id, i, z: ZONE_RANK[zoneOf(state.items[id])] })).sort((a, b) => a.z - b.z || a.i - b.i).map((x) => x.id);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/solve/bar-giveway.ts
|
|
361
|
+
var UNDER = 0.5;
|
|
362
|
+
function roomOf(state, l) {
|
|
363
|
+
const bars = state.edges.filter((e) => e.mode === "overlay" && !isSide(e)).reduce((s, e) => s + (l.edges[e.id]?.cross ?? 0), 0);
|
|
364
|
+
return l.content.height - bars;
|
|
365
|
+
}
|
|
366
|
+
function settersOf(state, l, edge) {
|
|
367
|
+
return (l.edges[edge.id]?.items ?? []).flatMap((id) => {
|
|
368
|
+
const at = l.items[id];
|
|
369
|
+
const item = state.items[id];
|
|
370
|
+
if (!at || !item || at.inMenu) return [];
|
|
371
|
+
const f = formsOf(item, "row")[at.form];
|
|
372
|
+
return f && formSetsCross(f) ? [formCrossMin(f)] : [];
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function barGiveWay(state, first, lay) {
|
|
376
|
+
if (!state.contentMin) return null;
|
|
377
|
+
const minH = px(state.contentMin.height);
|
|
378
|
+
const shortOf = (l) => minH - roomOf(state, l);
|
|
379
|
+
if (shortOf(first) <= EPS) return null;
|
|
380
|
+
const rankOf = (edge) => {
|
|
381
|
+
const items = (first.edges[edge.id]?.items ?? []).filter((id) => state.items[id] !== void 0);
|
|
382
|
+
return {
|
|
383
|
+
edge,
|
|
384
|
+
kept: items.some((id) => state.items[id].kept === true),
|
|
385
|
+
age: Math.max(-Infinity, ...items.map((id) => finite(state.items[id].used, 0)))
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
const bars = cutOrder(state.edges).filter((e) => !isSide(e) && e.giveWay === true && (first.edges[e.id]?.cross ?? 0) > EPS).map(rankOf).sort(giveWayOrder).map((r) => r.edge);
|
|
389
|
+
if (bars.length === 0) return null;
|
|
390
|
+
const folds = /* @__PURE__ */ new Map();
|
|
391
|
+
const shrinkFrom = (l) => {
|
|
392
|
+
const caps = new Map(folds);
|
|
393
|
+
const notes = [];
|
|
394
|
+
let left = shortOf(l);
|
|
395
|
+
for (const e of bars) {
|
|
396
|
+
if (left <= EPS) break;
|
|
397
|
+
if (folds.has(e.id)) continue;
|
|
398
|
+
const cross = l.edges[e.id]?.cross ?? 0;
|
|
399
|
+
const min = Math.max(px(e.cross.min), ...settersOf(state, l, e));
|
|
400
|
+
const cut2 = Math.min(left, cross - min);
|
|
401
|
+
if (cut2 <= EPS) continue;
|
|
402
|
+
caps.set(e.id, cross - cut2);
|
|
403
|
+
notes.push({ code: "bar-shrunk", edge: e.id, from: cross, to: cross - cut2 });
|
|
404
|
+
left -= cut2;
|
|
405
|
+
}
|
|
406
|
+
return { caps, notes, left };
|
|
407
|
+
};
|
|
408
|
+
let base = first;
|
|
409
|
+
let way = shrinkFrom(base);
|
|
410
|
+
for (const e of bars) {
|
|
411
|
+
if (way.left <= EPS) break;
|
|
412
|
+
const setters = settersOf(state, first, e);
|
|
413
|
+
if (setters.length === 0) continue;
|
|
414
|
+
folds.set(e.id, Math.min(...setters) - UNDER);
|
|
415
|
+
const l = lay(folds);
|
|
416
|
+
if ((l.edges[e.id]?.cross ?? 0) >= (base.edges[e.id]?.cross ?? 0) - EPS) {
|
|
417
|
+
folds.delete(e.id);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
base = l;
|
|
421
|
+
way = shrinkFrom(base);
|
|
422
|
+
}
|
|
423
|
+
if (way.caps.size === 0) return null;
|
|
424
|
+
return { caps: way.caps, notes: [...way.notes, ...[...folds.keys()].map((edge) => ({ code: "bar-folded", edge }))] };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/solve/bars.ts
|
|
428
|
+
import { cutEdges } from "@n-uf/placement/stack";
|
|
429
|
+
|
|
430
|
+
// src/solve/draft.ts
|
|
431
|
+
import { EPS as EPS2, rect } from "@n-uf/placement";
|
|
432
|
+
import { formMain, wrapLines } from "@n-uf/placement/stack";
|
|
433
|
+
function createDraft(given, options, caps = /* @__PURE__ */ new Map()) {
|
|
434
|
+
const previous = options.previous;
|
|
435
|
+
const opened = /* @__PURE__ */ new Set();
|
|
436
|
+
if (previous) {
|
|
437
|
+
for (const e of given.edges) {
|
|
438
|
+
for (const id of e.items) {
|
|
439
|
+
const it = Object.hasOwn(given.items, id) ? given.items[id] : void 0;
|
|
440
|
+
const was = previous.items[id];
|
|
441
|
+
if (it && !it.closed && !it.fixed && (!was || was.closed)) opened.add(id);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const stayedOpen = (e) => e.items.some((id) => !opened.has(id) && Object.hasOwn(given.items, id) && !given.items[id].closed && !given.items[id].fixed);
|
|
446
|
+
const newest = Object.values(given.items).reduce((m, it) => Math.max(m, finite(it.used, 0)), 0) + 1;
|
|
447
|
+
const byAge = [...opened].filter((id) => given.edges.some((e) => e.items.includes(id) && stayedOpen(e))).sort((a, b) => finite(given.items[a].used, 0) - finite(given.items[b].used, 0) || (a < b ? -1 : 1));
|
|
448
|
+
const state = byAge.length === 0 ? given : { ...given, items: { ...given.items, ...Object.fromEntries(byAge.map((id, k) => [id, { ...given.items[id], used: newest + k }])) } };
|
|
449
|
+
const fresh = new Set(options.fresh ?? []);
|
|
450
|
+
const prevEdge = (edge) => !previous || fresh.has(edge.id) || edge.items.some((id) => fresh.has(id)) ? void 0 : previous.edges[edge.id];
|
|
451
|
+
const notes = [];
|
|
452
|
+
const order = cutOrder(state.edges);
|
|
453
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
454
|
+
const claim = (id) => {
|
|
455
|
+
if (!Object.hasOwn(state.items, id)) {
|
|
456
|
+
notes.push({ code: "unknown-item", id });
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
if (claimed.has(id)) {
|
|
460
|
+
notes.push({ code: "twice", id });
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
claimed.add(id);
|
|
464
|
+
return true;
|
|
465
|
+
};
|
|
466
|
+
const owned = /* @__PURE__ */ new Map();
|
|
467
|
+
for (const e of order) owned.set(e, e.items.filter(claim));
|
|
468
|
+
return { state, previous, opened, fresh, order, owned, claim, prevEdge, notes, items: {}, edges: {}, rails: {}, railPlaces: {}, caps };
|
|
469
|
+
}
|
|
470
|
+
function shapeOf(f, r, axis, cross) {
|
|
471
|
+
if (!f) return {};
|
|
472
|
+
if (f.wrap) {
|
|
473
|
+
const lead = Math.max(0, finite(f.wrap.lead ?? 0, 0));
|
|
474
|
+
const row = Math.max(0, finite(f.wrap.row, 0));
|
|
475
|
+
return { rows: wrapLines(f.wrap, cross).lines, grip: rect(r.x, r.y, lead, Math.min(row, r.height)) };
|
|
476
|
+
}
|
|
477
|
+
const g = typeof f.grip === "number" && Number.isFinite(f.grip) && f.grip > 0 ? f.grip : 0;
|
|
478
|
+
if (!g) return {};
|
|
479
|
+
return { grip: axis === "column" ? rect(r.x, r.y, r.width, Math.min(g, r.height)) : rect(r.x, r.y, Math.min(g, r.width), r.height) };
|
|
480
|
+
}
|
|
481
|
+
function zoneStarts(state, fit, input) {
|
|
482
|
+
const column = fit.axis === "column";
|
|
483
|
+
const at = (r) => column ? r.y : r.x;
|
|
484
|
+
const out = /* @__PURE__ */ new Map();
|
|
485
|
+
const lengths = /* @__PURE__ */ new Map();
|
|
486
|
+
const drawn = fit.items.filter((p) => p.kind !== "menu");
|
|
487
|
+
for (const p of drawn) {
|
|
488
|
+
out.set(p.id, at(p.rect));
|
|
489
|
+
lengths.set(p.id, column ? p.rect.height : p.rect.width);
|
|
490
|
+
}
|
|
491
|
+
const len2 = (p) => lengths.get(p.id);
|
|
492
|
+
const gap = px(input.gap);
|
|
493
|
+
const start = px(input.pad?.start);
|
|
494
|
+
const end = px(input.pad?.end);
|
|
495
|
+
const menu = fit.menu ? (column ? fit.menu.rect.height : fit.menu.rect.width) + (drawn.length > 0 ? gap : 0) : 0;
|
|
496
|
+
const zone = (z) => drawn.filter((p) => zoneOf(state.items[p.id]) === z);
|
|
497
|
+
const s = zone("start");
|
|
498
|
+
const c = zone("center");
|
|
499
|
+
const e = zone("end");
|
|
500
|
+
const title = column ? void 0 : s.find((p) => {
|
|
501
|
+
const it = state.items[p.id];
|
|
502
|
+
const f = formsOf(it, "row")[p.form];
|
|
503
|
+
return it.fixed && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS2;
|
|
504
|
+
});
|
|
505
|
+
if (title) lengths.set(title.id, formMain(formsOf(state.items[title.id], "row")[title.form], "natural", fit.cross));
|
|
506
|
+
const used = drawn.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, drawn.length - 1) * gap;
|
|
507
|
+
const spare = fit.length - start - end - menu - used;
|
|
508
|
+
if (spare <= EPS2) return { starts: out, lengths };
|
|
509
|
+
const spaceOf = (p) => {
|
|
510
|
+
const v = state.items[p.id]?.space;
|
|
511
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
512
|
+
};
|
|
513
|
+
const spacing = new Set([...s, ...e].map((p) => p.id));
|
|
514
|
+
const asked = [...s, ...e].reduce((sum, p) => sum + spaceOf(p), 0);
|
|
515
|
+
const share = asked > spare ? spare / asked : 1;
|
|
516
|
+
const room = (p) => spacing.has(p.id) ? spaceOf(p) * share : 0;
|
|
517
|
+
const total = (ps) => ps.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, ps.length - 1) * gap;
|
|
518
|
+
const lay = (ps, from, lead) => {
|
|
519
|
+
let x = from;
|
|
520
|
+
for (const p of ps) {
|
|
521
|
+
if (lead) x += room(p);
|
|
522
|
+
out.set(p.id, x);
|
|
523
|
+
x += len2(p) + gap + (lead ? 0 : room(p));
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const spaced = (ps) => total(ps) + ps.reduce((sum, p) => sum + room(p), 0);
|
|
527
|
+
lay(s, start, true);
|
|
528
|
+
const endStart = fit.length - end - menu - spaced(e);
|
|
529
|
+
lay(e, endStart, false);
|
|
530
|
+
const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
|
|
531
|
+
const hi = endStart - (e.length > 0 ? gap : 0);
|
|
532
|
+
const mid2 = (fit.length - total(c)) / 2;
|
|
533
|
+
const clear = mid2 >= lo2 - EPS2 && mid2 + total(c) <= hi + EPS2;
|
|
534
|
+
lay(c, title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid2, hi - total(c))), false);
|
|
535
|
+
if (title && s[s.length - 1] === title) {
|
|
536
|
+
const next = [...c, ...e].map((p) => out.get(p.id));
|
|
537
|
+
const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
|
|
538
|
+
lengths.set(title.id, Math.max(len2(title), until - out.get(title.id)));
|
|
539
|
+
}
|
|
540
|
+
return { starts: out, lengths };
|
|
541
|
+
}
|
|
542
|
+
function emit(d, edge, r, solved, extra = {}) {
|
|
543
|
+
const { state, notes, items, edges } = d;
|
|
544
|
+
const column = axisOf(edge.side) === "column";
|
|
545
|
+
const { stack } = solved;
|
|
546
|
+
const thick = column ? r.width : r.height;
|
|
547
|
+
const { starts, lengths } = zoneStarts(state, stack, solved.input);
|
|
548
|
+
const toStage = (l, id) => {
|
|
549
|
+
const s = id !== void 0 ? starts.get(id) : void 0;
|
|
550
|
+
const n = id !== void 0 ? lengths.get(id) : void 0;
|
|
551
|
+
const x = column ? l.x : s ?? l.x;
|
|
552
|
+
const y = column ? s ?? l.y : l.y;
|
|
553
|
+
return rect(r.x + x, r.y + y, column ? l.width : n ?? l.width, column ? n ?? l.height : l.height);
|
|
554
|
+
};
|
|
555
|
+
const tabs = new Set(solved.tabs);
|
|
556
|
+
for (const id of solved.leftOut ?? []) notes.push({ code: "no-vertical-form", edge: edge.id, id });
|
|
557
|
+
for (const id of solved.leftOutIcons ?? []) notes.push({ code: "no-icons-form", edge: edge.id, id });
|
|
558
|
+
for (const p of stack.items) {
|
|
559
|
+
const it = state.items[p.id];
|
|
560
|
+
const inMenu = p.kind === "menu";
|
|
561
|
+
const drawnRect = toStage(p.rect, inMenu ? void 0 : p.id);
|
|
562
|
+
const f = formsOf(it, column ? "column" : "row")[p.form];
|
|
563
|
+
const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? "column" : "row", stack.cross);
|
|
564
|
+
const foldedBy = foldedByOf(it, formsOf(it, column ? "column" : "row"), p.form, solved.starts.get(p.id), edge);
|
|
565
|
+
items[p.id] = {
|
|
566
|
+
...shape,
|
|
567
|
+
...controlsOf(inMenu ? void 0 : f),
|
|
568
|
+
rect: drawnRect,
|
|
569
|
+
kind: it.kind,
|
|
570
|
+
axis: column ? "column" : "row",
|
|
571
|
+
form: p.form,
|
|
572
|
+
formKind: p.kind,
|
|
573
|
+
edge: edge.id,
|
|
574
|
+
zone: zoneOf(it),
|
|
575
|
+
...inMenu ? { inMenu: true } : {},
|
|
576
|
+
...tabs.has(p.id) ? { tab: true } : {},
|
|
577
|
+
...tabs.has(p.id) && f?.title === true && (edge.side === "left" || edge.side === "right") ? { railTitle: edge.side } : {},
|
|
578
|
+
...solved.closedTabs.has(p.id) ? { closed: true } : {},
|
|
579
|
+
...foldedBy ? { foldedBy } : {},
|
|
580
|
+
...it.fixed ? { fixed: true } : {}
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
for (const n of stack.notes) notes.push({ edge: edge.id, ...n });
|
|
584
|
+
edges[edge.id] = {
|
|
585
|
+
side: edge.side,
|
|
586
|
+
ring: finite(edge.ring, 0),
|
|
587
|
+
rect: r,
|
|
588
|
+
cross: thick,
|
|
589
|
+
menu: stack.menu ? { rect: toStage(stack.menu.rect), items: stack.menu.items } : null,
|
|
590
|
+
// The stack's items are in zone order, the order `emit` drew them in.
|
|
591
|
+
items: stack.items.map((p) => p.id),
|
|
592
|
+
tabs: solved.tabs,
|
|
593
|
+
stack,
|
|
594
|
+
free: solved.free,
|
|
595
|
+
...extra
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// src/solve/edge.ts
|
|
600
|
+
import { EPS as EPS3 } from "@n-uf/placement";
|
|
601
|
+
import { fitStack, formCompact, formCrossMin as formCrossMin2, formSetsCross as formSetsCross2 } from "@n-uf/placement/stack";
|
|
602
|
+
var stackItemOf = (item, forms, edge, from) => ({
|
|
603
|
+
id: item.id,
|
|
604
|
+
forms,
|
|
605
|
+
used: finite(item.used, 0),
|
|
606
|
+
...item.kept ? { kept: true } : {},
|
|
607
|
+
// Where its ladder starts: as asked, else its hand fold resolved on this axis (`startOf`: its folded form).
|
|
608
|
+
...from !== void 0 ? { from } : startOf(item, forms, edge) > 0 ? { from: startOf(item, forms, edge) } : {},
|
|
609
|
+
...item.fixed ? { fixed: true } : {}
|
|
610
|
+
});
|
|
611
|
+
function hasSetter(fit, forms) {
|
|
612
|
+
return fit.items.some((p) => p.kind !== "menu" && formSetsCross2(forms(p.id)[p.form]));
|
|
613
|
+
}
|
|
614
|
+
var TRAY_RANK = 100;
|
|
615
|
+
var startsOf = (input) => new Map(input.items.map((i) => [i.id, i.from ?? 0]));
|
|
616
|
+
function compactEdge(f) {
|
|
617
|
+
const { state, edge, formsById } = f;
|
|
618
|
+
const iconsAt = (id) => {
|
|
619
|
+
const forms = formsById(id);
|
|
620
|
+
for (let j = startOf(state.items[id], forms, edge); j < forms.length; j++) if (formCompact(forms[j])) return j;
|
|
621
|
+
return forms.findIndex(formCompact);
|
|
622
|
+
};
|
|
623
|
+
const shown = f.ordered.filter((id) => !state.items[id].closed && iconsAt(id) >= 0);
|
|
624
|
+
const leftOutIcons = f.ordered.filter((id) => !state.items[id].closed && iconsAt(id) < 0);
|
|
625
|
+
const compactInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(state.items[id], formsById(id), edge, iconsAt(id))) };
|
|
626
|
+
const stack = fitStack(compactInput, f.previous ? { previous: f.previous.free } : {});
|
|
627
|
+
return { stack, free: stack, tabs: [], closedTabs: /* @__PURE__ */ new Set(), input: compactInput, starts: startsOf(compactInput), leftOutIcons };
|
|
628
|
+
}
|
|
629
|
+
function railEdge(f, free, asStackItem, starts) {
|
|
630
|
+
const { state, edge, formsById } = f;
|
|
631
|
+
const railIndex = (item, forms) => {
|
|
632
|
+
if (item.fixed) return -1;
|
|
633
|
+
for (let j = startOf(item, forms, edge); j < forms.length; j++) if (forms[j].kind === "rail") return j;
|
|
634
|
+
return -1;
|
|
635
|
+
};
|
|
636
|
+
const wrapOnly = (id) => railIndex(state.items[id], formsById(id)) < 0 && pastWrap(formsById(id), startOf(state.items[id], formsById(id), edge)) === void 0;
|
|
637
|
+
const shown = f.ordered.filter((id) => {
|
|
638
|
+
const it = state.items[id];
|
|
639
|
+
if (!it.closed && wrapOnly(id)) return false;
|
|
640
|
+
return !it.closed || edge.railShowsClosed === true && railIndex(it, formsById(id)) >= 0;
|
|
641
|
+
});
|
|
642
|
+
const leftOut = f.ordered.filter((id) => !state.items[id].closed && wrapOnly(id));
|
|
643
|
+
const anyRail = shown.some((id) => railIndex(state.items[id], formsById(id)) >= 0);
|
|
644
|
+
if (!anyRail) return null;
|
|
645
|
+
const railInput = {
|
|
646
|
+
...f.base,
|
|
647
|
+
// The side's rail mode: a title rail form is offered only while the side shows titles.
|
|
648
|
+
...railModeOf(state, edge.side) === "titles" ? { titles: true } : {},
|
|
649
|
+
items: shown.map((id) => {
|
|
650
|
+
const it = state.items[id];
|
|
651
|
+
const j = railIndex(it, formsById(id));
|
|
652
|
+
const forms = asStackItem(id).forms;
|
|
653
|
+
return stackItemOf(it, forms, edge, j >= 0 ? j : pastWrap(forms, startOf(it, forms, edge)));
|
|
654
|
+
})
|
|
655
|
+
};
|
|
656
|
+
const stack = fitStack(railInput, f.previous ? { previous: f.previous.stack } : {});
|
|
657
|
+
const tabs = stack.items.filter((p) => p.kind === "rail").map((p) => p.id);
|
|
658
|
+
const closedTabs = new Set(shown.filter((id) => state.items[id].closed));
|
|
659
|
+
return { stack, free, tabs, closedTabs, input: railInput, starts, leftOut };
|
|
660
|
+
}
|
|
661
|
+
function solveEdge(state, edge, ids, length, room, previous) {
|
|
662
|
+
const axis = axisOf(edge.side);
|
|
663
|
+
const column = axis === "column";
|
|
664
|
+
const ordered = zoneSorted(state, ids);
|
|
665
|
+
const priorityOf = (id) => finite(state.items[id].priority ?? edge.priority ?? 0, 0);
|
|
666
|
+
const formsById = (id) => {
|
|
667
|
+
const forms = formsOf(state.items[id], axis);
|
|
668
|
+
const p = priorityOf(id);
|
|
669
|
+
return p === 0 ? forms : forms.map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + p }));
|
|
670
|
+
};
|
|
671
|
+
const maxOf = Number.isNaN(edge.cross.max) ? Infinity : edge.cross.max;
|
|
672
|
+
const cross = { min: Math.min(px(edge.cross.min), room), max: Math.min(maxOf, room), rail: Math.min(px(edge.cross.rail ?? 30), room) };
|
|
673
|
+
const base = {
|
|
674
|
+
axis,
|
|
675
|
+
length,
|
|
676
|
+
cross,
|
|
677
|
+
...edge.menu ? { menu: edge.menu } : {},
|
|
678
|
+
...edge.gap !== void 0 ? { gap: edge.gap } : {},
|
|
679
|
+
...edge.pad ? { pad: edge.pad } : {},
|
|
680
|
+
...column ? { ownCross: true } : {}
|
|
681
|
+
};
|
|
682
|
+
const frame = { state, edge, column, ordered, formsById, base, previous };
|
|
683
|
+
if (edge.compact) return compactEdge(frame);
|
|
684
|
+
const open = ordered.filter((id) => !state.items[id].closed);
|
|
685
|
+
const asStackItem = (id) => {
|
|
686
|
+
const it = state.items[id];
|
|
687
|
+
const forms = formsById(id);
|
|
688
|
+
if (!column || !edge.zoneAccepts?.end || zoneOf(it) !== "end") return stackItemOf(it, forms, edge);
|
|
689
|
+
const tray = (f) => f.kind === "wrap" || formCompact(f) || !!f.wrap;
|
|
690
|
+
let first = -1;
|
|
691
|
+
for (let j = startOf(it, forms, edge); j < forms.length && first < 0; j++) if (tray(forms[j])) first = j;
|
|
692
|
+
let last = -1;
|
|
693
|
+
forms.forEach((f, j) => {
|
|
694
|
+
if (tray(f)) last = j;
|
|
695
|
+
});
|
|
696
|
+
if (first < 0) return stackItemOf(it, forms, edge);
|
|
697
|
+
return stackItemOf(it, forms.slice(0, last + 1).map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + TRAY_RANK })), edge, first);
|
|
698
|
+
};
|
|
699
|
+
const input = { ...base, items: open.map(asStackItem) };
|
|
700
|
+
const free = fitStack(input, previous ? { previous: previous.free } : {});
|
|
701
|
+
const none = /* @__PURE__ */ new Set();
|
|
702
|
+
const starts = startsOf(input);
|
|
703
|
+
if (column && !hasSetter(free, formsById)) {
|
|
704
|
+
const rail = railEdge(frame, free, asStackItem, starts);
|
|
705
|
+
if (rail) return rail;
|
|
706
|
+
}
|
|
707
|
+
if (!column && edge.giveWay === true) {
|
|
708
|
+
const fits = (f) => !formSetsCross2(f) || formCrossMin2(f) <= cross.max + EPS3;
|
|
709
|
+
let moved = false;
|
|
710
|
+
const items = input.items.map((it) => {
|
|
711
|
+
const from = it.from ?? 0;
|
|
712
|
+
if (it.fixed || fits(it.forms[from])) return it;
|
|
713
|
+
const j = it.forms.findIndex((f, k) => k > from && f.kind !== "menu" && fits(f));
|
|
714
|
+
if (j < 0) return it;
|
|
715
|
+
moved = true;
|
|
716
|
+
return { ...it, from: j };
|
|
717
|
+
});
|
|
718
|
+
if (moved) {
|
|
719
|
+
const folded = { ...input, items };
|
|
720
|
+
return { stack: fitStack(folded), free, tabs: [], closedTabs: none, input: folded, starts };
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const size = edge.size;
|
|
724
|
+
if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
|
|
725
|
+
const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross2(formsById(p.id)[p.form]));
|
|
726
|
+
const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin2(formsById(p.id)[p.form])));
|
|
727
|
+
const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
|
|
728
|
+
if (Math.abs(s - free.cross) > EPS3) {
|
|
729
|
+
const sized2 = { ...input, cross: { ...cross, min: s, max: s } };
|
|
730
|
+
const stack = fitStack(sized2, previous ? { previous: previous.stack } : {});
|
|
731
|
+
return { stack, free, tabs: [], closedTabs: none, input: sized2, starts };
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return { stack: free, free, tabs: [], closedTabs: none, input, starts };
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/solve/bars.ts
|
|
738
|
+
function cutEdge(d, edge, area7, cut2) {
|
|
739
|
+
const column = axisOf(edge.side) === "column";
|
|
740
|
+
const length = column ? area7.height : area7.width;
|
|
741
|
+
const room = Math.max(0, column ? area7.width : area7.height);
|
|
742
|
+
const cap = d.caps.get(edge.id);
|
|
743
|
+
const solvedAs = cap === void 0 ? edge : { ...edge, cross: { ...edge.cross, max: Math.min(edge.cross.max, cap) } };
|
|
744
|
+
const solved = solveEdge(d.state, solvedAs, d.owned.get(edge), length, room, d.prevEdge(edge));
|
|
745
|
+
const band = cutEdges(area7, [{ id: edge.id, side: edge.side, size: solved.stack.items.length === 0 ? 0 : solved.stack.cross }]);
|
|
746
|
+
emit(d, edge, band.bands[edge.id], solved);
|
|
747
|
+
return cut2 ? band.rest : area7;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// src/solve/floats.ts
|
|
751
|
+
import { EPS as EPS4, rect as rect2 } from "@n-uf/placement";
|
|
752
|
+
import { fitFloat, formFolded as formFolded2 } from "@n-uf/placement/stack";
|
|
753
|
+
var sinceOf = (f) => isSince(f.since) ? f.since : 0;
|
|
754
|
+
function anchored(content, w, h, given) {
|
|
755
|
+
const anchor = anchorName(given);
|
|
756
|
+
const dx = typeof given === "string" ? 0 : finite(given.dx ?? 0, 0);
|
|
757
|
+
const dy = typeof given === "string" ? 0 : finite(given.dy ?? 0, 0);
|
|
758
|
+
const left = content.x;
|
|
759
|
+
const right = content.x + content.width - w;
|
|
760
|
+
const midX = content.x + (content.width - w) / 2;
|
|
761
|
+
const top = content.y;
|
|
762
|
+
const bottom = content.y + content.height - h;
|
|
763
|
+
const midY = content.y + (content.height - h) / 2;
|
|
764
|
+
const at = {
|
|
765
|
+
"content-top-left": [left, top],
|
|
766
|
+
"content-top": [midX, top],
|
|
767
|
+
"content-top-right": [right, top],
|
|
768
|
+
"content-right": [right, midY],
|
|
769
|
+
"content-bottom-right": [right, bottom],
|
|
770
|
+
"content-bottom": [midX, bottom],
|
|
771
|
+
"content-bottom-left": [left, bottom],
|
|
772
|
+
"content-left": [left, midY]
|
|
773
|
+
};
|
|
774
|
+
const [x, y] = at[anchor] ?? at["content-top-right"];
|
|
775
|
+
return rect2(x + dx, y + dy, w, h);
|
|
776
|
+
}
|
|
777
|
+
function floatFloor(item, form, orient, size) {
|
|
778
|
+
const row = orient === "row";
|
|
779
|
+
return {
|
|
780
|
+
width: item.floatMin ? px(item.floatMin.width) : Math.min(size.width, px(row ? form?.main.min : form?.cross.min)),
|
|
781
|
+
height: item.floatMin ? px(item.floatMin.height) : Math.min(size.height, px(row ? form?.cross.min : form?.main.min))
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
function clearSize(region, avoid) {
|
|
785
|
+
const span = (axis) => {
|
|
786
|
+
const lo2 = axis === "y" ? region.y : region.x;
|
|
787
|
+
const hi = lo2 + (axis === "y" ? region.height : region.width);
|
|
788
|
+
const mid2 = (lo2 + hi) / 2;
|
|
789
|
+
let a = lo2;
|
|
790
|
+
let b = hi;
|
|
791
|
+
for (const r of avoid) {
|
|
792
|
+
const whole = axis === "y" ? r.x <= region.x + EPS4 && r.x + r.width >= region.x + region.width - EPS4 : r.y <= region.y + EPS4 && r.y + r.height >= region.y + region.height - EPS4;
|
|
793
|
+
const s = axis === "y" ? r.y : r.x;
|
|
794
|
+
const e = s + (axis === "y" ? r.height : r.width);
|
|
795
|
+
if (!whole || e <= lo2 || s >= hi) continue;
|
|
796
|
+
if (s + e <= 2 * mid2) a = Math.max(a, e);
|
|
797
|
+
else b = Math.min(b, s);
|
|
798
|
+
}
|
|
799
|
+
return Math.max(0, b - a);
|
|
800
|
+
};
|
|
801
|
+
return { width: span("x"), height: span("y") };
|
|
802
|
+
}
|
|
803
|
+
function fitBeside(want, region, avoid, earlier) {
|
|
804
|
+
if (earlier.length === 0) return fitFloat(want, region, avoid);
|
|
805
|
+
const both = fitFloat(want, region, [...avoid, ...earlier]);
|
|
806
|
+
return both.covers.length === 0 ? both : fitFloat(want, region, avoid);
|
|
807
|
+
}
|
|
808
|
+
function placeFloat(item, f, region, avoid, content, stage, earlier = []) {
|
|
809
|
+
const shape = floatShape(item, f);
|
|
810
|
+
const from = shape.form;
|
|
811
|
+
const fo = f.orient ?? floatOrientOf(item);
|
|
812
|
+
const form = formsOf(item, fo)[from];
|
|
813
|
+
const floor = floatFloor(item, form, fo, shape);
|
|
814
|
+
const cap = { width: Number.isFinite(item.floatMax?.width) ? item.floatMax.width : Infinity, height: Number.isFinite(item.floatMax?.height) ? item.floatMax.height : Infinity };
|
|
815
|
+
const clear = clearSize(region, avoid);
|
|
816
|
+
const w = Math.max(floor.width, Math.min(shape.width, clear.width, cap.width));
|
|
817
|
+
const folded = !!form && formFolded2(form);
|
|
818
|
+
const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, clear.height, cap.height));
|
|
819
|
+
const want = f.anchor ? anchored(content, w, h, f.anchor) : rect2(finite(f.rect.x, stage.x), finite(f.rect.y, stage.y), w, h);
|
|
820
|
+
const fit0 = f.anchor ? fitBeside(want, region, avoid, earlier) : fitFloat(want, region, avoid);
|
|
821
|
+
const fit = w > region.width + EPS4 ? { ...fit0, rect: rect2(region.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
|
|
822
|
+
return { from, fo, form, fit };
|
|
823
|
+
}
|
|
824
|
+
function layFloats(d, stage, content, inset) {
|
|
825
|
+
const { state, notes, items, edges } = d;
|
|
826
|
+
const avoid = [];
|
|
827
|
+
for (const l of Object.values(items)) avoid.push(l.rect);
|
|
828
|
+
for (const e of Object.values(edges)) {
|
|
829
|
+
if (axisOf(e.side) === "row" && e.cross > 0) avoid.push(e.rect);
|
|
830
|
+
if (e.menu) avoid.push(e.menu.rect);
|
|
831
|
+
}
|
|
832
|
+
for (const c of keepClearFor(state, "floats")) avoid.push(c);
|
|
833
|
+
const floatRegion2 = rect2(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);
|
|
834
|
+
const drawn = [];
|
|
835
|
+
const noForm = /* @__PURE__ */ new Set();
|
|
836
|
+
for (const f of state.floats) {
|
|
837
|
+
if (!d.claim(f.id)) continue;
|
|
838
|
+
const it = state.items[f.id];
|
|
839
|
+
if (it.closed) continue;
|
|
840
|
+
if (floatShape(it, f).none) noForm.add(f.id);
|
|
841
|
+
drawn.push(f);
|
|
842
|
+
}
|
|
843
|
+
const placed = /* @__PURE__ */ new Map();
|
|
844
|
+
const place = (f, earlier = []) => {
|
|
845
|
+
placed.set(f.id, placeFloat(state.items[f.id], f, floatRegion2, avoid, content, stage, earlier));
|
|
846
|
+
};
|
|
847
|
+
const live = drawn.filter((f) => !noForm.has(f.id));
|
|
848
|
+
for (const f of live) if (!f.anchor) place(f);
|
|
849
|
+
const own = [...placed.values()].map((p) => p.fit.rect);
|
|
850
|
+
const anchored2 = live.filter((f) => f.anchor).sort((a, b) => sinceOf(a) - sinceOf(b) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
851
|
+
anchored2.forEach((f, i) => place(f, [...own, ...anchored2.slice(0, i).map((a) => placed.get(a.id).fit.rect)]));
|
|
852
|
+
const floats = [];
|
|
853
|
+
for (const f of drawn) {
|
|
854
|
+
if (noForm.has(f.id)) {
|
|
855
|
+
notes.push({ code: "no-vertical-form", id: f.id });
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
const it = state.items[f.id];
|
|
859
|
+
const { from, fo, form, fit } = placed.get(f.id);
|
|
860
|
+
if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
|
|
861
|
+
if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
|
|
862
|
+
if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
|
|
863
|
+
const foldedBy = foldedByOf(it, formsOf(it, fo), from);
|
|
864
|
+
items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), ...controlsOf(form), rect: fit.rect, kind: it.kind, axis: fo, form: from, formKind: form?.kind ?? "open", floating: true, ...foldedBy ? { foldedBy } : {} };
|
|
865
|
+
floats.push(f.id);
|
|
866
|
+
}
|
|
867
|
+
return floats;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/solve/insets.ts
|
|
871
|
+
import { EPS as EPS5, rect as rect3 } from "@n-uf/placement";
|
|
872
|
+
function insetOf(d) {
|
|
873
|
+
const { state } = d;
|
|
874
|
+
const docked = d.order.some((e) => isSide(e) && e.accepts.length > 0 && d.owned.get(e).some((id) => isDockingPanel(state.items[id])));
|
|
875
|
+
const inset = state.insetWhen === "docked" && !docked ? {} : state.inset ?? {};
|
|
876
|
+
return { inset, docked };
|
|
877
|
+
}
|
|
878
|
+
var insideInset = (outer, inset) => rect3(outer.x + px(inset.left), outer.y + px(inset.top), Math.max(0, outer.width - px(inset.left) - px(inset.right)), Math.max(0, outer.height - px(inset.top) - px(inset.bottom)));
|
|
879
|
+
function insetReach(area7, f) {
|
|
880
|
+
const up = area7.y <= f.outer.y + px(f.inset.top) + EPS5 ? px(f.inset.top) : 0;
|
|
881
|
+
const down = area7.y + area7.height >= f.outer.y + f.outer.height - px(f.inset.bottom) - EPS5 ? px(f.inset.bottom) : 0;
|
|
882
|
+
return { up, down };
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// src/solve/notes.ts
|
|
886
|
+
import { EPS as EPS6 } from "@n-uf/placement";
|
|
887
|
+
function contentNotes(d, content) {
|
|
888
|
+
const { state, notes, previous } = d;
|
|
889
|
+
if (state.contentMin) {
|
|
890
|
+
const minW = px(state.contentMin.width) - (d.chromeAllowance ?? 0);
|
|
891
|
+
const minH = px(state.contentMin.height);
|
|
892
|
+
if (content.width < minW - EPS6) notes.push({ code: "content-narrow", width: content.width, min: minW });
|
|
893
|
+
const bars = d.order.filter((e) => e.mode === "overlay" && !isSide(e)).reduce((s, e) => s + (d.edges[e.id]?.cross ?? 0), 0);
|
|
894
|
+
if (content.height - bars < minH - EPS6) notes.push({ code: "content-short", height: content.height - bars, min: minH });
|
|
895
|
+
}
|
|
896
|
+
if (previous) {
|
|
897
|
+
const was = previous.content;
|
|
898
|
+
const moved = Math.abs(was.x - content.x) > EPS6 || Math.abs(was.y - content.y) > EPS6 || Math.abs(was.width - content.width) > EPS6 || Math.abs(was.height - content.height) > EPS6;
|
|
899
|
+
if (moved) notes.push({ code: "content-changed", from: was, to: content });
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// src/solve/sides.ts
|
|
904
|
+
import { EPS as EPS8, rect as rect5 } from "@n-uf/placement";
|
|
905
|
+
|
|
906
|
+
// src/solve/columns.ts
|
|
907
|
+
import { EPS as EPS7 } from "@n-uf/placement";
|
|
908
|
+
import { formCrossMin as formCrossMin3, formSetsCross as formSetsCross3 } from "@n-uf/placement/stack";
|
|
909
|
+
var isChrome = (state, c) => !c.dyn && isSideBar(state, c.edge);
|
|
910
|
+
function columnsOf(d, sideEdges, area7, tall) {
|
|
911
|
+
const { state } = d;
|
|
912
|
+
return sideEdges.map((edge) => {
|
|
913
|
+
const side = edge.side;
|
|
914
|
+
const solved = solveEdge(state, edge, d.owned.get(edge), tall(edge), Math.max(0, area7.width), d.prevEdge(edge));
|
|
915
|
+
const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area7.width);
|
|
916
|
+
const visible = d.owned.get(edge).filter((id) => !state.items[id].closed);
|
|
917
|
+
const dyn = (edge.column === true || edge.giveWay === true) && state.rails?.[side] !== void 0 && visible.length > 0;
|
|
918
|
+
const forms = (id) => formsOf(state.items[id], "column");
|
|
919
|
+
const setters = solved.free.items.filter((p) => p.kind !== "menu" && formSetsCross3(forms(p.id)[p.form]));
|
|
920
|
+
const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin3(forms(p.id)[p.form])))) : width;
|
|
921
|
+
return {
|
|
922
|
+
edge,
|
|
923
|
+
side,
|
|
924
|
+
solved,
|
|
925
|
+
width,
|
|
926
|
+
min,
|
|
927
|
+
visible,
|
|
928
|
+
dyn,
|
|
929
|
+
hand: dyn && edge.column === true && visible.every((id) => startOf(state.items[id], formsOf(state.items[id], "column")) > 0),
|
|
930
|
+
kept: visible.some((id) => state.items[id].kept === true),
|
|
931
|
+
age: Math.max(-Infinity, ...visible.map((id) => finite(state.items[id].used, 0)))
|
|
932
|
+
};
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
function giveWay(d, cols, area7, gutter) {
|
|
936
|
+
const { state, previous, fresh, opened } = d;
|
|
937
|
+
const ride = state.handFold === "ride";
|
|
938
|
+
const cmin = state.contentMin ? px(state.contentMin.width) : void 0;
|
|
939
|
+
const chromeWidth = state.contentMin?.chromeWidth;
|
|
940
|
+
const floor = cmin !== void 0 && typeof chromeWidth === "number" && Number.isFinite(chromeWidth) ? Math.min(cmin, px(chromeWidth)) : void 0;
|
|
941
|
+
const chrome = floor === void 0 ? 0 : cols.filter((c) => isChrome(state, c) && c.width > 0).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : gutter), 0);
|
|
942
|
+
if (floor !== void 0) d.chromeAllowance = Math.min(chrome, cmin - floor);
|
|
943
|
+
const foldOrder = cols.filter((c) => c.dyn && !c.hand && c.width > 0).sort((a, b) => giveWayOrder(a, b) || (a.side === b.side ? 0 : a.side === "left" ? -1 : 1));
|
|
944
|
+
const shrunkBefore = (previous?.notes ?? []).flatMap((n) => n.code === "column-shrunk" ? [n.edge] : []);
|
|
945
|
+
const rankOf = (c) => shrunkBefore.includes(c.edge.id) ? shrunkBefore.indexOf(c.edge.id) : Infinity;
|
|
946
|
+
const shrinkOrder = foldOrder.map((c, i) => ({ c, i })).sort((a, b) => rankOf(a.c) === rankOf(b.c) ? a.i - b.i : rankOf(a.c) < rankOf(b.c) ? -1 : 1).map((x) => x.c);
|
|
947
|
+
const railW = (side) => px(state.rails?.[side]?.width);
|
|
948
|
+
const evaluate = (auto2) => {
|
|
949
|
+
const openOn = (side) => cols.some((c) => c.side === side && c.dyn && c.edge.column === true && !c.hand && !auto2.has(c) && c.width > 0);
|
|
950
|
+
const riding = (c) => ride && c.hand && openOn(c.side);
|
|
951
|
+
const railed = (c) => c.dyn && (auto2.has(c) || c.hand && !riding(c));
|
|
952
|
+
const widths = new Map(cols.filter((c) => !railed(c) && !riding(c)).map((c) => [c, c.width]));
|
|
953
|
+
const railSides = ["left", "right"].filter((s) => cols.some((c) => c.side === s && railed(c)));
|
|
954
|
+
let used = 0;
|
|
955
|
+
for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : gutter) : 0;
|
|
956
|
+
for (const s of railSides) used += railW(s) + gutter;
|
|
957
|
+
let excess = cmin === void 0 ? -Infinity : floor === void 0 ? used + cmin - area7.width : Math.max(used - chrome + cmin, used + floor) - area7.width;
|
|
958
|
+
for (const c of shrinkOrder) {
|
|
959
|
+
if (excess <= EPS7) break;
|
|
960
|
+
const w = widths.get(c);
|
|
961
|
+
if (w === void 0) continue;
|
|
962
|
+
const take = Math.min(excess, w - c.min);
|
|
963
|
+
if (take > 0) {
|
|
964
|
+
widths.set(c, w - take);
|
|
965
|
+
excess -= take;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return { auto: auto2, widths, excess, railed, riding, shrinkOrder };
|
|
969
|
+
};
|
|
970
|
+
let auto = /* @__PURE__ */ new Set();
|
|
971
|
+
if (cmin !== void 0) {
|
|
972
|
+
const unfold = () => {
|
|
973
|
+
for (const c of [...auto].reverse()) {
|
|
974
|
+
const fewer = new Set([...auto].filter((x) => x !== c));
|
|
975
|
+
if (evaluate(fewer).excess <= EPS7) auto = fewer;
|
|
976
|
+
else break;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
if (previous) {
|
|
980
|
+
const byId = new Map(foldOrder.map((c) => [c.edge.id, c]));
|
|
981
|
+
const anew = (c) => fresh.has(c.edge.id) || c.visible.some((id) => fresh.has(id)) || c.visible.some((id) => opened.has(id)) && c.visible.some((id) => !opened.has(id));
|
|
982
|
+
const was = previous.notes.flatMap((n) => (n.code === "column-folded" || n.code === "kept-folded") && byId.has(n.edge) && !anew(byId.get(n.edge)) ? [byId.get(n.edge)] : []);
|
|
983
|
+
auto = new Set(was);
|
|
984
|
+
if (evaluate(auto).excess <= EPS7) unfold();
|
|
985
|
+
}
|
|
986
|
+
for (const c of foldOrder) {
|
|
987
|
+
if (evaluate(auto).excess <= EPS7) break;
|
|
988
|
+
if (!auto.has(c)) auto = /* @__PURE__ */ new Set([...auto, c]);
|
|
989
|
+
}
|
|
990
|
+
for (let size = -1; size !== auto.size; ) {
|
|
991
|
+
size = auto.size;
|
|
992
|
+
unfold();
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return evaluate(auto);
|
|
996
|
+
}
|
|
997
|
+
function columnRoom(d, cols, area7, f) {
|
|
998
|
+
const { state } = d;
|
|
999
|
+
const cmin = state.contentMin ? px(state.contentMin.width) : void 0;
|
|
1000
|
+
const openMin = (ids, least) => Math.max(
|
|
1001
|
+
least,
|
|
1002
|
+
...ids.map((id) => {
|
|
1003
|
+
const form = formsOf(state.items[id], "column")[0];
|
|
1004
|
+
return form && formSetsCross3(form) ? formCrossMin3(form) : 0;
|
|
1005
|
+
})
|
|
1006
|
+
);
|
|
1007
|
+
const open = cols.filter((c) => c.edge.column === true && c.visible.length > 0).map((c) => c.hand ? openMin(c.visible, px(c.edge.cross.min)) : c.min);
|
|
1008
|
+
const templates = ["left", "right"].flatMap((s) => {
|
|
1009
|
+
const t = state.columns?.[s];
|
|
1010
|
+
if (!t) return [];
|
|
1011
|
+
const takes = Object.values(state.items).filter((it) => !it.fixed && !it.closed && t.accepts.includes(it.kind));
|
|
1012
|
+
return [openMin(takes.map((it) => it.id), px(t.cross.min))];
|
|
1013
|
+
});
|
|
1014
|
+
const colMins = open.length > 0 ? open : templates;
|
|
1015
|
+
if (cmin === void 0 || colMins.length === 0) return;
|
|
1016
|
+
const allBars = cols.filter((c) => c.width > 0 && isChrome(state, c)).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : f.gutter), 0);
|
|
1017
|
+
const bars = d.chromeAllowance === void 0 ? allBars : allBars - Math.min(allBars, d.chromeAllowance);
|
|
1018
|
+
const width = area7.width - bars - (state.insetWhen === "docked" && !f.docked ? px(state.inset?.left) + px(state.inset?.right) : 0);
|
|
1019
|
+
const need = cmin + Math.min(...colMins) + f.gutter;
|
|
1020
|
+
d.columnRoom = width >= need - EPS7;
|
|
1021
|
+
if (!d.columnRoom) d.notes.push({ code: "no-column-room", width, need });
|
|
1022
|
+
}
|
|
1023
|
+
function giveWayNotes(d, g, cols) {
|
|
1024
|
+
const { state, previous } = d;
|
|
1025
|
+
const dormant = new Set(cols.filter((c) => c.visible.length === 0 && (c.edge.column === true || c.edge.giveWay === true) && state.rails?.[c.side] !== void 0).map((c) => c.edge.id));
|
|
1026
|
+
const before = previous?.notes ?? [];
|
|
1027
|
+
const shrunk = /* @__PURE__ */ new Map();
|
|
1028
|
+
for (const c of g.shrinkOrder) {
|
|
1029
|
+
const w = g.widths.get(c);
|
|
1030
|
+
if (w !== void 0 && w < c.width - EPS7) shrunk.set(c.edge.id, { code: "column-shrunk", edge: c.edge.id, from: c.width, to: w });
|
|
1031
|
+
}
|
|
1032
|
+
const folded = new Map([...g.auto].map((c) => [c.edge.id, { code: c.kept ? "kept-folded" : "column-folded", edge: c.edge.id }]));
|
|
1033
|
+
const merge = (now, kept) => {
|
|
1034
|
+
const order = [];
|
|
1035
|
+
for (const n of before) {
|
|
1036
|
+
const edge = kept(n) && "edge" in n ? n.edge : void 0;
|
|
1037
|
+
if (edge === void 0) continue;
|
|
1038
|
+
if (dormant.has(edge)) order.push(n);
|
|
1039
|
+
else if (now.has(edge)) {
|
|
1040
|
+
order.push(now.get(edge));
|
|
1041
|
+
now.delete(edge);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
d.notes.push(...order, ...now.values());
|
|
1045
|
+
};
|
|
1046
|
+
d.notes.push(...shrunk.values());
|
|
1047
|
+
merge(folded, (n) => n.code === "column-folded" || n.code === "kept-folded");
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// src/solve/rails.ts
|
|
1051
|
+
import { rect as rect4 } from "@n-uf/placement";
|
|
1052
|
+
import { fitStack as fitStack2 } from "@n-uf/placement/stack";
|
|
1053
|
+
function riderBars(d, c) {
|
|
1054
|
+
const { state } = d;
|
|
1055
|
+
return zoneSorted(state, c.visible).map((id) => {
|
|
1056
|
+
const forms = formsOf(state.items[id], "column");
|
|
1057
|
+
const form = forms.length === 0 ? 0 : startOf(state.items[id], forms);
|
|
1058
|
+
return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
var ridersHeight = (d, riders) => riders.reduce((s, c) => s + riderBars(d, c).reduce((t, b) => t + b.h, 0), 0);
|
|
1062
|
+
function layRiders(d, host, riders, top) {
|
|
1063
|
+
const { state, items, edges } = d;
|
|
1064
|
+
const hr = edges[host.edge.id].rect;
|
|
1065
|
+
let y = top;
|
|
1066
|
+
for (const c of riders) {
|
|
1067
|
+
const bars = riderBars(d, c);
|
|
1068
|
+
const y0 = y;
|
|
1069
|
+
for (const b of bars) {
|
|
1070
|
+
const at = rect4(hr.x, y, hr.width, b.h);
|
|
1071
|
+
const it = state.items[b.id];
|
|
1072
|
+
items[b.id] = { rect: at, ...controlsOf(b.f), kind: it.kind, axis: "column", form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand", foldedBy: "hand" };
|
|
1073
|
+
y += b.h;
|
|
1074
|
+
}
|
|
1075
|
+
edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect4(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, items: bars.map((b) => b.id), tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: "hand" };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
function layRail(d, side, railRect, railed, g) {
|
|
1079
|
+
const { state, items } = d;
|
|
1080
|
+
const segments = [];
|
|
1081
|
+
const members = railed.flatMap((c) => zoneSorted(state, c.visible).map((id) => ({ id, c })));
|
|
1082
|
+
const formsById = (id) => formsOf(state.items[id], "column");
|
|
1083
|
+
const tileOf = (id) => formsById(id).findIndex((f) => f.kind === "rail" && f.title !== true);
|
|
1084
|
+
const titleOf = (id) => {
|
|
1085
|
+
const t = tileOf(id);
|
|
1086
|
+
return t > 0 && formsById(id)[t - 1].kind === "rail" && formsById(id)[t - 1].title === true ? t - 1 : -1;
|
|
1087
|
+
};
|
|
1088
|
+
const titles = railModeOf(state, side) === "titles" && members.some((m) => titleOf(m.id) >= 0) && members.every((m) => tileOf(m.id) >= 0);
|
|
1089
|
+
let fit;
|
|
1090
|
+
if (titles) {
|
|
1091
|
+
const input = {
|
|
1092
|
+
axis: "column",
|
|
1093
|
+
length: railRect.height,
|
|
1094
|
+
cross: { min: railRect.width, max: railRect.width, rail: railRect.width },
|
|
1095
|
+
titles: true,
|
|
1096
|
+
items: members.map(({ id }) => {
|
|
1097
|
+
const it = state.items[id];
|
|
1098
|
+
const p = finite(it.priority ?? 0, 0);
|
|
1099
|
+
const forms = formsById(id).slice(0, tileOf(id) + 1).map((f) => p === 0 ? f : { ...f, rank: finite(f.rank ?? 0, 0) + p });
|
|
1100
|
+
return { id, forms, used: finite(it.used, 0), ...it.kept ? { kept: true } : {}, from: titleOf(id) >= 0 ? titleOf(id) : tileOf(id) };
|
|
1101
|
+
})
|
|
1102
|
+
};
|
|
1103
|
+
const fresh = members.some((m) => d.fresh.has(m.id) || d.fresh.has(m.c.edge.id));
|
|
1104
|
+
const previous = d.previous && !fresh ? d.previous.rails[side]?.stack : void 0;
|
|
1105
|
+
fit = fitStack2(input, previous ? { previous } : {});
|
|
1106
|
+
}
|
|
1107
|
+
const placed = new Map(fit?.items.map((p) => [p.id, p]) ?? []);
|
|
1108
|
+
let y = railRect.y;
|
|
1109
|
+
for (const { id, c } of members) {
|
|
1110
|
+
const it = state.items[id];
|
|
1111
|
+
const forms = formsById(id);
|
|
1112
|
+
const ri = tileOf(id);
|
|
1113
|
+
const p = placed.get(id);
|
|
1114
|
+
const form = p ? p.form : ri >= 0 ? ri : forms.length === 0 ? 0 : startOf(it, forms);
|
|
1115
|
+
const at = p ? rect4(railRect.x, railRect.y + p.rect.y, railRect.width, p.rect.height) : rect4(railRect.x, y, railRect.width, ri >= 0 ? px(forms[ri].main.natural) : railRect.width);
|
|
1116
|
+
const title = forms[form]?.title === true;
|
|
1117
|
+
items[id] = { rect: at, ...controlsOf(forms[form]), kind: it.kind, axis: "column", form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand", foldedBy: startOf(it, forms) > 0 ? "hand" : "auto" };
|
|
1118
|
+
segments.push({ id, edge: c.edge.id, rect: at });
|
|
1119
|
+
y += at.height;
|
|
1120
|
+
}
|
|
1121
|
+
d.rails[side] = { rect: railRect, segments, ...fit ? { stack: fit } : {} };
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// src/solve/sides.ts
|
|
1125
|
+
function laySides(d, sideEdges, area7, f) {
|
|
1126
|
+
const H = area7.height;
|
|
1127
|
+
const reach = insetReach(area7, f);
|
|
1128
|
+
const tall = (edge) => H + (edge.outsideInset === true ? reach.up + reach.down : 0);
|
|
1129
|
+
const cols = columnsOf(d, sideEdges, area7, tall);
|
|
1130
|
+
const g = giveWay(d, cols, area7, f.gutter);
|
|
1131
|
+
columnRoom(d, cols, area7, f);
|
|
1132
|
+
giveWayNotes(d, g, cols);
|
|
1133
|
+
const walk = { x0: area7.x, x1: area7.x + area7.width };
|
|
1134
|
+
for (const side of ["left", "right"]) laySide(d, side, cols, g, area7, f, walk, reach.up, tall);
|
|
1135
|
+
return rect5(walk.x0, area7.y, Math.max(0, walk.x1 - walk.x0), H);
|
|
1136
|
+
}
|
|
1137
|
+
function forced(d, c, length, w) {
|
|
1138
|
+
const edge = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };
|
|
1139
|
+
const { size: _s, ...plain } = edge;
|
|
1140
|
+
return solveEdge(d.state, plain, d.owned.get(c.edge), length, w, d.prevEdge(c.edge));
|
|
1141
|
+
}
|
|
1142
|
+
function laySide(d, side, cols, g, area7, f, walk, upInset, tall) {
|
|
1143
|
+
const { state, edges } = d;
|
|
1144
|
+
const H = area7.height;
|
|
1145
|
+
const outsideSideBar = (c) => c.width > 0 && isOutsideSideBar(state, c.edge) && !g.railed(c) && !g.riding(c);
|
|
1146
|
+
const all = cols.filter((c) => c.side === side);
|
|
1147
|
+
const mine = [...all.filter(outsideSideBar), ...all.filter((c) => !outsideSideBar(c))];
|
|
1148
|
+
const railed = mine.filter((c) => g.railed(c));
|
|
1149
|
+
const riders = mine.filter((c) => g.riding(c));
|
|
1150
|
+
const host = mine.find((c) => c.dyn && c.edge.column === true && !c.hand && !g.auto.has(c) && c.width > 0);
|
|
1151
|
+
const ridersTop = ridersHeight(d, riders);
|
|
1152
|
+
const railW = px(state.rails?.[side]?.width);
|
|
1153
|
+
let railRect = null;
|
|
1154
|
+
let gap = px(side === "left" ? f.inset.left : f.inset.right);
|
|
1155
|
+
let barLaid = false;
|
|
1156
|
+
let railPlace = null;
|
|
1157
|
+
const placeRail = () => {
|
|
1158
|
+
const lead = barLaid ? gap : 0;
|
|
1159
|
+
return side === "left" ? rect5(walk.x0 - lead, area7.y, railW, H) : rect5(walk.x1 + lead - railW, area7.y, railW, H);
|
|
1160
|
+
};
|
|
1161
|
+
for (const c of mine) {
|
|
1162
|
+
if (!railPlace && !outsideSideBar(c)) {
|
|
1163
|
+
railPlace = placeRail();
|
|
1164
|
+
if (railed.length > 0) {
|
|
1165
|
+
railRect = railPlace;
|
|
1166
|
+
const lead = barLaid ? gap : 0;
|
|
1167
|
+
const after = barLaid ? Math.max(gap, f.gutter) : f.gutter;
|
|
1168
|
+
if (side === "left") walk.x0 += railPlace.width - lead + after;
|
|
1169
|
+
else walk.x1 -= railPlace.width - lead + after;
|
|
1170
|
+
gap = after;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (outsideSideBar(c)) barLaid = true;
|
|
1174
|
+
const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, items: zoneSorted(state, c.visible), tabs: [], stack: c.solved.stack, free: c.solved.free };
|
|
1175
|
+
if (g.railed(c)) {
|
|
1176
|
+
edges[c.edge.id] = { ...base, rect: rect5(railRect.x, area7.y, 0, H), folded: g.auto.has(c) ? "auto" : "hand" };
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (g.riding(c)) continue;
|
|
1180
|
+
const w = Math.min(g.widths.get(c), Math.max(0, walk.x1 - walk.x0));
|
|
1181
|
+
const top = c === host ? ridersTop : 0;
|
|
1182
|
+
let solved = top > 0 || Math.abs(w - c.width) > EPS8 ? forced(d, c, H - top, w) : c.solved;
|
|
1183
|
+
let r;
|
|
1184
|
+
if (c.edge.outsideInset === true) {
|
|
1185
|
+
const y0 = area7.y - upInset;
|
|
1186
|
+
const h = tall(c.edge);
|
|
1187
|
+
if (side === "left") {
|
|
1188
|
+
r = rect5(walk.x0 - gap, y0, w, h);
|
|
1189
|
+
walk.x0 += w;
|
|
1190
|
+
} else {
|
|
1191
|
+
r = rect5(walk.x1 + gap - w, y0, w, h);
|
|
1192
|
+
walk.x1 -= w;
|
|
1193
|
+
}
|
|
1194
|
+
if (Math.abs(h - H) > EPS8 || Math.abs(w - c.width) > EPS8) solved = forced(d, c, h, w);
|
|
1195
|
+
} else if (side === "left") {
|
|
1196
|
+
r = rect5(walk.x0, area7.y + top, w, H - top);
|
|
1197
|
+
walk.x0 += w > 0 ? w + f.gutter : 0;
|
|
1198
|
+
if (w > 0) gap = f.gutter;
|
|
1199
|
+
} else {
|
|
1200
|
+
walk.x1 -= w;
|
|
1201
|
+
r = rect5(walk.x1, area7.y + top, w, H - top);
|
|
1202
|
+
walk.x1 -= w > 0 ? f.gutter : 0;
|
|
1203
|
+
if (w > 0) gap = f.gutter;
|
|
1204
|
+
}
|
|
1205
|
+
emit(d, c.edge, r, solved, w < c.width - EPS8 ? { shrunk: true } : {});
|
|
1206
|
+
}
|
|
1207
|
+
if (host && riders.length > 0) layRiders(d, host, riders, area7.y);
|
|
1208
|
+
if (railRect) layRail(d, side, railRect, railed, g);
|
|
1209
|
+
if (state.rails?.[side]) d.railPlaces[side] = railPlace ?? placeRail();
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/solve.ts
|
|
1213
|
+
function solve(given, options = {}) {
|
|
1214
|
+
checkEdgeIds(given);
|
|
1215
|
+
const { view: shown, ignored } = viewOf(given);
|
|
1216
|
+
const lay = (caps, gave = []) => layOut(shown, options, caps, gave);
|
|
1217
|
+
const first = lay(/* @__PURE__ */ new Map());
|
|
1218
|
+
const way = barGiveWay(shown, first, lay);
|
|
1219
|
+
const l = way ? lay(way.caps, way.notes) : first;
|
|
1220
|
+
return ignored.length === 0 ? l : { ...l, notes: [...l.notes, ...ignored.map((edge) => ({ code: "show-in-ignored", edge }))] };
|
|
1221
|
+
}
|
|
1222
|
+
var withHeightOf = (area7, over) => rect6(over.x, area7.y, over.width, area7.height);
|
|
1223
|
+
function layOut(given, options, caps, gave) {
|
|
1224
|
+
const d = createDraft(given, options, caps);
|
|
1225
|
+
const { state, order } = d;
|
|
1226
|
+
const stage = rect6(finite(state.stage.x, 0), finite(state.stage.y, 0), px(state.stage.width), px(state.stage.height));
|
|
1227
|
+
const { inset, docked } = insetOf(d);
|
|
1228
|
+
const reserved = order.filter((e) => e.mode !== "overlay");
|
|
1229
|
+
const outsideBar = (e) => !isSide(e) && e.span !== "between" && e.outsideInset === true;
|
|
1230
|
+
let outer = stage;
|
|
1231
|
+
for (const e of reserved) if (outsideBar(e)) outer = cutEdge(d, e, outer, true);
|
|
1232
|
+
let area7 = insideInset(outer, inset);
|
|
1233
|
+
for (const e of reserved) if (!isSide(e) && e.span !== "between" && !outsideBar(e)) area7 = cutEdge(d, e, area7, true);
|
|
1234
|
+
const wide = area7;
|
|
1235
|
+
area7 = laySides(d, reserved.filter(isSide), area7, { inset, gutter: px(state.gutter), docked, outer });
|
|
1236
|
+
for (const e of reserved) if (!isSide(e) && e.span === "between") area7 = cutEdge(d, e, area7, true);
|
|
1237
|
+
const content = area7;
|
|
1238
|
+
let over = content;
|
|
1239
|
+
for (const e of order) {
|
|
1240
|
+
if (e.mode !== "overlay") continue;
|
|
1241
|
+
if (isSide(e) || e.span !== "full") over = cutEdge(d, e, over, true);
|
|
1242
|
+
else {
|
|
1243
|
+
const across2 = e.outsideInset === true ? outer : wide;
|
|
1244
|
+
over = withHeightOf(cutEdge(d, e, rect6(across2.x, over.y, across2.width, over.height), true), over);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
for (const n of gave) {
|
|
1248
|
+
d.notes.push(n);
|
|
1249
|
+
if (n.code === "bar-shrunk" && d.edges[n.edge]) d.edges[n.edge] = { ...d.edges[n.edge], shrunk: true };
|
|
1250
|
+
}
|
|
1251
|
+
contentNotes(d, content);
|
|
1252
|
+
const floats = layFloats(d, stage, content, inset);
|
|
1253
|
+
const { items, edges, rails, railPlaces, columnRoom: columnRoom2, notes } = d;
|
|
1254
|
+
return { items, edges, content, floats, rails, railPlaces, ...columnRoom2 !== void 0 ? { columnRoom: columnRoom2 } : {}, notes };
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// src/changes.ts
|
|
1258
|
+
import { clampInto as clampInto2 } from "@n-uf/placement";
|
|
1259
|
+
|
|
1260
|
+
// src/float-resize.ts
|
|
1261
|
+
var LIMITS = ["min", "max", "region", "docked"];
|
|
1262
|
+
var EPS9 = 0.5;
|
|
1263
|
+
var TOUCH = 1e-3;
|
|
1264
|
+
var fin = (v, d) => Number.isFinite(v) ? v : d;
|
|
1265
|
+
function floatObstacles(state, l, id) {
|
|
1266
|
+
const out = [];
|
|
1267
|
+
for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);
|
|
1268
|
+
for (const e of Object.values(l.edges)) {
|
|
1269
|
+
if (axisOf(e.side) === "row" && e.cross > 0) out.push(e.rect);
|
|
1270
|
+
if (e.menu) out.push(e.menu.rect);
|
|
1271
|
+
}
|
|
1272
|
+
for (const c of keepClearFor(state, "floats")) out.push(c);
|
|
1273
|
+
return out.filter((r) => r.width > 0 && r.height > 0);
|
|
1274
|
+
}
|
|
1275
|
+
function obstacleStop(drawn, obstacles, axis, drag, span) {
|
|
1276
|
+
const none = drag === "start" ? -Infinity : Infinity;
|
|
1277
|
+
if (!drawn || !drag) return none;
|
|
1278
|
+
const lo2 = (r) => axis === "x" ? r.x : r.y;
|
|
1279
|
+
const len2 = (r) => axis === "x" ? r.width : r.height;
|
|
1280
|
+
const across2 = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1281
|
+
let at = none;
|
|
1282
|
+
for (const o of obstacles) {
|
|
1283
|
+
const [c0, c1] = across2(o);
|
|
1284
|
+
if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
|
|
1285
|
+
const begin = lo2(o);
|
|
1286
|
+
const finish = begin + len2(o);
|
|
1287
|
+
const edge = drag === "start" ? lo2(drawn) : lo2(drawn) + len2(drawn);
|
|
1288
|
+
if (drag === "start") {
|
|
1289
|
+
if (finish <= edge + EPS9) at = Math.max(at, finish);
|
|
1290
|
+
else if (begin < edge - TOUCH) at = edge;
|
|
1291
|
+
} else {
|
|
1292
|
+
if (begin >= edge - EPS9) at = Math.min(at, begin);
|
|
1293
|
+
else if (finish > edge + TOUCH) at = edge;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return drag === "start" ? Math.min(at, lo2(drawn)) : Math.max(at, lo2(drawn) + len2(drawn));
|
|
1297
|
+
}
|
|
1298
|
+
function fitAxis(start, length, b, drag, hit) {
|
|
1299
|
+
const { min, lo: lo2, hi, stop } = b;
|
|
1300
|
+
const max = Math.max(min, b.max);
|
|
1301
|
+
const raw = fin(length, min);
|
|
1302
|
+
if (min >= hi - lo2) {
|
|
1303
|
+
hit.add("region");
|
|
1304
|
+
return [lo2, min];
|
|
1305
|
+
}
|
|
1306
|
+
const bind = (cands, pick) => {
|
|
1307
|
+
const at = cands.reduce((m, [v]) => pick(m, v), cands[0][0]);
|
|
1308
|
+
return [at, cands.filter(([v]) => Math.abs(v - at) <= EPS9).map(([, k]) => k)];
|
|
1309
|
+
};
|
|
1310
|
+
if (drag === "start") {
|
|
1311
|
+
const asked2 = fin(start, lo2) + raw;
|
|
1312
|
+
const end = Math.min(hi, Math.max(lo2 + min, asked2));
|
|
1313
|
+
if (Math.abs(end - asked2) > EPS9) hit.add("region");
|
|
1314
|
+
const [down, why2] = bind([[end - max, "max"], [lo2, "region"], [stop, "docked"]], Math.max);
|
|
1315
|
+
let from = end - raw;
|
|
1316
|
+
if (from > end - min) {
|
|
1317
|
+
from = end - min;
|
|
1318
|
+
hit.add("min");
|
|
1319
|
+
} else if (from < down - TOUCH) {
|
|
1320
|
+
from = why2.includes("docked") ? Math.min(down, end) : Math.min(down, end - min);
|
|
1321
|
+
for (const k of from === down ? why2 : ["min"]) hit.add(k);
|
|
1322
|
+
}
|
|
1323
|
+
return [from, end - from];
|
|
1324
|
+
}
|
|
1325
|
+
const asked = fin(start, lo2);
|
|
1326
|
+
const a = Math.max(lo2, Math.min(hi - min, asked));
|
|
1327
|
+
if (Math.abs(a - asked) > EPS9) hit.add("region");
|
|
1328
|
+
const [up, why] = bind([[a + max, "max"], [hi, "region"], [stop, "docked"]], Math.min);
|
|
1329
|
+
let to = a + raw;
|
|
1330
|
+
if (to < a + min) {
|
|
1331
|
+
to = a + min;
|
|
1332
|
+
hit.add("min");
|
|
1333
|
+
} else if (to > up + TOUCH) {
|
|
1334
|
+
to = why.includes("docked") ? Math.max(up, a) : Math.max(up, a + min);
|
|
1335
|
+
for (const k of to === up ? why : ["min"]) hit.add(k);
|
|
1336
|
+
}
|
|
1337
|
+
return [a, to - a];
|
|
1338
|
+
}
|
|
1339
|
+
function fitResize(state, id, rect18, moving) {
|
|
1340
|
+
const f = state.floats.find((x2) => x2.id === id);
|
|
1341
|
+
const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
1342
|
+
if (!f || !item || item.fixed) return null;
|
|
1343
|
+
const fo = f.orient ?? floatOrientOf(item);
|
|
1344
|
+
const form = formsOf(item, fo)[0];
|
|
1345
|
+
if (floatShape(item, f).form !== 0 || form && !form.main.grows) return null;
|
|
1346
|
+
const l = solve(state);
|
|
1347
|
+
const drawn = l.items[id]?.rect;
|
|
1348
|
+
if (!drawn) return null;
|
|
1349
|
+
const min = floatFloor(item, form, fo, drawn);
|
|
1350
|
+
const max = { width: fin(item.floatMax?.width, Infinity), height: fin(item.floatMax?.height, Infinity) };
|
|
1351
|
+
const region = floatRegion(state);
|
|
1352
|
+
const dragX = moving.left ? "start" : moving.right ? "end" : null;
|
|
1353
|
+
const dragY = moving.top ? "start" : moving.bottom ? "end" : null;
|
|
1354
|
+
const obstacles = floatObstacles(state, l, id);
|
|
1355
|
+
const hit = /* @__PURE__ */ new Set();
|
|
1356
|
+
const [x, width] = fitAxis(rect18.x, rect18.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, obstacles, "x", dragX ?? "end", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);
|
|
1357
|
+
const [y, height] = fitAxis(rect18.y, rect18.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, obstacles, "y", dragY ?? "end", [x, x + width]) }, dragY, hit);
|
|
1358
|
+
const { anchor: _a, ...plain } = f;
|
|
1359
|
+
const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, state.stage).fit.rect;
|
|
1360
|
+
if (Math.abs(placed.x - x) > EPS9 || Math.abs(placed.y - y) > EPS9) hit.add("docked");
|
|
1361
|
+
if (Math.abs(placed.width - width) > EPS9 || Math.abs(placed.height - height) > EPS9) hit.add("min");
|
|
1362
|
+
return { rect: placed, limits: LIMITS.filter((k) => hit.has(k)) };
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// src/changes.ts
|
|
1366
|
+
var withItem = (state, item) => ({ ...state, items: { ...state.items, [item.id]: item } });
|
|
1367
|
+
var itemOf = (state, id) => Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
1368
|
+
function closeRings(edges, sides) {
|
|
1369
|
+
const out = [...edges];
|
|
1370
|
+
for (const side of sides) {
|
|
1371
|
+
const idx = out.map((e, i) => ({ e, i })).filter((x) => x.e.side === side);
|
|
1372
|
+
idx.sort((a, b) => a.e.ring === b.e.ring ? a.i - b.i : a.e.ring < b.e.ring ? -1 : 1);
|
|
1373
|
+
idx.forEach((x, ring) => {
|
|
1374
|
+
if (x.e.ring !== ring) out[x.i] = { ...x.e, ring };
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
return out;
|
|
1378
|
+
}
|
|
1379
|
+
function prune(state) {
|
|
1380
|
+
const gone = state.edges.filter((e) => e.column === true && e.items.length === 0);
|
|
1381
|
+
if (gone.length === 0) return state;
|
|
1382
|
+
const sides = new Set(gone.map((e) => e.side));
|
|
1383
|
+
return { ...state, edges: closeRings(state.edges.filter((e) => !gone.includes(e)), sides) };
|
|
1384
|
+
}
|
|
1385
|
+
function mergeSideColumns(state) {
|
|
1386
|
+
let edges = [...state.edges];
|
|
1387
|
+
const sides = /* @__PURE__ */ new Set();
|
|
1388
|
+
for (const side of ["left", "right"]) {
|
|
1389
|
+
const cols = edges.filter((e) => e.side === side && isSideColumn(state, e)).sort((a, b) => a.ring - b.ring);
|
|
1390
|
+
if (cols.length < 2) continue;
|
|
1391
|
+
const [keep, ...rest] = cols;
|
|
1392
|
+
const merged = { ...keep, items: [...keep.items, ...rest.flatMap((e) => e.items)] };
|
|
1393
|
+
edges = edges.filter((e) => !rest.includes(e)).map((e) => e === keep ? merged : e);
|
|
1394
|
+
sides.add(side);
|
|
1395
|
+
}
|
|
1396
|
+
return sides.size === 0 ? state : { ...state, edges: closeRings(edges, sides) };
|
|
1397
|
+
}
|
|
1398
|
+
function liftItem(state, id) {
|
|
1399
|
+
const inEdge = state.edges.some((e) => e.items.includes(id));
|
|
1400
|
+
const inFloat = state.floats.some((f) => f.id === id);
|
|
1401
|
+
if (!inEdge && !inFloat) return state;
|
|
1402
|
+
let s = state;
|
|
1403
|
+
const from = state.edges.find((e) => e.items.includes(id));
|
|
1404
|
+
const owner = from ? roomOwner(state, from, from.items.indexOf(id)) : void 0;
|
|
1405
|
+
if (from && owner) {
|
|
1406
|
+
const length = lengthOn(state, from, id);
|
|
1407
|
+
if (length > 0) s = withSpace(s, owner, (state.items[owner].space ?? 0) + (state.items[id]?.space ?? 0) + length + nonNegative(from.gap));
|
|
1408
|
+
}
|
|
1409
|
+
return prune({
|
|
1410
|
+
...s,
|
|
1411
|
+
edges: inEdge ? s.edges.map((e) => e.items.includes(id) ? { ...e, items: e.items.filter((x) => x !== id) } : e) : s.edges,
|
|
1412
|
+
floats: inFloat ? s.floats.filter((f) => f.id !== id) : s.floats
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
function roomOwner(state, edge, k) {
|
|
1416
|
+
const id = edge.items[k];
|
|
1417
|
+
if (id === void 0) return void 0;
|
|
1418
|
+
const zone = zoneAt(state, edge, id);
|
|
1419
|
+
if (zone === "center") return void 0;
|
|
1420
|
+
const step = zone === "start" ? 1 : -1;
|
|
1421
|
+
for (let j = k + step; j >= 0 && j < edge.items.length; j += step) {
|
|
1422
|
+
const nb = edge.items[j];
|
|
1423
|
+
if (zoneAt(state, edge, nb) !== zone || state.items[nb]?.closed) continue;
|
|
1424
|
+
if ((state.items[nb]?.space ?? 0) > 0) return nb;
|
|
1425
|
+
}
|
|
1426
|
+
return void 0;
|
|
1427
|
+
}
|
|
1428
|
+
function lengthOn(state, edge, id) {
|
|
1429
|
+
const it = solve(state).items[id];
|
|
1430
|
+
if (!it || it.inMenu || it.edge !== edge.id) return 0;
|
|
1431
|
+
return axisOf(edge.side) === "column" ? it.rect.height : it.rect.width;
|
|
1432
|
+
}
|
|
1433
|
+
var nonNegative = (n) => Number.isFinite(n) && n > 0 ? n : 0;
|
|
1434
|
+
function withSpace(state, id, space) {
|
|
1435
|
+
const { space: _old, ...bare } = state.items[id];
|
|
1436
|
+
return { ...state, items: { ...state.items, [id]: space > 1e-6 ? { ...bare, space } : bare } };
|
|
1437
|
+
}
|
|
1438
|
+
function newColumn(state, side, kind, ring, items, others) {
|
|
1439
|
+
const t = state.columns?.[side];
|
|
1440
|
+
if (!t || !t.accepts.includes(kind)) return null;
|
|
1441
|
+
const taken = new Set([...state.edges, ...others].map((e) => e.id));
|
|
1442
|
+
let n = 0;
|
|
1443
|
+
while (taken.has(`${side}-${n}`)) n++;
|
|
1444
|
+
return columnFromTemplate(t, `${side}-${n}`, side, ring, items);
|
|
1445
|
+
}
|
|
1446
|
+
function sideRings(edges, side) {
|
|
1447
|
+
return new Map(closeRings(edges, /* @__PURE__ */ new Set([side])).filter((e) => e.side === side).map((e) => [e.id, e.ring]));
|
|
1448
|
+
}
|
|
1449
|
+
function columnFloor(edges, side) {
|
|
1450
|
+
const mine = edges.filter((e) => e.side === side).sort((a, b) => a.ring - b.ring);
|
|
1451
|
+
let n = 0;
|
|
1452
|
+
while (n < mine.length && mine[n].column !== true) n++;
|
|
1453
|
+
return n;
|
|
1454
|
+
}
|
|
1455
|
+
function insertColumn(state0, id, side, ring, others) {
|
|
1456
|
+
const state = { ...state0, edges: closeRings(state0.edges, /* @__PURE__ */ new Set([side])) };
|
|
1457
|
+
const kind = state.items[id].kind;
|
|
1458
|
+
const mine = state.edges.filter((e) => e.side === side);
|
|
1459
|
+
const floor = columnFloor(state.edges, side);
|
|
1460
|
+
const r = Math.max(floor, Math.min(Number.isNaN(ring) ? Infinity : Math.floor(ring), mine.length === 0 ? 0 : Math.max(...mine.map((e) => e.ring)) + 1));
|
|
1461
|
+
const col = newColumn(state, side, kind, r, [id], others);
|
|
1462
|
+
if (!col) return null;
|
|
1463
|
+
if (!zoneTakes(col, "start", kind)) return null;
|
|
1464
|
+
const shifted = state.edges.map((e) => e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e);
|
|
1465
|
+
return { ...state, edges: closeRings([...shifted, col], /* @__PURE__ */ new Set([side])) };
|
|
1466
|
+
}
|
|
1467
|
+
var zoneAt = (state, edge, id) => {
|
|
1468
|
+
const it = itemOf(state, id);
|
|
1469
|
+
return it ? zoneIn(edge, it) : "start";
|
|
1470
|
+
};
|
|
1471
|
+
function insertIndex(state, edge, zone, at) {
|
|
1472
|
+
const rank = { start: 0, center: 1, end: 2 };
|
|
1473
|
+
const inZone = edge.items.map((id, i) => ({ id, i })).filter((x) => zoneAt(state, edge, x.id) === zone);
|
|
1474
|
+
const k = Math.min(Math.max(0, Math.floor(Number.isFinite(at) ? at : inZone.length)), inZone.length);
|
|
1475
|
+
if (k < inZone.length) return inZone[k].i;
|
|
1476
|
+
if (inZone.length > 0) return inZone[inZone.length - 1].i + 1;
|
|
1477
|
+
let idx = 0;
|
|
1478
|
+
edge.items.forEach((id, i) => {
|
|
1479
|
+
if (rank[zoneAt(state, edge, id)] < rank[zone]) idx = i + 1;
|
|
1480
|
+
});
|
|
1481
|
+
return idx;
|
|
1482
|
+
}
|
|
1483
|
+
function moveTo(state, id, place) {
|
|
1484
|
+
return moveAmong(state, id, place, []);
|
|
1485
|
+
}
|
|
1486
|
+
function moveAmong(state, id, place, others) {
|
|
1487
|
+
const item = itemOf(state, id);
|
|
1488
|
+
if (!item || item.fixed) return state;
|
|
1489
|
+
if (place.kind === "float") {
|
|
1490
|
+
const out = floatAt(state, id, place.rect);
|
|
1491
|
+
const anchor = place.anchor;
|
|
1492
|
+
if (!anchor || out === state) return out;
|
|
1493
|
+
return { ...out, floats: out.floats.map((f) => f.id === id ? { ...f, anchor } : f) };
|
|
1494
|
+
}
|
|
1495
|
+
const railColumn = place.kind === "rail" ? railColumnOf(state, place.side, item.kind) : void 0;
|
|
1496
|
+
if (railColumn) {
|
|
1497
|
+
const docked = moveAmong(state, id, { edge: railColumn.id, at: Infinity }, others);
|
|
1498
|
+
return docked === state ? state : withItem(docked, { ...docked.items[id], from: Math.max(1, item.from ?? 0) });
|
|
1499
|
+
}
|
|
1500
|
+
if (place.kind === "column" || place.kind === "rail") {
|
|
1501
|
+
if (place.kind === "rail" && !state.rails?.[place.side]?.accepts.includes(item.kind)) return state;
|
|
1502
|
+
const { space: _space2, ...unspaced2 } = item;
|
|
1503
|
+
const folded = place.kind === "rail" ? { ...unspaced2, from: Math.max(1, item.from ?? 0) } : unspaced2;
|
|
1504
|
+
const made = insertColumn(withItem(liftItem(state, id), folded), id, place.side, place.ring, others);
|
|
1505
|
+
return made ?? state;
|
|
1506
|
+
}
|
|
1507
|
+
const edge = state.edges.find((e) => e.id === place.edge);
|
|
1508
|
+
if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return state;
|
|
1509
|
+
const zone = place.zone ?? zoneIn(edge, item);
|
|
1510
|
+
if (!zoneTakes(edge, zone, item.kind)) return state;
|
|
1511
|
+
const { space: _space, ...unspaced } = item;
|
|
1512
|
+
const { align: _drop, ...rest } = unspaced;
|
|
1513
|
+
const kept = Number.isFinite(place.space) && place.space > 0 ? { space: place.space } : {};
|
|
1514
|
+
const moved = { ...place.zone === void 0 || !namesZone(edge, item.kind) ? unspaced : zone === "start" ? rest : { ...rest, align: zone }, ...kept };
|
|
1515
|
+
const lifted = withItem(liftItem(state, id), moved);
|
|
1516
|
+
const target = lifted.edges.find((e) => e.id === place.edge);
|
|
1517
|
+
if (!target) return state;
|
|
1518
|
+
const k = insertIndex(lifted, target, zone, place.at);
|
|
1519
|
+
const into = { ...target, items: [...target.items.slice(0, k), id, ...target.items.slice(k)] };
|
|
1520
|
+
const placed = { ...lifted, edges: lifted.edges.map((e) => e === target ? into : e) };
|
|
1521
|
+
const owner = roomOwner(placed, into, k);
|
|
1522
|
+
if (!owner) return placed;
|
|
1523
|
+
const length = lengthOn(placed, into, id);
|
|
1524
|
+
if (length <= 0) return placed;
|
|
1525
|
+
const room = placed.items[owner].space ?? 0;
|
|
1526
|
+
return withSpace(placed, owner, room - (placed.items[id].space ?? 0) - length - nonNegative(into.gap));
|
|
1527
|
+
}
|
|
1528
|
+
function nextSince(state) {
|
|
1529
|
+
const most = state.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
|
|
1530
|
+
return Math.min(most + 1, Number.MAX_SAFE_INTEGER);
|
|
1531
|
+
}
|
|
1532
|
+
function floatAt(state, id, at, orient) {
|
|
1533
|
+
const item = itemOf(state, id);
|
|
1534
|
+
if (!item || item.fixed || !state.floatKinds.includes(item.kind)) return state;
|
|
1535
|
+
const was = state.floats.find((f) => f.id === id);
|
|
1536
|
+
const o = orient ?? was?.orient;
|
|
1537
|
+
const fo = o ?? floatOrientOf(item);
|
|
1538
|
+
const size = floatSizeOf(item, fo);
|
|
1539
|
+
const since = was ? was.since : nextSince(state);
|
|
1540
|
+
const seq = since !== void 0 ? { since } : {};
|
|
1541
|
+
const float = at ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...o ? { orient: o } : {}, ...seq } : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: "content-top-right", ...o ? { orient: o } : {}, ...seq };
|
|
1542
|
+
const { space: _space, ...unspaced } = item;
|
|
1543
|
+
const set = at && at.width > 0 && at.height > 0 ? { orient: fo, size: { width: at.width, height: at.height } } : void 0;
|
|
1544
|
+
const next = set || declaresFloatSizes(item) ? withFloatSizes(unspaced, set) : unspaced;
|
|
1545
|
+
const lifted = withItem(liftItem(state, id), next);
|
|
1546
|
+
return { ...lifted, floats: [...lifted.floats, float] };
|
|
1547
|
+
}
|
|
1548
|
+
function withFloatSizes(item, set) {
|
|
1549
|
+
const { floatSizes: _sizes, ...rest } = item;
|
|
1550
|
+
const sizes = { ...floatSizesOf(item), ...set ? { [set.orient]: set.size } : {} };
|
|
1551
|
+
return sizes.row || sizes.column ? { ...rest, floatSizes: sizes } : rest;
|
|
1552
|
+
}
|
|
1553
|
+
function canFold(state, id) {
|
|
1554
|
+
const item = itemOf(state, id);
|
|
1555
|
+
if (!item || item.fixed && !state.edges.some((e) => e.foldable === true && e.items.includes(id))) return false;
|
|
1556
|
+
const edge = placingOf(state, id).edges.find((e) => e.items.includes(id));
|
|
1557
|
+
return axesOf(state, id).some((a) => foldedIndex(item, formsOf(item, a), edge) >= 0);
|
|
1558
|
+
}
|
|
1559
|
+
function foldItem(state, id, on) {
|
|
1560
|
+
const item = itemOf(state, id);
|
|
1561
|
+
if (!item || item.fixed && !state.edges.some((e) => e.foldable === true && e.items.includes(id))) return state;
|
|
1562
|
+
if (on) return isHandFolded(state, id) || !canFold(state, id) ? state : withItem(state, { ...item, from: 1 });
|
|
1563
|
+
if (item.from === void 0) return state;
|
|
1564
|
+
const { from: _f, ...rest } = item;
|
|
1565
|
+
return withItem(state, rest);
|
|
1566
|
+
}
|
|
1567
|
+
var nextAge = (state) => Object.values(state.items).reduce((m, it) => Math.max(m, Number.isFinite(it.used) ? it.used : 0), 0) + 1;
|
|
1568
|
+
function markUsed(state, id) {
|
|
1569
|
+
const item = itemOf(state, id);
|
|
1570
|
+
if (!item) return state;
|
|
1571
|
+
const age = (it) => Number.isFinite(it.used) ? it.used : 0;
|
|
1572
|
+
if (Number.isFinite(item.used) && Object.values(state.items).every((it) => it.id === id || age(it) < item.used)) return state;
|
|
1573
|
+
return withItem(state, { ...item, used: nextAge(state) });
|
|
1574
|
+
}
|
|
1575
|
+
function keepItem(state, id, on) {
|
|
1576
|
+
const item = itemOf(state, id);
|
|
1577
|
+
if (!item || !!item.kept === on) return state;
|
|
1578
|
+
if (on) return withItem(state, { ...item, kept: true });
|
|
1579
|
+
const { kept: _k, ...rest } = item;
|
|
1580
|
+
return withItem(state, rest);
|
|
1581
|
+
}
|
|
1582
|
+
function openItem(state, id) {
|
|
1583
|
+
const item = itemOf(state, id);
|
|
1584
|
+
if (!item || !item.closed) return state;
|
|
1585
|
+
const { closed: _c, ...rest } = item;
|
|
1586
|
+
return withItem(state, rest);
|
|
1587
|
+
}
|
|
1588
|
+
function closeItem(state, id) {
|
|
1589
|
+
const item = itemOf(state, id);
|
|
1590
|
+
if (!item || item.closed || item.fixed) return state;
|
|
1591
|
+
return withItem(state, { ...item, closed: true });
|
|
1592
|
+
}
|
|
1593
|
+
function raiseFloat(state, id) {
|
|
1594
|
+
const i = state.floats.findIndex((f) => f.id === id);
|
|
1595
|
+
if (i < 0 || i === state.floats.length - 1) return state;
|
|
1596
|
+
return { ...state, floats: [...state.floats.slice(0, i), ...state.floats.slice(i + 1), state.floats[i]] };
|
|
1597
|
+
}
|
|
1598
|
+
function orientFloat(state, id, to) {
|
|
1599
|
+
const i = state.floats.findIndex((f2) => f2.id === id);
|
|
1600
|
+
const item = state.items[id];
|
|
1601
|
+
const f = state.floats[i];
|
|
1602
|
+
if (!f || !item) return state;
|
|
1603
|
+
const from = f.orient ?? floatOrientOf(item);
|
|
1604
|
+
if (from === to) return state;
|
|
1605
|
+
if (!declaresFloatSizes(item)) return { ...state, floats: state.floats.map((g, k) => k === i ? { ...g, orient: to } : g) };
|
|
1606
|
+
const grows = formsOf(item, from)[0]?.main.grows === true;
|
|
1607
|
+
const kept = withFloatSizes(item, grows && f.rect.width > 0 && f.rect.height > 0 ? { orient: from, size: { width: f.rect.width, height: f.rect.height } } : void 0);
|
|
1608
|
+
const size = drawnFloatSize(kept, { rect: { ...f.rect, ...floatSizeOf(kept, to) }, orient: to });
|
|
1609
|
+
const turned = { ...f, rect: { x: f.rect.x, y: f.rect.y, width: size.width, height: size.height }, orient: to };
|
|
1610
|
+
return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? turned : g) }, kept);
|
|
1611
|
+
}
|
|
1612
|
+
function resizeFloat(state, floatId, rect18, moving = { right: true, bottom: true }) {
|
|
1613
|
+
const fit = fitResize(state, floatId, rect18, moving);
|
|
1614
|
+
const i = state.floats.findIndex((f) => f.id === floatId);
|
|
1615
|
+
const item = itemOf(state, floatId);
|
|
1616
|
+
if (!fit || i < 0 || !item) return state;
|
|
1617
|
+
const { anchor: _a, ...plain } = state.floats[i];
|
|
1618
|
+
const float = { ...plain, rect: fit.rect };
|
|
1619
|
+
const fo = float.orient ?? floatOrientOf(item);
|
|
1620
|
+
return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? float : g) }, withFloatSizes(item, { orient: fo, size: { width: fit.rect.width, height: fit.rect.height } }));
|
|
1621
|
+
}
|
|
1622
|
+
function resizeEdge(state, edgeId, size) {
|
|
1623
|
+
const edge = state.edges.find((e) => e.id === edgeId);
|
|
1624
|
+
if (!edge) return state;
|
|
1625
|
+
if (!Number.isFinite(size)) {
|
|
1626
|
+
if (edge.size === void 0) return state;
|
|
1627
|
+
const { size: _s, ...rest } = edge;
|
|
1628
|
+
return { ...state, edges: state.edges.map((e) => e === edge ? rest : e) };
|
|
1629
|
+
}
|
|
1630
|
+
return { ...state, edges: state.edges.map((e) => e === edge ? { ...e, size } : e) };
|
|
1631
|
+
}
|
|
1632
|
+
function setRailMode(state, side, mode) {
|
|
1633
|
+
if (side !== "left" && side !== "right" || !RAIL_MODES.includes(mode) || railModeOf(state, side) === mode) return state;
|
|
1634
|
+
return { ...state, railModes: { ...state.railModes, [side]: mode } };
|
|
1635
|
+
}
|
|
1636
|
+
function setSide(state, edgeId, side) {
|
|
1637
|
+
const edge = state.edges.find((e) => e.id === edgeId);
|
|
1638
|
+
if (!edge || edge.side === side || axisOf(edge.side) !== axisOf(side)) return state;
|
|
1639
|
+
const moved = { ...edge, side, ring: 0 };
|
|
1640
|
+
const others = state.edges.filter((e) => e !== edge).map((e) => e.side === side ? { ...e, ring: e.ring + 1 } : e);
|
|
1641
|
+
return { ...state, edges: closeRings([moved, ...others], /* @__PURE__ */ new Set([edge.side, side])) };
|
|
1642
|
+
}
|
|
1643
|
+
function homeFor(state, id, start) {
|
|
1644
|
+
for (const e of start.edges) {
|
|
1645
|
+
const k = e.items.indexOf(id);
|
|
1646
|
+
if (k < 0) continue;
|
|
1647
|
+
const own = itemOf(start, id) ?? itemOf(state, id);
|
|
1648
|
+
const found = state.edges.find((x) => x.id === e.id);
|
|
1649
|
+
const here = found && (e.column !== true || found.items.some((x) => e.items.includes(x))) ? found : void 0;
|
|
1650
|
+
if (here) {
|
|
1651
|
+
const zone = own ? zoneIn(here, own) : "start";
|
|
1652
|
+
const now = here.items.filter((x) => x !== id && zoneAt(state, here, x) === zone);
|
|
1653
|
+
const next = e.items.slice(k + 1).find((x) => now.includes(x));
|
|
1654
|
+
return { kind: "gap", edge: e.id, zone, at: next ? now.indexOf(next) : now.length };
|
|
1655
|
+
}
|
|
1656
|
+
if (e.column === true && (e.side === "left" || e.side === "right")) return { kind: "column", side: e.side, ring: sideRings(start.edges, e.side).get(e.id) ?? e.ring };
|
|
1657
|
+
return null;
|
|
1658
|
+
}
|
|
1659
|
+
const f = start.floats.find((x) => x.id === id);
|
|
1660
|
+
if (f) return { kind: "float", rect: f.rect, ...f.anchor ? { anchor: f.anchor } : {} };
|
|
1661
|
+
return null;
|
|
1662
|
+
}
|
|
1663
|
+
function dockHome(state, id, start) {
|
|
1664
|
+
const place = homeFor(state, id, start);
|
|
1665
|
+
if (!place) return state;
|
|
1666
|
+
const moved = moveTo(state, id, place);
|
|
1667
|
+
const item = itemOf(moved, id);
|
|
1668
|
+
if (!item) return state;
|
|
1669
|
+
const was = itemOf(start, id);
|
|
1670
|
+
const from = was?.from;
|
|
1671
|
+
let out = item;
|
|
1672
|
+
if (was && out.align !== was.align) {
|
|
1673
|
+
const { align: _a, ...plain } = out;
|
|
1674
|
+
out = was.align === void 0 ? plain : { ...plain, align: was.align };
|
|
1675
|
+
}
|
|
1676
|
+
if (out.from !== from) {
|
|
1677
|
+
const { from: _f, ...plain } = out;
|
|
1678
|
+
out = from === void 0 ? plain : { ...plain, from };
|
|
1679
|
+
}
|
|
1680
|
+
return out === item ? moved : withItem(moved, out);
|
|
1681
|
+
}
|
|
1682
|
+
function clampFloat(r, stage, drawn = r) {
|
|
1683
|
+
const at = clampInto2({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);
|
|
1684
|
+
return { x: at.x, y: at.y, width: r.width, height: r.height };
|
|
1685
|
+
}
|
|
1686
|
+
function drawnFloatSize(item, f) {
|
|
1687
|
+
const s = floatShape(item, f);
|
|
1688
|
+
return { width: s.width, height: s.height };
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// src/store.ts
|
|
1692
|
+
import { rect as rect7 } from "@n-uf/placement";
|
|
1693
|
+
var isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
1694
|
+
var isSize = (x) => isNum(x) && x > 0;
|
|
1695
|
+
var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
1696
|
+
var isAnchor = (x) => FLOAT_ANCHORS.includes(x);
|
|
1697
|
+
function anchorOf(v, drop) {
|
|
1698
|
+
if (v === void 0) return void 0;
|
|
1699
|
+
if (isAnchor(v)) return v;
|
|
1700
|
+
if (!isObject(v) || !isAnchor(v.at)) {
|
|
1701
|
+
drop?.("");
|
|
1702
|
+
return void 0;
|
|
1703
|
+
}
|
|
1704
|
+
for (const k of Object.keys(v)) if (k !== "at" && k !== "dx" && k !== "dy") drop?.(`:${k}`);
|
|
1705
|
+
for (const k of ["dx", "dy"]) if (v[k] !== void 0 && !isNum(v[k])) drop?.(`:${k}`);
|
|
1706
|
+
return { at: v.at, ...isNum(v.dx) ? { dx: v.dx } : {}, ...isNum(v.dy) ? { dy: v.dy } : {} };
|
|
1707
|
+
}
|
|
1708
|
+
var record = () => /* @__PURE__ */ Object.create(null);
|
|
1709
|
+
function railModesOf(v, drop) {
|
|
1710
|
+
if (v === void 0) return null;
|
|
1711
|
+
if (!isObject(v)) {
|
|
1712
|
+
drop?.("railModes");
|
|
1713
|
+
return null;
|
|
1714
|
+
}
|
|
1715
|
+
const out = {};
|
|
1716
|
+
for (const k of Object.keys(v)) {
|
|
1717
|
+
const m = v[k];
|
|
1718
|
+
if ((k === "left" || k === "right") && RAIL_MODES.includes(m)) out[k] = m;
|
|
1719
|
+
else drop?.(`railModes:${k}`);
|
|
1720
|
+
}
|
|
1721
|
+
return Object.keys(out).length > 0 ? out : null;
|
|
1722
|
+
}
|
|
1723
|
+
function floatSizesStored(it) {
|
|
1724
|
+
const out = {};
|
|
1725
|
+
for (const o of ["row", "column"]) {
|
|
1726
|
+
const s = it.floatSizes?.[o];
|
|
1727
|
+
if (s && isSize(s.width) && isSize(s.height)) out[o] = { width: s.width, height: s.height };
|
|
1728
|
+
}
|
|
1729
|
+
return out.row || out.column ? out : void 0;
|
|
1730
|
+
}
|
|
1731
|
+
function storeDockState(state) {
|
|
1732
|
+
const items = record();
|
|
1733
|
+
for (const [id, it] of Object.entries(state.items)) {
|
|
1734
|
+
if (id === "__proto__") continue;
|
|
1735
|
+
const sizes = floatSizesStored(it);
|
|
1736
|
+
items[id] = {
|
|
1737
|
+
used: isNum(it.used) ? it.used : 0,
|
|
1738
|
+
...it.kept ? { kept: true } : {},
|
|
1739
|
+
...isNum(it.from) && it.from >= 1 ? { from: Math.floor(it.from) } : {},
|
|
1740
|
+
...it.closed ? { closed: true } : {},
|
|
1741
|
+
...it.align === "center" || it.align === "end" ? { align: it.align } : {},
|
|
1742
|
+
...isNum(it.space) && it.space > 0 ? { space: it.space } : {},
|
|
1743
|
+
...sizes ? { floatSizes: sizes } : {}
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
const modes = railModesOf(state.railModes);
|
|
1747
|
+
return {
|
|
1748
|
+
v: 1,
|
|
1749
|
+
edges: state.edges.map((e) => ({ id: e.id, side: e.side, ring: e.ring, items: [...e.items], ...isNum(e.size) ? { size: e.size } : {}, ...e.column === true ? { column: true } : {} })),
|
|
1750
|
+
floats: state.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) => {
|
|
1751
|
+
const anchor = anchorOf(f.anchor);
|
|
1752
|
+
return { id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...anchor ? { anchor } : {}, ...isSince(f.since) ? { since: f.since } : {} };
|
|
1753
|
+
}),
|
|
1754
|
+
items,
|
|
1755
|
+
...modes ? { railModes: modes } : {}
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
function readDockState(data, base) {
|
|
1759
|
+
checkEdgeIds(base);
|
|
1760
|
+
try {
|
|
1761
|
+
return read(data, base);
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
return { state: base, dropped: [], error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
var words = (v) => typeof v === "number" ? String(v) : typeof v === "string" ? JSON.stringify(v.length > 24 ? `${v.slice(0, 24)}\u2026` : v) : typeof v;
|
|
1767
|
+
function withFixed(baseIds, stored, isFixed) {
|
|
1768
|
+
const out = [...stored];
|
|
1769
|
+
const missing = (id) => isFixed(id) && !stored.includes(id);
|
|
1770
|
+
let tail = baseIds.length;
|
|
1771
|
+
while (tail > 0 && isFixed(baseIds[tail - 1])) tail--;
|
|
1772
|
+
baseIds.forEach((id, i) => {
|
|
1773
|
+
if (missing(id) && i < tail) out.splice(Math.min(i, out.length), 0, id);
|
|
1774
|
+
});
|
|
1775
|
+
return [...out, ...baseIds.slice(tail).filter(missing)];
|
|
1776
|
+
}
|
|
1777
|
+
function read(data, base) {
|
|
1778
|
+
if (!isObject(data)) return { state: base, dropped: [], error: "not an object" };
|
|
1779
|
+
if (data.v !== 1) return { state: base, dropped: [], error: `unknown version ${words(data.v)} (this reads version 1)` };
|
|
1780
|
+
const dropped = [];
|
|
1781
|
+
const drop = (what) => {
|
|
1782
|
+
if (!dropped.includes(what)) dropped.push(what);
|
|
1783
|
+
};
|
|
1784
|
+
for (const k of Object.keys(data)) if (!["v", "edges", "floats", "items", "railModes"].includes(k)) drop(k);
|
|
1785
|
+
const storedModes = railModesOf(data.railModes, drop);
|
|
1786
|
+
const railModes = storedModes ? { ...base.railModes, ...storedModes } : base.railModes;
|
|
1787
|
+
const known = (id) => typeof id === "string" && id !== "__proto__" && Object.hasOwn(base.items, id);
|
|
1788
|
+
const isFixed = (id) => known(id) && base.items[id].fixed === true;
|
|
1789
|
+
const items = { ...base.items };
|
|
1790
|
+
const legacy = /* @__PURE__ */ new Map();
|
|
1791
|
+
if (data.items !== void 0 && !isObject(data.items)) drop("items");
|
|
1792
|
+
else if (isObject(data.items)) {
|
|
1793
|
+
for (const id of Object.keys(data.items)) {
|
|
1794
|
+
const s = data.items[id];
|
|
1795
|
+
if (!known(id) || !isObject(s)) {
|
|
1796
|
+
drop(`item:${id}`);
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
const b = base.items[id];
|
|
1800
|
+
const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSizes: _ss, ...plain } = b;
|
|
1801
|
+
let it = { ...plain, used: b.used };
|
|
1802
|
+
for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize", "floatSizes"].includes(k)) drop(`item:${id}:${k}`);
|
|
1803
|
+
if (isNum(s.used)) it = { ...it, used: s.used };
|
|
1804
|
+
else if (s.used !== void 0) drop(`item:${id}:used`);
|
|
1805
|
+
if (s.kept === true) it = { ...it, kept: true };
|
|
1806
|
+
else if (s.kept !== void 0 && s.kept !== false) drop(`item:${id}:kept`);
|
|
1807
|
+
const byHand = !b.fixed || base.edges.some((e) => e.foldable === true && e.items.includes(id));
|
|
1808
|
+
if (isNum(s.from) && Number.isInteger(s.from) && s.from >= 1 && byHand) it = { ...it, from: s.from };
|
|
1809
|
+
else if (s.from !== void 0) drop(`item:${id}:from`);
|
|
1810
|
+
if (!byHand && b.from !== void 0) it = { ...it, from: b.from };
|
|
1811
|
+
if (s.closed === true && !b.fixed) it = { ...it, closed: true };
|
|
1812
|
+
else if (s.closed !== void 0 && s.closed !== false) drop(`item:${id}:closed`);
|
|
1813
|
+
if (s.align === "center" || s.align === "end") it = { ...it, align: s.align };
|
|
1814
|
+
else if (s.align !== void 0 && s.align !== "start") drop(`item:${id}:align`);
|
|
1815
|
+
if (b.fixed && b.align) it = { ...it, align: b.align };
|
|
1816
|
+
if (isNum(s.space) && s.space > 0 && !b.fixed) it = { ...it, space: s.space };
|
|
1817
|
+
else if (s.space !== void 0) drop(`item:${id}:space`);
|
|
1818
|
+
const fs = s.floatSize;
|
|
1819
|
+
if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) legacy.set(id, { width: fs.width, height: fs.height });
|
|
1820
|
+
else if (fs !== void 0) drop(`item:${id}:floatSize`);
|
|
1821
|
+
const sizes2 = s.floatSizes;
|
|
1822
|
+
if (isObject(sizes2)) {
|
|
1823
|
+
const own = {};
|
|
1824
|
+
for (const k of Object.keys(sizes2)) {
|
|
1825
|
+
const v = sizes2[k];
|
|
1826
|
+
if ((k === "row" || k === "column") && isObject(v) && isSize(v.width) && isSize(v.height)) own[k] = { width: v.width, height: v.height };
|
|
1827
|
+
else drop(`item:${id}:floatSizes:${k}`);
|
|
1828
|
+
}
|
|
1829
|
+
if (own.row || own.column) it = { ...it, floatSizes: own };
|
|
1830
|
+
} else if (sizes2 !== void 0) drop(`item:${id}:floatSizes`);
|
|
1831
|
+
items[id] = it;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
const placed = /* @__PURE__ */ new Set();
|
|
1835
|
+
const order = /* @__PURE__ */ new Map();
|
|
1836
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
1837
|
+
const made = [];
|
|
1838
|
+
const rings = /* @__PURE__ */ new Map();
|
|
1839
|
+
const moves = /* @__PURE__ */ new Map();
|
|
1840
|
+
const anchorMoves = /* @__PURE__ */ new Map();
|
|
1841
|
+
const anchorSizes = /* @__PURE__ */ new Map();
|
|
1842
|
+
if (data.edges !== void 0 && !Array.isArray(data.edges)) drop("edges");
|
|
1843
|
+
for (const e of Array.isArray(data.edges) ? data.edges : []) {
|
|
1844
|
+
if (!isObject(e) || typeof e.id !== "string") {
|
|
1845
|
+
drop("an edge with no id");
|
|
1846
|
+
continue;
|
|
1847
|
+
}
|
|
1848
|
+
let edge = base.edges.find((x) => x.id === e.id) ?? made.find((x) => x.id === e.id);
|
|
1849
|
+
const listed = Array.isArray(e.items) ? e.items : [];
|
|
1850
|
+
const anchorEdges = base.edges.filter((b) => b.column !== true && b.accepts.length === 0 && b.id !== edge?.id && b.items.some((id) => isFixed(id) && listed.includes(id)));
|
|
1851
|
+
for (const b of anchorEdges) {
|
|
1852
|
+
const side = SIDES.includes(e.side) ? e.side : edge?.side;
|
|
1853
|
+
if (side && side !== b.side && axisOf(side) === axisOf(b.side)) anchorMoves.set(b.id, side);
|
|
1854
|
+
if (isNum(e.size)) anchorSizes.set(b.id, e.size);
|
|
1855
|
+
}
|
|
1856
|
+
const describesAnchor = anchorEdges.length > 0;
|
|
1857
|
+
if (!edge && describesAnchor) continue;
|
|
1858
|
+
if (!edge && e.column === true && (e.side === "left" || e.side === "right") && base.columns?.[e.side] && !isReservedEdgeId(e.id)) {
|
|
1859
|
+
edge = columnFromTemplate(base.columns[e.side], e.id, e.side, isNum(e.ring) ? e.ring : Infinity, []);
|
|
1860
|
+
made.push(edge);
|
|
1861
|
+
}
|
|
1862
|
+
if (!edge || order.has(edge.id)) {
|
|
1863
|
+
drop(`edge:${e.id}`);
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);
|
|
1867
|
+
if (e.hidden !== void 0) drop(`edge:${edge.id}:hidden`);
|
|
1868
|
+
if (e.showIn !== void 0) drop(`edge:${edge.id}:showIn`);
|
|
1869
|
+
if (e.side !== void 0 && !SIDES.includes(e.side)) drop(`edge:${e.id}:side`);
|
|
1870
|
+
else if (!describesAnchor && edge.column !== true && typeof e.side === "string" && e.side !== edge.side && axisOf(e.side) === axisOf(edge.side)) moves.set(edge.id, e.side);
|
|
1871
|
+
const ids = [];
|
|
1872
|
+
for (const id of Array.isArray(e.items) ? e.items : []) {
|
|
1873
|
+
if (!known(id) || placed.has(id)) drop(`edge:${edge.id}:${String(id)}`);
|
|
1874
|
+
else if (isFixed(id)) {
|
|
1875
|
+
if (edge.items.includes(id) && base.edges.some((x) => x.id === edge.id)) {
|
|
1876
|
+
ids.push(id);
|
|
1877
|
+
placed.add(id);
|
|
1878
|
+
} else if (!anchorEdges.some((b) => b.items.includes(id))) drop(`edge:${edge.id}:${id}`);
|
|
1879
|
+
} else if (!edge.accepts.includes(items[id].kind)) drop(`edge:${edge.id}:${id}`);
|
|
1880
|
+
else {
|
|
1881
|
+
ids.push(id);
|
|
1882
|
+
placed.add(id);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
order.set(edge.id, ids);
|
|
1886
|
+
if (describesAnchor) {
|
|
1887
|
+
if (!sizes.has(edge.id)) sizes.set(edge.id, edge.size);
|
|
1888
|
+
} else if (isNum(e.size)) sizes.set(edge.id, e.size);
|
|
1889
|
+
else if (e.size !== void 0) drop(`edge:${edge.id}:size`);
|
|
1890
|
+
else sizes.set(edge.id, void 0);
|
|
1891
|
+
}
|
|
1892
|
+
for (const [id, side] of anchorMoves) moves.set(id, side);
|
|
1893
|
+
for (const [id, size] of anchorSizes) sizes.set(id, size);
|
|
1894
|
+
const floats = [];
|
|
1895
|
+
if (data.floats !== void 0 && !Array.isArray(data.floats)) drop("floats");
|
|
1896
|
+
for (const f of Array.isArray(data.floats) ? data.floats : []) {
|
|
1897
|
+
if (!isObject(f) || typeof f.id !== "string") {
|
|
1898
|
+
drop("a float with no id");
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
const id = f.id;
|
|
1902
|
+
if (!known(id) || placed.has(id) || isFixed(id) || !base.floatKinds.includes(items[id].kind) || !isNum(f.x) || !isNum(f.y) || !isSize(f.width) || !isSize(f.height)) {
|
|
1903
|
+
drop(`float:${id}`);
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
for (const k of Object.keys(f)) if (k === "pinned") drop(`pinned:${id}`);
|
|
1907
|
+
else if (!["id", "x", "y", "width", "height", "orient", "anchor", "since"].includes(k)) drop(`float:${id}:${k}`);
|
|
1908
|
+
const o = f.orient === "row" || f.orient === "column" ? f.orient : void 0;
|
|
1909
|
+
if (f.orient !== void 0 && !o) drop(`float:${id}:orient`);
|
|
1910
|
+
const a = anchorOf(f.anchor, (what) => drop(`float:${id}:anchor${what}`));
|
|
1911
|
+
const since = isSince(f.since) ? f.since : void 0;
|
|
1912
|
+
if (f.since !== void 0 && since === void 0) drop(`float:${id}:since`);
|
|
1913
|
+
placed.add(id);
|
|
1914
|
+
const r = rect7(f.x, f.y, f.width, f.height);
|
|
1915
|
+
const drawn = drawnFloatSize(items[id], { rect: r, ...o ? { orient: o } : {} });
|
|
1916
|
+
floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {}, ...since !== void 0 ? { since } : {} });
|
|
1917
|
+
}
|
|
1918
|
+
const edges = [...base.edges, ...made].map((edge) => {
|
|
1919
|
+
const stored = order.get(edge.id) ?? [];
|
|
1920
|
+
const rest = edge.items.filter((id) => !isFixed(id) && !placed.has(id));
|
|
1921
|
+
for (const id of rest) placed.add(id);
|
|
1922
|
+
let tail = stored.length;
|
|
1923
|
+
while (tail > 0 && isFixed(stored[tail - 1])) tail--;
|
|
1924
|
+
const listed = [...stored.slice(0, tail), ...rest, ...stored.slice(tail)];
|
|
1925
|
+
const items1 = withFixed(edge.items, listed, isFixed);
|
|
1926
|
+
const size = sizes.has(edge.id) ? sizes.get(edge.id) : edge.size;
|
|
1927
|
+
const { size: _s, ...plain } = edge;
|
|
1928
|
+
return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...size !== void 0 ? { size } : {} };
|
|
1929
|
+
});
|
|
1930
|
+
for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);
|
|
1931
|
+
for (const [id, size] of legacy) {
|
|
1932
|
+
const it = items[id];
|
|
1933
|
+
const float = floats.find((f) => f.id === id);
|
|
1934
|
+
if (float && !declaresFloatSizes(it)) {
|
|
1935
|
+
drop(`item:${id}:floatSize`);
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
const orient = float?.orient ?? floatOrientOf(it);
|
|
1939
|
+
if (!it.floatSizes?.[orient]) items[id] = withFloatSizes(it, { orient, size });
|
|
1940
|
+
}
|
|
1941
|
+
let state = prune({ ...base, ...railModes ? { railModes } : {}, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
|
|
1942
|
+
for (const [id, side] of moves) state = setSide(state, id, side);
|
|
1943
|
+
return { state, dropped };
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
// src/targets.ts
|
|
1947
|
+
import { EPS as EPS19, PLANE, area as area6, overlaps as overlaps6, rect as rect16 } from "@n-uf/placement";
|
|
1948
|
+
|
|
1949
|
+
// src/targets/anchor.ts
|
|
1950
|
+
import { EPS as EPS10, area, rect as rect8, subtract } from "@n-uf/placement";
|
|
1951
|
+
var OTHER = { left: "right", right: "left", top: "bottom", bottom: "top" };
|
|
1952
|
+
function anchorTargets(state, dragged, options) {
|
|
1953
|
+
const none = { targets: [], refusals: [], lost: [] };
|
|
1954
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
1955
|
+
const now = solve(state, prev);
|
|
1956
|
+
const me = now.items[dragged];
|
|
1957
|
+
const edge = me?.edge ? state.edges.find((e) => e.id === me.edge) : void 0;
|
|
1958
|
+
if (!me || !edge || edge.moves !== "side" || me.floating) return none;
|
|
1959
|
+
const homeAfter = () => ({ state, layout: now });
|
|
1960
|
+
const targets2 = [];
|
|
1961
|
+
const side = OTHER[edge.side];
|
|
1962
|
+
const moved = markUsed(setSide(state, edge.id, side), dragged);
|
|
1963
|
+
const layout = solve(moved, prev);
|
|
1964
|
+
const placed = layout.edges[edge.id]?.rect;
|
|
1965
|
+
const slot = layout.items[dragged]?.rect;
|
|
1966
|
+
if (placed && slot && area(placed) > EPS10) {
|
|
1967
|
+
const pieces = keepClearFor(state, "targets").reduce((ps, c) => ps.flatMap((p) => subtract(p, rect8(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);
|
|
1968
|
+
if (pieces.length > 0) {
|
|
1969
|
+
const hit = pieces.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1970
|
+
const result = { state: moved, layout };
|
|
1971
|
+
targets2.push({ id: targetId({ kind: "side", side }), priority: 2, hit, ...pieces.length > 1 ? { hits: pieces } : {}, slot, item: dragged, place: { kind: "side", edge: edge.id, side }, after: () => result });
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit: me.rect, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
1975
|
+
return { targets: targets2, refusals: [], lost: [] };
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
// src/targets/edges.ts
|
|
1979
|
+
import { EPS as EPS11, area as area2, rect as rect9 } from "@n-uf/placement";
|
|
1980
|
+
import { formCrossMin as formCrossMin4, formMain as formMain2, formSetsCross as formSetsCross4 } from "@n-uf/placement/stack";
|
|
1981
|
+
|
|
1982
|
+
// src/targets/kinds.ts
|
|
1983
|
+
var COLUMN_REACH = 22;
|
|
1984
|
+
var RAIL_EDGE = 10;
|
|
1985
|
+
var RAIL_REACH = 24;
|
|
1986
|
+
var MIN_HIT = { across: 12, along: 24 };
|
|
1987
|
+
var EDGE_KINDS = {
|
|
1988
|
+
bar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1989
|
+
sideBar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1990
|
+
column: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1991
|
+
barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1992
|
+
rail: { zoneExtent: "thirds", opens: "any", inward: RAIL_REACH, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 14, overreach: 34, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1993
|
+
railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1994
|
+
columnLine: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, edgePlace: DEFAULT_HIT_BAND, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true, minHit: MIN_HIT }
|
|
1995
|
+
};
|
|
1996
|
+
function edgeKindOf(state, e) {
|
|
1997
|
+
if (e.compact) return "rail";
|
|
1998
|
+
if (e.side === "top" || e.side === "bottom") return e.span === "between" ? "barBetween" : "bar";
|
|
1999
|
+
return isSideBar(state, e) ? "sideBar" : "column";
|
|
2000
|
+
}
|
|
2001
|
+
var opensEmpty = (state, edge, kind) => EDGE_KINDS[edgeKindOf(state, edge)].opens === "any" || zoneTakes(edge, "start", kind);
|
|
2002
|
+
|
|
2003
|
+
// src/targets/edges.ts
|
|
2004
|
+
function reservedRect(state, l, id) {
|
|
2005
|
+
const it = l.items[id];
|
|
2006
|
+
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
2007
|
+
const f = e ? formsOf(state.items[id], axisOf(e.side))[it.form] : void 0;
|
|
2008
|
+
if (!e || !f?.main.grows) return it.rect;
|
|
2009
|
+
const column = axisOf(e.side) === "column";
|
|
2010
|
+
const len2 = column ? it.rect.height : it.rect.width;
|
|
2011
|
+
const keep = Math.min(len2, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len2));
|
|
2012
|
+
const shift = it.zone === "end" ? len2 - keep : it.zone === "center" ? (len2 - keep) / 2 : 0;
|
|
2013
|
+
return column ? rect9(it.rect.x, it.rect.y + shift, it.rect.width, keep) : rect9(it.rect.x + shift, it.rect.y, keep, it.rect.height);
|
|
2014
|
+
}
|
|
2015
|
+
function slotAt(c, zone, line, id, place, lands, home = false) {
|
|
2016
|
+
const result = c.settle(markUsed(moveAmong(c.state, c.dragged, place, c.others), c.dragged));
|
|
2017
|
+
const isHome = home || c.isHome(result);
|
|
2018
|
+
return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout) };
|
|
2019
|
+
}
|
|
2020
|
+
function distinctSlots(c, slots) {
|
|
2021
|
+
const landing = (s) => s.result.layout.items[c.dragged]?.rect;
|
|
2022
|
+
const sameMove = (a, b) => {
|
|
2023
|
+
if (a.zone !== b.zone) return false;
|
|
2024
|
+
if (a.home && b.home) return true;
|
|
2025
|
+
const [p, q] = [landing(a), landing(b)];
|
|
2026
|
+
const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS11;
|
|
2027
|
+
return sameLine && (!p || !q ? p === q : Math.abs(p.x - q.x) + Math.abs(p.y - q.y) + Math.abs(p.width - q.width) + Math.abs(p.height - q.height) < 0.01);
|
|
2028
|
+
};
|
|
2029
|
+
const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
|
|
2030
|
+
return slots.filter((s, i) => !slots.some((o, j) => j !== i && sameMove(o, s) && wins(o, j, s, i)));
|
|
2031
|
+
}
|
|
2032
|
+
function zoneSpans(state, seen, edge, reach, probe) {
|
|
2033
|
+
const el = seen.edges[edge.id];
|
|
2034
|
+
const column = axisOf(edge.side) === "column";
|
|
2035
|
+
const main0 = column ? el.rect.y : el.rect.x;
|
|
2036
|
+
const length = column ? el.rect.height : el.rect.width;
|
|
2037
|
+
const thirds = EDGE_KINDS[edgeKindOf(state, edge)].zoneExtent === "thirds";
|
|
2038
|
+
const at = (r) => column ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
2039
|
+
const declared = new Set(edge.zoneAccepts ? ZONES.filter((z) => edge.zoneAccepts[z] !== void 0) : ["start"]);
|
|
2040
|
+
const placed = /* @__PURE__ */ new Map();
|
|
2041
|
+
for (const [id, it] of Object.entries(seen.items)) {
|
|
2042
|
+
if (it.edge !== edge.id || it.inMenu) continue;
|
|
2043
|
+
const z = it.zone ?? zoneOf(state.items[id]);
|
|
2044
|
+
const [a, b] = at(thirds && it.fixed ? reservedRect(state, seen, id) : it.rect);
|
|
2045
|
+
const was = placed.get(z);
|
|
2046
|
+
placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
|
|
2047
|
+
declared.add(z);
|
|
2048
|
+
}
|
|
2049
|
+
const lo2 = (z) => placed.get(z)?.[0] ?? Infinity;
|
|
2050
|
+
const hi = (z) => placed.get(z)?.[1] ?? -Infinity;
|
|
2051
|
+
if (edge.zones !== void 0) {
|
|
2052
|
+
const has = zonesOf(edge);
|
|
2053
|
+
let prev = main0 - reach;
|
|
2054
|
+
return has.map((zone, i) => {
|
|
2055
|
+
const last = i === has.length - 1;
|
|
2056
|
+
const mark = main0 + length * (i + 1) / has.length;
|
|
2057
|
+
const b = last ? main0 + length + reach : Math.max(prev, Math.min(Math.max(mark, ...has.slice(0, i + 1).map(hi)), ...has.slice(i + 1).map(lo2)));
|
|
2058
|
+
const span = { zone, a: prev, b };
|
|
2059
|
+
prev = b;
|
|
2060
|
+
return span;
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
if (thirds) {
|
|
2064
|
+
const nearest = state.barZones === "nearest";
|
|
2065
|
+
const landing = (z, side) => placed.has(z) ? side === "after" ? [hi(z), hi(z)] : [lo2(z), lo2(z)] : probe(z);
|
|
2066
|
+
const between = (l, r, fallback) => {
|
|
2067
|
+
const a = landing(l, "after");
|
|
2068
|
+
const b = landing(r, "before");
|
|
2069
|
+
return nearest && a && b ? (a[1] + b[0]) / 2 : fallback;
|
|
2070
|
+
};
|
|
2071
|
+
const b1 = Math.min(Math.max(between("start", "center", main0 + length / 3), hi("start")), lo2("center"), lo2("end"));
|
|
2072
|
+
const b2 = Math.max(Math.min(between("center", "end", main0 + 2 * length / 3), lo2("end")), hi("center"), hi("start"), b1);
|
|
2073
|
+
return [
|
|
2074
|
+
{ zone: "start", a: main0 - reach, b: b1 },
|
|
2075
|
+
{ zone: "center", a: b1, b: b2 },
|
|
2076
|
+
{ zone: "end", a: b2, b: main0 + length + reach }
|
|
2077
|
+
];
|
|
2078
|
+
}
|
|
2079
|
+
const anchor = { start: main0, center: main0 + length / 2, end: main0 + length };
|
|
2080
|
+
const spans = ZONES.filter((z) => declared.has(z)).map((zone) => ({ zone, s: placed.get(zone) ?? probe(zone) ?? [anchor[zone], anchor[zone]] }));
|
|
2081
|
+
return spans.map(({ zone, s }, i) => ({
|
|
2082
|
+
zone,
|
|
2083
|
+
a: i === 0 ? main0 - reach : (spans[i - 1].s[1] + s[0]) / 2,
|
|
2084
|
+
b: i === spans.length - 1 ? main0 + length + reach : (s[1] + spans[i + 1].s[0]) / 2
|
|
2085
|
+
}));
|
|
2086
|
+
}
|
|
2087
|
+
function edgeSlots(c, edge, accepts) {
|
|
2088
|
+
const { state, rest, now, base, dragged, kind } = c;
|
|
2089
|
+
const el = now.edges[edge.id];
|
|
2090
|
+
const column = axisOf(edge.side) === "column";
|
|
2091
|
+
const at = (r) => column ? r.y : r.x;
|
|
2092
|
+
const len2 = (r) => column ? r.height : r.width;
|
|
2093
|
+
const main0 = at(el.rect);
|
|
2094
|
+
const length = len2(el.rect);
|
|
2095
|
+
const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];
|
|
2096
|
+
const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
|
|
2097
|
+
const firstKind = formsOf(state.items[dragged], axisOf(edge.side))[0]?.kind;
|
|
2098
|
+
const titles = edge.items.filter((id) => base.items[id]?.edge === edge.id && base.items[id].fixed && !!formsOf(state.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows);
|
|
2099
|
+
const lands = ({ layout: after }) => {
|
|
2100
|
+
const me = after.items[dragged];
|
|
2101
|
+
if (me.edge !== edge.id || me.inMenu) return false;
|
|
2102
|
+
if (titles.length === 0) return true;
|
|
2103
|
+
if (formsOf(state.items[dragged], axisOf(edge.side))[me.form]?.kind !== firstKind) return false;
|
|
2104
|
+
return edge.items.every((id) => {
|
|
2105
|
+
const a = after.items[id];
|
|
2106
|
+
const b = base.items[id];
|
|
2107
|
+
if (!a || !b || b.edge !== edge.id || id === dragged) return true;
|
|
2108
|
+
if (!titles.includes(id)) return a.form === b.form && !!a.inMenu === !!b.inMenu;
|
|
2109
|
+
const f = formsOf(state.items[id], axisOf(edge.side))[a.form];
|
|
2110
|
+
return !f || (column ? a.rect.height : a.rect.width) >= formMain2(f, "natural", after.edges[edge.id].cross) - 0.5;
|
|
2111
|
+
});
|
|
2112
|
+
};
|
|
2113
|
+
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
2114
|
+
const menuLen = el.menu ? len2(el.menu.rect) : 0;
|
|
2115
|
+
const occupied = (id) => now.items[id]?.fixed ? reservedRect(state, now, id) : now.items[id].rect;
|
|
2116
|
+
const shown = (id) => now.items[id]?.edge === edge.id && !now.items[id].inMenu;
|
|
2117
|
+
const drawnOf2 = (z) => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
|
|
2118
|
+
const startEnd = (() => {
|
|
2119
|
+
const s = drawnOf2("start");
|
|
2120
|
+
return s.length ? at(s[s.length - 1]) + len2(s[s.length - 1]) : main0 + pad.start;
|
|
2121
|
+
})();
|
|
2122
|
+
const endStart = (() => {
|
|
2123
|
+
const e = drawnOf2("end");
|
|
2124
|
+
return e.length ? at(e[0]) : main0 + length - pad.end - menuLen;
|
|
2125
|
+
})();
|
|
2126
|
+
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 };
|
|
2127
|
+
const slots = [];
|
|
2128
|
+
const aimed = (id) => shown(id) && !now.items[id].fixed;
|
|
2129
|
+
let earlier = 0;
|
|
2130
|
+
for (const zone of ZONES) {
|
|
2131
|
+
const members = members0.filter((id) => zoneOf(rest.items[id]) === zone);
|
|
2132
|
+
const before0 = earlier;
|
|
2133
|
+
earlier += members.filter(aimed).length;
|
|
2134
|
+
if (!accepts || !zoneTakes(edge, zone, kind)) continue;
|
|
2135
|
+
const fixedHere = (id) => !!base.items[id]?.fixed && base.items[id].edge === edge.id;
|
|
2136
|
+
const fromAnchor = (zone === "start" ? members : zone === "end" ? [...members].reverse() : []).filter((id) => fixedHere(id) || shown(id));
|
|
2137
|
+
const firstMovable = fromAnchor.findIndex((id) => !fixedHere(id));
|
|
2138
|
+
const anchored2 = new Set(firstMovable < 0 ? fromAnchor : fromAnchor.slice(0, firstMovable));
|
|
2139
|
+
const pushable = (id) => fixedHere(id) && state.items[id]?.pushable === true;
|
|
2140
|
+
const isProtected = (id) => fixedHere(id) && (zone === "center" || zoneOf(rest.items[id]) !== zone || anchored2.has(id) && !pushable(id));
|
|
2141
|
+
for (let k = 0; k <= members.length; k++) {
|
|
2142
|
+
const next = members.slice(k).find(shown);
|
|
2143
|
+
const before = members.slice(0, k).reverse().find(shown);
|
|
2144
|
+
if (before && next && pushable(before) && pushable(next)) continue;
|
|
2145
|
+
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len2(occupied(before)) : anchorLine[zone];
|
|
2146
|
+
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 };
|
|
2147
|
+
const movesFixed = members0.some((id) => {
|
|
2148
|
+
const b = base.items[id];
|
|
2149
|
+
const a = s.result.layout.items[id];
|
|
2150
|
+
if (fixedHere(id) && !a) return true;
|
|
2151
|
+
return isProtected(id) && (Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5);
|
|
2152
|
+
});
|
|
2153
|
+
if (!movesFixed) slots.push(s);
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
return slots;
|
|
2157
|
+
}
|
|
2158
|
+
function thickerThan(forms, cross) {
|
|
2159
|
+
const shown = forms.filter((f) => f.kind !== "menu");
|
|
2160
|
+
return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS11);
|
|
2161
|
+
}
|
|
2162
|
+
var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
|
|
2163
|
+
function edgeSpec(c, edge) {
|
|
2164
|
+
const { state, rest, now, dragged, kind } = c;
|
|
2165
|
+
const el = now.edges[edge.id];
|
|
2166
|
+
if (!el || el.folded || el.rides || !rest.edges.some((e) => e.id === edge.id)) return null;
|
|
2167
|
+
const edgeKind = edgeKindOf(state, edge);
|
|
2168
|
+
const data = EDGE_KINDS[edgeKind];
|
|
2169
|
+
const column = axisOf(edge.side) === "column";
|
|
2170
|
+
const at = (r2) => column ? r2.y : r2.x;
|
|
2171
|
+
const len2 = (r2) => column ? r2.height : r2.width;
|
|
2172
|
+
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
2173
|
+
const accepts = edgeTakes(edge, kind);
|
|
2174
|
+
if (!accepts && (empty || area2(el.rect) <= EPS11)) return null;
|
|
2175
|
+
if (accepts && empty && !opensEmpty(state, edge, kind)) return null;
|
|
2176
|
+
const ownNow = now.items[dragged];
|
|
2177
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS11 ? ownNow.rect : null;
|
|
2178
|
+
const oneEnd = state.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
|
|
2179
|
+
const allSlots = edgeSlots(c, edge, accepts);
|
|
2180
|
+
const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
|
|
2181
|
+
const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
|
|
2182
|
+
const grows = (id) => !!formsOf(state.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
|
|
2183
|
+
const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
|
|
2184
|
+
const cards = Object.entries(now.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) > EPS11).map(([, p]) => spanOf(p.rect));
|
|
2185
|
+
const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(state, now, edge, c.reach, (zone) => {
|
|
2186
|
+
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
2187
|
+
const me = s?.result.layout.items[dragged];
|
|
2188
|
+
return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
|
|
2189
|
+
});
|
|
2190
|
+
const r = el.rect;
|
|
2191
|
+
const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
|
|
2192
|
+
const outer = edge.side === "left" ? r.x : edge.side === "right" ? r.x + r.width : edge.side === "top" ? r.y : r.y + r.height;
|
|
2193
|
+
const inward = (depth) => edge.side === "left" || edge.side === "top" ? [outer, outer + depth] : [outer - depth, outer];
|
|
2194
|
+
const thin = edgeKind === "rail" || edgeKind === "bar" || edgeKind === "barBetween";
|
|
2195
|
+
const landed = el.cross > 0 || !thin ? 0 : Math.max(0, ...slots.map((s) => s.result.layout.edges[edge.id]?.cross ?? 0));
|
|
2196
|
+
const across2 = (after) => inward((el.cross > 0 ? Math.max(el.cross, after?.edges[edge.id]?.cross ?? 0) : Math.max(strip, landed)) + data.inward);
|
|
2197
|
+
const drawn = el.cross > 0;
|
|
2198
|
+
const marker = (s) => {
|
|
2199
|
+
const slot = s.result.layout.items[dragged].rect;
|
|
2200
|
+
const e = s.result.layout.edges[edge.id];
|
|
2201
|
+
return column ? rect9(e.rect.x, slot.y, e.cross, 0) : rect9(slot.x, e.rect.y, 0, e.cross);
|
|
2202
|
+
};
|
|
2203
|
+
const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
|
|
2204
|
+
const tooThick = thickerThan(formsOf(state.items[dragged], axisOf(edge.side)), el.stack.cross);
|
|
2205
|
+
return {
|
|
2206
|
+
id: edge.id,
|
|
2207
|
+
edge,
|
|
2208
|
+
kind: edgeKind,
|
|
2209
|
+
lay: c.lay.get(edge.id),
|
|
2210
|
+
vertical: column,
|
|
2211
|
+
zones,
|
|
2212
|
+
slots,
|
|
2213
|
+
refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS11 ? "not-accepted" : null,
|
|
2214
|
+
own: ownHere,
|
|
2215
|
+
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
2216
|
+
reserved,
|
|
2217
|
+
cards,
|
|
2218
|
+
across: across2,
|
|
2219
|
+
owned: inward(drawn ? el.cross : landed > 0 ? landed : Math.min(strip, data.place)),
|
|
2220
|
+
...!drawn && landed > Math.min(strip, data.place) ? { thinOwned: inward(Math.min(strip, data.place)) } : {},
|
|
2221
|
+
ownedAlong: null,
|
|
2222
|
+
drawn,
|
|
2223
|
+
marker
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
// src/targets/filter.ts
|
|
2228
|
+
import { overlaps } from "@n-uf/placement";
|
|
2229
|
+
import { formMain as formMain3 } from "@n-uf/placement/stack";
|
|
2230
|
+
function placeKey(s, id) {
|
|
2231
|
+
const it = Object.hasOwn(s.items, id) ? s.items[id] : void 0;
|
|
2232
|
+
const byZone = (items) => ZONES.flatMap((z) => items.filter((x) => zoneOf(s.items[x]) === z));
|
|
2233
|
+
return JSON.stringify({
|
|
2234
|
+
edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? "" : e.id, byZone(e.items), e.size ?? null])).sort(),
|
|
2235
|
+
floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),
|
|
2236
|
+
folded: isHandFolded(s, id),
|
|
2237
|
+
align: it?.align ?? "start"
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
function soundness(state, base, dragged) {
|
|
2241
|
+
const chrome = keepClearFor(state, "targets");
|
|
2242
|
+
const noteKey = (n) => "edge" in n && (n.code === "overflow" || n.code === "too-wide") ? `${n.edge}:${n.code}:${"id" in n ? n.id : ""}` : null;
|
|
2243
|
+
const hadNotes = new Set(base.notes.map(noteKey).filter((k) => k !== null));
|
|
2244
|
+
return (after) => {
|
|
2245
|
+
if (after.notes.some((n) => {
|
|
2246
|
+
const k = noteKey(n);
|
|
2247
|
+
return k !== null && !hadNotes.has(k);
|
|
2248
|
+
})) return false;
|
|
2249
|
+
for (const [id, b] of Object.entries(base.items)) {
|
|
2250
|
+
if (!b.fixed) continue;
|
|
2251
|
+
const a = after.items[id];
|
|
2252
|
+
const e = a?.edge ? after.edges[a.edge] : void 0;
|
|
2253
|
+
if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;
|
|
2254
|
+
const f = formsOf(state.items[id], axisOf(e.side))[a.form];
|
|
2255
|
+
const len2 = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
|
|
2256
|
+
if (f && len2 < formMain3(f, "min", e.cross) - 0.5) return false;
|
|
2257
|
+
}
|
|
2258
|
+
const me = after.items[dragged];
|
|
2259
|
+
if (!me) return true;
|
|
2260
|
+
const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && id !== dragged).map(([id]) => reservedRect(state, after, id));
|
|
2261
|
+
return !chrome.some((c) => overlaps(me.rect, c)) && !fixedAfter.some((f) => overlaps(me.rect, f));
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
function context(state, dragged, options, others = []) {
|
|
2265
|
+
const item = Object.hasOwn(state.items, dragged) ? state.items[dragged] : void 0;
|
|
2266
|
+
if (!item || item.fixed || item.closed) return null;
|
|
2267
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
2268
|
+
const settle2 = (s) => ({ state: s, layout: solve(s, prev) });
|
|
2269
|
+
const now = solve(state, prev);
|
|
2270
|
+
const rest = liftItem(state, dragged);
|
|
2271
|
+
const base = solve(rest, prev);
|
|
2272
|
+
const here = placeKey(prune(state), dragged);
|
|
2273
|
+
const c = {
|
|
2274
|
+
state,
|
|
2275
|
+
others,
|
|
2276
|
+
rest,
|
|
2277
|
+
now,
|
|
2278
|
+
base,
|
|
2279
|
+
dragged,
|
|
2280
|
+
kind: item.kind,
|
|
2281
|
+
reach: Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0),
|
|
2282
|
+
settle: settle2,
|
|
2283
|
+
isHome: (r) => placeKey(r.state, dragged) === here,
|
|
2284
|
+
sound: soundness(state, base, dragged),
|
|
2285
|
+
lay: layKeys(state)
|
|
2286
|
+
};
|
|
2287
|
+
return { c, item, prev };
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
// src/targets/ownership.ts
|
|
2291
|
+
import { EPS as EPS14, area as area3, overlaps as overlaps2, rect as rect11, subtract as subtract2 } from "@n-uf/placement";
|
|
2292
|
+
import { formBody } from "@n-uf/placement/stack";
|
|
2293
|
+
|
|
2294
|
+
// src/targets/meet.ts
|
|
2295
|
+
import { EPS as EPS12, rect as rect10 } from "@n-uf/placement";
|
|
2296
|
+
function meet(a, b) {
|
|
2297
|
+
const x = Math.max(a.x, b.x);
|
|
2298
|
+
const y = Math.max(a.y, b.y);
|
|
2299
|
+
const w = Math.min(a.x + a.width, b.x + b.width) - x;
|
|
2300
|
+
const h = Math.min(a.y + a.height, b.y + b.height) - y;
|
|
2301
|
+
return w > EPS12 && h > EPS12 ? rect10(x, y, w, h) : null;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/targets/model.ts
|
|
2305
|
+
import { EPS as EPS13 } from "@n-uf/placement";
|
|
2306
|
+
var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u > EPS13)), [...spans]);
|
|
2307
|
+
|
|
2308
|
+
// src/targets/ownership.ts
|
|
2309
|
+
var isBody = (f) => !!f && formBody(f);
|
|
2310
|
+
var bandOf = (s) => {
|
|
2311
|
+
const a = Math.min(...s.zones.map((z) => z.a));
|
|
2312
|
+
const b = Math.max(...s.zones.map((z) => z.b));
|
|
2313
|
+
return s.vertical ? rect11(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect11(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);
|
|
2314
|
+
};
|
|
2315
|
+
var ownedRectOf = (s) => {
|
|
2316
|
+
const b = bandOf(s);
|
|
2317
|
+
if (!s.ownedAlong) return b;
|
|
2318
|
+
const [a0, a1] = s.ownedAlong;
|
|
2319
|
+
return s.vertical ? rect11(b.x, a0, b.width, a1 - a0) : rect11(a0, b.y, a1 - a0, b.height);
|
|
2320
|
+
};
|
|
2321
|
+
function ownedRectsOf(s, along2) {
|
|
2322
|
+
if (along2.length === 0) return [];
|
|
2323
|
+
const o = ownedRectOf(s);
|
|
2324
|
+
if (s.ownedAlong) return [o];
|
|
2325
|
+
return along2.map(([a, b]) => s.vertical ? rect11(o.x, a, o.width, b - a) : rect11(a, o.y, b - a, o.height));
|
|
2326
|
+
}
|
|
2327
|
+
function drawnOf(c, live) {
|
|
2328
|
+
return Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS14 && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
|
|
2329
|
+
}
|
|
2330
|
+
function homeRectOf(c, ownSpec) {
|
|
2331
|
+
const own = c.now.items[c.dragged];
|
|
2332
|
+
if (!own || own.floating || !own.edge) return null;
|
|
2333
|
+
const o = own.rect;
|
|
2334
|
+
const hull3 = (a, b) => rect11(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.x + a.width, b.x + b.width) - Math.min(a.x, b.x), Math.max(a.y + a.height, b.y + b.height) - Math.min(a.y, b.y));
|
|
2335
|
+
if (own.inMenu) return o;
|
|
2336
|
+
if (!ownSpec) {
|
|
2337
|
+
const e = c.now.edges[own.edge];
|
|
2338
|
+
const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
|
|
2339
|
+
return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS14 ? hull3(o, e.rect) : o;
|
|
2340
|
+
}
|
|
2341
|
+
const [c0, c1] = ownSpec.across();
|
|
2342
|
+
return ownSpec.vertical ? hull3(o, rect11(c0, o.y, c1 - c0, o.height)) : hull3(o, rect11(o.x, c0, o.width, c1 - c0));
|
|
2343
|
+
}
|
|
2344
|
+
function ownersOf(c, live, drawn, alongOf) {
|
|
2345
|
+
const ownEdge = c.now.items[c.dragged]?.edge;
|
|
2346
|
+
const ownSpec = ownEdge && live.find((s) => s.edge?.id === ownEdge) || null;
|
|
2347
|
+
const homeRect = homeRectOf(c, ownSpec);
|
|
2348
|
+
return [
|
|
2349
|
+
// Home first: its tile is its own, for every edge but its own (which tiles it as its own interval).
|
|
2350
|
+
...homeRect ? [{ spec: ownSpec, rect: homeRect, lay: { phase: -1, side: "", at: -Infinity }, place: false }] : [],
|
|
2351
|
+
// Every edge the tiler reads, along each zone with a slot the filter keeps: what it owns, drawn or a band of its
|
|
2352
|
+
// place (a column line's band about its line). A zone whose every slot is refused owns nothing against the others
|
|
2353
|
+
// (its drawn rect still counts, below).
|
|
2354
|
+
...live.flatMap((s) => {
|
|
2355
|
+
const rects = ownedRectsOf(s, alongOf(s));
|
|
2356
|
+
if (!s.thinOwned) return rects.map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }));
|
|
2357
|
+
const thin = (r) => s.vertical ? rect11(Math.max(r.x, s.thinOwned[0]), r.y, Math.min(r.x + r.width, s.thinOwned[1]) - Math.max(r.x, s.thinOwned[0]), r.height) : rect11(r.x, Math.max(r.y, s.thinOwned[0]), r.width, Math.min(r.y + r.height, s.thinOwned[1]) - Math.max(r.y, s.thinOwned[0]));
|
|
2358
|
+
return rects.flatMap((r) => [{ spec: s, rect: thin(r), lay: s.lay, place: true }, ...subtract2(r, thin(r)).map((d) => ({ spec: s, rect: d, lay: s.lay, place: true, deep: true }))]);
|
|
2359
|
+
}).filter((o) => area3(o.rect) > EPS14),
|
|
2360
|
+
// Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
|
|
2361
|
+
...drawn.map((d) => ({ ...d, place: false }))
|
|
2362
|
+
];
|
|
2363
|
+
}
|
|
2364
|
+
function ownership(c, live, alongOf) {
|
|
2365
|
+
const { state, now, dragged } = c;
|
|
2366
|
+
const drawn = drawnOf(c, live);
|
|
2367
|
+
const owners = ownersOf(c, live, drawn, alongOf);
|
|
2368
|
+
const wins = (o, s) => {
|
|
2369
|
+
if (o.spec === s) return false;
|
|
2370
|
+
if (pushes(o.lay, s.lay)) return true;
|
|
2371
|
+
if (pushes(s.lay, o.lay)) return false;
|
|
2372
|
+
const place = !s.drawn;
|
|
2373
|
+
return o.place === place ? !place || o.lay.at < s.lay.at : !o.place;
|
|
2374
|
+
};
|
|
2375
|
+
const takingRects = (s) => s.drawn ? s.zones.filter((z) => s.slots.some((sl) => sl.ok && sl.zone === z.zone)).map((z) => s.vertical ? rect11(s.owned[0], z.a, s.owned[1] - s.owned[0], z.b - z.a) : rect11(z.a, s.owned[0], z.b - z.a, s.owned[1] - s.owned[0])) : [];
|
|
2376
|
+
const thinRectOf = (s) => {
|
|
2377
|
+
const b = bandOf(s);
|
|
2378
|
+
const [t0, t1] = s.thinOwned;
|
|
2379
|
+
return s.vertical ? rect11(t0, b.y, t1 - t0, b.height) : rect11(b.x, t0, b.width, t1 - t0);
|
|
2380
|
+
};
|
|
2381
|
+
const endsOf = (s) => {
|
|
2382
|
+
const e = s.edge ? now.edges[s.id] : void 0;
|
|
2383
|
+
if (!e || EDGE_KINDS[s.kind].virtual) return null;
|
|
2384
|
+
const span = s.vertical ? [e.rect.y, e.rect.y + e.rect.height] : [e.rect.x, e.rect.x + e.rect.width];
|
|
2385
|
+
return span[1] - span[0] > EPS14 ? span : null;
|
|
2386
|
+
};
|
|
2387
|
+
const pastEnds = (s, r) => {
|
|
2388
|
+
const ends = endsOf(s);
|
|
2389
|
+
if (!ends) return [];
|
|
2390
|
+
const [lo2, hi] = s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
2391
|
+
return less([[lo2, hi]], [ends]).map(([u, w]) => s.vertical ? rect11(r.x, u, r.width, w - u) : rect11(u, r.y, w - u, r.height));
|
|
2392
|
+
};
|
|
2393
|
+
const ownSpanOf = (s) => {
|
|
2394
|
+
const ends = endsOf(s);
|
|
2395
|
+
if (!ends) return null;
|
|
2396
|
+
const [o0, o1] = s.owned;
|
|
2397
|
+
return s.vertical ? rect11(o0, ends[0], o1 - o0, ends[1] - ends[0]) : rect11(ends[0], o0, ends[1] - ends[0], o1 - o0);
|
|
2398
|
+
};
|
|
2399
|
+
const reachLess = (o, r, s) => {
|
|
2400
|
+
const span = ownSpanOf(s);
|
|
2401
|
+
if (!o.spec || !span) return [r];
|
|
2402
|
+
return pastEnds(o.spec, r).flatMap((p) => meet(p, span) ?? []).reduce((acc, cut2) => acc.flatMap((q) => subtract2(q, cut2)), [r]);
|
|
2403
|
+
};
|
|
2404
|
+
const reachYields = (s) => {
|
|
2405
|
+
const past = pastEnds(s, bandOf(s));
|
|
2406
|
+
if (past.length === 0) return [];
|
|
2407
|
+
return live.filter((d) => d !== s).flatMap((d) => {
|
|
2408
|
+
const span = ownSpanOf(d);
|
|
2409
|
+
return span ? ownedRectsOf(d, alongOf(d)).flatMap((r) => meet(r, span) ?? []) : [];
|
|
2410
|
+
}).flatMap((q) => past.flatMap((p) => meet(p, q) ?? []));
|
|
2411
|
+
};
|
|
2412
|
+
const taken = new Map(
|
|
2413
|
+
live.map((s) => [
|
|
2414
|
+
s,
|
|
2415
|
+
[
|
|
2416
|
+
...owners.filter((o) => wins(o, s)).flatMap((o) => (o.deep ? takingRects(s).reduce((acc, t) => acc.flatMap((r) => subtract2(r, t)), [o.rect]) : [o.rect]).flatMap((r) => reachLess(o, r, s))),
|
|
2417
|
+
...EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.spec !== s && !wins(o, s)).flatMap((o) => subtract2(o.rect, ownedRectOf(s))) : [],
|
|
2418
|
+
...s.thinOwned ? live.filter((d) => d !== s).flatMap((d) => takingRects(d).flatMap((t) => subtract2(t, thinRectOf(s)))) : [],
|
|
2419
|
+
...reachYields(s)
|
|
2420
|
+
]
|
|
2421
|
+
])
|
|
2422
|
+
);
|
|
2423
|
+
const halfBandOf = (e) => {
|
|
2424
|
+
const bandOpt = hitBandOf(state, e);
|
|
2425
|
+
return bandOpt === "middle" ? null : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND) / 2;
|
|
2426
|
+
};
|
|
2427
|
+
const bodySpans = (e) => {
|
|
2428
|
+
const half = e ? halfBandOf(e) : null;
|
|
2429
|
+
if (!e || half === null) return [];
|
|
2430
|
+
const column = axisOf(e.side) === "column";
|
|
2431
|
+
return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && iid !== dragged && isBody(formsOf(state.items[iid], axisOf(e.side))[p.form])).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS14);
|
|
2432
|
+
};
|
|
2433
|
+
const rooms = /* @__PURE__ */ new Map();
|
|
2434
|
+
const cutsOf = (s) => {
|
|
2435
|
+
let room = rooms.get(s);
|
|
2436
|
+
if (!room) rooms.set(s, room = roomOf2(s));
|
|
2437
|
+
return room;
|
|
2438
|
+
};
|
|
2439
|
+
const roomOf2 = (s) => {
|
|
2440
|
+
const b = bandOf(s);
|
|
2441
|
+
const along2 = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
2442
|
+
const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
2443
|
+
const rs = taken.get(s).filter((r) => overlaps2(r, b));
|
|
2444
|
+
const ends = [.../* @__PURE__ */ new Set([...along2(b), ...rs.flatMap(along2)])].filter((x) => x >= along2(b)[0] && x <= along2(b)[1]).sort((p, q) => p - q);
|
|
2445
|
+
const owned = [];
|
|
2446
|
+
for (let k = 1; k < ends.length; k++) {
|
|
2447
|
+
const [u, w] = [ends[k - 1], ends[k]];
|
|
2448
|
+
const over = rs.filter((r) => along2(r)[0] <= u + EPS14 && along2(r)[1] >= w - EPS14).map(across2);
|
|
2449
|
+
if (w - u > EPS14 && less([across2(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
2450
|
+
}
|
|
2451
|
+
const half = s.edge ? halfBandOf(s.edge) : null;
|
|
2452
|
+
const raw = bodySpans(s.edge);
|
|
2453
|
+
if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
|
|
2454
|
+
const merged = owned.reduce((m, [u, w]) => {
|
|
2455
|
+
const last = m[m.length - 1];
|
|
2456
|
+
if (last && u <= last[1] + EPS14) last[1] = Math.max(last[1], w);
|
|
2457
|
+
else m.push([u, w]);
|
|
2458
|
+
return m;
|
|
2459
|
+
}, []);
|
|
2460
|
+
const [lo2, hi] = endsOf(s) ?? along2(b);
|
|
2461
|
+
const placed = (p) => {
|
|
2462
|
+
const cut2 = merged.find(([u, w]) => p >= u - EPS14 && p <= w + EPS14);
|
|
2463
|
+
if (!cut2) return p;
|
|
2464
|
+
const sides = [...cut2[0] > lo2 + EPS14 ? [cut2[0]] : [], ...cut2[1] < hi - EPS14 ? [cut2[1]] : []];
|
|
2465
|
+
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
2466
|
+
};
|
|
2467
|
+
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
2468
|
+
return { cuts: owned, bodies: less(raw, bands) };
|
|
2469
|
+
};
|
|
2470
|
+
const grows = (id) => {
|
|
2471
|
+
const it = now.items[id];
|
|
2472
|
+
const e = it.edge ? now.edges[it.edge] : void 0;
|
|
2473
|
+
return !!e && !!formsOf(state.items[id], axisOf(e.side))[it.form]?.main.grows;
|
|
2474
|
+
};
|
|
2475
|
+
const solid = Object.entries(now.items).filter(([id, it]) => it.fixed && !grows(id)).map(([, it]) => it.rect);
|
|
2476
|
+
const bodies = (s) => {
|
|
2477
|
+
const e = s.edge;
|
|
2478
|
+
if (!e) return [];
|
|
2479
|
+
const column = axisOf(e.side) === "column";
|
|
2480
|
+
const across2 = (a, b) => column ? rect11(-1e9, a, 2e9, b - a) : rect11(a, -1e9, b - a, 2e9);
|
|
2481
|
+
const reserved = Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid)).map(([, p]) => column ? across2(p.rect.y, p.rect.y + p.rect.height) : across2(p.rect.x, p.rect.x + p.rect.width));
|
|
2482
|
+
return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS14);
|
|
2483
|
+
};
|
|
2484
|
+
const drawnBySpec = /* @__PURE__ */ new Map();
|
|
2485
|
+
const drawnBesides = (s) => {
|
|
2486
|
+
let rs = drawnBySpec.get(s);
|
|
2487
|
+
if (!rs) drawnBySpec.set(s, rs = drawn.filter((d) => d.spec !== s).map((d) => d.rect));
|
|
2488
|
+
return rs;
|
|
2489
|
+
};
|
|
2490
|
+
return { owners, taken, cutsOf, bodies, solid, drawnBesides };
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
// src/targets/tiles.ts
|
|
2494
|
+
import { EPS as EPS15, area as area4, overlaps as overlaps3, rect as rect12, subtract as subtract3 } from "@n-uf/placement";
|
|
2495
|
+
function tilerOf(spec) {
|
|
2496
|
+
const data = EDGE_KINDS[spec.kind];
|
|
2497
|
+
const v = spec.vertical;
|
|
2498
|
+
const band = (a, b, after) => {
|
|
2499
|
+
const [c0, c1] = spec.across(after);
|
|
2500
|
+
return v ? rect12(c0, a, c1 - c0, b - a) : rect12(a, c0, b - a, c1 - c0);
|
|
2501
|
+
};
|
|
2502
|
+
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
2503
|
+
const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
2504
|
+
const split = (t) => {
|
|
2505
|
+
const h = t.hit;
|
|
2506
|
+
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
2507
|
+
const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
|
|
2508
|
+
const part = (a, b) => v ? rect12(a, h.y, b - a, h.height) : rect12(h.x, a, h.width, b - a);
|
|
2509
|
+
const beyond = less([[h0, h1]], [spec.owned]);
|
|
2510
|
+
if (beyond.length === 0) return [t];
|
|
2511
|
+
if (c1 - c0 <= EPS15) return [{ ...t, order: data.overreach }];
|
|
2512
|
+
const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
|
|
2513
|
+
return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
|
|
2514
|
+
};
|
|
2515
|
+
return { band, keepAt, tile, split };
|
|
2516
|
+
}
|
|
2517
|
+
function wholeRefusal(c, spec) {
|
|
2518
|
+
if (!spec.edge || spec.own || spec.holds || ZONES.some((z) => spec.refuse(z) !== "not-accepted")) return null;
|
|
2519
|
+
const drawn = c.now.edges[spec.id]?.rect;
|
|
2520
|
+
const hit = drawn ? meet(drawn, c.state.stage) : null;
|
|
2521
|
+
if (!hit) return null;
|
|
2522
|
+
const data = EDGE_KINDS[spec.kind];
|
|
2523
|
+
return { edge: spec.id, spec, edgeKind: spec.kind, vertical: spec.vertical, zone: "start", hit, kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason: "not-accepted", whole: true };
|
|
2524
|
+
}
|
|
2525
|
+
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS15);
|
|
2526
|
+
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
2527
|
+
const reserved = spec.reserved;
|
|
2528
|
+
const lines = mine.map((s) => s.line);
|
|
2529
|
+
const lo2 = Math.min(z.a, ...lines);
|
|
2530
|
+
const hi = Math.max(z.b, ...lines);
|
|
2531
|
+
const free = less([[z.a, z.b]], reserved);
|
|
2532
|
+
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
2533
|
+
const spread = (x) => {
|
|
2534
|
+
if (hi - lo2 <= EPS15 || freeLen <= EPS15) return x;
|
|
2535
|
+
let d = (x - lo2) / (hi - lo2) * freeLen;
|
|
2536
|
+
for (const [a, b] of free) {
|
|
2537
|
+
if (d <= b - a + EPS15) return a + Math.min(d, b - a);
|
|
2538
|
+
d -= b - a;
|
|
2539
|
+
}
|
|
2540
|
+
return free[free.length - 1][1];
|
|
2541
|
+
};
|
|
2542
|
+
const past = lines.some((x) => x < z.a - EPS15 || x > z.b + EPS15);
|
|
2543
|
+
const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
|
|
2544
|
+
const proj = (x) => {
|
|
2545
|
+
const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
|
|
2546
|
+
const p = own ? nearer(q, own) : q;
|
|
2547
|
+
if (pieces.some(([a, b]) => p >= a - EPS15 && p <= b + EPS15)) return p;
|
|
2548
|
+
return pieces.map(([a, b]) => Math.min(Math.max(p, a), b)).reduce((m, y) => Math.abs(y - p) < Math.abs(m - p) ? y : m);
|
|
2549
|
+
};
|
|
2550
|
+
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS15 || Math.abs(s.line - own[1]) < EPS15);
|
|
2551
|
+
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS15 && s.line <= pb + EPS15 : proj(s.line) >= pa - EPS15 && proj(s.line) <= pb + EPS15).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
|
|
2552
|
+
const projected = inPiece.map((s) => proj(s.line));
|
|
2553
|
+
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS15) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
|
|
2554
|
+
return { inPiece, at };
|
|
2555
|
+
}
|
|
2556
|
+
function reachStrips(c, spec, room, ends) {
|
|
2557
|
+
const inEdge = (s) => !!ends && s[0] < ends[1] - EPS15 && s[1] > ends[0] + EPS15;
|
|
2558
|
+
const pieces = room.filter(inEdge);
|
|
2559
|
+
if (!ends || pieces.length === 0) return { pieces: [...room], before: [], after: [] };
|
|
2560
|
+
const [c0, c1] = spec.across();
|
|
2561
|
+
const bandOf2 = (a, b) => spec.vertical ? rect12(c0, a, c1 - c0, b - a) : rect12(a, c0, b - a, c1 - c0);
|
|
2562
|
+
const across2 = c.state.edges.filter((e) => axisOf(e.side) === "column" !== spec.vertical).map((e) => c.now.edges[e.id]);
|
|
2563
|
+
const drawnBetween = (a, b) => b - a > EPS15 && across2.some((e) => !!e && e.cross > EPS15 && area4(e.rect) > EPS15 && overlaps3(e.rect, bandOf2(a, b)));
|
|
2564
|
+
const first = pieces[0][0];
|
|
2565
|
+
const last = pieces[pieces.length - 1][1];
|
|
2566
|
+
return {
|
|
2567
|
+
pieces,
|
|
2568
|
+
before: room.filter((s) => s[1] <= ends[0] + EPS15 && !drawnBetween(s[1], first)),
|
|
2569
|
+
after: room.filter((s) => s[0] >= ends[1] - EPS15 && !drawnBetween(last, s[0]))
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
2573
|
+
const whole = wholeRefusal(c, spec);
|
|
2574
|
+
if (whole) return [whole];
|
|
2575
|
+
const data = EDGE_KINDS[spec.kind];
|
|
2576
|
+
const v = spec.vertical;
|
|
2577
|
+
const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
|
|
2578
|
+
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
2579
|
+
const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
|
|
2580
|
+
const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS15 ? v ? rect12(-1e9, drawn.y, 2e9, drawn.height) : rect12(drawn.x, -1e9, drawn.width, 2e9) : null;
|
|
2581
|
+
const refused = (zone, hit, reason) => {
|
|
2582
|
+
const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
|
|
2583
|
+
const shown = inEdge && meet(inEdge, c.state.stage);
|
|
2584
|
+
return shown ? split(tile(zone, shown, { kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason })) : [];
|
|
2585
|
+
};
|
|
2586
|
+
const slots = distinctSlots(c, spec.slots);
|
|
2587
|
+
const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
|
|
2588
|
+
const last = acc[acc.length - 1];
|
|
2589
|
+
if (last && a <= last[1] + EPS15) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
|
|
2590
|
+
else acc.push([a, b]);
|
|
2591
|
+
return acc;
|
|
2592
|
+
}, []);
|
|
2593
|
+
const wedged = (line) => runs.some(([a, b]) => line > a + EPS15 && line < b - EPS15);
|
|
2594
|
+
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
2595
|
+
const ends = alongLimit && drawn ? v ? [drawn.y, drawn.y + drawn.height] : [drawn.x, drawn.x + drawn.width] : null;
|
|
2596
|
+
const out = [];
|
|
2597
|
+
for (const z of spec.zones) {
|
|
2598
|
+
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS15);
|
|
2599
|
+
const { pieces, before, after } = reachStrips(c, spec, own ? less(room, [own]) : room, ends);
|
|
2600
|
+
if (!hasRoom(pieces, bodies)) continue;
|
|
2601
|
+
const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
|
|
2602
|
+
const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS15 && a < s.line + data.reach - EPS15));
|
|
2603
|
+
const reason = spec.refuse(z.zone);
|
|
2604
|
+
for (const [k, [pa, pb]] of pieces.entries()) {
|
|
2605
|
+
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
2606
|
+
const stripsOf = (i) => [...k === 0 && i === 0 ? before : [], ...k === pieces.length - 1 && i === inPiece.length - 1 ? after : []];
|
|
2607
|
+
if (inPiece.length === 0) {
|
|
2608
|
+
const lone = (reason === "no-room" || reason === "too-thick") && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
|
|
2609
|
+
const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS15 && pa < s.line + data.reach - EPS15);
|
|
2610
|
+
const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
|
|
2611
|
+
if (joins.length > 0) {
|
|
2612
|
+
const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
|
|
2613
|
+
const hit = band(pa, pb, s.result.layout);
|
|
2614
|
+
out.push(...split(tile(z.zone, hit, { kind: "slot", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(Math.min(Math.max(s.line, pa), pb), hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged].rect })));
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
2617
|
+
if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? "own-place" : reason));
|
|
2618
|
+
continue;
|
|
2619
|
+
}
|
|
2620
|
+
const meet2 = (i) => {
|
|
2621
|
+
const [lo2, hi] = [at[i - 1], at[i]];
|
|
2622
|
+
const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS15 && w <= inPiece[i].line + EPS15);
|
|
2623
|
+
const mid2 = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
|
|
2624
|
+
return mid2 > lo2 + EPS15 && mid2 < hi - EPS15 ? mid2 : (lo2 + hi) / 2;
|
|
2625
|
+
};
|
|
2626
|
+
inPiece.forEach((s, i) => {
|
|
2627
|
+
const p = at[i];
|
|
2628
|
+
const lim = data.virtual ? Infinity : data.reach;
|
|
2629
|
+
const a = Math.max(i === 0 ? pa : meet2(i), p - lim);
|
|
2630
|
+
const b = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
|
|
2631
|
+
if (b - a <= EPS15) {
|
|
2632
|
+
if (s.ok && !s.home) lost.push(s.id);
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
if (!hasRoom([[a, b]], bodies)) return;
|
|
2636
|
+
const homeTile = (id, u, w, line) => {
|
|
2637
|
+
const hit = band(u, w, s.home ? s.result.layout : void 0);
|
|
2638
|
+
return tile(z.zone, hit, { kind: "home", id, order: data.layer, priority: data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: "home" } });
|
|
2639
|
+
};
|
|
2640
|
+
if (s.home) {
|
|
2641
|
+
for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.id, u, w, p)));
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2644
|
+
const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS15 && u < b - EPS15) : [];
|
|
2645
|
+
for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
|
|
2646
|
+
for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
|
|
2647
|
+
const line = Math.min(Math.max(p, u), w);
|
|
2648
|
+
const hit = band(u, w, s.result.layout);
|
|
2649
|
+
if (!s.ok) out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
|
|
2650
|
+
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 })));
|
|
2651
|
+
}
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
if (own && spec.own) {
|
|
2656
|
+
const home = spec.slots.find((s) => s.home);
|
|
2657
|
+
const [a, b] = own;
|
|
2658
|
+
const h = band(a, b);
|
|
2659
|
+
const o = spec.own;
|
|
2660
|
+
const hit = v ? rect12(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect12(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));
|
|
2661
|
+
out.push(tile(home?.zone ?? zoneOf(c.state.items[c.dragged]), hit, { kind: "home", id: home ? home.id : targetId({ kind: "home", item: c.dragged }), order: 0, priority: home ? data.priority : 1, keep: null, place: { kind: "home" } }));
|
|
2662
|
+
}
|
|
2663
|
+
return out;
|
|
2664
|
+
}
|
|
2665
|
+
var clip = (r, cuts) => cuts.reduce((ps, cut2) => ps.flatMap((p) => subtract3(p, cut2)), [r]);
|
|
2666
|
+
var coverOf = (t) => t.hits ?? [t.hit];
|
|
2667
|
+
var largest = (ps) => ps.reduce((a, p) => area4(p) > area4(a) ? p : a);
|
|
2668
|
+
var withPieces = (t, ps) => {
|
|
2669
|
+
const { hits: _h, ...rest } = t;
|
|
2670
|
+
return { ...rest, hit: largest(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
2671
|
+
};
|
|
2672
|
+
function placeReach(t, pieces, placed, landed, gone) {
|
|
2673
|
+
const of = t.of;
|
|
2674
|
+
const at = landed.get(of) ?? [];
|
|
2675
|
+
if (at.length === 0 && gone.has(of)) {
|
|
2676
|
+
const line = t.vertical ? of.keep.y : of.keep.x;
|
|
2677
|
+
const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
2678
|
+
const on = whole.filter((p) => t.vertical ? p.y <= line + EPS15 && line <= p.y + p.height + EPS15 : p.x <= line + EPS15 && line <= p.x + p.width + EPS15);
|
|
2679
|
+
const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area4(p) > area4(a) ? p : a, null);
|
|
2680
|
+
if (kept) {
|
|
2681
|
+
placed.push({ ...of, hit: kept });
|
|
2682
|
+
gone.delete(of);
|
|
2683
|
+
}
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
for (const i of at) {
|
|
2687
|
+
const cover = coverOf(placed[i]);
|
|
2688
|
+
for (let k = 0; k < cover.length; k++) {
|
|
2689
|
+
const h = cover[k];
|
|
2690
|
+
const joint = pieces.find(
|
|
2691
|
+
(p) => t.vertical ? p.y <= h.y + EPS15 && p.y + p.height >= h.y + h.height - EPS15 && (Math.abs(p.x - h.x - h.width) < EPS15 || Math.abs(p.x + p.width - h.x) < EPS15) : p.x <= h.x + EPS15 && p.x + p.width >= h.x + h.width - EPS15 && (Math.abs(p.y - h.y - h.height) < EPS15 || Math.abs(p.y + p.height - h.y) < EPS15)
|
|
2692
|
+
);
|
|
2693
|
+
if (!joint) continue;
|
|
2694
|
+
const merged = t.vertical ? rect12(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height) : rect12(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));
|
|
2695
|
+
placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
var isRefused = (t) => t.kind === "refuse" || t.kind === "reach" && t.of.kind === "refuse";
|
|
2701
|
+
function clipTiles(tiles, own, chrome, lost) {
|
|
2702
|
+
const { owners, taken, bodies, solid } = own;
|
|
2703
|
+
const bySpec = /* @__PURE__ */ new Map();
|
|
2704
|
+
const others = (t) => {
|
|
2705
|
+
let rs = bySpec.get(t.spec);
|
|
2706
|
+
if (!rs) bySpec.set(t.spec, rs = owners.filter((o) => o.spec !== t.spec).map((o) => o.rect));
|
|
2707
|
+
return rs;
|
|
2708
|
+
};
|
|
2709
|
+
const besides = (t) => t.spec ? own.drawnBesides(t.spec) : [];
|
|
2710
|
+
const bodiesOf = (t) => t.spec ? bodies(t.spec) : [];
|
|
2711
|
+
const placed = [];
|
|
2712
|
+
const later = [];
|
|
2713
|
+
const refused = tiles.filter(isRefused);
|
|
2714
|
+
const landed = /* @__PURE__ */ new Map();
|
|
2715
|
+
const gone = /* @__PURE__ */ new Set();
|
|
2716
|
+
const place = (t) => {
|
|
2717
|
+
if (t.order === 0) {
|
|
2718
|
+
placed.push(t);
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
if (t.whole) {
|
|
2722
|
+
const pieces2 = clip(t.hit, placed.flatMap(coverOf)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
2723
|
+
if (pieces2.length > 0) placed.push(withPieces(t, pieces2));
|
|
2724
|
+
return;
|
|
2725
|
+
}
|
|
2726
|
+
const data = EDGE_KINDS[t.edgeKind];
|
|
2727
|
+
if (data.virtual && t.kind === "refuse") {
|
|
2728
|
+
later.push(t);
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
if (t.kind === "reach") {
|
|
2732
|
+
placeReach(t, clip(t.hit, [...placed.flatMap(coverOf), ...others(t), ...bodiesOf(t), ...solid, ...chrome]), placed, landed, gone);
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2735
|
+
const yields = t.kind === "refuse" ? besides(t) : [];
|
|
2736
|
+
const cuts = [...placed.flatMap(coverOf), ...(t.spec && taken.get(t.spec)) ?? [], ...yields, ...data.virtual || t.kind === "refuse" ? [] : bodiesOf(t), ...solid, ...chrome];
|
|
2737
|
+
const pieces = clip(t.hit, cuts);
|
|
2738
|
+
if (pieces.length === 0) {
|
|
2739
|
+
if (t.kind !== "refuse") gone.add(t);
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
if (t.kind === "refuse") {
|
|
2743
|
+
landed.set(t, pieces.map((_, k) => placed.length + k));
|
|
2744
|
+
for (const p of pieces) placed.push({ ...t, hit: p });
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
const solidPieces = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
2748
|
+
for (const p of pieces) if (!solidPieces.includes(p)) (data.virtual ? later : refused).push({ ...t, kind: "refuse", reason: t.spec ? roomReason(t.spec, t.zone) : "no-room", hit: p, keep: null });
|
|
2749
|
+
if (solidPieces.length === 0) return;
|
|
2750
|
+
landed.set(t, [placed.length]);
|
|
2751
|
+
placed.push(withPieces(t, solidPieces));
|
|
2752
|
+
};
|
|
2753
|
+
const byOrder = (a, b) => a.order - b.order;
|
|
2754
|
+
for (const t of tiles.filter((x) => !isRefused(x)).sort(byOrder)) place(t);
|
|
2755
|
+
for (const t of refused.sort(byOrder)) place(t);
|
|
2756
|
+
for (const t of gone) if (t.kind !== "home") lost.push(t.id);
|
|
2757
|
+
for (const t of later) for (const p of clip(t.hit, [...placed.flatMap(coverOf), ...besides(t), ...solid, ...chrome])) placed.push({ ...t, hit: p });
|
|
2758
|
+
return placed;
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
// src/targets/rail-strip.ts
|
|
2762
|
+
import { EPS as EPS17, overlaps as overlaps4, rect as rect14, subtract as subtract4 } from "@n-uf/placement";
|
|
2763
|
+
|
|
2764
|
+
// src/targets/virtual.ts
|
|
2765
|
+
import { EPS as EPS16, clamp, rect as rect13 } from "@n-uf/placement";
|
|
2766
|
+
function ringsOf(c, side) {
|
|
2767
|
+
const seen = sideRings(c.state.edges, side);
|
|
2768
|
+
const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
|
|
2769
|
+
const at = (e) => seen.get(e.id) ?? e.ring;
|
|
2770
|
+
return { before: (e) => kept.filter((r) => r < at(e)).length, after: (e) => kept.filter((r) => r <= at(e)).length, count: kept.length };
|
|
2771
|
+
}
|
|
2772
|
+
function railOuter(c, side) {
|
|
2773
|
+
const { now, state } = c;
|
|
2774
|
+
const place = now.railPlaces[side];
|
|
2775
|
+
const windowEdge = side === "left" ? state.stage.x : state.stage.x + state.stage.width;
|
|
2776
|
+
if (!place) return windowEdge;
|
|
2777
|
+
const placeOuter = side === "left" ? place.x : place.x + place.width;
|
|
2778
|
+
const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter + EPS16 : e.rect.x >= placeOuter - EPS16));
|
|
2779
|
+
return barOutside ? placeOuter : windowEdge;
|
|
2780
|
+
}
|
|
2781
|
+
function collapsesAt(c, result, side) {
|
|
2782
|
+
const me = result.layout.items[c.dragged];
|
|
2783
|
+
if (!me || me.floating || me.inMenu || !isHandFolded(result.state, c.dragged) || c.isHome(result) || !c.sound(result.layout)) return false;
|
|
2784
|
+
const sideOf = (edgeId) => edgeId ? result.layout.edges[edgeId]?.side : void 0;
|
|
2785
|
+
return me.rail === side || sideOf(me.rides) === side || sideOf(me.edge) === side;
|
|
2786
|
+
}
|
|
2787
|
+
function columnLines(c, side, railLands) {
|
|
2788
|
+
const { state, now, dragged } = c;
|
|
2789
|
+
if (state.sideColumns === "one" && c.rest.edges.some((e) => e.side === side && isSideColumn(c.rest, e) && (e.items.length > 0 || e.column !== true))) return [];
|
|
2790
|
+
const cols = state.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 }));
|
|
2791
|
+
const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);
|
|
2792
|
+
const span = own[0]?.rect ?? now.content;
|
|
2793
|
+
const rings = ringsOf(c, side);
|
|
2794
|
+
const lines = [];
|
|
2795
|
+
const outerX = (r) => side === "left" ? r.x : r.x + r.width;
|
|
2796
|
+
const innerX = (r) => side === "left" ? r.x + r.width : r.x;
|
|
2797
|
+
const atOf = (e) => c.lay.get(e.id)?.at ?? 0;
|
|
2798
|
+
cols.forEach((x) => lines.push({ x: outerX(x.r), ring: rings.before(x.edge), at: atOf(x.edge) - 0.5 }));
|
|
2799
|
+
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 });
|
|
2800
|
+
else lines.push({ x: side === "left" ? now.content.x : now.content.x + now.content.width, ring: rings.count, at: Math.max(-1, ...state.edges.filter((e) => e.side === side).map(atOf)) + 0.5 });
|
|
2801
|
+
const lands = (r) => {
|
|
2802
|
+
const me = r.layout.items[dragged];
|
|
2803
|
+
const el = me.edge ? r.layout.edges[me.edge] : void 0;
|
|
2804
|
+
return !!el && !me.inMenu && !el.folded && !el.rides && r.state !== c.state;
|
|
2805
|
+
};
|
|
2806
|
+
const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
|
|
2807
|
+
const stage = c.state.stage;
|
|
2808
|
+
const dir = side === "left" ? 1 : -1;
|
|
2809
|
+
const outside2 = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x + EPS16 : e.rect.x >= x - EPS16));
|
|
2810
|
+
const railFirst = railLands && !!c.state.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
|
|
2811
|
+
const placeOf = (l, i) => {
|
|
2812
|
+
const atEdge = side === "left" ? l.x <= stage.x + EPS16 : l.x >= stage.x + stage.width - EPS16;
|
|
2813
|
+
if (i > 0 || outside2(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };
|
|
2814
|
+
const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
|
|
2815
|
+
const boundary = clamp(l.x, stage.x, stage.x + stage.width);
|
|
2816
|
+
const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
|
|
2817
|
+
const line = band0 + dir * edgePlace / 2;
|
|
2818
|
+
const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
|
|
2819
|
+
return { line, zone: span2(railFirst ? band0 : windowEdge, line + dir * reach), owned: span2(band0, band0 + dir * edgePlace) };
|
|
2820
|
+
};
|
|
2821
|
+
const most = state.columns?.[side]?.cross.max;
|
|
2822
|
+
const tooThick = most !== void 0 && thickerThan(formsOf(state.items[dragged], "column"), most);
|
|
2823
|
+
return lines.map((l, i) => {
|
|
2824
|
+
const p = placeOf(l, i);
|
|
2825
|
+
return {
|
|
2826
|
+
id: virtualEdgeId("column", side),
|
|
2827
|
+
edge: null,
|
|
2828
|
+
kind: "columnLine",
|
|
2829
|
+
lay: { phase: EDGE_KINDS.columnLine.phase, side, at: l.at },
|
|
2830
|
+
vertical: false,
|
|
2831
|
+
zones: [{ zone: "start", a: Math.max(p.zone[0], stage.x), b: Math.min(p.zone[1], stage.x + stage.width) }],
|
|
2832
|
+
slots: [slotAt(c, "start", p.line, targetId({ kind: "column", side, ring: l.ring }), { kind: "column", side, ring: l.ring }, lands)],
|
|
2833
|
+
refuse: () => tooThick ? "too-thick" : "no-room",
|
|
2834
|
+
own: null,
|
|
2835
|
+
holds: false,
|
|
2836
|
+
reserved: [],
|
|
2837
|
+
cards: [],
|
|
2838
|
+
across: () => [span.y, span.y + span.height],
|
|
2839
|
+
owned: [span.y, span.y + span.height],
|
|
2840
|
+
ownedAlong: p.owned,
|
|
2841
|
+
drawn: false,
|
|
2842
|
+
// Where the new column's edge lands: the line itself, inside the stage.
|
|
2843
|
+
marker: () => rect13(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
|
|
2844
|
+
};
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
function railEnd(c, side, segments, y) {
|
|
2848
|
+
const { state, rest, dragged } = c;
|
|
2849
|
+
const edge = [...segments].reverse().map((s) => rest.edges.find((e) => e.id === s.edge)).find((e) => !!e);
|
|
2850
|
+
if (!edge) return null;
|
|
2851
|
+
const at = edge.items.filter((id) => zoneOf(rest.items[id]) === "start").length;
|
|
2852
|
+
const place = { kind: "gap", edge: edge.id, zone: "start", at };
|
|
2853
|
+
const collapsed = isHandFolded(state, dragged);
|
|
2854
|
+
const lands = ({ layout }) => {
|
|
2855
|
+
const me = layout.items[dragged];
|
|
2856
|
+
return !me.inMenu && (collapsed ? me.rail === side : me.edge === edge.id && !me.rail && !me.rides && !layout.edges[edge.id]?.folded);
|
|
2857
|
+
};
|
|
2858
|
+
return slotAt(c, "start", y, targetId(place), place, lands);
|
|
2859
|
+
}
|
|
2860
|
+
function railStops(c, side) {
|
|
2861
|
+
const { state, now, dragged } = c;
|
|
2862
|
+
const rail = now.rails[side];
|
|
2863
|
+
const placeRect = now.railPlaces[side];
|
|
2864
|
+
if (!placeRect) return null;
|
|
2865
|
+
const rings = ringsOf(c, side);
|
|
2866
|
+
const seenRings = sideRings(state.edges, side);
|
|
2867
|
+
const mine = state.edges.filter((e) => e.side === side).sort((a, b) => (seenRings.get(a.id) ?? 0) - (seenRings.get(b.id) ?? 0));
|
|
2868
|
+
const edgeOf = (id) => mine.find((e) => e.id === id);
|
|
2869
|
+
const ringBefore = (id) => {
|
|
2870
|
+
const e = edgeOf(id);
|
|
2871
|
+
return e ? rings.before(e) : 0;
|
|
2872
|
+
};
|
|
2873
|
+
const ringAfter = (id) => {
|
|
2874
|
+
const e = edgeOf(id);
|
|
2875
|
+
return e ? rings.after(e) : 1;
|
|
2876
|
+
};
|
|
2877
|
+
const stops2 = [];
|
|
2878
|
+
let zone;
|
|
2879
|
+
if (rail && rail.segments.length > 0) {
|
|
2880
|
+
zone = rail.rect;
|
|
2881
|
+
const groups = [];
|
|
2882
|
+
for (const s of rail.segments) {
|
|
2883
|
+
const g = groups[groups.length - 1];
|
|
2884
|
+
if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;
|
|
2885
|
+
else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });
|
|
2886
|
+
}
|
|
2887
|
+
for (const g of groups) stops2.push({ y: g.y0, ring: ringBefore(g.edge) });
|
|
2888
|
+
const last = groups[groups.length - 1];
|
|
2889
|
+
stops2.push({ y: last.y1, ring: ringAfter(last.edge) });
|
|
2890
|
+
} else {
|
|
2891
|
+
const firstCol = mine.find((e) => e.column === true);
|
|
2892
|
+
const outer = railOuter(c, side);
|
|
2893
|
+
zone = rect13(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
|
|
2894
|
+
stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
|
|
2895
|
+
}
|
|
2896
|
+
const ownRail = now.items[dragged]?.rail === side;
|
|
2897
|
+
const shown = !!rail && rail.segments.length > 0;
|
|
2898
|
+
const lands = (r) => shown ? collapsesAt(c, r, side) : r.layout.items[dragged].rail === side && r.state !== c.state;
|
|
2899
|
+
const at = zone;
|
|
2900
|
+
const arriving = state.foldedColumnDrop === "end" && !ownRail;
|
|
2901
|
+
const end = arriving && shown ? railEnd(c, side, rail.segments, at.y + at.height) : null;
|
|
2902
|
+
if (arriving && (shown ? !end : !isHandFolded(state, dragged))) return null;
|
|
2903
|
+
const width = state.rails?.[side]?.width;
|
|
2904
|
+
const tooThick = width !== void 0 && thickerThan(formsOf(state.items[dragged], "column"), width);
|
|
2905
|
+
return {
|
|
2906
|
+
id: virtualEdgeId("rail", side),
|
|
2907
|
+
edge: null,
|
|
2908
|
+
kind: "railStop",
|
|
2909
|
+
// The rail lies outside every edge on its side: laid first among them.
|
|
2910
|
+
lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
|
|
2911
|
+
vertical: true,
|
|
2912
|
+
zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
|
|
2913
|
+
slots: end ? [end] : stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
|
|
2914
|
+
refuse: () => tooThick ? "too-thick" : "no-room",
|
|
2915
|
+
own: null,
|
|
2916
|
+
holds: false,
|
|
2917
|
+
reserved: [],
|
|
2918
|
+
cards: [],
|
|
2919
|
+
across: () => [at.x, at.x + at.width],
|
|
2920
|
+
// A drawn rail owns its rect; where none shows, a thin band of its place at the side's outer boundary.
|
|
2921
|
+
owned: rail && rail.segments.length > 0 ? [at.x, at.x + at.width] : side === "left" ? [at.x, at.x + Math.min(at.width, EDGE_KINDS.railStop.place)] : [at.x + at.width - Math.min(at.width, EDGE_KINDS.railStop.place), at.x + at.width],
|
|
2922
|
+
ownedAlong: null,
|
|
2923
|
+
drawn: !!rail && rail.segments.length > 0,
|
|
2924
|
+
marker: (s) => rect13(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
|
|
2925
|
+
};
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
// src/targets/rail-strip.ts
|
|
2929
|
+
var across = (side, outer, width) => side === "left" ? [outer, width] : [outer - width, width];
|
|
2930
|
+
function columnStrip(c, side, policy) {
|
|
2931
|
+
const edge = railColumnOf(c.state, side, c.kind);
|
|
2932
|
+
if (!edge) return null;
|
|
2933
|
+
const own = c.now.items[c.dragged];
|
|
2934
|
+
if (own?.edge === edge.id && isHandFolded(c.state, c.dragged)) return null;
|
|
2935
|
+
const place = { kind: "rail", side, ring: edge.ring };
|
|
2936
|
+
const moved = moveAmong(c.state, c.dragged, place, c.others);
|
|
2937
|
+
if (moved === c.state) return null;
|
|
2938
|
+
const result = c.settle(markUsed(moved, c.dragged));
|
|
2939
|
+
const el = result.layout.edges[edge.id];
|
|
2940
|
+
if (!el || el.rect.width <= EPS17 || !collapsesAt(c, result, side)) return null;
|
|
2941
|
+
const r = el.rect;
|
|
2942
|
+
const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
|
|
2943
|
+
const [x, w] = across(side, side === "left" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));
|
|
2944
|
+
return { side, rect: rect14(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
|
|
2945
|
+
}
|
|
2946
|
+
function declaredStrip(c, side, policy) {
|
|
2947
|
+
const template = c.state.columns?.[side];
|
|
2948
|
+
const spec = c.state.rails?.[side];
|
|
2949
|
+
if (!template || !spec || !zoneTakes(template, "start", c.kind) || !spec.accepts.includes(c.kind)) return null;
|
|
2950
|
+
const stops2 = railStops(c, side);
|
|
2951
|
+
const slots = (stops2?.slots ?? []).filter((s) => !s.home && s.place.kind === "rail" && collapsesAt(c, s.result, side)).sort((a2, b2) => a2.line - b2.line);
|
|
2952
|
+
if (!stops2 || slots.length === 0) return null;
|
|
2953
|
+
const a = Math.min(...stops2.zones.map((z) => z.a));
|
|
2954
|
+
const b = Math.max(...stops2.zones.map((z) => z.b));
|
|
2955
|
+
const drawn = c.now.rails[side];
|
|
2956
|
+
const outer = drawn && drawn.segments.length > 0 ? side === "left" ? drawn.rect.x : drawn.rect.x + drawn.rect.width : railOuter(c, side);
|
|
2957
|
+
const [x, w] = across(side, outer, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, spec.width));
|
|
2958
|
+
const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
|
|
2959
|
+
return {
|
|
2960
|
+
side,
|
|
2961
|
+
rect: rect14(x, a, w, b - a),
|
|
2962
|
+
slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
|
|
2963
|
+
};
|
|
2964
|
+
}
|
|
2965
|
+
var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => overlaps4(p, s) ? subtract4(p, s) : [p]), [...pieces]).filter((p) => p.width >= 1 && p.height >= 1);
|
|
2966
|
+
var largest2 = (rs) => rs.reduce((m, r) => r.width * r.height > m.width * m.height ? r : m);
|
|
2967
|
+
var sameRects = (a, b) => a.length === b.length && a.every((r, i) => r.x === b[i].x && r.y === b[i].y && r.width === b[i].width && r.height === b[i].height);
|
|
2968
|
+
function withRailStrips(c, targets2, refusals2) {
|
|
2969
|
+
const policy = c.state.foldedColumnDrop === "end" ? null : railPolicyOf(c.state, c.kind);
|
|
2970
|
+
const strips = policy ? ["left", "right"].map((side) => c.state.rails?.[side] ? declaredStrip(c, side, policy) : columnStrip(c, side, policy)).filter((s) => s !== null) : [];
|
|
2971
|
+
if (!policy || strips.length === 0) return { targets: [...targets2], refusals: [...refusals2], strips: [] };
|
|
2972
|
+
const sides = new Set(strips.map((s) => s.side));
|
|
2973
|
+
const rects = strips.map((s) => s.rect);
|
|
2974
|
+
const out = [];
|
|
2975
|
+
const lines = [];
|
|
2976
|
+
for (const t of targets2) {
|
|
2977
|
+
if (t.place.kind === "rail" && sides.has(t.place.side)) continue;
|
|
2978
|
+
if (t.free || t.place.kind === "none") {
|
|
2979
|
+
out.push(t.free && !policy.floatNearEdge ? clearOfStrips(t, c.dragged, rects) : t);
|
|
2980
|
+
continue;
|
|
2981
|
+
}
|
|
2982
|
+
const was = t.hits ?? [t.hit];
|
|
2983
|
+
const pieces = outside(was, rects);
|
|
2984
|
+
if (pieces.length === 0) {
|
|
2985
|
+
let moved = t.id.startsWith("strip:") || t.place.kind === "column" ? insideStrips(t.hit, strips) : null;
|
|
2986
|
+
let movedPieces = moved ? [moved] : [];
|
|
2987
|
+
if (moved && t.place.kind === "column") {
|
|
2988
|
+
const others = targets2.filter((x) => x !== t && (x.place.kind === "home" || x.place.kind === "column" || x.place.kind === "none" && !x.free)).flatMap((x) => x.hits ?? [x.hit]);
|
|
2989
|
+
movedPieces = outside([moved], others);
|
|
2990
|
+
moved = movedPieces.length ? largest2(movedPieces) : null;
|
|
2991
|
+
if (moved) lines.push({ side: t.place.side, pieces: movedPieces });
|
|
2992
|
+
}
|
|
2993
|
+
if (moved) out.push({ ...withoutHits(t), hit: moved, ...movedPieces.length > 1 ? { hits: movedPieces } : {} });
|
|
2994
|
+
continue;
|
|
2995
|
+
}
|
|
2996
|
+
if (sameRects(pieces, was)) {
|
|
2997
|
+
out.push(t);
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
out.push({ ...withoutHits(t), hit: largest2(pieces), ...pieces.length > 1 ? { hits: pieces } : {} });
|
|
3001
|
+
}
|
|
3002
|
+
const columnSide = (edge) => {
|
|
3003
|
+
const e = c.state.edges.find((x) => x.id === edge);
|
|
3004
|
+
return e?.column && (e.side === "left" || e.side === "right") ? e.side : null;
|
|
3005
|
+
};
|
|
3006
|
+
const lineCut = (edge) => lines.filter((l) => l.side === columnSide(edge)).flatMap((l) => l.pieces);
|
|
3007
|
+
for (let i = 0; i < out.length; i++) {
|
|
3008
|
+
const t = out[i];
|
|
3009
|
+
if (t.place.kind !== "gap") continue;
|
|
3010
|
+
const cut2 = lineCut(t.place.edge);
|
|
3011
|
+
if (!cut2.length) continue;
|
|
3012
|
+
const was = t.hits ?? [t.hit];
|
|
3013
|
+
const pieces = outside(was, cut2);
|
|
3014
|
+
if (sameRects(pieces, was)) continue;
|
|
3015
|
+
if (pieces.length === 0) out.splice(i--, 1);
|
|
3016
|
+
else out[i] = { ...withoutHits(t), hit: largest2(pieces), ...pieces.length > 1 ? { hits: pieces } : {} };
|
|
3017
|
+
}
|
|
3018
|
+
const refused = [];
|
|
3019
|
+
const railEdges = new Set([...sides].map((side) => virtualEdgeId("rail", side)));
|
|
3020
|
+
for (const r of refusals2) {
|
|
3021
|
+
if (railEdges.has(r.edge)) continue;
|
|
3022
|
+
const was = r.hits ?? [r.hit];
|
|
3023
|
+
const pieces = outside(was, [...rects, ...lineCut(r.edge)]);
|
|
3024
|
+
if (!pieces.length || sameRects(pieces, was)) {
|
|
3025
|
+
if (pieces.length) refused.push(r);
|
|
3026
|
+
continue;
|
|
3027
|
+
}
|
|
3028
|
+
const kept = r.hits ? pieces.filter((p) => p.width >= 1 && p.height >= 1) : [largest2(pieces)];
|
|
3029
|
+
const { hits: _h, ...one } = r;
|
|
3030
|
+
if (kept.length) refused.push({ ...one, hit: largest2(kept), ...kept.length > 1 ? { hits: kept } : {} });
|
|
3031
|
+
}
|
|
3032
|
+
const vertical = (r) => {
|
|
3033
|
+
const side = c.state.edges.find((e) => e.id === r.edge)?.side;
|
|
3034
|
+
return side ? side === "left" || side === "right" : r.edge === virtualEdgeId("rail", "left") || r.edge === virtualEdgeId("rail", "right");
|
|
3035
|
+
};
|
|
3036
|
+
const pos = (r) => vertical(r) ? [r.hit.y, r.hit.x] : [r.hit.x, r.hit.y];
|
|
3037
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3038
|
+
for (const r of refused) groups.set(`${r.edge}
|
|
3039
|
+
${r.zone}`, [...groups.get(`${r.edge}
|
|
3040
|
+
${r.zone}`) ?? [], r]);
|
|
3041
|
+
const numbered = /* @__PURE__ */ new Map();
|
|
3042
|
+
for (const group of groups.values())
|
|
3043
|
+
group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((r, n) => numbered.set(r, targetId({ kind: "refuse", edge: r.edge, zone: r.zone, n })));
|
|
3044
|
+
const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
|
|
3045
|
+
for (const s of strips) {
|
|
3046
|
+
const grown = s.side === "left" ? rect14(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect14(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
|
|
3047
|
+
for (const sl of s.slots) {
|
|
3048
|
+
const [a, b] = sl.along;
|
|
3049
|
+
const slot = sl.result.layout.items[c.dragged].rect;
|
|
3050
|
+
const result = sl.result;
|
|
3051
|
+
out.push({
|
|
3052
|
+
id: sl.id,
|
|
3053
|
+
priority: 1,
|
|
3054
|
+
hit: rect14(s.rect.x, a, s.rect.width, b - a),
|
|
3055
|
+
armedHit: rect14(grown.x, a, grown.width, b - a),
|
|
3056
|
+
arm: "dwell",
|
|
3057
|
+
// Armed, its room opens at once: a host that draws only a marker reads that from this one flag, as for any target.
|
|
3058
|
+
opensRoom: true,
|
|
3059
|
+
strip: s.rect,
|
|
3060
|
+
slot,
|
|
3061
|
+
item: c.dragged,
|
|
3062
|
+
place: sl.place,
|
|
3063
|
+
after: () => result
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
return { targets: out, refusals: renumbered, strips: rects };
|
|
3068
|
+
}
|
|
3069
|
+
var withoutHits = (t) => {
|
|
3070
|
+
const { hits: _pieces, ...rest } = t;
|
|
3071
|
+
return rest;
|
|
3072
|
+
};
|
|
3073
|
+
function insideStrips(r, strips) {
|
|
3074
|
+
const s = strips.find((x) => overlaps4(x.rect, r));
|
|
3075
|
+
if (!s) return null;
|
|
3076
|
+
return s.side === "left" ? rect14(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect14(s.rect.x - r.width, r.y, r.width, r.height);
|
|
3077
|
+
}
|
|
3078
|
+
function clearOfStrips(t, dragged, strips) {
|
|
3079
|
+
return {
|
|
3080
|
+
...t,
|
|
3081
|
+
after(point, grab) {
|
|
3082
|
+
const first = t.after(point, grab);
|
|
3083
|
+
const at = first.layout.items[dragged]?.rect;
|
|
3084
|
+
if (!at) return first;
|
|
3085
|
+
let dx = 0;
|
|
3086
|
+
for (const s of strips) {
|
|
3087
|
+
const r = rect14(at.x + dx, at.y, at.width, at.height);
|
|
3088
|
+
if (!overlaps4(r, s)) continue;
|
|
3089
|
+
dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
|
|
3090
|
+
}
|
|
3091
|
+
return dx === 0 ? first : t.after({ x: at.x + dx + (grab?.x ?? at.width / 2), y: point.y }, grab);
|
|
3092
|
+
}
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
// src/targets/min-hit.ts
|
|
3097
|
+
import { EPS as EPS18, area as area5, rect as rect15, subtract as subtract5 } from "@n-uf/placement";
|
|
3098
|
+
function kindOf(c, t) {
|
|
3099
|
+
const p = parseTargetId(t.id);
|
|
3100
|
+
if (!p) return null;
|
|
3101
|
+
if (p.kind === "column") return "columnLine";
|
|
3102
|
+
if (p.kind === "rail") return "railStop";
|
|
3103
|
+
if (p.kind === "gap" || p.kind === "strip") {
|
|
3104
|
+
const e = c.state.edges.find((x) => x.id === p.edge);
|
|
3105
|
+
return e ? edgeKindOf(c.state, e) : null;
|
|
3106
|
+
}
|
|
3107
|
+
return null;
|
|
3108
|
+
}
|
|
3109
|
+
var largest3 = (ps) => ps.reduce((a, p) => area5(p) > area5(a) ? p : a);
|
|
3110
|
+
var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS18 && Math.max(r.width, r.height) >= m.along - EPS18;
|
|
3111
|
+
var overlaps5 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS18 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS18;
|
|
3112
|
+
var cut = (ps, g) => ps.flatMap((p) => subtract5(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
3113
|
+
var piecesOf = (t) => t.hits ?? [t.hit];
|
|
3114
|
+
var withPieces2 = (t, ps) => {
|
|
3115
|
+
const { hits: _h, ...rest } = t;
|
|
3116
|
+
return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
3117
|
+
};
|
|
3118
|
+
function growths(r, axis, d) {
|
|
3119
|
+
const [lo2, hi] = axis === "x" ? [rect15(r.x - d, r.y, d, r.height), rect15(r.x + r.width, r.y, d, r.height)] : [rect15(r.x, r.y - d, r.width, d), rect15(r.x, r.y + r.height, r.width, d)];
|
|
3120
|
+
const h = d / 2;
|
|
3121
|
+
const halves = axis === "x" ? [rect15(r.x - h, r.y, h, r.height), rect15(r.x + r.width, r.y, h, r.height)] : [rect15(r.x, r.y - h, r.width, h), rect15(r.x, r.y + r.height, r.width, h)];
|
|
3122
|
+
return [[lo2], [hi], halves];
|
|
3123
|
+
}
|
|
3124
|
+
var union = (a, gs) => {
|
|
3125
|
+
const x0 = Math.min(a.x, ...gs.map((g) => g.x));
|
|
3126
|
+
const y0 = Math.min(a.y, ...gs.map((g) => g.y));
|
|
3127
|
+
return rect15(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);
|
|
3128
|
+
};
|
|
3129
|
+
function mayGrow(c, targets2, i, grow, minOf, zone, away) {
|
|
3130
|
+
const s = c.state.stage;
|
|
3131
|
+
for (const g of grow) {
|
|
3132
|
+
if (g.x < s.x - EPS18 || g.y < s.y - EPS18 || g.x + g.width > s.x + s.width + EPS18 || g.y + g.height > s.y + s.height + EPS18) return false;
|
|
3133
|
+
if ([...keepClearFor(c.state, "targets"), ...away].some((r) => overlaps5(r, g))) return false;
|
|
3134
|
+
if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS18)) return false;
|
|
3135
|
+
}
|
|
3136
|
+
return targets2.every((o, j) => {
|
|
3137
|
+
if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps5(p, g)))) return true;
|
|
3138
|
+
if (o.place.kind === "home" || o.place.kind === "none" || o.strip) return false;
|
|
3139
|
+
const m = minOf(o);
|
|
3140
|
+
const left = grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]);
|
|
3141
|
+
return !!m && left.length > 0 && keepsMinHit(largest3(left), m);
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
3145
|
+
const along2 = axis === "x" ? [l.y, l.y + l.height] : [l.x, l.x + l.width];
|
|
3146
|
+
let best = null;
|
|
3147
|
+
for (const [side] of growths(l, axis, d)) {
|
|
3148
|
+
const g = side;
|
|
3149
|
+
const strip = (a, b) => axis === "x" ? rect15(g.x, a, g.width, b - a) : rect15(a, g.y, b - a, g.height);
|
|
3150
|
+
const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
|
|
3151
|
+
for (const o of targets2)
|
|
3152
|
+
for (const p of piecesOf(o))
|
|
3153
|
+
if (overlaps5(p, g)) {
|
|
3154
|
+
for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along2[0] && v < along2[1]) cuts.add(v);
|
|
3155
|
+
}
|
|
3156
|
+
const marks = [...cuts].sort((a, b) => a - b);
|
|
3157
|
+
let runStart = null;
|
|
3158
|
+
const runs = [];
|
|
3159
|
+
for (let k = 0; k < marks.length - 1; k++) {
|
|
3160
|
+
const ok = mayGrow(c, targets2, i, [strip(marks[k], marks[k + 1])], minOf, zone, away);
|
|
3161
|
+
if (ok && runStart === null) runStart = marks[k];
|
|
3162
|
+
if (!ok && runStart !== null) {
|
|
3163
|
+
runs.push([runStart, marks[k]]);
|
|
3164
|
+
runStart = null;
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
|
|
3168
|
+
for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
|
|
3169
|
+
if (b - a < m.along - EPS18) break;
|
|
3170
|
+
const r = strip(a, b);
|
|
3171
|
+
if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area5(r) > area5(best))) best = r;
|
|
3172
|
+
break;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
return best ? [best] : null;
|
|
3176
|
+
}
|
|
3177
|
+
function withMinHit(c, targets2, refusals2, zones) {
|
|
3178
|
+
const out = [...targets2];
|
|
3179
|
+
const refused = refusals2.flatMap(piecesOf);
|
|
3180
|
+
const minOf = (t) => {
|
|
3181
|
+
const k = kindOf(c, t);
|
|
3182
|
+
return k ? EDGE_KINDS[k].minHit : null;
|
|
3183
|
+
};
|
|
3184
|
+
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS18 && e.rect.height > EPS18);
|
|
3185
|
+
for (let i = 0; i < out.length; i++) {
|
|
3186
|
+
const t = out[i];
|
|
3187
|
+
const m = minOf(t);
|
|
3188
|
+
const zone = zones.get(t.id);
|
|
3189
|
+
if (!m || !zone || t.free || t.strip || t.place.kind === "home" || t.place.kind === "none") continue;
|
|
3190
|
+
const ownEdge = t.place.kind === "gap" ? t.place.edge : parseTargetId(t.id)?.edge;
|
|
3191
|
+
const k = kindOf(c, t);
|
|
3192
|
+
const away = [...refused, ...k && EDGE_KINDS[k].virtual ? [] : drawn.filter(([id]) => id !== ownEdge).map(([, e]) => e.rect)];
|
|
3193
|
+
let l = largest3(piecesOf(t));
|
|
3194
|
+
if (keepsMinHit(l, m)) continue;
|
|
3195
|
+
const steps = ["across", "along"];
|
|
3196
|
+
for (const step of steps) {
|
|
3197
|
+
const narrowX = l.width <= l.height;
|
|
3198
|
+
const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
|
|
3199
|
+
const size = axis === "x" ? l.width : l.height;
|
|
3200
|
+
const d = (step === "across" ? m.across : m.along) - size;
|
|
3201
|
+
if (d <= EPS18) continue;
|
|
3202
|
+
let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
|
|
3203
|
+
if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
|
|
3204
|
+
if (!grow) continue;
|
|
3205
|
+
for (let j = 0; j < out.length; j++) {
|
|
3206
|
+
if (j === i || out[j].free) continue;
|
|
3207
|
+
const o = out[j];
|
|
3208
|
+
if (!piecesOf(o).some((p) => grow.some((g) => overlaps5(p, g)))) continue;
|
|
3209
|
+
out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
|
|
3210
|
+
}
|
|
3211
|
+
const g0 = grow[0];
|
|
3212
|
+
const span = axis === "x" ? rect15(l.x, g0.y, l.width, g0.height) : rect15(g0.x, l.y, g0.width, l.height);
|
|
3213
|
+
const grown = union(span, grow);
|
|
3214
|
+
const others = piecesOf(out[i]).filter((p) => p !== l);
|
|
3215
|
+
out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
|
|
3216
|
+
l = largest3(piecesOf(out[i]));
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
return out;
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
// src/targets.ts
|
|
3223
|
+
function specsOf(c, kind) {
|
|
3224
|
+
const { state } = c;
|
|
3225
|
+
const specs = state.edges.map((edge) => edgeSpec(c, edge));
|
|
3226
|
+
for (const side of ["left", "right"]) {
|
|
3227
|
+
const template = state.columns?.[side];
|
|
3228
|
+
if (!template || !zoneTakes(template, "start", kind)) continue;
|
|
3229
|
+
const rail = state.rails?.[side]?.accepts.includes(kind) ? railStops(c, side) : null;
|
|
3230
|
+
specs.push(...columnLines(c, side, !!rail?.slots.some((s) => s.ok)));
|
|
3231
|
+
specs.push(rail);
|
|
3232
|
+
}
|
|
3233
|
+
return specs.filter((s) => s !== null);
|
|
3234
|
+
}
|
|
3235
|
+
function emit2(c, placed) {
|
|
3236
|
+
const { state, now, base, dragged } = c;
|
|
3237
|
+
const homeId = targetId({ kind: "home", item: dragged });
|
|
3238
|
+
const targets2 = [];
|
|
3239
|
+
const refused = [];
|
|
3240
|
+
const homeAfter = () => ({ state, layout: now });
|
|
3241
|
+
const pos = (t) => t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y];
|
|
3242
|
+
const rank = /* @__PURE__ */ new Map();
|
|
3243
|
+
const edgeOf = (t) => t.spec?.edge ? t.spec : t.edge;
|
|
3244
|
+
const byZone = /* @__PURE__ */ new Map();
|
|
3245
|
+
for (const t of placed) {
|
|
3246
|
+
if (t.kind !== "refuse") continue;
|
|
3247
|
+
const zones = byZone.get(edgeOf(t)) ?? /* @__PURE__ */ new Map();
|
|
3248
|
+
byZone.set(edgeOf(t), zones.set(t.zone, [...zones.get(t.zone) ?? [], t]));
|
|
3249
|
+
}
|
|
3250
|
+
for (const zones of byZone.values()) for (const group of zones.values()) group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((t, n) => rank.set(t, n));
|
|
3251
|
+
let ownHome = null;
|
|
3252
|
+
for (const t of placed) {
|
|
3253
|
+
if (t.kind === "refuse") {
|
|
3254
|
+
const n = rank.get(t);
|
|
3255
|
+
refused.push({ id: targetId({ kind: "refuse", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, reason: t.reason });
|
|
3256
|
+
continue;
|
|
3257
|
+
}
|
|
3258
|
+
if (t.kind === "home" && t.id === homeId) {
|
|
3259
|
+
if (t.order === 0) ownHome = t.hit;
|
|
3260
|
+
continue;
|
|
3261
|
+
}
|
|
3262
|
+
const first = targets2.findIndex((x) => x.id === t.id);
|
|
3263
|
+
if (first >= 0) {
|
|
3264
|
+
const was = targets2[first];
|
|
3265
|
+
const pieces = [...was.hits ?? [was.hit], ...t.hits ?? [t.hit]];
|
|
3266
|
+
targets2[first] = { ...was, hit: pieces.reduce((m, p) => area6(p) > area6(m) ? p : m), hits: pieces };
|
|
3267
|
+
continue;
|
|
3268
|
+
}
|
|
3269
|
+
if (t.kind === "home") {
|
|
3270
|
+
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
3271
|
+
continue;
|
|
3272
|
+
}
|
|
3273
|
+
const result = t.result;
|
|
3274
|
+
const atEdge = WINDOW_EDGE_KINDS.has(t.edgeKind) && touchesSide(state.stage, t.hits ?? [t.hit]);
|
|
3275
|
+
const thickens = thicknessChanges(now, result.layout);
|
|
3276
|
+
const room = t.slot && slotOverMoved(now, base, result.layout, t.slot, dragged, t.edge) ? { opensRoom: true, ...atEdge ? { roomHold: EDGE_ROOM_HOLD } : {}, ...thickens ? { roomHit: hull(t.hit, t.slot) } : {} } : {};
|
|
3277
|
+
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, ...t.slot ? { slot: t.slot } : {}, ...t.marker ? { marker: t.marker } : {}, ...room, item: dragged, place: t.place, after: () => result });
|
|
3278
|
+
}
|
|
3279
|
+
return { targets: targets2, refused, ownHome };
|
|
3280
|
+
}
|
|
3281
|
+
function hull(a, b) {
|
|
3282
|
+
const x = Math.min(a.x, b.x);
|
|
3283
|
+
const y = Math.min(a.y, b.y);
|
|
3284
|
+
return rect16(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
|
|
3285
|
+
}
|
|
3286
|
+
var thicknessChanges = (now, after) => {
|
|
3287
|
+
const a = now.content;
|
|
3288
|
+
const b = after.content;
|
|
3289
|
+
return Math.abs(b.x - a.x) > EPS19 || Math.abs(b.y - a.y) > EPS19 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS19 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS19;
|
|
3290
|
+
};
|
|
3291
|
+
var WINDOW_EDGE_KINDS = /* @__PURE__ */ new Set(["rail", "railStop", "sideBar", "columnLine"]);
|
|
3292
|
+
var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS19 || r.x + r.width >= stage.x + stage.width - EPS19);
|
|
3293
|
+
function slotOverMoved(now, lifted, after, slot, dragged, onto) {
|
|
3294
|
+
const from = now.items[dragged]?.edge;
|
|
3295
|
+
return Object.entries(now.items).some(([id, was]) => {
|
|
3296
|
+
if (!overlaps6(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
|
|
3297
|
+
const r = after.items[id]?.rect;
|
|
3298
|
+
const start = (from !== void 0 && was.edge === from ? lifted.items[id]?.rect : void 0) ?? was.rect;
|
|
3299
|
+
return !!r && (Math.abs(r.x - start.x) > EPS19 || Math.abs(r.y - start.y) > EPS19 || Math.abs(r.width - start.width) > EPS19 || Math.abs(r.height - start.height) > EPS19);
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
function alongOfSlots(s, tiles) {
|
|
3303
|
+
const spans = tiles.filter((t) => t.kind === "slot").map((t) => s.vertical ? [t.hit.y, t.hit.y + t.hit.height] : [t.hit.x, t.hit.x + t.hit.width]).sort((a, b) => a[0] - b[0]);
|
|
3304
|
+
const out = [];
|
|
3305
|
+
for (const [a, b] of spans) {
|
|
3306
|
+
const last = out[out.length - 1];
|
|
3307
|
+
if (last && a <= last[1] + 1e-6) last[1] = Math.max(last[1], b);
|
|
3308
|
+
else out.push([a, b]);
|
|
3309
|
+
}
|
|
3310
|
+
return out;
|
|
3311
|
+
}
|
|
3312
|
+
function generate(state, dragged, options) {
|
|
3313
|
+
checkEdgeIds(state);
|
|
3314
|
+
const { view: shown, lent, rezoned } = viewOf(state);
|
|
3315
|
+
if (shown === state) return generateShown(state, dragged, options, []);
|
|
3316
|
+
if (inHiddenEdge(state, dragged) && !lent.has(dragged)) return { targets: [], refusals: [], lost: [] };
|
|
3317
|
+
const hidden = state.edges.filter((e) => e.hidden === true);
|
|
3318
|
+
const g = generateShown(shown, dragged, options, hidden);
|
|
3319
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
3320
|
+
const showsIn = hidden.some((e) => e.showIn !== void 0);
|
|
3321
|
+
return {
|
|
3322
|
+
...g,
|
|
3323
|
+
targets: g.targets.map((t) => ({
|
|
3324
|
+
...t,
|
|
3325
|
+
after: (point, grab) => {
|
|
3326
|
+
const a = t.after(point, grab);
|
|
3327
|
+
if (a.state === shown) return { state, layout: showsIn ? solve(state, prev) : a.layout };
|
|
3328
|
+
const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
|
|
3329
|
+
const named = !!on && namesZone(on, state.items[dragged].kind);
|
|
3330
|
+
const back = withHiddenOf(state, a.state, lent, dragged, named, rezoned);
|
|
3331
|
+
const restored = showsIn ? prune(back) : back;
|
|
3332
|
+
const ringOf = new Map(a.state.edges.map((e) => [e.id, e.ring]));
|
|
3333
|
+
const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
|
|
3334
|
+
const layout = renumbered || showsIn || rezoned.size > 0 ? solve(restored, prev) : a.layout;
|
|
3335
|
+
return { state: restored, layout };
|
|
3336
|
+
}
|
|
3337
|
+
}))
|
|
3338
|
+
};
|
|
3339
|
+
}
|
|
3340
|
+
function generateShown(state, dragged, options, hidden) {
|
|
3341
|
+
if (Object.hasOwn(state.items, dragged) && state.items[dragged].fixed) return anchorTargets(state, dragged, options);
|
|
3342
|
+
const ctx = context(state, dragged, options, hidden);
|
|
3343
|
+
if (!ctx) return { targets: [], refusals: [], lost: [] };
|
|
3344
|
+
const { c, item, prev } = ctx;
|
|
3345
|
+
const { now } = c;
|
|
3346
|
+
const live = specsOf(c, item.kind);
|
|
3347
|
+
const alone = new Map(live.map((s) => [s, tileEdge(c, s, { cuts: [], bodies: [] }, [])]));
|
|
3348
|
+
const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
|
|
3349
|
+
const own = ownership(c, live, (s) => along2.get(s));
|
|
3350
|
+
const lost = [];
|
|
3351
|
+
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
|
|
3352
|
+
const ownRect = now.items[dragged];
|
|
3353
|
+
const homeEdge = state.edges.find((e) => e.id === ownRect?.edge);
|
|
3354
|
+
const homeHit = homeRectOf(c, null);
|
|
3355
|
+
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
|
|
3356
|
+
tiles.push({ edge: homeEdge.id, spec: null, edgeKind: edgeKindOf(state, homeEdge), vertical: axisOf(homeEdge.side) === "column", zone: zoneOf(item), order: 0, kind: "home", id: targetId({ kind: "home", item: dragged }), priority: 1, place: { kind: "home" }, hit: homeHit, keep: null });
|
|
3357
|
+
const placed = clipTiles(tiles, own, keepClearFor(state, "targets"), lost);
|
|
3358
|
+
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
3359
|
+
const homeAfter = () => ({ state, layout: now });
|
|
3360
|
+
if (state.floatKinds.includes(item.kind)) {
|
|
3361
|
+
const was = state.floats.find((f) => f.id === dragged);
|
|
3362
|
+
const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
|
|
3363
|
+
const wasOrient = was?.orient ?? floatOrientOf(item);
|
|
3364
|
+
const size = options.floatSize ?? (was && wasOrient === fo ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
|
|
3365
|
+
targets2.push({
|
|
3366
|
+
id: targetId({ kind: "float", item: dragged }),
|
|
3367
|
+
priority: 3,
|
|
3368
|
+
free: true,
|
|
3369
|
+
hit: PLANE,
|
|
3370
|
+
// Over the whole plane, but only strictly inside the stage: its edge belongs to the targets drawn against it.
|
|
3371
|
+
bounds: stageOf(state),
|
|
3372
|
+
item: dragged,
|
|
3373
|
+
place: { kind: "float" },
|
|
3374
|
+
after(point, grab) {
|
|
3375
|
+
const g = grab ?? { x: size.width / 2, y: size.height / 2 };
|
|
3376
|
+
const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect16(point.x - g.x, point.y - g.y, size.width, size.height);
|
|
3377
|
+
const first = solve(markUsed(floatAt(state, dragged, raw, options.floatOrient), dragged), prev);
|
|
3378
|
+
const at = first.items[dragged]?.rect ?? raw;
|
|
3379
|
+
return c.settle(markUsed(floatAt(state, dragged, rect16(at.x, at.y, size.width, size.height), options.floatOrient), dragged));
|
|
3380
|
+
}
|
|
3381
|
+
});
|
|
3382
|
+
}
|
|
3383
|
+
(state.blocked ?? []).forEach((b, i) => {
|
|
3384
|
+
targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect16(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
|
|
3385
|
+
});
|
|
3386
|
+
const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
|
|
3387
|
+
const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
|
|
3388
|
+
if (sameAsHome.length) targets2.splice(0, targets2.length, ...targets2.filter((t) => !sameAsHome.includes(t)));
|
|
3389
|
+
const homeSlot = targets2.findIndex((t) => t.place.kind === "home");
|
|
3390
|
+
if (homeSlot >= 0 && homePieces.length) {
|
|
3391
|
+
const t = targets2[homeSlot];
|
|
3392
|
+
targets2[homeSlot] = { ...t, hits: [...t.hits ?? [t.hit], ...homePieces] };
|
|
3393
|
+
}
|
|
3394
|
+
if (ownRect && !ownRect.floating) {
|
|
3395
|
+
const hit = ownHome ?? ownRect.rect;
|
|
3396
|
+
const pieces = homeSlot < 0 && homePieces.length ? { hits: [hit, ...homePieces] } : {};
|
|
3397
|
+
targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit, ...pieces, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
3398
|
+
}
|
|
3399
|
+
const lostIds = [...new Set(lost)].filter((id) => !targets2.some((t) => t.id === id));
|
|
3400
|
+
const layered = withRailStrips(c, targets2, refused);
|
|
3401
|
+
const zones = /* @__PURE__ */ new Map();
|
|
3402
|
+
for (const t of [...alone.values()].flat()) if (t.kind !== "refuse" && t.id) zones.set(t.id, [...zones.get(t.id) ?? [], t.hit]);
|
|
3403
|
+
const bounds = stageOf(state);
|
|
3404
|
+
const held = withMinHit(c, layered.targets, layered.refusals, zones).map((t) => t.roomHit && t.slot ? { ...t, roomHit: hull(t.hit, t.slot) } : t);
|
|
3405
|
+
return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones };
|
|
3406
|
+
}
|
|
3407
|
+
var stageOf = (state) => rect16(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
|
|
3408
|
+
function targets(state, dragged, options = {}) {
|
|
3409
|
+
return generate(state, dragged, options).targets;
|
|
3410
|
+
}
|
|
3411
|
+
function targetsAndRefusals(state, dragged, options = {}) {
|
|
3412
|
+
const g = generate(state, dragged, options);
|
|
3413
|
+
return { targets: g.targets, refusals: g.refusals };
|
|
3414
|
+
}
|
|
3415
|
+
function refusals(state, dragged, options = {}) {
|
|
3416
|
+
return generate(state, dragged, options).refusals;
|
|
3417
|
+
}
|
|
3418
|
+
function refusalTargets(list) {
|
|
3419
|
+
return list.map((r) => ({ id: r.id, priority: 2, hit: r.hit, ...r.hits ? { hits: r.hits } : {}, ...r.bounds ? { bounds: r.bounds } : {}, refuse: true, refusal: r }));
|
|
3420
|
+
}
|
|
3421
|
+
var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
|
|
3422
|
+
function stops(state, dragged, options = {}) {
|
|
3423
|
+
const key = stopsKey(dragged, options);
|
|
3424
|
+
let memo2 = stopsMemo.get(state);
|
|
3425
|
+
if (!memo2) stopsMemo.set(state, memo2 = /* @__PURE__ */ new Map());
|
|
3426
|
+
let list = memo2.get(key);
|
|
3427
|
+
if (!list) {
|
|
3428
|
+
if (memo2.size >= STOPS_PER_STATE) memo2.clear();
|
|
3429
|
+
memo2.set(key, list = orderedStops(state, dragged, options));
|
|
3430
|
+
}
|
|
3431
|
+
return [...list];
|
|
3432
|
+
}
|
|
3433
|
+
var stopsMemo = /* @__PURE__ */ new WeakMap();
|
|
3434
|
+
var STOPS_PER_STATE = 512;
|
|
3435
|
+
var layoutIds = /* @__PURE__ */ new WeakMap();
|
|
3436
|
+
var nextLayoutId = 0;
|
|
3437
|
+
function stopsKey(dragged, o) {
|
|
3438
|
+
let prev = null;
|
|
3439
|
+
if (o.previous) {
|
|
3440
|
+
prev = layoutIds.get(o.previous) ?? nextLayoutId++;
|
|
3441
|
+
layoutIds.set(o.previous, prev);
|
|
3442
|
+
}
|
|
3443
|
+
return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);
|
|
3444
|
+
}
|
|
3445
|
+
function orderedStops(state, dragged, options) {
|
|
3446
|
+
const list = targets(state, dragged, options).filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
|
|
3447
|
+
const sideOf = (t) => {
|
|
3448
|
+
const p = t.place;
|
|
3449
|
+
if (p.kind === "float") return "float";
|
|
3450
|
+
if (p.kind === "column" || p.kind === "rail" || p.kind === "side") return p.side;
|
|
3451
|
+
if (p.kind === "gap") return state.edges.find((e) => e.id === p.edge)?.side ?? "float";
|
|
3452
|
+
return "float";
|
|
3453
|
+
};
|
|
3454
|
+
const key = (t) => {
|
|
3455
|
+
const side = sideOf(t);
|
|
3456
|
+
const r = t.slot ?? t.hit;
|
|
3457
|
+
const cx = r.x + r.width / 2;
|
|
3458
|
+
const cy = r.y + r.height / 2;
|
|
3459
|
+
const rank = side === "float" ? 4 : SIDE_RANK[side];
|
|
3460
|
+
return side === "left" ? [rank, cx, cy] : side === "right" ? [rank, -cx, cy] : [rank, cy * (side === "bottom" ? -1 : 1), cx];
|
|
3461
|
+
};
|
|
3462
|
+
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);
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
// src/lanes.ts
|
|
3466
|
+
import { EPS as EPS20, clamp as clamp2, rect as rect17 } from "@n-uf/placement";
|
|
3467
|
+
var SPOT_PITCH = 40;
|
|
3468
|
+
var SNAP_DISTANCE = 8;
|
|
3469
|
+
var STEP = 1;
|
|
3470
|
+
var mid = (r, axis) => axis === "x" ? r.x + r.width / 2 : r.y + r.height / 2;
|
|
3471
|
+
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
3472
|
+
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
3473
|
+
var hull2 = (a, b) => {
|
|
3474
|
+
const x = Math.min(a.x, b.x);
|
|
3475
|
+
const y = Math.min(a.y, b.y);
|
|
3476
|
+
return rect17(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
|
|
3477
|
+
};
|
|
3478
|
+
var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
3479
|
+
var sameRect = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.5;
|
|
3480
|
+
var ORIGIN = { x: 0, y: 0 };
|
|
3481
|
+
function onEdge(l, edge, dragged, axis) {
|
|
3482
|
+
return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS20 && it.rect.height > EPS20).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
|
|
3483
|
+
}
|
|
3484
|
+
function neighbors(after, edge, dragged, axis) {
|
|
3485
|
+
const me = after.items[dragged];
|
|
3486
|
+
const others = onEdge(after, edge, dragged, axis);
|
|
3487
|
+
const at = me ? mid(me.rect, axis) : 0;
|
|
3488
|
+
return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
|
|
3489
|
+
}
|
|
3490
|
+
function givesWay(now, after, lane, side, extent) {
|
|
3491
|
+
if (!now) return null;
|
|
3492
|
+
if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
|
|
3493
|
+
const [p0, p1] = extent(now.rect);
|
|
3494
|
+
const [q0, q1] = extent(after.rect);
|
|
3495
|
+
if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
|
|
3496
|
+
return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
|
|
3497
|
+
}
|
|
3498
|
+
function liftedLayout(state, dragged, options) {
|
|
3499
|
+
return solve(liftItem(state, dragged), options.previous ? { previous: options.previous } : {});
|
|
3500
|
+
}
|
|
3501
|
+
function othersKey(layout, dragged) {
|
|
3502
|
+
return Object.keys(layout.items).filter((id) => id !== dragged).sort().map((id) => {
|
|
3503
|
+
const it = layout.items[id];
|
|
3504
|
+
return it.inMenu ? `${id}:m` : `${id}:${Math.round(it.rect.x)},${Math.round(it.rect.y)},${Math.round(it.rect.width)},${Math.round(it.rect.height)}`;
|
|
3505
|
+
}).join(";");
|
|
3506
|
+
}
|
|
3507
|
+
function clipAtDrawn(band, axis, cuts) {
|
|
3508
|
+
let a = lo(band, axis);
|
|
3509
|
+
let b = a + len(band, axis);
|
|
3510
|
+
const center = (a + b) / 2;
|
|
3511
|
+
const x = axis === "x" ? "y" : "x";
|
|
3512
|
+
const line = lo(band, x) + len(band, x) / 2;
|
|
3513
|
+
for (const c of cuts) {
|
|
3514
|
+
if (!(lo(c, x) < line - EPS20 && line < lo(c, x) + len(c, x) - EPS20)) continue;
|
|
3515
|
+
const c0 = lo(c, axis);
|
|
3516
|
+
const c1 = c0 + len(c, axis);
|
|
3517
|
+
if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
|
|
3518
|
+
else b = Math.min(b, c0);
|
|
3519
|
+
}
|
|
3520
|
+
return b - a > EPS20 ? along(band, axis, a, b) : band;
|
|
3521
|
+
}
|
|
3522
|
+
var memo = /* @__PURE__ */ new WeakMap();
|
|
3523
|
+
var previousIds = /* @__PURE__ */ new WeakMap();
|
|
3524
|
+
var nextPrevious = 1;
|
|
3525
|
+
function keyOf(dragged, o) {
|
|
3526
|
+
const { previous, spot: _spot, ...rest } = o;
|
|
3527
|
+
let p = 0;
|
|
3528
|
+
if (previous) {
|
|
3529
|
+
if (!previousIds.has(previous)) previousIds.set(previous, nextPrevious++);
|
|
3530
|
+
p = previousIds.get(previous);
|
|
3531
|
+
}
|
|
3532
|
+
return `${dragged}\0${p}\0${JSON.stringify(rest)}`;
|
|
3533
|
+
}
|
|
3534
|
+
function lanes(state, dragged, options = {}) {
|
|
3535
|
+
const key = keyOf(dragged, options);
|
|
3536
|
+
let perState = memo.get(state);
|
|
3537
|
+
if (!perState) memo.set(state, perState = /* @__PURE__ */ new Map());
|
|
3538
|
+
let base = perState.get(key);
|
|
3539
|
+
if (!base) perState.set(key, base = build(state, dragged, options));
|
|
3540
|
+
if (!options.spot) return { ...base.regions, lanes: base.lanes };
|
|
3541
|
+
const found = [...base.raws].find(([, rs]) => rs.some((r) => r.id === options.spot));
|
|
3542
|
+
if (!found) return { ...base.regions, lanes: base.lanes };
|
|
3543
|
+
const [heldLane, list] = found;
|
|
3544
|
+
const held = list.find((r) => r.id === options.spot);
|
|
3545
|
+
const rebuilt = base.lanes.map((l) => {
|
|
3546
|
+
const raws = base.raws.get(l.id);
|
|
3547
|
+
if (!raws) return asDrawn(l);
|
|
3548
|
+
const again = l.id === heldLane ? heldLaneIn(l.id, raws, held, base, dragged) : laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, false, true);
|
|
3549
|
+
if (!again) return asDrawn(l);
|
|
3550
|
+
return l.id === heldLane ? again : { ...asDrawn(l), marks: again.marks };
|
|
3551
|
+
});
|
|
3552
|
+
const drawn = rebuilt.map((l) => settle(l, held.layout, state, dragged, rebuilt, options.emptyLanes, base.raws.get(l.id) ? laneRectOver(base.raws.get(l.id), held.layout, base.seen, base.marking).rect : l.rect));
|
|
3553
|
+
const heldMarks = drawn.find((l) => l.id === heldLane)?.marks.map((m) => m.rect) ?? [];
|
|
3554
|
+
return {
|
|
3555
|
+
...base.regions,
|
|
3556
|
+
lanes: drawn.map((l, i) => {
|
|
3557
|
+
if (l.id === heldLane || !base.predicted.has(l.id)) return l;
|
|
3558
|
+
return { ...l, marks: marksLess(base.lanes[i].marks, l.axis, heldMarks) };
|
|
3559
|
+
})
|
|
3560
|
+
};
|
|
3561
|
+
}
|
|
3562
|
+
function asDrawn(l) {
|
|
3563
|
+
if (!l.entry && !l.corners) return l;
|
|
3564
|
+
const { entry: _entry, corners: _corners, ...rest } = l;
|
|
3565
|
+
return rest;
|
|
3566
|
+
}
|
|
3567
|
+
function heldLaneIn(id, raws, held, base, dragged) {
|
|
3568
|
+
return laneFrom(id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(id), base.share, base.marking, !held.slide, true);
|
|
3569
|
+
}
|
|
3570
|
+
function build(state, dragged, options) {
|
|
3571
|
+
const seen = solve(state, options.previous ? { previous: options.previous } : {});
|
|
3572
|
+
const { targets: ts, refusals: rs } = targetsAndRefusals(state, dragged, options);
|
|
3573
|
+
const own = seen.items[dragged];
|
|
3574
|
+
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
3575
|
+
const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
|
|
3576
|
+
const raws = [];
|
|
3577
|
+
const axisOfEdge = (id) => {
|
|
3578
|
+
const e = state.edges.find((x) => x.id === id);
|
|
3579
|
+
return e && axisOf(e.side) === "column" ? "y" : "x";
|
|
3580
|
+
};
|
|
3581
|
+
const columnKey = (side, ring) => state.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
|
|
3582
|
+
for (const t of ts) {
|
|
3583
|
+
if (t.free) continue;
|
|
3584
|
+
const p = t.place;
|
|
3585
|
+
if (p.kind === "gap" || p.kind === "home" && ownEdge) {
|
|
3586
|
+
const edge = p.kind === "gap" ? p.edge : ownEdge;
|
|
3587
|
+
const axis = axisOfEdge(edge);
|
|
3588
|
+
const layout = p.kind === "home" ? seen : t.after(ORIGIN, ORIGIN).layout;
|
|
3589
|
+
const landing = p.kind === "home" ? own.rect : layout.items[dragged]?.rect;
|
|
3590
|
+
if (!landing) continue;
|
|
3591
|
+
const zone = p.kind === "gap" ? p.zone : own?.zone ?? "start";
|
|
3592
|
+
const n = neighbors(layout, edge, dragged, axis);
|
|
3593
|
+
const id = n.before === "^" && n.next === "$" ? `${edge}/${zone}` : `${edge}/${zone}/${n.before}|${n.next}`;
|
|
3594
|
+
raws.push({ lane: edge, edge, axis, id, ...n, landing, layout, target: t, hit: t.hit, ...p.kind === "home" ? { home: true } : {} });
|
|
3595
|
+
} else if (p.kind === "column" || p.kind === "rail") {
|
|
3596
|
+
const layout = t.after(ORIGIN, ORIGIN).layout;
|
|
3597
|
+
const landing = layout.items[dragged]?.rect;
|
|
3598
|
+
if (!landing) continue;
|
|
3599
|
+
const lane = p.kind === "column" ? `column:${p.side}:${columnKey(p.side, p.ring)}` : `rail:${p.side}`;
|
|
3600
|
+
const strip = p.kind === "rail" && t.strip ? t.strip : void 0;
|
|
3601
|
+
raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: strip ?? t.hit, ...strip ? { strip: true } : {} });
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
const lifted = liftedLayout(state, dragged, options);
|
|
3605
|
+
if (options.stretchPositions !== "pitched") {
|
|
3606
|
+
const { spots, absorbed } = slidingSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH);
|
|
3607
|
+
for (let i = raws.length - 1; i >= 0; i--) if (absorbed.has(raws[i])) raws.splice(i, 1);
|
|
3608
|
+
raws.push(...spots);
|
|
3609
|
+
} else if (pitch > 0) raws.push(...pitchedSpots(state, dragged, options, seen, lifted, raws, pitch));
|
|
3610
|
+
raws.push(...takeoverSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH));
|
|
3611
|
+
const byLane = /* @__PURE__ */ new Map();
|
|
3612
|
+
for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
|
|
3613
|
+
const halves = new Set(state.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
|
|
3614
|
+
const marking = {
|
|
3615
|
+
pitch,
|
|
3616
|
+
natural: (id, axis) => {
|
|
3617
|
+
const main = state.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
|
|
3618
|
+
return main?.grows ? main.natural : void 0;
|
|
3619
|
+
},
|
|
3620
|
+
gap: (edge) => nonNeg(state.edges.find((e) => e.id === edge)?.gap),
|
|
3621
|
+
lifted,
|
|
3622
|
+
crossing: (edge, over) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over.edges[e.id]?.cross ?? 0) > EPS20 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over.edges[e.id].rect)
|
|
3623
|
+
};
|
|
3624
|
+
const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS20 ? 0.5 : clamp2(g / size, 0, 1);
|
|
3625
|
+
const w = own?.rect.width ?? 0;
|
|
3626
|
+
const h = own?.rect.height ?? 0;
|
|
3627
|
+
const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
|
|
3628
|
+
const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
|
|
3629
|
+
const settled = built.map((l) => settle(l, seen, state, dragged, built, options.emptyLanes));
|
|
3630
|
+
const laneList = options.emptyLanes === "edge" ? settled : predict(settled, byLane, { seen, refusals: rs, halves, share, marking }, state, dragged, built, options.emptyLanes);
|
|
3631
|
+
const predicted = new Set(laneList.filter((l, i) => l !== settled[i]).map((l) => l.id));
|
|
3632
|
+
const onLanes = new Set(laneList.map((l) => l.id));
|
|
3633
|
+
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS20 && r.rect.height > EPS20 ? [r.rect] : []);
|
|
3634
|
+
const blocked = [
|
|
3635
|
+
...Object.values(seen.edges).filter((e) => e.cross > EPS20).map((e) => e.rect),
|
|
3636
|
+
...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
|
|
3637
|
+
...keepClearFor(state, "targets"),
|
|
3638
|
+
...rails,
|
|
3639
|
+
// Spots where a release cancels (`DockState.blocked`): no float lands there.
|
|
3640
|
+
...state.blocked ?? []
|
|
3641
|
+
];
|
|
3642
|
+
return {
|
|
3643
|
+
raws: byLane,
|
|
3644
|
+
lanes: laneList,
|
|
3645
|
+
seen,
|
|
3646
|
+
refusals: rs,
|
|
3647
|
+
halves,
|
|
3648
|
+
share,
|
|
3649
|
+
marking,
|
|
3650
|
+
predicted,
|
|
3651
|
+
regions: {
|
|
3652
|
+
refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
|
|
3653
|
+
content: floatRegion(state, dragged),
|
|
3654
|
+
blocked,
|
|
3655
|
+
stage: state.stage,
|
|
3656
|
+
floatRegion: floatRegion(state, dragged),
|
|
3657
|
+
item: own ? { width: own.rect.width, height: own.rect.height } : { width: 0, height: 0 },
|
|
3658
|
+
float: ts.find((t) => t.free) ?? null,
|
|
3659
|
+
refusals: rs
|
|
3660
|
+
}
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
function laneRectOver(list, over, seen, marking) {
|
|
3664
|
+
const first = list[0];
|
|
3665
|
+
const axis = first.axis;
|
|
3666
|
+
const edgeLayout = first.edge ? over.edges[first.edge] : void 0;
|
|
3667
|
+
const band = list.map((r) => r.landing).reduce(hull2);
|
|
3668
|
+
if (!edgeLayout) return { rect: list.every((r) => r.strip) ? list.map((r) => r.hit).reduce(hull2) : list.map((r) => r.hit).reduce(hull2, band) };
|
|
3669
|
+
const drawnHere = edgeLayout.cross > EPS20;
|
|
3670
|
+
const whole = drawnHere ? edgeLayout.rect : axis === "x" ? rect17(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect17(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
|
|
3671
|
+
const emptyAsSeen = (seen.edges[first.edge]?.cross ?? 0) <= EPS20;
|
|
3672
|
+
const clipped = emptyAsSeen ? clipAtDrawn(whole, axis, marking.crossing(first.edge, seen)) : whole;
|
|
3673
|
+
return drawnHere ? { rect: clipped } : { rect: clipped, band: whole };
|
|
3674
|
+
}
|
|
3675
|
+
function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, heldHere = false, spotHeld = false) {
|
|
3676
|
+
if (list.length === 0) return null;
|
|
3677
|
+
const first = list[0];
|
|
3678
|
+
const axis = first.axis;
|
|
3679
|
+
const { rect: laneRect, band: markBand } = laneRectOver(list, seen, seen, marking);
|
|
3680
|
+
const firstOf = (r) => r.slide?.first ?? r.landing;
|
|
3681
|
+
const lastOf = (r) => r.slide?.last ?? r.landing;
|
|
3682
|
+
const sorted = [...list].sort((a, b) => mid(firstOf(a), axis) - mid(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0));
|
|
3683
|
+
const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
|
|
3684
|
+
const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
|
|
3685
|
+
const unique = [];
|
|
3686
|
+
for (const x of sorted) {
|
|
3687
|
+
if (nearHome(x)) continue;
|
|
3688
|
+
const k = unique.findIndex((y) => !x.slide && !y.slide && sameRect(y.landing, x.landing) || y.id === x.id);
|
|
3689
|
+
if (k < 0) unique.push(x);
|
|
3690
|
+
else if (x.home && !unique[k].home && !unique.some((y) => y.id === x.id && y !== unique[k])) unique[k] = x;
|
|
3691
|
+
}
|
|
3692
|
+
const start = lo(laneRect, axis);
|
|
3693
|
+
const end = start + len(laneRect, axis);
|
|
3694
|
+
const whole = markBand ?? laneRect;
|
|
3695
|
+
const bandStart = lo(whole, axis);
|
|
3696
|
+
const bandEnd = bandStart + len(whole, axis);
|
|
3697
|
+
const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
|
|
3698
|
+
const held = halves ? 0.5 : share[axis];
|
|
3699
|
+
const cuts = [];
|
|
3700
|
+
for (let i = 0; i + 1 < unique.length; i++) {
|
|
3701
|
+
const a = unique[i];
|
|
3702
|
+
const b = unique[i + 1];
|
|
3703
|
+
const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
|
|
3704
|
+
const aLanding = lastOf(a);
|
|
3705
|
+
const bLanding = firstOf(b);
|
|
3706
|
+
const aEnd = lo(aLanding, axis) + len(aLanding, axis);
|
|
3707
|
+
const across2 = (aEnd + lo(bLanding, axis)) / 2;
|
|
3708
|
+
const overlap = lo(bLanding, axis) < aEnd - EPS20;
|
|
3709
|
+
const slack = Math.max(0, marking.pitch) / 2;
|
|
3710
|
+
const atGrab = clamp2(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
|
|
3711
|
+
const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
|
|
3712
|
+
cuts.push(clamp2(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
|
|
3713
|
+
}
|
|
3714
|
+
const spots = unique.flatMap((x, i) => {
|
|
3715
|
+
const a = i === 0 ? bandStart : cuts[i - 1];
|
|
3716
|
+
const b = i === unique.length - 1 ? bandEnd : cuts[i];
|
|
3717
|
+
const along2 = [clamp2(a, start, end), clamp2(b, start, end)];
|
|
3718
|
+
return along2[1] - along2[0] > EPS20 || b - a <= EPS20 || x.home ? [{ x, along: along2 }] : [];
|
|
3719
|
+
}).map(({ x, along: along2 }) => ({
|
|
3720
|
+
id: x.id,
|
|
3721
|
+
along: along2,
|
|
3722
|
+
landing: x.landing,
|
|
3723
|
+
target: x.target,
|
|
3724
|
+
...x.home ? { home: true } : {},
|
|
3725
|
+
...x.pitched ? { pitched: true } : {},
|
|
3726
|
+
...x.slide ? { slide: { from: x.slide.from, to: x.slide.to, snaps: x.slide.snaps, snapDistance: x.slide.snapDistance, step: x.slide.step } } : {},
|
|
3727
|
+
others: othersKey(x.layout, dragged)
|
|
3728
|
+
}));
|
|
3729
|
+
const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
|
|
3730
|
+
const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp2(lo(h, axis), start, end), clamp2(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS20) : [];
|
|
3731
|
+
const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
|
|
3732
|
+
const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
|
|
3733
|
+
const markRect = drawnEdge && drawnEdge.cross > EPS20 ? drawnEdge.rect : markBand ?? laneRect;
|
|
3734
|
+
const marked = first.edge ? onEdge(drawn, first.edge, heldHere ? "" : dragged, axis).map((o) => {
|
|
3735
|
+
const n = o.id === dragged || halves ? void 0 : marking.natural(o.id, axis);
|
|
3736
|
+
return n !== void 0 && n < len(o.r, axis) ? { ...o, r: along(o.r, axis, lo(o.r, axis), lo(o.r, axis) + n) } : o;
|
|
3737
|
+
}) : [];
|
|
3738
|
+
const landings = /* @__PURE__ */ new Map();
|
|
3739
|
+
if (!halves) {
|
|
3740
|
+
for (const x of unique) if (!x.pitched && !x.home && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
|
|
3741
|
+
}
|
|
3742
|
+
const extent = (iid, r) => {
|
|
3743
|
+
const n = halves ? void 0 : marking.natural(iid, axis);
|
|
3744
|
+
return [lo(r, axis), lo(r, axis) + (n !== void 0 && n < len(r, axis) ? n : len(r, axis))];
|
|
3745
|
+
};
|
|
3746
|
+
const marks = first.edge ? edgeMarks(id, markRect, axis, marked, refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged, {
|
|
3747
|
+
besideMin: halves || marking.pitch <= 0 ? itemLen : marking.pitch,
|
|
3748
|
+
gap: marking.gap(first.edge),
|
|
3749
|
+
landingOf: (pair) => landings.get(pair),
|
|
3750
|
+
// Judged against the layout the marks are drawn in; with a spot held, against the layout as seen with the held
|
|
3751
|
+
// item lifted (in the spot's own a neighbor has already stepped down or moved).
|
|
3752
|
+
givesWay: (iid, side, after) => givesWay((spotHeld ? marking.lifted : drawn).items[iid], after.items[iid], id, side, (r) => extent(iid, r))
|
|
3753
|
+
}) : virtualMarks(id, unique, drawn.items[dragged]);
|
|
3754
|
+
return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
|
|
3755
|
+
}
|
|
3756
|
+
var along = (r, axis, a, b) => axis === "x" ? rect17(a, r.y, b - a, r.height) : rect17(r.x, a, r.width, b - a);
|
|
3757
|
+
var LINE2 = 2;
|
|
3758
|
+
var MIN_BOX = 8;
|
|
3759
|
+
var HATCH_END = 8;
|
|
3760
|
+
var HATCH_EDGE = 8;
|
|
3761
|
+
function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
|
|
3762
|
+
const { besideMin } = more;
|
|
3763
|
+
const hatches = (pair, a, b, p, q, gl, gr) => {
|
|
3764
|
+
if (gl && Math.abs(p - a) < EPS20) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
|
|
3765
|
+
if (gr && Math.abs(q - b) < EPS20) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
|
|
3766
|
+
};
|
|
3767
|
+
const heldAt = items.find((o) => o.id === held);
|
|
3768
|
+
const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
|
|
3769
|
+
const out = [];
|
|
3770
|
+
const start = lo(laneRect, axis);
|
|
3771
|
+
const end = start + len(laneRect, axis);
|
|
3772
|
+
const ends = [{ id: "^", a: start, b: start }, ...items.map((o) => ({ id: o.id, a: lo(o.r, axis), b: lo(o.r, axis) + len(o.r, axis) })), { id: "$", a: end, b: end }];
|
|
3773
|
+
const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
|
|
3774
|
+
for (let i = 0; i + 1 < ends.length; i++) {
|
|
3775
|
+
const a = clamp2(ends[i].b, start, end);
|
|
3776
|
+
const b = clamp2(ends[i + 1].a, start, end);
|
|
3777
|
+
const pair = `${ends[i].id}|${ends[i + 1].id}`;
|
|
3778
|
+
if (ends[i + 1].a < start - EPS20 || ends[i].b > end + EPS20 || !lands(pair)) continue;
|
|
3779
|
+
const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
|
|
3780
|
+
const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
|
|
3781
|
+
const named = `${left}|${right}`;
|
|
3782
|
+
const beside = ends[i + 1].id === held ? "before" : ends[i].id === held ? "after" : null;
|
|
3783
|
+
const min = beside ? Math.min(itemLen, besideMin) : itemLen;
|
|
3784
|
+
const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
|
|
3785
|
+
const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
|
|
3786
|
+
const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
|
|
3787
|
+
if (b - a < min - EPS20) {
|
|
3788
|
+
if (spot && b - a >= besideMin - EPS20) {
|
|
3789
|
+
let ps = [[a, b]];
|
|
3790
|
+
for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
|
|
3791
|
+
if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
|
|
3792
|
+
ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS20);
|
|
3793
|
+
ps.forEach(([p, q], k2) => {
|
|
3794
|
+
out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
3795
|
+
hatches(pair, a, b, p, q, gl, gr);
|
|
3796
|
+
});
|
|
3797
|
+
if (ps.length > 0) continue;
|
|
3798
|
+
}
|
|
3799
|
+
const t = Math.max(0, Math.min(LINE2, b - a)) / 2;
|
|
3800
|
+
if (items.length > 0 && named === pair && !isRefused2((a + b) / 2)) out.push({ id: `${lane}/line/${pair}`, kind: "line", rect: along(laneRect, axis, (a + b) / 2 - t, (a + b) / 2 + t) });
|
|
3801
|
+
continue;
|
|
3802
|
+
}
|
|
3803
|
+
let pieces = [[a, b]];
|
|
3804
|
+
for (const f of refused) pieces = pieces.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]).filter(([p, q]) => q - p > EPS20);
|
|
3805
|
+
let k = 0;
|
|
3806
|
+
for (const [p, q] of pieces) {
|
|
3807
|
+
if (q - p < min - EPS20) continue;
|
|
3808
|
+
const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
|
|
3809
|
+
out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
3810
|
+
hatches(pair, a, b, p, q, gl, gr);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
return out;
|
|
3814
|
+
}
|
|
3815
|
+
function virtualMarks(lane, spots, held) {
|
|
3816
|
+
return spots.map((s) => {
|
|
3817
|
+
const l = s.landing;
|
|
3818
|
+
if (!held || held.floating || !overlaps7(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
|
|
3819
|
+
const x = mid(held.rect, "x") < mid(l, "x") ? l.x + l.width : l.x;
|
|
3820
|
+
return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect17(x, l.y, 0, l.height) };
|
|
3821
|
+
});
|
|
3822
|
+
}
|
|
3823
|
+
function inLane(l, r) {
|
|
3824
|
+
const marks = l.marks.flatMap((m) => {
|
|
3825
|
+
const x0 = Math.max(m.rect.x, r.x);
|
|
3826
|
+
const y0 = Math.max(m.rect.y, r.y);
|
|
3827
|
+
const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
|
|
3828
|
+
const y1 = Math.min(m.rect.y + m.rect.height, r.y + r.height);
|
|
3829
|
+
if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS20 && y1 - y0 >= m.rect.height - EPS20 ? [m] : [];
|
|
3830
|
+
if (x1 - x0 <= EPS20 || y1 - y0 <= EPS20) return [];
|
|
3831
|
+
return x1 - x0 >= m.rect.width - EPS20 && y1 - y0 >= m.rect.height - EPS20 ? [m] : [{ ...m, rect: rect17(x0, y0, x1 - x0, y1 - y0) }];
|
|
3832
|
+
});
|
|
3833
|
+
return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
|
|
3834
|
+
}
|
|
3835
|
+
function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within = lane.rect) {
|
|
3836
|
+
const l = inLane(lane, within);
|
|
3837
|
+
const edgeOf = (id) => state.edges.find((e) => e.id === id);
|
|
3838
|
+
const isDrawn = (id) => !!edgeOf(id) && (drawn.edges[id]?.cross ?? 0) > EPS20;
|
|
3839
|
+
const across2 = (side) => side === "top" || side === "bottom" ? "x" : "y";
|
|
3840
|
+
const cuts = [];
|
|
3841
|
+
if (!isDrawn(l.id)) {
|
|
3842
|
+
for (const e of state.edges) {
|
|
3843
|
+
const de = drawn.edges[e.id];
|
|
3844
|
+
if (e.id !== l.id && de && de.cross > EPS20 && across2(e.side) !== l.axis) cuts.push(de.rect);
|
|
3845
|
+
}
|
|
3846
|
+
if (l.axis === "y") {
|
|
3847
|
+
for (const o of all) if (o.id !== l.id && o.axis === "x" && !isDrawn(o.id)) cuts.push(o.rect);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
const empty = !isDrawn(l.id);
|
|
3851
|
+
const barOrRail = (edge) => {
|
|
3852
|
+
const e = edge ? edgeOf(edge) : void 0;
|
|
3853
|
+
return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
|
|
3854
|
+
};
|
|
3855
|
+
const stays = empty ? Object.entries(drawn.items).filter(([id, it]) => id !== dragged && it.edge !== l.id && barOrRail(it.edge) && !it.floating && !it.inMenu && it.rect.width > EPS20 && it.rect.height > EPS20).map(([, it]) => it.rect) : [];
|
|
3856
|
+
if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps7(m.rect, s)))))) return l;
|
|
3857
|
+
const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
|
|
3858
|
+
const marks = [];
|
|
3859
|
+
for (const m of l.marks) {
|
|
3860
|
+
const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
|
|
3861
|
+
if (m.kind === "line") {
|
|
3862
|
+
if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS20) marks.push(m);
|
|
3863
|
+
continue;
|
|
3864
|
+
}
|
|
3865
|
+
kept.forEach(([p, q], i) => {
|
|
3866
|
+
const piece = along(m.rect, l.axis, p, q);
|
|
3867
|
+
const id = i ? `${m.id}~c${i}` : m.id;
|
|
3868
|
+
if (m.kind !== "box" || !empty || emptyLanes === "real") return void marks.push({ ...m, id, rect: piece });
|
|
3869
|
+
const side = edgeOf(l.id)?.side ?? (/^(rail|column):/.test(l.id) ? l.id.split(":")[1] : void 0);
|
|
3870
|
+
const st = state.stage;
|
|
3871
|
+
let r;
|
|
3872
|
+
if (l.axis === "y") {
|
|
3873
|
+
const outerRight = side === "right" ? true : side === "left" ? false : Math.abs(piece.x + piece.width - (st.x + st.width)) <= Math.abs(piece.x - st.x);
|
|
3874
|
+
const t = Math.min(HATCH_EDGE, piece.width);
|
|
3875
|
+
r = rect17(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
|
|
3876
|
+
} else {
|
|
3877
|
+
const outerBottom = side === "bottom" ? true : side === "top" ? false : Math.abs(piece.y + piece.height - (st.y + st.height)) <= Math.abs(piece.y - st.y);
|
|
3878
|
+
const t = Math.min(HATCH_EDGE, piece.height);
|
|
3879
|
+
r = rect17(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
|
|
3880
|
+
}
|
|
3881
|
+
marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
return { ...l, marks };
|
|
3885
|
+
}
|
|
3886
|
+
function piecesLess(r, axis, cs) {
|
|
3887
|
+
const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
|
|
3888
|
+
const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS20 && r.y < c.y + c.height - EPS20 : c.x < r.x + r.width - EPS20 && r.x < c.x + c.width - EPS20;
|
|
3889
|
+
let ps = [span(r)];
|
|
3890
|
+
for (const c of cs) {
|
|
3891
|
+
if (!crosses(c)) continue;
|
|
3892
|
+
const [c0, c1] = span(c);
|
|
3893
|
+
ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS20);
|
|
3894
|
+
}
|
|
3895
|
+
return ps;
|
|
3896
|
+
}
|
|
3897
|
+
function marksLess(marks, axis, cs) {
|
|
3898
|
+
return marks.flatMap((m) => {
|
|
3899
|
+
const over = cs.filter((c) => overlaps7(m.rect, c));
|
|
3900
|
+
if (over.length === 0) return [m];
|
|
3901
|
+
const kept = piecesLess(m.rect, axis, over);
|
|
3902
|
+
if (m.kind === "line") return kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS20 ? [m] : [];
|
|
3903
|
+
return kept.map(([p, q], i) => ({ ...m, id: i ? `${m.id}~c${i}` : m.id, rect: along(m.rect, axis, p, q) }));
|
|
3904
|
+
});
|
|
3905
|
+
}
|
|
3906
|
+
function predict(settled, byLane, base, state, dragged, built, emptyLanes) {
|
|
3907
|
+
const whole = /* @__PURE__ */ new Map();
|
|
3908
|
+
for (const l of settled) {
|
|
3909
|
+
const raws = byLane.get(l.id);
|
|
3910
|
+
if (!raws || l.spots.length !== 1 || !state.edges.some((e) => e.id === l.id) || (base.seen.edges[l.id]?.cross ?? 0) > EPS20) continue;
|
|
3911
|
+
const held = raws.find((r) => r.id === l.spots[0].id);
|
|
3912
|
+
if (!held || (held.layout.edges[l.id]?.cross ?? 0) <= EPS20) continue;
|
|
3913
|
+
const again = heldLaneIn(l.id, raws, held, base, dragged);
|
|
3914
|
+
if (!again) continue;
|
|
3915
|
+
const after = settle(again, held.layout, state, dragged, built, emptyLanes, laneRectOver(raws, held.layout, base.seen, base.marking).rect).marks;
|
|
3916
|
+
whole.set(l.id, after.length === 0 && l.marks.length > 0 ? l.marks : after);
|
|
3917
|
+
}
|
|
3918
|
+
if (whole.size === 0) return [...settled];
|
|
3919
|
+
const order = [...settled].filter((l) => whole.has(l.id)).sort((a, b) => a.axis === b.axis ? 0 : a.axis === "x" ? -1 : 1);
|
|
3920
|
+
const final = new Map(settled.filter((l) => !whole.has(l.id)).map((l) => [l.id, l.marks]));
|
|
3921
|
+
const meets = /* @__PURE__ */ new Map();
|
|
3922
|
+
for (const l of order) {
|
|
3923
|
+
const mine = whole.get(l.id);
|
|
3924
|
+
const others = [...final].filter(([id, ms]) => id !== l.id && ms.some((m) => mine.some((x) => overlaps7(x.rect, m.rect))));
|
|
3925
|
+
meets.set(l.id, others.map(([id]) => id));
|
|
3926
|
+
final.set(l.id, marksLess(mine, l.axis, others.flatMap(([, ms]) => ms.map((m) => m.rect))));
|
|
3927
|
+
}
|
|
3928
|
+
return settled.map((l) => {
|
|
3929
|
+
const marks = final.get(l.id);
|
|
3930
|
+
const mine = whole.get(l.id);
|
|
3931
|
+
if (!mine) return l;
|
|
3932
|
+
const corners = meets.get(l.id);
|
|
3933
|
+
return corners.length > 0 ? { ...l, marks, entry: mine, corners } : { ...l, marks };
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
var overlaps7 = (a, b) => a.x < b.x + b.width - EPS20 && b.x < a.x + a.width - EPS20 && a.y < b.y + b.height - EPS20 && b.y < a.y + a.height - EPS20;
|
|
3937
|
+
function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
3938
|
+
const out = [];
|
|
3939
|
+
stretches(state, dragged, options, seen, lifted, raws, (run) => {
|
|
3940
|
+
const { e, axis, gap, middle } = run;
|
|
3941
|
+
const taken = run.mine.map((r) => r.landing);
|
|
3942
|
+
const emit3 = (zone, at, space, x0, flush) => {
|
|
3943
|
+
const hit = landsAt(state, dragged, run, { edge: e.id, zone, at, space }, x0);
|
|
3944
|
+
if (!hit) return false;
|
|
3945
|
+
const { next, layout } = hit;
|
|
3946
|
+
const landed = layout.items[dragged];
|
|
3947
|
+
const nb = flush !== void 0 ? layout.items[flush] : void 0;
|
|
3948
|
+
if (nb && Math.abs(lo(nb.rect, axis) + len(nb.rect, axis) + gap - lo(landed.rect, axis)) > 1 && Math.abs(lo(landed.rect, axis) + len(landed.rect, axis) + gap - lo(nb.rect, axis)) > 1) return false;
|
|
3949
|
+
const n = neighbors(layout, e.id, dragged, axis);
|
|
3950
|
+
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return true;
|
|
3951
|
+
taken.push(landed.rect);
|
|
3952
|
+
const result = { state: next, layout };
|
|
3953
|
+
const kept = Math.round(next.items[dragged]?.space ?? 0);
|
|
3954
|
+
const target = { id: `pitch:${e.id}:${zone}:${at}:${Math.round(space)}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
|
|
3955
|
+
const id = `${e.id}/${zone}/${n.before}|${n.next}@${flush !== void 0 && kept > 0 ? `to:${flush}` : Math.round(kept / pitch)}`;
|
|
3956
|
+
out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
|
|
3957
|
+
return true;
|
|
3958
|
+
};
|
|
3959
|
+
return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
|
|
3960
|
+
const end = (x0, order, flush) => {
|
|
3961
|
+
for (const zone of order) if (spaceAt(zone, x0) >= -EPS20 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
|
|
3962
|
+
};
|
|
3963
|
+
end(a, zones, before?.id ?? "^");
|
|
3964
|
+
if (b - w > a + EPS20) end(b - w, [...zones].reverse(), after?.id ?? "$");
|
|
3965
|
+
if (b - a < w + pitch) return;
|
|
3966
|
+
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS20; x0 += pitch) {
|
|
3967
|
+
const zone = x0 + w / 2 < middle ? "start" : "end";
|
|
3968
|
+
if (!zones.includes(zone)) continue;
|
|
3969
|
+
emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
});
|
|
3973
|
+
return out;
|
|
3974
|
+
}
|
|
3975
|
+
function stretches(state, dragged, options, seen, lifted, raws, visit) {
|
|
3976
|
+
if (!state.items[dragged]) return;
|
|
3977
|
+
const prev = options.previous ? { previous: options.previous } : {};
|
|
3978
|
+
const base = lifted;
|
|
3979
|
+
for (const e of state.edges) {
|
|
3980
|
+
const bar = e.side === "top" || e.side === "bottom";
|
|
3981
|
+
if (!bar && !e.compact) continue;
|
|
3982
|
+
const axis = bar ? "x" : "y";
|
|
3983
|
+
const mine = raws.filter((r) => r.edge === e.id);
|
|
3984
|
+
const drawn = base.edges[e.id] ?? seen.edges[e.id];
|
|
3985
|
+
if (mine.length === 0 || !drawn) continue;
|
|
3986
|
+
const gap = nonNeg(e.gap);
|
|
3987
|
+
const others = onEdge(base, e.id, dragged, axis);
|
|
3988
|
+
const zoneOf2 = (o) => o.zone ?? "start";
|
|
3989
|
+
const w = len(mine[0].landing, axis);
|
|
3990
|
+
const each = visit({ e, axis, w, gap, middle: mid(drawn.rect, axis), mine, fixed: others.filter((o) => state.items[o.id]?.fixed), prev });
|
|
3991
|
+
const slack = (o) => {
|
|
3992
|
+
const main = o ? state.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
|
|
3993
|
+
return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
|
|
3994
|
+
};
|
|
3995
|
+
const ends = (l, before, after) => {
|
|
3996
|
+
const at = (o) => {
|
|
3997
|
+
const it = l.items[o.id];
|
|
3998
|
+
return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
|
|
3999
|
+
};
|
|
4000
|
+
const rb = before ? at(before) : void 0;
|
|
4001
|
+
const ra = after ? at(after) : void 0;
|
|
4002
|
+
if (rb === null || ra === null) return null;
|
|
4003
|
+
const el = l.edges[e.id]?.rect ?? drawn.rect;
|
|
4004
|
+
return {
|
|
4005
|
+
a: before && rb ? lo(rb, axis) + len(rb, axis) - slack({ ...before, r: rb }) + gap : lo(el, axis) + nonNeg(e.pad?.start),
|
|
4006
|
+
// (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
|
|
4007
|
+
b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
|
|
4008
|
+
};
|
|
4009
|
+
};
|
|
4010
|
+
for (let i = 0; i <= others.length; i++) {
|
|
4011
|
+
const before = others[i - 1];
|
|
4012
|
+
const after = others[i];
|
|
4013
|
+
const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
|
|
4014
|
+
const atOf = (zone) => others.slice(0, i).filter((o) => zoneOf2(o) === zone).length;
|
|
4015
|
+
const probe = (() => {
|
|
4016
|
+
const zone = zones[0];
|
|
4017
|
+
if (!zone) return null;
|
|
4018
|
+
const next = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
|
|
4019
|
+
if (next === state) return null;
|
|
4020
|
+
const l = solve(next, prev);
|
|
4021
|
+
const landed = l.items[dragged];
|
|
4022
|
+
if (!landed || landed.inMenu || landed.edge !== e.id) return null;
|
|
4023
|
+
const n = neighbors(l, e.id, dragged, axis);
|
|
4024
|
+
if (n.before !== (before?.id ?? "^") || n.next !== (after?.id ?? "$")) return null;
|
|
4025
|
+
const r = ends(l, before, after);
|
|
4026
|
+
return r && { ...r, w: len(landed.rect, axis), layout: l };
|
|
4027
|
+
})();
|
|
4028
|
+
const seenEnds = ends(base, before, after);
|
|
4029
|
+
const pushed = (o, side) => !!o && !!probe && givesWay(base.items[o.id], probe.layout.items[o.id], e.id, side, (r) => [lo(r, axis), lo(r, axis) + len(r, axis) - slack({ ...o, r })]) === "moves";
|
|
4030
|
+
const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : seenEnds.a;
|
|
4031
|
+
const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : seenEnds.b;
|
|
4032
|
+
const wi = probe?.w ?? w;
|
|
4033
|
+
each({ before, after, a, b, w: wi, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + wi) });
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
4038
|
+
const out = [];
|
|
4039
|
+
stretches(state, dragged, options, seen, lifted, raws, (run) => {
|
|
4040
|
+
const { e, axis } = run;
|
|
4041
|
+
const taken = [...run.mine.map((r) => r.landing)];
|
|
4042
|
+
const emit3 = (zone, at, space, x0, nb) => {
|
|
4043
|
+
const hit = landsAt(state, dragged, run, { edge: e.id, zone, at, space }, x0);
|
|
4044
|
+
if (!hit) return;
|
|
4045
|
+
const { next, layout } = hit;
|
|
4046
|
+
const landed = layout.items[dragged];
|
|
4047
|
+
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return;
|
|
4048
|
+
taken.push(landed.rect);
|
|
4049
|
+
const n = neighbors(layout, e.id, dragged, axis);
|
|
4050
|
+
const result = { state: next, layout };
|
|
4051
|
+
const target = { id: `pitch:${e.id}:${zone}:${at}:in:${nb}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
|
|
4052
|
+
out.push({ lane: e.id, edge: e.id, axis, id: `${e.id}/${zone}/${n.before}|${n.next}@in:${nb}`, ...n, landing: landed.rect, layout, target, hit: landed.rect });
|
|
4053
|
+
};
|
|
4054
|
+
return ({ w, zones, atOf, spaceAt, before, after }) => {
|
|
4055
|
+
const zoneOf2 = (id) => state.items[id]?.align ?? "start";
|
|
4056
|
+
if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !state.items[after.id]?.fixed) {
|
|
4057
|
+
const x0 = lo(after.r, axis);
|
|
4058
|
+
emit3("start", atOf("start"), Math.max(0, spaceAt("start", x0)), x0, after.id);
|
|
4059
|
+
}
|
|
4060
|
+
if (before && zones.includes("end") && zoneOf2(before.id) === "end" && !state.items[before.id]?.fixed) {
|
|
4061
|
+
const x0 = lo(before.r, axis) + len(before.r, axis) - w;
|
|
4062
|
+
emit3("end", atOf("end"), Math.max(0, spaceAt("end", x0)), x0, before.id);
|
|
4063
|
+
}
|
|
4064
|
+
};
|
|
4065
|
+
});
|
|
4066
|
+
return out;
|
|
4067
|
+
}
|
|
4068
|
+
function landsAt(state, dragged, run, place, x0) {
|
|
4069
|
+
const next = moveTo(state, dragged, place);
|
|
4070
|
+
if (next === state) return null;
|
|
4071
|
+
const layout = solve(next, run.prev);
|
|
4072
|
+
const landed = layout.items[dragged];
|
|
4073
|
+
const { axis } = run;
|
|
4074
|
+
if (!landed || landed.inMenu || landed.edge !== run.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
|
|
4075
|
+
if (run.fixed.some((f) => {
|
|
4076
|
+
const r = layout.items[f.id]?.rect;
|
|
4077
|
+
return !r || Math.abs(lo(r, axis) - lo(f.r, axis)) > 1;
|
|
4078
|
+
})) return null;
|
|
4079
|
+
return { next, layout };
|
|
4080
|
+
}
|
|
4081
|
+
function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
4082
|
+
const spots = [];
|
|
4083
|
+
const absorbed = /* @__PURE__ */ new Set();
|
|
4084
|
+
const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
|
|
4085
|
+
const own = seen.items[dragged];
|
|
4086
|
+
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
4087
|
+
stretches(state, dragged, options, seen, lifted, raws, (run) => ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
|
|
4088
|
+
const { e, axis, middle, mine } = run;
|
|
4089
|
+
if (zones.length === 0) return;
|
|
4090
|
+
{
|
|
4091
|
+
const land = (x0) => {
|
|
4092
|
+
const near = x0 + w / 2 < middle ? "start" : "end";
|
|
4093
|
+
for (const zone2 of [near, near === "start" ? "end" : "start"]) {
|
|
4094
|
+
if (!zones.includes(zone2)) continue;
|
|
4095
|
+
const space = spaceAt(zone2, x0);
|
|
4096
|
+
if (space < -EPS20) continue;
|
|
4097
|
+
const place = { edge: e.id, zone: zone2, at: atOf(zone2), space: Math.max(0, space) };
|
|
4098
|
+
const hit = landsAt(state, dragged, run, place, x0);
|
|
4099
|
+
if (hit) return { place, result: { state: hit.next, layout: hit.layout } };
|
|
4100
|
+
}
|
|
4101
|
+
return null;
|
|
4102
|
+
};
|
|
4103
|
+
const tries = [a];
|
|
4104
|
+
for (let x0 = a + sample; x0 < b - w - EPS20; x0 += sample) tries.push(x0);
|
|
4105
|
+
if (b - w > a + EPS20) tries.push(b - w);
|
|
4106
|
+
const ok = tries.map((x0) => ({ x0, hit: land(x0) })).filter((t) => t.hit);
|
|
4107
|
+
if (ok.length === 0) return;
|
|
4108
|
+
const from = ok[0].x0;
|
|
4109
|
+
const to = ok.at(-1).x0;
|
|
4110
|
+
const bId = before?.id ?? "^";
|
|
4111
|
+
const nId = after?.id ?? "$";
|
|
4112
|
+
if (to - from < STEP) {
|
|
4113
|
+
if (mine.some((r) => !r.slide && Math.abs(lo(r.landing, axis) - from) <= 1)) return;
|
|
4114
|
+
const firstZone = (() => {
|
|
4115
|
+
for (const zone3 of zones) {
|
|
4116
|
+
const space = spaceAt(zone3, from);
|
|
4117
|
+
if (space < -EPS20) continue;
|
|
4118
|
+
const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
|
|
4119
|
+
const hit = landsAt(state, dragged, run, place2, from);
|
|
4120
|
+
if (hit) return { place: place2, result: { state: hit.next, layout: hit.layout } };
|
|
4121
|
+
}
|
|
4122
|
+
return null;
|
|
4123
|
+
})();
|
|
4124
|
+
const { place, result } = firstZone ?? ok[0].hit;
|
|
4125
|
+
const landed = result.layout.items[dragged].rect;
|
|
4126
|
+
const n = neighbors(result.layout, e.id, dragged, axis);
|
|
4127
|
+
const zone2 = place.zone;
|
|
4128
|
+
const isHome = ownEdge === e.id && !!own && Math.abs(lo(own.rect, axis) - lo(landed, axis)) <= 1 && Math.abs(len(own.rect, axis) - len(landed, axis)) <= 1;
|
|
4129
|
+
const target2 = { id: `pitch:${e.id}:${zone2}:${place.at}:${Math.round(place.space ?? 0)}`, priority: 2, hit: landed, slot: landed, item: dragged, place: { kind: "gap", edge: e.id, zone: zone2, at: place.at }, after: () => result };
|
|
4130
|
+
const plain = `${e.id}/${zone2}/${n.before}|${n.next}`;
|
|
4131
|
+
const id = mine.some((r) => r.id === plain) ? `${plain}@${Math.round((place.space ?? 0) / sample)}` : plain;
|
|
4132
|
+
spots.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed, layout: result.layout, target: target2, hit: landed, ...isHome ? { home: true } : {} });
|
|
4133
|
+
return;
|
|
4134
|
+
}
|
|
4135
|
+
const inside = mine.filter((r) => !r.slide && r.before === bId && r.next === nId && Math.abs(len(r.landing, axis) - w) <= 1 && lo(r.landing, axis) >= from - 1 && lo(r.landing, axis) <= to + 1);
|
|
4136
|
+
for (const r of inside) absorbed.add(r);
|
|
4137
|
+
const homeRaw = inside.find((r) => r.home);
|
|
4138
|
+
const points = [];
|
|
4139
|
+
const put = (at2, raw) => {
|
|
4140
|
+
const same = points.find((p) => Math.abs(p.at - at2) < 1e-6);
|
|
4141
|
+
if (!same) points.push({ at: at2, ...raw ? { raw } : {} });
|
|
4142
|
+
else if (raw && !same.raw) same.raw = raw;
|
|
4143
|
+
};
|
|
4144
|
+
put(from);
|
|
4145
|
+
put(to);
|
|
4146
|
+
for (const r of [...inside].sort((p, q) => p.home ? -1 : q.home ? 1 : 0)) put(lo(r.landing, axis), r);
|
|
4147
|
+
const homeAt = homeRaw ? lo(homeRaw.landing, axis) : void 0;
|
|
4148
|
+
const kept = points.filter((p) => homeAt === void 0 || Math.abs(p.at - homeAt) < 1e-6 || Math.abs(p.at - homeAt) > 2 * snapDistance).sort((p, q) => p.at - q.at);
|
|
4149
|
+
const snaps = kept.map((p) => p.at);
|
|
4150
|
+
const dockAt = (x0) => kept.find((p) => Math.abs(p.at - x0) < 1e-6)?.raw;
|
|
4151
|
+
const shape = ok[0].hit.result.layout.items[dragged].rect;
|
|
4152
|
+
const at = (x0) => along(shape, axis, x0, x0 + w);
|
|
4153
|
+
const snapped = (x0) => {
|
|
4154
|
+
let best = x0;
|
|
4155
|
+
let d = Infinity;
|
|
4156
|
+
for (const q of snaps) if (Math.abs(q - x0) <= snapDistance && Math.abs(q - x0) < d) [best, d] = [q, Math.abs(q - x0)];
|
|
4157
|
+
return best;
|
|
4158
|
+
};
|
|
4159
|
+
const startAt = (raw) => {
|
|
4160
|
+
const c = clamp2(raw, from, to);
|
|
4161
|
+
const s = snapped(c);
|
|
4162
|
+
return snaps.includes(s) ? s : clamp2(Math.round(c / STEP) * STEP, from, to);
|
|
4163
|
+
};
|
|
4164
|
+
const results = /* @__PURE__ */ new Map();
|
|
4165
|
+
const commitAt = (x0) => {
|
|
4166
|
+
const r = dockAt(x0);
|
|
4167
|
+
const k = `${r ? "dock " : ""}${Math.round(x0 * 1e3) / 1e3}`;
|
|
4168
|
+
const known = results.get(k);
|
|
4169
|
+
if (known) return known;
|
|
4170
|
+
const result = r ? r.target.after(ORIGIN, ORIGIN) : land(x0)?.result ?? ok.reduce((p, q) => Math.abs(q.x0 - x0) < Math.abs(p.x0 - x0) ? q : p).hit.result;
|
|
4171
|
+
results.set(k, result);
|
|
4172
|
+
return result;
|
|
4173
|
+
};
|
|
4174
|
+
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp2(lo(own.rect, axis), from, to)) : from;
|
|
4175
|
+
const restResult = commitAt(rest);
|
|
4176
|
+
const ownZone = own?.zone;
|
|
4177
|
+
const restPlace = (() => {
|
|
4178
|
+
if (homeRaw) return ownZone && zones.includes(ownZone) ? { zone: ownZone, at: atOf(ownZone), space: Math.max(0, spaceAt(ownZone, rest)) } : land(rest)?.place;
|
|
4179
|
+
const p = dockAt(rest)?.target.place;
|
|
4180
|
+
return p && p.kind === "gap" ? p : land(rest)?.place;
|
|
4181
|
+
})();
|
|
4182
|
+
const landing = homeRaw ? homeRaw.landing : restResult.layout.items[dragged]?.rect ?? at(rest);
|
|
4183
|
+
const ownLen = own ? Math.max(own.rect.width, own.rect.height) : 0;
|
|
4184
|
+
const long = own && own.rect.width >= own.rect.height ? "x" : "y";
|
|
4185
|
+
const target = {
|
|
4186
|
+
id: `slide:${e.id}:${bId}|${nId}`,
|
|
4187
|
+
priority: 2,
|
|
4188
|
+
hit: hull2(at(from), at(to)),
|
|
4189
|
+
slot: landing,
|
|
4190
|
+
item: dragged,
|
|
4191
|
+
place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
|
|
4192
|
+
after: (point, grab) => {
|
|
4193
|
+
const g = grab ? grab[long] : ownLen / 2;
|
|
4194
|
+
const share = axis === long && ownLen > EPS20 && Number.isFinite(g) ? clamp2(g / ownLen, 0, 1) : 0.5;
|
|
4195
|
+
return commitAt(startAt((axis === "x" ? point.x : point.y) - share * w));
|
|
4196
|
+
}
|
|
4197
|
+
};
|
|
4198
|
+
const zone = zones[0];
|
|
4199
|
+
spots.push({
|
|
4200
|
+
lane: e.id,
|
|
4201
|
+
edge: e.id,
|
|
4202
|
+
axis,
|
|
4203
|
+
id: `${e.id}/${zone}/${bId}|${nId}@slide`,
|
|
4204
|
+
before: bId,
|
|
4205
|
+
next: nId,
|
|
4206
|
+
landing,
|
|
4207
|
+
layout: restResult.layout,
|
|
4208
|
+
target,
|
|
4209
|
+
hit: target.hit,
|
|
4210
|
+
...homeRaw ? { home: true } : {},
|
|
4211
|
+
slide: { from, to, snaps, snapDistance, step: STEP, first: at(from), last: at(to) }
|
|
4212
|
+
});
|
|
4213
|
+
}
|
|
4214
|
+
});
|
|
4215
|
+
return { spots, absorbed };
|
|
4216
|
+
}
|
|
4217
|
+
|
|
4218
|
+
export {
|
|
4219
|
+
SIDES,
|
|
4220
|
+
ZONES,
|
|
4221
|
+
FLOAT_ANCHORS,
|
|
4222
|
+
RAIL_MODES,
|
|
4223
|
+
RAIL_VISIBILITIES,
|
|
4224
|
+
RAIL_STRIP_MIN,
|
|
4225
|
+
DEFAULT_RAIL_MAGNET,
|
|
4226
|
+
EDGE_ROOM_HOLD,
|
|
4227
|
+
DEFAULT_STRIP,
|
|
4228
|
+
DEFAULT_HIT_BAND,
|
|
4229
|
+
DEFAULT_FLOAT_SIZE,
|
|
4230
|
+
heldRect,
|
|
4231
|
+
anchorName,
|
|
4232
|
+
zoneTakes,
|
|
4233
|
+
zonesTaking,
|
|
4234
|
+
edgeTakes,
|
|
4235
|
+
railModeOf,
|
|
4236
|
+
zoneIn,
|
|
4237
|
+
namesZone,
|
|
4238
|
+
isOutsideSideBar,
|
|
4239
|
+
isSideBar,
|
|
4240
|
+
isSideColumn,
|
|
4241
|
+
floatOrientOf,
|
|
4242
|
+
declaresFloatSizes,
|
|
4243
|
+
floatSizeOf,
|
|
4244
|
+
targetId,
|
|
4245
|
+
parseTargetId,
|
|
4246
|
+
virtualEdgeId,
|
|
4247
|
+
placeTargetId,
|
|
4248
|
+
solve,
|
|
4249
|
+
fitResize,
|
|
4250
|
+
mergeSideColumns,
|
|
4251
|
+
liftItem,
|
|
4252
|
+
moveTo,
|
|
4253
|
+
floatAt,
|
|
4254
|
+
canFold,
|
|
4255
|
+
foldItem,
|
|
4256
|
+
markUsed,
|
|
4257
|
+
keepItem,
|
|
4258
|
+
openItem,
|
|
4259
|
+
closeItem,
|
|
4260
|
+
raiseFloat,
|
|
4261
|
+
orientFloat,
|
|
4262
|
+
resizeFloat,
|
|
4263
|
+
resizeEdge,
|
|
4264
|
+
setRailMode,
|
|
4265
|
+
setSide,
|
|
4266
|
+
homeFor,
|
|
4267
|
+
dockHome,
|
|
4268
|
+
storeDockState,
|
|
4269
|
+
readDockState,
|
|
4270
|
+
reservedRect,
|
|
4271
|
+
targets,
|
|
4272
|
+
refusals,
|
|
4273
|
+
refusalTargets,
|
|
4274
|
+
stops,
|
|
4275
|
+
SPOT_PITCH,
|
|
4276
|
+
lanes,
|
|
4277
|
+
HATCH_END,
|
|
4278
|
+
HATCH_EDGE
|
|
4279
|
+
};
|
|
4280
|
+
//# sourceMappingURL=chunk-KGNFLHSC.js.map
|