@n-uf/placement 26.11.56 → 26.11.58
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 +23 -0
- package/dist/index.d.ts +1 -0
- package/dist/side-zvoEwBLn.d.ts +10 -0
- package/dist/stack.d.ts +3 -4
- package/dist/stack.js.map +1 -1
- package/dist/tiling.d.ts +277 -57
- package/dist/tiling.js +367 -4
- package/dist/tiling.js.map +1 -1
- package/package.json +1 -1
package/dist/tiling.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
EPS,
|
|
3
|
+
clamp,
|
|
4
|
+
overlap
|
|
3
5
|
} from "./chunk-2UVUFEBP.js";
|
|
4
6
|
|
|
5
7
|
// src/tiling/order.ts
|
|
@@ -342,6 +344,362 @@ function giveWay(panes, layout, min, age) {
|
|
|
342
344
|
}
|
|
343
345
|
}
|
|
344
346
|
|
|
347
|
+
// src/tiling/drag.ts
|
|
348
|
+
var sameRect = (a, b) => Math.abs(a.x - b.x) <= EPS && Math.abs(a.y - b.y) <= EPS && Math.abs(a.width - b.width) <= EPS && Math.abs(a.height - b.height) <= EPS;
|
|
349
|
+
var px3 = (v) => v !== void 0 && Number.isFinite(v) && v > 0 ? v : 0;
|
|
350
|
+
function tilingDrag(tree, subject, options) {
|
|
351
|
+
const { ops, area } = options;
|
|
352
|
+
const normalize = (t) => ops.normalize ? ops.normalize(t) : t;
|
|
353
|
+
const lay2 = (t) => {
|
|
354
|
+
const { panes, splits } = layoutSplitTree(ops.split(t), area, options);
|
|
355
|
+
return { tree: t, layout: panes, splits };
|
|
356
|
+
};
|
|
357
|
+
const stackOf = (t, pane) => ops.stackOf?.(t, pane) ?? null;
|
|
358
|
+
const drawnAs = (t, pane) => stackOf(t, pane)?.active ?? pane;
|
|
359
|
+
const subjectKey = subject.kind === "pane" ? subject.pane : subject.stack.active;
|
|
360
|
+
const lift = lay2(tree);
|
|
361
|
+
const liftRect = lift.layout.get(drawnAs(tree, subjectKey));
|
|
362
|
+
if (!liftRect) {
|
|
363
|
+
const what = subject.kind === "pane" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`;
|
|
364
|
+
throw new Error(`tilingDrag: the subject (${what}) is not in the tree: it is neither drawn nor a member of a drawn stack`);
|
|
365
|
+
}
|
|
366
|
+
const base = lay2(ops.release(tree, subject));
|
|
367
|
+
const takesPane = panesOf(ops.split(base.tree)).length < panesOf(ops.split(tree)).length;
|
|
368
|
+
const home = takesPane ? { ...liftRect } : null;
|
|
369
|
+
const movedIn = (laid) => {
|
|
370
|
+
const own = drawnAs(laid.tree, subjectKey);
|
|
371
|
+
const out = [];
|
|
372
|
+
for (const [pane, to] of laid.layout) {
|
|
373
|
+
if (pane === own) continue;
|
|
374
|
+
const from = lift.layout.get(lift.layout.has(pane) ? pane : drawnAs(tree, pane));
|
|
375
|
+
if (from && !sameRect(from, to)) out.push({ pane, from, to });
|
|
376
|
+
}
|
|
377
|
+
return out;
|
|
378
|
+
};
|
|
379
|
+
const inSubject = (pane) => subject.kind === "pane" ? pane === subject.pane : subject.stack.members.includes(pane);
|
|
380
|
+
const refusalBefore = (held) => {
|
|
381
|
+
const at = held.at;
|
|
382
|
+
if (inSubject(at)) return { code: "self" };
|
|
383
|
+
if (held.kind === "swap") {
|
|
384
|
+
const own = stackOf(tree, subjectKey);
|
|
385
|
+
if (own && stackOf(tree, at)?.id === own.id) return { code: "self" };
|
|
386
|
+
}
|
|
387
|
+
if (!base.layout.has(at)) return { code: "missing" };
|
|
388
|
+
if (options.still?.(at)) return { code: "still" };
|
|
389
|
+
if (held.kind === "join" && !ops.join) return { code: "join" };
|
|
390
|
+
return null;
|
|
391
|
+
};
|
|
392
|
+
const refused = (held, refusal) => ({ ...lift, held, refusal, landing: null, moved: [] });
|
|
393
|
+
const roomFor = (at, side) => {
|
|
394
|
+
const r = base.layout.get(at);
|
|
395
|
+
if (canSplitPane(r, side, options).ok) return null;
|
|
396
|
+
const along = side === "left" || side === "right";
|
|
397
|
+
const gutter = px3(options.gap) + px3(options.handle);
|
|
398
|
+
const min = px3(options.min);
|
|
399
|
+
const span = along ? r.width : r.height;
|
|
400
|
+
return span < min * 2 + gutter ? { code: "room-along", need: min * 2 + gutter, have: span } : { code: "room-across", need: min, have: along ? r.height : r.width };
|
|
401
|
+
};
|
|
402
|
+
const make = (held) => {
|
|
403
|
+
if (held.kind === "home") return { ...lift, held, refusal: null, landing: liftRect, moved: [] };
|
|
404
|
+
const before = refusalBefore(held) ?? (held.kind === "beside" ? roomFor(held.at, held.side) : null);
|
|
405
|
+
if (before) return refused(held, before);
|
|
406
|
+
const changed = held.kind === "swap" ? ops.swap(tree, subject, held.at) : held.kind === "beside" ? ops.beside(base.tree, subject, held.at, held.side, { kind: "half" }) : ops.join(base.tree, subject, held.at, held.index);
|
|
407
|
+
const laid = lay2(normalize(changed));
|
|
408
|
+
const own = drawnAs(laid.tree, subjectKey);
|
|
409
|
+
const partner = drawnAs(laid.tree, held.at);
|
|
410
|
+
if (!dropFits(laid.layout, own, partner, area, { min: options.min, side: held.kind === "beside" ? held.side : "left" }).ok) {
|
|
411
|
+
const small = (r) => !r || r.width < px3(options.min) || r.height < px3(options.min);
|
|
412
|
+
return refused(held, { code: "fit", pane: small(laid.layout.get(own)) ? own : partner });
|
|
413
|
+
}
|
|
414
|
+
return { ...laid, held, refusal: null, landing: laid.layout.get(own) ?? null, moved: movedIn(laid) };
|
|
415
|
+
};
|
|
416
|
+
const homeAfter = make({ kind: "home" });
|
|
417
|
+
const memo = /* @__PURE__ */ new Map();
|
|
418
|
+
const after = (held) => {
|
|
419
|
+
if (held.kind === "home") return homeAfter;
|
|
420
|
+
const k = held.kind === "beside" ? `beside:${held.side}` : held.kind === "join" ? `join:${held.index ?? ""}` : "swap";
|
|
421
|
+
let byAt = memo.get(k);
|
|
422
|
+
if (!byAt) memo.set(k, byAt = /* @__PURE__ */ new Map());
|
|
423
|
+
let a = byAt.get(held.at);
|
|
424
|
+
if (!a) byAt.set(held.at, a = make(held));
|
|
425
|
+
return a;
|
|
426
|
+
};
|
|
427
|
+
return { subject, lift, base, home, after };
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/tiling/reference.ts
|
|
431
|
+
function mapKeys(split, fn) {
|
|
432
|
+
if (!split) return split;
|
|
433
|
+
if ("pane" in split) {
|
|
434
|
+
const k = fn(split.pane);
|
|
435
|
+
return k === split.pane ? split : { pane: k };
|
|
436
|
+
}
|
|
437
|
+
const a = mapKeys(split.a, fn);
|
|
438
|
+
const b = mapKeys(split.b, fn);
|
|
439
|
+
return a === split.a && b === split.b ? split : { ...split, a, b };
|
|
440
|
+
}
|
|
441
|
+
var stacksOf = (t) => t.stacks ?? [];
|
|
442
|
+
var of = (split, stacks) => stacks.length ? { split, stacks } : { split };
|
|
443
|
+
var membersOf = (s) => s.kind === "pane" ? [s.pane] : s.stack.members;
|
|
444
|
+
var drawnOf = (s) => s.kind === "pane" ? s.pane : s.stack.active;
|
|
445
|
+
function splitTreeOps() {
|
|
446
|
+
return {
|
|
447
|
+
split: (t) => t.split,
|
|
448
|
+
stackOf: (t, pane) => stacksOf(t).find((s) => s.members.includes(pane)) ?? null,
|
|
449
|
+
release(t, s) {
|
|
450
|
+
if (s.kind === "stack") {
|
|
451
|
+
const stack2 = stacksOf(t).find((x) => x.id === s.stack.id);
|
|
452
|
+
return of(removePane(t.split, stack2?.active ?? s.stack.active), stacksOf(t).filter((x) => x !== stack2));
|
|
453
|
+
}
|
|
454
|
+
const stack = stacksOf(t).find((x) => x.members.includes(s.pane));
|
|
455
|
+
if (!stack) return of(removePane(t.split, s.pane), stacksOf(t));
|
|
456
|
+
const i = stack.members.indexOf(s.pane);
|
|
457
|
+
const members = stack.members.filter((m) => m !== s.pane);
|
|
458
|
+
if (members.length === 0) return of(removePane(t.split, s.pane), stacksOf(t).filter((x) => x !== stack));
|
|
459
|
+
const active = stack.active === s.pane ? members[i] ?? members[i - 1] : stack.active;
|
|
460
|
+
const was = stack.active;
|
|
461
|
+
return of(
|
|
462
|
+
mapKeys(t.split, (k) => k === was ? active : k),
|
|
463
|
+
stacksOf(t).map((x) => x === stack ? { id: stack.id, members, active } : x)
|
|
464
|
+
);
|
|
465
|
+
},
|
|
466
|
+
beside(released, s, at, side) {
|
|
467
|
+
const split = splitPane(released.split, at, drawnOf(s), side);
|
|
468
|
+
return of(split, s.kind === "pane" ? stacksOf(released) : [...stacksOf(released), s.stack]);
|
|
469
|
+
},
|
|
470
|
+
swap(t, s, at) {
|
|
471
|
+
if (s.kind === "stack") {
|
|
472
|
+
const x2 = stacksOf(t).find((st) => st.id === s.stack.id)?.active ?? s.stack.active;
|
|
473
|
+
return of(mapKeys(t.split, (k) => k === x2 ? at : k === at ? x2 : k), stacksOf(t));
|
|
474
|
+
}
|
|
475
|
+
const x = s.pane;
|
|
476
|
+
const trade = (k) => k === x ? at : k === at ? x : k;
|
|
477
|
+
return of(
|
|
478
|
+
mapKeys(t.split, trade),
|
|
479
|
+
stacksOf(t).map((st) => ({ id: st.id, members: st.members.map(trade), active: trade(st.active) }))
|
|
480
|
+
);
|
|
481
|
+
},
|
|
482
|
+
join(released, s, at, index) {
|
|
483
|
+
const moving = membersOf(s);
|
|
484
|
+
const target = stacksOf(released).find((x) => x.members.includes(at));
|
|
485
|
+
const into = target ? target.members : [at];
|
|
486
|
+
const i = Math.max(0, Math.min(into.length, index ?? into.length));
|
|
487
|
+
const members = [...into.slice(0, i), ...moving, ...into.slice(i)];
|
|
488
|
+
const active = moving[0];
|
|
489
|
+
const drawn = target ? target.active : at;
|
|
490
|
+
const ids = new Set(stacksOf(released).map((x) => x.id));
|
|
491
|
+
let id = target?.id ?? `stack:${String(at)}`;
|
|
492
|
+
for (let n = 2; !target && ids.has(id); n++) id = `stack:${String(at)}:${n}`;
|
|
493
|
+
const stack = { id, members, active };
|
|
494
|
+
return of(
|
|
495
|
+
mapKeys(released.split, (k) => k === drawn ? active : k),
|
|
496
|
+
target ? stacksOf(released).map((x) => x === target ? stack : x) : [...stacksOf(released), stack]
|
|
497
|
+
);
|
|
498
|
+
},
|
|
499
|
+
normalize(t) {
|
|
500
|
+
const kept = stacksOf(t).filter((s) => s.members.length >= 2);
|
|
501
|
+
return kept.length === stacksOf(t).length ? t : of(t.split, kept);
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/tiling/conformance.ts
|
|
507
|
+
var TILING_PROPERTIES = [
|
|
508
|
+
/** `after(home).tree` is the lift tree itself, its layout the lift's, never normalized. */
|
|
509
|
+
"home-is-lift",
|
|
510
|
+
/** `home` is the subject's lift rect when the release takes a drawn pane away, else null. */
|
|
511
|
+
"home-is-the-gap",
|
|
512
|
+
/** Home lies only over base panes whose rect changed when the subject was released. */
|
|
513
|
+
"home-over-changed",
|
|
514
|
+
/** `after(held).layout` is `after(held).tree` laid out; the landing is the subject's rect there; a refused place is the lift. */
|
|
515
|
+
"one-layout",
|
|
516
|
+
/** A swap puts the partner in the subject's lift rect and the subject in the partner's, and the others keep theirs. Not checked under per-child layout callbacks (`fixed`, `fixedAcross`, `floor`), which may move the ratios. */
|
|
517
|
+
"swap-exchanges",
|
|
518
|
+
/** A swap puts the partner in the subject's old slot of the split (as it is drawn there) and the subject in the partner's. Checked under every option, the per-child callbacks included. */
|
|
519
|
+
"swap-trades-slots",
|
|
520
|
+
/** A pane swapped with a stack's drawn member takes its place in that stack, and the stack's other members stay, in order; a member torn out of a stack leaves the partner in its place there. */
|
|
521
|
+
"swap-keeps-stack-mates",
|
|
522
|
+
/**
|
|
523
|
+
* The subject is in every tree exactly once: no key (a drawn pane, or a member of a stack) is in an `after(held).tree`
|
|
524
|
+
* twice; the base holds none of the subject's members (a torn member's stack mates stay); and every `after(held).tree`
|
|
525
|
+
* holds the base's keys and the subject's, and no other. Catches an adapter whose `release` leaves the subject in.
|
|
526
|
+
*/
|
|
527
|
+
"subject-once",
|
|
528
|
+
/** `beside` and `join` commit `normalize(change(release(tree)))`: the subject is released first, then placed. */
|
|
529
|
+
"release-first",
|
|
530
|
+
/** A whole stack moves as one: after any change its members are in one stack, in their order. */
|
|
531
|
+
"stack-moves-whole",
|
|
532
|
+
/** `normalize` changes nothing on any `after(held).tree`. */
|
|
533
|
+
"normalize-idempotent",
|
|
534
|
+
/** The drag never changes the tree it is given, and remembers each held place (the same place, the same object). */
|
|
535
|
+
"nothing-changes"
|
|
536
|
+
];
|
|
537
|
+
function sameData(a, b) {
|
|
538
|
+
if (Object.is(a, b)) return true;
|
|
539
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
540
|
+
if (a instanceof Map || b instanceof Map) {
|
|
541
|
+
if (!(a instanceof Map && b instanceof Map) || a.size !== b.size) return false;
|
|
542
|
+
for (const [k, v] of a) if (!b.has(k) || !sameData(v, b.get(k))) return false;
|
|
543
|
+
return true;
|
|
544
|
+
}
|
|
545
|
+
if (a instanceof Set || b instanceof Set) {
|
|
546
|
+
if (!(a instanceof Set && b instanceof Set) || a.size !== b.size) return false;
|
|
547
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
551
|
+
const ka = Object.keys(a).filter((k) => a[k] !== void 0);
|
|
552
|
+
const kb = Object.keys(b).filter((k) => b[k] !== void 0);
|
|
553
|
+
if (ka.length !== kb.length) return false;
|
|
554
|
+
return ka.every((k) => sameData(a[k], b[k]));
|
|
555
|
+
}
|
|
556
|
+
function copy(v) {
|
|
557
|
+
if (typeof v !== "object" || v === null) return v;
|
|
558
|
+
if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copy(x)]));
|
|
559
|
+
if (v instanceof Set) return new Set([...v].map(copy));
|
|
560
|
+
if (Array.isArray(v)) return v.map(copy);
|
|
561
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, copy(x)]));
|
|
562
|
+
}
|
|
563
|
+
var near = (a, b, by = 0.5) => !!a && !!b && Math.abs(a.x - b.x) <= by && Math.abs(a.y - b.y) <= by && Math.abs(a.width - b.width) <= by && Math.abs(a.height - b.height) <= by;
|
|
564
|
+
function pathOf(split, key) {
|
|
565
|
+
if (!split) return null;
|
|
566
|
+
if ("pane" in split) return split.pane === key ? [] : null;
|
|
567
|
+
for (const side of ["a", "b"]) {
|
|
568
|
+
const rest = pathOf(split[side], key);
|
|
569
|
+
if (rest) return [side, ...rest];
|
|
570
|
+
}
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
function paneAt(split, path) {
|
|
574
|
+
let node = split;
|
|
575
|
+
for (const side of path) {
|
|
576
|
+
if (!node || "pane" in node) return void 0;
|
|
577
|
+
node = node[side];
|
|
578
|
+
}
|
|
579
|
+
return node && "pane" in node ? node.pane : void 0;
|
|
580
|
+
}
|
|
581
|
+
var sameList = (a, b) => a.length === b.length && a.every((k, i) => Object.is(k, b[i]));
|
|
582
|
+
var show = (h) => h.kind === "home" ? "home" : `${h.kind} ${String(h.at)}${h.kind === "beside" ? ` ${h.side}` : h.kind === "join" && h.index !== void 0 ? ` @${h.index}` : ""}`;
|
|
583
|
+
function tilingSubjects(tree, options) {
|
|
584
|
+
const { ops } = options;
|
|
585
|
+
const out = [];
|
|
586
|
+
for (const pane of panesOf(ops.split(tree))) {
|
|
587
|
+
const stack = ops.stackOf?.(tree, pane) ?? null;
|
|
588
|
+
if (!stack) out.push({ kind: "pane", pane });
|
|
589
|
+
else out.push({ kind: "stack", stack }, ...stack.members.map((m) => ({ kind: "pane", pane: m })));
|
|
590
|
+
}
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
function tilingConformance(trees, options, limit = 20) {
|
|
594
|
+
const { ops, area } = options;
|
|
595
|
+
const counts = Object.fromEntries(TILING_PROPERTIES.map((p) => [p, { checked: 0, failed: 0 }]));
|
|
596
|
+
const failures = [];
|
|
597
|
+
const norm = (t) => ops.normalize ? ops.normalize(t) : t;
|
|
598
|
+
const lay2 = (t) => layoutSplitTree(ops.split(t), area, options).panes;
|
|
599
|
+
const drawnAs = (t, k) => ops.stackOf?.(t, k)?.active ?? k;
|
|
600
|
+
const callbacks = !!(options.fixed || options.fixedAcross || options.floor);
|
|
601
|
+
const keysOf = (t) => panesOf(ops.split(t)).flatMap((p) => ops.stackOf?.(t, p)?.members ?? [p]);
|
|
602
|
+
const twice = (keys) => keys.filter((k, i) => keys.indexOf(k) !== i);
|
|
603
|
+
let n = 0;
|
|
604
|
+
for (const tree of trees) {
|
|
605
|
+
const snapshot = copy(tree);
|
|
606
|
+
for (const subject of tilingSubjects(tree, options)) {
|
|
607
|
+
const name = `tree ${n}, ${subject.kind === "pane" ? `pane ${String(subject.pane)}` : `stack ${subject.stack.id}`}`;
|
|
608
|
+
const check = (p, ok, why) => {
|
|
609
|
+
counts[p].checked++;
|
|
610
|
+
if (ok) return;
|
|
611
|
+
counts[p].failed++;
|
|
612
|
+
if (failures.length < limit) failures.push(`${p}: ${name}: ${why()}`);
|
|
613
|
+
};
|
|
614
|
+
const drag = tilingDrag(tree, subject, options);
|
|
615
|
+
const key = subject.kind === "pane" ? subject.pane : subject.stack.active;
|
|
616
|
+
const liftOf = (k) => drag.lift.layout.get(drag.lift.layout.has(k) ? k : drawnAs(tree, k));
|
|
617
|
+
const subjectLift = liftOf(key);
|
|
618
|
+
const members = subject.kind === "pane" ? [subject.pane] : subject.stack.members;
|
|
619
|
+
const baseKeys = keysOf(drag.base.tree);
|
|
620
|
+
const kept = baseKeys.filter((k) => members.includes(k));
|
|
621
|
+
check("subject-once", kept.length === 0 && twice(baseKeys).length === 0, () => `the base holds ${kept.length ? `the subject's ${kept.map(String).join(", ")}` : `${twice(baseKeys).map(String).join(", ")} twice`}`);
|
|
622
|
+
const want = /* @__PURE__ */ new Set([...baseKeys, ...members]);
|
|
623
|
+
const home = drag.after({ kind: "home" });
|
|
624
|
+
check("home-is-lift", home.tree === tree && sameData(home.layout, drag.lift.layout) && home.refusal === null, () => "after(home) is not the lift tree laid out");
|
|
625
|
+
const takes = panesOf(ops.split(drag.base.tree)).length < panesOf(ops.split(tree)).length;
|
|
626
|
+
check("home-is-the-gap", takes ? near(drag.home, subjectLift, EPS) : drag.home === null, () => `home ${JSON.stringify(drag.home)}, the release ${takes ? "takes" : "takes no"} drawn pane`);
|
|
627
|
+
if (drag.home) {
|
|
628
|
+
for (const [pane, r] of drag.base.layout) {
|
|
629
|
+
if (overlap(drag.home, r) <= EPS) continue;
|
|
630
|
+
check("home-over-changed", !near(r, liftOf(pane), EPS), () => `home lies over ${String(pane)}, which the release left at ${JSON.stringify(r)}`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const held = [{ kind: "home" }];
|
|
634
|
+
for (const at of drag.base.layout.keys()) {
|
|
635
|
+
held.push({ kind: "swap", at }, ...PANE_SIDES.map((side) => ({ kind: "beside", at, side })));
|
|
636
|
+
if (ops.join) held.push({ kind: "join", at }, { kind: "join", at, index: 0 });
|
|
637
|
+
}
|
|
638
|
+
for (const h of held) {
|
|
639
|
+
const a = drag.after(h);
|
|
640
|
+
check("nothing-changes", drag.after(h) === a, () => `${show(h)}: after() gave a new object for the same place`);
|
|
641
|
+
check("normalize-idempotent", sameData(norm(a.tree), a.tree), () => `${show(h)}: normalize changes after().tree`);
|
|
642
|
+
const keys = keysOf(a.tree);
|
|
643
|
+
const extra = keys.filter((k) => !want.has(k));
|
|
644
|
+
const lost = [...want].filter((k) => !keys.includes(k));
|
|
645
|
+
check(
|
|
646
|
+
"subject-once",
|
|
647
|
+
twice(keys).length === 0 && extra.length === 0 && lost.length === 0,
|
|
648
|
+
() => `${show(h)}: after().tree holds ${[twice(keys).length ? `${twice(keys).map(String).join(", ")} twice` : "", extra.length ? `${extra.map(String).join(", ")} it should not` : "", lost.length ? `no ${lost.map(String).join(", ")}` : ""].filter(Boolean).join("; ")}`
|
|
649
|
+
);
|
|
650
|
+
if (a.refusal) {
|
|
651
|
+
check("one-layout", a.tree === tree && a.landing === null && a.moved.length === 0, () => `${show(h)}: refused (${a.refusal.code}) but not the lift`);
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
const own = drawnAs(a.tree, key);
|
|
655
|
+
check("one-layout", sameData(a.layout, lay2(a.tree)) && near(a.landing, a.layout.get(own), EPS), () => `${show(h)}: the layout or the landing is not after().tree's`);
|
|
656
|
+
if (h.kind === "swap" && !callbacks) {
|
|
657
|
+
const partner = drawnAs(a.tree, h.at);
|
|
658
|
+
const exchanged = near(a.layout.get(partner), subjectLift) && near(a.layout.get(own), liftOf(h.at));
|
|
659
|
+
const others = [...a.layout].every(([p, r]) => p === own || p === partner || near(r, liftOf(p)));
|
|
660
|
+
check("swap-exchanges", exchanged && others, () => `${show(h)}: partner at ${JSON.stringify(a.layout.get(partner))} (subject was ${JSON.stringify(subjectLift)}), subject at ${JSON.stringify(a.layout.get(own))}${others ? "" : ", and another pane moved"}`);
|
|
661
|
+
}
|
|
662
|
+
if (h.kind === "swap") {
|
|
663
|
+
const liftSplit = ops.split(tree);
|
|
664
|
+
const afterSplit = ops.split(a.tree);
|
|
665
|
+
const subjectSlot = pathOf(liftSplit, drawnAs(tree, key));
|
|
666
|
+
const partnerSlot = pathOf(liftSplit, h.at);
|
|
667
|
+
const partnerThere = !!subjectSlot && paneAt(afterSplit, subjectSlot) === drawnAs(a.tree, h.at);
|
|
668
|
+
const subjectThere = !!partnerSlot && paneAt(afterSplit, partnerSlot) === drawnAs(a.tree, key);
|
|
669
|
+
check("swap-trades-slots", partnerThere && subjectThere, () => `${show(h)}: ${partnerThere ? "" : `the partner is not in the subject's old slot (${String(subjectSlot && paneAt(afterSplit, subjectSlot))} is)`}${partnerThere || subjectThere ? "" : "; "}${subjectThere ? "" : `the subject is not in the partner's old slot (${String(partnerSlot && paneAt(afterSplit, partnerSlot))} is)`}`);
|
|
670
|
+
if (subject.kind === "pane" && ops.stackOf) {
|
|
671
|
+
for (const [from, to] of [
|
|
672
|
+
[h.at, subject.pane],
|
|
673
|
+
[subject.pane, h.at]
|
|
674
|
+
]) {
|
|
675
|
+
const was = ops.stackOf(tree, from);
|
|
676
|
+
if (!was) continue;
|
|
677
|
+
const now = ops.stackOf(a.tree, to);
|
|
678
|
+
const expect = was.members.map((m) => m === from ? to : m);
|
|
679
|
+
check("swap-keeps-stack-mates", !!now && sameList(now.members, expect), () => `${show(h)}: ${String(to)} is in ${now ? `[${now.members.map(String).join(", ")}]` : "no stack"}, expected [${expect.map(String).join(", ")}]`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (h.kind === "beside" || h.kind === "join") {
|
|
684
|
+
const released = ops.release(tree, subject);
|
|
685
|
+
const changed = h.kind === "beside" ? ops.beside(released, subject, h.at, h.side, { kind: "half" }) : ops.join(released, subject, h.at, h.index);
|
|
686
|
+
check("release-first", sameData(a.tree, norm(changed)), () => `${show(h)}: after().tree is not normalize(change(release(tree)))`);
|
|
687
|
+
}
|
|
688
|
+
if (subject.kind === "stack" && h.kind !== "home") {
|
|
689
|
+
const ms = subject.stack.members;
|
|
690
|
+
const st = ops.stackOf?.(a.tree, ms[0]) ?? null;
|
|
691
|
+
const i = st ? st.members.indexOf(ms[0]) : -1;
|
|
692
|
+
const whole = !!st && ms.every((m, j) => st.members[i + j] === m);
|
|
693
|
+
check("stack-moves-whole", whole, () => `${show(h)}: the stack's members are not together in one stack`);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
check("nothing-changes", sameData(tree, snapshot), () => "the drag changed the tree it was given");
|
|
697
|
+
}
|
|
698
|
+
n++;
|
|
699
|
+
}
|
|
700
|
+
return { ok: failures.length === 0 && Object.values(counts).every((c) => c.failed === 0), failures, counts };
|
|
701
|
+
}
|
|
702
|
+
|
|
345
703
|
// src/tiling/neighbor.ts
|
|
346
704
|
function neighbor(rects, from, direction) {
|
|
347
705
|
const origin = rects.get(from);
|
|
@@ -360,8 +718,8 @@ function neighbor(rects, from, direction) {
|
|
|
360
718
|
const along = center(r, horizontal);
|
|
361
719
|
if (sign < 0 ? along >= fromAlong : along <= fromAlong) continue;
|
|
362
720
|
const [start, end] = reach(r, !horizontal);
|
|
363
|
-
const
|
|
364
|
-
const score = Math.abs(along - fromAlong) + Math.abs(center(r, !horizontal) - fromAcross) * 0.25 + (
|
|
721
|
+
const overlap2 = Math.max(0, Math.min(originEnd, end) - Math.max(originStart, start));
|
|
722
|
+
const score = Math.abs(along - fromAlong) + Math.abs(center(r, !horizontal) - fromAcross) * 0.25 + (overlap2 > 0 ? 0 : 100);
|
|
365
723
|
if (score < bestScore) {
|
|
366
724
|
bestScore = score;
|
|
367
725
|
best = key;
|
|
@@ -372,6 +730,7 @@ function neighbor(rects, from, direction) {
|
|
|
372
730
|
export {
|
|
373
731
|
PANE_REGION_DEFAULTS,
|
|
374
732
|
PANE_SIDES,
|
|
733
|
+
TILING_PROPERTIES,
|
|
375
734
|
canDropOnPane,
|
|
376
735
|
canSplitPane,
|
|
377
736
|
columns,
|
|
@@ -393,6 +752,10 @@ export {
|
|
|
393
752
|
removePane,
|
|
394
753
|
splitFromOrder,
|
|
395
754
|
splitPane,
|
|
396
|
-
|
|
755
|
+
splitTreeOps,
|
|
756
|
+
swapPanes,
|
|
757
|
+
tilingConformance,
|
|
758
|
+
tilingDrag,
|
|
759
|
+
tilingSubjects
|
|
397
760
|
};
|
|
398
761
|
//# sourceMappingURL=tiling.js.map
|