@n-uf/placement 26.11.26 → 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 +103 -0
- package/README.md +74 -13
- package/dist/{chunk-CIGRI35P.js → chunk-3GIUOVQH.js} +587 -241
- package/dist/chunk-3GIUOVQH.js.map +1 -0
- package/dist/{model-Dz4R5ydE.d.ts → model-Cxg_ySz6.d.ts} +84 -2
- package/dist/scene-cases.d.ts +38 -12
- package/dist/scene-cases.js +21 -34
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +81 -3
- package/dist/scene.js +11 -1
- package/package.json +3 -2
- package/dist/chunk-CIGRI35P.js.map +0 -1
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
PLANE,
|
|
13
13
|
RAIL_EDGE,
|
|
14
14
|
area,
|
|
15
|
+
clamp,
|
|
15
16
|
clampInto,
|
|
16
17
|
overlaps,
|
|
17
18
|
rect,
|
|
@@ -28,9 +29,26 @@ var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
|
|
|
28
29
|
// src/scene/helpers.ts
|
|
29
30
|
var zoneTakes = (edge, zone, kind) => edge.accepts.includes(kind) && (edge.zoneAccepts === void 0 || !!edge.zoneAccepts[zone]?.includes(kind));
|
|
30
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
|
+
});
|
|
31
47
|
var axisOf = (side) => side === "left" || side === "right" ? "column" : "row";
|
|
32
48
|
var zoneOf = (item) => item?.align === "center" || item?.align === "end" ? item.align : "start";
|
|
33
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 ?? "");
|
|
34
52
|
function isOutsideSideBar(scene, e) {
|
|
35
53
|
return e.outsideInset === true && isSideBar(scene, e);
|
|
36
54
|
}
|
|
@@ -78,6 +96,72 @@ function floatShape(item, f) {
|
|
|
78
96
|
return { form, width: w, height: h };
|
|
79
97
|
}
|
|
80
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
|
+
|
|
81
165
|
// src/scene/solve/order.ts
|
|
82
166
|
var finite = (x, fallback) => typeof x === "number" && Number.isFinite(x) ? x : fallback;
|
|
83
167
|
var px = (x) => Math.max(0, finite(x, 0));
|
|
@@ -401,6 +485,28 @@ function anchored(content, w, h, anchor) {
|
|
|
401
485
|
const [x, y] = at[anchor] ?? at["content-top-right"];
|
|
402
486
|
return rect(x, y, w, h);
|
|
403
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
|
+
}
|
|
404
510
|
function layFloats(d, stage, content, inset) {
|
|
405
511
|
const { scene, notes, items, edges } = d;
|
|
406
512
|
const avoid = [];
|
|
@@ -410,7 +516,7 @@ function layFloats(d, stage, content, inset) {
|
|
|
410
516
|
if (e.menu) avoid.push(e.menu.rect);
|
|
411
517
|
}
|
|
412
518
|
for (const c of scene.chrome ?? []) avoid.push(c);
|
|
413
|
-
const
|
|
519
|
+
const floatRegion2 = rect(stage.x + px(inset.left), stage.y, Math.max(0, stage.width - px(inset.left) - px(inset.right)), stage.height);
|
|
414
520
|
const floats = [];
|
|
415
521
|
for (const f of scene.floats) {
|
|
416
522
|
if (!d.claim(f.id)) continue;
|
|
@@ -421,20 +527,7 @@ function layFloats(d, stage, content, inset) {
|
|
|
421
527
|
notes.push({ code: "no-vertical-form", id: f.id });
|
|
422
528
|
continue;
|
|
423
529
|
}
|
|
424
|
-
const from =
|
|
425
|
-
const fo = f.orient ?? floatOrientOf(it);
|
|
426
|
-
const form = formsOf(it, fo)[from];
|
|
427
|
-
const row = fo === "row";
|
|
428
|
-
const floor = {
|
|
429
|
-
width: it.floatMin ? px(it.floatMin.width) : Math.min(shape.width, px(row ? form?.main.min : form?.cross.min)),
|
|
430
|
-
height: it.floatMin ? px(it.floatMin.height) : Math.min(shape.height, px(row ? form?.cross.min : form?.main.min))
|
|
431
|
-
};
|
|
432
|
-
const w = Math.max(floor.width, Math.min(shape.width, floatRegion.width));
|
|
433
|
-
const folded = form?.kind === "header";
|
|
434
|
-
const h = folded ? shape.height : Math.max(floor.height, Math.min(shape.height, floatRegion.height));
|
|
435
|
-
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);
|
|
436
|
-
const fit0 = fitFloat(want, floatRegion, avoid);
|
|
437
|
-
const fit = w > floatRegion.width + EPS ? { ...fit0, rect: rect(floatRegion.x, fit0.rect.y, w, fit0.rect.height) } : fit0;
|
|
530
|
+
const { from, fo, form, fit } = placeFloat(it, f, floatRegion2, avoid, content, stage);
|
|
438
531
|
if (fit.clamped) notes.push({ code: "float-clamped", id: f.id });
|
|
439
532
|
if (fit.snapped) notes.push({ code: "float-moved", id: f.id });
|
|
440
533
|
if (fit.covers.length > 0) notes.push({ code: "float-covers", id: f.id });
|
|
@@ -447,12 +540,7 @@ function layFloats(d, stage, content, inset) {
|
|
|
447
540
|
// src/scene/solve/insets.ts
|
|
448
541
|
function insetOf(d) {
|
|
449
542
|
const { scene } = d;
|
|
450
|
-
const
|
|
451
|
-
const isPanel = (id) => {
|
|
452
|
-
const it = scene.items[id];
|
|
453
|
-
return !it.closed && !it.fixed && PANEL_FORMS.has(formsOf(it, "column")[0]?.kind ?? "");
|
|
454
|
-
};
|
|
455
|
-
const docked = d.order.some((e) => isSide(e) && e.accepts.length > 0 && d.owned.get(e).some(isPanel));
|
|
543
|
+
const docked = d.order.some((e) => isSide(e) && e.accepts.length > 0 && d.owned.get(e).some((id) => isDockingPanel(scene.items[id])));
|
|
456
544
|
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
457
545
|
return { inset, docked };
|
|
458
546
|
}
|
|
@@ -752,6 +840,7 @@ function laySide(d, side, cols, g, area2, f, walk, upInset, tall) {
|
|
|
752
840
|
|
|
753
841
|
// src/scene/solve.ts
|
|
754
842
|
function solve(given, options = {}) {
|
|
843
|
+
checkEdgeIds(given);
|
|
755
844
|
const d = createDraft(given, options);
|
|
756
845
|
const { scene, order } = d;
|
|
757
846
|
const stage = rect(finite(scene.stage.x, 0), finite(scene.stage.y, 0), px(scene.stage.width), px(scene.stage.height));
|
|
@@ -773,6 +862,111 @@ function solve(given, options = {}) {
|
|
|
773
862
|
return { items, edges, content, floats, rails, railPlaces, ...columnRoom2 !== void 0 ? { columnRoom: columnRoom2 } : {}, notes };
|
|
774
863
|
}
|
|
775
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
|
+
|
|
776
970
|
// src/scene/changes.ts
|
|
777
971
|
var withItem = (scene, item) => ({ ...scene, items: { ...scene.items, [item.id]: item } });
|
|
778
972
|
var itemOf = (scene, id) => Object.hasOwn(scene.items, id) ? scene.items[id] : void 0;
|
|
@@ -809,19 +1003,7 @@ function newColumn(scene, side, kind, ring, items) {
|
|
|
809
1003
|
const taken = new Set(scene.edges.map((e) => e.id));
|
|
810
1004
|
let n = 0;
|
|
811
1005
|
while (taken.has(`${side}-${n}`)) n++;
|
|
812
|
-
return {
|
|
813
|
-
id: `${side}-${n}`,
|
|
814
|
-
side,
|
|
815
|
-
ring,
|
|
816
|
-
accepts: t.accepts,
|
|
817
|
-
items,
|
|
818
|
-
cross: t.cross,
|
|
819
|
-
...t.gap !== void 0 ? { gap: t.gap } : {},
|
|
820
|
-
...t.pad ? { pad: t.pad } : {},
|
|
821
|
-
...t.menu ? { menu: t.menu } : {},
|
|
822
|
-
...t.zoneAccepts ? { zoneAccepts: t.zoneAccepts } : {},
|
|
823
|
-
column: true
|
|
824
|
-
};
|
|
1006
|
+
return columnFromTemplate(t, `${side}-${n}`, side, ring, items);
|
|
825
1007
|
}
|
|
826
1008
|
function sideRings(edges, side) {
|
|
827
1009
|
return new Map(closeRings(edges, /* @__PURE__ */ new Set([side])).filter((e) => e.side === side).map((e) => [e.id, e.ring]));
|
|
@@ -900,7 +1082,7 @@ function floatAt(scene, id, at, orient2) {
|
|
|
900
1082
|
}
|
|
901
1083
|
function fold(scene, id, on) {
|
|
902
1084
|
const item = itemOf(scene, id);
|
|
903
|
-
if (!item || item.fixed) return scene;
|
|
1085
|
+
if (!item || item.fixed && !scene.edges.some((e) => e.foldable === true && e.items.includes(id))) return scene;
|
|
904
1086
|
if (on) return (item.from ?? 0) >= 1 ? scene : withItem(scene, { ...item, from: 1 });
|
|
905
1087
|
if (item.from === void 0) return scene;
|
|
906
1088
|
const { from: _f, ...rest } = item;
|
|
@@ -941,7 +1123,17 @@ function orient(scene, id, to) {
|
|
|
941
1123
|
if (i < 0 || !item || (scene.floats[i].orient ?? floatOrientOf(item)) === to) return scene;
|
|
942
1124
|
return { ...scene, floats: scene.floats.map((f, k) => k === i ? { ...f, orient: to } : f) };
|
|
943
1125
|
}
|
|
944
|
-
function resize(scene,
|
|
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) {
|
|
945
1137
|
const edge = scene.edges.find((e) => e.id === edgeId);
|
|
946
1138
|
if (!edge) return scene;
|
|
947
1139
|
if (!Number.isFinite(size)) {
|
|
@@ -1024,6 +1216,7 @@ function storeScene(scene) {
|
|
|
1024
1216
|
};
|
|
1025
1217
|
}
|
|
1026
1218
|
function readScene(data, base) {
|
|
1219
|
+
checkEdgeIds(base);
|
|
1027
1220
|
try {
|
|
1028
1221
|
return read(data, base);
|
|
1029
1222
|
} catch (e) {
|
|
@@ -1068,9 +1261,10 @@ function read(data, base) {
|
|
|
1068
1261
|
else if (s.used !== void 0) drop(`item:${id}:used`);
|
|
1069
1262
|
if (s.kept === true) it = { ...it, kept: true };
|
|
1070
1263
|
else if (s.kept !== void 0 && s.kept !== false) drop(`item:${id}:kept`);
|
|
1071
|
-
|
|
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 };
|
|
1072
1266
|
else if (s.from !== void 0) drop(`item:${id}:from`);
|
|
1073
|
-
if (
|
|
1267
|
+
if (!byHand && b.from !== void 0) it = { ...it, from: b.from };
|
|
1074
1268
|
if (s.closed === true && !b.fixed) it = { ...it, closed: true };
|
|
1075
1269
|
else if (s.closed !== void 0 && s.closed !== false) drop(`item:${id}:closed`);
|
|
1076
1270
|
if (s.align === "center" || s.align === "end") it = { ...it, align: s.align };
|
|
@@ -1088,6 +1282,8 @@ function read(data, base) {
|
|
|
1088
1282
|
const made = [];
|
|
1089
1283
|
const rings = /* @__PURE__ */ new Map();
|
|
1090
1284
|
const moves = /* @__PURE__ */ new Map();
|
|
1285
|
+
const anchorMoves = /* @__PURE__ */ new Map();
|
|
1286
|
+
const anchorSizes = /* @__PURE__ */ new Map();
|
|
1091
1287
|
if (data.edges !== void 0 && !Array.isArray(data.edges)) drop("edges");
|
|
1092
1288
|
for (const e of Array.isArray(data.edges) ? data.edges : []) {
|
|
1093
1289
|
if (!isObject(e) || typeof e.id !== "string") {
|
|
@@ -1095,9 +1291,17 @@ function read(data, base) {
|
|
|
1095
1291
|
continue;
|
|
1096
1292
|
}
|
|
1097
1293
|
let edge = base.edges.find((x) => x.id === e.id) ?? made.find((x) => x.id === e.id);
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
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, []);
|
|
1101
1305
|
made.push(edge);
|
|
1102
1306
|
}
|
|
1103
1307
|
if (!edge || order.has(edge.id)) {
|
|
@@ -1106,7 +1310,7 @@ function read(data, base) {
|
|
|
1106
1310
|
}
|
|
1107
1311
|
if (edge.column === true && isNum(e.ring)) rings.set(edge.id, e.ring);
|
|
1108
1312
|
if (e.side !== void 0 && !SIDES.includes(e.side)) drop(`edge:${e.id}:side`);
|
|
1109
|
-
else if (edge.column !== true && typeof e.side === "string" && e.side !== edge.side && axisOf(e.side) === axisOf(edge.side)) moves.set(edge.id, e.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);
|
|
1110
1314
|
const ids = [];
|
|
1111
1315
|
for (const id of Array.isArray(e.items) ? e.items : []) {
|
|
1112
1316
|
if (!known(id) || placed.has(id)) drop(`edge:${edge.id}:${String(id)}`);
|
|
@@ -1114,7 +1318,7 @@ function read(data, base) {
|
|
|
1114
1318
|
if (edge.items.includes(id) && base.edges.some((x) => x.id === edge.id)) {
|
|
1115
1319
|
ids.push(id);
|
|
1116
1320
|
placed.add(id);
|
|
1117
|
-
} else drop(`edge:${edge.id}:${id}`);
|
|
1321
|
+
} else if (!anchorEdges.some((b) => b.items.includes(id))) drop(`edge:${edge.id}:${id}`);
|
|
1118
1322
|
} else if (!edge.accepts.includes(items[id].kind)) drop(`edge:${edge.id}:${id}`);
|
|
1119
1323
|
else {
|
|
1120
1324
|
ids.push(id);
|
|
@@ -1122,10 +1326,14 @@ function read(data, base) {
|
|
|
1122
1326
|
}
|
|
1123
1327
|
}
|
|
1124
1328
|
order.set(edge.id, ids);
|
|
1125
|
-
if (
|
|
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);
|
|
1126
1332
|
else if (e.size !== void 0) drop(`edge:${edge.id}:size`);
|
|
1127
1333
|
else sizes.set(edge.id, void 0);
|
|
1128
1334
|
}
|
|
1335
|
+
for (const [id, side] of anchorMoves) moves.set(id, side);
|
|
1336
|
+
for (const [id, size] of anchorSizes) sizes.set(id, size);
|
|
1129
1337
|
const floats = [];
|
|
1130
1338
|
if (data.floats !== void 0 && !Array.isArray(data.floats)) drop("floats");
|
|
1131
1339
|
for (const f of Array.isArray(data.floats) ? data.floats : []) {
|
|
@@ -1167,6 +1375,34 @@ function read(data, base) {
|
|
|
1167
1375
|
return { scene, dropped };
|
|
1168
1376
|
}
|
|
1169
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
|
+
|
|
1170
1406
|
// src/scene/targets/kinds.ts
|
|
1171
1407
|
var RAIL_REACH = 24;
|
|
1172
1408
|
var EDGE_KINDS = {
|
|
@@ -1176,7 +1412,7 @@ var EDGE_KINDS = {
|
|
|
1176
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 },
|
|
1177
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 },
|
|
1178
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 },
|
|
1179
|
-
columnLine: { zoneExtent: "whole", opens: "any", inward: 0, place: DEFAULT_HIT_BAND / 2, phase: 2, layer: 21, overreach: 41, priority: 2, reach: COLUMN_REACH, virtual: true }
|
|
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 }
|
|
1180
1416
|
};
|
|
1181
1417
|
function edgeKindOf(scene, e) {
|
|
1182
1418
|
if (e.compact) return "rail";
|
|
@@ -1210,26 +1446,37 @@ function distinctSlots(c, slots) {
|
|
|
1210
1446
|
const [p, q] = [landing(a), landing(b)];
|
|
1211
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);
|
|
1212
1448
|
};
|
|
1213
|
-
|
|
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)));
|
|
1214
1451
|
}
|
|
1215
|
-
function zoneSpans(scene,
|
|
1216
|
-
const el =
|
|
1452
|
+
function zoneSpans(scene, seen, edge, reach, probe) {
|
|
1453
|
+
const el = seen.edges[edge.id];
|
|
1217
1454
|
const column = axisOf(edge.side) === "column";
|
|
1218
1455
|
const main0 = column ? el.rect.y : el.rect.x;
|
|
1219
1456
|
const length = column ? el.rect.height : el.rect.width;
|
|
1220
|
-
|
|
1221
|
-
return ZONES.map((zone, k) => ({ zone, a: k === 0 ? main0 - reach : main0 + length * k / 3, b: k === 2 ? main0 + length + reach : main0 + length * (k + 1) / 3 }));
|
|
1457
|
+
const thirds = EDGE_KINDS[edgeKindOf(scene, edge)].zoneExtent === "thirds";
|
|
1222
1458
|
const at = (r) => column ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1223
1459
|
const declared = new Set(edge.zoneAccepts ? ZONES.filter((z) => edge.zoneAccepts[z] !== void 0) : ["start"]);
|
|
1224
1460
|
const placed = /* @__PURE__ */ new Map();
|
|
1225
|
-
for (const [id, it] of Object.entries(
|
|
1461
|
+
for (const [id, it] of Object.entries(seen.items)) {
|
|
1226
1462
|
if (it.edge !== edge.id || it.inMenu) continue;
|
|
1227
1463
|
const z = zoneOf(scene.items[id]);
|
|
1228
|
-
const [a, b] = at(it.rect);
|
|
1464
|
+
const [a, b] = at(thirds && it.fixed ? reservedRect(scene, seen, id) : it.rect);
|
|
1229
1465
|
const was = placed.get(z);
|
|
1230
1466
|
placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
|
|
1231
1467
|
declared.add(z);
|
|
1232
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
|
+
}
|
|
1233
1480
|
const anchor = { start: main0, center: main0 + length / 2, end: main0 + length };
|
|
1234
1481
|
const spans = ZONES.filter((z) => declared.has(z)).map((zone) => ({ zone, s: placed.get(zone) ?? probe(zone) ?? [anchor[zone], anchor[zone]] }));
|
|
1235
1482
|
return spans.map(({ zone, s }, i) => ({
|
|
@@ -1239,15 +1486,15 @@ function zoneSpans(scene, base, edge, reach, probe) {
|
|
|
1239
1486
|
}));
|
|
1240
1487
|
}
|
|
1241
1488
|
function edgeSlots(c, edge, accepts) {
|
|
1242
|
-
const { scene, rest, base, dragged, kind } = c;
|
|
1243
|
-
const el =
|
|
1489
|
+
const { scene, rest, now, base, dragged, kind } = c;
|
|
1490
|
+
const el = now.edges[edge.id];
|
|
1244
1491
|
const column = axisOf(edge.side) === "column";
|
|
1245
1492
|
const at = (r) => column ? r.y : r.x;
|
|
1246
1493
|
const len = (r) => column ? r.height : r.width;
|
|
1247
1494
|
const main0 = at(el.rect);
|
|
1248
1495
|
const length = len(el.rect);
|
|
1249
|
-
const
|
|
1250
|
-
const slotId = (zone, k) =>
|
|
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 });
|
|
1251
1498
|
const firstKind = formsOf(scene.items[dragged], axisOf(edge.side))[0]?.kind;
|
|
1252
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);
|
|
1253
1500
|
const lands = ({ layout: after }) => {
|
|
@@ -1266,28 +1513,32 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1266
1513
|
};
|
|
1267
1514
|
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
1268
1515
|
const menuLen = el.menu ? len(el.menu.rect) : 0;
|
|
1269
|
-
const occupied = (id) =>
|
|
1270
|
-
const shown = (id) =>
|
|
1271
|
-
const
|
|
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);
|
|
1272
1519
|
const startEnd = (() => {
|
|
1273
|
-
const s =
|
|
1520
|
+
const s = drawnOf2("start");
|
|
1274
1521
|
return s.length ? at(s[s.length - 1]) + len(s[s.length - 1]) : main0 + pad.start;
|
|
1275
1522
|
})();
|
|
1276
1523
|
const endStart = (() => {
|
|
1277
|
-
const e =
|
|
1524
|
+
const e = drawnOf2("end");
|
|
1278
1525
|
return e.length ? at(e[0]) : main0 + length - pad.end - menuLen;
|
|
1279
1526
|
})();
|
|
1280
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 };
|
|
1281
1528
|
const slots = [];
|
|
1529
|
+
const aimed = (id) => shown(id) && !now.items[id].fixed;
|
|
1530
|
+
let earlier = 0;
|
|
1282
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;
|
|
1283
1535
|
if (!accepts || !zoneTakes(edge, zone, kind)) continue;
|
|
1284
|
-
const members = restEdge.items.filter((id) => zoneOf(rest.items[id]) === zone);
|
|
1285
1536
|
for (let k = 0; k <= members.length; k++) {
|
|
1286
1537
|
const next = members.slice(k).find(shown);
|
|
1287
1538
|
const before = members.slice(0, k).reverse().find(shown);
|
|
1288
1539
|
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len(occupied(before)) : anchorLine[zone];
|
|
1289
|
-
const s = slotAt(c, zone, line, slotId(zone, k), { kind: "gap", edge: edge.id, zone, at: k }, lands);
|
|
1290
|
-
const movesFixed =
|
|
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) => {
|
|
1291
1542
|
const b = base.items[id];
|
|
1292
1543
|
const a = s.result.layout.items[id];
|
|
1293
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);
|
|
@@ -1298,10 +1549,10 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1298
1549
|
return slots;
|
|
1299
1550
|
}
|
|
1300
1551
|
function edgeSpec(c, edge) {
|
|
1301
|
-
const { scene, rest, now,
|
|
1302
|
-
const el =
|
|
1303
|
-
if (!el || el.folded || el.rides) return null;
|
|
1304
|
-
const edgeKind = edgeKindOf(
|
|
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);
|
|
1305
1556
|
const data = EDGE_KINDS[edgeKind];
|
|
1306
1557
|
const column = axisOf(edge.side) === "column";
|
|
1307
1558
|
const at = (r2) => column ? r2.y : r2.x;
|
|
@@ -1309,26 +1560,25 @@ function edgeSpec(c, edge) {
|
|
|
1309
1560
|
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
1310
1561
|
const accepts = edge.accepts.includes(kind);
|
|
1311
1562
|
if (!accepts && (empty || area(el.rect) <= EPS)) return null;
|
|
1312
|
-
if (accepts && empty && !opensEmpty(
|
|
1563
|
+
if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;
|
|
1313
1564
|
const ownNow = now.items[dragged];
|
|
1314
|
-
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating &&
|
|
1565
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area(ownNow.rect) > EPS ? ownNow.rect : null;
|
|
1315
1566
|
const slots = edgeSlots(c, edge, accepts);
|
|
1316
1567
|
const spanOf = (r2) => [at(r2), at(r2) + len(r2)];
|
|
1317
|
-
const grows = (id) => !!formsOf(scene.items[id], axisOf(edge.side))[
|
|
1318
|
-
const reserved = Object.entries(
|
|
1319
|
-
const
|
|
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) => {
|
|
1320
1572
|
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
1321
1573
|
const me = s?.result.layout.items[dragged];
|
|
1322
1574
|
return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
|
|
1323
1575
|
});
|
|
1324
1576
|
const r = el.rect;
|
|
1325
1577
|
const strip = Math.max(0, Number.isFinite(edge.strip) ? edge.strip : DEFAULT_STRIP);
|
|
1326
|
-
const nowCross = now.edges[edge.id]?.cross ?? 0;
|
|
1327
1578
|
const outer = edge.side === "left" ? r.x : edge.side === "right" ? r.x + r.width : edge.side === "top" ? r.y : r.y + r.height;
|
|
1328
1579
|
const inward = (depth) => edge.side === "left" || edge.side === "top" ? [outer, outer + depth] : [outer - depth, outer];
|
|
1329
|
-
const across = (after) => inward((el.cross > 0
|
|
1330
|
-
const
|
|
1331
|
-
const drawn = ownCross > 0;
|
|
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;
|
|
1332
1582
|
const marker = (s) => {
|
|
1333
1583
|
const slot = s.result.layout.items[dragged].rect;
|
|
1334
1584
|
const e = s.result.layout.edges[edge.id];
|
|
@@ -1337,7 +1587,7 @@ function edgeSpec(c, edge) {
|
|
|
1337
1587
|
const takes = (zone) => accepts && zoneTakes(edge, zone, kind);
|
|
1338
1588
|
return {
|
|
1339
1589
|
id: edge.id,
|
|
1340
|
-
|
|
1590
|
+
edge,
|
|
1341
1591
|
kind: edgeKind,
|
|
1342
1592
|
lay: c.lay.get(edge.id),
|
|
1343
1593
|
vertical: column,
|
|
@@ -1347,8 +1597,9 @@ function edgeSpec(c, edge) {
|
|
|
1347
1597
|
own: ownHere,
|
|
1348
1598
|
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
1349
1599
|
reserved,
|
|
1600
|
+
cards,
|
|
1350
1601
|
across,
|
|
1351
|
-
owned: inward(drawn ?
|
|
1602
|
+
owned: inward(drawn ? el.cross : Math.min(strip, data.place)),
|
|
1352
1603
|
ownedAlong: null,
|
|
1353
1604
|
drawn,
|
|
1354
1605
|
marker
|
|
@@ -1398,7 +1649,7 @@ function context(scene, dragged, options) {
|
|
|
1398
1649
|
const now = solve(scene, prev);
|
|
1399
1650
|
const rest = lift(scene, dragged);
|
|
1400
1651
|
const base = solve(rest, prev);
|
|
1401
|
-
const here = placeKey(scene, dragged);
|
|
1652
|
+
const here = placeKey(prune(scene), dragged);
|
|
1402
1653
|
const c = {
|
|
1403
1654
|
scene,
|
|
1404
1655
|
rest,
|
|
@@ -1436,45 +1687,44 @@ function ownedRectsOf(s, along) {
|
|
|
1436
1687
|
if (s.ownedAlong) return [o];
|
|
1437
1688
|
return along.map(([a, b]) => s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height));
|
|
1438
1689
|
}
|
|
1439
|
-
function
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
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));
|
|
1444
1706
|
}
|
|
1445
|
-
function ownersOf(c, live, alongOf) {
|
|
1446
|
-
const
|
|
1447
|
-
const
|
|
1448
|
-
const
|
|
1449
|
-
const homeRect = (() => {
|
|
1450
|
-
if (!ownRect || ownRect.floating || !ownEdge) return null;
|
|
1451
|
-
const o = ownRect.rect;
|
|
1452
|
-
const s = live.find((x) => x.id === ownEdge);
|
|
1453
|
-
if (!s || ownRect.inMenu) return o;
|
|
1454
|
-
const [c0, c1] = s.across();
|
|
1455
|
-
return s.vertical ? rect(Math.min(c0, o.x), o.y, Math.max(c1, o.x + o.width) - Math.min(c0, o.x), o.height) : rect(o.x, Math.min(c0, o.y), o.width, Math.max(c1, o.y + o.height) - Math.min(c0, o.y));
|
|
1456
|
-
})();
|
|
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);
|
|
1457
1711
|
return [
|
|
1458
1712
|
// Home first: its tile is its own, for every edge but its own (which tiles it as its own interval).
|
|
1459
|
-
...homeRect
|
|
1713
|
+
...homeRect ? [{ spec: ownSpec, rect: homeRect, lay: { phase: -1, side: "", at: -Infinity }, place: false }] : [],
|
|
1460
1714
|
// Every edge the tiler reads, along each zone with a slot the filter keeps: what it owns, drawn or a band of its
|
|
1461
1715
|
// place (a column line's band about its line). A zone whose every slot is refused owns nothing against the others
|
|
1462
1716
|
// (its drawn rect still counts, below).
|
|
1463
|
-
...live.flatMap((s) => ownedRectsOf(s, alongOf(s)).map((r) => ({
|
|
1464
|
-
// Every
|
|
1465
|
-
|
|
1466
|
-
...Object.entries(base.edges).filter(([id, e]) => area(e.rect) > EPS && c.lay.has(id)).map(([id, e]) => ({ id, key: id, rect: e.rect, lay: c.lay.get(id), place: false })),
|
|
1467
|
-
// And where each edge is seen, as it is now, and no edge lies once lifted (`seenOf`): a stretch is owned by what the
|
|
1468
|
-
// user sees there. An edge that moves when the item lifts never owns, where it lay before, a stretch another edge
|
|
1469
|
-
// lies in once lifted.
|
|
1470
|
-
...seenOf(c).map(({ edge, rect: r }) => ({ id: edge, key: edge, rect: r, lay: c.lay.get(edge), place: false }))
|
|
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 }))
|
|
1471
1720
|
];
|
|
1472
1721
|
}
|
|
1473
1722
|
function ownership(c, live, alongOf) {
|
|
1474
|
-
const { scene,
|
|
1475
|
-
const
|
|
1723
|
+
const { scene, now, dragged } = c;
|
|
1724
|
+
const drawn = drawnOf(c, live);
|
|
1725
|
+
const owners = ownersOf(c, live, drawn, alongOf);
|
|
1476
1726
|
const wins = (o, s) => {
|
|
1477
|
-
if (o.
|
|
1727
|
+
if (o.spec === s) return false;
|
|
1478
1728
|
if (pushes(o.lay, s.lay)) return true;
|
|
1479
1729
|
if (pushes(s.lay, o.lay)) return false;
|
|
1480
1730
|
const place = !s.drawn;
|
|
@@ -1482,26 +1732,34 @@ function ownership(c, live, alongOf) {
|
|
|
1482
1732
|
};
|
|
1483
1733
|
const taken = new Map(
|
|
1484
1734
|
live.map((s) => [
|
|
1485
|
-
s
|
|
1735
|
+
s,
|
|
1486
1736
|
[
|
|
1487
1737
|
...owners.filter((o) => wins(o, s)).map((o) => o.rect),
|
|
1488
|
-
...EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.
|
|
1738
|
+
...EDGE_KINDS[s.kind].virtual ? owners.filter((o) => o.spec !== s && !wins(o, s)).flatMap((o) => subtract(o.rect, ownedRectOf(s))) : []
|
|
1489
1739
|
]
|
|
1490
1740
|
])
|
|
1491
1741
|
);
|
|
1492
|
-
const
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
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 [];
|
|
1496
1749
|
const column = axisOf(e.side) === "column";
|
|
1497
|
-
|
|
1498
|
-
return Object.entries(base.items).filter(([iid, p]) => p.edge === id && p.formKind === "open" && iid !== dragged).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS);
|
|
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);
|
|
1499
1751
|
};
|
|
1752
|
+
const rooms = /* @__PURE__ */ new Map();
|
|
1500
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) => {
|
|
1501
1759
|
const b = bandOf(s);
|
|
1502
1760
|
const along = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1503
1761
|
const across = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
1504
|
-
const rs = taken.get(s
|
|
1762
|
+
const rs = taken.get(s).filter((r) => overlaps(r, b));
|
|
1505
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);
|
|
1506
1764
|
const owned = [];
|
|
1507
1765
|
for (let k = 1; k < ends.length; k++) {
|
|
@@ -1509,27 +1767,43 @@ function ownership(c, live, alongOf) {
|
|
|
1509
1767
|
const over = rs.filter((r) => along(r)[0] <= u + EPS && along(r)[1] >= w - EPS).map(across);
|
|
1510
1768
|
if (w - u > EPS && less([across(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
1511
1769
|
}
|
|
1512
|
-
|
|
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) };
|
|
1513
1788
|
};
|
|
1514
|
-
const grows = (
|
|
1515
|
-
const it =
|
|
1516
|
-
const e = it.edge ?
|
|
1789
|
+
const grows = (id) => {
|
|
1790
|
+
const it = now.items[id];
|
|
1791
|
+
const e = it.edge ? now.edges[it.edge] : void 0;
|
|
1517
1792
|
return !!e && !!formsOf(scene.items[id], axisOf(e.side))[it.form]?.main.grows;
|
|
1518
1793
|
};
|
|
1519
|
-
const solid =
|
|
1520
|
-
const bodies = (
|
|
1521
|
-
const e =
|
|
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;
|
|
1522
1797
|
if (!e) return [];
|
|
1523
1798
|
const column = axisOf(e.side) === "column";
|
|
1524
1799
|
const across = (a, b) => column ? rect(-1e9, a, 2e9, b - a) : rect(a, -1e9, b - a, 2e9);
|
|
1525
|
-
const reserved = Object.entries(
|
|
1526
|
-
return [...reserved, ...
|
|
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);
|
|
1527
1802
|
};
|
|
1528
|
-
const
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
if (!rs) drawnByKey.set(key, rs = drawn.filter((d) => d.key !== key).map((d) => d.rect));
|
|
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));
|
|
1533
1807
|
return rs;
|
|
1534
1808
|
};
|
|
1535
1809
|
return { owners, taken, cutsOf, bodies, solid, drawnBesides };
|
|
@@ -1544,7 +1818,7 @@ function tilerOf(spec) {
|
|
|
1544
1818
|
return v ? rect(c0, a, c1 - c0, b - a) : rect(a, c0, b - a, c1 - c0);
|
|
1545
1819
|
};
|
|
1546
1820
|
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
1547
|
-
const tile = (zone, hit, more) => ({ edge: spec.id,
|
|
1821
|
+
const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
1548
1822
|
const split = (t) => {
|
|
1549
1823
|
const h = t.hit;
|
|
1550
1824
|
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
@@ -1558,6 +1832,7 @@ function tilerOf(spec) {
|
|
|
1558
1832
|
};
|
|
1559
1833
|
return { band, keepAt, tile, split };
|
|
1560
1834
|
}
|
|
1835
|
+
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS);
|
|
1561
1836
|
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
1562
1837
|
const reserved = spec.reserved;
|
|
1563
1838
|
const lines = mine.map((s) => s.line);
|
|
@@ -1582,46 +1857,75 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
|
1582
1857
|
if (pieces.some(([a, b]) => p >= a - EPS && p <= b + EPS)) return p;
|
|
1583
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);
|
|
1584
1859
|
};
|
|
1585
|
-
const
|
|
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);
|
|
1586
1862
|
const projected = inPiece.map((s) => proj(s.line));
|
|
1587
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;
|
|
1588
1864
|
return { inPiece, at };
|
|
1589
1865
|
}
|
|
1590
|
-
function tileEdge(c, spec, cuts, lost) {
|
|
1866
|
+
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
1591
1867
|
const data = EDGE_KINDS[spec.kind];
|
|
1592
1868
|
const v = spec.vertical;
|
|
1593
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;
|
|
1594
1870
|
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
1595
1871
|
const refused = (zone, hit, reason) => tile(zone, hit, { kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason });
|
|
1596
1872
|
const slots = distinctSlots(c, spec.slots);
|
|
1873
|
+
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
1597
1874
|
const out = [];
|
|
1598
1875
|
for (const z of spec.zones) {
|
|
1599
1876
|
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS);
|
|
1600
|
-
if (room.length === 0) continue;
|
|
1601
1877
|
const pieces = own ? less(room, [own]) : room;
|
|
1602
|
-
|
|
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));
|
|
1603
1881
|
const reason = spec.refuse(z.zone);
|
|
1604
1882
|
for (const [pa, pb] of pieces) {
|
|
1605
1883
|
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
1606
1884
|
if (inPiece.length === 0) {
|
|
1607
1885
|
const lone = reason === "no-room" && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
|
|
1608
|
-
const near = mine.length === 0 || mine.some((s) => pb > s.line - data.reach + EPS && pa < s.line + data.reach - EPS);
|
|
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
|
+
}
|
|
1609
1894
|
if (reason && near) out.push(...split(refused(z.zone, band(pa, pb), lone ? "own-place" : reason)));
|
|
1610
1895
|
continue;
|
|
1611
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
|
+
};
|
|
1612
1903
|
inPiece.forEach((s, i) => {
|
|
1613
1904
|
const p = at[i];
|
|
1614
|
-
const
|
|
1615
|
-
const
|
|
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);
|
|
1616
1908
|
if (b - a <= EPS) {
|
|
1617
|
-
if (s.ok) lost.push(s.id);
|
|
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)));
|
|
1618
1919
|
return;
|
|
1619
1920
|
}
|
|
1620
|
-
const
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
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
|
+
}
|
|
1625
1929
|
});
|
|
1626
1930
|
}
|
|
1627
1931
|
}
|
|
@@ -1631,7 +1935,7 @@ function tileEdge(c, spec, cuts, lost) {
|
|
|
1631
1935
|
const h = band(a, b);
|
|
1632
1936
|
const o = spec.own;
|
|
1633
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));
|
|
1634
|
-
out.push(tile(home?.zone ?? zoneOf(c.scene.items[c.dragged]), hit, { kind: "home", id: home ? home.id :
|
|
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" } }));
|
|
1635
1939
|
}
|
|
1636
1940
|
return out;
|
|
1637
1941
|
}
|
|
@@ -1673,12 +1977,14 @@ function placeReach(t, pieces, placed, landed, gone) {
|
|
|
1673
1977
|
var isRefused = (t) => t.kind === "refuse" || t.kind === "reach" && t.of.kind === "refuse";
|
|
1674
1978
|
function clipTiles(tiles, own, chrome, lost) {
|
|
1675
1979
|
const { owners, taken, bodies, solid } = own;
|
|
1676
|
-
const
|
|
1980
|
+
const bySpec = /* @__PURE__ */ new Map();
|
|
1677
1981
|
const others = (t) => {
|
|
1678
|
-
let rs =
|
|
1679
|
-
if (!rs)
|
|
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));
|
|
1680
1984
|
return rs;
|
|
1681
1985
|
};
|
|
1986
|
+
const besides = (t) => t.spec ? own.drawnBesides(t.spec) : [];
|
|
1987
|
+
const bodiesOf = (t) => t.spec ? bodies(t.spec) : [];
|
|
1682
1988
|
const placed = [];
|
|
1683
1989
|
const later = [];
|
|
1684
1990
|
const refused = tiles.filter(isRefused);
|
|
@@ -1695,11 +2001,11 @@ function clipTiles(tiles, own, chrome, lost) {
|
|
|
1695
2001
|
return;
|
|
1696
2002
|
}
|
|
1697
2003
|
if (t.kind === "reach") {
|
|
1698
|
-
placeReach(t, clip(t.hit, [...placed.flatMap(coverOf), ...others(t), ...
|
|
2004
|
+
placeReach(t, clip(t.hit, [...placed.flatMap(coverOf), ...others(t), ...bodiesOf(t), ...solid, ...chrome]), placed, landed, gone);
|
|
1699
2005
|
return;
|
|
1700
2006
|
}
|
|
1701
|
-
const yields = t.kind === "refuse" ?
|
|
1702
|
-
const cuts = [...placed.flatMap(coverOf), ...taken.get(t.
|
|
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];
|
|
1703
2009
|
const pieces = clip(t.hit, cuts);
|
|
1704
2010
|
if (pieces.length === 0) {
|
|
1705
2011
|
if (t.kind !== "refuse") gone.add(t);
|
|
@@ -1719,84 +2025,101 @@ function clipTiles(tiles, own, chrome, lost) {
|
|
|
1719
2025
|
const byOrder = (a, b) => a.order - b.order;
|
|
1720
2026
|
for (const t of tiles.filter((x) => !isRefused(x)).sort(byOrder)) place(t);
|
|
1721
2027
|
for (const t of refused.sort(byOrder)) place(t);
|
|
1722
|
-
for (const t of gone) lost.push(t.id);
|
|
1723
|
-
for (const t of later) for (const p of clip(t.hit, [...placed.flatMap(coverOf), ...
|
|
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 });
|
|
1724
2030
|
return placed;
|
|
1725
2031
|
}
|
|
1726
|
-
function seenRefusals(c, live, placed, own, chrome) {
|
|
1727
|
-
const out = [];
|
|
1728
|
-
const covered = placed.flatMap(coverOf);
|
|
1729
|
-
for (const { edge, rect: r } of seenOf(c)) {
|
|
1730
|
-
const e = c.scene.edges.find((x) => x.id === edge);
|
|
1731
|
-
if (!e) continue;
|
|
1732
|
-
const vertical = axisOf(e.side) === "column";
|
|
1733
|
-
const band = e.hitBand ?? DEFAULT_HIT_BAND;
|
|
1734
|
-
const half = band === "middle" ? 0 : Math.max(0, Number.isFinite(band) ? band : DEFAULT_HIT_BAND) / 2;
|
|
1735
|
-
const bodies = band === "middle" ? [] : Object.entries(c.now.items).filter(([id, p]) => p.edge === edge && p.formKind === "open" && id !== c.dragged).map(([, p]) => vertical ? rect(p.rect.x, p.rect.y + half, p.rect.width, p.rect.height - 2 * half) : rect(p.rect.x + half, p.rect.y, p.rect.width - 2 * half, p.rect.height)).filter((b) => b.width > EPS && b.height > EPS);
|
|
1736
|
-
const spec = live.find((s) => s.key === edge);
|
|
1737
|
-
const zones = spec?.zones ?? [{ zone: "start", a: -Infinity, b: Infinity }];
|
|
1738
|
-
const kind = edgeKindOf(c.rest, e);
|
|
1739
|
-
for (const p of clip(r, [...covered, ...bodies, ...own.solid, ...chrome]))
|
|
1740
|
-
for (const z of zones) {
|
|
1741
|
-
const [p0, p1] = vertical ? [p.y, p.y + p.height] : [p.x, p.x + p.width];
|
|
1742
|
-
const [a, b] = [Math.max(p0, z.a), Math.min(p1, z.b)];
|
|
1743
|
-
if (b - a <= EPS) continue;
|
|
1744
|
-
const hit = vertical ? rect(p.x, a, p.width, b - a) : rect(a, p.y, b - a, p.height);
|
|
1745
|
-
const reason = spec?.refuse(z.zone) ?? (zoneTakes(e, z.zone, c.kind) ? "no-room" : "not-accepted");
|
|
1746
|
-
out.push({ edge, key: edge, edgeKind: kind, vertical, zone: z.zone, order: 99, kind: "refuse", id: "", priority: EDGE_KINDS[kind].priority, hit, keep: null, reason });
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
return out;
|
|
1750
|
-
}
|
|
1751
2032
|
|
|
1752
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
|
+
}
|
|
1753
2049
|
function columnLines(c, side) {
|
|
1754
|
-
const {
|
|
1755
|
-
const cols =
|
|
1756
|
-
const own = Object.values(
|
|
1757
|
-
const span = own[0]?.rect ??
|
|
1758
|
-
const rings =
|
|
1759
|
-
const ringOf = (e) => rings.get(e.id) ?? e.ring;
|
|
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);
|
|
1760
2055
|
const lines = [];
|
|
1761
2056
|
const outerX = (r) => side === "left" ? r.x : r.x + r.width;
|
|
1762
2057
|
const innerX = (r) => side === "left" ? r.x + r.width : r.x;
|
|
1763
2058
|
const atOf = (e) => c.lay.get(e.id)?.at ?? 0;
|
|
1764
|
-
cols.forEach((x) => lines.push({ x: outerX(x.r), ring:
|
|
1765
|
-
if (cols.length > 0) lines.push({ x: innerX(cols[cols.length - 1].r), ring:
|
|
1766
|
-
else lines.push({ x: side === "left" ?
|
|
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 });
|
|
1767
2062
|
const lands = (r) => {
|
|
1768
2063
|
const me = r.layout.items[dragged];
|
|
1769
2064
|
const el = me.edge ? r.layout.edges[me.edge] : void 0;
|
|
1770
2065
|
return !!el && !me.inMenu && !el.folded && !el.rides && r.scene !== c.scene;
|
|
1771
2066
|
};
|
|
1772
|
-
const { reach, place } = EDGE_KINDS.columnLine;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
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
|
+
});
|
|
1791
2105
|
}
|
|
1792
2106
|
function railStops(c, side) {
|
|
1793
|
-
const {
|
|
1794
|
-
const rail =
|
|
1795
|
-
const placeRect =
|
|
2107
|
+
const { scene, now, dragged } = c;
|
|
2108
|
+
const rail = now.rails[side];
|
|
2109
|
+
const placeRect = now.railPlaces[side];
|
|
1796
2110
|
if (!placeRect) return null;
|
|
1797
|
-
const rings =
|
|
1798
|
-
const
|
|
1799
|
-
const
|
|
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
|
+
};
|
|
1800
2123
|
const stops2 = [];
|
|
1801
2124
|
let zone;
|
|
1802
2125
|
if (rail && rail.segments.length > 0) {
|
|
@@ -1807,30 +2130,32 @@ function railStops(c, side) {
|
|
|
1807
2130
|
if (g && g.edge === s.edge) g.y1 = s.rect.y + s.rect.height;
|
|
1808
2131
|
else groups.push({ edge: s.edge, y0: s.rect.y, y1: s.rect.y + s.rect.height });
|
|
1809
2132
|
}
|
|
1810
|
-
for (const g of groups) stops2.push({ y: g.y0, ring:
|
|
2133
|
+
for (const g of groups) stops2.push({ y: g.y0, ring: ringBefore(g.edge) });
|
|
1811
2134
|
const last = groups[groups.length - 1];
|
|
1812
|
-
stops2.push({ y: last.y1, ring:
|
|
2135
|
+
stops2.push({ y: last.y1, ring: ringAfter(last.edge) });
|
|
1813
2136
|
} else {
|
|
1814
2137
|
const firstCol = mine.find((e) => e.column === true);
|
|
1815
|
-
|
|
1816
|
-
|
|
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 });
|
|
1817
2141
|
}
|
|
1818
2142
|
const ownRail = now.items[dragged]?.rail === side;
|
|
1819
2143
|
const lands = (r) => r.layout.items[dragged].rail === side && r.scene !== c.scene;
|
|
1820
2144
|
const at = zone;
|
|
1821
2145
|
return {
|
|
1822
|
-
id:
|
|
1823
|
-
|
|
2146
|
+
id: virtualEdgeId("rail", side),
|
|
2147
|
+
edge: null,
|
|
1824
2148
|
kind: "railStop",
|
|
1825
2149
|
// The rail lies outside every edge on its side: laid first among them.
|
|
1826
2150
|
lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
|
|
1827
2151
|
vertical: true,
|
|
1828
2152
|
zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
|
|
1829
|
-
slots: stops2.map((s) => slotAt(c, "start", s.y,
|
|
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)),
|
|
1830
2154
|
refuse: () => "no-room",
|
|
1831
2155
|
own: null,
|
|
1832
2156
|
holds: false,
|
|
1833
2157
|
reserved: [],
|
|
2158
|
+
cards: [],
|
|
1834
2159
|
across: () => [at.x, at.x + at.width],
|
|
1835
2160
|
// A drawn rail owns its rect; where none shows, a thin band of its place at the side's outer boundary.
|
|
1836
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],
|
|
@@ -1842,8 +2167,8 @@ function railStops(c, side) {
|
|
|
1842
2167
|
|
|
1843
2168
|
// src/scene/targets.ts
|
|
1844
2169
|
function specsOf(c, kind) {
|
|
1845
|
-
const { scene
|
|
1846
|
-
const specs =
|
|
2170
|
+
const { scene } = c;
|
|
2171
|
+
const specs = scene.edges.map((edge) => edgeSpec(c, edge));
|
|
1847
2172
|
for (const side of ["left", "right"]) {
|
|
1848
2173
|
const template = scene.columns?.[side];
|
|
1849
2174
|
if (!template || !zoneTakes(template, "start", kind)) continue;
|
|
@@ -1854,25 +2179,39 @@ function specsOf(c, kind) {
|
|
|
1854
2179
|
}
|
|
1855
2180
|
function emit2(c, placed) {
|
|
1856
2181
|
const { scene, now, dragged } = c;
|
|
2182
|
+
const homeId = targetId({ kind: "home", item: dragged });
|
|
1857
2183
|
const targets2 = [];
|
|
1858
2184
|
const refused = [];
|
|
1859
2185
|
const homeAfter = () => ({ scene, layout: now });
|
|
1860
|
-
const keyOf = (t) => `refuse:${t.edge}:${t.zone}`;
|
|
1861
2186
|
const pos = (t) => t.vertical ? [t.hit.y, t.hit.x] : [t.hit.x, t.hit.y];
|
|
1862
2187
|
const rank = /* @__PURE__ */ new Map();
|
|
1863
|
-
const
|
|
1864
|
-
|
|
1865
|
-
for (const
|
|
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));
|
|
1866
2196
|
let ownHome = null;
|
|
1867
2197
|
for (const t of placed) {
|
|
1868
2198
|
if (t.kind === "refuse") {
|
|
1869
2199
|
const n = rank.get(t);
|
|
1870
|
-
refused.push({ id:
|
|
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 });
|
|
1871
2201
|
continue;
|
|
1872
2202
|
}
|
|
1873
|
-
if (t.kind === "home") {
|
|
2203
|
+
if (t.kind === "home" && t.id === homeId) {
|
|
1874
2204
|
if (t.order === 0) ownHome = t.hit;
|
|
1875
|
-
|
|
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") {
|
|
1876
2215
|
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, item: dragged, place: { kind: "home" }, after: homeAfter });
|
|
1877
2216
|
continue;
|
|
1878
2217
|
}
|
|
@@ -1892,21 +2231,23 @@ function alongOfSlots(s, tiles) {
|
|
|
1892
2231
|
return out;
|
|
1893
2232
|
}
|
|
1894
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);
|
|
1895
2236
|
const ctx = context(scene, dragged, options);
|
|
1896
2237
|
if (!ctx) return { targets: [], refusals: [], lost: [] };
|
|
1897
2238
|
const { c, item, prev } = ctx;
|
|
1898
2239
|
const { now } = c;
|
|
1899
2240
|
const live = specsOf(c, item.kind);
|
|
1900
|
-
const along = new Map(live.map((s) => [s
|
|
1901
|
-
const own = ownership(c, live, (s) => along.get(s
|
|
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));
|
|
1902
2243
|
const lost = [];
|
|
1903
2244
|
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
|
|
1904
2245
|
const ownRect = now.items[dragged];
|
|
1905
2246
|
const homeEdge = scene.edges.find((e) => e.id === ownRect?.edge);
|
|
1906
|
-
|
|
1907
|
-
|
|
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 });
|
|
1908
2250
|
const placed = clipTiles(tiles, own, scene.chrome ?? [], lost);
|
|
1909
|
-
placed.push(...seenRefusals(c, live, placed, own, scene.chrome ?? []));
|
|
1910
2251
|
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
1911
2252
|
const homeAfter = () => ({ scene, layout: now });
|
|
1912
2253
|
if (scene.floatKinds.includes(item.kind)) {
|
|
@@ -1914,7 +2255,7 @@ function generate(scene, dragged, options) {
|
|
|
1914
2255
|
const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
|
|
1915
2256
|
const size = options.floatSize ?? (was ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
|
|
1916
2257
|
targets2.push({
|
|
1917
|
-
id:
|
|
2258
|
+
id: targetId({ kind: "float", item: dragged }),
|
|
1918
2259
|
priority: 3,
|
|
1919
2260
|
free: true,
|
|
1920
2261
|
hit: PLANE,
|
|
@@ -1930,10 +2271,10 @@ function generate(scene, dragged, options) {
|
|
|
1930
2271
|
});
|
|
1931
2272
|
}
|
|
1932
2273
|
(scene.blocked ?? []).forEach((b, i) => {
|
|
1933
|
-
targets2.push({ id:
|
|
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 });
|
|
1934
2275
|
});
|
|
1935
|
-
if (ownRect && !ownRect.floating) targets2.push({ id:
|
|
1936
|
-
return { targets: targets2, refusals: refused, lost };
|
|
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)) };
|
|
1937
2278
|
}
|
|
1938
2279
|
function targets(scene, dragged, options = {}) {
|
|
1939
2280
|
return generate(scene, dragged, options).targets;
|
|
@@ -1947,7 +2288,7 @@ function stops(scene, dragged, options = {}) {
|
|
|
1947
2288
|
const sideOf = (t) => {
|
|
1948
2289
|
const p = t.place;
|
|
1949
2290
|
if (p.kind === "float") return "float";
|
|
1950
|
-
if (p.kind === "column" || p.kind === "rail") return p.side;
|
|
2291
|
+
if (p.kind === "column" || p.kind === "rail" || p.kind === "side") return p.side;
|
|
1951
2292
|
if (p.kind === "gap") return scene.edges.find((e) => e.id === p.edge)?.side ?? "float";
|
|
1952
2293
|
return "float";
|
|
1953
2294
|
};
|
|
@@ -1974,7 +2315,12 @@ export {
|
|
|
1974
2315
|
isSideBar,
|
|
1975
2316
|
floatOrientOf,
|
|
1976
2317
|
floatSizeOf,
|
|
2318
|
+
targetId,
|
|
2319
|
+
parseTargetId,
|
|
2320
|
+
virtualEdgeId,
|
|
2321
|
+
placeTargetId,
|
|
1977
2322
|
solve,
|
|
2323
|
+
fitResize,
|
|
1978
2324
|
lift,
|
|
1979
2325
|
moveTo,
|
|
1980
2326
|
floatAt,
|
|
@@ -1996,4 +2342,4 @@ export {
|
|
|
1996
2342
|
refusals,
|
|
1997
2343
|
stops
|
|
1998
2344
|
};
|
|
1999
|
-
//# sourceMappingURL=chunk-
|
|
2345
|
+
//# sourceMappingURL=chunk-3GIUOVQH.js.map
|