@draftably/editor 0.4.0 → 0.5.0

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.
@@ -207,8 +207,8 @@ function Vn(t, e, o = {}) {
207
207
  if (m.has(g)) continue;
208
208
  const y = [], P = [g];
209
209
  m.add(g);
210
- for (let A = 0; A < P.length; A++) {
211
- const w = P[A];
210
+ for (let O = 0; O < P.length; O++) {
211
+ const w = P[O];
212
212
  y.push(w);
213
213
  for (const k of d.get(w))
214
214
  m.has(k) || (m.add(k), P.push(k));
@@ -288,49 +288,49 @@ function ds(t, e, o, n) {
288
288
  if (o.mode === "rebuild" || o.ordering === "crossings") {
289
289
  const m = o.mode === "rebuild" ? e.declared : null, g = m ? c.map(
290
290
  (y) => y.slice().sort(
291
- (P, A) => (m.get(P) ?? 1 / 0) - (m.get(A) ?? 1 / 0) || ke(P, A)
291
+ (P, O) => (m.get(P) ?? 1 / 0) - (m.get(O) ?? 1 / 0) || ke(P, O)
292
292
  )
293
293
  ) : null;
294
294
  for (let y = 0; y < 10; y++) {
295
- const P = y % 2 === 0, A = P ? [...c.keys()] : [...c.keys()].reverse();
296
- for (const w of A) {
297
- const k = P ? e.inc : e.out, T = (F) => {
298
- const j = k.get(F).filter(($) => P ? e.rank.get($) < w : e.rank.get($) > w);
299
- return j.length ? j.reduce(($, v) => $ + u.get(v), 0) / j.length : u.get(F);
295
+ const P = y % 2 === 0, O = P ? [...c.keys()] : [...c.keys()].reverse();
296
+ for (const w of O) {
297
+ const k = P ? e.inc : e.out, F = (T) => {
298
+ const j = k.get(T).filter(($) => P ? e.rank.get($) < w : e.rank.get($) > w);
299
+ return j.length ? j.reduce(($, v) => $ + u.get(v), 0) / j.length : u.get(T);
300
300
  };
301
- c[w].sort((F, j) => T(F) - T(j) || u.get(F) - u.get(j) || ke(F, j)), i();
301
+ c[w].sort((T, j) => F(T) - F(j) || u.get(T) - u.get(j) || ke(T, j)), i();
302
302
  }
303
303
  }
304
304
  if (g) {
305
305
  const y = fs(e, l(c.length).map), P = c.map((w) => w.slice());
306
306
  g.forEach((w, k) => c[k] = w);
307
- const A = fs(e, l(c.length).map);
308
- A - y >= Ei(A) && P.forEach((w, k) => c[k] = w), i();
307
+ const O = fs(e, l(c.length).map);
308
+ O - y >= Ei(O) && P.forEach((w, k) => c[k] = w), i();
309
309
  }
310
310
  }
311
311
  function l(m) {
312
312
  const g = /* @__PURE__ */ new Map();
313
313
  let y = 0;
314
314
  for (let w = 0; w < c.length; w += m) {
315
- const k = Math.min(c.length, w + m), T = Math.max(...h.slice(w, k));
316
- let F = 0;
315
+ const k = Math.min(c.length, w + m), F = Math.max(...h.slice(w, k));
316
+ let T = 0;
317
317
  for (let j = w; j < k; j++) {
318
- let $ = y + (T - h[j]) / 2;
318
+ let $ = y + (F - h[j]) / 2;
319
319
  for (const v of c[j]) {
320
- const S = a.get(v), M = F + f[j] / 2, x = $ + d(S) / 2;
320
+ const S = a.get(v), M = T + f[j] / 2, x = $ + d(S) / 2;
321
321
  g.set(v, s ? { x, y: M } : { x: M, y: x }), $ += d(S) + o.nodeGap;
322
322
  }
323
- F += f[j] + o.rankGap;
323
+ T += f[j] + o.rankGap;
324
324
  }
325
- y += T + Math.max(o.rankGap + 40, 84);
325
+ y += F + Math.max(o.rankGap + 40, 84);
326
326
  }
327
327
  const P = Ie(
328
328
  t.map((w) => {
329
329
  const k = g.get(w.id);
330
330
  return { ...w, x: k.x - w.w / 2, y: k.y - w.h / 2 };
331
331
  })
332
- ), A = Math.abs(Math.log(P.w / P.h / n)) * 1.8 + Math.log(P.w * P.h) * 0.17 + (Math.ceil(c.length / m) - 1) * 0.16;
333
- return { map: g, score: A };
332
+ ), O = Math.abs(Math.log(P.w / P.h / n)) * 1.8 + Math.log(P.w * P.h) * 0.17 + (Math.ceil(c.length / m) - 1) * 0.16;
333
+ return { map: g, score: O };
334
334
  }
335
335
  let p = l(c.length);
336
336
  if (o.fold === "auto")
@@ -361,7 +361,7 @@ function $a(t, e, o, n) {
361
361
  function u(m) {
362
362
  const g = a.kids.get(m), y = Math.max(
363
363
  c(m),
364
- g.reduce((P, A) => P + u(A), 0) + Math.max(0, g.length - 1) * o.nodeGap
364
+ g.reduce((P, O) => P + u(O), 0) + Math.max(0, g.length - 1) * o.nodeGap
365
365
  );
366
366
  return d.set(m, y), y;
367
367
  }
@@ -379,10 +379,10 @@ function $a(t, e, o, n) {
379
379
  function l(m, g) {
380
380
  const y = g + d.get(m) / 2, P = f[a.depth.get(m)];
381
381
  h.set(m, r ? { x: y, y: P } : { x: P, y });
382
- const A = a.kids.get(m), w = A.reduce((T, F) => T + d.get(F), 0) + Math.max(0, A.length - 1) * o.nodeGap;
382
+ const O = a.kids.get(m), w = O.reduce((F, T) => F + d.get(T), 0) + Math.max(0, O.length - 1) * o.nodeGap;
383
383
  let k = g + (d.get(m) - w) / 2;
384
- for (const T of A)
385
- l(T, k), k += d.get(T) + o.nodeGap;
384
+ for (const F of O)
385
+ l(F, k), k += d.get(F) + o.nodeGap;
386
386
  }
387
387
  let p = 0;
388
388
  for (const m of a.roots)
@@ -414,13 +414,13 @@ function Ii(t, e, o, n) {
414
414
  let f = 0;
415
415
  for (const l of a.roots) {
416
416
  let m = function(g, y, P) {
417
- const A = (y + P) / 2 + (o.direction === "RIGHT" ? 0 : Math.PI / 2), w = c[a.depth.get(g)];
418
- i.set(g, { x: p + Math.cos(A) * w, y: Math.sin(A) * w });
417
+ const O = (y + P) / 2 + (o.direction === "RIGHT" ? 0 : Math.PI / 2), w = c[a.depth.get(g)];
418
+ i.set(g, { x: p + Math.cos(O) * w, y: Math.sin(O) * w });
419
419
  const k = a.kids.get(g);
420
- let T = y;
421
- for (const F of k) {
422
- const j = T + (P - y) * s.get(F) / s.get(g);
423
- m(F, T, j), T = j;
420
+ let F = y;
421
+ for (const T of k) {
422
+ const j = F + (P - y) * s.get(T) / s.get(g);
423
+ m(T, F, j), F = j;
424
424
  }
425
425
  };
426
426
  var h = m;
@@ -429,7 +429,7 @@ function Ii(t, e, o, n) {
429
429
  }
430
430
  return i;
431
431
  }
432
- function Oi(t, e, o) {
432
+ function Ai(t, e, o) {
433
433
  const n = So(t, e, o);
434
434
  if (e.mode === "rebuild") return n;
435
435
  const a = Ie(t), s = _t(a), r = Ie(
@@ -458,7 +458,7 @@ function Oi(t, e, o) {
458
458
  }
459
459
  return u;
460
460
  }
461
- function Tn(t, e, o, n, a = !1) {
461
+ function Fn(t, e, o, n, a = !1) {
462
462
  const s = Ie(e), r = Ie(
463
463
  e.map((h) => {
464
464
  const l = t.get(h.id);
@@ -515,17 +515,17 @@ function hs(t, e, o) {
515
515
  if (!e.index.has(n)) return null;
516
516
  const a = Yo(t, e, { ...o, rootId: n }), s = new Map(t.map((w) => [w.id, w])), r = o.direction === "DOWN", d = (w) => r ? s.get(w).w : s.get(w).h, c = (w) => r ? s.get(w).h : s.get(w).w, u = /* @__PURE__ */ new Map();
517
517
  function i(w) {
518
- const k = a.kids.get(w), T = Math.max(
518
+ const k = a.kids.get(w), F = Math.max(
519
519
  d(w),
520
- k.reduce((F, j) => F + i(j), 0) + Math.max(0, k.length - 1) * o.nodeGap
520
+ k.reduce((T, j) => T + i(j), 0) + Math.max(0, k.length - 1) * o.nodeGap
521
521
  );
522
- return u.set(w, T), T;
522
+ return u.set(w, F), F;
523
523
  }
524
524
  a.roots.forEach(i);
525
525
  const f = /* @__PURE__ */ new Map([[n, 0]]), h = { 1: [], "-1": [] }, l = { 1: 0, "-1": 0 };
526
526
  function p(w, k) {
527
527
  f.set(w, k);
528
- for (const T of a.kids.get(w)) p(T, k);
528
+ for (const F of a.kids.get(w)) p(F, k);
529
529
  }
530
530
  for (const w of a.kids.get(n)) {
531
531
  const k = l[1] <= l[-1] ? 1 : -1;
@@ -539,27 +539,27 @@ function hs(t, e, o) {
539
539
  const y = [0];
540
540
  for (let w = 1; w < g.length; w++)
541
541
  y[w] = y[w - 1] + g[w - 1] / 2 + o.rankGap + g[w] / 2;
542
- function P(w, k, T) {
543
- const F = T * y[a.depth.get(w)], j = k + u.get(w) / 2;
544
- m.set(w, r ? { x: j, y: F } : { x: F, y: j });
542
+ function P(w, k, F) {
543
+ const T = F * y[a.depth.get(w)], j = k + u.get(w) / 2;
544
+ m.set(w, r ? { x: j, y: T } : { x: T, y: j });
545
545
  const $ = a.kids.get(w), v = $.reduce((M, x) => M + u.get(x), 0) + Math.max(0, $.length - 1) * o.nodeGap;
546
546
  let S = k + (u.get(w) - v) / 2;
547
547
  for (const M of $)
548
- P(M, S, T), S += u.get(M) + o.nodeGap;
548
+ P(M, S, F), S += u.get(M) + o.nodeGap;
549
549
  }
550
550
  for (const w of [1, -1]) {
551
551
  let k = -(l[w] - o.nodeGap) / 2;
552
- for (const T of h[w])
553
- P(T, k, w), k += u.get(T) + o.nodeGap;
552
+ for (const F of h[w])
553
+ P(F, k, w), k += u.get(F) + o.nodeGap;
554
554
  }
555
- const A = t.filter((w) => !m.has(w.id));
556
- if (A.length) {
557
- const w = $a(A, Vn(A, e.edges), { ...o, rootId: "" }), k = Ie(
558
- t.filter((T) => m.has(T.id)).map((T) => ({ ...T, x: m.get(T.id).x - T.w / 2, y: m.get(T.id).y - T.h / 2 }))
555
+ const O = t.filter((w) => !m.has(w.id));
556
+ if (O.length) {
557
+ const w = $a(O, Vn(O, e.edges), { ...o, rootId: "" }), k = Ie(
558
+ t.filter((F) => m.has(F.id)).map((F) => ({ ...F, x: m.get(F.id).x - F.w / 2, y: m.get(F.id).y - F.h / 2 }))
559
559
  );
560
- for (const T of A) {
561
- const F = w.get(T.id);
562
- m.set(T.id, { x: F.x, y: F.y + k.y + k.h + o.rankGap });
560
+ for (const F of O) {
561
+ const T = w.get(F.id);
562
+ m.set(F.id, { x: T.x, y: T.y + k.y + k.h + o.rankGap });
563
563
  }
564
564
  }
565
565
  return e.branchSides = f, m;
@@ -618,7 +618,7 @@ function us(t, e, o, n, a, s) {
618
618
  }
619
619
  return c;
620
620
  }
621
- async function Ai(t, e = {}) {
621
+ async function Oi(t, e = {}) {
622
622
  const o = Date.now(), n = Pn(t), a = Pn(t.layout.nodes), s = La({ ...t.settings, ...e });
623
623
  n.layout.intent = Ga(
624
624
  n.layout.intent || {},
@@ -635,26 +635,26 @@ async function Ai(t, e = {}) {
635
635
  }, p = (E) => f(E).flatMap((L) => [L.id, ...c.has(L.id) ? p(L.id) : []]), m = new Map(n.graph.nodes.map((E, L) => [E.id, L])), g = new Set(e.fixedIds || []), y = (E) => g.has(E) || !!i[E]?.pinned || s.respectManual && !!i[E]?.manual, P = (E) => {
636
636
  for (let L = E; L; L = h(L)) if (y(L)) return !0;
637
637
  return !1;
638
- }, A = (E) => P(E) || c.has(E) && p(E).some(y), w = (E) => {
638
+ }, O = (E) => P(E) || c.has(E) && p(E).some(y), w = (E) => {
639
639
  for (let L = h(E); L; L = h(L)) if (n.collapsed.includes(L)) return !1;
640
640
  return !0;
641
641
  }, k = (E) => {
642
642
  const L = i[E];
643
643
  return n.collapsed.includes(E) ? { ...L, w: Math.min(L.w, 210), h: 58 } : L;
644
- }, T = /* @__PURE__ */ new Set();
645
- let F = 0, j = 0;
644
+ }, F = /* @__PURE__ */ new Set();
645
+ let T = 0, j = 0;
646
646
  const $ = [], v = s.aspect === "canvas" ? Me((e.viewport?.w || 1200) / (e.viewport?.h || 760), 0.5, 3) : Number(s.aspect), S = e.scope || "all", M = (e.selected || []).filter((E) => u.has(E));
647
647
  if (!["all", "selection", "container", "neighbourhood"].includes(S))
648
648
  throw Error("Invalid layout scope.");
649
649
  function x(E, L, R) {
650
- if (A(E) || !Number.isFinite(L) || !Number.isFinite(R)) return;
650
+ if (O(E) || !Number.isFinite(L) || !Number.isFinite(R)) return;
651
651
  const Z = [E, ...c.has(E) ? p(E) : []];
652
652
  let V = 1;
653
653
  if (s.mode === "pass") {
654
654
  const G = L * L + R * R;
655
655
  if (G < 1e-16) return;
656
656
  for (const X of Z) {
657
- const D = i[X], ct = a[X], B = D.x - ct.x, rt = D.y - ct.y, lt = 2 * (B * L + rt * R), kt = B * B + rt * rt - s.maxMove * s.maxMove, vt = lt * lt - 4 * G * kt;
657
+ const D = i[X], ct = a[X], q = D.x - ct.x, rt = D.y - ct.y, lt = 2 * (q * L + rt * R), kt = q * q + rt * rt - s.maxMove * s.maxMove, vt = lt * lt - 4 * G * kt;
658
658
  V = Math.min(V, Me((-lt + Math.sqrt(Math.max(0, vt))) / (2 * G), 0, 1));
659
659
  }
660
660
  }
@@ -662,7 +662,7 @@ async function Ai(t, e = {}) {
662
662
  i[G].x += L * V, i[G].y += R * V;
663
663
  }
664
664
  function N(E) {
665
- if (!s.growContainers || A(E) || !f(E).length) return;
665
+ if (!s.growContainers || O(E) || !f(E).length) return;
666
666
  const L = Ie(f(E).map((X) => i[X.id])), R = i[E], Z = n.layout.containers[E]?.padding || 24, V = Math.max(R.x + R.w, L.x + L.w + Z), G = Math.max(R.y + R.h, L.y + L.h + Z);
667
667
  R.w = V - R.x, R.h = G - R.y;
668
668
  }
@@ -674,8 +674,8 @@ async function Ai(t, e = {}) {
674
674
  const X = f(G).filter((D) => w(D.id));
675
675
  for (let D = 0; D < X.length; D++)
676
676
  for (let ct = D + 1; ct < X.length; ct++) {
677
- const B = yn(k(X[D].id), k(X[ct].id));
678
- B && (E++, L += B.area);
677
+ const q = yn(k(X[D].id), k(X[ct].id));
678
+ q && (E++, L += q.area);
679
679
  }
680
680
  }
681
681
  const Z = Ie(R.map((G) => k(G.id)));
@@ -683,8 +683,8 @@ async function Ai(t, e = {}) {
683
683
  for (const G of n.graph.edges) {
684
684
  const X = i[G.from], D = i[G.to];
685
685
  if (X && D) {
686
- const ct = _t(X), B = _t(D);
687
- V += ge(ct.x - B.x, ct.y - B.y);
686
+ const ct = _t(X), q = _t(D);
687
+ V += ge(ct.x - q.x, ct.y - q.y);
688
688
  }
689
689
  }
690
690
  return {
@@ -706,8 +706,8 @@ async function Ai(t, e = {}) {
706
706
  if (!L) {
707
707
  for (const G of u.values())
708
708
  if (h(G.id) && w(G.id)) {
709
- const X = i[G.id], D = i[h(G.id)], ct = n.layout.containers[h(G.id)]?.padding || 24, B = a[G.id], rt = a[h(G.id)], lt = (kt, vt) => Math.max(0, vt.x + ct - kt.x) + Math.max(0, vt.y + ct + 28 - kt.y) + Math.max(0, kt.x + kt.w - (vt.x + vt.w - ct)) + Math.max(0, kt.y + kt.h - (vt.y + vt.h - ct));
710
- if (lt(X, D) > lt(B, rt) + 0.01) return;
709
+ const X = i[G.id], D = i[h(G.id)], ct = n.layout.containers[h(G.id)]?.padding || 24, q = a[G.id], rt = a[h(G.id)], lt = (kt, vt) => Math.max(0, vt.x + ct - kt.x) + Math.max(0, vt.y + ct + 28 - kt.y) + Math.max(0, kt.x + kt.w - (vt.x + vt.w - ct)) + Math.max(0, kt.y + kt.h - (vt.y + vt.h - ct));
710
+ if (lt(X, D) > lt(q, rt) + 0.01) return;
711
711
  }
712
712
  }
713
713
  const Z = it.at(-1), V = Z ? Math.max(
@@ -735,7 +735,7 @@ async function Ai(t, e = {}) {
735
735
  n.graph.nodes.map((E) => ({ ...E, ...i[E.id] })),
736
736
  C,
737
737
  s
738
- ), C.feedback.size && T.add(
738
+ ), C.feedback.size && F.add(
739
739
  C.feedback.size + " feedback edge(s) remain visible; cyclic edges cannot all follow one direction."
740
740
  );
741
741
  let _ = 0;
@@ -743,17 +743,17 @@ async function Ai(t, e = {}) {
743
743
  function b(E, L) {
744
744
  if (E && P(E)) return;
745
745
  n.layout.containers[E]?.direction;
746
- const R = f(E).filter((B) => w(B.id)).map((B) => ({ id: B.id, ...k(B.id), fixed: A(B.id) }));
746
+ const R = f(E).filter((q) => w(q.id)).map((q) => ({ id: q.id, ...k(q.id), fixed: O(q.id) }));
747
747
  if (!R.length) return;
748
- const Z = E ? i[E] : null, V = n.layout.containers[E]?.padding || 24, G = Z ? { x: Z.x + V, y: Z.y + V + 28, w: Z.w - 2 * V, h: Z.h - 2 * V - 28 } : null, X = { ...s, fold: s.respectDirection ? "never" : s.fold }, D = G ? Math.max(0.3, G.w / Math.max(1, G.h)) : v, ct = Tn(So(R, X, D), R, G, X, !0);
749
- for (const B of R) {
750
- if (B.fixed) continue;
751
- const rt = ct.get(B.id);
752
- let lt = rt.x - B.w / 2, kt = rt.y - B.h / 2;
753
- G && !s.growContainers && (B.w <= G.w && (lt = Me(lt, G.x, G.x + G.w - B.w)), B.h <= G.h && (kt = Me(kt, G.y, G.y + G.h - B.h))), x(B.id, lt - i[B.id].x, kt - i[B.id].y);
748
+ const Z = E ? i[E] : null, V = n.layout.containers[E]?.padding || 24, G = Z ? { x: Z.x + V, y: Z.y + V + 28, w: Z.w - 2 * V, h: Z.h - 2 * V - 28 } : null, X = { ...s, fold: s.respectDirection ? "never" : s.fold }, D = G ? Math.max(0.3, G.w / Math.max(1, G.h)) : v, ct = Fn(So(R, X, D), R, G, X, !0);
749
+ for (const q of R) {
750
+ if (q.fixed) continue;
751
+ const rt = ct.get(q.id);
752
+ let lt = rt.x - q.w / 2, kt = rt.y - q.h / 2;
753
+ G && !s.growContainers && (q.w <= G.w && (lt = Me(lt, G.x, G.x + G.w - q.w)), q.h <= G.h && (kt = Me(kt, G.y, G.y + G.h - q.h))), x(q.id, lt - i[q.id].x, kt - i[q.id].y);
754
754
  }
755
- for (const B of R)
756
- c.has(B.id) && !n.collapsed.includes(B.id) && b(B.id);
755
+ for (const q of R)
756
+ c.has(q.id) && !n.collapsed.includes(q.id) && b(q.id);
757
757
  }
758
758
  if (J && s.mode === "rebuild" && !e.warmStart) {
759
759
  if (S === "all") b(null, s.direction);
@@ -764,61 +764,61 @@ async function Ai(t, e = {}) {
764
764
  }
765
765
  async function Y(E, L, R) {
766
766
  if (!E.length) return;
767
- F++;
768
- const Z = f(L).filter((q) => w(q.id)), V = new Set(E), G = new Set(Z.map((q) => q.id)), X = (q) => {
769
- for (let st = q; st; st = h(st)) if (G.has(st)) return st;
767
+ T++;
768
+ const Z = f(L).filter((B) => w(B.id)), V = new Set(E), G = new Set(Z.map((B) => B.id)), X = (B) => {
769
+ for (let st = B; st; st = h(st)) if (G.has(st)) return st;
770
770
  return null;
771
- }, D = Z.map((q) => ({
772
- id: q.id,
773
- ...k(q.id),
774
- fixed: !V.has(q.id) || A(q.id)
771
+ }, D = Z.map((B) => ({
772
+ id: B.id,
773
+ ...k(B.id),
774
+ fixed: !V.has(B.id) || O(B.id)
775
775
  }));
776
- if (D.every((q) => q.fixed)) return;
776
+ if (D.every((B) => B.fixed)) return;
777
777
  const ct = {};
778
- for (const [q, st] of Object.entries(r)) {
778
+ for (const [B, st] of Object.entries(r)) {
779
779
  const dt = X(st.id);
780
- dt && (ct[q] = { ...st, id: dt });
780
+ dt && (ct[B] = { ...st, id: dt });
781
781
  }
782
782
  ct.start?.id === ct.end?.id && delete ct.end;
783
- const B = {
783
+ const q = {
784
784
  ...s,
785
785
  direction: R,
786
786
  rootId: ct.start?.id || X(s.rootId) || "",
787
787
  fold: s.respectDirection ? "never" : s.fold
788
- }, rt = n.graph.edges.map((q) => ({ from: X(q.from), to: X(q.to), directed: q.directed !== !1 })).filter((q) => q.from && q.to && q.from !== q.to), lt = Vn(D, rt, ct);
789
- e.orderPrior !== !1 && s.algorithm === "layered" && !L && !D.some((q) => c.has(q.id)) && (lt.declared = new Map(D.map((q) => [q.id, m.get(q.id) ?? 1 / 0])));
790
- const kt = J ? n.graph.edges.map((q) => ({ ...q, a: X(q.from), b: X(q.to) })).filter((q) => (q.a || q.b) && q.a !== q.b) : [], vt = (q) => {
791
- const st = c.has(q) ? p(q).filter((dt) => !c.has(dt)) : [q];
788
+ }, rt = n.graph.edges.map((B) => ({ from: X(B.from), to: X(B.to), directed: B.directed !== !1 })).filter((B) => B.from && B.to && B.from !== B.to), lt = Vn(D, rt, ct);
789
+ e.orderPrior !== !1 && s.algorithm === "layered" && !L && !D.some((B) => c.has(B.id)) && (lt.declared = new Map(D.map((B) => [B.id, m.get(B.id) ?? 1 / 0])));
790
+ const kt = J ? n.graph.edges.map((B) => ({ ...B, a: X(B.from), b: X(B.to) })).filter((B) => (B.a || B.b) && B.a !== B.b) : [], vt = (B) => {
791
+ const st = c.has(B) ? p(B).filter((dt) => !c.has(dt)) : [B];
792
792
  return st.length ? Math.min(...st.map((dt) => C.rank.get(dt) || 0)) : 0;
793
793
  };
794
794
  if (s.algorithm === "compound-flow") {
795
- const q = [...new Set(D.map((dt) => vt(dt.id)))].sort((dt, gt) => dt - gt);
795
+ const B = [...new Set(D.map((dt) => vt(dt.id)))].sort((dt, gt) => dt - gt);
796
796
  for (const dt of D)
797
- lt.rank.set(dt.id, Math.max(lt.rank.get(dt.id) || 0, q.indexOf(vt(dt.id))));
797
+ lt.rank.set(dt.id, Math.max(lt.rank.get(dt.id) || 0, B.indexOf(vt(dt.id))));
798
798
  const st = [...new Set(lt.rank.values())].sort((dt, gt) => dt - gt);
799
799
  for (const [dt, gt] of lt.rank) lt.rank.set(dt, st.indexOf(gt));
800
- B.rankGap = Math.max(s.rankGap, D.some((dt) => c.has(dt.id)) ? s.groupGap : 0);
800
+ q.rankGap = Math.max(s.rankGap, D.some((dt) => c.has(dt.id)) ? s.groupGap : 0);
801
801
  }
802
- const Ot = (q, st) => J && (c.has(q.id) || c.has(st.id)) ? s.groupGap : s.nodeGap;
803
- J && (B._compoundEnergy = () => {
804
- let q = 0;
802
+ const At = (B, st) => J && (c.has(B.id) || c.has(st.id)) ? s.groupGap : s.nodeGap;
803
+ J && (q._compoundEnergy = () => {
804
+ let B = 0;
805
805
  const st = R === "DOWN";
806
806
  for (const dt of kt) {
807
807
  const gt = i[dt.from], bt = i[dt.to];
808
808
  if (!gt || !bt) continue;
809
- const It = _t(gt), Ct = _t(bt), ut = Ct.x - It.x, tt = Ct.y - It.y, yt = st ? ut : tt, At = ge(ut, tt), Lt = h(dt.from) !== h(dt.to) || !dt.a || !dt.b ? s.boundaryPull / 100 : 0.35, Pt = s.edgeLength + (Math.hypot(gt.w, gt.h) + Math.hypot(bt.w, bt.h)) / 4;
810
- s.algorithm === "boundary-align" ? q += yt * yt * (0.025 + s.alignment / 100 * 0.06) * Lt + (At - Pt) ** 2 * 1e-3 * Lt : q += (At - Pt) ** 2 * 8e-3 * Lt, s.algorithm === "compound-flow" && (q += yt * yt * 0.01 * Lt);
809
+ const It = _t(gt), Ct = _t(bt), ut = Ct.x - It.x, tt = Ct.y - It.y, yt = st ? ut : tt, Ot = ge(ut, tt), Lt = h(dt.from) !== h(dt.to) || !dt.a || !dt.b ? s.boundaryPull / 100 : 0.35, Pt = s.edgeLength + (Math.hypot(gt.w, gt.h) + Math.hypot(bt.w, bt.h)) / 4;
810
+ s.algorithm === "boundary-align" ? B += yt * yt * (0.025 + s.alignment / 100 * 0.06) * Lt + (Ot - Pt) ** 2 * 1e-3 * Lt : B += (Ot - Pt) ** 2 * 8e-3 * Lt, s.algorithm === "compound-flow" && (B += yt * yt * 0.01 * Lt);
811
811
  }
812
- return q;
812
+ return B;
813
813
  });
814
- const Et = L ? i[L] : null, Ft = n.layout.containers[L]?.padding || 24, St = Et ? { x: Et.x + Ft, y: Et.y + Ft + 28, w: Et.w - Ft * 2, h: Et.h - Ft * 2 - 28 } : null, Qt = St ? Math.max(0.3, St.w / Math.max(1, St.h)) : v;
814
+ const Et = L ? i[L] : null, Tt = n.layout.containers[L]?.padding || 24, St = Et ? { x: Et.x + Tt, y: Et.y + Tt + 28, w: Et.w - Tt * 2, h: Et.h - Tt * 2 - 28 } : null, Qt = St ? Math.max(0.3, St.w / Math.max(1, St.h)) : v;
815
815
  let Dt = null;
816
- (s.algorithm === "layered" || s.algorithm === "compound-flow") && (Dt = ds(D, lt, B, Qt)), s.algorithm === "tree" && (Dt = $a(D, lt, B)), s.algorithm === "radial" && (Dt = Ii(D, lt, B)), s.algorithm === "grid" && (Dt = Oi(D, B, Qt));
817
- const ne = ct.start?.placement === "center" && s.algorithm !== "separate" ? hs(D, lt, B) : null;
818
- if (ne && ["tree", "layered", "compound-flow"].includes(s.algorithm) && (Dt = ne), Dt && !(s.algorithm === "grid" && s.mode === "pass") && Tn(Dt, D, St, s, s.mode === "rebuild" && !e.warmStart), s.mode === "rebuild" && !e.warmStart && s.algorithm !== "separate" && (!J || !W.has(L))) {
816
+ (s.algorithm === "layered" || s.algorithm === "compound-flow") && (Dt = ds(D, lt, q, Qt)), s.algorithm === "tree" && (Dt = $a(D, lt, q)), s.algorithm === "radial" && (Dt = Ii(D, lt, q)), s.algorithm === "grid" && (Dt = Ai(D, q, Qt));
817
+ const ne = ct.start?.placement === "center" && s.algorithm !== "separate" ? hs(D, lt, q) : null;
818
+ if (ne && ["tree", "layered", "compound-flow"].includes(s.algorithm) && (Dt = ne), Dt && !(s.algorithm === "grid" && s.mode === "pass") && Fn(Dt, D, St, s, s.mode === "rebuild" && !e.warmStart), s.mode === "rebuild" && !e.warmStart && s.algorithm !== "separate" && (!J || !W.has(L))) {
819
819
  W.add(L);
820
- const q = Dt || (ne ? Tn(ne, D, St, s, !0) : null) || Tn(
821
- s.respectDirection && lt.forward.length ? ds(D, lt, { ...B, fold: "never" }, Qt) : So(D, s, Qt),
820
+ const B = Dt || (ne ? Fn(ne, D, St, s, !0) : null) || Fn(
821
+ s.respectDirection && lt.forward.length ? ds(D, lt, { ...q, fold: "never" }, Qt) : So(D, s, Qt),
822
822
  D,
823
823
  St,
824
824
  s,
@@ -826,32 +826,32 @@ async function Ai(t, e = {}) {
826
826
  );
827
827
  for (const st of D)
828
828
  if (!st.fixed) {
829
- const dt = q.get(st.id);
829
+ const dt = B.get(st.id);
830
830
  let gt = dt.x - st.w / 2, bt = dt.y - st.h / 2;
831
831
  St && !s.growContainers && (st.w <= St.w && (gt = Me(gt, St.x, St.x + St.w - st.w)), st.h <= St.h && (bt = Me(bt, St.y, St.y + St.h - st.h))), x(st.id, gt - i[st.id].x, bt - i[st.id].y);
832
832
  }
833
833
  }
834
- const Gt = () => D.forEach((q) => {
835
- q.x = i[q.id].x, q.y = i[q.id].y;
834
+ const Gt = () => D.forEach((B) => {
835
+ B.x = i[B.id].x, B.y = i[B.id].y;
836
836
  });
837
837
  Gt();
838
- const Yt = new Map(D.map((q) => [q.id, _t(q)])), Kt = new Map(D.map((q) => [q.id, q])), ae = new Map(D.map((q) => [q.id, { x: 0, y: 0 }])), Rt = s.algorithm === "stress" ? Si(lt) : null, Xt = Ie(D), te = _t(Xt), Ht = s.mode === "pass" ? (s.stability / 100) ** 2 * 0.18 : 0, oe = e.settle ? Me(Math.round(e.maxIterations || 640), 80, 1200) : s.mode === "rebuild" ? Math.max(80, s.iterations * 3) : s.iterations;
839
- let Bt = 0, le = 0, fe = "iteration limit", de = 0;
840
- const he = (q, st, dt) => {
841
- q.fixed || (St && !s.growContainers && (q.w <= St.w ? st = Me(q.x + st, St.x, St.x + St.w - q.w) - q.x : (T.add("A child is wider than its container. Resize the frame or allow growth."), st = 0), q.h <= St.h ? dt = Me(q.y + dt, St.y, St.y + St.h - q.h) - q.y : (T.add("A child is taller than its container. Resize the frame or allow growth."), dt = 0)), x(q.id, st, dt), q.x = i[q.id].x, q.y = i[q.id].y);
838
+ const Yt = new Map(D.map((B) => [B.id, _t(B)])), Kt = new Map(D.map((B) => [B.id, B])), ae = new Map(D.map((B) => [B.id, { x: 0, y: 0 }])), Rt = s.algorithm === "stress" ? Si(lt) : null, Xt = Ie(D), te = _t(Xt), Ht = s.mode === "pass" ? (s.stability / 100) ** 2 * 0.18 : 0, oe = e.settle ? Me(Math.round(e.maxIterations || 640), 80, 1200) : s.mode === "rebuild" ? Math.max(80, s.iterations * 3) : s.iterations;
839
+ let qt = 0, le = 0, fe = "iteration limit", de = 0;
840
+ const he = (B, st, dt) => {
841
+ B.fixed || (St && !s.growContainers && (B.w <= St.w ? st = Me(B.x + st, St.x, St.x + St.w - B.w) - B.x : (F.add("A child is wider than its container. Resize the frame or allow growth."), st = 0), B.h <= St.h ? dt = Me(B.y + dt, St.y, St.y + St.h - B.h) - B.y : (F.add("A child is taller than its container. Resize the frame or allow growth."), dt = 0)), x(B.id, st, dt), B.x = i[B.id].x, B.y = i[B.id].y);
842
842
  };
843
- function we(q, st, dt) {
844
- if (q.fixed) return 0;
843
+ function we(B, st, dt) {
844
+ if (B.fixed) return 0;
845
845
  let gt = 1 / 0;
846
846
  if (St && !s.growContainers) {
847
847
  const bt = st === "x" ? "w" : "h";
848
848
  gt = Math.max(
849
849
  0,
850
- dt > 0 ? St[st] + St[bt] - q[st] - q[bt] : q[st] - St[st]
850
+ dt > 0 ? St[st] + St[bt] - B[st] - B[bt] : B[st] - St[st]
851
851
  );
852
852
  }
853
853
  if (s.mode === "pass")
854
- for (const bt of [q.id, ...c.has(q.id) ? p(q.id) : []]) {
854
+ for (const bt of [B.id, ...c.has(B.id) ? p(B.id) : []]) {
855
855
  const It = i[bt], Ct = a[bt], ut = (It[st] - Ct[st]) * dt, tt = st === "x" ? It.y - Ct.y : It.x - Ct.x;
856
856
  gt = Math.min(
857
857
  gt,
@@ -860,67 +860,67 @@ async function Ai(t, e = {}) {
860
860
  }
861
861
  return gt;
862
862
  }
863
- function I(q = 3) {
864
- for (let st = 0; st < q; st++)
863
+ function I(B = 3) {
864
+ for (let st = 0; st < B; st++)
865
865
  for (let dt = 0; dt < D.length; dt++)
866
866
  for (let gt = dt + 1; gt < D.length; gt++) {
867
- const bt = D[dt], It = D[gt], Ct = Ot(bt, It), ut = yn(bt, It, Ct);
867
+ const bt = D[dt], It = D[gt], Ct = At(bt, It), ut = yn(bt, It, Ct);
868
868
  if (!ut || bt.fixed && It.fixed) continue;
869
869
  const tt = [];
870
- for (const qt of ["x", "y"])
870
+ for (const Bt of ["x", "y"])
871
871
  for (const zt of [1, -1]) {
872
- const Jt = qt === "x" ? (bt.w + It.w) / 2 : (bt.h + It.h) / 2, Vt = qt === "x" ? ut.dx : ut.dy, jt = Jt + Ct - zt * Vt + 0.15, Zt = we(bt, qt, -zt), ee = we(It, qt, zt), se = Zt + ee, Ce = se >= jt - 1e-3, Ke = Math.min(1, se / jt);
873
- tt.push({ axis: qt, sign: zt, need: jt, ca: Zt, cb: ee, available: se, feasible: Ce, coverage: Ke });
872
+ const Jt = Bt === "x" ? (bt.w + It.w) / 2 : (bt.h + It.h) / 2, Vt = Bt === "x" ? ut.dx : ut.dy, jt = Jt + Ct - zt * Vt + 0.15, Zt = we(bt, Bt, -zt), ee = we(It, Bt, zt), se = Zt + ee, Ce = se >= jt - 1e-3, Ke = Math.min(1, se / jt);
873
+ tt.push({ axis: Bt, sign: zt, need: jt, ca: Zt, cb: ee, available: se, feasible: Ce, coverage: Ke });
874
874
  }
875
875
  tt.sort(
876
- (qt, zt) => Number(zt.feasible) - Number(qt.feasible) || (qt.feasible ? qt.need - zt.need : zt.coverage - qt.coverage) || qt.need - zt.need
876
+ (Bt, zt) => Number(zt.feasible) - Number(Bt.feasible) || (Bt.feasible ? Bt.need - zt.need : zt.coverage - Bt.coverage) || Bt.need - zt.need
877
877
  );
878
878
  const yt = tt[0];
879
879
  if (yt.available < 1e-3) continue;
880
- const At = Math.min(yt.need, yt.available), Tt = Math.min(yt.ca, At / 2), Lt = Math.min(yt.cb, At - Tt), Pt = Math.min(yt.ca - Tt, At - Tt - Lt), $t = (Tt + Pt) * yt.sign, Nt = Lt * yt.sign;
880
+ const Ot = Math.min(yt.need, yt.available), Ft = Math.min(yt.ca, Ot / 2), Lt = Math.min(yt.cb, Ot - Ft), Pt = Math.min(yt.ca - Ft, Ot - Ft - Lt), $t = (Ft + Pt) * yt.sign, Nt = Lt * yt.sign;
881
881
  he(bt, yt.axis === "x" ? -$t : 0, yt.axis === "y" ? -$t : 0), he(It, yt.axis === "x" ? Nt : 0, yt.axis === "y" ? Nt : 0);
882
882
  }
883
883
  }
884
884
  const U = () => {
885
- let q = 0, st = 0;
885
+ let B = 0, st = 0;
886
886
  for (let dt = 0; dt < D.length; dt++)
887
887
  for (let gt = dt + 1; gt < D.length; gt++) {
888
888
  const bt = yn(D[dt], D[gt]);
889
- bt && (q++, st += bt.area);
889
+ bt && (B++, st += bt.area);
890
890
  }
891
- return { n: q, a: st };
891
+ return { n: B, a: st };
892
892
  };
893
893
  let nt = {
894
- coords: new Map(D.map((q) => [q.id, { x: q.x, y: q.y }])),
894
+ coords: new Map(D.map((B) => [B.id, { x: B.x, y: B.y }])),
895
895
  collisions: U(),
896
- energy: us(D, lt, B, Rt, Dt)
896
+ energy: us(D, lt, q, Rt, Dt)
897
897
  };
898
- for (let q = 0; q < oe; q++) {
898
+ for (let B = 0; B < oe; B++) {
899
899
  j++, de++;
900
- const st = D.map((ut) => ({ x: ut.x, y: ut.y })), dt = new Map(D.map((ut) => [ut.id, { x: 0, y: 0, degree: 0 }])), gt = (ut, tt, yt, At = 1) => {
901
- const Tt = dt.get(ut);
902
- Tt.x += tt, Tt.y += yt, Tt.degree += At;
900
+ const st = D.map((ut) => ({ x: ut.x, y: ut.y })), dt = new Map(D.map((ut) => [ut.id, { x: 0, y: 0, degree: 0 }])), gt = (ut, tt, yt, Ot = 1) => {
901
+ const Ft = dt.get(ut);
902
+ Ft.x += tt, Ft.y += yt, Ft.degree += Ot;
903
903
  };
904
904
  if (s.algorithm === "stress")
905
905
  for (let ut = 0; ut < D.length; ut++)
906
906
  for (let tt = ut + 1; tt < D.length; tt++) {
907
- const yt = D[ut], At = D[tt], Tt = Rt.get(yt.id).get(At.id);
908
- if (!Tt) continue;
909
- const Lt = _t(yt), Pt = _t(At);
910
- let $t = Pt.x - Lt.x, Nt = Pt.y - Lt.y, qt = ge($t, Nt);
911
- if (qt < 0.01) {
912
- const jt = fo(yt.id + "|" + At.id) * Math.PI * 2;
913
- $t = Math.cos(jt), Nt = Math.sin(jt), qt = 1;
907
+ const yt = D[ut], Ot = D[tt], Ft = Rt.get(yt.id).get(Ot.id);
908
+ if (!Ft) continue;
909
+ const Lt = _t(yt), Pt = _t(Ot);
910
+ let $t = Pt.x - Lt.x, Nt = Pt.y - Lt.y, Bt = ge($t, Nt);
911
+ if (Bt < 0.01) {
912
+ const jt = fo(yt.id + "|" + Ot.id) * Math.PI * 2;
913
+ $t = Math.cos(jt), Nt = Math.sin(jt), Bt = 1;
914
914
  }
915
- const zt = Tt * (s.edgeLength + (yt.w + At.w + yt.h + At.h) / 8), Jt = 1 / (Tt * Tt), Vt = (qt - zt) / qt * Jt * 0.16;
916
- gt(yt.id, $t * Vt, Nt * Vt, Jt), gt(At.id, -$t * Vt, -Nt * Vt, Jt);
915
+ const zt = Ft * (s.edgeLength + (yt.w + Ot.w + yt.h + Ot.h) / 8), Jt = 1 / (Ft * Ft), Vt = (Bt - zt) / Bt * Jt * 0.16;
916
+ gt(yt.id, $t * Vt, Nt * Vt, Jt), gt(Ot.id, -$t * Vt, -Nt * Vt, Jt);
917
917
  }
918
918
  else if (["tidy", "flow", "force"].includes(s.algorithm)) {
919
919
  for (const ut of lt.edges) {
920
- const tt = Kt.get(ut.from), yt = Kt.get(ut.to), At = _t(tt), Tt = _t(yt);
921
- let Lt = Tt.x - At.x, Pt = Tt.y - At.y, $t = ge(Lt, Pt);
920
+ const tt = Kt.get(ut.from), yt = Kt.get(ut.to), Ot = _t(tt), Ft = _t(yt);
921
+ let Lt = Ft.x - Ot.x, Pt = Ft.y - Ot.y, $t = ge(Lt, Pt);
922
922
  $t < 0.01 && (Lt = 1, Pt = 0.1, $t = 1.005);
923
- const Nt = (Math.hypot(tt.w, tt.h) + Math.hypot(yt.w, yt.h)) / 4, qt = Nt + s.edgeLength, zt = s.algorithm === "force" ? $t * $t / qt * 0.022 : ($t - qt) * 0.09;
923
+ const Nt = (Math.hypot(tt.w, tt.h) + Math.hypot(yt.w, yt.h)) / 4, Bt = Nt + s.edgeLength, zt = s.algorithm === "force" ? $t * $t / Bt * 0.022 : ($t - Bt) * 0.09;
924
924
  if (gt(tt.id, Lt / $t * zt, Pt / $t * zt), gt(yt.id, -Lt / $t * zt, -Pt / $t * zt), s.algorithm === "tidy") {
925
925
  const Jt = Math.abs(Lt) < Math.abs(Pt), Vt = Jt ? Lt : Pt, jt = Math.max(s.nodeGap * 2, 24);
926
926
  if (Math.abs(Vt) < jt) {
@@ -936,32 +936,32 @@ async function Ai(t, e = {}) {
936
936
  if (s.algorithm === "force")
937
937
  for (let ut = 0; ut < D.length; ut++)
938
938
  for (let tt = ut + 1; tt < D.length; tt++) {
939
- const yt = D[ut], At = D[tt], Tt = _t(yt), Lt = _t(At);
940
- let Pt = Lt.x - Tt.x, $t = Lt.y - Tt.y, Nt = ge(Pt, $t);
939
+ const yt = D[ut], Ot = D[tt], Ft = _t(yt), Lt = _t(Ot);
940
+ let Pt = Lt.x - Ft.x, $t = Lt.y - Ft.y, Nt = ge(Pt, $t);
941
941
  if (Nt < 0.1) {
942
- const Jt = fo(yt.id + At.id) * Math.PI * 2;
942
+ const Jt = fo(yt.id + Ot.id) * Math.PI * 2;
943
943
  Pt = Math.cos(Jt), $t = Math.sin(Jt), Nt = 1;
944
944
  }
945
- const qt = s.edgeLength + 80, zt = qt * qt / Math.max(Nt, 18) * s.repulsion / 100 * 0.015;
946
- gt(yt.id, -Pt / Nt * zt, -$t / Nt * zt, 0), gt(At.id, Pt / Nt * zt, $t / Nt * zt, 0);
945
+ const Bt = s.edgeLength + 80, zt = Bt * Bt / Math.max(Nt, 18) * s.repulsion / 100 * 0.015;
946
+ gt(yt.id, -Pt / Nt * zt, -$t / Nt * zt, 0), gt(Ot.id, Pt / Nt * zt, $t / Nt * zt, 0);
947
947
  }
948
948
  }
949
949
  if (J)
950
950
  for (const ut of kt) {
951
951
  const tt = i[ut.from], yt = i[ut.to];
952
952
  if (!tt || !yt) continue;
953
- const At = _t(tt), Tt = _t(yt);
954
- let Lt = Tt.x - At.x, Pt = Tt.y - At.y, $t = ge(Lt, Pt);
953
+ const Ot = _t(tt), Ft = _t(yt);
954
+ let Lt = Ft.x - Ot.x, Pt = Ft.y - Ot.y, $t = ge(Lt, Pt);
955
955
  $t < 0.01 && (Lt = 1, Pt = 0.1, $t = 1);
956
- const qt = h(ut.from) !== h(ut.to) || !ut.a || !ut.b ? s.boundaryPull / 100 : 0.35, zt = R === "DOWN", Jt = s.edgeLength + (Math.hypot(tt.w, tt.h) + Math.hypot(yt.w, yt.h)) / 4;
956
+ const Bt = h(ut.from) !== h(ut.to) || !ut.a || !ut.b ? s.boundaryPull / 100 : 0.35, zt = R === "DOWN", Jt = s.edgeLength + (Math.hypot(tt.w, tt.h) + Math.hypot(yt.w, yt.h)) / 4;
957
957
  let Vt = 0, jt = 0;
958
958
  if (s.algorithm === "boundary-align") {
959
- const Zt = (zt ? Lt : Pt) * (0.04 + s.alignment / 100 * 0.16) * qt;
960
- Vt = zt ? Zt : Lt / $t * ($t - Jt) * 8e-3 * qt, jt = zt ? Pt / $t * ($t - Jt) * 8e-3 * qt : Zt;
959
+ const Zt = (zt ? Lt : Pt) * (0.04 + s.alignment / 100 * 0.16) * Bt;
960
+ Vt = zt ? Zt : Lt / $t * ($t - Jt) * 8e-3 * Bt, jt = zt ? Pt / $t * ($t - Jt) * 8e-3 * Bt : Zt;
961
961
  } else {
962
- const Zt = ($t - Jt) * 0.1 * qt;
962
+ const Zt = ($t - Jt) * 0.1 * Bt;
963
963
  if (Vt = Lt / $t * Zt, jt = Pt / $t * Zt, s.algorithm === "compound-flow") {
964
- const ee = (zt ? Lt : Pt) * 0.055 * qt;
964
+ const ee = (zt ? Lt : Pt) * 0.055 * Bt;
965
965
  Vt += zt ? ee : 0, jt += zt ? 0 : ee;
966
966
  }
967
967
  }
@@ -969,25 +969,25 @@ async function Ai(t, e = {}) {
969
969
  }
970
970
  if (s.respectDirection && s.algorithm !== "separate")
971
971
  for (const ut of lt.forward) {
972
- const tt = Kt.get(ut.from), yt = Kt.get(ut.to), At = R === "DOWN", Tt = _t(tt), Lt = _t(yt), Pt = (At ? tt.h + yt.h : tt.w + yt.w) / 2 + s.rankGap, $t = Pt - (At ? Lt.y - Tt.y : Lt.x - Tt.x);
972
+ const tt = Kt.get(ut.from), yt = Kt.get(ut.to), Ot = R === "DOWN", Ft = _t(tt), Lt = _t(yt), Pt = (Ot ? tt.h + yt.h : tt.w + yt.w) / 2 + s.rankGap, $t = Pt - (Ot ? Lt.y - Ft.y : Lt.x - Ft.x);
973
973
  if ($t <= 0) continue;
974
974
  const Nt = $t * (0.12 + s.flowStrength / 100 * 0.65);
975
- gt(tt.id, At ? 0 : -Nt, At ? -Nt : 0, 0), gt(yt.id, At ? 0 : Nt, At ? Nt : 0, 0);
975
+ gt(tt.id, Ot ? 0 : -Nt, Ot ? -Nt : 0, 0), gt(yt.id, Ot ? 0 : Nt, Ot ? Nt : 0, 0);
976
976
  }
977
977
  if (Dt)
978
978
  for (const ut of D) {
979
- const tt = _t(ut), yt = Dt.get(ut.id), At = s.algorithm === "grid" ? 0.018 + s.gridStrength / 100 * 0.16 : 0.18;
980
- gt(ut.id, (yt.x - tt.x) * At, (yt.y - tt.y) * At);
979
+ const tt = _t(ut), yt = Dt.get(ut.id), Ot = s.algorithm === "grid" ? 0.018 + s.gridStrength / 100 * 0.16 : 0.18;
980
+ gt(ut.id, (yt.x - tt.x) * Ot, (yt.y - tt.y) * Ot);
981
981
  }
982
982
  if (s.algorithm !== "separate") {
983
- const ut = Ie(D), tt = _t(ut), yt = ut.w / ut.h, At = Me(Math.log(yt / Qt), -2, 2);
984
- for (const Tt of D) {
985
- const Lt = _t(Tt), Pt = Yt.get(Tt.id), $t = dt.get(Tt.id), Nt = Math.max(1, Math.sqrt($t.degree));
983
+ const ut = Ie(D), tt = _t(ut), yt = ut.w / ut.h, Ot = Me(Math.log(yt / Qt), -2, 2);
984
+ for (const Ft of D) {
985
+ const Lt = _t(Ft), Pt = Yt.get(Ft.id), $t = dt.get(Ft.id), Nt = Math.max(1, Math.sqrt($t.degree));
986
986
  if ($t.x /= Nt, $t.y /= Nt, $t.x += (Pt.x - Lt.x) * Ht, $t.y += (Pt.y - Lt.y) * Ht, !["flow", "tree", "radial", "layered", "compound-flow", "boundary-align"].includes(
987
987
  s.algorithm
988
988
  )) {
989
- const qt = s.compactness / 100 * 0.016;
990
- $t.x += (te.x - Lt.x) * qt - (Lt.x - tt.x) * At * qt, $t.y += (te.y - Lt.y) * qt + (Lt.y - tt.y) * At * qt, ["stress", "force"].includes(s.algorithm) && Math.abs(Lt.y - tt.y) < 0.01 && At > 0.8 && ($t.y += (fo(Tt.id) - 0.5) * s.nodeGap * 0.025);
989
+ const Bt = s.compactness / 100 * 0.016;
990
+ $t.x += (te.x - Lt.x) * Bt - (Lt.x - tt.x) * Ot * Bt, $t.y += (te.y - Lt.y) * Bt + (Lt.y - tt.y) * Ot * Bt, ["stress", "force"].includes(s.algorithm) && Math.abs(Lt.y - tt.y) < 0.01 && Ot > 0.8 && ($t.y += (fo(Ft.id) - 0.5) * s.nodeGap * 0.025);
991
991
  }
992
992
  }
993
993
  }
@@ -998,47 +998,47 @@ async function Ai(t, e = {}) {
998
998
  }
999
999
  for (const ut of D) {
1000
1000
  if (ut.fixed) continue;
1001
- const tt = dt.get(ut.id), yt = ae.get(ut.id), At = s.mode === "pass" ? Math.max(1, s.maxMove * 0.13) : Math.max(2, 32 * (1 - q / oe));
1001
+ const tt = dt.get(ut.id), yt = ae.get(ut.id), Ot = s.mode === "pass" ? Math.max(1, s.maxMove * 0.13) : Math.max(2, 32 * (1 - B / oe));
1002
1002
  yt.x = yt.x * 0.28 + tt.x * 0.72, yt.y = yt.y * 0.28 + tt.y * 0.72;
1003
- const Tt = ge(yt.x, yt.y), Lt = Tt > At ? At / Tt : 1;
1003
+ const Ft = ge(yt.x, yt.y), Lt = Ft > Ot ? Ot / Ft : 1;
1004
1004
  he(ut, yt.x * Lt, yt.y * Lt);
1005
1005
  }
1006
1006
  if (I(s.algorithm === "separate" ? 6 : 3), s.respectDirection && s.algorithm !== "separate")
1007
1007
  for (let ut = 0; ut < 2; ut++) {
1008
1008
  const tt = ut ? lt.forward.slice().reverse() : lt.forward;
1009
1009
  for (const yt of tt) {
1010
- const At = Kt.get(yt.from), Tt = Kt.get(yt.to), Lt = R === "DOWN", Pt = Lt ? "y" : "x", $t = (Lt ? At.h + Tt.h : At.w + Tt.w) / 2 + s.rankGap, Nt = vn(lt, yt);
1010
+ const Ot = Kt.get(yt.from), Ft = Kt.get(yt.to), Lt = R === "DOWN", Pt = Lt ? "y" : "x", $t = (Lt ? Ot.h + Ft.h : Ot.w + Ft.w) / 2 + s.rankGap, Nt = vn(lt, yt);
1011
1011
  if (!Nt) continue;
1012
- const qt = $t - (_t(Tt)[Pt] - _t(At)[Pt]) * Nt;
1013
- if (qt <= 0.01) continue;
1014
- const zt = we(At, Pt, -Nt), Jt = we(Tt, Pt, Nt), Vt = qt * (s.mode === "pass" ? 0.4 : 0.95), jt = Math.min(zt, Jt < Vt / 2 ? Vt - Jt : Vt / 2), Zt = Math.min(Jt, Vt - jt);
1015
- he(At, Lt ? 0 : -jt * Nt, Lt ? -jt * Nt : 0), he(Tt, Lt ? 0 : Zt * Nt, Lt ? Zt * Nt : 0);
1012
+ const Bt = $t - (_t(Ft)[Pt] - _t(Ot)[Pt]) * Nt;
1013
+ if (Bt <= 0.01) continue;
1014
+ const zt = we(Ot, Pt, -Nt), Jt = we(Ft, Pt, Nt), Vt = Bt * (s.mode === "pass" ? 0.4 : 0.95), jt = Math.min(zt, Jt < Vt / 2 ? Vt - Jt : Vt / 2), Zt = Math.min(Jt, Vt - jt);
1015
+ he(Ot, Lt ? 0 : -jt * Nt, Lt ? -jt * Nt : 0), he(Ft, Lt ? 0 : Zt * Nt, Lt ? Zt * Nt : 0);
1016
1016
  }
1017
1017
  }
1018
1018
  I(2);
1019
- const bt = U(), It = us(D, lt, B, Rt, Dt);
1019
+ const bt = U(), It = us(D, lt, q, Rt, Dt);
1020
1020
  if (bt.n < nt.collisions.n || bt.n === nt.collisions.n && (bt.a < nt.collisions.a - 0.1 || Math.abs(bt.a - nt.collisions.a) < 0.1 && (It < nt.energy - 1e-3 || s.algorithm === "separate")) ? (nt = {
1021
1021
  coords: new Map(D.map((ut) => [ut.id, { x: ut.x, y: ut.y }])),
1022
1022
  collisions: bt,
1023
1023
  energy: It
1024
- }, le = 0) : le++, Bt = Math.max(
1024
+ }, le = 0) : le++, qt = Math.max(
1025
1025
  ...D.map((ut, tt) => ge(ut.x - st[tt].x, ut.y - st[tt].y)),
1026
1026
  0
1027
- ) < (e.tolerance || 0.08) ? Bt + 1 : 0, e.settle && q >= 40 && (Bt >= 12 || le >= 80)) {
1028
- fe = Bt >= 12 ? "settled" : "objective plateau";
1027
+ ) < (e.tolerance || 0.08) ? qt + 1 : 0, e.settle && B >= 40 && (qt >= 12 || le >= 80)) {
1028
+ fe = qt >= 12 ? "settled" : "objective plateau";
1029
1029
  break;
1030
1030
  }
1031
- q % 4 === 3 && H(
1031
+ B % 4 === 3 && H(
1032
1032
  "Refining " + (L ? c.get(L)?.title || "container" : "diagram")
1033
- ), q % 12 === 11 && await ki();
1033
+ ), B % 12 === 11 && await ki();
1034
1034
  }
1035
1035
  $.push({ parentId: L, iterations: de, reason: fe });
1036
- for (const q of D) {
1037
- const st = nt.coords.get(q.id);
1038
- x(q.id, st.x - i[q.id].x, st.y - i[q.id].y);
1036
+ for (const B of D) {
1037
+ const st = nt.coords.get(B.id);
1038
+ x(B.id, st.x - i[B.id].x, st.y - i[B.id].y);
1039
1039
  }
1040
1040
  if (Gt(), s.algorithm !== "separate")
1041
- for (let q = 0; q < 4; q++)
1041
+ for (let B = 0; B < 4; B++)
1042
1042
  for (const [st, dt] of Un(D, ct)) {
1043
1043
  const gt = Kt.get(st);
1044
1044
  if (!gt || gt.fixed) continue;
@@ -1051,11 +1051,11 @@ async function Ai(t, e = {}) {
1051
1051
  }
1052
1052
  }
1053
1053
  if (nt.collisions.n && s.mode === "rebuild" && St && !s.growContainers && D.length <= 24) {
1054
- const q = D.filter((bt) => !bt.fixed), st = D.filter((bt) => bt.fixed), dt = [
1055
- [...q].sort((bt, It) => It.w * It.h - bt.w * bt.h || ke(bt.id, It.id)),
1056
- [...q].sort((bt, It) => ke(bt.id, It.id)),
1057
- [...q].sort((bt, It) => It.h - bt.h || It.w - bt.w || ke(bt.id, It.id)),
1058
- [...q].sort((bt, It) => ke(It.id, bt.id))
1054
+ const B = D.filter((bt) => !bt.fixed), st = D.filter((bt) => bt.fixed), dt = [
1055
+ [...B].sort((bt, It) => It.w * It.h - bt.w * bt.h || ke(bt.id, It.id)),
1056
+ [...B].sort((bt, It) => ke(bt.id, It.id)),
1057
+ [...B].sort((bt, It) => It.h - bt.h || It.w - bt.w || ke(bt.id, It.id)),
1058
+ [...B].sort((bt, It) => ke(It.id, bt.id))
1059
1059
  ];
1060
1060
  let gt = null;
1061
1061
  for (const bt of dt) {
@@ -1066,26 +1066,26 @@ async function Ai(t, e = {}) {
1066
1066
  ut = !0;
1067
1067
  break;
1068
1068
  }
1069
- const yt = Dt?.get(tt.id) || _t(tt), At = /* @__PURE__ */ new Set([
1069
+ const yt = Dt?.get(tt.id) || _t(tt), Ot = /* @__PURE__ */ new Set([
1070
1070
  St.x,
1071
1071
  St.x + St.w - tt.w,
1072
1072
  Me(yt.x - tt.w / 2, St.x, St.x + St.w - tt.w)
1073
- ]), Tt = /* @__PURE__ */ new Set([
1073
+ ]), Ft = /* @__PURE__ */ new Set([
1074
1074
  St.y,
1075
1075
  St.y + St.h - tt.h,
1076
1076
  Me(yt.y - tt.h / 2, St.y, St.y + St.h - tt.h)
1077
1077
  ]);
1078
1078
  for (const Pt of It)
1079
- At.add(Pt.x + Pt.w + s.nodeGap + 0.2), At.add(Pt.x - tt.w - s.nodeGap - 0.2), Tt.add(Pt.y + Pt.h + s.nodeGap + 0.2), Tt.add(Pt.y - tt.h - s.nodeGap - 0.2);
1079
+ Ot.add(Pt.x + Pt.w + s.nodeGap + 0.2), Ot.add(Pt.x - tt.w - s.nodeGap - 0.2), Ft.add(Pt.y + Pt.h + s.nodeGap + 0.2), Ft.add(Pt.y - tt.h - s.nodeGap - 0.2);
1080
1080
  let Lt = null;
1081
- for (const Pt of [...Tt].sort(($t, Nt) => $t - Nt))
1082
- for (const $t of [...At].sort((Nt, qt) => Nt - qt)) {
1081
+ for (const Pt of [...Ft].sort(($t, Nt) => $t - Nt))
1082
+ for (const $t of [...Ot].sort((Nt, Bt) => Nt - Bt)) {
1083
1083
  if ($t < St.x - 1e-3 || Pt < St.y - 1e-3 || $t + tt.w > St.x + St.w + 1e-3 || Pt + tt.h > St.y + St.h + 1e-3)
1084
1084
  continue;
1085
1085
  const Nt = { ...tt, x: $t, y: Pt };
1086
1086
  if (It.some((zt) => yn(Nt, zt, s.nodeGap))) continue;
1087
- const qt = ($t + tt.w / 2 - yt.x) ** 2 + (Pt + tt.h / 2 - yt.y) ** 2;
1088
- (!Lt || qt < Lt.cost - 1e-3) && (Lt = { box: Nt, cost: qt });
1087
+ const Bt = ($t + tt.w / 2 - yt.x) ** 2 + (Pt + tt.h / 2 - yt.y) ** 2;
1088
+ (!Lt || Bt < Lt.cost - 1e-3) && (Lt = { box: Nt, cost: Bt });
1089
1089
  }
1090
1090
  if (!Lt) {
1091
1091
  ut = !0;
@@ -1100,12 +1100,12 @@ async function Ai(t, e = {}) {
1100
1100
  }
1101
1101
  if (gt) {
1102
1102
  for (const [bt, It] of gt) x(bt, It.x - i[bt].x, It.y - i[bt].y);
1103
- Gt(), T.add(
1103
+ Gt(), F.add(
1104
1104
  'Used local packing inside "' + (c.get(L)?.title || L) + '" because the requested arrangement did not fit its fixed frame.'
1105
1105
  );
1106
1106
  }
1107
1107
  }
1108
- U().n && T.add(
1108
+ U().n && F.add(
1109
1109
  "Some overlaps remain. Pins, fixed frames or the movement limit may prevent this pass from clearing them."
1110
1110
  ), L && N(L), H(
1111
1111
  "Finished " + (L ? c.get(L)?.title || "container" : "diagram"),
@@ -1156,7 +1156,7 @@ async function Ai(t, e = {}) {
1156
1156
  for (const [E, L] of Object.entries(i)) {
1157
1157
  const R = a[E];
1158
1158
  if (!R) continue;
1159
- if (A(E) || L.x === R.x && L.y === R.y) {
1159
+ if (O(E) || L.x === R.x && L.y === R.y) {
1160
1160
  L.x = R.x, L.y = R.y;
1161
1161
  continue;
1162
1162
  }
@@ -1170,13 +1170,13 @@ async function Ai(t, e = {}) {
1170
1170
  for (const E of u.values())
1171
1171
  if (h(E.id) && w(E.id)) {
1172
1172
  const L = i[E.id], R = i[h(E.id)], Z = n.layout.containers[h(E.id)]?.padding || 24;
1173
- (L.x < R.x + Z - 0.01 || L.y < R.y + Z + 28 - 0.01 || L.x + L.w > R.x + R.w - Z + 0.01 || L.y + L.h > R.y + R.h - Z + 0.01) && T.add(
1173
+ (L.x < R.x + Z - 0.01 || L.y < R.y + Z + 28 - 0.01 || L.x + L.w > R.x + R.w - Z + 0.01 || L.y + L.h > R.y + R.h - Z + 0.01) && F.add(
1174
1174
  "Some children extend beyond a frame. Enlarge that container or relax its constraints."
1175
1175
  );
1176
1176
  }
1177
1177
  if (z().overlaps > mt.overlaps && s.mode === "pass") {
1178
1178
  for (const E of Object.keys(i)) i[E] = Pn(a[E]);
1179
- T.add(
1179
+ F.add(
1180
1180
  "This pass was rejected because it introduced overlaps. Try a smaller scope or a different approach."
1181
1181
  ), at = 0, pt = 0, ot = 0;
1182
1182
  }
@@ -1198,7 +1198,7 @@ async function Ai(t, e = {}) {
1198
1198
  const G = l(V) === "DOWN" ? "y" : "x", X = vn(C, E);
1199
1199
  X && (_t(R)[G] - _t(L)[G]) * X <= 0.01 && ft++;
1200
1200
  }
1201
- s.respectDirection && ft && T.add(
1201
+ s.respectDirection && ft && F.add(
1202
1202
  ft + " forward-order conflict(s) remain; pins, frames, hierarchy directions or the movement budget can constrain placement."
1203
1203
  );
1204
1204
  const xt = Object.entries(r).map(([E, L]) => {
@@ -1208,13 +1208,13 @@ async function Ai(t, e = {}) {
1208
1208
  ...L,
1209
1209
  error: +G.toFixed(1),
1210
1210
  satisfied: G <= Math.max(12, s.nodeGap),
1211
- pinned: A(L.id)
1211
+ pinned: O(L.id)
1212
1212
  };
1213
1213
  });
1214
- xt.some((E) => !E.satisfied) && T.add(
1214
+ xt.some((E) => !E.satisfied) && F.add(
1215
1215
  "Some placement preferences remain approximate. They never override pins, fixed frames, collision safety, scope, or a pass movement limit."
1216
1216
  );
1217
- const O = {
1217
+ const A = {
1218
1218
  intent: xt,
1219
1219
  backwardEdges: ft,
1220
1220
  directedEdges: Mt,
@@ -1228,26 +1228,26 @@ async function Ai(t, e = {}) {
1228
1228
  rmsDisplacement: +Math.sqrt(ot / Math.max(1, at)).toFixed(2),
1229
1229
  movementLimit: s.mode === "pass" ? s.maxMove : null,
1230
1230
  iterations: j,
1231
- batches: F,
1231
+ batches: T,
1232
1232
  before: mt,
1233
1233
  after: z(),
1234
- warnings: [...T],
1234
+ warnings: [...F],
1235
1235
  milliseconds: Date.now() - o,
1236
1236
  deterministic: s.mode === "rebuild" && !e.warmStart && s.algorithm !== "separate",
1237
1237
  termination: e.settle ? $.some((E) => E.reason === "iteration limit") ? "iteration limit" : $.some((E) => E.reason === "objective plateau") ? "objective plateau" : "settled" : "bounded pass",
1238
1238
  solverStops: $
1239
1239
  };
1240
- return H("Computed finish", !0), { document: n, report: O, ...e.trace ? { trace: it } : {} };
1240
+ return H("Computed finish", !0), { document: n, report: A, ...e.trace ? { trace: it } : {} };
1241
1241
  }
1242
1242
  const Li = {
1243
1243
  algorithms: Wo,
1244
1244
  defaults: Uo,
1245
1245
  settings: La,
1246
- compute: Ai,
1246
+ compute: Oi,
1247
1247
  normalizeIntent: Ga,
1248
1248
  placements: Xo,
1249
1249
  topology: Vn
1250
- }, xe = Li, Fn = ["right", "bottom", "left", "top"], wt = 1e-4, Ut = (t) => Math.round(t * 100) / 100, Qn = (t, e, o) => Math.max(e, Math.min(o, t)), qe = (t) => JSON.parse(JSON.stringify(t)), _n = (t, e) => t < e ? -1 : t > e ? 1 : 0, ie = (t) => ({ x: t.x + t.w / 2, y: t.y + t.h / 2 }), Pe = (t, e) => Math.abs(t.x - e.x) < wt && Math.abs(t.y - e.y) < wt, re = (t, e) => Math.abs(t.x - e.x) + Math.abs(t.y - e.y), ue = {
1250
+ }, xe = Li, Tn = ["right", "bottom", "left", "top"], wt = 1e-4, Ut = (t) => Math.round(t * 100) / 100, Qn = (t, e, o) => Math.max(e, Math.min(o, t)), Be = (t) => JSON.parse(JSON.stringify(t)), _n = (t, e) => t < e ? -1 : t > e ? 1 : 0, ie = (t) => ({ x: t.x + t.w / 2, y: t.y + t.h / 2 }), Pe = (t, e) => Math.abs(t.x - e.x) < wt && Math.abs(t.y - e.y) < wt, re = (t, e) => Math.abs(t.x - e.x) + Math.abs(t.y - e.y), ue = {
1251
1251
  left: { x: -1, y: 0 },
1252
1252
  right: { x: 1, y: 0 },
1253
1253
  top: { x: 0, y: -1 },
@@ -1357,7 +1357,7 @@ function Pi(t) {
1357
1357
  return e.forEach((n, a) => o.set([n.x0, n.y0, n.x1, n.y1], a * 4)), un.set(t, { spansOf: e, box: o }), !0;
1358
1358
  }
1359
1359
  const Vo = (t, e, o, n) => o.x0 - n <= t[e * 4 + 2] + wt && t[e * 4] - n <= o.x1 + wt && o.y0 - n <= t[e * 4 + 3] + wt && t[e * 4 + 1] - n <= o.y1 + wt;
1360
- function Ti(t, e, o, n, a) {
1360
+ function Fi(t, e, o, n, a) {
1361
1361
  const s = Math.abs(t.y - e.y) < wt, r = Math.abs(o.y - n.y) < wt;
1362
1362
  if (s !== r) return null;
1363
1363
  const d = s ? "x" : "y", c = s ? "y" : "x", u = Math.min(Math.max(t[d], e[d]), Math.max(o[d], n[d])) - Math.max(Math.min(t[d], e[d]), Math.min(o[d], n[d])), i = Math.abs(t[c] - o[c]);
@@ -1385,7 +1385,7 @@ function je(t, e, o) {
1385
1385
  minGap: Number.isFinite(s) ? Ut(s) : null
1386
1386
  };
1387
1387
  }
1388
- function Fi(t, e, o, n) {
1388
+ function Ti(t, e, o, n) {
1389
1389
  let a = 0;
1390
1390
  const s = Ne(t), r = n - 0.05, d = un.get(e);
1391
1391
  for (let c = 0; c < e.length; c++) {
@@ -1403,7 +1403,7 @@ function Fi(t, e, o, n) {
1403
1403
  }
1404
1404
  return a;
1405
1405
  }
1406
- let Be = new Float64Array(96);
1406
+ let qe = new Float64Array(96);
1407
1407
  function be(t, e, o = 1 / 0, n = Ko) {
1408
1408
  let a = 0, s = 0;
1409
1409
  const r = Ne(t), d = un.get(e), c = t[0], u = t.at(-1);
@@ -1413,8 +1413,8 @@ function be(t, e, o = 1 / 0, n = Ko) {
1413
1413
  if (!Jo(r, h, 0)) continue;
1414
1414
  const l = s;
1415
1415
  for (let p = 0; p < r.n; p++) {
1416
- const m = r.h[p] === 1, g = m ? r.lo[p] : r.at[p], y = m ? r.hi[p] : r.at[p], P = m ? r.at[p] : r.lo[p], A = m ? r.at[p] : r.hi[p];
1417
- if (!(y < h.x0 - 2 * wt || g > h.x1 + 2 * wt || A < h.y0 - 2 * wt || P > h.y1 + 2 * wt))
1416
+ const m = r.h[p] === 1, g = m ? r.lo[p] : r.at[p], y = m ? r.hi[p] : r.at[p], P = m ? r.at[p] : r.lo[p], O = m ? r.at[p] : r.hi[p];
1417
+ if (!(y < h.x0 - 2 * wt || g > h.x1 + 2 * wt || O < h.y0 - 2 * wt || P > h.y1 + 2 * wt))
1418
1418
  for (let w = 0; w < h.n; w++) {
1419
1419
  if (r.h[p] === h.h[w]) {
1420
1420
  if (Math.abs(r.at[p] - h.at[w]) > wt) continue;
@@ -1423,22 +1423,22 @@ function be(t, e, o = 1 / 0, n = Ko) {
1423
1423
  return { crossings: s, shared: a };
1424
1424
  continue;
1425
1425
  }
1426
- const k = r.h[p] === 1, T = k ? r : h, F = k ? p : w, j = k ? h : r, $ = k ? w : p, v = j.at[$], S = T.at[F];
1427
- if (v < T.lo[F] - wt || v > T.hi[F] + wt || S < j.lo[$] - wt || S > j.hi[$] + wt)
1426
+ const k = r.h[p] === 1, F = k ? r : h, T = k ? p : w, j = k ? h : r, $ = k ? w : p, v = j.at[$], S = F.at[T];
1427
+ if (v < F.lo[T] - wt || v > F.hi[T] + wt || S < j.lo[$] - wt || S > j.hi[$] + wt)
1428
1428
  continue;
1429
1429
  const M = { x: v, y: S };
1430
1430
  if ((Pe(M, c) || Pe(M, u)) && (Pe(M, f.points[0]) || Pe(M, f.points.at(-1))))
1431
1431
  continue;
1432
1432
  const x = Ut(v), N = Ut(S);
1433
1433
  let z = l;
1434
- for (; z < s && !(Be[z * 3] === i && Be[z * 3 + 1] === x && Be[z * 3 + 2] === N); )
1434
+ for (; z < s && !(qe[z * 3] === i && qe[z * 3 + 1] === x && qe[z * 3 + 2] === N); )
1435
1435
  z++;
1436
1436
  if (!(z < s)) {
1437
- if (s * 3 + 3 > Be.length) {
1438
- const mt = new Float64Array(Be.length * 2);
1439
- mt.set(Be), Be = mt;
1437
+ if (s * 3 + 3 > qe.length) {
1438
+ const mt = new Float64Array(qe.length * 2);
1439
+ mt.set(qe), qe = mt;
1440
1440
  }
1441
- if (Be.set([i, x, N], s++ * 3), o < 1 / 0 && s * n.crossingPenalty + a * n.sharedPenalty >= o)
1441
+ if (qe.set([i, x, N], s++ * 3), o < 1 / 0 && s * n.crossingPenalty + a * n.sharedPenalty >= o)
1442
1442
  return { crossings: s, shared: a };
1443
1443
  }
1444
1444
  }
@@ -1487,7 +1487,7 @@ function ji(t, e, o) {
1487
1487
  }
1488
1488
  return n * Yn;
1489
1489
  }
1490
- function Ta(t, e, o) {
1490
+ function Fa(t, e, o) {
1491
1491
  for (const n of t) {
1492
1492
  const a = n.border ? [-n.band, n.band] : [-n.band];
1493
1493
  for (const s of a)
@@ -1495,9 +1495,9 @@ function Ta(t, e, o) {
1495
1495
  }
1496
1496
  }
1497
1497
  function ms(t, e) {
1498
- return Qo(t) + Math.max(0, t.length - 2) * e.bendPenalty + Fa(t);
1498
+ return Qo(t) + Math.max(0, t.length - 2) * e.bendPenalty + Ta(t);
1499
1499
  }
1500
- function Fa(t) {
1500
+ function Ta(t) {
1501
1501
  let e = 0;
1502
1502
  for (let o = 2; o < t.length - 1; o++) e += Math.max(0, 8 - re(t[o - 1], t[o])) * 4;
1503
1503
  return e;
@@ -1512,7 +1512,7 @@ function jn(t, e, o, n = []) {
1512
1512
  );
1513
1513
  }
1514
1514
  function _a(t, e, o, n, a) {
1515
- return o + Qo(t) + Math.max(0, t.length - 2) * e.bendPenalty + n.crossings * e.crossingPenalty + n.shared * e.sharedPenalty + a * e.parallelPenalty + Fa(t);
1515
+ return o + Qo(t) + Math.max(0, t.length - 2) * e.bendPenalty + n.crossings * e.crossingPenalty + n.shared * e.sharedPenalty + a * e.parallelPenalty + Ta(t);
1516
1516
  }
1517
1517
  class Di {
1518
1518
  constructor() {
@@ -1560,7 +1560,7 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1560
1560
  [u, C.y + C.h]
1561
1561
  ])
1562
1562
  Math.abs(W) < Ni && _.push(W);
1563
- Ta(s, c, u);
1563
+ Fa(s, c, u);
1564
1564
  for (const C of [t, e])
1565
1565
  c.push(C.x - a.edgeGap, C.x + a.edgeGap), u.push(C.y - a.edgeGap, C.y + a.edgeGap);
1566
1566
  for (const C of n)
@@ -1569,12 +1569,12 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1569
1569
  c.push(Math.min(...c) - 32, Math.max(...c) + 32), u.push(Math.min(...u) - 32, Math.max(...u) + 32);
1570
1570
  const i = (C) => !d || C >= d.x0 && C <= d.x1, f = (C) => !d || C >= d.y0 && C <= d.y1;
1571
1571
  d && (c.push(d.x0, d.x1), u.push(d.y0, d.y1));
1572
- const h = [...new Set(c.filter(i).map(Ut))].sort((C, _) => C - _), l = [...new Set(u.filter(f).map(Ut))].sort((C, _) => C - _), p = h.length, m = l.length, g = l.indexOf(Ut(t.y)) * p + h.indexOf(Ut(t.x)), y = l.indexOf(Ut(e.y)) * p + h.indexOf(Ut(e.x)), P = new Di(), A = new Float64Array(p * m * 2).fill(1 / 0), w = new Int32Array(p * m * 2).fill(-1), k = new Float64Array(p * m * 2).fill(NaN), T = Math.max(a.edgeGap, wt) + 1, F = h[0], j = h[p - 1], $ = l[0], v = l[m - 1], S = o.filter((C) => C.x < j && C.x + C.w > F && C.y < v && C.y + C.h > $), M = s.filter(
1573
- (C) => C.x - C.band < j && C.x + C.w + C.band > F && C.y - C.band < v && C.y + C.h + C.band > $
1572
+ const h = [...new Set(c.filter(i).map(Ut))].sort((C, _) => C - _), l = [...new Set(u.filter(f).map(Ut))].sort((C, _) => C - _), p = h.length, m = l.length, g = l.indexOf(Ut(t.y)) * p + h.indexOf(Ut(t.x)), y = l.indexOf(Ut(e.y)) * p + h.indexOf(Ut(e.x)), P = new Di(), O = new Float64Array(p * m * 2).fill(1 / 0), w = new Int32Array(p * m * 2).fill(-1), k = new Float64Array(p * m * 2).fill(NaN), F = Math.max(a.edgeGap, wt) + 1, T = h[0], j = h[p - 1], $ = l[0], v = l[m - 1], S = o.filter((C) => C.x < j && C.x + C.w > T && C.y < v && C.y + C.h > $), M = s.filter(
1573
+ (C) => C.x - C.band < j && C.x + C.w + C.band > T && C.y - C.band < v && C.y + C.h + C.band > $
1574
1574
  ), x = [];
1575
1575
  for (const C of n) {
1576
1576
  const _ = Ne(C.points);
1577
- if (!(_.x1 < F - T || _.x0 > j + T || _.y1 < $ - T || _.y0 > v + T))
1577
+ if (!(_.x1 < T - F || _.x0 > j + F || _.y1 < $ - F || _.y0 > v + F))
1578
1578
  for (const [W, b] of Se(C.points))
1579
1579
  x.push({
1580
1580
  a: W,
@@ -1603,7 +1603,7 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1603
1603
  };
1604
1604
  const ot = /* @__PURE__ */ new Set();
1605
1605
  for (const K of x) {
1606
- if (K[pt] < _ - T || K[at] > _ + T) continue;
1606
+ if (K[pt] < _ - F || K[at] > _ + F) continue;
1607
1607
  if (C === K.h) {
1608
1608
  b.parallel.push(K);
1609
1609
  continue;
@@ -1629,13 +1629,13 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1629
1629
  }
1630
1630
  for (const C of [0, 1]) {
1631
1631
  const _ = g * 2 + C;
1632
- A[_] = 0, P.push(_, 0, re(t, e));
1632
+ O[_] = 0, P.push(_, 0, re(t, e));
1633
1633
  }
1634
1634
  let Q = null, H = 0;
1635
1635
  for (; P.length && H++ < r; ) {
1636
1636
  P.pop();
1637
1637
  const C = P.key, _ = P.g;
1638
- if (_ !== A[C]) continue;
1638
+ if (_ !== O[C]) continue;
1639
1639
  const W = C >> 1, b = C & 1;
1640
1640
  if (W === y) {
1641
1641
  Q = C;
@@ -1646,14 +1646,14 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1646
1646
  const pt = at & 1, ot = at === 0 ? Y + 1 : at === 2 ? Y - 1 : Y, K = at === 1 ? et + 1 : at === 3 ? et - 1 : et;
1647
1647
  if (ot < 0 || K < 0 || ot >= p || K >= m) continue;
1648
1648
  const ft = K * p + ot, Mt = ft * 2 + pt, xt = (W < ft ? W : ft) * 2 + pt;
1649
- let O = k[xt];
1650
- if (O !== O) {
1649
+ let A = k[xt];
1650
+ if (A !== A) {
1651
1651
  const L = { x: h[Y], y: l[et] }, R = { x: h[ot], y: l[K] }, Z = pt ? z(!1, L.x) : z(!0, L.y);
1652
- O = Je(L, R, Z.obs) ? 1 / 0 : ht(L, R, Z), k[xt] = O;
1652
+ A = Je(L, R, Z.obs) ? 1 / 0 : ht(L, R, Z), k[xt] = A;
1653
1653
  }
1654
- if (O === 1 / 0) continue;
1655
- const E = _ + O + (b !== pt ? a.bendPenalty : 0);
1656
- E >= A[Mt] - 1e-3 || (A[Mt] = E, w[Mt] = C, P.push(Mt, E, E + Math.abs(h[ot] - e.x) + Math.abs(l[K] - e.y)));
1654
+ if (A === 1 / 0) continue;
1655
+ const E = _ + A + (b !== pt ? a.bendPenalty : 0);
1656
+ E >= O[Mt] - 1e-3 || (O[Mt] = E, w[Mt] = C, P.push(Mt, E, E + Math.abs(h[ot] - e.x) + Math.abs(l[K] - e.y)));
1657
1657
  }
1658
1658
  }
1659
1659
  if (Q === null) return null;
@@ -1664,21 +1664,21 @@ function Ci(t, e, o, n, a, s = [], r = 16e3, d = null) {
1664
1664
  }
1665
1665
  return We(J.reverse());
1666
1666
  }
1667
- function qi(t, e) {
1667
+ function Bi(t, e) {
1668
1668
  const o = [], n = [];
1669
1669
  for (const a of t)
1670
1670
  for (const [s, r] of Se(a.points))
1671
1671
  Math.abs(s.x - r.x) < wt ? o.push(s.x - e.edgeGap, s.x + e.edgeGap) : n.push(s.y - e.edgeGap, s.y + e.edgeGap);
1672
1672
  return { xs: o, ys: n };
1673
1673
  }
1674
- function Bi(t, e, o, n, a, s, r, d) {
1674
+ function qi(t, e, o, n, a, s, r, d) {
1675
1675
  const c = /* @__PURE__ */ new Set([(t.x + e.x) / 2]), u = /* @__PURE__ */ new Set([(t.y + e.y) / 2]);
1676
1676
  for (const m of o)
1677
1677
  m.x < Math.max(t.x, e.x) + 80 && m.x + m.w > Math.min(t.x, e.x) - 80 && (u.add(m.y), u.add(m.y + m.h)), m.y < Math.max(t.y, e.y) + 80 && m.y + m.h > Math.min(t.y, e.y) - 80 && (c.add(m.x), c.add(m.x + m.w));
1678
1678
  for (const m of a.xs) c.add(m);
1679
1679
  for (const m of a.ys) u.add(m);
1680
1680
  const i = { x: [], y: [] };
1681
- Ta(s, i.x, i.y);
1681
+ Fa(s, i.x, i.y);
1682
1682
  for (const m of i.x)
1683
1683
  m > Math.min(t.x, e.x) - 80 && m < Math.max(t.x, e.x) + 80 && c.add(m);
1684
1684
  for (const m of i.y)
@@ -1755,10 +1755,10 @@ function Hi(t) {
1755
1755
  const m = p ? 0 : 1;
1756
1756
  let g = h[m];
1757
1757
  if (!g) {
1758
- const w = p ? Math.min(i.x, f.x) : Math.min(i.y, f.y), k = p ? Math.max(i.x, f.x) : Math.max(i.y, f.y), T = p ? i.x : i.y, F = p ? f.x : f.y, j = p ? e : o;
1758
+ const w = p ? Math.min(i.x, f.x) : Math.min(i.y, f.y), k = p ? Math.max(i.x, f.x) : Math.max(i.y, f.y), F = p ? i.x : i.y, T = p ? f.x : f.y, j = p ? e : o;
1759
1759
  g = {
1760
- first: c(s((p ? "v" : "h") + T, j, T), p ? i.y : i.x),
1761
- last: c(s((p ? "v" : "h") + F, j, F), p ? f.y : f.x),
1760
+ first: c(s((p ? "v" : "h") + F, j, F), p ? i.y : i.x),
1761
+ last: c(s((p ? "v" : "h") + T, j, T), p ? f.y : f.x),
1762
1762
  middle: k - w <= 2 * pe ? null : r(
1763
1763
  (p ? "H" : "V") + w + "," + k,
1764
1764
  p ? o : e,
@@ -1847,19 +1847,19 @@ function ys(t, e, o, n, a, s, r = !1, d = !0) {
1847
1847
  for (const y of p) if (l.every((P) => Math.abs(y - P) >= h - 0.01)) return y;
1848
1848
  if (d && !r && kn < h) {
1849
1849
  const y = kn, P = [];
1850
- for (let A = 1; A <= 16; A++)
1851
- for (const w of [1, -1]) A * y <= u / 2 + wt && P.push(w * A * y);
1852
- P.sort((A, w) => Math.abs(A) - Math.abs(w) || (f < 0 ? A - w : w - A));
1853
- for (const A of P) if (l.every((w) => Math.abs(A - w) >= y - 0.01)) return A;
1850
+ for (let O = 1; O <= 16; O++)
1851
+ for (const w of [1, -1]) O * y <= u / 2 + wt && P.push(w * O * y);
1852
+ P.sort((O, w) => Math.abs(O) - Math.abs(w) || (f < 0 ? O - w : w - O));
1853
+ for (const O of P) if (l.every((w) => Math.abs(O - w) >= y - 0.01)) return O;
1854
1854
  }
1855
1855
  let m = 0, g = -1;
1856
1856
  for (let y = -u / 2; y <= u / 2; y += 2) {
1857
- const P = Math.min(...l.map((A) => Math.abs(y - A)));
1857
+ const P = Math.min(...l.map((O) => Math.abs(y - O)));
1858
1858
  P > g && (g = P, m = y);
1859
1859
  }
1860
1860
  return Ut(m);
1861
1861
  }
1862
- const xs = 100, ws = { right: "right", down: "bottom" }, Ms = { right: "left", down: "top" }, bs = 300, vs = { right: ["left", "top"], down: ["top", "left"] }, ks = { right: ["right", "bottom"], down: ["bottom", "right"] }, Ui = 80, Ss = 40, Es = 12, Is = 12, Yi = 0.5, Xi = 0.3, Os = 1;
1862
+ const xs = 100, ws = { right: "right", down: "bottom" }, Ms = { right: "left", down: "top" }, bs = 300, vs = { right: ["left", "top"], down: ["top", "left"] }, ks = { right: ["right", "bottom"], down: ["bottom", "right"] }, Ui = 80, Ss = 40, Es = 12, Is = 12, Yi = 0.5, Xi = 0.3, As = 1;
1863
1863
  function Ki(t, e) {
1864
1864
  let o = 0;
1865
1865
  for (let n = 1; n < t.length; n++) {
@@ -1874,7 +1874,7 @@ function Ki(t, e) {
1874
1874
  }
1875
1875
  return o;
1876
1876
  }
1877
- const Ji = 10, As = 1.75, Vi = 1.2, Qi = 120, uo = (t) => Se(t).reduce((e, [o, n]) => e + re(o, n), 0), po = 4, Ls = 100, Zi = 1, tr = 4, er = 4, nr = 32;
1877
+ const Ji = 10, Os = 1.75, Vi = 1.2, Qi = 120, uo = (t) => Se(t).reduce((e, [o, n]) => e + re(o, n), 0), po = 4, Ls = 100, Zi = 1, tr = 4, er = 4, nr = 32;
1878
1878
  function $s(t, e, o, n, a) {
1879
1879
  if (!t.some((r) => r.gates)) return t;
1880
1880
  const s = [...o === "top" ? [e.x] : [], ...a === "top" ? [n.x] : []];
@@ -1913,25 +1913,25 @@ function or(t, e = {}) {
1913
1913
  };
1914
1914
  for (const b of h)
1915
1915
  if (b.from !== b.to && !b.label)
1916
- for (const Y of Fn)
1916
+ for (const Y of Tn)
1917
1917
  y(b.from, b.to, Y) && g.set(b.from + "|" + Y, (g.get(b.from + "|" + Y) ?? 0) + 1);
1918
1918
  const P = (b, Y) => {
1919
1919
  const et = r.get(b), at = (Y === "left" || Y === "right" ? et.h : et.w) - 24, pt = Math.max(s.portGap, s.edgeGap), ot = (ft) => 1 + 2 * Math.floor(at / 2 / ft + wt), K = ot(pt);
1920
1920
  return o && (g.get(b + "|" + Y) ?? 0) > K && ot(Math.min(kn, pt)) > K;
1921
- }, A = (b) => [b.cfg.flow, e.direction].find((Y) => Y === "right" || Y === "down"), w = /* @__PURE__ */ new WeakMap(), k = (b, Y = l.has(b.id)) => {
1921
+ }, O = (b) => [b.cfg.flow, e.direction].find((Y) => Y === "right" || Y === "down"), w = /* @__PURE__ */ new WeakMap(), k = (b, Y = l.has(b.id)) => {
1922
1922
  const et = /* @__PURE__ */ new Set([...i(b.from), ...i(b.to)]), at = [...r.values()].filter((K) => !K.frame || K.id === b.from || K.id === b.to).map((K) => ho(K, s.clearance));
1923
1923
  for (const [K, ft] of d)
1924
1924
  if (!ft.collapsed)
1925
1925
  if (!et.has(K)) at.push(ho(ft, s.clearance));
1926
1926
  else {
1927
- const Mt = Math.max(1, Math.min(ft.w - 6, ft.titleWidth ?? 1 / 0)), xt = { y: ft.y + 2, h: (ft.titleHeight ?? 28) + s.clearance }, O = Math.max(s.clearance, s.standoff);
1927
+ const Mt = Math.max(1, Math.min(ft.w - 6, ft.titleWidth ?? 1 / 0)), xt = { y: ft.y + 2, h: (ft.titleHeight ?? 28) + s.clearance }, A = Math.max(s.clearance, s.standoff);
1928
1928
  at.push({ id: K + ":header", x: ft.x + 3, w: Mt, ...xt }), n ? at.push({
1929
1929
  id: K + ":header-band",
1930
1930
  // Beside the group only a clearance out, so a line can pass midway along its side.
1931
1931
  x: ft.x - s.clearance,
1932
1932
  w: ft.w + 2 * s.clearance,
1933
- y: ft.y - O,
1934
- h: xt.y + xt.h - ft.y + O,
1933
+ y: ft.y - A,
1934
+ h: xt.y + xt.h - ft.y + A,
1935
1935
  across: !0,
1936
1936
  ...Y ? {} : { gates: [] }
1937
1937
  }) : Mt < ft.w - 6 && at.push({
@@ -1950,11 +1950,11 @@ function or(t, e = {}) {
1950
1950
  { id: "wall-b", x: ot.x, y: ot.y + ot.h, w: ot.w, h: 2e6 }
1951
1951
  ), at;
1952
1952
  };
1953
- function T(b, Y, et, at, pt) {
1953
+ function F(b, Y, et, at, pt) {
1954
1954
  if (b.length < 2) return !1;
1955
1955
  pt = $s(pt, b[0], et, b.at(-1), at);
1956
- const ot = b[0], K = b[1], ft = b.at(-1), Mt = b.at(-2), xt = ue[et], O = ue[at];
1957
- if (xt.x * (K.x - ot.x) + xt.y * (K.y - ot.y) <= wt || O.x * (Mt.x - ft.x) + O.y * (Mt.y - ft.y) <= wt)
1956
+ const ot = b[0], K = b[1], ft = b.at(-1), Mt = b.at(-2), xt = ue[et], A = ue[at];
1957
+ if (xt.x * (K.x - ot.x) + xt.y * (K.y - ot.y) <= wt || A.x * (Mt.x - ft.x) + A.y * (Mt.y - ft.y) <= wt)
1958
1958
  return !1;
1959
1959
  for (let E = 1; E < b.length; E++) {
1960
1960
  const L = b[E - 1], R = b[E];
@@ -1970,20 +1970,20 @@ function or(t, e = {}) {
1970
1970
  }
1971
1971
  return !0;
1972
1972
  }
1973
- function F(b, Y, et, at, pt, ot) {
1973
+ function T(b, Y, et, at, pt, ot) {
1974
1974
  if (Y.cfg.waypoints?.length) return b;
1975
1975
  let K = We(b), ft = jn(K, ot, s, u);
1976
1976
  for (let Mt = 0; Mt < 4; Mt++) {
1977
1977
  let xt = !1;
1978
- const O = be(K, ot), E = je(K, ot, s.edgeGap);
1978
+ const A = be(K, ot), E = je(K, ot, s.edgeGap);
1979
1979
  t: for (let L = K.length - 1; L >= 2; L--)
1980
1980
  for (let R = 0; R + L < K.length; R++) {
1981
1981
  const Z = R + L, V = K[R], G = K[Z];
1982
1982
  for (const X of [[{ x: V.x, y: G.y }], [{ x: G.x, y: V.y }], []]) {
1983
1983
  const D = We([...K.slice(0, R + 1), ...X, ...K.slice(Z)]);
1984
- if (D.length >= K.length || !T(D, Y, et, at, pt)) continue;
1985
- const ct = be(D, ot), B = je(D, ot, s.edgeGap), rt = jn(D, ot, s, u);
1986
- if (!(ct.crossings > O.crossings || B.laneDeficit > E.laneDeficit + 0.1 || rt >= ft - 0.01)) {
1984
+ if (D.length >= K.length || !F(D, Y, et, at, pt)) continue;
1985
+ const ct = be(D, ot), q = je(D, ot, s.edgeGap), rt = jn(D, ot, s, u);
1986
+ if (!(ct.crossings > A.crossings || q.laneDeficit > E.laneDeficit + 0.1 || rt >= ft - 0.01)) {
1987
1987
  K = D, ft = rt, xt = !0;
1988
1988
  break t;
1989
1989
  }
@@ -1996,15 +1996,15 @@ function or(t, e = {}) {
1996
1996
  function j(b, Y, et, at = []) {
1997
1997
  const pt = v(b, Y, et, !1, at);
1998
1998
  if (!n || !k(b, !1).some((X) => X.gates)) return pt;
1999
- const ot = r.get(b.from), K = r.get(b.to), ft = ie(ot), Mt = ie(K), xt = Math.max(0, Math.abs(ft.x - Mt.x) - (ot.w + K.w) / 2) + Math.max(0, Math.abs(ft.y - Mt.y) - (ot.h + K.h) / 2), O = pt.blocked ? 1 / 0 : uo(pt.points), E = O > As * xt, L = [b.cfg.fromSide, b.cfg.toSide].some((X) => X && X !== "auto"), R = !pt.blocked && ($(b, pt) || L && O > Vi * xt + 40);
1999
+ const ot = r.get(b.from), K = r.get(b.to), ft = ie(ot), Mt = ie(K), xt = Math.max(0, Math.abs(ft.x - Mt.x) - (ot.w + K.w) / 2) + Math.max(0, Math.abs(ft.y - Mt.y) - (ot.h + K.h) / 2), A = pt.blocked ? 1 / 0 : uo(pt.points), E = A > Os * xt, L = [b.cfg.fromSide, b.cfg.toSide].some((X) => X && X !== "auto"), R = !pt.blocked && ($(b, pt) || L && A > Vi * xt + 40);
2000
2000
  if (!E && !R) return pt;
2001
2001
  const Z = v(b, Y, et, !0, at);
2002
2002
  if (Z.blocked) return pt;
2003
- const V = E && O > As * uo(Z.points), G = R && w.get(Z) + Qi < w.get(pt);
2003
+ const V = E && A > Os * uo(Z.points), G = R && w.get(Z) + Qi < w.get(pt);
2004
2004
  return !V && !G ? pt : (p.add(Z), Z);
2005
2005
  }
2006
2006
  function $(b, Y) {
2007
- const et = ie(r.get(b.from)), at = ie(r.get(b.to)), pt = A(b);
2007
+ const et = ie(r.get(b.from)), at = ie(r.get(b.to)), pt = O(b);
2008
2008
  return !!pt && b.from !== b.to && (pt === "down" ? at.y - et.y : at.x - et.x) > 20 && (vs[pt].includes(Y.fromSide) || ks[pt].includes(Y.toSide));
2009
2009
  }
2010
2010
  function v(b, Y, et, at, pt = []) {
@@ -2016,44 +2016,44 @@ function or(t, e = {}) {
2016
2016
  }
2017
2017
  }
2018
2018
  function S(b, Y, et, at, pt = []) {
2019
- const ot = r.get(b.from), K = r.get(b.to), ft = b.cfg, Mt = pt.length ? [...k(b, at), ...pt] : k(b, at), xt = ie(ot), O = ie(K), E = b.pin || {}, L = E.from ? [E.from.side] : ft.fromSide && ft.fromSide !== "auto" ? [ft.fromSide] : e.quick && et ? [et.fromSide] : Fn, R = E.to ? [E.to.side] : ft.toSide && ft.toSide !== "auto" ? [ft.toSide] : e.quick && et ? [et.toSide] : Fn, Z = A(b), V = Z === "down" ? O.y - xt.y : O.x - xt.x, G = Z && b.from !== b.to && V > 20, X = (I) => G ? (I.fs === ws[Z] ? 0 : vs[Z].includes(I.fs) ? bs : xs) + (I.ts === Ms[Z] ? 0 : ks[Z].includes(I.ts) ? bs : xs) : 0, D = (I, U) => G && I === (U === "from" ? ws : Ms)[Z], ct = [];
2020
- let B = null;
2021
- const rt = o ? u.filter((I) => !I.border && (I.id === b.from || I.id === b.to)) : [], lt = (I, U, nt) => Y.filter((q) => q[nt] === I && q[nt + "Side"] === U).length, kt = (I, U, nt) => ue[I].x * (nt.x - U.x) + ue[I].y * (nt.y - U.y) > 0.01, vt = (I, U, nt) => {
2022
- const q = (I === "left" || I === "right" ? U.h : U.w) - 24, st = o ? Math.min(kn, Math.max(s.portGap, s.edgeGap)) : Math.max(s.portGap, s.edgeGap);
2023
- return nt < 1 + 2 * Math.floor(q / 2 / st + wt);
2019
+ const ot = r.get(b.from), K = r.get(b.to), ft = b.cfg, Mt = pt.length ? [...k(b, at), ...pt] : k(b, at), xt = ie(ot), A = ie(K), E = b.pin || {}, L = E.from ? [E.from.side] : ft.fromSide && ft.fromSide !== "auto" ? [ft.fromSide] : e.quick && et ? [et.fromSide] : Tn, R = E.to ? [E.to.side] : ft.toSide && ft.toSide !== "auto" ? [ft.toSide] : e.quick && et ? [et.toSide] : Tn, Z = O(b), V = Z === "down" ? A.y - xt.y : A.x - xt.x, G = Z && b.from !== b.to && V > 20, X = (I) => G ? (I.fs === ws[Z] ? 0 : vs[Z].includes(I.fs) ? bs : xs) + (I.ts === Ms[Z] ? 0 : ks[Z].includes(I.ts) ? bs : xs) : 0, D = (I, U) => G && I === (U === "from" ? ws : Ms)[Z], ct = [];
2020
+ let q = null;
2021
+ const rt = o ? u.filter((I) => !I.border && (I.id === b.from || I.id === b.to)) : [], lt = (I, U, nt) => Y.filter((B) => B[nt] === I && B[nt + "Side"] === U).length, kt = (I, U, nt) => ue[I].x * (nt.x - U.x) + ue[I].y * (nt.y - U.y) > 0.01, vt = (I, U, nt) => {
2022
+ const B = (I === "left" || I === "right" ? U.h : U.w) - 24, st = o ? Math.min(kn, Math.max(s.portGap, s.edgeGap)) : Math.max(s.portGap, s.edgeGap);
2023
+ return nt < 1 + 2 * Math.floor(B / 2 / st + wt);
2024
2024
  };
2025
- function Ot(I, U, nt, q, st, dt) {
2025
+ function At(I, U, nt, B, st, dt) {
2026
2026
  const gt = lt(dt, I, st);
2027
- return !gt || (st === "from" ? D(I, "from") : D(I, "to")) || o && kt(I, nt, q) && vt(I, U, gt) ? 0 : gt * s.fanoutPenalty;
2027
+ return !gt || (st === "from" ? D(I, "from") : D(I, "to")) || o && kt(I, nt, B) && vt(I, U, gt) ? 0 : gt * s.fanoutPenalty;
2028
2028
  }
2029
- const Et = Math.max(0, Math.abs(xt.x - O.x) - (ot.w + K.w) / 2) + Math.max(0, Math.abs(xt.y - O.y) - (ot.h + K.h) / 2), Ft = (I) => Math.max(0, uo(I) - Et), St = o ? [
2029
+ const Et = Math.max(0, Math.abs(xt.x - A.x) - (ot.w + K.w) / 2) + Math.max(0, Math.abs(xt.y - A.y) - (ot.h + K.h) / 2), Tt = (I) => Math.max(0, uo(I) - Et), St = o ? [
2030
2030
  ...i(b.from).filter((I) => !i(b.to).includes(I)).map((I) => ({ g: d.get(I), box: ot })),
2031
2031
  ...i(b.to).filter((I) => !i(b.from).includes(I)).map((I) => ({ g: d.get(I), box: K }))
2032
- ].filter((I) => I.g && !I.g.collapsed) : [], Qt = (I) => St.reduce((U, { g: nt, box: q }) => {
2032
+ ].filter((I) => I.g && !I.g.collapsed) : [], Qt = (I) => St.reduce((U, { g: nt, box: B }) => {
2033
2033
  const st = Math.min(
2034
- q.x - nt.x,
2035
- nt.x + nt.w - (q.x + q.w),
2036
- q.y - nt.y,
2037
- nt.y + nt.h - (q.y + q.h)
2034
+ B.x - nt.x,
2035
+ nt.x + nt.w - (B.x + B.w),
2036
+ B.y - nt.y,
2037
+ nt.y + nt.h - (B.y + B.h)
2038
2038
  );
2039
2039
  return U + Math.max(0, Ki(I, nt) - Math.max(0, st));
2040
2040
  }, 0);
2041
- function Dt(I, U, nt = 1 / 0, q = !1) {
2042
- const st = ue[U.fs], dt = ue[U.ts], gt = { x: O.x - xt.x, y: O.y - xt.y }, bt = o ? Ls : 18, It = st.x * gt.x + st.y * gt.y < -0.01, Ct = dt.x * -gt.x + dt.y * -gt.y < -0.01, ut = o && (It && L.length > 1 || Ct && R.length > 1) ? Yi * Ft(I) : 0, tt = (It ? bt : 0) + (Ct ? bt : 0) + ut, yt = o ? (U.ts === "bottom" ? Ss : 0) + (U.ts === "right" ? Es : 0) + (U.fs === "top" || U.fs === "left" ? Is : 0) : 0, At = et ? (U.fs !== et.fromSide ? s.portStability : 0) + (U.ts !== et.toSide ? s.portStability : 0) : 0, Tt = U.fanout ??= Ot(U.fs, ot, xt, O, "from", b.from) + Ot(U.ts, K, O, xt, "to", b.to), Lt = o && U.fs === U.ts && I.length > 3 ? Ui : 0;
2043
- if (ms(I, s) + tt + yt + Lt + At + Tt + X(U) - Os >= nt)
2041
+ function Dt(I, U, nt = 1 / 0, B = !1) {
2042
+ const st = ue[U.fs], dt = ue[U.ts], gt = { x: A.x - xt.x, y: A.y - xt.y }, bt = o ? Ls : 18, It = st.x * gt.x + st.y * gt.y < -0.01, Ct = dt.x * -gt.x + dt.y * -gt.y < -0.01, ut = o && (It && L.length > 1 || Ct && R.length > 1) ? Yi * Tt(I) : 0, tt = (It ? bt : 0) + (Ct ? bt : 0) + ut, yt = o ? (U.ts === "bottom" ? Ss : 0) + (U.ts === "right" ? Es : 0) + (U.fs === "top" || U.fs === "left" ? Is : 0) : 0, Ot = et ? (U.fs !== et.fromSide ? s.portStability : 0) + (U.ts !== et.toSide ? s.portStability : 0) : 0, Ft = U.fanout ??= At(U.fs, ot, xt, A, "from", b.from) + At(U.ts, K, A, xt, "to", b.to), Lt = o && U.fs === U.ts && I.length > 3 ? Ui : 0;
2043
+ if (ms(I, s) + tt + yt + Lt + Ot + Ft + X(U) - As >= nt)
2044
2044
  return 1 / 0;
2045
- if (q) return 0;
2045
+ if (B) return 0;
2046
2046
  let Pt = 0;
2047
2047
  for (const [ee, se, Ce, Ke] of o ? [
2048
2048
  ["from", b.from, b.to, U.fs],
2049
2049
  ["to", b.to, b.from, U.ts]
2050
2050
  ] : []) {
2051
2051
  if (se === Ce) continue;
2052
- const Ae = Y.filter((mn) => mn[ee] === se && mn[ee + "Side"] === Ke), lo = ee === "from" && !b.label ? Fn.filter((mn) => P(se, mn) && y(se, Ce, mn)) : [];
2053
- lo.length && !lo.includes(Ke) && (Pt += 2 * s.fanoutPenalty), Pt -= Fi(I, Ae, lo.includes(Ke) ? 0 : Ji, s.edgeGap) * s.parallelPenalty;
2052
+ const Oe = Y.filter((mn) => mn[ee] === se && mn[ee + "Side"] === Ke), lo = ee === "from" && !b.label ? Tn.filter((mn) => P(se, mn) && y(se, Ce, mn)) : [];
2053
+ lo.length && !lo.includes(Ke) && (Pt += 2 * s.fanoutPenalty), Pt -= Ti(I, Oe, lo.includes(Ke) ? 0 : Ji, s.edgeGap) * s.parallelPenalty;
2054
2054
  }
2055
- const $t = Xi * Qt(I), Nt = rt.length ? cn(I, rt) * Zi : 0, qt = tt + yt + Lt + At + Tt + X(U), zt = (ee) => nt < 1 / 0 && ee - 1e-6 >= nt;
2056
- let Jt = ms(I, s) + $t + Pt + Nt + qt;
2055
+ const $t = Xi * Qt(I), Nt = rt.length ? cn(I, rt) * Zi : 0, Bt = tt + yt + Lt + Ot + Ft + X(U), zt = (ee) => nt < 1 / 0 && ee - 1e-6 >= nt;
2056
+ let Jt = ms(I, s) + $t + Pt + Nt + Bt;
2057
2057
  if (zt(Jt)) return 1 / 0;
2058
2058
  const Vt = u.length ? cn(I, u, nt - Jt + 1e-3) : 0;
2059
2059
  if (zt(Jt += Vt)) return 1 / 0;
@@ -2061,50 +2061,50 @@ function or(t, e = {}) {
2061
2061
  if (zt(Jt += jt.crossings * s.crossingPenalty + jt.shared * s.sharedPenalty))
2062
2062
  return 1 / 0;
2063
2063
  const Zt = je(I, Y, s.edgeGap).laneDeficit;
2064
- return $t + Pt + _a(I, s, Vt, jt, Zt) + Nt + tt + yt + Lt + At + Tt + X(U);
2064
+ return $t + Pt + _a(I, s, Vt, jt, Zt) + Nt + tt + yt + Lt + Ot + Ft + X(U);
2065
2065
  }
2066
- const ne = (I) => B ? I < B.gen ? B.score + 0.01 : B.score - 0.01 : 1 / 0, Gt = (I, U, nt = U.obs, q = 1 / 0) => {
2066
+ const ne = (I) => q ? I < q.gen ? q.score + 0.01 : q.score - 0.01 : 1 / 0, Gt = (I, U, nt = U.obs, B = 1 / 0) => {
2067
2067
  if (!I) return;
2068
- const st = ne(q), dt = We([U.start, ...I, U.end]);
2068
+ const st = ne(B), dt = We([U.start, ...I, U.end]);
2069
2069
  for (let bt = 2; bt < dt.length; bt++) {
2070
2070
  const It = dt[bt - 2], Ct = dt[bt - 1], ut = dt[bt];
2071
2071
  if ((Math.abs(It.x - Ct.x) < wt && Math.abs(Ct.x - ut.x) < wt || Math.abs(It.y - Ct.y) < wt && Math.abs(Ct.y - ut.y) < wt) && (Ct.x - It.x) * (ut.x - Ct.x) + (Ct.y - It.y) * (ut.y - Ct.y) < -1e-3)
2072
2072
  return;
2073
2073
  }
2074
- if (B && Dt(dt, U, st, !0) === 1 / 0 || dt.length < 2 || Se(dt).some(([bt, It], Ct) => Ct > 0 && Ct < dt.length - 2 && Je(bt, It, nt)))
2074
+ if (q && Dt(dt, U, st, !0) === 1 / 0 || dt.length < 2 || Se(dt).some(([bt, It], Ct) => Ct > 0 && Ct < dt.length - 2 && Je(bt, It, nt)))
2075
2075
  return;
2076
2076
  const gt = Dt(dt, U, st);
2077
- (!B || gt < st) && (B = { ...U, points: dt, score: gt, gen: q });
2077
+ (!q || gt < st) && (q = { ...U, points: dt, score: gt, gen: B });
2078
2078
  }, Yt = (I) => o && I.shape === "diamond", Kt = (I, U) => Y.some(
2079
2079
  (nt) => nt.from === I && nt.fromSide === U || nt.to === I && nt.toSide === U
2080
- ), ae = (I, U, nt, q) => Yt(I) && q.length > 1 && Kt(U, nt) && q.some((st) => !Kt(U, st)), Rt = qi(Y, s), Xt = new zi(
2080
+ ), ae = (I, U, nt, B) => Yt(I) && B.length > 1 && Kt(U, nt) && B.some((st) => !Kt(U, st)), Rt = Bi(Y, s), Xt = new zi(
2081
2081
  (I, U) => I.floor < U.floor || I.floor === U.floor && (I.idx < U.idx || I.idx === U.idx && I.k < U.k)
2082
2082
  ), te = (I) => {
2083
- const U = { x: O.x - xt.x, y: O.y - xt.y }, nt = ue[I.fs], q = ue[I.ts], st = o ? Ls : 18;
2084
- return (nt.x * U.x + nt.y * U.y < -0.01 ? st : 0) + (q.x * -U.x + q.y * -U.y < -0.01 ? st : 0) + (o ? (I.ts === "bottom" ? Ss : 0) + (I.ts === "right" ? Es : 0) + (I.fs === "top" || I.fs === "left" ? Is : 0) : 0) + (et && I.fs !== et.fromSide ? s.portStability : 0) + (et && I.ts !== et.toSide ? s.portStability : 0) + (I.fanout ??= Ot(I.fs, ot, xt, O, "from", b.from) + Ot(I.ts, K, O, xt, "to", b.to)) + X(I) - Os - 1;
2083
+ const U = { x: A.x - xt.x, y: A.y - xt.y }, nt = ue[I.fs], B = ue[I.ts], st = o ? Ls : 18;
2084
+ return (nt.x * U.x + nt.y * U.y < -0.01 ? st : 0) + (B.x * -U.x + B.y * -U.y < -0.01 ? st : 0) + (o ? (I.ts === "bottom" ? Ss : 0) + (I.ts === "right" ? Es : 0) + (I.fs === "top" || I.fs === "left" ? Is : 0) : 0) + (et && I.fs !== et.fromSide ? s.portStability : 0) + (et && I.ts !== et.toSide ? s.portStability : 0) + (I.fanout ??= At(I.fs, ot, xt, A, "from", b.from) + At(I.ts, K, A, xt, "to", b.to)) + X(I) - As - 1;
2085
2085
  }, Ht = [], oe = (I, U) => {
2086
2086
  const nt = te(I) + re(I.start, I.as) + re(I.bs, I.end);
2087
2087
  Ht.push({ c: I, o: U, stubs: nt, idx: Ht.length, min: nt + re(I.as, I.bs) });
2088
- }, Bt = () => B ? B.score + 0.01 : 1 / 0, le = (I) => I.idx * 1e6 + I.k + 1, fe = Hi(Y), de = ({ c: I, o: U, stubs: nt, idx: q }) => {
2088
+ }, qt = () => q ? q.score + 0.01 : 1 / 0, le = (I) => I.idx * 1e6 + I.k + 1, fe = Hi(Y), de = ({ c: I, o: U, stubs: nt, idx: B }) => {
2089
2089
  const st = fe(I.as, I.bs);
2090
- Bi(I.as, I.bs, U, s, Rt, u, Bt() - nt, (dt, gt, bt) => {
2090
+ qi(I.as, I.bs, U, s, Rt, u, qt() - nt, (dt, gt, bt) => {
2091
2091
  let It = nt + Qo(dt) + Wi(I.start, dt, I.end) * s.bendPenalty;
2092
- It >= Bt() || (It += st(dt, bt) * s.crossingPenalty, It < Bt() && Xt.push({ c: I, o: U, raw: dt, floor: It, idx: q, k: gt }));
2092
+ It >= qt() || (It += st(dt, bt) * s.crossingPenalty, It < qt() && Xt.push({ c: I, o: U, raw: dt, floor: It, idx: B, k: gt }));
2093
2093
  });
2094
2094
  };
2095
2095
  for (const I of L)
2096
2096
  for (const U of R) {
2097
2097
  if (b.from === b.to && I === U || ae(ot, b.from, I, L) || ae(K, b.to, U, R)) continue;
2098
- let nt = Yt(ot) ? 0 : ys(b.from, I, ot, Y, s, K, !b.label && P(b.from, I), o), q = Yt(K) ? 0 : ys(b.to, U, K, Y, s, ot, !1, o);
2098
+ let nt = Yt(ot) ? 0 : ys(b.from, I, ot, Y, s, K, !b.label && P(b.from, I), o), B = Yt(K) ? 0 : ys(b.to, U, K, Y, s, ot, !1, o);
2099
2099
  if ((I === "left" || I === "right") == (U === "left" || U === "right") && b.from !== b.to && !Yt(K)) {
2100
- const jt = I === "left" || I === "right", Zt = jt ? "y" : "x", ee = (jt ? K.h : K.w) / 2 - 12, se = me(ot, I, nt)[Zt] - ie(K)[Zt], Ce = K.frame ? Qn(se, -ee, ee) : se, Ke = Y.flatMap((Ae) => [
2101
- ...Ae.from === b.to && Ae.fromSide === U ? [Ae.fromOffset] : [],
2102
- ...Ae.to === b.to && Ae.toSide === U ? [Ae.toOffset] : []
2100
+ const jt = I === "left" || I === "right", Zt = jt ? "y" : "x", ee = (jt ? K.h : K.w) / 2 - 12, se = me(ot, I, nt)[Zt] - ie(K)[Zt], Ce = K.frame ? Qn(se, -ee, ee) : se, Ke = Y.flatMap((Oe) => [
2101
+ ...Oe.from === b.to && Oe.fromSide === U ? [Oe.fromOffset] : [],
2102
+ ...Oe.to === b.to && Oe.toSide === U ? [Oe.toOffset] : []
2103
2103
  ]);
2104
- Math.abs(Ce) <= ee && Ke.every((Ae) => Math.abs(Ce - Ae) >= Math.max(s.portGap, s.edgeGap) - 0.01) && (q = Ce);
2104
+ Math.abs(Ce) <= ee && Ke.every((Oe) => Math.abs(Ce - Oe) >= Math.max(s.portGap, s.edgeGap) - 0.01) && (B = Ce);
2105
2105
  }
2106
- typeof ft.toOffset == "number" && ft.toSide === U && !Yt(K) && (q = ft.toOffset), E.from && (nt = E.from.offset), E.to && (q = E.to.offset);
2107
- const dt = me(ot, I, nt), gt = me(K, U, q), bt = $s(Mt, dt, I, gt, U), It = s.standoff ? {
2106
+ typeof ft.toOffset == "number" && ft.toSide === U && !Yt(K) && (B = ft.toOffset), E.from && (nt = E.from.offset), E.to && (B = E.to.offset);
2107
+ const dt = me(ot, I, nt), gt = me(K, U, B), bt = $s(Mt, dt, I, gt, U), It = s.standoff ? {
2108
2108
  right: K.x - ot.x - ot.w,
2109
2109
  left: ot.x - K.x - K.w,
2110
2110
  bottom: K.y - ot.y - ot.h,
@@ -2112,26 +2112,26 @@ function or(t, e = {}) {
2112
2112
  }[I] : 0, Ct = ue[I].x === -ue[U].x && ue[I].y === -ue[U].y && It > 0 && It < 2 * (s.clearance + 3), ut = Ct ? It / 2 : s.clearance + 3, tt = Ct ? bt.filter((jt) => jt.id !== b.from && jt.id !== b.to) : null, yt = (jt, Zt, ee, se) => ({
2113
2113
  x: Ut(Zt === "left" ? jt.x - se : Zt === "right" ? jt.x + jt.w + se : ee.x),
2114
2114
  y: Ut(Zt === "top" ? jt.y - se : Zt === "bottom" ? jt.y + jt.h + se : ee.y)
2115
- }), At = (jt, Zt, ee) => !Je(jt, Zt, tt || bt.filter((se) => se.id !== ee)), Tt = Math.max(ut, s.standoff);
2115
+ }), Ot = (jt, Zt, ee) => !Je(jt, Zt, tt || bt.filter((se) => se.id !== ee)), Ft = Math.max(ut, s.standoff);
2116
2116
  let Lt = yt(ot, I, dt, ut), Pt = yt(K, U, gt, ut);
2117
- if (!At(dt, Lt, b.from) || !At(gt, Pt, b.to)) continue;
2118
- if (!Ct && Yt(ot) && Tt > ut) {
2119
- const jt = yt(ot, I, dt, Tt);
2120
- At(dt, jt, b.from) && (Lt = jt);
2117
+ if (!Ot(dt, Lt, b.from) || !Ot(gt, Pt, b.to)) continue;
2118
+ if (!Ct && Yt(ot) && Ft > ut) {
2119
+ const jt = yt(ot, I, dt, Ft);
2120
+ Ot(dt, jt, b.from) && (Lt = jt);
2121
2121
  }
2122
- if (!Ct && Yt(K) && Tt > ut) {
2123
- const jt = yt(K, U, gt, Tt);
2124
- At(gt, jt, b.to) && (Pt = jt);
2122
+ if (!Ct && Yt(K) && Ft > ut) {
2123
+ const jt = yt(K, U, gt, Ft);
2124
+ Ot(gt, jt, b.to) && (Pt = jt);
2125
2125
  }
2126
- const $t = { fs: I, ts: U, fo: nt, toff: q, start: dt, end: gt, as: Lt, bs: Pt, obs: bt }, Nt = [dt, ...ft.waypoints || [], gt];
2126
+ const $t = { fs: I, ts: U, fo: nt, toff: B, start: dt, end: gt, as: Lt, bs: Pt, obs: bt }, Nt = [dt, ...ft.waypoints || [], gt];
2127
2127
  if ($t.lower = Nt.reduce((jt, Zt, ee) => ee ? jt + re(Nt[ee - 1], Zt) : 0, 0) + X($t) + (et && I !== et.fromSide ? s.portStability : 0) + (et && U !== et.toSide ? s.portStability : 0), Ct) {
2128
2128
  if (ft.waypoints?.length) continue;
2129
2129
  oe($t, [...tt, { ...ot, id: b.from }, { ...K, id: b.to }]);
2130
2130
  continue;
2131
2131
  }
2132
2132
  if (ct.push($t), ft.waypoints?.length) continue;
2133
- const qt = ue[I], zt = ue[U], Jt = gt.x - dt.x, Vt = gt.y - dt.y;
2134
- (dt.x === gt.x || dt.y === gt.y) && qt.x * Jt + qt.y * Vt > 0 && zt.x * -Jt + zt.y * -Vt > 0 && !Je(
2133
+ const Bt = ue[I], zt = ue[U], Jt = gt.x - dt.x, Vt = gt.y - dt.y;
2134
+ (dt.x === gt.x || dt.y === gt.y) && Bt.x * Jt + Bt.y * Vt > 0 && zt.x * -Jt + zt.y * -Vt > 0 && !Je(
2135
2135
  dt,
2136
2136
  gt,
2137
2137
  bt.filter((jt) => jt.id !== b.from && jt.id !== b.to)
@@ -2148,26 +2148,26 @@ function or(t, e = {}) {
2148
2148
  for (let I = 0; ; ) {
2149
2149
  const U = Xt.items[0];
2150
2150
  if (I < Ht.length && (!U || Ht[I].min <= U.floor)) {
2151
- Ht[I].min >= Bt() ? I = Ht.length : de(Ht[I++]);
2151
+ Ht[I].min >= qt() ? I = Ht.length : de(Ht[I++]);
2152
2152
  continue;
2153
2153
  }
2154
- if (!U || U.floor >= Bt()) break;
2154
+ if (!U || U.floor >= qt()) break;
2155
2155
  const nt = Xt.pop();
2156
2156
  if (nt.path) {
2157
2157
  Gt(nt.path, nt.c, nt.c.obs, le(nt));
2158
2158
  continue;
2159
2159
  }
2160
- const q = We(nt.raw);
2161
- Se(q).some(([st, dt]) => Je(st, dt, nt.o)) || Gt(q, nt.c, nt.o, le(nt));
2160
+ const B = We(nt.raw);
2161
+ Se(B).some(([st, dt]) => Je(st, dt, nt.o)) || Gt(B, nt.c, nt.o, le(nt));
2162
2162
  }
2163
2163
  ct.sort((I, U) => I.lower - U.lower || _n(I.fs + ":" + I.ts, U.fs + ":" + U.ts));
2164
2164
  let he = 0;
2165
2165
  for (const I of ct) {
2166
- if (B && I.lower > B.score) continue;
2167
- if (he++ >= (e.quick ? 1 : 3) || B && !be(B.points, Y).crossings && !je(B.points, Y, s.edgeGap).lanePairs && !ft.waypoints?.length && B.points.length <= 6)
2166
+ if (q && I.lower > q.score) continue;
2167
+ if (he++ >= (e.quick ? 1 : 3) || q && !be(q.points, Y).crossings && !je(q.points, Y, s.edgeGap).lanePairs && !ft.waypoints?.length && q.points.length <= 6)
2168
2168
  break;
2169
2169
  const U = [I.as, ...ft.waypoints || [], I.bs], nt = [];
2170
- let q = !0;
2170
+ let B = !0;
2171
2171
  for (let st = 1; st < U.length; st++) {
2172
2172
  const dt = U[st - 1], gt = U[st], bt = {
2173
2173
  x0: Math.min(ot.x, K.x, dt.x, gt.x),
@@ -2181,16 +2181,16 @@ function or(t, e = {}) {
2181
2181
  if (Ct = Ci(dt, gt, I.obs, Y, s, u, u.length ? 64e3 : 16e3, tt), Ct) break;
2182
2182
  }
2183
2183
  if (!Ct) {
2184
- q = !1;
2184
+ B = !1;
2185
2185
  break;
2186
2186
  }
2187
2187
  nt.push(...Ct);
2188
2188
  }
2189
- q && Gt(nt, I);
2189
+ B && Gt(nt, I);
2190
2190
  }
2191
- if (!B && e.quick && et) return S(b, Y, null, at, pt);
2192
- if (!B) {
2193
- const I = L[0], U = R[0], nt = me(ot, I), q = me(K, U);
2191
+ if (!q && e.quick && et) return S(b, Y, null, at, pt);
2192
+ if (!q) {
2193
+ const I = L[0], U = R[0], nt = me(ot, I), B = me(K, U);
2194
2194
  return {
2195
2195
  id: b.id,
2196
2196
  from: b.from,
@@ -2199,30 +2199,30 @@ function or(t, e = {}) {
2199
2199
  toSide: U,
2200
2200
  fromOffset: 0,
2201
2201
  toOffset: 0,
2202
- points: We([nt, { x: q.x, y: nt.y }, q]),
2202
+ points: We([nt, { x: B.x, y: nt.y }, B]),
2203
2203
  blocked: !0,
2204
2204
  reason: "No clear route within the search budget and current side / waypoint constraints."
2205
2205
  };
2206
2206
  }
2207
- B.points = F(B.points, b, B.fs, B.ts, Mt, Y);
2207
+ q.points = T(q.points, b, q.fs, q.ts, Mt, Y);
2208
2208
  const we = {
2209
2209
  id: b.id,
2210
2210
  from: b.from,
2211
2211
  to: b.to,
2212
- fromSide: B.fs,
2213
- toSide: B.ts,
2214
- fromOffset: B.fo,
2215
- toOffset: B.toff,
2216
- points: B.points,
2212
+ fromSide: q.fs,
2213
+ toSide: q.ts,
2214
+ fromOffset: q.fo,
2215
+ toOffset: q.toff,
2216
+ points: q.points,
2217
2217
  blocked: !1
2218
2218
  };
2219
- return w.set(we, B.score), we;
2219
+ return w.set(we, q.score), we;
2220
2220
  }
2221
2221
  const M = (b) => {
2222
2222
  const Y = b.cfg.plan;
2223
2223
  if (!Y || b.from === b.to || b.cfg.waypoints?.length) return null;
2224
2224
  const et = Y.points, at = Math.abs(et[0].y - et[1].y) < wt, pt = at ? et[1].x > et[0].x ? "right" : "left" : et[1].y > et[0].y ? "bottom" : "top", ot = et.at(-2), K = et.at(-1), ft = Math.abs(ot.y - K.y) < wt ? K.x > ot.x ? "left" : "right" : K.y > ot.y ? "top" : "bottom", Mt = me(r.get(b.from), pt, Y.fromOffset), xt = me(r.get(b.to), ft, Y.toOffset);
2225
- return b.cfg.fromSide && b.cfg.fromSide !== "auto" && b.cfg.fromSide !== pt || b.cfg.toSide && b.cfg.toSide !== "auto" && b.cfg.toSide !== ft || typeof b.cfg.toOffset == "number" && b.cfg.toOffset !== Y.toOffset || re(et[0], Mt) > 0.02 || re(K, xt) > 0.02 || !T(et, b, pt, ft, k(b)) ? null : {
2225
+ return b.cfg.fromSide && b.cfg.fromSide !== "auto" && b.cfg.fromSide !== pt || b.cfg.toSide && b.cfg.toSide !== "auto" && b.cfg.toSide !== ft || typeof b.cfg.toOffset == "number" && b.cfg.toOffset !== Y.toOffset || re(et[0], Mt) > 0.02 || re(K, xt) > 0.02 || !F(et, b, pt, ft, k(b)) ? null : {
2226
2226
  id: b.id,
2227
2227
  from: b.from,
2228
2228
  to: b.to,
@@ -2230,7 +2230,7 @@ function or(t, e = {}) {
2230
2230
  toSide: ft,
2231
2231
  fromOffset: Y.fromOffset,
2232
2232
  toOffset: Y.toOffset,
2233
- points: et.map((O) => ({ x: O.x, y: O.y })),
2233
+ points: et.map((A) => ({ x: A.x, y: A.y })),
2234
2234
  blocked: !1
2235
2235
  };
2236
2236
  };
@@ -2257,7 +2257,7 @@ function or(t, e = {}) {
2257
2257
  blocked: b.filter((K) => K.blocked).length,
2258
2258
  bends: b.reduce((K, ft) => K + Math.max(0, ft.points.length - 2), 0),
2259
2259
  length: Ut(
2260
- b.reduce((K, ft) => K + Se(ft.points).reduce((Mt, [xt, O]) => Mt + re(xt, O), 0), 0)
2260
+ b.reduce((K, ft) => K + Se(ft.points).reduce((Mt, [xt, A]) => Mt + re(xt, A), 0), 0)
2261
2261
  )
2262
2262
  };
2263
2263
  }, mt = (b) => {
@@ -2292,16 +2292,16 @@ function or(t, e = {}) {
2292
2292
  const K = x.findIndex((L) => L.id === ot.id), ft = x.filter((L, R) => R !== K), Mt = be(x[K].points, ft);
2293
2293
  if (!x[K].blocked && !Mt.crossings && !Mt.shared && !je(x[K].points, ft, s.edgeGap).lanePairs && !ht(x[K]))
2294
2294
  continue;
2295
- const xt = j(ot, ft, x[K]), O = [...x];
2296
- O[K] = xt;
2297
- const E = mt(O);
2298
- E < pt - 0.1 && (x = O, pt = E, m(), Q++);
2295
+ const xt = j(ot, ft, x[K]), A = [...x];
2296
+ A[K] = xt;
2297
+ const E = mt(A);
2298
+ E < pt - 0.1 && (x = A, pt = E, m(), Q++);
2299
2299
  }
2300
2300
  }
2301
2301
  let H = 0;
2302
2302
  if (!e.quick && o && h.length <= nr) {
2303
- const b = (xt) => xt.toSide === "bottom" || ht(xt) || xt.fromSide === xt.toSide && xt.points.length > 3, Y = (xt) => mt(xt) + xt.reduce((O, E) => O + cn(E.points, u), 0), et = (xt, O) => {
2304
- const E = /* @__PURE__ */ new Set([O.from, O.to]), L = Se(xt.points);
2303
+ const b = (xt) => xt.toSide === "bottom" || ht(xt) || xt.fromSide === xt.toSide && xt.points.length > 3, Y = (xt) => mt(xt) + xt.reduce((A, E) => A + cn(E.points, u), 0), et = (xt, A) => {
2304
+ const E = /* @__PURE__ */ new Set([A.from, A.to]), L = Se(xt.points);
2305
2305
  return L.filter(
2306
2306
  (R, Z) => !(Z === 0 && E.has(xt.from)) && !(Z === L.length - 1 && E.has(xt.to))
2307
2307
  ).map(
@@ -2315,45 +2315,45 @@ function or(t, e = {}) {
2315
2315
  s.edgeGap / 2
2316
2316
  )
2317
2317
  );
2318
- }, at = new Map(h.map((xt) => [xt.id, xt])), pt = (xt) => xt.cfg.waypoints?.length > 0 || N.has(xt.id), ot = ["from", "to"], K = (xt, O) => xt[O] + "|" + xt[O + "Side"], ft = (xt, O) => {
2319
- const E = new Set([x[xt], x[O]].flatMap((B) => ot.map((rt) => K(B, rt)))), L = x.flatMap(
2320
- (B, rt) => rt === xt || rt === O || B.from !== B.to && ot.some((lt) => E.has(K(B, lt))) ? [rt] : []
2318
+ }, at = new Map(h.map((xt) => [xt.id, xt])), pt = (xt) => xt.cfg.waypoints?.length > 0 || N.has(xt.id), ot = ["from", "to"], K = (xt, A) => xt[A] + "|" + xt[A + "Side"], ft = (xt, A) => {
2319
+ const E = new Set([x[xt], x[A]].flatMap((q) => ot.map((rt) => K(q, rt)))), L = x.flatMap(
2320
+ (q, rt) => rt === xt || rt === A || q.from !== q.to && ot.some((lt) => E.has(K(q, lt))) ? [rt] : []
2321
2321
  );
2322
- if (L.length > er || L.some((B) => pt(at.get(x[B].id)))) return [];
2322
+ if (L.length > er || L.some((q) => pt(at.get(x[q].id)))) return [];
2323
2323
  const R = /* @__PURE__ */ new Map();
2324
- for (const B of L)
2324
+ for (const q of L)
2325
2325
  for (const rt of ot) {
2326
- const lt = K(x[B], rt);
2327
- R.has(lt) || R.set(lt, []), R.get(lt).push({ q: B, end: rt });
2326
+ const lt = K(x[q], rt);
2327
+ R.has(lt) || R.set(lt, []), R.get(lt).push({ q, end: rt });
2328
2328
  }
2329
- const Z = new Map(L.map((B) => [B, {}]));
2329
+ const Z = new Map(L.map((q) => [q, {}]));
2330
2330
  let V = !1;
2331
- for (const B of R.values()) {
2332
- if (B.length < 2) continue;
2333
- const rt = x[B[0].q][B[0].end + "Side"], lt = rt === "left" || rt === "right" ? "y" : "x", kt = ({ q: Et, end: Ft }) => x[Et][Ft + "Offset"], vt = ({ q: Et, end: Ft }) => ie(r.get(x[Et][Ft === "from" ? "to" : "from"]))[lt], Ot = B.map(kt).sort((Et, Ft) => Et - Ft);
2334
- [...B].sort((Et, Ft) => vt(Et) - vt(Ft) || kt(Et) - kt(Ft)).forEach((Et, Ft) => {
2335
- Ot[Ft] !== kt(Et) && (V = !0), Z.get(Et.q)[Et.end] = { side: rt, offset: Ot[Ft] };
2331
+ for (const q of R.values()) {
2332
+ if (q.length < 2) continue;
2333
+ const rt = x[q[0].q][q[0].end + "Side"], lt = rt === "left" || rt === "right" ? "y" : "x", kt = ({ q: Et, end: Tt }) => x[Et][Tt + "Offset"], vt = ({ q: Et, end: Tt }) => ie(r.get(x[Et][Tt === "from" ? "to" : "from"]))[lt], At = q.map(kt).sort((Et, Tt) => Et - Tt);
2334
+ [...q].sort((Et, Tt) => vt(Et) - vt(Tt) || kt(Et) - kt(Tt)).forEach((Et, Tt) => {
2335
+ At[Tt] !== kt(Et) && (V = !0), Z.get(Et.q)[Et.end] = { side: rt, offset: At[Tt] };
2336
2336
  });
2337
2337
  }
2338
2338
  if (!V) return [];
2339
- const G = x.filter((B, rt) => !L.includes(rt)), X = (B) => {
2340
- const rt = x[B], lt = Z.get(B).from, kt = lt ? me(r.get(rt.from), lt.side, lt.offset) : rt.points[0];
2339
+ const G = x.filter((q, rt) => !L.includes(rt)), X = (q) => {
2340
+ const rt = x[q], lt = Z.get(q).from, kt = lt ? me(r.get(rt.from), lt.side, lt.offset) : rt.points[0];
2341
2341
  return rt.fromSide === "left" || rt.fromSide === "right" ? kt.y : kt.x;
2342
- }, D = [...L].sort((B, rt) => X(B) - X(rt) || B - rt);
2342
+ }, D = [...L].sort((q, rt) => X(q) - X(rt) || q - rt);
2343
2343
  return [...new Map(
2344
- [L, [...L].reverse(), D, [...D].reverse()].map((B) => [B.join(), B])
2345
- ).values()].map((B) => {
2344
+ [L, [...L].reverse(), D, [...D].reverse()].map((q) => [q.join(), q])
2345
+ ).values()].map((q) => {
2346
2346
  const rt = [...x], lt = [];
2347
- for (const kt of B) {
2348
- const vt = at.get(x[kt].id), Ot = j({ ...vt, pin: Z.get(kt) }, [...G, ...lt], x[kt]);
2349
- if (Ot.blocked) return x;
2350
- rt[kt] = Ot, lt.push(Ot);
2347
+ for (const kt of q) {
2348
+ const vt = at.get(x[kt].id), At = j({ ...vt, pin: Z.get(kt) }, [...G, ...lt], x[kt]);
2349
+ if (At.blocked) return x;
2350
+ rt[kt] = At, lt.push(At);
2351
2351
  }
2352
2352
  return rt;
2353
2353
  });
2354
2354
  }, Mt = /* @__PURE__ */ new Set();
2355
2355
  for (let xt = 0; xt < 2; xt++) {
2356
- let O = !1;
2356
+ let A = !1;
2357
2357
  for (let E = 0; E < x.length; E++)
2358
2358
  for (let L = E + 1; L < x.length; L++) {
2359
2359
  if (!be(x[E].points, [x[L]]).crossings) continue;
@@ -2362,7 +2362,7 @@ function or(t, e = {}) {
2362
2362
  Mt.add(R);
2363
2363
  let Z = null, V = Y(x) - 0.1;
2364
2364
  const G = (X) => {
2365
- if (X.some((ct, B) => ct !== x[B] && b(ct) && !b(x[B])) || z(X).crossings >= z(x).crossings)
2365
+ if (X.some((ct, q) => ct !== x[q] && b(ct) && !b(x[q])) || z(X).crossings >= z(x).crossings)
2366
2366
  return;
2367
2367
  const D = Y(X);
2368
2368
  D < V && (Z = X, V = D);
@@ -2371,29 +2371,29 @@ function or(t, e = {}) {
2371
2371
  [E, L],
2372
2372
  [L, E]
2373
2373
  ]) {
2374
- const ct = at.get(x[X].id), B = at.get(x[D].id);
2374
+ const ct = at.get(x[X].id), q = at.get(x[D].id);
2375
2375
  if (pt(ct)) continue;
2376
- const rt = x.filter((vt, Ot) => Ot !== X && Ot !== D), lt = [], kt = j(ct, [...rt, x[D]], x[X], et(x[D], ct));
2376
+ const rt = x.filter((vt, At) => At !== X && At !== D), lt = [], kt = j(ct, [...rt, x[D]], x[X], et(x[D], ct));
2377
2377
  if (!kt.blocked) {
2378
2378
  const vt = [...x];
2379
- if (vt[X] = kt, lt.push(vt), !pt(B)) {
2380
- const Ot = [...vt];
2381
- Ot[D] = j(B, [...rt, kt], x[D]), lt.push(Ot);
2379
+ if (vt[X] = kt, lt.push(vt), !pt(q)) {
2380
+ const At = [...vt];
2381
+ At[D] = j(q, [...rt, kt], x[D]), lt.push(At);
2382
2382
  }
2383
2383
  }
2384
- if (!pt(B)) {
2385
- const vt = j(B, rt, x[D]), Ot = j(ct, [...rt, vt], x[X], et(vt, ct));
2386
- if (!Ot.blocked) {
2384
+ if (!pt(q)) {
2385
+ const vt = j(q, rt, x[D]), At = j(ct, [...rt, vt], x[X], et(vt, ct));
2386
+ if (!At.blocked) {
2387
2387
  const Et = [...x];
2388
- Et[D] = vt, Et[X] = Ot, lt.push(Et);
2388
+ Et[D] = vt, Et[X] = At, lt.push(Et);
2389
2389
  }
2390
2390
  }
2391
2391
  for (const vt of lt) G(vt);
2392
2392
  }
2393
2393
  if (!Z) for (const X of ft(E, L)) G(X);
2394
- Z && (x = Z, m(), H++, O = !0);
2394
+ Z && (x = Z, m(), H++, A = !0);
2395
2395
  }
2396
- if (!O) break;
2396
+ if (!A) break;
2397
2397
  }
2398
2398
  }
2399
2399
  let J = 0;
@@ -2401,21 +2401,21 @@ function or(t, e = {}) {
2401
2401
  for (let b = 0; b < 3; b++) {
2402
2402
  let Y = !1;
2403
2403
  for (let et = 0; et < x.length; et++) {
2404
- const at = x[et], pt = h.find((O) => O.id === at.id);
2404
+ const at = x[et], pt = h.find((A) => A.id === at.id);
2405
2405
  if (at.blocked || pt.cfg.waypoints?.length || N.has(pt.id)) continue;
2406
- const ot = x.filter((O, E) => E !== et), K = k(pt);
2406
+ const ot = x.filter((A, E) => E !== et), K = k(pt);
2407
2407
  if (!je(at.points, ot, s.edgeGap).lanePairs) continue;
2408
2408
  let ft = at.points, Mt = jn(ft, ot, s, u), xt = be(ft, ot);
2409
- for (let O = 1; O < at.points.length - 2; O++) {
2410
- const E = at.points[O], L = at.points[O + 1], R = Math.abs(E.y - L.y) < wt, Z = R ? "y" : "x", V = /* @__PURE__ */ new Set();
2409
+ for (let A = 1; A < at.points.length - 2; A++) {
2410
+ const E = at.points[A], L = at.points[A + 1], R = Math.abs(E.y - L.y) < wt, Z = R ? "y" : "x", V = /* @__PURE__ */ new Set();
2411
2411
  for (const G of ot)
2412
2412
  for (const [X, D] of Se(G.points))
2413
- Math.abs(X.y - D.y) < wt === R && Ti(E, L, X, D, s.edgeGap * 2) && (V.add(Ut(X[Z] + s.edgeGap)), V.add(Ut(X[Z] - s.edgeGap)));
2413
+ Math.abs(X.y - D.y) < wt === R && Fi(E, L, X, D, s.edgeGap * 2) && (V.add(Ut(X[Z] + s.edgeGap)), V.add(Ut(X[Z] - s.edgeGap)));
2414
2414
  for (const G of V) {
2415
- const X = qe(at.points);
2416
- X[O][Z] = G, X[O + 1][Z] = G;
2415
+ const X = Be(at.points);
2416
+ X[A][Z] = G, X[A + 1][Z] = G;
2417
2417
  const D = We(X);
2418
- if (!T(D, pt, at.fromSide, at.toSide, K) || be(D, ot).crossings > xt.crossings)
2418
+ if (!F(D, pt, at.fromSide, at.toSide, K) || be(D, ot).crossings > xt.crossings)
2419
2419
  continue;
2420
2420
  const ct = jn(D, ot, s, u);
2421
2421
  ct < Mt - 0.1 && (ft = D, Mt = ct);
@@ -2423,7 +2423,7 @@ function or(t, e = {}) {
2423
2423
  }
2424
2424
  ft !== at.points && (x[et] = {
2425
2425
  ...at,
2426
- points: F(ft, pt, at.fromSide, at.toSide, K, ot)
2426
+ points: T(ft, pt, at.fromSide, at.toSide, K, ot)
2427
2427
  }, Y = !0, J++);
2428
2428
  }
2429
2429
  if (!Y) break;
@@ -2436,82 +2436,82 @@ function or(t, e = {}) {
2436
2436
  ), ot = [...r.values()], K = (G) => {
2437
2437
  let X = 0;
2438
2438
  for (const [D, ct] of Se(G)) {
2439
- const B = Math.abs(D.y - ct.y) < wt;
2440
- if (!B && Math.abs(D.x - ct.x) >= wt) continue;
2441
- const rt = B ? D.y : D.x, lt = B ? Math.min(D.x, ct.x) : Math.min(D.y, ct.y), kt = B ? Math.max(D.x, ct.x) : Math.max(D.y, ct.y);
2439
+ const q = Math.abs(D.y - ct.y) < wt;
2440
+ if (!q && Math.abs(D.x - ct.x) >= wt) continue;
2441
+ const rt = q ? D.y : D.x, lt = q ? Math.min(D.x, ct.x) : Math.min(D.y, ct.y), kt = q ? Math.max(D.x, ct.x) : Math.max(D.y, ct.y);
2442
2442
  for (const vt of ot) {
2443
- const Ot = B ? vt.y : vt.x, Et = B ? vt.y + vt.h : vt.x + vt.w, Ft = Math.min(kt, B ? vt.x + vt.w : vt.y + vt.h) - Math.max(lt, B ? vt.x : vt.y), St = rt < Ot ? Ot - rt : rt > Et ? rt - Et : -1;
2444
- Ft > s.portGap && St > wt && St < s.clearance + 5 && X++;
2443
+ const At = q ? vt.y : vt.x, Et = q ? vt.y + vt.h : vt.x + vt.w, Tt = Math.min(kt, q ? vt.x + vt.w : vt.y + vt.h) - Math.max(lt, q ? vt.x : vt.y), St = rt < At ? At - rt : rt > Et ? rt - Et : -1;
2444
+ Tt > s.portGap && St > wt && St < s.clearance + 5 && X++;
2445
2445
  }
2446
2446
  }
2447
2447
  return X;
2448
2448
  }, ft = (G, X = {}, D = !1, ct = 0.5) => {
2449
- const B = x.map(
2450
- (Ot, Et) => G.has(Et) ? { ...Ot, ...X[Et], points: We(G.get(Et)) } : Ot
2449
+ const q = x.map(
2450
+ (At, Et) => G.has(Et) ? { ...At, ...X[Et], points: We(G.get(Et)) } : At
2451
2451
  );
2452
- for (const Ot of G.keys()) {
2453
- const Et = B[Ot], Ft = b.get(Et.id), St = Ft.cfg.waypoints || [];
2454
- if (N.has(Et.id) || St.length && !(D && St.every((Qt) => pt(Qt, Et.points))) || !T(Et.points, Ft, Et.fromSide, Et.toSide, et(Ft)) || at(Et.points) > at(x[Ot].points)) return !1;
2452
+ for (const At of G.keys()) {
2453
+ const Et = q[At], Tt = b.get(Et.id), St = Tt.cfg.waypoints || [];
2454
+ if (N.has(Et.id) || St.length && !(D && St.every((Qt) => pt(Qt, Et.points))) || !F(Et.points, Tt, Et.fromSide, Et.toSide, et(Tt)) || at(Et.points) > at(x[At].points)) return !1;
2455
2455
  }
2456
- const rt = z(x), lt = z(B);
2456
+ const rt = z(x), lt = z(q);
2457
2457
  if (lt.crossings > rt.crossings || lt.shared > rt.shared + 0.01 || lt.lanePairs > rt.lanePairs || lt.laneDeficit > rt.laneDeficit + 0.1)
2458
2458
  return !1;
2459
2459
  let kt = 0, vt = 0;
2460
- for (const Ot of G.keys())
2461
- kt += cn(x[Ot].points, u), vt += cn(B[Ot].points, u);
2460
+ for (const At of G.keys())
2461
+ kt += cn(x[At].points, u), vt += cn(q[At].points, u);
2462
2462
  if (vt > kt + ct) return !1;
2463
2463
  if (ct > 0.5) {
2464
- let Ot = 0, Et = 0;
2465
- for (const Ft of G.keys())
2466
- Ot += K(x[Ft].points), Et += K(B[Ft].points);
2467
- if (Et > Ot) return !1;
2464
+ let At = 0, Et = 0;
2465
+ for (const Tt of G.keys())
2466
+ At += K(x[Tt].points), Et += K(q[Tt].points);
2467
+ if (Et > At) return !1;
2468
2468
  }
2469
- return x = B, _++, !0;
2470
- }, Mt = (G) => !["pill", "circle", "diamond", "icon"].includes(G.shape), xt = ["from", "to"], O = (G, X, D = 0) => X === "from" ? G[D] : G[G.length - 1 - D], E = (G, X, D) => {
2469
+ return x = q, _++, !0;
2470
+ }, Mt = (G) => !["pill", "circle", "diamond", "icon"].includes(G.shape), xt = ["from", "to"], A = (G, X, D = 0) => X === "from" ? G[D] : G[G.length - 1 - D], E = (G, X, D) => {
2471
2471
  const ct = X === "left" || X === "right" ? "x" : "y";
2472
2472
  return Mt(G) || Math.abs(me(G, X, D)[ct] - me(G, X)[ct]) <= 2;
2473
2473
  }, L = () => {
2474
2474
  const G = /* @__PURE__ */ new Map();
2475
2475
  x.forEach((X, D) => {
2476
2476
  for (const ct of xt) {
2477
- const B = X[ct] + "|" + X[ct + "Side"];
2478
- G.has(B) || G.set(B, []), G.get(B).push({ i: D, end: ct });
2477
+ const q = X[ct] + "|" + X[ct + "Side"];
2478
+ G.has(q) || G.set(q, []), G.get(q).push({ i: D, end: ct });
2479
2479
  }
2480
2480
  });
2481
2481
  for (const [X, D] of G) {
2482
- const [ct, B] = X.split("|"), rt = r.get(ct), lt = B === "left" || B === "right", kt = lt ? "y" : "x", vt = ie(rt)[kt], Ot = (lt ? rt.h : rt.w) / 2 - 10, Et = [...new Set(D.map(({ i: Rt, end: Xt }) => Ut(O(x[Rt].points, Xt)[kt])))];
2482
+ const [ct, q] = X.split("|"), rt = r.get(ct), lt = q === "left" || q === "right", kt = lt ? "y" : "x", vt = ie(rt)[kt], At = (lt ? rt.h : rt.w) / 2 - 10, Et = [...new Set(D.map(({ i: Rt, end: Xt }) => Ut(A(x[Rt].points, Xt)[kt])))];
2483
2483
  if (Et.length < 2) continue;
2484
- const Ft = Ut(vt - Et.reduce((Rt, Xt) => Rt + Xt, 0) / Et.length);
2485
- if (Math.abs(Ft) < 2 || Et.some((Rt) => Math.abs(Rt + Ft - vt) > Ot + wt) || Et.some((Rt) => !E(rt, B, Rt + Ft - vt))) continue;
2484
+ const Tt = Ut(vt - Et.reduce((Rt, Xt) => Rt + Xt, 0) / Et.length);
2485
+ if (Math.abs(Tt) < 2 || Et.some((Rt) => Math.abs(Rt + Tt - vt) > At + wt) || Et.some((Rt) => !E(rt, q, Rt + Tt - vt))) continue;
2486
2486
  const St = /* @__PURE__ */ new Map(), Qt = {}, Dt = /* @__PURE__ */ new Set();
2487
2487
  for (const { i: Rt, end: Xt } of D) {
2488
- const te = qe(St.get(Rt) ?? x[Rt].points), Ht = Ut(O(te, Xt)[kt] + Ft - vt), oe = me(rt, B, Ht);
2489
- if (Object.assign(O(te, Xt), oe), Qt[Rt] = { ...Qt[Rt], [Xt + "Offset"]: Ht }, te.length === 2) {
2490
- const Bt = Xt === "from" ? "to" : "from", le = r.get(x[Rt][Bt]), fe = x[Rt][Bt + "Side"], de = Ut(O(te, Bt)[kt] + Ft - ie(le)[kt]);
2488
+ const te = Be(St.get(Rt) ?? x[Rt].points), Ht = Ut(A(te, Xt)[kt] + Tt - vt), oe = me(rt, q, Ht);
2489
+ if (Object.assign(A(te, Xt), oe), Qt[Rt] = { ...Qt[Rt], [Xt + "Offset"]: Ht }, te.length === 2) {
2490
+ const qt = Xt === "from" ? "to" : "from", le = r.get(x[Rt][qt]), fe = x[Rt][qt + "Side"], de = Ut(A(te, qt)[kt] + Tt - ie(le)[kt]);
2491
2491
  if (!E(le, fe, de)) {
2492
2492
  St.clear();
2493
2493
  break;
2494
2494
  }
2495
- Object.assign(O(te, Bt), me(le, fe, de)), Qt[Rt][Bt + "Offset"] = de, Dt.add(x[Rt][Bt] + "|" + fe);
2496
- } else O(te, Xt, 1)[kt] = oe[kt];
2495
+ Object.assign(A(te, qt), me(le, fe, de)), Qt[Rt][qt + "Offset"] = de, Dt.add(x[Rt][qt] + "|" + fe);
2496
+ } else A(te, Xt, 1)[kt] = oe[kt];
2497
2497
  St.set(Rt, te);
2498
2498
  }
2499
2499
  const ne = new Map(St);
2500
2500
  for (const Rt of Dt) {
2501
- const [Xt, te] = Rt.split("|"), Ht = r.get(Xt), oe = ie(Ht)[kt], Bt = (lt ? Ht.h : Ht.w) / 2 - 10, le = G.get(Rt) ?? [], fe = ({ i: I, end: U }) => O(St.get(I) ?? x[I].points, U)[kt], de = le.filter(({ i: I }) => !St.has(I) && x[I].points.length >= 4);
2501
+ const [Xt, te] = Rt.split("|"), Ht = r.get(Xt), oe = ie(Ht)[kt], qt = (lt ? Ht.h : Ht.w) / 2 - 10, le = G.get(Rt) ?? [], fe = ({ i: I, end: U }) => A(St.get(I) ?? x[I].points, U)[kt], de = le.filter(({ i: I }) => !St.has(I) && x[I].points.length >= 4);
2502
2502
  if (!de.length || !Mt(Ht)) continue;
2503
2503
  const he = le.reduce((I, U) => I + fe(U), 0), we = Ut((le.length * oe - he) / de.length);
2504
2504
  if (!(Math.abs(we) < 2))
2505
2505
  for (const I of de) {
2506
- const U = qe(x[I.i].points), nt = Ut(O(U, I.end)[kt] + we - oe);
2507
- Math.abs(nt) > Bt + wt || (Object.assign(O(U, I.end), me(Ht, te, nt)), O(U, I.end, 1)[kt] = O(U, I.end)[kt], Qt[I.i] = { ...Qt[I.i], [I.end + "Offset"]: nt }, St.set(I.i, U));
2506
+ const U = Be(x[I.i].points), nt = Ut(A(U, I.end)[kt] + we - oe);
2507
+ Math.abs(nt) > qt + wt || (Object.assign(A(U, I.end), me(Ht, te, nt)), A(U, I.end, 1)[kt] = A(U, I.end)[kt], Qt[I.i] = { ...Qt[I.i], [I.end + "Offset"]: nt }, St.set(I.i, U));
2508
2508
  }
2509
2509
  }
2510
2510
  if (!St.size) continue;
2511
- const Gt = lt ? "x" : "y", Yt = { left: rt.x, right: rt.x + rt.w, top: rt.y, bottom: rt.y + rt.h }[B], Kt = B === "left" || B === "top" ? -1 : 1, ae = (Rt) => new Map(
2511
+ const Gt = lt ? "x" : "y", Yt = { left: rt.x, right: rt.x + rt.w, top: rt.y, bottom: rt.y + rt.h }[q], Kt = q === "left" || q === "top" ? -1 : 1, ae = (Rt) => new Map(
2512
2512
  [...Rt].map(([Xt, te]) => {
2513
- const Ht = D.find((Bt) => Bt.i === Xt)?.end, oe = qe(te);
2514
- return Ht && oe.length >= 4 && Math.abs(O(oe, Ht, 1)[Gt] - O(oe, Ht, 2)[Gt]) < wt && Math.abs(O(oe, Ht, 1)[Gt] - Yt) < s.standoff && (O(oe, Ht, 1)[Gt] = Yt + Kt * s.standoff, O(oe, Ht, 2)[Gt] = Yt + Kt * s.standoff), [Xt, oe];
2513
+ const Ht = D.find((qt) => qt.i === Xt)?.end, oe = Be(te);
2514
+ return Ht && oe.length >= 4 && Math.abs(A(oe, Ht, 1)[Gt] - A(oe, Ht, 2)[Gt]) < wt && Math.abs(A(oe, Ht, 1)[Gt] - Yt) < s.standoff && (A(oe, Ht, 1)[Gt] = Yt + Kt * s.standoff, A(oe, Ht, 2)[Gt] = Yt + Kt * s.standoff), [Xt, oe];
2515
2515
  })
2516
2516
  );
2517
2517
  for (const Rt of St.size > ne.size ? [St, ne] : [ne])
@@ -2530,82 +2530,82 @@ function or(t, e = {}) {
2530
2530
  });
2531
2531
  for (const [G, X] of R) {
2532
2532
  if (X.length < 2) continue;
2533
- const [, D, ct] = G.split("|"), B = ct === "left" || ct === "right" ? "x" : "y", rt = (vt) => Ut(O(x[vt].points, D, 1)[B]), lt = [...new Set(X.map(rt))];
2533
+ const [, D, ct] = G.split("|"), q = ct === "left" || ct === "right" ? "x" : "y", rt = (vt) => Ut(A(x[vt].points, D, 1)[q]), lt = [...new Set(X.map(rt))];
2534
2534
  if (lt.length < 2) continue;
2535
- const kt = (vt) => X.reduce((Ot, Et) => Ot + Math.abs(rt(Et) - vt), 0);
2536
- lt.sort((vt, Ot) => kt(vt) - kt(Ot) || vt - Ot);
2535
+ const kt = (vt) => X.reduce((At, Et) => At + Math.abs(rt(Et) - vt), 0);
2536
+ lt.sort((vt, At) => kt(vt) - kt(At) || vt - At);
2537
2537
  for (const vt of lt) {
2538
- const Ot = /* @__PURE__ */ new Map();
2538
+ const At = /* @__PURE__ */ new Map();
2539
2539
  for (const Et of X) {
2540
2540
  if (rt(Et) === vt) continue;
2541
- const Ft = qe(x[Et].points);
2542
- O(Ft, D, 1)[B] = vt, O(Ft, D, 2)[B] = vt, Ot.set(Et, Ft);
2541
+ const Tt = Be(x[Et].points);
2542
+ A(Tt, D, 1)[q] = vt, A(Tt, D, 2)[q] = vt, At.set(Et, Tt);
2543
2543
  }
2544
- if (ft(Ot)) break;
2544
+ if (ft(At)) break;
2545
2545
  }
2546
2546
  }
2547
2547
  if (e.jogs !== !1)
2548
2548
  for (let G = 0; G < x.length; G++) {
2549
- const X = Math.max(s.portGap, s.edgeGap), D = (B, rt, lt, kt) => {
2550
- const vt = qe(B), Ot = {};
2549
+ const X = Math.max(s.portGap, s.edgeGap), D = (q, rt, lt, kt) => {
2550
+ const vt = Be(q), At = {};
2551
2551
  vt[rt][lt] = kt, vt[rt + 1][lt] = kt;
2552
- for (const [Et, Ft] of [
2552
+ for (const [Et, Tt] of [
2553
2553
  [rt, "from"],
2554
2554
  [rt + 1, "to"]
2555
2555
  ]) {
2556
- if (Et !== (Ft === "from" ? 0 : B.length - 1)) continue;
2557
- const St = x[G][Ft], Qt = x[G][Ft + "Side"], Dt = r.get(St);
2556
+ if (Et !== (Tt === "from" ? 0 : q.length - 1)) continue;
2557
+ const St = x[G][Tt], Qt = x[G][Tt + "Side"], Dt = r.get(St);
2558
2558
  if (!Dt || !Mt(Dt) || (Qt === "left" || Qt === "right") != (lt === "y"))
2559
2559
  return null;
2560
2560
  const ne = Ut(kt - ie(Dt)[lt]);
2561
2561
  if (Math.abs(ne) > (lt === "y" ? Dt.h : Dt.w) / 2 - 10 + wt || x.some(
2562
2562
  (Yt, Kt) => xt.some(
2563
- (ae) => (Kt !== G || ae !== Ft) && Yt[ae] === St && Yt[ae + "Side"] === Qt && Math.abs(O(Yt.points, ae)[lt] - kt) < X - 0.01
2563
+ (ae) => (Kt !== G || ae !== Tt) && Yt[ae] === St && Yt[ae + "Side"] === Qt && Math.abs(A(Yt.points, ae)[lt] - kt) < X - 0.01
2564
2564
  )
2565
2565
  )) return null;
2566
- Object.assign(vt[Et], me(Dt, Qt, ne)), Ot[Ft + "Offset"] = ne;
2566
+ Object.assign(vt[Et], me(Dt, Qt, ne)), At[Tt + "Offset"] = ne;
2567
2567
  }
2568
- return { next: vt, extra: Ot };
2568
+ return { next: vt, extra: At };
2569
2569
  }, ct = x[G].points;
2570
- for (let B = 1; B < ct.length - 2; B++) {
2571
- if (re(ct[B], ct[B + 1]) >= 12) continue;
2572
- const rt = Math.abs(ct[B].x - ct[B + 1].x) < wt ? "y" : "x";
2570
+ for (let q = 1; q < ct.length - 2; q++) {
2571
+ if (re(ct[q], ct[q + 1]) >= 12) continue;
2572
+ const rt = Math.abs(ct[q].x - ct[q + 1].x) < wt ? "y" : "x";
2573
2573
  if ([
2574
- D(ct, B - 1, rt, ct[B + 1][rt]),
2575
- D(ct, B + 1, rt, ct[B][rt])
2574
+ D(ct, q - 1, rt, ct[q + 1][rt]),
2575
+ D(ct, q + 1, rt, ct[q][rt])
2576
2576
  ].some((kt) => kt && ft(/* @__PURE__ */ new Map([[G, kt.next]]), { [G]: kt.extra }, !0)))
2577
2577
  break;
2578
2578
  }
2579
2579
  }
2580
2580
  L();
2581
2581
  const Z = (G, X, D, ct) => {
2582
- let B = -1 / 0, rt = 1 / 0;
2582
+ let q = -1 / 0, rt = 1 / 0;
2583
2583
  for (const lt of u)
2584
2584
  if (!(Math.min(ct, G ? lt.x + lt.w : lt.y + lt.h) - Math.max(D, G ? lt.x : lt.y) <= 1))
2585
2585
  for (const vt of G ? [lt.y, lt.y + lt.h] : [lt.x, lt.x + lt.w])
2586
- !lt.border && vt === (G ? lt.y + lt.h : lt.x + lt.w) && X < vt - wt || !lt.border && vt === (G ? lt.y : lt.x) && X > vt + wt || (vt <= X + wt && (B = Math.max(B, vt)), vt >= X - wt && (rt = Math.min(rt, vt)));
2587
- return [B, rt];
2586
+ !lt.border && vt === (G ? lt.y + lt.h : lt.x + lt.w) && X < vt - wt || !lt.border && vt === (G ? lt.y : lt.x) && X > vt + wt || (vt <= X + wt && (q = Math.max(q, vt)), vt >= X - wt && (rt = Math.min(rt, vt)));
2587
+ return [q, rt];
2588
2588
  };
2589
2589
  for (let G = 0; G < x.length; G++)
2590
2590
  for (let X = 1; X < x[G].points.length - 2; X++) {
2591
- const D = x[G].points, ct = D[X], B = D[X + 1], rt = Math.abs(ct.y - B.y) < wt, lt = rt ? "y" : "x", kt = rt ? "x" : "y";
2592
- if (re(ct, B) <= 12) continue;
2593
- const [vt, Ot] = Z(
2591
+ const D = x[G].points, ct = D[X], q = D[X + 1], rt = Math.abs(ct.y - q.y) < wt, lt = rt ? "y" : "x", kt = rt ? "x" : "y";
2592
+ if (re(ct, q) <= 12) continue;
2593
+ const [vt, At] = Z(
2594
2594
  rt,
2595
2595
  ct[lt],
2596
- Math.min(ct[kt], B[kt]),
2597
- Math.max(ct[kt], B[kt])
2598
- ), Et = Ot - vt, Ft = Ut((vt + Ot) / 2);
2599
- if (!(Et <= 4 * s.standoff) || Math.abs(Ft - ct[lt]) < 1) continue;
2600
- const St = qe(D);
2601
- St[X][lt] = Ft, St[X + 1][lt] = Ft, ft(/* @__PURE__ */ new Map([[G, St]]), {}, !1, po);
2596
+ Math.min(ct[kt], q[kt]),
2597
+ Math.max(ct[kt], q[kt])
2598
+ ), Et = At - vt, Tt = Ut((vt + At) / 2);
2599
+ if (!(Et <= 4 * s.standoff) || Math.abs(Tt - ct[lt]) < 1) continue;
2600
+ const St = Be(D);
2601
+ St[X][lt] = Tt, St[X + 1][lt] = Tt, ft(/* @__PURE__ */ new Map([[G, St]]), {}, !1, po);
2602
2602
  }
2603
2603
  const V = s.edgeGap;
2604
2604
  for (const G of [!0, !1]) {
2605
2605
  const X = G ? "y" : "x", D = G ? "x" : "y", ct = [];
2606
2606
  x.forEach(
2607
- (B, rt) => Se(B.points).forEach(([lt, kt], vt) => {
2608
- vt === 0 || vt === B.points.length - 2 || re(lt, kt) <= 12 || Math.abs(lt.y - kt.y) < wt === G && ct.push({
2607
+ (q, rt) => Se(q.points).forEach(([lt, kt], vt) => {
2608
+ vt === 0 || vt === q.points.length - 2 || re(lt, kt) <= 12 || Math.abs(lt.y - kt.y) < wt === G && ct.push({
2609
2609
  i: rt,
2610
2610
  k: vt,
2611
2611
  at: Ut(lt[X]),
@@ -2613,16 +2613,16 @@ function or(t, e = {}) {
2613
2613
  hi: Math.max(lt[D], kt[D])
2614
2614
  });
2615
2615
  })
2616
- ), ct.sort((B, rt) => B.at - rt.at);
2617
- for (let B = 1; B < ct.length; B++) {
2618
- const rt = ct[B], lt = ct.slice(0, B).filter(
2616
+ ), ct.sort((q, rt) => q.at - rt.at);
2617
+ for (let q = 1; q < ct.length; q++) {
2618
+ const rt = ct[q], lt = ct.slice(0, q).filter(
2619
2619
  (Et) => Et.i !== rt.i && Et.at < rt.at && Math.min(Et.hi, rt.hi) - Math.max(Et.lo, rt.lo) > 1
2620
2620
  ).at(-1);
2621
2621
  if (!lt) continue;
2622
2622
  const kt = rt.at - lt.at;
2623
2623
  if (Math.abs(kt - V) <= 1 || kt > 2.5 * V) continue;
2624
- const vt = Ut(lt.at + V), Ot = qe(x[rt.i].points);
2625
- Math.abs(Ot[rt.k][X] - rt.at) > wt || Math.abs(Ot[rt.k + 1][X] - rt.at) > wt || (Ot[rt.k][X] = vt, Ot[rt.k + 1][X] = vt, ft(/* @__PURE__ */ new Map([[rt.i, Ot]])) && (rt.at = vt));
2624
+ const vt = Ut(lt.at + V), At = Be(x[rt.i].points);
2625
+ Math.abs(At[rt.k][X] - rt.at) > wt || Math.abs(At[rt.k + 1][X] - rt.at) > wt || (At[rt.k][X] = vt, At[rt.k + 1][X] = vt, ft(/* @__PURE__ */ new Map([[rt.i, At]])) && (rt.at = vt));
2626
2626
  }
2627
2627
  }
2628
2628
  }
@@ -2860,7 +2860,7 @@ function Ca(t, e, o = 0.75) {
2860
2860
  const a = (t - n) / Math.max(1e-5, e - n);
2861
2861
  return 1 - a * a * (3 - 2 * a);
2862
2862
  }
2863
- function qa(t, e) {
2863
+ function Ba(t, e) {
2864
2864
  return Math.hypot(
2865
2865
  Math.max(e.x - t.x, 0, t.x - e.x - e.w),
2866
2866
  Math.max(e.y - t.y, 0, t.y - e.y - e.h)
@@ -2882,11 +2882,11 @@ function ts(t) {
2882
2882
  )
2883
2883
  };
2884
2884
  }
2885
- function Ba(t, e, o, n = 0.75, a = []) {
2885
+ function qa(t, e, o, n = 0.75, a = []) {
2886
2886
  const s = ts(t), r = new Set(a), d = {}, c = [];
2887
2887
  for (const u of t.graph.nodes) {
2888
2888
  if (!s.visible(u.id)) continue;
2889
- const i = Ca(qa(e, t.layout.nodes[u.id]), o, n);
2889
+ const i = Ca(Ba(e, t.layout.nodes[u.id]), o, n);
2890
2890
  if (!(i <= 1e-4)) {
2891
2891
  if (s.locked(u.id) || r.has(u.id) || s.parents(u.id).some((f) => r.has(f))) {
2892
2892
  c.push(u.id);
@@ -2897,23 +2897,23 @@ function Ba(t, e, o, n = 0.75, a = []) {
2897
2897
  }
2898
2898
  return { weights: d, locked: c };
2899
2899
  }
2900
- function Oo(t, e) {
2900
+ function Ao(t, e) {
2901
2901
  const o = Math.min(t.x + t.w, e.x + e.w) - Math.max(t.x, e.x), n = Math.min(t.y + t.h, e.y + e.h) - Math.max(t.y, e.y);
2902
2902
  return o > 5e-3 && n > 5e-3 ? o * n : 0;
2903
2903
  }
2904
- function Ao(t, e) {
2904
+ function Oo(t, e) {
2905
2905
  const o = ts(t), n = [...t.graph.nodes, ...t.graph.groups].filter((s) => o.visible(s.id)), a = /* @__PURE__ */ new Map();
2906
2906
  for (let s = 0; s < n.length; s++)
2907
2907
  for (let r = s + 1; r < n.length; r++) {
2908
2908
  const d = n[s], c = n[r];
2909
2909
  if (o.parents(d.id).includes(c.id) || o.parents(c.id).includes(d.id)) continue;
2910
- const u = Oo(e[d.id], e[c.id]);
2910
+ const u = Ao(e[d.id], e[c.id]);
2911
2911
  u && a.set(d.id + "\0" + c.id, u);
2912
2912
  }
2913
2913
  return a;
2914
2914
  }
2915
2915
  function fr(t, e, o) {
2916
- const n = Ao(t, e), a = Ao(t, o);
2916
+ const n = Oo(t, e), a = Oo(t, o);
2917
2917
  for (const [s, r] of a) if (r > (n.get(s) || 0) + 0.01) return !1;
2918
2918
  return !0;
2919
2919
  }
@@ -2924,7 +2924,7 @@ function dr(t, e, o, n) {
2924
2924
  return { x: fn(n.x, c, u), y: fn(n.y, i, f) };
2925
2925
  }
2926
2926
  function hr(t, e = {}) {
2927
- const o = Ra(e), n = De(t), a = n.layout.nodes, s = De(a), r = e.point || { x: 0, y: 0 }, d = e.worldRadius ?? o.radius, c = Ba(
2927
+ const o = Ra(e), n = De(t), a = n.layout.nodes, s = De(a), r = e.point || { x: 0, y: 0 }, d = e.worldRadius ?? o.radius, c = qa(
2928
2928
  t,
2929
2929
  r,
2930
2930
  d,
@@ -3004,25 +3004,25 @@ function hr(t, e = {}) {
3004
3004
  const ht = dr(t, a, S, { x: s[S].x + x, y: s[S].y + N });
3005
3005
  a[S].x = ht.x, a[S].y = ht.y;
3006
3006
  }
3007
- const y = new Set(Object.keys(u)), P = [...n.graph.nodes, ...n.graph.groups].filter((S) => i.visible(S.id)), A = new Map(P.map((S) => [S.id, new Set(i.parents(S.id))])), w = [];
3007
+ const y = new Set(Object.keys(u)), P = [...n.graph.nodes, ...n.graph.groups].filter((S) => i.visible(S.id)), O = new Map(P.map((S) => [S.id, new Set(i.parents(S.id))])), w = [];
3008
3008
  for (let S = 0; S < P.length; S++)
3009
3009
  for (let M = S + 1; M < P.length; M++) {
3010
3010
  const x = P[S].id, N = P[M].id;
3011
- !y.has(x) && !y.has(N) || A.get(x).has(N) || A.get(N).has(x) || w.push([x, N, Oo(s[x], s[N])]);
3011
+ !y.has(x) && !y.has(N) || O.get(x).has(N) || O.get(N).has(x) || w.push([x, N, Ao(s[x], s[N])]);
3012
3012
  }
3013
- const k = () => w.every(([S, M, x]) => Oo(a[S], a[M]) <= x + 0.01);
3014
- let T = !1, F = 1;
3013
+ const k = () => w.every(([S, M, x]) => Ao(a[S], a[M]) <= x + 0.01);
3014
+ let F = !1, T = 1;
3015
3015
  const j = De(a);
3016
3016
  for (let S = 0; S < 12; S++) {
3017
3017
  for (const M of Object.keys(u))
3018
- a[M].x = s[M].x + (j[M].x - s[M].x) * F, a[M].y = s[M].y + (j[M].y - s[M].y) * F;
3018
+ a[M].x = s[M].x + (j[M].x - s[M].x) * T, a[M].y = s[M].y + (j[M].y - s[M].y) * T;
3019
3019
  if (k()) {
3020
- T = !0;
3020
+ F = !0;
3021
3021
  break;
3022
3022
  }
3023
- F *= 0.5;
3023
+ T *= 0.5;
3024
3024
  }
3025
- T || (n.layout.nodes = De(s));
3025
+ F || (n.layout.nodes = De(s));
3026
3026
  const $ = Object.keys(u).filter((S) => Io(s[S], n.layout.nodes[S]) > 1e-3), v = Math.max(0, ...$.map((S) => Io(s[S], n.layout.nodes[S])));
3027
3027
  return {
3028
3028
  document: n,
@@ -3030,8 +3030,8 @@ function hr(t, e = {}) {
3030
3030
  locked: c.locked,
3031
3031
  moved: $,
3032
3032
  maxDisplacement: v,
3033
- blocked: !T || F < 0.02,
3034
- attenuation: F,
3033
+ blocked: !F || T < 0.02,
3034
+ attenuation: T,
3035
3035
  mode: o.mode
3036
3036
  };
3037
3037
  }
@@ -3115,13 +3115,13 @@ const gr = {
3115
3115
  defaults: lr,
3116
3116
  settings: Ra,
3117
3117
  weight: Ca,
3118
- rectDistance: qa,
3119
- field: Ba,
3118
+ rectDistance: Ba,
3119
+ field: qa,
3120
3120
  dab: hr,
3121
3121
  journey: ur,
3122
3122
  lookahead: pr,
3123
3123
  summarizeFrames: Ha,
3124
- violationPairs: Ao,
3124
+ violationPairs: Oo,
3125
3125
  noWorse: fr
3126
3126
  }, mr = gr;
3127
3127
  var yr = {
@@ -3257,7 +3257,7 @@ function Er(t, e, o) {
3257
3257
  for (; n && ce(n + "…", o) > e; ) n = n.slice(0, -1);
3258
3258
  return n.trimEnd() + "…";
3259
3259
  }
3260
- const Ps = ["drafting", "fieldnotes", "signal", "ink", "blueprint"], Zn = "drafting", $o = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950], Qe = 500, Ir = (t) => en[t]?.dark ? 950 : 50, Or = (t) => en[t]?.dark ? 900 : 100, Go = [
3260
+ const Ps = ["drafting", "fieldnotes", "signal", "ink", "blueprint"], Zn = "drafting", $o = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950], Qe = 500, Ir = (t) => en[t]?.dark ? 950 : 50, Ar = (t) => en[t]?.dark ? 900 : 100, Go = [
3261
3261
  "primary",
3262
3262
  "secondary",
3263
3263
  "slate",
@@ -3272,15 +3272,15 @@ const Ps = ["drafting", "fieldnotes", "signal", "ink", "blueprint"], Zn = "draft
3272
3272
  "red",
3273
3273
  "rose",
3274
3274
  "violet"
3275
- ], to = (t) => Go.includes(t), Ts = ["dashed", "solid"], es = () => ({
3275
+ ], to = (t) => Go.includes(t), Fs = ["dashed", "solid"], es = () => ({
3276
3276
  theme: Zn,
3277
3277
  overrides: {},
3278
3278
  colors: []
3279
- }), Fs = {
3279
+ }), Ts = {
3280
3280
  paddingX: { min: 4, max: 48 },
3281
3281
  paddingY: { min: 4, max: 48 },
3282
3282
  radius: { min: 0, max: 24 }
3283
- }, Ar = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i, en = {
3283
+ }, Or = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i, en = {
3284
3284
  drafting: {
3285
3285
  label: "Drafting",
3286
3286
  description: "Navy ink on cool paper, with drafting blue and marker gold",
@@ -3385,6 +3385,32 @@ const Ps = ["drafting", "fieldnotes", "signal", "ink", "blueprint"], Zn = "draft
3385
3385
  primary: ["#2B3A55", 900],
3386
3386
  secondary: ["#C23B22", 600]
3387
3387
  },
3388
+ // The default theme on a dark page: the same type, spacing and families as drafting, so it
3389
+ // draws every box in the same place. Graphite surfaces, lighter than the canvas the higher
3390
+ // they sit, with drafting blue and marker gold lifted to read on them. Not a file's theme.
3391
+ "drafting-dark": {
3392
+ label: "Drafting dark",
3393
+ description: "Drafting on a graphite page, for a dark host",
3394
+ dark: !0,
3395
+ canvas: "#16191E",
3396
+ text: "#E7EAEF",
3397
+ muted: "#9BA3B0",
3398
+ connection: "#AEB6C2",
3399
+ node: { fill: "#21252C", stroke: "#3D4450", ink: "#E7EAEF" },
3400
+ group: { fill: "#1B1F25", stroke: "#30363F", ink: "#C8CED8" },
3401
+ paddingX: 12,
3402
+ paddingY: 20,
3403
+ radius: 4,
3404
+ shadow: !1,
3405
+ titleFont: "sans",
3406
+ annotationFont: "sans",
3407
+ titleSize: 13,
3408
+ titleLine: 16,
3409
+ annotationSize: 11,
3410
+ chroma: 0.9,
3411
+ primary: ["#7FA4E6", 300],
3412
+ secondary: ["#F0B43C", 400]
3413
+ },
3388
3414
  blueprint: {
3389
3415
  label: "Blueprint",
3390
3416
  description: "White lines on blueprint blue, cyan and yellow, monospace titles",
@@ -3453,7 +3479,7 @@ const js = {
3453
3479
  800: 0.38,
3454
3480
  900: 0.32,
3455
3481
  950: 0.26
3456
- }, os = (t) => t <= 300, Ka = (t) => t >= 45 && t <= 110, To = { 400: 0.8, 500: 0.74 }, $r = (t, e) => To[t] === void 0 ? void 0 : To[t] - (e < 65 ? 0.07 : 0), Gr = (t, e) => os(t) || Ka(e) && t in To, Ge = {
3482
+ }, os = (t) => t <= 300, Ka = (t) => t >= 45 && t <= 110, Fo = { 400: 0.8, 500: 0.74 }, $r = (t, e) => Fo[t] === void 0 ? void 0 : Fo[t] - (e < 65 ? 0.07 : 0), Gr = (t, e) => os(t) || Ka(e) && t in Fo, Ge = {
3457
3483
  /** Dark title text on a pale fill. */
3458
3484
  paleInk: 7,
3459
3485
  /** White title text on a dark fill. */
@@ -3477,7 +3503,7 @@ const js = {
3477
3503
  red: [32, 0.17],
3478
3504
  rose: [358, 0.12],
3479
3505
  violet: [305, 0.13]
3480
- }, Tr = (t) => In([0.24, 0.035, t]), Fr = "#FFFFFF";
3506
+ }, Fr = (t) => In([0.24, 0.035, t]), Tr = "#FFFFFF";
3481
3507
  function Ue(t, e, o) {
3482
3508
  if (eo(t, e) >= o) return t;
3483
3509
  const [n, a, s] = ns(t), r = Po(e) > 0.18 ? -0.01 : 0.01;
@@ -3487,7 +3513,7 @@ function Ue(t, e, o) {
3487
3513
  return d;
3488
3514
  }
3489
3515
  function Ds(t, e, o, n, a, s, r) {
3490
- const d = Gr(t, n), c = d ? Tr(n) : Fr, u = os(t) ? Ge.paleInk : Ge.darkInk;
3516
+ const d = Gr(t, n), c = d ? Fr(n) : Tr, u = os(t) ? Ge.paleInk : Ge.darkInk;
3491
3517
  let i = r ? ns(r)[0] : e, f = r ?? In([i, o * Xn(i), n]);
3492
3518
  for (; eo(f, c) < u && i > 0.05 && i < 0.995; )
3493
3519
  i += d ? 5e-3 : -0.01, f = In([i, o * Xn(i), n]);
@@ -3591,7 +3617,7 @@ function Re(t) {
3591
3617
  };
3592
3618
  return Nn.size > 50 && Nn.clear(), Nn.set(o, h), h;
3593
3619
  }
3594
- const Ye = (t) => Math.round(t * 10) / 10, nn = (t, e) => Math.abs(t.x - e.x) + Math.abs(t.y - e.y), Fo = (t, e, o = 0) => t.x >= e.x - o && t.x <= e.x + e.w + o && t.y >= e.y - o && t.y <= e.y + e.h + o, Nr = (t, e) => Fo({ x: e.x, y: e.y }, t) && Fo({ x: e.x + e.w, y: e.y + e.h }, t), Xe = (t, e, o = 0) => t.x < e.x + e.w + o && t.x + t.w + o > e.x && t.y < e.y + e.h + o && t.y + t.h + o > e.y;
3620
+ const Ye = (t) => Math.round(t * 10) / 10, nn = (t, e) => Math.abs(t.x - e.x) + Math.abs(t.y - e.y), To = (t, e, o = 0) => t.x >= e.x - o && t.x <= e.x + e.w + o && t.y >= e.y - o && t.y <= e.y + e.h + o, Nr = (t, e) => To({ x: e.x, y: e.y }, t) && To({ x: e.x + e.w, y: e.y + e.h }, t), Xe = (t, e, o = 0) => t.x < e.x + e.w + o && t.x + t.w + o > e.x && t.y < e.y + e.h + o && t.y + t.h + o > e.y;
3595
3621
  function Cs(t, e = 0) {
3596
3622
  if (!t.length) return { x: 70, y: 160, w: 240, h: 160 };
3597
3623
  let o = 1 / 0, n = 1 / 0, a = -1 / 0, s = -1 / 0;
@@ -3613,15 +3639,15 @@ function Rr(t, e) {
3613
3639
  }
3614
3640
  return o;
3615
3641
  }
3616
- const Mn = (t) => JSON.parse(JSON.stringify(t)), ye = 24, Cr = 48, no = 97, On = 10, oo = 18, Va = (t, e = Cr) => ({
3642
+ const Mn = (t) => JSON.parse(JSON.stringify(t)), ye = 24, Cr = 48, no = 97, An = 10, oo = 18, Va = (t, e = Cr) => ({
3617
3643
  x: t.x + ye,
3618
3644
  y: t.y + e
3619
- }), qr = 48, Br = { shape: "box", color: "auto", icon: "" };
3645
+ }), Br = 48, qr = { shape: "box", color: "auto", icon: "" };
3620
3646
  function Qa(t) {
3621
3647
  return t === "circle" || t === "icon" ? { w: 80, h: 80 } : t === "diamond" ? { w: 112, h: 112 } : t === "text" ? { w: 164, h: 38 } : { w: 164, h: 56 };
3622
3648
  }
3623
3649
  const ss = (t, e) => e ? t.graph.nodes.find((o) => o.id === e) : void 0, Za = (t, e) => e ? t.graph.groups.find((o) => o.id === e) : void 0, go = (t, e) => e ? t.graph.edges.find((o) => o.id === e) : void 0, Hr = (t, e) => ss(t, e) ?? Za(t, e), zr = (t, e) => ({
3624
- ...Br,
3650
+ ...qr,
3625
3651
  ...t.styles[e]
3626
3652
  }), Wr = (t, e) => e ? t.layout.containers[e]?.cellsBand : void 0, Ur = (t, e) => Wr(t, ss(t, e)?.parentId) !== void 0;
3627
3653
  function gn(t, e) {
@@ -3676,7 +3702,7 @@ function ec(t, e, o) {
3676
3702
  return s;
3677
3703
  }
3678
3704
  }
3679
- const qs = 3, Kn = (t, e = 1) => t.groupHeader + (e - 1) * t.groupTitle.lineHeight;
3705
+ const Bs = 3, Kn = (t, e = 1) => t.groupHeader + (e - 1) * t.groupTitle.lineHeight;
3680
3706
  function nc(t, e, o, n = 1) {
3681
3707
  const a = Math.max(40, e - no), s = tn(t, a, o.groupTitle, !0);
3682
3708
  if (s.length <= n) return s;
@@ -3684,16 +3710,16 @@ function nc(t, e, o, n = 1) {
3684
3710
  return r[n - 1] = Er(s.slice(n - 1).join(" "), a, o.groupTitle), r;
3685
3711
  }
3686
3712
  const oc = 168, ti = (t, e = !1) => e ? { ...t.annotation, size: t.annotation.size + 1.5, lineHeight: t.annotation.lineHeight + 2 } : t.annotation, sc = 140, ei = (t, e, o = !1) => tn(t, o ? oc : sc, ti(e, o)), ve = { out: 36, down: 22, label: 4 };
3687
- function Te(t, e = Re(), o = !1) {
3713
+ function Fe(t, e = Re(), o = !1) {
3688
3714
  const n = ti(e, o), a = ei(t, e, o), s = Math.max(...a.map((r) => ce(r, n))) + 16;
3689
3715
  return {
3690
3716
  w: Math.round(Math.max(36, s)),
3691
3717
  h: Math.round(a.length * n.lineHeight + 6)
3692
3718
  };
3693
3719
  }
3694
- function Bs(t, e) {
3720
+ function qs(t, e) {
3695
3721
  if (!t) return { right: ve.out, above: 0, below: ve.down };
3696
- const { w: o, h: n } = Te(t, e, !0);
3722
+ const { w: o, h: n } = Fe(t, e, !0);
3697
3723
  return {
3698
3724
  right: ve.out + ve.label + o,
3699
3725
  above: Math.max(0, n / 2 - ve.down / 2),
@@ -3725,12 +3751,12 @@ function cc(t, e, o, n = 0) {
3725
3751
  }
3726
3752
  const i = Array(r).fill(0), f = Array(a.length ? c + 1 : 0).fill(0);
3727
3753
  for (const w of a) {
3728
- const { row: k, col: T, span: F } = d.get(w.id);
3729
- F === 1 && (i[T] = Math.max(i[T], s.get(w.id).w)), f[k] = Math.max(f[k], s.get(w.id).h);
3754
+ const { row: k, col: F, span: T } = d.get(w.id);
3755
+ T === 1 && (i[F] = Math.max(i[F], s.get(w.id).w)), f[k] = Math.max(f[k], s.get(w.id).h);
3730
3756
  }
3731
3757
  for (const w of a) {
3732
- const { col: k, span: T } = d.get(w.id), F = s.get(w.id).w - i.slice(k, k + T).reduce((j, $) => j + $, 0);
3733
- F > 0 && (i[k + T - 1] += F);
3758
+ const { col: k, span: F } = d.get(w.id), T = s.get(w.id).w - i.slice(k, k + F).reduce((j, $) => j + $, 0);
3759
+ T > 0 && (i[k + F - 1] += T);
3734
3760
  }
3735
3761
  const h = n - i.reduce((w, k) => w + k, 0);
3736
3762
  h > 0 && (i[r - 1] += h);
@@ -3739,16 +3765,16 @@ function cc(t, e, o, n = 0) {
3739
3765
  for (const w of f) p.push(p.at(-1) + w);
3740
3766
  const m = l.at(-1), g = p.at(-1), y = /* @__PURE__ */ new Map();
3741
3767
  for (const w of a) {
3742
- const { row: k, col: T, span: F } = d.get(w.id);
3743
- y.set(w.id, { x: l[T], y: p[k], w: l[T + F] - l[T], h: f[k] });
3768
+ const { row: k, col: F, span: T } = d.get(w.id);
3769
+ y.set(w.id, { x: l[F], y: p[k], w: l[F + T] - l[F], h: f[k] });
3744
3770
  }
3745
- const P = ao(o.groupTitle.lineHeight), A = r > 1 || e.direction === "right";
3771
+ const P = ao(o.groupTitle.lineHeight), O = r > 1 || e.direction === "right";
3746
3772
  return t.forEach((w, k) => {
3747
3773
  if (!w.marker) return;
3748
- const T = t.slice(k + 1).find(($) => !$.marker), F = T ? y.get(T.id) : void 0, j = yo / 2;
3774
+ const F = t.slice(k + 1).find(($) => !$.marker), T = F ? y.get(F.id) : void 0, j = yo / 2;
3749
3775
  y.set(
3750
3776
  w.id,
3751
- A ? { x: (F?.x ?? m) - j, y: -P, w: yo, h: g + P + Hs } : { x: 0, y: (F?.y ?? g) - j, w: m + Hs, h: yo }
3777
+ O ? { x: (T?.x ?? m) - j, y: -P, w: yo, h: g + P + Hs } : { x: 0, y: (T?.y ?? g) - j, w: m + Hs, h: yo }
3752
3778
  );
3753
3779
  }), { boxes: y, w: m, h: g };
3754
3780
  }
@@ -3762,8 +3788,8 @@ function dc(t, e, o) {
3762
3788
  y.push({ row: d, col: c, span: n - c }), d++, c = 0;
3763
3789
  else
3764
3790
  for (let P = g.span ?? 1; P > 0; ) {
3765
- const A = Math.min(P, n - c);
3766
- y.push({ row: d, col: c, span: A }), P -= A, c += A, c === n && (d++, c = 0);
3791
+ const O = Math.min(P, n - c);
3792
+ y.push({ row: d, col: c, span: O }), P -= O, c += O, c === n && (d++, c = 0);
3767
3793
  }
3768
3794
  r.set(g.id, y);
3769
3795
  }
@@ -3780,7 +3806,7 @@ function dc(t, e, o) {
3780
3806
  h: f
3781
3807
  }), l = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
3782
3808
  for (const g of t) {
3783
- const y = i(g.id), P = r.get(g.id).filter((A) => A !== y);
3809
+ const y = i(g.id), P = r.get(g.id).filter((O) => O !== y);
3784
3810
  l.set(g.id, h(y)), P.length && p.set(g.id, P.map(h));
3785
3811
  }
3786
3812
  const m = e.ruler ? Math.round(o.annotation.lineHeight + 6) : 0;
@@ -3885,28 +3911,28 @@ function vc(t, e, o = {}) {
3885
3911
  for (const p of e) {
3886
3912
  const m = n.get(p.source), g = n.get(p.target);
3887
3913
  if (!m || !g || m === g || p.from !== "auto" || p.to !== "auto") continue;
3888
- const y = [m.id, ...a(m.id)], P = [g.id, ...a(g.id)].find((F) => y.includes(F) && F !== m.id && F !== g.id), A = P && n.get(P)?.type === "group" ? n.get(P) : void 0, w = (F) => {
3889
- let j = F;
3890
- for (; j.parent !== (A?.id ?? "root"); ) j = n.get(j.parent);
3914
+ const y = [m.id, ...a(m.id)], P = [g.id, ...a(g.id)].find((T) => y.includes(T) && T !== m.id && T !== g.id), O = P && n.get(P)?.type === "group" ? n.get(P) : void 0, w = (T) => {
3915
+ let j = T;
3916
+ for (; j.parent !== (O?.id ?? "root"); ) j = n.get(j.parent);
3891
3917
  return j;
3892
- }, [k, T] = [w(m), w(g)];
3893
- if (A && k !== T) {
3894
- const F = (z, mt, it) => z === mt || i(mt, c(it)).some((ht) => !u(z, mt, ht, ""));
3918
+ }, [k, F] = [w(m), w(g)];
3919
+ if (O && k !== F) {
3920
+ const T = (z, mt, it) => z === mt || i(mt, c(it)).some((ht) => !u(z, mt, ht, ""));
3895
3921
  if (!t.some(
3896
- (z) => z.parent === A.id && z !== k && z !== T && kc(k, T, z)
3897
- ) && F(m, k, g) && F(g, T, m)) continue;
3898
- const $ = Math.abs(c(k).y - c(T).y) > Math.abs(c(k).x - c(T).x), v = (z, mt, it) => (c(z)[it] - c(mt)[it]) / Math.max(1, it === "x" ? mt.w : mt.h), S = $ ? "x" : "y", M = v(m, k, S) + v(g, T, S), x = c(T)[$ ? "y" : "x"] > c(k)[$ ? "y" : "x"], N = Math.abs(M) > 0.1 ? M > 0 : x;
3899
- d(A.id, $ ? N ? "right" : "left" : N ? "bottom" : "top");
3922
+ (z) => z.parent === O.id && z !== k && z !== F && kc(k, F, z)
3923
+ ) && T(m, k, g) && T(g, F, m)) continue;
3924
+ const $ = Math.abs(c(k).y - c(F).y) > Math.abs(c(k).x - c(F).x), v = (z, mt, it) => (c(z)[it] - c(mt)[it]) / Math.max(1, it === "x" ? mt.w : mt.h), S = $ ? "x" : "y", M = v(m, k, S) + v(g, F, S), x = c(F)[$ ? "y" : "x"] > c(k)[$ ? "y" : "x"], N = Math.abs(M) > 0.1 ? M > 0 : x;
3925
+ d(O.id, $ ? N ? "right" : "left" : N ? "bottom" : "top");
3900
3926
  continue;
3901
3927
  }
3902
- for (const [F, j] of [
3928
+ for (const [T, j] of [
3903
3929
  [m, g],
3904
3930
  [g, m]
3905
3931
  ]) {
3906
- const $ = F.parent === "root" ? void 0 : n.get(F.parent);
3907
- if (!$ || A && $.id === A.id || s(j.id, $.id)) continue;
3932
+ const $ = T.parent === "root" ? void 0 : n.get(T.parent);
3933
+ if (!$ || O && $.id === O.id || s(j.id, $.id)) continue;
3908
3934
  const v = i($, c(j));
3909
- !v.length || v.some((S) => !u(F, $, S, j.id)) || (v.some((S) => S === "left" || S === "right") ? d($.id, c(F).y < c($).y + 24 ? "top" : "bottom") : d($.id, c(j).x < c(F).x ? "left" : "right"));
3935
+ !v.length || v.some((S) => !u(T, $, S, j.id)) || (v.some((S) => S === "left" || S === "right") ? d($.id, c(T).y < c($).y + 24 ? "top" : "bottom") : d($.id, c(j).x < c(T).x ? "left" : "right"));
3910
3936
  }
3911
3937
  }
3912
3938
  const f = o.standoff ?? bc, h = Math.max(o.edgeGap ?? Ws, o.portGap ?? Ws), l = (p) => p ? 2 * f + (p - 1) * h : ye;
@@ -3928,14 +3954,14 @@ function kc(t, e, o) {
3928
3954
  return o.x < c.x && o.x + o.w > d.x && o.y < c.y && o.y + o.h > d.y;
3929
3955
  }
3930
3956
  const Us = 20, Cn = 20, Sc = 12, Ec = 16;
3931
- function Ic(t, e, o, n, a = (s) => Te(s)) {
3957
+ function Ic(t, e, o, n, a = (s) => Fe(s)) {
3932
3958
  const s = /* @__PURE__ */ new Map();
3933
3959
  for (const r of t.filter((d) => d.scope === "root")) {
3934
3960
  const d = r.axis === "right", c = (g) => d ? g.x : g.y, u = (g) => d ? g.x + g.w : g.y + g.h, i = (g) => d ? g.y : g.x, f = (g) => d ? g.y + g.h : g.x + g.w, h = (g) => (c(g) + u(g)) / 2, l = (g) => (i(g) + f(g)) / 2, p = [...o.values()].filter((g) => g.parent === r.scope);
3935
3961
  (r.bands?.map((g) => g.map((y) => o.get(y))) ?? [p]).forEach((g) => {
3936
- const y = Math.min(...g.map(i)), P = Math.max(...g.map(f)), A = Math.min(...g.map(c)), w = Math.max(...g.map(u)), k = new Set(g.map(($) => $.id)), T = ($) => [...o.values()].some(
3937
- (v) => v.parent === r.scope && !k.has(v.id) && c(v) < w && u(v) > A && ($ ? f(v) <= y : i(v) >= P)
3938
- ), F = { before: !T(!0), after: !T(!1) }, j = [];
3962
+ const y = Math.min(...g.map(i)), P = Math.max(...g.map(f)), O = Math.min(...g.map(c)), w = Math.max(...g.map(u)), k = new Set(g.map(($) => $.id)), F = ($) => [...o.values()].some(
3963
+ (v) => v.parent === r.scope && !k.has(v.id) && c(v) < w && u(v) > O && ($ ? f(v) <= y : i(v) >= P)
3964
+ ), T = { before: !F(!0), after: !F(!1) }, j = [];
3939
3965
  for (const $ of e) {
3940
3966
  if (n.has($.id) || $.from !== "auto" || $.to !== "auto") continue;
3941
3967
  const v = o.get($.source), S = o.get($.target);
@@ -3946,7 +3972,7 @@ function Ic(t, e, o, n, a = (s) => Te(s)) {
3946
3972
  if (!it.some((W) => i(W) < mt && f(W) > z) && !(M && it.length)) continue;
3947
3973
  const Q = (W, b) => !g.some(
3948
3974
  (Y) => Y !== W && c(Y) < u(W) && u(Y) > c(W) && (b ? f(Y) <= i(W) : i(Y) >= f(W))
3949
- ), H = (W) => !F[W ? "before" : "after"] || !Q(v, W) || !Q(S, W) ? 1 / 0 : W ? i(v) - y + (i(S) - y) : P - f(v) + (P - f(S)), [J, C] = [H(!0), H(!1)];
3975
+ ), H = (W) => !T[W ? "before" : "after"] || !Q(v, W) || !Q(S, W) ? 1 / 0 : W ? i(v) - y + (i(S) - y) : P - f(v) + (P - f(S)), [J, C] = [H(!0), H(!1)];
3950
3976
  if (!Number.isFinite(J) && !Number.isFinite(C)) continue;
3951
3977
  const _ = J === C ? !M : J < C;
3952
3978
  j.push({ id: $.id, before: _, from: h(x), to: h(N), back: M });
@@ -3960,7 +3986,7 @@ function Ic(t, e, o, n, a = (s) => Te(s)) {
3960
3986
  let z = 0;
3961
3987
  for (; S[z]?.some(([W, b]) => x.from < b + Cn && x.to > W - Cn); ) z++;
3962
3988
  (S[z] ??= []).push([x.from, x.to]);
3963
- const mt = e.find((W) => W.id === x.id), it = o.get(mt.target), ht = $ ? y - Us - z * Cn : P + Us + z * Cn, Q = Oc(it, g, !x.back, c, u), H = Math.min(Ec, (f(it) - i(it)) / 2 - Sc), J = Ac(it, g, !x.back, mt.id, e, o, c, u, i, f), C = it.shape === "diamond" && J.length > 0 || J.some((W) => {
3989
+ const mt = e.find((W) => W.id === x.id), it = o.get(mt.target), ht = $ ? y - Us - z * Cn : P + Us + z * Cn, Q = Ac(it, g, !x.back, c, u), H = Math.min(Ec, (f(it) - i(it)) / 2 - Sc), J = Oc(it, g, !x.back, mt.id, e, o, c, u, i, f), C = it.shape === "diamond" && J.length > 0 || J.some((W) => {
3964
3990
  if (!W.label) return !1;
3965
3991
  const { w: b, h: Y } = a(W.label);
3966
3992
  return (d ? Y : b) / 2 + 2 > H;
@@ -3977,11 +4003,11 @@ function Ic(t, e, o, n, a = (s) => Te(s)) {
3977
4003
  }
3978
4004
  return s;
3979
4005
  }
3980
- function Oc(t, e, o, n, a) {
4006
+ function Ac(t, e, o, n, a) {
3981
4007
  const s = e.filter((r) => r !== t && (o ? a(r) <= n(t) : n(r) >= a(t))).map((r) => o ? n(t) - a(r) : n(r) - a(t));
3982
4008
  return Math.min(48, ...s);
3983
4009
  }
3984
- function Ac(t, e, o, n, a, s, r, d, c, u) {
4010
+ function Oc(t, e, o, n, a, s, r, d, c, u) {
3985
4011
  const i = new Set(
3986
4012
  e.filter(
3987
4013
  (h) => h !== t && (o ? d(h) <= r(t) : r(h) >= d(t)) && c(h) < u(t) && u(h) > c(t)
@@ -4006,19 +4032,19 @@ function Lc(t, e, o, n, a, s = si) {
4006
4032
  ), p = [], m = [];
4007
4033
  for (const [g, y] of e.entries())
4008
4034
  for (const P of y) {
4009
- const A = c(P);
4010
- A && (p[g] = Math.min(p[g] ?? 1 / 0, A.y), m[g] = Math.max(m[g] ?? -1 / 0, A.y + A.h));
4035
+ const O = c(P);
4036
+ O && (p[g] = Math.min(p[g] ?? 1 / 0, O.y), m[g] = Math.max(m[g] ?? -1 / 0, O.y + O.h));
4011
4037
  }
4012
4038
  for (const [g, { placed: y, level: P }] of h) {
4013
- const A = Math.max(0, ...P) + 1, w = (p[g + 1] ?? 0) - (m[g] ?? 0), k = A > 1 ? Math.min(s.track, Math.max(0, w - 2 * ai) / (A - 1)) : 0, T = (m[g] ?? 0) + (w - (A - 1) * k) / 2;
4014
- y.forEach((F, j) => F.y = dn(T + P[j] * k));
4039
+ const O = Math.max(0, ...P) + 1, w = (p[g + 1] ?? 0) - (m[g] ?? 0), k = O > 1 ? Math.min(s.track, Math.max(0, w - 2 * ai) / (O - 1)) : 0, F = (m[g] ?? 0) + (w - (O - 1) * k) / 2;
4040
+ y.forEach((T, j) => T.y = dn(F + P[j] * k));
4015
4041
  }
4016
4042
  for (const g of u) {
4017
- const y = c(g.chain[0]), P = c(g.chain.at(-1)), A = i.get(g.id), w = f.get(g.id), k = [{ x: A, y: y.y + y.h }];
4018
- for (const T of l.get(g.id)) k.push({ x: T.up, y: T.y }, { x: T.low, y: T.y });
4043
+ const y = c(g.chain[0]), P = c(g.chain.at(-1)), O = i.get(g.id), w = f.get(g.id), k = [{ x: O, y: y.y + y.h }];
4044
+ for (const F of l.get(g.id)) k.push({ x: F.up, y: F.y }, { x: F.low, y: F.y });
4019
4045
  k.push({ x: w, y: P.y }), d.set(g.id, {
4020
- points: Gc(k).map((T) => r ? { x: T.y, y: T.x } : T),
4021
- fromOffset: dn(A - (y.x + y.w / 2)),
4046
+ points: Gc(k).map((F) => r ? { x: F.y, y: F.x } : F),
4047
+ fromOffset: dn(O - (y.x + y.w / 2)),
4022
4048
  toOffset: dn(w - (P.x + P.w / 2))
4023
4049
  });
4024
4050
  }
@@ -4031,16 +4057,16 @@ function $c(t, e, o, n, a, s = si) {
4031
4057
  return r;
4032
4058
  }
4033
4059
  function ii(t, e, o, n, a, s) {
4034
- const r = t === "right", d = (F) => {
4035
- const j = n(F);
4060
+ const r = t === "right", d = (T) => {
4061
+ const j = n(T);
4036
4062
  return j && (r ? { x: j.y, y: j.x, w: j.h, h: j.w } : j);
4037
- }, c = new Map(e.flatMap((F, j) => F.map(($) => [$, j]))), u = o.filter(
4038
- (F) => F.chain.length >= 2 && d(F.chain[0]) && d(F.chain.at(-1)) && F.chain.slice(1, -1).every((j) => a(j) !== void 0) && F.chain.every((j, $) => $ === 0 || c.get(j) === c.get(F.chain[$ - 1]) + 1)
4039
- ), i = (F) => {
4040
- const j = d(F);
4041
- return j ? j.x + j.w / 2 : a(F);
4042
- }, f = (F, j, $) => {
4043
- const v = d(F), S = v.x + Ys, M = v.x + v.w - Ys, x = j.length;
4063
+ }, c = new Map(e.flatMap((T, j) => T.map(($) => [$, j]))), u = o.filter(
4064
+ (T) => T.chain.length >= 2 && d(T.chain[0]) && d(T.chain.at(-1)) && T.chain.slice(1, -1).every((j) => a(j) !== void 0) && T.chain.every((j, $) => $ === 0 || c.get(j) === c.get(T.chain[$ - 1]) + 1)
4065
+ ), i = (T) => {
4066
+ const j = d(T);
4067
+ return j ? j.x + j.w / 2 : a(T);
4068
+ }, f = (T, j, $) => {
4069
+ const v = d(T), S = v.x + Ys, M = v.x + v.w - Ys, x = j.length;
4044
4070
  j.sort((it, ht) => it.want - ht.want || (it.line < ht.line ? -1 : 1));
4045
4071
  const N = x > 1 ? Math.min(s.port, Math.max(0, M - S) / (x - 1)) : 0, z = [];
4046
4072
  for (const [it, ht] of j.entries())
@@ -4054,30 +4080,30 @@ function ii(t, e, o, n, a, s) {
4054
4080
  mt.push(Math.max(S, Math.min(M - (x - 1) * N, it.sum / it.n)) + mt.length * N);
4055
4081
  j.forEach((it, ht) => $.set(it.line, dn(mt[ht])));
4056
4082
  }, h = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
4057
- for (const F of u) {
4058
- const [j, $] = F.chain;
4059
- (h.get(j) ?? h.set(j, []).get(j)).push({ line: F.id, want: i($) });
4083
+ for (const T of u) {
4084
+ const [j, $] = T.chain;
4085
+ (h.get(j) ?? h.set(j, []).get(j)).push({ line: T.id, want: i($) });
4060
4086
  }
4061
4087
  const p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
4062
- for (const [F, j] of h) f(F, j, p);
4063
- for (const F of u) {
4064
- const j = F.chain.at(-1), $ = F.chain.at(-2), v = F.chain.length === 2 ? p.get(F.id) : a($);
4065
- (l.get(j) ?? l.set(j, []).get(j)).push({ line: F.id, want: v });
4066
- }
4067
- for (const [F, j] of l) f(F, j, m);
4068
- const g = (F, j) => j === 0 ? p.get(F.id) : j === F.chain.length - 1 ? m.get(F.id) : a(F.chain[j]), y = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map();
4069
- for (const F of u) {
4088
+ for (const [T, j] of h) f(T, j, p);
4089
+ for (const T of u) {
4090
+ const j = T.chain.at(-1), $ = T.chain.at(-2), v = T.chain.length === 2 ? p.get(T.id) : a($);
4091
+ (l.get(j) ?? l.set(j, []).get(j)).push({ line: T.id, want: v });
4092
+ }
4093
+ for (const [T, j] of l) f(T, j, m);
4094
+ const g = (T, j) => j === 0 ? p.get(T.id) : j === T.chain.length - 1 ? m.get(T.id) : a(T.chain[j]), y = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map();
4095
+ for (const T of u) {
4070
4096
  const j = [];
4071
- for (let $ = 0; $ + 1 < F.chain.length; $++) {
4072
- const v = g(F, $), S = g(F, $ + 1);
4097
+ for (let $ = 0; $ + 1 < T.chain.length; $++) {
4098
+ const v = g(T, $), S = g(T, $ + 1);
4073
4099
  if (Math.abs(v - S) < xo) continue;
4074
- const M = { line: F.id, up: v, low: S, lo: Math.min(v, S), hi: Math.max(v, S) }, x = c.get(F.chain[$]);
4100
+ const M = { line: T.id, up: v, low: S, lo: Math.min(v, S), hi: Math.max(v, S) }, x = c.get(T.chain[$]);
4075
4101
  (y.get(x) ?? y.set(x, []).get(x)).push(M), j.push(M);
4076
4102
  }
4077
- P.set(F.id, j);
4103
+ P.set(T.id, j);
4078
4104
  }
4079
- const A = (F, j) => F > j.lo + xo && F < j.hi - xo, w = (F, j) => (A(F.low, j) ? 1 : 0) + (A(j.up, F) ? 1 : 0), k = (F, j) => F.lo < j.hi + s.track && j.lo < F.hi + s.track, T = /* @__PURE__ */ new Map();
4080
- for (const [F, j] of y) {
4105
+ const O = (T, j) => T > j.lo + xo && T < j.hi - xo, w = (T, j) => (O(T.low, j) ? 1 : 0) + (O(j.up, T) ? 1 : 0), k = (T, j) => T.lo < j.hi + s.track && j.lo < T.hi + s.track, F = /* @__PURE__ */ new Map();
4106
+ for (const [T, j] of y) {
4081
4107
  const $ = [];
4082
4108
  for (const S of [...j].sort((M, x) => M.lo - x.lo || M.hi - x.hi)) {
4083
4109
  let M = 0, x = 1 / 0;
@@ -4093,9 +4119,9 @@ function ii(t, e, o, n, a, s) {
4093
4119
  for (let S = 0; S < $.length; S++)
4094
4120
  for (let M = 0; M < S; M++)
4095
4121
  k($[S], $[M]) && (v[S] = Math.max(v[S], v[M] + 1));
4096
- T.set(F, { placed: $, level: v });
4122
+ F.set(T, { placed: $, level: v });
4097
4123
  }
4098
- return { rectOf: d, usable: u, outPort: p, inPort: m, gaps: T, runs: P };
4124
+ return { rectOf: d, usable: u, outPort: p, inPort: m, gaps: F, runs: P };
4099
4125
  }
4100
4126
  const dn = (t) => Math.round(t * 100) / 100;
4101
4127
  function Gc(t) {
@@ -4117,7 +4143,7 @@ const Pc = ["vscode", "vscode-insiders", "cursor", "windsurf", "zed"], Xs = [
4117
4143
  "open-diamond",
4118
4144
  "circle",
4119
4145
  "cross"
4120
- ], Ks = "M1 4.5L7.5 1L14 4.5L7.5 8Z", Tc = {
4146
+ ], Ks = "M1 4.5L7.5 1L14 4.5L7.5 8Z", Fc = {
4121
4147
  arrow: { w: 8, h: 8, x: 7, d: "M1 1L7 4L1 7", fill: "none", stop: 0 },
4122
4148
  triangle: { w: 10, h: 9, x: 1, d: "M1 1L9 4.5L1 8Z", fill: "ink", stop: 8 },
4123
4149
  "open-triangle": { w: 12, h: 11, x: 1, d: "M1 1L11 5.5L1 10Z", fill: "surface", stop: 10 },
@@ -4133,7 +4159,7 @@ const Pc = ["vscode", "vscode-insiders", "cursor", "windsurf", "zed"], Xs = [
4133
4159
  },
4134
4160
  // Set back from the end, with the line running on through it.
4135
4161
  cross: { w: 9, h: 9, x: 10.5, d: "M1 1L8 8M8 1L1 8", fill: "none", stop: 0 }
4136
- }, jo = (t) => t === "none" ? void 0 : Tc[t], as = (t) => t.directed === !1 ? "none" : t.head ?? "arrow", is = (t) => t.directed === !1 ? "none" : t.tail ?? "none", Fc = (t) => as(t) !== "arrow" || is(t) !== "none";
4162
+ }, jo = (t) => t === "none" ? void 0 : Fc[t], as = (t) => t.directed === !1 ? "none" : t.head ?? "arrow", is = (t) => t.directed === !1 ? "none" : t.tail ?? "none", Tc = (t) => as(t) !== "arrow" || is(t) !== "none";
4137
4163
  function Js(t, e, o) {
4138
4164
  const n = Math.hypot(e.x - t.x, e.y - t.y), a = Math.min(o, n - 1);
4139
4165
  return a > 0 ? { x: t.x + (e.x - t.x) * a / n, y: t.y + (e.y - t.y) * a / n } : t;
@@ -4201,30 +4227,30 @@ const No = {
4201
4227
  right: { x: 1, y: 0 },
4202
4228
  top: { x: 0, y: -1 },
4203
4229
  bottom: { x: 0, y: 1 }
4204
- }, Ro = (t, e, o) => Math.max(t.x, e.x) > o.x && Math.min(t.x, e.x) < o.x + o.w && Math.max(t.y, e.y) > o.y && Math.min(t.y, e.y) < o.y + o.h, bn = (t, e) => ({ x: t.x - e, y: t.y - e, w: t.w + 2 * e, h: t.h + 2 * e }), Cc = 8, qc = 10, ri = 2;
4230
+ }, Ro = (t, e, o) => Math.max(t.x, e.x) > o.x && Math.min(t.x, e.x) < o.x + o.w && Math.max(t.y, e.y) > o.y && Math.min(t.y, e.y) < o.y + o.h, bn = (t, e) => ({ x: t.x - e, y: t.y - e, w: t.w + 2 * e, h: t.h + 2 * e }), Cc = 8, Bc = 10, ri = 2;
4205
4231
  function ci(t, e, o, n, a) {
4206
- const { w: s, h: r } = Te(t, n), d = [], c = (p) => ({ x: p.x - s / 2, y: p.y - r / 2, w: s, h: r }), u = e[0], i = (a.routes ?? []).map((p) => ({
4232
+ const { w: s, h: r } = Fe(t, n), d = [], c = (p) => ({ x: p.x - s / 2, y: p.y - r / 2, w: s, h: r }), u = e[0], i = (a.routes ?? []).map((p) => ({
4207
4233
  route: p,
4208
4234
  shared: !!u && !!p[0] && nn(p[0], u) < 1
4209
4235
  })), f = n.annotation.size + (ei(t, n).length - 1) * n.annotation.lineHeight, h = (p) => {
4210
- const m = c(p), g = { x: m.x + 8, y: p.y - f / 2, w: Math.max(1, s - 16), h: f }, y = bn(m, -1), P = bn(m, 3), A = bn(m, Cc);
4236
+ const m = c(p), g = { x: m.x + 8, y: p.y - f / 2, w: Math.max(1, s - 16), h: f }, y = bn(m, -1), P = bn(m, 3), O = bn(m, Cc);
4211
4237
  let w = 0;
4212
- for (const { route: k, shared: T } of i) {
4213
- const F = (j) => k.some(($, v) => v && Ro(k[v - 1], $, j));
4214
- F(g) ? w += T ? 1 : 5 : F(y) ? w += T ? 1 : 3 : !T && F(P) ? w += 2 : !T && F(A) && (w += 1);
4238
+ for (const { route: k, shared: F } of i) {
4239
+ const T = (j) => k.some(($, v) => v && Ro(k[v - 1], $, j));
4240
+ T(g) ? w += F ? 1 : 5 : T(y) ? w += F ? 1 : 3 : !F && T(P) ? w += 2 : !F && T(O) && (w += 1);
4215
4241
  }
4216
4242
  for (const k of a.borders ?? []) Xe(m, k, 2) && (w += 2);
4217
4243
  for (const k of a.marks ?? []) Xe(m, k, 1) && (w += 5);
4218
- return a.home && !Nr(bn(a.home, -2), m) && (w += 4), o.some((k) => Xe(m, k, qc)) && (w += 1), w;
4244
+ return a.home && !Nr(bn(a.home, -2), m) && (w += 4), o.some((k) => Xe(m, k, Bc)) && (w += 1), w;
4219
4245
  }, l = (p, m) => {
4220
4246
  const g = Math.min(p.y, m.y) - r, y = Math.max(p.y, m.y) + r, P = [];
4221
- for (const { route: A } of i)
4222
- for (let w = 1; w < A.length; w++) {
4223
- const k = A[w - 1], T = A[w];
4224
- if (k.x !== T.x || Math.max(k.y, T.y) < g || Math.min(k.y, T.y) > y) continue;
4225
- const F = k.x - p.x;
4226
- if (!F || Math.abs(F) > s) continue;
4227
- const j = F < 0 ? F + 4 + s / 2 : F - 4 - s / 2;
4247
+ for (const { route: O } of i)
4248
+ for (let w = 1; w < O.length; w++) {
4249
+ const k = O[w - 1], F = O[w];
4250
+ if (k.x !== F.x || Math.max(k.y, F.y) < g || Math.min(k.y, F.y) > y) continue;
4251
+ const T = k.x - p.x;
4252
+ if (!T || Math.abs(T) > s) continue;
4253
+ const j = T < 0 ? T + 4 + s / 2 : T - 4 - s / 2;
4228
4254
  Math.abs(j) <= s / 2 - 6 && Math.abs(j) > r - 4 && P.push(j);
4229
4255
  }
4230
4256
  return P;
@@ -4232,9 +4258,9 @@ function ci(t, e, o, n, a) {
4232
4258
  for (let p = 1; p < e.length; p++) {
4233
4259
  const m = e[p - 1], g = e[p], y = nn(m, g);
4234
4260
  if (y < 8) continue;
4235
- const P = m.y === g.y, A = y + (P ? 50 : 0), w = a.marks?.length ? [-(r / 2 + 7), r / 2 + 7] : [], k = P ? [0, -(r / 2 + 4), r / 2 + 4, ...w] : [0, -(r - 4), r - 4, ...l(m, g)], T = Math.max(2, Math.ceil(y / 6));
4236
- for (let F = 0; F <= T; F++) {
4237
- const j = F / T, $ = { x: m.x + (g.x - m.x) * j, y: m.y + (g.y - m.y) * j };
4261
+ const P = m.y === g.y, O = y + (P ? 50 : 0), w = a.marks?.length ? [-(r / 2 + 7), r / 2 + 7] : [], k = P ? [0, -(r / 2 + 4), r / 2 + 4, ...w] : [0, -(r - 4), r - 4, ...l(m, g)], F = Math.max(2, Math.ceil(y / 6));
4262
+ for (let T = 0; T <= F; T++) {
4263
+ const j = T / F, $ = { x: m.x + (g.x - m.x) * j, y: m.y + (g.y - m.y) * j };
4238
4264
  for (const v of k) {
4239
4265
  const S = P ? { x: $.x, y: $.y + v } : { x: $.x + v, y: $.y };
4240
4266
  o.some((M) => Xe(c(S), M, 4)) || d.push({
@@ -4243,40 +4269,40 @@ function ci(t, e, o, n, a) {
4243
4269
  h: r,
4244
4270
  cost: h(S) + (P && v ? ri : 0),
4245
4271
  // Prefer long level segments, the middle of a segment, on the line, then above it.
4246
- score: A - Math.abs(j - 0.5) * y * 0.5 - Math.abs(v) * 3 + (v < 0 ? 1 : 0)
4272
+ score: O - Math.abs(j - 0.5) * y * 0.5 - Math.abs(v) * 3 + (v < 0 ? 1 : 0)
4247
4273
  });
4248
4274
  }
4249
4275
  }
4250
4276
  }
4251
4277
  return { w: s, h: r, spots: d, cost: h };
4252
4278
  }
4253
- function Bc(t, e, o = Re(), n = []) {
4279
+ function qc(t, e, o = Re(), n = []) {
4254
4280
  const a = t.map((i) => ci(i.label, i.points, e, o, i.avoid ?? {})), s = t.map(() => null), r = (i, f) => ({
4255
4281
  x: f.x + (t[i].dx ?? 0) - f.w / 2,
4256
4282
  y: f.y + (t[i].dy ?? 0) - f.h / 2,
4257
4283
  w: f.w,
4258
4284
  h: f.h
4259
4285
  }), d = (i) => {
4260
- const f = [...n, ...s.flatMap((A, w) => w !== i && A ? [r(w, A)] : [])], { w: h, h: l, spots: p, cost: m } = a[i];
4286
+ const f = [...n, ...s.flatMap((O, w) => w !== i && O ? [r(w, O)] : [])], { w: h, h: l, spots: p, cost: m } = a[i];
4261
4287
  let g = null, y = 1 / 0;
4262
- for (const A of p) {
4263
- const w = r(i, A);
4264
- if (f.some((T) => Xe(w, T, 6))) continue;
4265
- const k = A.cost + f.filter((T) => Xe(w, T, l)).length * ri;
4266
- (k < y || k === y && A.score > g.score) && ([g, y] = [A, k]);
4288
+ for (const O of p) {
4289
+ const w = r(i, O);
4290
+ if (f.some((F) => Xe(w, F, 6))) continue;
4291
+ const k = O.cost + f.filter((F) => Xe(w, F, l)).length * ri;
4292
+ (k < y || k === y && O.score > g.score) && ([g, y] = [O, k]);
4267
4293
  }
4268
4294
  if (g) {
4269
- const { cost: A, ...w } = g;
4295
+ const { cost: O, ...w } = g;
4270
4296
  return w;
4271
4297
  }
4272
- const P = (A) => ({ x: A.x - h / 2, y: A.y - l / 2, w: h, h: l });
4298
+ const P = (O) => ({ x: O.x - h / 2, y: O.y - l / 2, w: h, h: l });
4273
4299
  return Hc(
4274
4300
  t[i].points,
4275
4301
  h,
4276
4302
  l,
4277
4303
  e,
4278
4304
  f,
4279
- (A) => e.some((w) => Xe(P(A), w, 4)) || f.some((w) => Xe(P(A), w, 6)),
4305
+ (O) => e.some((w) => Xe(P(O), w, 4)) || f.some((w) => Xe(P(O), w, 6)),
4280
4306
  m,
4281
4307
  t[i].avoid?.home
4282
4308
  );
@@ -4294,12 +4320,12 @@ function Hc(t, e, o, n, a, s, r = () => 0, d) {
4294
4320
  for (let h = 1; h < t.length; h++) {
4295
4321
  const l = t[h - 1], p = t[h], m = nn(l, p);
4296
4322
  if (!m) continue;
4297
- const g = l.y === p.y ? 0 : l.x === p.x ? 1 : -(p.y - l.y) / m, y = l.y === p.y ? 1 : l.x === p.x ? 0 : (p.x - l.x) / m, P = (e * Math.abs(g) + o * Math.abs(y)) / 2, A = m + (l.y === p.y ? 50 : 0), w = e * Math.abs(y) + o * Math.abs(g), k = Array.from(
4323
+ const g = l.y === p.y ? 0 : l.x === p.x ? 1 : -(p.y - l.y) / m, y = l.y === p.y ? 1 : l.x === p.x ? 0 : (p.x - l.x) / m, P = (e * Math.abs(g) + o * Math.abs(y)) / 2, O = m + (l.y === p.y ? 50 : 0), w = e * Math.abs(y) + o * Math.abs(g), k = Array.from(
4298
4324
  { length: 2 * Math.ceil(w / 6) + 1 },
4299
- (T, F) => (F - Math.ceil(w / 6)) * 6
4325
+ (F, T) => (T - Math.ceil(w / 6)) * 6
4300
4326
  );
4301
- for (const T of [0.5, 0.35, 0.65]) {
4302
- const F = { x: l.x + (p.x - l.x) * T, y: l.y + (p.y - l.y) * T }, j = F.x * g + F.y * y, $ = /* @__PURE__ */ new Set();
4327
+ for (const F of [0.5, 0.35, 0.65]) {
4328
+ const T = { x: l.x + (p.x - l.x) * F, y: l.y + (p.y - l.y) * F }, j = T.x * g + T.y * y, $ = /* @__PURE__ */ new Set();
4303
4329
  for (const [v, S] of [
4304
4330
  [n, 5],
4305
4331
  [a, 7]
@@ -4314,8 +4340,8 @@ function Hc(t, e, o, n, a, s, r = () => 0, d) {
4314
4340
  }
4315
4341
  for (const v of $)
4316
4342
  for (const S of v ? k : []) {
4317
- const M = { x: F.x + g * v + y * S, y: F.y + y * v - g * S };
4318
- s(M) || c.push({ ...M, w: e, h: o, score: A - (Math.abs(v) + Math.abs(S)) * 2 });
4343
+ const M = { x: T.x + g * v + y * S, y: T.y + y * v - g * S };
4344
+ s(M) || c.push({ ...M, w: e, h: o, score: O - (Math.abs(v) + Math.abs(S)) * 2 });
4319
4345
  }
4320
4346
  }
4321
4347
  }
@@ -4392,7 +4418,7 @@ function li(t, e, o) {
4392
4418
  ]) {
4393
4419
  const f = o.get(c), h = o.get(ss(t, c)?.parentId ?? ""), l = o.get(u);
4394
4420
  if (i || !f || !h || !l || !Ur(t, c)) continue;
4395
- const p = (T, F) => Math.abs(T - F) < 0.5, m = [
4421
+ const p = (F, T) => Math.abs(F - T) < 0.5, m = [
4396
4422
  ...p(f.x, h.x) ? ["left"] : [],
4397
4423
  ...p(f.x + f.w, h.x + h.w) ? ["right"] : [],
4398
4424
  ...f.y + f.h > h.y + h.h - 0.5 ? ["bottom"] : []
@@ -4401,16 +4427,16 @@ function li(t, e, o) {
4401
4427
  n.set(s.id, { ...n.get(s.id), [d]: Zs(f, m, Jn(l)) });
4402
4428
  continue;
4403
4429
  }
4404
- const g = Zs(h, ["left", "right", "top", "bottom"], Jn(l)), y = Jn(f), P = No[g], A = {
4430
+ const g = Zs(h, ["left", "right", "top", "bottom"], Jn(l)), y = Jn(f), P = No[g], O = {
4405
4431
  x: (g === "left" ? h.x : g === "right" ? h.x + h.w : y.x) + P.x * ta,
4406
4432
  y: (g === "top" ? h.y : g === "bottom" ? h.y + h.h : y.y) + P.y * ta
4407
4433
  }, w = {
4408
4434
  x: g === "left" ? f.x : g === "right" ? f.x + f.w : y.x,
4409
4435
  y: g === "top" ? f.y : g === "bottom" ? f.y + f.h : y.y
4410
- }, k = P.y ? { x: A.x - 16, y: P.y < 0 ? A.y - 2 : A.y, w: 32, h: 2 } : { x: P.x < 0 ? A.x - 2 : A.x, y: A.y - 16, w: 2, h: 32 };
4436
+ }, k = P.y ? { x: O.x - 16, y: P.y < 0 ? O.y - 2 : O.y, w: 32, h: 2 } : { x: P.x < 0 ? O.x - 2 : O.x, y: O.y - 16, w: 2, h: 32 };
4411
4437
  a.set(s.id, {
4412
4438
  ...a.get(s.id),
4413
- [d]: { side: g, stub: k, cross: [A, w] }
4439
+ [d]: { side: g, stub: k, cross: [O, w] }
4414
4440
  }), n.set(s.id, { ...n.get(s.id), [d]: g });
4415
4441
  }
4416
4442
  }
@@ -4491,12 +4517,12 @@ function Jc(t, e, o, n, a) {
4491
4517
  ), u = c(t);
4492
4518
  let i = null, f = 1 / 0;
4493
4519
  for (let h = 1; h + 2 < t.length; h++) {
4494
- const [l, p, m, g] = t.slice(h - 1, h + 3), y = s(p, m) ? "y" : "x", P = (s(p, m) ? o : e) + 2 * ea, A = (s(p, m) ? o : e) + 8, w = Math.abs(g[y] - l[y]) - Kc;
4495
- if (Math.sign(p[y] - l[y]) !== Math.sign(g[y] - m[y]) || w < A) continue;
4496
- const k = Math.sign(g[y] - l[y]), T = Math.min(P, w);
4497
- for (const F of [l[y] + k * T, g[y] - k * T]) {
4498
- const j = t.map((v, S) => S === h || S === h + 1 ? { ...v, [y]: F } : v), $ = j.slice(h - 1, h + 3);
4499
- Math.abs(F - p[y]) >= f || Math.abs(F - p[y]) < 0.5 || Ze($).some(([v, S]) => n.some((M) => Ro(v, S, M))) || n.some((v) => Ro(j[h], j[h + 1], bn(v, na))) || c(j) > u || (i = j, f = Math.abs(F - p[y]));
4520
+ const [l, p, m, g] = t.slice(h - 1, h + 3), y = s(p, m) ? "y" : "x", P = (s(p, m) ? o : e) + 2 * ea, O = (s(p, m) ? o : e) + 8, w = Math.abs(g[y] - l[y]) - Kc;
4521
+ if (Math.sign(p[y] - l[y]) !== Math.sign(g[y] - m[y]) || w < O) continue;
4522
+ const k = Math.sign(g[y] - l[y]), F = Math.min(P, w);
4523
+ for (const T of [l[y] + k * F, g[y] - k * F]) {
4524
+ const j = t.map((v, S) => S === h || S === h + 1 ? { ...v, [y]: T } : v), $ = j.slice(h - 1, h + 3);
4525
+ Math.abs(T - p[y]) >= f || Math.abs(T - p[y]) < 0.5 || Ze($).some(([v, S]) => n.some((M) => Ro(v, S, M))) || n.some((v) => Ro(j[h], j[h + 1], bn(v, na))) || c(j) > u || (i = j, f = Math.abs(T - p[y]));
4500
4526
  }
4501
4527
  }
4502
4528
  return i ?? t;
@@ -4540,11 +4566,11 @@ function Vc(t, e, o, n) {
4540
4566
  }, n = {
4541
4567
  ...n,
4542
4568
  routes: n.routes.map((w, k) => {
4543
- const T = c.get(w.id)?.label;
4544
- if (!T || w.blocked || f(w) || t.layout.edges[w.id]?.waypoints?.length)
4569
+ const F = c.get(w.id)?.label;
4570
+ if (!F || w.blocked || f(w) || t.layout.edges[w.id]?.waypoints?.length)
4545
4571
  return w;
4546
- const { w: F, h: j } = Te(T, d), $ = n.routes.filter((M, x) => x !== k).map((M) => M.points), v = Jc(w.points, F, j, [...a, ...s], $), S = (M) => Math.min(
4547
- ...ci(T, M, a, d, { routes: $, borders: s }).spots.map(
4572
+ const { w: T, h: j } = Fe(F, d), $ = n.routes.filter((M, x) => x !== k).map((M) => M.points), v = Jc(w.points, T, j, [...a, ...s], $), S = (M) => Math.min(
4573
+ ...ci(F, M, a, d, { routes: $, borders: s }).spots.map(
4548
4574
  (x) => x.cost
4549
4575
  )
4550
4576
  );
@@ -4553,18 +4579,18 @@ function Vc(t, e, o, n) {
4553
4579
  };
4554
4580
  const h = n.routes.flatMap((w) => {
4555
4581
  const k = go(t, w.id);
4556
- return k && Fc(k) ? Qs(w.points, k) : [];
4582
+ return k && Tc(k) ? Qs(w.points, k) : [];
4557
4583
  }), l = (w) => {
4558
4584
  const k = new Set(gn(t, w.b));
4559
- return r.get(gn(t, w.a).find((T) => k.has(T) && r.has(T)) ?? "");
4560
- }, p = n.routes.filter((w) => c.get(w.id).label && !f(w)), m = Bc(
4585
+ return r.get(gn(t, w.a).find((F) => k.has(F) && r.has(F)) ?? "");
4586
+ }, p = n.routes.filter((w) => c.get(w.id).label && !f(w)), m = qc(
4561
4587
  p.map((w) => {
4562
4588
  const k = t.layout.edges[w.id] || {};
4563
4589
  return {
4564
4590
  label: c.get(w.id).label,
4565
4591
  points: w.points,
4566
4592
  avoid: {
4567
- routes: n.routes.filter((T) => T !== w).map((T) => T.points),
4593
+ routes: n.routes.filter((F) => F !== w).map((F) => F.points),
4568
4594
  borders: s,
4569
4595
  marks: h,
4570
4596
  home: l(c.get(w.id))
@@ -4579,15 +4605,15 @@ function Vc(t, e, o, n) {
4579
4605
  for (const w of n.routes) {
4580
4606
  const k = c.get(w.id).label;
4581
4607
  if (!k || !f(w)) continue;
4582
- const { w: T, h: F } = Te(k, d, !0), [j, $] = [w.points[0], w.points[w.points.length - 1]];
4608
+ const { w: F, h: T } = Fe(k, d, !0), [j, $] = [w.points[0], w.points[w.points.length - 1]];
4583
4609
  g.set(
4584
4610
  w,
4585
4611
  w.from === w.to ? {
4586
- x: w.points[1].x + ve.label + T / 2,
4612
+ x: w.points[1].x + ve.label + F / 2,
4587
4613
  y: (w.points[1].y + w.points[2].y) / 2,
4588
- w: T,
4589
- h: F
4590
- } : { x: (j.x + $.x) / 2, y: j.y - F / 2 - 1, w: T, h: F }
4614
+ w: F,
4615
+ h: T
4616
+ } : { x: (j.x + $.x) / 2, y: j.y - T / 2 - 1, w: F, h: T }
4591
4617
  );
4592
4618
  }
4593
4619
  const y = e.groups.flatMap(
@@ -4597,21 +4623,21 @@ function Vc(t, e, o, n) {
4597
4623
  const k = go(t, w.id);
4598
4624
  return { points: w.points, marks: k ? Qs(w.points, k) : [] };
4599
4625
  })
4600
- ), A = n.routes.map((w, k) => {
4601
- const T = i.get(w.id), F = go(t, w.id);
4626
+ ), O = n.routes.map((w, k) => {
4627
+ const F = i.get(w.id), T = go(t, w.id);
4602
4628
  return {
4603
4629
  ...w,
4604
4630
  label: g.get(w) ?? null,
4605
- path: Rr(F ? _c(w.points, F) : w.points, u),
4631
+ path: Rr(T ? _c(w.points, T) : w.points, u),
4606
4632
  halo: tl(
4607
4633
  w.points,
4608
4634
  n.routes.filter((j, $) => $ !== k && !(P.has(k) && P.has($))).map((j) => j.points),
4609
4635
  y
4610
4636
  ),
4611
- ...T?.to ? { cross: T.to.cross } : T?.from ? { cross: T.from.cross } : {}
4637
+ ...F?.to ? { cross: F.to.cross } : F?.from ? { cross: F.from.cross } : {}
4612
4638
  };
4613
4639
  });
4614
- return [...A.filter((w, k) => !P.has(k)), ...A.filter((w, k) => P.has(k))];
4640
+ return [...O.filter((w, k) => !P.has(k)), ...O.filter((w, k) => P.has(k))];
4615
4641
  }
4616
4642
  const Qc = 8, oa = 7, Ze = (t) => t.slice(1).map((e, o) => [t[o], e]), sa = (t) => Math.abs(t[0].y - t[1].y) < 0.5, aa = (t) => Math.abs(t[0].x - t[1].x) < 0.5, ia = (t, e, o) => t > Math.min(e, o) + 0.5 && t < Math.max(e, o) - 0.5;
4617
4643
  function rs(t, e) {
@@ -4635,7 +4661,7 @@ function Zc(t) {
4635
4661
  (d, c) => c !== s && fi(n[s], n[c]) && o[s].some(
4636
4662
  (u) => o[c].some((i) => {
4637
4663
  const f = rs(u, i);
4638
- return f && a.some((h) => Fo(f, h, Qc / 2));
4664
+ return f && a.some((h) => To(f, h, Qc / 2));
4639
4665
  })
4640
4666
  )
4641
4667
  ) && e.add(s);
@@ -4908,7 +4934,7 @@ function yl(t) {
4908
4934
  }))
4909
4935
  ) : [];
4910
4936
  }
4911
- class Oe extends Error {
4937
+ class Ae extends Error {
4912
4938
  constructor(e, o = 0, n = 0) {
4913
4939
  super((o ? `Line ${o}${n ? `, column ${n}` : ""}: ` : "") + e), this.line = o, this.column = n, this.name = "DslError";
4914
4940
  }
@@ -4932,7 +4958,7 @@ function bl(t, e = 0) {
4932
4958
  }
4933
4959
  if (f === '"') {
4934
4960
  if (d && i + 1 < t.length && !/[\s#]/.test(t[i + 1]) && !t.startsWith("//", i + 1))
4935
- throw new Oe(Ml, e, i + 1);
4961
+ throw new Ae(Ml, e, i + 1);
4936
4962
  d || (r = i), d = !d, a += f;
4937
4963
  continue;
4938
4964
  }
@@ -4941,7 +4967,7 @@ function bl(t, e = 0) {
4941
4967
  return u(), { tokens: o, columns: n, comment: t.slice(i).trim() };
4942
4968
  !d && /\s/.test(f) ? u() : a += f;
4943
4969
  }
4944
- if (d) throw new Oe("Unclosed quoted string.", e, r + 1);
4970
+ if (d) throw new Ae("Unclosed quoted string.", e, r + 1);
4945
4971
  return u(), { tokens: o, columns: n };
4946
4972
  }
4947
4973
  function ca(t, e, o) {
@@ -4949,7 +4975,7 @@ function ca(t, e, o) {
4949
4975
  try {
4950
4976
  return wl(JSON.parse(t));
4951
4977
  } catch {
4952
- throw new Oe(
4978
+ throw new Ae(
4953
4979
  'Invalid escape in a quoted string. Use \\" for a quote, \\\\ for a backslash and \\n for a line break.',
4954
4980
  e,
4955
4981
  o
@@ -4957,8 +4983,8 @@ function ca(t, e, o) {
4957
4983
  }
4958
4984
  }
4959
4985
  function vl(t) {
4960
- if (typeof t != "string") throw new Oe("Source must be text.");
4961
- if (t.length > 3e5) throw new Oe("Limit: 300,000 source characters.");
4986
+ if (typeof t != "string") throw new Ae("Source must be text.");
4987
+ if (t.length > 3e5) throw new Ae("Limit: 300,000 source characters.");
4962
4988
  return { lines: t.split(/\r?\n/).map((o, n) => {
4963
4989
  const a = n + 1, { tokens: s, columns: r, comment: d } = bl(o, a);
4964
4990
  if (!s.length) return d ? { kind: "comment", text: d } : { kind: "blank" };
@@ -4967,14 +4993,14 @@ function vl(t) {
4967
4993
  const g = p.indexOf("="), y = r[m + 1];
4968
4994
  if (g > 0 && !p.startsWith('"')) {
4969
4995
  const P = p.slice(0, g);
4970
- if (l.some(([A]) => A === P)) throw new Oe(`Duplicate attribute ${P}.`, a);
4996
+ if (l.some(([O]) => O === P)) throw new Ae(`Duplicate attribute ${P}.`, a);
4971
4997
  l.push([P, ca(p.slice(g + 1), a, y + g + 1)]);
4972
4998
  } else h.push(ca(p, a, y));
4973
4999
  }), { kind: "statement", command: f, ...i ? { mark: i } : {}, args: h, attrs: l, comment: d, line: a };
4974
5000
  }) };
4975
5001
  }
4976
5002
  const ui = { wide: 2, slide: 1.78, square: 1, page: 0.77, tall: 0.6 };
4977
- function qo(t, e, o) {
5003
+ function Bo(t, e, o) {
4978
5004
  const n = hn(t, e);
4979
5005
  for (let a = o; a && a !== "root"; a = hn(t, a))
4980
5006
  if (hn(t, a) === n) return a === e ? void 0 : a;
@@ -5003,7 +5029,7 @@ const kl = ["near", "nudge", "stay", "pin"], la = {
5003
5029
  "layered",
5004
5030
  "tree",
5005
5031
  "grid"
5006
- ], Bo = {
5032
+ ], qo = {
5007
5033
  "rank-gap": { key: "rankGap", min: 12, max: 220 },
5008
5034
  "group-gap": { key: "groupGap", min: 12, max: 180 },
5009
5035
  "node-gap": { key: "nodeGap", min: 4, max: 160 },
@@ -5034,10 +5060,10 @@ const kl = ["near", "nudge", "stay", "pin"], la = {
5034
5060
  standoff: { key: "standoff", min: 0, max: 40 }
5035
5061
  };
5036
5062
  function Sl(t, e) {
5037
- return e && t === "gap" ? "Engine lines space boxes with node-gap= and rank-gap=." : !e && t in Bo ? `${t}= needs an engine: add engine=layered or another engine.` : t === "fit" ? "fit= goes on the layout root line." : "draftably skill print lists the layout settings.";
5063
+ return e && t === "gap" ? "Engine lines space boxes with node-gap= and rank-gap=." : !e && t in qo ? `${t}= needs an engine: add engine=layered or another engine.` : t === "fit" ? "fit= goes on the layout root line." : "draftably skill print lists the layout settings.";
5038
5064
  }
5039
- const El = /^[A-Za-z_][A-Za-z0-9_.-]*$/, wo = /^[A-Za-z_][A-Za-z0-9_-]*$/, pi = ["box", "pill", "circle", "diamond", "text", "marker"], Il = pi.filter((t) => t !== "marker"), ua = ["box", "soft", "none"], Ol = /^[A-Za-z]{1,8}$/, pa = ["auto", "left", "right", "top", "bottom"];
5040
- function Al(t) {
5065
+ const El = /^[A-Za-z_][A-Za-z0-9_.-]*$/, wo = /^[A-Za-z_][A-Za-z0-9_-]*$/, pi = ["box", "pill", "circle", "diamond", "text", "marker"], Il = pi.filter((t) => t !== "marker"), ua = ["box", "soft", "none"], Al = /^[A-Za-z]{1,8}$/, pa = ["auto", "left", "right", "top", "bottom"];
5066
+ function Ol(t) {
5041
5067
  const e = typeof t == "string" ? vl(t) : t, o = {
5042
5068
  title: "Untitled diagram",
5043
5069
  objects: [],
@@ -5059,7 +5085,7 @@ function Al(t) {
5059
5085
  for (const c of e.lines) {
5060
5086
  if (c.kind !== "statement") continue;
5061
5087
  const u = c.line, { command: i, args: f } = c, h = new Map(c.attrs), l = (M) => {
5062
- throw new Oe(M, u);
5088
+ throw new Ae(M, u);
5063
5089
  }, p = (M, x) => {
5064
5090
  M || l(x);
5065
5091
  }, m = (M) => {
@@ -5068,7 +5094,7 @@ function Al(t) {
5068
5094
  }, g = (M, x = M) => p(f.length >= M && f.length <= x, `Wrong number of arguments for ${i}.`), y = (M) => (p(
5069
5095
  M && !M.quoted && El.test(M.value),
5070
5096
  "Expected a stable identifier (letters, digits, _, . or -)."
5071
- ), M.value), P = (M) => M?.value ?? "", A = (M, x, N = -1e5, z = 1e5) => {
5097
+ ), M.value), P = (M) => M?.value ?? "", O = (M, x, N = -1e5, z = 1e5) => {
5072
5098
  const mt = h.get(M);
5073
5099
  if (mt === void 0) return x;
5074
5100
  const it = Number(mt.value);
@@ -5078,20 +5104,20 @@ function Al(t) {
5078
5104
  ), it;
5079
5105
  }, w = (M, x) => {
5080
5106
  const N = h.get(M);
5081
- return !N.quoted && Ol.test(N.value) ? N.value : A(M, x, x, 1e6);
5107
+ return !N.quoted && Al.test(N.value) ? N.value : O(M, x, x, 1e6);
5082
5108
  }, k = (M, x, N) => {
5083
5109
  const z = h.get(M)?.value ?? x;
5084
5110
  return p(N.includes(z), `Expected ${M}=${N.join("|")}; got ${z}.`), z;
5085
- }, T = (M) => {
5111
+ }, F = (M) => {
5086
5112
  const x = Number(M.value);
5087
5113
  return p(
5088
5114
  !M.quoted && $o.includes(x),
5089
5115
  `Expected shade=${$o.join("|")}; got ${M.value}.`
5090
5116
  ), x;
5091
- }, F = (M) => {
5117
+ }, T = (M) => {
5092
5118
  const x = h.get(M);
5093
5119
  return p(
5094
- x.quoted && Ar.test(x.value),
5120
+ x.quoted && Or.test(x.value),
5095
5121
  `Expected ${M}="#rrggbb" in double quotes; got ${x.value || "nothing"}.`
5096
5122
  ), x.value.toUpperCase();
5097
5123
  }, j = (M) => {
@@ -5112,12 +5138,12 @@ function Al(t) {
5112
5138
  }, S = (M) => {
5113
5139
  const x = {};
5114
5140
  for (const [N, z] of Object.entries(M))
5115
- h.has(N) && ("min" in z ? x[z.key] = A(N, 0, z.min, z.max) : z.choices.length ? x[z.key] = k(N, z.choices[0], z.choices) : x[z.key] = y(h.get(N)));
5141
+ h.has(N) && ("min" in z ? x[z.key] = O(N, 0, z.min, z.max) : z.choices.length ? x[z.key] = k(N, z.choices[0], z.choices) : x[z.key] = y(h.get(N)));
5116
5142
  return x;
5117
5143
  };
5118
5144
  switch (i) {
5119
5145
  case "diagram":
5120
- g(1), m(["version", "width"]), p(!d, "Only one diagram declaration is allowed."), d = u, o.title = P(f[0]), A("version", 1, 1, 1), o.title && ((o.appearance.heading ??= {}).title = o.title), h.has("width") && ((o.appearance.heading ??= {}).width = A("width", 0, 160, 8e3));
5146
+ g(1), m(["version", "width"]), p(!d, "Only one diagram declaration is allowed."), d = u, o.title = P(f[0]), O("version", 1, 1, 1), o.title && ((o.appearance.heading ??= {}).title = o.title), h.has("width") && ((o.appearance.heading ??= {}).width = O("width", 0, 160, 8e3));
5121
5147
  break;
5122
5148
  case "compare": {
5123
5149
  g(0, 2), m(["direction", "aspect"]), j("compare");
@@ -5126,7 +5152,7 @@ function Al(t) {
5126
5152
  before: P(f[0]) || "Before",
5127
5153
  after: P(f[1]) || "After",
5128
5154
  ...M !== "auto" ? { direction: M } : {},
5129
- ...h.has("aspect") ? { aspect: A("aspect", 1.6, 0.25, 8) } : {}
5155
+ ...h.has("aspect") ? { aspect: O("aspect", 1.6, 0.25, 8) } : {}
5130
5156
  };
5131
5157
  break;
5132
5158
  }
@@ -5190,7 +5216,7 @@ function Al(t) {
5190
5216
  !h.get("color")?.quoted && wo.test(x),
5191
5217
  `Expected color=auto, a built-in color (${Go.join(", ")}) or a theme-color name; got ${x}.`
5192
5218
  );
5193
- const N = h.has("shade") ? T(h.get("shade")) : void 0;
5219
+ const N = h.has("shade") ? F(h.get("shade")) : void 0;
5194
5220
  o.objects.push({
5195
5221
  id: M,
5196
5222
  type: i,
@@ -5206,7 +5232,7 @@ function Al(t) {
5206
5232
  ...i === "group" && k("fold", "auto", ["auto", "never"]) === "never" ? { fold: "never" } : {},
5207
5233
  ...i === "group" && k("frame", "box", ua) !== "box" ? { frame: k("frame", "box", ua) } : {},
5208
5234
  ...h.has("span") ? {
5209
- span: h.get("span").value === "var" ? "var" : A("span", 1, 1, 4096)
5235
+ span: h.get("span").value === "var" ? "var" : O("span", 1, 1, 4096)
5210
5236
  } : {},
5211
5237
  line: u
5212
5238
  });
@@ -5266,7 +5292,7 @@ function Al(t) {
5266
5292
  g(1), p(
5267
5293
  da.includes(x),
5268
5294
  `Unknown layout engine ${x}; use ${da.join(", ")}.`
5269
- ), z(["engine", ...mt, ...Object.keys(Bo)]), it = { algorithm: x, params: S(Bo) };
5295
+ ), z(["engine", ...mt, ...Object.keys(qo)]), it = { algorithm: x, params: S(qo) };
5270
5296
  else {
5271
5297
  g(2);
5272
5298
  const Q = f[1]?.value;
@@ -5291,15 +5317,15 @@ function Al(t) {
5291
5317
  direction: k("direction", "auto", ["auto", "right", "down"]),
5292
5318
  fold: x ? "auto" : k("fold", "auto", ["auto", "never"]),
5293
5319
  ...h.has("fit") ? { fit: k("fit", "slide", Object.keys(ui)) } : {},
5294
- ...h.has("columns") ? { columns: A("columns", 1, 1, 512) } : {},
5320
+ ...h.has("columns") ? { columns: O("columns", 1, 1, 512) } : {},
5295
5321
  ...h.has("unit") ? {
5296
5322
  unit: k("unit", "byte", ["bit", "byte"]),
5297
5323
  ruler: k("ruler", "on", ["on", "off"]) === "on",
5298
- ...h.has("unit-width") ? { unitWidth: A("unit-width", 24, 8, 200) } : {}
5324
+ ...h.has("unit-width") ? { unitWidth: O("unit-width", 24, 8, 200) } : {}
5299
5325
  } : {},
5300
- gap: A("gap", 28, 8, 300),
5301
- minWidth: A("min-width", 0, 0, 1e4),
5302
- minHeight: A("min-height", 0, 0, 1e4),
5326
+ gap: O("gap", 28, 8, 300),
5327
+ minWidth: O("min-width", 0, 0, 1e4),
5328
+ minHeight: O("min-height", 0, 0, 1e4),
5303
5329
  line: u
5304
5330
  });
5305
5331
  break;
@@ -5310,7 +5336,7 @@ function Al(t) {
5310
5336
  p(Ps.includes(M), `Unknown theme ${M}; use ${Ps.join(", ")}.`), o.appearance.theme = M, o.themeLine = u;
5311
5337
  const x = o.appearance.overrides;
5312
5338
  for (const [N, z] of Object.entries(fa))
5313
- h.has(N) && (z === "paddingX" || z === "paddingY" || z === "radius" ? x[z] = A(N, 0, Fs[z].min, Fs[z].max) : z === "titleFont" || z === "annotationFont" ? x[z] = k(N, "sans", xr) : x[z] = F(N));
5339
+ h.has(N) && (z === "paddingX" || z === "paddingY" || z === "radius" ? x[z] = O(N, 0, Ts[z].min, Ts[z].max) : z === "titleFont" || z === "annotationFont" ? x[z] = k(N, "sans", xr) : x[z] = T(N));
5314
5340
  break;
5315
5341
  }
5316
5342
  case "theme-color": {
@@ -5320,11 +5346,11 @@ function Al(t) {
5320
5346
  !f[0].quoted && wo.test(M) && M !== "auto",
5321
5347
  "Expected a color family name (letters, digits, _ or -)."
5322
5348
  );
5323
- const x = h.has("shade") ? T(h.get("shade")) : 500;
5349
+ const x = h.has("shade") ? F(h.get("shade")) : 500;
5324
5350
  j(`theme-color:${M}:${x}`);
5325
5351
  const N = { family: M, shade: x };
5326
5352
  for (const z of ["fill", "stroke", "ink"])
5327
- h.has(z) && (N[z] = F(z));
5353
+ h.has(z) && (N[z] = T(z));
5328
5354
  p(
5329
5355
  to(M) || N.fill && N.stroke && N.ink,
5330
5356
  `${M} is not a built-in color, so shade ${x} needs fill, stroke and ink.`
@@ -5336,8 +5362,8 @@ function Al(t) {
5336
5362
  g(3), m([]);
5337
5363
  const N = f[1].value;
5338
5364
  p(
5339
- !f[1].quoted && Ts.includes(N),
5340
- `Expected legend line ${Ts.join("|")} "meaning".`
5365
+ !f[1].quoted && Fs.includes(N),
5366
+ `Expected legend line ${Fs.join("|")} "meaning".`
5341
5367
  ), j(`legend:line:${N}`), p(P(f[2]).trim(), "A legend entry needs its meaning in quotes."), (o.appearance.legend ??= []).push({ line: N, label: P(f[2]) }), o.legendLines.push(u);
5342
5368
  break;
5343
5369
  }
@@ -5347,7 +5373,7 @@ function Al(t) {
5347
5373
  !f[0].quoted && wo.test(M) && M !== "auto",
5348
5374
  `Expected legend family "meaning", with a built-in color (${Go.join(", ")}) or a theme-color name.`
5349
5375
  ), j(`legend:${M}:${h.get("shade")?.value ?? ""}`);
5350
- const x = h.has("shade") ? T(h.get("shade")) : void 0;
5376
+ const x = h.has("shade") ? F(h.get("shade")) : void 0;
5351
5377
  p(P(f[1]).trim(), "A legend entry needs its meaning in quotes."), (o.appearance.legend ??= []).push({
5352
5378
  family: M,
5353
5379
  label: P(f[1]),
@@ -5360,7 +5386,7 @@ function Al(t) {
5360
5386
  text: f[0].value,
5361
5387
  ...h.has("near") ? { near: y(h.get("near")) } : {},
5362
5388
  ...h.has("side") ? { side: k("side", "below", pc) } : {},
5363
- ...h.has("width") ? { width: A("width", ni, 80, 1200) } : {}
5389
+ ...h.has("width") ? { width: O("width", ni, 80, 1200) } : {}
5364
5390
  }), o.noteLines.push(u);
5365
5391
  break;
5366
5392
  }
@@ -5411,25 +5437,25 @@ function Al(t) {
5411
5437
  id: M,
5412
5438
  ref: x,
5413
5439
  side: k("side", "right", ["right", "left", "above", "below"]),
5414
- gap: A("gap", 28, 0, 2e3),
5415
- offset: A("offset", 0),
5440
+ gap: O("gap", 28, 0, 2e3),
5441
+ offset: O("offset", 0),
5416
5442
  strength: k("strength", "prefer", ["prefer", "required"]),
5417
5443
  line: u
5418
5444
  });
5419
5445
  } else if (i === "nudge")
5420
- m(["dx", "dy"]), o.hints.push({ type: "nudge", id: M, dx: A("dx", 0), dy: A("dy", 0), line: u });
5446
+ m(["dx", "dy"]), o.hints.push({ type: "nudge", id: M, dx: O("dx", 0), dy: O("dy", 0), line: u });
5421
5447
  else if (i === "stay")
5422
5448
  m(["x", "y", "weight"]), o.hints.push({
5423
5449
  type: "stay",
5424
5450
  id: M,
5425
5451
  // The root has no frame, so an arrangement can place objects left of or above 0,0.
5426
- x: A("x", 0),
5427
- y: A("y", 0),
5428
- weight: A("weight", 8, 1, 100),
5452
+ x: O("x", 0),
5453
+ y: O("y", 0),
5454
+ weight: O("weight", 8, 1, 100),
5429
5455
  line: u
5430
5456
  });
5431
5457
  else if (i === "pin")
5432
- m(["x", "y"]), o.hints.push({ type: "pin", id: M, x: A("x", 0, 0), y: A("y", 0, 0), line: u });
5458
+ m(["x", "y"]), o.hints.push({ type: "pin", id: M, x: O("x", 0, 0), y: O("y", 0, 0), line: u });
5433
5459
  else {
5434
5460
  m(["width", "height", "min-height"]);
5435
5461
  const x = h.get("height")?.value === "auto";
@@ -5439,9 +5465,9 @@ function Al(t) {
5439
5465
  ), o.hints.push({
5440
5466
  type: "size",
5441
5467
  id: M,
5442
- width: A("width", 164, 40, 1200),
5443
- ...x ? {} : { height: A("height", 56, 24, 1200) },
5444
- ...h.has("min-height") ? { minHeight: A("min-height", 24, 24, 1200) } : {},
5468
+ width: O("width", 164, 40, 1200),
5469
+ ...x ? {} : { height: O("height", 56, 24, 1200) },
5470
+ ...h.has("min-height") ? { minHeight: O("min-height", 24, 24, 1200) } : {},
5445
5471
  line: u
5446
5472
  });
5447
5473
  }
@@ -5456,8 +5482,8 @@ function Al(t) {
5456
5482
  l(`Unknown statement ${i}.`);
5457
5483
  }
5458
5484
  }
5459
- if (o.objects.length > 500) throw new Oe("Limit: 500 nodes and groups.");
5460
- if (o.edges.length > 1200) throw new Oe("Limit: 1,200 edges.");
5485
+ if (o.objects.length > 500) throw new Ae("Limit: 500 nodes and groups.");
5486
+ if (o.edges.length > 1200) throw new Ae("Limit: 1,200 edges.");
5461
5487
  return Ll(o), o;
5462
5488
  }
5463
5489
  function hn(t, e) {
@@ -5471,7 +5497,7 @@ function Ll(t) {
5471
5497
  `${l} is a ${e.get(l)?.frame} group, so it has no ${m} of its own. Use frame=box, or ${m === "layout" ? "set the layout of the container around it" : "place its members"}.`,
5472
5498
  p
5473
5499
  ), n = (l) => hn(e, l), a = (l, p, m) => {
5474
- if (!l) throw new Oe(p, m);
5500
+ if (!l) throw new Ae(p, m);
5475
5501
  }, s = (l, p) => a(e.has(l), `Unknown node/group ${l}.`, p), r = (l, p) => a(l === "root" || e.get(l)?.type === "group", `Unknown container ${l}.`, p), d = /* @__PURE__ */ new Map();
5476
5502
  for (const l of t.appearance.colors)
5477
5503
  d.has(l.family) || d.set(l.family, /* @__PURE__ */ new Set()), d.get(l.family).add(l.shade);
@@ -5486,7 +5512,7 @@ function Ll(t) {
5486
5512
  });
5487
5513
  for (const l of t.objects) {
5488
5514
  if (l.color !== "auto" && !to(l.color)) {
5489
- const m = d.get(l.color), g = l.shade ?? (l.type === "group" ? Or(t.appearance.theme) : Qe);
5515
+ const m = d.get(l.color), g = l.shade ?? (l.type === "group" ? Ar(t.appearance.theme) : Qe);
5490
5516
  a(
5491
5517
  m,
5492
5518
  `Unknown color ${l.color}. Define it with theme-color ${l.color} shade=… fill= stroke= ink=.`,
@@ -5636,7 +5662,7 @@ function Ll(t) {
5636
5662
  );
5637
5663
  } else
5638
5664
  s(l.id, l.line), o(l.id, l.line, "position"), l.type === "near" && (s(l.ref, l.line), o(l.ref, l.line, "position"), a(
5639
- qo(e, l.id, l.ref) !== void 0,
5665
+ Bo(e, l.id, l.ref) !== void 0,
5640
5666
  `Relative placement is between siblings, or with something inside a sibling group. ${l.id} is inside ${n(l.id)}; place ${n(l.id)} relative to ${l.ref} instead.`,
5641
5667
  l.line
5642
5668
  )), l.type === "size" && a(
@@ -5645,12 +5671,12 @@ function Ll(t) {
5645
5671
  l.line
5646
5672
  );
5647
5673
  }
5648
- const sn = { width: 1100, height: 720 }, An = 12, $l = 56, ga = 24, ma = 0, Gl = 56, ya = { w: 260, h: 110 }, xa = (t, e) => Math.max(e.x - t.x - t.w, t.x - e.x - e.w, e.y - t.y - t.h, t.y - e.y - e.h), Wt = (t) => Math.round(t);
5674
+ const sn = { width: 1100, height: 720 }, On = 12, $l = 56, ga = 24, ma = 0, Gl = 56, ya = { w: 260, h: 110 }, xa = (t, e) => Math.max(e.x - t.x - t.w, t.x - e.x - e.w, e.y - t.y - t.h, t.y - e.y - e.h), Wt = (t) => Math.round(t);
5649
5675
  async function gi(t) {
5650
- const e = Al(t), o = e.layouts.find((r) => r.scope === "root" && r.fit);
5676
+ const e = Ol(t), o = e.layouts.find((r) => r.scope === "root" && r.fit);
5651
5677
  if (!o?.fit) return wa(e);
5652
5678
  const n = ui[o.fit], a = [];
5653
- for (const r of Fl(o)) {
5679
+ for (const r of Tl(o)) {
5654
5680
  const d = await wa({
5655
5681
  ...e,
5656
5682
  layouts: e.layouts.map((c) => c === o ? { ...c, ...r.layout } : c)
@@ -5673,20 +5699,20 @@ async function gi(t) {
5673
5699
  }), s.scene;
5674
5700
  }
5675
5701
  function wa(t) {
5676
- const e = Bl(t), o = Pl(e);
5702
+ const e = ql(t), o = Pl(e);
5677
5703
  return Kl(o).then(
5678
- (n) => ql(mi(Ul(Tl(co(o, n), e), t)))
5704
+ (n) => Bl(mi(Ul(Fl(co(o, n), e), t)))
5679
5705
  );
5680
5706
  }
5681
5707
  function Pl(t) {
5682
5708
  if (!t.appearance.compare || !t.edges.some((n) => n.was)) return t;
5683
- const e = Re(t.appearance), o = (n) => n ? Te(n, e).w : 0;
5709
+ const e = Re(t.appearance), o = (n) => n ? Fe(n, e).w : 0;
5684
5710
  return {
5685
5711
  ...t,
5686
5712
  edges: t.edges.map((n) => n.was && o(n.was) > o(n.label) ? { ...n, label: n.was } : n)
5687
5713
  };
5688
5714
  }
5689
- function Tl(t, e) {
5715
+ function Fl(t, e) {
5690
5716
  if (t.model.edges === e.edges) return t;
5691
5717
  const o = new Map(e.edges.map((n) => [n.id, n.label]));
5692
5718
  return {
@@ -5699,7 +5725,7 @@ function Mo(t) {
5699
5725
  const e = t.objects.filter((o) => o.parent === "root");
5700
5726
  return (Math.max(...e.map((o) => o.x + o.w)) - Math.min(...e.map((o) => o.x))) / (Math.max(...e.map((o) => o.y + o.h)) - Math.min(...e.map((o) => o.y)));
5701
5727
  }
5702
- function Fl(t) {
5728
+ function Tl(t) {
5703
5729
  const e = (a) => `reading ${a.direction === "auto" ? "as the engine picks" : a.direction}`, o = [
5704
5730
  { label: `as written (${e(t)})`, layout: {} }
5705
5731
  ];
@@ -5738,15 +5764,15 @@ function mi(t) {
5738
5764
  n.filter((W) => W.parent === _).map((W) => W.id)
5739
5765
  )
5740
5766
  ).map((_) => t.byId.get(_)).map((_) => o.has(_.id) ? _ : { ..._, w: Cl(_, e) }), u = new Map(c.map((_, W) => [_.id, W])), i = t.model.phases.length ? Math.max(...t.model.phases.map((_) => ce(_.label, e.annotation))) + 2 * Le : 0, f = a.length ? e.groupHeader : 0, h = (_) => c[_ - 1].parent !== c[_].parent, l = !!t.model.appearance.compare, p = (_) => [_.label, l ? _.was : ""].filter((W) => !!W), m = (_) => {
5741
- const W = p(_).map((b) => Te(b, e, !0));
5767
+ const W = p(_).map((b) => Fe(b, e, !0));
5742
5768
  return { w: Math.max(0, ...W.map((b) => b.w)), h: Math.max(0, ...W.map((b) => b.h)) };
5743
5769
  }, g = (_) => {
5744
- const W = p(_).map((b) => Bs(b, e));
5770
+ const W = p(_).map((b) => qs(b, e));
5745
5771
  return W.length ? {
5746
5772
  right: Math.max(...W.map((b) => b.right)),
5747
5773
  above: Math.max(...W.map((b) => b.above)),
5748
5774
  below: Math.max(...W.map((b) => b.below))
5749
- } : Bs(void 0, e);
5775
+ } : qs(void 0, e);
5750
5776
  }, y = /* @__PURE__ */ new Map(), P = c.map(() => []);
5751
5777
  for (const _ of t.edges) {
5752
5778
  const [W, b] = [u.get(_.source), u.get(_.target)].sort((et, at) => et - at);
@@ -5761,31 +5787,30 @@ function mi(t) {
5761
5787
  room: Y + ba + (h(W + 1) ? 2 * Le + c[W + 1].w / 2 : 0)
5762
5788
  });
5763
5789
  }
5764
- const A = [];
5790
+ const O = [];
5765
5791
  c.forEach((_, W) => {
5766
- if (!W) return void A.push(i + Le + _.w / 2);
5792
+ if (!W) return void O.push(i + Le + _.w / 2);
5767
5793
  const b = c[W - 1].w / 2 + Dl + (h(W) ? 2 * Le : 0) + _.w / 2;
5768
- A.push(Math.max(A[W - 1] + b, ...P[W].map((Y) => A[Y.from] + Y.room)));
5794
+ O.push(Math.max(O[W - 1] + b, ...P[W].map((Y) => O[Y.from] + Y.room)));
5769
5795
  });
5770
5796
  let w = f + Math.max(0, ...c.map((_) => _.h)) - jl, k = 0;
5771
- const T = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map();
5797
+ const F = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
5772
5798
  for (const _ of t.edges) {
5773
5799
  const W = m(_).h, b = _.source === _.target ? g(_) : void 0, Y = b ? b.above : W && W + 1;
5774
5800
  w = Math.ceil(
5775
5801
  Math.max(w + Math.max(Ma, W ? W + 8 : 0), k + ba + Y)
5776
- ), T.set(_.id, w), k = b ? w + b.below : 0, F.set(_.id, { from: w - Math.max(W, Ma / 2) - 4, to: Math.max(w, k) + 8 }), b && (w += ve.down);
5802
+ ), F.set(_.id, w), k = b ? w + b.below : 0, T.set(_.id, { from: w - Math.max(W, Ma / 2) - 4, to: Math.max(w, k) + 8 }), b && (w += ve.down);
5777
5803
  }
5778
5804
  const j = Math.max(w, k) + _l, $ = new Map(
5779
5805
  c.map((_) => {
5780
- const W = Wt(A[u.get(_.id)] - _.w / 2);
5806
+ const W = Wt(O[u.get(_.id)] - _.w / 2);
5781
5807
  return [_.id, { x: W, w: _.w }];
5782
5808
  })
5783
- ), v = (_) => Math.max($.get(_.id).x + _.w, A[u.get(_.id)] + (y.get(_.id) ?? 0)), S = t.objects.map((_) => {
5809
+ ), v = (_) => Math.max($.get(_.id).x + _.w, O[u.get(_.id)] + (y.get(_.id) ?? 0)), S = t.objects.map((_) => {
5784
5810
  if (_.type === "group") {
5785
5811
  const Y = c.filter((pt) => pt.parent === _.id), et = Wt(Math.min(...Y.map((pt) => $.get(pt.id).x)) - Le), at = Wt(Math.max(...Y.map((pt) => v(pt))) + Le - et);
5786
5812
  return {
5787
5813
  ..._,
5788
- shade: _.shade ?? 50,
5789
5814
  x: et,
5790
5815
  y: 0,
5791
5816
  w: at,
@@ -5810,18 +5835,18 @@ function mi(t) {
5810
5835
  };
5811
5836
  }), M = Math.min(0, ...S.map((_) => _.x)) - (i ? 0 : Le), x = Math.max(
5812
5837
  ...S.map((_) => _.x + _.w + Le),
5813
- ...c.map((_) => A[u.get(_.id)] + (y.get(_.id) ?? 0))
5838
+ ...c.map((_) => O[u.get(_.id)] + (y.get(_.id) ?? 0))
5814
5839
  ), N = {
5815
5840
  x: M - an,
5816
5841
  y: -an,
5817
5842
  w: x - M + 2 * an,
5818
5843
  h: j + Le + 2 * an
5819
- }, z = t.model.appearance.notes ?? [], mt = new Map([...T].filter(([_]) => !t.byId.has(_))), it = xc(e, z, mt, {
5844
+ }, z = t.model.appearance.notes ?? [], mt = new Map([...F].filter(([_]) => !t.byId.has(_))), it = xc(e, z, mt, {
5820
5845
  left: M - (i ? an : va),
5821
5846
  right: x + va,
5822
5847
  top: 0
5823
5848
  }), ht = it.filter((_) => _ !== null), Q = ht.length ? Cs([N, Cs(ht, an)]) : N, H = Q.x < N.x ? N.x : void 0, J = t.model.phases.map((_) => {
5824
- const W = _.ids.map((b) => F.get(b));
5849
+ const W = _.ids.map((b) => T.get(b));
5825
5850
  return {
5826
5851
  id: _.id,
5827
5852
  label: _.label,
@@ -5838,7 +5863,7 @@ function mi(t) {
5838
5863
  ...t,
5839
5864
  objects: S,
5840
5865
  byId: new Map(S.map((_) => [_.id, _])),
5841
- edges: t.edges.map((_) => ({ ..._, lane: void 0, row: T.get(_.id) })),
5866
+ edges: t.edges.map((_) => ({ ..._, lane: void 0, row: F.get(_.id) })),
5842
5867
  sequence: {
5843
5868
  panel: Q,
5844
5869
  phases: C,
@@ -5847,7 +5872,7 @@ function mi(t) {
5847
5872
  }
5848
5873
  };
5849
5874
  }
5850
- function ql(t) {
5875
+ function Bl(t) {
5851
5876
  const e = t.model.wasOrder?.ids.flatMap((s) => t.edges.filter((r) => r.id === s));
5852
5877
  if (!e || !t.sequence) return t;
5853
5878
  const o = [...e], n = mi({
@@ -5866,7 +5891,7 @@ function ql(t) {
5866
5891
  }
5867
5892
  };
5868
5893
  }
5869
- function Bl(t) {
5894
+ function ql(t) {
5870
5895
  if (!t.objects.some((n) => n.frame)) return t;
5871
5896
  const e = new Map(t.objects.map((n) => [n.id, n])), o = (n) => {
5872
5897
  const a = [];
@@ -5890,7 +5915,7 @@ function ls(t, e, o = 0) {
5890
5915
  const Hl = 8;
5891
5916
  function io(t = [], e = [], o) {
5892
5917
  const n = t.filter((s) => !e.includes(s)).length, a = e.filter((s) => !t.includes(s)).length;
5893
- return !n && !a ? 0 : (n + a) * On + (o && a ? oo : 0) + Hl;
5918
+ return !n && !a ? 0 : (n + a) * An + (o && a ? oo : 0) + Hl;
5894
5919
  }
5895
5920
  function yi(t, e, o, n) {
5896
5921
  const a = new Set(t.flatMap((c) => o(c) ?? [])), s = (c, u) => (o(c) ?? []).filter((i) => !u.has(i)), r = new Set(e.flatMap((c) => o(c) ?? []));
@@ -5899,7 +5924,7 @@ function yi(t, e, o, n) {
5899
5924
  for (const u of e) d = Math.max(d, io(s(c, r), s(u, a), n));
5900
5925
  return d;
5901
5926
  }
5902
- const qn = (t, e) => t.x < e.x + e.w && t.x + t.w > e.x && t.y < e.y + e.h && t.y + t.h > e.y, zl = (t, e) => ({
5927
+ const Bn = (t, e) => t.x < e.x + e.w && t.x + t.w > e.x && t.y < e.y + e.h && t.y + t.h > e.y, zl = (t, e) => ({
5903
5928
  x: t.x - e,
5904
5929
  y: t.y - e,
5905
5930
  w: t.w + 2 * e,
@@ -5935,7 +5960,7 @@ function Ul(t, e) {
5935
5960
  for (const f of [...o].sort((h, l) => d(l.id) - d(h.id))) {
5936
5961
  const h = [...a.values()].filter(($) => r($.id, f.id)), l = a.get(hn(n, f.id)), p = l ? Va(l, Kn(t.look, l.titleLines)) : { x: 0, y: 0 }, m = [...a.values()].filter(
5937
5962
  ($) => !$.frame && !r($.id, f.id) && !r(f.id, $.id)
5938
- ), g = h.flatMap(($) => c($).map((v) => zl(v, On)));
5963
+ ), g = h.flatMap(($) => c($).map((v) => zl(v, An)));
5939
5964
  let y = [], P = 0;
5940
5965
  if (g.length) {
5941
5966
  const $ = g.reduce((it, ht) => ht.y < it.y || ht.y === it.y && ht.x < it.x ? ht : it);
@@ -5946,7 +5971,7 @@ function Ul(t, e) {
5946
5971
  w: Math.max(...y.map((it) => it.x + it.w)) - v,
5947
5972
  h: Math.max(...y.map((it) => it.y + it.h)) - S
5948
5973
  };
5949
- m.some((it) => qn(it, M)) || (y = [M]);
5974
+ m.some((it) => Bn(it, M)) || (y = [M]);
5950
5975
  const x = (it, ht) => Math.max(ht.x - (it.x + it.w), it.x - (ht.x + ht.w), ht.y - (it.y + it.h), it.y - (ht.y + ht.h), 0), N = [y[0]], z = y.slice(1), mt = [];
5951
5976
  for (; z.length; ) {
5952
5977
  let it = { gap: 1 / 0, a: y[0], i: 0 };
@@ -5956,27 +5981,27 @@ function Ul(t, e) {
5956
5981
  _ < it.gap && (it = { gap: _, a: H, i: C });
5957
5982
  });
5958
5983
  const [ht] = z.splice(it.i, 1);
5959
- if (N.push(ht), qn(it.a, ht)) continue;
5984
+ if (N.push(ht), Bn(it.a, ht)) continue;
5960
5985
  const Q = Wl(it.a, ht);
5961
- m.some((H) => qn(H, Q)) ? P++ : mt.push(Q);
5986
+ m.some((H) => Bn(H, Q)) ? P++ : mt.push(Q);
5962
5987
  }
5963
5988
  y.push(...mt);
5964
5989
  }
5965
- const A = y.length ? Math.min(...y.map(($) => $.x)) : p.x, w = y.length ? Math.min(...y.map(($) => $.y)) : p.y, k = y.length ? Math.max(...y.map(($) => $.x + $.w)) : p.x, T = y.length ? Math.max(...y.map(($) => $.y + $.h)) : p.y, F = { x: A - p.x, y: w - p.y };
5990
+ const O = y.length ? Math.min(...y.map(($) => $.x)) : p.x, w = y.length ? Math.min(...y.map(($) => $.y)) : p.y, k = y.length ? Math.max(...y.map(($) => $.x + $.w)) : p.x, F = y.length ? Math.max(...y.map(($) => $.y + $.h)) : p.y, T = { x: O - p.x, y: w - p.y };
5966
5991
  if (a.set(f.id, {
5967
5992
  ...f,
5968
- x: A,
5993
+ x: O,
5969
5994
  y: w,
5970
- w: k - A,
5971
- h: T - w,
5972
- localX: F.x,
5973
- localY: F.y,
5974
- baseX: F.x,
5975
- baseY: F.y,
5995
+ w: k - O,
5996
+ h: F - w,
5997
+ localX: T.x,
5998
+ localY: T.y,
5999
+ baseX: T.x,
6000
+ baseY: T.y,
5976
6001
  depth: d(f.id),
5977
- hull: y.map(($) => ({ x: $.x - A, y: $.y - w, w: $.w, h: $.h }))
6002
+ hull: y.map(($) => ({ x: $.x - O, y: $.y - w, w: $.w, h: $.h }))
5978
6003
  }), f.frame !== "soft") continue;
5979
- const j = m.filter(($) => y.some((v) => qn($, v)));
6004
+ const j = m.filter(($) => y.some((v) => Bn($, v)));
5980
6005
  j.length && s.push({
5981
6006
  level: "warning",
5982
6007
  code: "soft-overlap",
@@ -6018,7 +6043,7 @@ function $e(t) {
6018
6043
  const { width: e, height: o } = sn;
6019
6044
  return e >= 700 && e / o > 1.12 ? "right" : "down";
6020
6045
  }
6021
- function Bn(t, e) {
6046
+ function qn(t, e) {
6022
6047
  const o = new Map(t.objects.map((n) => [n.id, n.parent]));
6023
6048
  for (let n = e; n; n = n === "root" ? void 0 : o.get(n)) {
6024
6049
  const a = t.layouts.find((s) => s.scope === n);
@@ -6117,13 +6142,13 @@ function tf(t, e, o) {
6117
6142
  let a = Math.max(e, Ql);
6118
6143
  if (n <= a * Zl) return { w: n, lines: 1 };
6119
6144
  const s = () => tn(t, a - no, o.groupTitle, !0).length;
6120
- for (; s() > qs && a < n; ) a += 8;
6121
- return { w: Math.min(a, n), lines: Math.min(s(), qs) };
6145
+ for (; s() > Bs && a < n; ) a += 8;
6146
+ return { w: Math.min(a, n), lines: Math.min(s(), Bs) };
6122
6147
  }
6123
- const Sa = 16, ef = 1.5, nf = 640, Fe = 14;
6148
+ const Sa = 16, ef = 1.5, nf = 640, Te = 14;
6124
6149
  function bo(t, e, o, n) {
6125
- const a = Te(o, n);
6126
- return { a: t, b: e, w: a.w + 2 * Fe, h: a.h + 2 * Fe };
6150
+ const a = Fe(o, n);
6151
+ return { a: t, b: e, w: a.w + 2 * Te, h: a.h + 2 * Te };
6127
6152
  }
6128
6153
  function Ho(t, e, o, n, a) {
6129
6154
  let s = n;
@@ -6204,7 +6229,7 @@ function Ln(t, e) {
6204
6229
  for (const h of t) (f[c.get(h)] ||= []).push(h);
6205
6230
  return f.filter(Boolean);
6206
6231
  }
6207
- const xi = 3, Ia = 5, Oa = 1.25, Ve = 20, rf = 3, cf = 2, lf = 1;
6232
+ const xi = 3, Ia = 5, Aa = 1.25, Ve = 20, rf = 3, cf = 2, lf = 1;
6208
6233
  function ff(t, e) {
6209
6234
  const o = new Map(t.map((d) => [d, []]));
6210
6235
  for (const [d, c] of e) o.get(d)?.push(c);
@@ -6238,32 +6263,32 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6238
6263
  let y = m(d);
6239
6264
  const P = (Q) => Q.map((H) => [...H.ids].sort().join(",")).join("|");
6240
6265
  P(y) !== P(g) && (d = e, y = g);
6241
- const A = (Q, H) => {
6266
+ const O = (Q, H) => {
6242
6267
  const J = Math.min(...t.map((_) => Q.get(_.id)[H]));
6243
6268
  return Math.max(...t.map((_) => Q.get(_.id)[H] + p(_, H))) - J;
6244
- }, w = (Q, H, J = 1) => Q <= i * J || Q <= c * H * J, k = (Q) => w(A(Q, h), A(Q, l)), T = (Q) => k(Q) || A(Q, h) <= i * Oa;
6245
- if (t.length < u || k(d) && T(e)) return { positions: e };
6246
- const F = new Map(g.flatMap((Q, H) => Q.ids.map((J) => [J, H]))), j = (Q, H, J) => {
6247
- const [C, _] = [F.get(H), F.get(J)];
6269
+ }, w = (Q, H, J = 1) => Q <= i * J || Q <= c * H * J, k = (Q) => w(O(Q, h), O(Q, l)), F = (Q) => k(Q) || O(Q, h) <= i * Aa;
6270
+ if (t.length < u || k(d) && F(e)) return { positions: e };
6271
+ const T = new Map(g.flatMap((Q, H) => Q.ids.map((J) => [J, H]))), j = (Q, H, J) => {
6272
+ const [C, _] = [T.get(H), T.get(J)];
6248
6273
  return C !== void 0 && _ !== void 0 && Math.min(C, _) < Q && Math.max(C, _) >= Q;
6249
6274
  }, $ = (Q) => a.filter(([H, J]) => j(Q, H, J)).length, v = ff(
6250
6275
  t.map((Q) => Q.id),
6251
6276
  a
6252
6277
  ), S = (Q) => rf * [...r].filter((H) => a.some((J) => J[0] === H && j(Q, ...J))).length + cf * v.filter((H) => H.some((J) => j(Q, H[0], J))).length, M = (Q, H) => {
6253
- const J = (H ? s : []).filter((C) => j(Q, C.a, C.b)).map((C) => (o === "right" ? C.h : C.w) - 2 * Fe);
6278
+ const J = (H ? s : []).filter((C) => j(Q, C.a, C.b)).map((C) => (o === "right" ? C.h : C.w) - 2 * Te);
6254
6279
  return Math.max(
6255
6280
  n + 40,
6256
6281
  84,
6257
- J.length ? Math.max(...J) + 2 * Fe : 0,
6282
+ J.length ? Math.max(...J) + 2 * Te : 0,
6258
6283
  ($(Q) + 1) * Ve + J.reduce((C, _) => C + _, 0)
6259
6284
  );
6260
6285
  }, x = (Q, H) => {
6261
6286
  const J = H[H.length - 1].end - H[0].start, C = [], _ = new Map(H.flatMap((W) => W.ids.map((b) => [b, W.start])));
6262
6287
  for (let W = 1; W < Q; W++) {
6263
- const b = (Mt) => a.filter((xt) => j(Mt, ...xt)).reduce((xt, [O, E]) => {
6264
- const [L, R] = F.get(O) < F.get(E) ? [O, E] : [E, O];
6288
+ const b = (Mt) => a.filter((xt) => j(Mt, ...xt)).reduce((xt, [A, E]) => {
6289
+ const [L, R] = T.get(A) < T.get(E) ? [A, E] : [E, A];
6265
6290
  return xt + Math.abs(_.get(L) - at - (_.get(R) - H[Mt].start));
6266
- }, 0) / (J / Q), Y = H[0].start + J * W / Q, et = (Mt) => $(Mt) + S(Mt) + b(Mt) * lf + Math.abs(H[Mt].start - Y) / (J / Q) * 2, at = H[C.at(-1) ?? 0].start, pt = J / Q, ot = (Mt, xt, O) => H[Mt - 1].end - at >= pt * O && H[Mt - 1].end - at <= pt * (1 + xt) && H[H.length - 1].end - H[Mt].start <= pt * (Q - W) * (1 + xt), K = (Mt) => !S(Mt) && ot(Mt, 0.25, 0.5) ? 0 : !S(Mt) && ot(Mt, 0.5, 0) ? 1 : ot(Mt, 0.25, 0.5) ? 2 : 3;
6291
+ }, 0) / (J / Q), Y = H[0].start + J * W / Q, et = (Mt) => $(Mt) + S(Mt) + b(Mt) * lf + Math.abs(H[Mt].start - Y) / (J / Q) * 2, at = H[C.at(-1) ?? 0].start, pt = J / Q, ot = (Mt, xt, A) => H[Mt - 1].end - at >= pt * A && H[Mt - 1].end - at <= pt * (1 + xt) && H[H.length - 1].end - H[Mt].start <= pt * (Q - W) * (1 + xt), K = (Mt) => !S(Mt) && ot(Mt, 0.25, 0.5) ? 0 : !S(Mt) && ot(Mt, 0.5, 0) ? 1 : ot(Mt, 0.25, 0.5) ? 2 : 3;
6267
6292
  let ft = 0;
6268
6293
  for (let Mt = (C.at(-1) ?? 0) + 1; Mt < H.length; Mt++)
6269
6294
  (!ft || K(Mt) < K(ft) || K(Mt) === K(ft) && et(Mt) < et(ft)) && (ft = Mt);
@@ -6284,11 +6309,11 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6284
6309
  const et = [];
6285
6310
  for (const at of Y[0].ids) {
6286
6311
  if (r.has(at)) continue;
6287
- const pt = a.filter(([O, E]) => E === at && O !== at).map(([O]) => O), ot = a.filter(([O, E]) => O === at && E !== at).map(([, O]) => O);
6288
- if (!pt.length || pt.some((O) => C.get(O) !== b - 1)) continue;
6289
- const K = (O, E) => _.get(O) - J[E][0].start, ft = (O) => pt.reduce((E, L) => E + Math.abs(K(L, b - 1) - K(at, O)), 0) + ot.reduce((E, L) => E + Math.abs(K(at, O) - K(L, C.get(L))), 0), Mt = (O) => (O === b - 1 ? 0 : pt.length) + ot.filter((E) => C.get(E) !== O).length;
6312
+ const pt = a.filter(([A, E]) => E === at && A !== at).map(([A]) => A), ot = a.filter(([A, E]) => A === at && E !== at).map(([, A]) => A);
6313
+ if (!pt.length || pt.some((A) => C.get(A) !== b - 1)) continue;
6314
+ const K = (A, E) => _.get(A) - J[E][0].start, ft = (A) => pt.reduce((E, L) => E + Math.abs(K(L, b - 1) - K(at, A)), 0) + ot.reduce((E, L) => E + Math.abs(K(at, A) - K(L, C.get(L))), 0), Mt = (A) => (A === b - 1 ? 0 : pt.length) + ot.filter((E) => C.get(E) !== A).length;
6290
6315
  if (Mt(b - 1) > Mt(b) || ft(b - 1) >= ft(b)) continue;
6291
- const xt = pt.reduce((O, E) => _.get(E) > _.get(O) ? E : O);
6316
+ const xt = pt.reduce((A, E) => _.get(E) > _.get(A) ? E : A);
6292
6317
  et.push({ id: at, source: xt, saves: ft(b) - ft(b - 1) });
6293
6318
  }
6294
6319
  et.sort((at, pt) => pt.saves - at.saves);
@@ -6302,9 +6327,9 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6302
6327
  const ot = [];
6303
6328
  for (const [K, ft] of _) {
6304
6329
  const Mt = f.get(K);
6305
- let O = J.get(ft)[l] + (p(f.get(ft), l) - p(Mt, l)) / 2;
6306
- for (const E of ot) O < E.hi + n && O + p(Mt, l) > E.lo && (O = E.hi + n);
6307
- ot.push({ lo: O, hi: O + p(Mt, l) }), J.set(K, { ...J.get(K), [l]: O });
6330
+ let A = J.get(ft)[l] + (p(f.get(ft), l) - p(Mt, l)) / 2;
6331
+ for (const E of ot) A < E.hi + n && A + p(Mt, l) > E.lo && (A = E.hi + n);
6332
+ ot.push({ lo: A, hi: A + p(Mt, l) }), J.set(K, { ...J.get(K), [l]: A });
6308
6333
  }
6309
6334
  }
6310
6335
  const b = /* @__PURE__ */ new Map(), Y = [];
@@ -6313,13 +6338,13 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6313
6338
  const ft = W[ot + 1]?.[0].ids ?? [], Mt = [
6314
6339
  ...K.flatMap((V) => V.ids).filter((V) => !_.has(V)),
6315
6340
  ...ft.filter((V) => _.has(V))
6316
- ], xt = Math.min(...Mt.map((V) => J.get(V)[h])), O = Math.min(...Mt.map((V) => J.get(V)[l])), E = Math.max(...Mt.map((V) => J.get(V)[l] + p(f.get(V), l)));
6341
+ ], xt = Math.min(...Mt.map((V) => J.get(V)[h])), A = Math.min(...Mt.map((V) => J.get(V)[l])), E = Math.max(...Mt.map((V) => J.get(V)[l] + p(f.get(V), l)));
6317
6342
  for (const V of Mt) {
6318
- const G = J.get(V), X = G[h] - xt, D = G[l] - O + et;
6343
+ const G = J.get(V), X = G[h] - xt, D = G[l] - A + et;
6319
6344
  b.set(V, o === "right" ? { x: X, y: D } : { x: D, y: X });
6320
6345
  }
6321
6346
  const L = ot < Q.length ? M(Q[ot], C) : 0, R = Mt.filter((V) => !N.has(V)), Z = R.length ? R : Mt;
6322
- et += E - O + L, pt += Math.max(...Z.map((V) => J.get(V)[l] + p(f.get(V), l))) - Math.min(...Z.map((V) => J.get(V)[l])) + L, at = Math.max(
6347
+ et += E - A + L, pt += Math.max(...Z.map((V) => J.get(V)[l] + p(f.get(V), l))) - Math.min(...Z.map((V) => J.get(V)[l])) + L, at = Math.max(
6323
6348
  at,
6324
6349
  Math.max(...Mt.map((V) => J.get(V)[h] + p(f.get(V), h))) - xt
6325
6350
  ), Y.push(Mt);
@@ -6340,7 +6365,7 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6340
6365
  H.count === Q && w(H.length, H.depth) && (ht = Q);
6341
6366
  }
6342
6367
  for (let Q = Math.max(2, ht); Q <= g.length; Q++) {
6343
- const H = x(Q, y), J = it(H, g, e, !0), C = Q === ht ? Oa : 1;
6368
+ const H = x(Q, y), J = it(H, g, e, !0), C = Q === ht ? Aa : 1;
6344
6369
  if (J.count !== Q || !w(J.length, J.depth, C)) continue;
6345
6370
  const _ = mt(H, y), W = _.size ? it(H, g, e, !0, _) : void 0, b = W && w(W.length, W.depth, C) ? W : J;
6346
6371
  return { positions: b.out, fold: { bands: b.bands, axis: o } };
@@ -6350,11 +6375,11 @@ function ko(t, e, o, n, a, s = [], r = /* @__PURE__ */ new Set(), d = e, {
6350
6375
  function df(t, e, o, n, a) {
6351
6376
  const s = /* @__PURE__ */ new Map();
6352
6377
  for (const { scope: r, fold: d } of t) {
6353
- const c = d.axis === "right", u = (A) => c ? A.y : A.x, i = (A) => c ? A.y + A.h : A.x + A.w, f = (A) => c ? A.x : A.y, h = (A) => c ? A.x + A.w : A.y + A.h, l = (A) => (f(A) + h(A)) / 2, p = (A) => (u(A) + i(A)) / 2, m = (A, w) => f(A) < h(w) && h(A) > f(w), g = new Map(d.bands.flatMap((A, w) => A.map((k) => [k, w]))), y = (A) => g.get(n(A.id, r) ?? ""), P = (A) => [...o.values()].filter((w) => w.type !== "group" && y(w) === A);
6354
- for (let A = 0; A + 1 < d.bands.length; A++) {
6355
- const w = d.bands[A].map((ht) => o.get(ht)), k = d.bands[A + 1].map((ht) => o.get(ht)), T = Math.max(...w.map(i)), F = Math.min(...k.map(u)), j = Math.max(...w.map(h)) + Ve, $ = Math.min(...k.map(f)) - Ve, [v, S] = [P(A), P(A + 1)], M = e.flatMap((ht) => {
6378
+ const c = d.axis === "right", u = (O) => c ? O.y : O.x, i = (O) => c ? O.y + O.h : O.x + O.w, f = (O) => c ? O.x : O.y, h = (O) => c ? O.x + O.w : O.y + O.h, l = (O) => (f(O) + h(O)) / 2, p = (O) => (u(O) + i(O)) / 2, m = (O, w) => f(O) < h(w) && h(O) > f(w), g = new Map(d.bands.flatMap((O, w) => O.map((k) => [k, w]))), y = (O) => g.get(n(O.id, r) ?? ""), P = (O) => [...o.values()].filter((w) => w.type !== "group" && y(w) === O);
6379
+ for (let O = 0; O + 1 < d.bands.length; O++) {
6380
+ const w = d.bands[O].map((ht) => o.get(ht)), k = d.bands[O + 1].map((ht) => o.get(ht)), F = Math.max(...w.map(i)), T = Math.min(...k.map(u)), j = Math.max(...w.map(h)) + Ve, $ = Math.min(...k.map(f)) - Ve, [v, S] = [P(O), P(O + 1)], M = e.flatMap((ht) => {
6356
6381
  const Q = o.get(ht.source), H = o.get(ht.target);
6357
- if (y(Q) !== A || y(H) !== A + 1) return [];
6382
+ if (y(Q) !== O || y(H) !== O + 1) return [];
6358
6383
  if (ht.from !== "auto" || ht.to !== "auto") return [];
6359
6384
  const J = v.some((W) => u(W) > u(Q) && m(W, Q)), C = n(ht.target, r) !== ht.target || S.some((W) => u(W) < u(H) && m(W, H)), _ = (W, b) => u(W) < i(b) && i(W) > u(b);
6360
6385
  return J && v.some((W) => _(W, Q) && f(W) >= h(Q)) ? [] : C && S.some((W) => _(W, H) && h(W) <= f(H)) ? [] : [{ id: ht.id, source: Q, target: H, leave: J, enter: C }];
@@ -6368,12 +6393,12 @@ function df(t, e, o, n, a) {
6368
6393
  x.set(H.id, l(H.source) + _);
6369
6394
  });
6370
6395
  }
6371
- if (!M.length || F - T < (M.length + 1) * Ve) continue;
6396
+ if (!M.length || T - F < (M.length + 1) * Ve) continue;
6372
6397
  const z = (ht) => {
6373
6398
  const Q = ht.filter((J) => J.leave), H = ht.filter((J) => J.enter);
6374
6399
  return ht.map((J, C) => ({
6375
6400
  w: J,
6376
- at: Wt(T + (F - T) * (C + 1) / (ht.length + 1)),
6401
+ at: Wt(F + (T - F) * (C + 1) / (ht.length + 1)),
6377
6402
  leave: J.leave ? Wt(j + Ve * Q.indexOf(J)) : void 0,
6378
6403
  enter: J.enter ? Wt($ - Ve * (H.length - 1 - H.indexOf(J))) : void 0
6379
6404
  }));
@@ -6383,7 +6408,7 @@ function df(t, e, o, n, a) {
6383
6408
  { u: J, v: p(Q.source) },
6384
6409
  { u: J, v: H }
6385
6410
  ] : [
6386
- { u: x.get(Q.id), v: T },
6411
+ { u: x.get(Q.id), v: F },
6387
6412
  { u: x.get(Q.id), v: H }
6388
6413
  ],
6389
6414
  ...C !== void 0 ? [
@@ -6392,7 +6417,7 @@ function df(t, e, o, n, a) {
6392
6417
  { u: f(Q.target), v: p(Q.target) }
6393
6418
  ] : [
6394
6419
  { u: l(Q.target), v: H },
6395
- { u: l(Q.target), v: F }
6420
+ { u: l(Q.target), v: T }
6396
6421
  ]
6397
6422
  ]), it = uf(
6398
6423
  [...M].sort((ht, Q) => l(Q.source) - l(ht.source)),
@@ -6461,15 +6486,15 @@ function gf(t, e, o) {
6461
6486
  i[n] < u[n] && ([u, i] = [i, u]);
6462
6487
  const f = u[n] + s(u, n), h = i[n];
6463
6488
  if (h <= f) continue;
6464
- const l = (e === "right" ? c.w : c.h) - 2 * Fe, p = (e === "right" ? c.h : c.w) - 2 * Fe, m = f - l / 2 - ze, g = h + l / 2 + ze, y = u[a] + s(u, a) / 2, P = i[a] + s(i, a) / 2, A = Math.min(y, P) + ze, w = Math.max(y, P) - ze;
6465
- if (w - A < p) continue;
6489
+ const l = (e === "right" ? c.w : c.h) - 2 * Te, p = (e === "right" ? c.h : c.w) - 2 * Te, m = f - l / 2 - ze, g = h + l / 2 + ze, y = u[a] + s(u, a) / 2, P = i[a] + s(i, a) / 2, O = Math.min(y, P) + ze, w = Math.max(y, P) - ze;
6490
+ if (w - O < p) continue;
6466
6491
  const k = [
6467
6492
  ...[...t.values()].filter(($) => $[n] < g && $[n] + s($, n) > m).map(($) => ({
6468
6493
  lo: $[a] - ze,
6469
6494
  hi: $[a] + s($, a) + ze
6470
6495
  })),
6471
6496
  ...r.filter(($) => $.from < g && $.to > m)
6472
- ], T = ($) => k.every((v) => $ + p <= v.lo || $ >= v.hi), F = (A + w - p) / 2, j = [A, F, ...k.map(($) => $.hi)].filter(($) => $ >= A && $ + p <= w && T($)).sort(($, v) => Math.abs($ - F) - Math.abs(v - F))[0];
6497
+ ], F = ($) => k.every((v) => $ + p <= v.lo || $ >= v.hi), T = (O + w - p) / 2, j = [O, T, ...k.map(($) => $.hi)].filter(($) => $ >= O && $ + p <= w && F($)).sort(($, v) => Math.abs($ - T) - Math.abs(v - T))[0];
6473
6498
  j !== void 0 && (d.add(c), r.push({ lo: j - ze, hi: j + p + ze, from: m, to: g }));
6474
6499
  }
6475
6500
  return d;
@@ -6496,7 +6521,7 @@ function wf(t, e, o, n, a) {
6496
6521
  }
6497
6522
  function Mf(t, e, o, n, a, s, r = !1, d = [], c = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), i = () => {
6498
6523
  }) {
6499
- const f = new Map(t.map((H) => [H.id, H])), h = t.map((H) => H.id), l = o === "right", p = (H) => l ? f.get(H).w : f.get(H).h, m = (H) => l ? f.get(H).h : f.get(H).w, g = (H) => f.get(H).type === "group", y = (H) => l ? H.y + H.h / 2 : H.x + H.w / 2, P = new Set(n.flat()), A = (H) => {
6524
+ const f = new Map(t.map((H) => [H.id, H])), h = t.map((H) => H.id), l = o === "right", p = (H) => l ? f.get(H).w : f.get(H).h, m = (H) => l ? f.get(H).h : f.get(H).w, g = (H) => f.get(H).type === "group", y = (H) => l ? H.y + H.h / 2 : H.x + H.w / 2, P = new Set(n.flat()), O = (H) => {
6500
6525
  const J = !P.size || P.has(H) ? [] : (c.get(H) ?? []).flatMap((_) => e.get(_) ?? []);
6501
6526
  if (J.length) return J.reduce((_, W) => _ + y(W), 0) / J.length;
6502
6527
  const C = e.get(H);
@@ -6504,7 +6529,7 @@ function Mf(t, e, o, n, a, s, r = !1, d = [], c = /* @__PURE__ */ new Map(), u =
6504
6529
  }, w = (H, J) => Math.max(
6505
6530
  Ho(a, H, J, g(H) || g(J) ? s.group : s.node, !l),
6506
6531
  io(f.get(H).soft, f.get(J).soft, l)
6507
- ), k = (H) => H.reduce((J, C, _) => J + m(C) + (_ ? w(H[_ - 1], C) : 0), 0), T = wf(
6532
+ ), k = (H) => H.reduce((J, C, _) => J + m(C) + (_ ? w(H[_ - 1], C) : 0), 0), F = wf(
6508
6533
  Ln(h, n),
6509
6534
  n,
6510
6535
  r ? g : () => !1,
@@ -6512,21 +6537,21 @@ function Mf(t, e, o, n, a, s, r = !1, d = [], c = /* @__PURE__ */ new Map(), u =
6512
6537
  k
6513
6538
  ).map(
6514
6539
  (H) => ls(
6515
- [...H].sort((J, C) => A(J) - A(C) || h.indexOf(J) - h.indexOf(C)),
6540
+ [...H].sort((J, C) => O(J) - O(C) || h.indexOf(J) - h.indexOf(C)),
6516
6541
  (J) => f.get(J).soft
6517
6542
  )
6518
- ), F = new Map(T.flatMap((H, J) => H.map((C) => [C, J]))), j = T.map(k), $ = Math.max(...j), v = new Map(h.map((H) => [H, /* @__PURE__ */ new Set()])), S = new Map(h.map((H) => [H, /* @__PURE__ */ new Set()]));
6543
+ ), T = new Map(F.flatMap((H, J) => H.map((C) => [C, J]))), j = F.map(k), $ = Math.max(...j), v = new Map(h.map((H) => [H, /* @__PURE__ */ new Set()])), S = new Map(h.map((H) => [H, /* @__PURE__ */ new Set()]));
6519
6544
  for (const [H, J] of n)
6520
- F.get(J) > F.get(H) && (v.get(H).add(J), S.get(J).add(H));
6545
+ T.get(J) > T.get(H) && (v.get(H).add(J), S.get(J).add(H));
6521
6546
  const M = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
6522
- for (const [H, J] of T.entries()) {
6547
+ for (const [H, J] of F.entries()) {
6523
6548
  let C = ($ - j[H]) / 2, _ = -1 / 0;
6524
6549
  for (const [W, b] of J.entries()) {
6525
6550
  const [Y] = S.get(b), et = S.get(b).size === 1 && v.get(Y).size === 1, at = et ? i(Y, b) : void 0, pt = at !== void 0 ? M.get(Y) + at : et ? x.get(Y) - m(b) / 2 : C, ot = W ? Math.max(pt, _ + w(J[W - 1], b)) : pt;
6526
6551
  M.set(b, ot), x.set(b, ot + m(b) / 2), _ = ot + m(b), C = Math.max(C + m(b), _) + (J[W + 1] ? w(b, J[W + 1]) : 0);
6527
6552
  }
6528
6553
  }
6529
- const N = T.length === 1 && z(T[0]);
6554
+ const N = F.length === 1 && z(F[0]);
6530
6555
  function z(H) {
6531
6556
  const J = H.map((b) => u.get(b));
6532
6557
  if (H.length < 2 || J.some((b, Y) => b === void 0 || Y && b < J[Y - 1]))
@@ -6540,14 +6565,14 @@ function Mf(t, e, o, n, a, s, r = !1, d = [], c = /* @__PURE__ */ new Map(), u =
6540
6565
  const W = J.at(-1) - J[0] + (m(H[0]) + m(H.at(-1))) / 2;
6541
6566
  return _ - C[0] > Math.max(j[0] * 1.25, W + 1) ? !1 : (H.forEach((b, Y) => M.set(b, C[Y])), !0);
6542
6567
  }
6543
- const mt = Math.min(...M.values()), it = zo(T, d, a, o), ht = /* @__PURE__ */ new Map();
6568
+ const mt = Math.min(...M.values()), it = zo(F, d, a, o), ht = /* @__PURE__ */ new Map();
6544
6569
  let Q = 0;
6545
- for (const [H, J] of T.entries()) {
6570
+ for (const [H, J] of F.entries()) {
6546
6571
  for (const W of J) {
6547
6572
  const b = Wt(M.get(W) - mt);
6548
6573
  ht.set(W, l ? { x: Q, y: b } : { x: b, y: Q });
6549
6574
  }
6550
- const C = T[H + 1];
6575
+ const C = F[H + 1];
6551
6576
  if (!C) break;
6552
6577
  let _ = Math.max(
6553
6578
  J.some(g) || C.some(g) ? s.group : s.rank,
@@ -6555,7 +6580,7 @@ function Mf(t, e, o, n, a, s, r = !1, d = [], c = /* @__PURE__ */ new Map(), u =
6555
6580
  yi(J, C, (W) => f.get(W).soft, !l)
6556
6581
  );
6557
6582
  for (const W of a)
6558
- Math.min(F.get(W.a), F.get(W.b)) === H && Math.abs(F.get(W.a) - F.get(W.b)) === 1 && (_ = Math.max(_, l ? W.w : W.h));
6583
+ Math.min(T.get(W.a), T.get(W.b)) === H && Math.abs(T.get(W.a) - T.get(W.b)) === 1 && (_ = Math.max(_, l ? W.w : W.h));
6559
6584
  Q += Math.max(...J.map(p)) + _;
6560
6585
  }
6561
6586
  return { positions: ht, axis: o, followed: N };
@@ -6581,7 +6606,7 @@ function bf(t, e, o, n) {
6581
6606
  }
6582
6607
  const ro = 20;
6583
6608
  function zo(t, e, o, n) {
6584
- const a = new Map(t.flatMap((d, c) => d.map((u) => [u, c]))), s = (d) => n === "right" ? 2 * Fe : d.h, r = 2 * Fe;
6609
+ const a = new Map(t.flatMap((d, c) => d.map((u) => [u, c]))), s = (d) => n === "right" ? 2 * Te : d.h, r = 2 * Te;
6585
6610
  return t.slice(0, -1).map((d, c) => {
6586
6611
  let u = 0, i = 0;
6587
6612
  const f = [...o], h = [], l = [];
@@ -6589,12 +6614,12 @@ function zo(t, e, o, n) {
6589
6614
  const g = m.a !== void 0 ? a.get(m.a) : void 0, y = m.b !== void 0 ? a.get(m.b) : void 0;
6590
6615
  let P;
6591
6616
  if (g !== void 0 && y !== void 0) {
6592
- const A = Math.min(g, y), w = Math.max(g, y);
6593
- if (P = A <= c && w > c && (A === c || w === c + 1), !P) continue;
6617
+ const O = Math.min(g, y), w = Math.max(g, y);
6618
+ if (P = O <= c && w > c && (O === c || w === c + 1), !P) continue;
6594
6619
  const k = f.findIndex(
6595
- (T) => T.a === m.a && T.b === m.b || T.a === m.b && T.b === m.a
6620
+ (F) => F.a === m.a && F.b === m.b || F.a === m.b && F.b === m.a
6596
6621
  );
6597
- k >= 0 && (i += s(f.splice(k, 1)[0]) - r, A === c && w === c + 1 && l.push(m));
6622
+ k >= 0 && (i += s(f.splice(k, 1)[0]) - r, O === c && w === c + 1 && l.push(m));
6598
6623
  } else {
6599
6624
  if (P = g !== void 0 ? g === c : y === c + 1, !P) continue;
6600
6625
  m.label && o.length && (i += s(m.label) - (n === "right" ? r : 0));
@@ -6620,13 +6645,13 @@ function vf(t, e, o, n, a) {
6620
6645
  for (const [y, P] of i.entries())
6621
6646
  h.push(y ? h[y - 1] + n.get(P) - n.get(i[y - 1]) : 0);
6622
6647
  const l = i.map((y, P) => {
6623
- const A = (f.get(y) ?? []).map(d).sort((k, T) => k - T);
6624
- return (A.length ? A[A.length - 1 >> 1] : d(y)) - a(y) / 2 - h[P];
6648
+ const O = (f.get(y) ?? []).map(d).sort((k, F) => k - F);
6649
+ return (O.length ? O[O.length - 1 >> 1] : d(y)) - a(y) / 2 - h[P];
6625
6650
  }), p = [], m = (y) => y[y.length >> 1];
6626
6651
  for (const y of l)
6627
6652
  for (p.push([y]); p.length > 1 && m(p.at(-2)) > m(p.at(-1)); ) {
6628
6653
  const P = p.pop();
6629
- p.push([...p.pop(), ...P].sort((A, w) => A - w));
6654
+ p.push([...p.pop(), ...P].sort((O, w) => O - w));
6630
6655
  }
6631
6656
  let g = 0;
6632
6657
  for (const y of p)
@@ -6679,40 +6704,40 @@ function Sf(t, e, o, n = [], a = [], s) {
6679
6704
  );
6680
6705
  }
6681
6706
  } else {
6682
- const f = t.map(($) => $.id), h = ($) => i.get($).soft, l = o.length ? If(Ln(f, o), o, ($) => ls($, h)) : null, p = l ? l.layers : f.map(($) => [$]), m = !!l && l.chains.size >= Of && l.crossings <= 2 * l.chains.size && !t.some(($) => $.soft?.length), g = m ? l.order : p, y = m ? o.flatMap(([$, v], S) => {
6707
+ const f = t.map(($) => $.id), h = ($) => i.get($).soft, l = o.length ? If(Ln(f, o), o, ($) => ls($, h)) : null, p = l ? l.layers : f.map(($) => [$]), m = !!l && l.chains.size >= Af && l.crossings <= 2 * l.chains.size && !t.some(($) => $.soft?.length), g = m ? l.order : p, y = m ? o.flatMap(([$, v], S) => {
6683
6708
  const M = [$, ...l.chains.get(S) ?? [], v];
6684
6709
  return M.slice(1).map((x, N) => [M[N], x]);
6685
- }) : o, P = ($) => _e($) ? 0 : c === "right" ? i.get($).w : i.get($).h, A = ($) => _e($) ? 0 : c === "right" ? i.get($).h : i.get($).w, w = new Map(g.flatMap(($, v) => $.map((S) => [S, v]))), k = zo(p, a, n, c), T = /* @__PURE__ */ new Map();
6710
+ }) : o, P = ($) => _e($) ? 0 : c === "right" ? i.get($).w : i.get($).h, O = ($) => _e($) ? 0 : c === "right" ? i.get($).h : i.get($).w, w = new Map(g.flatMap(($, v) => $.map((S) => [S, v]))), k = zo(p, a, n, c), F = /* @__PURE__ */ new Map();
6686
6711
  for (const $ of g) {
6687
6712
  let v = 0, S;
6688
6713
  for (const [M, x] of $.entries()) {
6689
6714
  const N = $[M - 1];
6690
6715
  N !== void 0 && _e(N) ? v += _e(x) ? wi : ro : N !== void 0 && _e(x) && (v += ro), !_e(x) && S !== void 0 && (v = Math.max(
6691
6716
  v,
6692
- T.get(S) + A(S) + Math.max(
6717
+ F.get(S) + O(S) + Math.max(
6693
6718
  Ho(n, S, x, d, c !== "right"),
6694
6719
  io(h(S), h(x), c === "right")
6695
6720
  )
6696
- )), T.set(x, v), v += A(x), _e(x) || (S = x);
6721
+ )), F.set(x, v), v += O(x), _e(x) || (S = x);
6697
6722
  }
6698
6723
  }
6699
- o.length && vf(g, y, w, T, A);
6700
- const F = kf(g.length, y, w, ($) => T.get($) + A($) / 2);
6724
+ o.length && vf(g, y, w, F, O);
6725
+ const T = kf(g.length, y, w, ($) => F.get($) + O($) / 2);
6701
6726
  m && $c(
6702
6727
  c,
6703
6728
  g,
6704
6729
  o.flatMap(
6705
6730
  ([v, S], M) => w.get(v) < w.get(S) ? [{ id: String(M), chain: [v, ...l.chains.get(M) ?? [], S] }] : []
6706
6731
  ),
6707
- (v) => _e(v) ? void 0 : c === "right" ? { x: 0, y: T.get(v), w: P(v), h: A(v) } : { x: T.get(v), y: 0, w: A(v), h: P(v) },
6708
- (v) => T.get(v),
6732
+ (v) => _e(v) ? void 0 : c === "right" ? { x: 0, y: F.get(v), w: P(v), h: O(v) } : { x: F.get(v), y: 0, w: O(v), h: P(v) },
6733
+ (v) => F.get(v),
6709
6734
  s
6710
- ).forEach((v, S) => F[S] = Math.max(F[S] ?? 0, v));
6735
+ ).forEach((v, S) => T[S] = Math.max(T[S] ?? 0, v));
6711
6736
  let j = 0;
6712
6737
  for (const [$, v] of p.entries()) {
6713
- let S = Math.max(d, k[$] ?? 0, F[$] ?? 0);
6738
+ let S = Math.max(d, k[$] ?? 0, T[$] ?? 0);
6714
6739
  for (const M of v) {
6715
- const x = T.get(M);
6740
+ const x = F.get(M);
6716
6741
  r.set(M, c === "right" ? { x: j, y: x } : { x, y: j });
6717
6742
  }
6718
6743
  p[$ + 1] && (S = Math.max(S, yi(v, p[$ + 1], h, c === "down")));
@@ -6723,7 +6748,7 @@ function Sf(t, e, o, n = [], a = [], s) {
6723
6748
  m && (u = {
6724
6749
  order: g,
6725
6750
  chains: l.chains,
6726
- across: new Map(g.flat().flatMap(($) => _e($) ? [[$, T.get($)]] : []))
6751
+ across: new Map(g.flat().flatMap(($) => _e($) ? [[$, F.get($)]] : []))
6727
6752
  });
6728
6753
  }
6729
6754
  return { positions: r, axis: c, corridors: u };
@@ -6745,13 +6770,13 @@ function Mi(t, e, o = (n) => n) {
6745
6770
  }
6746
6771
  const Ef = 8;
6747
6772
  function If(t, e, o = (n) => n) {
6748
- const n = Mi(t, e, o), a = new Map(n.flatMap((k, T) => k.map((F) => [F, T]))), s = n.map((k) => [...k]), r = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), c = (k, T) => {
6749
- d.set(k, [...d.get(k) ?? [], T]), r.set(T, [...r.get(T) ?? [], k]);
6773
+ const n = Mi(t, e, o), a = new Map(n.flatMap((k, F) => k.map((T) => [T, F]))), s = n.map((k) => [...k]), r = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), c = (k, F) => {
6774
+ d.set(k, [...d.get(k) ?? [], F]), r.set(F, [...r.get(F) ?? [], k]);
6750
6775
  }, u = new Set(a.keys()), i = /* @__PURE__ */ new Map();
6751
- for (const [k, [T, F]] of e.entries()) {
6752
- const j = a.get(T), $ = a.get(F);
6776
+ for (const [k, [F, T]] of e.entries()) {
6777
+ const j = a.get(F), $ = a.get(T);
6753
6778
  if (j === void 0 || $ === void 0 || j >= $) continue;
6754
- let v = T;
6779
+ let v = F;
6755
6780
  i.set(k, []);
6756
6781
  for (let S = j + 1; S < $; S++) {
6757
6782
  const M = `\0${k}:${S}`;
@@ -6759,67 +6784,67 @@ function If(t, e, o = (n) => n) {
6759
6784
  const x = s[S].indexOf(v);
6760
6785
  s[S].splice(x < 0 ? s[S].length : x + 1, 0, M), c(v, M), v = M;
6761
6786
  }
6762
- c(v, F);
6787
+ c(v, T);
6763
6788
  }
6764
6789
  if (s.length < 2) return { layers: n, order: n, chains: i, crossings: 0 };
6765
- const f = (k) => o(k.filter((T) => u.has(T))), h = (k) => {
6766
- const T = f(k);
6767
- let F = 0;
6768
- return k.map((j) => u.has(j) ? T[F++] : j);
6790
+ const f = (k) => o(k.filter((F) => u.has(F))), h = (k) => {
6791
+ const F = f(k);
6792
+ let T = 0;
6793
+ return k.map((j) => u.has(j) ? F[T++] : j);
6769
6794
  }, l = (k) => {
6770
- const T = new Map(s[k + 1].map(($, v) => [$, v])), F = s[k].flatMap(
6771
- ($) => (d.get($) ?? []).map((v) => T.get(v)).sort((v, S) => v - S)
6795
+ const F = new Map(s[k + 1].map(($, v) => [$, v])), T = s[k].flatMap(
6796
+ ($) => (d.get($) ?? []).map((v) => F.get(v)).sort((v, S) => v - S)
6772
6797
  );
6773
6798
  let j = 0;
6774
- for (let $ = 0; $ < F.length; $++)
6775
- for (let v = $ + 1; v < F.length; v++) F[$] > F[v] && j++;
6799
+ for (let $ = 0; $ < T.length; $++)
6800
+ for (let v = $ + 1; v < T.length; v++) T[$] > T[v] && j++;
6776
6801
  return j;
6777
- }, p = () => s.slice(1).reduce((k, T, F) => k + l(F), 0), m = (k, T, F, j) => {
6802
+ }, p = () => s.slice(1).reduce((k, F, T) => k + l(T), 0), m = (k, F, T, j) => {
6778
6803
  let $ = 0;
6779
- for (const v of F.get(k) ?? [])
6780
- for (const S of F.get(T) ?? []) j.get(v) > j.get(S) && $++;
6804
+ for (const v of T.get(k) ?? [])
6805
+ for (const S of T.get(F) ?? []) j.get(v) > j.get(S) && $++;
6781
6806
  return $;
6782
- }, g = (k) => new Map((s[k] ?? []).map((T, F) => [T, F])), y = (k) => {
6783
- const T = s[k], F = g(k - 1), j = g(k + 1), $ = (v, S) => m(v, S, r, F) + m(v, S, d, j);
6784
- for (let v = !0, S = 0; v && S < T.length; S++) {
6807
+ }, g = (k) => new Map((s[k] ?? []).map((F, T) => [F, T])), y = (k) => {
6808
+ const F = s[k], T = g(k - 1), j = g(k + 1), $ = (v, S) => m(v, S, r, T) + m(v, S, d, j);
6809
+ for (let v = !0, S = 0; v && S < F.length; S++) {
6785
6810
  v = !1;
6786
- for (let M = 0; M + 1 < T.length; M++) {
6787
- const x = T[M], N = T[M + 1];
6811
+ for (let M = 0; M + 1 < F.length; M++) {
6812
+ const x = F[M], N = F[M + 1];
6788
6813
  if (!($(N, x) >= $(x, N))) {
6789
- if ([T[M], T[M + 1]] = [N, x], f(T).join(`
6790
- `) !== T.filter((z) => u.has(z)).join(`
6814
+ if ([F[M], F[M + 1]] = [N, x], f(F).join(`
6815
+ `) !== F.filter((z) => u.has(z)).join(`
6791
6816
  `)) {
6792
- [T[M], T[M + 1]] = [x, N];
6817
+ [F[M], F[M + 1]] = [x, N];
6793
6818
  continue;
6794
6819
  }
6795
6820
  v = !0;
6796
6821
  }
6797
6822
  }
6798
6823
  }
6799
- }, P = (k, T, F) => {
6824
+ }, P = (k, F, T) => {
6800
6825
  const $ = s[k].map((M, x) => {
6801
- const N = (T.get(M) ?? []).map((z) => F.get(z));
6826
+ const N = (F.get(M) ?? []).map((z) => T.get(z));
6802
6827
  return { id: M, k: x, key: N.length ? N.reduce((z, mt) => z + mt, 0) / N.length : null };
6803
6828
  }).filter((M) => M.key !== null), v = $.map((M) => M.k), S = [...s[k]];
6804
6829
  [...$].sort((M, x) => M.key - x.key || M.k - x.k).forEach((M, x) => S[v[x]] = M.id), s[k] = h(S);
6805
6830
  };
6806
- let A = s.map((k) => [...k]), w = p();
6807
- for (let k = 0, T = 0; k < Ef && w && T < 2; k++) {
6808
- const F = k % 2 === 0, j = F ? s.map((v, S) => S).slice(1) : s.map((v, S) => S).reverse().slice(1);
6831
+ let O = s.map((k) => [...k]), w = p();
6832
+ for (let k = 0, F = 0; k < Ef && w && F < 2; k++) {
6833
+ const T = k % 2 === 0, j = T ? s.map((v, S) => S).slice(1) : s.map((v, S) => S).reverse().slice(1);
6809
6834
  for (const v of j)
6810
- P(v, F ? r : d, g(F ? v - 1 : v + 1)), y(v);
6835
+ P(v, T ? r : d, g(T ? v - 1 : v + 1)), y(v);
6811
6836
  const $ = p();
6812
- $ < w ? [A, w, T] = [s.map((v) => [...v]), $, 0] : T++;
6837
+ $ < w ? [O, w, F] = [s.map((v) => [...v]), $, 0] : F++;
6813
6838
  }
6814
6839
  return {
6815
- layers: A.map((k) => k.filter((T) => u.has(T))),
6816
- order: A,
6840
+ layers: O.map((k) => k.filter((F) => u.has(F))),
6841
+ order: O,
6817
6842
  chains: i,
6818
6843
  crossings: w
6819
6844
  };
6820
6845
  }
6821
- const Of = 40, _e = (t) => t.charCodeAt(0) === 0;
6822
- class Aa {
6846
+ const Af = 40, _e = (t) => t.charCodeAt(0) === 0;
6847
+ class Oa {
6823
6848
  parent;
6824
6849
  constructor(e) {
6825
6850
  this.parent = new Map(e.map((o) => [o, o]));
@@ -6833,7 +6858,7 @@ class Aa {
6833
6858
  e = this.find(e), o = this.find(o), e !== o && this.parent.set(o, e);
6834
6859
  }
6835
6860
  }
6836
- function Af(t, e, o, n) {
6861
+ function Of(t, e, o, n) {
6837
6862
  const a = o.filter((f) => f.type === "stay");
6838
6863
  if (!a.length) return [];
6839
6864
  const s = new Map(a.map((f) => [f.id, { x: f.x, y: f.y }])), r = /* @__PURE__ */ new Set(), d = n === "right" ? "x" : "y", c = n === "right" ? "y" : "x", u = (f, h) => h === "x" ? f.w : f.h, i = (f, h, l, p, m) => Math.min(h[m] + u(f, m), p[m] + u(l, m)) - Math.max(h[m], p[m]);
@@ -6847,7 +6872,7 @@ function Af(t, e, o, n) {
6847
6872
  function Lf(t, e, o, n, a, s) {
6848
6873
  const r = t.map((v) => v.id), d = new Map(t.map((v) => [v.id, v])), c = new Map(t.map((v) => [v.id, { ...e.get(v.id) }])), u = new Map(r.map((v) => [v, 1])), i = o.filter(
6849
6874
  (v) => "ids" in v ? v.type === "align" && v.ids.every((S) => d.has(S)) : "id" in v && d.has(v.id)
6850
- ), f = /* @__PURE__ */ new Map(), h = Af(t, e, i, s);
6875
+ ), f = /* @__PURE__ */ new Map(), h = Of(t, e, i, s);
6851
6876
  h.length && a.push({
6852
6877
  level: "info",
6853
6878
  code: "stale-stay",
@@ -6868,7 +6893,7 @@ function Lf(t, e, o, n, a, s) {
6868
6893
  const S = l.get(v);
6869
6894
  if (p.has(v) || !S) return;
6870
6895
  if (m.has(v))
6871
- throw new Oe(
6896
+ throw new Ae(
6872
6897
  `Relative placement cycle in ${n}. Replace one near with nudge.`,
6873
6898
  S.line
6874
6899
  );
@@ -6885,30 +6910,30 @@ function Lf(t, e, o, n, a, s) {
6885
6910
  }
6886
6911
  const y = new Map(i.flatMap((v) => v.type === "pin" ? [[v.id, v]] : []));
6887
6912
  for (const [v, S] of y) c.set(v, { x: S.x, y: S.y });
6888
- const P = (v, S) => (v === "x" ? d.get(S).w : d.get(S).h) / 2, A = { x: new Aa(r), y: new Aa(r) };
6913
+ const P = (v, S) => (v === "x" ? d.get(S).w : d.get(S).h) / 2, O = { x: new Oa(r), y: new Oa(r) };
6889
6914
  for (const v of i)
6890
6915
  if (v.type === "align" && v.strength === "required")
6891
6916
  for (const S of v.ids.slice(1)) {
6892
- const M = /* @__PURE__ */ new Set([A[v.axis].find(v.ids[0]), A[v.axis].find(S)]), x = r.filter((N) => y.has(N) && M.has(A[v.axis].find(N))).map((N) => c.get(N)[v.axis] + P(v.axis, N));
6917
+ const M = /* @__PURE__ */ new Set([O[v.axis].find(v.ids[0]), O[v.axis].find(S)]), x = r.filter((N) => y.has(N) && M.has(O[v.axis].find(N))).map((N) => c.get(N)[v.axis] + P(v.axis, N));
6893
6918
  x.length > 1 && Math.max(...x) - Math.min(...x) > 0.01 ? a.push({
6894
6919
  level: "error",
6895
6920
  code: "pin-align-conflict",
6896
6921
  message: `Pins conflict with required ${v.axis} alignment in ${n}. The pins were kept.`,
6897
6922
  line: v.line,
6898
6923
  ids: v.ids
6899
- }) : A[v.axis].join(v.ids[0], S);
6924
+ }) : O[v.axis].join(v.ids[0], S);
6900
6925
  }
6901
6926
  const w = { x: /* @__PURE__ */ new Map(), y: /* @__PURE__ */ new Map() };
6902
6927
  for (const v of ["x", "y"])
6903
6928
  for (const S of r) {
6904
- const M = A[v].find(S), x = c.get(S)[v] + P(v, S);
6929
+ const M = O[v].find(S), x = c.get(S)[v] + P(v, S);
6905
6930
  w[v].has(M) || w[v].set(M, { sum: 0, weight: 0, value: 0, fixed: null, members: [] });
6906
6931
  const N = w[v].get(M);
6907
6932
  N.sum += x * u.get(S), N.weight += u.get(S), N.members.push(S), y.has(S) && (N.fixed = x);
6908
6933
  }
6909
6934
  for (const v of ["x", "y"])
6910
6935
  for (const S of w[v].values()) S.value = S.fixed ?? S.sum / S.weight;
6911
- const k = (v, S) => w[v].get(A[v].find(S)), T = (v, S) => k(v, S).value, F = (v, S, M, x) => {
6936
+ const k = (v, S) => w[v].get(O[v].find(S)), F = (v, S) => k(v, S).value, T = (v, S, M, x) => {
6912
6937
  const N = k(v, S), z = k(v, M), mt = x - (N.value - z.value);
6913
6938
  if (mt <= 5e-3 || N === z || N.fixed !== null && z.fixed !== null) return 0;
6914
6939
  if (N.fixed !== null) z.value -= mt;
@@ -6925,7 +6950,7 @@ function Lf(t, e, o, n, a, s) {
6925
6950
  let S = 0;
6926
6951
  for (const M of j) {
6927
6952
  const x = M.side === "right" || M.side === "left" ? "x" : "y", N = M.side === "right" || M.side === "below";
6928
- S += F(
6953
+ S += T(
6929
6954
  x,
6930
6955
  N ? M.id : M.ref,
6931
6956
  N ? M.ref : M.id,
@@ -6934,18 +6959,18 @@ function Lf(t, e, o, n, a, s) {
6934
6959
  }
6935
6960
  for (let M = 0; M < t.length; M++)
6936
6961
  for (let x = M + 1; x < t.length; x++) {
6937
- const N = t[M], z = t[x], mt = T("x", z.id) - T("x", N.id), it = T("y", z.id) - T("y", N.id), ht = (N.w + z.w) / 2 + An - Math.abs(mt), Q = (N.h + z.h) / 2 + An - Math.abs(it);
6962
+ const N = t[M], z = t[x], mt = F("x", z.id) - F("x", N.id), it = F("y", z.id) - F("y", N.id), ht = (N.w + z.w) / 2 + On - Math.abs(mt), Q = (N.h + z.h) / 2 + On - Math.abs(it);
6938
6963
  if (ht <= 5e-3 || Q <= 5e-3) continue;
6939
6964
  const H = ["x", "y"].filter(
6940
6965
  (W) => k(W, N.id) !== k(W, z.id) && !(k(W, N.id).fixed !== null && k(W, z.id).fixed !== null)
6941
6966
  );
6942
6967
  if (!H.length) continue;
6943
6968
  const J = (W) => (W === "x" ? ht : Q) + (W === $ ? 0 : 3), C = [...H].sort((W, b) => J(W) - J(b))[0], _ = C === "x" ? mt : it;
6944
- S += F(
6969
+ S += T(
6945
6970
  C,
6946
6971
  _ >= 0 ? z.id : N.id,
6947
6972
  _ >= 0 ? N.id : z.id,
6948
- (C === "x" ? N.w + z.w : N.h + z.h) / 2 + An
6973
+ (C === "x" ? N.w + z.w : N.h + z.h) / 2 + On
6949
6974
  );
6950
6975
  }
6951
6976
  if (n !== "root")
@@ -6958,8 +6983,8 @@ function Lf(t, e, o, n, a, s) {
6958
6983
  }
6959
6984
  for (const v of t)
6960
6985
  c.set(v.id, {
6961
- x: Wt(T("x", v.id) - v.w / 2),
6962
- y: Wt(T("y", v.id) - v.h / 2)
6986
+ x: Wt(F("x", v.id) - v.w / 2),
6987
+ y: Wt(F("y", v.id) - v.h / 2)
6963
6988
  });
6964
6989
  for (let v = 0; v < t.length; v++)
6965
6990
  for (let S = v + 1; S < t.length; S++) {
@@ -6998,7 +7023,7 @@ const $f = 0.5, Gf = 16, zn = (t) => Math.min(t * $f, Math.max(0, t - Gf));
6998
7023
  function co(t, e, o = !1) {
6999
7024
  if (o) return Wn(t, e, !0);
7000
7025
  const n = new Map(t.objects.map((f) => [f.id, f])), a = t.hints.filter(
7001
- (f) => f.type === "near" && qo(n, f.id, f.ref) !== f.ref
7026
+ (f) => f.type === "near" && Bo(n, f.id, f.ref) !== f.ref
7002
7027
  );
7003
7028
  if (a.length) {
7004
7029
  const f = co(
@@ -7009,7 +7034,7 @@ function co(t, e, o = !1) {
7009
7034
  return m === "x" ? g.x + g.w / 2 : g.y + g.h / 2;
7010
7035
  }, l = t.hints.map((p) => {
7011
7036
  if (!a.includes(p) || p.type !== "near") return p;
7012
- const m = qo(n, p.id, p.ref), g = p.side === "left" || p.side === "right" ? "y" : "x";
7037
+ const m = Bo(n, p.id, p.ref), g = p.side === "left" || p.side === "right" ? "y" : "x";
7013
7038
  return { ...p, ref: m, offset: p.offset + h(p.ref, g) - h(m, g) };
7014
7039
  });
7015
7040
  return co({ ...t, hints: l }, e);
@@ -7023,67 +7048,67 @@ function co(t, e, o = !1) {
7023
7048
  }
7024
7049
  const bi = /* @__PURE__ */ new WeakMap();
7025
7050
  function Wn(t, e, o = !1, n, a) {
7026
- const s = t.edges.filter((O) => O.constraint !== !1 && O.directed !== !1), r = new Set(s.filter((O) => !O.dashed).map((O) => O.target)), d = s.filter((O) => !O.dashed || !r.has(O.target)), c = {
7051
+ const s = t.edges.filter((A) => A.constraint !== !1 && A.directed !== !1), r = new Set(s.filter((A) => !A.dashed).map((A) => A.target)), d = s.filter((A) => !A.dashed || !r.has(A.target)), c = {
7027
7052
  port: Math.max(t.routing.portGap ?? 16, t.routing.edgeGap ?? 16),
7028
7053
  track: t.routing.edgeGap ?? 16
7029
7054
  }, u = [], i = /* @__PURE__ */ new Map([["root", []]]);
7030
- for (const O of t.objects)
7031
- i.has(O.parent) || i.set(O.parent, []), i.get(O.parent).push(O);
7032
- const f = Re(t.appearance), h = f.groupHeader, l = /* @__PURE__ */ new Map(), p = f.theme === Zn ? f : Re({ ...t.appearance, theme: Zn }), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), k = new Map(t.objects.map((O) => [O.id, O])), T = /* @__PURE__ */ new Map(), F = (O, E) => {
7033
- let L = k.get(O);
7055
+ for (const A of t.objects)
7056
+ i.has(A.parent) || i.set(A.parent, []), i.get(A.parent).push(A);
7057
+ const f = Re(t.appearance), h = f.groupHeader, l = /* @__PURE__ */ new Map(), p = f.theme === Zn ? f : Re({ ...t.appearance, theme: Zn }), m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), k = new Map(t.objects.map((A) => [A.id, A])), F = /* @__PURE__ */ new Map(), T = (A, E) => {
7058
+ let L = k.get(A);
7034
7059
  for (; L && L.parent !== E; ) L = k.get(L.parent);
7035
7060
  return L?.id;
7036
7061
  }, j = [], $ = [], v = /* @__PURE__ */ new Map(), S = new Set(a?.groups);
7037
7062
  let M = a?.wrap ?? !1;
7038
- const x = (O) => {
7063
+ const x = (A) => {
7039
7064
  const E = /* @__PURE__ */ new Map();
7040
7065
  for (const L of d) {
7041
- const R = F(L.source, O);
7042
- R && F(L.target, O) !== R && E.set(R, [...E.get(R) ?? [], L]);
7066
+ const R = T(L.source, A);
7067
+ R && T(L.target, A) !== R && E.set(R, [...E.get(R) ?? [], L]);
7043
7068
  }
7044
7069
  return new Set(
7045
7070
  [...E].filter(
7046
7071
  ([L, R]) => R.length > 1 && (k.get(L).shape === "diamond" || R.filter((Z) => Z.label).length > 1)
7047
7072
  ).map(([L]) => L)
7048
7073
  );
7049
- }, N = (O) => d.map((E) => [F(E.source, O), F(E.target, O)]).filter((E) => !!E[0] && !!E[1] && E[0] !== E[1]), z = (O, E, L) => {
7050
- const R = (D) => F(D, O) !== void 0, Z = t.objects.filter((D) => R(D.id)).map((D) => D.id), V = new Map(
7074
+ }, N = (A) => d.map((E) => [T(E.source, A), T(E.target, A)]).filter((E) => !!E[0] && !!E[1] && E[0] !== E[1]), z = (A, E, L) => {
7075
+ const R = (D) => T(D, A) !== void 0, Z = t.objects.filter((D) => R(D.id)).map((D) => D.id), V = new Map(
7051
7076
  Ln(
7052
7077
  Z,
7053
7078
  d.filter((D) => R(D.source) && R(D.target)).map((D) => [D.source, D.target])
7054
- ).flatMap((D, ct) => D.map((B) => [B, ct]))
7079
+ ).flatMap((D, ct) => D.map((q) => [q, ct]))
7055
7080
  ), G = new Map(E.map((D) => [D, 1 / 0]));
7056
7081
  for (const D of Z) {
7057
- const ct = F(D, O);
7082
+ const ct = T(D, A);
7058
7083
  G.set(ct, Math.min(G.get(ct), V.get(D)));
7059
7084
  }
7060
7085
  const X = (D, ct) => {
7061
- const B = /* @__PURE__ */ new Set([D]), rt = [D];
7086
+ const q = /* @__PURE__ */ new Set([D]), rt = [D];
7062
7087
  for (; rt.length; ) {
7063
7088
  const lt = rt.pop();
7064
7089
  if (lt === ct) return !0;
7065
7090
  for (const [kt, vt] of L)
7066
- kt === lt && !B.has(vt) && (B.add(vt), rt.push(vt));
7091
+ kt === lt && !q.has(vt) && (q.add(vt), rt.push(vt));
7067
7092
  }
7068
7093
  return !1;
7069
7094
  };
7070
7095
  return L.filter(([D, ct]) => !(G.get(ct) < G.get(D) && X(ct, D)));
7071
- }, mt = (O) => {
7072
- const E = e && Bn(t, O), L = i.get(O) ?? [];
7073
- if (!(!E?.engine || !mf.has(E.engine.algorithm)) && !(O === "root" && !L.some((R) => R.type === "group" || R.soft?.length)) && L.every((R) => e.has(R.id)))
7096
+ }, mt = (A) => {
7097
+ const E = e && qn(t, A), L = i.get(A) ?? [];
7098
+ if (!(!E?.engine || !mf.has(E.engine.algorithm)) && !(A === "root" && !L.some((R) => R.type === "group" || R.soft?.length)) && L.every((R) => e.has(R.id)))
7074
7099
  return xe.settings({
7075
7100
  algorithm: E.engine.algorithm,
7076
7101
  ...E.engine.params
7077
7102
  });
7078
7103
  };
7079
7104
  let it = 0, ht = 0;
7080
- for (const O of i.keys()) {
7081
- const E = mt(O);
7105
+ for (const A of i.keys()) {
7106
+ const E = mt(A);
7082
7107
  if (!E) continue;
7083
7108
  it = Math.max(it, E.groupGap);
7084
- const L = N(O), R = new Map(
7109
+ const L = N(A), R = new Map(
7085
7110
  Ln(
7086
- (i.get(O) ?? []).map((V) => V.id),
7111
+ (i.get(A) ?? []).map((V) => V.id),
7087
7112
  L
7088
7113
  ).flatMap((V, G) => V.map((X) => [X, G]))
7089
7114
  ), Z = Math.max(0, ...R.values());
@@ -7096,23 +7121,23 @@ function Wn(t, e, o = !1, n, a) {
7096
7121
  );
7097
7122
  }
7098
7123
  it = Math.min(yf, Math.max(it, (ht + 1) * (t.routing.edgeGap ?? 16)));
7099
- function Q(O) {
7100
- const E = e && Bn(t, O);
7124
+ function Q(A) {
7125
+ const E = e && qn(t, A);
7101
7126
  if (E?.engine) return $e(E);
7102
- const L = vo(t, O);
7127
+ const L = vo(t, A);
7103
7128
  return L.algorithm === "row" ? "right" : L.algorithm === "column" ? "down" : $e(L);
7104
7129
  }
7105
- function H(O, E) {
7130
+ function H(A, E) {
7106
7131
  const L = $e(E) === "right", R = Math.max(E.gap, $l), Z = /* @__PURE__ */ new Map();
7107
- for (const Gt of O) for (const Yt of i.get(Gt.id) ?? []) Z.set(Yt.id, Gt.id);
7132
+ for (const Gt of A) for (const Yt of i.get(Gt.id) ?? []) Z.set(Yt.id, Gt.id);
7108
7133
  const V = [...Z.keys()], G = (Gt) => m.get(Gt) ?? P.get(Gt), X = (Gt) => L ? G(Gt).w : G(Gt).h, D = (Gt) => L ? G(Gt).h : G(Gt).w, ct = (Gt) => {
7109
7134
  let Yt = k.get(Gt);
7110
7135
  for (; Yt && !Z.has(Yt.id); ) Yt = k.get(Yt.parent);
7111
7136
  return Yt?.id;
7112
- }, B = d.map((Gt) => [ct(Gt.source), ct(Gt.target)]).filter((Gt) => !!Gt[0] && !!Gt[1] && Gt[0] !== Gt[1]), rt = V.length ? Mi(Ln(V, B), B) : [], lt = new Map(rt.flatMap((Gt, Yt) => Gt.map((Kt) => [Kt, Yt]))), kt = rt.map((Gt) => Math.max(...Gt.map(X))), vt = [];
7113
- let Ot = 0;
7137
+ }, q = d.map((Gt) => [ct(Gt.source), ct(Gt.target)]).filter((Gt) => !!Gt[0] && !!Gt[1] && Gt[0] !== Gt[1]), rt = V.length ? Mi(Ln(V, q), q) : [], lt = new Map(rt.flatMap((Gt, Yt) => Gt.map((Kt) => [Kt, Yt]))), kt = rt.map((Gt) => Math.max(...Gt.map(X))), vt = [];
7138
+ let At = 0;
7114
7139
  for (const [Gt, Yt] of rt.entries()) {
7115
- vt.push(Ot);
7140
+ vt.push(At);
7116
7141
  let Kt = R;
7117
7142
  for (const ae of t.edges) {
7118
7143
  const Rt = lt.get(ct(ae.source) ?? ""), Xt = lt.get(ct(ae.target) ?? "");
@@ -7121,32 +7146,32 @@ function Wn(t, e, o = !1, n, a) {
7121
7146
  Kt = Math.max(Kt, L ? te.w : te.h);
7122
7147
  }
7123
7148
  }
7124
- Ot += kt[Gt] + (Yt === rt.at(-1) ? 0 : Kt);
7149
+ At += kt[Gt] + (Yt === rt.at(-1) ? 0 : Kt);
7125
7150
  }
7126
- const Et = Ot, Ft = /* @__PURE__ */ new Map();
7127
- for (const Gt of O) {
7151
+ const Et = At, Tt = /* @__PURE__ */ new Map();
7152
+ for (const Gt of A) {
7128
7153
  const Yt = rt.map((Rt) => Rt.filter((Xt) => Z.get(Xt) === Gt.id)), Kt = (Rt) => Rt.reduce((Xt, te, Ht) => Xt + D(te) + (Ht ? ga : 0), 0), ae = Math.max(Gl, ...Yt.map(Kt));
7129
- Ft.set(Gt.id, ae), Yt.forEach((Rt, Xt) => {
7154
+ Tt.set(Gt.id, ae), Yt.forEach((Rt, Xt) => {
7130
7155
  let te = (ae - Kt(Rt)) / 2;
7131
7156
  for (const Ht of Rt) {
7132
- const oe = vt[Xt] + (kt[Xt] - X(Ht)) / 2, Bt = L ? { x: oe, y: te } : { x: te, y: oe };
7133
- A.set(Ht, { x: Wt(Bt.x), y: Wt(Bt.y) }), w.set(Ht, Bt), te += D(Ht) + ga;
7157
+ const oe = vt[Xt] + (kt[Xt] - X(Ht)) / 2, qt = L ? { x: oe, y: te } : { x: te, y: oe };
7158
+ O.set(Ht, { x: Wt(qt.x), y: Wt(qt.y) }), w.set(Ht, qt), te += D(Ht) + ga;
7134
7159
  }
7135
7160
  });
7136
7161
  }
7137
- const St = (Gt) => Math.ceil(ce(Gt.label, f.groupTitle)) + no, Qt = Math.max(Et + 2 * ye, ...O.map(St));
7162
+ const St = (Gt) => Math.ceil(ce(Gt.label, f.groupTitle)) + no, Qt = Math.max(Et + 2 * ye, ...A.map(St));
7138
7163
  let Dt = 0;
7139
- for (const Gt of O) {
7140
- const Yt = Ft.get(Gt.id);
7164
+ for (const Gt of A) {
7165
+ const Yt = Tt.get(Gt.id);
7141
7166
  Gt.w = L ? Qt : Math.max(Yt + 2 * ye, St(Gt)), Gt.h = h + (L ? Yt : Et) + ye;
7142
7167
  const Kt = L ? { x: 0, y: Dt } : { x: Dt, y: 0 };
7143
- A.set(Gt.id, Kt), w.set(Gt.id, Kt), Dt += (L ? Gt.h : Gt.w) + ma;
7168
+ O.set(Gt.id, Kt), w.set(Gt.id, Kt), Dt += (L ? Gt.h : Gt.w) + ma;
7144
7169
  }
7145
7170
  const ne = Math.max(0, Dt - ma);
7146
- return L ? { w: O.length ? Qt : 0, h: ne } : { w: ne, h: O.length ? h + Et + ye : 0 };
7171
+ return L ? { w: A.length ? Qt : 0, h: ne } : { w: ne, h: A.length ? h + Et + ye : 0 };
7147
7172
  }
7148
- function J(O, E) {
7149
- const L = O.filter((G) => G.type === "node" && (G.shape === "box" || G.shape === "pill"));
7173
+ function J(A, E) {
7174
+ const L = A.filter((G) => G.type === "node" && (G.shape === "box" || G.shape === "pill"));
7150
7175
  if (L.length < 2) return;
7151
7176
  const R = (G) => t.hints.some((X) => X.type === "size" && X.id === G.id), Z = Math.max(...L.map((G) => G.w)), V = Math.max(...L.map((G) => E.get(G.id)?.ref.w ?? G.w));
7152
7177
  for (const G of L) {
@@ -7160,42 +7185,42 @@ function Wn(t, e, o = !1, n, a) {
7160
7185
  });
7161
7186
  }
7162
7187
  }
7163
- function C(O) {
7164
- const E = vo(t, O), L = t.hints.find((I) => I.type === "order" && I.scope === O);
7165
- let R = i.get(O) ?? [];
7166
- if (L?.type === "order" && (R = [...L.ids.flatMap((U) => R.filter((nt) => nt.id === U)), ...R.filter((U) => !L.ids.includes(U.id))]), E.algorithm === "cells") return _(O, R, E);
7188
+ function C(A) {
7189
+ const E = vo(t, A), L = t.hints.find((I) => I.type === "order" && I.scope === A);
7190
+ let R = i.get(A) ?? [];
7191
+ if (L?.type === "order" && (R = [...L.ids.flatMap((U) => R.filter((nt) => nt.id === U)), ...R.filter((U) => !L.ids.includes(U.id))]), E.algorithm === "cells") return _(A, R, E);
7167
7192
  const Z = /* @__PURE__ */ new Map(), V = R.map((I) => {
7168
7193
  let U;
7169
7194
  if (I.type === "group") {
7170
- const q = C(I.id), st = vo(t, I.id), dt = !i.get(I.id)?.length, gt = g.get(I.id);
7195
+ const B = C(I.id), st = vo(t, I.id), dt = !i.get(I.id)?.length, gt = g.get(I.id);
7171
7196
  U = gt !== void 0 ? {
7172
- w: Math.max(q.w, st.minWidth),
7173
- h: Math.max(q.h + gt, st.minHeight)
7197
+ w: Math.max(B.w, st.minWidth),
7198
+ h: Math.max(B.h + gt, st.minHeight)
7174
7199
  } : (() => {
7175
7200
  const bt = Math.max(
7176
7201
  dt ? ya.w : 0,
7177
- q.w + ye + (n?.get(I.id)?.right ?? ye),
7202
+ B.w + ye + (n?.get(I.id)?.right ?? ye),
7178
7203
  st.minWidth
7179
7204
  ), It = tf(I.label, bt, f);
7180
7205
  return It.lines > 1 && l.set(I.id, It.lines), {
7181
7206
  w: Math.max(bt, It.w),
7182
7207
  h: Math.max(
7183
7208
  dt ? ya.h : 0,
7184
- q.h + Kn(f, It.lines) + (n?.get(I.id)?.bottom ?? ye),
7209
+ B.h + Kn(f, It.lines) + (n?.get(I.id)?.bottom ?? ye),
7185
7210
  st.minHeight
7186
7211
  )
7187
7212
  };
7188
7213
  })();
7189
7214
  } else {
7190
- const q = t.hints.find((dt) => dt.type === "size" && dt.id === I.id), st = Hn(I, q?.type === "size" ? q : void 0, f);
7215
+ const B = t.hints.find((dt) => dt.type === "size" && dt.id === I.id), st = Hn(I, B?.type === "size" ? B : void 0, f);
7191
7216
  if (U = st, p !== f) {
7192
- const dt = Hn(I, q?.type === "size" ? q : void 0, p);
7217
+ const dt = Hn(I, B?.type === "size" ? B : void 0, p);
7193
7218
  Z.set(I.id, {
7194
7219
  look: { w: Wt(st.w), h: Wt(st.h) },
7195
7220
  ref: { w: Wt(dt.w), h: Wt(dt.h) }
7196
7221
  });
7197
7222
  }
7198
- I.shape === "diamond" && !q && st.w > Qa("diamond").w * af && u.push({
7223
+ I.shape === "diamond" && !B && st.w > Qa("diamond").w * af && u.push({
7199
7224
  level: "info",
7200
7225
  code: "big-diamond",
7201
7226
  message: `${I.id}'s question makes its diamond ${Wt(st.w)}px square, much larger than the shapes around it. Shorten the question, or move the detail onto its edges' labels.`,
@@ -7205,48 +7230,48 @@ function Wn(t, e, o = !1, n, a) {
7205
7230
  level: "warning",
7206
7231
  code: "text-overflow",
7207
7232
  message: `${I.id}'s title does not fit in its requested size. Make it larger or remove the size line.`,
7208
- line: q?.line,
7233
+ line: B?.line,
7209
7234
  ids: [I.id]
7210
7235
  });
7211
7236
  }
7212
7237
  const nt = { ...I, w: Wt(U.w), h: Wt(U.h) };
7213
7238
  return P.set(I.id, nt), nt;
7214
7239
  });
7215
- if (E.algorithm === "column" && J(V, Z), O === "root" && E.algorithm === "lanes") return H(V, E);
7216
- const G = N(O), X = k.get(O)?.parent, D = X !== void 0 && Q(X) === Q(O), ct = (O === "root" ? [] : t.edges).flatMap((I) => {
7217
- const U = F(I.source, O), nt = F(I.target, O);
7218
- return !U && !nt || U === nt || !(U && nt) && !D ? [] : [{ a: U, b: nt, label: I.label && !(U && nt) ? Te(I.label, f) : void 0 }];
7219
- }), B = /* @__PURE__ */ new Map();
7240
+ if (E.algorithm === "column" && J(V, Z), A === "root" && E.algorithm === "lanes") return H(V, E);
7241
+ const G = N(A), X = k.get(A)?.parent, D = X !== void 0 && Q(X) === Q(A), ct = (A === "root" ? [] : t.edges).flatMap((I) => {
7242
+ const U = T(I.source, A), nt = T(I.target, A);
7243
+ return !U && !nt || U === nt || !(U && nt) && !D ? [] : [{ a: U, b: nt, label: I.label && !(U && nt) ? Fe(I.label, f) : void 0 }];
7244
+ }), q = /* @__PURE__ */ new Map();
7220
7245
  for (const I of d) {
7221
- const U = F(I.source, O), nt = F(I.target, O);
7222
- U && !nt && B.set(U, [...B.get(U) ?? [], I.target]), nt && !U && B.set(nt, [...B.get(nt) ?? [], I.source]);
7246
+ const U = T(I.source, A), nt = T(I.target, A);
7247
+ U && !nt && q.set(U, [...q.get(U) ?? [], I.target]), nt && !U && q.set(nt, [...q.get(nt) ?? [], I.source]);
7223
7248
  }
7224
7249
  const rt = (I, U) => {
7225
- const nt = A.get(I), q = m.get(I) ?? P.get(I);
7226
- return U ? nt.y + q.h / 2 : nt.x + q.w / 2;
7227
- }, lt = /* @__PURE__ */ new Map(), kt = k.get(O)?.parent, vt = kt !== void 0 && i.get(kt) || [], Ot = V.map((I) => B.get(I.id) ?? []), Et = Ot[0]?.length === 1 ? k.get(Ot[0][0])?.parent : void 0, Ft = vt.findIndex((I) => I.id === Et) < vt.findIndex((I) => I.id === O);
7228
- if (Et !== void 0 && Et !== O && vt.some((I) => I.id === Et) && Ft && Ot.every((I) => I.length === 1 && k.get(I[0])?.parent === Et && A.has(I[0])))
7250
+ const nt = O.get(I), B = m.get(I) ?? P.get(I);
7251
+ return U ? nt.y + B.h / 2 : nt.x + B.w / 2;
7252
+ }, lt = /* @__PURE__ */ new Map(), kt = k.get(A)?.parent, vt = kt !== void 0 && i.get(kt) || [], At = V.map((I) => q.get(I.id) ?? []), Et = At[0]?.length === 1 ? k.get(At[0][0])?.parent : void 0, Tt = vt.findIndex((I) => I.id === Et) < vt.findIndex((I) => I.id === A);
7253
+ if (Et !== void 0 && Et !== A && vt.some((I) => I.id === Et) && Tt && At.every((I) => I.length === 1 && k.get(I[0])?.parent === Et && O.has(I[0])))
7229
7254
  for (const [I, U] of V.entries())
7230
- lt.set(U.id, rt(Ot[I][0], Q(Et) === "right"));
7255
+ lt.set(U.id, rt(At[I][0], Q(Et) === "right"));
7231
7256
  const St = (I, U) => {
7232
- if (T.get(U) !== I) return;
7233
- const nt = Q(O) === "right", q = (gt) => nt ? Kn(f, l.get(gt)) : ye, dt = t.edges.filter(
7257
+ if (F.get(U) !== I) return;
7258
+ const nt = Q(A) === "right", B = (gt) => nt ? Kn(f, l.get(gt)) : ye, dt = t.edges.filter(
7234
7259
  (gt) => k.get(gt.source)?.parent === I && k.get(gt.target)?.parent === U
7235
7260
  ).sort((gt, bt) => rt(gt.target, nt) - rt(bt.target, nt))[0];
7236
- return dt ? q(I) + rt(dt.source, nt) - q(U) - rt(dt.target, nt) : void 0;
7261
+ return dt ? B(I) + rt(dt.source, nt) - B(U) - rt(dt.target, nt) : void 0;
7237
7262
  }, Qt = t.edges.flatMap((I) => {
7238
- const U = F(I.source, O), nt = F(I.target, O);
7263
+ const U = T(I.source, A), nt = T(I.target, A);
7239
7264
  if (!I.label || !U || !nt || U === nt) return [];
7240
- const q = bo(U, nt, I.label, f);
7241
- if (p === f) return [q];
7265
+ const B = bo(U, nt, I.label, f);
7266
+ if (p === f) return [B];
7242
7267
  const st = bo(U, nt, I.label, p);
7243
- return [{ a: U, b: nt, w: Math.max(st.w, q.w - Fe), h: Math.max(st.h, q.h - Fe) }];
7244
- }), Dt = e && Bn(t, O), ne = mt(O), Gt = ne ? { node: ne.nodeGap, rank: ne.rankGap, group: it } : void 0, Yt = ne ? z(
7245
- O,
7268
+ return [{ a: U, b: nt, w: Math.max(st.w, B.w - Te), h: Math.max(st.h, B.h - Te) }];
7269
+ }), Dt = e && qn(t, A), ne = mt(A), Gt = ne ? { node: ne.nodeGap, rank: ne.rankGap, group: it } : void 0, Yt = ne ? z(
7270
+ A,
7246
7271
  V.map((I) => I.id),
7247
7272
  G
7248
- ) : void 0, Kt = Dt?.engine && Dt.scope === O ? Dt.engine : void 0, ae = (I, U) => {
7249
- const nt = E.algorithm === "row" ? "right" : E.algorithm === "column" ? "down" : I, q = {
7273
+ ) : void 0, Kt = Dt?.engine && Dt.scope === A ? Dt.engine : void 0, ae = (I, U) => {
7274
+ const nt = E.algorithm === "row" ? "right" : E.algorithm === "column" ? "down" : I, B = {
7250
7275
  x: !!Dt?.engine || nt === "right",
7251
7276
  y: !!Dt?.engine || nt === "down"
7252
7277
  }, st = (gt) => o ? gt : Z.get(gt.id)?.look ?? gt, dt = /* @__PURE__ */ new Map();
@@ -7263,8 +7288,8 @@ function Wn(t, e, o = !1, n, a) {
7263
7288
  return [
7264
7289
  gt.id,
7265
7290
  {
7266
- x: q.x ? (gt.w - bt.w) / 2 : 0,
7267
- y: dt.get(gt.id) ?? (q.y ? (gt.h - bt.h) / 2 : 0),
7291
+ x: B.x ? (gt.w - bt.w) / 2 : 0,
7292
+ y: dt.get(gt.id) ?? (B.y ? (gt.h - bt.h) / 2 : 0),
7268
7293
  w: bt.w,
7269
7294
  h: bt.h
7270
7295
  }
@@ -7283,21 +7308,21 @@ function Wn(t, e, o = !1, n, a) {
7283
7308
  Yt,
7284
7309
  tt,
7285
7310
  Gt,
7286
- O === "root",
7311
+ A === "root",
7287
7312
  ct,
7288
- B,
7313
+ q,
7289
7314
  lt,
7290
7315
  St
7291
- ) : Dt?.engine && V.every((yt) => e.has(yt.id)) ? pf(V, e, $e(Dt), tt) : Sf(V, E, G, tt, ct, c), nt = Qt.length ? U([]) : void 0, q = nt ? gf(
7316
+ ) : Dt?.engine && V.every((yt) => e.has(yt.id)) ? pf(V, e, $e(Dt), tt) : Sf(V, E, G, tt, ct, c), nt = Qt.length ? U([]) : void 0, B = nt ? gf(
7292
7317
  new Map(
7293
7318
  V.map((tt) => {
7294
- const yt = nt.positions.get(tt.id), At = ae(nt.axis, nt.positions).get(tt.id);
7295
- return [tt.id, { x: yt.x + At.x, y: yt.y + At.y, w: At.w, h: At.h }];
7319
+ const yt = nt.positions.get(tt.id), Ot = ae(nt.axis, nt.positions).get(tt.id);
7320
+ return [tt.id, { x: yt.x + Ot.x, y: yt.y + Ot.y, w: Ot.w, h: Ot.h }];
7296
7321
  })
7297
7322
  ),
7298
7323
  nt.axis,
7299
7324
  Qt
7300
- ) : /* @__PURE__ */ new Set(), st = U(Qt.filter((tt) => !q.has(tt)));
7325
+ ) : /* @__PURE__ */ new Set(), st = U(Qt.filter((tt) => !B.has(tt)));
7301
7326
  let dt;
7302
7327
  if (Kt ? !ne && Kt.algorithm === "layered" && Kt.params.fold !== "never" : !Dt?.engine && E.algorithm === "flow" && E.fold === "auto") {
7303
7328
  const tt = ko(
@@ -7307,13 +7332,13 @@ function Wn(t, e, o = !1, n, a) {
7307
7332
  E.gap,
7308
7333
  G,
7309
7334
  Qt,
7310
- x(O),
7335
+ x(A),
7311
7336
  (nt ?? st).positions
7312
7337
  );
7313
7338
  st.positions = tt.positions, dt = tt.fold;
7314
7339
  }
7315
7340
  const gt = !dt && ne && Dt?.engine?.params.fold !== "never";
7316
- if (gt && S.has(O)) {
7341
+ if (gt && S.has(A)) {
7317
7342
  const tt = ko(
7318
7343
  V,
7319
7344
  st.positions,
@@ -7321,13 +7346,13 @@ function Wn(t, e, o = !1, n, a) {
7321
7346
  Gt.rank,
7322
7347
  G,
7323
7348
  Qt,
7324
- x(O),
7349
+ x(A),
7325
7350
  (nt ?? st).positions,
7326
7351
  { fewest: 2, room: 0 }
7327
7352
  );
7328
7353
  st.positions = tt.positions, dt = tt.fold;
7329
7354
  }
7330
- if (gt && O === "root" && M) {
7355
+ if (gt && A === "root" && M) {
7331
7356
  const tt = ko(
7332
7357
  V,
7333
7358
  st.positions,
@@ -7335,23 +7360,23 @@ function Wn(t, e, o = !1, n, a) {
7335
7360
  Gt.rank,
7336
7361
  G,
7337
7362
  Qt,
7338
- x(O),
7363
+ x(A),
7339
7364
  (nt ?? st).positions,
7340
7365
  { aspect: Ia, fewest: 2 }
7341
7366
  );
7342
7367
  st.positions = tt.positions, dt = tt.fold;
7343
7368
  }
7344
- const bt = n?.get(O);
7369
+ const bt = n?.get(A);
7345
7370
  if (bt && (bt.left > ye || bt.top))
7346
7371
  for (const [tt, yt] of st.positions)
7347
7372
  st.positions.set(tt, { x: yt.x + bt.left - ye, y: yt.y + bt.top });
7348
7373
  const It = ae(st.axis, st.positions), Ct = Z.size ? t.hints.map(
7349
7374
  (tt) => (tt.type === "stay" || tt.type === "pin") && It.has(tt.id) ? { ...tt, x: tt.x - It.get(tt.id).x, y: tt.y - It.get(tt.id).y } : tt
7350
- ) : t.hints, ut = Lf(V, st.positions, Ct, O, u, st.axis);
7351
- return "followed" in st && st.followed ? T.set(O, Et) : T.delete(O), { base: st, fold: dt, pos: ut, off: It };
7375
+ ) : t.hints, ut = Lf(V, st.positions, Ct, A, u, st.axis);
7376
+ return "followed" in st && st.followed ? F.set(A, Et) : F.delete(A), { base: st, fold: dt, pos: ut, off: It };
7352
7377
  }, Xt = (I, U) => {
7353
- const nt = U.pos.get(I.id), q = U.off.get(I.id);
7354
- return { x: nt.x + q.x, y: nt.y + q.y, w: q.w, h: q.h };
7378
+ const nt = U.pos.get(I.id), B = U.off.get(I.id);
7379
+ return { x: nt.x + B.x, y: nt.y + B.y, w: B.w, h: B.h };
7355
7380
  }, te = (I, U) => ({
7356
7381
  ...U.pos.get(I.id),
7357
7382
  w: I.w,
@@ -7360,35 +7385,35 @@ function Wn(t, e, o = !1, n, a) {
7360
7385
  const I = zn(Dt.engine.params.rankGap ?? 52), U = zn(Dt.engine.params.nodeGap ?? 24);
7361
7386
  return $e(Dt) === "right" ? { w: I, h: U } : { w: U, h: I };
7362
7387
  })() : { w: zn(E.gap), h: zn(E.gap) } : { w: 0, h: 0 }, oe = u.length;
7363
- let Bt = Rt(Ht);
7388
+ let qt = Rt(Ht);
7364
7389
  !o && (Ht.w || Ht.h) && V.some(
7365
7390
  (I, U) => V.slice(U + 1).some(
7366
- (nt) => xa(te(I, Bt), te(nt, Bt)) >= An - 0.5 && xa(Xt(I, Bt), Xt(nt, Bt)) < An - 0.5
7391
+ (nt) => xa(te(I, qt), te(nt, qt)) >= On - 0.5 && xa(Xt(I, qt), Xt(nt, qt)) < On - 0.5
7367
7392
  )
7368
- ) && (u.length = oe, Bt = Rt({ w: 0, h: 0 })), Bt.fold && j.push({ scope: O, fold: Bt.fold });
7369
- const le = Bt.base.corridors;
7370
- le && O === "root" && !Bt.fold && !n?.get(O) && V.every((I) => {
7371
- const U = Bt.pos.get(I.id), nt = Bt.base.positions.get(I.id);
7393
+ ) && (u.length = oe, qt = Rt({ w: 0, h: 0 })), qt.fold && j.push({ scope: A, fold: qt.fold });
7394
+ const le = qt.base.corridors;
7395
+ le && A === "root" && !qt.fold && !n?.get(A) && V.every((I) => {
7396
+ const U = qt.pos.get(I.id), nt = qt.base.positions.get(I.id);
7372
7397
  return U && nt && Math.abs(U.x - nt.x) < 0.01 && Math.abs(U.y - nt.y) < 0.01;
7373
- }) && v.set(O, { axis: Bt.base.axis, corridors: le }), (Kt ? Kt.algorithm === "layered" : !Dt?.engine && E.algorithm === "flow") && $.push({ scope: O, axis: Bt.base.axis });
7374
- const fe = V.map((I) => Xt(I, Bt)), de = O === "root" ? 0 : Math.max(0, ...V.map((I) => I.soft?.length ?? 0)), he = O === "root" || !V.length ? { x: 0, y: 0 } : {
7375
- x: Math.max(0, -Math.min(...fe.map((I) => I.x))) + de * On,
7376
- y: Math.max(0, -Math.min(...fe.map((I) => I.y))) + de * (On + oo)
7398
+ }) && v.set(A, { axis: qt.base.axis, corridors: le }), (Kt ? Kt.algorithm === "layered" : !Dt?.engine && E.algorithm === "flow") && $.push({ scope: A, axis: qt.base.axis });
7399
+ const fe = V.map((I) => Xt(I, qt)), de = A === "root" ? 0 : Math.max(0, ...V.map((I) => I.soft?.length ?? 0)), he = A === "root" || !V.length ? { x: 0, y: 0 } : {
7400
+ x: Math.max(0, -Math.min(...fe.map((I) => I.x))) + de * An,
7401
+ y: Math.max(0, -Math.min(...fe.map((I) => I.y))) + de * (An + oo)
7377
7402
  };
7378
7403
  for (const [I, U] of V.entries()) {
7379
- const nt = fe[I], q = Bt.off.get(U.id), st = Bt.base.positions.get(U.id);
7380
- A.set(U.id, { x: Wt(nt.x + he.x), y: Wt(nt.y + he.y) }), w.set(U.id, { x: st.x + q.x + he.x, y: st.y + q.y + he.y }), Z.has(U.id) && m.set(U.id, { w: Wt(nt.w), h: Wt(nt.h) });
7404
+ const nt = fe[I], B = qt.off.get(U.id), st = qt.base.positions.get(U.id);
7405
+ O.set(U.id, { x: Wt(nt.x + he.x), y: Wt(nt.y + he.y) }), w.set(U.id, { x: st.x + B.x + he.x, y: st.y + B.y + he.y }), Z.has(U.id) && m.set(U.id, { w: Wt(nt.w), h: Wt(nt.h) });
7381
7406
  }
7382
7407
  const we = (I, U) => V.length ? Math.max(
7383
7408
  ...V.map(
7384
- (nt, q) => Math.max(Bt.pos.get(nt.id)[I] + nt[U], fe[q][I] + fe[q][U])
7409
+ (nt, B) => Math.max(qt.pos.get(nt.id)[I] + nt[U], fe[B][I] + fe[B][U])
7385
7410
  )
7386
- ) + he[I] + de * On : 0;
7411
+ ) + he[I] + de * An : 0;
7387
7412
  return { w: we("x", "w"), h: we("y", "h") };
7388
7413
  }
7389
- function _(O, E, L) {
7390
- if (L.unit) return W(O, E, L);
7391
- const R = Math.ceil(ce(k.get(O).label, f.groupTitle)) + qr, Z = (G) => t.hints.find((X) => X.type === "size" && X.id === G), V = cc(
7414
+ function _(A, E, L) {
7415
+ if (L.unit) return W(A, E, L);
7416
+ const R = Math.ceil(ce(k.get(A).label, f.groupTitle)) + Br, Z = (G) => t.hints.find((X) => X.type === "size" && X.id === G), V = cc(
7392
7417
  E.map((G) => {
7393
7418
  const X = Z(G.id);
7394
7419
  return {
@@ -7406,9 +7431,9 @@ function Wn(t, e, o = !1, n, a) {
7406
7431
  f,
7407
7432
  R
7408
7433
  );
7409
- return b(O, E, V.boxes), g.set(O, ao(f.groupTitle.lineHeight)), { w: Math.max(V.w, R), h: V.h };
7434
+ return b(A, E, V.boxes), g.set(A, ao(f.groupTitle.lineHeight)), { w: Math.max(V.w, R), h: V.h };
7410
7435
  }
7411
- function W(O, E, L) {
7436
+ function W(A, E, L) {
7412
7437
  const R = dc(
7413
7438
  E.map((G) => ({
7414
7439
  id: G.id,
@@ -7425,7 +7450,7 @@ function Wn(t, e, o = !1, n, a) {
7425
7450
  },
7426
7451
  f
7427
7452
  ), Z = ao(f.groupTitle.lineHeight), V = Z + (R.ruler?.h ?? 0);
7428
- return b(O, E, R.boxes), g.set(O, V), y.set(O, {
7453
+ return b(A, E, R.boxes), g.set(A, V), y.set(A, {
7429
7454
  ...R.ruler ? { ruler: { y: Z, ...R.ruler } } : {},
7430
7455
  ...R.pieces.size ? {
7431
7456
  pieces: Object.fromEntries(
@@ -7435,41 +7460,41 @@ function Wn(t, e, o = !1, n, a) {
7435
7460
  ...R.open.length ? { open: R.open } : {}
7436
7461
  }), { w: R.w, h: R.h };
7437
7462
  }
7438
- function b(O, E, L) {
7463
+ function b(A, E, L) {
7439
7464
  for (const R of E) {
7440
7465
  const Z = L.get(R.id);
7441
- P.set(R.id, { ...R, w: Wt(Z.w), h: Wt(Z.h) }), A.set(R.id, { x: Wt(Z.x), y: Wt(Z.y) }), w.set(R.id, { x: Z.x, y: Z.y });
7466
+ P.set(R.id, { ...R, w: Wt(Z.w), h: Wt(Z.h) }), O.set(R.id, { x: Wt(Z.x), y: Wt(Z.y) }), w.set(R.id, { x: Z.x, y: Z.y });
7442
7467
  const V = t.hints.find(
7443
7468
  (G) => kl.includes(G.type) && "id" in G && G.id === R.id
7444
7469
  );
7445
7470
  V && u.push({
7446
7471
  level: "warning",
7447
7472
  code: "cell-position",
7448
- message: `${R.id} is a cell of ${O}, so it stays in its place. Move ${O} instead, or reorder its cells with order.`,
7473
+ message: `${R.id} is a cell of ${A}, so it stays in its place. Move ${A} instead, or reorder its cells with order.`,
7449
7474
  line: V.line,
7450
7475
  ids: [R.id]
7451
7476
  });
7452
7477
  }
7453
7478
  }
7454
- const Y = u.length, et = mt("root") && Bn(t, "root");
7479
+ const Y = u.length, et = mt("root") && qn(t, "root");
7455
7480
  let at = C("root");
7456
7481
  if (!a && et && et.engine?.params.fold !== "never") {
7457
- let O = function(G) {
7482
+ let A = function(G) {
7458
7483
  return L(G) > xi * R(G);
7459
7484
  };
7460
7485
  const E = $e(et) === "right", L = (G) => E ? G.w : G.h, R = (G) => E ? G.h : G.w, Z = E ? sn.width : sn.height, V = (G) => L(G) > Z && L(G) > Ia * R(G);
7461
7486
  for (; V(at) && !M; ) {
7462
7487
  const G = [...P.values()].filter(
7463
- (X) => X.type === "group" && !S.has(X.id) && mt(X.id) && O(X)
7488
+ (X) => X.type === "group" && !S.has(X.id) && mt(X.id) && A(X)
7464
7489
  ).sort((X, D) => L(D) - L(X))[0];
7465
7490
  G ? S.add(G.id) : M = !0, u.length = Y, j.length = $.length = 0, m.clear(), at = C("root");
7466
7491
  }
7467
7492
  }
7468
7493
  if (!a && et && $e(et) === "down" && et.engine?.params.fold !== "never") {
7469
- const O = (L) => L.h, E = (L) => L.w * L.h;
7494
+ const A = (L) => L.h, E = (L) => L.w * L.h;
7470
7495
  for (; ; ) {
7471
- const L = (i.get("root") ?? []).map((G) => P.get(G.id)).filter(Boolean).sort((G, X) => O(X) - O(G)), [R, Z] = L;
7472
- if (!R || !Z || R.type !== "group" || R.fold === "never" || S.has(R.id) || !mt(R.id) || O(R) < ef * O(Z))
7496
+ const L = (i.get("root") ?? []).map((G) => P.get(G.id)).filter(Boolean).sort((G, X) => A(X) - A(G)), [R, Z] = L;
7497
+ if (!R || !Z || R.type !== "group" || R.fold === "never" || S.has(R.id) || !mt(R.id) || A(R) < ef * A(Z))
7473
7498
  break;
7474
7499
  const V = at;
7475
7500
  if (S.add(R.id), u.length = Y, j.length = $.length = 0, m.clear(), at = C("root"), !(E(at) < E(V))) {
@@ -7478,9 +7503,9 @@ function Wn(t, e, o = !1, n, a) {
7478
7503
  }
7479
7504
  }
7480
7505
  }
7481
- const pt = [], ot = (O, E, L) => {
7482
- for (const R of i.get(O) ?? []) {
7483
- const Z = m.get(R.id) ?? P.get(R.id), V = A.get(R.id), G = w.get(R.id), X = {
7506
+ const pt = [], ot = (A, E, L) => {
7507
+ for (const R of i.get(A) ?? []) {
7508
+ const Z = m.get(R.id) ?? P.get(R.id), V = O.get(R.id), G = w.get(R.id), X = {
7484
7509
  ...R,
7485
7510
  x: E.x + V.x,
7486
7511
  y: E.y + V.y,
@@ -7501,43 +7526,43 @@ function Wn(t, e, o = !1, n, a) {
7501
7526
  }
7502
7527
  };
7503
7528
  ot("root", { x: 0, y: 0 }, 0);
7504
- const K = Pf(v, pt, d, F, c), ft = df(
7529
+ const K = Pf(v, pt, d, T, c), ft = df(
7505
7530
  j,
7506
7531
  t.edges,
7507
- new Map(pt.map((O) => [O.id, O])),
7508
- F,
7532
+ new Map(pt.map((A) => [A.id, A])),
7533
+ T,
7509
7534
  Math.max(t.routing.portGap ?? 16, t.routing.edgeGap ?? 16)
7510
7535
  );
7511
- for (const [O, E] of Ic(
7536
+ for (const [A, E] of Ic(
7512
7537
  $.map((L) => ({ ...L, bands: j.find((R) => R.scope === L.scope)?.fold.bands })),
7513
7538
  t.edges,
7514
7539
  new Map(pt.map((L) => [L.id, L])),
7515
7540
  new Set(ft.keys()),
7516
- (L) => Te(L, f)
7541
+ (L) => Fe(L, f)
7517
7542
  ))
7518
- ft.set(O, E);
7519
- for (const O of t.layouts) {
7520
- const E = pt.find((L) => L.id === O.scope);
7521
- !E || !O.minWidth && !O.minHeight || (O.minWidth && E.w > O.minWidth + 0.5 || O.minHeight && E.h > O.minHeight + 0.5) && u.push({
7543
+ ft.set(A, E);
7544
+ for (const A of t.layouts) {
7545
+ const E = pt.find((L) => L.id === A.scope);
7546
+ !E || !A.minWidth && !A.minHeight || (A.minWidth && E.w > A.minWidth + 0.5 || A.minHeight && E.h > A.minHeight + 0.5) && u.push({
7522
7547
  level: "info",
7523
7548
  code: "group-grew",
7524
7549
  message: `${E.id} needs at least ${E.w}×${E.h} for its contents.`,
7525
- line: O.line,
7550
+ line: A.line,
7526
7551
  ids: [E.id]
7527
7552
  });
7528
7553
  }
7529
7554
  pl(t), u.push(...Xl(t), ...fl(t));
7530
- for (const O of t.warnings) u.push({ level: "warning", ...O, ids: [] });
7531
- const Mt = new Map(t.objects.map((O, E) => [O.id, E]));
7532
- pt.sort((O, E) => Mt.get(O.id) - Mt.get(E.id));
7555
+ for (const A of t.warnings) u.push({ level: "warning", ...A, ids: [] });
7556
+ const Mt = new Map(t.objects.map((A, E) => [A.id, E]));
7557
+ pt.sort((A, E) => Mt.get(A.id) - Mt.get(E.id));
7533
7558
  const xt = {
7534
7559
  model: t,
7535
7560
  title: t.title,
7536
7561
  objects: pt,
7537
- byId: new Map(pt.map((O) => [O.id, O])),
7538
- edges: t.edges.map((O) => {
7539
- const E = ft.get(O.id), L = E ? void 0 : K.get(O.id);
7540
- return E ? { ...O, lane: E } : L ? { ...O, plan: L } : O;
7562
+ byId: new Map(pt.map((A) => [A.id, A])),
7563
+ edges: t.edges.map((A) => {
7564
+ const E = ft.get(A.id), L = E ? void 0 : K.get(A.id);
7565
+ return E ? { ...A, lane: E } : L ? { ...A, plan: L } : A;
7541
7566
  }),
7542
7567
  diagnostics: u,
7543
7568
  look: f,
@@ -7571,10 +7596,10 @@ function Pf(t, e, o, n, a) {
7571
7596
  }
7572
7597
  return s;
7573
7598
  }
7574
- function Tf(t) {
7575
- return t.kind === "scene" ? _f(t.source, t.view) : t.kind === "compile" ? vi(t.source) : t.kind === "layout" ? xe.compute(t.doc, t.options) : t.kind === "route" ? Promise.resolve(pn.compute(t.input, t.options)) : t.kind === "candidate" ? Na.candidate(t.baseline, t.spec, t.config) : t.kind === "source" ? Ff(t.source, t.spec) : mr.journey(t.doc, t.options);
7599
+ function Ff(t) {
7600
+ return t.kind === "scene" ? _f(t.source, t.view) : t.kind === "compile" ? vi(t.source) : t.kind === "layout" ? xe.compute(t.doc, t.options) : t.kind === "route" ? Promise.resolve(pn.compute(t.input, t.options)) : t.kind === "candidate" ? Na.candidate(t.baseline, t.spec, t.config) : t.kind === "source" ? Tf(t.source, t.spec) : mr.journey(t.doc, t.options);
7576
7601
  }
7577
- async function Ff(t, e) {
7602
+ async function Tf(t, e) {
7578
7603
  const o = cs(await gi(t)), n = pn.compute(Na.sceneInput(o), {
7579
7604
  ...o.settings.routing,
7580
7605
  previous: []
@@ -7598,7 +7623,7 @@ async function _f(t, e) {
7598
7623
  self.onmessage = async ({ data: t }) => {
7599
7624
  const e = "id" in t ? t.id : void 0, o = "id" in t ? t.task : t;
7600
7625
  try {
7601
- self.postMessage({ id: e, ok: !0, result: await Tf(o) });
7626
+ self.postMessage({ id: e, ok: !0, result: await Ff(o) });
7602
7627
  } catch (n) {
7603
7628
  self.postMessage({
7604
7629
  id: e,