@n-uf/placement 26.11.48 → 26.11.50
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 +64 -0
- package/README.md +23 -1702
- package/dist/{chunk-IDWMDPY7.js → chunk-NM4ADJC2.js} +267 -61
- package/dist/chunk-NM4ADJC2.js.map +1 -0
- package/dist/{chunk-GIBUM6TB.js → chunk-TWI644JK.js} +1 -1
- package/dist/chunk-TWI644JK.js.map +1 -0
- package/dist/desk.d.ts +2 -0
- package/dist/desk.js.map +1 -1
- package/dist/{lanes-BcglySmh.d.ts → lanes-CkFz9E5l.d.ts} +69 -10
- package/dist/scene-cases.d.ts +13 -2
- package/dist/scene-cases.js +30 -5
- package/dist/scene-cases.js.map +1 -1
- package/dist/scene.d.ts +2 -2
- package/dist/scene.js +1 -1
- package/dist/targets.js +1 -1
- package/dist/toolbar.d.ts +2 -0
- package/dist/toolbar.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-GIBUM6TB.js.map +0 -1
- package/dist/chunk-IDWMDPY7.js.map +0 -1
|
@@ -1376,12 +1376,42 @@ function lift(scene, id) {
|
|
|
1376
1376
|
const inEdge = scene.edges.some((e) => e.items.includes(id));
|
|
1377
1377
|
const inFloat = scene.floats.some((f) => f.id === id);
|
|
1378
1378
|
if (!inEdge && !inFloat) return scene;
|
|
1379
|
+
let s = scene;
|
|
1380
|
+
const from = scene.edges.find((e) => e.items.includes(id));
|
|
1381
|
+
const owner = from ? roomOwner(scene, from, from.items.indexOf(id)) : void 0;
|
|
1382
|
+
if (from && owner) {
|
|
1383
|
+
const length = lengthOn(scene, from, id);
|
|
1384
|
+
if (length > 0) s = withSpace(s, owner, (scene.items[owner].space ?? 0) + (scene.items[id]?.space ?? 0) + length + nonNegative(from.gap));
|
|
1385
|
+
}
|
|
1379
1386
|
return prune({
|
|
1380
|
-
...
|
|
1381
|
-
edges: inEdge ?
|
|
1382
|
-
floats: inFloat ?
|
|
1387
|
+
...s,
|
|
1388
|
+
edges: inEdge ? s.edges.map((e) => e.items.includes(id) ? { ...e, items: e.items.filter((x) => x !== id) } : e) : s.edges,
|
|
1389
|
+
floats: inFloat ? s.floats.filter((f) => f.id !== id) : s.floats
|
|
1383
1390
|
});
|
|
1384
1391
|
}
|
|
1392
|
+
function roomOwner(scene, edge, k) {
|
|
1393
|
+
const id = edge.items[k];
|
|
1394
|
+
if (id === void 0) return void 0;
|
|
1395
|
+
const zone = zoneAt(scene, edge, id);
|
|
1396
|
+
if (zone === "center") return void 0;
|
|
1397
|
+
const step = zone === "start" ? 1 : -1;
|
|
1398
|
+
for (let j = k + step; j >= 0 && j < edge.items.length; j += step) {
|
|
1399
|
+
const nb = edge.items[j];
|
|
1400
|
+
if (zoneAt(scene, edge, nb) !== zone || scene.items[nb]?.closed) continue;
|
|
1401
|
+
if ((scene.items[nb]?.space ?? 0) > 0) return nb;
|
|
1402
|
+
}
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1405
|
+
function lengthOn(scene, edge, id) {
|
|
1406
|
+
const it = solve(scene).items[id];
|
|
1407
|
+
if (!it || it.inMenu || it.edge !== edge.id) return 0;
|
|
1408
|
+
return axisOf(edge.side) === "column" ? it.rect.height : it.rect.width;
|
|
1409
|
+
}
|
|
1410
|
+
var nonNegative = (n) => Number.isFinite(n) && n > 0 ? n : 0;
|
|
1411
|
+
function withSpace(scene, id, space) {
|
|
1412
|
+
const { space: _old, ...bare } = scene.items[id];
|
|
1413
|
+
return { ...scene, items: { ...scene.items, [id]: space > 1e-6 ? { ...bare, space } : bare } };
|
|
1414
|
+
}
|
|
1385
1415
|
function newColumn(scene, side, kind, ring, items, others) {
|
|
1386
1416
|
const t = scene.columns?.[side];
|
|
1387
1417
|
if (!t || !t.accepts.includes(kind)) return null;
|
|
@@ -1463,13 +1493,14 @@ function moveAmong(scene, id, place, others) {
|
|
|
1463
1493
|
const target = lifted.edges.find((e) => e.id === place.edge);
|
|
1464
1494
|
if (!target) return scene;
|
|
1465
1495
|
const k = insertIndex(lifted, target, zone, place.at);
|
|
1466
|
-
const
|
|
1467
|
-
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1496
|
+
const into = { ...target, items: [...target.items.slice(0, k), id, ...target.items.slice(k)] };
|
|
1497
|
+
const placed = { ...lifted, edges: lifted.edges.map((e) => e === target ? into : e) };
|
|
1498
|
+
const owner = roomOwner(placed, into, k);
|
|
1499
|
+
if (!owner) return placed;
|
|
1500
|
+
const length = lengthOn(placed, into, id);
|
|
1501
|
+
if (length <= 0) return placed;
|
|
1502
|
+
const room = placed.items[owner].space ?? 0;
|
|
1503
|
+
return withSpace(placed, owner, room - (placed.items[id].space ?? 0) - length - nonNegative(into.gap));
|
|
1473
1504
|
}
|
|
1474
1505
|
function nextSince(scene) {
|
|
1475
1506
|
const most = scene.floats.reduce((m, f) => Math.max(m, isSince(f.since) ? f.since : 0), 0);
|
|
@@ -1486,7 +1517,7 @@ function floatAt(scene, id, at, orient2) {
|
|
|
1486
1517
|
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 };
|
|
1487
1518
|
const { space: _space, ...unspaced } = item;
|
|
1488
1519
|
const next = at && at.width > 0 && at.height > 0 ? { ...unspaced, floatSize: { width: at.width, height: at.height } } : unspaced;
|
|
1489
|
-
const lifted = lift(
|
|
1520
|
+
const lifted = withItem(lift(scene, id), next);
|
|
1490
1521
|
return { ...lifted, floats: [...lifted.floats, float] };
|
|
1491
1522
|
}
|
|
1492
1523
|
function canFold(scene, id) {
|
|
@@ -3274,6 +3305,8 @@ function orderedStops(scene, dragged, options) {
|
|
|
3274
3305
|
|
|
3275
3306
|
// src/scene/lanes.ts
|
|
3276
3307
|
var SPOT_PITCH = 40;
|
|
3308
|
+
var SNAP_DISTANCE = 8;
|
|
3309
|
+
var STEP = 1;
|
|
3277
3310
|
var mid = (r, axis) => axis === "x" ? r.x + r.width / 2 : r.y + r.height / 2;
|
|
3278
3311
|
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
3279
3312
|
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
@@ -3326,7 +3359,7 @@ function lanes(scene, dragged, options = {}) {
|
|
|
3326
3359
|
const rebuilt = base.lanes.map((l) => {
|
|
3327
3360
|
const raws = base.raws.get(l.id);
|
|
3328
3361
|
if (!raws) return l;
|
|
3329
|
-
const again = laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, l.id === heldLane);
|
|
3362
|
+
const again = laneFrom(l.id, raws, held.layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.share, base.marking, l.id === heldLane && !held.slide);
|
|
3330
3363
|
if (!again) return l;
|
|
3331
3364
|
return l.id === heldLane ? again : { ...l, marks: again.marks };
|
|
3332
3365
|
});
|
|
@@ -3366,7 +3399,12 @@ function build(scene, dragged, options) {
|
|
|
3366
3399
|
raws.push({ lane, edge: null, axis: "y", id: `${lane}/${p.kind === "rail" ? "end" : "line"}`, before: "^", next: "$", landing, layout, target: t, hit: strip ?? t.hit, ...strip ? { strip: true } : {} });
|
|
3367
3400
|
}
|
|
3368
3401
|
}
|
|
3369
|
-
if (
|
|
3402
|
+
if (options.stretchPositions !== "pitched") {
|
|
3403
|
+
const { spots, absorbed } = slidingSpots(scene, dragged, options, seen, raws, pitch > 0 ? pitch : SPOT_PITCH);
|
|
3404
|
+
for (let i = raws.length - 1; i >= 0; i--) if (absorbed.has(raws[i])) raws.splice(i, 1);
|
|
3405
|
+
raws.push(...spots);
|
|
3406
|
+
} else if (pitch > 0) raws.push(...pitchedSpots(scene, dragged, options, seen, raws, pitch));
|
|
3407
|
+
raws.push(...takeoverSpots(scene, dragged, options, seen, raws, pitch > 0 ? pitch : SPOT_PITCH));
|
|
3370
3408
|
const byLane = /* @__PURE__ */ new Map();
|
|
3371
3409
|
for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
|
|
3372
3410
|
const halves = new Set(scene.edges.filter((e) => (e.side === "left" || e.side === "right") && !e.compact).map((e) => e.id));
|
|
@@ -3404,7 +3442,7 @@ function build(scene, dragged, options) {
|
|
|
3404
3442
|
marking,
|
|
3405
3443
|
regions: {
|
|
3406
3444
|
refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
|
|
3407
|
-
content:
|
|
3445
|
+
content: floatRegion(scene, dragged),
|
|
3408
3446
|
blocked,
|
|
3409
3447
|
stage: scene.stage,
|
|
3410
3448
|
floatRegion: floatRegion(scene, dragged),
|
|
@@ -3425,10 +3463,12 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
|
|
|
3425
3463
|
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);
|
|
3426
3464
|
else if (list.every((r) => r.strip)) laneRect = list.map((r) => r.hit).reduce(hull2);
|
|
3427
3465
|
else laneRect = list.map((r) => r.hit).reduce(hull2, band);
|
|
3428
|
-
const
|
|
3466
|
+
const firstOf = (r) => r.slide?.first ?? r.landing;
|
|
3467
|
+
const lastOf = (r) => r.slide?.last ?? r.landing;
|
|
3468
|
+
const sorted = [...list].sort((a, b) => mid(firstOf(a), axis) - mid(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0));
|
|
3429
3469
|
const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
|
|
3430
|
-
const nearHome = (r) => !!homeAt && !r.home && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
|
|
3431
|
-
const unique = sorted.filter((x, i) => !nearHome(x) && !sorted.slice(0, i).some((y) => sameRect(y.landing, x.landing) || y.id === x.id));
|
|
3470
|
+
const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
|
|
3471
|
+
const unique = sorted.filter((x, i) => !nearHome(x) && !sorted.slice(0, i).some((y) => !x.slide && !y.slide && sameRect(y.landing, x.landing) || y.id === x.id));
|
|
3432
3472
|
const start = lo(laneRect, axis);
|
|
3433
3473
|
const end = start + len(laneRect, axis);
|
|
3434
3474
|
const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
|
|
@@ -3438,11 +3478,13 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
|
|
|
3438
3478
|
const a = unique[i];
|
|
3439
3479
|
const b = unique[i + 1];
|
|
3440
3480
|
const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
|
|
3441
|
-
const
|
|
3442
|
-
const
|
|
3443
|
-
const
|
|
3481
|
+
const aLanding = lastOf(a);
|
|
3482
|
+
const bLanding = firstOf(b);
|
|
3483
|
+
const aEnd = lo(aLanding, axis) + len(aLanding, axis);
|
|
3484
|
+
const across2 = (aEnd + lo(bLanding, axis)) / 2;
|
|
3485
|
+
const overlap = lo(bLanding, axis) < aEnd - EPS;
|
|
3444
3486
|
const slack = Math.max(0, marking.pitch) / 2;
|
|
3445
|
-
const atGrab = clamp(across2 + (held - 0.5) * (len(
|
|
3487
|
+
const atGrab = clamp(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
|
|
3446
3488
|
const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
|
|
3447
3489
|
cuts.push(clamp(Math.max(raw, cuts[i - 1] ?? start), start, end));
|
|
3448
3490
|
}
|
|
@@ -3453,6 +3495,7 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
|
|
|
3453
3495
|
target: x.target,
|
|
3454
3496
|
...x.home ? { home: true } : {},
|
|
3455
3497
|
...x.pitched ? { pitched: true } : {},
|
|
3498
|
+
...x.slide ? { slide: { from: x.slide.from, to: x.slide.to, snaps: x.slide.snaps, snapDistance: x.slide.snapDistance, step: x.slide.step } } : {},
|
|
3456
3499
|
others: othersKey(x.layout, dragged)
|
|
3457
3500
|
}));
|
|
3458
3501
|
const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
|
|
@@ -3466,7 +3509,7 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, he
|
|
|
3466
3509
|
}) : [];
|
|
3467
3510
|
const landings = /* @__PURE__ */ new Map();
|
|
3468
3511
|
if (!halves) {
|
|
3469
|
-
for (const x of unique) if (!x.pitched && !x.home && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
|
|
3512
|
+
for (const x of unique) if (!x.pitched && !x.home && !x.slide && !landings.has(`${x.before}|${x.next}`)) landings.set(`${x.before}|${x.next}`, { landing: x.landing, layout: x.layout });
|
|
3470
3513
|
}
|
|
3471
3514
|
const extent = (iid, r) => {
|
|
3472
3515
|
const n = halves ? void 0 : marking.natural(iid, axis);
|
|
@@ -3620,45 +3663,60 @@ function settle(l, drawn, scene, dragged, all, emptyLanes = "real") {
|
|
|
3620
3663
|
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;
|
|
3621
3664
|
function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
|
|
3622
3665
|
const out = [];
|
|
3623
|
-
|
|
3666
|
+
stretches(scene, dragged, options, seen, raws, (run) => {
|
|
3667
|
+
const { e, axis, w, gap, middle } = run;
|
|
3668
|
+
const taken = run.mine.map((r) => r.landing);
|
|
3669
|
+
const emit3 = (zone, at, space, x0, flush) => {
|
|
3670
|
+
const hit = landsAt(scene, dragged, run, { edge: e.id, zone, at, space }, x0);
|
|
3671
|
+
if (!hit) return false;
|
|
3672
|
+
const { next, layout } = hit;
|
|
3673
|
+
const landed = layout.items[dragged];
|
|
3674
|
+
const nb = flush !== void 0 ? layout.items[flush] : void 0;
|
|
3675
|
+
if (nb && Math.abs(lo(nb.rect, axis) + len(nb.rect, axis) + gap - lo(landed.rect, axis)) > 1 && Math.abs(lo(landed.rect, axis) + len(landed.rect, axis) + gap - lo(nb.rect, axis)) > 1) return false;
|
|
3676
|
+
const n = neighbors(layout, e.id, dragged, axis);
|
|
3677
|
+
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return true;
|
|
3678
|
+
taken.push(landed.rect);
|
|
3679
|
+
const result = { scene: next, layout };
|
|
3680
|
+
const kept = Math.round(next.items[dragged]?.space ?? 0);
|
|
3681
|
+
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 };
|
|
3682
|
+
const id = `${e.id}/${zone}/${n.before}|${n.next}@${flush !== void 0 && kept > 0 ? `to:${flush}` : Math.round(kept / pitch)}`;
|
|
3683
|
+
out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
|
|
3684
|
+
return true;
|
|
3685
|
+
};
|
|
3686
|
+
return ({ a, b, zones, atOf, spaceAt, before, after }) => {
|
|
3687
|
+
const end = (x0, order, flush) => {
|
|
3688
|
+
for (const zone of order) if (spaceAt(zone, x0) >= -EPS && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
|
|
3689
|
+
};
|
|
3690
|
+
end(a, zones, before?.id ?? "^");
|
|
3691
|
+
if (b - w > a + EPS) end(b - w, [...zones].reverse(), after?.id ?? "$");
|
|
3692
|
+
if (b - a < w + pitch) return;
|
|
3693
|
+
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS; x0 += pitch) {
|
|
3694
|
+
const zone = x0 + w / 2 < middle ? "start" : "end";
|
|
3695
|
+
if (!zones.includes(zone)) continue;
|
|
3696
|
+
emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
|
|
3697
|
+
}
|
|
3698
|
+
};
|
|
3699
|
+
});
|
|
3700
|
+
return out;
|
|
3701
|
+
}
|
|
3702
|
+
function stretches(scene, dragged, options, seen, raws, visit) {
|
|
3703
|
+
if (!scene.items[dragged]) return;
|
|
3624
3704
|
const prev = options.previous ? { previous: options.previous } : {};
|
|
3705
|
+
const base = solve(lift(scene, dragged), prev);
|
|
3625
3706
|
for (const e of scene.edges) {
|
|
3626
3707
|
const bar = e.side === "top" || e.side === "bottom";
|
|
3627
3708
|
if (!bar && !e.compact) continue;
|
|
3628
3709
|
const axis = bar ? "x" : "y";
|
|
3629
3710
|
const mine = raws.filter((r) => r.edge === e.id);
|
|
3630
|
-
const drawn = seen.edges[e.id];
|
|
3711
|
+
const drawn = base.edges[e.id] ?? seen.edges[e.id];
|
|
3631
3712
|
if (mine.length === 0 || !drawn) continue;
|
|
3632
|
-
const w = len(mine[0].landing, axis);
|
|
3633
3713
|
const gap = nonNeg(e.gap);
|
|
3634
|
-
const others = onEdge(
|
|
3714
|
+
const others = onEdge(base, e.id, dragged, axis);
|
|
3635
3715
|
const edgeStart = lo(drawn.rect, axis) + nonNeg(e.pad?.start);
|
|
3636
3716
|
const edgeEnd = lo(drawn.rect, axis) + len(drawn.rect, axis) - nonNeg(e.pad?.end);
|
|
3637
|
-
const middle = mid(drawn.rect, axis);
|
|
3638
3717
|
const zoneOf2 = (o) => o.zone ?? "start";
|
|
3639
|
-
const
|
|
3640
|
-
const
|
|
3641
|
-
const place = { edge: e.id, zone, at, space };
|
|
3642
|
-
const next = moveTo(scene, dragged, place);
|
|
3643
|
-
if (next === scene) return;
|
|
3644
|
-
const layout = solve(next, prev);
|
|
3645
|
-
const landed = layout.items[dragged];
|
|
3646
|
-
if (!landed || landed.inMenu || landed.edge !== e.id || x0 !== void 0 && Math.abs(lo(landed.rect, axis) - x0) > 1) return;
|
|
3647
|
-
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return;
|
|
3648
|
-
taken.push(landed.rect);
|
|
3649
|
-
const result = { scene: next, layout };
|
|
3650
|
-
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 };
|
|
3651
|
-
const n = neighbors(layout, e.id, dragged, axis);
|
|
3652
|
-
const id = `${e.id}/${zone}/${n.before}|${n.next}@${Math.round(space / pitch)}`;
|
|
3653
|
-
out.push({ lane: e.id, edge: e.id, axis, id, ...n, landing: landed.rect, layout, target, hit: landed.rect, pitched: true });
|
|
3654
|
-
};
|
|
3655
|
-
const spaced = (o) => !!o && (scene.items[o.id]?.space ?? 0) > 0;
|
|
3656
|
-
const own = scene.items[dragged];
|
|
3657
|
-
if (own && (own.space ?? 0) > 0 && seen.items[dragged]?.edge === e.id) {
|
|
3658
|
-
const zone = zoneIn(e, own);
|
|
3659
|
-
if (zone === "start") emit3("start", 0, 0);
|
|
3660
|
-
else if (zone === "end") emit3("end", others.filter((o) => zoneOf2(o) === "end").length, 0);
|
|
3661
|
-
}
|
|
3718
|
+
const w = len(mine[0].landing, axis);
|
|
3719
|
+
const each = visit({ e, axis, w, gap, middle: mid(drawn.rect, axis), mine, fixed: others.filter((o) => scene.items[o.id]?.fixed), prev });
|
|
3662
3720
|
const slack = (o) => {
|
|
3663
3721
|
const main = o ? scene.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
|
|
3664
3722
|
return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
|
|
@@ -3668,20 +3726,168 @@ function pitchedSpots(scene, dragged, options, seen, raws, pitch) {
|
|
|
3668
3726
|
const after = others[i];
|
|
3669
3727
|
const a = before ? lo(before.r, axis) + len(before.r, axis) - slack(before) + gap : edgeStart;
|
|
3670
3728
|
const b = after ? lo(after.r, axis) - gap : edgeEnd;
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
if (b - a < w + pitch) continue;
|
|
3674
|
-
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS; x0 += pitch) {
|
|
3675
|
-
const toStart = x0 + w / 2 < middle;
|
|
3676
|
-
if (toStart && before && zoneOf2(before) !== "start") continue;
|
|
3677
|
-
if (!toStart && after && zoneOf2(after) !== "end") continue;
|
|
3678
|
-
const zone = toStart ? "start" : "end";
|
|
3679
|
-
emit3(zone, others.filter((o) => zoneOf2(o) === zone && lo(o.r, axis) < x0).length, toStart ? x0 - a : b - (x0 + w), x0);
|
|
3680
|
-
}
|
|
3729
|
+
const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
|
|
3730
|
+
each({ before, after, a, b, zones, atOf: (zone) => others.slice(0, i).filter((o) => zoneOf2(o) === zone).length, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + w) });
|
|
3681
3731
|
}
|
|
3682
3732
|
}
|
|
3733
|
+
}
|
|
3734
|
+
function takeoverSpots(scene, dragged, options, seen, raws, pitch) {
|
|
3735
|
+
const out = [];
|
|
3736
|
+
stretches(scene, dragged, options, seen, raws, (run) => {
|
|
3737
|
+
const { e, axis, w } = run;
|
|
3738
|
+
const taken = [...run.mine.map((r) => r.landing)];
|
|
3739
|
+
const emit3 = (zone, at, space, x0, nb) => {
|
|
3740
|
+
const hit = landsAt(scene, dragged, run, { edge: e.id, zone, at, space }, x0);
|
|
3741
|
+
if (!hit) return;
|
|
3742
|
+
const { next, layout } = hit;
|
|
3743
|
+
const landed = layout.items[dragged];
|
|
3744
|
+
if (taken.some((r) => Math.abs(lo(r, axis) - lo(landed.rect, axis)) < pitch / 2)) return;
|
|
3745
|
+
taken.push(landed.rect);
|
|
3746
|
+
const n = neighbors(layout, e.id, dragged, axis);
|
|
3747
|
+
const result = { scene: next, layout };
|
|
3748
|
+
const target = { id: `pitch:${e.id}:${zone}:${at}:in:${nb}`, priority: 2, hit: landed.rect, slot: landed.rect, item: dragged, place: { kind: "gap", edge: e.id, zone, at }, after: () => result };
|
|
3749
|
+
out.push({ lane: e.id, edge: e.id, axis, id: `${e.id}/${zone}/${n.before}|${n.next}@in:${nb}`, ...n, landing: landed.rect, layout, target, hit: landed.rect });
|
|
3750
|
+
};
|
|
3751
|
+
return ({ zones, atOf, spaceAt, before, after }) => {
|
|
3752
|
+
const zoneOf2 = (id) => scene.items[id]?.align ?? "start";
|
|
3753
|
+
if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !scene.items[after.id]?.fixed) {
|
|
3754
|
+
const x0 = lo(after.r, axis);
|
|
3755
|
+
emit3("start", atOf("start"), Math.max(0, spaceAt("start", x0)), x0, after.id);
|
|
3756
|
+
}
|
|
3757
|
+
if (before && zones.includes("end") && zoneOf2(before.id) === "end" && !scene.items[before.id]?.fixed) {
|
|
3758
|
+
const x0 = lo(before.r, axis) + len(before.r, axis) - w;
|
|
3759
|
+
emit3("end", atOf("end"), Math.max(0, spaceAt("end", x0)), x0, before.id);
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
});
|
|
3683
3763
|
return out;
|
|
3684
3764
|
}
|
|
3765
|
+
function landsAt(scene, dragged, run, place, x0) {
|
|
3766
|
+
const next = moveTo(scene, dragged, place);
|
|
3767
|
+
if (next === scene) return null;
|
|
3768
|
+
const layout = solve(next, run.prev);
|
|
3769
|
+
const landed = layout.items[dragged];
|
|
3770
|
+
const { axis } = run;
|
|
3771
|
+
if (!landed || landed.inMenu || landed.edge !== run.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
|
|
3772
|
+
if (run.fixed.some((f) => {
|
|
3773
|
+
const r = layout.items[f.id]?.rect;
|
|
3774
|
+
return !r || Math.abs(lo(r, axis) - lo(f.r, axis)) > 1;
|
|
3775
|
+
})) return null;
|
|
3776
|
+
return { next, layout };
|
|
3777
|
+
}
|
|
3778
|
+
function slidingSpots(scene, dragged, options, seen, raws, sample) {
|
|
3779
|
+
const spots = [];
|
|
3780
|
+
const absorbed = /* @__PURE__ */ new Set();
|
|
3781
|
+
const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
|
|
3782
|
+
const own = seen.items[dragged];
|
|
3783
|
+
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
3784
|
+
stretches(scene, dragged, options, seen, raws, (run) => ({ a, b, zones, atOf, spaceAt, before, after }) => {
|
|
3785
|
+
const { e, axis, w, middle, mine } = run;
|
|
3786
|
+
if (zones.length === 0 || b - w < a - EPS) return;
|
|
3787
|
+
{
|
|
3788
|
+
const land = (x0) => {
|
|
3789
|
+
const near = x0 + w / 2 < middle ? "start" : "end";
|
|
3790
|
+
for (const zone2 of [near, near === "start" ? "end" : "start"]) {
|
|
3791
|
+
if (!zones.includes(zone2)) continue;
|
|
3792
|
+
const space = spaceAt(zone2, x0);
|
|
3793
|
+
if (space < -EPS) continue;
|
|
3794
|
+
const place = { edge: e.id, zone: zone2, at: atOf(zone2), space: Math.max(0, space) };
|
|
3795
|
+
const hit = landsAt(scene, dragged, run, place, x0);
|
|
3796
|
+
if (hit) return { place, result: { scene: hit.next, layout: hit.layout } };
|
|
3797
|
+
}
|
|
3798
|
+
return null;
|
|
3799
|
+
};
|
|
3800
|
+
const tries = [a];
|
|
3801
|
+
for (let x0 = a + sample; x0 < b - w - EPS; x0 += sample) tries.push(x0);
|
|
3802
|
+
if (b - w > a + EPS) tries.push(b - w);
|
|
3803
|
+
const ok = tries.map((x0) => ({ x0, hit: land(x0) })).filter((t) => t.hit);
|
|
3804
|
+
if (ok.length === 0) return;
|
|
3805
|
+
const from = ok[0].x0;
|
|
3806
|
+
const to = ok.at(-1).x0;
|
|
3807
|
+
const bId = before?.id ?? "^";
|
|
3808
|
+
const nId = after?.id ?? "$";
|
|
3809
|
+
const inside = mine.filter((r) => !r.slide && r.before === bId && r.next === nId && Math.abs(len(r.landing, axis) - w) <= 1 && lo(r.landing, axis) >= from - 1 && lo(r.landing, axis) <= to + 1);
|
|
3810
|
+
for (const r of inside) absorbed.add(r);
|
|
3811
|
+
const homeRaw = inside.find((r) => r.home);
|
|
3812
|
+
const points = [];
|
|
3813
|
+
const put = (at2, raw) => {
|
|
3814
|
+
const same = points.find((p) => Math.abs(p.at - at2) < 1e-6);
|
|
3815
|
+
if (!same) points.push({ at: at2, ...raw ? { raw } : {} });
|
|
3816
|
+
else if (raw && !same.raw) same.raw = raw;
|
|
3817
|
+
};
|
|
3818
|
+
put(from);
|
|
3819
|
+
put(to);
|
|
3820
|
+
for (const r of [...inside].sort((p, q) => p.home ? -1 : q.home ? 1 : 0)) put(lo(r.landing, axis), r);
|
|
3821
|
+
const homeAt = homeRaw ? lo(homeRaw.landing, axis) : void 0;
|
|
3822
|
+
const kept = points.filter((p) => homeAt === void 0 || Math.abs(p.at - homeAt) < 1e-6 || Math.abs(p.at - homeAt) > 2 * snapDistance).sort((p, q) => p.at - q.at);
|
|
3823
|
+
const snaps = kept.map((p) => p.at);
|
|
3824
|
+
const dockAt = (x0) => kept.find((p) => Math.abs(p.at - x0) < 1e-6)?.raw;
|
|
3825
|
+
const shape = ok[0].hit.result.layout.items[dragged].rect;
|
|
3826
|
+
const at = (x0) => along(shape, axis, x0, x0 + w);
|
|
3827
|
+
const snapped = (x0) => {
|
|
3828
|
+
let best = x0;
|
|
3829
|
+
let d = Infinity;
|
|
3830
|
+
for (const q of snaps) if (Math.abs(q - x0) <= snapDistance && Math.abs(q - x0) < d) [best, d] = [q, Math.abs(q - x0)];
|
|
3831
|
+
return best;
|
|
3832
|
+
};
|
|
3833
|
+
const startAt = (raw) => {
|
|
3834
|
+
const c = clamp(raw, from, to);
|
|
3835
|
+
const s = snapped(c);
|
|
3836
|
+
return snaps.includes(s) ? s : clamp(Math.round(c / STEP) * STEP, from, to);
|
|
3837
|
+
};
|
|
3838
|
+
const results = /* @__PURE__ */ new Map();
|
|
3839
|
+
const commitAt = (x0) => {
|
|
3840
|
+
const r = dockAt(x0);
|
|
3841
|
+
const k = `${r ? "dock " : ""}${Math.round(x0 * 1e3) / 1e3}`;
|
|
3842
|
+
const known = results.get(k);
|
|
3843
|
+
if (known) return known;
|
|
3844
|
+
const result = r ? r.target.after(ORIGIN, ORIGIN) : land(x0)?.result ?? ok.reduce((p, q) => Math.abs(q.x0 - x0) < Math.abs(p.x0 - x0) ? q : p).hit.result;
|
|
3845
|
+
results.set(k, result);
|
|
3846
|
+
return result;
|
|
3847
|
+
};
|
|
3848
|
+
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp(lo(own.rect, axis), from, to)) : from;
|
|
3849
|
+
const restResult = commitAt(rest);
|
|
3850
|
+
const ownZone = own?.zone;
|
|
3851
|
+
const restPlace = (() => {
|
|
3852
|
+
if (homeRaw) return ownZone && zones.includes(ownZone) ? { zone: ownZone, at: atOf(ownZone), space: Math.max(0, spaceAt(ownZone, rest)) } : land(rest)?.place;
|
|
3853
|
+
const p = dockAt(rest)?.target.place;
|
|
3854
|
+
return p && p.kind === "gap" ? p : land(rest)?.place;
|
|
3855
|
+
})();
|
|
3856
|
+
const landing = homeRaw ? homeRaw.landing : restResult.layout.items[dragged]?.rect ?? at(rest);
|
|
3857
|
+
const ownLen = own ? Math.max(own.rect.width, own.rect.height) : 0;
|
|
3858
|
+
const long = own && own.rect.width >= own.rect.height ? "x" : "y";
|
|
3859
|
+
const target = {
|
|
3860
|
+
id: `slide:${e.id}:${bId}|${nId}`,
|
|
3861
|
+
priority: 2,
|
|
3862
|
+
hit: hull2(at(from), at(to)),
|
|
3863
|
+
slot: landing,
|
|
3864
|
+
item: dragged,
|
|
3865
|
+
place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
|
|
3866
|
+
after: (point, grab) => {
|
|
3867
|
+
const g = grab ? grab[long] : ownLen / 2;
|
|
3868
|
+
const share = axis === long && ownLen > EPS && Number.isFinite(g) ? clamp(g / ownLen, 0, 1) : 0.5;
|
|
3869
|
+
return commitAt(startAt((axis === "x" ? point.x : point.y) - share * w));
|
|
3870
|
+
}
|
|
3871
|
+
};
|
|
3872
|
+
const zone = zones[0];
|
|
3873
|
+
spots.push({
|
|
3874
|
+
lane: e.id,
|
|
3875
|
+
edge: e.id,
|
|
3876
|
+
axis,
|
|
3877
|
+
id: `${e.id}/${zone}/${bId}|${nId}@slide`,
|
|
3878
|
+
before: bId,
|
|
3879
|
+
next: nId,
|
|
3880
|
+
landing,
|
|
3881
|
+
layout: restResult.layout,
|
|
3882
|
+
target,
|
|
3883
|
+
hit: target.hit,
|
|
3884
|
+
...homeRaw ? { home: true } : {},
|
|
3885
|
+
slide: { from, to, snaps, snapDistance, step: STEP, first: at(from), last: at(to) }
|
|
3886
|
+
});
|
|
3887
|
+
}
|
|
3888
|
+
});
|
|
3889
|
+
return { spots, absorbed };
|
|
3890
|
+
}
|
|
3685
3891
|
|
|
3686
3892
|
export {
|
|
3687
3893
|
SIDES,
|
|
@@ -3743,4 +3949,4 @@ export {
|
|
|
3743
3949
|
HATCH_END,
|
|
3744
3950
|
HATCH_EDGE
|
|
3745
3951
|
};
|
|
3746
|
-
//# sourceMappingURL=chunk-
|
|
3952
|
+
//# sourceMappingURL=chunk-NM4ADJC2.js.map
|