@n-uf/docking 26.11.58 → 26.11.59
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 +51 -0
- package/dist/{chunk-7QOY2URO.js → chunk-Y3RK6BQT.js} +585 -352
- package/dist/chunk-Y3RK6BQT.js.map +1 -0
- package/dist/{drag-BGcY5DGm.d.ts → drag-DpoWfEc7.d.ts} +12 -3
- package/dist/index.d.ts +30 -7
- package/dist/index.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +12 -9
- package/dist/testing.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunk-7QOY2URO.js.map +0 -1
|
@@ -576,9 +576,9 @@ function zoneStarts(state, edge, fit, input) {
|
|
|
576
576
|
lay(e, endStart, false);
|
|
577
577
|
const lo2 = start + spaced(s) + (s.length > 0 ? gap : 0);
|
|
578
578
|
const hi = endStart - (e.length > 0 ? gap : 0);
|
|
579
|
-
const
|
|
580
|
-
const clear =
|
|
581
|
-
const cAt = centerAt ?? (title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(
|
|
579
|
+
const mid3 = (fit.length - total(c)) / 2;
|
|
580
|
+
const clear = mid3 >= lo2 - EPS2 && mid3 + total(c) <= hi + EPS2;
|
|
581
|
+
const cAt = centerAt ?? (title && !clear ? Math.max(lo2, (lo2 + hi - total(c)) / 2) : Math.max(lo2, Math.min(mid3, hi - total(c))));
|
|
582
582
|
lay(c, cAt, false);
|
|
583
583
|
const spans2 = [
|
|
584
584
|
{ ps: s, a: start, b: start + spaced(s) },
|
|
@@ -869,7 +869,7 @@ function clearSize(region, avoid) {
|
|
|
869
869
|
const span = (axis) => {
|
|
870
870
|
const lo2 = axis === "y" ? region.y : region.x;
|
|
871
871
|
const hi = lo2 + (axis === "y" ? region.height : region.width);
|
|
872
|
-
const
|
|
872
|
+
const mid3 = (lo2 + hi) / 2;
|
|
873
873
|
let a = lo2;
|
|
874
874
|
let b = hi;
|
|
875
875
|
for (const r of avoid) {
|
|
@@ -877,7 +877,7 @@ function clearSize(region, avoid) {
|
|
|
877
877
|
const s = axis === "y" ? r.y : r.x;
|
|
878
878
|
const e = s + (axis === "y" ? r.height : r.width);
|
|
879
879
|
if (!whole || e <= lo2 || s >= hi) continue;
|
|
880
|
-
if (s + e <= 2 *
|
|
880
|
+
if (s + e <= 2 * mid3) a = Math.max(a, e);
|
|
881
881
|
else b = Math.min(b, s);
|
|
882
882
|
}
|
|
883
883
|
return Math.max(0, b - a);
|
|
@@ -1539,7 +1539,7 @@ function fitAxis(start, length, b, drag, hit) {
|
|
|
1539
1539
|
}
|
|
1540
1540
|
return [a, to - a];
|
|
1541
1541
|
}
|
|
1542
|
-
function fitResize(state, id,
|
|
1542
|
+
function fitResize(state, id, rect21, moving) {
|
|
1543
1543
|
const f = state.floats.find((x2) => x2.id === id);
|
|
1544
1544
|
const item = Object.hasOwn(state.items, id) ? state.items[id] : void 0;
|
|
1545
1545
|
if (!f || !item || item.fixed) return null;
|
|
@@ -1557,8 +1557,8 @@ function fitResize(state, id, rect20, moving) {
|
|
|
1557
1557
|
const { rects: obstacles, docked } = floatObstacles(state, l, id);
|
|
1558
1558
|
const hit = /* @__PURE__ */ new Set();
|
|
1559
1559
|
const stops2 = f.stays ? obstacles.slice(docked) : obstacles;
|
|
1560
|
-
const [x, width] = fitAxis(
|
|
1561
|
-
const [y, height] = fitAxis(
|
|
1560
|
+
const [x, width] = fitAxis(rect21.x, rect21.width, { min: min.width, max: max.width, lo: region.x, hi: region.x + region.width, stop: obstacleStop(drawn, stops2, "x", dragX ?? "end", [drawn.y, drawn.y + drawn.height]) }, dragX, hit);
|
|
1561
|
+
const [y, height] = fitAxis(rect21.y, rect21.height, { min: min.height, max: max.height, lo: region.y, hi: region.y + region.height, stop: obstacleStop(drawn, stops2, "y", dragY ?? "end", [x, x + width]) }, dragY, hit);
|
|
1562
1562
|
const { anchor: _a, ...plain } = f;
|
|
1563
1563
|
const placed = placeFloat(item, { ...plain, rect: { x, y, width, height } }, region, obstacles, l.content, state.stage, [], docked).fit.rect;
|
|
1564
1564
|
if (Math.abs(placed.x - x) > EPS9 || Math.abs(placed.y - y) > EPS9) hit.add("docked");
|
|
@@ -1826,8 +1826,8 @@ function orientFloat(state, id, to) {
|
|
|
1826
1826
|
const turned = { ...f, rect: { x: f.rect.x, y: f.rect.y, width: size.width, height: size.height }, orient: to };
|
|
1827
1827
|
return withItem({ ...state, floats: state.floats.map((g, k) => k === i ? turned : g) }, kept);
|
|
1828
1828
|
}
|
|
1829
|
-
function resizeFloat(state, floatId,
|
|
1830
|
-
const fit = fitResize(state, floatId,
|
|
1829
|
+
function resizeFloat(state, floatId, rect21, moving = { right: true, bottom: true }) {
|
|
1830
|
+
const fit = fitResize(state, floatId, rect21, moving);
|
|
1831
1831
|
const i = state.floats.findIndex((f) => f.id === floatId);
|
|
1832
1832
|
const item = itemOf(state, floatId);
|
|
1833
1833
|
if (!fit || i < 0 || !item) return state;
|
|
@@ -2183,7 +2183,7 @@ function read(data, base) {
|
|
|
2183
2183
|
}
|
|
2184
2184
|
|
|
2185
2185
|
// src/targets.ts
|
|
2186
|
-
import { EPS as
|
|
2186
|
+
import { EPS as EPS22, PLANE, area as area6, clamp as clamp3, contains, overlaps as overlaps7, rect as rect19 } from "@n-uf/placement";
|
|
2187
2187
|
|
|
2188
2188
|
// src/targets/anchor.ts
|
|
2189
2189
|
import { EPS as EPS11, area, rect as rect10, subtract } from "@n-uf/placement";
|
|
@@ -2214,8 +2214,62 @@ function anchorTargets(state, dragged, options) {
|
|
|
2214
2214
|
return { targets: targets2, refusals: [], lost: [] };
|
|
2215
2215
|
}
|
|
2216
2216
|
|
|
2217
|
+
// src/aim.ts
|
|
2218
|
+
import { EPS as EPS12, clamp } from "@n-uf/placement";
|
|
2219
|
+
var SPOT_PITCH = 40;
|
|
2220
|
+
var SNAP_DISTANCE = 8;
|
|
2221
|
+
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
2222
|
+
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
2223
|
+
function zoneIn2(layout, id) {
|
|
2224
|
+
return (id === void 0 ? void 0 : layout.items[id]?.zone) ?? "start";
|
|
2225
|
+
}
|
|
2226
|
+
function cutsByHalves(edge) {
|
|
2227
|
+
return (edge.side === "left" || edge.side === "right") && !edge.compact;
|
|
2228
|
+
}
|
|
2229
|
+
function aimSlack(pitch) {
|
|
2230
|
+
return Math.max(0, pitch === void 0 || !Number.isFinite(pitch) ? SPOT_PITCH : pitch) / 2;
|
|
2231
|
+
}
|
|
2232
|
+
function grabShare(own, grab) {
|
|
2233
|
+
const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS12 ? 0.5 : clamp(g / size, 0, 1);
|
|
2234
|
+
const w = own?.width ?? 0;
|
|
2235
|
+
const h = own?.height ?? 0;
|
|
2236
|
+
return { x: w >= h ? shareOf(grab?.x, w) : 0.5, y: h > w ? shareOf(grab?.y, h) : 0.5 };
|
|
2237
|
+
}
|
|
2238
|
+
function aimCut(a, b, axis, held, slack, shared) {
|
|
2239
|
+
if (shared) return lo(shared, axis) + len(shared, axis) / 2;
|
|
2240
|
+
const aEnd = lo(a, axis) + len(a, axis);
|
|
2241
|
+
const bStart = lo(b, axis);
|
|
2242
|
+
const across2 = (aEnd + bStart) / 2;
|
|
2243
|
+
if (!(bStart < aEnd - EPS12)) return across2;
|
|
2244
|
+
const s = Math.max(0, slack);
|
|
2245
|
+
return clamp(across2 + (held - 0.5) * (len(a, axis) + len(b, axis)) / 2, bStart - s, aEnd + s);
|
|
2246
|
+
}
|
|
2247
|
+
function crossFreeCuts(n, cut2, pinned, min = -Infinity, max = Infinity) {
|
|
2248
|
+
const active = Array.from({ length: n }, (_, i) => i);
|
|
2249
|
+
for (let changed = true; changed; ) {
|
|
2250
|
+
changed = false;
|
|
2251
|
+
for (let k = 1; k + 1 < active.length; k++) {
|
|
2252
|
+
const [p, q, r] = [active[k - 1], active[k], active[k + 1]];
|
|
2253
|
+
if (!pinned(q) && cut2(q, r) < cut2(p, q) - EPS12) {
|
|
2254
|
+
active.splice(k, 1);
|
|
2255
|
+
changed = true;
|
|
2256
|
+
break;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
const kept = [];
|
|
2261
|
+
for (let k = 0; k + 1 < active.length; k++) kept.push(clamp(Math.max(cut2(active[k], active[k + 1]), kept[k - 1] ?? min), min, max));
|
|
2262
|
+
return Array.from({ length: Math.max(0, n - 1) }, (_, i) => kept[active.findIndex((j) => j > i) - 1]);
|
|
2263
|
+
}
|
|
2264
|
+
function rangeTries(a, b, w, sample) {
|
|
2265
|
+
const tries = [a];
|
|
2266
|
+
for (let x0 = a + sample; x0 < b - w - EPS12; x0 += sample) tries.push(x0);
|
|
2267
|
+
if (b - w > a + EPS12) tries.push(b - w);
|
|
2268
|
+
return tries;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2217
2271
|
// src/targets/edges.ts
|
|
2218
|
-
import { EPS as
|
|
2272
|
+
import { EPS as EPS13, area as area2, rect as rect11 } from "@n-uf/placement";
|
|
2219
2273
|
import { formCrossMin as formCrossMin4, formMenu as formMenu5, formSetsCross as formSetsCross4, itemSteps as itemSteps3 } from "@n-uf/placement/stack";
|
|
2220
2274
|
|
|
2221
2275
|
// src/targets/kinds.ts
|
|
@@ -2271,7 +2325,7 @@ function distinctSlots(c, slots) {
|
|
|
2271
2325
|
if (a.zone !== b.zone) return false;
|
|
2272
2326
|
if (a.home && b.home) return true;
|
|
2273
2327
|
const [p, q] = [landing(a), landing(b)];
|
|
2274
|
-
const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) <
|
|
2328
|
+
const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS13;
|
|
2275
2329
|
return sameLine && (!p || !q ? p === q : Math.abs(p.x - q.x) + Math.abs(p.y - q.y) + Math.abs(p.width - q.width) + Math.abs(p.height - q.height) < 0.01);
|
|
2276
2330
|
};
|
|
2277
2331
|
const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
|
|
@@ -2398,7 +2452,7 @@ function edgeSlots(c, edge, accepts) {
|
|
|
2398
2452
|
}
|
|
2399
2453
|
function thickerThan(forms, cross) {
|
|
2400
2454
|
const shown = forms.filter((f) => !formMenu5(f));
|
|
2401
|
-
return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross +
|
|
2455
|
+
return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS13);
|
|
2402
2456
|
}
|
|
2403
2457
|
var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
|
|
2404
2458
|
function edgeSpec(c, edge, as) {
|
|
@@ -2412,17 +2466,17 @@ function edgeSpec(c, edge, as) {
|
|
|
2412
2466
|
const len2 = (r2) => column ? r2.height : r2.width;
|
|
2413
2467
|
const empty = el.stack.items.every((p) => el.stack.menu?.items.includes(p.id)) && !el.menu;
|
|
2414
2468
|
const accepts = edgeTakes(edge, kind);
|
|
2415
|
-
if (!accepts && (empty || area2(el.rect) <=
|
|
2469
|
+
if (!accepts && (empty || area2(el.rect) <= EPS13)) return null;
|
|
2416
2470
|
if (accepts && empty && !opensEmpty(state, edge, kind)) return null;
|
|
2417
2471
|
const ownNow = c.room.items[dragged];
|
|
2418
|
-
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) >
|
|
2472
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS13 ? ownNow.rect : null;
|
|
2419
2473
|
const oneEnd = state.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
|
|
2420
2474
|
const allSlots = edgeSlots(c, edge, accepts);
|
|
2421
2475
|
const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
|
|
2422
2476
|
const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
|
|
2423
2477
|
const grows = (id) => !!formsOf(state.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
|
|
2424
2478
|
const reserved = Object.entries(now.items).filter(([id, p]) => p.edge === edge.id && p.fixed && !p.inMenu && !grows(id)).map(([, p]) => spanOf(p.rect));
|
|
2425
|
-
const cards = Object.entries(c.room.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) >
|
|
2479
|
+
const cards = Object.entries(c.room.items).filter(([id, p]) => id !== dragged && p.edge === edge.id && !p.fixed && !p.inMenu && !p.floating && area2(p.rect) > EPS13).map(([, p]) => spanOf(p.rect));
|
|
2426
2480
|
const zones = oneEnd ? [{ zone: "start", a: at(el.rect) - c.reach, b: at(el.rect) + len2(el.rect) + c.reach }] : zoneSpans(state, c.room, edge, c.reach, (zone) => {
|
|
2427
2481
|
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
2428
2482
|
const me = s?.result.layout.items[dragged];
|
|
@@ -2451,7 +2505,7 @@ function edgeSpec(c, edge, as) {
|
|
|
2451
2505
|
vertical: column,
|
|
2452
2506
|
zones,
|
|
2453
2507
|
slots,
|
|
2454
|
-
refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) >
|
|
2508
|
+
refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS13 ? "not-accepted" : null,
|
|
2455
2509
|
own: ownHere,
|
|
2456
2510
|
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
2457
2511
|
reserved,
|
|
@@ -2544,28 +2598,32 @@ function context(state, dragged, options, others = []) {
|
|
|
2544
2598
|
settle: settle2,
|
|
2545
2599
|
isHome: (r) => placeKey(r.state, dragged) === here,
|
|
2546
2600
|
sound: soundness(state, base, dragged),
|
|
2547
|
-
lay: layKeys(state)
|
|
2601
|
+
lay: layKeys(state),
|
|
2602
|
+
// (Held, a movable grower is its natural length, as `lanes()` reads the grab: `landedLayout`.)
|
|
2603
|
+
share: grabShare(landedLayout(state, now, dragged, prev).items[dragged]?.rect, options.grab),
|
|
2604
|
+
slack: aimSlack(options.pitch),
|
|
2605
|
+
slideRanges: /* @__PURE__ */ new Map()
|
|
2548
2606
|
};
|
|
2549
2607
|
return { c, item, prev };
|
|
2550
2608
|
}
|
|
2551
2609
|
|
|
2552
|
-
// src/targets/ownership.ts
|
|
2553
|
-
import { EPS as EPS15, area as area3, overlaps as overlaps3, rect as rect13, subtract as subtract2 } from "@n-uf/placement";
|
|
2554
|
-
import { formBody as formBody2, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
|
|
2555
|
-
|
|
2556
2610
|
// src/targets/meet.ts
|
|
2557
|
-
import { EPS as
|
|
2611
|
+
import { EPS as EPS14, rect as rect12 } from "@n-uf/placement";
|
|
2558
2612
|
function meet(a, b) {
|
|
2559
2613
|
const x = Math.max(a.x, b.x);
|
|
2560
2614
|
const y = Math.max(a.y, b.y);
|
|
2561
2615
|
const w = Math.min(a.x + a.width, b.x + b.width) - x;
|
|
2562
2616
|
const h = Math.min(a.y + a.height, b.y + b.height) - y;
|
|
2563
|
-
return w >
|
|
2617
|
+
return w > EPS14 && h > EPS14 ? rect12(x, y, w, h) : null;
|
|
2564
2618
|
}
|
|
2565
2619
|
|
|
2620
|
+
// src/targets/ownership.ts
|
|
2621
|
+
import { EPS as EPS16, area as area3, overlaps as overlaps3, rect as rect13, subtract as subtract2 } from "@n-uf/placement";
|
|
2622
|
+
import { formBody as formBody2, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
|
|
2623
|
+
|
|
2566
2624
|
// src/targets/model.ts
|
|
2567
|
-
import { EPS as
|
|
2568
|
-
var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u >
|
|
2625
|
+
import { EPS as EPS15 } from "@n-uf/placement";
|
|
2626
|
+
var less = (spans, away) => away.reduce((acc, [ra, rb]) => acc.flatMap(([a, b]) => rb <= a || ra >= b ? [[a, b]] : [[a, Math.max(a, ra)], [Math.min(b, rb), b]].filter(([u, w]) => w - u > EPS15)), [...spans]);
|
|
2569
2627
|
|
|
2570
2628
|
// src/targets/ownership.ts
|
|
2571
2629
|
var isBody = (f) => !!f && formBody2(f);
|
|
@@ -2587,10 +2645,10 @@ function ownedRectsOf(s, along2) {
|
|
|
2587
2645
|
return along2.map(([a, b]) => s.vertical ? rect13(o.x, a, o.width, b - a) : rect13(a, o.y, b - a, o.height));
|
|
2588
2646
|
}
|
|
2589
2647
|
function drawnOf(c, live) {
|
|
2590
|
-
const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) >
|
|
2648
|
+
const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS16 && c.lay.has(id)).map(([id, e]) => ({ spec: live.find((s) => s.edge?.id === id) ?? null, rect: e.rect, lay: c.lay.get(id) }));
|
|
2591
2649
|
const rails = ["left", "right"].flatMap((side) => {
|
|
2592
2650
|
const rail = c.now.rails[side];
|
|
2593
|
-
if (!rail || rail.segments.length === 0 || area3(rail.rect) <=
|
|
2651
|
+
if (!rail || rail.segments.length === 0 || area3(rail.rect) <= EPS16) return [];
|
|
2594
2652
|
const spec = live.find((s) => s.kind === "railStop" && s.lay.side === side) ?? null;
|
|
2595
2653
|
const lay = spec?.lay ?? { phase: EDGE_KINDS.railStop.phase, side, at: -1 };
|
|
2596
2654
|
const me = c.now.items[c.dragged];
|
|
@@ -2612,7 +2670,7 @@ function homeRectOf(c, ownSpec) {
|
|
|
2612
2670
|
if (!ownSpec) {
|
|
2613
2671
|
const e = c.now.edges[own.edge];
|
|
2614
2672
|
const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
|
|
2615
|
-
return e && vanishes && !e.folded && !e.rides && area3(e.rect) >
|
|
2673
|
+
return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS16 ? hull3(o, e.rect) : o;
|
|
2616
2674
|
}
|
|
2617
2675
|
const [c0, c1] = ownSpec.across();
|
|
2618
2676
|
return ownSpec.vertical ? hull3(o, rect13(c0, o.y, c1 - c0, o.height)) : hull3(o, rect13(o.x, c0, o.width, c1 - c0));
|
|
@@ -2632,7 +2690,7 @@ function ownersOf(c, live, drawn, alongOf) {
|
|
|
2632
2690
|
if (!s.thinOwned) return rects.map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }));
|
|
2633
2691
|
const thin = (r) => s.vertical ? rect13(Math.max(r.x, s.thinOwned[0]), r.y, Math.min(r.x + r.width, s.thinOwned[1]) - Math.max(r.x, s.thinOwned[0]), r.height) : rect13(r.x, Math.max(r.y, s.thinOwned[0]), r.width, Math.min(r.y + r.height, s.thinOwned[1]) - Math.max(r.y, s.thinOwned[0]));
|
|
2634
2692
|
return rects.flatMap((r) => [{ spec: s, rect: thin(r), lay: s.lay, place: true }, ...subtract2(r, thin(r)).map((d) => ({ spec: s, rect: d, lay: s.lay, place: true, deep: true }))]);
|
|
2635
|
-
}).filter((o) => area3(o.rect) >
|
|
2693
|
+
}).filter((o) => area3(o.rect) > EPS16),
|
|
2636
2694
|
// Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
|
|
2637
2695
|
...drawn.map((d) => ({ ...d, place: false }))
|
|
2638
2696
|
];
|
|
@@ -2658,7 +2716,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2658
2716
|
const e = s.edge ? now.edges[s.id] : void 0;
|
|
2659
2717
|
if (!e) return null;
|
|
2660
2718
|
const span = s.vertical ? [e.rect.y, e.rect.y + e.rect.height] : [e.rect.x, e.rect.x + e.rect.width];
|
|
2661
|
-
return span[1] - span[0] >
|
|
2719
|
+
return span[1] - span[0] > EPS16 ? span : null;
|
|
2662
2720
|
};
|
|
2663
2721
|
const pastEnds = (s, r) => {
|
|
2664
2722
|
const ends = endsOf(s);
|
|
@@ -2710,7 +2768,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2710
2768
|
const half = e ? halfBandOf(e) : null;
|
|
2711
2769
|
if (!e || half === null) return [];
|
|
2712
2770
|
const column = axisOf(e.side) === "column";
|
|
2713
|
-
return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && iid !== dragged && isBody(formsOf(state.items[iid], axisOf(e.side))[p.form])).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a >
|
|
2771
|
+
return Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && iid !== dragged && isBody(formsOf(state.items[iid], axisOf(e.side))[p.form])).map(([, p]) => column ? [p.rect.y + half, p.rect.y + p.rect.height - half] : [p.rect.x + half, p.rect.x + p.rect.width - half]).filter(([a, b]) => b - a > EPS16);
|
|
2714
2772
|
};
|
|
2715
2773
|
const rooms = /* @__PURE__ */ new Map();
|
|
2716
2774
|
const cutsOf = (s) => {
|
|
@@ -2727,23 +2785,23 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2727
2785
|
const owned = [];
|
|
2728
2786
|
for (let k = 1; k < ends.length; k++) {
|
|
2729
2787
|
const [u, w] = [ends[k - 1], ends[k]];
|
|
2730
|
-
const over2 = rs.filter((r) => along2(r)[0] <= u +
|
|
2731
|
-
if (w - u >
|
|
2788
|
+
const over2 = rs.filter((r) => along2(r)[0] <= u + EPS16 && along2(r)[1] >= w - EPS16).map(across2);
|
|
2789
|
+
if (w - u > EPS16 && less([across2(b)], over2).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
2732
2790
|
}
|
|
2733
2791
|
const half = s.edge ? halfBandOf(s.edge) : null;
|
|
2734
2792
|
const raw = bodySpans(s.edge);
|
|
2735
2793
|
if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
|
|
2736
2794
|
const merged = owned.reduce((m, [u, w]) => {
|
|
2737
2795
|
const last = m[m.length - 1];
|
|
2738
|
-
if (last && u <= last[1] +
|
|
2796
|
+
if (last && u <= last[1] + EPS16) last[1] = Math.max(last[1], w);
|
|
2739
2797
|
else m.push([u, w]);
|
|
2740
2798
|
return m;
|
|
2741
2799
|
}, []);
|
|
2742
2800
|
const [lo2, hi] = endsOf(s) ?? along2(b);
|
|
2743
2801
|
const placed = (p) => {
|
|
2744
|
-
const cut2 = merged.find(([u, w]) => p >= u -
|
|
2802
|
+
const cut2 = merged.find(([u, w]) => p >= u - EPS16 && p <= w + EPS16);
|
|
2745
2803
|
if (!cut2) return p;
|
|
2746
|
-
const sides = [...cut2[0] > lo2 +
|
|
2804
|
+
const sides = [...cut2[0] > lo2 + EPS16 ? [cut2[0]] : [], ...cut2[1] < hi - EPS16 ? [cut2[1]] : []];
|
|
2747
2805
|
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
2748
2806
|
};
|
|
2749
2807
|
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
@@ -2761,7 +2819,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2761
2819
|
const column = axisOf(e.side) === "column";
|
|
2762
2820
|
const across2 = (a, b) => column ? rect13(-1e9, a, 2e9, b - a) : rect13(a, -1e9, b - a, 2e9);
|
|
2763
2821
|
const reserved = Object.entries(now.items).filter(([iid, p]) => p.edge === e.id && p.fixed && !p.inMenu && !grows(iid)).map(([, p]) => column ? across2(p.rect.y, p.rect.y + p.rect.height) : across2(p.rect.x, p.rect.x + p.rect.width));
|
|
2764
|
-
return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) >
|
|
2822
|
+
return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS16);
|
|
2765
2823
|
};
|
|
2766
2824
|
const drawnBySpec = /* @__PURE__ */ new Map();
|
|
2767
2825
|
const drawnBesides = (s) => {
|
|
@@ -2773,13 +2831,138 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2773
2831
|
}
|
|
2774
2832
|
|
|
2775
2833
|
// src/targets/tiles.ts
|
|
2776
|
-
import { EPS as
|
|
2834
|
+
import { EPS as EPS18, area as area4, overlaps as overlaps4, rect as rect15, subtract as subtract3 } from "@n-uf/placement";
|
|
2835
|
+
|
|
2836
|
+
// src/slide.ts
|
|
2837
|
+
import { EPS as EPS17, rect as rect14 } from "@n-uf/placement";
|
|
2838
|
+
import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
|
|
2839
|
+
var mid = (r, axis) => lo(r, axis) + len(r, axis) / 2;
|
|
2840
|
+
var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
2841
|
+
function onEdge(l, edge, dragged, axis) {
|
|
2842
|
+
return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS17 && it.rect.height > EPS17).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
|
|
2843
|
+
}
|
|
2844
|
+
function neighbors(after, edge, dragged, axis) {
|
|
2845
|
+
const me = after.items[dragged];
|
|
2846
|
+
const others = onEdge(after, edge, dragged, axis);
|
|
2847
|
+
const at = me ? mid(me.rect, axis) : 0;
|
|
2848
|
+
return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
|
|
2849
|
+
}
|
|
2850
|
+
function givesWay(now, after, lane, side, extent) {
|
|
2851
|
+
if (!now) return null;
|
|
2852
|
+
if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
|
|
2853
|
+
const [p0, p1] = extent(now.rect);
|
|
2854
|
+
const [q0, q1] = extent(after.rect);
|
|
2855
|
+
if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
|
|
2856
|
+
return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
|
|
2857
|
+
}
|
|
2858
|
+
function slackOf(state, id, axis, r) {
|
|
2859
|
+
const main = state.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
|
|
2860
|
+
return main?.grows ? Math.max(0, len(r, axis) - main.natural) : 0;
|
|
2861
|
+
}
|
|
2862
|
+
function placeOf(se, l) {
|
|
2863
|
+
const counts = (id) => !(se.state.items[id]?.fixed && itemSteps6(se.state.items[id]));
|
|
2864
|
+
const shown = Object.entries(l.items).filter(([id, it]) => counts(id) && it.edge === se.e.id && !it.inMenu && !it.floating && it.rect.width > EPS17 && it.rect.height > EPS17).sort(([, p], [, q]) => lo(p.rect, se.axis) - lo(q.rect, se.axis)).map(([id]) => id);
|
|
2865
|
+
const menu = Object.entries(l.items).filter(([id, it]) => counts(id) && it.inMenu && it.edge === se.e.id).map(([id]) => id).sort();
|
|
2866
|
+
return `${shown.join(" ")} \xBB ${menu.join(" ")}`;
|
|
2867
|
+
}
|
|
2868
|
+
function endsIn(se, l, before, after) {
|
|
2869
|
+
const { e, axis } = se;
|
|
2870
|
+
const at = (id) => {
|
|
2871
|
+
const it = l.items[id];
|
|
2872
|
+
return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
|
|
2873
|
+
};
|
|
2874
|
+
const rb = before ? at(before) : void 0;
|
|
2875
|
+
const ra = after ? at(after) : void 0;
|
|
2876
|
+
if (rb === null || ra === null) return null;
|
|
2877
|
+
const el = l.edges[e.id]?.rect ?? se.drawn;
|
|
2878
|
+
const gap = nonNeg(e.gap);
|
|
2879
|
+
return {
|
|
2880
|
+
a: before && rb ? lo(rb, axis) + len(rb, axis) - slackOf(se.state, before, axis, rb) + gap : lo(el, axis) + nonNeg(e.pad?.start),
|
|
2881
|
+
// (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
|
|
2882
|
+
b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
|
|
2883
|
+
};
|
|
2884
|
+
}
|
|
2885
|
+
function slideRoom(se, before, after, preceding, w) {
|
|
2886
|
+
const { state, dragged, e, axis } = se;
|
|
2887
|
+
const zoneOf2 = (id) => zoneIn2(se.base, id);
|
|
2888
|
+
const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
|
|
2889
|
+
const atOf = (zone) => preceding.filter((id) => zoneOf2(id) === zone).length;
|
|
2890
|
+
const probe = (() => {
|
|
2891
|
+
const zone = zones[0];
|
|
2892
|
+
if (!zone) return null;
|
|
2893
|
+
const moved = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
|
|
2894
|
+
if (moved === state) return null;
|
|
2895
|
+
const l = solveLanded(markUsed(moved, dragged), dragged, se.prev);
|
|
2896
|
+
const landed = l.items[dragged];
|
|
2897
|
+
if (!landed || landed.inMenu || landed.edge !== e.id) return null;
|
|
2898
|
+
const n = neighbors(l, e.id, dragged, axis);
|
|
2899
|
+
if (n.before !== (before ?? "^") || n.next !== (after ?? "$")) return null;
|
|
2900
|
+
const r = endsIn(se, l, before, after);
|
|
2901
|
+
return r && { ...r, w: len(landed.rect, axis), layout: l };
|
|
2902
|
+
})();
|
|
2903
|
+
const seen = endsIn(se, se.base, before, after);
|
|
2904
|
+
const width = probe?.w ?? w;
|
|
2905
|
+
if (!probe && !seen || width === void 0) return null;
|
|
2906
|
+
const pushed = (id, side) => !!id && !!probe && givesWay(se.base.items[id], probe.layout.items[id], e.id, side, (r) => [lo(r, axis), lo(r, axis) + len(r, axis) - slackOf(state, id, axis, r)]) === "moves";
|
|
2907
|
+
const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : (seen ?? probe).a;
|
|
2908
|
+
const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : (seen ?? probe).b;
|
|
2909
|
+
return { before, after, a, b, w: width, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + width), ...probe ? { place: placeOf(se, probe.layout) } : {} };
|
|
2910
|
+
}
|
|
2911
|
+
function landsAt(se, place, x0) {
|
|
2912
|
+
const { state, dragged, axis } = se;
|
|
2913
|
+
const moved = moveTo(state, dragged, place);
|
|
2914
|
+
if (moved === state) return null;
|
|
2915
|
+
const next = markUsed(moved, dragged);
|
|
2916
|
+
const layout = solveLanded(next, dragged, se.prev);
|
|
2917
|
+
const landed = layout.items[dragged];
|
|
2918
|
+
if (!landed || landed.inMenu || landed.edge !== se.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
|
|
2919
|
+
const kept = (f) => {
|
|
2920
|
+
const it = layout.items[f.id];
|
|
2921
|
+
if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
|
|
2922
|
+
return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
|
|
2923
|
+
};
|
|
2924
|
+
if (!se.fixed.every(kept)) return null;
|
|
2925
|
+
return { next, layout };
|
|
2926
|
+
}
|
|
2927
|
+
function slideLand(se, room, x0) {
|
|
2928
|
+
const near = x0 + room.w / 2 < se.middle ? "start" : "end";
|
|
2929
|
+
for (const zone of [near, near === "start" ? "end" : "start"]) {
|
|
2930
|
+
if (!room.zones.includes(zone)) continue;
|
|
2931
|
+
const space = room.spaceAt(zone, x0);
|
|
2932
|
+
if (space < -EPS17) continue;
|
|
2933
|
+
const place = { edge: se.e.id, zone, at: room.atOf(zone), space: Math.max(0, space) };
|
|
2934
|
+
const hit = landsAt(se, place, x0);
|
|
2935
|
+
if (hit && (room.place === void 0 || placeOf(se, hit.layout) === room.place)) return { place, result: { state: hit.next, layout: hit.layout } };
|
|
2936
|
+
}
|
|
2937
|
+
return null;
|
|
2938
|
+
}
|
|
2939
|
+
function slideRange(se, room, sample) {
|
|
2940
|
+
const memo2 = /* @__PURE__ */ new Map();
|
|
2941
|
+
const land = (x0) => {
|
|
2942
|
+
if (!memo2.has(x0)) memo2.set(x0, slideLand(se, room, x0));
|
|
2943
|
+
return memo2.get(x0);
|
|
2944
|
+
};
|
|
2945
|
+
const tries = rangeTries(room.a, room.b, room.w, sample);
|
|
2946
|
+
const from = tries.find((x0) => !!land(x0));
|
|
2947
|
+
if (from === void 0) return null;
|
|
2948
|
+
const to = [...tries].reverse().find((x0) => x0 <= from || !!land(x0));
|
|
2949
|
+
const start = land(from);
|
|
2950
|
+
const shape = start.result.layout.items[se.dragged].rect;
|
|
2951
|
+
const at = (x0) => se.axis === "x" ? rect14(x0, shape.y, room.w, shape.height) : rect14(shape.x, x0, shape.width, room.w);
|
|
2952
|
+
const nearest = (x0) => {
|
|
2953
|
+
const order = tries.map((t, i) => ({ t, i })).sort((p, q) => Math.abs(p.t - x0) - Math.abs(q.t - x0) || p.i - q.i);
|
|
2954
|
+
return land(order.find(({ t }) => !!land(t)).t);
|
|
2955
|
+
};
|
|
2956
|
+
return { from, to, first: at(from), last: at(to), at, start, land, nearest };
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
// src/targets/tiles.ts
|
|
2777
2960
|
function tilerOf(spec) {
|
|
2778
2961
|
const data = EDGE_KINDS[spec.kind];
|
|
2779
2962
|
const v = spec.vertical;
|
|
2780
2963
|
const band = (a, b, after) => {
|
|
2781
2964
|
const [c0, c1] = spec.across(after);
|
|
2782
|
-
return v ?
|
|
2965
|
+
return v ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
|
|
2783
2966
|
};
|
|
2784
2967
|
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
2785
2968
|
const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
@@ -2787,10 +2970,10 @@ function tilerOf(spec) {
|
|
|
2787
2970
|
const h = t.hit;
|
|
2788
2971
|
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
2789
2972
|
const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
|
|
2790
|
-
const part = (a, b) => v ?
|
|
2973
|
+
const part = (a, b) => v ? rect15(a, h.y, b - a, h.height) : rect15(h.x, a, h.width, b - a);
|
|
2791
2974
|
const beyond = less([[h0, h1]], [spec.owned]);
|
|
2792
2975
|
if (beyond.length === 0) return [t];
|
|
2793
|
-
if (c1 - c0 <=
|
|
2976
|
+
if (c1 - c0 <= EPS18) return [{ ...t, order: data.overreach }];
|
|
2794
2977
|
const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
|
|
2795
2978
|
return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
|
|
2796
2979
|
};
|
|
@@ -2804,7 +2987,7 @@ function wholeRefusal(c, spec) {
|
|
|
2804
2987
|
const data = EDGE_KINDS[spec.kind];
|
|
2805
2988
|
return { edge: spec.id, spec, edgeKind: spec.kind, vertical: spec.vertical, zone: "start", hit, kind: "refuse", id: "", order: data.layer, priority: data.priority, keep: null, reason: "not-accepted", whole: true };
|
|
2806
2989
|
}
|
|
2807
|
-
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a >
|
|
2990
|
+
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS18);
|
|
2808
2991
|
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
2809
2992
|
const reserved = spec.reserved;
|
|
2810
2993
|
const lines = mine.map((s) => s.line);
|
|
@@ -2813,53 +2996,54 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
|
2813
2996
|
const free = less([[z.a, z.b]], reserved);
|
|
2814
2997
|
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
2815
2998
|
const spread = (x) => {
|
|
2816
|
-
if (hi - lo2 <=
|
|
2999
|
+
if (hi - lo2 <= EPS18 || freeLen <= EPS18) return x;
|
|
2817
3000
|
let d = (x - lo2) / (hi - lo2) * freeLen;
|
|
2818
3001
|
for (const [a, b] of free) {
|
|
2819
|
-
if (d <= b - a +
|
|
3002
|
+
if (d <= b - a + EPS18) return a + Math.min(d, b - a);
|
|
2820
3003
|
d -= b - a;
|
|
2821
3004
|
}
|
|
2822
3005
|
return free[free.length - 1][1];
|
|
2823
3006
|
};
|
|
2824
|
-
const past = lines.some((x) => x < z.a -
|
|
3007
|
+
const past = lines.some((x) => x < z.a - EPS18 || x > z.b + EPS18);
|
|
2825
3008
|
const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
|
|
2826
3009
|
const proj = (x) => {
|
|
2827
3010
|
const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
|
|
2828
3011
|
const p = own ? nearer(q, own) : q;
|
|
2829
|
-
if (pieces.some(([a, b]) => p >= a -
|
|
3012
|
+
if (pieces.some(([a, b]) => p >= a - EPS18 && p <= b + EPS18)) return p;
|
|
2830
3013
|
return pieces.map(([a, b]) => Math.min(Math.max(p, a), b)).reduce((m, y) => Math.abs(y - p) < Math.abs(m - p) ? y : m);
|
|
2831
3014
|
};
|
|
2832
|
-
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) <
|
|
2833
|
-
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa -
|
|
3015
|
+
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS18 || Math.abs(s.line - own[1]) < EPS18);
|
|
3016
|
+
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS18 && s.line <= pb + EPS18 : proj(s.line) >= pa - EPS18 && proj(s.line) <= pb + EPS18).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
|
|
2834
3017
|
const projected = inPiece.map((s) => proj(s.line));
|
|
2835
|
-
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <=
|
|
3018
|
+
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS18) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
|
|
2836
3019
|
return { inPiece, at };
|
|
2837
3020
|
}
|
|
2838
3021
|
function reachStrips(c, spec, room, ends) {
|
|
2839
|
-
const inEdge = (s) => !!ends && s[0] < ends[1] -
|
|
3022
|
+
const inEdge = (s) => !!ends && s[0] < ends[1] - EPS18 && s[1] > ends[0] + EPS18;
|
|
2840
3023
|
const pieces = room.filter(inEdge);
|
|
2841
3024
|
if (!ends || pieces.length === 0) return { pieces: [...room], before: [], after: [] };
|
|
2842
3025
|
const [c0, c1] = spec.across();
|
|
2843
|
-
const bandOf2 = (a, b) => spec.vertical ?
|
|
3026
|
+
const bandOf2 = (a, b) => spec.vertical ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
|
|
2844
3027
|
const across2 = c.state.edges.filter((e) => axisOf(e.side) === "column" !== spec.vertical).map((e) => c.now.edges[e.id]);
|
|
2845
|
-
const drawnBetween = (a, b) => b - a >
|
|
3028
|
+
const drawnBetween = (a, b) => b - a > EPS18 && across2.some((e) => !!e && e.cross > EPS18 && area4(e.rect) > EPS18 && overlaps4(e.rect, bandOf2(a, b)));
|
|
2846
3029
|
const first = pieces[0][0];
|
|
2847
3030
|
const last = pieces[pieces.length - 1][1];
|
|
2848
3031
|
return {
|
|
2849
3032
|
pieces,
|
|
2850
|
-
before: room.filter((s) => s[1] <= ends[0] +
|
|
2851
|
-
after: room.filter((s) => s[0] >= ends[1] -
|
|
3033
|
+
before: room.filter((s) => s[1] <= ends[0] + EPS18 && !drawnBetween(s[1], first)),
|
|
3034
|
+
after: room.filter((s) => s[0] >= ends[1] - EPS18 && !drawnBetween(last, s[0]))
|
|
2852
3035
|
};
|
|
2853
3036
|
}
|
|
2854
|
-
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
3037
|
+
function tileEdge(c, spec, { cuts, bodies }, lost, slides) {
|
|
2855
3038
|
const whole = wholeRefusal(c, spec);
|
|
2856
3039
|
if (whole) return [whole];
|
|
2857
3040
|
const data = EDGE_KINDS[spec.kind];
|
|
2858
3041
|
const v = spec.vertical;
|
|
3042
|
+
const halves = !spec.edge || cutsByHalves(spec.edge);
|
|
2859
3043
|
const own = spec.own ? v ? [spec.own.y, spec.own.y + spec.own.height] : [spec.own.x, spec.own.x + spec.own.width] : null;
|
|
2860
3044
|
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
2861
3045
|
const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
|
|
2862
|
-
const alongLimit = drawn && (v ? drawn.height : drawn.width) >
|
|
3046
|
+
const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS18 ? v ? rect15(-1e9, drawn.y, 2e9, drawn.height) : rect15(drawn.x, -1e9, drawn.width, 2e9) : null;
|
|
2863
3047
|
const refused = (zone, hit, reason) => {
|
|
2864
3048
|
const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
|
|
2865
3049
|
const shown = inEdge && meet(inEdge, c.state.stage);
|
|
@@ -2868,27 +3052,52 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2868
3052
|
const slots = distinctSlots(c, spec.slots);
|
|
2869
3053
|
const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
|
|
2870
3054
|
const last = acc[acc.length - 1];
|
|
2871
|
-
if (last && a <= last[1] +
|
|
3055
|
+
if (last && a <= last[1] + EPS18) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
|
|
2872
3056
|
else acc.push([a, b]);
|
|
2873
3057
|
return acc;
|
|
2874
3058
|
}, []);
|
|
2875
|
-
const wedged = (line) => runs.some(([a, b]) => line > a +
|
|
3059
|
+
const wedged = (line) => runs.some(([a, b]) => line > a + EPS18 && line < b - EPS18);
|
|
2876
3060
|
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
2877
3061
|
const ends = alongLimit && drawn ? v ? [drawn.y, drawn.y + drawn.height] : [drawn.x, drawn.x + drawn.width] : null;
|
|
2878
3062
|
const out = [];
|
|
3063
|
+
const slotSpans = [];
|
|
3064
|
+
let ownKept = null;
|
|
3065
|
+
const ownRect = landedLayout(c.state, c.now, c.dragged, c.prev).items[c.dragged]?.rect ?? spec.own ?? void 0;
|
|
3066
|
+
const movesOthers = (s) => Object.entries(c.base.items).some(([id, it]) => {
|
|
3067
|
+
if (id === c.dragged || it.edge !== spec.id || it.inMenu) return false;
|
|
3068
|
+
const now = s.result.layout.items[id];
|
|
3069
|
+
return !now || Math.abs(now.rect.x - it.rect.x) > 0.5 || Math.abs(now.rect.y - it.rect.y) > 0.5;
|
|
3070
|
+
});
|
|
3071
|
+
const axis = v ? "y" : "x";
|
|
3072
|
+
const span = (r) => v ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
3073
|
+
const orderIn = (l) => Object.entries(l.items).filter(([, it]) => it.edge === spec.id && !it.inMenu && !it.floating && area4(it.rect) > EPS18).sort(([, p], [, q]) => span(p.rect)[0] - span(q.rect)[0]).map(([id]) => id).join(" ");
|
|
3074
|
+
const homeOrder = orderIn(c.now);
|
|
3075
|
+
const nearHome = (s) => {
|
|
3076
|
+
if (halves || s.home || !spec.own || !ownRect || c.now.items[c.dragged]?.inMenu) return false;
|
|
3077
|
+
const l = s.result.layout.items[c.dragged]?.rect;
|
|
3078
|
+
return !!l && Math.abs((v ? l.y : l.x) - (v ? ownRect.y : ownRect.x)) < c.slack && movesOthers(s) && orderIn(s.result.layout) !== homeOrder;
|
|
3079
|
+
};
|
|
3080
|
+
const landingOf = (s) => s.home || nearHome(s) ? ownRect : s.result.layout.items[c.dragged]?.rect;
|
|
3081
|
+
const orders = /* @__PURE__ */ new Map();
|
|
3082
|
+
const orderOf = (s) => {
|
|
3083
|
+
let k = orders.get(s);
|
|
3084
|
+
if (k === void 0) orders.set(s, k = s.home || nearHome(s) ? homeOrder : orderIn(s.result.layout));
|
|
3085
|
+
return k;
|
|
3086
|
+
};
|
|
3087
|
+
const stretchesOf = [];
|
|
2879
3088
|
for (const z of spec.zones) {
|
|
2880
|
-
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a >
|
|
3089
|
+
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS18);
|
|
2881
3090
|
const { pieces, before, after } = reachStrips(c, spec, own ? less(room, [own]) : room, ends);
|
|
2882
3091
|
if (!hasRoom(pieces, bodies)) continue;
|
|
2883
3092
|
const lined = slots.flatMap((s) => spec.holds && s.home ? own ? [{ ...s, line: own[0] }, { ...s, line: own[1] }] : [] : [s]);
|
|
2884
|
-
const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach +
|
|
3093
|
+
const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS18 && a < s.line + data.reach - EPS18));
|
|
2885
3094
|
const reason = spec.refuse(z.zone);
|
|
2886
3095
|
for (const [k, [pa, pb]] of pieces.entries()) {
|
|
2887
3096
|
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
2888
3097
|
const stripsOf = (i) => [...k === 0 && i === 0 ? before : [], ...k === pieces.length - 1 && i === inPiece.length - 1 ? after : []];
|
|
2889
3098
|
if (inPiece.length === 0) {
|
|
2890
3099
|
const lone = (reason === "no-room" || reason === "too-thick") && mine.length === 0 && slots.some((s) => s.zone === z.zone && s.home);
|
|
2891
|
-
const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach +
|
|
3100
|
+
const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS18 && pa < s.line + data.reach - EPS18);
|
|
2892
3101
|
const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
|
|
2893
3102
|
if (joins.length > 0) {
|
|
2894
3103
|
const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
|
|
@@ -2899,47 +3108,144 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2899
3108
|
if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? "own-place" : reason));
|
|
2900
3109
|
continue;
|
|
2901
3110
|
}
|
|
2902
|
-
const
|
|
3111
|
+
const meets = [];
|
|
3112
|
+
for (let i = 1; i < inPiece.length; i++) {
|
|
2903
3113
|
const [lo2, hi] = [at[i - 1], at[i]];
|
|
2904
|
-
const between = spec.cards.filter(([
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
3114
|
+
const between = spec.cards.filter(([u2, w2]) => u2 >= inPiece[i - 1].line - EPS18 && w2 <= inPiece[i].line + EPS18);
|
|
3115
|
+
const la = landingOf(inPiece[i - 1]);
|
|
3116
|
+
const lb = landingOf(inPiece[i]);
|
|
3117
|
+
const [u, w] = between[0] ?? [NaN, NaN];
|
|
3118
|
+
const mid3 = between.length === 1 ? aimCut(la ?? rect15(0, 0, 0, 0), lb ?? rect15(0, 0, 0, 0), v ? "y" : "x", 0.5, 0, v ? rect15(0, u, 0, w - u) : rect15(u, 0, w - u, 0)) : NaN;
|
|
3119
|
+
meets[i] = mid3 > lo2 + EPS18 && mid3 < hi - EPS18 ? mid3 : (lo2 + hi) / 2;
|
|
3120
|
+
}
|
|
3121
|
+
const meet2 = (i) => meets[i];
|
|
2908
3122
|
inPiece.forEach((s, i) => {
|
|
2909
3123
|
const p = at[i];
|
|
2910
3124
|
const lim = data.virtual ? Infinity : data.reach;
|
|
2911
|
-
const
|
|
2912
|
-
const
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3125
|
+
const a0 = Math.max(i === 0 ? pa : meet2(i), p - lim);
|
|
3126
|
+
const b0 = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
|
|
3127
|
+
stretchesOf.push({ s, a: a0, b: b0, make: (a, b) => makeTiles(a, b) });
|
|
3128
|
+
const makeTiles = (a, b) => {
|
|
3129
|
+
if (b - a <= EPS18) {
|
|
3130
|
+
if (s.ok && !s.home) lost.push(s.id);
|
|
3131
|
+
return;
|
|
3132
|
+
}
|
|
3133
|
+
if (!hasRoom([[a, b]], bodies)) return;
|
|
3134
|
+
const homeTile = (id, u, w, line) => {
|
|
3135
|
+
const hit = band(u, w, s.home ? s.result.layout : void 0);
|
|
3136
|
+
return tile(z.zone, hit, { kind: "home", id, order: data.layer, priority: spec.homePriority ?? data.priority, keep: keepAt(Math.min(Math.max(line, u), w), hit), place: { kind: "home" } });
|
|
3137
|
+
};
|
|
3138
|
+
if (s.home || nearHome(s)) {
|
|
3139
|
+
for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.home ? s.id : homeSlot?.id ?? s.id, u, w, p)));
|
|
3140
|
+
return;
|
|
3141
|
+
}
|
|
3142
|
+
const faced = halves && homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS18 && u < b - EPS18) : [];
|
|
3143
|
+
for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
|
|
3144
|
+
for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
|
|
3145
|
+
const line = Math.min(Math.max(p, u), w);
|
|
3146
|
+
const hit = band(u, w, s.result.layout);
|
|
3147
|
+
if (!s.ok) {
|
|
3148
|
+
out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
|
|
3149
|
+
continue;
|
|
3150
|
+
}
|
|
3151
|
+
slotSpans.push([u, w]);
|
|
3152
|
+
out.push(...split(tile(z.zone, hit, { kind: "slot", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged].rect })));
|
|
3153
|
+
}
|
|
2921
3154
|
};
|
|
2922
|
-
if (s.home) {
|
|
2923
|
-
for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.id, u, w, p)));
|
|
2924
|
-
return;
|
|
2925
|
-
}
|
|
2926
|
-
const faced = homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS16 && u < b - EPS16) : [];
|
|
2927
|
-
for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
|
|
2928
|
-
for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
|
|
2929
|
-
const line = Math.min(Math.max(p, u), w);
|
|
2930
|
-
const hit = band(u, w, s.result.layout);
|
|
2931
|
-
if (!s.ok) out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
|
|
2932
|
-
else out.push(...split(tile(z.zone, hit, { kind: "slot", id: s.id, order: data.layer, priority: data.priority, keep: keepAt(line, hit), place: s.place, result: s.result, marker: spec.marker(s), slot: s.result.layout.items[c.dragged].rect })));
|
|
2933
|
-
}
|
|
2934
3155
|
});
|
|
2935
3156
|
}
|
|
2936
3157
|
}
|
|
2937
|
-
if (
|
|
3158
|
+
if (!halves) {
|
|
3159
|
+
const ownStretch = own && homeSlot ? [{ s: homeSlot, a: own[0], b: own[1], make: () => void 0 }] : [];
|
|
3160
|
+
const all = [...stretchesOf, ...ownStretch];
|
|
3161
|
+
const neighborsIn = (order) => {
|
|
3162
|
+
const ids = order.split(" ");
|
|
3163
|
+
const k = ids.indexOf(c.dragged);
|
|
3164
|
+
return k < 0 ? null : { ...k > 0 ? { before: ids[k - 1] } : {}, ...k + 1 < ids.length ? { after: ids[k + 1] } : {} };
|
|
3165
|
+
};
|
|
3166
|
+
const edgeRect = c.base.edges[spec.id]?.rect ?? drawn;
|
|
3167
|
+
const slideEdge = spec.edge && edgeRect ? { state: c.state, dragged: c.dragged, e: spec.edge, axis, base: c.base, drawn: edgeRect, middle: (span(edgeRect)[0] + span(edgeRect)[1]) / 2, fixed: onEdge(c.base, spec.id, c.dragged, axis).filter((o) => c.state.items[o.id]?.fixed), prev: c.prev } : null;
|
|
3168
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
3169
|
+
const rangeOf = (order) => {
|
|
3170
|
+
if (ranges.has(order)) return ranges.get(order);
|
|
3171
|
+
const key = `${spec.id} ${order}`;
|
|
3172
|
+
const known = c.slideRanges.get(key);
|
|
3173
|
+
const r = known !== void 0 ? known : (() => {
|
|
3174
|
+
const n = neighborsIn(order);
|
|
3175
|
+
const ids = order.split(" ");
|
|
3176
|
+
const room = n && slideEdge ? slideRoom(slideEdge, n.before, n.after, ids.slice(0, ids.indexOf(c.dragged))) : null;
|
|
3177
|
+
const range = room && slideEdge ? slideRange(slideEdge, room, c.slack > 0 ? 2 * c.slack : SPOT_PITCH) : null;
|
|
3178
|
+
return room && range && range.to - range.from >= 1 ? { before: n?.before, after: n?.after, from: range.from, to: range.to, w: room.w, first: range.first, last: range.last } : null;
|
|
3179
|
+
})();
|
|
3180
|
+
c.slideRanges.set(key, r);
|
|
3181
|
+
ranges.set(order, r);
|
|
3182
|
+
if (r && slides) slides.push({ edge: spec.id, ...r });
|
|
3183
|
+
return r;
|
|
3184
|
+
};
|
|
3185
|
+
const rangeFor = (s) => {
|
|
3186
|
+
const l = landingOf(s);
|
|
3187
|
+
const r = l ? rangeOf(orderOf(s)) : null;
|
|
3188
|
+
const [l0, l1] = l ? span(l) : [NaN, NaN];
|
|
3189
|
+
return r && Math.abs(l1 - l0 - r.w) <= 1 && l0 >= r.from - 1 && l0 <= r.to + 1 ? r : null;
|
|
3190
|
+
};
|
|
3191
|
+
const firstOf = (s) => rangeFor(s)?.first ?? landingOf(s);
|
|
3192
|
+
const lastOf = (s) => rangeFor(s)?.last ?? landingOf(s);
|
|
3193
|
+
const mid3 = (r) => (span(r)[0] + span(r)[1]) / 2;
|
|
3194
|
+
const besideZone = (s) => {
|
|
3195
|
+
const before = neighborsIn(orderOf(s))?.before;
|
|
3196
|
+
return s.place.kind === "gap" && s.place.zone === zoneIn2(c.base, before) ? 0 : 1;
|
|
3197
|
+
};
|
|
3198
|
+
const inMenu = !!c.now.items[c.dragged]?.inMenu;
|
|
3199
|
+
const lands = all.filter((r) => (r.s.ok || r.s.home) && !!landingOf(r.s) && !(inMenu && r.s.home));
|
|
3200
|
+
const sorted = [...lands].sort((p, q) => mid3(firstOf(p.s)) - mid3(firstOf(q.s)) || (p.s.home ? -1 : q.s.home ? 1 : 0) || besideZone(p.s) - besideZone(q.s) || p.a - q.a);
|
|
3201
|
+
const sameAt = (p, q) => span(landingOf(p)).every((x, n) => Math.abs(x - span(landingOf(q))[n]) < 0.5);
|
|
3202
|
+
const runs2 = [];
|
|
3203
|
+
const dropped = [];
|
|
3204
|
+
for (const r of sorted) {
|
|
3205
|
+
const last = runs2.at(-1);
|
|
3206
|
+
if (last && orderOf(last[0].s) === orderOf(r.s)) {
|
|
3207
|
+
last.push(r);
|
|
3208
|
+
continue;
|
|
3209
|
+
}
|
|
3210
|
+
if (runs2.some((run) => run.some((x) => !rangeFor(x.s) && !rangeFor(r.s) && sameAt(x.s, r.s)))) dropped.push(r);
|
|
3211
|
+
else runs2.push([r]);
|
|
3212
|
+
}
|
|
3213
|
+
const facing = (run, end) => run.map((r) => end ? lastOf(r.s) : firstOf(r.s)).reduce((m, x) => end ? span(x)[1] > span(m)[1] ? x : m : span(x)[0] < span(m)[0] ? x : m);
|
|
3214
|
+
const cutOf = (p, q) => aimCut(facing(p, true), facing(q, false), axis, c.share[axis], c.slack);
|
|
3215
|
+
const bandStart = ends?.[0] ?? -Infinity;
|
|
3216
|
+
const bandEnd = ends?.[1] ?? Infinity;
|
|
3217
|
+
const cuts2 = crossFreeCuts(runs2.length, (i, j) => cutOf(runs2[i], runs2[j]), (i) => runs2[i].some((x) => x.s.home), bandStart, bandEnd);
|
|
3218
|
+
const spans = [];
|
|
3219
|
+
runs2.forEach((run, i) => {
|
|
3220
|
+
const cp = i > 0 ? cuts2[i - 1] : Math.min(...run.map((r) => r.a));
|
|
3221
|
+
const cn = i + 1 < runs2.length ? cuts2[i] : Math.max(...run.map((r) => r.b));
|
|
3222
|
+
for (const r of run) [r.a, r.b] = [Math.min(Math.max(r.a, cp), cn), Math.max(Math.min(r.b, cn), cp)];
|
|
3223
|
+
const held = run.filter((r) => r.b - r.a > EPS18).sort((p, q) => p.a - q.a);
|
|
3224
|
+
if (held.length === 0) {
|
|
3225
|
+
const one = run.find((r) => !ownStretch.includes(r)) ?? run[0];
|
|
3226
|
+
[one.a, one.b] = [cp, Math.max(cp, cn)];
|
|
3227
|
+
} else {
|
|
3228
|
+
held[0].a = cp;
|
|
3229
|
+
held.at(-1).b = Math.max(cp, cn);
|
|
3230
|
+
}
|
|
3231
|
+
if (cn - cp > EPS18) spans.push([cp, cn]);
|
|
3232
|
+
});
|
|
3233
|
+
for (const r of dropped) r.a = r.b;
|
|
3234
|
+
for (const r of lands) if (r.s.ok && !r.s.home) lost.push(r.s.id);
|
|
3235
|
+
if (ownStretch[0]) ownKept = ownStretch[0].b - ownStretch[0].a > EPS18 ? [[ownStretch[0].a, ownStretch[0].b]] : [];
|
|
3236
|
+
for (const r of all.filter((x) => !lands.includes(x))) {
|
|
3237
|
+
const left = less([[r.a, r.b]], spans).filter(([u, w]) => w - u > EPS18);
|
|
3238
|
+
[r.a, r.b] = left.length ? left.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : [r.a, r.a];
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
for (const r of stretchesOf) r.make(r.a, r.b);
|
|
3242
|
+
if (own && spec.own && (ownKept === null || ownKept.length > 0)) {
|
|
2938
3243
|
const home = spec.slots.find((s) => s.home);
|
|
2939
|
-
const [
|
|
3244
|
+
const kept = ownKept ?? (halves ? [] : less([own], slotSpans).filter(([u, w]) => w - u > EPS18));
|
|
3245
|
+
const [a, b] = kept.length > 0 ? kept.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : own;
|
|
2940
3246
|
const h = band(a, b);
|
|
2941
3247
|
const o = spec.own;
|
|
2942
|
-
const hit = v ?
|
|
3248
|
+
const hit = v ? rect15(Math.min(h.x, o.x), a, Math.max(h.x + h.width, o.x + o.width) - Math.min(h.x, o.x), b - a) : rect15(a, Math.min(h.y, o.y), b - a, Math.max(h.y + h.height, o.y + o.height) - Math.min(h.y, o.y));
|
|
2943
3249
|
out.push(tile(home?.zone ?? zoneOf(c.state.items[c.dragged]), hit, { kind: "home", id: home ? home.id : targetId({ kind: "home", item: c.dragged }), order: 0, priority: home ? data.priority : 1, keep: null, place: { kind: "home" } }));
|
|
2944
3250
|
}
|
|
2945
3251
|
return out;
|
|
@@ -2957,7 +3263,7 @@ function placeReach(t, pieces, placed, landed, gone) {
|
|
|
2957
3263
|
if (at.length === 0 && gone.has(of)) {
|
|
2958
3264
|
const line = t.vertical ? of.keep.y : of.keep.x;
|
|
2959
3265
|
const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
2960
|
-
const on = whole.filter((p) => t.vertical ? p.y <= line +
|
|
3266
|
+
const on = whole.filter((p) => t.vertical ? p.y <= line + EPS18 && line <= p.y + p.height + EPS18 : p.x <= line + EPS18 && line <= p.x + p.width + EPS18);
|
|
2961
3267
|
const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area4(p) > area4(a) ? p : a, null);
|
|
2962
3268
|
if (kept) {
|
|
2963
3269
|
placed.push({ ...of, hit: kept });
|
|
@@ -2970,10 +3276,10 @@ function placeReach(t, pieces, placed, landed, gone) {
|
|
|
2970
3276
|
for (let k = 0; k < cover.length; k++) {
|
|
2971
3277
|
const h = cover[k];
|
|
2972
3278
|
const joint = pieces.find(
|
|
2973
|
-
(p) => t.vertical ? p.y <= h.y +
|
|
3279
|
+
(p) => t.vertical ? p.y <= h.y + EPS18 && p.y + p.height >= h.y + h.height - EPS18 && (Math.abs(p.x - h.x - h.width) < EPS18 || Math.abs(p.x + p.width - h.x) < EPS18) : p.x <= h.x + EPS18 && p.x + p.width >= h.x + h.width - EPS18 && (Math.abs(p.y - h.y - h.height) < EPS18 || Math.abs(p.y + p.height - h.y) < EPS18)
|
|
2974
3280
|
);
|
|
2975
3281
|
if (!joint) continue;
|
|
2976
|
-
const merged = t.vertical ?
|
|
3282
|
+
const merged = t.vertical ? rect15(Math.min(h.x, joint.x), h.y, Math.max(h.x + h.width, joint.x + joint.width) - Math.min(h.x, joint.x), h.height) : rect15(h.x, Math.min(h.y, joint.y), h.width, Math.max(h.y + h.height, joint.y + joint.height) - Math.min(h.y, joint.y));
|
|
2977
3283
|
placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
|
|
2978
3284
|
return;
|
|
2979
3285
|
}
|
|
@@ -3041,10 +3347,10 @@ function clipTiles(tiles, own, chrome, lost) {
|
|
|
3041
3347
|
}
|
|
3042
3348
|
|
|
3043
3349
|
// src/targets/rail-strip.ts
|
|
3044
|
-
import { EPS as
|
|
3350
|
+
import { EPS as EPS20, overlaps as overlaps5, rect as rect17, subtract as subtract4 } from "@n-uf/placement";
|
|
3045
3351
|
|
|
3046
3352
|
// src/targets/virtual.ts
|
|
3047
|
-
import { EPS as
|
|
3353
|
+
import { EPS as EPS19, clamp as clamp2, rect as rect16 } from "@n-uf/placement";
|
|
3048
3354
|
function ringsOf(c, side) {
|
|
3049
3355
|
const seen = sideRings(c.state.edges, side);
|
|
3050
3356
|
const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
|
|
@@ -3057,7 +3363,7 @@ function railOuter(c, side) {
|
|
|
3057
3363
|
const windowEdge = side === "left" ? state.stage.x : state.stage.x + state.stage.width;
|
|
3058
3364
|
if (!place) return windowEdge;
|
|
3059
3365
|
const placeOuter = side === "left" ? place.x : place.x + place.width;
|
|
3060
|
-
const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter +
|
|
3366
|
+
const barOutside = Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= placeOuter + EPS19 : e.rect.x >= placeOuter - EPS19));
|
|
3061
3367
|
return barOutside ? placeOuter : windowEdge;
|
|
3062
3368
|
}
|
|
3063
3369
|
function collapsesAt(c, result, side) {
|
|
@@ -3088,13 +3394,13 @@ function columnLines(c, side, railLands) {
|
|
|
3088
3394
|
const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
|
|
3089
3395
|
const stage = c.state.stage;
|
|
3090
3396
|
const dir = side === "left" ? 1 : -1;
|
|
3091
|
-
const outside2 = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x +
|
|
3397
|
+
const outside2 = (x) => Object.values(now.edges).some((e) => e.side === side && e.rect.width > 0 && e.rect.height > 0 && (side === "left" ? e.rect.x + e.rect.width <= x + EPS19 : e.rect.x >= x - EPS19));
|
|
3092
3398
|
const railFirst = railLands && !!c.state.rails?.[side]?.accepts.includes(c.kind) && !!now.railPlaces[side] && !(now.rails[side]?.segments.length ?? 0);
|
|
3093
|
-
const
|
|
3094
|
-
const atEdge = side === "left" ? l.x <= stage.x +
|
|
3399
|
+
const placeOf2 = (l, i) => {
|
|
3400
|
+
const atEdge = side === "left" ? l.x <= stage.x + EPS19 : l.x >= stage.x + stage.width - EPS19;
|
|
3095
3401
|
if (i > 0 || outside2(l.x) || !(atEdge || railFirst)) return { line: l.x, zone: [l.x - reach, l.x + reach], owned: [l.x - place / 2, l.x + place / 2] };
|
|
3096
3402
|
const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
|
|
3097
|
-
const boundary =
|
|
3403
|
+
const boundary = clamp2(l.x, stage.x, stage.x + stage.width);
|
|
3098
3404
|
const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
|
|
3099
3405
|
const line = band0 + dir * edgePlace / 2;
|
|
3100
3406
|
const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
|
|
@@ -3103,7 +3409,7 @@ function columnLines(c, side, railLands) {
|
|
|
3103
3409
|
const most = state.columns?.[side]?.cross.max;
|
|
3104
3410
|
const tooThick = most !== void 0 && thickerThan(formsOf(state.items[dragged], "column"), most);
|
|
3105
3411
|
return lines.map((l, i) => {
|
|
3106
|
-
const p =
|
|
3412
|
+
const p = placeOf2(l, i);
|
|
3107
3413
|
return {
|
|
3108
3414
|
id: virtualEdgeId("column", side),
|
|
3109
3415
|
edge: null,
|
|
@@ -3122,7 +3428,7 @@ function columnLines(c, side, railLands) {
|
|
|
3122
3428
|
ownedAlong: p.owned,
|
|
3123
3429
|
drawn: false,
|
|
3124
3430
|
// Where the new column's edge lands: the line itself, inside the stage.
|
|
3125
|
-
marker: () =>
|
|
3431
|
+
marker: () => rect16(clamp2(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
|
|
3126
3432
|
};
|
|
3127
3433
|
});
|
|
3128
3434
|
}
|
|
@@ -3149,7 +3455,7 @@ function ownColumnRun(c, side, rail) {
|
|
|
3149
3455
|
const tiles = shown.segments.filter((s) => s.edge === edge.id).map((s) => s.rect);
|
|
3150
3456
|
if (tiles.length === 0) return null;
|
|
3151
3457
|
const top = Math.min(...tiles.map((r) => r.y));
|
|
3152
|
-
const spec = railColumnSpec(c, edge,
|
|
3458
|
+
const spec = railColumnSpec(c, edge, rect16(shown.rect.x, top, shown.rect.width, Math.max(...tiles.map((r) => r.y + r.height)) - top));
|
|
3153
3459
|
if (!spec) return null;
|
|
3154
3460
|
const stays = ({ layout }) => layout.items[dragged]?.rail === side && layout.items[dragged]?.edge === edge.id;
|
|
3155
3461
|
return { ...spec, own: null, holds: false, homePriority: EDGE_KINDS.railStop.priority, slots: spec.slots.map((s) => s.home ? { ...s, id: homeId } : { ...s, ok: s.ok && stays(s.result) }) };
|
|
@@ -3187,7 +3493,7 @@ function railStops(c, side) {
|
|
|
3187
3493
|
} else {
|
|
3188
3494
|
const firstCol = mine.find((e) => e.column === true);
|
|
3189
3495
|
const outer = railOuter(c, side);
|
|
3190
|
-
zone =
|
|
3496
|
+
zone = rect16(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
|
|
3191
3497
|
stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
|
|
3192
3498
|
}
|
|
3193
3499
|
const ownRail = now.items[dragged]?.rail === side;
|
|
@@ -3218,7 +3524,7 @@ function railStops(c, side) {
|
|
|
3218
3524
|
owned: rail && rail.segments.length > 0 ? [at.x, at.x + at.width] : side === "left" ? [at.x, at.x + Math.min(at.width, EDGE_KINDS.railStop.place)] : [at.x + at.width - Math.min(at.width, EDGE_KINDS.railStop.place), at.x + at.width],
|
|
3219
3525
|
ownedAlong: null,
|
|
3220
3526
|
drawn: !!rail && rail.segments.length > 0,
|
|
3221
|
-
marker: (s) =>
|
|
3527
|
+
marker: (s) => rect16(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
|
|
3222
3528
|
};
|
|
3223
3529
|
}
|
|
3224
3530
|
|
|
@@ -3234,11 +3540,11 @@ function columnStrip(c, side, policy) {
|
|
|
3234
3540
|
if (moved === c.state) return null;
|
|
3235
3541
|
const result = c.settle(markUsed(moved, c.dragged));
|
|
3236
3542
|
const el = result.layout.edges[edge.id];
|
|
3237
|
-
if (!el || el.rect.width <=
|
|
3543
|
+
if (!el || el.rect.width <= EPS20 || !collapsesAt(c, result, side)) return null;
|
|
3238
3544
|
const r = el.rect;
|
|
3239
3545
|
const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
|
|
3240
3546
|
const [x, w] = across(side, side === "left" ? r.x : r.x + r.width, policy.railStripWidth ?? Math.max(RAIL_STRIP_MIN, railWidth));
|
|
3241
|
-
return { side, rect:
|
|
3547
|
+
return { side, rect: rect17(x, r.y, w, r.height), slots: [{ id: targetId({ kind: "rail", side, ring: edge.ring }), place, along: [r.y, r.y + r.height], result }] };
|
|
3242
3548
|
}
|
|
3243
3549
|
function declaredStrip(c, side, policy) {
|
|
3244
3550
|
const template = c.state.columns?.[side];
|
|
@@ -3255,7 +3561,7 @@ function declaredStrip(c, side, policy) {
|
|
|
3255
3561
|
const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
|
|
3256
3562
|
return {
|
|
3257
3563
|
side,
|
|
3258
|
-
rect:
|
|
3564
|
+
rect: rect17(x, a, w, b - a),
|
|
3259
3565
|
slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
|
|
3260
3566
|
};
|
|
3261
3567
|
}
|
|
@@ -3340,7 +3646,7 @@ ${r.zone}`) ?? [], r]);
|
|
|
3340
3646
|
group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((r, n) => numbered.set(r, targetId({ kind: "refuse", edge: r.edge, zone: r.zone, n })));
|
|
3341
3647
|
const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
|
|
3342
3648
|
for (const s of strips) {
|
|
3343
|
-
const grown = s.side === "left" ?
|
|
3649
|
+
const grown = s.side === "left" ? rect17(s.rect.x, s.rect.y, s.rect.width + policy.magnet, s.rect.height) : rect17(s.rect.x - policy.magnet, s.rect.y, s.rect.width + policy.magnet, s.rect.height);
|
|
3344
3650
|
for (const sl of s.slots) {
|
|
3345
3651
|
const [a, b] = sl.along;
|
|
3346
3652
|
const slot = sl.result.layout.items[c.dragged].rect;
|
|
@@ -3348,8 +3654,8 @@ ${r.zone}`) ?? [], r]);
|
|
|
3348
3654
|
out.push({
|
|
3349
3655
|
id: sl.id,
|
|
3350
3656
|
priority: 1,
|
|
3351
|
-
hit:
|
|
3352
|
-
armedHit:
|
|
3657
|
+
hit: rect17(s.rect.x, a, s.rect.width, b - a),
|
|
3658
|
+
armedHit: rect17(grown.x, a, grown.width, b - a),
|
|
3353
3659
|
arm: "dwell",
|
|
3354
3660
|
// Armed, its room opens at once: a host that draws only a marker reads that from this one flag, as for any target.
|
|
3355
3661
|
opensRoom: true,
|
|
@@ -3370,7 +3676,7 @@ var withoutHits = (t) => {
|
|
|
3370
3676
|
function insideStrips(r, strips) {
|
|
3371
3677
|
const s = strips.find((x) => overlaps5(x.rect, r));
|
|
3372
3678
|
if (!s) return null;
|
|
3373
|
-
return s.side === "left" ?
|
|
3679
|
+
return s.side === "left" ? rect17(s.rect.x + s.rect.width, r.y, r.width, r.height) : rect17(s.rect.x - r.width, r.y, r.width, r.height);
|
|
3374
3680
|
}
|
|
3375
3681
|
function clearOfStrips(t, dragged, strips) {
|
|
3376
3682
|
return {
|
|
@@ -3381,7 +3687,7 @@ function clearOfStrips(t, dragged, strips) {
|
|
|
3381
3687
|
if (!at) return first;
|
|
3382
3688
|
let dx = 0;
|
|
3383
3689
|
for (const s of strips) {
|
|
3384
|
-
const r =
|
|
3690
|
+
const r = rect17(at.x + dx, at.y, at.width, at.height);
|
|
3385
3691
|
if (!overlaps5(r, s)) continue;
|
|
3386
3692
|
dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
|
|
3387
3693
|
}
|
|
@@ -3391,7 +3697,7 @@ function clearOfStrips(t, dragged, strips) {
|
|
|
3391
3697
|
}
|
|
3392
3698
|
|
|
3393
3699
|
// src/targets/min-hit.ts
|
|
3394
|
-
import { EPS as
|
|
3700
|
+
import { EPS as EPS21, area as area5, rect as rect18, subtract as subtract5 } from "@n-uf/placement";
|
|
3395
3701
|
function kindOf(c, t) {
|
|
3396
3702
|
const p = parseTargetId(t.id);
|
|
3397
3703
|
if (!p) return null;
|
|
@@ -3404,8 +3710,8 @@ function kindOf(c, t) {
|
|
|
3404
3710
|
return null;
|
|
3405
3711
|
}
|
|
3406
3712
|
var largest3 = (ps) => ps.reduce((a, p) => area5(p) > area5(a) ? p : a);
|
|
3407
|
-
var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across -
|
|
3408
|
-
var overlaps6 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) >
|
|
3713
|
+
var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS21 && Math.max(r.width, r.height) >= m.along - EPS21;
|
|
3714
|
+
var overlaps6 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS21 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS21;
|
|
3409
3715
|
var cut = (ps, g) => ps.flatMap((p) => subtract5(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
3410
3716
|
var piecesOf = (t) => t.hits ?? [t.hit];
|
|
3411
3717
|
var withPieces2 = (t, ps) => {
|
|
@@ -3413,22 +3719,22 @@ var withPieces2 = (t, ps) => {
|
|
|
3413
3719
|
return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
3414
3720
|
};
|
|
3415
3721
|
function growths(r, axis, d) {
|
|
3416
|
-
const [lo2, hi] = axis === "x" ? [
|
|
3722
|
+
const [lo2, hi] = axis === "x" ? [rect18(r.x - d, r.y, d, r.height), rect18(r.x + r.width, r.y, d, r.height)] : [rect18(r.x, r.y - d, r.width, d), rect18(r.x, r.y + r.height, r.width, d)];
|
|
3417
3723
|
const h = d / 2;
|
|
3418
|
-
const halves = axis === "x" ? [
|
|
3724
|
+
const halves = axis === "x" ? [rect18(r.x - h, r.y, h, r.height), rect18(r.x + r.width, r.y, h, r.height)] : [rect18(r.x, r.y - h, r.width, h), rect18(r.x, r.y + r.height, r.width, h)];
|
|
3419
3725
|
return [[lo2], [hi], halves];
|
|
3420
3726
|
}
|
|
3421
3727
|
var union = (a, gs) => {
|
|
3422
3728
|
const x0 = Math.min(a.x, ...gs.map((g) => g.x));
|
|
3423
3729
|
const y0 = Math.min(a.y, ...gs.map((g) => g.y));
|
|
3424
|
-
return
|
|
3730
|
+
return rect18(x0, y0, Math.max(a.x + a.width, ...gs.map((g) => g.x + g.width)) - x0, Math.max(a.y + a.height, ...gs.map((g) => g.y + g.height)) - y0);
|
|
3425
3731
|
};
|
|
3426
3732
|
function mayGrow(c, targets2, i, grow, minOf, zone, away) {
|
|
3427
3733
|
const s = c.state.stage;
|
|
3428
3734
|
for (const g of grow) {
|
|
3429
|
-
if (g.x < s.x -
|
|
3735
|
+
if (g.x < s.x - EPS21 || g.y < s.y - EPS21 || g.x + g.width > s.x + s.width + EPS21 || g.y + g.height > s.y + s.height + EPS21) return false;
|
|
3430
3736
|
if ([...keepClearFor(c.state, c.now, "targets"), ...away].some((r) => overlaps6(r, g))) return false;
|
|
3431
|
-
if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) >
|
|
3737
|
+
if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS21)) return false;
|
|
3432
3738
|
}
|
|
3433
3739
|
return targets2.every((o, j) => {
|
|
3434
3740
|
if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps6(p, g)))) return true;
|
|
@@ -3443,7 +3749,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
|
3443
3749
|
let best = null;
|
|
3444
3750
|
for (const [side] of growths(l, axis, d)) {
|
|
3445
3751
|
const g = side;
|
|
3446
|
-
const strip = (a, b) => axis === "x" ?
|
|
3752
|
+
const strip = (a, b) => axis === "x" ? rect18(g.x, a, g.width, b - a) : rect18(a, g.y, b - a, g.height);
|
|
3447
3753
|
const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
|
|
3448
3754
|
for (const o of targets2)
|
|
3449
3755
|
for (const p of piecesOf(o))
|
|
@@ -3463,7 +3769,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
|
3463
3769
|
}
|
|
3464
3770
|
if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
|
|
3465
3771
|
for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
|
|
3466
|
-
if (b - a < m.along -
|
|
3772
|
+
if (b - a < m.along - EPS21) break;
|
|
3467
3773
|
const r = strip(a, b);
|
|
3468
3774
|
if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area5(r) > area5(best))) best = r;
|
|
3469
3775
|
break;
|
|
@@ -3478,7 +3784,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3478
3784
|
const k = kindOf(c, t);
|
|
3479
3785
|
return k ? EDGE_KINDS[k].minHit : null;
|
|
3480
3786
|
};
|
|
3481
|
-
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width >
|
|
3787
|
+
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS21 && e.rect.height > EPS21);
|
|
3482
3788
|
for (let i = 0; i < out.length; i++) {
|
|
3483
3789
|
const t = out[i];
|
|
3484
3790
|
const m = minOf(t);
|
|
@@ -3495,7 +3801,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3495
3801
|
const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
|
|
3496
3802
|
const size = axis === "x" ? l.width : l.height;
|
|
3497
3803
|
const d = (step === "across" ? m.across : m.along) - size;
|
|
3498
|
-
if (d <=
|
|
3804
|
+
if (d <= EPS21) continue;
|
|
3499
3805
|
let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
|
|
3500
3806
|
if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
|
|
3501
3807
|
if (!grow) continue;
|
|
@@ -3506,7 +3812,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3506
3812
|
out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
|
|
3507
3813
|
}
|
|
3508
3814
|
const g0 = grow[0];
|
|
3509
|
-
const span = axis === "x" ?
|
|
3815
|
+
const span = axis === "x" ? rect18(l.x, g0.y, l.width, g0.height) : rect18(g0.x, l.y, g0.width, l.height);
|
|
3510
3816
|
const grown = union(span, grow);
|
|
3511
3817
|
const others = piecesOf(out[i]).filter((p) => p !== l);
|
|
3512
3818
|
out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
|
|
@@ -3547,12 +3853,16 @@ function emit2(c, placed) {
|
|
|
3547
3853
|
}
|
|
3548
3854
|
for (const zones of byZone.values()) for (const group of zones.values()) group.sort((a, b) => pos(a)[0] - pos(b)[0] || pos(a)[1] - pos(b)[1]).forEach((t, n) => rank.set(t, n));
|
|
3549
3855
|
let ownHome = null;
|
|
3856
|
+
let ownSlot = null;
|
|
3857
|
+
const homeTiles = [];
|
|
3550
3858
|
for (const t of placed) {
|
|
3551
3859
|
if (t.kind === "refuse") {
|
|
3552
3860
|
const n = rank.get(t);
|
|
3553
3861
|
refused.push({ id: targetId({ kind: "refuse", edge: t.edge, zone: t.zone, n }), edge: t.edge, zone: t.zone, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, reason: t.reason });
|
|
3554
3862
|
continue;
|
|
3555
3863
|
}
|
|
3864
|
+
if (t.kind === "home" && t.order === 0 && t.id !== homeId) ownSlot = t.hit;
|
|
3865
|
+
else if (t.kind === "home" && t.id !== homeId) homeTiles.push(t.hit);
|
|
3556
3866
|
if (t.kind === "home" && t.id === homeId) {
|
|
3557
3867
|
if (t.order === 0) ownHome = t.hit;
|
|
3558
3868
|
continue;
|
|
@@ -3574,27 +3884,36 @@ function emit2(c, placed) {
|
|
|
3574
3884
|
const room = t.slot && slotOverMoved(now, base, result.layout, t.slot, dragged, t.edge) ? { opensRoom: true, ...atEdge ? { roomHold: EDGE_ROOM_HOLD } : {}, ...thickens ? { roomHit: hull(t.hit, t.slot) } : {} } : {};
|
|
3575
3885
|
targets2.push({ id: t.id, priority: t.priority, hit: t.hit, ...t.hits ? { hits: t.hits } : {}, ...t.slot ? { slot: t.slot } : {}, ...t.marker ? { marker: t.marker } : {}, ...room, item: dragged, place: t.place, after: () => result });
|
|
3576
3886
|
}
|
|
3887
|
+
if (!ownHome && ownSlot) {
|
|
3888
|
+
const o = now.items[dragged]?.rect;
|
|
3889
|
+
ownHome = (o ? meet(o, ownSlot) : null) ?? ownSlot;
|
|
3890
|
+
} else if (!ownHome && homeTiles.length > 0) {
|
|
3891
|
+
const o = now.items[dragged]?.rect;
|
|
3892
|
+
const largest4 = (rs) => rs.reduce((m, r) => area6(r) > area6(m) ? r : m);
|
|
3893
|
+
const met = o ? homeTiles.flatMap((h) => meet(o, h) ?? []) : [];
|
|
3894
|
+
ownHome = largest4(met.length > 0 ? met : homeTiles);
|
|
3895
|
+
}
|
|
3577
3896
|
return { targets: targets2, refused, ownHome };
|
|
3578
3897
|
}
|
|
3579
3898
|
function hull(a, b) {
|
|
3580
3899
|
const x = Math.min(a.x, b.x);
|
|
3581
3900
|
const y = Math.min(a.y, b.y);
|
|
3582
|
-
return
|
|
3901
|
+
return rect19(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
|
|
3583
3902
|
}
|
|
3584
3903
|
var thicknessChanges = (now, after) => {
|
|
3585
3904
|
const a = now.content;
|
|
3586
3905
|
const b = after.content;
|
|
3587
|
-
return Math.abs(b.x - a.x) >
|
|
3906
|
+
return Math.abs(b.x - a.x) > EPS22 || Math.abs(b.y - a.y) > EPS22 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS22 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS22;
|
|
3588
3907
|
};
|
|
3589
3908
|
var WINDOW_EDGE_KINDS = /* @__PURE__ */ new Set(["rail", "railStop", "sideBar", "columnLine"]);
|
|
3590
|
-
var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x +
|
|
3909
|
+
var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS22 || r.x + r.width >= stage.x + stage.width - EPS22);
|
|
3591
3910
|
function slotOverMoved(now, lifted, after, slot, dragged, onto) {
|
|
3592
3911
|
const from = now.items[dragged]?.edge;
|
|
3593
3912
|
return Object.entries(now.items).some(([id, was]) => {
|
|
3594
3913
|
if (!overlaps7(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
|
|
3595
3914
|
const r = after.items[id]?.rect;
|
|
3596
3915
|
const start = (from !== void 0 && was.edge === from ? lifted.items[id]?.rect : void 0) ?? was.rect;
|
|
3597
|
-
return !!r && (Math.abs(r.x - start.x) >
|
|
3916
|
+
return !!r && (Math.abs(r.x - start.x) > EPS22 || Math.abs(r.y - start.y) > EPS22 || Math.abs(r.width - start.width) > EPS22 || Math.abs(r.height - start.height) > EPS22);
|
|
3598
3917
|
});
|
|
3599
3918
|
}
|
|
3600
3919
|
function aloneRects(tiles) {
|
|
@@ -3619,24 +3938,22 @@ function generate(state, dragged, options) {
|
|
|
3619
3938
|
const g = generateShown(shown, dragged, options, hidden);
|
|
3620
3939
|
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
3621
3940
|
const showsIn = hidden.some((e) => e.showIn !== void 0);
|
|
3622
|
-
|
|
3623
|
-
...
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
}))
|
|
3639
|
-
};
|
|
3941
|
+
const wrap = (t) => ({
|
|
3942
|
+
...t,
|
|
3943
|
+
after: (point, grab) => {
|
|
3944
|
+
const a = t.after(point, grab);
|
|
3945
|
+
if (a.state === shown) return { state, layout: showsIn ? solveLanded(state, dragged, prev) : a.layout };
|
|
3946
|
+
const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
|
|
3947
|
+
const named = !!on && namesZone(on, state.items[dragged].kind);
|
|
3948
|
+
const back = withHiddenOf(state, a.state, lent, dragged, named, rezoned);
|
|
3949
|
+
const restored = showsIn ? prune(back) : back;
|
|
3950
|
+
const ringOf = new Map(a.state.edges.map((e) => [e.id, e.ring]));
|
|
3951
|
+
const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
|
|
3952
|
+
const layout = renumbered || showsIn || rezoned.size > 0 ? solveLanded(restored, dragged, prev) : a.layout;
|
|
3953
|
+
return { state: restored, layout };
|
|
3954
|
+
}
|
|
3955
|
+
});
|
|
3956
|
+
return { ...g, targets: g.targets.map(wrap), ...g.places ? { places: g.places.map(wrap) } : {} };
|
|
3640
3957
|
}
|
|
3641
3958
|
function generateShown(state, dragged, options, hidden) {
|
|
3642
3959
|
if (Object.hasOwn(state.items, dragged) && state.items[dragged].fixed) return anchorTargets(state, dragged, options);
|
|
@@ -3649,11 +3966,12 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3649
3966
|
const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
|
|
3650
3967
|
const own = ownership(c, live, (s) => along2.get(s), (s) => aloneRects(alone.get(s)));
|
|
3651
3968
|
const lost = [];
|
|
3652
|
-
const
|
|
3969
|
+
const slides = [];
|
|
3970
|
+
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost, slides));
|
|
3653
3971
|
const ownRect = now.items[dragged];
|
|
3654
3972
|
const homeEdge = state.edges.find((e) => e.id === ownRect?.edge);
|
|
3655
3973
|
const homeHit = homeRectOf(c, null);
|
|
3656
|
-
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
|
|
3974
|
+
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0 || t.kind === "home" && t.edge === homeEdge.id && !!t.spec?.edge && !cutsByHalves(t.spec.edge)))
|
|
3657
3975
|
tiles.push({ edge: homeEdge.id, spec: null, edgeKind: edgeKindOf(state, homeEdge), vertical: axisOf(homeEdge.side) === "column", zone: zoneOf(item), order: 0, kind: "home", id: targetId({ kind: "home", item: dragged }), priority: 1, place: { kind: "home" }, hit: homeHit, keep: null });
|
|
3658
3976
|
const placed = clipTiles(tiles, own, keepClearFor(state, now, "targets"), lost);
|
|
3659
3977
|
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
@@ -3666,7 +3984,7 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3666
3984
|
const seenOwn = now.items[dragged];
|
|
3667
3985
|
const seenEdge = seenOwn?.edge ? state.edges.find((e) => e.id === seenOwn.edge) : void 0;
|
|
3668
3986
|
const grown = seenOwn && seenEdge && growsOnBar(state, seenEdge, dragged, seenOwn.form) && seenOwn.rect.width > 0 && seenOwn.rect.height > 0 ? seenOwn.rect : null;
|
|
3669
|
-
const handOf = (g) => g && grown ? { x:
|
|
3987
|
+
const handOf = (g) => g && grown ? { x: clamp3(g.x / grown.width, 0, 1) * size.width, y: clamp3(g.y / grown.height, 0, 1) * size.height } : g;
|
|
3670
3988
|
targets2.push({
|
|
3671
3989
|
id: targetId({ kind: "float", item: dragged }),
|
|
3672
3990
|
priority: 3,
|
|
@@ -3678,16 +3996,16 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3678
3996
|
place: { kind: "float" },
|
|
3679
3997
|
after(point, grab) {
|
|
3680
3998
|
const g = handOf(grab) ?? { x: size.width / 2, y: size.height / 2 };
|
|
3681
|
-
const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) :
|
|
3999
|
+
const raw = options.floatFromHeld ? heldRect(state, dragged, size, point, g) : rect19(point.x - g.x, point.y - g.y, size.width, size.height);
|
|
3682
4000
|
const first = solve(markUsed(floatAt(state, dragged, raw, options.floatOrient), dragged), prev);
|
|
3683
4001
|
const fitted = first.items[dragged]?.rect;
|
|
3684
4002
|
const at = fitted ?? raw;
|
|
3685
4003
|
const placed2 = (x, y, stays) => {
|
|
3686
|
-
const s = floatAt(state, dragged,
|
|
4004
|
+
const s = floatAt(state, dragged, rect19(x, y, size.width, size.height), options.floatOrient);
|
|
3687
4005
|
return c.settle(markUsed(stays ? { ...s, floats: s.floats.map((f) => f.id === dragged ? { ...f, stays: true } : f) } : s, dragged));
|
|
3688
4006
|
};
|
|
3689
4007
|
const hand = heldRect(state, dragged, fitted ?? size, point, g);
|
|
3690
|
-
const on = { x:
|
|
4008
|
+
const on = { x: clamp3(point.x, hand.x, hand.x + hand.width), y: clamp3(point.y, hand.y, hand.y + hand.height) };
|
|
3691
4009
|
const clear = !first.notes.some((n) => n.code === "float-covers" && n.id === dragged);
|
|
3692
4010
|
if (!fitted || clear && contains(fitted, on)) return placed2(at.x, at.y, false);
|
|
3693
4011
|
const left = placed2(hand.x, hand.y, true);
|
|
@@ -3698,7 +4016,7 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3698
4016
|
});
|
|
3699
4017
|
}
|
|
3700
4018
|
(state.blocked ?? []).forEach((b, i) => {
|
|
3701
|
-
targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit:
|
|
4019
|
+
targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit: rect19(b.x, b.y, b.width, b.height), item: dragged, place: { kind: "none" }, after: homeAfter });
|
|
3702
4020
|
});
|
|
3703
4021
|
const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
|
|
3704
4022
|
const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
|
|
@@ -3719,15 +4037,22 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3719
4037
|
for (const t of [...alone.values()].flat()) if (t.kind !== "refuse" && t.id) zones.set(t.id, [...zones.get(t.id) ?? [], t.hit]);
|
|
3720
4038
|
const bounds = stageOf(state);
|
|
3721
4039
|
const held = withMinHit(c, layered.targets, layered.refusals, zones).map((t) => t.roomHit && t.slot ? { ...t, roomHit: hull(t.hit, t.slot) } : t);
|
|
3722
|
-
|
|
4040
|
+
const lostSet = new Set(lostIds);
|
|
4041
|
+
const places = live.flatMap(
|
|
4042
|
+
(spec) => spec.slots.filter((s) => lostSet.has(s.id) && s.ok && !s.home && s.place.kind === "gap" && !!s.result.layout.items[dragged]).map((s) => {
|
|
4043
|
+
const landed = s.result.layout.items[dragged].rect;
|
|
4044
|
+
return { id: s.id, priority: EDGE_KINDS[spec.kind].priority, hit: landed, slot: landed, marker: spec.marker(s), item: dragged, place: s.place, after: () => s.result };
|
|
4045
|
+
})
|
|
4046
|
+
).filter((t, i, all) => all.findIndex((x) => x.id === t.id) === i);
|
|
4047
|
+
return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones, slides, ...places.length ? { places } : {} };
|
|
3723
4048
|
}
|
|
3724
|
-
var stageOf = (state) =>
|
|
4049
|
+
var stageOf = (state) => rect19(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
|
|
3725
4050
|
function targets(state, dragged, options = {}) {
|
|
3726
4051
|
return generate(state, dragged, options).targets;
|
|
3727
4052
|
}
|
|
3728
4053
|
function targetsAndRefusals(state, dragged, options = {}) {
|
|
3729
4054
|
const g = generate(state, dragged, options);
|
|
3730
|
-
return { targets: g.targets, refusals: g.refusals };
|
|
4055
|
+
return { targets: g.targets, refusals: g.refusals, places: g.places ?? [] };
|
|
3731
4056
|
}
|
|
3732
4057
|
function refusals(state, dragged, options = {}) {
|
|
3733
4058
|
return generate(state, dragged, options).refusals;
|
|
@@ -3757,10 +4082,11 @@ function stopsKey(dragged, o) {
|
|
|
3757
4082
|
prev = layoutIds.get(o.previous) ?? nextLayoutId++;
|
|
3758
4083
|
layoutIds.set(o.previous, prev);
|
|
3759
4084
|
}
|
|
3760
|
-
return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);
|
|
4085
|
+
return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null, o.grab ? [o.grab.x, o.grab.y] : null, o.pitch ?? null]);
|
|
3761
4086
|
}
|
|
3762
4087
|
function orderedStops(state, dragged, options) {
|
|
3763
|
-
const
|
|
4088
|
+
const g = generate(state, dragged, options);
|
|
4089
|
+
const list = [...g.targets, ...g.places ?? []].filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
|
|
3764
4090
|
const sideOf = (t) => {
|
|
3765
4091
|
const p = t.place;
|
|
3766
4092
|
if (p.kind === "float") return "float";
|
|
@@ -3776,43 +4102,27 @@ function orderedStops(state, dragged, options) {
|
|
|
3776
4102
|
const rank = side === "float" ? 4 : SIDE_RANK[side];
|
|
3777
4103
|
return side === "left" ? [rank, cx, cy] : side === "right" ? [rank, -cx, cy] : [rank, cy * (side === "bottom" ? -1 : 1), cx];
|
|
3778
4104
|
};
|
|
3779
|
-
|
|
4105
|
+
const ZONE_RANK2 = { start: 0, center: 1, end: 2 };
|
|
4106
|
+
const inEdge = (a, b) => {
|
|
4107
|
+
const p = a.place;
|
|
4108
|
+
const q = b.place;
|
|
4109
|
+
return p.kind === "gap" && q.kind === "gap" && p.edge === q.edge ? ZONE_RANK2[p.zone] - ZONE_RANK2[q.zone] || p.at - q.at : 0;
|
|
4110
|
+
};
|
|
4111
|
+
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] || inEdge(a.t, b.t) || a.i - b.i).map((x) => x.t);
|
|
3780
4112
|
}
|
|
3781
4113
|
|
|
3782
4114
|
// src/lanes.ts
|
|
3783
|
-
import { EPS as
|
|
3784
|
-
import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
|
|
3785
|
-
var SPOT_PITCH = 40;
|
|
3786
|
-
var SNAP_DISTANCE = 8;
|
|
4115
|
+
import { EPS as EPS23, area as area7, clamp as clamp4, rect as rect20, subtract as subtract6 } from "@n-uf/placement";
|
|
3787
4116
|
var STEP = 1;
|
|
3788
|
-
var
|
|
3789
|
-
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
3790
|
-
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
4117
|
+
var mid2 = (r, axis) => lo(r, axis) + len(r, axis) / 2;
|
|
3791
4118
|
var hull2 = (a, b) => {
|
|
3792
4119
|
const x = Math.min(a.x, b.x);
|
|
3793
4120
|
const y = Math.min(a.y, b.y);
|
|
3794
|
-
return
|
|
4121
|
+
return rect20(x, y, Math.max(a.x + a.width, b.x + b.width) - x, Math.max(a.y + a.height, b.y + b.height) - y);
|
|
3795
4122
|
};
|
|
3796
|
-
var
|
|
4123
|
+
var nonNeg2 = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
3797
4124
|
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;
|
|
3798
4125
|
var ORIGIN = { x: 0, y: 0 };
|
|
3799
|
-
function onEdge(l, edge, dragged, axis) {
|
|
3800
|
-
return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS21 && it.rect.height > EPS21).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
|
|
3801
|
-
}
|
|
3802
|
-
function neighbors(after, edge, dragged, axis) {
|
|
3803
|
-
const me = after.items[dragged];
|
|
3804
|
-
const others = onEdge(after, edge, dragged, axis);
|
|
3805
|
-
const at = me ? mid(me.rect, axis) : 0;
|
|
3806
|
-
return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
|
|
3807
|
-
}
|
|
3808
|
-
function givesWay(now, after, lane, side, extent) {
|
|
3809
|
-
if (!now) return null;
|
|
3810
|
-
if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
|
|
3811
|
-
const [p0, p1] = extent(now.rect);
|
|
3812
|
-
const [q0, q1] = extent(after.rect);
|
|
3813
|
-
if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
|
|
3814
|
-
return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
|
|
3815
|
-
}
|
|
3816
4126
|
function liftedLayout(state, dragged, options) {
|
|
3817
4127
|
return solve(liftItem(state, dragged), options.previous ? { previous: options.previous } : {});
|
|
3818
4128
|
}
|
|
@@ -3829,13 +4139,13 @@ function clipAtDrawn(band, axis, cuts) {
|
|
|
3829
4139
|
const x = axis === "x" ? "y" : "x";
|
|
3830
4140
|
const line = lo(band, x) + len(band, x) / 2;
|
|
3831
4141
|
for (const c of cuts) {
|
|
3832
|
-
if (!(lo(c, x) < line -
|
|
4142
|
+
if (!(lo(c, x) < line - EPS23 && line < lo(c, x) + len(c, x) - EPS23)) continue;
|
|
3833
4143
|
const c0 = lo(c, axis);
|
|
3834
4144
|
const c1 = c0 + len(c, axis);
|
|
3835
4145
|
if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
|
|
3836
4146
|
else b = Math.min(b, c0);
|
|
3837
4147
|
}
|
|
3838
|
-
return b - a >
|
|
4148
|
+
return b - a > EPS23 ? along(band, axis, a, b) : band;
|
|
3839
4149
|
}
|
|
3840
4150
|
var memo = /* @__PURE__ */ new WeakMap();
|
|
3841
4151
|
var previousIds = /* @__PURE__ */ new WeakMap();
|
|
@@ -3894,7 +4204,7 @@ function rawSpot(base, id) {
|
|
|
3894
4204
|
}
|
|
3895
4205
|
function build(state, dragged, options) {
|
|
3896
4206
|
const seen = solve(state, options.previous ? { previous: options.previous } : {});
|
|
3897
|
-
const { targets: ts, refusals: rs } = targetsAndRefusals(state, dragged, options);
|
|
4207
|
+
const { targets: ts, refusals: rs, places } = targetsAndRefusals(state, dragged, options);
|
|
3898
4208
|
const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
|
|
3899
4209
|
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
3900
4210
|
const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
|
|
@@ -3904,7 +4214,7 @@ function build(state, dragged, options) {
|
|
|
3904
4214
|
return e && axisOf(e.side) === "column" ? "y" : "x";
|
|
3905
4215
|
};
|
|
3906
4216
|
const columnKey = (side, ring) => state.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
|
|
3907
|
-
for (const t of ts) {
|
|
4217
|
+
for (const t of [...ts, ...places]) {
|
|
3908
4218
|
if (t.free) continue;
|
|
3909
4219
|
const p = t.place;
|
|
3910
4220
|
if (p.kind === "gap" || p.kind === "home" && ownEdge) {
|
|
@@ -3935,7 +4245,7 @@ function build(state, dragged, options) {
|
|
|
3935
4245
|
raws.push(...takeoverSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH));
|
|
3936
4246
|
const byLane = /* @__PURE__ */ new Map();
|
|
3937
4247
|
for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
|
|
3938
|
-
const halves = new Set(state.edges.filter(
|
|
4248
|
+
const halves = new Set(state.edges.filter(cutsByHalves).map((e) => e.id));
|
|
3939
4249
|
const marking = {
|
|
3940
4250
|
pitch,
|
|
3941
4251
|
natural: (id, axis) => {
|
|
@@ -3943,19 +4253,16 @@ function build(state, dragged, options) {
|
|
|
3943
4253
|
const main = it?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
|
|
3944
4254
|
return it?.fixed && main?.grows ? main.natural : void 0;
|
|
3945
4255
|
},
|
|
3946
|
-
gap: (edge) =>
|
|
3947
|
-
crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) >
|
|
4256
|
+
gap: (edge) => nonNeg2(state.edges.find((e) => e.id === edge)?.gap),
|
|
4257
|
+
crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) > EPS23 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over2.edges[e.id].rect)
|
|
3948
4258
|
};
|
|
3949
|
-
const
|
|
3950
|
-
const w = own?.rect.width ?? 0;
|
|
3951
|
-
const h = own?.rect.height ?? 0;
|
|
3952
|
-
const share = { x: w >= h ? shareOf(options.grab?.x, w) : 0.5, y: h > w ? shareOf(options.grab?.y, h) : 0.5 };
|
|
4259
|
+
const share = grabShare(own?.rect, options.grab);
|
|
3953
4260
|
const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), share, marking)).filter((l) => !!l);
|
|
3954
4261
|
const laneList = newColumnsGiveWay(built.map((l) => settle(l, seen, state, dragged, built, options.emptyLanes)), (l) => l.id, state).map((l) => clearOfRail(l, seen, byLane.get(l.id)));
|
|
3955
4262
|
const onLanes = new Set(laneList.map((l) => l.id));
|
|
3956
|
-
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width >
|
|
4263
|
+
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS23 && r.rect.height > EPS23 ? [r.rect] : []);
|
|
3957
4264
|
const blocked = [
|
|
3958
|
-
...Object.values(seen.edges).filter((e) => e.cross >
|
|
4265
|
+
...Object.values(seen.edges).filter((e) => e.cross > EPS23).map((e) => e.rect),
|
|
3959
4266
|
...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
|
|
3960
4267
|
...keepClearFor(state, seen, "targets"),
|
|
3961
4268
|
...rails,
|
|
@@ -4002,7 +4309,7 @@ function laneRectOver(list, over2, marking) {
|
|
|
4002
4309
|
if (!edgeLayout) return { rect: list.every((r) => r.strip) ? list.map((r) => r.hit).reduce(hull2) : list.map((r) => r.hit).reduce(hull2, band) };
|
|
4003
4310
|
const drawnAt = drawnRect(over2, first.edge);
|
|
4004
4311
|
if (drawnAt) return { rect: drawnAt };
|
|
4005
|
-
const whole = axis === "x" ?
|
|
4312
|
+
const whole = axis === "x" ? rect20(edgeLayout.rect.x, band.y, edgeLayout.rect.width, band.height) : rect20(band.x, edgeLayout.rect.y, band.width, edgeLayout.rect.height);
|
|
4006
4313
|
return { rect: clipAtDrawn(whole, axis, marking.crossing(first.edge, over2)), band: whole };
|
|
4007
4314
|
}
|
|
4008
4315
|
function drawnIn(layout, id) {
|
|
@@ -4011,7 +4318,7 @@ function drawnIn(layout, id) {
|
|
|
4011
4318
|
function drawnRect(layout, id) {
|
|
4012
4319
|
const e = layout.edges[id];
|
|
4013
4320
|
if (!e) return void 0;
|
|
4014
|
-
if (e.cross >
|
|
4321
|
+
if (e.cross > EPS23) return e.rect;
|
|
4015
4322
|
if (!e.folded) return void 0;
|
|
4016
4323
|
const run = Object.values(layout.rails).flatMap((r) => r?.segments.filter((g) => g.edge === id).map((g) => g.rect) ?? []);
|
|
4017
4324
|
return run.length > 0 ? run.reduce(hull2) : void 0;
|
|
@@ -4023,7 +4330,8 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
|
|
|
4023
4330
|
const { rect: laneRect, band: markBand } = laneRectOver(list, seen, marking);
|
|
4024
4331
|
const firstOf = (r) => r.slide?.first ?? r.landing;
|
|
4025
4332
|
const lastOf = (r) => r.slide?.last ?? r.landing;
|
|
4026
|
-
const
|
|
4333
|
+
const besideZone = (r) => r.target.place.kind === "gap" && r.target.place.zone === zoneIn2(seen, r.before) ? 0 : 1;
|
|
4334
|
+
const sorted = [...list].sort((a, b) => mid2(firstOf(a), axis) - mid2(firstOf(b), axis) || (a.home ? -1 : b.home ? 1 : 0) || besideZone(a) - besideZone(b));
|
|
4027
4335
|
const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
|
|
4028
4336
|
const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
|
|
4029
4337
|
const unique = [];
|
|
@@ -4040,38 +4348,30 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
|
|
|
4040
4348
|
const bandEnd = bandStart + len(whole, axis);
|
|
4041
4349
|
const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
|
|
4042
4350
|
const held = halves ? 0.5 : share[axis];
|
|
4043
|
-
const
|
|
4044
|
-
for (let i = 0; i + 1 < unique.length; i++) {
|
|
4045
|
-
const a = unique[i];
|
|
4046
|
-
const b = unique[i + 1];
|
|
4351
|
+
const cutOf = (a, b) => {
|
|
4047
4352
|
const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
const across2 = (aEnd + lo(bLanding, axis)) / 2;
|
|
4052
|
-
const overlap = lo(bLanding, axis) < aEnd - EPS21;
|
|
4053
|
-
const slack = Math.max(0, marking.pitch) / 2;
|
|
4054
|
-
const atGrab = clamp3(across2 + (held - 0.5) * (len(aLanding, axis) + len(bLanding, axis)) / 2, lo(bLanding, axis) - slack, aEnd + slack);
|
|
4055
|
-
const raw = shared ? mid(shared, axis) : overlap ? atGrab : across2;
|
|
4056
|
-
cuts.push(clamp3(Math.max(raw, cuts[i - 1] ?? bandStart), bandStart, bandEnd));
|
|
4057
|
-
}
|
|
4353
|
+
return aimCut(lastOf(a), firstOf(b), axis, held, aimSlack(marking.pitch), shared);
|
|
4354
|
+
};
|
|
4355
|
+
const cuts = crossFreeCuts(unique.length, (i, j) => cutOf(unique[i], unique[j]), (i) => halves || !!unique[i].home, bandStart, bandEnd);
|
|
4058
4356
|
const spots = unique.flatMap((x, i) => {
|
|
4059
4357
|
const a = i === 0 ? bandStart : cuts[i - 1];
|
|
4060
4358
|
const b = i === unique.length - 1 ? bandEnd : cuts[i];
|
|
4061
|
-
const along2 = [
|
|
4062
|
-
return along2[1] - along2[0] >
|
|
4359
|
+
const along2 = [clamp4(a, start, end), clamp4(b, start, end)];
|
|
4360
|
+
return along2[1] - along2[0] > EPS23 || b - a <= EPS23 || x.home ? [{ x, along: along2 }] : [];
|
|
4063
4361
|
}).map(({ x, along: along2 }) => ({
|
|
4064
4362
|
id: x.id,
|
|
4065
4363
|
along: along2,
|
|
4066
4364
|
landing: x.landing,
|
|
4067
|
-
target
|
|
4365
|
+
// A sliding spot's target holds the pointer over its stretch only (its range of landings runs past the cuts either
|
|
4366
|
+
// side, over the neighbors' stretches).
|
|
4367
|
+
target: x.slide && along2[1] - along2[0] > EPS23 ? { ...x.target, hit: axis === "x" ? rect20(along2[0], x.target.hit.y, along2[1] - along2[0], x.target.hit.height) : rect20(x.target.hit.x, along2[0], x.target.hit.width, along2[1] - along2[0]) } : x.target,
|
|
4068
4368
|
...x.home ? { home: true } : {},
|
|
4069
4369
|
...x.pitched ? { pitched: true } : {},
|
|
4070
4370
|
...x.slide ? { slide: { from: x.slide.from, to: x.slide.to, snaps: x.slide.snaps, snapDistance: x.slide.snapDistance, step: x.slide.step } } : {},
|
|
4071
4371
|
others: othersKey(x.layout, dragged)
|
|
4072
4372
|
}));
|
|
4073
4373
|
const itemLen = Math.min(...unique.map((x) => len(x.landing, axis)));
|
|
4074
|
-
const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [
|
|
4374
|
+
const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp4(lo(h, axis), start, end), clamp4(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS23) : [];
|
|
4075
4375
|
const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
|
|
4076
4376
|
const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
|
|
4077
4377
|
const markRect = (first.edge ? drawnRect(drawn, first.edge) : void 0) ?? laneRectOver(list, drawn, marking).band ?? markBand ?? laneRect;
|
|
@@ -4096,7 +4396,7 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
|
|
|
4096
4396
|
}) : virtualMarks(id, unique, drawn.items[dragged]);
|
|
4097
4397
|
return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
|
|
4098
4398
|
}
|
|
4099
|
-
var along = (r, axis, a, b) => axis === "x" ?
|
|
4399
|
+
var along = (r, axis, a, b) => axis === "x" ? rect20(a, r.y, b - a, r.height) : rect20(r.x, a, r.width, b - a);
|
|
4100
4400
|
var LINE2 = 2;
|
|
4101
4401
|
var MIN_BOX = 8;
|
|
4102
4402
|
var HATCH_END = 8;
|
|
@@ -4104,8 +4404,8 @@ var HATCH_EDGE = 8;
|
|
|
4104
4404
|
function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
|
|
4105
4405
|
const { besideMin } = more;
|
|
4106
4406
|
const hatches = (pair, a, b, p, q, gl, gr) => {
|
|
4107
|
-
if (gl && Math.abs(p - a) <
|
|
4108
|
-
if (gr && Math.abs(q - b) <
|
|
4407
|
+
if (gl && Math.abs(p - a) < EPS23) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
|
|
4408
|
+
if (gr && Math.abs(q - b) < EPS23) out.push({ id: `${lane}/hatch/${pair}:after`, kind: "hatch", rect: along(laneRect, axis, q - Math.min(HATCH_END, (q - p) / 2), q), givesWay: gr });
|
|
4109
4409
|
};
|
|
4110
4410
|
const heldAt = items.find((o) => o.id === held);
|
|
4111
4411
|
const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
|
|
@@ -4115,10 +4415,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4115
4415
|
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 }];
|
|
4116
4416
|
const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
|
|
4117
4417
|
for (let i = 0; i + 1 < ends.length; i++) {
|
|
4118
|
-
const a =
|
|
4119
|
-
const b =
|
|
4418
|
+
const a = clamp4(ends[i].b, start, end);
|
|
4419
|
+
const b = clamp4(ends[i + 1].a, start, end);
|
|
4120
4420
|
const pair = `${ends[i].id}|${ends[i + 1].id}`;
|
|
4121
|
-
if (ends[i + 1].a < start -
|
|
4421
|
+
if (ends[i + 1].a < start - EPS23 || ends[i].b > end + EPS23 || !lands(pair)) continue;
|
|
4122
4422
|
const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
|
|
4123
4423
|
const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
|
|
4124
4424
|
const named = `${left}|${right}`;
|
|
@@ -4127,12 +4427,12 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4127
4427
|
const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
|
|
4128
4428
|
const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
|
|
4129
4429
|
const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
|
|
4130
|
-
if (b - a < min -
|
|
4131
|
-
if (spot && b - a >= besideMin -
|
|
4430
|
+
if (b - a < min - EPS23) {
|
|
4431
|
+
if (spot && b - a >= besideMin - EPS23) {
|
|
4132
4432
|
let ps = [[a, b]];
|
|
4133
4433
|
for (const f of refused) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, f.along[0])], [Math.max(p, f.along[1]), q]]);
|
|
4134
4434
|
if (heldSpan) ps = ps.flatMap(([p, q]) => [[p, Math.min(q, heldSpan[0])], [Math.max(p, heldSpan[1]), q]]);
|
|
4135
|
-
ps = ps.filter(([p, q]) => q - p >= MIN_BOX -
|
|
4435
|
+
ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS23);
|
|
4136
4436
|
ps.forEach(([p, q], k2) => {
|
|
4137
4437
|
out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
4138
4438
|
hatches(pair, a, b, p, q, gl, gr);
|
|
@@ -4144,10 +4444,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4144
4444
|
continue;
|
|
4145
4445
|
}
|
|
4146
4446
|
let pieces = [[a, b]];
|
|
4147
|
-
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 >
|
|
4447
|
+
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 > EPS23);
|
|
4148
4448
|
let k = 0;
|
|
4149
4449
|
for (const [p, q] of pieces) {
|
|
4150
|
-
if (q - p < min -
|
|
4450
|
+
if (q - p < min - EPS23) continue;
|
|
4151
4451
|
const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
|
|
4152
4452
|
out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
4153
4453
|
hatches(pair, a, b, p, q, gl, gr);
|
|
@@ -4159,8 +4459,8 @@ function virtualMarks(lane, spots, held) {
|
|
|
4159
4459
|
return spots.map((s) => {
|
|
4160
4460
|
const l = s.landing;
|
|
4161
4461
|
if (!held || held.floating || !overlaps8(l, held.rect)) return { id: `${lane}/box/${s.id}`, kind: "box", rect: l };
|
|
4162
|
-
const x =
|
|
4163
|
-
return { id: `${lane}/line/${s.id}`, kind: "line", rect:
|
|
4462
|
+
const x = mid2(held.rect, "x") < mid2(l, "x") ? l.x + l.width : l.x;
|
|
4463
|
+
return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect20(x, l.y, 0, l.height) };
|
|
4164
4464
|
});
|
|
4165
4465
|
}
|
|
4166
4466
|
function inLane(l, r) {
|
|
@@ -4169,9 +4469,9 @@ function inLane(l, r) {
|
|
|
4169
4469
|
const y0 = Math.max(m.rect.y, r.y);
|
|
4170
4470
|
const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
|
|
4171
4471
|
const y1 = Math.min(m.rect.y + m.rect.height, r.y + r.height);
|
|
4172
|
-
if (m.kind === "line") return x1 - x0 >= m.rect.width -
|
|
4173
|
-
if (x1 - x0 <=
|
|
4174
|
-
return x1 - x0 >= m.rect.width -
|
|
4472
|
+
if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS23 && y1 - y0 >= m.rect.height - EPS23 ? [m] : [];
|
|
4473
|
+
if (x1 - x0 <= EPS23 || y1 - y0 <= EPS23) return [];
|
|
4474
|
+
return x1 - x0 >= m.rect.width - EPS23 && y1 - y0 >= m.rect.height - EPS23 ? [m] : [{ ...m, rect: rect20(x0, y0, x1 - x0, y1 - y0) }];
|
|
4175
4475
|
});
|
|
4176
4476
|
return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
|
|
4177
4477
|
}
|
|
@@ -4195,14 +4495,14 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4195
4495
|
const e = edge ? edgeOf(edge) : void 0;
|
|
4196
4496
|
return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
|
|
4197
4497
|
};
|
|
4198
|
-
const stays = empty ? Object.entries(drawn.items).filter(([id, it]) => id !== dragged && it.edge !== l.id && barOrRail(it.edge) && !it.floating && !it.inMenu && it.rect.width >
|
|
4498
|
+
const stays = empty ? Object.entries(drawn.items).filter(([id, it]) => id !== dragged && it.edge !== l.id && barOrRail(it.edge) && !it.floating && !it.inMenu && it.rect.width > EPS23 && it.rect.height > EPS23).map(([, it]) => it.rect) : [];
|
|
4199
4499
|
if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps8(m.rect, s)))))) return l;
|
|
4200
4500
|
const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
|
|
4201
4501
|
const marks = [];
|
|
4202
4502
|
for (const m of l.marks) {
|
|
4203
4503
|
const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
|
|
4204
4504
|
if (m.kind === "line") {
|
|
4205
|
-
if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) <
|
|
4505
|
+
if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS23) marks.push(m);
|
|
4206
4506
|
continue;
|
|
4207
4507
|
}
|
|
4208
4508
|
kept.forEach(([p, q], i) => {
|
|
@@ -4215,11 +4515,11 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4215
4515
|
if (l.axis === "y") {
|
|
4216
4516
|
const outerRight = side === "right" ? true : side === "left" ? false : Math.abs(piece.x + piece.width - (st.x + st.width)) <= Math.abs(piece.x - st.x);
|
|
4217
4517
|
const t = Math.min(HATCH_EDGE, piece.width);
|
|
4218
|
-
r =
|
|
4518
|
+
r = rect20(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
|
|
4219
4519
|
} else {
|
|
4220
4520
|
const outerBottom = side === "bottom" ? true : side === "top" ? false : Math.abs(piece.y + piece.height - (st.y + st.height)) <= Math.abs(piece.y - st.y);
|
|
4221
4521
|
const t = Math.min(HATCH_EDGE, piece.height);
|
|
4222
|
-
r =
|
|
4522
|
+
r = rect20(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
|
|
4223
4523
|
}
|
|
4224
4524
|
marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
|
|
4225
4525
|
});
|
|
@@ -4228,12 +4528,12 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4228
4528
|
}
|
|
4229
4529
|
function piecesLess(r, axis, cs) {
|
|
4230
4530
|
const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
|
|
4231
|
-
const crosses = (c) => axis === "x" ? c.y < r.y + r.height -
|
|
4531
|
+
const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS23 && r.y < c.y + c.height - EPS23 : c.x < r.x + r.width - EPS23 && r.x < c.x + c.width - EPS23;
|
|
4232
4532
|
let ps = [span(r)];
|
|
4233
4533
|
for (const c of cs) {
|
|
4234
4534
|
if (!crosses(c)) continue;
|
|
4235
4535
|
const [c0, c1] = span(c);
|
|
4236
|
-
ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p >
|
|
4536
|
+
ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS23);
|
|
4237
4537
|
}
|
|
4238
4538
|
return ps;
|
|
4239
4539
|
}
|
|
@@ -4244,18 +4544,18 @@ function marksLess(marks, axis, cs, options = {}) {
|
|
|
4244
4544
|
const over2 = cs.filter((c) => overlaps8(m.rect, c));
|
|
4245
4545
|
if (over2.length === 0) return [m];
|
|
4246
4546
|
const kept = piecesLess(m.rect, axis, over2);
|
|
4247
|
-
if (m.kind === "line") return (options.lines === "covered" ? kept.length > 0 : kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) <
|
|
4547
|
+
if (m.kind === "line") return (options.lines === "covered" ? kept.length > 0 : kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, axis)) < EPS23) ? [m] : [];
|
|
4248
4548
|
return kept.filter(([p, q]) => m.kind !== "box" || q - p > minBox).map(([p, q], i) => ({ ...m, id: i ? `${m.id}${suffix}${i}` : m.id, rect: along(m.rect, axis, p, q) }));
|
|
4249
4549
|
});
|
|
4250
4550
|
}
|
|
4251
|
-
var overlaps8 = (a, b) => a.x < b.x + b.width -
|
|
4551
|
+
var overlaps8 = (a, b) => a.x < b.x + b.width - EPS23 && b.x < a.x + a.width - EPS23 && a.y < b.y + b.height - EPS23 && b.y < a.y + a.height - EPS23;
|
|
4252
4552
|
function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
4253
4553
|
const out = [];
|
|
4254
4554
|
stretches(state, dragged, options, seen, lifted, raws, (run) => {
|
|
4255
4555
|
const { e, axis, gap, middle } = run;
|
|
4256
4556
|
const taken = run.mine.map((r) => r.landing);
|
|
4257
4557
|
const emit3 = (zone, at, space, x0, flush) => {
|
|
4258
|
-
const hit = landsAt(
|
|
4558
|
+
const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
|
|
4259
4559
|
if (!hit) return false;
|
|
4260
4560
|
const { next, layout } = hit;
|
|
4261
4561
|
const landed = layout.items[dragged];
|
|
@@ -4273,12 +4573,12 @@ function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4273
4573
|
};
|
|
4274
4574
|
return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
|
|
4275
4575
|
const end = (x0, order, flush) => {
|
|
4276
|
-
for (const zone of order) if (spaceAt(zone, x0) >= -
|
|
4576
|
+
for (const zone of order) if (spaceAt(zone, x0) >= -EPS23 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
|
|
4277
4577
|
};
|
|
4278
4578
|
end(a, zones, before?.id ?? "^");
|
|
4279
|
-
if (b - w > a +
|
|
4579
|
+
if (b - w > a + EPS23) end(b - w, [...zones].reverse(), after?.id ?? "$");
|
|
4280
4580
|
if (b - a < w + pitch) return;
|
|
4281
|
-
for (let x0 = a + pitch; x0 + w <= b - pitch +
|
|
4581
|
+
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS23; x0 += pitch) {
|
|
4282
4582
|
const zone = x0 + w / 2 < middle ? "start" : "end";
|
|
4283
4583
|
if (!zones.includes(zone)) continue;
|
|
4284
4584
|
emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
|
|
@@ -4298,54 +4598,15 @@ function stretches(state, dragged, options, seen, lifted, raws, visit) {
|
|
|
4298
4598
|
const mine = raws.filter((r) => r.edge === e.id);
|
|
4299
4599
|
const drawn = base.edges[e.id] ?? seen.edges[e.id];
|
|
4300
4600
|
if (mine.length === 0 || !drawn) continue;
|
|
4301
|
-
const gap = nonNeg(e.gap);
|
|
4302
4601
|
const others = onEdge(base, e.id, dragged, axis);
|
|
4303
|
-
const
|
|
4602
|
+
const run = { state, dragged, e, axis, base, drawn: drawn.rect, gap: nonNeg2(e.gap), middle: mid2(drawn.rect, axis), mine, fixed: others.filter((o) => state.items[o.id]?.fixed), prev };
|
|
4603
|
+
const each = visit(run);
|
|
4304
4604
|
const w = len(mine[0].landing, axis);
|
|
4305
|
-
const each = visit({ e, axis, w, gap, middle: mid(drawn.rect, axis), mine, fixed: others.filter((o) => state.items[o.id]?.fixed), prev });
|
|
4306
|
-
const slack = (o) => {
|
|
4307
|
-
const main = o ? state.items[o.id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main : void 0;
|
|
4308
|
-
return o && main?.grows ? Math.max(0, len(o.r, axis) - main.natural) : 0;
|
|
4309
|
-
};
|
|
4310
|
-
const ends = (l, before, after) => {
|
|
4311
|
-
const at = (o) => {
|
|
4312
|
-
const it = l.items[o.id];
|
|
4313
|
-
return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
|
|
4314
|
-
};
|
|
4315
|
-
const rb = before ? at(before) : void 0;
|
|
4316
|
-
const ra = after ? at(after) : void 0;
|
|
4317
|
-
if (rb === null || ra === null) return null;
|
|
4318
|
-
const el = l.edges[e.id]?.rect ?? drawn.rect;
|
|
4319
|
-
return {
|
|
4320
|
-
a: before && rb ? lo(rb, axis) + len(rb, axis) - slack({ ...before, r: rb }) + gap : lo(el, axis) + nonNeg(e.pad?.start),
|
|
4321
|
-
// (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
|
|
4322
|
-
b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
|
|
4323
|
-
};
|
|
4324
|
-
};
|
|
4325
4605
|
for (let i = 0; i <= others.length; i++) {
|
|
4326
4606
|
const before = others[i - 1];
|
|
4327
4607
|
const after = others[i];
|
|
4328
|
-
const
|
|
4329
|
-
|
|
4330
|
-
const probe = (() => {
|
|
4331
|
-
const zone = zones[0];
|
|
4332
|
-
if (!zone) return null;
|
|
4333
|
-
const next = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
|
|
4334
|
-
if (next === state) return null;
|
|
4335
|
-
const l = solveLanded(next, dragged, prev);
|
|
4336
|
-
const landed = l.items[dragged];
|
|
4337
|
-
if (!landed || landed.inMenu || landed.edge !== e.id) return null;
|
|
4338
|
-
const n = neighbors(l, e.id, dragged, axis);
|
|
4339
|
-
if (n.before !== (before?.id ?? "^") || n.next !== (after?.id ?? "$")) return null;
|
|
4340
|
-
const r = ends(l, before, after);
|
|
4341
|
-
return r && { ...r, w: len(landed.rect, axis), layout: l };
|
|
4342
|
-
})();
|
|
4343
|
-
const seenEnds = ends(base, before, after);
|
|
4344
|
-
const pushed = (o, side) => !!o && !!probe && givesWay(base.items[o.id], probe.layout.items[o.id], e.id, side, (r) => [lo(r, axis), lo(r, axis) + len(r, axis) - slack({ ...o, r })]) === "moves";
|
|
4345
|
-
const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : seenEnds.a;
|
|
4346
|
-
const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : seenEnds.b;
|
|
4347
|
-
const wi = probe?.w ?? w;
|
|
4348
|
-
each({ before, after, a, b, w: wi, zones, atOf, spaceAt: (zone, x0) => zone === "start" ? x0 - a : b - (x0 + wi) });
|
|
4608
|
+
const room = slideRoom(run, before?.id, after?.id, others.slice(0, i).map((o) => o.id), w);
|
|
4609
|
+
if (room) each({ ...room, before, after, room });
|
|
4349
4610
|
}
|
|
4350
4611
|
}
|
|
4351
4612
|
}
|
|
@@ -4355,7 +4616,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4355
4616
|
const { e, axis } = run;
|
|
4356
4617
|
const taken = [...run.mine.map((r) => r.landing)];
|
|
4357
4618
|
const emit3 = (zone, at, space, x0, nb) => {
|
|
4358
|
-
const hit = landsAt(
|
|
4619
|
+
const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
|
|
4359
4620
|
if (!hit) return;
|
|
4360
4621
|
const { next, layout } = hit;
|
|
4361
4622
|
const landed = layout.items[dragged];
|
|
@@ -4367,7 +4628,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4367
4628
|
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 });
|
|
4368
4629
|
};
|
|
4369
4630
|
return ({ w, zones, atOf, spaceAt, before, after }) => {
|
|
4370
|
-
const zoneOf2 = (id) =>
|
|
4631
|
+
const zoneOf2 = (id) => zoneIn2(run.base, id);
|
|
4371
4632
|
if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !state.items[after.id]?.fixed) {
|
|
4372
4633
|
const x0 = lo(after.r, axis);
|
|
4373
4634
|
emit3("start", atOf("start"), Math.max(0, spaceAt("start", x0)), x0, after.id);
|
|
@@ -4380,50 +4641,19 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4380
4641
|
});
|
|
4381
4642
|
return out;
|
|
4382
4643
|
}
|
|
4383
|
-
function landsAt(state, dragged, run, place, x0) {
|
|
4384
|
-
const next = moveTo(state, dragged, place);
|
|
4385
|
-
if (next === state) return null;
|
|
4386
|
-
const layout = solveLanded(next, dragged, run.prev);
|
|
4387
|
-
const landed = layout.items[dragged];
|
|
4388
|
-
const { axis } = run;
|
|
4389
|
-
if (!landed || landed.inMenu || landed.edge !== run.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
|
|
4390
|
-
const kept = (f) => {
|
|
4391
|
-
const it = layout.items[f.id];
|
|
4392
|
-
if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
|
|
4393
|
-
return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
|
|
4394
|
-
};
|
|
4395
|
-
if (!run.fixed.every(kept)) return null;
|
|
4396
|
-
return { next, layout };
|
|
4397
|
-
}
|
|
4398
4644
|
function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
4399
4645
|
const spots = [];
|
|
4400
4646
|
const absorbed = /* @__PURE__ */ new Set();
|
|
4401
4647
|
const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
|
|
4402
4648
|
const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
|
|
4403
4649
|
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
4404
|
-
stretches(state, dragged, options, seen, lifted, raws, (run) => ({
|
|
4405
|
-
const { e, axis,
|
|
4650
|
+
stretches(state, dragged, options, seen, lifted, raws, (run) => ({ w, zones, atOf, spaceAt, before, after, room }) => {
|
|
4651
|
+
const { e, axis, mine } = run;
|
|
4406
4652
|
if (zones.length === 0) return;
|
|
4407
4653
|
{
|
|
4408
|
-
const
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
if (!zones.includes(zone2)) continue;
|
|
4412
|
-
const space = spaceAt(zone2, x0);
|
|
4413
|
-
if (space < -EPS21) continue;
|
|
4414
|
-
const place = { edge: e.id, zone: zone2, at: atOf(zone2), space: Math.max(0, space) };
|
|
4415
|
-
const hit = landsAt(state, dragged, run, place, x0);
|
|
4416
|
-
if (hit) return { place, result: { state: hit.next, layout: hit.layout } };
|
|
4417
|
-
}
|
|
4418
|
-
return null;
|
|
4419
|
-
};
|
|
4420
|
-
const tries = [a];
|
|
4421
|
-
for (let x0 = a + sample; x0 < b - w - EPS21; x0 += sample) tries.push(x0);
|
|
4422
|
-
if (b - w > a + EPS21) tries.push(b - w);
|
|
4423
|
-
const ok = tries.map((x0) => ({ x0, hit: land(x0) })).filter((t) => t.hit);
|
|
4424
|
-
if (ok.length === 0) return;
|
|
4425
|
-
const from = ok[0].x0;
|
|
4426
|
-
const to = ok.at(-1).x0;
|
|
4654
|
+
const range = slideRange(run, room, sample);
|
|
4655
|
+
if (!range) return;
|
|
4656
|
+
const { from, to, land } = range;
|
|
4427
4657
|
const bId = before?.id ?? "^";
|
|
4428
4658
|
const nId = after?.id ?? "$";
|
|
4429
4659
|
if (to - from < STEP) {
|
|
@@ -4431,14 +4661,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4431
4661
|
const firstZone = (() => {
|
|
4432
4662
|
for (const zone3 of zones) {
|
|
4433
4663
|
const space = spaceAt(zone3, from);
|
|
4434
|
-
if (space < -
|
|
4664
|
+
if (space < -EPS23) continue;
|
|
4435
4665
|
const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
|
|
4436
|
-
const hit = landsAt(
|
|
4666
|
+
const hit = landsAt(run, place2, from);
|
|
4437
4667
|
if (hit) return { place: place2, result: { state: hit.next, layout: hit.layout } };
|
|
4438
4668
|
}
|
|
4439
4669
|
return null;
|
|
4440
4670
|
})();
|
|
4441
|
-
const { place, result } = firstZone ??
|
|
4671
|
+
const { place, result } = firstZone ?? range.start;
|
|
4442
4672
|
const landed = result.layout.items[dragged].rect;
|
|
4443
4673
|
const n = neighbors(result.layout, e.id, dragged, axis);
|
|
4444
4674
|
const zone2 = place.zone;
|
|
@@ -4460,13 +4690,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4460
4690
|
};
|
|
4461
4691
|
put(from);
|
|
4462
4692
|
put(to);
|
|
4463
|
-
|
|
4693
|
+
const beforeZone = zoneIn2(run.base, before?.id);
|
|
4694
|
+
const rank = (r) => r.home ? 0 : r.target.place.kind === "gap" && r.target.place.zone === beforeZone ? 1 : 2;
|
|
4695
|
+
for (const r of [...inside].sort((p, q) => rank(p) - rank(q))) put(lo(r.landing, axis), r);
|
|
4464
4696
|
const homeAt = homeRaw ? lo(homeRaw.landing, axis) : void 0;
|
|
4465
4697
|
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);
|
|
4466
4698
|
const snaps = kept.map((p) => p.at);
|
|
4467
4699
|
const dockAt = (x0) => kept.find((p) => Math.abs(p.at - x0) < 1e-6)?.raw;
|
|
4468
|
-
const
|
|
4469
|
-
const at = (x0) => along(shape, axis, x0, x0 + w);
|
|
4700
|
+
const { at } = range;
|
|
4470
4701
|
const snapped = (x0) => {
|
|
4471
4702
|
let best = x0;
|
|
4472
4703
|
let d = Infinity;
|
|
@@ -4474,9 +4705,9 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4474
4705
|
return best;
|
|
4475
4706
|
};
|
|
4476
4707
|
const startAt = (raw) => {
|
|
4477
|
-
const c =
|
|
4708
|
+
const c = clamp4(raw, from, to);
|
|
4478
4709
|
const s = snapped(c);
|
|
4479
|
-
return snaps.includes(s) ? s :
|
|
4710
|
+
return snaps.includes(s) ? s : clamp4(Math.round(c / STEP) * STEP, from, to);
|
|
4480
4711
|
};
|
|
4481
4712
|
const results = /* @__PURE__ */ new Map();
|
|
4482
4713
|
const commitAt = (x0) => {
|
|
@@ -4484,11 +4715,11 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4484
4715
|
const k = `${r ? "dock " : ""}${Math.round(x0 * 1e3) / 1e3}`;
|
|
4485
4716
|
const known = results.get(k);
|
|
4486
4717
|
if (known) return known;
|
|
4487
|
-
const result = r ? r.target.after(ORIGIN, ORIGIN) : land(x0)
|
|
4718
|
+
const result = r ? r.target.after(ORIGIN, ORIGIN) : (land(x0) ?? range.nearest(x0)).result;
|
|
4488
4719
|
results.set(k, result);
|
|
4489
4720
|
return result;
|
|
4490
4721
|
};
|
|
4491
|
-
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(
|
|
4722
|
+
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp4(lo(own.rect, axis), from, to)) : from;
|
|
4492
4723
|
const restResult = commitAt(rest);
|
|
4493
4724
|
const ownZone = own?.zone;
|
|
4494
4725
|
const restPlace = (() => {
|
|
@@ -4508,7 +4739,7 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4508
4739
|
place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
|
|
4509
4740
|
after: (point, grab) => {
|
|
4510
4741
|
const g = grab ? grab[long] : ownLen / 2;
|
|
4511
|
-
const share = axis === long && ownLen >
|
|
4742
|
+
const share = axis === long && ownLen > EPS23 && Number.isFinite(g) ? clamp4(g / ownLen, 0, 1) : 0.5;
|
|
4512
4743
|
return commitAt(startAt((axis === "x" ? point.x : point.y) - share * w));
|
|
4513
4744
|
}
|
|
4514
4745
|
};
|
|
@@ -4525,6 +4756,8 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4525
4756
|
target,
|
|
4526
4757
|
hit: target.hit,
|
|
4527
4758
|
...homeRaw ? { home: true } : {},
|
|
4759
|
+
// Its stretch of the lane is cut from its range's end landings, where its drop lands at the hand: a range that runs
|
|
4760
|
+
// into a growing neighbor's slack (the room the drop makes; the neighbor gives way) cuts from there too.
|
|
4528
4761
|
slide: { from, to, snaps, snapDistance, step: STEP, first: at(from), last: at(to) }
|
|
4529
4762
|
});
|
|
4530
4763
|
}
|
|
@@ -4533,20 +4766,20 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4533
4766
|
}
|
|
4534
4767
|
|
|
4535
4768
|
// src/drag.ts
|
|
4536
|
-
import { EPS as
|
|
4769
|
+
import { EPS as EPS24, area as area8, overlaps as overlaps9, subtract as subtract7 } from "@n-uf/placement";
|
|
4537
4770
|
var MIN_PIECE = 8;
|
|
4538
4771
|
function trimmedBy(marks, cs) {
|
|
4539
4772
|
if (cs.length === 0) return [...marks];
|
|
4540
4773
|
return marks.flatMap((m) => {
|
|
4541
4774
|
const r = m.rect;
|
|
4542
|
-
if (r.width <=
|
|
4543
|
-
const across2 = r.height <=
|
|
4775
|
+
if (r.width <= EPS24 || r.height <= EPS24) {
|
|
4776
|
+
const across2 = r.height <= EPS24;
|
|
4544
4777
|
const at = across2 ? r.y : r.x;
|
|
4545
4778
|
let pieces2 = [across2 ? [r.x, r.x + r.width] : [r.y, r.y + r.height]];
|
|
4546
4779
|
let touched = false;
|
|
4547
4780
|
for (const c of cs) {
|
|
4548
4781
|
const [lo2, hi] = across2 ? [c.y, c.y + c.height] : [c.x, c.x + c.width];
|
|
4549
|
-
if (!(at > lo2 +
|
|
4782
|
+
if (!(at > lo2 + EPS24 && at < hi - EPS24)) continue;
|
|
4550
4783
|
const [a, b] = across2 ? [c.x, c.x + c.width] : [c.y, c.y + c.height];
|
|
4551
4784
|
pieces2 = pieces2.flatMap(([s2, e2]) => {
|
|
4552
4785
|
if (b <= s2 || a >= e2) return [[s2, e2]];
|
|
@@ -4558,7 +4791,7 @@ function trimmedBy(marks, cs) {
|
|
|
4558
4791
|
const kept = pieces2.filter(([s2, e2]) => e2 - s2 >= 1);
|
|
4559
4792
|
if (kept.length === 0) return [];
|
|
4560
4793
|
const [s, e] = kept.reduce((x, y) => y[1] - y[0] > x[1] - x[0] ? y : x);
|
|
4561
|
-
if (Math.abs(s - (across2 ? r.x : r.y)) <
|
|
4794
|
+
if (Math.abs(s - (across2 ? r.x : r.y)) < EPS24 && Math.abs(e - s - (across2 ? r.width : r.height)) < EPS24) return [m];
|
|
4562
4795
|
return [{ ...m, rect: across2 ? { x: s, y: r.y, width: e - s, height: r.height } : { x: r.x, y: s, width: r.width, height: e - s } }];
|
|
4563
4796
|
}
|
|
4564
4797
|
const over2 = cs.filter((c) => overlaps9(m.rect, c));
|
|
@@ -4652,7 +4885,7 @@ function dockDrag(state, dragged, options = {}) {
|
|
|
4652
4885
|
shown.push(near);
|
|
4653
4886
|
}
|
|
4654
4887
|
const drawnStays = [
|
|
4655
|
-
...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) >
|
|
4888
|
+
...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) > EPS24).map((e) => screen.layout.edges[e.id].rect),
|
|
4656
4889
|
...Object.values(screen.layout.rails).flatMap((r) => r?.segments.filter((g) => g.id !== dragged).map((g) => g.rect) ?? [])
|
|
4657
4890
|
];
|
|
4658
4891
|
const onScreen = [...shown.filter((s) => !s.created && s !== near).flatMap((s) => s.marks.map((m) => m.rect)), ...drawnStays, ...screen.landing ? [screen.landing] : []];
|
|
@@ -4728,15 +4961,15 @@ export {
|
|
|
4728
4961
|
dockHome,
|
|
4729
4962
|
storeDockState,
|
|
4730
4963
|
readDockState,
|
|
4964
|
+
SPOT_PITCH,
|
|
4731
4965
|
reservedRect,
|
|
4732
4966
|
targets,
|
|
4733
4967
|
refusals,
|
|
4734
4968
|
refusalTargets,
|
|
4735
4969
|
stops,
|
|
4736
|
-
SPOT_PITCH,
|
|
4737
4970
|
lanes,
|
|
4738
4971
|
HATCH_END,
|
|
4739
4972
|
HATCH_EDGE,
|
|
4740
4973
|
dockDrag
|
|
4741
4974
|
};
|
|
4742
|
-
//# sourceMappingURL=chunk-
|
|
4975
|
+
//# sourceMappingURL=chunk-Y3RK6BQT.js.map
|