@n-uf/placement 26.11.25 → 26.11.27
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 +163 -0
- package/README.md +152 -27
- package/dist/chunk-3GIUOVQH.js +2345 -0
- package/dist/chunk-3GIUOVQH.js.map +1 -0
- package/dist/{chunk-KGZCYLQN.js → chunk-IHU6IOZH.js} +126 -10
- package/dist/chunk-IHU6IOZH.js.map +1 -0
- package/dist/desk.d.ts +2 -2
- package/dist/float-fit-DRSOU_2y.d.ts +37 -0
- package/dist/index.d.ts +1 -1
- package/dist/{model-mm16NrSX.d.ts → model-Bd0oELzF.d.ts} +8 -0
- package/dist/{targets-CDR5Towj.d.ts → model-Cxg_ySz6.d.ts} +92 -104
- package/dist/panels.d.ts +3 -3
- package/dist/scene-cases.d.ts +45 -15
- package/dist/scene-cases.js +24 -35
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +150 -6
- package/dist/scene.js +15 -2
- package/dist/stack.d.ts +52 -32
- package/dist/stack.js +4 -98
- package/dist/stack.js.map +1 -1
- package/dist/{target-C-HJjPcz.d.ts → target-CEVCfJd-.d.ts} +3 -1
- package/dist/{targets-CBpO_LEy.d.ts → targets-BPG7Kf02.d.ts} +1 -1
- package/dist/targets.d.ts +2 -2
- package/package.json +3 -2
- package/dist/chunk-KGZCYLQN.js.map +0 -1
- package/dist/chunk-SZKU7CRX.js +0 -1745
- package/dist/chunk-SZKU7CRX.js.map +0 -1
|
@@ -0,0 +1,2345 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fitFloat,
|
|
3
|
+
fitStack,
|
|
4
|
+
formCrossMin,
|
|
5
|
+
formMain,
|
|
6
|
+
formSetsCross,
|
|
7
|
+
wrapLines
|
|
8
|
+
} from "./chunk-IHU6IOZH.js";
|
|
9
|
+
import {
|
|
10
|
+
COLUMN_REACH,
|
|
11
|
+
EPS,
|
|
12
|
+
PLANE,
|
|
13
|
+
RAIL_EDGE,
|
|
14
|
+
area,
|
|
15
|
+
clamp,
|
|
16
|
+
clampInto,
|
|
17
|
+
overlaps,
|
|
18
|
+
rect,
|
|
19
|
+
subtract
|
|
20
|
+
} from "./chunk-WM5FJ3IS.js";
|
|
21
|
+
|
|
22
|
+
// src/scene/model.ts
|
|
23
|
+
var SIDES = ["top", "right", "bottom", "left"];
|
|
24
|
+
var ZONES = ["start", "center", "end"];
|
|
25
|
+
var DEFAULT_STRIP = 24;
|
|
26
|
+
var DEFAULT_HIT_BAND = 24;
|
|
27
|
+
var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
|
|
28
|
+
|
|
29
|
+
// src/scene/helpers.ts
|
|
30
|
+
var zoneTakes = (edge, zone, kind) => edge.accepts.includes(kind) && (edge.zoneAccepts === void 0 || !!edge.zoneAccepts[zone]?.includes(kind));
|
|
31
|
+
var zonesTaking = (edge, kind) => ZONES.filter((z) => zoneTakes(edge, z, kind));
|
|
32
|
+
var hitBandOf = (scene, edge) => edge.hitBand ?? (edge.column === true && (edge.side === "left" || edge.side === "right") ? scene.columns?.[edge.side]?.hitBand : void 0) ?? DEFAULT_HIT_BAND;
|
|
33
|
+
var columnFromTemplate = (t, id, side, ring, items) => ({
|
|
34
|
+
id,
|
|
35
|
+
side,
|
|
36
|
+
ring,
|
|
37
|
+
accepts: t.accepts,
|
|
38
|
+
items,
|
|
39
|
+
cross: t.cross,
|
|
40
|
+
...t.gap !== void 0 ? { gap: t.gap } : {},
|
|
41
|
+
...t.pad ? { pad: t.pad } : {},
|
|
42
|
+
...t.menu ? { menu: t.menu } : {},
|
|
43
|
+
...t.zoneAccepts ? { zoneAccepts: t.zoneAccepts } : {},
|
|
44
|
+
...t.hitBand !== void 0 ? { hitBand: t.hitBand } : {},
|
|
45
|
+
column: true
|
|
46
|
+
});
|
|
47
|
+
var axisOf = (side) => side === "left" || side === "right" ? "column" : "row";
|
|
48
|
+
var zoneOf = (item) => item?.align === "center" || item?.align === "end" ? item.align : "start";
|
|
49
|
+
var formsOf = (item, axis) => item.forms[axis] ?? [];
|
|
50
|
+
var PANEL_FORMS = /* @__PURE__ */ new Set(["open", "header", "rail"]);
|
|
51
|
+
var isDockingPanel = (item) => !item.closed && !item.fixed && PANEL_FORMS.has(formsOf(item, "column")[0]?.kind ?? "");
|
|
52
|
+
function isOutsideSideBar(scene, e) {
|
|
53
|
+
return e.outsideInset === true && isSideBar(scene, e);
|
|
54
|
+
}
|
|
55
|
+
function isSideBar(scene, e) {
|
|
56
|
+
if (e.side !== "left" && e.side !== "right" || e.column === true || e.accepts.length === 0) return false;
|
|
57
|
+
const template = scene.columns?.[e.side];
|
|
58
|
+
const rail = scene.rails?.[e.side];
|
|
59
|
+
if (!template && !rail) return false;
|
|
60
|
+
const panelKinds = [...template?.accepts ?? [], ...rail?.accepts ?? []];
|
|
61
|
+
return !e.accepts.some((k) => panelKinds.includes(k));
|
|
62
|
+
}
|
|
63
|
+
var floatOrientOf = (item) => {
|
|
64
|
+
if (item.floatOrient === "row" || item.floatOrient === "column") return item.floatOrient;
|
|
65
|
+
for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
|
|
66
|
+
return "column";
|
|
67
|
+
};
|
|
68
|
+
function floatSizeOf(item, orient2 = floatOrientOf(item)) {
|
|
69
|
+
if (item.floatSize) return item.floatSize;
|
|
70
|
+
const f = formsOf(item, orient2)[0];
|
|
71
|
+
if (!f || f.main.grows) return DEFAULT_FLOAT_SIZE;
|
|
72
|
+
const main = Number.isFinite(f.main.natural) ? Math.max(0, f.main.natural) : 0;
|
|
73
|
+
const cross = Number.isFinite(f.cross.natural) ? Math.max(0, f.cross.natural) : 0;
|
|
74
|
+
if (main <= 0 || cross <= 0) return DEFAULT_FLOAT_SIZE;
|
|
75
|
+
return orient2 === "row" ? { width: main, height: cross } : { width: cross, height: main };
|
|
76
|
+
}
|
|
77
|
+
function pastWrap(forms, from) {
|
|
78
|
+
for (let j = Math.max(0, Math.floor(from)); j < forms.length; j++) if (forms[j].kind !== "wrap" && !forms[j].wrap) return j;
|
|
79
|
+
return void 0;
|
|
80
|
+
}
|
|
81
|
+
function floatShape(item, f) {
|
|
82
|
+
const orient2 = f.orient ?? floatOrientOf(item);
|
|
83
|
+
const forms = formsOf(item, orient2);
|
|
84
|
+
const px2 = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
|
|
85
|
+
const w = px2(f.rect.width);
|
|
86
|
+
const h = px2(f.rect.height);
|
|
87
|
+
if (forms.length === 0) return { form: 0, width: w, height: h };
|
|
88
|
+
const asked = Math.min(Math.max(0, Math.floor(Number.isFinite(item.from) ? item.from : 0)), forms.length - 1);
|
|
89
|
+
const isWrap = (x) => x.kind === "wrap" || !!x.wrap;
|
|
90
|
+
const skipped = orient2 === "column" ? pastWrap(forms, asked) : asked;
|
|
91
|
+
if (skipped === void 0) return { form: asked, width: w, height: h, none: true };
|
|
92
|
+
const form = skipped;
|
|
93
|
+
const fm = forms[form];
|
|
94
|
+
if (orient2 === "column" && forms.slice(0, form + 1).some(isWrap)) return { form, width: px2(fm.cross.natural), height: px2(fm.main.natural) };
|
|
95
|
+
if (form > 0) return orient2 === "column" ? { form, width: w, height: px2(fm.main.natural) } : { form, width: px2(fm.main.natural), height: h };
|
|
96
|
+
return { form, width: w, height: h };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/scene/targets/ids.ts
|
|
100
|
+
function targetId(parts) {
|
|
101
|
+
switch (parts.kind) {
|
|
102
|
+
case "gap":
|
|
103
|
+
return `gap:${parts.edge}:${parts.zone}:${parts.at}`;
|
|
104
|
+
case "strip":
|
|
105
|
+
return `strip:${parts.edge}:${parts.zone}`;
|
|
106
|
+
case "column":
|
|
107
|
+
case "rail":
|
|
108
|
+
return `${parts.kind}:${parts.side}:${parts.ring}`;
|
|
109
|
+
case "side":
|
|
110
|
+
return `side:${parts.side}`;
|
|
111
|
+
case "home":
|
|
112
|
+
case "float":
|
|
113
|
+
return `${parts.kind}:${parts.item}`;
|
|
114
|
+
case "none":
|
|
115
|
+
return `none:${parts.index}`;
|
|
116
|
+
case "refuse":
|
|
117
|
+
return parts.n === 0 ? `refuse:${parts.edge}:${parts.zone}` : `refuse:${parts.edge}:${parts.zone}:${parts.n}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
var ZONE = "(start|center|end)";
|
|
121
|
+
var INT = "(-?\\d+)";
|
|
122
|
+
var GAP = new RegExp(`^gap:(.+):${ZONE}:${INT}$`);
|
|
123
|
+
var STRIP = new RegExp(`^strip:(.+):${ZONE}$`);
|
|
124
|
+
var LINE = new RegExp(`^(column|rail):(left|right):${INT}$`);
|
|
125
|
+
var SIDE = /^side:(left|right|top|bottom)$/;
|
|
126
|
+
var ITEM = /^(home|float):(.+)$/;
|
|
127
|
+
var NONE = new RegExp(`^none:${INT}$`);
|
|
128
|
+
var REFUSE = new RegExp(`^refuse:(.+):${ZONE}(?::${INT})?$`);
|
|
129
|
+
function parseTargetId(id) {
|
|
130
|
+
let m;
|
|
131
|
+
if (m = GAP.exec(id)) return { kind: "gap", edge: m[1], zone: m[2], at: Number(m[3]) };
|
|
132
|
+
if (m = STRIP.exec(id)) return { kind: "strip", edge: m[1], zone: m[2] };
|
|
133
|
+
if (m = LINE.exec(id)) return { kind: m[1], side: m[2], ring: Number(m[3]) };
|
|
134
|
+
if (m = SIDE.exec(id)) return { kind: "side", side: m[1] };
|
|
135
|
+
if (m = ITEM.exec(id)) return { kind: m[1], item: m[2] };
|
|
136
|
+
if (m = NONE.exec(id)) return { kind: "none", index: Number(m[1]) };
|
|
137
|
+
if (m = REFUSE.exec(id)) return { kind: "refuse", edge: m[1], zone: m[2], n: m[3] === void 0 ? 0 : Number(m[3]) };
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
var virtualEdgeId = (kind, side) => `${kind}:${side}`;
|
|
141
|
+
var RESERVED_EDGE_IDS = new Set(["column", "rail"].flatMap((k) => ["left", "right"].map((s) => virtualEdgeId(k, s))));
|
|
142
|
+
var isReservedEdgeId = (id) => RESERVED_EDGE_IDS.has(id);
|
|
143
|
+
function checkEdgeIds(scene) {
|
|
144
|
+
for (const e of scene.edges) {
|
|
145
|
+
if (isReservedEdgeId(e.id)) throw new Error(`placement: the edge id "${e.id}" is reserved for a side's virtual edge (column:<side>, rail:<side>); name the edge otherwise`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function placeTargetId(place, item) {
|
|
149
|
+
switch (place.kind) {
|
|
150
|
+
case "gap":
|
|
151
|
+
return targetId(place);
|
|
152
|
+
case "column":
|
|
153
|
+
case "rail":
|
|
154
|
+
return targetId(place);
|
|
155
|
+
case "side":
|
|
156
|
+
return targetId({ kind: "side", side: place.side });
|
|
157
|
+
case "float":
|
|
158
|
+
case "home":
|
|
159
|
+
return targetId({ kind: place.kind, item });
|
|
160
|
+
default:
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/scene/solve/order.ts
|
|
166
|
+
var finite = (x, fallback) => typeof x === "number" && Number.isFinite(x) ? x : fallback;
|
|
167
|
+
var px = (x) => Math.max(0, finite(x, 0));
|
|
168
|
+
var isSide = (e) => e.side === "left" || e.side === "right";
|
|
169
|
+
function cutOrder(edges) {
|
|
170
|
+
const phase = (e) => e.side === "left" || e.side === "right" ? 1 : e.span === "between" ? 2 : 0;
|
|
171
|
+
const sideRank = (e) => e.side === "top" || e.side === "left" ? 0 : 1;
|
|
172
|
+
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);
|
|
173
|
+
}
|
|
174
|
+
function layKeys(scene) {
|
|
175
|
+
const phase = (e) => e.mode === "overlay" ? 4 : isSide(e) ? 2 : e.span === "between" ? 3 : e.outsideInset === true ? 0 : 1;
|
|
176
|
+
return new Map(cutOrder(scene.edges).map((e, at) => [e.id, { phase: phase(e), side: e.side, at }]));
|
|
177
|
+
}
|
|
178
|
+
function pushes(a, b) {
|
|
179
|
+
if (a.phase === 4 || b.phase === 4) return false;
|
|
180
|
+
if (a.phase !== b.phase) return a.phase < b.phase;
|
|
181
|
+
return a.side === b.side && a.at < b.at;
|
|
182
|
+
}
|
|
183
|
+
var ZONE_RANK = { start: 0, center: 1, end: 2 };
|
|
184
|
+
function zoneSorted(scene, ids) {
|
|
185
|
+
return ids.map((id, i) => ({ id, i, z: ZONE_RANK[zoneOf(scene.items[id])] })).sort((a, b) => a.z - b.z || a.i - b.i).map((x) => x.id);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/scene/solve/draft.ts
|
|
189
|
+
function createDraft(given, options) {
|
|
190
|
+
const previous = options.previous;
|
|
191
|
+
const opened = /* @__PURE__ */ new Set();
|
|
192
|
+
if (previous) {
|
|
193
|
+
for (const e of given.edges) {
|
|
194
|
+
for (const id of e.items) {
|
|
195
|
+
const it = Object.hasOwn(given.items, id) ? given.items[id] : void 0;
|
|
196
|
+
const was = previous.items[id];
|
|
197
|
+
if (it && !it.closed && !it.fixed && (!was || was.closed)) opened.add(id);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const stayedOpen = (e) => e.items.some((id) => !opened.has(id) && Object.hasOwn(given.items, id) && !given.items[id].closed && !given.items[id].fixed);
|
|
202
|
+
const newest = Object.values(given.items).reduce((m, it) => Math.max(m, finite(it.used, 0)), 0) + 1;
|
|
203
|
+
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));
|
|
204
|
+
const scene = byAge.length === 0 ? given : { ...given, items: { ...given.items, ...Object.fromEntries(byAge.map((id, k) => [id, { ...given.items[id], used: newest + k }])) } };
|
|
205
|
+
const fresh = new Set(options.fresh ?? []);
|
|
206
|
+
const prevEdge = (edge) => !previous || fresh.has(edge.id) || edge.items.some((id) => fresh.has(id)) ? void 0 : previous.edges[edge.id];
|
|
207
|
+
const notes = [];
|
|
208
|
+
const order = cutOrder(scene.edges);
|
|
209
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
210
|
+
const claim = (id) => {
|
|
211
|
+
if (!Object.hasOwn(scene.items, id)) {
|
|
212
|
+
notes.push({ code: "unknown-item", id });
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (claimed.has(id)) {
|
|
216
|
+
notes.push({ code: "twice", id });
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
claimed.add(id);
|
|
220
|
+
return true;
|
|
221
|
+
};
|
|
222
|
+
const owned = /* @__PURE__ */ new Map();
|
|
223
|
+
for (const e of order) owned.set(e, e.items.filter(claim));
|
|
224
|
+
return { scene, previous, opened, fresh, order, owned, claim, prevEdge, notes, items: {}, edges: {}, rails: {}, railPlaces: {} };
|
|
225
|
+
}
|
|
226
|
+
function shapeOf(f, r, axis, cross) {
|
|
227
|
+
if (!f) return {};
|
|
228
|
+
if (f.wrap) {
|
|
229
|
+
const lead = Math.max(0, finite(f.wrap.lead ?? 0, 0));
|
|
230
|
+
const row = Math.max(0, finite(f.wrap.row, 0));
|
|
231
|
+
return { rows: wrapLines(f.wrap, cross).lines, grip: rect(r.x, r.y, lead, Math.min(row, r.height)) };
|
|
232
|
+
}
|
|
233
|
+
const g = typeof f.grip === "number" && Number.isFinite(f.grip) && f.grip > 0 ? f.grip : 0;
|
|
234
|
+
if (!g) return {};
|
|
235
|
+
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) };
|
|
236
|
+
}
|
|
237
|
+
function zoneStarts(scene, fit, input) {
|
|
238
|
+
const column = fit.axis === "column";
|
|
239
|
+
const at = (r) => column ? r.y : r.x;
|
|
240
|
+
const out = /* @__PURE__ */ new Map();
|
|
241
|
+
const lengths = /* @__PURE__ */ new Map();
|
|
242
|
+
const drawn = fit.items.filter((p) => p.kind !== "menu");
|
|
243
|
+
for (const p of drawn) {
|
|
244
|
+
out.set(p.id, at(p.rect));
|
|
245
|
+
lengths.set(p.id, column ? p.rect.height : p.rect.width);
|
|
246
|
+
}
|
|
247
|
+
const len = (p) => lengths.get(p.id);
|
|
248
|
+
const gap = px(input.gap);
|
|
249
|
+
const start = px(input.pad?.start);
|
|
250
|
+
const end = px(input.pad?.end);
|
|
251
|
+
const menu = fit.menu ? (column ? fit.menu.rect.height : fit.menu.rect.width) + (drawn.length > 0 ? gap : 0) : 0;
|
|
252
|
+
const zone = (z) => drawn.filter((p) => zoneOf(scene.items[p.id]) === z);
|
|
253
|
+
const s = zone("start");
|
|
254
|
+
const c = zone("center");
|
|
255
|
+
const e = zone("end");
|
|
256
|
+
const title = column ? void 0 : s.find((p) => {
|
|
257
|
+
const it = scene.items[p.id];
|
|
258
|
+
const f = formsOf(it, "row")[p.form];
|
|
259
|
+
return it.fixed && f?.main.grows && len(p) > formMain(f, "natural", fit.cross) + EPS;
|
|
260
|
+
});
|
|
261
|
+
if (title) lengths.set(title.id, formMain(formsOf(scene.items[title.id], "row")[title.form], "natural", fit.cross));
|
|
262
|
+
const used = drawn.reduce((sum, p) => sum + len(p), 0) + Math.max(0, drawn.length - 1) * gap;
|
|
263
|
+
const spare = fit.length - start - end - menu - used;
|
|
264
|
+
if (spare <= EPS) return { starts: out, lengths };
|
|
265
|
+
const total = (ps) => ps.reduce((sum, p) => sum + len(p), 0) + Math.max(0, ps.length - 1) * gap;
|
|
266
|
+
const lay = (ps, from) => {
|
|
267
|
+
let x = from;
|
|
268
|
+
for (const p of ps) {
|
|
269
|
+
out.set(p.id, x);
|
|
270
|
+
x += len(p) + gap;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
lay(s, start);
|
|
274
|
+
const endStart = fit.length - end - menu - total(e);
|
|
275
|
+
lay(e, endStart);
|
|
276
|
+
const lo = start + total(s) + (s.length > 0 ? gap : 0);
|
|
277
|
+
const hi = endStart - (e.length > 0 ? gap : 0);
|
|
278
|
+
const mid = (fit.length - total(c)) / 2;
|
|
279
|
+
const clear = mid >= lo - EPS && mid + total(c) <= hi + EPS;
|
|
280
|
+
lay(c, title && !clear ? Math.max(lo, (lo + hi - total(c)) / 2) : Math.max(lo, Math.min(mid, hi - total(c))));
|
|
281
|
+
if (title && s[s.length - 1] === title) {
|
|
282
|
+
const next = [...c, ...e].map((p) => out.get(p.id));
|
|
283
|
+
const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
|
|
284
|
+
lengths.set(title.id, Math.max(len(title), until - out.get(title.id)));
|
|
285
|
+
}
|
|
286
|
+
return { starts: out, lengths };
|
|
287
|
+
}
|
|
288
|
+
function emit(d, edge, r, solved, extra = {}) {
|
|
289
|
+
const { scene, notes, items, edges } = d;
|
|
290
|
+
const column = axisOf(edge.side) === "column";
|
|
291
|
+
const { stack } = solved;
|
|
292
|
+
const thick = column ? r.width : r.height;
|
|
293
|
+
const { starts, lengths } = zoneStarts(scene, stack, solved.input);
|
|
294
|
+
const toStage = (l, id) => {
|
|
295
|
+
const s = id !== void 0 ? starts.get(id) : void 0;
|
|
296
|
+
const n = id !== void 0 ? lengths.get(id) : void 0;
|
|
297
|
+
const x = column ? l.x : s ?? l.x;
|
|
298
|
+
const y = column ? s ?? l.y : l.y;
|
|
299
|
+
return rect(r.x + x, r.y + y, column ? l.width : n ?? l.width, column ? n ?? l.height : l.height);
|
|
300
|
+
};
|
|
301
|
+
const tabs = new Set(solved.tabs);
|
|
302
|
+
for (const id of solved.leftOut ?? []) notes.push({ code: "no-vertical-form", edge: edge.id, id });
|
|
303
|
+
for (const id of solved.leftOutIcons ?? []) notes.push({ code: "no-icons-form", edge: edge.id, id });
|
|
304
|
+
for (const p of stack.items) {
|
|
305
|
+
const it = scene.items[p.id];
|
|
306
|
+
const inMenu = p.kind === "menu";
|
|
307
|
+
const drawnRect = toStage(p.rect, inMenu ? void 0 : p.id);
|
|
308
|
+
const f = formsOf(it, column ? "column" : "row")[p.form];
|
|
309
|
+
const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? "column" : "row", stack.cross);
|
|
310
|
+
items[p.id] = {
|
|
311
|
+
...shape,
|
|
312
|
+
hidden: inMenu ? [] : f?.hides ?? [],
|
|
313
|
+
rect: drawnRect,
|
|
314
|
+
kind: it.kind,
|
|
315
|
+
form: p.form,
|
|
316
|
+
formKind: p.kind,
|
|
317
|
+
edge: edge.id,
|
|
318
|
+
zone: zoneOf(it),
|
|
319
|
+
...inMenu ? { inMenu: true } : {},
|
|
320
|
+
...tabs.has(p.id) ? { tab: true } : {},
|
|
321
|
+
...solved.closedTabs.has(p.id) ? { closed: true } : {},
|
|
322
|
+
...it.fixed ? { fixed: true } : {}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
for (const n of stack.notes) notes.push({ edge: edge.id, ...n });
|
|
326
|
+
edges[edge.id] = {
|
|
327
|
+
side: edge.side,
|
|
328
|
+
ring: finite(edge.ring, 0),
|
|
329
|
+
rect: r,
|
|
330
|
+
cross: thick,
|
|
331
|
+
menu: stack.menu ? { rect: toStage(stack.menu.rect), items: stack.menu.items } : null,
|
|
332
|
+
tabs: solved.tabs,
|
|
333
|
+
stack,
|
|
334
|
+
free: solved.free,
|
|
335
|
+
...extra
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/scene/solve/edge.ts
|
|
340
|
+
var stackItemOf = (item, forms, from) => ({
|
|
341
|
+
id: item.id,
|
|
342
|
+
forms,
|
|
343
|
+
used: finite(item.used, 0),
|
|
344
|
+
...item.kept ? { kept: true } : {},
|
|
345
|
+
...from !== void 0 ? { from } : item.from !== void 0 ? { from: item.from } : {},
|
|
346
|
+
...item.fixed ? { fixed: true } : {}
|
|
347
|
+
});
|
|
348
|
+
function hasSetter(fit, forms) {
|
|
349
|
+
return fit.items.some((p) => p.kind !== "menu" && formSetsCross(forms(p.id)[p.form]));
|
|
350
|
+
}
|
|
351
|
+
var TRAY_RANK = 100;
|
|
352
|
+
function compactEdge(f) {
|
|
353
|
+
const { scene, formsById } = f;
|
|
354
|
+
const iconsAt = (id) => {
|
|
355
|
+
const forms = formsById(id);
|
|
356
|
+
for (let j = Math.max(0, Math.floor(finite(scene.items[id].from, 0))); j < forms.length; j++) if (forms[j].kind === "icons") return j;
|
|
357
|
+
return forms.findIndex((x) => x.kind === "icons");
|
|
358
|
+
};
|
|
359
|
+
const shown = f.ordered.filter((id) => !scene.items[id].closed && iconsAt(id) >= 0);
|
|
360
|
+
const leftOutIcons = f.ordered.filter((id) => !scene.items[id].closed && iconsAt(id) < 0);
|
|
361
|
+
const compactInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(scene.items[id], formsById(id), iconsAt(id))) };
|
|
362
|
+
const stack = fitStack(compactInput, f.previous ? { previous: f.previous.free } : {});
|
|
363
|
+
return { stack, free: stack, tabs: [], closedTabs: /* @__PURE__ */ new Set(), input: compactInput, leftOutIcons };
|
|
364
|
+
}
|
|
365
|
+
function railEdge(f, free, asStackItem) {
|
|
366
|
+
const { scene, edge, formsById } = f;
|
|
367
|
+
const railIndex = (item, forms) => {
|
|
368
|
+
if (item.fixed) return -1;
|
|
369
|
+
for (let j = Math.max(0, Math.floor(finite(item.from, 0))); j < forms.length; j++) if (forms[j].kind === "rail") return j;
|
|
370
|
+
return -1;
|
|
371
|
+
};
|
|
372
|
+
const wrapOnly = (id) => railIndex(scene.items[id], formsById(id)) < 0 && pastWrap(formsById(id), finite(scene.items[id].from, 0)) === void 0;
|
|
373
|
+
const shown = f.ordered.filter((id) => {
|
|
374
|
+
const it = scene.items[id];
|
|
375
|
+
if (!it.closed && wrapOnly(id)) return false;
|
|
376
|
+
return !it.closed || edge.railShowsClosed === true && railIndex(it, formsById(id)) >= 0;
|
|
377
|
+
});
|
|
378
|
+
const leftOut = f.ordered.filter((id) => !scene.items[id].closed && wrapOnly(id));
|
|
379
|
+
const anyRail = shown.some((id) => railIndex(scene.items[id], formsById(id)) >= 0);
|
|
380
|
+
if (!anyRail) return null;
|
|
381
|
+
const railInput = {
|
|
382
|
+
...f.base,
|
|
383
|
+
items: shown.map((id) => {
|
|
384
|
+
const it = scene.items[id];
|
|
385
|
+
const j = railIndex(it, formsById(id));
|
|
386
|
+
const forms = asStackItem(id).forms;
|
|
387
|
+
return stackItemOf(it, forms, j >= 0 ? j : pastWrap(forms, finite(it.from, 0)));
|
|
388
|
+
})
|
|
389
|
+
};
|
|
390
|
+
const stack = fitStack(railInput, f.previous ? { previous: f.previous.stack } : {});
|
|
391
|
+
const tabs = stack.items.filter((p) => p.kind === "rail").map((p) => p.id);
|
|
392
|
+
const closedTabs = new Set(shown.filter((id) => scene.items[id].closed));
|
|
393
|
+
return { stack, free, tabs, closedTabs, input: railInput, leftOut };
|
|
394
|
+
}
|
|
395
|
+
function solveEdge(scene, edge, ids, length, room, previous) {
|
|
396
|
+
const axis = axisOf(edge.side);
|
|
397
|
+
const column = axis === "column";
|
|
398
|
+
const ordered = zoneSorted(scene, ids);
|
|
399
|
+
const priorityOf = (id) => finite(scene.items[id].priority ?? edge.priority ?? 0, 0);
|
|
400
|
+
const formsById = (id) => {
|
|
401
|
+
const forms = formsOf(scene.items[id], axis);
|
|
402
|
+
const p = priorityOf(id);
|
|
403
|
+
return p === 0 ? forms : forms.map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + p }));
|
|
404
|
+
};
|
|
405
|
+
const maxOf = Number.isNaN(edge.cross.max) ? Infinity : edge.cross.max;
|
|
406
|
+
const cross = { min: Math.min(px(edge.cross.min), room), max: Math.min(maxOf, room), rail: Math.min(px(edge.cross.rail ?? 30), room) };
|
|
407
|
+
const base = {
|
|
408
|
+
axis,
|
|
409
|
+
length,
|
|
410
|
+
cross,
|
|
411
|
+
...edge.menu ? { menu: edge.menu } : {},
|
|
412
|
+
...edge.gap !== void 0 ? { gap: edge.gap } : {},
|
|
413
|
+
...edge.pad ? { pad: edge.pad } : {},
|
|
414
|
+
...column ? { ownCross: true } : {}
|
|
415
|
+
};
|
|
416
|
+
const frame = { scene, edge, column, ordered, formsById, base, previous };
|
|
417
|
+
if (edge.compact) return compactEdge(frame);
|
|
418
|
+
const open2 = ordered.filter((id) => !scene.items[id].closed);
|
|
419
|
+
const asStackItem = (id) => {
|
|
420
|
+
const it = scene.items[id];
|
|
421
|
+
const forms = formsById(id);
|
|
422
|
+
if (!column || !edge.zoneAccepts?.end || zoneOf(it) !== "end") return stackItemOf(it, forms);
|
|
423
|
+
const tray = (f) => f.kind === "wrap" || f.kind === "icons" || !!f.wrap;
|
|
424
|
+
let first = -1;
|
|
425
|
+
for (let j = Math.max(0, Math.floor(finite(it.from, 0))); j < forms.length && first < 0; j++) if (tray(forms[j])) first = j;
|
|
426
|
+
let last = -1;
|
|
427
|
+
forms.forEach((f, j) => {
|
|
428
|
+
if (tray(f)) last = j;
|
|
429
|
+
});
|
|
430
|
+
if (first < 0) return stackItemOf(it, forms);
|
|
431
|
+
return stackItemOf(it, forms.slice(0, last + 1).map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + TRAY_RANK })), first);
|
|
432
|
+
};
|
|
433
|
+
const input = { ...base, items: open2.map(asStackItem) };
|
|
434
|
+
const free = fitStack(input, previous ? { previous: previous.free } : {});
|
|
435
|
+
const none = /* @__PURE__ */ new Set();
|
|
436
|
+
if (column && !hasSetter(free, formsById)) {
|
|
437
|
+
const rail = railEdge(frame, free, asStackItem);
|
|
438
|
+
if (rail) return rail;
|
|
439
|
+
}
|
|
440
|
+
const size = edge.size;
|
|
441
|
+
if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
|
|
442
|
+
const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross(formsById(p.id)[p.form]));
|
|
443
|
+
const lo = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(formsById(p.id)[p.form])));
|
|
444
|
+
const s = Math.min(Math.max(size, lo), Math.max(lo, maxOf), room);
|
|
445
|
+
if (Math.abs(s - free.cross) > EPS) {
|
|
446
|
+
const sized = { ...input, cross: { ...cross, min: s, max: s } };
|
|
447
|
+
const stack = fitStack(sized, previous ? { previous: previous.stack } : {});
|
|
448
|
+
return { stack, free, tabs: [], closedTabs: none, input: sized };
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return { stack: free, free, tabs: [], closedTabs: none, input };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// src/scene/solve/bars.ts
|
|
455
|
+
function cutEdge(d, edge, area2, cut) {
|
|
456
|
+
const column = axisOf(edge.side) === "column";
|
|
457
|
+
const length = column ? area2.height : area2.width;
|
|
458
|
+
const room = Math.max(0, column ? area2.width : area2.height);
|
|
459
|
+
const solved = solveEdge(d.scene, edge, d.owned.get(edge), length, room, d.prevEdge(edge));
|
|
460
|
+
const thick = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, room);
|
|
461
|
+
const r = edge.side === "top" ? rect(area2.x, area2.y, area2.width, thick) : edge.side === "bottom" ? rect(area2.x, area2.y + area2.height - thick, area2.width, thick) : edge.side === "left" ? rect(area2.x, area2.y, thick, area2.height) : rect(area2.x + area2.width - thick, area2.y, thick, area2.height);
|
|
462
|
+
emit(d, edge, r, solved);
|
|
463
|
+
if (!cut) return area2;
|
|
464
|
+
return edge.side === "top" ? rect(area2.x, area2.y + thick, area2.width, area2.height - thick) : edge.side === "bottom" ? rect(area2.x, area2.y, area2.width, area2.height - thick) : edge.side === "left" ? rect(area2.x + thick, area2.y, area2.width - thick, area2.height) : rect(area2.x, area2.y, area2.width - thick, area2.height);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/scene/solve/floats.ts
|
|
468
|
+
function anchored(content, w, h, anchor) {
|
|
469
|
+
const left = content.x;
|
|
470
|
+
const right = content.x + content.width - w;
|
|
471
|
+
const midX = content.x + (content.width - w) / 2;
|
|
472
|
+
const top = content.y;
|
|
473
|
+
const bottom = content.y + content.height - h;
|
|
474
|
+
const midY = content.y + (content.height - h) / 2;
|
|
475
|
+
const at = {
|
|
476
|
+
"content-top-left": [left, top],
|
|
477
|
+
"content-top": [midX, top],
|
|
478
|
+
"content-top-right": [right, top],
|
|
479
|
+
"content-right": [right, midY],
|
|
480
|
+
"content-bottom-right": [right, bottom],
|
|
481
|
+
"content-bottom": [midX, bottom],
|
|
482
|
+
"content-bottom-left": [left, bottom],
|
|
483
|
+
"content-left": [left, midY]
|
|
484
|
+
};
|
|
485
|
+
const [x, y] = at[anchor] ?? at["content-top-right"];
|
|
486
|
+
return rect(x, y, w, h);
|
|
487
|
+
}
|
|
488
|
+
function floatFloor(item, form, orient2, size) {
|
|
489
|
+
const row = orient2 === "row";
|
|
490
|
+
return {
|
|
491
|
+
width: item.floatMin ? px(item.floatMin.width) : Math.min(size.width, px(row ? form?.main.min : form?.cross.min)),
|
|
492
|
+
height: item.floatMin ? px(item.floatMin.height) : Math.min(size.height, px(row ? form?.cross.min : form?.main.min))
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function placeFloat(item, f, region, avoid, content, stage) {
|
|
496
|
+
const shape = floatShape(item, f);
|
|
497
|
+
const from = shape.form;
|
|
498
|
+
const fo = f.orient ?? floatOrientOf(item);
|
|
499
|
+
const form = formsOf(item, fo)[from];
|
|
500
|
+
const floor = floatFloor(item, form, fo, shape);
|
|
501
|
+
const cap = { width: Number.isFinite(item.floatMax?.width) ? item.floatMax.width : Infinity, height: Number.isFinite(item.floatMax?.height) ? item.floatMax.height : Infinity };
|
|
502
|
+
const w = Math.max(floor.width, Math.min(shape.width, region.width, cap.width));
|
|
503
|
+
const folded = form?.kind === "header";
|
|
504
|
+
const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, region.height, cap.height));
|
|
505
|
+
const want = f.anchor ? anchored(content, w, h, f.anchor) : rect(finite(f.rect.x, stage.x), finite(f.rect.y, stage.y), w, h);
|
|
506
|
+
const fit0 = fitFloat(want, region, avoid);
|
|
507
|
+
const fit = w > region.width + EPS ? { ...fit0, rect: rect(region.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
|
|
508
|
+
return { from, fo, form, fit };
|
|
509
|
+
}
|
|
510
|
+
function layFloats(d, stage, content, inset) {
|
|
511
|
+
const { scene, notes, items, edges } = d;
|
|
512
|
+
const avoid = [];
|
|
513
|
+
for (const l of Object.values(items)) avoid.push(l.rect);
|
|
514
|
+
for (const e of Object.values(edges)) {
|
|
515
|
+
if (axisOf(e.side) === "row" && e.cross > 0) avoid.push(e.rect);
|
|
516
|
+
if (e.menu) avoid.push(e.menu.rect);
|
|
517
|
+
}
|
|
518
|
+
for (const c of scene.chrome ?? []) avoid.push(c);
|
|
519
|
+
const floatRegion2 = rect(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);
|
|
520
|
+
const floats = [];
|
|
521
|
+
for (const f of scene.floats) {
|
|
522
|
+
if (!d.claim(f.id)) continue;
|
|
523
|
+
const it = scene.items[f.id];
|
|
524
|
+
if (it.closed) continue;
|
|
525
|
+
const shape = floatShape(it, f);
|
|
526
|
+
if (shape.none) {
|
|
527
|
+
notes.push({ code: "no-vertical-form", id: f.id });
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
const { from, fo, form, fit } = placeFloat(it, f, floatRegion2, avoid, content, stage);
|
|
531
|
+
if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
|
|
532
|
+
if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
|
|
533
|
+
if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
|
|
534
|
+
items[f.id] = { ...shapeOf(form, fit.rect, fo, fit.rect.width), hidden: form?.hides ?? [], rect: fit.rect, kind: it.kind, form: from, formKind: form?.kind ?? "open", floating: true };
|
|
535
|
+
floats.push(f.id);
|
|
536
|
+
}
|
|
537
|
+
return floats;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/scene/solve/insets.ts
|
|
541
|
+
function insetOf(d) {
|
|
542
|
+
const { scene } = d;
|
|
543
|
+
const docked = d.order.some((e) => isSide(e) && e.accepts.length > 0 && d.owned.get(e).some((id) => isDockingPanel(scene.items[id])));
|
|
544
|
+
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
545
|
+
return { inset, docked };
|
|
546
|
+
}
|
|
547
|
+
var insideInset = (outer, inset) => rect(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)));
|
|
548
|
+
function insetReach(area2, f) {
|
|
549
|
+
const up = area2.y <= f.outer.y + px(f.inset.top) + EPS ? px(f.inset.top) : 0;
|
|
550
|
+
const down = area2.y + area2.height >= f.outer.y + f.outer.height - px(f.inset.bottom) - EPS ? px(f.inset.bottom) : 0;
|
|
551
|
+
return { up, down };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// src/scene/solve/notes.ts
|
|
555
|
+
function contentNotes(d, content) {
|
|
556
|
+
const { scene, notes, previous } = d;
|
|
557
|
+
if (scene.contentMin) {
|
|
558
|
+
const minW = px(scene.contentMin.width);
|
|
559
|
+
const minH = px(scene.contentMin.height);
|
|
560
|
+
if (content.width < minW - EPS) notes.push({ code: "content-narrow", width: content.width, min: minW });
|
|
561
|
+
const bars = d.order.filter((e) => e.mode === "overlay" && !isSide(e)).reduce((s, e) => s + (d.edges[e.id]?.cross ?? 0), 0);
|
|
562
|
+
if (content.height - bars < minH - EPS) notes.push({ code: "content-short", height: content.height - bars, min: minH });
|
|
563
|
+
}
|
|
564
|
+
if (previous) {
|
|
565
|
+
const was = previous.content;
|
|
566
|
+
const moved = Math.abs(was.x - content.x) > EPS || Math.abs(was.y - content.y) > EPS || Math.abs(was.width - content.width) > EPS || Math.abs(was.height - content.height) > EPS;
|
|
567
|
+
if (moved) notes.push({ code: "content-changed", from: was, to: content });
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/scene/solve/columns.ts
|
|
572
|
+
function columnsOf(d, sideEdges, area2, tall) {
|
|
573
|
+
const { scene } = d;
|
|
574
|
+
return sideEdges.map((edge) => {
|
|
575
|
+
const side = edge.side;
|
|
576
|
+
const solved = solveEdge(scene, edge, d.owned.get(edge), tall(edge), Math.max(0, area2.width), d.prevEdge(edge));
|
|
577
|
+
const width = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, area2.width);
|
|
578
|
+
const visible = d.owned.get(edge).filter((id) => !scene.items[id].closed);
|
|
579
|
+
const dyn = (edge.column === true || edge.giveWay === true) && scene.rails?.[side] !== void 0 && visible.length > 0;
|
|
580
|
+
const forms = (id) => formsOf(scene.items[id], "column");
|
|
581
|
+
const setters = solved.free.items.filter((p) => p.kind !== "menu" && formSetsCross(forms(p.id)[p.form]));
|
|
582
|
+
const min = setters.length > 0 ? Math.min(width, Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(forms(p.id)[p.form])))) : width;
|
|
583
|
+
return {
|
|
584
|
+
edge,
|
|
585
|
+
side,
|
|
586
|
+
solved,
|
|
587
|
+
width,
|
|
588
|
+
min,
|
|
589
|
+
visible,
|
|
590
|
+
dyn,
|
|
591
|
+
hand: dyn && edge.column === true && visible.every((id) => finite(scene.items[id].from, 0) >= 1),
|
|
592
|
+
kept: visible.some((id) => scene.items[id].kept === true),
|
|
593
|
+
age: Math.max(-Infinity, ...visible.map((id) => finite(scene.items[id].used, 0)))
|
|
594
|
+
};
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
function giveWay(d, cols, area2, gutter) {
|
|
598
|
+
const { scene, previous, fresh, opened } = d;
|
|
599
|
+
const ride = scene.handFold === "ride";
|
|
600
|
+
const cmin = scene.contentMin ? px(scene.contentMin.width) : void 0;
|
|
601
|
+
const foldOrder = cols.filter((c) => c.dyn && !c.hand && c.width > 0).sort((a, b) => Number(a.kept) - Number(b.kept) || a.age - b.age || finite(a.edge.ring, 0) - finite(b.edge.ring, 0) || (a.side === b.side ? 0 : a.side === "left" ? -1 : 1));
|
|
602
|
+
const shrunkBefore = (previous?.notes ?? []).flatMap((n) => n.code === "column-shrunk" ? [n.edge] : []);
|
|
603
|
+
const rankOf = (c) => shrunkBefore.includes(c.edge.id) ? shrunkBefore.indexOf(c.edge.id) : Infinity;
|
|
604
|
+
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);
|
|
605
|
+
const railW = (side) => px(scene.rails?.[side]?.width);
|
|
606
|
+
const evaluate = (auto2) => {
|
|
607
|
+
const openOn = (side) => cols.some((c) => c.side === side && c.dyn && c.edge.column === true && !c.hand && !auto2.has(c) && c.width > 0);
|
|
608
|
+
const riding = (c) => ride && c.hand && openOn(c.side);
|
|
609
|
+
const railed = (c) => c.dyn && (auto2.has(c) || c.hand && !riding(c));
|
|
610
|
+
const widths = new Map(cols.filter((c) => !railed(c) && !riding(c)).map((c) => [c, c.width]));
|
|
611
|
+
const railSides = ["left", "right"].filter((s) => cols.some((c) => c.side === s && railed(c)));
|
|
612
|
+
let used = 0;
|
|
613
|
+
for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : gutter) : 0;
|
|
614
|
+
for (const s of railSides) used += railW(s) + gutter;
|
|
615
|
+
let excess = cmin === void 0 ? -Infinity : used + cmin - area2.width;
|
|
616
|
+
for (const c of shrinkOrder) {
|
|
617
|
+
if (excess <= EPS) break;
|
|
618
|
+
const w = widths.get(c);
|
|
619
|
+
if (w === void 0) continue;
|
|
620
|
+
const take = Math.min(excess, w - c.min);
|
|
621
|
+
if (take > 0) {
|
|
622
|
+
widths.set(c, w - take);
|
|
623
|
+
excess -= take;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return { auto: auto2, widths, excess, railed, riding, shrinkOrder };
|
|
627
|
+
};
|
|
628
|
+
let auto = /* @__PURE__ */ new Set();
|
|
629
|
+
if (cmin !== void 0) {
|
|
630
|
+
const unfold = () => {
|
|
631
|
+
for (const c of [...auto].reverse()) {
|
|
632
|
+
const fewer = new Set([...auto].filter((x) => x !== c));
|
|
633
|
+
if (evaluate(fewer).excess <= EPS) auto = fewer;
|
|
634
|
+
else break;
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
if (previous) {
|
|
638
|
+
const byId = new Map(foldOrder.map((c) => [c.edge.id, c]));
|
|
639
|
+
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));
|
|
640
|
+
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)] : []);
|
|
641
|
+
auto = new Set(was);
|
|
642
|
+
if (evaluate(auto).excess <= EPS) unfold();
|
|
643
|
+
}
|
|
644
|
+
for (const c of foldOrder) {
|
|
645
|
+
if (evaluate(auto).excess <= EPS) break;
|
|
646
|
+
if (!auto.has(c)) auto = /* @__PURE__ */ new Set([...auto, c]);
|
|
647
|
+
}
|
|
648
|
+
for (let size = -1; size !== auto.size; ) {
|
|
649
|
+
size = auto.size;
|
|
650
|
+
unfold();
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return evaluate(auto);
|
|
654
|
+
}
|
|
655
|
+
function columnRoom(d, cols, area2, f) {
|
|
656
|
+
const { scene } = d;
|
|
657
|
+
const cmin = scene.contentMin ? px(scene.contentMin.width) : void 0;
|
|
658
|
+
const openMin = (ids, least) => Math.max(
|
|
659
|
+
least,
|
|
660
|
+
...ids.map((id) => {
|
|
661
|
+
const form = formsOf(scene.items[id], "column")[0];
|
|
662
|
+
return form && formSetsCross(form) ? formCrossMin(form) : 0;
|
|
663
|
+
})
|
|
664
|
+
);
|
|
665
|
+
const open2 = 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);
|
|
666
|
+
const templates = ["left", "right"].flatMap((s) => {
|
|
667
|
+
const t = scene.columns?.[s];
|
|
668
|
+
if (!t) return [];
|
|
669
|
+
const takes = Object.values(scene.items).filter((it) => !it.fixed && !it.closed && t.accepts.includes(it.kind));
|
|
670
|
+
return [openMin(takes.map((it) => it.id), px(t.cross.min))];
|
|
671
|
+
});
|
|
672
|
+
const colMins = open2.length > 0 ? open2 : templates;
|
|
673
|
+
if (cmin === void 0 || colMins.length === 0) return;
|
|
674
|
+
const bars = cols.filter((c) => c.width > 0 && !c.dyn && isSideBar(scene, c.edge)).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : f.gutter), 0);
|
|
675
|
+
const width = area2.width - bars - (scene.insetWhen === "docked" && !f.docked ? px(scene.inset?.left) + px(scene.inset?.right) : 0);
|
|
676
|
+
const need = cmin + Math.min(...colMins) + f.gutter;
|
|
677
|
+
d.columnRoom = width >= need - EPS;
|
|
678
|
+
if (!d.columnRoom) d.notes.push({ code: "no-column-room", width, need });
|
|
679
|
+
}
|
|
680
|
+
function giveWayNotes(d, g, cols) {
|
|
681
|
+
const { scene, previous } = d;
|
|
682
|
+
const dormant = new Set(cols.filter((c) => c.visible.length === 0 && (c.edge.column === true || c.edge.giveWay === true) && scene.rails?.[c.side] !== void 0).map((c) => c.edge.id));
|
|
683
|
+
const before = previous?.notes ?? [];
|
|
684
|
+
const shrunk = /* @__PURE__ */ new Map();
|
|
685
|
+
for (const c of g.shrinkOrder) {
|
|
686
|
+
const w = g.widths.get(c);
|
|
687
|
+
if (w !== void 0 && w < c.width - EPS) shrunk.set(c.edge.id, { code: "column-shrunk", edge: c.edge.id, from: c.width, to: w });
|
|
688
|
+
}
|
|
689
|
+
const folded = new Map([...g.auto].map((c) => [c.edge.id, { code: c.kept ? "kept-folded" : "column-folded", edge: c.edge.id }]));
|
|
690
|
+
const merge = (now, kept) => {
|
|
691
|
+
const order = [];
|
|
692
|
+
for (const n of before) {
|
|
693
|
+
const edge = kept(n) && "edge" in n ? n.edge : void 0;
|
|
694
|
+
if (edge === void 0) continue;
|
|
695
|
+
if (dormant.has(edge)) order.push(n);
|
|
696
|
+
else if (now.has(edge)) {
|
|
697
|
+
order.push(now.get(edge));
|
|
698
|
+
now.delete(edge);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
d.notes.push(...order, ...now.values());
|
|
702
|
+
};
|
|
703
|
+
d.notes.push(...shrunk.values());
|
|
704
|
+
merge(folded, (n) => n.code === "column-folded" || n.code === "kept-folded");
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/scene/solve/rails.ts
|
|
708
|
+
function riderBars(d, c) {
|
|
709
|
+
const { scene } = d;
|
|
710
|
+
return zoneSorted(scene, c.visible).map((id) => {
|
|
711
|
+
const forms = formsOf(scene.items[id], "column");
|
|
712
|
+
const form = forms.length === 0 ? 0 : Math.min(Math.max(0, Math.floor(finite(scene.items[id].from, 0))), forms.length - 1);
|
|
713
|
+
return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
var ridersHeight = (d, riders) => riders.reduce((s, c) => s + riderBars(d, c).reduce((t, b) => t + b.h, 0), 0);
|
|
717
|
+
function layRiders(d, host, riders, top) {
|
|
718
|
+
const { scene, items, edges } = d;
|
|
719
|
+
const hr = edges[host.edge.id].rect;
|
|
720
|
+
let y = top;
|
|
721
|
+
for (const c of riders) {
|
|
722
|
+
const bars = riderBars(d, c);
|
|
723
|
+
const y0 = y;
|
|
724
|
+
for (const b of bars) {
|
|
725
|
+
const at = rect(hr.x, y, hr.width, b.h);
|
|
726
|
+
const it = scene.items[b.id];
|
|
727
|
+
items[b.id] = { rect: at, hidden: b.f?.hides ?? [], kind: it.kind, form: b.form, formKind: b.f?.kind ?? "header", edge: c.edge.id, zone: zoneOf(it), rides: host.edge.id, folded: "hand" };
|
|
728
|
+
y += b.h;
|
|
729
|
+
}
|
|
730
|
+
edges[c.edge.id] = { side: c.edge.side, ring: finite(c.edge.ring, 0), rect: rect(hr.x, y0, hr.width, y - y0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free, rides: host.edge.id, folded: "hand" };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
function layRail(d, side, railRect, railed, g) {
|
|
734
|
+
const { scene, items } = d;
|
|
735
|
+
const segments = [];
|
|
736
|
+
let y = railRect.y;
|
|
737
|
+
for (const c of railed) {
|
|
738
|
+
for (const id of zoneSorted(scene, c.visible)) {
|
|
739
|
+
const it = scene.items[id];
|
|
740
|
+
const forms = formsOf(it, "column");
|
|
741
|
+
const ri = forms.findIndex((f) => f.kind === "rail");
|
|
742
|
+
const form = ri >= 0 ? ri : Math.min(Math.max(0, Math.floor(finite(it.from, 0))), Math.max(0, forms.length - 1));
|
|
743
|
+
const h = ri >= 0 ? px(forms[ri].main.natural) : railRect.width;
|
|
744
|
+
const at = rect(railRect.x, y, railRect.width, h);
|
|
745
|
+
items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, folded: g.auto.has(c) ? "auto" : "hand" };
|
|
746
|
+
segments.push({ id, edge: c.edge.id, rect: at });
|
|
747
|
+
y += h;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
d.rails[side] = { rect: railRect, segments };
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/scene/solve/sides.ts
|
|
754
|
+
function laySides(d, sideEdges, area2, f) {
|
|
755
|
+
const H = area2.height;
|
|
756
|
+
const reach = insetReach(area2, f);
|
|
757
|
+
const tall = (edge) => H + (edge.outsideInset === true ? reach.up + reach.down : 0);
|
|
758
|
+
const cols = columnsOf(d, sideEdges, area2, tall);
|
|
759
|
+
const g = giveWay(d, cols, area2, f.gutter);
|
|
760
|
+
columnRoom(d, cols, area2, f);
|
|
761
|
+
giveWayNotes(d, g, cols);
|
|
762
|
+
const walk = { x0: area2.x, x1: area2.x + area2.width };
|
|
763
|
+
for (const side of ["left", "right"]) laySide(d, side, cols, g, area2, f, walk, reach.up, tall);
|
|
764
|
+
return rect(walk.x0, area2.y, Math.max(0, walk.x1 - walk.x0), H);
|
|
765
|
+
}
|
|
766
|
+
function forced(d, c, length, w) {
|
|
767
|
+
const edge = { ...c.edge, cross: { ...c.edge.cross, min: w, max: w } };
|
|
768
|
+
const { size: _s, ...plain } = edge;
|
|
769
|
+
return solveEdge(d.scene, plain, d.owned.get(c.edge), length, w, d.prevEdge(c.edge));
|
|
770
|
+
}
|
|
771
|
+
function laySide(d, side, cols, g, area2, f, walk, upInset, tall) {
|
|
772
|
+
const { scene, edges } = d;
|
|
773
|
+
const H = area2.height;
|
|
774
|
+
const outsideSideBar = (c) => c.width > 0 && isOutsideSideBar(scene, c.edge) && !g.railed(c) && !g.riding(c);
|
|
775
|
+
const all = cols.filter((c) => c.side === side);
|
|
776
|
+
const mine = [...all.filter(outsideSideBar), ...all.filter((c) => !outsideSideBar(c))];
|
|
777
|
+
const railed = mine.filter((c) => g.railed(c));
|
|
778
|
+
const riders = mine.filter((c) => g.riding(c));
|
|
779
|
+
const host = mine.find((c) => c.dyn && c.edge.column === true && !c.hand && !g.auto.has(c) && c.width > 0);
|
|
780
|
+
const ridersTop = ridersHeight(d, riders);
|
|
781
|
+
const railW = px(scene.rails?.[side]?.width);
|
|
782
|
+
let railRect = null;
|
|
783
|
+
let gap = px(side === "left" ? f.inset.left : f.inset.right);
|
|
784
|
+
let barLaid = false;
|
|
785
|
+
let railPlace = null;
|
|
786
|
+
const placeRail = () => {
|
|
787
|
+
const lead = barLaid ? gap : 0;
|
|
788
|
+
return side === "left" ? rect(walk.x0 - lead, area2.y, railW, H) : rect(walk.x1 + lead - railW, area2.y, railW, H);
|
|
789
|
+
};
|
|
790
|
+
for (const c of mine) {
|
|
791
|
+
if (!railPlace && !outsideSideBar(c)) {
|
|
792
|
+
railPlace = placeRail();
|
|
793
|
+
if (railed.length > 0) {
|
|
794
|
+
railRect = railPlace;
|
|
795
|
+
const lead = barLaid ? gap : 0;
|
|
796
|
+
const after = barLaid ? Math.max(gap, f.gutter) : f.gutter;
|
|
797
|
+
if (side === "left") walk.x0 += railPlace.width - lead + after;
|
|
798
|
+
else walk.x1 -= railPlace.width - lead + after;
|
|
799
|
+
gap = after;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (outsideSideBar(c)) barLaid = true;
|
|
803
|
+
const base = { side: c.edge.side, ring: finite(c.edge.ring, 0), cross: 0, menu: null, tabs: [], stack: c.solved.stack, free: c.solved.free };
|
|
804
|
+
if (g.railed(c)) {
|
|
805
|
+
edges[c.edge.id] = { ...base, rect: rect(railRect.x, area2.y, 0, H), folded: g.auto.has(c) ? "auto" : "hand" };
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if (g.riding(c)) continue;
|
|
809
|
+
const w = Math.min(g.widths.get(c), Math.max(0, walk.x1 - walk.x0));
|
|
810
|
+
const top = c === host ? ridersTop : 0;
|
|
811
|
+
let solved = top > 0 || Math.abs(w - c.width) > EPS ? forced(d, c, H - top, w) : c.solved;
|
|
812
|
+
let r;
|
|
813
|
+
if (c.edge.outsideInset === true) {
|
|
814
|
+
const y0 = area2.y - upInset;
|
|
815
|
+
const h = tall(c.edge);
|
|
816
|
+
if (side === "left") {
|
|
817
|
+
r = rect(walk.x0 - gap, y0, w, h);
|
|
818
|
+
walk.x0 += w;
|
|
819
|
+
} else {
|
|
820
|
+
r = rect(walk.x1 + gap - w, y0, w, h);
|
|
821
|
+
walk.x1 -= w;
|
|
822
|
+
}
|
|
823
|
+
if (Math.abs(h - H) > EPS || Math.abs(w - c.width) > EPS) solved = forced(d, c, h, w);
|
|
824
|
+
} else if (side === "left") {
|
|
825
|
+
r = rect(walk.x0, area2.y + top, w, H - top);
|
|
826
|
+
walk.x0 += w > 0 ? w + f.gutter : 0;
|
|
827
|
+
if (w > 0) gap = f.gutter;
|
|
828
|
+
} else {
|
|
829
|
+
walk.x1 -= w;
|
|
830
|
+
r = rect(walk.x1, area2.y + top, w, H - top);
|
|
831
|
+
walk.x1 -= w > 0 ? f.gutter : 0;
|
|
832
|
+
if (w > 0) gap = f.gutter;
|
|
833
|
+
}
|
|
834
|
+
emit(d, c.edge, r, solved, w < c.width - EPS ? { shrunk: true } : {});
|
|
835
|
+
}
|
|
836
|
+
if (host && riders.length > 0) layRiders(d, host, riders, area2.y);
|
|
837
|
+
if (railRect) layRail(d, side, railRect, railed, g);
|
|
838
|
+
if (scene.rails?.[side]) d.railPlaces[side] = railPlace ?? placeRail();
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// src/scene/solve.ts
|
|
842
|
+
function solve(given, options = {}) {
|
|
843
|
+
checkEdgeIds(given);
|
|
844
|
+
const d = createDraft(given, options);
|
|
845
|
+
const { scene, order } = d;
|
|
846
|
+
const stage = rect(finite(scene.stage.x, 0), finite(scene.stage.y, 0), px(scene.stage.width), px(scene.stage.height));
|
|
847
|
+
const { inset, docked } = insetOf(d);
|
|
848
|
+
const reserved = order.filter((e) => e.mode !== "overlay");
|
|
849
|
+
const outsideBar = (e) => !isSide(e) && e.span !== "between" && e.outsideInset === true;
|
|
850
|
+
let outer = stage;
|
|
851
|
+
for (const e of reserved) if (outsideBar(e)) outer = cutEdge(d, e, outer, true);
|
|
852
|
+
let area2 = insideInset(outer, inset);
|
|
853
|
+
for (const e of reserved) if (!isSide(e) && e.span !== "between" && !outsideBar(e)) area2 = cutEdge(d, e, area2, true);
|
|
854
|
+
area2 = laySides(d, reserved.filter(isSide), area2, { inset, gutter: px(scene.gutter), docked, outer });
|
|
855
|
+
for (const e of reserved) if (!isSide(e) && e.span === "between") area2 = cutEdge(d, e, area2, true);
|
|
856
|
+
const content = area2;
|
|
857
|
+
let over = content;
|
|
858
|
+
for (const e of order) if (e.mode === "overlay") over = cutEdge(d, e, over, true);
|
|
859
|
+
contentNotes(d, content);
|
|
860
|
+
const floats = layFloats(d, stage, content, inset);
|
|
861
|
+
const { items, edges, rails, railPlaces, columnRoom: columnRoom2, notes } = d;
|
|
862
|
+
return { items, edges, content, floats, rails, railPlaces, ...columnRoom2 !== void 0 ? { columnRoom: columnRoom2 } : {}, notes };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// src/scene/float-resize.ts
|
|
866
|
+
var LIMITS = ["min", "max", "region", "docked"];
|
|
867
|
+
var EPS2 = 0.5;
|
|
868
|
+
var TOUCH = 1e-3;
|
|
869
|
+
var fin = (v, d) => Number.isFinite(v) ? v : d;
|
|
870
|
+
var nonNeg = (v) => Math.max(0, fin(v, 0));
|
|
871
|
+
function floatRegion(scene) {
|
|
872
|
+
const floating = new Set(scene.floats.map((f) => f.id));
|
|
873
|
+
const docked = scene.edges.some((e) => (e.side === "left" || e.side === "right") && e.accepts.length > 0 && e.items.some((id) => !floating.has(id) && !!scene.items[id] && isDockingPanel(scene.items[id])));
|
|
874
|
+
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
875
|
+
const { stage } = scene;
|
|
876
|
+
return { x: stage.x + nonNeg(inset.left), y: stage.y, width: Math.max(0, stage.width - nonNeg(inset.left) - nonNeg(inset.right)), height: stage.height };
|
|
877
|
+
}
|
|
878
|
+
function floatObstacles(scene, l, id) {
|
|
879
|
+
const out = [];
|
|
880
|
+
for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);
|
|
881
|
+
for (const e of Object.values(l.edges)) {
|
|
882
|
+
if (axisOf(e.side) === "row" && e.cross > 0) out.push(e.rect);
|
|
883
|
+
if (e.menu) out.push(e.menu.rect);
|
|
884
|
+
}
|
|
885
|
+
for (const c of scene.chrome ?? []) out.push(c);
|
|
886
|
+
return out.filter((r) => r.width > 0 && r.height > 0);
|
|
887
|
+
}
|
|
888
|
+
function obstacleStop(drawn, obstacles, axis, drag, span) {
|
|
889
|
+
const none = drag === "start" ? -Infinity : Infinity;
|
|
890
|
+
if (!drawn || !drag) return none;
|
|
891
|
+
const lo = (r) => axis === "x" ? r.x : r.y;
|
|
892
|
+
const len = (r) => axis === "x" ? r.width : r.height;
|
|
893
|
+
const across = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
894
|
+
let at = none;
|
|
895
|
+
for (const o of obstacles) {
|
|
896
|
+
const [c0, c1] = across(o);
|
|
897
|
+
if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
|
|
898
|
+
if (drag === "start" && lo(o) + len(o) <= lo(drawn) + EPS2) at = Math.max(at, lo(o) + len(o));
|
|
899
|
+
if (drag === "end" && lo(o) >= lo(drawn) + len(drawn) - EPS2) at = Math.min(at, lo(o));
|
|
900
|
+
}
|
|
901
|
+
return drag === "start" ? Math.min(at, lo(drawn)) : Math.max(at, lo(drawn) + len(drawn));
|
|
902
|
+
}
|
|
903
|
+
function fitAxis(start, length, b, drag, hit) {
|
|
904
|
+
const { min, lo, hi, stop } = b;
|
|
905
|
+
const max = Math.max(min, b.max);
|
|
906
|
+
const raw = fin(length, min);
|
|
907
|
+
if (min >= hi - lo) {
|
|
908
|
+
hit.add("region");
|
|
909
|
+
return [lo, min];
|
|
910
|
+
}
|
|
911
|
+
const bind = (cands, pick) => {
|
|
912
|
+
const at = cands.reduce((m, [v]) => pick(m, v), cands[0][0]);
|
|
913
|
+
return [at, cands.filter(([v]) => Math.abs(v - at) <= EPS2).map(([, k]) => k)];
|
|
914
|
+
};
|
|
915
|
+
if (drag === "start") {
|
|
916
|
+
const asked2 = fin(start, lo) + raw;
|
|
917
|
+
const end = Math.min(hi, Math.max(lo + min, asked2));
|
|
918
|
+
if (Math.abs(end - asked2) > EPS2) hit.add("region");
|
|
919
|
+
const [down, why2] = bind([[end - max, "max"], [lo, "region"], [stop, "docked"]], Math.max);
|
|
920
|
+
let from = end - raw;
|
|
921
|
+
if (from > end - min) {
|
|
922
|
+
from = end - min;
|
|
923
|
+
hit.add("min");
|
|
924
|
+
} else if (from < down - TOUCH) {
|
|
925
|
+
from = why2.includes("docked") ? Math.min(down, end) : Math.min(down, end - min);
|
|
926
|
+
for (const k of from === down ? why2 : ["min"]) hit.add(k);
|
|
927
|
+
}
|
|
928
|
+
return [from, end - from];
|
|
929
|
+
}
|
|
930
|
+
const asked = fin(start, lo);
|
|
931
|
+
const a = Math.max(lo, Math.min(hi - min, asked));
|
|
932
|
+
if (Math.abs(a - asked) > EPS2) hit.add("region");
|
|
933
|
+
const [up, why] = bind([[a + max, "max"], [hi, "region"], [stop, "docked"]], Math.min);
|
|
934
|
+
let to = a + raw;
|
|
935
|
+
if (to < a + min) {
|
|
936
|
+
to = a + min;
|
|
937
|
+
hit.add("min");
|
|
938
|
+
} else if (to > up + TOUCH) {
|
|
939
|
+
to = why.includes("docked") ? Math.max(up, a) : Math.max(up, a + min);
|
|
940
|
+
for (const k of to === up ? why : ["min"]) hit.add(k);
|
|
941
|
+
}
|
|
942
|
+
return [a, to - a];
|
|
943
|
+
}
|
|
944
|
+
function fitResize(scene, id, rect2, moving) {
|
|
945
|
+
const f = scene.floats.find((x2) => x2.id === id);
|
|
946
|
+
const item = Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
|
|
947
|
+
if (!f || !item || item.fixed) return null;
|
|
948
|
+
const fo = f.orient ?? floatOrientOf(item);
|
|
949
|
+
const form = formsOf(item, fo)[0];
|
|
950
|
+
if (floatShape(item, f).form !== 0 || form && !form.main.grows) return null;
|
|
951
|
+
const l = solve(scene);
|
|
952
|
+
const drawn = l.items[id]?.rect;
|
|
953
|
+
if (!drawn) return null;
|
|
954
|
+
const min = floatFloor(item, form, fo, drawn);
|
|
955
|
+
const max = { width: fin(item.floatMax?.width, Infinity), height: fin(item.floatMax?.height, Infinity) };
|
|
956
|
+
const region = floatRegion(scene);
|
|
957
|
+
const dragX = moving.left ? "start" : moving.right ? "end" : null;
|
|
958
|
+
const dragY = moving.top ? "start" : moving.bottom ? "end" : null;
|
|
959
|
+
const obstacles = floatObstacles(scene, l, id);
|
|
960
|
+
const hit = /* @__PURE__ */ new Set();
|
|
961
|
+
const [x, width] = fitAxis(rect2.x, rect2.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);
|
|
962
|
+
const [y, height] = fitAxis(rect2.y, rect2.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);
|
|
963
|
+
const { anchor: _a, ...plain } = f;
|
|
964
|
+
const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, scene.stage).fit.rect;
|
|
965
|
+
if (Math.abs(placed.x - x) > EPS2 || Math.abs(placed.y - y) > EPS2) hit.add("docked");
|
|
966
|
+
if (Math.abs(placed.width - width) > EPS2 || Math.abs(placed.height - height) > EPS2) hit.add("min");
|
|
967
|
+
return { rect: placed, limits: LIMITS.filter((k) => hit.has(k)) };
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/scene/changes.ts
|
|
971
|
+
var withItem = (scene, item) => ({ ...scene, items: { ...scene.items, [item.id]: item } });
|
|
972
|
+
var itemOf = (scene, id) => Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
|
|
973
|
+
function closeRings(edges, sides) {
|
|
974
|
+
const out = [...edges];
|
|
975
|
+
for (const side of sides) {
|
|
976
|
+
const idx = out.map((e, i) => ({ e, i })).filter((x) => x.e.side === side);
|
|
977
|
+
idx.sort((a, b) => a.e.ring === b.e.ring ? a.i - b.i : a.e.ring < b.e.ring ? -1 : 1);
|
|
978
|
+
idx.forEach((x, ring) => {
|
|
979
|
+
if (x.e.ring !== ring) out[x.i] = { ...x.e, ring };
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
return out;
|
|
983
|
+
}
|
|
984
|
+
function prune(scene) {
|
|
985
|
+
const gone = scene.edges.filter((e) => e.column === true && e.items.length === 0);
|
|
986
|
+
if (gone.length === 0) return scene;
|
|
987
|
+
const sides = new Set(gone.map((e) => e.side));
|
|
988
|
+
return { ...scene, edges: closeRings(scene.edges.filter((e) => !gone.includes(e)), sides) };
|
|
989
|
+
}
|
|
990
|
+
function lift(scene, id) {
|
|
991
|
+
const inEdge = scene.edges.some((e) => e.items.includes(id));
|
|
992
|
+
const inFloat = scene.floats.some((f) => f.id === id);
|
|
993
|
+
if (!inEdge && !inFloat) return scene;
|
|
994
|
+
return prune({
|
|
995
|
+
...scene,
|
|
996
|
+
edges: inEdge ? scene.edges.map((e) => e.items.includes(id) ? { ...e, items: e.items.filter((x) => x !== id) } : e) : scene.edges,
|
|
997
|
+
floats: inFloat ? scene.floats.filter((f) => f.id !== id) : scene.floats
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
function newColumn(scene, side, kind, ring, items) {
|
|
1001
|
+
const t = scene.columns?.[side];
|
|
1002
|
+
if (!t || !t.accepts.includes(kind)) return null;
|
|
1003
|
+
const taken = new Set(scene.edges.map((e) => e.id));
|
|
1004
|
+
let n = 0;
|
|
1005
|
+
while (taken.has(`${side}-${n}`)) n++;
|
|
1006
|
+
return columnFromTemplate(t, `${side}-${n}`, side, ring, items);
|
|
1007
|
+
}
|
|
1008
|
+
function sideRings(edges, side) {
|
|
1009
|
+
return new Map(closeRings(edges, /* @__PURE__ */ new Set([side])).filter((e) => e.side === side).map((e) => [e.id, e.ring]));
|
|
1010
|
+
}
|
|
1011
|
+
function columnFloor(edges, side) {
|
|
1012
|
+
const mine = edges.filter((e) => e.side === side).sort((a, b) => a.ring - b.ring);
|
|
1013
|
+
let n = 0;
|
|
1014
|
+
while (n < mine.length && mine[n].column !== true) n++;
|
|
1015
|
+
return n;
|
|
1016
|
+
}
|
|
1017
|
+
function insertColumn(scene0, id, side, ring) {
|
|
1018
|
+
const scene = { ...scene0, edges: closeRings(scene0.edges, /* @__PURE__ */ new Set([side])) };
|
|
1019
|
+
const kind = scene.items[id].kind;
|
|
1020
|
+
const mine = scene.edges.filter((e) => e.side === side);
|
|
1021
|
+
const floor = columnFloor(scene.edges, side);
|
|
1022
|
+
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));
|
|
1023
|
+
const col = newColumn(scene, side, kind, r, [id]);
|
|
1024
|
+
if (!col) return null;
|
|
1025
|
+
if (!zoneTakes(col, "start", kind)) return null;
|
|
1026
|
+
const item = scene.items[id];
|
|
1027
|
+
const zone = zoneTakes(col, zoneOf(item), kind) ? zoneOf(item) : zonesTaking(col, kind)[0] ?? "start";
|
|
1028
|
+
const { align: _a, ...plain } = item;
|
|
1029
|
+
const placed = withItem(scene, zone === "start" ? plain : { ...plain, align: zone });
|
|
1030
|
+
const shifted = placed.edges.map((e) => e.side === side && e.ring >= r ? { ...e, ring: e.ring + 1 } : e);
|
|
1031
|
+
return { ...placed, edges: closeRings([...shifted, col], /* @__PURE__ */ new Set([side])) };
|
|
1032
|
+
}
|
|
1033
|
+
function insertIndex(scene, edge, zone, at) {
|
|
1034
|
+
const rank = { start: 0, center: 1, end: 2 };
|
|
1035
|
+
const inZone = edge.items.map((id, i) => ({ id, i })).filter((x) => zoneOf(itemOf(scene, x.id)) === zone);
|
|
1036
|
+
const k = Math.min(Math.max(0, Math.floor(Number.isFinite(at) ? at : inZone.length)), inZone.length);
|
|
1037
|
+
if (k < inZone.length) return inZone[k].i;
|
|
1038
|
+
if (inZone.length > 0) return inZone[inZone.length - 1].i + 1;
|
|
1039
|
+
let idx = 0;
|
|
1040
|
+
edge.items.forEach((id, i) => {
|
|
1041
|
+
if (rank[zoneOf(itemOf(scene, id))] < rank[zone]) idx = i + 1;
|
|
1042
|
+
});
|
|
1043
|
+
return idx;
|
|
1044
|
+
}
|
|
1045
|
+
function moveTo(scene, id, place) {
|
|
1046
|
+
const item = itemOf(scene, id);
|
|
1047
|
+
if (!item || item.fixed) return scene;
|
|
1048
|
+
if (place.kind === "float") {
|
|
1049
|
+
const out = floatAt(scene, id, place.rect);
|
|
1050
|
+
const anchor = place.anchor;
|
|
1051
|
+
if (!anchor || out === scene) return out;
|
|
1052
|
+
return { ...out, floats: out.floats.map((f) => f.id === id ? { ...f, anchor } : f) };
|
|
1053
|
+
}
|
|
1054
|
+
if (place.kind === "column" || place.kind === "rail") {
|
|
1055
|
+
if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
|
|
1056
|
+
const folded = place.kind === "rail" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;
|
|
1057
|
+
const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring);
|
|
1058
|
+
return made ?? scene;
|
|
1059
|
+
}
|
|
1060
|
+
const edge = scene.edges.find((e) => e.id === place.edge);
|
|
1061
|
+
if (!edge || !edge.accepts.includes(item.kind)) return scene;
|
|
1062
|
+
const zone = place.zone ?? (zoneTakes(edge, zoneOf(item), item.kind) ? zoneOf(item) : zonesTaking(edge, item.kind)[0]);
|
|
1063
|
+
if (!zone || !zoneTakes(edge, zone, item.kind)) return scene;
|
|
1064
|
+
const { align: _drop, ...rest } = item;
|
|
1065
|
+
const moved = zone === "start" ? rest : { ...rest, align: zone };
|
|
1066
|
+
const lifted = withItem(lift(scene, id), moved);
|
|
1067
|
+
const target = lifted.edges.find((e) => e.id === place.edge);
|
|
1068
|
+
if (!target) return scene;
|
|
1069
|
+
const k = insertIndex(lifted, target, zone, place.at);
|
|
1070
|
+
return { ...lifted, edges: lifted.edges.map((e) => e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e) };
|
|
1071
|
+
}
|
|
1072
|
+
function floatAt(scene, id, at, orient2) {
|
|
1073
|
+
const item = itemOf(scene, id);
|
|
1074
|
+
if (!item || item.fixed || !scene.floatKinds.includes(item.kind)) return scene;
|
|
1075
|
+
const was = scene.floats.find((f) => f.id === id);
|
|
1076
|
+
const o = orient2 ?? was?.orient;
|
|
1077
|
+
const size = floatSizeOf(item, o ?? floatOrientOf(item));
|
|
1078
|
+
const float = at ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...o ? { orient: o } : {} } : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: "content-top-right", ...o ? { orient: o } : {} };
|
|
1079
|
+
const next = at && at.width > 0 && at.height > 0 ? { ...item, floatSize: { width: at.width, height: at.height } } : item;
|
|
1080
|
+
const lifted = lift(withItem(scene, next), id);
|
|
1081
|
+
return { ...lifted, floats: [...lifted.floats, float] };
|
|
1082
|
+
}
|
|
1083
|
+
function fold(scene, id, on) {
|
|
1084
|
+
const item = itemOf(scene, id);
|
|
1085
|
+
if (!item || item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id))) return scene;
|
|
1086
|
+
if (on) return (item.from ?? 0) >= 1 ? scene : withItem(scene, { ...item, from: 1 });
|
|
1087
|
+
if (item.from === void 0) return scene;
|
|
1088
|
+
const { from: _f, ...rest } = item;
|
|
1089
|
+
return withItem(scene, rest);
|
|
1090
|
+
}
|
|
1091
|
+
var nextAge = (scene) => Object.values(scene.items).reduce((m, it) => Math.max(m, Number.isFinite(it.used) ? it.used : 0), 0) + 1;
|
|
1092
|
+
function use(scene, id) {
|
|
1093
|
+
const item = itemOf(scene, id);
|
|
1094
|
+
if (!item) return scene;
|
|
1095
|
+
return withItem(scene, { ...item, used: nextAge(scene) });
|
|
1096
|
+
}
|
|
1097
|
+
function keep(scene, id, on) {
|
|
1098
|
+
const item = itemOf(scene, id);
|
|
1099
|
+
if (!item || !!item.kept === on) return scene;
|
|
1100
|
+
if (on) return withItem(scene, { ...item, kept: true });
|
|
1101
|
+
const { kept: _k, ...rest } = item;
|
|
1102
|
+
return withItem(scene, rest);
|
|
1103
|
+
}
|
|
1104
|
+
function open(scene, id) {
|
|
1105
|
+
const item = itemOf(scene, id);
|
|
1106
|
+
if (!item || !item.closed) return scene;
|
|
1107
|
+
const { closed: _c, ...rest } = item;
|
|
1108
|
+
return withItem(scene, rest);
|
|
1109
|
+
}
|
|
1110
|
+
function close(scene, id) {
|
|
1111
|
+
const item = itemOf(scene, id);
|
|
1112
|
+
if (!item || item.closed || item.fixed) return scene;
|
|
1113
|
+
return withItem(scene, { ...item, closed: true });
|
|
1114
|
+
}
|
|
1115
|
+
function raise(scene, id) {
|
|
1116
|
+
const i = scene.floats.findIndex((f) => f.id === id);
|
|
1117
|
+
if (i < 0 || i === scene.floats.length - 1) return scene;
|
|
1118
|
+
return { ...scene, floats: [...scene.floats.slice(0, i), ...scene.floats.slice(i + 1), scene.floats[i]] };
|
|
1119
|
+
}
|
|
1120
|
+
function orient(scene, id, to) {
|
|
1121
|
+
const i = scene.floats.findIndex((f) => f.id === id);
|
|
1122
|
+
const item = scene.items[id];
|
|
1123
|
+
if (i < 0 || !item || (scene.floats[i].orient ?? floatOrientOf(item)) === to) return scene;
|
|
1124
|
+
return { ...scene, floats: scene.floats.map((f, k) => k === i ? { ...f, orient: to } : f) };
|
|
1125
|
+
}
|
|
1126
|
+
function resize(scene, id, size, moving = { right: true, bottom: true }) {
|
|
1127
|
+
if (typeof size === "number") return resizeEdge(scene, id, size);
|
|
1128
|
+
const fit = fitResize(scene, id, size, moving);
|
|
1129
|
+
const i = scene.floats.findIndex((f) => f.id === id);
|
|
1130
|
+
const item = itemOf(scene, id);
|
|
1131
|
+
if (!fit || i < 0 || !item) return scene;
|
|
1132
|
+
const { anchor: _a, ...plain } = scene.floats[i];
|
|
1133
|
+
const float = { ...plain, rect: fit.rect };
|
|
1134
|
+
return withItem({ ...scene, floats: scene.floats.map((g, k) => k === i ? float : g) }, { ...item, floatSize: { width: fit.rect.width, height: fit.rect.height } });
|
|
1135
|
+
}
|
|
1136
|
+
function resizeEdge(scene, edgeId, size) {
|
|
1137
|
+
const edge = scene.edges.find((e) => e.id === edgeId);
|
|
1138
|
+
if (!edge) return scene;
|
|
1139
|
+
if (!Number.isFinite(size)) {
|
|
1140
|
+
if (edge.size === void 0) return scene;
|
|
1141
|
+
const { size: _s, ...rest } = edge;
|
|
1142
|
+
return { ...scene, edges: scene.edges.map((e) => e === edge ? rest : e) };
|
|
1143
|
+
}
|
|
1144
|
+
return { ...scene, edges: scene.edges.map((e) => e === edge ? { ...e, size } : e) };
|
|
1145
|
+
}
|
|
1146
|
+
function setSide(scene, edgeId, side) {
|
|
1147
|
+
const edge = scene.edges.find((e) => e.id === edgeId);
|
|
1148
|
+
if (!edge || edge.side === side || axisOf(edge.side) !== axisOf(side)) return scene;
|
|
1149
|
+
const moved = { ...edge, side, ring: 0 };
|
|
1150
|
+
const others = scene.edges.filter((e) => e !== edge).map((e) => e.side === side ? { ...e, ring: e.ring + 1 } : e);
|
|
1151
|
+
return { ...scene, edges: closeRings([moved, ...others], /* @__PURE__ */ new Set([edge.side, side])) };
|
|
1152
|
+
}
|
|
1153
|
+
function homeFor(scene, id, start) {
|
|
1154
|
+
for (const e of start.edges) {
|
|
1155
|
+
const k = e.items.indexOf(id);
|
|
1156
|
+
if (k < 0) continue;
|
|
1157
|
+
const zone = zoneOf(itemOf(start, id) ?? itemOf(scene, id));
|
|
1158
|
+
const found = scene.edges.find((x) => x.id === e.id);
|
|
1159
|
+
const here = found && (e.column !== true || found.items.some((x) => e.items.includes(x))) ? found : void 0;
|
|
1160
|
+
if (here) {
|
|
1161
|
+
const now = here.items.filter((x) => x !== id && zoneOf(itemOf(scene, x)) === zone);
|
|
1162
|
+
const next = e.items.slice(k + 1).find((x) => now.includes(x));
|
|
1163
|
+
return { kind: "gap", edge: e.id, zone, at: next ? now.indexOf(next) : now.length };
|
|
1164
|
+
}
|
|
1165
|
+
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 };
|
|
1166
|
+
return null;
|
|
1167
|
+
}
|
|
1168
|
+
const f = start.floats.find((x) => x.id === id);
|
|
1169
|
+
if (f) return { kind: "float", rect: f.rect, ...f.anchor ? { anchor: f.anchor } : {} };
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
function dockHome(scene, id, start) {
|
|
1173
|
+
const place = homeFor(scene, id, start);
|
|
1174
|
+
if (!place) return scene;
|
|
1175
|
+
const moved = moveTo(scene, id, place);
|
|
1176
|
+
const item = itemOf(moved, id);
|
|
1177
|
+
if (!item) return scene;
|
|
1178
|
+
const from = itemOf(start, id)?.from;
|
|
1179
|
+
if (item.from === from) return moved;
|
|
1180
|
+
const { from: _f, ...plain } = item;
|
|
1181
|
+
return withItem(moved, from === void 0 ? plain : { ...plain, from });
|
|
1182
|
+
}
|
|
1183
|
+
function clampFloat(r, stage, drawn = r) {
|
|
1184
|
+
const at = clampInto({ x: r.x, y: r.y, width: drawn.width, height: drawn.height }, stage);
|
|
1185
|
+
return { x: at.x, y: at.y, width: r.width, height: r.height };
|
|
1186
|
+
}
|
|
1187
|
+
function drawnFloatSize(item, f) {
|
|
1188
|
+
const s = floatShape(item, f);
|
|
1189
|
+
return { width: s.width, height: s.height };
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// src/scene/store.ts
|
|
1193
|
+
var ANCHORS = ["content-top-left", "content-top", "content-top-right", "content-right", "content-bottom-right", "content-bottom", "content-bottom-left", "content-left"];
|
|
1194
|
+
var isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
1195
|
+
var isSize = (x) => isNum(x) && x > 0;
|
|
1196
|
+
var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
1197
|
+
var record = () => /* @__PURE__ */ Object.create(null);
|
|
1198
|
+
function storeScene(scene) {
|
|
1199
|
+
const items = record();
|
|
1200
|
+
for (const [id, it] of Object.entries(scene.items)) {
|
|
1201
|
+
if (id === "__proto__") continue;
|
|
1202
|
+
items[id] = {
|
|
1203
|
+
used: isNum(it.used) ? it.used : 0,
|
|
1204
|
+
...it.kept ? { kept: true } : {},
|
|
1205
|
+
...isNum(it.from) && it.from >= 1 ? { from: Math.floor(it.from) } : {},
|
|
1206
|
+
...it.closed ? { closed: true } : {},
|
|
1207
|
+
...it.align === "center" || it.align === "end" ? { align: it.align } : {},
|
|
1208
|
+
...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
return {
|
|
1212
|
+
v: 1,
|
|
1213
|
+
edges: scene.edges.map((e) => ({ id: e.id, side: e.side, ring: e.ring, items: [...e.items], ...isNum(e.size) ? { size: e.size } : {}, ...e.column === true ? { column: true } : {} })),
|
|
1214
|
+
floats: scene.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) => ({ id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...f.anchor ? { anchor: f.anchor } : {} })),
|
|
1215
|
+
items
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
function readScene(data, base) {
|
|
1219
|
+
checkEdgeIds(base);
|
|
1220
|
+
try {
|
|
1221
|
+
return read(data, base);
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
return { scene: base, dropped: [], error: `unreadable: ${e instanceof Error ? e.message : typeof e}` };
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
var words = (v) => typeof v === "number" ? String(v) : typeof v === "string" ? JSON.stringify(v.length > 24 ? `${v.slice(0, 24)}\u2026` : v) : typeof v;
|
|
1227
|
+
function withFixed(baseIds, stored, isFixed) {
|
|
1228
|
+
const out = [...stored];
|
|
1229
|
+
const missing = (id) => isFixed(id) && !stored.includes(id);
|
|
1230
|
+
let tail = baseIds.length;
|
|
1231
|
+
while (tail > 0 && isFixed(baseIds[tail - 1])) tail--;
|
|
1232
|
+
baseIds.forEach((id, i) => {
|
|
1233
|
+
if (missing(id) && i < tail) out.splice(Math.min(i, out.length), 0, id);
|
|
1234
|
+
});
|
|
1235
|
+
return [...out, ...baseIds.slice(tail).filter(missing)];
|
|
1236
|
+
}
|
|
1237
|
+
function read(data, base) {
|
|
1238
|
+
if (!isObject(data)) return { scene: base, dropped: [], error: "not an object" };
|
|
1239
|
+
if (data.v !== 1) return { scene: base, dropped: [], error: `unknown version ${words(data.v)} (this reads version 1)` };
|
|
1240
|
+
const dropped = [];
|
|
1241
|
+
const drop = (what) => {
|
|
1242
|
+
if (!dropped.includes(what)) dropped.push(what);
|
|
1243
|
+
};
|
|
1244
|
+
for (const k of Object.keys(data)) if (!["v", "edges", "floats", "items"].includes(k)) drop(k);
|
|
1245
|
+
const known = (id) => typeof id === "string" && id !== "__proto__" && Object.hasOwn(base.items, id);
|
|
1246
|
+
const isFixed = (id) => known(id) && base.items[id].fixed === true;
|
|
1247
|
+
const items = { ...base.items };
|
|
1248
|
+
if (data.items !== void 0 && !isObject(data.items)) drop("items");
|
|
1249
|
+
else if (isObject(data.items)) {
|
|
1250
|
+
for (const id of Object.keys(data.items)) {
|
|
1251
|
+
const s = data.items[id];
|
|
1252
|
+
if (!known(id) || !isObject(s)) {
|
|
1253
|
+
drop(`item:${id}`);
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
const b = base.items[id];
|
|
1257
|
+
const { kept: _k, from: _f, closed: _c, align: _a, floatSize: _s, ...plain } = b;
|
|
1258
|
+
let it = { ...plain, used: b.used };
|
|
1259
|
+
for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
|
|
1260
|
+
if (isNum(s.used)) it = { ...it, used: s.used };
|
|
1261
|
+
else if (s.used !== void 0) drop(`item:${id}:used`);
|
|
1262
|
+
if (s.kept === true) it = { ...it, kept: true };
|
|
1263
|
+
else if (s.kept !== void 0 && s.kept !== false) drop(`item:${id}:kept`);
|
|
1264
|
+
const byHand = !b.fixed || base.edges.some((e) => e.foldable === true && e.items.includes(id));
|
|
1265
|
+
if (isNum(s.from) && Number.isInteger(s.from) && s.from >= 1 && byHand) it = { ...it, from: s.from };
|
|
1266
|
+
else if (s.from !== void 0) drop(`item:${id}:from`);
|
|
1267
|
+
if (!byHand && b.from !== void 0) it = { ...it, from: b.from };
|
|
1268
|
+
if (s.closed === true && !b.fixed) it = { ...it, closed: true };
|
|
1269
|
+
else if (s.closed !== void 0 && s.closed !== false) drop(`item:${id}:closed`);
|
|
1270
|
+
if (s.align === "center" || s.align === "end") it = { ...it, align: s.align };
|
|
1271
|
+
else if (s.align !== void 0 && s.align !== "start") drop(`item:${id}:align`);
|
|
1272
|
+
if (b.fixed && b.align) it = { ...it, align: b.align };
|
|
1273
|
+
const fs = s.floatSize;
|
|
1274
|
+
if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) it = { ...it, floatSize: { width: fs.width, height: fs.height } };
|
|
1275
|
+
else if (fs !== void 0) drop(`item:${id}:floatSize`);
|
|
1276
|
+
items[id] = it;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
const placed = /* @__PURE__ */ new Set();
|
|
1280
|
+
const order = /* @__PURE__ */ new Map();
|
|
1281
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
1282
|
+
const made = [];
|
|
1283
|
+
const rings = /* @__PURE__ */ new Map();
|
|
1284
|
+
const moves = /* @__PURE__ */ new Map();
|
|
1285
|
+
const anchorMoves = /* @__PURE__ */ new Map();
|
|
1286
|
+
const anchorSizes = /* @__PURE__ */ new Map();
|
|
1287
|
+
if (data.edges !== void 0 && !Array.isArray(data.edges)) drop("edges");
|
|
1288
|
+
for (const e of Array.isArray(data.edges) ? data.edges : []) {
|
|
1289
|
+
if (!isObject(e) || typeof e.id !== "string") {
|
|
1290
|
+
drop("an edge with no id");
|
|
1291
|
+
continue;
|
|
1292
|
+
}
|
|
1293
|
+
let edge = base.edges.find((x) => x.id === e.id) ?? made.find((x) => x.id === e.id);
|
|
1294
|
+
const listed = Array.isArray(e.items) ? e.items : [];
|
|
1295
|
+
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)));
|
|
1296
|
+
for (const b of anchorEdges) {
|
|
1297
|
+
const side = SIDES.includes(e.side) ? e.side : edge?.side;
|
|
1298
|
+
if (side && side !== b.side && axisOf(side) === axisOf(b.side)) anchorMoves.set(b.id, side);
|
|
1299
|
+
if (isNum(e.size)) anchorSizes.set(b.id, e.size);
|
|
1300
|
+
}
|
|
1301
|
+
const describesAnchor = anchorEdges.length > 0;
|
|
1302
|
+
if (!edge && describesAnchor) continue;
|
|
1303
|
+
if (!edge && e.column === true && (e.side === "left" || e.side === "right") && base.columns?.[e.side] && !isReservedEdgeId(e.id)) {
|
|
1304
|
+
edge = columnFromTemplate(base.columns[e.side], e.id, e.side, isNum(e.ring) ? e.ring : Infinity, []);
|
|
1305
|
+
made.push(edge);
|
|
1306
|
+
}
|
|
1307
|
+
if (!edge || order.has(edge.id)) {
|
|
1308
|
+
drop(`edge:${e.id}`);
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);
|
|
1312
|
+
if (e.side !== void 0 && !SIDES.includes(e.side)) drop(`edge:${e.id}:side`);
|
|
1313
|
+
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);
|
|
1314
|
+
const ids = [];
|
|
1315
|
+
for (const id of Array.isArray(e.items) ? e.items : []) {
|
|
1316
|
+
if (!known(id) || placed.has(id)) drop(`edge:${edge.id}:${String(id)}`);
|
|
1317
|
+
else if (isFixed(id)) {
|
|
1318
|
+
if (edge.items.includes(id) && base.edges.some((x) => x.id === edge.id)) {
|
|
1319
|
+
ids.push(id);
|
|
1320
|
+
placed.add(id);
|
|
1321
|
+
} else if (!anchorEdges.some((b) => b.items.includes(id))) drop(`edge:${edge.id}:${id}`);
|
|
1322
|
+
} else if (!edge.accepts.includes(items[id].kind)) drop(`edge:${edge.id}:${id}`);
|
|
1323
|
+
else {
|
|
1324
|
+
ids.push(id);
|
|
1325
|
+
placed.add(id);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
order.set(edge.id, ids);
|
|
1329
|
+
if (describesAnchor) {
|
|
1330
|
+
if (!sizes.has(edge.id)) sizes.set(edge.id, edge.size);
|
|
1331
|
+
} else if (isNum(e.size)) sizes.set(edge.id, e.size);
|
|
1332
|
+
else if (e.size !== void 0) drop(`edge:${edge.id}:size`);
|
|
1333
|
+
else sizes.set(edge.id, void 0);
|
|
1334
|
+
}
|
|
1335
|
+
for (const [id, side] of anchorMoves) moves.set(id, side);
|
|
1336
|
+
for (const [id, size] of anchorSizes) sizes.set(id, size);
|
|
1337
|
+
const floats = [];
|
|
1338
|
+
if (data.floats !== void 0 && !Array.isArray(data.floats)) drop("floats");
|
|
1339
|
+
for (const f of Array.isArray(data.floats) ? data.floats : []) {
|
|
1340
|
+
if (!isObject(f) || typeof f.id !== "string") {
|
|
1341
|
+
drop("a float with no id");
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
const id = f.id;
|
|
1345
|
+
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)) {
|
|
1346
|
+
drop(`float:${id}`);
|
|
1347
|
+
continue;
|
|
1348
|
+
}
|
|
1349
|
+
for (const k of Object.keys(f)) if (k === "pinned") drop(`pinned:${id}`);
|
|
1350
|
+
else if (!["id", "x", "y", "width", "height", "orient", "anchor"].includes(k)) drop(`float:${id}:${k}`);
|
|
1351
|
+
const o = f.orient === "row" || f.orient === "column" ? f.orient : void 0;
|
|
1352
|
+
if (f.orient !== void 0 && !o) drop(`float:${id}:orient`);
|
|
1353
|
+
const a = ANCHORS.includes(f.anchor) ? f.anchor : void 0;
|
|
1354
|
+
if (f.anchor !== void 0 && !a) drop(`float:${id}:anchor`);
|
|
1355
|
+
placed.add(id);
|
|
1356
|
+
const r = rect(f.x, f.y, f.width, f.height);
|
|
1357
|
+
const drawn = drawnFloatSize(items[id], { rect: r, ...o ? { orient: o } : {} });
|
|
1358
|
+
floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {} });
|
|
1359
|
+
}
|
|
1360
|
+
const edges = [...base.edges, ...made].map((edge) => {
|
|
1361
|
+
const stored = order.get(edge.id) ?? [];
|
|
1362
|
+
const rest = edge.items.filter((id) => !isFixed(id) && !placed.has(id));
|
|
1363
|
+
for (const id of rest) placed.add(id);
|
|
1364
|
+
let tail = stored.length;
|
|
1365
|
+
while (tail > 0 && isFixed(stored[tail - 1])) tail--;
|
|
1366
|
+
const listed = [...stored.slice(0, tail), ...rest, ...stored.slice(tail)];
|
|
1367
|
+
const items1 = withFixed(edge.items, listed, isFixed);
|
|
1368
|
+
const size = sizes.has(edge.id) ? sizes.get(edge.id) : edge.size;
|
|
1369
|
+
const { size: _s, ...plain } = edge;
|
|
1370
|
+
return { ...plain, ring: rings.get(edge.id) ?? edge.ring, items: items1, ...size !== void 0 ? { size } : {} };
|
|
1371
|
+
});
|
|
1372
|
+
for (const f of base.floats) if (!placed.has(f.id)) floats.push(f);
|
|
1373
|
+
let scene = prune({ ...base, items, edges: closeRings(edges, new Set(made.length > 0 || rings.size > 0 ? ["left", "right"] : [])), floats });
|
|
1374
|
+
for (const [id, side] of moves) scene = setSide(scene, id, side);
|
|
1375
|
+
return { scene, dropped };
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
// src/scene/targets/anchor.ts
|
|
1379
|
+
var OTHER = { left: "right", right: "left", top: "bottom", bottom: "top" };
|
|
1380
|
+
function anchorTargets(scene, dragged, options) {
|
|
1381
|
+
const none = { targets: [], refusals: [], lost: [] };
|
|
1382
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
1383
|
+
const now = solve(scene, prev);
|
|
1384
|
+
const me = now.items[dragged];
|
|
1385
|
+
const edge = me?.edge ? scene.edges.find((e) => e.id === me.edge) : void 0;
|
|
1386
|
+
if (!me || !edge || edge.moves !== "side" || me.floating) return none;
|
|
1387
|
+
const homeAfter = () => ({ scene, layout: now });
|
|
1388
|
+
const targets2 = [];
|
|
1389
|
+
const side = OTHER[edge.side];
|
|
1390
|
+
const moved = use(setSide(scene, edge.id, side), dragged);
|
|
1391
|
+
const layout = solve(moved, prev);
|
|
1392
|
+
const placed = layout.edges[edge.id]?.rect;
|
|
1393
|
+
const slot = layout.items[dragged]?.rect;
|
|
1394
|
+
if (placed && slot && area(placed) > EPS) {
|
|
1395
|
+
const pieces = (scene.chrome ?? []).reduce((ps, c) => ps.flatMap((p) => subtract(p, rect(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);
|
|
1396
|
+
if (pieces.length > 0) {
|
|
1397
|
+
const hit = pieces.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1398
|
+
const result = { scene: moved, layout };
|
|
1399
|
+
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 });
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit: me.rect, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
1403
|
+
return { targets: targets2, refusals: [], lost: [] };
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/scene/targets/kinds.ts
|
|
1407
|
+
var RAIL_REACH = 24;
|
|
1408
|
+
var EDGE_KINDS = {
|
|
1409
|
+
bar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false },
|
|
1410
|
+
sideBar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false },
|
|
1411
|
+
column: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false },
|
|
1412
|
+
barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false },
|
|
1413
|
+
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 },
|
|
1414
|
+
railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false },
|
|
1415
|
+
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 }
|
|
1416
|
+
};
|
|
1417
|
+
function edgeKindOf(scene, e) {
|
|
1418
|
+
if (e.compact) return "rail";
|
|
1419
|
+
if (e.side === "top" || e.side === "bottom") return e.span === "between" ? "barBetween" : "bar";
|
|
1420
|
+
return isSideBar(scene, e) ? "sideBar" : "column";
|
|
1421
|
+
}
|
|
1422
|
+
var opensEmpty = (scene, edge, kind) => EDGE_KINDS[edgeKindOf(scene, edge)].opens === "any" || zoneTakes(edge, "start", kind);
|
|
1423
|
+
|
|
1424
|
+
// src/scene/targets/edges.ts
|
|
1425
|
+
function reservedRect(scene, l, id) {
|
|
1426
|
+
const it = l.items[id];
|
|
1427
|
+
const e = it.edge ? l.edges[it.edge] : void 0;
|
|
1428
|
+
const f = e ? formsOf(scene.items[id], axisOf(e.side))[it.form] : void 0;
|
|
1429
|
+
if (!e || !f?.main.grows) return it.rect;
|
|
1430
|
+
const column = axisOf(e.side) === "column";
|
|
1431
|
+
const len = column ? it.rect.height : it.rect.width;
|
|
1432
|
+
const keep2 = Math.min(len, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len));
|
|
1433
|
+
const shift = it.zone === "end" ? len - keep2 : it.zone === "center" ? (len - keep2) / 2 : 0;
|
|
1434
|
+
return column ? rect(it.rect.x, it.rect.y + shift, it.rect.width, keep2) : rect(it.rect.x + shift, it.rect.y, keep2, it.rect.height);
|
|
1435
|
+
}
|
|
1436
|
+
function slotAt(c, zone, line, id, place, lands, home = false) {
|
|
1437
|
+
const result = c.settle(use(moveTo(c.scene, c.dragged, place), c.dragged));
|
|
1438
|
+
const isHome = home || c.isHome(result);
|
|
1439
|
+
return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout) };
|
|
1440
|
+
}
|
|
1441
|
+
function distinctSlots(c, slots) {
|
|
1442
|
+
const landing = (s) => s.result.layout.items[c.dragged]?.rect;
|
|
1443
|
+
const sameMove = (a, b) => {
|
|
1444
|
+
if (a.zone !== b.zone) return false;
|
|
1445
|
+
if (a.home && b.home) return true;
|
|
1446
|
+
const [p, q] = [landing(a), landing(b)];
|
|
1447
|
+
return Math.abs(a.line - b.line) < EPS && (!p || !q ? p === q : Math.abs(p.x - q.x) + Math.abs(p.y - q.y) + Math.abs(p.width - q.width) + Math.abs(p.height - q.height) < 0.01);
|
|
1448
|
+
};
|
|
1449
|
+
const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
|
|
1450
|
+
return slots.filter((s, i) => !slots.some((o, j) => j !== i && sameMove(o, s) && wins(o, j, s, i)));
|
|
1451
|
+
}
|
|
1452
|
+
function zoneSpans(scene, seen, edge, reach, probe) {
|
|
1453
|
+
const el = seen.edges[edge.id];
|
|
1454
|
+
const column = axisOf(edge.side) === "column";
|
|
1455
|
+
const main0 = column ? el.rect.y : el.rect.x;
|
|
1456
|
+
const length = column ? el.rect.height : el.rect.width;
|
|
1457
|
+
const thirds = EDGE_KINDS[edgeKindOf(scene, edge)].zoneExtent === "thirds";
|
|
1458
|
+
const at = (r) => column ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1459
|
+
const declared = new Set(edge.zoneAccepts ? ZONES.filter((z) => edge.zoneAccepts[z] !== void 0) : ["start"]);
|
|
1460
|
+
const placed = /* @__PURE__ */ new Map();
|
|
1461
|
+
for (const [id, it] of Object.entries(seen.items)) {
|
|
1462
|
+
if (it.edge !== edge.id || it.inMenu) continue;
|
|
1463
|
+
const z = zoneOf(scene.items[id]);
|
|
1464
|
+
const [a, b] = at(thirds && it.fixed ? reservedRect(scene, seen, id) : it.rect);
|
|
1465
|
+
const was = placed.get(z);
|
|
1466
|
+
placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
|
|
1467
|
+
declared.add(z);
|
|
1468
|
+
}
|
|
1469
|
+
if (thirds) {
|
|
1470
|
+
const lo = (z) => placed.get(z)?.[0] ?? Infinity;
|
|
1471
|
+
const hi = (z) => placed.get(z)?.[1] ?? -Infinity;
|
|
1472
|
+
const b1 = Math.min(Math.max(main0 + length / 3, hi("start")), lo("center"), lo("end"));
|
|
1473
|
+
const b2 = Math.max(Math.min(main0 + 2 * length / 3, lo("end")), hi("center"), hi("start"), b1);
|
|
1474
|
+
return [
|
|
1475
|
+
{ zone: "start", a: main0 - reach, b: b1 },
|
|
1476
|
+
{ zone: "center", a: b1, b: b2 },
|
|
1477
|
+
{ zone: "end", a: b2, b: main0 + length + reach }
|
|
1478
|
+
];
|
|
1479
|
+
}
|
|
1480
|
+
const anchor = { start: main0, center: main0 + length / 2, end: main0 + length };
|
|
1481
|
+
const spans = ZONES.filter((z) => declared.has(z)).map((zone) => ({ zone, s: placed.get(zone) ?? probe(zone) ?? [anchor[zone], anchor[zone]] }));
|
|
1482
|
+
return spans.map(({ zone, s }, i) => ({
|
|
1483
|
+
zone,
|
|
1484
|
+
a: i === 0 ? main0 - reach : (spans[i - 1].s[1] + s[0]) / 2,
|
|
1485
|
+
b: i === spans.length - 1 ? main0 + length + reach : (s[1] + spans[i + 1].s[0]) / 2
|
|
1486
|
+
}));
|
|
1487
|
+
}
|
|
1488
|
+
function edgeSlots(c, edge, accepts) {
|
|
1489
|
+
const { scene, rest, now, base, dragged, kind } = c;
|
|
1490
|
+
const el = now.edges[edge.id];
|
|
1491
|
+
const column = axisOf(edge.side) === "column";
|
|
1492
|
+
const at = (r) => column ? r.y : r.x;
|
|
1493
|
+
const len = (r) => column ? r.height : r.width;
|
|
1494
|
+
const main0 = at(el.rect);
|
|
1495
|
+
const length = len(el.rect);
|
|
1496
|
+
const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];
|
|
1497
|
+
const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
|
|
1498
|
+
const firstKind = formsOf(scene.items[dragged], axisOf(edge.side))[0]?.kind;
|
|
1499
|
+
const titles = edge.items.filter((id) => base.items[id]?.edge === edge.id && base.items[id].fixed && !!formsOf(scene.items[id], axisOf(edge.side))[base.items[id].form]?.main.grows);
|
|
1500
|
+
const lands = ({ layout: after }) => {
|
|
1501
|
+
const me = after.items[dragged];
|
|
1502
|
+
if (me.edge !== edge.id || me.inMenu) return false;
|
|
1503
|
+
if (titles.length === 0) return true;
|
|
1504
|
+
if (formsOf(scene.items[dragged], axisOf(edge.side))[me.form]?.kind !== firstKind) return false;
|
|
1505
|
+
return edge.items.every((id) => {
|
|
1506
|
+
const a = after.items[id];
|
|
1507
|
+
const b = base.items[id];
|
|
1508
|
+
if (!a || !b || b.edge !== edge.id || id === dragged) return true;
|
|
1509
|
+
if (!titles.includes(id)) return a.form === b.form && !!a.inMenu === !!b.inMenu;
|
|
1510
|
+
const f = formsOf(scene.items[id], axisOf(edge.side))[a.form];
|
|
1511
|
+
return !f || (column ? a.rect.height : a.rect.width) >= formMain(f, "natural", after.edges[edge.id].cross) - 0.5;
|
|
1512
|
+
});
|
|
1513
|
+
};
|
|
1514
|
+
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
1515
|
+
const menuLen = el.menu ? len(el.menu.rect) : 0;
|
|
1516
|
+
const occupied = (id) => now.items[id]?.fixed ? reservedRect(scene, now, id) : now.items[id].rect;
|
|
1517
|
+
const shown = (id) => now.items[id]?.edge === edge.id && !now.items[id].inMenu;
|
|
1518
|
+
const drawnOf2 = (z) => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
|
|
1519
|
+
const startEnd = (() => {
|
|
1520
|
+
const s = drawnOf2("start");
|
|
1521
|
+
return s.length ? at(s[s.length - 1]) + len(s[s.length - 1]) : main0 + pad.start;
|
|
1522
|
+
})();
|
|
1523
|
+
const endStart = (() => {
|
|
1524
|
+
const e = drawnOf2("end");
|
|
1525
|
+
return e.length ? at(e[0]) : main0 + length - pad.end - menuLen;
|
|
1526
|
+
})();
|
|
1527
|
+
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 };
|
|
1528
|
+
const slots = [];
|
|
1529
|
+
const aimed = (id) => shown(id) && !now.items[id].fixed;
|
|
1530
|
+
let earlier = 0;
|
|
1531
|
+
for (const zone of ZONES) {
|
|
1532
|
+
const members = members0.filter((id) => zoneOf(rest.items[id]) === zone);
|
|
1533
|
+
const before0 = earlier;
|
|
1534
|
+
earlier += members.filter(aimed).length;
|
|
1535
|
+
if (!accepts || !zoneTakes(edge, zone, kind)) continue;
|
|
1536
|
+
for (let k = 0; k <= members.length; k++) {
|
|
1537
|
+
const next = members.slice(k).find(shown);
|
|
1538
|
+
const before = members.slice(0, k).reverse().find(shown);
|
|
1539
|
+
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];
|
|
1540
|
+
const s = { ...slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands), order: before0 + members.slice(0, k).filter(aimed).length };
|
|
1541
|
+
const movesFixed = members0.some((id) => {
|
|
1542
|
+
const b = base.items[id];
|
|
1543
|
+
const a = s.result.layout.items[id];
|
|
1544
|
+
return !!b?.fixed && b.edge === edge.id && (!a || Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5);
|
|
1545
|
+
});
|
|
1546
|
+
if (!movesFixed) slots.push(s);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
return slots;
|
|
1550
|
+
}
|
|
1551
|
+
function edgeSpec(c, edge) {
|
|
1552
|
+
const { scene, rest, now, dragged, kind } = c;
|
|
1553
|
+
const el = now.edges[edge.id];
|
|
1554
|
+
if (!el || el.folded || el.rides || !rest.edges.some((e) => e.id === edge.id)) return null;
|
|
1555
|
+
const edgeKind = edgeKindOf(scene, edge);
|
|
1556
|
+
const data = EDGE_KINDS[edgeKind];
|
|
1557
|
+
const column = axisOf(edge.side) === "column";
|
|
1558
|
+
const at = (r2) => column ? r2.y : r2.x;
|
|
1559
|
+
const len = (r2) => column ? r2.height : r2.width;
|
|
1560
|
+
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
1561
|
+
const accepts = edge.accepts.includes(kind);
|
|
1562
|
+
if (!accepts && (empty || area(el.rect) <= EPS)) return null;
|
|
1563
|
+
if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;
|
|
1564
|
+
const ownNow = now.items[dragged];
|
|
1565
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area(ownNow.rect) > EPS ? ownNow.rect : null;
|
|
1566
|
+
const slots = edgeSlots(c, edge, accepts);
|
|
1567
|
+
const spanOf = (r2) => [at(r2), at(r2) + len(r2)];
|
|
1568
|
+
const grows = (id) => !!formsOf(scene.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
|
|
1569
|
+
const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
|
|
1570
|
+
const cards = Object.entries(now.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area(p.rect) > EPS).map(([, p]) => spanOf(p.rect));
|
|
1571
|
+
const zones = zoneSpans(scene, now, edge, c.reach, (zone) => {
|
|
1572
|
+
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
1573
|
+
const me = s?.result.layout.items[dragged];
|
|
1574
|
+
return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
|
|
1575
|
+
});
|
|
1576
|
+
const r = el.rect;
|
|
1577
|
+
const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
|
|
1578
|
+
const outer = edge.side === "left" ? r.x : edge.side === "right" ? r.x + r.width : edge.side === "top" ? r.y : r.y + r.height;
|
|
1579
|
+
const inward = (depth) => edge.side === "left" || edge.side === "top" ? [outer, outer + depth] : [outer - depth, outer];
|
|
1580
|
+
const across = (after) => inward((el.cross > 0 ? Math.max(el.cross, after?.edges[edge.id]?.cross ?? 0) : strip) + data.inward);
|
|
1581
|
+
const drawn = el.cross > 0;
|
|
1582
|
+
const marker = (s) => {
|
|
1583
|
+
const slot = s.result.layout.items[dragged].rect;
|
|
1584
|
+
const e = s.result.layout.edges[edge.id];
|
|
1585
|
+
return column ? rect(e.rect.x, slot.y, e.cross, 0) : rect(slot.x, e.rect.y, 0, e.cross);
|
|
1586
|
+
};
|
|
1587
|
+
const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
|
|
1588
|
+
return {
|
|
1589
|
+
id: edge.id,
|
|
1590
|
+
edge,
|
|
1591
|
+
kind: edgeKind,
|
|
1592
|
+
lay: c.lay.get(edge.id),
|
|
1593
|
+
vertical: column,
|
|
1594
|
+
zones,
|
|
1595
|
+
slots,
|
|
1596
|
+
refuse: (zone) => takes(zone) ? "no-room" : accepts || area(el.rect) > EPS ? "not-accepted" : null,
|
|
1597
|
+
own: ownHere,
|
|
1598
|
+
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
1599
|
+
reserved,
|
|
1600
|
+
cards,
|
|
1601
|
+
across,
|
|
1602
|
+
owned: inward(drawn ? el.cross : Math.min(strip, data.place)),
|
|
1603
|
+
ownedAlong: null,
|
|
1604
|
+
drawn,
|
|
1605
|
+
marker
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// src/scene/targets/filter.ts
|
|
1610
|
+
function placeKey(s, id) {
|
|
1611
|
+
const it = Object.hasOwn(s.items, id) ? s.items[id] : void 0;
|
|
1612
|
+
const byZone = (items) => ZONES.flatMap((z) => items.filter((x) => zoneOf(s.items[x]) === z));
|
|
1613
|
+
return JSON.stringify({
|
|
1614
|
+
edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? "" : e.id, byZone(e.items), e.size ?? null])).sort(),
|
|
1615
|
+
floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),
|
|
1616
|
+
from: it?.from ?? 0,
|
|
1617
|
+
align: it?.align ?? "start"
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
function soundness(scene, base, dragged) {
|
|
1621
|
+
const chrome = scene.chrome ?? [];
|
|
1622
|
+
const noteKey = (n) => "edge" in n && (n.code === "overflow" || n.code === "too-wide") ? `${n.edge}:${n.code}:${"id" in n ? n.id : ""}` : null;
|
|
1623
|
+
const hadNotes = new Set(base.notes.map(noteKey).filter((k) => k !== null));
|
|
1624
|
+
return (after) => {
|
|
1625
|
+
if (after.notes.some((n) => {
|
|
1626
|
+
const k = noteKey(n);
|
|
1627
|
+
return k !== null && !hadNotes.has(k);
|
|
1628
|
+
})) return false;
|
|
1629
|
+
for (const [id, b] of Object.entries(base.items)) {
|
|
1630
|
+
if (!b.fixed) continue;
|
|
1631
|
+
const a = after.items[id];
|
|
1632
|
+
const e = a?.edge ? after.edges[a.edge] : void 0;
|
|
1633
|
+
if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;
|
|
1634
|
+
const f = formsOf(scene.items[id], axisOf(e.side))[a.form];
|
|
1635
|
+
const len = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
|
|
1636
|
+
if (f && len < formMain(f, "min", e.cross) - 0.5) return false;
|
|
1637
|
+
}
|
|
1638
|
+
const me = after.items[dragged];
|
|
1639
|
+
if (!me) return true;
|
|
1640
|
+
const fixedAfter = Object.entries(after.items).filter(([id, it]) => it.fixed && id !== dragged).map(([id]) => reservedRect(scene, after, id));
|
|
1641
|
+
return !chrome.some((c) => overlaps(me.rect, c)) && !fixedAfter.some((f) => overlaps(me.rect, f));
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
function context(scene, dragged, options) {
|
|
1645
|
+
const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
|
|
1646
|
+
if (!item || item.fixed || item.closed) return null;
|
|
1647
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
1648
|
+
const settle = (s) => ({ scene: s, layout: solve(s, prev) });
|
|
1649
|
+
const now = solve(scene, prev);
|
|
1650
|
+
const rest = lift(scene, dragged);
|
|
1651
|
+
const base = solve(rest, prev);
|
|
1652
|
+
const here = placeKey(prune(scene), dragged);
|
|
1653
|
+
const c = {
|
|
1654
|
+
scene,
|
|
1655
|
+
rest,
|
|
1656
|
+
now,
|
|
1657
|
+
base,
|
|
1658
|
+
dragged,
|
|
1659
|
+
kind: item.kind,
|
|
1660
|
+
reach: Math.max(0, Number.isFinite(options.endReach) ? options.endReach : 0),
|
|
1661
|
+
settle,
|
|
1662
|
+
isHome: (r) => placeKey(r.scene, dragged) === here,
|
|
1663
|
+
sound: soundness(scene, base, dragged),
|
|
1664
|
+
lay: layKeys(scene)
|
|
1665
|
+
};
|
|
1666
|
+
return { c, item, prev };
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// src/scene/targets/model.ts
|
|
1670
|
+
var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u > EPS)), [...spans]);
|
|
1671
|
+
|
|
1672
|
+
// src/scene/targets/ownership.ts
|
|
1673
|
+
var bandOf = (s) => {
|
|
1674
|
+
const a = Math.min(...s.zones.map((z) => z.a));
|
|
1675
|
+
const b = Math.max(...s.zones.map((z) => z.b));
|
|
1676
|
+
return s.vertical ? rect(s.owned[0], a, s.owned[1] - s.owned[0], b - a) : rect(a, s.owned[0], b - a, s.owned[1] - s.owned[0]);
|
|
1677
|
+
};
|
|
1678
|
+
var ownedRectOf = (s) => {
|
|
1679
|
+
const b = bandOf(s);
|
|
1680
|
+
if (!s.ownedAlong) return b;
|
|
1681
|
+
const [a0, a1] = s.ownedAlong;
|
|
1682
|
+
return s.vertical ? rect(b.x, a0, b.width, a1 - a0) : rect(a0, b.y, a1 - a0, b.height);
|
|
1683
|
+
};
|
|
1684
|
+
function ownedRectsOf(s, along) {
|
|
1685
|
+
if (along.length === 0) return [];
|
|
1686
|
+
const o = ownedRectOf(s);
|
|
1687
|
+
if (s.ownedAlong) return [o];
|
|
1688
|
+
return along.map(([a, b]) => s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height));
|
|
1689
|
+
}
|
|
1690
|
+
function drawnOf(c, live) {
|
|
1691
|
+
return Object.entries(c.now.edges).filter(([id, e]) => area(e.rect) > EPS && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
|
|
1692
|
+
}
|
|
1693
|
+
function homeRectOf(c, ownSpec) {
|
|
1694
|
+
const own = c.now.items[c.dragged];
|
|
1695
|
+
if (!own || own.floating || !own.edge) return null;
|
|
1696
|
+
const o = own.rect;
|
|
1697
|
+
const hull = (a, b) => rect(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));
|
|
1698
|
+
if (own.inMenu) return o;
|
|
1699
|
+
if (!ownSpec) {
|
|
1700
|
+
const e = c.now.edges[own.edge];
|
|
1701
|
+
const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
|
|
1702
|
+
return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ? hull(o, e.rect) : o;
|
|
1703
|
+
}
|
|
1704
|
+
const [c0, c1] = ownSpec.across();
|
|
1705
|
+
return ownSpec.vertical ? hull(o, rect(c0, o.y, c1 - c0, o.height)) : hull(o, rect(o.x, c0, o.width, c1 - c0));
|
|
1706
|
+
}
|
|
1707
|
+
function ownersOf(c, live, drawn, alongOf) {
|
|
1708
|
+
const ownEdge = c.now.items[c.dragged]?.edge;
|
|
1709
|
+
const ownSpec = ownEdge && live.find((s) => s.edge?.id === ownEdge) || null;
|
|
1710
|
+
const homeRect = homeRectOf(c, ownSpec);
|
|
1711
|
+
return [
|
|
1712
|
+
// Home first: its tile is its own, for every edge but its own (which tiles it as its own interval).
|
|
1713
|
+
...homeRect ? [{ spec: ownSpec, rect: homeRect, lay: { phase: -1, side: "", at: -Infinity }, place: false }] : [],
|
|
1714
|
+
// Every edge the tiler reads, along each zone with a slot the filter keeps: what it owns, drawn or a band of its
|
|
1715
|
+
// place (a column line's band about its line). A zone whose every slot is refused owns nothing against the others
|
|
1716
|
+
// (its drawn rect still counts, below).
|
|
1717
|
+
...live.flatMap((s) => ownedRectsOf(s, alongOf(s)).map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }))).filter((o) => area(o.rect) > EPS),
|
|
1718
|
+
// Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
|
|
1719
|
+
...drawn.map((d) => ({ ...d, place: false }))
|
|
1720
|
+
];
|
|
1721
|
+
}
|
|
1722
|
+
function ownership(c, live, alongOf) {
|
|
1723
|
+
const { scene, now, dragged } = c;
|
|
1724
|
+
const drawn = drawnOf(c, live);
|
|
1725
|
+
const owners = ownersOf(c, live, drawn, alongOf);
|
|
1726
|
+
const wins = (o, s) => {
|
|
1727
|
+
if (o.spec === s) return false;
|
|
1728
|
+
if (pushes(o.lay, s.lay)) return true;
|
|
1729
|
+
if (pushes(s.lay, o.lay)) return false;
|
|
1730
|
+
const place = !s.drawn;
|
|
1731
|
+
return o.place === place ? !place || o.lay.at < s.lay.at : !o.place;
|
|
1732
|
+
};
|
|
1733
|
+
const taken = new Map(
|
|
1734
|
+
live.map((s) => [
|
|
1735
|
+
s,
|
|
1736
|
+
[
|
|
1737
|
+
...owners.filter((o) => wins(o, s)).map((o) => o.rect),
|
|
1738
|
+
...EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.spec !== s && !wins(o, s)).flatMap((o) => subtract(o.rect, ownedRectOf(s))) : []
|
|
1739
|
+
]
|
|
1740
|
+
])
|
|
1741
|
+
);
|
|
1742
|
+
const halfBandOf = (e) => {
|
|
1743
|
+
const bandOpt = hitBandOf(scene, e);
|
|
1744
|
+
return bandOpt === "middle" ? null : Math.max(0, Number.isFinite(bandOpt) ? bandOpt : DEFAULT_HIT_BAND) / 2;
|
|
1745
|
+
};
|
|
1746
|
+
const bodySpans = (e) => {
|
|
1747
|
+
const half = e ? halfBandOf(e) : null;
|
|
1748
|
+
if (!e || half === null) return [];
|
|
1749
|
+
const column = axisOf(e.side) === "column";
|
|
1750
|
+
return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.formKind === "open" && iid !== dragged).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS);
|
|
1751
|
+
};
|
|
1752
|
+
const rooms = /* @__PURE__ */ new Map();
|
|
1753
|
+
const cutsOf = (s) => {
|
|
1754
|
+
let room = rooms.get(s);
|
|
1755
|
+
if (!room) rooms.set(s, room = roomOf(s));
|
|
1756
|
+
return room;
|
|
1757
|
+
};
|
|
1758
|
+
const roomOf = (s) => {
|
|
1759
|
+
const b = bandOf(s);
|
|
1760
|
+
const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1761
|
+
const across = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
1762
|
+
const rs = taken.get(s).filter((r) => overlaps(r, b));
|
|
1763
|
+
const ends = [.../* @__PURE__ */ new Set([...along(b), ...rs.flatMap(along)])].filter((x) => x >= along(b)[0] && x <= along(b)[1]).sort((p, q) => p - q);
|
|
1764
|
+
const owned = [];
|
|
1765
|
+
for (let k = 1; k < ends.length; k++) {
|
|
1766
|
+
const [u, w] = [ends[k - 1], ends[k]];
|
|
1767
|
+
const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across);
|
|
1768
|
+
if (w - u > EPS && less([across(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
1769
|
+
}
|
|
1770
|
+
const half = s.edge ? halfBandOf(s.edge) : null;
|
|
1771
|
+
const raw = bodySpans(s.edge);
|
|
1772
|
+
if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
|
|
1773
|
+
const merged = owned.reduce((m, [u, w]) => {
|
|
1774
|
+
const last = m[m.length - 1];
|
|
1775
|
+
if (last && u <= last[1] + EPS) last[1] = Math.max(last[1], w);
|
|
1776
|
+
else m.push([u, w]);
|
|
1777
|
+
return m;
|
|
1778
|
+
}, []);
|
|
1779
|
+
const [lo, hi] = along(b);
|
|
1780
|
+
const placed = (p) => {
|
|
1781
|
+
const cut = merged.find(([u, w]) => p >= u - EPS && p <= w + EPS);
|
|
1782
|
+
if (!cut) return p;
|
|
1783
|
+
const sides = [...cut[0] > lo + EPS ? [cut[0]] : [], ...cut[1] < hi - EPS ? [cut[1]] : []];
|
|
1784
|
+
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
1785
|
+
};
|
|
1786
|
+
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
1787
|
+
return { cuts: owned, bodies: less(raw, bands) };
|
|
1788
|
+
};
|
|
1789
|
+
const grows = (id) => {
|
|
1790
|
+
const it = now.items[id];
|
|
1791
|
+
const e = it.edge ? now.edges[it.edge] : void 0;
|
|
1792
|
+
return !!e && !!formsOf(scene.items[id], axisOf(e.side))[it.form]?.main.grows;
|
|
1793
|
+
};
|
|
1794
|
+
const solid = Object.entries(now.items).filter(([id, it]) => it.fixed && !grows(id)).map(([, it]) => it.rect);
|
|
1795
|
+
const bodies = (s) => {
|
|
1796
|
+
const e = s.edge;
|
|
1797
|
+
if (!e) return [];
|
|
1798
|
+
const column = axisOf(e.side) === "column";
|
|
1799
|
+
const across = (a, b) => column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9);
|
|
1800
|
+
const reserved = Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid)).map(([, p]) => column ? across(p.rect.y, p.rect.y + p.rect.height) : across(p.rect.x, p.rect.x + p.rect.width));
|
|
1801
|
+
return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across(a, b))].filter((b) => area(b) > EPS);
|
|
1802
|
+
};
|
|
1803
|
+
const drawnBySpec = /* @__PURE__ */ new Map();
|
|
1804
|
+
const drawnBesides = (s) => {
|
|
1805
|
+
let rs = drawnBySpec.get(s);
|
|
1806
|
+
if (!rs) drawnBySpec.set(s, rs = drawn.filter((d) => d.spec !== s).map((d) => d.rect));
|
|
1807
|
+
return rs;
|
|
1808
|
+
};
|
|
1809
|
+
return { owners, taken, cutsOf, bodies, solid, drawnBesides };
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
// src/scene/targets/tiles.ts
|
|
1813
|
+
function tilerOf(spec) {
|
|
1814
|
+
const data = EDGE_KINDS[spec.kind];
|
|
1815
|
+
const v = spec.vertical;
|
|
1816
|
+
const band = (a, b, after) => {
|
|
1817
|
+
const [c0, c1] = spec.across(after);
|
|
1818
|
+
return v ? rect(c0, a, c1 - c0, b - a) : rect(a, c0, b - a, c1 - c0);
|
|
1819
|
+
};
|
|
1820
|
+
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
1821
|
+
const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
1822
|
+
const split = (t) => {
|
|
1823
|
+
const h = t.hit;
|
|
1824
|
+
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
1825
|
+
const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
|
|
1826
|
+
const part = (a, b) => v ? rect(a, h.y, b - a, h.height) : rect(h.x, a, h.width, b - a);
|
|
1827
|
+
const beyond = less([[h0, h1]], [spec.owned]);
|
|
1828
|
+
if (beyond.length === 0) return [t];
|
|
1829
|
+
if (c1 - c0 <= EPS) return [{ ...t, order: data.overreach }];
|
|
1830
|
+
const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
|
|
1831
|
+
return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
|
|
1832
|
+
};
|
|
1833
|
+
return { band, keepAt, tile, split };
|
|
1834
|
+
}
|
|
1835
|
+
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS);
|
|
1836
|
+
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
1837
|
+
const reserved = spec.reserved;
|
|
1838
|
+
const lines = mine.map((s) => s.line);
|
|
1839
|
+
const lo = Math.min(z.a, ...lines);
|
|
1840
|
+
const hi = Math.max(z.b, ...lines);
|
|
1841
|
+
const free = less([[z.a, z.b]], reserved);
|
|
1842
|
+
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
1843
|
+
const spread = (x) => {
|
|
1844
|
+
if (hi - lo <= EPS || freeLen <= EPS) return x;
|
|
1845
|
+
let d = (x - lo) / (hi - lo) * freeLen;
|
|
1846
|
+
for (const [a, b] of free) {
|
|
1847
|
+
if (d <= b - a + EPS) return a + Math.min(d, b - a);
|
|
1848
|
+
d -= b - a;
|
|
1849
|
+
}
|
|
1850
|
+
return free[free.length - 1][1];
|
|
1851
|
+
};
|
|
1852
|
+
const past = lines.some((x) => x < z.a - EPS || x > z.b + EPS);
|
|
1853
|
+
const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
|
|
1854
|
+
const proj = (x) => {
|
|
1855
|
+
const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
|
|
1856
|
+
const p = own ? nearer(q, own) : q;
|
|
1857
|
+
if (pieces.some(([a, b]) => p >= a - EPS && p <= b + EPS)) return p;
|
|
1858
|
+
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);
|
|
1859
|
+
};
|
|
1860
|
+
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS || Math.abs(s.line - own[1]) < EPS);
|
|
1861
|
+
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS && s.line <= pb + EPS : proj(s.line) >= pa - EPS && proj(s.line) <= pb + EPS).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
|
|
1862
|
+
const projected = inPiece.map((s) => proj(s.line));
|
|
1863
|
+
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
|
|
1864
|
+
return { inPiece, at };
|
|
1865
|
+
}
|
|
1866
|
+
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
1867
|
+
const data = EDGE_KINDS[spec.kind];
|
|
1868
|
+
const v = spec.vertical;
|
|
1869
|
+
const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
|
|
1870
|
+
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
1871
|
+
const refused = (zone, hit, reason) => tile(zone, hit, { kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason });
|
|
1872
|
+
const slots = distinctSlots(c, spec.slots);
|
|
1873
|
+
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
1874
|
+
const out = [];
|
|
1875
|
+
for (const z of spec.zones) {
|
|
1876
|
+
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS);
|
|
1877
|
+
const pieces = own ? less(room, [own]) : room;
|
|
1878
|
+
if (!hasRoom(pieces, bodies)) continue;
|
|
1879
|
+
const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
|
|
1880
|
+
const mine = lined.filter((s) => s.zone === z.zone && pieces.some(([a, b]) => b > s.line - data.reach + EPS && a < s.line + data.reach - EPS));
|
|
1881
|
+
const reason = spec.refuse(z.zone);
|
|
1882
|
+
for (const [pa, pb] of pieces) {
|
|
1883
|
+
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
1884
|
+
if (inPiece.length === 0) {
|
|
1885
|
+
const lone = reason === "no-room" && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
|
|
1886
|
+
const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS && pa < s.line + data.reach - EPS);
|
|
1887
|
+
const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
|
|
1888
|
+
if (joins.length > 0) {
|
|
1889
|
+
const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
|
|
1890
|
+
const hit = band(pa, pb, s.result.layout);
|
|
1891
|
+
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 })));
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1894
|
+
if (reason && near) out.push(...split(refused(z.zone, band(pa, pb), lone ? "own-place" : reason)));
|
|
1895
|
+
continue;
|
|
1896
|
+
}
|
|
1897
|
+
const meet = (i) => {
|
|
1898
|
+
const [lo, hi] = [at[i - 1], at[i]];
|
|
1899
|
+
const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS && w <= inPiece[i].line + EPS);
|
|
1900
|
+
const mid = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
|
|
1901
|
+
return mid > lo + EPS && mid < hi - EPS ? mid : (lo + hi) / 2;
|
|
1902
|
+
};
|
|
1903
|
+
inPiece.forEach((s, i) => {
|
|
1904
|
+
const p = at[i];
|
|
1905
|
+
const lim = data.virtual ? Infinity : data.reach;
|
|
1906
|
+
const a = Math.max(i === 0 ? pa : meet(i), p - lim);
|
|
1907
|
+
const b = Math.min(i === inPiece.length - 1 ? pb : meet(i + 1), p + lim);
|
|
1908
|
+
if (b - a <= EPS) {
|
|
1909
|
+
if (s.ok && !s.home) lost.push(s.id);
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
if (!hasRoom([[a, b]], bodies)) return;
|
|
1913
|
+
const homeTile = (id, u, w, line) => {
|
|
1914
|
+
const hit = band(u, w, s.home ? s.result.layout : void 0);
|
|
1915
|
+
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" } });
|
|
1916
|
+
};
|
|
1917
|
+
if (s.home) {
|
|
1918
|
+
out.push(...split(homeTile(s.id, a, b, p)));
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS && u < b - EPS) : [];
|
|
1922
|
+
for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
|
|
1923
|
+
for (const [u, w] of less([[a, b]], faced)) {
|
|
1924
|
+
const line = Math.min(Math.max(p, u), w);
|
|
1925
|
+
const hit = band(u, w, s.result.layout);
|
|
1926
|
+
if (!s.ok) out.push(...split(refused(z.zone, hit, "no-room")));
|
|
1927
|
+
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 })));
|
|
1928
|
+
}
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
if (own && spec.own) {
|
|
1933
|
+
const home = spec.slots.find((s) => s.home);
|
|
1934
|
+
const [a, b] = own;
|
|
1935
|
+
const h = band(a, b);
|
|
1936
|
+
const o = spec.own;
|
|
1937
|
+
const hit = v ? rect(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));
|
|
1938
|
+
out.push(tile(home?.zone ?? zoneOf(c.scene.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" } }));
|
|
1939
|
+
}
|
|
1940
|
+
return out;
|
|
1941
|
+
}
|
|
1942
|
+
var clip = (r, cuts) => cuts.reduce((ps, cut) => ps.flatMap((p) => subtract(p, cut)), [r]);
|
|
1943
|
+
var coverOf = (t) => t.hits ?? [t.hit];
|
|
1944
|
+
var largest = (ps) => ps.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1945
|
+
var withPieces = (t, ps) => {
|
|
1946
|
+
const { hits: _h, ...rest } = t;
|
|
1947
|
+
return { ...rest, hit: largest(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
1948
|
+
};
|
|
1949
|
+
function placeReach(t, pieces, placed, landed, gone) {
|
|
1950
|
+
const of = t.of;
|
|
1951
|
+
const at = landed.get(of) ?? [];
|
|
1952
|
+
if (at.length === 0 && gone.has(of)) {
|
|
1953
|
+
const line = t.vertical ? of.keep.y : of.keep.x;
|
|
1954
|
+
const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
1955
|
+
const on = whole.filter((p) => t.vertical ? p.y <= line + EPS && line <= p.y + p.height + EPS : p.x <= line + EPS && line <= p.x + p.width + EPS);
|
|
1956
|
+
const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area(p) > area(a) ? p : a, null);
|
|
1957
|
+
if (kept) {
|
|
1958
|
+
placed.push({ ...of, hit: kept });
|
|
1959
|
+
gone.delete(of);
|
|
1960
|
+
}
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
for (const i of at) {
|
|
1964
|
+
const cover = coverOf(placed[i]);
|
|
1965
|
+
for (let k = 0; k < cover.length; k++) {
|
|
1966
|
+
const h = cover[k];
|
|
1967
|
+
const joint = pieces.find(
|
|
1968
|
+
(p) => t.vertical ? p.y <= h.y + EPS && p.y + p.height >= h.y + h.height - EPS && (Math.abs(p.x - h.x - h.width) < EPS || Math.abs(p.x + p.width - h.x) < EPS) : p.x <= h.x + EPS && p.x + p.width >= h.x + h.width - EPS && (Math.abs(p.y - h.y - h.height) < EPS || Math.abs(p.y + p.height - h.y) < EPS)
|
|
1969
|
+
);
|
|
1970
|
+
if (!joint) continue;
|
|
1971
|
+
const merged = t.vertical ? rect(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height) : rect(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));
|
|
1972
|
+
placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
var isRefused = (t) => t.kind === "refuse" || t.kind === "reach" && t.of.kind === "refuse";
|
|
1978
|
+
function clipTiles(tiles, own, chrome, lost) {
|
|
1979
|
+
const { owners, taken, bodies, solid } = own;
|
|
1980
|
+
const bySpec = /* @__PURE__ */ new Map();
|
|
1981
|
+
const others = (t) => {
|
|
1982
|
+
let rs = bySpec.get(t.spec);
|
|
1983
|
+
if (!rs) bySpec.set(t.spec, rs = owners.filter((o) => o.spec !== t.spec).map((o) => o.rect));
|
|
1984
|
+
return rs;
|
|
1985
|
+
};
|
|
1986
|
+
const besides = (t) => t.spec ? own.drawnBesides(t.spec) : [];
|
|
1987
|
+
const bodiesOf = (t) => t.spec ? bodies(t.spec) : [];
|
|
1988
|
+
const placed = [];
|
|
1989
|
+
const later = [];
|
|
1990
|
+
const refused = tiles.filter(isRefused);
|
|
1991
|
+
const landed = /* @__PURE__ */ new Map();
|
|
1992
|
+
const gone = /* @__PURE__ */ new Set();
|
|
1993
|
+
const place = (t) => {
|
|
1994
|
+
if (t.order === 0) {
|
|
1995
|
+
placed.push(t);
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
const data = EDGE_KINDS[t.edgeKind];
|
|
1999
|
+
if (data.virtual && t.kind === "refuse") {
|
|
2000
|
+
later.push(t);
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
if (t.kind === "reach") {
|
|
2004
|
+
placeReach(t, clip(t.hit, [...placed.flatMap(coverOf), ...others(t), ...bodiesOf(t), ...solid, ...chrome]), placed, landed, gone);
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
const yields = t.kind === "refuse" ? besides(t) : [];
|
|
2008
|
+
const cuts = [...placed.flatMap(coverOf), ...(t.spec && taken.get(t.spec)) ?? [], ...yields, ...data.virtual ? [] : bodiesOf(t), ...solid, ...chrome];
|
|
2009
|
+
const pieces = clip(t.hit, cuts);
|
|
2010
|
+
if (pieces.length === 0) {
|
|
2011
|
+
if (t.kind !== "refuse") gone.add(t);
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
if (t.kind === "refuse") {
|
|
2015
|
+
landed.set(t, pieces.map((_, k) => placed.length + k));
|
|
2016
|
+
for (const p of pieces) placed.push({ ...t, hit: p });
|
|
2017
|
+
return;
|
|
2018
|
+
}
|
|
2019
|
+
const solidPieces = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
2020
|
+
for (const p of pieces) if (!solidPieces.includes(p)) (data.virtual ? later : refused).push({ ...t, kind: "refuse", reason: "no-room", hit: p, keep: null });
|
|
2021
|
+
if (solidPieces.length === 0) return;
|
|
2022
|
+
landed.set(t, [placed.length]);
|
|
2023
|
+
placed.push(withPieces(t, solidPieces));
|
|
2024
|
+
};
|
|
2025
|
+
const byOrder = (a, b) => a.order - b.order;
|
|
2026
|
+
for (const t of tiles.filter((x) => !isRefused(x)).sort(byOrder)) place(t);
|
|
2027
|
+
for (const t of refused.sort(byOrder)) place(t);
|
|
2028
|
+
for (const t of gone) if (t.kind !== "home") lost.push(t.id);
|
|
2029
|
+
for (const t of later) for (const p of clip(t.hit, [...placed.flatMap(coverOf), ...besides(t), ...solid, ...chrome])) placed.push({ ...t, hit: p });
|
|
2030
|
+
return placed;
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// src/scene/targets/virtual.ts
|
|
2034
|
+
function ringsOf(c, side) {
|
|
2035
|
+
const seen = sideRings(c.scene.edges, side);
|
|
2036
|
+
const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
|
|
2037
|
+
const at = (e) => seen.get(e.id) ?? e.ring;
|
|
2038
|
+
return { before: (e) => kept.filter((r) => r < at(e)).length, after: (e) => kept.filter((r) => r <= at(e)).length, count: kept.length };
|
|
2039
|
+
}
|
|
2040
|
+
function railOuter(c, side) {
|
|
2041
|
+
const { now, scene } = c;
|
|
2042
|
+
const place = now.railPlaces[side];
|
|
2043
|
+
const windowEdge = side === "left" ? scene.stage.x : scene.stage.x + scene.stage.width;
|
|
2044
|
+
if (!place) return windowEdge;
|
|
2045
|
+
const placeOuter = side === "left" ? place.x : place.x + place.width;
|
|
2046
|
+
const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter + EPS : e.rect.x >= placeOuter - EPS));
|
|
2047
|
+
return barOutside ? placeOuter : windowEdge;
|
|
2048
|
+
}
|
|
2049
|
+
function columnLines(c, side) {
|
|
2050
|
+
const { scene, now, dragged } = c;
|
|
2051
|
+
const cols = scene.edges.filter((e) => e.side === side && e.column === true).map((edge) => ({ edge, l: now.edges[edge.id] })).filter((x) => x.l && !x.l.folded && !x.l.rides && x.l.cross > 0).sort((a, b) => a.edge.ring - b.edge.ring).map((x) => ({ edge: x.edge, r: x.l.rect }));
|
|
2052
|
+
const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);
|
|
2053
|
+
const span = own[0]?.rect ?? now.content;
|
|
2054
|
+
const rings = ringsOf(c, side);
|
|
2055
|
+
const lines = [];
|
|
2056
|
+
const outerX = (r) => side === "left" ? r.x : r.x + r.width;
|
|
2057
|
+
const innerX = (r) => side === "left" ? r.x + r.width : r.x;
|
|
2058
|
+
const atOf = (e) => c.lay.get(e.id)?.at ?? 0;
|
|
2059
|
+
cols.forEach((x) => lines.push({ x: outerX(x.r), ring: rings.before(x.edge), at: atOf(x.edge) - 0.5 }));
|
|
2060
|
+
if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1].r), ring: rings.after(cols[cols.length - 1].edge), at: atOf(cols[cols.length - 1].edge) + 0.5 });
|
|
2061
|
+
else lines.push({ x: side === "left" ? now.content.x : now.content.x + now.content.width, ring: rings.count, at: Math.max(-1, ...scene.edges.filter((e) => e.side === side).map(atOf)) + 0.5 });
|
|
2062
|
+
const lands = (r) => {
|
|
2063
|
+
const me = r.layout.items[dragged];
|
|
2064
|
+
const el = me.edge ? r.layout.edges[me.edge] : void 0;
|
|
2065
|
+
return !!el && !me.inMenu && !el.folded && !el.rides && r.scene !== c.scene;
|
|
2066
|
+
};
|
|
2067
|
+
const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
|
|
2068
|
+
const stage = c.scene.stage;
|
|
2069
|
+
const dir = side === "left" ? 1 : -1;
|
|
2070
|
+
const outside = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x + EPS : e.rect.x >= x - EPS));
|
|
2071
|
+
const railFirst = !!c.scene.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
|
|
2072
|
+
const placeOf = (l, i) => {
|
|
2073
|
+
const atEdge = side === "left" ? l.x <= stage.x + EPS : l.x >= stage.x + stage.width - EPS;
|
|
2074
|
+
if (i > 0 || outside(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };
|
|
2075
|
+
const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
|
|
2076
|
+
const boundary = clamp(l.x, stage.x, stage.x + stage.width);
|
|
2077
|
+
const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
|
|
2078
|
+
const line = band0 + dir * edgePlace / 2;
|
|
2079
|
+
const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
|
|
2080
|
+
return { line, zone: span2(railFirst ? band0 : windowEdge, line + dir * reach), owned: span2(band0, band0 + dir * edgePlace) };
|
|
2081
|
+
};
|
|
2082
|
+
return lines.map((l, i) => {
|
|
2083
|
+
const p = placeOf(l, i);
|
|
2084
|
+
return {
|
|
2085
|
+
id: virtualEdgeId("column", side),
|
|
2086
|
+
edge: null,
|
|
2087
|
+
kind: "columnLine",
|
|
2088
|
+
lay: { phase: EDGE_KINDS.columnLine.phase, side, at: l.at },
|
|
2089
|
+
vertical: false,
|
|
2090
|
+
zones: [{ zone: "start", a: Math.max(p.zone[0], stage.x), b: Math.min(p.zone[1], stage.x + stage.width) }],
|
|
2091
|
+
slots: [slotAt(c, "start", p.line, targetId({ kind: "column", side, ring: l.ring }), { kind: "column", side, ring: l.ring }, lands)],
|
|
2092
|
+
refuse: () => "no-room",
|
|
2093
|
+
own: null,
|
|
2094
|
+
holds: false,
|
|
2095
|
+
reserved: [],
|
|
2096
|
+
cards: [],
|
|
2097
|
+
across: () => [span.y, span.y + span.height],
|
|
2098
|
+
owned: [span.y, span.y + span.height],
|
|
2099
|
+
ownedAlong: p.owned,
|
|
2100
|
+
drawn: false,
|
|
2101
|
+
// Where the new column's edge lands: the line itself, inside the stage.
|
|
2102
|
+
marker: () => rect(clamp(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
|
|
2103
|
+
};
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
function railStops(c, side) {
|
|
2107
|
+
const { scene, now, dragged } = c;
|
|
2108
|
+
const rail = now.rails[side];
|
|
2109
|
+
const placeRect = now.railPlaces[side];
|
|
2110
|
+
if (!placeRect) return null;
|
|
2111
|
+
const rings = ringsOf(c, side);
|
|
2112
|
+
const seenRings = sideRings(scene.edges, side);
|
|
2113
|
+
const mine = scene.edges.filter((e) => e.side === side).sort((a, b) => (seenRings.get(a.id) ?? 0) - (seenRings.get(b.id) ?? 0));
|
|
2114
|
+
const edgeOf = (id) => mine.find((e) => e.id === id);
|
|
2115
|
+
const ringBefore = (id) => {
|
|
2116
|
+
const e = edgeOf(id);
|
|
2117
|
+
return e ? rings.before(e) : 0;
|
|
2118
|
+
};
|
|
2119
|
+
const ringAfter = (id) => {
|
|
2120
|
+
const e = edgeOf(id);
|
|
2121
|
+
return e ? rings.after(e) : 1;
|
|
2122
|
+
};
|
|
2123
|
+
const stops2 = [];
|
|
2124
|
+
let zone;
|
|
2125
|
+
if (rail && rail.segments.length > 0) {
|
|
2126
|
+
zone = rail.rect;
|
|
2127
|
+
const groups = [];
|
|
2128
|
+
for (const s of rail.segments) {
|
|
2129
|
+
const g = groups[groups.length - 1];
|
|
2130
|
+
if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;
|
|
2131
|
+
else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });
|
|
2132
|
+
}
|
|
2133
|
+
for (const g of groups) stops2.push({ y: g.y0, ring: ringBefore(g.edge) });
|
|
2134
|
+
const last = groups[groups.length - 1];
|
|
2135
|
+
stops2.push({ y: last.y1, ring: ringAfter(last.edge) });
|
|
2136
|
+
} else {
|
|
2137
|
+
const firstCol = mine.find((e) => e.column === true);
|
|
2138
|
+
const outer = railOuter(c, side);
|
|
2139
|
+
zone = rect(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
|
|
2140
|
+
stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
|
|
2141
|
+
}
|
|
2142
|
+
const ownRail = now.items[dragged]?.rail === side;
|
|
2143
|
+
const lands = (r) => r.layout.items[dragged].rail === side && r.scene !== c.scene;
|
|
2144
|
+
const at = zone;
|
|
2145
|
+
return {
|
|
2146
|
+
id: virtualEdgeId("rail", side),
|
|
2147
|
+
edge: null,
|
|
2148
|
+
kind: "railStop",
|
|
2149
|
+
// The rail lies outside every edge on its side: laid first among them.
|
|
2150
|
+
lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
|
|
2151
|
+
vertical: true,
|
|
2152
|
+
zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
|
|
2153
|
+
slots: stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
|
|
2154
|
+
refuse: () => "no-room",
|
|
2155
|
+
own: null,
|
|
2156
|
+
holds: false,
|
|
2157
|
+
reserved: [],
|
|
2158
|
+
cards: [],
|
|
2159
|
+
across: () => [at.x, at.x + at.width],
|
|
2160
|
+
// A drawn rail owns its rect; where none shows, a thin band of its place at the side's outer boundary.
|
|
2161
|
+
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],
|
|
2162
|
+
ownedAlong: null,
|
|
2163
|
+
drawn: !!rail && rail.segments.length > 0,
|
|
2164
|
+
marker: (s) => rect(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
// src/scene/targets.ts
|
|
2169
|
+
function specsOf(c, kind) {
|
|
2170
|
+
const { scene } = c;
|
|
2171
|
+
const specs = scene.edges.map((edge) => edgeSpec(c, edge));
|
|
2172
|
+
for (const side of ["left", "right"]) {
|
|
2173
|
+
const template = scene.columns?.[side];
|
|
2174
|
+
if (!template || !zoneTakes(template, "start", kind)) continue;
|
|
2175
|
+
specs.push(...columnLines(c, side));
|
|
2176
|
+
if (scene.rails?.[side]?.accepts.includes(kind)) specs.push(railStops(c, side));
|
|
2177
|
+
}
|
|
2178
|
+
return specs.filter((s) => s !== null);
|
|
2179
|
+
}
|
|
2180
|
+
function emit2(c, placed) {
|
|
2181
|
+
const { scene, now, dragged } = c;
|
|
2182
|
+
const homeId = targetId({ kind: "home", item: dragged });
|
|
2183
|
+
const targets2 = [];
|
|
2184
|
+
const refused = [];
|
|
2185
|
+
const homeAfter = () => ({ scene, layout: now });
|
|
2186
|
+
const pos = (t) => t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y];
|
|
2187
|
+
const rank = /* @__PURE__ */ new Map();
|
|
2188
|
+
const edgeOf = (t) => t.spec?.edge ? t.spec : t.edge;
|
|
2189
|
+
const byZone = /* @__PURE__ */ new Map();
|
|
2190
|
+
for (const t of placed) {
|
|
2191
|
+
if (t.kind !== "refuse") continue;
|
|
2192
|
+
const zones = byZone.get(edgeOf(t)) ?? /* @__PURE__ */ new Map();
|
|
2193
|
+
byZone.set(edgeOf(t), zones.set(t.zone, [...zones.get(t.zone) ?? [], t]));
|
|
2194
|
+
}
|
|
2195
|
+
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));
|
|
2196
|
+
let ownHome = null;
|
|
2197
|
+
for (const t of placed) {
|
|
2198
|
+
if (t.kind === "refuse") {
|
|
2199
|
+
const n = rank.get(t);
|
|
2200
|
+
refused.push({ id: targetId({ kind: "refuse", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, reason: t.reason });
|
|
2201
|
+
continue;
|
|
2202
|
+
}
|
|
2203
|
+
if (t.kind === "home" && t.id === homeId) {
|
|
2204
|
+
if (t.order === 0) ownHome = t.hit;
|
|
2205
|
+
continue;
|
|
2206
|
+
}
|
|
2207
|
+
const first = targets2.findIndex((x) => x.id === t.id);
|
|
2208
|
+
if (first >= 0) {
|
|
2209
|
+
const was = targets2[first];
|
|
2210
|
+
const pieces = [...was.hits ?? [was.hit], ...t.hits ?? [t.hit]];
|
|
2211
|
+
targets2[first] = { ...was, hit: pieces.reduce((m, p) => area(p) > area(m) ? p : m), hits: pieces };
|
|
2212
|
+
continue;
|
|
2213
|
+
}
|
|
2214
|
+
if (t.kind === "home") {
|
|
2215
|
+
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
2216
|
+
continue;
|
|
2217
|
+
}
|
|
2218
|
+
const result = t.result;
|
|
2219
|
+
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 } : {}, item: dragged, place: t.place, after: () => result });
|
|
2220
|
+
}
|
|
2221
|
+
return { targets: targets2, refused, ownHome };
|
|
2222
|
+
}
|
|
2223
|
+
function alongOfSlots(s, tiles) {
|
|
2224
|
+
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]);
|
|
2225
|
+
const out = [];
|
|
2226
|
+
for (const [a, b] of spans) {
|
|
2227
|
+
const last = out[out.length - 1];
|
|
2228
|
+
if (last && a <= last[1] + 1e-6) last[1] = Math.max(last[1], b);
|
|
2229
|
+
else out.push([a, b]);
|
|
2230
|
+
}
|
|
2231
|
+
return out;
|
|
2232
|
+
}
|
|
2233
|
+
function generate(scene, dragged, options) {
|
|
2234
|
+
checkEdgeIds(scene);
|
|
2235
|
+
if (Object.hasOwn(scene.items, dragged) && scene.items[dragged].fixed) return anchorTargets(scene, dragged, options);
|
|
2236
|
+
const ctx = context(scene, dragged, options);
|
|
2237
|
+
if (!ctx) return { targets: [], refusals: [], lost: [] };
|
|
2238
|
+
const { c, item, prev } = ctx;
|
|
2239
|
+
const { now } = c;
|
|
2240
|
+
const live = specsOf(c, item.kind);
|
|
2241
|
+
const along = new Map(live.map((s) => [s, alongOfSlots(s, tileEdge(c, s, { cuts: [], bodies: [] }, []))]));
|
|
2242
|
+
const own = ownership(c, live, (s) => along.get(s));
|
|
2243
|
+
const lost = [];
|
|
2244
|
+
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
|
|
2245
|
+
const ownRect = now.items[dragged];
|
|
2246
|
+
const homeEdge = scene.edges.find((e) => e.id === ownRect?.edge);
|
|
2247
|
+
const homeHit = homeRectOf(c, null);
|
|
2248
|
+
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
|
|
2249
|
+
tiles.push({ edge: homeEdge.id, spec: null, edgeKind: edgeKindOf(scene, 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 });
|
|
2250
|
+
const placed = clipTiles(tiles, own, scene.chrome ?? [], lost);
|
|
2251
|
+
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
2252
|
+
const homeAfter = () => ({ scene, layout: now });
|
|
2253
|
+
if (scene.floatKinds.includes(item.kind)) {
|
|
2254
|
+
const was = scene.floats.find((f) => f.id === dragged);
|
|
2255
|
+
const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
|
|
2256
|
+
const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
|
|
2257
|
+
targets2.push({
|
|
2258
|
+
id: targetId({ kind: "float", item: dragged }),
|
|
2259
|
+
priority: 3,
|
|
2260
|
+
free: true,
|
|
2261
|
+
hit: PLANE,
|
|
2262
|
+
item: dragged,
|
|
2263
|
+
place: { kind: "float" },
|
|
2264
|
+
after(point, grab) {
|
|
2265
|
+
const g = grab ?? { x: size.width / 2, y: size.height / 2 };
|
|
2266
|
+
const raw = rect(point.x - g.x, point.y - g.y, size.width, size.height);
|
|
2267
|
+
const first = solve(use(floatAt(scene, dragged, raw, options.floatOrient), dragged), prev);
|
|
2268
|
+
const at = first.items[dragged]?.rect ?? raw;
|
|
2269
|
+
return c.settle(use(floatAt(scene, dragged, rect(at.x, at.y, size.width, size.height), options.floatOrient), dragged));
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
(scene.blocked ?? []).forEach((b, i) => {
|
|
2274
|
+
targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
|
|
2275
|
+
});
|
|
2276
|
+
if (ownRect && !ownRect.floating) targets2.push({ id: targetId({ kind: "home", item: dragged }), priority: 1, hit: ownHome ?? ownRect.rect, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
2277
|
+
return { targets: targets2, refusals: refused, lost: [...new Set(lost)].filter((id) => !targets2.some((t) => t.id === id)) };
|
|
2278
|
+
}
|
|
2279
|
+
function targets(scene, dragged, options = {}) {
|
|
2280
|
+
return generate(scene, dragged, options).targets;
|
|
2281
|
+
}
|
|
2282
|
+
function refusals(scene, dragged, options = {}) {
|
|
2283
|
+
return generate(scene, dragged, options).refusals;
|
|
2284
|
+
}
|
|
2285
|
+
var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
|
|
2286
|
+
function stops(scene, dragged, options = {}) {
|
|
2287
|
+
const list = targets(scene, dragged, options).filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
|
|
2288
|
+
const sideOf = (t) => {
|
|
2289
|
+
const p = t.place;
|
|
2290
|
+
if (p.kind === "float") return "float";
|
|
2291
|
+
if (p.kind === "column" || p.kind === "rail" || p.kind === "side") return p.side;
|
|
2292
|
+
if (p.kind === "gap") return scene.edges.find((e) => e.id === p.edge)?.side ?? "float";
|
|
2293
|
+
return "float";
|
|
2294
|
+
};
|
|
2295
|
+
const key = (t) => {
|
|
2296
|
+
const side = sideOf(t);
|
|
2297
|
+
const r = t.slot ?? t.hit;
|
|
2298
|
+
const cx = r.x + r.width / 2;
|
|
2299
|
+
const cy = r.y + r.height / 2;
|
|
2300
|
+
const rank = side === "float" ? 4 : SIDE_RANK[side];
|
|
2301
|
+
return side === "left" ? [rank, cx, cy] : side === "right" ? [rank, -cx, cy] : [rank, cy * (side === "bottom" ? -1 : 1), cx];
|
|
2302
|
+
};
|
|
2303
|
+
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);
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
export {
|
|
2307
|
+
SIDES,
|
|
2308
|
+
ZONES,
|
|
2309
|
+
DEFAULT_STRIP,
|
|
2310
|
+
DEFAULT_HIT_BAND,
|
|
2311
|
+
DEFAULT_FLOAT_SIZE,
|
|
2312
|
+
zoneTakes,
|
|
2313
|
+
zonesTaking,
|
|
2314
|
+
isOutsideSideBar,
|
|
2315
|
+
isSideBar,
|
|
2316
|
+
floatOrientOf,
|
|
2317
|
+
floatSizeOf,
|
|
2318
|
+
targetId,
|
|
2319
|
+
parseTargetId,
|
|
2320
|
+
virtualEdgeId,
|
|
2321
|
+
placeTargetId,
|
|
2322
|
+
solve,
|
|
2323
|
+
fitResize,
|
|
2324
|
+
lift,
|
|
2325
|
+
moveTo,
|
|
2326
|
+
floatAt,
|
|
2327
|
+
fold,
|
|
2328
|
+
use,
|
|
2329
|
+
keep,
|
|
2330
|
+
open,
|
|
2331
|
+
close,
|
|
2332
|
+
raise,
|
|
2333
|
+
orient,
|
|
2334
|
+
resize,
|
|
2335
|
+
setSide,
|
|
2336
|
+
homeFor,
|
|
2337
|
+
dockHome,
|
|
2338
|
+
storeScene,
|
|
2339
|
+
readScene,
|
|
2340
|
+
reservedRect,
|
|
2341
|
+
targets,
|
|
2342
|
+
refusals,
|
|
2343
|
+
stops
|
|
2344
|
+
};
|
|
2345
|
+
//# sourceMappingURL=chunk-3GIUOVQH.js.map
|