@n-uf/docking 26.11.58 → 26.11.60
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 +74 -0
- package/dist/{chunk-7QOY2URO.js → chunk-Y2IM76RG.js} +743 -378
- package/dist/chunk-Y2IM76RG.js.map +1 -0
- package/dist/{drag-BGcY5DGm.d.ts → drag-B8JbX6Sq.d.ts} +127 -23
- 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,10 +2183,154 @@ function read(data, base) {
|
|
|
2183
2183
|
}
|
|
2184
2184
|
|
|
2185
2185
|
// src/targets.ts
|
|
2186
|
-
import { EPS as
|
|
2186
|
+
import { EPS as EPS23, PLANE, area as area6, clamp as clamp4, contains, overlaps as overlaps7, rect as rect19 } from "@n-uf/placement";
|
|
2187
|
+
|
|
2188
|
+
// src/grab.ts
|
|
2189
|
+
import { EPS as EPS12, clamp as clamp2 } from "@n-uf/placement";
|
|
2190
|
+
|
|
2191
|
+
// src/aim.ts
|
|
2192
|
+
import { EPS as EPS11, clamp } from "@n-uf/placement";
|
|
2193
|
+
var SPOT_PITCH = 40;
|
|
2194
|
+
var SNAP_DISTANCE = 8;
|
|
2195
|
+
var lo = (r, axis) => axis === "x" ? r.x : r.y;
|
|
2196
|
+
var len = (r, axis) => axis === "x" ? r.width : r.height;
|
|
2197
|
+
function zoneIn2(layout, id) {
|
|
2198
|
+
return (id === void 0 ? void 0 : layout.items[id]?.zone) ?? "start";
|
|
2199
|
+
}
|
|
2200
|
+
function cutsByHalves(edge) {
|
|
2201
|
+
return (edge.side === "left" || edge.side === "right") && !edge.compact;
|
|
2202
|
+
}
|
|
2203
|
+
function aimSlack(pitch) {
|
|
2204
|
+
return Math.max(0, pitch === void 0 || !Number.isFinite(pitch) ? SPOT_PITCH : pitch) / 2;
|
|
2205
|
+
}
|
|
2206
|
+
function grabShare(own, grab) {
|
|
2207
|
+
const shareOf = (g, size) => g === void 0 || !Number.isFinite(g) || size <= EPS11 ? 0.5 : clamp(g / size, 0, 1);
|
|
2208
|
+
const w = own?.width ?? 0;
|
|
2209
|
+
const h = own?.height ?? 0;
|
|
2210
|
+
return { x: w >= h ? shareOf(grab?.x, w) : 0.5, y: h > w ? shareOf(grab?.y, h) : 0.5 };
|
|
2211
|
+
}
|
|
2212
|
+
function aimCut(a, b, axis, heldA, heldB, slack, shared) {
|
|
2213
|
+
if (shared) return lo(shared, axis) + len(shared, axis) / 2;
|
|
2214
|
+
const aEnd = lo(a, axis) + len(a, axis);
|
|
2215
|
+
const bStart = lo(b, axis);
|
|
2216
|
+
const across2 = (aEnd + bStart) / 2;
|
|
2217
|
+
if (!(bStart < aEnd - EPS11)) return across2;
|
|
2218
|
+
const s = Math.max(0, slack);
|
|
2219
|
+
return clamp(across2 + (heldA - len(a, axis) / 2 + (heldB - len(b, axis) / 2)) / 2, bStart - s, aEnd + s);
|
|
2220
|
+
}
|
|
2221
|
+
function crossFreeCuts(n, cut2, pinned, min = -Infinity, max = Infinity) {
|
|
2222
|
+
const active = Array.from({ length: n }, (_, i) => i);
|
|
2223
|
+
for (let changed = true; changed; ) {
|
|
2224
|
+
changed = false;
|
|
2225
|
+
for (let k = 1; k + 1 < active.length; k++) {
|
|
2226
|
+
const [p, q, r] = [active[k - 1], active[k], active[k + 1]];
|
|
2227
|
+
if (!pinned(q) && cut2(q, r) < cut2(p, q) - EPS11) {
|
|
2228
|
+
active.splice(k, 1);
|
|
2229
|
+
changed = true;
|
|
2230
|
+
break;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
const kept = [];
|
|
2235
|
+
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));
|
|
2236
|
+
return Array.from({ length: Math.max(0, n - 1) }, (_, i) => kept[active.findIndex((j) => j > i) - 1]);
|
|
2237
|
+
}
|
|
2238
|
+
function rangeTries(a, b, w, sample) {
|
|
2239
|
+
const tries = [a];
|
|
2240
|
+
for (let x0 = a + sample; x0 < b - w - EPS11; x0 += sample) tries.push(x0);
|
|
2241
|
+
if (b - w > a + EPS11) tries.push(b - w);
|
|
2242
|
+
return tries;
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
// src/grab.ts
|
|
2246
|
+
function grabPlaceOf(it) {
|
|
2247
|
+
const side = it.rail ?? it.railTitle;
|
|
2248
|
+
if (side) return { kind: "rail", side, orient: it.axis };
|
|
2249
|
+
if (!it.floating && it.edge !== void 0) return { kind: "spot", edge: it.edge };
|
|
2250
|
+
return { kind: "float" };
|
|
2251
|
+
}
|
|
2252
|
+
var samePlace = (a, b) => a.kind === b.kind && (a.kind !== "spot" || a.edge === b.edge) && (a.kind !== "rail" || a.side === b.side && a.orient === b.orient);
|
|
2253
|
+
function sameForm(a, b) {
|
|
2254
|
+
return a.axis === b.axis && a.form === b.form && a.formKind === b.formKind && samePlace(grabPlaceOf(a), grabPlaceOf(b));
|
|
2255
|
+
}
|
|
2256
|
+
var sizeOf = (r) => ({ width: r.width, height: r.height });
|
|
2257
|
+
function liftOf(state, seen, dragged, own) {
|
|
2258
|
+
const home = seen.items[dragged];
|
|
2259
|
+
const edge = home?.edge ? state.edges.find((e) => e.id === home.edge) : void 0;
|
|
2260
|
+
const grown = home && edge && growsOnBar(state, edge, dragged, home.form) && home.rect.width > 0 && home.rect.height > 0 ? home.rect : void 0;
|
|
2261
|
+
return { ...home ? { home } : {}, ...own ? { own } : {}, ...grown ? { grown } : {} };
|
|
2262
|
+
}
|
|
2263
|
+
function grabOf(lift, grab, onNote) {
|
|
2264
|
+
const host = typeof grab === "function" ? grab : void 0;
|
|
2265
|
+
const ask = (laid2, size) => {
|
|
2266
|
+
if (!host || !laid2) return void 0;
|
|
2267
|
+
const p = host({ ...laid2, place: grabPlaceOf(laid2) }, { width: size.width, height: size.height });
|
|
2268
|
+
return p && Number.isFinite(p.x) && Number.isFinite(p.y) ? { x: clamp2(p.x, 0, Math.max(0, size.width)), y: clamp2(p.y, 0, Math.max(0, size.height)) } : void 0;
|
|
2269
|
+
};
|
|
2270
|
+
const home = lift.home;
|
|
2271
|
+
const homeSize = home ? sizeOf(home.rect) : void 0;
|
|
2272
|
+
const press = host ? ask(home, homeSize ?? { width: 0, height: 0 }) : grab;
|
|
2273
|
+
const share = grabShare(lift.own, press);
|
|
2274
|
+
const grown = lift.grown;
|
|
2275
|
+
const atHome = (laid2, size) => !!home && !!homeSize && !!laid2 && sameForm(laid2, home) && Math.abs(size.width - homeSize.width) < EPS12 && Math.abs(size.height - homeSize.height) < EPS12;
|
|
2276
|
+
if (host) {
|
|
2277
|
+
const asked = (laid2, size) => {
|
|
2278
|
+
const p = ask(laid2, size);
|
|
2279
|
+
if (onNote && p && press && !noted.has(host) && atHome(laid2, size) && Math.max(Math.abs(p.x - press.x), Math.abs(p.y - press.y)) > LIFT_SLACK) {
|
|
2280
|
+
noted.add(host);
|
|
2281
|
+
onNote({ code: "lift-drift", press, at: p });
|
|
2282
|
+
}
|
|
2283
|
+
return p;
|
|
2284
|
+
};
|
|
2285
|
+
return (laid2, size, rule) => asked(laid2, size) ?? twin(laid2, size, rule);
|
|
2286
|
+
}
|
|
2287
|
+
return twin;
|
|
2288
|
+
function twin(laid2, size, rule) {
|
|
2289
|
+
if (press && rule !== "lane" && atHome(laid2, size)) return press;
|
|
2290
|
+
if (rule === "lift") return laid2?.floating ? twin(laid2, size, "float") : twin(laid2, size, "lane");
|
|
2291
|
+
if (rule === "float") {
|
|
2292
|
+
if (!press) return { x: size.width / 2, y: size.height / 2 };
|
|
2293
|
+
return grown ? { x: clamp2(press.x / grown.width, 0, 1) * size.width, y: clamp2(press.y / grown.height, 0, 1) * size.height } : press;
|
|
2294
|
+
}
|
|
2295
|
+
return { x: share.x * size.width, y: share.y * size.height };
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
var LIFT_SLACK = 0.5;
|
|
2299
|
+
var noted = /* @__PURE__ */ new WeakSet();
|
|
2300
|
+
function grabResolver(lift) {
|
|
2301
|
+
let last = null;
|
|
2302
|
+
return (grab) => {
|
|
2303
|
+
if (last && last.grab === grab) return last.fn;
|
|
2304
|
+
last = { grab, fn: grabOf(lift, grab) };
|
|
2305
|
+
return last.fn;
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
var fnIds = /* @__PURE__ */ new WeakMap();
|
|
2309
|
+
var nextFnId = 0;
|
|
2310
|
+
function grabKey(grab) {
|
|
2311
|
+
if (!grab) return null;
|
|
2312
|
+
if (typeof grab !== "function") return [grab.x, grab.y];
|
|
2313
|
+
let id = fnIds.get(grab);
|
|
2314
|
+
if (id === void 0) fnIds.set(grab, id = nextFnId++);
|
|
2315
|
+
return `fn${id}`;
|
|
2316
|
+
}
|
|
2317
|
+
var samePoint = (a, b) => Math.abs(a.x - b.x) < EPS12 && Math.abs(a.y - b.y) < EPS12;
|
|
2318
|
+
function aimOnce(fn, rule, first, aim, laidOf, sizeIn) {
|
|
2319
|
+
const g0 = fn(first.laid, first.size, rule);
|
|
2320
|
+
const r1 = aim(g0);
|
|
2321
|
+
const l1 = laidOf(r1);
|
|
2322
|
+
if (!first.laid || !l1 || sameForm(l1, first.laid)) return { result: r1, grab: g0 };
|
|
2323
|
+
const g1 = fn(l1, sizeIn(l1), rule);
|
|
2324
|
+
if (samePoint(g1, g0)) return { result: r1, grab: g1 };
|
|
2325
|
+
const r2 = aim(g1);
|
|
2326
|
+
const l2 = laidOf(r2);
|
|
2327
|
+
if (l2 && sameForm(l2, l1)) return { result: r2, grab: g1 };
|
|
2328
|
+
if (l2 && sameForm(l2, first.laid)) return { result: r2, grab: g0 };
|
|
2329
|
+
return { result: r1, grab: g1 };
|
|
2330
|
+
}
|
|
2187
2331
|
|
|
2188
2332
|
// src/targets/anchor.ts
|
|
2189
|
-
import { EPS as
|
|
2333
|
+
import { EPS as EPS13, area, rect as rect10, subtract } from "@n-uf/placement";
|
|
2190
2334
|
var OTHER = { left: "right", right: "left", top: "bottom", bottom: "top" };
|
|
2191
2335
|
function anchorTargets(state, dragged, options) {
|
|
2192
2336
|
const none = { targets: [], refusals: [], lost: [] };
|
|
@@ -2202,7 +2346,7 @@ function anchorTargets(state, dragged, options) {
|
|
|
2202
2346
|
const layout = solve(moved, prev);
|
|
2203
2347
|
const placed = layout.edges[edge.id]?.rect;
|
|
2204
2348
|
const slot = layout.items[dragged]?.rect;
|
|
2205
|
-
if (placed && slot && area(placed) >
|
|
2349
|
+
if (placed && slot && area(placed) > EPS13) {
|
|
2206
2350
|
const pieces = keepClearFor(state, now, "targets").reduce((ps, c) => ps.flatMap((p) => subtract(p, rect10(c.x, c.y, c.width, c.height))), [placed]).filter((p) => p.width >= 1 && p.height >= 1);
|
|
2207
2351
|
if (pieces.length > 0) {
|
|
2208
2352
|
const hit = pieces.reduce((a, p) => area(p) > area(a) ? p : a);
|
|
@@ -2215,7 +2359,7 @@ function anchorTargets(state, dragged, options) {
|
|
|
2215
2359
|
}
|
|
2216
2360
|
|
|
2217
2361
|
// src/targets/edges.ts
|
|
2218
|
-
import { EPS as
|
|
2362
|
+
import { EPS as EPS14, area as area2, rect as rect11 } from "@n-uf/placement";
|
|
2219
2363
|
import { formCrossMin as formCrossMin4, formMenu as formMenu5, formSetsCross as formSetsCross4, itemSteps as itemSteps3 } from "@n-uf/placement/stack";
|
|
2220
2364
|
|
|
2221
2365
|
// src/targets/kinds.ts
|
|
@@ -2271,7 +2415,7 @@ function distinctSlots(c, slots) {
|
|
|
2271
2415
|
if (a.zone !== b.zone) return false;
|
|
2272
2416
|
if (a.home && b.home) return true;
|
|
2273
2417
|
const [p, q] = [landing(a), landing(b)];
|
|
2274
|
-
const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) <
|
|
2418
|
+
const sameLine = a.place.kind === "rail" && b.place.kind === "rail" || Math.abs(a.line - b.line) < EPS14;
|
|
2275
2419
|
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
2420
|
};
|
|
2277
2421
|
const wins = (o, j, s, i) => o.home !== s.home ? o.home : j < i;
|
|
@@ -2398,7 +2542,7 @@ function edgeSlots(c, edge, accepts) {
|
|
|
2398
2542
|
}
|
|
2399
2543
|
function thickerThan(forms, cross) {
|
|
2400
2544
|
const shown = forms.filter((f) => !formMenu5(f));
|
|
2401
|
-
return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross +
|
|
2545
|
+
return shown.length > 0 && shown.every((f) => !formSetsCross4(f) && formCrossMin4(f) > cross + EPS14);
|
|
2402
2546
|
}
|
|
2403
2547
|
var roomReason = (spec, zone) => spec.refuse(zone) === "too-thick" ? "too-thick" : "no-room";
|
|
2404
2548
|
function edgeSpec(c, edge, as) {
|
|
@@ -2412,17 +2556,17 @@ function edgeSpec(c, edge, as) {
|
|
|
2412
2556
|
const len2 = (r2) => column ? r2.height : r2.width;
|
|
2413
2557
|
const empty = el.stack.items.every((p) => el.stack.menu?.items.includes(p.id)) && !el.menu;
|
|
2414
2558
|
const accepts = edgeTakes(edge, kind);
|
|
2415
|
-
if (!accepts && (empty || area2(el.rect) <=
|
|
2559
|
+
if (!accepts && (empty || area2(el.rect) <= EPS14)) return null;
|
|
2416
2560
|
if (accepts && empty && !opensEmpty(state, edge, kind)) return null;
|
|
2417
2561
|
const ownNow = c.room.items[dragged];
|
|
2418
|
-
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) >
|
|
2562
|
+
const ownHere = ownNow && ownNow.edge === edge.id && !ownNow.floating && area2(ownNow.rect) > EPS14 ? ownNow.rect : null;
|
|
2419
2563
|
const oneEnd = state.foldedColumnDrop === "end" && column && el.tabs.length > 0 && ownNow?.edge !== edge.id && zoneTakes(edge, "start", kind);
|
|
2420
2564
|
const allSlots = edgeSlots(c, edge, accepts);
|
|
2421
2565
|
const slots = oneEnd ? allSlots.filter((s) => s.zone === "start").sort((a, b) => a.line - b.line).slice(-1) : allSlots;
|
|
2422
2566
|
const spanOf = (r2) => [at(r2), at(r2) + len2(r2)];
|
|
2423
2567
|
const grows = (id) => !!formsOf(state.items[id], axisOf(edge.side))[now.items[id].form]?.main.grows;
|
|
2424
2568
|
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) >
|
|
2569
|
+
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) > EPS14).map(([, p]) => spanOf(p.rect));
|
|
2426
2570
|
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
2571
|
const s = slots.find((x) => x.zone === zone && x.place.kind === "gap" && x.place.at === 0);
|
|
2428
2572
|
const me = s?.result.layout.items[dragged];
|
|
@@ -2451,7 +2595,7 @@ function edgeSpec(c, edge, as) {
|
|
|
2451
2595
|
vertical: column,
|
|
2452
2596
|
zones,
|
|
2453
2597
|
slots,
|
|
2454
|
-
refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) >
|
|
2598
|
+
refuse: (zone) => takes(zone) ? tooThick ? "too-thick" : "no-room" : accepts || area2(el.rect) > EPS14 ? "not-accepted" : null,
|
|
2455
2599
|
own: ownHere,
|
|
2456
2600
|
holds: !!ownNow && ownNow.edge === edge.id && !ownNow.floating,
|
|
2457
2601
|
reserved,
|
|
@@ -2530,6 +2674,8 @@ function context(state, dragged, options, others = []) {
|
|
|
2530
2674
|
const rest = liftItem(state, dragged);
|
|
2531
2675
|
const base = solve(rest, prev);
|
|
2532
2676
|
const here = placeKey(prune(state), dragged);
|
|
2677
|
+
const own = landedLayout(state, now, dragged, prev).items[dragged];
|
|
2678
|
+
const lift = liftOf(state, now, dragged, own?.rect);
|
|
2533
2679
|
const c = {
|
|
2534
2680
|
state,
|
|
2535
2681
|
others,
|
|
@@ -2544,28 +2690,33 @@ function context(state, dragged, options, others = []) {
|
|
|
2544
2690
|
settle: settle2,
|
|
2545
2691
|
isHome: (r) => placeKey(r.state, dragged) === here,
|
|
2546
2692
|
sound: soundness(state, base, dragged),
|
|
2547
|
-
lay: layKeys(state)
|
|
2693
|
+
lay: layKeys(state),
|
|
2694
|
+
lift,
|
|
2695
|
+
grab: grabOf(lift, options.grab, options.onGrabNote),
|
|
2696
|
+
...own ? { own } : {},
|
|
2697
|
+
slack: aimSlack(options.pitch),
|
|
2698
|
+
slideRanges: /* @__PURE__ */ new Map()
|
|
2548
2699
|
};
|
|
2549
2700
|
return { c, item, prev };
|
|
2550
2701
|
}
|
|
2551
2702
|
|
|
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
2703
|
// src/targets/meet.ts
|
|
2557
|
-
import { EPS as
|
|
2704
|
+
import { EPS as EPS15, rect as rect12 } from "@n-uf/placement";
|
|
2558
2705
|
function meet(a, b) {
|
|
2559
2706
|
const x = Math.max(a.x, b.x);
|
|
2560
2707
|
const y = Math.max(a.y, b.y);
|
|
2561
2708
|
const w = Math.min(a.x + a.width, b.x + b.width) - x;
|
|
2562
2709
|
const h = Math.min(a.y + a.height, b.y + b.height) - y;
|
|
2563
|
-
return w >
|
|
2710
|
+
return w > EPS15 && h > EPS15 ? rect12(x, y, w, h) : null;
|
|
2564
2711
|
}
|
|
2565
2712
|
|
|
2713
|
+
// src/targets/ownership.ts
|
|
2714
|
+
import { EPS as EPS17, area as area3, overlaps as overlaps3, rect as rect13, subtract as subtract2 } from "@n-uf/placement";
|
|
2715
|
+
import { formBody as formBody2, itemSteps as itemSteps5 } from "@n-uf/placement/stack";
|
|
2716
|
+
|
|
2566
2717
|
// 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 >
|
|
2718
|
+
import { EPS as EPS16 } from "@n-uf/placement";
|
|
2719
|
+
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 > EPS16)), [...spans]);
|
|
2569
2720
|
|
|
2570
2721
|
// src/targets/ownership.ts
|
|
2571
2722
|
var isBody = (f) => !!f && formBody2(f);
|
|
@@ -2587,10 +2738,10 @@ function ownedRectsOf(s, along2) {
|
|
|
2587
2738
|
return along2.map(([a, b]) => s.vertical ? rect13(o.x, a, o.width, b - a) : rect13(a, o.y, b - a, o.height));
|
|
2588
2739
|
}
|
|
2589
2740
|
function drawnOf(c, live) {
|
|
2590
|
-
const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) >
|
|
2741
|
+
const edges = Object.entries(c.now.edges).filter(([id, e]) => area3(e.rect) > EPS17 && 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
2742
|
const rails = ["left", "right"].flatMap((side) => {
|
|
2592
2743
|
const rail = c.now.rails[side];
|
|
2593
|
-
if (!rail || rail.segments.length === 0 || area3(rail.rect) <=
|
|
2744
|
+
if (!rail || rail.segments.length === 0 || area3(rail.rect) <= EPS17) return [];
|
|
2594
2745
|
const spec = live.find((s) => s.kind === "railStop" && s.lay.side === side) ?? null;
|
|
2595
2746
|
const lay = spec?.lay ?? { phase: EDGE_KINDS.railStop.phase, side, at: -1 };
|
|
2596
2747
|
const me = c.now.items[c.dragged];
|
|
@@ -2612,7 +2763,7 @@ function homeRectOf(c, ownSpec) {
|
|
|
2612
2763
|
if (!ownSpec) {
|
|
2613
2764
|
const e = c.now.edges[own.edge];
|
|
2614
2765
|
const vanishes = !c.rest.edges.some((x) => x.id === own.edge);
|
|
2615
|
-
return e && vanishes && !e.folded && !e.rides && area3(e.rect) >
|
|
2766
|
+
return e && vanishes && !e.folded && !e.rides && area3(e.rect) > EPS17 ? hull3(o, e.rect) : o;
|
|
2616
2767
|
}
|
|
2617
2768
|
const [c0, c1] = ownSpec.across();
|
|
2618
2769
|
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 +2783,7 @@ function ownersOf(c, live, drawn, alongOf) {
|
|
|
2632
2783
|
if (!s.thinOwned) return rects.map((r) => ({ spec: s, rect: r, lay: s.lay, place: !s.drawn }));
|
|
2633
2784
|
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
2785
|
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) >
|
|
2786
|
+
}).filter((o) => area3(o.rect) > EPS17),
|
|
2636
2787
|
// Every seen rect: the edges the tiler doesn't read (folded, riding, taking nothing) among them.
|
|
2637
2788
|
...drawn.map((d) => ({ ...d, place: false }))
|
|
2638
2789
|
];
|
|
@@ -2658,7 +2809,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2658
2809
|
const e = s.edge ? now.edges[s.id] : void 0;
|
|
2659
2810
|
if (!e) return null;
|
|
2660
2811
|
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] >
|
|
2812
|
+
return span[1] - span[0] > EPS17 ? span : null;
|
|
2662
2813
|
};
|
|
2663
2814
|
const pastEnds = (s, r) => {
|
|
2664
2815
|
const ends = endsOf(s);
|
|
@@ -2710,7 +2861,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2710
2861
|
const half = e ? halfBandOf(e) : null;
|
|
2711
2862
|
if (!e || half === null) return [];
|
|
2712
2863
|
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 >
|
|
2864
|
+
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 > EPS17);
|
|
2714
2865
|
};
|
|
2715
2866
|
const rooms = /* @__PURE__ */ new Map();
|
|
2716
2867
|
const cutsOf = (s) => {
|
|
@@ -2727,23 +2878,23 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2727
2878
|
const owned = [];
|
|
2728
2879
|
for (let k = 1; k < ends.length; k++) {
|
|
2729
2880
|
const [u, w] = [ends[k - 1], ends[k]];
|
|
2730
|
-
const over2 = rs.filter((r) => along2(r)[0] <= u +
|
|
2731
|
-
if (w - u >
|
|
2881
|
+
const over2 = rs.filter((r) => along2(r)[0] <= u + EPS17 && along2(r)[1] >= w - EPS17).map(across2);
|
|
2882
|
+
if (w - u > EPS17 && less([across2(b)], over2).reduce((n, [p, q]) => n + q - p, 0) < 1) owned.push([u, w]);
|
|
2732
2883
|
}
|
|
2733
2884
|
const half = s.edge ? halfBandOf(s.edge) : null;
|
|
2734
2885
|
const raw = bodySpans(s.edge);
|
|
2735
2886
|
if (half === null || raw.length === 0) return { cuts: owned, bodies: raw };
|
|
2736
2887
|
const merged = owned.reduce((m, [u, w]) => {
|
|
2737
2888
|
const last = m[m.length - 1];
|
|
2738
|
-
if (last && u <= last[1] +
|
|
2889
|
+
if (last && u <= last[1] + EPS17) last[1] = Math.max(last[1], w);
|
|
2739
2890
|
else m.push([u, w]);
|
|
2740
2891
|
return m;
|
|
2741
2892
|
}, []);
|
|
2742
2893
|
const [lo2, hi] = endsOf(s) ?? along2(b);
|
|
2743
2894
|
const placed = (p) => {
|
|
2744
|
-
const cut2 = merged.find(([u, w]) => p >= u -
|
|
2895
|
+
const cut2 = merged.find(([u, w]) => p >= u - EPS17 && p <= w + EPS17);
|
|
2745
2896
|
if (!cut2) return p;
|
|
2746
|
-
const sides = [...cut2[0] > lo2 +
|
|
2897
|
+
const sides = [...cut2[0] > lo2 + EPS17 ? [cut2[0]] : [], ...cut2[1] < hi - EPS17 ? [cut2[1]] : []];
|
|
2747
2898
|
return sides.length === 0 ? p : sides.reduce((m, x) => Math.abs(x - p) < Math.abs(m - p) ? x : m);
|
|
2748
2899
|
};
|
|
2749
2900
|
const bands = s.slots.map((sl) => [placed(sl.line) - half, placed(sl.line) + half]);
|
|
@@ -2761,7 +2912,7 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2761
2912
|
const column = axisOf(e.side) === "column";
|
|
2762
2913
|
const across2 = (a, b) => column ? rect13(-1e9, a, 2e9, b - a) : rect13(a, -1e9, b - a, 2e9);
|
|
2763
2914
|
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) >
|
|
2915
|
+
return [...reserved, ...cutsOf(s).bodies.map(([a, b]) => across2(a, b))].filter((b) => area3(b) > EPS17);
|
|
2765
2916
|
};
|
|
2766
2917
|
const drawnBySpec = /* @__PURE__ */ new Map();
|
|
2767
2918
|
const drawnBesides = (s) => {
|
|
@@ -2773,13 +2924,138 @@ function ownership(c, live, alongOf, aloneOf) {
|
|
|
2773
2924
|
}
|
|
2774
2925
|
|
|
2775
2926
|
// src/targets/tiles.ts
|
|
2776
|
-
import { EPS as
|
|
2927
|
+
import { EPS as EPS19, area as area4, overlaps as overlaps4, rect as rect15, subtract as subtract3 } from "@n-uf/placement";
|
|
2928
|
+
|
|
2929
|
+
// src/slide.ts
|
|
2930
|
+
import { EPS as EPS18, rect as rect14 } from "@n-uf/placement";
|
|
2931
|
+
import { itemSteps as itemSteps6 } from "@n-uf/placement/stack";
|
|
2932
|
+
var mid = (r, axis) => lo(r, axis) + len(r, axis) / 2;
|
|
2933
|
+
var nonNeg = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
2934
|
+
function onEdge(l, edge, dragged, axis) {
|
|
2935
|
+
return Object.entries(l.items).filter(([id, it]) => id !== dragged && it.edge === edge && !it.inMenu && !it.floating && it.rect.width > EPS18 && it.rect.height > EPS18).map(([id, it]) => ({ id, r: it.rect, zone: it.zone })).sort((a, b) => lo(a.r, axis) - lo(b.r, axis));
|
|
2936
|
+
}
|
|
2937
|
+
function neighbors(after, edge, dragged, axis) {
|
|
2938
|
+
const me = after.items[dragged];
|
|
2939
|
+
const others = onEdge(after, edge, dragged, axis);
|
|
2940
|
+
const at = me ? mid(me.rect, axis) : 0;
|
|
2941
|
+
return { before: [...others].reverse().find((o) => mid(o.r, axis) < at)?.id ?? "^", next: others.find((o) => mid(o.r, axis) >= at)?.id ?? "$" };
|
|
2942
|
+
}
|
|
2943
|
+
function givesWay(now, after, lane, side, extent) {
|
|
2944
|
+
if (!now) return null;
|
|
2945
|
+
if (!after || after.inMenu || after.floating || after.edge !== lane) return "leaves";
|
|
2946
|
+
const [p0, p1] = extent(now.rect);
|
|
2947
|
+
const [q0, q1] = extent(after.rect);
|
|
2948
|
+
if (after.form !== now.form && q1 - q0 < p1 - p0 - 0.5) return "steps";
|
|
2949
|
+
return (side === "before" ? p1 - q1 : q0 - p0) > 0.5 ? "moves" : null;
|
|
2950
|
+
}
|
|
2951
|
+
function slackOf(state, id, axis, r) {
|
|
2952
|
+
const main = state.items[id]?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
|
|
2953
|
+
return main?.grows ? Math.max(0, len(r, axis) - main.natural) : 0;
|
|
2954
|
+
}
|
|
2955
|
+
function placeOf(se, l) {
|
|
2956
|
+
const counts = (id) => !(se.state.items[id]?.fixed && itemSteps6(se.state.items[id]));
|
|
2957
|
+
const shown = Object.entries(l.items).filter(([id, it]) => counts(id) && it.edge === se.e.id && !it.inMenu && !it.floating && it.rect.width > EPS18 && it.rect.height > EPS18).sort(([, p], [, q]) => lo(p.rect, se.axis) - lo(q.rect, se.axis)).map(([id]) => id);
|
|
2958
|
+
const menu = Object.entries(l.items).filter(([id, it]) => counts(id) && it.inMenu && it.edge === se.e.id).map(([id]) => id).sort();
|
|
2959
|
+
return `${shown.join(" ")} \xBB ${menu.join(" ")}`;
|
|
2960
|
+
}
|
|
2961
|
+
function endsIn(se, l, before, after) {
|
|
2962
|
+
const { e, axis } = se;
|
|
2963
|
+
const at = (id) => {
|
|
2964
|
+
const it = l.items[id];
|
|
2965
|
+
return it && it.edge === e.id && !it.inMenu && !it.floating ? it.rect : null;
|
|
2966
|
+
};
|
|
2967
|
+
const rb = before ? at(before) : void 0;
|
|
2968
|
+
const ra = after ? at(after) : void 0;
|
|
2969
|
+
if (rb === null || ra === null) return null;
|
|
2970
|
+
const el = l.edges[e.id]?.rect ?? se.drawn;
|
|
2971
|
+
const gap = nonNeg(e.gap);
|
|
2972
|
+
return {
|
|
2973
|
+
a: before && rb ? lo(rb, axis) + len(rb, axis) - slackOf(se.state, before, axis, rb) + gap : lo(el, axis) + nonNeg(e.pad?.start),
|
|
2974
|
+
// (Not before a growing item: a dock there keeps no space, the item it precedes takes all that is spare.)
|
|
2975
|
+
b: ra ? lo(ra, axis) - gap : lo(el, axis) + len(el, axis) - nonNeg(e.pad?.end)
|
|
2976
|
+
};
|
|
2977
|
+
}
|
|
2978
|
+
function slideRoom(se, before, after, preceding, w) {
|
|
2979
|
+
const { state, dragged, e, axis } = se;
|
|
2980
|
+
const zoneOf2 = (id) => zoneIn2(se.base, id);
|
|
2981
|
+
const zones = [...!before || zoneOf2(before) === "start" ? ["start"] : [], ...!after || zoneOf2(after) === "end" ? ["end"] : []];
|
|
2982
|
+
const atOf = (zone) => preceding.filter((id) => zoneOf2(id) === zone).length;
|
|
2983
|
+
const probe = (() => {
|
|
2984
|
+
const zone = zones[0];
|
|
2985
|
+
if (!zone) return null;
|
|
2986
|
+
const moved = moveTo(state, dragged, { edge: e.id, zone, at: atOf(zone), space: 0 });
|
|
2987
|
+
if (moved === state) return null;
|
|
2988
|
+
const l = solveLanded(markUsed(moved, dragged), dragged, se.prev);
|
|
2989
|
+
const landed = l.items[dragged];
|
|
2990
|
+
if (!landed || landed.inMenu || landed.edge !== e.id) return null;
|
|
2991
|
+
const n = neighbors(l, e.id, dragged, axis);
|
|
2992
|
+
if (n.before !== (before ?? "^") || n.next !== (after ?? "$")) return null;
|
|
2993
|
+
const r = endsIn(se, l, before, after);
|
|
2994
|
+
return r && { ...r, w: len(landed.rect, axis), layout: l };
|
|
2995
|
+
})();
|
|
2996
|
+
const seen = endsIn(se, se.base, before, after);
|
|
2997
|
+
const width = probe?.w ?? w;
|
|
2998
|
+
if (!probe && !seen || width === void 0) return null;
|
|
2999
|
+
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";
|
|
3000
|
+
const a = probe && (zones.includes("start") || !pushed(before, "before")) ? probe.a : (seen ?? probe).a;
|
|
3001
|
+
const b = probe && (zones.includes("end") || !pushed(after, "after")) ? probe.b : (seen ?? probe).b;
|
|
3002
|
+
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) } : {} };
|
|
3003
|
+
}
|
|
3004
|
+
function landsAt(se, place, x0) {
|
|
3005
|
+
const { state, dragged, axis } = se;
|
|
3006
|
+
const moved = moveTo(state, dragged, place);
|
|
3007
|
+
if (moved === state) return null;
|
|
3008
|
+
const next = markUsed(moved, dragged);
|
|
3009
|
+
const layout = solveLanded(next, dragged, se.prev);
|
|
3010
|
+
const landed = layout.items[dragged];
|
|
3011
|
+
if (!landed || landed.inMenu || landed.edge !== se.e.id || Math.abs(lo(landed.rect, axis) - x0) > 1) return null;
|
|
3012
|
+
const kept = (f) => {
|
|
3013
|
+
const it = layout.items[f.id];
|
|
3014
|
+
if (it?.inMenu && itemSteps6(state.items[f.id])) return true;
|
|
3015
|
+
return !!it && Math.abs(lo(it.rect, axis) - lo(f.r, axis)) <= 1;
|
|
3016
|
+
};
|
|
3017
|
+
if (!se.fixed.every(kept)) return null;
|
|
3018
|
+
return { next, layout };
|
|
3019
|
+
}
|
|
3020
|
+
function slideLand(se, room, x0) {
|
|
3021
|
+
const near = x0 + room.w / 2 < se.middle ? "start" : "end";
|
|
3022
|
+
for (const zone of [near, near === "start" ? "end" : "start"]) {
|
|
3023
|
+
if (!room.zones.includes(zone)) continue;
|
|
3024
|
+
const space = room.spaceAt(zone, x0);
|
|
3025
|
+
if (space < -EPS18) continue;
|
|
3026
|
+
const place = { edge: se.e.id, zone, at: room.atOf(zone), space: Math.max(0, space) };
|
|
3027
|
+
const hit = landsAt(se, place, x0);
|
|
3028
|
+
if (hit && (room.place === void 0 || placeOf(se, hit.layout) === room.place)) return { place, result: { state: hit.next, layout: hit.layout } };
|
|
3029
|
+
}
|
|
3030
|
+
return null;
|
|
3031
|
+
}
|
|
3032
|
+
function slideRange(se, room, sample) {
|
|
3033
|
+
const memo2 = /* @__PURE__ */ new Map();
|
|
3034
|
+
const land = (x0) => {
|
|
3035
|
+
if (!memo2.has(x0)) memo2.set(x0, slideLand(se, room, x0));
|
|
3036
|
+
return memo2.get(x0);
|
|
3037
|
+
};
|
|
3038
|
+
const tries = rangeTries(room.a, room.b, room.w, sample);
|
|
3039
|
+
const from = tries.find((x0) => !!land(x0));
|
|
3040
|
+
if (from === void 0) return null;
|
|
3041
|
+
const to = [...tries].reverse().find((x0) => x0 <= from || !!land(x0));
|
|
3042
|
+
const start = land(from);
|
|
3043
|
+
const shape = start.result.layout.items[se.dragged].rect;
|
|
3044
|
+
const at = (x0) => se.axis === "x" ? rect14(x0, shape.y, room.w, shape.height) : rect14(shape.x, x0, shape.width, room.w);
|
|
3045
|
+
const nearest = (x0) => {
|
|
3046
|
+
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);
|
|
3047
|
+
return land(order.find(({ t }) => !!land(t)).t);
|
|
3048
|
+
};
|
|
3049
|
+
return { from, to, first: at(from), last: at(to), at, start, land, nearest };
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
// src/targets/tiles.ts
|
|
2777
3053
|
function tilerOf(spec) {
|
|
2778
3054
|
const data = EDGE_KINDS[spec.kind];
|
|
2779
3055
|
const v = spec.vertical;
|
|
2780
3056
|
const band = (a, b, after) => {
|
|
2781
3057
|
const [c0, c1] = spec.across(after);
|
|
2782
|
-
return v ?
|
|
3058
|
+
return v ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
|
|
2783
3059
|
};
|
|
2784
3060
|
const keepAt = (line, h) => v ? { x: h.x + h.width / 2, y: line } : { x: line, y: h.y + h.height / 2 };
|
|
2785
3061
|
const tile = (zone, hit, more) => ({ edge: spec.id, spec, edgeKind: spec.kind, vertical: v, zone, hit, ...more });
|
|
@@ -2787,10 +3063,10 @@ function tilerOf(spec) {
|
|
|
2787
3063
|
const h = t.hit;
|
|
2788
3064
|
const [h0, h1] = v ? [h.x, h.x + h.width] : [h.y, h.y + h.height];
|
|
2789
3065
|
const [c0, c1] = [Math.max(h0, spec.owned[0]), Math.min(h1, spec.owned[1])];
|
|
2790
|
-
const part = (a, b) => v ?
|
|
3066
|
+
const part = (a, b) => v ? rect15(a, h.y, b - a, h.height) : rect15(h.x, a, h.width, b - a);
|
|
2791
3067
|
const beyond = less([[h0, h1]], [spec.owned]);
|
|
2792
3068
|
if (beyond.length === 0) return [t];
|
|
2793
|
-
if (c1 - c0 <=
|
|
3069
|
+
if (c1 - c0 <= EPS19) return [{ ...t, order: data.overreach }];
|
|
2794
3070
|
const core = { ...t, hit: part(c0, c1), keep: t.keep && keepAt(v ? t.keep.y : t.keep.x, part(c0, c1)) };
|
|
2795
3071
|
return [core, ...beyond.map(([a, b]) => ({ ...t, kind: "reach", of: core, order: data.overreach, hit: part(a, b), keep: null }))];
|
|
2796
3072
|
};
|
|
@@ -2804,7 +3080,7 @@ function wholeRefusal(c, spec) {
|
|
|
2804
3080
|
const data = EDGE_KINDS[spec.kind];
|
|
2805
3081
|
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
3082
|
}
|
|
2807
|
-
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a >
|
|
3083
|
+
var hasRoom = (spans, away) => less(spans, away).some(([a, b]) => b - a > EPS19);
|
|
2808
3084
|
function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
2809
3085
|
const reserved = spec.reserved;
|
|
2810
3086
|
const lines = mine.map((s) => s.line);
|
|
@@ -2813,53 +3089,54 @@ function linesIn(spec, z, mine, pieces, [pa, pb], own) {
|
|
|
2813
3089
|
const free = less([[z.a, z.b]], reserved);
|
|
2814
3090
|
const freeLen = free.reduce((n, [a, b]) => n + (b - a), 0);
|
|
2815
3091
|
const spread = (x) => {
|
|
2816
|
-
if (hi - lo2 <=
|
|
3092
|
+
if (hi - lo2 <= EPS19 || freeLen <= EPS19) return x;
|
|
2817
3093
|
let d = (x - lo2) / (hi - lo2) * freeLen;
|
|
2818
3094
|
for (const [a, b] of free) {
|
|
2819
|
-
if (d <= b - a +
|
|
3095
|
+
if (d <= b - a + EPS19) return a + Math.min(d, b - a);
|
|
2820
3096
|
d -= b - a;
|
|
2821
3097
|
}
|
|
2822
3098
|
return free[free.length - 1][1];
|
|
2823
3099
|
};
|
|
2824
|
-
const past = lines.some((x) => x < z.a -
|
|
3100
|
+
const past = lines.some((x) => x < z.a - EPS19 || x > z.b + EPS19);
|
|
2825
3101
|
const nearer = (p, [a, b]) => p > a && p < b ? p - a < b - p ? a : b : p;
|
|
2826
3102
|
const proj = (x) => {
|
|
2827
3103
|
const q = reserved.reduce((r, s) => nearer(r, s), past ? spread(x) : x);
|
|
2828
3104
|
const p = own ? nearer(q, own) : q;
|
|
2829
|
-
if (pieces.some(([a, b]) => p >= a -
|
|
3105
|
+
if (pieces.some(([a, b]) => p >= a - EPS19 && p <= b + EPS19)) return p;
|
|
2830
3106
|
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
3107
|
};
|
|
2832
|
-
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) <
|
|
2833
|
-
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa -
|
|
3108
|
+
const ownEnd = (s) => !!own && s.home && (Math.abs(s.line - own[0]) < EPS19 || Math.abs(s.line - own[1]) < EPS19);
|
|
3109
|
+
const inPiece = mine.filter((s) => ownEnd(s) ? s.line >= pa - EPS19 && s.line <= pb + EPS19 : proj(s.line) >= pa - EPS19 && proj(s.line) <= pb + EPS19).sort((a, b) => proj(a.line) - proj(b.line) || a.line - b.line);
|
|
2834
3110
|
const projected = inPiece.map((s) => proj(s.line));
|
|
2835
|
-
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <=
|
|
3111
|
+
const at = projected.some((p, i) => i > 0 && p - projected[i - 1] <= EPS19) ? inPiece.map((_, i) => pa + (i + 0.5) * (pb - pa) / inPiece.length) : projected;
|
|
2836
3112
|
return { inPiece, at };
|
|
2837
3113
|
}
|
|
2838
3114
|
function reachStrips(c, spec, room, ends) {
|
|
2839
|
-
const inEdge = (s) => !!ends && s[0] < ends[1] -
|
|
3115
|
+
const inEdge = (s) => !!ends && s[0] < ends[1] - EPS19 && s[1] > ends[0] + EPS19;
|
|
2840
3116
|
const pieces = room.filter(inEdge);
|
|
2841
3117
|
if (!ends || pieces.length === 0) return { pieces: [...room], before: [], after: [] };
|
|
2842
3118
|
const [c0, c1] = spec.across();
|
|
2843
|
-
const bandOf2 = (a, b) => spec.vertical ?
|
|
3119
|
+
const bandOf2 = (a, b) => spec.vertical ? rect15(c0, a, c1 - c0, b - a) : rect15(a, c0, b - a, c1 - c0);
|
|
2844
3120
|
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 >
|
|
3121
|
+
const drawnBetween = (a, b) => b - a > EPS19 && across2.some((e) => !!e && e.cross > EPS19 && area4(e.rect) > EPS19 && overlaps4(e.rect, bandOf2(a, b)));
|
|
2846
3122
|
const first = pieces[0][0];
|
|
2847
3123
|
const last = pieces[pieces.length - 1][1];
|
|
2848
3124
|
return {
|
|
2849
3125
|
pieces,
|
|
2850
|
-
before: room.filter((s) => s[1] <= ends[0] +
|
|
2851
|
-
after: room.filter((s) => s[0] >= ends[1] -
|
|
3126
|
+
before: room.filter((s) => s[1] <= ends[0] + EPS19 && !drawnBetween(s[1], first)),
|
|
3127
|
+
after: room.filter((s) => s[0] >= ends[1] - EPS19 && !drawnBetween(last, s[0]))
|
|
2852
3128
|
};
|
|
2853
3129
|
}
|
|
2854
|
-
function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
3130
|
+
function tileEdge(c, spec, { cuts, bodies }, lost, slides) {
|
|
2855
3131
|
const whole = wholeRefusal(c, spec);
|
|
2856
3132
|
if (whole) return [whole];
|
|
2857
3133
|
const data = EDGE_KINDS[spec.kind];
|
|
2858
3134
|
const v = spec.vertical;
|
|
3135
|
+
const halves = !spec.edge || cutsByHalves(spec.edge);
|
|
2859
3136
|
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
3137
|
const { band, keepAt, tile, split } = tilerOf(spec);
|
|
2861
3138
|
const drawn = spec.edge ? c.now.edges[spec.id]?.rect : void 0;
|
|
2862
|
-
const alongLimit = drawn && (v ? drawn.height : drawn.width) >
|
|
3139
|
+
const alongLimit = drawn && (v ? drawn.height : drawn.width) > EPS19 ? v ? rect15(-1e9, drawn.y, 2e9, drawn.height) : rect15(drawn.x, -1e9, drawn.width, 2e9) : null;
|
|
2863
3140
|
const refused = (zone, hit, reason) => {
|
|
2864
3141
|
const inEdge = alongLimit ? meet(hit, alongLimit) : hit;
|
|
2865
3142
|
const shown = inEdge && meet(inEdge, c.state.stage);
|
|
@@ -2868,27 +3145,52 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2868
3145
|
const slots = distinctSlots(c, spec.slots);
|
|
2869
3146
|
const runs = [...spec.reserved].sort((p, q) => p[0] - q[0]).reduce((acc, [a, b]) => {
|
|
2870
3147
|
const last = acc[acc.length - 1];
|
|
2871
|
-
if (last && a <= last[1] +
|
|
3148
|
+
if (last && a <= last[1] + EPS19) acc[acc.length - 1] = [last[0], Math.max(last[1], b)];
|
|
2872
3149
|
else acc.push([a, b]);
|
|
2873
3150
|
return acc;
|
|
2874
3151
|
}, []);
|
|
2875
|
-
const wedged = (line) => runs.some(([a, b]) => line > a +
|
|
3152
|
+
const wedged = (line) => runs.some(([a, b]) => line > a + EPS19 && line < b - EPS19);
|
|
2876
3153
|
const homeSlot = spec.holds && own ? slots.find((s) => s.home && s.order !== void 0) : void 0;
|
|
2877
3154
|
const ends = alongLimit && drawn ? v ? [drawn.y, drawn.y + drawn.height] : [drawn.x, drawn.x + drawn.width] : null;
|
|
2878
3155
|
const out = [];
|
|
3156
|
+
const slotSpans = [];
|
|
3157
|
+
let ownKept = null;
|
|
3158
|
+
const ownRect = landedLayout(c.state, c.now, c.dragged, c.prev).items[c.dragged]?.rect ?? spec.own ?? void 0;
|
|
3159
|
+
const movesOthers = (s) => Object.entries(c.base.items).some(([id, it]) => {
|
|
3160
|
+
if (id === c.dragged || it.edge !== spec.id || it.inMenu) return false;
|
|
3161
|
+
const now = s.result.layout.items[id];
|
|
3162
|
+
return !now || Math.abs(now.rect.x - it.rect.x) > 0.5 || Math.abs(now.rect.y - it.rect.y) > 0.5;
|
|
3163
|
+
});
|
|
3164
|
+
const axis = v ? "y" : "x";
|
|
3165
|
+
const span = (r) => v ? [r.y, r.y + r.height] : [r.x, r.x + r.width];
|
|
3166
|
+
const orderIn = (l) => Object.entries(l.items).filter(([, it]) => it.edge === spec.id && !it.inMenu && !it.floating && area4(it.rect) > EPS19).sort(([, p], [, q]) => span(p.rect)[0] - span(q.rect)[0]).map(([id]) => id).join(" ");
|
|
3167
|
+
const homeOrder = orderIn(c.now);
|
|
3168
|
+
const nearHome = (s) => {
|
|
3169
|
+
if (halves || s.home || !spec.own || !ownRect || c.now.items[c.dragged]?.inMenu) return false;
|
|
3170
|
+
const l = s.result.layout.items[c.dragged]?.rect;
|
|
3171
|
+
return !!l && Math.abs((v ? l.y : l.x) - (v ? ownRect.y : ownRect.x)) < c.slack && movesOthers(s) && orderIn(s.result.layout) !== homeOrder;
|
|
3172
|
+
};
|
|
3173
|
+
const landingOf = (s) => s.home || nearHome(s) ? ownRect : s.result.layout.items[c.dragged]?.rect;
|
|
3174
|
+
const orders = /* @__PURE__ */ new Map();
|
|
3175
|
+
const orderOf = (s) => {
|
|
3176
|
+
let k = orders.get(s);
|
|
3177
|
+
if (k === void 0) orders.set(s, k = s.home || nearHome(s) ? homeOrder : orderIn(s.result.layout));
|
|
3178
|
+
return k;
|
|
3179
|
+
};
|
|
3180
|
+
const stretchesOf = [];
|
|
2879
3181
|
for (const z of spec.zones) {
|
|
2880
|
-
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a >
|
|
3182
|
+
const room = less([[z.a, z.b]], [...cuts, ...spec.reserved]).filter(([a, b]) => b - a > EPS19);
|
|
2881
3183
|
const { pieces, before, after } = reachStrips(c, spec, own ? less(room, [own]) : room, ends);
|
|
2882
3184
|
if (!hasRoom(pieces, bodies)) continue;
|
|
2883
3185
|
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 +
|
|
3186
|
+
const mine = lined.filter((s) => s.zone === z.zone && !wedged(s.line) && pieces.some(([a, b]) => b > s.line - data.reach + EPS19 && a < s.line + data.reach - EPS19));
|
|
2885
3187
|
const reason = spec.refuse(z.zone);
|
|
2886
3188
|
for (const [k, [pa, pb]] of pieces.entries()) {
|
|
2887
3189
|
const { inPiece, at } = linesIn(spec, z, mine, pieces, [pa, pb], own);
|
|
2888
3190
|
const stripsOf = (i) => [...k === 0 && i === 0 ? before : [], ...k === pieces.length - 1 && i === inPiece.length - 1 ? after : []];
|
|
2889
3191
|
if (inPiece.length === 0) {
|
|
2890
3192
|
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 +
|
|
3193
|
+
const near = mine.length === 0 || data.virtual || mine.some((s) => pb > s.line - data.reach + EPS19 && pa < s.line + data.reach - EPS19);
|
|
2892
3194
|
const joins = data.virtual ? mine.filter((s) => s.ok && !s.home) : [];
|
|
2893
3195
|
if (joins.length > 0) {
|
|
2894
3196
|
const s = joins.reduce((m, x) => Math.abs(x.line - (pa + pb) / 2) < Math.abs(m.line - (pa + pb) / 2) ? x : m);
|
|
@@ -2899,47 +3201,151 @@ function tileEdge(c, spec, { cuts, bodies }, lost) {
|
|
|
2899
3201
|
if (reason && near) out.push(...refused(z.zone, band(pa, pb), lone ? "own-place" : reason));
|
|
2900
3202
|
continue;
|
|
2901
3203
|
}
|
|
2902
|
-
const
|
|
3204
|
+
const meets = [];
|
|
3205
|
+
for (let i = 1; i < inPiece.length; i++) {
|
|
2903
3206
|
const [lo2, hi] = [at[i - 1], at[i]];
|
|
2904
|
-
const between = spec.cards.filter(([
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
3207
|
+
const between = spec.cards.filter(([u2, w2]) => u2 >= inPiece[i - 1].line - EPS19 && w2 <= inPiece[i].line + EPS19);
|
|
3208
|
+
const la = landingOf(inPiece[i - 1]);
|
|
3209
|
+
const lb = landingOf(inPiece[i]);
|
|
3210
|
+
const [u, w] = between[0] ?? [NaN, NaN];
|
|
3211
|
+
const mid3 = between.length === 1 ? aimCut(la ?? rect15(0, 0, 0, 0), lb ?? rect15(0, 0, 0, 0), v ? "y" : "x", 0, 0, 0, v ? rect15(0, u, 0, w - u) : rect15(u, 0, w - u, 0)) : NaN;
|
|
3212
|
+
meets[i] = mid3 > lo2 + EPS19 && mid3 < hi - EPS19 ? mid3 : (lo2 + hi) / 2;
|
|
3213
|
+
}
|
|
3214
|
+
const meet2 = (i) => meets[i];
|
|
2908
3215
|
inPiece.forEach((s, i) => {
|
|
2909
3216
|
const p = at[i];
|
|
2910
3217
|
const lim = data.virtual ? Infinity : data.reach;
|
|
2911
|
-
const
|
|
2912
|
-
const
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
3218
|
+
const a0 = Math.max(i === 0 ? pa : meet2(i), p - lim);
|
|
3219
|
+
const b0 = Math.min(i === inPiece.length - 1 ? pb : meet2(i + 1), p + lim);
|
|
3220
|
+
stretchesOf.push({ s, a: a0, b: b0, make: (a, b) => makeTiles(a, b) });
|
|
3221
|
+
const makeTiles = (a, b) => {
|
|
3222
|
+
if (b - a <= EPS19) {
|
|
3223
|
+
if (s.ok && !s.home) lost.push(s.id);
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
if (!hasRoom([[a, b]], bodies)) return;
|
|
3227
|
+
const homeTile = (id, u, w, line) => {
|
|
3228
|
+
const hit = band(u, w, s.home ? s.result.layout : void 0);
|
|
3229
|
+
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" } });
|
|
3230
|
+
};
|
|
3231
|
+
if (s.home || nearHome(s)) {
|
|
3232
|
+
for (const [u, w] of [[a, b], ...stripsOf(i)]) out.push(...split(homeTile(s.home ? s.id : homeSlot?.id ?? s.id, u, w, p)));
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
const faced = halves && homeSlot && s.order === homeSlot.order ? spec.cards.filter(([u, w]) => w > a + EPS19 && u < b - EPS19) : [];
|
|
3236
|
+
for (const [u, w] of faced) out.push(...split(homeTile(homeSlot.id, Math.max(u, a), Math.min(w, b), p)));
|
|
3237
|
+
for (const [u, w] of [...less([[a, b]], faced), ...stripsOf(i)]) {
|
|
3238
|
+
const line = Math.min(Math.max(p, u), w);
|
|
3239
|
+
const hit = band(u, w, s.result.layout);
|
|
3240
|
+
if (!s.ok) {
|
|
3241
|
+
out.push(...refused(z.zone, hit, roomReason(spec, z.zone)));
|
|
3242
|
+
continue;
|
|
3243
|
+
}
|
|
3244
|
+
slotSpans.push([u, w]);
|
|
3245
|
+
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 })));
|
|
3246
|
+
}
|
|
2921
3247
|
};
|
|
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
3248
|
});
|
|
2935
3249
|
}
|
|
2936
3250
|
}
|
|
2937
|
-
if (
|
|
3251
|
+
if (!halves) {
|
|
3252
|
+
const ownStretch = own && homeSlot ? [{ s: homeSlot, a: own[0], b: own[1], make: () => void 0 }] : [];
|
|
3253
|
+
const all = [...stretchesOf, ...ownStretch];
|
|
3254
|
+
const neighborsIn = (order) => {
|
|
3255
|
+
const ids = order.split(" ");
|
|
3256
|
+
const k = ids.indexOf(c.dragged);
|
|
3257
|
+
return k < 0 ? null : { ...k > 0 ? { before: ids[k - 1] } : {}, ...k + 1 < ids.length ? { after: ids[k + 1] } : {} };
|
|
3258
|
+
};
|
|
3259
|
+
const edgeRect = c.base.edges[spec.id]?.rect ?? drawn;
|
|
3260
|
+
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;
|
|
3261
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
3262
|
+
const rangeOf = (order) => {
|
|
3263
|
+
if (ranges.has(order)) return ranges.get(order);
|
|
3264
|
+
const key = `${spec.id} ${order}`;
|
|
3265
|
+
const known = c.slideRanges.get(key);
|
|
3266
|
+
const r = known !== void 0 ? known : (() => {
|
|
3267
|
+
const n = neighborsIn(order);
|
|
3268
|
+
const ids = order.split(" ");
|
|
3269
|
+
const room = n && slideEdge ? slideRoom(slideEdge, n.before, n.after, ids.slice(0, ids.indexOf(c.dragged))) : null;
|
|
3270
|
+
const range = room && slideEdge ? slideRange(slideEdge, room, c.slack > 0 ? 2 * c.slack : SPOT_PITCH) : null;
|
|
3271
|
+
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;
|
|
3272
|
+
})();
|
|
3273
|
+
c.slideRanges.set(key, r);
|
|
3274
|
+
ranges.set(order, r);
|
|
3275
|
+
if (r && slides) slides.push({ edge: spec.id, ...r });
|
|
3276
|
+
return r;
|
|
3277
|
+
};
|
|
3278
|
+
const rangeFor = (s) => {
|
|
3279
|
+
const l = landingOf(s);
|
|
3280
|
+
const r = l ? rangeOf(orderOf(s)) : null;
|
|
3281
|
+
const [l0, l1] = l ? span(l) : [NaN, NaN];
|
|
3282
|
+
return r && Math.abs(l1 - l0 - r.w) <= 1 && l0 >= r.from - 1 && l0 <= r.to + 1 ? r : null;
|
|
3283
|
+
};
|
|
3284
|
+
const firstOf = (s) => rangeFor(s)?.first ?? landingOf(s);
|
|
3285
|
+
const lastOf = (s) => rangeFor(s)?.last ?? landingOf(s);
|
|
3286
|
+
const mid3 = (r) => (span(r)[0] + span(r)[1]) / 2;
|
|
3287
|
+
const besideZone = (s) => {
|
|
3288
|
+
const before = neighborsIn(orderOf(s))?.before;
|
|
3289
|
+
return s.place.kind === "gap" && s.place.zone === zoneIn2(c.base, before) ? 0 : 1;
|
|
3290
|
+
};
|
|
3291
|
+
const inMenu = !!c.now.items[c.dragged]?.inMenu;
|
|
3292
|
+
const lands = all.filter((r) => (r.s.ok || r.s.home) && !!landingOf(r.s) && !(inMenu && r.s.home));
|
|
3293
|
+
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);
|
|
3294
|
+
const sameAt = (p, q) => span(landingOf(p)).every((x, n) => Math.abs(x - span(landingOf(q))[n]) < 0.5);
|
|
3295
|
+
const runs2 = [];
|
|
3296
|
+
const dropped = [];
|
|
3297
|
+
for (const r of sorted) {
|
|
3298
|
+
const last = runs2.at(-1);
|
|
3299
|
+
if (last && orderOf(last[0].s) === orderOf(r.s)) {
|
|
3300
|
+
last.push(r);
|
|
3301
|
+
continue;
|
|
3302
|
+
}
|
|
3303
|
+
if (runs2.some((run) => run.some((x) => !rangeFor(x.s) && !rangeFor(r.s) && sameAt(x.s, r.s)))) dropped.push(r);
|
|
3304
|
+
else runs2.push([r]);
|
|
3305
|
+
}
|
|
3306
|
+
const facing = (run, end) => run.map((r) => ({ r: end ? lastOf(r.s) : firstOf(r.s), s: r.s })).reduce((m, x) => end ? span(x.r)[1] > span(m.r)[1] ? x : m : span(x.r)[0] < span(m.r)[0] ? x : m);
|
|
3307
|
+
const heldIn = ({ r, s }) => {
|
|
3308
|
+
const laid2 = s.home || nearHome(s) ? c.own : s.result.layout.items[c.dragged];
|
|
3309
|
+
return c.grab(laid2 ? { ...laid2, rect: r } : void 0, sizeOf(r), "lane")[axis];
|
|
3310
|
+
};
|
|
3311
|
+
const cutOf = (p, q) => {
|
|
3312
|
+
const [a, b] = [facing(p, true), facing(q, false)];
|
|
3313
|
+
return aimCut(a.r, b.r, axis, heldIn(a), heldIn(b), c.slack);
|
|
3314
|
+
};
|
|
3315
|
+
const bandStart = ends?.[0] ?? -Infinity;
|
|
3316
|
+
const bandEnd = ends?.[1] ?? Infinity;
|
|
3317
|
+
const cuts2 = crossFreeCuts(runs2.length, (i, j) => cutOf(runs2[i], runs2[j]), (i) => runs2[i].some((x) => x.s.home), bandStart, bandEnd);
|
|
3318
|
+
const spans = [];
|
|
3319
|
+
runs2.forEach((run, i) => {
|
|
3320
|
+
const cp = i > 0 ? cuts2[i - 1] : Math.min(...run.map((r) => r.a));
|
|
3321
|
+
const cn = i + 1 < runs2.length ? cuts2[i] : Math.max(...run.map((r) => r.b));
|
|
3322
|
+
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)];
|
|
3323
|
+
const held = run.filter((r) => r.b - r.a > EPS19).sort((p, q) => p.a - q.a);
|
|
3324
|
+
if (held.length === 0) {
|
|
3325
|
+
const one = run.find((r) => !ownStretch.includes(r)) ?? run[0];
|
|
3326
|
+
[one.a, one.b] = [cp, Math.max(cp, cn)];
|
|
3327
|
+
} else {
|
|
3328
|
+
held[0].a = cp;
|
|
3329
|
+
held.at(-1).b = Math.max(cp, cn);
|
|
3330
|
+
}
|
|
3331
|
+
if (cn - cp > EPS19) spans.push([cp, cn]);
|
|
3332
|
+
});
|
|
3333
|
+
for (const r of dropped) r.a = r.b;
|
|
3334
|
+
for (const r of lands) if (r.s.ok && !r.s.home) lost.push(r.s.id);
|
|
3335
|
+
if (ownStretch[0]) ownKept = ownStretch[0].b - ownStretch[0].a > EPS19 ? [[ownStretch[0].a, ownStretch[0].b]] : [];
|
|
3336
|
+
for (const r of all.filter((x) => !lands.includes(x))) {
|
|
3337
|
+
const left = less([[r.a, r.b]], spans).filter(([u, w]) => w - u > EPS19);
|
|
3338
|
+
[r.a, r.b] = left.length ? left.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : [r.a, r.a];
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
for (const r of stretchesOf) r.make(r.a, r.b);
|
|
3342
|
+
if (own && spec.own && (ownKept === null || ownKept.length > 0)) {
|
|
2938
3343
|
const home = spec.slots.find((s) => s.home);
|
|
2939
|
-
const [
|
|
3344
|
+
const kept = ownKept ?? (halves ? [] : less([own], slotSpans).filter(([u, w]) => w - u > EPS19));
|
|
3345
|
+
const [a, b] = kept.length > 0 ? kept.reduce((m, x) => x[1] - x[0] > m[1] - m[0] ? x : m) : own;
|
|
2940
3346
|
const h = band(a, b);
|
|
2941
3347
|
const o = spec.own;
|
|
2942
|
-
const hit = v ?
|
|
3348
|
+
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
3349
|
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
3350
|
}
|
|
2945
3351
|
return out;
|
|
@@ -2957,7 +3363,7 @@ function placeReach(t, pieces, placed, landed, gone) {
|
|
|
2957
3363
|
if (at.length === 0 && gone.has(of)) {
|
|
2958
3364
|
const line = t.vertical ? of.keep.y : of.keep.x;
|
|
2959
3365
|
const whole = pieces.filter((p) => p.width >= 1 && p.height >= 1);
|
|
2960
|
-
const on = whole.filter((p) => t.vertical ? p.y <= line +
|
|
3366
|
+
const on = whole.filter((p) => t.vertical ? p.y <= line + EPS19 && line <= p.y + p.height + EPS19 : p.x <= line + EPS19 && line <= p.x + p.width + EPS19);
|
|
2961
3367
|
const kept = (on.length > 0 ? on : whole).reduce((a, p) => !a || area4(p) > area4(a) ? p : a, null);
|
|
2962
3368
|
if (kept) {
|
|
2963
3369
|
placed.push({ ...of, hit: kept });
|
|
@@ -2970,10 +3376,10 @@ function placeReach(t, pieces, placed, landed, gone) {
|
|
|
2970
3376
|
for (let k = 0; k < cover.length; k++) {
|
|
2971
3377
|
const h = cover[k];
|
|
2972
3378
|
const joint = pieces.find(
|
|
2973
|
-
(p) => t.vertical ? p.y <= h.y +
|
|
3379
|
+
(p) => t.vertical ? p.y <= h.y + EPS19 && p.y + p.height >= h.y + h.height - EPS19 && (Math.abs(p.x - h.x - h.width) < EPS19 || Math.abs(p.x + p.width - h.x) < EPS19) : p.x <= h.x + EPS19 && p.x + p.width >= h.x + h.width - EPS19 && (Math.abs(p.y - h.y - h.height) < EPS19 || Math.abs(p.y + p.height - h.y) < EPS19)
|
|
2974
3380
|
);
|
|
2975
3381
|
if (!joint) continue;
|
|
2976
|
-
const merged = t.vertical ?
|
|
3382
|
+
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
3383
|
placed[i] = cover.length > 1 ? withPieces(placed[i], cover.map((r, j) => j === k ? merged : r)) : { ...placed[i], hit: merged };
|
|
2978
3384
|
return;
|
|
2979
3385
|
}
|
|
@@ -3041,10 +3447,10 @@ function clipTiles(tiles, own, chrome, lost) {
|
|
|
3041
3447
|
}
|
|
3042
3448
|
|
|
3043
3449
|
// src/targets/rail-strip.ts
|
|
3044
|
-
import { EPS as
|
|
3450
|
+
import { EPS as EPS21, overlaps as overlaps5, rect as rect17, subtract as subtract4 } from "@n-uf/placement";
|
|
3045
3451
|
|
|
3046
3452
|
// src/targets/virtual.ts
|
|
3047
|
-
import { EPS as
|
|
3453
|
+
import { EPS as EPS20, clamp as clamp3, rect as rect16 } from "@n-uf/placement";
|
|
3048
3454
|
function ringsOf(c, side) {
|
|
3049
3455
|
const seen = sideRings(c.state.edges, side);
|
|
3050
3456
|
const kept = c.rest.edges.filter((e) => e.side === side).map((e) => seen.get(e.id) ?? e.ring);
|
|
@@ -3057,7 +3463,7 @@ function railOuter(c, side) {
|
|
|
3057
3463
|
const windowEdge = side === "left" ? state.stage.x : state.stage.x + state.stage.width;
|
|
3058
3464
|
if (!place) return windowEdge;
|
|
3059
3465
|
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 +
|
|
3466
|
+
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 + EPS20 : e.rect.x >= placeOuter - EPS20));
|
|
3061
3467
|
return barOutside ? placeOuter : windowEdge;
|
|
3062
3468
|
}
|
|
3063
3469
|
function collapsesAt(c, result, side) {
|
|
@@ -3088,13 +3494,13 @@ function columnLines(c, side, railLands) {
|
|
|
3088
3494
|
const { reach, place, edgePlace } = EDGE_KINDS.columnLine;
|
|
3089
3495
|
const stage = c.state.stage;
|
|
3090
3496
|
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 +
|
|
3497
|
+
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 + EPS20 : e.rect.x >= x - EPS20));
|
|
3092
3498
|
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 +
|
|
3499
|
+
const placeOf2 = (l, i) => {
|
|
3500
|
+
const atEdge = side === "left" ? l.x <= stage.x + EPS20 : l.x >= stage.x + stage.width - EPS20;
|
|
3095
3501
|
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
3502
|
const windowEdge = side === "left" ? stage.x : stage.x + stage.width;
|
|
3097
|
-
const boundary =
|
|
3503
|
+
const boundary = clamp3(l.x, stage.x, stage.x + stage.width);
|
|
3098
3504
|
const band0 = railFirst ? railOuter(c, side) + dir * RAIL_EDGE : boundary;
|
|
3099
3505
|
const line = band0 + dir * edgePlace / 2;
|
|
3100
3506
|
const span2 = (a, b) => [Math.min(a, b), Math.max(a, b)];
|
|
@@ -3103,7 +3509,7 @@ function columnLines(c, side, railLands) {
|
|
|
3103
3509
|
const most = state.columns?.[side]?.cross.max;
|
|
3104
3510
|
const tooThick = most !== void 0 && thickerThan(formsOf(state.items[dragged], "column"), most);
|
|
3105
3511
|
return lines.map((l, i) => {
|
|
3106
|
-
const p =
|
|
3512
|
+
const p = placeOf2(l, i);
|
|
3107
3513
|
return {
|
|
3108
3514
|
id: virtualEdgeId("column", side),
|
|
3109
3515
|
edge: null,
|
|
@@ -3122,7 +3528,7 @@ function columnLines(c, side, railLands) {
|
|
|
3122
3528
|
ownedAlong: p.owned,
|
|
3123
3529
|
drawn: false,
|
|
3124
3530
|
// Where the new column's edge lands: the line itself, inside the stage.
|
|
3125
|
-
marker: () =>
|
|
3531
|
+
marker: () => rect16(clamp3(l.x, stage.x, stage.x + stage.width), span.y, 0, span.height)
|
|
3126
3532
|
};
|
|
3127
3533
|
});
|
|
3128
3534
|
}
|
|
@@ -3149,7 +3555,7 @@ function ownColumnRun(c, side, rail) {
|
|
|
3149
3555
|
const tiles = shown.segments.filter((s) => s.edge === edge.id).map((s) => s.rect);
|
|
3150
3556
|
if (tiles.length === 0) return null;
|
|
3151
3557
|
const top = Math.min(...tiles.map((r) => r.y));
|
|
3152
|
-
const spec = railColumnSpec(c, edge,
|
|
3558
|
+
const spec = railColumnSpec(c, edge, rect16(shown.rect.x, top, shown.rect.width, Math.max(...tiles.map((r) => r.y + r.height)) - top));
|
|
3153
3559
|
if (!spec) return null;
|
|
3154
3560
|
const stays = ({ layout }) => layout.items[dragged]?.rail === side && layout.items[dragged]?.edge === edge.id;
|
|
3155
3561
|
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 +3593,7 @@ function railStops(c, side) {
|
|
|
3187
3593
|
} else {
|
|
3188
3594
|
const firstCol = mine.find((e) => e.column === true);
|
|
3189
3595
|
const outer = railOuter(c, side);
|
|
3190
|
-
zone =
|
|
3596
|
+
zone = rect16(side === "left" ? outer : outer - RAIL_EDGE, placeRect.y, RAIL_EDGE, placeRect.height);
|
|
3191
3597
|
stops2.push({ y: placeRect.y, ring: firstCol ? rings.before(firstCol) : rings.count });
|
|
3192
3598
|
}
|
|
3193
3599
|
const ownRail = now.items[dragged]?.rail === side;
|
|
@@ -3218,7 +3624,7 @@ function railStops(c, side) {
|
|
|
3218
3624
|
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
3625
|
ownedAlong: null,
|
|
3220
3626
|
drawn: !!rail && rail.segments.length > 0,
|
|
3221
|
-
marker: (s) =>
|
|
3627
|
+
marker: (s) => rect16(at.x, s.result.layout.items[dragged].rect.y, at.width, 0)
|
|
3222
3628
|
};
|
|
3223
3629
|
}
|
|
3224
3630
|
|
|
@@ -3234,11 +3640,11 @@ function columnStrip(c, side, policy) {
|
|
|
3234
3640
|
if (moved === c.state) return null;
|
|
3235
3641
|
const result = c.settle(markUsed(moved, c.dragged));
|
|
3236
3642
|
const el = result.layout.edges[edge.id];
|
|
3237
|
-
if (!el || el.rect.width <=
|
|
3643
|
+
if (!el || el.rect.width <= EPS21 || !collapsesAt(c, result, side)) return null;
|
|
3238
3644
|
const r = el.rect;
|
|
3239
3645
|
const railWidth = result.layout.items[c.dragged].tab ? r.width : edge.cross.rail ?? 30;
|
|
3240
3646
|
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:
|
|
3647
|
+
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
3648
|
}
|
|
3243
3649
|
function declaredStrip(c, side, policy) {
|
|
3244
3650
|
const template = c.state.columns?.[side];
|
|
@@ -3255,7 +3661,7 @@ function declaredStrip(c, side, policy) {
|
|
|
3255
3661
|
const cuts = [a, ...slots.slice(1).map((s, i) => (slots[i].line + s.line) / 2), b];
|
|
3256
3662
|
return {
|
|
3257
3663
|
side,
|
|
3258
|
-
rect:
|
|
3664
|
+
rect: rect17(x, a, w, b - a),
|
|
3259
3665
|
slots: slots.map((s, i) => ({ id: s.id, place: s.place, along: [cuts[i], cuts[i + 1]], result: s.result }))
|
|
3260
3666
|
};
|
|
3261
3667
|
}
|
|
@@ -3340,7 +3746,7 @@ ${r.zone}`) ?? [], r]);
|
|
|
3340
3746
|
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
3747
|
const renumbered = refused.map((r) => numbered.get(r) === r.id ? r : { ...r, id: numbered.get(r) });
|
|
3342
3748
|
for (const s of strips) {
|
|
3343
|
-
const grown = s.side === "left" ?
|
|
3749
|
+
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
3750
|
for (const sl of s.slots) {
|
|
3345
3751
|
const [a, b] = sl.along;
|
|
3346
3752
|
const slot = sl.result.layout.items[c.dragged].rect;
|
|
@@ -3348,8 +3754,8 @@ ${r.zone}`) ?? [], r]);
|
|
|
3348
3754
|
out.push({
|
|
3349
3755
|
id: sl.id,
|
|
3350
3756
|
priority: 1,
|
|
3351
|
-
hit:
|
|
3352
|
-
armedHit:
|
|
3757
|
+
hit: rect17(s.rect.x, a, s.rect.width, b - a),
|
|
3758
|
+
armedHit: rect17(grown.x, a, grown.width, b - a),
|
|
3353
3759
|
arm: "dwell",
|
|
3354
3760
|
// Armed, its room opens at once: a host that draws only a marker reads that from this one flag, as for any target.
|
|
3355
3761
|
opensRoom: true,
|
|
@@ -3370,7 +3776,7 @@ var withoutHits = (t) => {
|
|
|
3370
3776
|
function insideStrips(r, strips) {
|
|
3371
3777
|
const s = strips.find((x) => overlaps5(x.rect, r));
|
|
3372
3778
|
if (!s) return null;
|
|
3373
|
-
return s.side === "left" ?
|
|
3779
|
+
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
3780
|
}
|
|
3375
3781
|
function clearOfStrips(t, dragged, strips) {
|
|
3376
3782
|
return {
|
|
@@ -3381,17 +3787,17 @@ function clearOfStrips(t, dragged, strips) {
|
|
|
3381
3787
|
if (!at) return first;
|
|
3382
3788
|
let dx = 0;
|
|
3383
3789
|
for (const s of strips) {
|
|
3384
|
-
const r =
|
|
3790
|
+
const r = rect17(at.x + dx, at.y, at.width, at.height);
|
|
3385
3791
|
if (!overlaps5(r, s)) continue;
|
|
3386
3792
|
dx += s.x + s.width / 2 < r.x + r.width / 2 ? s.x + s.width - r.x : s.x - (r.x + r.width);
|
|
3387
3793
|
}
|
|
3388
|
-
return dx === 0 ? first : t.after({ x: at.x + dx + (grab?.x ?? at.width / 2), y: point.y }, grab);
|
|
3794
|
+
return dx === 0 ? first : t.after({ x: at.x + dx + (first.grab?.x ?? at.width / 2), y: point.y }, grab);
|
|
3389
3795
|
}
|
|
3390
3796
|
};
|
|
3391
3797
|
}
|
|
3392
3798
|
|
|
3393
3799
|
// src/targets/min-hit.ts
|
|
3394
|
-
import { EPS as
|
|
3800
|
+
import { EPS as EPS22, area as area5, rect as rect18, subtract as subtract5 } from "@n-uf/placement";
|
|
3395
3801
|
function kindOf(c, t) {
|
|
3396
3802
|
const p = parseTargetId(t.id);
|
|
3397
3803
|
if (!p) return null;
|
|
@@ -3404,8 +3810,8 @@ function kindOf(c, t) {
|
|
|
3404
3810
|
return null;
|
|
3405
3811
|
}
|
|
3406
3812
|
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) >
|
|
3813
|
+
var keepsMinHit = (r, m) => Math.min(r.width, r.height) >= m.across - EPS22 && Math.max(r.width, r.height) >= m.along - EPS22;
|
|
3814
|
+
var overlaps6 = (a, b) => Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x) > EPS22 && Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y) > EPS22;
|
|
3409
3815
|
var cut = (ps, g) => ps.flatMap((p) => subtract5(p, g)).filter((p) => p.width >= 1 && p.height >= 1);
|
|
3410
3816
|
var piecesOf = (t) => t.hits ?? [t.hit];
|
|
3411
3817
|
var withPieces2 = (t, ps) => {
|
|
@@ -3413,22 +3819,22 @@ var withPieces2 = (t, ps) => {
|
|
|
3413
3819
|
return { ...rest, hit: largest3(ps), ...ps.length > 1 ? { hits: ps } : {} };
|
|
3414
3820
|
};
|
|
3415
3821
|
function growths(r, axis, d) {
|
|
3416
|
-
const [lo2, hi] = axis === "x" ? [
|
|
3822
|
+
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
3823
|
const h = d / 2;
|
|
3418
|
-
const halves = axis === "x" ? [
|
|
3824
|
+
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
3825
|
return [[lo2], [hi], halves];
|
|
3420
3826
|
}
|
|
3421
3827
|
var union = (a, gs) => {
|
|
3422
3828
|
const x0 = Math.min(a.x, ...gs.map((g) => g.x));
|
|
3423
3829
|
const y0 = Math.min(a.y, ...gs.map((g) => g.y));
|
|
3424
|
-
return
|
|
3830
|
+
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
3831
|
};
|
|
3426
3832
|
function mayGrow(c, targets2, i, grow, minOf, zone, away) {
|
|
3427
3833
|
const s = c.state.stage;
|
|
3428
3834
|
for (const g of grow) {
|
|
3429
|
-
if (g.x < s.x -
|
|
3835
|
+
if (g.x < s.x - EPS22 || g.y < s.y - EPS22 || g.x + g.width > s.x + s.width + EPS22 || g.y + g.height > s.y + s.height + EPS22) return false;
|
|
3430
3836
|
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) >
|
|
3837
|
+
if (zone.reduce((ps, z) => ps.flatMap((p) => subtract5(p, z)), [g]).some((p) => area5(p) > EPS22)) return false;
|
|
3432
3838
|
}
|
|
3433
3839
|
return targets2.every((o, j) => {
|
|
3434
3840
|
if (j === i || o.free || !piecesOf(o).some((p) => grow.some((g) => overlaps6(p, g)))) return true;
|
|
@@ -3443,7 +3849,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
|
3443
3849
|
let best = null;
|
|
3444
3850
|
for (const [side] of growths(l, axis, d)) {
|
|
3445
3851
|
const g = side;
|
|
3446
|
-
const strip = (a, b) => axis === "x" ?
|
|
3852
|
+
const strip = (a, b) => axis === "x" ? rect18(g.x, a, g.width, b - a) : rect18(a, g.y, b - a, g.height);
|
|
3447
3853
|
const cuts = /* @__PURE__ */ new Set([along2[0], along2[1]]);
|
|
3448
3854
|
for (const o of targets2)
|
|
3449
3855
|
for (const p of piecesOf(o))
|
|
@@ -3463,7 +3869,7 @@ function partialGrowth(c, targets2, i, l, axis, d, m, minOf, zone, away) {
|
|
|
3463
3869
|
}
|
|
3464
3870
|
if (runStart !== null) runs.push([runStart, marks[marks.length - 1]]);
|
|
3465
3871
|
for (const [a, b] of runs.sort((p, q) => q[1] - q[0] - (p[1] - p[0]))) {
|
|
3466
|
-
if (b - a < m.along -
|
|
3872
|
+
if (b - a < m.along - EPS22) break;
|
|
3467
3873
|
const r = strip(a, b);
|
|
3468
3874
|
if (mayGrow(c, targets2, i, [r], minOf, zone, away) && (!best || area5(r) > area5(best))) best = r;
|
|
3469
3875
|
break;
|
|
@@ -3478,7 +3884,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3478
3884
|
const k = kindOf(c, t);
|
|
3479
3885
|
return k ? EDGE_KINDS[k].minHit : null;
|
|
3480
3886
|
};
|
|
3481
|
-
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width >
|
|
3887
|
+
const drawn = Object.entries(c.now.edges).filter(([, e]) => e.rect.width > EPS22 && e.rect.height > EPS22);
|
|
3482
3888
|
for (let i = 0; i < out.length; i++) {
|
|
3483
3889
|
const t = out[i];
|
|
3484
3890
|
const m = minOf(t);
|
|
@@ -3495,7 +3901,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3495
3901
|
const axis = step === "across" ? narrowX ? "x" : "y" : narrowX ? "y" : "x";
|
|
3496
3902
|
const size = axis === "x" ? l.width : l.height;
|
|
3497
3903
|
const d = (step === "across" ? m.across : m.along) - size;
|
|
3498
|
-
if (d <=
|
|
3904
|
+
if (d <= EPS22) continue;
|
|
3499
3905
|
let grow = growths(l, axis, d).find((g) => mayGrow(c, out, i, g, minOf, zone, away));
|
|
3500
3906
|
if (!grow && step === "across") grow = partialGrowth(c, out, i, l, axis, d, m, minOf, zone, away) ?? void 0;
|
|
3501
3907
|
if (!grow) continue;
|
|
@@ -3506,7 +3912,7 @@ function withMinHit(c, targets2, refusals2, zones) {
|
|
|
3506
3912
|
out[j] = withPieces2(o, grow.reduce((ps, g) => cut(ps, g), [...piecesOf(o)]));
|
|
3507
3913
|
}
|
|
3508
3914
|
const g0 = grow[0];
|
|
3509
|
-
const span = axis === "x" ?
|
|
3915
|
+
const span = axis === "x" ? rect18(l.x, g0.y, l.width, g0.height) : rect18(g0.x, l.y, g0.width, l.height);
|
|
3510
3916
|
const grown = union(span, grow);
|
|
3511
3917
|
const others = piecesOf(out[i]).filter((p) => p !== l);
|
|
3512
3918
|
out[i] = withPieces2(out[i], [...cut([...others, l], grown), grown]);
|
|
@@ -3547,12 +3953,16 @@ function emit2(c, placed) {
|
|
|
3547
3953
|
}
|
|
3548
3954
|
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
3955
|
let ownHome = null;
|
|
3956
|
+
let ownSlot = null;
|
|
3957
|
+
const homeTiles = [];
|
|
3550
3958
|
for (const t of placed) {
|
|
3551
3959
|
if (t.kind === "refuse") {
|
|
3552
3960
|
const n = rank.get(t);
|
|
3553
3961
|
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
3962
|
continue;
|
|
3555
3963
|
}
|
|
3964
|
+
if (t.kind === "home" && t.order === 0 && t.id !== homeId) ownSlot = t.hit;
|
|
3965
|
+
else if (t.kind === "home" && t.id !== homeId) homeTiles.push(t.hit);
|
|
3556
3966
|
if (t.kind === "home" && t.id === homeId) {
|
|
3557
3967
|
if (t.order === 0) ownHome = t.hit;
|
|
3558
3968
|
continue;
|
|
@@ -3574,27 +3984,36 @@ function emit2(c, placed) {
|
|
|
3574
3984
|
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
3985
|
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
3986
|
}
|
|
3987
|
+
if (!ownHome && ownSlot) {
|
|
3988
|
+
const o = now.items[dragged]?.rect;
|
|
3989
|
+
ownHome = (o ? meet(o, ownSlot) : null) ?? ownSlot;
|
|
3990
|
+
} else if (!ownHome && homeTiles.length > 0) {
|
|
3991
|
+
const o = now.items[dragged]?.rect;
|
|
3992
|
+
const largest4 = (rs) => rs.reduce((m, r) => area6(r) > area6(m) ? r : m);
|
|
3993
|
+
const met = o ? homeTiles.flatMap((h) => meet(o, h) ?? []) : [];
|
|
3994
|
+
ownHome = largest4(met.length > 0 ? met : homeTiles);
|
|
3995
|
+
}
|
|
3577
3996
|
return { targets: targets2, refused, ownHome };
|
|
3578
3997
|
}
|
|
3579
3998
|
function hull(a, b) {
|
|
3580
3999
|
const x = Math.min(a.x, b.x);
|
|
3581
4000
|
const y = Math.min(a.y, b.y);
|
|
3582
|
-
return
|
|
4001
|
+
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
4002
|
}
|
|
3584
4003
|
var thicknessChanges = (now, after) => {
|
|
3585
4004
|
const a = now.content;
|
|
3586
4005
|
const b = after.content;
|
|
3587
|
-
return Math.abs(b.x - a.x) >
|
|
4006
|
+
return Math.abs(b.x - a.x) > EPS23 || Math.abs(b.y - a.y) > EPS23 || Math.abs(b.x + b.width - (a.x + a.width)) > EPS23 || Math.abs(b.y + b.height - (a.y + a.height)) > EPS23;
|
|
3588
4007
|
};
|
|
3589
4008
|
var WINDOW_EDGE_KINDS = /* @__PURE__ */ new Set(["rail", "railStop", "sideBar", "columnLine"]);
|
|
3590
|
-
var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x +
|
|
4009
|
+
var touchesSide = (stage, pieces) => pieces.some((r) => r.x <= stage.x + EPS23 || r.x + r.width >= stage.x + stage.width - EPS23);
|
|
3591
4010
|
function slotOverMoved(now, lifted, after, slot, dragged, onto) {
|
|
3592
4011
|
const from = now.items[dragged]?.edge;
|
|
3593
4012
|
return Object.entries(now.items).some(([id, was]) => {
|
|
3594
4013
|
if (!overlaps7(slot, was.rect) || id === dragged || was.floating || was.edge === onto) return false;
|
|
3595
4014
|
const r = after.items[id]?.rect;
|
|
3596
4015
|
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) >
|
|
4016
|
+
return !!r && (Math.abs(r.x - start.x) > EPS23 || Math.abs(r.y - start.y) > EPS23 || Math.abs(r.width - start.width) > EPS23 || Math.abs(r.height - start.height) > EPS23);
|
|
3598
4017
|
});
|
|
3599
4018
|
}
|
|
3600
4019
|
function aloneRects(tiles) {
|
|
@@ -3619,24 +4038,23 @@ function generate(state, dragged, options) {
|
|
|
3619
4038
|
const g = generateShown(shown, dragged, options, hidden);
|
|
3620
4039
|
const prev = { ...options.previous ? { previous: options.previous } : {}, ...options.fresh ? { fresh: options.fresh } : {} };
|
|
3621
4040
|
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
|
-
};
|
|
4041
|
+
const wrap = (t) => ({
|
|
4042
|
+
...t,
|
|
4043
|
+
after: (point, grab) => {
|
|
4044
|
+
const a = t.after(point, grab);
|
|
4045
|
+
const held = a.grab ? { grab: a.grab } : {};
|
|
4046
|
+
if (a.state === shown) return { state, layout: showsIn ? solveLanded(state, dragged, prev) : a.layout, ...held };
|
|
4047
|
+
const on = t.place.kind === "gap" ? shown.edges.find((e) => t.place.kind === "gap" && e.id === t.place.edge) : void 0;
|
|
4048
|
+
const named = !!on && namesZone(on, state.items[dragged].kind);
|
|
4049
|
+
const back = withHiddenOf(state, a.state, lent, dragged, named, rezoned);
|
|
4050
|
+
const restored = showsIn ? prune(back) : back;
|
|
4051
|
+
const ringOf = new Map(a.state.edges.map((e) => [e.id, e.ring]));
|
|
4052
|
+
const renumbered = restored.edges.some((e) => e.hidden !== true && ringOf.get(e.id) !== e.ring);
|
|
4053
|
+
const layout = renumbered || showsIn || rezoned.size > 0 ? solveLanded(restored, dragged, prev) : a.layout;
|
|
4054
|
+
return { state: restored, layout, ...held };
|
|
4055
|
+
}
|
|
4056
|
+
});
|
|
4057
|
+
return { ...g, targets: g.targets.map(wrap), ...g.places ? { places: g.places.map(wrap) } : {} };
|
|
3640
4058
|
}
|
|
3641
4059
|
function generateShown(state, dragged, options, hidden) {
|
|
3642
4060
|
if (Object.hasOwn(state.items, dragged) && state.items[dragged].fixed) return anchorTargets(state, dragged, options);
|
|
@@ -3649,11 +4067,12 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3649
4067
|
const along2 = new Map(live.map((s) => [s, alongOfSlots(s, alone.get(s))]));
|
|
3650
4068
|
const own = ownership(c, live, (s) => along2.get(s), (s) => aloneRects(alone.get(s)));
|
|
3651
4069
|
const lost = [];
|
|
3652
|
-
const
|
|
4070
|
+
const slides = [];
|
|
4071
|
+
const tiles = live.flatMap((spec) => tileEdge(c, spec, own.cutsOf(spec), lost, slides));
|
|
3653
4072
|
const ownRect = now.items[dragged];
|
|
3654
4073
|
const homeEdge = state.edges.find((e) => e.id === ownRect?.edge);
|
|
3655
4074
|
const homeHit = homeRectOf(c, null);
|
|
3656
|
-
if (ownRect && homeEdge && homeHit && !tiles.some((t) => t.order === 0))
|
|
4075
|
+
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
4076
|
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
4077
|
const placed = clipTiles(tiles, own, keepClearFor(state, now, "targets"), lost);
|
|
3659
4078
|
const { targets: targets2, refused, ownHome } = emit2(c, placed);
|
|
@@ -3663,10 +4082,9 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3663
4082
|
const fo = options.floatOrient ?? was?.orient ?? floatOrientOf(item);
|
|
3664
4083
|
const wasOrient = was?.orient ?? floatOrientOf(item);
|
|
3665
4084
|
const size = options.floatSize ?? (was && wasOrient === fo ? { width: was.rect.width, height: was.rect.height } : floatSizeOf(item, fo));
|
|
3666
|
-
const
|
|
3667
|
-
|
|
3668
|
-
const
|
|
3669
|
-
const handOf = (g) => g && grown ? { x: clamp2(g.x / grown.width, 0, 1) * size.width, y: clamp2(g.y / grown.height, 0, 1) * size.height } : g;
|
|
4085
|
+
const grabs = grabResolver(c.lift);
|
|
4086
|
+
let probe = null;
|
|
4087
|
+
const probeForm = () => (probe ??= { laid: solve(markUsed(floatAt(state, dragged, rect19(0, 0, size.width, size.height), options.floatOrient), dragged), prev).items[dragged] }).laid;
|
|
3670
4088
|
targets2.push({
|
|
3671
4089
|
id: targetId({ kind: "float", item: dragged }),
|
|
3672
4090
|
priority: 3,
|
|
@@ -3677,17 +4095,20 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3677
4095
|
item: dragged,
|
|
3678
4096
|
place: { kind: "float" },
|
|
3679
4097
|
after(point, grab) {
|
|
3680
|
-
const
|
|
3681
|
-
|
|
3682
|
-
|
|
4098
|
+
const aimed = (g2) => {
|
|
4099
|
+
const raw2 = options.floatFromHeld ? heldRect(state, dragged, size, point, g2) : rect19(point.x - g2.x, point.y - g2.y, size.width, size.height);
|
|
4100
|
+
return { raw: raw2, first: solve(markUsed(floatAt(state, dragged, raw2, options.floatOrient), dragged), prev) };
|
|
4101
|
+
};
|
|
4102
|
+
const { result, grab: g } = aimOnce(grabs(grab), "float", { laid: probeForm(), size }, aimed, (a) => a.first.items[dragged], (l) => sizeOf(l.rect));
|
|
4103
|
+
const { raw, first } = result;
|
|
3683
4104
|
const fitted = first.items[dragged]?.rect;
|
|
3684
4105
|
const at = fitted ?? raw;
|
|
3685
4106
|
const placed2 = (x, y, stays) => {
|
|
3686
|
-
const s = floatAt(state, dragged,
|
|
3687
|
-
return c.settle(markUsed(stays ? { ...s, floats: s.floats.map((f) => f.id === dragged ? { ...f, stays: true } : f) } : s, dragged));
|
|
4107
|
+
const s = floatAt(state, dragged, rect19(x, y, size.width, size.height), options.floatOrient);
|
|
4108
|
+
return { ...c.settle(markUsed(stays ? { ...s, floats: s.floats.map((f) => f.id === dragged ? { ...f, stays: true } : f) } : s, dragged)), grab: g };
|
|
3688
4109
|
};
|
|
3689
4110
|
const hand = heldRect(state, dragged, fitted ?? size, point, g);
|
|
3690
|
-
const on = { x:
|
|
4111
|
+
const on = { x: clamp4(point.x, hand.x, hand.x + hand.width), y: clamp4(point.y, hand.y, hand.y + hand.height) };
|
|
3691
4112
|
const clear = !first.notes.some((n) => n.code === "float-covers" && n.id === dragged);
|
|
3692
4113
|
if (!fitted || clear && contains(fitted, on)) return placed2(at.x, at.y, false);
|
|
3693
4114
|
const left = placed2(hand.x, hand.y, true);
|
|
@@ -3698,7 +4119,7 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3698
4119
|
});
|
|
3699
4120
|
}
|
|
3700
4121
|
(state.blocked ?? []).forEach((b, i) => {
|
|
3701
|
-
targets2.push({ id: targetId({ kind: "none", index: i }), priority: 1, hit:
|
|
4122
|
+
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
4123
|
});
|
|
3703
4124
|
const sameAsHome = targets2.filter((t) => t.place.kind === "home" && parseTargetId(t.id)?.kind === "column");
|
|
3704
4125
|
const homePieces = sameAsHome.flatMap((t) => t.hits ?? [t.hit]);
|
|
@@ -3719,15 +4140,22 @@ function generateShown(state, dragged, options, hidden) {
|
|
|
3719
4140
|
for (const t of [...alone.values()].flat()) if (t.kind !== "refuse" && t.id) zones.set(t.id, [...zones.get(t.id) ?? [], t.hit]);
|
|
3720
4141
|
const bounds = stageOf(state);
|
|
3721
4142
|
const held = withMinHit(c, layered.targets, layered.refusals, zones).map((t) => t.roomHit && t.slot ? { ...t, roomHit: hull(t.hit, t.slot) } : t);
|
|
3722
|
-
|
|
4143
|
+
const lostSet = new Set(lostIds);
|
|
4144
|
+
const places = live.flatMap(
|
|
4145
|
+
(spec) => spec.slots.filter((s) => lostSet.has(s.id) && s.ok && !s.home && s.place.kind === "gap" && !!s.result.layout.items[dragged]).map((s) => {
|
|
4146
|
+
const landed = s.result.layout.items[dragged].rect;
|
|
4147
|
+
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 };
|
|
4148
|
+
})
|
|
4149
|
+
).filter((t, i, all) => all.findIndex((x) => x.id === t.id) === i);
|
|
4150
|
+
return { targets: held, refusals: layered.refusals.map((r) => ({ ...r, bounds })), lost: lostIds, zones, slides, ...places.length ? { places } : {} };
|
|
3723
4151
|
}
|
|
3724
|
-
var stageOf = (state) =>
|
|
4152
|
+
var stageOf = (state) => rect19(state.stage.x, state.stage.y, state.stage.width, state.stage.height);
|
|
3725
4153
|
function targets(state, dragged, options = {}) {
|
|
3726
4154
|
return generate(state, dragged, options).targets;
|
|
3727
4155
|
}
|
|
3728
4156
|
function targetsAndRefusals(state, dragged, options = {}) {
|
|
3729
4157
|
const g = generate(state, dragged, options);
|
|
3730
|
-
return { targets: g.targets, refusals: g.refusals };
|
|
4158
|
+
return { targets: g.targets, refusals: g.refusals, places: g.places ?? [] };
|
|
3731
4159
|
}
|
|
3732
4160
|
function refusals(state, dragged, options = {}) {
|
|
3733
4161
|
return generate(state, dragged, options).refusals;
|
|
@@ -3757,10 +4185,11 @@ function stopsKey(dragged, o) {
|
|
|
3757
4185
|
prev = layoutIds.get(o.previous) ?? nextLayoutId++;
|
|
3758
4186
|
layoutIds.set(o.previous, prev);
|
|
3759
4187
|
}
|
|
3760
|
-
return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null]);
|
|
4188
|
+
return JSON.stringify([dragged, prev, o.endReach ?? null, o.floatOrient ?? null, o.floatSize ? [o.floatSize.width, o.floatSize.height] : null, o.fresh ?? null, grabKey(o.grab), o.pitch ?? null]);
|
|
3761
4189
|
}
|
|
3762
4190
|
function orderedStops(state, dragged, options) {
|
|
3763
|
-
const
|
|
4191
|
+
const g = generate(state, dragged, options);
|
|
4192
|
+
const list = [...g.targets, ...g.places ?? []].filter((t) => t.place.kind !== "home" && t.place.kind !== "none");
|
|
3764
4193
|
const sideOf = (t) => {
|
|
3765
4194
|
const p = t.place;
|
|
3766
4195
|
if (p.kind === "float") return "float";
|
|
@@ -3776,43 +4205,27 @@ function orderedStops(state, dragged, options) {
|
|
|
3776
4205
|
const rank = side === "float" ? 4 : SIDE_RANK[side];
|
|
3777
4206
|
return side === "left" ? [rank, cx, cy] : side === "right" ? [rank, -cx, cy] : [rank, cy * (side === "bottom" ? -1 : 1), cx];
|
|
3778
4207
|
};
|
|
3779
|
-
|
|
4208
|
+
const ZONE_RANK2 = { start: 0, center: 1, end: 2 };
|
|
4209
|
+
const inEdge = (a, b) => {
|
|
4210
|
+
const p = a.place;
|
|
4211
|
+
const q = b.place;
|
|
4212
|
+
return p.kind === "gap" && q.kind === "gap" && p.edge === q.edge ? ZONE_RANK2[p.zone] - ZONE_RANK2[q.zone] || p.at - q.at : 0;
|
|
4213
|
+
};
|
|
4214
|
+
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
4215
|
}
|
|
3781
4216
|
|
|
3782
4217
|
// 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;
|
|
4218
|
+
import { EPS as EPS24, area as area7, clamp as clamp5, rect as rect20, subtract as subtract6 } from "@n-uf/placement";
|
|
3787
4219
|
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;
|
|
4220
|
+
var mid2 = (r, axis) => lo(r, axis) + len(r, axis) / 2;
|
|
3791
4221
|
var hull2 = (a, b) => {
|
|
3792
4222
|
const x = Math.min(a.x, b.x);
|
|
3793
4223
|
const y = Math.min(a.y, b.y);
|
|
3794
|
-
return
|
|
4224
|
+
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
4225
|
};
|
|
3796
|
-
var
|
|
4226
|
+
var nonNeg2 = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
3797
4227
|
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
4228
|
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
4229
|
function liftedLayout(state, dragged, options) {
|
|
3817
4230
|
return solve(liftItem(state, dragged), options.previous ? { previous: options.previous } : {});
|
|
3818
4231
|
}
|
|
@@ -3829,25 +4242,25 @@ function clipAtDrawn(band, axis, cuts) {
|
|
|
3829
4242
|
const x = axis === "x" ? "y" : "x";
|
|
3830
4243
|
const line = lo(band, x) + len(band, x) / 2;
|
|
3831
4244
|
for (const c of cuts) {
|
|
3832
|
-
if (!(lo(c, x) < line -
|
|
4245
|
+
if (!(lo(c, x) < line - EPS24 && line < lo(c, x) + len(c, x) - EPS24)) continue;
|
|
3833
4246
|
const c0 = lo(c, axis);
|
|
3834
4247
|
const c1 = c0 + len(c, axis);
|
|
3835
4248
|
if ((c0 + c1) / 2 <= center) a = Math.max(a, c1);
|
|
3836
4249
|
else b = Math.min(b, c0);
|
|
3837
4250
|
}
|
|
3838
|
-
return b - a >
|
|
4251
|
+
return b - a > EPS24 ? along(band, axis, a, b) : band;
|
|
3839
4252
|
}
|
|
3840
4253
|
var memo = /* @__PURE__ */ new WeakMap();
|
|
3841
4254
|
var previousIds = /* @__PURE__ */ new WeakMap();
|
|
3842
4255
|
var nextPrevious = 1;
|
|
3843
4256
|
function keyOf(dragged, o) {
|
|
3844
|
-
const { previous, ...rest } = o;
|
|
4257
|
+
const { previous, grab, ...rest } = o;
|
|
3845
4258
|
let p = 0;
|
|
3846
4259
|
if (previous) {
|
|
3847
4260
|
if (!previousIds.has(previous)) previousIds.set(previous, nextPrevious++);
|
|
3848
4261
|
p = previousIds.get(previous);
|
|
3849
4262
|
}
|
|
3850
|
-
return `${dragged}\0${p}\0${JSON.stringify(rest)}`;
|
|
4263
|
+
return `${dragged}\0${p}\0${JSON.stringify(rest)}\0${JSON.stringify(grabKey(grab))}`;
|
|
3851
4264
|
}
|
|
3852
4265
|
function lanes(state, dragged, options = {}) {
|
|
3853
4266
|
const base = baseOf(state, dragged, options);
|
|
@@ -3866,7 +4279,7 @@ function marksIn(base, state, dragged, layout, held, emptyLanes) {
|
|
|
3866
4279
|
const on = heldEdge && !heldEdge.floating && !heldEdge.inMenu ? heldEdge.edge : void 0;
|
|
3867
4280
|
const built = base.lanes.flatMap((l) => {
|
|
3868
4281
|
const raws = base.raws.get(l.id);
|
|
3869
|
-
const again = raws ? laneFrom(l.id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.
|
|
4282
|
+
const again = raws ? laneFrom(l.id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(l.id), base.held, base.marking, l.id === on, l.id === on && held === "slide" ? MIN_BOX : void 0) : null;
|
|
3870
4283
|
return again ? [{ lane: again, over: laneRectOver(raws, layout, base.marking).rect }] : [];
|
|
3871
4284
|
});
|
|
3872
4285
|
const over2 = built.map(({ lane, over: r }) => ({ ...lane, rect: r }));
|
|
@@ -3883,7 +4296,7 @@ function newColumnsGiveWay(ls, idOf, state) {
|
|
|
3883
4296
|
}
|
|
3884
4297
|
function spotsIn(base, id, layout, dragged) {
|
|
3885
4298
|
const raws = base.raws.get(id);
|
|
3886
|
-
return raws ? laneFrom(id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(id), base.
|
|
4299
|
+
return raws ? laneFrom(id, raws, layout, base.seen, dragged, base.refusals, base.halves.has(id), base.held, base.marking)?.spots ?? null : null;
|
|
3887
4300
|
}
|
|
3888
4301
|
function rawSpot(base, id) {
|
|
3889
4302
|
for (const [lane, list] of base.raws) {
|
|
@@ -3894,17 +4307,18 @@ function rawSpot(base, id) {
|
|
|
3894
4307
|
}
|
|
3895
4308
|
function build(state, dragged, options) {
|
|
3896
4309
|
const seen = solve(state, options.previous ? { previous: options.previous } : {});
|
|
3897
|
-
const { targets: ts, refusals: rs } = targetsAndRefusals(state, dragged, options);
|
|
4310
|
+
const { targets: ts, refusals: rs, places } = targetsAndRefusals(state, dragged, options);
|
|
3898
4311
|
const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
|
|
3899
4312
|
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
3900
4313
|
const pitch = options.pitch === void 0 ? SPOT_PITCH : options.pitch;
|
|
4314
|
+
const lift = liftOf(state, seen, dragged, own?.rect);
|
|
3901
4315
|
const raws = [];
|
|
3902
4316
|
const axisOfEdge = (id) => {
|
|
3903
4317
|
const e = state.edges.find((x) => x.id === id);
|
|
3904
4318
|
return e && axisOf(e.side) === "column" ? "y" : "x";
|
|
3905
4319
|
};
|
|
3906
4320
|
const columnKey = (side, ring) => state.edges.find((e) => e.side === side && e.column === true && e.ring === ring)?.id ?? "$";
|
|
3907
|
-
for (const t of ts) {
|
|
4321
|
+
for (const t of [...ts, ...places]) {
|
|
3908
4322
|
if (t.free) continue;
|
|
3909
4323
|
const p = t.place;
|
|
3910
4324
|
if (p.kind === "gap" || p.kind === "home" && ownEdge) {
|
|
@@ -3928,14 +4342,14 @@ function build(state, dragged, options) {
|
|
|
3928
4342
|
}
|
|
3929
4343
|
const lifted = liftedLayout(state, dragged, options);
|
|
3930
4344
|
if (options.stretchPositions !== "pitched") {
|
|
3931
|
-
const { spots, absorbed } = slidingSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH);
|
|
4345
|
+
const { spots, absorbed } = slidingSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH, grabResolver(lift));
|
|
3932
4346
|
for (let i = raws.length - 1; i >= 0; i--) if (absorbed.has(raws[i])) raws.splice(i, 1);
|
|
3933
4347
|
raws.push(...spots);
|
|
3934
4348
|
} else if (pitch > 0) raws.push(...pitchedSpots(state, dragged, options, seen, lifted, raws, pitch));
|
|
3935
4349
|
raws.push(...takeoverSpots(state, dragged, options, seen, lifted, raws, pitch > 0 ? pitch : SPOT_PITCH));
|
|
3936
4350
|
const byLane = /* @__PURE__ */ new Map();
|
|
3937
4351
|
for (const r of raws) byLane.set(r.lane, [...byLane.get(r.lane) ?? [], r]);
|
|
3938
|
-
const halves = new Set(state.edges.filter(
|
|
4352
|
+
const halves = new Set(state.edges.filter(cutsByHalves).map((e) => e.id));
|
|
3939
4353
|
const marking = {
|
|
3940
4354
|
pitch,
|
|
3941
4355
|
natural: (id, axis) => {
|
|
@@ -3943,19 +4357,26 @@ function build(state, dragged, options) {
|
|
|
3943
4357
|
const main = it?.forms[axis === "x" ? "row" : "column"]?.[0]?.main;
|
|
3944
4358
|
return it?.fixed && main?.grows ? main.natural : void 0;
|
|
3945
4359
|
},
|
|
3946
|
-
gap: (edge) =>
|
|
3947
|
-
crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) >
|
|
4360
|
+
gap: (edge) => nonNeg2(state.edges.find((e) => e.id === edge)?.gap),
|
|
4361
|
+
crossing: (edge, over2) => state.edges.filter((e) => e.id !== edge && byLane.has(e.id) && (over2.edges[e.id]?.cross ?? 0) > EPS24 && axisOfEdge(e.id) !== axisOfEdge(edge)).map((e) => over2.edges[e.id].rect)
|
|
3948
4362
|
};
|
|
3949
|
-
const
|
|
3950
|
-
const
|
|
3951
|
-
const
|
|
3952
|
-
|
|
3953
|
-
|
|
4363
|
+
const grab = grabOf(lift, options.grab, options.onGrabNote);
|
|
4364
|
+
const heldAt = /* @__PURE__ */ new WeakMap();
|
|
4365
|
+
const held = (r, end) => {
|
|
4366
|
+
let both = heldAt.get(r);
|
|
4367
|
+
if (!both) {
|
|
4368
|
+
const laid2 = r.layout.items[dragged];
|
|
4369
|
+
const at = (x) => grab(laid2 ? { ...laid2, rect: x } : void 0, sizeOf(x), "lane")[r.axis];
|
|
4370
|
+
heldAt.set(r, both = [at(r.slide?.first ?? r.landing), at(r.slide?.last ?? r.landing)]);
|
|
4371
|
+
}
|
|
4372
|
+
return both[end ? 1 : 0];
|
|
4373
|
+
};
|
|
4374
|
+
const built = [...byLane].map(([id, list]) => laneFrom(id, list, seen, seen, dragged, rs, halves.has(id), held, marking)).filter((l) => !!l);
|
|
3954
4375
|
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
4376
|
const onLanes = new Set(laneList.map((l) => l.id));
|
|
3956
|
-
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width >
|
|
4377
|
+
const rails = Object.values(seen.rails).flatMap((r) => r && r.rect.width > EPS24 && r.rect.height > EPS24 ? [r.rect] : []);
|
|
3957
4378
|
const blocked = [
|
|
3958
|
-
...Object.values(seen.edges).filter((e) => e.cross >
|
|
4379
|
+
...Object.values(seen.edges).filter((e) => e.cross > EPS24).map((e) => e.rect),
|
|
3959
4380
|
...Object.entries(seen.items).filter(([id, it]) => id !== dragged && !it.floating && !it.inMenu).map(([, it]) => it.rect),
|
|
3960
4381
|
...keepClearFor(state, seen, "targets"),
|
|
3961
4382
|
...rails,
|
|
@@ -3971,7 +4392,8 @@ function build(state, dragged, options) {
|
|
|
3971
4392
|
seen,
|
|
3972
4393
|
refusals: rs,
|
|
3973
4394
|
halves,
|
|
3974
|
-
|
|
4395
|
+
grab,
|
|
4396
|
+
held,
|
|
3975
4397
|
marking,
|
|
3976
4398
|
regions: {
|
|
3977
4399
|
refused: rs.filter((f) => !onLanes.has(f.edge)).flatMap((f) => f.hits ?? [f.hit]),
|
|
@@ -4002,7 +4424,7 @@ function laneRectOver(list, over2, marking) {
|
|
|
4002
4424
|
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
4425
|
const drawnAt = drawnRect(over2, first.edge);
|
|
4004
4426
|
if (drawnAt) return { rect: drawnAt };
|
|
4005
|
-
const whole = axis === "x" ?
|
|
4427
|
+
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
4428
|
return { rect: clipAtDrawn(whole, axis, marking.crossing(first.edge, over2)), band: whole };
|
|
4007
4429
|
}
|
|
4008
4430
|
function drawnIn(layout, id) {
|
|
@@ -4011,19 +4433,20 @@ function drawnIn(layout, id) {
|
|
|
4011
4433
|
function drawnRect(layout, id) {
|
|
4012
4434
|
const e = layout.edges[id];
|
|
4013
4435
|
if (!e) return void 0;
|
|
4014
|
-
if (e.cross >
|
|
4436
|
+
if (e.cross > EPS24) return e.rect;
|
|
4015
4437
|
if (!e.folded) return void 0;
|
|
4016
4438
|
const run = Object.values(layout.rails).flatMap((r) => r?.segments.filter((g) => g.edge === id).map((g) => g.rect) ?? []);
|
|
4017
4439
|
return run.length > 0 ? run.reduce(hull2) : void 0;
|
|
4018
4440
|
}
|
|
4019
|
-
function laneFrom(id, list, drawn, seen, dragged, rs, halves,
|
|
4441
|
+
function laneFrom(id, list, drawn, seen, dragged, rs, halves, held, marking, showsHeld = false, besideFloor) {
|
|
4020
4442
|
if (list.length === 0) return null;
|
|
4021
4443
|
const first = list[0];
|
|
4022
4444
|
const axis = first.axis;
|
|
4023
4445
|
const { rect: laneRect, band: markBand } = laneRectOver(list, seen, marking);
|
|
4024
4446
|
const firstOf = (r) => r.slide?.first ?? r.landing;
|
|
4025
4447
|
const lastOf = (r) => r.slide?.last ?? r.landing;
|
|
4026
|
-
const
|
|
4448
|
+
const besideZone = (r) => r.target.place.kind === "gap" && r.target.place.zone === zoneIn2(seen, r.before) ? 0 : 1;
|
|
4449
|
+
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
4450
|
const homeAt = halves ? void 0 : list.find((r) => r.home)?.landing;
|
|
4028
4451
|
const nearHome = (r) => !!homeAt && !r.home && !r.slide && Math.abs(lo(r.landing, axis) - lo(homeAt, axis)) < Math.max(0, marking.pitch) / 2;
|
|
4029
4452
|
const unique = [];
|
|
@@ -4039,39 +4462,31 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
|
|
|
4039
4462
|
const bandStart = lo(whole, axis);
|
|
4040
4463
|
const bandEnd = bandStart + len(whole, axis);
|
|
4041
4464
|
const drawnItems = first.edge && halves ? new Map(onEdge(drawn, first.edge, dragged, axis).map((o) => [o.id, o.r])) : /* @__PURE__ */ new Map();
|
|
4042
|
-
const
|
|
4043
|
-
const cuts = [];
|
|
4044
|
-
for (let i = 0; i + 1 < unique.length; i++) {
|
|
4045
|
-
const a = unique[i];
|
|
4046
|
-
const b = unique[i + 1];
|
|
4465
|
+
const cutOf = (a, b) => {
|
|
4047
4466
|
const shared = a.next === b.before && a.next !== "$" ? drawnItems.get(a.next) : void 0;
|
|
4048
|
-
const
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
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
|
-
}
|
|
4467
|
+
const [la, lb] = [lastOf(a), firstOf(b)];
|
|
4468
|
+
return aimCut(la, lb, axis, halves ? len(la, axis) / 2 : held(a, true), halves ? len(lb, axis) / 2 : held(b, false), aimSlack(marking.pitch), shared);
|
|
4469
|
+
};
|
|
4470
|
+
const cuts = crossFreeCuts(unique.length, (i, j) => cutOf(unique[i], unique[j]), (i) => halves || !!unique[i].home, bandStart, bandEnd);
|
|
4058
4471
|
const spots = unique.flatMap((x, i) => {
|
|
4059
4472
|
const a = i === 0 ? bandStart : cuts[i - 1];
|
|
4060
4473
|
const b = i === unique.length - 1 ? bandEnd : cuts[i];
|
|
4061
|
-
const along2 = [
|
|
4062
|
-
return along2[1] - along2[0] >
|
|
4474
|
+
const along2 = [clamp5(a, start, end), clamp5(b, start, end)];
|
|
4475
|
+
return along2[1] - along2[0] > EPS24 || b - a <= EPS24 || x.home ? [{ x, along: along2 }] : [];
|
|
4063
4476
|
}).map(({ x, along: along2 }) => ({
|
|
4064
4477
|
id: x.id,
|
|
4065
4478
|
along: along2,
|
|
4066
4479
|
landing: x.landing,
|
|
4067
|
-
target
|
|
4480
|
+
// A sliding spot's target holds the pointer over its stretch only (its range of landings runs past the cuts either
|
|
4481
|
+
// side, over the neighbors' stretches).
|
|
4482
|
+
target: x.slide && along2[1] - along2[0] > EPS24 ? { ...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
4483
|
...x.home ? { home: true } : {},
|
|
4069
4484
|
...x.pitched ? { pitched: true } : {},
|
|
4070
4485
|
...x.slide ? { slide: { from: x.slide.from, to: x.slide.to, snaps: x.slide.snaps, snapDistance: x.slide.snapDistance, step: x.slide.step } } : {},
|
|
4071
4486
|
others: othersKey(x.layout, dragged)
|
|
4072
4487
|
}));
|
|
4073
4488
|
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: [
|
|
4489
|
+
const refused = first.edge ? rs.filter((f) => f.edge === first.edge).flatMap((f) => (f.hits ?? [f.hit]).map((h) => ({ along: [clamp5(lo(h, axis), start, end), clamp5(lo(h, axis) + len(h, axis), start, end)], reason: f.reason }))).filter((f) => f.along[1] - f.along[0] >= itemLen - EPS24) : [];
|
|
4075
4490
|
const places = new Set(unique.map((x) => `${x.before}|${x.next}`));
|
|
4076
4491
|
const drawnEdge = first.edge ? drawn.edges[first.edge] : void 0;
|
|
4077
4492
|
const markRect = (first.edge ? drawnRect(drawn, first.edge) : void 0) ?? laneRectOver(list, drawn, marking).band ?? markBand ?? laneRect;
|
|
@@ -4096,7 +4511,7 @@ function laneFrom(id, list, drawn, seen, dragged, rs, halves, share, marking, sh
|
|
|
4096
4511
|
}) : virtualMarks(id, unique, drawn.items[dragged]);
|
|
4097
4512
|
return { id, rect: laneRect, axis, spots, refused, marks, ...list.every((r) => r.strip) ? { owns: true } : {} };
|
|
4098
4513
|
}
|
|
4099
|
-
var along = (r, axis, a, b) => axis === "x" ?
|
|
4514
|
+
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
4515
|
var LINE2 = 2;
|
|
4101
4516
|
var MIN_BOX = 8;
|
|
4102
4517
|
var HATCH_END = 8;
|
|
@@ -4104,8 +4519,8 @@ var HATCH_EDGE = 8;
|
|
|
4104
4519
|
function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, more) {
|
|
4105
4520
|
const { besideMin } = more;
|
|
4106
4521
|
const hatches = (pair, a, b, p, q, gl, gr) => {
|
|
4107
|
-
if (gl && Math.abs(p - a) <
|
|
4108
|
-
if (gr && Math.abs(q - b) <
|
|
4522
|
+
if (gl && Math.abs(p - a) < EPS24) out.push({ id: `${lane}/hatch/${pair}:before`, kind: "hatch", rect: along(laneRect, axis, p, p + Math.min(HATCH_END, (q - p) / 2)), givesWay: gl });
|
|
4523
|
+
if (gr && Math.abs(q - b) < EPS24) 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
4524
|
};
|
|
4110
4525
|
const heldAt = items.find((o) => o.id === held);
|
|
4111
4526
|
const heldSpan = heldAt ? [lo(heldAt.r, axis), lo(heldAt.r, axis) + len(heldAt.r, axis)] : null;
|
|
@@ -4115,10 +4530,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4115
4530
|
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
4531
|
const isRefused2 = (v) => refused.some((f) => v >= f.along[0] && v <= f.along[1]);
|
|
4117
4532
|
for (let i = 0; i + 1 < ends.length; i++) {
|
|
4118
|
-
const a =
|
|
4119
|
-
const b =
|
|
4533
|
+
const a = clamp5(ends[i].b, start, end);
|
|
4534
|
+
const b = clamp5(ends[i + 1].a, start, end);
|
|
4120
4535
|
const pair = `${ends[i].id}|${ends[i + 1].id}`;
|
|
4121
|
-
if (ends[i + 1].a < start -
|
|
4536
|
+
if (ends[i + 1].a < start - EPS24 || ends[i].b > end + EPS24 || !lands(pair)) continue;
|
|
4122
4537
|
const left = ends[i].id === held ? ends[i - 1]?.id ?? "^" : ends[i].id;
|
|
4123
4538
|
const right = ends[i + 1].id === held ? ends[i + 2]?.id ?? "$" : ends[i + 1].id;
|
|
4124
4539
|
const named = `${left}|${right}`;
|
|
@@ -4127,12 +4542,12 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4127
4542
|
const spot = !beside && named === pair && items.length > 0 && !isRefused2((a + b) / 2) ? more.landingOf(pair) : void 0;
|
|
4128
4543
|
const gl = spot && left !== "^" && more.givesWay(left, "before", spot.layout) ? left : null;
|
|
4129
4544
|
const gr = spot && right !== "$" && more.givesWay(right, "after", spot.layout) ? right : null;
|
|
4130
|
-
if (b - a < min -
|
|
4131
|
-
if (spot && b - a >= besideMin -
|
|
4545
|
+
if (b - a < min - EPS24) {
|
|
4546
|
+
if (spot && b - a >= besideMin - EPS24) {
|
|
4132
4547
|
let ps = [[a, b]];
|
|
4133
4548
|
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
4549
|
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 -
|
|
4550
|
+
ps = ps.filter(([p, q]) => q - p >= MIN_BOX - EPS24);
|
|
4136
4551
|
ps.forEach(([p, q], k2) => {
|
|
4137
4552
|
out.push({ id: `${lane}/box/${pair}${k2 ? `#${k2}` : ""}`, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
4138
4553
|
hatches(pair, a, b, p, q, gl, gr);
|
|
@@ -4144,10 +4559,10 @@ function edgeMarks(lane, laneRect, axis, items, refused, itemLen, lands, held, m
|
|
|
4144
4559
|
continue;
|
|
4145
4560
|
}
|
|
4146
4561
|
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 >
|
|
4562
|
+
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 > EPS24);
|
|
4148
4563
|
let k = 0;
|
|
4149
4564
|
for (const [p, q] of pieces) {
|
|
4150
|
-
if (q - p < min -
|
|
4565
|
+
if (q - p < min - EPS24) continue;
|
|
4151
4566
|
const base = `${lane}/box/${named}${beside ? `:${beside}` : ""}${k++ ? `#${k - 1}` : ""}`;
|
|
4152
4567
|
out.push({ id: out.some((m) => m.id === base) ? `${base}~2` : base, kind: "box", rect: along(laneRect, axis, p, q) });
|
|
4153
4568
|
hatches(pair, a, b, p, q, gl, gr);
|
|
@@ -4159,8 +4574,8 @@ function virtualMarks(lane, spots, held) {
|
|
|
4159
4574
|
return spots.map((s) => {
|
|
4160
4575
|
const l = s.landing;
|
|
4161
4576
|
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:
|
|
4577
|
+
const x = mid2(held.rect, "x") < mid2(l, "x") ? l.x + l.width : l.x;
|
|
4578
|
+
return { id: `${lane}/line/${s.id}`, kind: "line", rect: rect20(x, l.y, 0, l.height) };
|
|
4164
4579
|
});
|
|
4165
4580
|
}
|
|
4166
4581
|
function inLane(l, r) {
|
|
@@ -4169,9 +4584,9 @@ function inLane(l, r) {
|
|
|
4169
4584
|
const y0 = Math.max(m.rect.y, r.y);
|
|
4170
4585
|
const x1 = Math.min(m.rect.x + m.rect.width, r.x + r.width);
|
|
4171
4586
|
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 -
|
|
4587
|
+
if (m.kind === "line") return x1 - x0 >= m.rect.width - EPS24 && y1 - y0 >= m.rect.height - EPS24 ? [m] : [];
|
|
4588
|
+
if (x1 - x0 <= EPS24 || y1 - y0 <= EPS24) return [];
|
|
4589
|
+
return x1 - x0 >= m.rect.width - EPS24 && y1 - y0 >= m.rect.height - EPS24 ? [m] : [{ ...m, rect: rect20(x0, y0, x1 - x0, y1 - y0) }];
|
|
4175
4590
|
});
|
|
4176
4591
|
return marks.length === l.marks.length && marks.every((m, i) => m === l.marks[i]) ? l : { ...l, marks };
|
|
4177
4592
|
}
|
|
@@ -4195,14 +4610,14 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4195
4610
|
const e = edge ? edgeOf(edge) : void 0;
|
|
4196
4611
|
return !!e && (e.side === "top" || e.side === "bottom" || !!e.compact);
|
|
4197
4612
|
};
|
|
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 >
|
|
4613
|
+
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 > EPS24 && it.rect.height > EPS24).map(([, it]) => it.rect) : [];
|
|
4199
4614
|
if (cuts.length === 0 && !(empty && (emptyLanes === "edge" || l.marks.some((m) => m.kind === "box" && stays.some((s) => overlaps8(m.rect, s)))))) return l;
|
|
4200
4615
|
const cut2 = (r, cs) => piecesLess(r, l.axis, cs);
|
|
4201
4616
|
const marks = [];
|
|
4202
4617
|
for (const m of l.marks) {
|
|
4203
4618
|
const kept = cut2(m.rect, m.kind === "box" ? [...cuts, ...stays] : cuts);
|
|
4204
4619
|
if (m.kind === "line") {
|
|
4205
|
-
if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) <
|
|
4620
|
+
if (kept.length === 1 && Math.abs(kept[0][1] - kept[0][0] - len(m.rect, l.axis)) < EPS24) marks.push(m);
|
|
4206
4621
|
continue;
|
|
4207
4622
|
}
|
|
4208
4623
|
kept.forEach(([p, q], i) => {
|
|
@@ -4215,11 +4630,11 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4215
4630
|
if (l.axis === "y") {
|
|
4216
4631
|
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
4632
|
const t = Math.min(HATCH_EDGE, piece.width);
|
|
4218
|
-
r =
|
|
4633
|
+
r = rect20(outerRight ? piece.x + piece.width - t : piece.x, piece.y, t, piece.height);
|
|
4219
4634
|
} else {
|
|
4220
4635
|
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
4636
|
const t = Math.min(HATCH_EDGE, piece.height);
|
|
4222
|
-
r =
|
|
4637
|
+
r = rect20(piece.x, outerBottom ? piece.y + piece.height - t : piece.y, piece.width, t);
|
|
4223
4638
|
}
|
|
4224
4639
|
marks.push({ id: id.replace("/box/", "/hatch/"), kind: "hatch", rect: r });
|
|
4225
4640
|
});
|
|
@@ -4228,12 +4643,12 @@ function settle(lane, drawn, state, dragged, all, emptyLanes = "real", within =
|
|
|
4228
4643
|
}
|
|
4229
4644
|
function piecesLess(r, axis, cs) {
|
|
4230
4645
|
const span = (x) => [lo(x, axis), lo(x, axis) + len(x, axis)];
|
|
4231
|
-
const crosses = (c) => axis === "x" ? c.y < r.y + r.height -
|
|
4646
|
+
const crosses = (c) => axis === "x" ? c.y < r.y + r.height - EPS24 && r.y < c.y + c.height - EPS24 : c.x < r.x + r.width - EPS24 && r.x < c.x + c.width - EPS24;
|
|
4232
4647
|
let ps = [span(r)];
|
|
4233
4648
|
for (const c of cs) {
|
|
4234
4649
|
if (!crosses(c)) continue;
|
|
4235
4650
|
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 >
|
|
4651
|
+
ps = ps.flatMap(([p, q]) => [[p, Math.min(q, c0)], [Math.max(p, c1), q]]).filter(([p, q]) => q - p > EPS24);
|
|
4237
4652
|
}
|
|
4238
4653
|
return ps;
|
|
4239
4654
|
}
|
|
@@ -4244,18 +4659,18 @@ function marksLess(marks, axis, cs, options = {}) {
|
|
|
4244
4659
|
const over2 = cs.filter((c) => overlaps8(m.rect, c));
|
|
4245
4660
|
if (over2.length === 0) return [m];
|
|
4246
4661
|
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)) <
|
|
4662
|
+
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)) < EPS24) ? [m] : [];
|
|
4248
4663
|
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
4664
|
});
|
|
4250
4665
|
}
|
|
4251
|
-
var overlaps8 = (a, b) => a.x < b.x + b.width -
|
|
4666
|
+
var overlaps8 = (a, b) => a.x < b.x + b.width - EPS24 && b.x < a.x + a.width - EPS24 && a.y < b.y + b.height - EPS24 && b.y < a.y + a.height - EPS24;
|
|
4252
4667
|
function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
4253
4668
|
const out = [];
|
|
4254
4669
|
stretches(state, dragged, options, seen, lifted, raws, (run) => {
|
|
4255
4670
|
const { e, axis, gap, middle } = run;
|
|
4256
4671
|
const taken = run.mine.map((r) => r.landing);
|
|
4257
4672
|
const emit3 = (zone, at, space, x0, flush) => {
|
|
4258
|
-
const hit = landsAt(
|
|
4673
|
+
const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
|
|
4259
4674
|
if (!hit) return false;
|
|
4260
4675
|
const { next, layout } = hit;
|
|
4261
4676
|
const landed = layout.items[dragged];
|
|
@@ -4273,12 +4688,12 @@ function pitchedSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4273
4688
|
};
|
|
4274
4689
|
return ({ a, b, w, zones, atOf, spaceAt, before, after }) => {
|
|
4275
4690
|
const end = (x0, order, flush) => {
|
|
4276
|
-
for (const zone of order) if (spaceAt(zone, x0) >= -
|
|
4691
|
+
for (const zone of order) if (spaceAt(zone, x0) >= -EPS24 && emit3(zone, atOf(zone), Math.max(0, spaceAt(zone, x0)), x0, flush)) return;
|
|
4277
4692
|
};
|
|
4278
4693
|
end(a, zones, before?.id ?? "^");
|
|
4279
|
-
if (b - w > a +
|
|
4694
|
+
if (b - w > a + EPS24) end(b - w, [...zones].reverse(), after?.id ?? "$");
|
|
4280
4695
|
if (b - a < w + pitch) return;
|
|
4281
|
-
for (let x0 = a + pitch; x0 + w <= b - pitch +
|
|
4696
|
+
for (let x0 = a + pitch; x0 + w <= b - pitch + EPS24; x0 += pitch) {
|
|
4282
4697
|
const zone = x0 + w / 2 < middle ? "start" : "end";
|
|
4283
4698
|
if (!zones.includes(zone)) continue;
|
|
4284
4699
|
emit3(zone, atOf(zone), spaceAt(zone, x0), x0);
|
|
@@ -4298,54 +4713,15 @@ function stretches(state, dragged, options, seen, lifted, raws, visit) {
|
|
|
4298
4713
|
const mine = raws.filter((r) => r.edge === e.id);
|
|
4299
4714
|
const drawn = base.edges[e.id] ?? seen.edges[e.id];
|
|
4300
4715
|
if (mine.length === 0 || !drawn) continue;
|
|
4301
|
-
const gap = nonNeg(e.gap);
|
|
4302
4716
|
const others = onEdge(base, e.id, dragged, axis);
|
|
4303
|
-
const
|
|
4717
|
+
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 };
|
|
4718
|
+
const each = visit(run);
|
|
4304
4719
|
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
4720
|
for (let i = 0; i <= others.length; i++) {
|
|
4326
4721
|
const before = others[i - 1];
|
|
4327
4722
|
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) });
|
|
4723
|
+
const room = slideRoom(run, before?.id, after?.id, others.slice(0, i).map((o) => o.id), w);
|
|
4724
|
+
if (room) each({ ...room, before, after, room });
|
|
4349
4725
|
}
|
|
4350
4726
|
}
|
|
4351
4727
|
}
|
|
@@ -4355,7 +4731,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4355
4731
|
const { e, axis } = run;
|
|
4356
4732
|
const taken = [...run.mine.map((r) => r.landing)];
|
|
4357
4733
|
const emit3 = (zone, at, space, x0, nb) => {
|
|
4358
|
-
const hit = landsAt(
|
|
4734
|
+
const hit = landsAt(run, { edge: e.id, zone, at, space }, x0);
|
|
4359
4735
|
if (!hit) return;
|
|
4360
4736
|
const { next, layout } = hit;
|
|
4361
4737
|
const landed = layout.items[dragged];
|
|
@@ -4367,7 +4743,7 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4367
4743
|
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
4744
|
};
|
|
4369
4745
|
return ({ w, zones, atOf, spaceAt, before, after }) => {
|
|
4370
|
-
const zoneOf2 = (id) =>
|
|
4746
|
+
const zoneOf2 = (id) => zoneIn2(run.base, id);
|
|
4371
4747
|
if (after && zones.includes("start") && zoneOf2(after.id) === "start" && !state.items[after.id]?.fixed) {
|
|
4372
4748
|
const x0 = lo(after.r, axis);
|
|
4373
4749
|
emit3("start", atOf("start"), Math.max(0, spaceAt("start", x0)), x0, after.id);
|
|
@@ -4380,50 +4756,19 @@ function takeoverSpots(state, dragged, options, seen, lifted, raws, pitch) {
|
|
|
4380
4756
|
});
|
|
4381
4757
|
return out;
|
|
4382
4758
|
}
|
|
4383
|
-
function
|
|
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
|
-
function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
4759
|
+
function slidingSpots(state, dragged, options, seen, lifted, raws, sample, grabs) {
|
|
4399
4760
|
const spots = [];
|
|
4400
4761
|
const absorbed = /* @__PURE__ */ new Set();
|
|
4401
4762
|
const snapDistance = Number.isFinite(options.snapDistance) && options.snapDistance >= 0 ? options.snapDistance : SNAP_DISTANCE;
|
|
4402
4763
|
const own = landedLayout(state, seen, dragged, options.previous ? { previous: options.previous } : {}).items[dragged];
|
|
4403
4764
|
const ownEdge = own && !own.floating && !own.inMenu ? own.edge : void 0;
|
|
4404
|
-
stretches(state, dragged, options, seen, lifted, raws, (run) => ({
|
|
4405
|
-
const { e, axis,
|
|
4765
|
+
stretches(state, dragged, options, seen, lifted, raws, (run) => ({ w, zones, atOf, spaceAt, before, after, room }) => {
|
|
4766
|
+
const { e, axis, mine } = run;
|
|
4406
4767
|
if (zones.length === 0) return;
|
|
4407
4768
|
{
|
|
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;
|
|
4769
|
+
const range = slideRange(run, room, sample);
|
|
4770
|
+
if (!range) return;
|
|
4771
|
+
const { from, to, land } = range;
|
|
4427
4772
|
const bId = before?.id ?? "^";
|
|
4428
4773
|
const nId = after?.id ?? "$";
|
|
4429
4774
|
if (to - from < STEP) {
|
|
@@ -4431,14 +4776,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4431
4776
|
const firstZone = (() => {
|
|
4432
4777
|
for (const zone3 of zones) {
|
|
4433
4778
|
const space = spaceAt(zone3, from);
|
|
4434
|
-
if (space < -
|
|
4779
|
+
if (space < -EPS24) continue;
|
|
4435
4780
|
const place2 = { edge: e.id, zone: zone3, at: atOf(zone3), space: Math.max(0, space) };
|
|
4436
|
-
const hit = landsAt(
|
|
4781
|
+
const hit = landsAt(run, place2, from);
|
|
4437
4782
|
if (hit) return { place: place2, result: { state: hit.next, layout: hit.layout } };
|
|
4438
4783
|
}
|
|
4439
4784
|
return null;
|
|
4440
4785
|
})();
|
|
4441
|
-
const { place, result } = firstZone ??
|
|
4786
|
+
const { place, result } = firstZone ?? range.start;
|
|
4442
4787
|
const landed = result.layout.items[dragged].rect;
|
|
4443
4788
|
const n = neighbors(result.layout, e.id, dragged, axis);
|
|
4444
4789
|
const zone2 = place.zone;
|
|
@@ -4460,13 +4805,14 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4460
4805
|
};
|
|
4461
4806
|
put(from);
|
|
4462
4807
|
put(to);
|
|
4463
|
-
|
|
4808
|
+
const beforeZone = zoneIn2(run.base, before?.id);
|
|
4809
|
+
const rank = (r) => r.home ? 0 : r.target.place.kind === "gap" && r.target.place.zone === beforeZone ? 1 : 2;
|
|
4810
|
+
for (const r of [...inside].sort((p, q) => rank(p) - rank(q))) put(lo(r.landing, axis), r);
|
|
4464
4811
|
const homeAt = homeRaw ? lo(homeRaw.landing, axis) : void 0;
|
|
4465
4812
|
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
4813
|
const snaps = kept.map((p) => p.at);
|
|
4467
4814
|
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);
|
|
4815
|
+
const { at } = range;
|
|
4470
4816
|
const snapped = (x0) => {
|
|
4471
4817
|
let best = x0;
|
|
4472
4818
|
let d = Infinity;
|
|
@@ -4474,9 +4820,9 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4474
4820
|
return best;
|
|
4475
4821
|
};
|
|
4476
4822
|
const startAt = (raw) => {
|
|
4477
|
-
const c =
|
|
4823
|
+
const c = clamp5(raw, from, to);
|
|
4478
4824
|
const s = snapped(c);
|
|
4479
|
-
return snaps.includes(s) ? s :
|
|
4825
|
+
return snaps.includes(s) ? s : clamp5(Math.round(c / STEP) * STEP, from, to);
|
|
4480
4826
|
};
|
|
4481
4827
|
const results = /* @__PURE__ */ new Map();
|
|
4482
4828
|
const commitAt = (x0) => {
|
|
@@ -4484,11 +4830,11 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4484
4830
|
const k = `${r ? "dock " : ""}${Math.round(x0 * 1e3) / 1e3}`;
|
|
4485
4831
|
const known = results.get(k);
|
|
4486
4832
|
if (known) return known;
|
|
4487
|
-
const result = r ? r.target.after(ORIGIN, ORIGIN) : land(x0)
|
|
4833
|
+
const result = r ? r.target.after(ORIGIN, ORIGIN) : (land(x0) ?? range.nearest(x0)).result;
|
|
4488
4834
|
results.set(k, result);
|
|
4489
4835
|
return result;
|
|
4490
4836
|
};
|
|
4491
|
-
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(
|
|
4837
|
+
const rest = homeRaw ? lo(homeRaw.landing, axis) : ownEdge === e.id && own ? snapped(clamp5(lo(own.rect, axis), from, to)) : from;
|
|
4492
4838
|
const restResult = commitAt(rest);
|
|
4493
4839
|
const ownZone = own?.zone;
|
|
4494
4840
|
const restPlace = (() => {
|
|
@@ -4497,8 +4843,16 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4497
4843
|
return p && p.kind === "gap" ? p : land(rest)?.place;
|
|
4498
4844
|
})();
|
|
4499
4845
|
const landing = homeRaw ? homeRaw.landing : restResult.layout.items[dragged]?.rect ?? at(rest);
|
|
4500
|
-
const
|
|
4501
|
-
const
|
|
4846
|
+
const restLaid = restResult.layout.items[dragged];
|
|
4847
|
+
const cross = restLaid?.rect ?? landing;
|
|
4848
|
+
const inStretch = axis === "x" ? { width: w, height: cross.height } : { width: cross.width, height: w };
|
|
4849
|
+
const aimed = /* @__PURE__ */ new Map();
|
|
4850
|
+
const withGrab = (r, g, x0) => {
|
|
4851
|
+
const k = `${Math.round(x0 * 1e3) / 1e3} ${g.x} ${g.y}`;
|
|
4852
|
+
let out = aimed.get(k);
|
|
4853
|
+
if (!out || out.state !== r.state) aimed.set(k, out = { ...r, grab: g });
|
|
4854
|
+
return out;
|
|
4855
|
+
};
|
|
4502
4856
|
const target = {
|
|
4503
4857
|
id: `slide:${e.id}:${bId}|${nId}`,
|
|
4504
4858
|
priority: 2,
|
|
@@ -4507,9 +4861,13 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4507
4861
|
item: dragged,
|
|
4508
4862
|
place: { kind: "gap", edge: e.id, zone: restPlace?.zone ?? zones[0], at: restPlace?.at ?? atOf(zones[0]), ...restPlace?.space ? { space: restPlace.space } : {} },
|
|
4509
4863
|
after: (point, grab) => {
|
|
4510
|
-
const
|
|
4511
|
-
const
|
|
4512
|
-
|
|
4864
|
+
const p = axis === "x" ? point.x : point.y;
|
|
4865
|
+
const aimAt = (g2) => {
|
|
4866
|
+
const x0 = startAt(p - g2[axis]);
|
|
4867
|
+
return { x0, r: commitAt(x0) };
|
|
4868
|
+
};
|
|
4869
|
+
const { result, grab: g } = aimOnce(grabs(grab), "lane", { laid: restLaid, size: inStretch }, aimAt, (a) => a.r.layout.items[dragged], (l) => sizeOf(l.rect));
|
|
4870
|
+
return withGrab(result.r, g, result.x0);
|
|
4513
4871
|
}
|
|
4514
4872
|
};
|
|
4515
4873
|
const zone = zones[0];
|
|
@@ -4525,6 +4883,8 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4525
4883
|
target,
|
|
4526
4884
|
hit: target.hit,
|
|
4527
4885
|
...homeRaw ? { home: true } : {},
|
|
4886
|
+
// Its stretch of the lane is cut from its range's end landings, where its drop lands at the hand: a range that runs
|
|
4887
|
+
// into a growing neighbor's slack (the room the drop makes; the neighbor gives way) cuts from there too.
|
|
4528
4888
|
slide: { from, to, snaps, snapDistance, step: STEP, first: at(from), last: at(to) }
|
|
4529
4889
|
});
|
|
4530
4890
|
}
|
|
@@ -4533,20 +4893,20 @@ function slidingSpots(state, dragged, options, seen, lifted, raws, sample) {
|
|
|
4533
4893
|
}
|
|
4534
4894
|
|
|
4535
4895
|
// src/drag.ts
|
|
4536
|
-
import { EPS as
|
|
4896
|
+
import { EPS as EPS25, area as area8, overlaps as overlaps9, subtract as subtract7 } from "@n-uf/placement";
|
|
4537
4897
|
var MIN_PIECE = 8;
|
|
4538
4898
|
function trimmedBy(marks, cs) {
|
|
4539
4899
|
if (cs.length === 0) return [...marks];
|
|
4540
4900
|
return marks.flatMap((m) => {
|
|
4541
4901
|
const r = m.rect;
|
|
4542
|
-
if (r.width <=
|
|
4543
|
-
const across2 = r.height <=
|
|
4902
|
+
if (r.width <= EPS25 || r.height <= EPS25) {
|
|
4903
|
+
const across2 = r.height <= EPS25;
|
|
4544
4904
|
const at = across2 ? r.y : r.x;
|
|
4545
4905
|
let pieces2 = [across2 ? [r.x, r.x + r.width] : [r.y, r.y + r.height]];
|
|
4546
4906
|
let touched = false;
|
|
4547
4907
|
for (const c of cs) {
|
|
4548
4908
|
const [lo2, hi] = across2 ? [c.y, c.y + c.height] : [c.x, c.x + c.width];
|
|
4549
|
-
if (!(at > lo2 +
|
|
4909
|
+
if (!(at > lo2 + EPS25 && at < hi - EPS25)) continue;
|
|
4550
4910
|
const [a, b] = across2 ? [c.x, c.x + c.width] : [c.y, c.y + c.height];
|
|
4551
4911
|
pieces2 = pieces2.flatMap(([s2, e2]) => {
|
|
4552
4912
|
if (b <= s2 || a >= e2) return [[s2, e2]];
|
|
@@ -4558,7 +4918,7 @@ function trimmedBy(marks, cs) {
|
|
|
4558
4918
|
const kept = pieces2.filter(([s2, e2]) => e2 - s2 >= 1);
|
|
4559
4919
|
if (kept.length === 0) return [];
|
|
4560
4920
|
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)) <
|
|
4921
|
+
if (Math.abs(s - (across2 ? r.x : r.y)) < EPS25 && Math.abs(e - s - (across2 ? r.width : r.height)) < EPS25) return [m];
|
|
4562
4922
|
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
4923
|
}
|
|
4564
4924
|
const over2 = cs.filter((c) => overlaps9(m.rect, c));
|
|
@@ -4577,7 +4937,12 @@ function dockDrag(state, dragged, options = {}) {
|
|
|
4577
4937
|
const fixed = /* @__PURE__ */ new Map();
|
|
4578
4938
|
const axisOf2 = new Map(base.lanes.map((l) => [l.id, l.axis]));
|
|
4579
4939
|
const flat = (ls) => ls.flatMap((l) => l.marks.map((m) => ({ ...m, lane: l.lane })));
|
|
4580
|
-
const
|
|
4940
|
+
const grabIn = (layout, lift = false) => {
|
|
4941
|
+
const laid2 = layout.items[dragged];
|
|
4942
|
+
if (laid2) return base.grab(laid2, sizeOf(laid2.rect), lift ? "lift" : laid2.floating ? "float" : "lane");
|
|
4943
|
+
return grab && typeof grab !== "function" ? { x: grab.x, y: grab.y } : ORIGIN2;
|
|
4944
|
+
};
|
|
4945
|
+
const rest = { state, layout: base.seen, landing: null, grab: grabIn(base.seen, true), marks: flat(base.lanes.map((l) => ({ lane: l.id, axis: l.axis, marks: l.marks }))) };
|
|
4581
4946
|
let lastFloat = null;
|
|
4582
4947
|
const of = (result, spot) => {
|
|
4583
4948
|
const known = byResult.get(result);
|
|
@@ -4585,7 +4950,7 @@ function dockDrag(state, dragged, options = {}) {
|
|
|
4585
4950
|
const it = result.layout.items[dragged];
|
|
4586
4951
|
const landing = it && !it.inMenu && (spot ? !it.floating : it.floating) ? it.rect : null;
|
|
4587
4952
|
const spots = spot ? spotsIn(base, spot.lane, result.layout, dragged) : null;
|
|
4588
|
-
const out = { ...result, landing, marks: flat(marksIn(base, state, dragged, result.layout, spot ? spot.slide ? "slide" : "spot" : false, options.emptyLanes)), ...spots ? { spots } : {} };
|
|
4953
|
+
const out = { ...result, landing, grab: result.grab ?? grabIn(result.layout), marks: flat(marksIn(base, state, dragged, result.layout, spot ? spot.slide ? "slide" : "spot" : false, options.emptyLanes)), ...spots ? { spots } : {} };
|
|
4589
4954
|
byResult.set(result, out);
|
|
4590
4955
|
return out;
|
|
4591
4956
|
};
|
|
@@ -4623,7 +4988,7 @@ function dockDrag(state, dragged, options = {}) {
|
|
|
4623
4988
|
const screenOf = (frame) => {
|
|
4624
4989
|
const held = after(frame.held);
|
|
4625
4990
|
if (frame.room || held === rest) return held;
|
|
4626
|
-
return held.landing ? { ...rest, landing: held.landing } : rest;
|
|
4991
|
+
return held.landing ? { ...rest, landing: held.landing, grab: held.grab } : rest;
|
|
4627
4992
|
};
|
|
4628
4993
|
const shownLayout = (frame) => screenOf(frame).layout;
|
|
4629
4994
|
const guides = (frame) => {
|
|
@@ -4652,7 +5017,7 @@ function dockDrag(state, dragged, options = {}) {
|
|
|
4652
5017
|
shown.push(near);
|
|
4653
5018
|
}
|
|
4654
5019
|
const drawnStays = [
|
|
4655
|
-
...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) >
|
|
5020
|
+
...state.edges.filter((e) => (e.side === "top" || e.side === "bottom" || !!e.compact) && (screen.layout.edges[e.id]?.cross ?? 0) > EPS25).map((e) => screen.layout.edges[e.id].rect),
|
|
4656
5021
|
...Object.values(screen.layout.rails).flatMap((r) => r?.segments.filter((g) => g.id !== dragged).map((g) => g.rect) ?? [])
|
|
4657
5022
|
];
|
|
4658
5023
|
const onScreen = [...shown.filter((s) => !s.created && s !== near).flatMap((s) => s.marks.map((m) => m.rect)), ...drawnStays, ...screen.landing ? [screen.landing] : []];
|
|
@@ -4728,15 +5093,15 @@ export {
|
|
|
4728
5093
|
dockHome,
|
|
4729
5094
|
storeDockState,
|
|
4730
5095
|
readDockState,
|
|
5096
|
+
SPOT_PITCH,
|
|
4731
5097
|
reservedRect,
|
|
4732
5098
|
targets,
|
|
4733
5099
|
refusals,
|
|
4734
5100
|
refusalTargets,
|
|
4735
5101
|
stops,
|
|
4736
|
-
SPOT_PITCH,
|
|
4737
5102
|
lanes,
|
|
4738
5103
|
HATCH_END,
|
|
4739
5104
|
HATCH_EDGE,
|
|
4740
5105
|
dockDrag
|
|
4741
5106
|
};
|
|
4742
|
-
//# sourceMappingURL=chunk-
|
|
5107
|
+
//# sourceMappingURL=chunk-Y2IM76RG.js.map
|