@n-uf/placement 26.11.34 → 26.11.37
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 +147 -20
- package/dist/{chunk-VKB3UWKX.js → chunk-2PWDUBPG.js} +520 -97
- package/dist/chunk-2PWDUBPG.js.map +1 -0
- package/dist/{chunk-AVMZIXGO.js → chunk-NF7RYK3U.js} +9 -49
- package/dist/chunk-NF7RYK3U.js.map +1 -0
- package/dist/chunk-R3AAANRY.js +220 -0
- package/dist/chunk-R3AAANRY.js.map +1 -0
- package/dist/desk.d.ts +2 -2
- package/dist/dock.js +2 -1
- package/dist/dock.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{model-BSIKmANw.d.ts → model-CuE-ML-f.d.ts} +111 -19
- package/dist/panels.d.ts +3 -3
- package/dist/regions-Db_RyT4P.d.ts +48 -0
- package/dist/scene-cases.d.ts +42 -10
- package/dist/scene-cases.js +109 -10
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +100 -6
- package/dist/scene.js +11 -1
- package/dist/stack.d.ts +1 -1
- package/dist/{target-2RYYKkd1.d.ts → target-fhD5UVlt.d.ts} +2 -0
- package/dist/{targets-Du5_4T1u.d.ts → targets-DnVNZVQW.d.ts} +1 -1
- package/dist/targets.d.ts +17 -32
- package/dist/targets.js +20 -54
- package/dist/targets.js.map +1 -1
- package/dist/tiling.d.ts +114 -0
- package/dist/tiling.js +40 -0
- package/dist/tiling.js.map +1 -0
- package/package.json +6 -2
- package/dist/chunk-AVMZIXGO.js.map +0 -1
- package/dist/chunk-VKB3UWKX.js.map +0 -1
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
// src/scene/model.ts
|
|
23
23
|
var SIDES = ["top", "right", "bottom", "left"];
|
|
24
24
|
var ZONES = ["start", "center", "end"];
|
|
25
|
+
var FLOAT_ANCHORS = ["content-top-left", "content-top", "content-top-right", "content-right", "content-bottom-right", "content-bottom", "content-bottom-left", "content-left"];
|
|
25
26
|
var RAIL_MODES = ["titles", "icons"];
|
|
26
27
|
var RAIL_VISIBILITIES = ["whileDragging", "always", "never"];
|
|
27
28
|
var RAIL_STRIP_MIN = 24;
|
|
@@ -31,8 +32,11 @@ var DEFAULT_HIT_BAND = 24;
|
|
|
31
32
|
var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
|
|
32
33
|
|
|
33
34
|
// src/scene/helpers.ts
|
|
35
|
+
var anchorName = (anchor) => typeof anchor === "string" ? anchor : anchor.at;
|
|
36
|
+
var isSince = (x) => typeof x === "number" && x >= 0 && x <= Number.MAX_SAFE_INTEGER;
|
|
34
37
|
var zoneTakes = (edge, zone, kind) => edge.accepts.includes(kind) && (edge.zoneAccepts === void 0 || !!edge.zoneAccepts[zone]?.includes(kind));
|
|
35
38
|
var zonesTaking = (edge, kind) => ZONES.filter((z) => zoneTakes(edge, z, kind));
|
|
39
|
+
var edgeTakes = (edge, kind) => zonesTaking(edge, kind).length > 0;
|
|
36
40
|
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;
|
|
37
41
|
var columnFromTemplate = (t, id, side, ring, items) => ({
|
|
38
42
|
id,
|
|
@@ -50,9 +54,36 @@ var columnFromTemplate = (t, id, side, ring, items) => ({
|
|
|
50
54
|
});
|
|
51
55
|
var railModeOf = (scene, side) => side === "left" || side === "right" ? scene.railModes?.[side] === "icons" ? "icons" : "titles" : "icons";
|
|
52
56
|
var axisOf = (side) => side === "left" || side === "right" ? "column" : "row";
|
|
57
|
+
var chromeFor = (scene, who) => (scene.chrome ?? []).filter((c) => who === "floats" || c.for !== "floats").map((c) => ({ x: c.x, y: c.y, width: c.width, height: c.height }));
|
|
53
58
|
function railColumnOf(scene, side, kind) {
|
|
54
59
|
if (scene.rails?.[side]) return void 0;
|
|
55
|
-
return scene.edges.filter((e) => e.side === side && !e.compact && zoneTakes(e, "start", kind)).reduce((m, e) => !m || e.ring < m.ring ? e : m, void 0);
|
|
60
|
+
return scene.edges.filter((e) => e.side === side && !e.compact && e.hidden !== true && zoneTakes(e, "start", kind)).reduce((m, e) => !m || e.ring < m.ring ? e : m, void 0);
|
|
61
|
+
}
|
|
62
|
+
function shownScene(scene) {
|
|
63
|
+
return scene.edges.some((e) => e.hidden === true) ? { ...scene, edges: scene.edges.filter((e) => e.hidden !== true) } : scene;
|
|
64
|
+
}
|
|
65
|
+
var inHiddenEdge = (scene, id) => scene.edges.some((e) => e.hidden === true && e.items.includes(id));
|
|
66
|
+
function withHiddenOf(scene, shown) {
|
|
67
|
+
if (shown === scene || !scene.edges.some((e) => e.hidden === true)) return shown;
|
|
68
|
+
const edges = shown.edges.filter((e) => e.hidden !== true);
|
|
69
|
+
scene.edges.forEach((e, i) => {
|
|
70
|
+
if (e.hidden === true) edges.splice(Math.min(i, edges.length), 0, e);
|
|
71
|
+
});
|
|
72
|
+
const ringBefore = new Map(scene.edges.filter((e) => e.hidden !== true).map((e) => [e.id, e.ring]));
|
|
73
|
+
for (const side of new Set(scene.edges.filter((e) => e.hidden === true).map((e) => e.side))) {
|
|
74
|
+
const was = scene.edges.filter((e) => e.side === side && e.hidden !== true).map((e) => e.id).sort();
|
|
75
|
+
const now = edges.filter((e) => e.side === side && e.hidden !== true);
|
|
76
|
+
if (now.length === was.length && now.every((e) => was.includes(e.id))) continue;
|
|
77
|
+
const order = [...now].sort((a, b) => a.ring - b.ring || edges.indexOf(a) - edges.indexOf(b));
|
|
78
|
+
for (const h of scene.edges.filter((e) => e.side === side && e.hidden === true).sort((a, b) => a.ring - b.ring)) {
|
|
79
|
+
const k = order.findIndex((e) => e.hidden !== true && (ringBefore.get(e.id) ?? -Infinity) > h.ring);
|
|
80
|
+
order.splice(k < 0 ? order.length : k, 0, h);
|
|
81
|
+
}
|
|
82
|
+
order.forEach((e, ring) => {
|
|
83
|
+
if (e.ring !== ring) edges[edges.indexOf(e)] = { ...e, ring };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return { ...shown, edges };
|
|
56
87
|
}
|
|
57
88
|
function railPolicyOf(scene, kind) {
|
|
58
89
|
const p = Object.hasOwn(scene.railDrop ?? {}, kind) ? scene.railDrop[kind] : void 0;
|
|
@@ -96,12 +127,34 @@ function floatSizeOf(item, orient2 = floatOrientOf(item)) {
|
|
|
96
127
|
if (main <= 0 || cross <= 0) return DEFAULT_FLOAT_SIZE;
|
|
97
128
|
return orient2 === "row" ? { width: main, height: cross } : { width: cross, height: main };
|
|
98
129
|
}
|
|
99
|
-
function foldedByOf(item, form, start) {
|
|
130
|
+
function foldedByOf(item, forms, form, start, edge) {
|
|
100
131
|
if (item.closed || form < 1) return void 0;
|
|
101
|
-
if (
|
|
132
|
+
if (startOf(item, forms, edge) > 0) return "hand";
|
|
102
133
|
return start !== void 0 && form > start ? "auto" : void 0;
|
|
103
134
|
}
|
|
104
135
|
var foldedByHand = (item) => Number.isFinite(item.from) && Math.floor(item.from) >= 1;
|
|
136
|
+
var foldsToRail = (item, edge) => !!item.fixed && edge?.foldable === true;
|
|
137
|
+
function foldedIndex(item, forms, edge) {
|
|
138
|
+
const bar = forms.findIndex((f) => f.kind === "header" || f.kind === "fold");
|
|
139
|
+
return bar >= 0 || !foldsToRail(item, edge) ? bar : forms.findIndex((f) => f.kind === "rail");
|
|
140
|
+
}
|
|
141
|
+
function startOf(item, forms, edge) {
|
|
142
|
+
if (!foldedByHand(item)) return 0;
|
|
143
|
+
const folded = foldedIndex(item, forms, edge);
|
|
144
|
+
return folded < 0 ? 0 : Math.min(Math.max(folded, Math.floor(item.from)), forms.length - 1);
|
|
145
|
+
}
|
|
146
|
+
function axesOf(scene, id) {
|
|
147
|
+
const item = scene.items[id];
|
|
148
|
+
const edge = scene.edges.find((e) => e.items.includes(id));
|
|
149
|
+
if (edge) return [axisOf(edge.side)];
|
|
150
|
+
const float = scene.floats.find((f) => f.id === id);
|
|
151
|
+
return float && item ? [float.orient ?? floatOrientOf(item)] : ["row", "column"];
|
|
152
|
+
}
|
|
153
|
+
function isHandFolded(scene, id) {
|
|
154
|
+
const item = Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
|
|
155
|
+
const edge = scene.edges.find((e) => e.items.includes(id));
|
|
156
|
+
return !!item && axesOf(scene, id).some((a) => startOf(item, formsOf(item, a), edge) > 0);
|
|
157
|
+
}
|
|
105
158
|
function pastWrap(forms, from) {
|
|
106
159
|
for (let j = Math.max(0, Math.floor(from)); j < forms.length; j++) if (forms[j].kind !== "wrap" && !forms[j].wrap) return j;
|
|
107
160
|
return void 0;
|
|
@@ -113,7 +166,7 @@ function floatShape(item, f) {
|
|
|
113
166
|
const w = px2(f.rect.width);
|
|
114
167
|
const h = px2(f.rect.height);
|
|
115
168
|
if (forms.length === 0) return { form: 0, width: w, height: h };
|
|
116
|
-
const asked =
|
|
169
|
+
const asked = startOf(item, forms);
|
|
117
170
|
const isWrap = (x) => x.kind === "wrap" || !!x.wrap;
|
|
118
171
|
const skipped = orient2 === "column" ? pastWrap(forms, asked) : asked;
|
|
119
172
|
if (skipped === void 0) return { form: asked, width: w, height: h, none: true };
|
|
@@ -194,6 +247,7 @@ function placeTargetId(place, item) {
|
|
|
194
247
|
var finite = (x, fallback) => typeof x === "number" && Number.isFinite(x) ? x : fallback;
|
|
195
248
|
var px = (x) => Math.max(0, finite(x, 0));
|
|
196
249
|
var isSide = (e) => e.side === "left" || e.side === "right";
|
|
250
|
+
var giveWayOrder = (a, b) => Number(a.kept) - Number(b.kept) || a.age - b.age || finite(a.edge.ring, 0) - finite(b.edge.ring, 0);
|
|
197
251
|
function cutOrder(edges) {
|
|
198
252
|
const phase = (e) => e.side === "left" || e.side === "right" ? 1 : e.span === "between" ? 2 : 0;
|
|
199
253
|
const sideRank = (e) => e.side === "top" || e.side === "left" ? 0 : 1;
|
|
@@ -213,8 +267,75 @@ function zoneSorted(scene, ids) {
|
|
|
213
267
|
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);
|
|
214
268
|
}
|
|
215
269
|
|
|
270
|
+
// src/scene/solve/bar-giveway.ts
|
|
271
|
+
var UNDER = 0.5;
|
|
272
|
+
function roomOf(scene, l) {
|
|
273
|
+
const bars = scene.edges.filter((e) => e.mode === "overlay" && !isSide(e)).reduce((s, e) => s + (l.edges[e.id]?.cross ?? 0), 0);
|
|
274
|
+
return l.content.height - bars;
|
|
275
|
+
}
|
|
276
|
+
function settersOf(scene, l, edge) {
|
|
277
|
+
return (l.edges[edge.id]?.items ?? []).flatMap((id) => {
|
|
278
|
+
const at = l.items[id];
|
|
279
|
+
const item = scene.items[id];
|
|
280
|
+
if (!at || !item || at.inMenu) return [];
|
|
281
|
+
const f = formsOf(item, "row")[at.form];
|
|
282
|
+
return f && formSetsCross(f) ? [formCrossMin(f)] : [];
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function barGiveWay(scene, first, lay) {
|
|
286
|
+
if (!scene.contentMin) return null;
|
|
287
|
+
const minH = px(scene.contentMin.height);
|
|
288
|
+
const shortOf = (l) => minH - roomOf(scene, l);
|
|
289
|
+
if (shortOf(first) <= EPS) return null;
|
|
290
|
+
const rankOf = (edge) => {
|
|
291
|
+
const items = (first.edges[edge.id]?.items ?? []).filter((id) => scene.items[id] !== void 0);
|
|
292
|
+
return {
|
|
293
|
+
edge,
|
|
294
|
+
kept: items.some((id) => scene.items[id].kept === true),
|
|
295
|
+
age: Math.max(-Infinity, ...items.map((id) => finite(scene.items[id].used, 0)))
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
const bars = cutOrder(scene.edges).filter((e) => !isSide(e) && e.giveWay === true && (first.edges[e.id]?.cross ?? 0) > EPS).map(rankOf).sort(giveWayOrder).map((r) => r.edge);
|
|
299
|
+
if (bars.length === 0) return null;
|
|
300
|
+
const folds = /* @__PURE__ */ new Map();
|
|
301
|
+
const shrinkFrom = (l) => {
|
|
302
|
+
const caps = new Map(folds);
|
|
303
|
+
const notes = [];
|
|
304
|
+
let left = shortOf(l);
|
|
305
|
+
for (const e of bars) {
|
|
306
|
+
if (left <= EPS) break;
|
|
307
|
+
if (folds.has(e.id)) continue;
|
|
308
|
+
const cross = l.edges[e.id]?.cross ?? 0;
|
|
309
|
+
const min = Math.max(px(e.cross.min), ...settersOf(scene, l, e));
|
|
310
|
+
const cut2 = Math.min(left, cross - min);
|
|
311
|
+
if (cut2 <= EPS) continue;
|
|
312
|
+
caps.set(e.id, cross - cut2);
|
|
313
|
+
notes.push({ code: "bar-shrunk", edge: e.id, from: cross, to: cross - cut2 });
|
|
314
|
+
left -= cut2;
|
|
315
|
+
}
|
|
316
|
+
return { caps, notes, left };
|
|
317
|
+
};
|
|
318
|
+
let base = first;
|
|
319
|
+
let way = shrinkFrom(base);
|
|
320
|
+
for (const e of bars) {
|
|
321
|
+
if (way.left <= EPS) break;
|
|
322
|
+
const setters = settersOf(scene, first, e);
|
|
323
|
+
if (setters.length === 0) continue;
|
|
324
|
+
folds.set(e.id, Math.min(...setters) - UNDER);
|
|
325
|
+
const l = lay(folds);
|
|
326
|
+
if ((l.edges[e.id]?.cross ?? 0) >= (base.edges[e.id]?.cross ?? 0) - EPS) {
|
|
327
|
+
folds.delete(e.id);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
base = l;
|
|
331
|
+
way = shrinkFrom(base);
|
|
332
|
+
}
|
|
333
|
+
if (way.caps.size === 0) return null;
|
|
334
|
+
return { caps: way.caps, notes: [...way.notes, ...[...folds.keys()].map((edge) => ({ code: "bar-folded", edge }))] };
|
|
335
|
+
}
|
|
336
|
+
|
|
216
337
|
// src/scene/solve/draft.ts
|
|
217
|
-
function createDraft(given, options) {
|
|
338
|
+
function createDraft(given, options, caps = /* @__PURE__ */ new Map()) {
|
|
218
339
|
const previous = options.previous;
|
|
219
340
|
const opened = /* @__PURE__ */ new Set();
|
|
220
341
|
if (previous) {
|
|
@@ -249,7 +370,7 @@ function createDraft(given, options) {
|
|
|
249
370
|
};
|
|
250
371
|
const owned = /* @__PURE__ */ new Map();
|
|
251
372
|
for (const e of order) owned.set(e, e.items.filter(claim));
|
|
252
|
-
return { scene, previous, opened, fresh, order, owned, claim, prevEdge, notes, items: {}, edges: {}, rails: {}, railPlaces: {} };
|
|
373
|
+
return { scene, previous, opened, fresh, order, owned, claim, prevEdge, notes, items: {}, edges: {}, rails: {}, railPlaces: {}, caps };
|
|
253
374
|
}
|
|
254
375
|
function shapeOf(f, r, axis, cross) {
|
|
255
376
|
if (!f) return {};
|
|
@@ -335,7 +456,7 @@ function emit(d, edge, r, solved, extra = {}) {
|
|
|
335
456
|
const drawnRect = toStage(p.rect, inMenu ? void 0 : p.id);
|
|
336
457
|
const f = formsOf(it, column ? "column" : "row")[p.form];
|
|
337
458
|
const shape = inMenu ? {} : shapeOf(f, drawnRect, column ? "column" : "row", stack.cross);
|
|
338
|
-
const foldedBy = foldedByOf(it, p.form, solved.starts.get(p.id));
|
|
459
|
+
const foldedBy = foldedByOf(it, formsOf(it, column ? "column" : "row"), p.form, solved.starts.get(p.id), edge);
|
|
339
460
|
items[p.id] = {
|
|
340
461
|
...shape,
|
|
341
462
|
hidden: inMenu ? [] : f?.hides ?? [],
|
|
@@ -370,12 +491,13 @@ function emit(d, edge, r, solved, extra = {}) {
|
|
|
370
491
|
}
|
|
371
492
|
|
|
372
493
|
// src/scene/solve/edge.ts
|
|
373
|
-
var stackItemOf = (item, forms, from) => ({
|
|
494
|
+
var stackItemOf = (item, forms, edge, from) => ({
|
|
374
495
|
id: item.id,
|
|
375
496
|
forms,
|
|
376
497
|
used: finite(item.used, 0),
|
|
377
498
|
...item.kept ? { kept: true } : {},
|
|
378
|
-
|
|
499
|
+
// Where its ladder starts: as asked, else its hand fold resolved on this axis (`startOf`: its folded form).
|
|
500
|
+
...from !== void 0 ? { from } : startOf(item, forms, edge) > 0 ? { from: startOf(item, forms, edge) } : {},
|
|
379
501
|
...item.fixed ? { fixed: true } : {}
|
|
380
502
|
});
|
|
381
503
|
function hasSetter(fit, forms) {
|
|
@@ -384,15 +506,15 @@ function hasSetter(fit, forms) {
|
|
|
384
506
|
var TRAY_RANK = 100;
|
|
385
507
|
var startsOf = (input) => new Map(input.items.map((i) => [i.id, i.from ?? 0]));
|
|
386
508
|
function compactEdge(f) {
|
|
387
|
-
const { scene, formsById } = f;
|
|
509
|
+
const { scene, edge, formsById } = f;
|
|
388
510
|
const iconsAt = (id) => {
|
|
389
511
|
const forms = formsById(id);
|
|
390
|
-
for (let j =
|
|
512
|
+
for (let j = startOf(scene.items[id], forms, edge); j < forms.length; j++) if (forms[j].kind === "icons") return j;
|
|
391
513
|
return forms.findIndex((x) => x.kind === "icons");
|
|
392
514
|
};
|
|
393
515
|
const shown = f.ordered.filter((id) => !scene.items[id].closed && iconsAt(id) >= 0);
|
|
394
516
|
const leftOutIcons = f.ordered.filter((id) => !scene.items[id].closed && iconsAt(id) < 0);
|
|
395
|
-
const compactInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(scene.items[id], formsById(id), iconsAt(id))) };
|
|
517
|
+
const compactInput = { ...f.base, ownCross: false, items: shown.map((id) => stackItemOf(scene.items[id], formsById(id), edge, iconsAt(id))) };
|
|
396
518
|
const stack = fitStack(compactInput, f.previous ? { previous: f.previous.free } : {});
|
|
397
519
|
return { stack, free: stack, tabs: [], closedTabs: /* @__PURE__ */ new Set(), input: compactInput, starts: startsOf(compactInput), leftOutIcons };
|
|
398
520
|
}
|
|
@@ -400,10 +522,10 @@ function railEdge(f, free, asStackItem, starts) {
|
|
|
400
522
|
const { scene, edge, formsById } = f;
|
|
401
523
|
const railIndex = (item, forms) => {
|
|
402
524
|
if (item.fixed) return -1;
|
|
403
|
-
for (let j =
|
|
525
|
+
for (let j = startOf(item, forms, edge); j < forms.length; j++) if (forms[j].kind === "rail") return j;
|
|
404
526
|
return -1;
|
|
405
527
|
};
|
|
406
|
-
const wrapOnly = (id) => railIndex(scene.items[id], formsById(id)) < 0 && pastWrap(formsById(id),
|
|
528
|
+
const wrapOnly = (id) => railIndex(scene.items[id], formsById(id)) < 0 && pastWrap(formsById(id), startOf(scene.items[id], formsById(id), edge)) === void 0;
|
|
407
529
|
const shown = f.ordered.filter((id) => {
|
|
408
530
|
const it = scene.items[id];
|
|
409
531
|
if (!it.closed && wrapOnly(id)) return false;
|
|
@@ -420,7 +542,7 @@ function railEdge(f, free, asStackItem, starts) {
|
|
|
420
542
|
const it = scene.items[id];
|
|
421
543
|
const j = railIndex(it, formsById(id));
|
|
422
544
|
const forms = asStackItem(id).forms;
|
|
423
|
-
return stackItemOf(it, forms, j >= 0 ? j : pastWrap(forms,
|
|
545
|
+
return stackItemOf(it, forms, edge, j >= 0 ? j : pastWrap(forms, startOf(it, forms, edge)));
|
|
424
546
|
})
|
|
425
547
|
};
|
|
426
548
|
const stack = fitStack(railInput, f.previous ? { previous: f.previous.stack } : {});
|
|
@@ -455,16 +577,16 @@ function solveEdge(scene, edge, ids, length, room, previous) {
|
|
|
455
577
|
const asStackItem = (id) => {
|
|
456
578
|
const it = scene.items[id];
|
|
457
579
|
const forms = formsById(id);
|
|
458
|
-
if (!column || !edge.zoneAccepts?.end || zoneOf(it) !== "end") return stackItemOf(it, forms);
|
|
580
|
+
if (!column || !edge.zoneAccepts?.end || zoneOf(it) !== "end") return stackItemOf(it, forms, edge);
|
|
459
581
|
const tray = (f) => f.kind === "wrap" || f.kind === "icons" || !!f.wrap;
|
|
460
582
|
let first = -1;
|
|
461
|
-
for (let j =
|
|
583
|
+
for (let j = startOf(it, forms, edge); j < forms.length && first < 0; j++) if (tray(forms[j])) first = j;
|
|
462
584
|
let last = -1;
|
|
463
585
|
forms.forEach((f, j) => {
|
|
464
586
|
if (tray(f)) last = j;
|
|
465
587
|
});
|
|
466
|
-
if (first < 0) return stackItemOf(it, forms);
|
|
467
|
-
return stackItemOf(it, forms.slice(0, last + 1).map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + TRAY_RANK })), first);
|
|
588
|
+
if (first < 0) return stackItemOf(it, forms, edge);
|
|
589
|
+
return stackItemOf(it, forms.slice(0, last + 1).map((f) => ({ ...f, rank: finite(f.rank ?? 0, 0) + TRAY_RANK })), edge, first);
|
|
468
590
|
};
|
|
469
591
|
const input = { ...base, items: open2.map(asStackItem) };
|
|
470
592
|
const free = fitStack(input, previous ? { previous: previous.free } : {});
|
|
@@ -474,6 +596,22 @@ function solveEdge(scene, edge, ids, length, room, previous) {
|
|
|
474
596
|
const rail = railEdge(frame, free, asStackItem, starts);
|
|
475
597
|
if (rail) return rail;
|
|
476
598
|
}
|
|
599
|
+
if (!column && edge.giveWay === true) {
|
|
600
|
+
const fits = (f) => !formSetsCross(f) || formCrossMin(f) <= cross.max + EPS;
|
|
601
|
+
let moved = false;
|
|
602
|
+
const items = input.items.map((it) => {
|
|
603
|
+
const from = it.from ?? 0;
|
|
604
|
+
if (it.fixed || fits(it.forms[from])) return it;
|
|
605
|
+
const j = it.forms.findIndex((f, k) => k > from && f.kind !== "menu" && fits(f));
|
|
606
|
+
if (j < 0) return it;
|
|
607
|
+
moved = true;
|
|
608
|
+
return { ...it, from: j };
|
|
609
|
+
});
|
|
610
|
+
if (moved) {
|
|
611
|
+
const folded = { ...input, items };
|
|
612
|
+
return { stack: fitStack(folded), free, tabs: [], closedTabs: none, input: folded, starts };
|
|
613
|
+
}
|
|
614
|
+
}
|
|
477
615
|
const size = edge.size;
|
|
478
616
|
if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
|
|
479
617
|
const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross(formsById(p.id)[p.form]));
|
|
@@ -489,20 +627,26 @@ function solveEdge(scene, edge, ids, length, room, previous) {
|
|
|
489
627
|
}
|
|
490
628
|
|
|
491
629
|
// src/scene/solve/bars.ts
|
|
492
|
-
function cutEdge(d, edge, area2,
|
|
630
|
+
function cutEdge(d, edge, area2, cut2) {
|
|
493
631
|
const column = axisOf(edge.side) === "column";
|
|
494
632
|
const length = column ? area2.height : area2.width;
|
|
495
633
|
const room = Math.max(0, column ? area2.width : area2.height);
|
|
496
|
-
const
|
|
634
|
+
const cap = d.caps.get(edge.id);
|
|
635
|
+
const solvedAs = cap === void 0 ? edge : { ...edge, cross: { ...edge.cross, max: Math.min(edge.cross.max, cap) } };
|
|
636
|
+
const solved = solveEdge(d.scene, solvedAs, d.owned.get(edge), length, room, d.prevEdge(edge));
|
|
497
637
|
const thick = solved.stack.items.length === 0 ? 0 : Math.min(solved.stack.cross, room);
|
|
498
638
|
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);
|
|
499
639
|
emit(d, edge, r, solved);
|
|
500
|
-
if (!
|
|
640
|
+
if (!cut2) return area2;
|
|
501
641
|
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);
|
|
502
642
|
}
|
|
503
643
|
|
|
504
644
|
// src/scene/solve/floats.ts
|
|
505
|
-
|
|
645
|
+
var sinceOf = (f) => isSince(f.since) ? f.since : 0;
|
|
646
|
+
function anchored(content, w, h, given) {
|
|
647
|
+
const anchor = anchorName(given);
|
|
648
|
+
const dx = typeof given === "string" ? 0 : finite(given.dx ?? 0, 0);
|
|
649
|
+
const dy = typeof given === "string" ? 0 : finite(given.dy ?? 0, 0);
|
|
506
650
|
const left = content.x;
|
|
507
651
|
const right = content.x + content.width - w;
|
|
508
652
|
const midX = content.x + (content.width - w) / 2;
|
|
@@ -520,7 +664,7 @@ function anchored(content, w, h, anchor) {
|
|
|
520
664
|
"content-left": [left, midY]
|
|
521
665
|
};
|
|
522
666
|
const [x, y] = at[anchor] ?? at["content-top-right"];
|
|
523
|
-
return rect(x, y, w, h);
|
|
667
|
+
return rect(x + dx, y + dy, w, h);
|
|
524
668
|
}
|
|
525
669
|
function floatFloor(item, form, orient2, size) {
|
|
526
670
|
const row = orient2 === "row";
|
|
@@ -548,7 +692,12 @@ function clearSize(region, avoid) {
|
|
|
548
692
|
};
|
|
549
693
|
return { width: span("x"), height: span("y") };
|
|
550
694
|
}
|
|
551
|
-
function
|
|
695
|
+
function fitBeside(want, region, avoid, earlier) {
|
|
696
|
+
if (earlier.length === 0) return fitFloat(want, region, avoid);
|
|
697
|
+
const both = fitFloat(want, region, [...avoid, ...earlier]);
|
|
698
|
+
return both.covers.length === 0 ? both : fitFloat(want, region, avoid);
|
|
699
|
+
}
|
|
700
|
+
function placeFloat(item, f, region, avoid, content, stage, earlier = []) {
|
|
552
701
|
const shape = floatShape(item, f);
|
|
553
702
|
const from = shape.form;
|
|
554
703
|
const fo = f.orient ?? floatOrientOf(item);
|
|
@@ -557,10 +706,10 @@ function placeFloat(item, f, region, avoid, content, stage) {
|
|
|
557
706
|
const cap = { width: Number.isFinite(item.floatMax?.width) ? item.floatMax.width : Infinity, height: Number.isFinite(item.floatMax?.height) ? item.floatMax.height : Infinity };
|
|
558
707
|
const clear = clearSize(region, avoid);
|
|
559
708
|
const w = Math.max(floor.width, Math.min(shape.width, clear.width, cap.width));
|
|
560
|
-
const folded = form?.kind === "header";
|
|
709
|
+
const folded = form?.kind === "header" || form?.kind === "fold";
|
|
561
710
|
const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, clear.height, cap.height));
|
|
562
711
|
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);
|
|
563
|
-
const fit0 = fitFloat(want, region, avoid);
|
|
712
|
+
const fit0 = f.anchor ? fitBeside(want, region, avoid, earlier) : fitFloat(want, region, avoid);
|
|
564
713
|
const fit = w > region.width + EPS ? { ...fit0, rect: rect(region.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
|
|
565
714
|
return { from, fo, form, fit };
|
|
566
715
|
}
|
|
@@ -572,23 +721,38 @@ function layFloats(d, stage, content, inset) {
|
|
|
572
721
|
if (axisOf(e.side) === "row" && e.cross > 0) avoid.push(e.rect);
|
|
573
722
|
if (e.menu) avoid.push(e.menu.rect);
|
|
574
723
|
}
|
|
575
|
-
for (const c of scene
|
|
724
|
+
for (const c of chromeFor(scene, "floats")) avoid.push(c);
|
|
576
725
|
const floatRegion2 = rect(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);
|
|
577
|
-
const
|
|
726
|
+
const drawn = [];
|
|
727
|
+
const noForm = /* @__PURE__ */ new Set();
|
|
578
728
|
for (const f of scene.floats) {
|
|
579
729
|
if (!d.claim(f.id)) continue;
|
|
580
730
|
const it = scene.items[f.id];
|
|
581
731
|
if (it.closed) continue;
|
|
582
|
-
|
|
583
|
-
|
|
732
|
+
if (floatShape(it, f).none) noForm.add(f.id);
|
|
733
|
+
drawn.push(f);
|
|
734
|
+
}
|
|
735
|
+
const placed = /* @__PURE__ */ new Map();
|
|
736
|
+
const place = (f, earlier = []) => {
|
|
737
|
+
placed.set(f.id, placeFloat(scene.items[f.id], f, floatRegion2, avoid, content, stage, earlier));
|
|
738
|
+
};
|
|
739
|
+
const live = drawn.filter((f) => !noForm.has(f.id));
|
|
740
|
+
for (const f of live) if (!f.anchor) place(f);
|
|
741
|
+
const own = [...placed.values()].map((p) => p.fit.rect);
|
|
742
|
+
const anchored2 = live.filter((f) => f.anchor).sort((a, b) => sinceOf(a) - sinceOf(b) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
743
|
+
anchored2.forEach((f, i) => place(f, [...own, ...anchored2.slice(0, i).map((a) => placed.get(a.id).fit.rect)]));
|
|
744
|
+
const floats = [];
|
|
745
|
+
for (const f of drawn) {
|
|
746
|
+
if (noForm.has(f.id)) {
|
|
584
747
|
notes.push({ code: "no-vertical-form", id: f.id });
|
|
585
748
|
continue;
|
|
586
749
|
}
|
|
587
|
-
const
|
|
750
|
+
const it = scene.items[f.id];
|
|
751
|
+
const { from, fo, form, fit } = placed.get(f.id);
|
|
588
752
|
if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
|
|
589
753
|
if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
|
|
590
754
|
if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
|
|
591
|
-
const foldedBy = foldedByOf(it, from);
|
|
755
|
+
const foldedBy = foldedByOf(it, formsOf(it, fo), from);
|
|
592
756
|
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, ...foldedBy ? { foldedBy } : {} };
|
|
593
757
|
floats.push(f.id);
|
|
594
758
|
}
|
|
@@ -646,7 +810,7 @@ function columnsOf(d, sideEdges, area2, tall) {
|
|
|
646
810
|
min,
|
|
647
811
|
visible,
|
|
648
812
|
dyn,
|
|
649
|
-
hand: dyn && edge.column === true && visible.every((id) =>
|
|
813
|
+
hand: dyn && edge.column === true && visible.every((id) => startOf(scene.items[id], formsOf(scene.items[id], "column")) > 0),
|
|
650
814
|
kept: visible.some((id) => scene.items[id].kept === true),
|
|
651
815
|
age: Math.max(-Infinity, ...visible.map((id) => finite(scene.items[id].used, 0)))
|
|
652
816
|
};
|
|
@@ -656,7 +820,7 @@ function giveWay(d, cols, area2, gutter) {
|
|
|
656
820
|
const { scene, previous, fresh, opened } = d;
|
|
657
821
|
const ride = scene.handFold === "ride";
|
|
658
822
|
const cmin = scene.contentMin ? px(scene.contentMin.width) : void 0;
|
|
659
|
-
const foldOrder = cols.filter((c) => c.dyn && !c.hand && c.width > 0).sort((a, b) =>
|
|
823
|
+
const foldOrder = cols.filter((c) => c.dyn && !c.hand && c.width > 0).sort((a, b) => giveWayOrder(a, b) || (a.side === b.side ? 0 : a.side === "left" ? -1 : 1));
|
|
660
824
|
const shrunkBefore = (previous?.notes ?? []).flatMap((n) => n.code === "column-shrunk" ? [n.edge] : []);
|
|
661
825
|
const rankOf = (c) => shrunkBefore.includes(c.edge.id) ? shrunkBefore.indexOf(c.edge.id) : Infinity;
|
|
662
826
|
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);
|
|
@@ -767,7 +931,7 @@ function riderBars(d, c) {
|
|
|
767
931
|
const { scene } = d;
|
|
768
932
|
return zoneSorted(scene, c.visible).map((id) => {
|
|
769
933
|
const forms = formsOf(scene.items[id], "column");
|
|
770
|
-
const form = forms.length === 0 ? 0 :
|
|
934
|
+
const form = forms.length === 0 ? 0 : startOf(scene.items[id], forms);
|
|
771
935
|
return { id, form, f: forms[form], h: px(forms[form]?.main.natural) };
|
|
772
936
|
});
|
|
773
937
|
}
|
|
@@ -824,10 +988,10 @@ function layRail(d, side, railRect, railed, g) {
|
|
|
824
988
|
const forms = formsById(id);
|
|
825
989
|
const ri = tileOf(id);
|
|
826
990
|
const p = placed.get(id);
|
|
827
|
-
const form = p ? p.form : ri >= 0 ? ri :
|
|
991
|
+
const form = p ? p.form : ri >= 0 ? ri : forms.length === 0 ? 0 : startOf(it, forms);
|
|
828
992
|
const at = p ? rect(railRect.x, railRect.y + p.rect.y, railRect.width, p.rect.height) : rect(railRect.x, y, railRect.width, ri >= 0 ? px(forms[ri].main.natural) : railRect.width);
|
|
829
993
|
const title = forms[form]?.title === true;
|
|
830
|
-
items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand", foldedBy:
|
|
994
|
+
items[id] = { rect: at, hidden: forms[form]?.hides ?? [], kind: it.kind, form, formKind: "rail", edge: c.edge.id, zone: zoneOf(it), rail: side, ...title ? { railTitle: side } : {}, folded: g.auto.has(c) ? "auto" : "hand", foldedBy: startOf(it, forms) > 0 ? "hand" : "auto" };
|
|
831
995
|
segments.push({ id, edge: c.edge.id, rect: at });
|
|
832
996
|
y += at.height;
|
|
833
997
|
}
|
|
@@ -925,7 +1089,15 @@ function laySide(d, side, cols, g, area2, f, walk, upInset, tall) {
|
|
|
925
1089
|
// src/scene/solve.ts
|
|
926
1090
|
function solve(given, options = {}) {
|
|
927
1091
|
checkEdgeIds(given);
|
|
928
|
-
const
|
|
1092
|
+
const shown = shownScene(given);
|
|
1093
|
+
const lay = (caps, gave = []) => layOut(shown, options, caps, gave);
|
|
1094
|
+
const first = lay(/* @__PURE__ */ new Map());
|
|
1095
|
+
const way = barGiveWay(shown, first, lay);
|
|
1096
|
+
return way ? lay(way.caps, way.notes) : first;
|
|
1097
|
+
}
|
|
1098
|
+
var withHeightOf = (area2, over) => rect(over.x, area2.y, over.width, area2.height);
|
|
1099
|
+
function layOut(given, options, caps, gave) {
|
|
1100
|
+
const d = createDraft(given, options, caps);
|
|
929
1101
|
const { scene, order } = d;
|
|
930
1102
|
const stage = rect(finite(scene.stage.x, 0), finite(scene.stage.y, 0), px(scene.stage.width), px(scene.stage.height));
|
|
931
1103
|
const { inset, docked } = insetOf(d);
|
|
@@ -935,11 +1107,23 @@ function solve(given, options = {}) {
|
|
|
935
1107
|
for (const e of reserved) if (outsideBar(e)) outer = cutEdge(d, e, outer, true);
|
|
936
1108
|
let area2 = insideInset(outer, inset);
|
|
937
1109
|
for (const e of reserved) if (!isSide(e) && e.span !== "between" && !outsideBar(e)) area2 = cutEdge(d, e, area2, true);
|
|
1110
|
+
const wide = area2;
|
|
938
1111
|
area2 = laySides(d, reserved.filter(isSide), area2, { inset, gutter: px(scene.gutter), docked, outer });
|
|
939
1112
|
for (const e of reserved) if (!isSide(e) && e.span === "between") area2 = cutEdge(d, e, area2, true);
|
|
940
1113
|
const content = area2;
|
|
941
1114
|
let over = content;
|
|
942
|
-
for (const e of order)
|
|
1115
|
+
for (const e of order) {
|
|
1116
|
+
if (e.mode !== "overlay") continue;
|
|
1117
|
+
if (isSide(e) || e.span !== "full") over = cutEdge(d, e, over, true);
|
|
1118
|
+
else {
|
|
1119
|
+
const across2 = e.outsideInset === true ? outer : wide;
|
|
1120
|
+
over = withHeightOf(cutEdge(d, e, rect(across2.x, over.y, across2.width, over.height), true), over);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
for (const n of gave) {
|
|
1124
|
+
d.notes.push(n);
|
|
1125
|
+
if (n.code === "bar-shrunk" && d.edges[n.edge]) d.edges[n.edge] = { ...d.edges[n.edge], shrunk: true };
|
|
1126
|
+
}
|
|
943
1127
|
contentNotes(d, content);
|
|
944
1128
|
const floats = layFloats(d, stage, content, inset);
|
|
945
1129
|
const { items, edges, rails, railPlaces, columnRoom: columnRoom2, notes } = d;
|
|
@@ -966,7 +1150,7 @@ function floatObstacles(scene, l, id) {
|
|
|
966
1150
|
if (axisOf(e.side) === "row" && e.cross > 0) out.push(e.rect);
|
|
967
1151
|
if (e.menu) out.push(e.menu.rect);
|
|
968
1152
|
}
|
|
969
|
-
for (const c of scene
|
|
1153
|
+
for (const c of chromeFor(scene, "floats")) out.push(c);
|
|
970
1154
|
return out.filter((r) => r.width > 0 && r.height > 0);
|
|
971
1155
|
}
|
|
972
1156
|
function obstacleStop(drawn, obstacles, axis, drag, span) {
|
|
@@ -1089,10 +1273,10 @@ function lift(scene, id) {
|
|
|
1089
1273
|
floats: inFloat ? scene.floats.filter((f) => f.id !== id) : scene.floats
|
|
1090
1274
|
});
|
|
1091
1275
|
}
|
|
1092
|
-
function newColumn(scene, side, kind, ring, items) {
|
|
1276
|
+
function newColumn(scene, side, kind, ring, items, others) {
|
|
1093
1277
|
const t = scene.columns?.[side];
|
|
1094
1278
|
if (!t || !t.accepts.includes(kind)) return null;
|
|
1095
|
-
const taken = new Set(scene.edges.map((e) => e.id));
|
|
1279
|
+
const taken = new Set([...scene.edges, ...others].map((e) => e.id));
|
|
1096
1280
|
let n = 0;
|
|
1097
1281
|
while (taken.has(`${side}-${n}`)) n++;
|
|
1098
1282
|
return columnFromTemplate(t, `${side}-${n}`, side, ring, items);
|
|
@@ -1106,13 +1290,13 @@ function columnFloor(edges, side) {
|
|
|
1106
1290
|
while (n < mine.length && mine[n].column !== true) n++;
|
|
1107
1291
|
return n;
|
|
1108
1292
|
}
|
|
1109
|
-
function insertColumn(scene0, id, side, ring) {
|
|
1293
|
+
function insertColumn(scene0, id, side, ring, others) {
|
|
1110
1294
|
const scene = { ...scene0, edges: closeRings(scene0.edges, /* @__PURE__ */ new Set([side])) };
|
|
1111
1295
|
const kind = scene.items[id].kind;
|
|
1112
1296
|
const mine = scene.edges.filter((e) => e.side === side);
|
|
1113
1297
|
const floor = columnFloor(scene.edges, side);
|
|
1114
1298
|
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));
|
|
1115
|
-
const col = newColumn(scene, side, kind, r, [id]);
|
|
1299
|
+
const col = newColumn(scene, side, kind, r, [id], others);
|
|
1116
1300
|
if (!col) return null;
|
|
1117
1301
|
if (!zoneTakes(col, "start", kind)) return null;
|
|
1118
1302
|
const item = scene.items[id];
|
|
@@ -1135,6 +1319,9 @@ function insertIndex(scene, edge, zone, at) {
|
|
|
1135
1319
|
return idx;
|
|
1136
1320
|
}
|
|
1137
1321
|
function moveTo(scene, id, place) {
|
|
1322
|
+
return moveAmong(scene, id, place, []);
|
|
1323
|
+
}
|
|
1324
|
+
function moveAmong(scene, id, place, others) {
|
|
1138
1325
|
const item = itemOf(scene, id);
|
|
1139
1326
|
if (!item || item.fixed) return scene;
|
|
1140
1327
|
if (place.kind === "float") {
|
|
@@ -1145,17 +1332,17 @@ function moveTo(scene, id, place) {
|
|
|
1145
1332
|
}
|
|
1146
1333
|
const railColumn = place.kind === "rail" ? railColumnOf(scene, place.side, item.kind) : void 0;
|
|
1147
1334
|
if (railColumn) {
|
|
1148
|
-
const docked =
|
|
1335
|
+
const docked = moveAmong(scene, id, { edge: railColumn.id, zone: "start", at: Infinity }, others);
|
|
1149
1336
|
return docked === scene ? scene : withItem(docked, { ...docked.items[id], from: Math.max(1, item.from ?? 0) });
|
|
1150
1337
|
}
|
|
1151
1338
|
if (place.kind === "column" || place.kind === "rail") {
|
|
1152
1339
|
if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
|
|
1153
1340
|
const folded = place.kind === "rail" ? { ...item, from: Math.max(1, item.from ?? 0) } : item;
|
|
1154
|
-
const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring);
|
|
1341
|
+
const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring, others);
|
|
1155
1342
|
return made ?? scene;
|
|
1156
1343
|
}
|
|
1157
1344
|
const edge = scene.edges.find((e) => e.id === place.edge);
|
|
1158
|
-
if (!edge || !edge.accepts.includes(item.kind)) return scene;
|
|
1345
|
+
if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return scene;
|
|
1159
1346
|
const zone = place.zone ?? (zoneTakes(edge, zoneOf(item), item.kind) ? zoneOf(item) : zonesTaking(edge, item.kind)[0]);
|
|
1160
1347
|
if (!zone || !zoneTakes(edge, zone, item.kind)) return scene;
|
|
1161
1348
|
const { align: _drop, ...rest } = item;
|
|
@@ -1166,21 +1353,33 @@ function moveTo(scene, id, place) {
|
|
|
1166
1353
|
const k = insertIndex(lifted, target, zone, place.at);
|
|
1167
1354
|
return { ...lifted, edges: lifted.edges.map((e) => e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e) };
|
|
1168
1355
|
}
|
|
1356
|
+
function nextSince(scene) {
|
|
1357
|
+
const most = scene.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
|
|
1358
|
+
return Math.min(most + 1, Number.MAX_SAFE_INTEGER);
|
|
1359
|
+
}
|
|
1169
1360
|
function floatAt(scene, id, at, orient2) {
|
|
1170
1361
|
const item = itemOf(scene, id);
|
|
1171
1362
|
if (!item || item.fixed || !scene.floatKinds.includes(item.kind)) return scene;
|
|
1172
1363
|
const was = scene.floats.find((f) => f.id === id);
|
|
1173
1364
|
const o = orient2 ?? was?.orient;
|
|
1174
1365
|
const size = floatSizeOf(item, o ?? floatOrientOf(item));
|
|
1175
|
-
const
|
|
1366
|
+
const since = was ? was.since : nextSince(scene);
|
|
1367
|
+
const seq = since !== void 0 ? { since } : {};
|
|
1368
|
+
const float = at ? { id, rect: { x: at.x, y: at.y, width: at.width, height: at.height }, ...o ? { orient: o } : {}, ...seq } : { id, rect: { x: 0, y: 0, width: size.width, height: size.height }, anchor: "content-top-right", ...o ? { orient: o } : {}, ...seq };
|
|
1176
1369
|
const next = at && at.width > 0 && at.height > 0 ? { ...item, floatSize: { width: at.width, height: at.height } } : item;
|
|
1177
1370
|
const lifted = lift(withItem(scene, next), id);
|
|
1178
1371
|
return { ...lifted, floats: [...lifted.floats, float] };
|
|
1179
1372
|
}
|
|
1373
|
+
function canFold(scene, id) {
|
|
1374
|
+
const item = itemOf(scene, id);
|
|
1375
|
+
if (!item || item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id))) return false;
|
|
1376
|
+
const edge = scene.edges.find((e) => e.items.includes(id));
|
|
1377
|
+
return axesOf(scene, id).some((a) => foldedIndex(item, formsOf(item, a), edge) >= 0);
|
|
1378
|
+
}
|
|
1180
1379
|
function fold(scene, id, on) {
|
|
1181
1380
|
const item = itemOf(scene, id);
|
|
1182
1381
|
if (!item || item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id))) return scene;
|
|
1183
|
-
if (on) return (
|
|
1382
|
+
if (on) return isHandFolded(scene, id) || !canFold(scene, id) ? scene : withItem(scene, { ...item, from: 1 });
|
|
1184
1383
|
if (item.from === void 0) return scene;
|
|
1185
1384
|
const { from: _f, ...rest } = item;
|
|
1186
1385
|
return withItem(scene, rest);
|
|
@@ -1291,10 +1490,21 @@ function drawnFloatSize(item, f) {
|
|
|
1291
1490
|
}
|
|
1292
1491
|
|
|
1293
1492
|
// src/scene/store.ts
|
|
1294
|
-
var ANCHORS = ["content-top-left", "content-top", "content-top-right", "content-right", "content-bottom-right", "content-bottom", "content-bottom-left", "content-left"];
|
|
1295
1493
|
var isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
1296
1494
|
var isSize = (x) => isNum(x) && x > 0;
|
|
1297
1495
|
var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
1496
|
+
var isAnchor = (x) => FLOAT_ANCHORS.includes(x);
|
|
1497
|
+
function anchorOf(v, drop) {
|
|
1498
|
+
if (v === void 0) return void 0;
|
|
1499
|
+
if (isAnchor(v)) return v;
|
|
1500
|
+
if (!isObject(v) || !isAnchor(v.at)) {
|
|
1501
|
+
drop?.("");
|
|
1502
|
+
return void 0;
|
|
1503
|
+
}
|
|
1504
|
+
for (const k of Object.keys(v)) if (k !== "at" && k !== "dx" && k !== "dy") drop?.(`:${k}`);
|
|
1505
|
+
for (const k of ["dx", "dy"]) if (v[k] !== void 0 && !isNum(v[k])) drop?.(`:${k}`);
|
|
1506
|
+
return { at: v.at, ...isNum(v.dx) ? { dx: v.dx } : {}, ...isNum(v.dy) ? { dy: v.dy } : {} };
|
|
1507
|
+
}
|
|
1298
1508
|
var record = () => /* @__PURE__ */ Object.create(null);
|
|
1299
1509
|
function railModesOf(v, drop) {
|
|
1300
1510
|
if (v === void 0) return null;
|
|
@@ -1327,7 +1537,10 @@ function storeScene(scene) {
|
|
|
1327
1537
|
return {
|
|
1328
1538
|
v: 1,
|
|
1329
1539
|
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 } : {} })),
|
|
1330
|
-
floats: scene.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) =>
|
|
1540
|
+
floats: scene.floats.filter((f) => isNum(f.rect.x) && isNum(f.rect.y) && isSize(f.rect.width) && isSize(f.rect.height)).map((f) => {
|
|
1541
|
+
const anchor = anchorOf(f.anchor);
|
|
1542
|
+
return { id: f.id, x: f.rect.x, y: f.rect.y, width: f.rect.width, height: f.rect.height, ...f.orient ? { orient: f.orient } : {}, ...anchor ? { anchor } : {}, ...isSince(f.since) ? { since: f.since } : {} };
|
|
1543
|
+
}),
|
|
1331
1544
|
items,
|
|
1332
1545
|
...modes ? { railModes: modes } : {}
|
|
1333
1546
|
};
|
|
@@ -1428,6 +1641,7 @@ function read(data, base) {
|
|
|
1428
1641
|
continue;
|
|
1429
1642
|
}
|
|
1430
1643
|
if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);
|
|
1644
|
+
if (e.hidden !== void 0) drop(`edge:${edge.id}:hidden`);
|
|
1431
1645
|
if (e.side !== void 0 && !SIDES.includes(e.side)) drop(`edge:${e.id}:side`);
|
|
1432
1646
|
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);
|
|
1433
1647
|
const ids = [];
|
|
@@ -1466,15 +1680,16 @@ function read(data, base) {
|
|
|
1466
1680
|
continue;
|
|
1467
1681
|
}
|
|
1468
1682
|
for (const k of Object.keys(f)) if (k === "pinned") drop(`pinned:${id}`);
|
|
1469
|
-
else if (!["id", "x", "y", "width", "height", "orient", "anchor"].includes(k)) drop(`float:${id}:${k}`);
|
|
1683
|
+
else if (!["id", "x", "y", "width", "height", "orient", "anchor", "since"].includes(k)) drop(`float:${id}:${k}`);
|
|
1470
1684
|
const o = f.orient === "row" || f.orient === "column" ? f.orient : void 0;
|
|
1471
1685
|
if (f.orient !== void 0 && !o) drop(`float:${id}:orient`);
|
|
1472
|
-
const a =
|
|
1473
|
-
|
|
1686
|
+
const a = anchorOf(f.anchor, (what) => drop(`float:${id}:anchor${what}`));
|
|
1687
|
+
const since = isSince(f.since) ? f.since : void 0;
|
|
1688
|
+
if (f.since !== void 0 && since === void 0) drop(`float:${id}:since`);
|
|
1474
1689
|
placed.add(id);
|
|
1475
1690
|
const r = rect(f.x, f.y, f.width, f.height);
|
|
1476
1691
|
const drawn = drawnFloatSize(items[id], { rect: r, ...o ? { orient: o } : {} });
|
|
1477
|
-
floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {} });
|
|
1692
|
+
floats.push({ id, rect: clampFloat(r, base.stage, drawn), ...o ? { orient: o } : {}, ...a ? { anchor: a } : {}, ...since !== void 0 ? { since } : {} });
|
|
1478
1693
|
}
|
|
1479
1694
|
const edges = [...base.edges, ...made].map((edge) => {
|
|
1480
1695
|
const stored = order.get(edge.id) ?? [];
|
|
@@ -1511,7 +1726,7 @@ function anchorTargets(scene, dragged, options) {
|
|
|
1511
1726
|
const placed = layout.edges[edge.id]?.rect;
|
|
1512
1727
|
const slot = layout.items[dragged]?.rect;
|
|
1513
1728
|
if (placed && slot && area(placed) > EPS) {
|
|
1514
|
-
const pieces = (scene
|
|
1729
|
+
const pieces = chromeFor(scene, "targets").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);
|
|
1515
1730
|
if (pieces.length > 0) {
|
|
1516
1731
|
const hit = pieces.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
1517
1732
|
const result = { scene: moved, layout };
|
|
@@ -1524,14 +1739,15 @@ function anchorTargets(scene, dragged, options) {
|
|
|
1524
1739
|
|
|
1525
1740
|
// src/scene/targets/kinds.ts
|
|
1526
1741
|
var RAIL_REACH = 24;
|
|
1742
|
+
var MIN_HIT = { across: 12, along: 24 };
|
|
1527
1743
|
var EDGE_KINDS = {
|
|
1528
|
-
bar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false },
|
|
1529
|
-
sideBar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false },
|
|
1530
|
-
column: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false },
|
|
1531
|
-
barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false },
|
|
1532
|
-
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 },
|
|
1533
|
-
railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false },
|
|
1534
|
-
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 }
|
|
1744
|
+
bar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 10, overreach: 30, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1745
|
+
sideBar: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 11, overreach: 31, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1746
|
+
column: { zoneExtent: "solved", opens: "start", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 12, overreach: 32, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1747
|
+
barBetween: { zoneExtent: "thirds", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 13, overreach: 33, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1748
|
+
rail: { zoneExtent: "thirds", opens: "any", inward: RAIL_REACH, place: DEFAULT_HIT_BAND / 2, phase: null, layer: 14, overreach: 34, priority: 2, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1749
|
+
railStop: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 9, overreach: 39, priority: 1, reach: Infinity, virtual: false, minHit: MIN_HIT },
|
|
1750
|
+
columnLine: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, edgePlace: DEFAULT_HIT_BAND, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true, minHit: MIN_HIT }
|
|
1535
1751
|
};
|
|
1536
1752
|
function edgeKindOf(scene, e) {
|
|
1537
1753
|
if (e.compact) return "rail";
|
|
@@ -1553,7 +1769,7 @@ function reservedRect(scene, l, id) {
|
|
|
1553
1769
|
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);
|
|
1554
1770
|
}
|
|
1555
1771
|
function slotAt(c, zone, line, id, place, lands, home = false) {
|
|
1556
|
-
const result = c.settle(use(
|
|
1772
|
+
const result = c.settle(use(moveAmong(c.scene, c.dragged, place, c.others), c.dragged));
|
|
1557
1773
|
const isHome = home || c.isHome(result);
|
|
1558
1774
|
return { zone, line, id, place, result, home: isHome, ok: isHome || !!result.layout.items[c.dragged] && lands(result) && c.sound(result.layout) };
|
|
1559
1775
|
}
|
|
@@ -1653,6 +1869,11 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1653
1869
|
const before0 = earlier;
|
|
1654
1870
|
earlier += members.filter(aimed).length;
|
|
1655
1871
|
if (!accepts || !zoneTakes(edge, zone, kind)) continue;
|
|
1872
|
+
const fixedHere = (id) => !!base.items[id]?.fixed && base.items[id].edge === edge.id;
|
|
1873
|
+
const fromAnchor = (zone === "start" ? members : zone === "end" ? [...members].reverse() : []).filter((id) => fixedHere(id) || shown(id));
|
|
1874
|
+
const firstMovable = fromAnchor.findIndex((id) => !fixedHere(id));
|
|
1875
|
+
const anchored2 = new Set(firstMovable < 0 ? fromAnchor : fromAnchor.slice(0, firstMovable));
|
|
1876
|
+
const isProtected = (id) => fixedHere(id) && (zone === "center" || zoneOf(rest.items[id]) !== zone || anchored2.has(id));
|
|
1656
1877
|
for (let k = 0; k <= members.length; k++) {
|
|
1657
1878
|
const next = members.slice(k).find(shown);
|
|
1658
1879
|
const before = members.slice(0, k).reverse().find(shown);
|
|
@@ -1661,7 +1882,8 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1661
1882
|
const movesFixed = members0.some((id) => {
|
|
1662
1883
|
const b = base.items[id];
|
|
1663
1884
|
const a = s.result.layout.items[id];
|
|
1664
|
-
|
|
1885
|
+
if (fixedHere(id) && !a) return true;
|
|
1886
|
+
return isProtected(id) && (Math.abs(a.rect.x - b.rect.x) > 0.5 || Math.abs(a.rect.y - b.rect.y) > 0.5);
|
|
1665
1887
|
});
|
|
1666
1888
|
if (!movesFixed) slots.push(s);
|
|
1667
1889
|
}
|
|
@@ -1678,7 +1900,7 @@ function edgeSpec(c, edge) {
|
|
|
1678
1900
|
const at = (r2) => column ? r2.y : r2.x;
|
|
1679
1901
|
const len = (r2) => column ? r2.height : r2.width;
|
|
1680
1902
|
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
1681
|
-
const accepts = edge
|
|
1903
|
+
const accepts = edgeTakes(edge, kind);
|
|
1682
1904
|
if (!accepts && (empty || area(el.rect) <= EPS)) return null;
|
|
1683
1905
|
if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;
|
|
1684
1906
|
const ownNow = now.items[dragged];
|
|
@@ -1733,12 +1955,12 @@ function placeKey(s, id) {
|
|
|
1733
1955
|
return JSON.stringify({
|
|
1734
1956
|
edges: s.edges.map((e) => JSON.stringify([e.side, e.ring, e.column === true ? "" : e.id, byZone(e.items), e.size ?? null])).sort(),
|
|
1735
1957
|
floats: s.floats.map((f) => [f.id, f.rect, f.anchor ?? null, f.orient ?? null]),
|
|
1736
|
-
|
|
1958
|
+
folded: isHandFolded(s, id),
|
|
1737
1959
|
align: it?.align ?? "start"
|
|
1738
1960
|
});
|
|
1739
1961
|
}
|
|
1740
1962
|
function soundness(scene, base, dragged) {
|
|
1741
|
-
const chrome = scene
|
|
1963
|
+
const chrome = chromeFor(scene, "targets");
|
|
1742
1964
|
const noteKey = (n) => "edge" in n && (n.code === "overflow" || n.code === "too-wide") ? `${n.edge}:${n.code}:${"id" in n ? n.id : ""}` : null;
|
|
1743
1965
|
const hadNotes = new Set(base.notes.map(noteKey).filter((k) => k !== null));
|
|
1744
1966
|
return (after) => {
|
|
@@ -1761,7 +1983,7 @@ function soundness(scene, base, dragged) {
|
|
|
1761
1983
|
return !chrome.some((c) => overlaps(me.rect, c)) && !fixedAfter.some((f) => overlaps(me.rect, f));
|
|
1762
1984
|
};
|
|
1763
1985
|
}
|
|
1764
|
-
function context(scene, dragged, options) {
|
|
1986
|
+
function context(scene, dragged, options, others = []) {
|
|
1765
1987
|
const item = Object.hasOwn(scene.items, dragged) ? scene.items[dragged] : void 0;
|
|
1766
1988
|
if (!item || item.fixed || item.closed) return null;
|
|
1767
1989
|
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
@@ -1772,6 +1994,7 @@ function context(scene, dragged, options) {
|
|
|
1772
1994
|
const here = placeKey(prune(scene), dragged);
|
|
1773
1995
|
const c = {
|
|
1774
1996
|
scene,
|
|
1997
|
+
others,
|
|
1775
1998
|
rest,
|
|
1776
1999
|
now,
|
|
1777
2000
|
base,
|
|
@@ -1872,10 +2095,10 @@ function ownership(c, live, alongOf) {
|
|
|
1872
2095
|
const rooms = /* @__PURE__ */ new Map();
|
|
1873
2096
|
const cutsOf = (s) => {
|
|
1874
2097
|
let room = rooms.get(s);
|
|
1875
|
-
if (!room) rooms.set(s, room =
|
|
2098
|
+
if (!room) rooms.set(s, room = roomOf2(s));
|
|
1876
2099
|
return room;
|
|
1877
2100
|
};
|
|
1878
|
-
const
|
|
2101
|
+
const roomOf2 = (s) => {
|
|
1879
2102
|
const b = bandOf(s);
|
|
1880
2103
|
const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1881
2104
|
const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
@@ -1898,9 +2121,9 @@ function ownership(c, live, alongOf) {
|
|
|
1898
2121
|
}, []);
|
|
1899
2122
|
const [lo, hi] = along(b);
|
|
1900
2123
|
const placed = (p) => {
|
|
1901
|
-
const
|
|
1902
|
-
if (!
|
|
1903
|
-
const sides = [...
|
|
2124
|
+
const cut2 = merged.find(([u, w]) => p >= u - EPS && p <= w + EPS);
|
|
2125
|
+
if (!cut2) return p;
|
|
2126
|
+
const sides = [...cut2[0] > lo + EPS ? [cut2[0]] : [], ...cut2[1] < hi - EPS ? [cut2[1]] : []];
|
|
1904
2127
|
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
1905
2128
|
};
|
|
1906
2129
|
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
@@ -1952,6 +2175,21 @@ function tilerOf(spec) {
|
|
|
1952
2175
|
};
|
|
1953
2176
|
return { band, keepAt, tile, split };
|
|
1954
2177
|
}
|
|
2178
|
+
function meet(a, b) {
|
|
2179
|
+
const x = Math.max(a.x, b.x);
|
|
2180
|
+
const y = Math.max(a.y, b.y);
|
|
2181
|
+
const w = Math.min(a.x + a.width, b.x + b.width) - x;
|
|
2182
|
+
const h = Math.min(a.y + a.height, b.y + b.height) - y;
|
|
2183
|
+
return w > EPS && h > EPS ? rect(x, y, w, h) : null;
|
|
2184
|
+
}
|
|
2185
|
+
function wholeRefusal(c, spec) {
|
|
2186
|
+
if (!spec.edge || spec.own || spec.holds || ZONES.some((z) => spec.refuse(z) !== "not-accepted")) return null;
|
|
2187
|
+
const drawn = c.now.edges[spec.id]?.rect;
|
|
2188
|
+
const hit = drawn ? meet(drawn, c.scene.stage) : null;
|
|
2189
|
+
if (!hit) return null;
|
|
2190
|
+
const data = EDGE_KINDS[spec.kind];
|
|
2191
|
+
return { edge: spec.id, spec, edgeKind: spec.kind, vertical: spec.vertical, zone: "start", hit, kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason: "not-accepted", whole: true };
|
|
2192
|
+
}
|
|
1955
2193
|
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS);
|
|
1956
2194
|
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
1957
2195
|
const reserved = spec.reserved;
|
|
@@ -1984,12 +2222,27 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
|
1984
2222
|
return { inPiece, at };
|
|
1985
2223
|
}
|
|
1986
2224
|
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
2225
|
+
const whole = wholeRefusal(c, spec);
|
|
2226
|
+
if (whole) return [whole];
|
|
1987
2227
|
const data = EDGE_KINDS[spec.kind];
|
|
1988
2228
|
const v = spec.vertical;
|
|
1989
2229
|
const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
|
|
1990
2230
|
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
1991
|
-
const
|
|
2231
|
+
const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
|
|
2232
|
+
const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS ? v ? rect(-1e9, drawn.y, 2e9, drawn.height) : rect(drawn.x, -1e9, drawn.width, 2e9) : null;
|
|
2233
|
+
const refused = (zone, hit, reason) => {
|
|
2234
|
+
const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
|
|
2235
|
+
const shown = inEdge && meet(inEdge, c.scene.stage);
|
|
2236
|
+
return shown ? split(tile(zone, shown, { kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason })) : [];
|
|
2237
|
+
};
|
|
1992
2238
|
const slots = distinctSlots(c, spec.slots);
|
|
2239
|
+
const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
|
|
2240
|
+
const last = acc[acc.length - 1];
|
|
2241
|
+
if (last && a <= last[1] + EPS) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
|
|
2242
|
+
else acc.push([a, b]);
|
|
2243
|
+
return acc;
|
|
2244
|
+
}, []);
|
|
2245
|
+
const wedged = (line) => runs.some(([a, b]) => line > a + EPS && line < b - EPS);
|
|
1993
2246
|
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
1994
2247
|
const out = [];
|
|
1995
2248
|
for (const z of spec.zones) {
|
|
@@ -1997,7 +2250,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
1997
2250
|
const pieces = own ? less(room, [own]) : room;
|
|
1998
2251
|
if (!hasRoom(pieces, bodies)) continue;
|
|
1999
2252
|
const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
|
|
2000
|
-
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));
|
|
2253
|
+
const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS && a < s.line + data.reach - EPS));
|
|
2001
2254
|
const reason = spec.refuse(z.zone);
|
|
2002
2255
|
for (const [pa, pb] of pieces) {
|
|
2003
2256
|
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
@@ -2011,10 +2264,10 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2011
2264
|
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 })));
|
|
2012
2265
|
continue;
|
|
2013
2266
|
}
|
|
2014
|
-
if (reason && near) out.push(...
|
|
2267
|
+
if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? "own-place" : reason));
|
|
2015
2268
|
continue;
|
|
2016
2269
|
}
|
|
2017
|
-
const
|
|
2270
|
+
const meet2 = (i) => {
|
|
2018
2271
|
const [lo, hi] = [at[i - 1], at[i]];
|
|
2019
2272
|
const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS && w <= inPiece[i].line + EPS);
|
|
2020
2273
|
const mid = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
|
|
@@ -2023,8 +2276,8 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2023
2276
|
inPiece.forEach((s, i) => {
|
|
2024
2277
|
const p = at[i];
|
|
2025
2278
|
const lim = data.virtual ? Infinity : data.reach;
|
|
2026
|
-
const a = Math.max(i === 0 ? pa :
|
|
2027
|
-
const b = Math.min(i === inPiece.length - 1 ? pb :
|
|
2279
|
+
const a = Math.max(i === 0 ? pa : meet2(i), p - lim);
|
|
2280
|
+
const b = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
|
|
2028
2281
|
if (b - a <= EPS) {
|
|
2029
2282
|
if (s.ok && !s.home) lost.push(s.id);
|
|
2030
2283
|
return;
|
|
@@ -2043,7 +2296,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2043
2296
|
for (const [u, w] of less([[a, b]], faced)) {
|
|
2044
2297
|
const line = Math.min(Math.max(p, u), w);
|
|
2045
2298
|
const hit = band(u, w, s.result.layout);
|
|
2046
|
-
if (!s.ok) out.push(...
|
|
2299
|
+
if (!s.ok) out.push(...refused(z.zone, hit, "no-room"));
|
|
2047
2300
|
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 })));
|
|
2048
2301
|
}
|
|
2049
2302
|
});
|
|
@@ -2059,7 +2312,7 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2059
2312
|
}
|
|
2060
2313
|
return out;
|
|
2061
2314
|
}
|
|
2062
|
-
var clip = (r, cuts) => cuts.reduce((ps,
|
|
2315
|
+
var clip = (r, cuts) => cuts.reduce((ps, cut2) => ps.flatMap((p) => subtract(p, cut2)), [r]);
|
|
2063
2316
|
var coverOf = (t) => t.hits ?? [t.hit];
|
|
2064
2317
|
var largest = (ps) => ps.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
2065
2318
|
var withPieces = (t, ps) => {
|
|
@@ -2115,6 +2368,11 @@ function clipTiles(tiles, own, chrome, lost) {
|
|
|
2115
2368
|
placed.push(t);
|
|
2116
2369
|
return;
|
|
2117
2370
|
}
|
|
2371
|
+
if (t.whole) {
|
|
2372
|
+
const pieces2 = clip(t.hit, placed.flatMap(coverOf)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
2373
|
+
if (pieces2.length > 0) placed.push(withPieces(t, pieces2));
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2118
2376
|
const data = EDGE_KINDS[t.edgeKind];
|
|
2119
2377
|
if (data.virtual && t.kind === "refuse") {
|
|
2120
2378
|
later.push(t);
|
|
@@ -2168,7 +2426,7 @@ function railOuter(c, side) {
|
|
|
2168
2426
|
}
|
|
2169
2427
|
function collapsesAt(c, result, side) {
|
|
2170
2428
|
const me = result.layout.items[c.dragged];
|
|
2171
|
-
if (!me || me.floating || me.inMenu || (result.scene
|
|
2429
|
+
if (!me || me.floating || me.inMenu || !isHandFolded(result.scene, c.dragged) || c.isHome(result) || !c.sound(result.layout)) return false;
|
|
2172
2430
|
const sideOf = (edgeId) => edgeId ? result.layout.edges[edgeId]?.side : void 0;
|
|
2173
2431
|
return me.rail === side || sideOf(me.rides) === side || sideOf(me.edge) === side;
|
|
2174
2432
|
}
|
|
@@ -2298,9 +2556,9 @@ function columnStrip(c, side, policy) {
|
|
|
2298
2556
|
const edge = railColumnOf(c.scene, side, c.kind);
|
|
2299
2557
|
if (!edge) return null;
|
|
2300
2558
|
const own = c.now.items[c.dragged];
|
|
2301
|
-
if (own?.edge === edge.id && (c.scene
|
|
2559
|
+
if (own?.edge === edge.id && isHandFolded(c.scene, c.dragged)) return null;
|
|
2302
2560
|
const place = { kind: "rail", side, ring: edge.ring };
|
|
2303
|
-
const moved =
|
|
2561
|
+
const moved = moveAmong(c.scene, c.dragged, place, c.others);
|
|
2304
2562
|
if (moved === c.scene) return null;
|
|
2305
2563
|
const result = c.settle(use(moved, c.dragged));
|
|
2306
2564
|
const el = result.layout.edges[edge.id];
|
|
@@ -2374,10 +2632,10 @@ function withRailStrips(c, targets2, refusals2) {
|
|
|
2374
2632
|
for (let i = 0; i < out.length; i++) {
|
|
2375
2633
|
const t = out[i];
|
|
2376
2634
|
if (t.place.kind !== "gap") continue;
|
|
2377
|
-
const
|
|
2378
|
-
if (!
|
|
2635
|
+
const cut2 = lineCut(t.place.edge);
|
|
2636
|
+
if (!cut2.length) continue;
|
|
2379
2637
|
const was = t.hits ?? [t.hit];
|
|
2380
|
-
const pieces = outside(was,
|
|
2638
|
+
const pieces = outside(was, cut2);
|
|
2381
2639
|
if (sameRects(pieces, was)) continue;
|
|
2382
2640
|
if (pieces.length === 0) out.splice(i--, 1);
|
|
2383
2641
|
else out[i] = { ...withoutHits(t), hit: largest2(pieces), ...pieces.length > 1 ? { hits: pieces } : {} };
|
|
@@ -2386,8 +2644,15 @@ function withRailStrips(c, targets2, refusals2) {
|
|
|
2386
2644
|
const railEdges = new Set([...sides].map((side) => virtualEdgeId("rail", side)));
|
|
2387
2645
|
for (const r of refusals2) {
|
|
2388
2646
|
if (railEdges.has(r.edge)) continue;
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2647
|
+
const was = r.hits ?? [r.hit];
|
|
2648
|
+
const pieces = outside(was, [...rects, ...lineCut(r.edge)]);
|
|
2649
|
+
if (!pieces.length || sameRects(pieces, was)) {
|
|
2650
|
+
if (pieces.length) refused.push(r);
|
|
2651
|
+
continue;
|
|
2652
|
+
}
|
|
2653
|
+
const kept = r.hits ? pieces.filter((p) => p.width >= 1 && p.height >= 1) : [largest2(pieces)];
|
|
2654
|
+
const { hits: _h, ...one } = r;
|
|
2655
|
+
if (kept.length) refused.push({ ...one, hit: largest2(kept), ...kept.length > 1 ? { hits: kept } : {} });
|
|
2391
2656
|
}
|
|
2392
2657
|
const vertical = (r) => {
|
|
2393
2658
|
const side = c.scene.edges.find((e) => e.id === r.edge)?.side;
|
|
@@ -2451,6 +2716,131 @@ function clearOfStrips(t, dragged, strips) {
|
|
|
2451
2716
|
};
|
|
2452
2717
|
}
|
|
2453
2718
|
|
|
2719
|
+
// src/scene/targets/min-hit.ts
|
|
2720
|
+
function kindOf(c, t) {
|
|
2721
|
+
const p = parseTargetId(t.id);
|
|
2722
|
+
if (!p) return null;
|
|
2723
|
+
if (p.kind === "column") return "columnLine";
|
|
2724
|
+
if (p.kind === "rail") return "railStop";
|
|
2725
|
+
if (p.kind === "gap" || p.kind === "strip") {
|
|
2726
|
+
const e = c.scene.edges.find((x) => x.id === p.edge);
|
|
2727
|
+
return e ? edgeKindOf(c.scene, e) : null;
|
|
2728
|
+
}
|
|
2729
|
+
return null;
|
|
2730
|
+
}
|
|
2731
|
+
var largest3 = (ps) => ps.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
2732
|
+
var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS && Math.max(r.width, r.height) >= m.along - EPS;
|
|
2733
|
+
var overlaps2 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS;
|
|
2734
|
+
var cut = (ps, g) => ps.flatMap((p) => subtract(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
2735
|
+
var piecesOf = (t) => t.hits ?? [t.hit];
|
|
2736
|
+
var withPieces2 = (t, ps) => {
|
|
2737
|
+
const { hits: _h, ...rest } = t;
|
|
2738
|
+
return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
2739
|
+
};
|
|
2740
|
+
function growths(r, axis, d) {
|
|
2741
|
+
const [lo, hi] = axis === "x" ? [rect(r.x - d, r.y, d, r.height), rect(r.x + r.width, r.y, d, r.height)] : [rect(r.x, r.y - d, r.width, d), rect(r.x, r.y + r.height, r.width, d)];
|
|
2742
|
+
const h = d / 2;
|
|
2743
|
+
const halves = axis === "x" ? [rect(r.x - h, r.y, h, r.height), rect(r.x + r.width, r.y, h, r.height)] : [rect(r.x, r.y - h, r.width, h), rect(r.x, r.y + r.height, r.width, h)];
|
|
2744
|
+
return [[lo], [hi], halves];
|
|
2745
|
+
}
|
|
2746
|
+
var union = (a, gs) => {
|
|
2747
|
+
const x0 = Math.min(a.x, ...gs.map((g) => g.x));
|
|
2748
|
+
const y0 = Math.min(a.y, ...gs.map((g) => g.y));
|
|
2749
|
+
return rect(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);
|
|
2750
|
+
};
|
|
2751
|
+
function mayGrow(c, targets2, i, grow, minOf, zone, away) {
|
|
2752
|
+
const s = c.scene.stage;
|
|
2753
|
+
for (const g of grow) {
|
|
2754
|
+
if (g.x < s.x - EPS || g.y < s.y - EPS || g.x + g.width > s.x + s.width + EPS || g.y + g.height > s.y + s.height + EPS) return false;
|
|
2755
|
+
if ([...chromeFor(c.scene, "targets"), ...away].some((r) => overlaps2(r, g))) return false;
|
|
2756
|
+
if (zone.reduce((ps, z) => ps.flatMap((p) => subtract(p, z)), [g]).some((p) => area(p) > EPS)) return false;
|
|
2757
|
+
}
|
|
2758
|
+
return targets2.every((o, j) => {
|
|
2759
|
+
if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps2(p, g)))) return true;
|
|
2760
|
+
if (o.place.kind === "home" || o.place.kind === "none" || o.strip) return false;
|
|
2761
|
+
const m = minOf(o);
|
|
2762
|
+
const left = grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]);
|
|
2763
|
+
return !!m && left.length > 0 && keepsMinHit(largest3(left), m);
|
|
2764
|
+
});
|
|
2765
|
+
}
|
|
2766
|
+
function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
2767
|
+
const along = axis === "x" ? [l.y, l.y + l.height] : [l.x, l.x + l.width];
|
|
2768
|
+
let best = null;
|
|
2769
|
+
for (const [side] of growths(l, axis, d)) {
|
|
2770
|
+
const g = side;
|
|
2771
|
+
const strip = (a, b) => axis === "x" ? rect(g.x, a, g.width, b - a) : rect(a, g.y, b - a, g.height);
|
|
2772
|
+
const cuts = /* @__PURE__ */ new Set([along[0], along[1]]);
|
|
2773
|
+
for (const o of targets2)
|
|
2774
|
+
for (const p of piecesOf(o))
|
|
2775
|
+
if (overlaps2(p, g)) {
|
|
2776
|
+
for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along[0] && v < along[1]) cuts.add(v);
|
|
2777
|
+
}
|
|
2778
|
+
const marks = [...cuts].sort((a, b) => a - b);
|
|
2779
|
+
let runStart = null;
|
|
2780
|
+
const runs = [];
|
|
2781
|
+
for (let k = 0; k < marks.length - 1; k++) {
|
|
2782
|
+
const ok = mayGrow(c, targets2, i, [strip(marks[k], marks[k + 1])], minOf, zone, away);
|
|
2783
|
+
if (ok && runStart === null) runStart = marks[k];
|
|
2784
|
+
if (!ok && runStart !== null) {
|
|
2785
|
+
runs.push([runStart, marks[k]]);
|
|
2786
|
+
runStart = null;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
|
|
2790
|
+
for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
|
|
2791
|
+
if (b - a < m.along - EPS) break;
|
|
2792
|
+
const r = strip(a, b);
|
|
2793
|
+
if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area(r) > area(best))) best = r;
|
|
2794
|
+
break;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
return best ? [best] : null;
|
|
2798
|
+
}
|
|
2799
|
+
function withMinHit(c, targets2, refusals2, zones) {
|
|
2800
|
+
const out = [...targets2];
|
|
2801
|
+
const refused = refusals2.flatMap(piecesOf);
|
|
2802
|
+
const minOf = (t) => {
|
|
2803
|
+
const k = kindOf(c, t);
|
|
2804
|
+
return k ? EDGE_KINDS[k].minHit : null;
|
|
2805
|
+
};
|
|
2806
|
+
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS && e.rect.height > EPS);
|
|
2807
|
+
for (let i = 0; i < out.length; i++) {
|
|
2808
|
+
const t = out[i];
|
|
2809
|
+
const m = minOf(t);
|
|
2810
|
+
const zone = zones.get(t.id);
|
|
2811
|
+
if (!m || !zone || t.free || t.strip || t.place.kind === "home" || t.place.kind === "none") continue;
|
|
2812
|
+
const ownEdge = t.place.kind === "gap" ? t.place.edge : parseTargetId(t.id)?.edge;
|
|
2813
|
+
const k = kindOf(c, t);
|
|
2814
|
+
const away = [...refused, ...k && EDGE_KINDS[k].virtual ? [] : drawn.filter(([id]) => id !== ownEdge).map(([, e]) => e.rect)];
|
|
2815
|
+
let l = largest3(piecesOf(t));
|
|
2816
|
+
if (keepsMinHit(l, m)) continue;
|
|
2817
|
+
const steps = ["across", "along"];
|
|
2818
|
+
for (const step of steps) {
|
|
2819
|
+
const narrowX = l.width <= l.height;
|
|
2820
|
+
const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
|
|
2821
|
+
const size = axis === "x" ? l.width : l.height;
|
|
2822
|
+
const d = (step === "across" ? m.across : m.along) - size;
|
|
2823
|
+
if (d <= EPS) continue;
|
|
2824
|
+
let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
|
|
2825
|
+
if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
|
|
2826
|
+
if (!grow) continue;
|
|
2827
|
+
for (let j = 0; j < out.length; j++) {
|
|
2828
|
+
if (j === i || out[j].free) continue;
|
|
2829
|
+
const o = out[j];
|
|
2830
|
+
if (!piecesOf(o).some((p) => grow.some((g) => overlaps2(p, g)))) continue;
|
|
2831
|
+
out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
|
|
2832
|
+
}
|
|
2833
|
+
const g0 = grow[0];
|
|
2834
|
+
const span = axis === "x" ? rect(l.x, g0.y, l.width, g0.height) : rect(g0.x, l.y, g0.width, l.height);
|
|
2835
|
+
const grown = union(span, grow);
|
|
2836
|
+
const others = piecesOf(out[i]).filter((p) => p !== l);
|
|
2837
|
+
out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
|
|
2838
|
+
l = largest3(piecesOf(out[i]));
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
return out;
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2454
2844
|
// src/scene/targets.ts
|
|
2455
2845
|
function specsOf(c, kind) {
|
|
2456
2846
|
const { scene } = c;
|
|
@@ -2484,7 +2874,7 @@ function emit2(c, placed) {
|
|
|
2484
2874
|
for (const t of placed) {
|
|
2485
2875
|
if (t.kind === "refuse") {
|
|
2486
2876
|
const n = rank.get(t);
|
|
2487
|
-
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 });
|
|
2877
|
+
refused.push({ id: targetId({ kind: "refuse", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, reason: t.reason });
|
|
2488
2878
|
continue;
|
|
2489
2879
|
}
|
|
2490
2880
|
if (t.kind === "home" && t.id === homeId) {
|
|
@@ -2519,13 +2909,36 @@ function alongOfSlots(s, tiles) {
|
|
|
2519
2909
|
}
|
|
2520
2910
|
function generate(scene, dragged, options) {
|
|
2521
2911
|
checkEdgeIds(scene);
|
|
2912
|
+
const shown = shownScene(scene);
|
|
2913
|
+
if (shown === scene) return generateShown(scene, dragged, options, []);
|
|
2914
|
+
if (inHiddenEdge(scene, dragged)) return { targets: [], refusals: [], lost: [] };
|
|
2915
|
+
const hidden = scene.edges.filter((e) => e.hidden === true);
|
|
2916
|
+
const g = generateShown(shown, dragged, options, hidden);
|
|
2917
|
+
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
2918
|
+
return {
|
|
2919
|
+
...g,
|
|
2920
|
+
targets: g.targets.map((t) => ({
|
|
2921
|
+
...t,
|
|
2922
|
+
after: (point, grab) => {
|
|
2923
|
+
const a = t.after(point, grab);
|
|
2924
|
+
if (a.scene === shown) return { scene, layout: a.layout };
|
|
2925
|
+
const restored = withHiddenOf(scene, a.scene);
|
|
2926
|
+
const ringOf = new Map(a.scene.edges.map((e) => [e.id, e.ring]));
|
|
2927
|
+
const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
|
|
2928
|
+
return { scene: restored, layout: renumbered ? solve(restored, prev) : a.layout };
|
|
2929
|
+
}
|
|
2930
|
+
}))
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
function generateShown(scene, dragged, options, hidden) {
|
|
2522
2934
|
if (Object.hasOwn(scene.items, dragged) && scene.items[dragged].fixed) return anchorTargets(scene, dragged, options);
|
|
2523
|
-
const ctx = context(scene, dragged, options);
|
|
2935
|
+
const ctx = context(scene, dragged, options, hidden);
|
|
2524
2936
|
if (!ctx) return { targets: [], refusals: [], lost: [] };
|
|
2525
2937
|
const { c, item, prev } = ctx;
|
|
2526
2938
|
const { now } = c;
|
|
2527
2939
|
const live = specsOf(c, item.kind);
|
|
2528
|
-
const
|
|
2940
|
+
const alone = new Map(live.map((s) => [s, tileEdge(c, s, { cuts: [], bodies: [] }, [])]));
|
|
2941
|
+
const along = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
|
|
2529
2942
|
const own = ownership(c, live, (s) => along.get(s));
|
|
2530
2943
|
const lost = [];
|
|
2531
2944
|
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
|
|
@@ -2534,7 +2947,7 @@ function generate(scene, dragged, options) {
|
|
|
2534
2947
|
const homeHit = homeRectOf(c, null);
|
|
2535
2948
|
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
|
|
2536
2949
|
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 });
|
|
2537
|
-
const placed = clipTiles(tiles, own, scene
|
|
2950
|
+
const placed = clipTiles(tiles, own, chromeFor(scene, "targets"), lost);
|
|
2538
2951
|
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
2539
2952
|
const homeAfter = () => ({ scene, layout: now });
|
|
2540
2953
|
if (scene.floatKinds.includes(item.kind)) {
|
|
@@ -2575,7 +2988,9 @@ function generate(scene, dragged, options) {
|
|
|
2575
2988
|
}
|
|
2576
2989
|
const lostIds = [...new Set(lost)].filter((id) => !targets2.some((t) => t.id === id));
|
|
2577
2990
|
const layered = withRailStrips(c, targets2, refused);
|
|
2578
|
-
|
|
2991
|
+
const zones = /* @__PURE__ */ new Map();
|
|
2992
|
+
for (const t of [...alone.values()].flat()) if (t.kind !== "refuse" && t.id) zones.set(t.id, [...zones.get(t.id) ?? [], t.hit]);
|
|
2993
|
+
return { targets: withMinHit(c, layered.targets, layered.refusals, zones), refusals: layered.refusals, lost: lostIds, zones };
|
|
2579
2994
|
}
|
|
2580
2995
|
function targets(scene, dragged, options = {}) {
|
|
2581
2996
|
return generate(scene, dragged, options).targets;
|
|
@@ -2583,6 +2998,9 @@ function targets(scene, dragged, options = {}) {
|
|
|
2583
2998
|
function refusals(scene, dragged, options = {}) {
|
|
2584
2999
|
return generate(scene, dragged, options).refusals;
|
|
2585
3000
|
}
|
|
3001
|
+
function refusalTargets(list) {
|
|
3002
|
+
return list.map((r) => ({ id: r.id, priority: 2, hit: r.hit, ...r.hits ? { hits: r.hits } : {}, refuse: true, refusal: r }));
|
|
3003
|
+
}
|
|
2586
3004
|
var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
|
|
2587
3005
|
function stops(scene, dragged, options = {}) {
|
|
2588
3006
|
const key = stopsKey(dragged, options);
|
|
@@ -2630,6 +3048,7 @@ function orderedStops(scene, dragged, options) {
|
|
|
2630
3048
|
export {
|
|
2631
3049
|
SIDES,
|
|
2632
3050
|
ZONES,
|
|
3051
|
+
FLOAT_ANCHORS,
|
|
2633
3052
|
RAIL_MODES,
|
|
2634
3053
|
RAIL_VISIBILITIES,
|
|
2635
3054
|
RAIL_STRIP_MIN,
|
|
@@ -2637,8 +3056,10 @@ export {
|
|
|
2637
3056
|
DEFAULT_STRIP,
|
|
2638
3057
|
DEFAULT_HIT_BAND,
|
|
2639
3058
|
DEFAULT_FLOAT_SIZE,
|
|
3059
|
+
anchorName,
|
|
2640
3060
|
zoneTakes,
|
|
2641
3061
|
zonesTaking,
|
|
3062
|
+
edgeTakes,
|
|
2642
3063
|
railModeOf,
|
|
2643
3064
|
isOutsideSideBar,
|
|
2644
3065
|
isSideBar,
|
|
@@ -2653,6 +3074,7 @@ export {
|
|
|
2653
3074
|
lift,
|
|
2654
3075
|
moveTo,
|
|
2655
3076
|
floatAt,
|
|
3077
|
+
canFold,
|
|
2656
3078
|
fold,
|
|
2657
3079
|
use,
|
|
2658
3080
|
keep,
|
|
@@ -2670,6 +3092,7 @@ export {
|
|
|
2670
3092
|
reservedRect,
|
|
2671
3093
|
targets,
|
|
2672
3094
|
refusals,
|
|
3095
|
+
refusalTargets,
|
|
2673
3096
|
stops
|
|
2674
3097
|
};
|
|
2675
|
-
//# sourceMappingURL=chunk-
|
|
3098
|
+
//# sourceMappingURL=chunk-2PWDUBPG.js.map
|