@n-uf/placement 26.11.43 → 26.11.45
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 +70 -0
- package/README.md +114 -0
- package/dist/{chunk-PO3ILUMO.js → chunk-6IHRZ3NP.js} +449 -106
- package/dist/chunk-6IHRZ3NP.js.map +1 -0
- package/dist/{model-CSO5fk_L.d.ts → lanes-CRAFabRE.d.ts} +174 -4
- package/dist/scene-cases.d.ts +186 -2
- package/dist/scene-cases.js +310 -7
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +13 -4
- package/dist/scene.js +11 -1
- package/package.json +2 -2
- package/dist/chunk-PO3ILUMO.js.map +0 -1
|
@@ -33,6 +33,15 @@ var DEFAULT_HIT_BAND = 24;
|
|
|
33
33
|
var DEFAULT_FLOAT_SIZE = { width: 280, height: 360 };
|
|
34
34
|
|
|
35
35
|
// src/scene/helpers.ts
|
|
36
|
+
var insetPx = (v) => Number.isFinite(v) ? Math.max(0, v) : 0;
|
|
37
|
+
function floatRegion(scene, lifted) {
|
|
38
|
+
const floating = new Set(scene.floats.map((f) => f.id));
|
|
39
|
+
const docked = scene.edges.some((e) => (e.side === "left" || e.side === "right") && e.accepts.length > 0 && e.items.some((id) => id !== lifted && !floating.has(id) && !!scene.items[id] && isDockingPanel(scene.items[id])));
|
|
40
|
+
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
41
|
+
const { stage } = scene;
|
|
42
|
+
return { x: stage.x + insetPx(inset.left), y: stage.y, width: Math.max(0, stage.width - insetPx(inset.left) - insetPx(inset.right)), height: stage.height };
|
|
43
|
+
}
|
|
44
|
+
var heldRect = (scene, id, size, pointer, grab) => clampInto({ x: pointer.x - grab.x, y: pointer.y - grab.y, width: size.width, height: size.height }, floatRegion(scene, id));
|
|
36
45
|
var anchorName = (anchor) => typeof anchor === "string" ? anchor : anchor.at;
|
|
37
46
|
var isSince = (x) => typeof x === "number" && x >= 0 && x <= Number.MAX_SAFE_INTEGER;
|
|
38
47
|
var zonesOf = (edge) => {
|
|
@@ -183,6 +192,7 @@ function isSideBar(scene, e) {
|
|
|
183
192
|
const panelKinds = [...template?.accepts ?? [], ...rail?.accepts ?? []];
|
|
184
193
|
return !e.accepts.some((k) => panelKinds.includes(k));
|
|
185
194
|
}
|
|
195
|
+
var isSideColumn = (scene, e) => (e.side === "left" || e.side === "right") && !e.compact && e.accepts.length > 0 && !isSideBar(scene, e);
|
|
186
196
|
var floatOrientOf = (item) => {
|
|
187
197
|
if (item.floatOrient === "row" || item.floatOrient === "column") return item.floatOrient;
|
|
188
198
|
for (const k of Object.keys(item.forms)) if ((k === "row" || k === "column") && formsOf(item, k).length > 0) return k;
|
|
@@ -470,7 +480,7 @@ function zoneStarts(scene, fit, input) {
|
|
|
470
480
|
out.set(p.id, at(p.rect));
|
|
471
481
|
lengths.set(p.id, column ? p.rect.height : p.rect.width);
|
|
472
482
|
}
|
|
473
|
-
const
|
|
483
|
+
const len2 = (p) => lengths.get(p.id);
|
|
474
484
|
const gap = px(input.gap);
|
|
475
485
|
const start = px(input.pad?.start);
|
|
476
486
|
const end = px(input.pad?.end);
|
|
@@ -482,32 +492,42 @@ function zoneStarts(scene, fit, input) {
|
|
|
482
492
|
const title = column ? void 0 : s.find((p) => {
|
|
483
493
|
const it = scene.items[p.id];
|
|
484
494
|
const f = formsOf(it, "row")[p.form];
|
|
485
|
-
return it.fixed && f?.main.grows &&
|
|
495
|
+
return it.fixed && f?.main.grows && len2(p) > formMain(f, "natural", fit.cross) + EPS;
|
|
486
496
|
});
|
|
487
497
|
if (title) lengths.set(title.id, formMain(formsOf(scene.items[title.id], "row")[title.form], "natural", fit.cross));
|
|
488
|
-
const used = drawn.reduce((sum, p) => sum +
|
|
498
|
+
const used = drawn.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, drawn.length - 1) * gap;
|
|
489
499
|
const spare = fit.length - start - end - menu - used;
|
|
490
500
|
if (spare <= EPS) return { starts: out, lengths };
|
|
491
|
-
const
|
|
492
|
-
|
|
501
|
+
const spaceOf = (p) => {
|
|
502
|
+
const v = scene.items[p.id]?.space;
|
|
503
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
504
|
+
};
|
|
505
|
+
const spacing = new Set([...s, ...e].map((p) => p.id));
|
|
506
|
+
const asked = [...s, ...e].reduce((sum, p) => sum + spaceOf(p), 0);
|
|
507
|
+
const share = asked > spare ? spare / asked : 1;
|
|
508
|
+
const room = (p) => spacing.has(p.id) ? spaceOf(p) * share : 0;
|
|
509
|
+
const total = (ps) => ps.reduce((sum, p) => sum + len2(p), 0) + Math.max(0, ps.length - 1) * gap;
|
|
510
|
+
const lay = (ps, from, lead) => {
|
|
493
511
|
let x = from;
|
|
494
512
|
for (const p of ps) {
|
|
513
|
+
if (lead) x += room(p);
|
|
495
514
|
out.set(p.id, x);
|
|
496
|
-
x +=
|
|
515
|
+
x += len2(p) + gap + (lead ? 0 : room(p));
|
|
497
516
|
}
|
|
498
517
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
518
|
+
const spaced = (ps) => total(ps) + ps.reduce((sum, p) => sum + room(p), 0);
|
|
519
|
+
lay(s, start, true);
|
|
520
|
+
const endStart = fit.length - end - menu - spaced(e);
|
|
521
|
+
lay(e, endStart, false);
|
|
522
|
+
const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
|
|
503
523
|
const hi = endStart - (e.length > 0 ? gap : 0);
|
|
504
|
-
const
|
|
505
|
-
const clear =
|
|
506
|
-
lay(c, title && !clear ? Math.max(
|
|
524
|
+
const mid2 = (fit.length - total(c)) / 2;
|
|
525
|
+
const clear = mid2 >= lo2 - EPS && mid2 + total(c) <= hi + EPS;
|
|
526
|
+
lay(c, title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid2, hi - total(c))), false);
|
|
507
527
|
if (title && s[s.length - 1] === title) {
|
|
508
528
|
const next = [...c, ...e].map((p) => out.get(p.id));
|
|
509
529
|
const until = next.length ? Math.min(...next) - gap : fit.length - end - menu;
|
|
510
|
-
lengths.set(title.id, Math.max(
|
|
530
|
+
lengths.set(title.id, Math.max(len2(title), until - out.get(title.id)));
|
|
511
531
|
}
|
|
512
532
|
return { starts: out, lengths };
|
|
513
533
|
}
|
|
@@ -692,8 +712,8 @@ function solveEdge(scene, edge, ids, length, room, previous) {
|
|
|
692
712
|
const size = edge.size;
|
|
693
713
|
if (typeof size === "number" && Number.isFinite(size) && hasSetter(free, formsById)) {
|
|
694
714
|
const setters = free.items.filter((p) => p.kind !== "menu" && formSetsCross(formsById(p.id)[p.form]));
|
|
695
|
-
const
|
|
696
|
-
const s = Math.min(Math.max(size,
|
|
715
|
+
const lo2 = Math.max(px(edge.cross.min), ...setters.map((p) => formCrossMin(formsById(p.id)[p.form])));
|
|
716
|
+
const s = Math.min(Math.max(size, lo2), Math.max(lo2, maxOf), room);
|
|
697
717
|
if (Math.abs(s - free.cross) > EPS) {
|
|
698
718
|
const sized = { ...input, cross: { ...cross, min: s, max: s } };
|
|
699
719
|
const stack = fitStack(sized, previous ? { previous: previous.stack } : {});
|
|
@@ -752,17 +772,17 @@ function floatFloor(item, form, orient2, size) {
|
|
|
752
772
|
}
|
|
753
773
|
function clearSize(region, avoid) {
|
|
754
774
|
const span = (axis) => {
|
|
755
|
-
const
|
|
756
|
-
const hi =
|
|
757
|
-
const
|
|
758
|
-
let a =
|
|
775
|
+
const lo2 = axis === "y" ? region.y : region.x;
|
|
776
|
+
const hi = lo2 + (axis === "y" ? region.height : region.width);
|
|
777
|
+
const mid2 = (lo2 + hi) / 2;
|
|
778
|
+
let a = lo2;
|
|
759
779
|
let b = hi;
|
|
760
780
|
for (const r of avoid) {
|
|
761
781
|
const whole = axis === "y" ? r.x <= region.x + EPS && r.x + r.width >= region.x + region.width - EPS : r.y <= region.y + EPS && r.y + r.height >= region.y + region.height - EPS;
|
|
762
782
|
const s = axis === "y" ? r.y : r.x;
|
|
763
783
|
const e = s + (axis === "y" ? r.height : r.width);
|
|
764
|
-
if (!whole || e <=
|
|
765
|
-
if (s + e <= 2 *
|
|
784
|
+
if (!whole || e <= lo2 || s >= hi) continue;
|
|
785
|
+
if (s + e <= 2 * mid2) a = Math.max(a, e);
|
|
766
786
|
else b = Math.min(b, s);
|
|
767
787
|
}
|
|
768
788
|
return Math.max(0, b - a);
|
|
@@ -854,7 +874,7 @@ function insetReach(area2, f) {
|
|
|
854
874
|
function contentNotes(d, content) {
|
|
855
875
|
const { scene, notes, previous } = d;
|
|
856
876
|
if (scene.contentMin) {
|
|
857
|
-
const minW = px(scene.contentMin.width);
|
|
877
|
+
const minW = px(scene.contentMin.width) - (d.chromeAllowance ?? 0);
|
|
858
878
|
const minH = px(scene.contentMin.height);
|
|
859
879
|
if (content.width < minW - EPS) notes.push({ code: "content-narrow", width: content.width, min: minW });
|
|
860
880
|
const bars = d.order.filter((e) => e.mode === "overlay" && !isSide(e)).reduce((s, e) => s + (d.edges[e.id]?.cross ?? 0), 0);
|
|
@@ -868,6 +888,7 @@ function contentNotes(d, content) {
|
|
|
868
888
|
}
|
|
869
889
|
|
|
870
890
|
// src/scene/solve/columns.ts
|
|
891
|
+
var isChrome = (scene, c) => !c.dyn && isSideBar(scene, c.edge);
|
|
871
892
|
function columnsOf(d, sideEdges, area2, tall) {
|
|
872
893
|
const { scene } = d;
|
|
873
894
|
return sideEdges.map((edge) => {
|
|
@@ -897,6 +918,10 @@ function giveWay(d, cols, area2, gutter) {
|
|
|
897
918
|
const { scene, previous, fresh, opened } = d;
|
|
898
919
|
const ride = scene.handFold === "ride";
|
|
899
920
|
const cmin = scene.contentMin ? px(scene.contentMin.width) : void 0;
|
|
921
|
+
const chromeWidth = scene.contentMin?.chromeWidth;
|
|
922
|
+
const floor = cmin !== void 0 && typeof chromeWidth === "number" && Number.isFinite(chromeWidth) ? Math.min(cmin, px(chromeWidth)) : void 0;
|
|
923
|
+
const chrome = floor === void 0 ? 0 : cols.filter((c) => isChrome(scene, c) && c.width > 0).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : gutter), 0);
|
|
924
|
+
if (floor !== void 0) d.chromeAllowance = Math.min(chrome, cmin - floor);
|
|
900
925
|
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));
|
|
901
926
|
const shrunkBefore = (previous?.notes ?? []).flatMap((n) => n.code === "column-shrunk" ? [n.edge] : []);
|
|
902
927
|
const rankOf = (c) => shrunkBefore.includes(c.edge.id) ? shrunkBefore.indexOf(c.edge.id) : Infinity;
|
|
@@ -911,7 +936,7 @@ function giveWay(d, cols, area2, gutter) {
|
|
|
911
936
|
let used = 0;
|
|
912
937
|
for (const [c, w] of widths) used += w > 0 ? w + (c.edge.outsideInset === true ? 0 : gutter) : 0;
|
|
913
938
|
for (const s of railSides) used += railW(s) + gutter;
|
|
914
|
-
let excess = cmin === void 0 ? -Infinity : used + cmin - area2.width;
|
|
939
|
+
let excess = cmin === void 0 ? -Infinity : floor === void 0 ? used + cmin - area2.width : Math.max(used - chrome + cmin, used + floor) - area2.width;
|
|
915
940
|
for (const c of shrinkOrder) {
|
|
916
941
|
if (excess <= EPS) break;
|
|
917
942
|
const w = widths.get(c);
|
|
@@ -970,7 +995,8 @@ function columnRoom(d, cols, area2, f) {
|
|
|
970
995
|
});
|
|
971
996
|
const colMins = open2.length > 0 ? open2 : templates;
|
|
972
997
|
if (cmin === void 0 || colMins.length === 0) return;
|
|
973
|
-
const
|
|
998
|
+
const allBars = cols.filter((c) => c.width > 0 && isChrome(scene, c)).reduce((s, c) => s + c.width + (c.edge.outsideInset === true ? 0 : f.gutter), 0);
|
|
999
|
+
const bars = d.chromeAllowance === void 0 ? allBars : allBars - Math.min(allBars, d.chromeAllowance);
|
|
974
1000
|
const width = area2.width - bars - (scene.insetWhen === "docked" && !f.docked ? px(scene.inset?.left) + px(scene.inset?.right) : 0);
|
|
975
1001
|
const need = cmin + Math.min(...colMins) + f.gutter;
|
|
976
1002
|
d.columnRoom = width >= need - EPS;
|
|
@@ -1213,14 +1239,6 @@ var LIMITS = ["min", "max", "region", "docked"];
|
|
|
1213
1239
|
var EPS2 = 0.5;
|
|
1214
1240
|
var TOUCH = 1e-3;
|
|
1215
1241
|
var fin = (v, d) => Number.isFinite(v) ? v : d;
|
|
1216
|
-
var nonNeg = (v) => Math.max(0, fin(v, 0));
|
|
1217
|
-
function floatRegion(scene) {
|
|
1218
|
-
const floating = new Set(scene.floats.map((f) => f.id));
|
|
1219
|
-
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])));
|
|
1220
|
-
const inset = scene.insetWhen === "docked" && !docked ? {} : scene.inset ?? {};
|
|
1221
|
-
const { stage } = scene;
|
|
1222
|
-
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 };
|
|
1223
|
-
}
|
|
1224
1242
|
function floatObstacles(scene, l, id) {
|
|
1225
1243
|
const out = [];
|
|
1226
1244
|
for (const [k, p] of Object.entries(l.items)) if (k !== id && !p.floating) out.push(p.rect);
|
|
@@ -1234,16 +1252,16 @@ function floatObstacles(scene, l, id) {
|
|
|
1234
1252
|
function obstacleStop(drawn, obstacles, axis, drag, span) {
|
|
1235
1253
|
const none = drag === "start" ? -Infinity : Infinity;
|
|
1236
1254
|
if (!drawn || !drag) return none;
|
|
1237
|
-
const
|
|
1238
|
-
const
|
|
1255
|
+
const lo2 = (r) => axis === "x" ? r.x : r.y;
|
|
1256
|
+
const len2 = (r) => axis === "x" ? r.width : r.height;
|
|
1239
1257
|
const across2 = (r) => axis === "x" ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
1240
1258
|
let at = none;
|
|
1241
1259
|
for (const o of obstacles) {
|
|
1242
1260
|
const [c0, c1] = across2(o);
|
|
1243
1261
|
if (c0 >= span[1] - TOUCH || c1 <= span[0] + TOUCH) continue;
|
|
1244
|
-
const begin =
|
|
1245
|
-
const finish = begin +
|
|
1246
|
-
const edge = drag === "start" ?
|
|
1262
|
+
const begin = lo2(o);
|
|
1263
|
+
const finish = begin + len2(o);
|
|
1264
|
+
const edge = drag === "start" ? lo2(drawn) : lo2(drawn) + len2(drawn);
|
|
1247
1265
|
if (drag === "start") {
|
|
1248
1266
|
if (finish <= edge + EPS2) at = Math.max(at, finish);
|
|
1249
1267
|
else if (begin < edge - TOUCH) at = edge;
|
|
@@ -1252,25 +1270,25 @@ function obstacleStop(drawn, obstacles, axis, drag, span) {
|
|
|
1252
1270
|
else if (finish > edge + TOUCH) at = edge;
|
|
1253
1271
|
}
|
|
1254
1272
|
}
|
|
1255
|
-
return drag === "start" ? Math.min(at,
|
|
1273
|
+
return drag === "start" ? Math.min(at, lo2(drawn)) : Math.max(at, lo2(drawn) + len2(drawn));
|
|
1256
1274
|
}
|
|
1257
1275
|
function fitAxis(start, length, b, drag, hit) {
|
|
1258
|
-
const { min, lo, hi, stop } = b;
|
|
1276
|
+
const { min, lo: lo2, hi, stop } = b;
|
|
1259
1277
|
const max = Math.max(min, b.max);
|
|
1260
1278
|
const raw = fin(length, min);
|
|
1261
|
-
if (min >= hi -
|
|
1279
|
+
if (min >= hi - lo2) {
|
|
1262
1280
|
hit.add("region");
|
|
1263
|
-
return [
|
|
1281
|
+
return [lo2, min];
|
|
1264
1282
|
}
|
|
1265
1283
|
const bind = (cands, pick) => {
|
|
1266
1284
|
const at = cands.reduce((m, [v]) => pick(m, v), cands[0][0]);
|
|
1267
1285
|
return [at, cands.filter(([v]) => Math.abs(v - at) <= EPS2).map(([, k]) => k)];
|
|
1268
1286
|
};
|
|
1269
1287
|
if (drag === "start") {
|
|
1270
|
-
const asked2 = fin(start,
|
|
1271
|
-
const end = Math.min(hi, Math.max(
|
|
1288
|
+
const asked2 = fin(start, lo2) + raw;
|
|
1289
|
+
const end = Math.min(hi, Math.max(lo2 + min, asked2));
|
|
1272
1290
|
if (Math.abs(end - asked2) > EPS2) hit.add("region");
|
|
1273
|
-
const [down, why2] = bind([[end - max, "max"], [
|
|
1291
|
+
const [down, why2] = bind([[end - max, "max"], [lo2, "region"], [stop, "docked"]], Math.max);
|
|
1274
1292
|
let from = end - raw;
|
|
1275
1293
|
if (from > end - min) {
|
|
1276
1294
|
from = end - min;
|
|
@@ -1281,8 +1299,8 @@ function fitAxis(start, length, b, drag, hit) {
|
|
|
1281
1299
|
}
|
|
1282
1300
|
return [from, end - from];
|
|
1283
1301
|
}
|
|
1284
|
-
const asked = fin(start,
|
|
1285
|
-
const a = Math.max(
|
|
1302
|
+
const asked = fin(start, lo2);
|
|
1303
|
+
const a = Math.max(lo2, Math.min(hi - min, asked));
|
|
1286
1304
|
if (Math.abs(a - asked) > EPS2) hit.add("region");
|
|
1287
1305
|
const [up, why] = bind([[a + max, "max"], [hi, "region"], [stop, "docked"]], Math.min);
|
|
1288
1306
|
let to = a + raw;
|
|
@@ -1341,6 +1359,19 @@ function prune(scene) {
|
|
|
1341
1359
|
const sides = new Set(gone.map((e) => e.side));
|
|
1342
1360
|
return { ...scene, edges: closeRings(scene.edges.filter((e) => !gone.includes(e)), sides) };
|
|
1343
1361
|
}
|
|
1362
|
+
function mergeSideColumns(scene) {
|
|
1363
|
+
let edges = [...scene.edges];
|
|
1364
|
+
const sides = /* @__PURE__ */ new Set();
|
|
1365
|
+
for (const side of ["left", "right"]) {
|
|
1366
|
+
const cols = edges.filter((e) => e.side === side && isSideColumn(scene, e)).sort((a, b) => a.ring - b.ring);
|
|
1367
|
+
if (cols.length < 2) continue;
|
|
1368
|
+
const [keep2, ...rest] = cols;
|
|
1369
|
+
const merged = { ...keep2, items: [...keep2.items, ...rest.flatMap((e) => e.items)] };
|
|
1370
|
+
edges = edges.filter((e) => !rest.includes(e)).map((e) => e === keep2 ? merged : e);
|
|
1371
|
+
sides.add(side);
|
|
1372
|
+
}
|
|
1373
|
+
return sides.size === 0 ? scene : { ...scene, edges: closeRings(edges, sides) };
|
|
1374
|
+
}
|
|
1344
1375
|
function lift(scene, id) {
|
|
1345
1376
|
const inEdge = scene.edges.some((e) => e.items.includes(id));
|
|
1346
1377
|
const inFloat = scene.floats.some((f) => f.id === id);
|
|
@@ -1415,7 +1446,8 @@ function moveAmong(scene, id, place, others) {
|
|
|
1415
1446
|
}
|
|
1416
1447
|
if (place.kind === "column" || place.kind === "rail") {
|
|
1417
1448
|
if (place.kind === "rail" && !scene.rails?.[place.side]?.accepts.includes(item.kind)) return scene;
|
|
1418
|
-
const
|
|
1449
|
+
const { space: _space2, ...unspaced2 } = item;
|
|
1450
|
+
const folded = place.kind === "rail" ? { ...unspaced2, from: Math.max(1, item.from ?? 0) } : unspaced2;
|
|
1419
1451
|
const made = insertColumn(withItem(lift(scene, id), folded), id, place.side, place.ring, others);
|
|
1420
1452
|
return made ?? scene;
|
|
1421
1453
|
}
|
|
@@ -1423,13 +1455,21 @@ function moveAmong(scene, id, place, others) {
|
|
|
1423
1455
|
if (!edge || edge.hidden === true || !edge.accepts.includes(item.kind)) return scene;
|
|
1424
1456
|
const zone = place.zone ?? zoneIn(edge, item);
|
|
1425
1457
|
if (!zoneTakes(edge, zone, item.kind)) return scene;
|
|
1426
|
-
const {
|
|
1427
|
-
const
|
|
1458
|
+
const { space: _space, ...unspaced } = item;
|
|
1459
|
+
const { align: _drop, ...rest } = unspaced;
|
|
1460
|
+
const kept = Number.isFinite(place.space) && place.space > 0 ? { space: place.space } : {};
|
|
1461
|
+
const moved = { ...place.zone === void 0 || !namesZone(edge, item.kind) ? unspaced : zone === "start" ? rest : { ...rest, align: zone }, ...kept };
|
|
1428
1462
|
const lifted = withItem(lift(scene, id), moved);
|
|
1429
1463
|
const target = lifted.edges.find((e) => e.id === place.edge);
|
|
1430
1464
|
if (!target) return scene;
|
|
1431
1465
|
const k = insertIndex(lifted, target, zone, place.at);
|
|
1432
|
-
|
|
1466
|
+
const placed = { ...lifted, edges: lifted.edges.map((e) => e === target ? { ...e, items: [...e.items.slice(0, k), id, ...e.items.slice(k)] } : e) };
|
|
1467
|
+
if (place.space !== void 0) return placed;
|
|
1468
|
+
const nb = zone === "start" ? target.items[k] : zone === "end" ? target.items[k - 1] : void 0;
|
|
1469
|
+
const nbItem = nb !== void 0 ? placed.items[nb] : void 0;
|
|
1470
|
+
if (!nbItem || !(nbItem.space > 0) || zoneIn(target, nbItem) !== zone) return placed;
|
|
1471
|
+
const { space: given, ...bare } = nbItem;
|
|
1472
|
+
return { ...placed, items: { ...placed.items, [nb]: bare, [id]: { ...placed.items[id], space: given } } };
|
|
1433
1473
|
}
|
|
1434
1474
|
function nextSince(scene) {
|
|
1435
1475
|
const most = scene.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
|
|
@@ -1444,7 +1484,8 @@ function floatAt(scene, id, at, orient2) {
|
|
|
1444
1484
|
const since = was ? was.since : nextSince(scene);
|
|
1445
1485
|
const seq = since !== void 0 ? { since } : {};
|
|
1446
1486
|
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 };
|
|
1447
|
-
const
|
|
1487
|
+
const { space: _space, ...unspaced } = item;
|
|
1488
|
+
const next = at && at.width > 0 && at.height > 0 ? { ...unspaced, floatSize: { width: at.width, height: at.height } } : unspaced;
|
|
1448
1489
|
const lifted = lift(withItem(scene, next), id);
|
|
1449
1490
|
return { ...lifted, floats: [...lifted.floats, float] };
|
|
1450
1491
|
}
|
|
@@ -1619,6 +1660,7 @@ function storeScene(scene) {
|
|
|
1619
1660
|
...isNum(it.from) && it.from >= 1 ? { from: Math.floor(it.from) } : {},
|
|
1620
1661
|
...it.closed ? { closed: true } : {},
|
|
1621
1662
|
...it.align === "center" || it.align === "end" ? { align: it.align } : {},
|
|
1663
|
+
...isNum(it.space) && it.space > 0 ? { space: it.space } : {},
|
|
1622
1664
|
...it.floatSize && isSize(it.floatSize.width) && isSize(it.floatSize.height) ? { floatSize: { width: it.floatSize.width, height: it.floatSize.height } } : {}
|
|
1623
1665
|
};
|
|
1624
1666
|
}
|
|
@@ -1675,9 +1717,9 @@ function read(data, base) {
|
|
|
1675
1717
|
continue;
|
|
1676
1718
|
}
|
|
1677
1719
|
const b = base.items[id];
|
|
1678
|
-
const { kept: _k, from: _f, closed: _c, align: _a, floatSize: _s, ...plain } = b;
|
|
1720
|
+
const { kept: _k, from: _f, closed: _c, align: _a, space: _sp, floatSize: _s, ...plain } = b;
|
|
1679
1721
|
let it = { ...plain, used: b.used };
|
|
1680
|
-
for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
|
|
1722
|
+
for (const k of Object.keys(s)) if (!["used", "kept", "from", "closed", "align", "space", "floatSize"].includes(k)) drop(`item:${id}:${k}`);
|
|
1681
1723
|
if (isNum(s.used)) it = { ...it, used: s.used };
|
|
1682
1724
|
else if (s.used !== void 0) drop(`item:${id}:used`);
|
|
1683
1725
|
if (s.kept === true) it = { ...it, kept: true };
|
|
@@ -1691,6 +1733,8 @@ function read(data, base) {
|
|
|
1691
1733
|
if (s.align === "center" || s.align === "end") it = { ...it, align: s.align };
|
|
1692
1734
|
else if (s.align !== void 0 && s.align !== "start") drop(`item:${id}:align`);
|
|
1693
1735
|
if (b.fixed && b.align) it = { ...it, align: b.align };
|
|
1736
|
+
if (isNum(s.space) && s.space > 0 && !b.fixed) it = { ...it, space: s.space };
|
|
1737
|
+
else if (s.space !== void 0) drop(`item:${id}:space`);
|
|
1694
1738
|
const fs = s.floatSize;
|
|
1695
1739
|
if (isObject(fs) && isSize(fs.width) && isSize(fs.height)) it = { ...it, floatSize: { width: fs.width, height: fs.height } };
|
|
1696
1740
|
else if (fs !== void 0) drop(`item:${id}:floatSize`);
|
|
@@ -1853,9 +1897,9 @@ function reservedRect(scene, l, id) {
|
|
|
1853
1897
|
const f = e ? formsOf(scene.items[id], axisOf(e.side))[it.form] : void 0;
|
|
1854
1898
|
if (!e || !f?.main.grows) return it.rect;
|
|
1855
1899
|
const column = axisOf(e.side) === "column";
|
|
1856
|
-
const
|
|
1857
|
-
const keep2 = Math.min(
|
|
1858
|
-
const shift = it.zone === "end" ?
|
|
1900
|
+
const len2 = column ? it.rect.height : it.rect.width;
|
|
1901
|
+
const keep2 = Math.min(len2, Math.max(0, Number.isFinite(f.main.natural) ? f.main.natural : len2));
|
|
1902
|
+
const shift = it.zone === "end" ? len2 - keep2 : it.zone === "center" ? (len2 - keep2) / 2 : 0;
|
|
1859
1903
|
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);
|
|
1860
1904
|
}
|
|
1861
1905
|
function slotAt(c, zone, line, id, place, lands, home = false) {
|
|
@@ -1892,7 +1936,7 @@ function zoneSpans(scene, seen, edge, reach, probe) {
|
|
|
1892
1936
|
placed.set(z, was ? [Math.min(was[0], a), Math.max(was[1], b)] : [a, b]);
|
|
1893
1937
|
declared.add(z);
|
|
1894
1938
|
}
|
|
1895
|
-
const
|
|
1939
|
+
const lo2 = (z) => placed.get(z)?.[0] ?? Infinity;
|
|
1896
1940
|
const hi = (z) => placed.get(z)?.[1] ?? -Infinity;
|
|
1897
1941
|
if (edge.zones !== void 0) {
|
|
1898
1942
|
const has = zonesOf(edge);
|
|
@@ -1900,15 +1944,22 @@ function zoneSpans(scene, seen, edge, reach, probe) {
|
|
|
1900
1944
|
return has.map((zone, i) => {
|
|
1901
1945
|
const last = i === has.length - 1;
|
|
1902
1946
|
const mark = main0 + length * (i + 1) / has.length;
|
|
1903
|
-
const b = last ? main0 + length + reach : Math.max(prev, Math.min(Math.max(mark, ...has.slice(0, i + 1).map(hi)), ...has.slice(i + 1).map(
|
|
1947
|
+
const b = last ? main0 + length + reach : Math.max(prev, Math.min(Math.max(mark, ...has.slice(0, i + 1).map(hi)), ...has.slice(i + 1).map(lo2)));
|
|
1904
1948
|
const span = { zone, a: prev, b };
|
|
1905
1949
|
prev = b;
|
|
1906
1950
|
return span;
|
|
1907
1951
|
});
|
|
1908
1952
|
}
|
|
1909
1953
|
if (thirds) {
|
|
1910
|
-
const
|
|
1911
|
-
const
|
|
1954
|
+
const nearest = scene.barZones === "nearest";
|
|
1955
|
+
const landing = (z, side) => placed.has(z) ? side === "after" ? [hi(z), hi(z)] : [lo2(z), lo2(z)] : probe(z);
|
|
1956
|
+
const between = (l, r, fallback) => {
|
|
1957
|
+
const a = landing(l, "after");
|
|
1958
|
+
const b = landing(r, "before");
|
|
1959
|
+
return nearest && a && b ? (a[1] + b[0]) / 2 : fallback;
|
|
1960
|
+
};
|
|
1961
|
+
const b1 = Math.min(Math.max(between("start", "center", main0 + length / 3), hi("start")), lo2("center"), lo2("end"));
|
|
1962
|
+
const b2 = Math.max(Math.min(between("center", "end", main0 + 2 * length / 3), lo2("end")), hi("center"), hi("start"), b1);
|
|
1912
1963
|
return [
|
|
1913
1964
|
{ zone: "start", a: main0 - reach, b: b1 },
|
|
1914
1965
|
{ zone: "center", a: b1, b: b2 },
|
|
@@ -1928,9 +1979,9 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1928
1979
|
const el = now.edges[edge.id];
|
|
1929
1980
|
const column = axisOf(edge.side) === "column";
|
|
1930
1981
|
const at = (r) => column ? r.y : r.x;
|
|
1931
|
-
const
|
|
1982
|
+
const len2 = (r) => column ? r.height : r.width;
|
|
1932
1983
|
const main0 = at(el.rect);
|
|
1933
|
-
const length =
|
|
1984
|
+
const length = len2(el.rect);
|
|
1934
1985
|
const members0 = rest.edges.find((e) => e.id === edge.id)?.items ?? [];
|
|
1935
1986
|
const slotId = (zone, k) => targetId(members0.length === 0 ? { kind: "strip", edge: edge.id, zone } : { kind: "gap", edge: edge.id, zone, at: k });
|
|
1936
1987
|
const firstKind = formsOf(scene.items[dragged], axisOf(edge.side))[0]?.kind;
|
|
@@ -1950,13 +2001,13 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1950
2001
|
});
|
|
1951
2002
|
};
|
|
1952
2003
|
const pad = { start: Math.max(0, edge.pad?.start ?? 0), end: Math.max(0, edge.pad?.end ?? 0) };
|
|
1953
|
-
const menuLen = el.menu ?
|
|
2004
|
+
const menuLen = el.menu ? len2(el.menu.rect) : 0;
|
|
1954
2005
|
const occupied = (id) => now.items[id]?.fixed ? reservedRect(scene, now, id) : now.items[id].rect;
|
|
1955
2006
|
const shown = (id) => now.items[id]?.edge === edge.id && !now.items[id].inMenu;
|
|
1956
2007
|
const drawnOf2 = (z) => members0.filter((id) => zoneOf(rest.items[id]) === z && shown(id)).map(occupied);
|
|
1957
2008
|
const startEnd = (() => {
|
|
1958
2009
|
const s = drawnOf2("start");
|
|
1959
|
-
return s.length ? at(s[s.length - 1]) +
|
|
2010
|
+
return s.length ? at(s[s.length - 1]) + len2(s[s.length - 1]) : main0 + pad.start;
|
|
1960
2011
|
})();
|
|
1961
2012
|
const endStart = (() => {
|
|
1962
2013
|
const e = drawnOf2("end");
|
|
@@ -1979,7 +2030,7 @@ function edgeSlots(c, edge, accepts) {
|
|
|
1979
2030
|
for (let k = 0; k <= members.length; k++) {
|
|
1980
2031
|
const next = members.slice(k).find(shown);
|
|
1981
2032
|
const before = members.slice(0, k).reverse().find(shown);
|
|
1982
|
-
const line = next ? at(occupied(next)) : before ? at(occupied(before)) +
|
|
2033
|
+
const line = next ? at(occupied(next)) : before ? at(occupied(before)) + len2(occupied(before)) : anchorLine[zone];
|
|
1983
2034
|
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 };
|
|
1984
2035
|
const movesFixed = members0.some((id) => {
|
|
1985
2036
|
const b = base.items[id];
|
|
@@ -2000,19 +2051,21 @@ function edgeSpec(c, edge) {
|
|
|
2000
2051
|
const data = EDGE_KINDS[edgeKind];
|
|
2001
2052
|
const column = axisOf(edge.side) === "column";
|
|
2002
2053
|
const at = (r2) => column ? r2.y : r2.x;
|
|
2003
|
-
const
|
|
2054
|
+
const len2 = (r2) => column ? r2.height : r2.width;
|
|
2004
2055
|
const empty = el.stack.items.every((p) => p.kind === "menu") && !el.menu;
|
|
2005
2056
|
const accepts = edgeTakes(edge, kind);
|
|
2006
2057
|
if (!accepts && (empty || area(el.rect) <= EPS)) return null;
|
|
2007
2058
|
if (accepts && empty && !opensEmpty(scene, edge, kind)) return null;
|
|
2008
2059
|
const ownNow = now.items[dragged];
|
|
2009
2060
|
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area(ownNow.rect) > EPS ? ownNow.rect : null;
|
|
2010
|
-
const
|
|
2011
|
-
const
|
|
2061
|
+
const oneEnd = scene.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
|
|
2062
|
+
const allSlots = edgeSlots(c, edge, accepts);
|
|
2063
|
+
const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
|
|
2064
|
+
const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
|
|
2012
2065
|
const grows = (id) => !!formsOf(scene.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
|
|
2013
2066
|
const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
|
|
2014
2067
|
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));
|
|
2015
|
-
const zones = zoneSpans(scene, now, edge, c.reach, (zone) => {
|
|
2068
|
+
const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(scene, now, edge, c.reach, (zone) => {
|
|
2016
2069
|
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
2017
2070
|
const me = s?.result.layout.items[dragged];
|
|
2018
2071
|
return me && me.edge === edge.id && me.zone === zone ? spanOf(me.rect) : null;
|
|
@@ -2079,8 +2132,8 @@ function soundness(scene, base, dragged) {
|
|
|
2079
2132
|
const e = a?.edge ? after.edges[a.edge] : void 0;
|
|
2080
2133
|
if (!a || !e || a.form !== b.form || a.formKind !== b.formKind) return false;
|
|
2081
2134
|
const f = formsOf(scene.items[id], axisOf(e.side))[a.form];
|
|
2082
|
-
const
|
|
2083
|
-
if (f &&
|
|
2135
|
+
const len2 = axisOf(e.side) === "column" ? a.rect.height : a.rect.width;
|
|
2136
|
+
if (f && len2 < formMain(f, "min", e.cross) - 0.5) return false;
|
|
2084
2137
|
}
|
|
2085
2138
|
const me = after.items[dragged];
|
|
2086
2139
|
if (!me) return true;
|
|
@@ -2129,11 +2182,11 @@ var ownedRectOf = (s) => {
|
|
|
2129
2182
|
const [a0, a1] = s.ownedAlong;
|
|
2130
2183
|
return s.vertical ? rect(b.x, a0, b.width, a1 - a0) : rect(a0, b.y, a1 - a0, b.height);
|
|
2131
2184
|
};
|
|
2132
|
-
function ownedRectsOf(s,
|
|
2133
|
-
if (
|
|
2185
|
+
function ownedRectsOf(s, along2) {
|
|
2186
|
+
if (along2.length === 0) return [];
|
|
2134
2187
|
const o = ownedRectOf(s);
|
|
2135
2188
|
if (s.ownedAlong) return [o];
|
|
2136
|
-
return
|
|
2189
|
+
return along2.map(([a, b]) => s.vertical ? rect(o.x, a, o.width, b - a) : rect(a, o.y, b - a, o.height));
|
|
2137
2190
|
}
|
|
2138
2191
|
function drawnOf(c, live) {
|
|
2139
2192
|
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) }));
|
|
@@ -2142,15 +2195,15 @@ function homeRectOf(c, ownSpec) {
|
|
|
2142
2195
|
const own = c.now.items[c.dragged];
|
|
2143
2196
|
if (!own || own.floating || !own.edge) return null;
|
|
2144
2197
|
const o = own.rect;
|
|
2145
|
-
const
|
|
2198
|
+
const hull3 = (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));
|
|
2146
2199
|
if (own.inMenu) return o;
|
|
2147
2200
|
if (!ownSpec) {
|
|
2148
2201
|
const e = c.now.edges[own.edge];
|
|
2149
2202
|
const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
|
|
2150
|
-
return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ?
|
|
2203
|
+
return e && vanishes && !e.folded && !e.rides && area(e.rect) > EPS ? hull3(o, e.rect) : o;
|
|
2151
2204
|
}
|
|
2152
2205
|
const [c0, c1] = ownSpec.across();
|
|
2153
|
-
return ownSpec.vertical ?
|
|
2206
|
+
return ownSpec.vertical ? hull3(o, rect(c0, o.y, c1 - c0, o.height)) : hull3(o, rect(o.x, c0, o.width, c1 - c0));
|
|
2154
2207
|
}
|
|
2155
2208
|
function ownersOf(c, live, drawn, alongOf) {
|
|
2156
2209
|
const ownEdge = c.now.items[c.dragged]?.edge;
|
|
@@ -2217,14 +2270,14 @@ function ownership(c, live, alongOf) {
|
|
|
2217
2270
|
};
|
|
2218
2271
|
const roomOf2 = (s) => {
|
|
2219
2272
|
const b = bandOf(s);
|
|
2220
|
-
const
|
|
2273
|
+
const along2 = (r) => s.vertical ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
2221
2274
|
const across2 = (r) => s.vertical ? [r.x, r.x + r.width] : [r.y, r.y + r.height];
|
|
2222
2275
|
const rs = taken.get(s).filter((r) => overlaps(r, b));
|
|
2223
|
-
const ends = [.../* @__PURE__ */ new Set([...
|
|
2276
|
+
const ends = [.../* @__PURE__ */ new Set([...along2(b), ...rs.flatMap(along2)])].filter((x) => x >= along2(b)[0] && x <= along2(b)[1]).sort((p, q) => p - q);
|
|
2224
2277
|
const owned = [];
|
|
2225
2278
|
for (let k = 1; k < ends.length; k++) {
|
|
2226
2279
|
const [u, w] = [ends[k - 1], ends[k]];
|
|
2227
|
-
const over = rs.filter((r) =>
|
|
2280
|
+
const over = rs.filter((r) => along2(r)[0] <= u + EPS && along2(r)[1] >= w - EPS).map(across2);
|
|
2228
2281
|
if (w - u > EPS && less([across2(b)], over).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
2229
2282
|
}
|
|
2230
2283
|
const half = s.edge ? halfBandOf(s.edge) : null;
|
|
@@ -2236,11 +2289,11 @@ function ownership(c, live, alongOf) {
|
|
|
2236
2289
|
else m.push([u, w]);
|
|
2237
2290
|
return m;
|
|
2238
2291
|
}, []);
|
|
2239
|
-
const [
|
|
2292
|
+
const [lo2, hi] = along2(b);
|
|
2240
2293
|
const placed = (p) => {
|
|
2241
2294
|
const cut2 = merged.find(([u, w]) => p >= u - EPS && p <= w + EPS);
|
|
2242
2295
|
if (!cut2) return p;
|
|
2243
|
-
const sides = [...cut2[0] >
|
|
2296
|
+
const sides = [...cut2[0] > lo2 + EPS ? [cut2[0]] : [], ...cut2[1] < hi - EPS ? [cut2[1]] : []];
|
|
2244
2297
|
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
2245
2298
|
};
|
|
2246
2299
|
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
@@ -2311,13 +2364,13 @@ var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS);
|
|
|
2311
2364
|
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
2312
2365
|
const reserved = spec.reserved;
|
|
2313
2366
|
const lines = mine.map((s) => s.line);
|
|
2314
|
-
const
|
|
2367
|
+
const lo2 = Math.min(z.a, ...lines);
|
|
2315
2368
|
const hi = Math.max(z.b, ...lines);
|
|
2316
2369
|
const free = less([[z.a, z.b]], reserved);
|
|
2317
2370
|
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
2318
2371
|
const spread = (x) => {
|
|
2319
|
-
if (hi -
|
|
2320
|
-
let d = (x -
|
|
2372
|
+
if (hi - lo2 <= EPS || freeLen <= EPS) return x;
|
|
2373
|
+
let d = (x - lo2) / (hi - lo2) * freeLen;
|
|
2321
2374
|
for (const [a, b] of free) {
|
|
2322
2375
|
if (d <= b - a + EPS) return a + Math.min(d, b - a);
|
|
2323
2376
|
d -= b - a;
|
|
@@ -2385,10 +2438,10 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2385
2438
|
continue;
|
|
2386
2439
|
}
|
|
2387
2440
|
const meet2 = (i) => {
|
|
2388
|
-
const [
|
|
2441
|
+
const [lo2, hi] = [at[i - 1], at[i]];
|
|
2389
2442
|
const between = spec.cards.filter(([u, w]) => u >= inPiece[i - 1].line - EPS && w <= inPiece[i].line + EPS);
|
|
2390
|
-
const
|
|
2391
|
-
return
|
|
2443
|
+
const mid2 = between.length === 1 ? (between[0][0] + between[0][1]) / 2 : NaN;
|
|
2444
|
+
return mid2 > lo2 + EPS && mid2 < hi - EPS ? mid2 : (lo2 + hi) / 2;
|
|
2392
2445
|
};
|
|
2393
2446
|
inPiece.forEach((s, i) => {
|
|
2394
2447
|
const p = at[i];
|
|
@@ -2549,6 +2602,7 @@ function collapsesAt(c, result, side) {
|
|
|
2549
2602
|
}
|
|
2550
2603
|
function columnLines(c, side, railLands) {
|
|
2551
2604
|
const { scene, now, dragged } = c;
|
|
2605
|
+
if (scene.sideColumns === "one" && c.rest.edges.some((e) => e.side === side && e.items.length > 0 && isSideColumn(c.rest, e))) return [];
|
|
2552
2606
|
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 }));
|
|
2553
2607
|
const own = Object.values(now.edges).filter((e) => e.side === side && e.rect.height > 0);
|
|
2554
2608
|
const span = own[0]?.rect ?? now.content;
|
|
@@ -2604,6 +2658,19 @@ function columnLines(c, side, railLands) {
|
|
|
2604
2658
|
};
|
|
2605
2659
|
});
|
|
2606
2660
|
}
|
|
2661
|
+
function railEnd(c, side, segments, y) {
|
|
2662
|
+
const { scene, rest, dragged } = c;
|
|
2663
|
+
const edge = [...segments].reverse().map((s) => rest.edges.find((e) => e.id === s.edge)).find((e) => !!e);
|
|
2664
|
+
if (!edge) return null;
|
|
2665
|
+
const at = edge.items.filter((id) => zoneOf(rest.items[id]) === "start").length;
|
|
2666
|
+
const place = { kind: "gap", edge: edge.id, zone: "start", at };
|
|
2667
|
+
const collapsed = isHandFolded(scene, dragged);
|
|
2668
|
+
const lands = ({ layout }) => {
|
|
2669
|
+
const me = layout.items[dragged];
|
|
2670
|
+
return !me.inMenu && (collapsed ? me.rail === side : me.edge === edge.id && !me.rail && !me.rides && !layout.edges[edge.id]?.folded);
|
|
2671
|
+
};
|
|
2672
|
+
return slotAt(c, "start", y, targetId(place), place, lands);
|
|
2673
|
+
}
|
|
2607
2674
|
function railStops(c, side) {
|
|
2608
2675
|
const { scene, now, dragged } = c;
|
|
2609
2676
|
const rail = now.rails[side];
|
|
@@ -2644,6 +2711,9 @@ function railStops(c, side) {
|
|
|
2644
2711
|
const shown = !!rail && rail.segments.length > 0;
|
|
2645
2712
|
const lands = (r) => shown ? collapsesAt(c, r, side) : r.layout.items[dragged].rail === side && r.scene !== c.scene;
|
|
2646
2713
|
const at = zone;
|
|
2714
|
+
const arriving = scene.foldedColumnDrop === "end" && !ownRail;
|
|
2715
|
+
const end = arriving && shown ? railEnd(c, side, rail.segments, at.y + at.height) : null;
|
|
2716
|
+
if (arriving && (shown ? !end : !isHandFolded(scene, dragged))) return null;
|
|
2647
2717
|
return {
|
|
2648
2718
|
id: virtualEdgeId("rail", side),
|
|
2649
2719
|
edge: null,
|
|
@@ -2652,7 +2722,7 @@ function railStops(c, side) {
|
|
|
2652
2722
|
lay: { phase: EDGE_KINDS.railStop.phase, side, at: -1 },
|
|
2653
2723
|
vertical: true,
|
|
2654
2724
|
zones: [{ zone: "start", a: at.y, b: at.y + at.height }],
|
|
2655
|
-
slots: stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
|
|
2725
|
+
slots: end ? [end] : stops2.map((s) => slotAt(c, "start", s.y, targetId({ kind: "rail", side, ring: s.ring }), { kind: "rail", side, ring: s.ring }, lands, ownRail)),
|
|
2656
2726
|
refuse: () => "no-room",
|
|
2657
2727
|
own: null,
|
|
2658
2728
|
holds: false,
|
|
@@ -2708,7 +2778,7 @@ var outside = (pieces, strips) => strips.reduce((acc, s) => acc.flatMap((p) => o
|
|
|
2708
2778
|
var largest2 = (rs) => rs.reduce((m, r) => r.width * r.height > m.width * m.height ? r : m);
|
|
2709
2779
|
var sameRects = (a, b) => a.length === b.length && a.every((r, i) => r.x === b[i].x && r.y === b[i].y && r.width === b[i].width && r.height === b[i].height);
|
|
2710
2780
|
function withRailStrips(c, targets2, refusals2) {
|
|
2711
|
-
const policy = railPolicyOf(c.scene, c.kind);
|
|
2781
|
+
const policy = c.scene.foldedColumnDrop === "end" ? null : railPolicyOf(c.scene, c.kind);
|
|
2712
2782
|
const strips = policy ? ["left", "right"].map((side) => c.scene.rails?.[side] ? declaredStrip(c, side, policy) : columnStrip(c, side, policy)).filter((s) => s !== null) : [];
|
|
2713
2783
|
if (!policy || strips.length === 0) return { targets: [...targets2], refusals: [...refusals2], strips: [] };
|
|
2714
2784
|
const sides = new Set(strips.map((s) => s.side));
|
|
@@ -2857,10 +2927,10 @@ var withPieces2 = (t, ps) => {
|
|
|
2857
2927
|
return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
2858
2928
|
};
|
|
2859
2929
|
function growths(r, axis, d) {
|
|
2860
|
-
const [
|
|
2930
|
+
const [lo2, 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)];
|
|
2861
2931
|
const h = d / 2;
|
|
2862
2932
|
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)];
|
|
2863
|
-
return [[
|
|
2933
|
+
return [[lo2], [hi], halves];
|
|
2864
2934
|
}
|
|
2865
2935
|
var union = (a, gs) => {
|
|
2866
2936
|
const x0 = Math.min(a.x, ...gs.map((g) => g.x));
|
|
@@ -2883,16 +2953,16 @@ function mayGrow(c, targets2, i, grow, minOf, zone, away) {
|
|
|
2883
2953
|
});
|
|
2884
2954
|
}
|
|
2885
2955
|
function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
2886
|
-
const
|
|
2956
|
+
const along2 = axis === "x" ? [l.y, l.y + l.height] : [l.x, l.x + l.width];
|
|
2887
2957
|
let best = null;
|
|
2888
2958
|
for (const [side] of growths(l, axis, d)) {
|
|
2889
2959
|
const g = side;
|
|
2890
2960
|
const strip = (a, b) => axis === "x" ? rect(g.x, a, g.width, b - a) : rect(a, g.y, b - a, g.height);
|
|
2891
|
-
const cuts = /* @__PURE__ */ new Set([
|
|
2961
|
+
const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
|
|
2892
2962
|
for (const o of targets2)
|
|
2893
2963
|
for (const p of piecesOf(o))
|
|
2894
2964
|
if (overlaps2(p, g)) {
|
|
2895
|
-
for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v >
|
|
2965
|
+
for (const v of axis === "x" ? [p.y, p.y + p.height] : [p.x, p.x + p.width]) if (v > along2[0] && v < along2[1]) cuts.add(v);
|
|
2896
2966
|
}
|
|
2897
2967
|
const marks = [...cuts].sort((a, b) => a - b);
|
|
2898
2968
|
let runStart = null;
|
|
@@ -3086,8 +3156,8 @@ function generateShown(scene, dragged, options, hidden) {
|
|
|
3086
3156
|
const { now } = c;
|
|
3087
3157
|
const live = specsOf(c, item.kind);
|
|
3088
3158
|
const alone = new Map(live.map((s) => [s, tileEdge(c, s, { cuts: [], bodies: [] }, [])]));
|
|
3089
|
-
const
|
|
3090
|
-
const own = ownership(c, live, (s) =>
|
|
3159
|
+
const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
|
|
3160
|
+
const own = ownership(c, live, (s) => along2.get(s));
|
|
3091
3161
|
const lost = [];
|
|
3092
3162
|
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost));
|
|
3093
3163
|
const ownRect = now.items[dragged];
|
|
@@ -3113,7 +3183,7 @@ function generateShown(scene, dragged, options, hidden) {
|
|
|
3113
3183
|
place: { kind: "float" },
|
|
3114
3184
|
after(point, grab) {
|
|
3115
3185
|
const g = grab ?? { x: size.width / 2, y: size.height / 2 };
|
|
3116
|
-
const raw = rect(point.x - g.x, point.y - g.y, size.width, size.height);
|
|
3186
|
+
const raw = options.floatFromHeld ? heldRect(scene, dragged, size, point, g) : rect(point.x - g.x, point.y - g.y, size.width, size.height);
|
|
3117
3187
|
const first = solve(use(floatAt(scene, dragged, raw, options.floatOrient), dragged), prev);
|
|
3118
3188
|
const at = first.items[dragged]?.rect ?? raw;
|
|
3119
3189
|
return c.settle(use(floatAt(scene, dragged, rect(at.x, at.y, size.width, size.height), options.floatOrient), dragged));
|
|
@@ -3148,6 +3218,10 @@ var stageOf = (scene) => rect(scene.stage.x, scene.stage.y, scene.stage.width, s
|
|
|
3148
3218
|
function targets(scene, dragged, options = {}) {
|
|
3149
3219
|
return generate(scene, dragged, options).targets;
|
|
3150
3220
|
}
|
|
3221
|
+
function targetsAndRefusals(scene, dragged, options = {}) {
|
|
3222
|
+
const g = generate(scene, dragged, options);
|
|
3223
|
+
return { targets: g.targets, refusals: g.refusals };
|
|
3224
|
+
}
|
|
3151
3225
|
function refusals(scene, dragged, options = {}) {
|
|
3152
3226
|
return generate(scene, dragged, options).refusals;
|
|
3153
3227
|
}
|
|
@@ -3157,12 +3231,12 @@ function refusalTargets(list) {
|
|
|
3157
3231
|
var SIDE_RANK = { left: 0, top: 1, bottom: 2, right: 3 };
|
|
3158
3232
|
function stops(scene, dragged, options = {}) {
|
|
3159
3233
|
const key = stopsKey(dragged, options);
|
|
3160
|
-
let
|
|
3161
|
-
if (!
|
|
3162
|
-
let list =
|
|
3234
|
+
let memo2 = stopsMemo.get(scene);
|
|
3235
|
+
if (!memo2) stopsMemo.set(scene, memo2 = /* @__PURE__ */ new Map());
|
|
3236
|
+
let list = memo2.get(key);
|
|
3163
3237
|
if (!list) {
|
|
3164
|
-
if (
|
|
3165
|
-
|
|
3238
|
+
if (memo2.size >= STOPS_PER_SCENE) memo2.clear();
|
|
3239
|
+
memo2.set(key, list = orderedStops(scene, dragged, options));
|
|
3166
3240
|
}
|
|
3167
3241
|
return [...list];
|
|
3168
3242
|
}
|
|
@@ -3198,6 +3272,270 @@ function orderedStops(scene, dragged, options) {
|
|
|
3198
3272
|
return list.map((t, i) => ({ t, i, k: key(t) })).sort((a, b) => a.k[0] - b.k[0] || a.k[1] - b.k[1] || a.k[2] - b.k[2] || a.i - b.i).map((x) => x.t);
|
|
3199
3273
|
}
|
|
3200
3274
|
|
|
3275
|
+
// src/scene/lanes.ts
|
|
3276
|
+
var SPOT_PITCH = 40;
|
|
3277
|
+
var mid = (r, axis) => axis === "x" ? r.x + r.width / 2 : r.y + r.height / 2;
|
|
3278
|
+
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
3279
|
+
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
3280
|
+
var hull2 = (a, b) => {
|
|
3281
|
+
const x = Math.min(a.x, b.x);
|
|
3282
|
+
const y = Math.min(a.y, b.y);
|
|
3283
|
+
return rect(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
|
|
3284
|
+
};
|
|
3285
|
+
var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
3286
|
+
var sameRect = (a, b) => Math.max(Math.abs(a.x - b.x), Math.abs(a.y - b.y), Math.abs(a.width - b.width), Math.abs(a.height - b.height)) < 0.5;
|
|
3287
|
+
var ORIGIN = { x: 0, y: 0 };
|
|
3288
|
+
function onEdge(l, edge, dragged, axis) {
|
|
3289
|
+
return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS && it.rect.height > EPS).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
|
|
3290
|
+
}
|
|
3291
|
+
function neighbors(after, edge, dragged, axis) {
|
|
3292
|
+
const me = after.items[dragged];
|
|
3293
|
+
const others = onEdge(after, edge, dragged, axis);
|
|
3294
|
+
const at = me ? mid(me.rect, axis) : 0;
|
|
3295
|
+
return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
|
|
3296
|
+
}
|
|
3297
|
+
function othersKey(layout, dragged) {
|
|
3298
|
+
return Object.keys(layout.items).filter((id) => id !== dragged).sort().map((id) => {
|
|
3299
|
+
const it = layout.items[id];
|
|
3300
|
+
return it.inMenu ? `${id}:m` : `${id}:${Math.round(it.rect.x)},${Math.round(it.rect.y)},${Math.round(it.rect.width)},${Math.round(it.rect.height)}`;
|
|
3301
|
+
}).join(";");
|
|
3302
|
+
}
|
|
3303
|
+
var memo = /* @__PURE__ */ new WeakMap();
|
|
3304
|
+
var previousIds = /* @__PURE__ */ new WeakMap();
|
|
3305
|
+
var nextPrevious = 1;
|
|
3306
|
+
function keyOf(dragged, o) {
|
|
3307
|
+
const { previous, spot: _spot, ...rest } = o;
|
|
3308
|
+
let p = 0;
|
|
3309
|
+
if (previous) {
|
|
3310
|
+
if (!previousIds.has(previous)) previousIds.set(previous, nextPrevious++);
|
|
3311
|
+
p = previousIds.get(previous);
|
|
3312
|
+
}
|
|
3313
|
+
return `${dragged}\0${p}\0${JSON.stringify(rest)}`;
|
|
3314
|
+
}
|
|
3315
|
+
function lanes(scene, dragged, options = {}) {
|
|
3316
|
+
const key = keyOf(dragged, options);
|
|
3317
|
+
let perScene = memo.get(scene);
|
|
3318
|
+
if (!perScene) memo.set(scene, perScene = /* @__PURE__ */ new Map());
|
|
3319
|
+
let base = perScene.get(key);
|
|
3320
|
+
if (!base) perScene.set(key, base = build(scene, dragged, options));
|
|
3321
|
+
if (!options.spot) return { ...base.regions, lanes: base.lanes };
|
|
3322
|
+
const found = [...base.raws].find(([, rs]) => rs.some((r) => r.id === options.spot));
|
|
3323
|
+
if (!found) return { ...base.regions, lanes: base.lanes };
|
|
3324
|
+
const [heldLane, list] = found;
|
|
3325
|
+
const held = list.find((r) => r.id === options.spot);
|
|
3326
|
+
const lane = laneFrom(heldLane, list, held.layout, base.seen, dragged, base.refusals, base.halves.has(heldLane));
|
|
3327
|
+
return { ...base.regions, lanes: base.lanes.map((l) => l.id === heldLane && lane ? lane : l) };
|
|
3328
|
+
}
|
|
3329
|
+
function build(scene, dragged, options) {
|
|
3330
|
+
const seen = solve(scene, options.previous ? { previous: options.previous } : {});
|
|
3331
|
+
const { targets: ts, refusals: rs } = targetsAndRefusals(scene, dragged, options);
|
|
3332
|
+
const own = seen.items[dragged];
|
|
3333
|
+
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
3334
|
+
const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
|
|
3335
|
+
const raws = [];
|
|
3336
|
+
const axisOfEdge = (id) => {
|
|
3337
|
+
const e = scene.edges.find((x) => x.id === id);
|
|
3338
|
+
return e && axisOf(e.side) === "column" ? "y" : "x";
|
|
3339
|
+
};
|
|
3340
|
+
const columnKey = (side, ring) => scene.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
|
|
3341
|
+
for (const t of ts) {
|
|
3342
|
+
if (t.free) continue;
|
|
3343
|
+
const p = t.place;
|
|
3344
|
+
if (p.kind === "gap" || p.kind === "home" && ownEdge) {
|
|
3345
|
+
const edge = p.kind === "gap" ? p.edge : ownEdge;
|
|
3346
|
+
const axis = axisOfEdge(edge);
|
|
3347
|
+
const layout = p.kind === "home" ? seen : t.after(ORIGIN, ORIGIN).layout;
|
|
3348
|
+
const landing = p.kind === "home" ? own.rect : layout.items[dragged]?.rect;
|
|
3349
|
+
if (!landing) continue;
|
|
3350
|
+
const zone = p.kind === "gap" ? p.zone : own?.zone ?? "start";
|
|
3351
|
+
const n = neighbors(layout, edge, dragged, axis);
|
|
3352
|
+
const id = n.before === "^" && n.next === "$" ? `${edge}/${zone}` : `${edge}/${zone}/${n.before}|${n.next}`;
|
|
3353
|
+
raws.push({ lane: edge, edge, axis, id, ...n, landing, layout, target: t, hit: t.hit, ...p.kind === "home" ? { home: true } : {} });
|
|
3354
|
+
} else if (p.kind === "column" || p.kind === "rail") {
|
|
3355
|
+
const layout = t.after(ORIGIN, ORIGIN).layout;
|
|
3356
|
+
const landing = layout.items[dragged]?.rect;
|
|
3357
|
+
if (!landing) continue;
|
|
3358
|
+
const lane = p.kind === "column" ? `column:${p.side}:${columnKey(p.side, p.ring)}` : `rail:${p.side}`;
|
|
3359
|
+
raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: t.hit });
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, raws, pitch));
|
|
3363
|
+
const byLane = /* @__PURE__ */ new Map();
|
|
3364
|
+
for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
|
|
3365
|
+
const halves = new Set(scene.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
|
|
3366
|
+
const laneList = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id))).filter((l) => !!l);
|
|
3367
|
+
const onLanes = new Set(laneList.map((l) => l.id));
|
|
3368
|
+
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS && r.rect.height > EPS ? [r.rect] : []);
|
|
3369
|
+
const blocked = [
|
|
3370
|
+
...Object.values(seen.edges).filter((e) => e.cross > EPS).map((e) => e.rect),
|
|
3371
|
+
...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
|
|
3372
|
+
...chromeFor(scene, "targets"),
|
|
3373
|
+
...rails,
|
|
3374
|
+
// Spots where a release cancels (`Scene.blocked`): no float lands there.
|
|
3375
|
+
...scene.blocked ?? []
|
|
3376
|
+
];
|
|
3377
|
+
return {
|
|
3378
|
+
raws: byLane,
|
|
3379
|
+
lanes: laneList,
|
|
3380
|
+
seen,
|
|
3381
|
+
refusals: rs,
|
|
3382
|
+
halves,
|
|
3383
|
+
regions: {
|
|
3384
|
+
refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
|
|
3385
|
+
content: seen.content,
|
|
3386
|
+
blocked,
|
|
3387
|
+
stage: scene.stage,
|
|
3388
|
+
floatRegion: floatRegion(scene, dragged),
|
|
3389
|
+
item: own ? { width: own.rect.width, height: own.rect.height } : { width: 0, height: 0 },
|
|
3390
|
+
float: ts.find((t) => t.free) ?? null,
|
|
3391
|
+
refusals: rs
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
}
|
|
3395
|
+
function laneFrom(id, list, drawn, seen, dragged, rs, halves) {
|
|
3396
|
+
if (list.length === 0) return null;
|
|
3397
|
+
const first = list[0];
|
|
3398
|
+
const axis = first.axis;
|
|
3399
|
+
const edgeLayout = first.edge ? seen.edges[first.edge] : void 0;
|
|
3400
|
+
const band = list.map((r) => r.landing).reduce(hull2);
|
|
3401
|
+
let laneRect;
|
|
3402
|
+
if (edgeLayout && edgeLayout.cross > EPS) laneRect = edgeLayout.rect;
|
|
3403
|
+
else if (edgeLayout) laneRect = axis === "x" ? rect(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
|
|
3404
|
+
else laneRect = list.map((r) => r.hit).reduce(hull2, band);
|
|
3405
|
+
const sorted = [...list].sort((a, b) => mid(a.landing, axis) - mid(b.landing, axis) || (a.home ? -1 : b.home ? 1 : 0));
|
|
3406
|
+
const unique = sorted.filter((x, i) => !sorted.slice(0, i).some((y) => sameRect(y.landing, x.landing) || y.id === x.id));
|
|
3407
|
+
const start = lo(laneRect, axis);
|
|
3408
|
+
const end = start + len(laneRect, axis);
|
|
3409
|
+
const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
|
|
3410
|
+
const cuts = [];
|
|
3411
|
+
for (let i = 0; i + 1 < unique.length; i++) {
|
|
3412
|
+
const a = unique[i];
|
|
3413
|
+
const b = unique[i + 1];
|
|
3414
|
+
const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
|
|
3415
|
+
const raw = shared ? mid(shared, axis) : (lo(a.landing, axis) + len(a.landing, axis) + lo(b.landing, axis)) / 2;
|
|
3416
|
+
cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? start), start, end));
|
|
3417
|
+
}
|
|
3418
|
+
const spots = unique.map((x, i) => ({
|
|
3419
|
+
id: x.id,
|
|
3420
|
+
along: [i === 0 ? start : cuts[i - 1], i === unique.length - 1 ? end : cuts[i]],
|
|
3421
|
+
landing: x.landing,
|
|
3422
|
+
target: x.target,
|
|
3423
|
+
...x.home ? { home: true } : {},
|
|
3424
|
+
...x.pitched ? { pitched: true } : {},
|
|
3425
|
+
others: othersKey(x.layout, dragged)
|
|
3426
|
+
}));
|
|
3427
|
+
const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
|
|
3428
|
+
const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp(lo(h, axis), start, end), clamp(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS) : [];
|
|
3429
|
+
const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
|
|
3430
|
+
const marks = first.edge ? edgeMarks(id, laneRect, axis, onEdge(drawn, first.edge, "", axis), refused, itemLen, (pair) => places.has(pair) || pair.split("|").includes(dragged), dragged) : virtualMarks(id, unique, drawn.items[dragged]);
|
|
3431
|
+
return { id, rect: laneRect, axis, spots, refused, marks };
|
|
3432
|
+
}
|
|
3433
|
+
var along = (r, axis, a, b) => axis === "x" ? rect(a, r.y, b - a, r.height) : rect(r.x, a, r.width, b - a);
|
|
3434
|
+
var LINE2 = 2;
|
|
3435
|
+
function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held) {
|
|
3436
|
+
const out = [];
|
|
3437
|
+
const start = lo(laneRect, axis);
|
|
3438
|
+
const end = start + len(laneRect, axis);
|
|
3439
|
+
const ends = [{ id: "^", a: start, b: start }, ...items.map((o) => ({ id: o.id, a: lo(o.r, axis), b: lo(o.r, axis) + len(o.r, axis) })), { id: "$", a: end, b: end }];
|
|
3440
|
+
const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
|
|
3441
|
+
for (let i = 0; i + 1 < ends.length; i++) {
|
|
3442
|
+
const a = clamp(ends[i].b, start, end);
|
|
3443
|
+
const b = clamp(ends[i + 1].a, start, end);
|
|
3444
|
+
const pair = `${ends[i].id}|${ends[i + 1].id}`;
|
|
3445
|
+
if (ends[i + 1].a < start - EPS || ends[i].b > end + EPS || !lands(pair)) continue;
|
|
3446
|
+
const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
|
|
3447
|
+
const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
|
|
3448
|
+
const named = `${left}|${right}`;
|
|
3449
|
+
if (b - a < itemLen - EPS) {
|
|
3450
|
+
const t = Math.max(0, Math.min(LINE2, b - a)) / 2;
|
|
3451
|
+
if (items.length > 0 && named === pair && !isRefused2((a + b) / 2)) out.push({ id: `${lane}/line/${pair}`, kind: "line", rect: along(laneRect, axis, (a + b) / 2 - t, (a + b) / 2 + t) });
|
|
3452
|
+
continue;
|
|
3453
|
+
}
|
|
3454
|
+
let pieces = [[a, b]];
|
|
3455
|
+
for (const f of refused) pieces = pieces.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]).filter(([p, q]) => q - p > EPS);
|
|
3456
|
+
let k = 0;
|
|
3457
|
+
for (const [p, q] of pieces) {
|
|
3458
|
+
if (q - p < itemLen - EPS) continue;
|
|
3459
|
+
const base = `${lane}/box/${named}${k++ ? `#${k - 1}` : ""}`;
|
|
3460
|
+
out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
return out;
|
|
3464
|
+
}
|
|
3465
|
+
function virtualMarks(lane, spots, held) {
|
|
3466
|
+
return spots.map((s) => {
|
|
3467
|
+
const l = s.landing;
|
|
3468
|
+
if (!held || held.floating || !overlaps3(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
|
|
3469
|
+
const x = mid(held.rect, "x") < mid(l, "x") ? l.x + l.width : l.x;
|
|
3470
|
+
return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect(x, l.y, 0, l.height) };
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
var overlaps3 = (a, b) => a.x < b.x + b.width - EPS && b.x < a.x + a.width - EPS && a.y < b.y + b.height - EPS && b.y < a.y + a.height - EPS;
|
|
3474
|
+
function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
|
|
3475
|
+
const out = [];
|
|
3476
|
+
if (!scene.items[dragged]) return out;
|
|
3477
|
+
const prev = options.previous ? { previous: options.previous } : {};
|
|
3478
|
+
for (const e of scene.edges) {
|
|
3479
|
+
const bar = e.side === "top" || e.side === "bottom";
|
|
3480
|
+
if (!bar && !e.compact) continue;
|
|
3481
|
+
const axis = bar ? "x" : "y";
|
|
3482
|
+
const mine = raws.filter((r) => r.edge === e.id);
|
|
3483
|
+
const drawn = seen.edges[e.id];
|
|
3484
|
+
if (mine.length === 0 || !drawn) continue;
|
|
3485
|
+
const w = len(mine[0].landing, axis);
|
|
3486
|
+
const gap = nonNeg(e.gap);
|
|
3487
|
+
const others = onEdge(seen, e.id, dragged, axis);
|
|
3488
|
+
const edgeStart = lo(drawn.rect, axis) + nonNeg(e.pad?.start);
|
|
3489
|
+
const edgeEnd = lo(drawn.rect, axis) + len(drawn.rect, axis) - nonNeg(e.pad?.end);
|
|
3490
|
+
const middle = mid(drawn.rect, axis);
|
|
3491
|
+
const zoneOf2 = (o) => o.zone ?? "start";
|
|
3492
|
+
const taken = mine.map((r) => r.landing);
|
|
3493
|
+
const emit3 = (zone, at, space, x0) => {
|
|
3494
|
+
const place = { edge: e.id, zone, at, space };
|
|
3495
|
+
const next = moveTo(scene, dragged, place);
|
|
3496
|
+
if (next === scene) return;
|
|
3497
|
+
const layout = solve(next, prev);
|
|
3498
|
+
const landed = layout.items[dragged];
|
|
3499
|
+
if (!landed || landed.inMenu || landed.edge !== e.id || x0 !== void 0 && Math.abs(lo(landed.rect, axis) - x0) > 1) return;
|
|
3500
|
+
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return;
|
|
3501
|
+
taken.push(landed.rect);
|
|
3502
|
+
const result = { scene: next, layout };
|
|
3503
|
+
const target = { id: `pitch:${e.id}:${zone}:${at}:${Math.round(space)}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
|
|
3504
|
+
const n = neighbors(layout, e.id, dragged, axis);
|
|
3505
|
+
const id = `${e.id}/${zone}/${n.before}|${n.next}@${Math.round(space / pitch)}`;
|
|
3506
|
+
out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
|
|
3507
|
+
};
|
|
3508
|
+
const spaced = (o) => !!o && (scene.items[o.id]?.space ?? 0) > 0;
|
|
3509
|
+
const own = scene.items[dragged];
|
|
3510
|
+
if (own && (own.space ?? 0) > 0 && seen.items[dragged]?.edge === e.id) {
|
|
3511
|
+
const zone = zoneIn(e, own);
|
|
3512
|
+
if (zone === "start") emit3("start", 0, 0);
|
|
3513
|
+
else if (zone === "end") emit3("end", others.filter((o) => zoneOf2(o) === "end").length, 0);
|
|
3514
|
+
}
|
|
3515
|
+
const slack = (o) => {
|
|
3516
|
+
const main = o ? scene.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
|
|
3517
|
+
return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
|
|
3518
|
+
};
|
|
3519
|
+
for (let i = 0; i <= others.length; i++) {
|
|
3520
|
+
const before = others[i - 1];
|
|
3521
|
+
const after = others[i];
|
|
3522
|
+
const a = before ? lo(before.r, axis) + len(before.r, axis) - slack(before) + gap : edgeStart;
|
|
3523
|
+
const b = after ? lo(after.r, axis) - gap : edgeEnd;
|
|
3524
|
+
if (spaced(after) && zoneOf2(after) === "start" && (!before || zoneOf2(before) === "start")) emit3("start", others.filter((o) => zoneOf2(o) === "start" && lo(o.r, axis) < lo(after.r, axis)).length, 0);
|
|
3525
|
+
if (spaced(before) && zoneOf2(before) === "end" && (!after || zoneOf2(after) === "end")) emit3("end", others.filter((o) => zoneOf2(o) === "end" && lo(o.r, axis) <= lo(before.r, axis)).length, 0);
|
|
3526
|
+
if (b - a < w + pitch) continue;
|
|
3527
|
+
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS; x0 += pitch) {
|
|
3528
|
+
const toStart = x0 + w / 2 < middle;
|
|
3529
|
+
if (toStart && before && zoneOf2(before) !== "start") continue;
|
|
3530
|
+
if (!toStart && after && zoneOf2(after) !== "end") continue;
|
|
3531
|
+
const zone = toStart ? "start" : "end";
|
|
3532
|
+
emit3(zone, others.filter((o) => zoneOf2(o) === zone && lo(o.r, axis) < x0).length, toStart ? x0 - a : b - (x0 + w), x0);
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
return out;
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3201
3539
|
export {
|
|
3202
3540
|
SIDES,
|
|
3203
3541
|
ZONES,
|
|
@@ -3210,6 +3548,7 @@ export {
|
|
|
3210
3548
|
DEFAULT_STRIP,
|
|
3211
3549
|
DEFAULT_HIT_BAND,
|
|
3212
3550
|
DEFAULT_FLOAT_SIZE,
|
|
3551
|
+
heldRect,
|
|
3213
3552
|
anchorName,
|
|
3214
3553
|
zoneTakes,
|
|
3215
3554
|
zonesTaking,
|
|
@@ -3219,6 +3558,7 @@ export {
|
|
|
3219
3558
|
namesZone,
|
|
3220
3559
|
isOutsideSideBar,
|
|
3221
3560
|
isSideBar,
|
|
3561
|
+
isSideColumn,
|
|
3222
3562
|
floatOrientOf,
|
|
3223
3563
|
floatSizeOf,
|
|
3224
3564
|
targetId,
|
|
@@ -3227,6 +3567,7 @@ export {
|
|
|
3227
3567
|
placeTargetId,
|
|
3228
3568
|
solve,
|
|
3229
3569
|
fitResize,
|
|
3570
|
+
mergeSideColumns,
|
|
3230
3571
|
lift,
|
|
3231
3572
|
moveTo,
|
|
3232
3573
|
floatAt,
|
|
@@ -3249,6 +3590,8 @@ export {
|
|
|
3249
3590
|
targets,
|
|
3250
3591
|
refusals,
|
|
3251
3592
|
refusalTargets,
|
|
3252
|
-
stops
|
|
3593
|
+
stops,
|
|
3594
|
+
SPOT_PITCH,
|
|
3595
|
+
lanes
|
|
3253
3596
|
};
|
|
3254
|
-
//# sourceMappingURL=chunk-
|
|
3597
|
+
//# sourceMappingURL=chunk-6IHRZ3NP.js.map
|