sldeditor 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sldeditor.js CHANGED
@@ -3,7 +3,7 @@ var tv = (e, t, n) => t in e ? ev(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var wt = (e, t, n) => tv(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsxs as j, jsx as m, Fragment as et } from "react/jsx-runtime";
5
5
  import * as Se from "react";
6
- import jt, { forwardRef as Dr, createElement as Ln, useState as ye, useRef as he, useCallback as Kt, useMemo as Rr, useLayoutEffect as sn, useEffect as se, createContext as Fr, useContext as Hr, useId as nv, cloneElement as ov, Fragment as rv } from "react";
6
+ import jt, { forwardRef as Dr, createElement as Ln, useState as ye, useRef as he, useCallback as Kt, useMemo as Rr, useLayoutEffect as sn, useEffect as ae, createContext as Fr, useContext as Hr, useId as nv, cloneElement as ov, Fragment as rv } from "react";
7
7
  import { createPortal as Wr } from "react-dom";
8
8
  /**
9
9
  * @license lucide-react v0.469.0 - ISC
@@ -728,8 +728,8 @@ const no = "-", $v = (e) => {
728
728
  continue;
729
729
  i.push(k);
730
730
  const x = r(g, h);
731
- for (let S = 0; S < x.length; ++S) {
732
- const I = x[S];
731
+ for (let T = 0; T < x.length; ++T) {
732
+ const I = x[T];
733
733
  i.push($ + I);
734
734
  }
735
735
  a = c + (a.length > 0 ? " " + a : a);
@@ -779,7 +779,7 @@ const fe = (e) => {
779
779
  // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
780
780
  Rv.test(e) && !Fv.test(e)
781
781
  ), ai = () => !1, Zv = (e) => Hv.test(e), Qv = (e) => Wv.test(e), e2 = () => {
782
- const e = fe("colors"), t = fe("spacing"), n = fe("blur"), o = fe("brightness"), r = fe("borderColor"), i = fe("borderRadius"), s = fe("borderSpacing"), a = fe("borderWidth"), l = fe("contrast"), c = fe("grayscale"), d = fe("hueRotate"), u = fe("invert"), f = fe("gap"), p = fe("gradientColorStops"), h = fe("gradientColorStopPositions"), g = fe("inset"), w = fe("margin"), $ = fe("opacity"), k = fe("padding"), x = fe("saturate"), S = fe("scale"), I = fe("sepia"), D = fe("skew"), X = fe("space"), V = fe("translate"), te = () => ["auto", "contain", "none"], le = () => ["auto", "hidden", "clip", "visible", "scroll"], R = () => ["auto", ee, t], W = () => [ee, t], xe = () => ["", Re, Ge], me = () => ["auto", ct, ee], be = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], ne = () => ["solid", "dashed", "dotted", "double", "none"], re = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], we = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], ve = () => ["", "0", ee], Ne = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], Ae = () => [ct, ee];
782
+ const e = fe("colors"), t = fe("spacing"), n = fe("blur"), o = fe("brightness"), r = fe("borderColor"), i = fe("borderRadius"), s = fe("borderSpacing"), a = fe("borderWidth"), l = fe("contrast"), c = fe("grayscale"), d = fe("hueRotate"), u = fe("invert"), f = fe("gap"), p = fe("gradientColorStops"), h = fe("gradientColorStopPositions"), g = fe("inset"), w = fe("margin"), $ = fe("opacity"), k = fe("padding"), x = fe("saturate"), T = fe("scale"), I = fe("sepia"), z = fe("skew"), X = fe("space"), V = fe("translate"), te = () => ["auto", "contain", "none"], se = () => ["auto", "hidden", "clip", "visible", "scroll"], R = () => ["auto", ee, t], W = () => [ee, t], xe = () => ["", Re, Ge], me = () => ["auto", ct, ee], be = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], ne = () => ["solid", "dashed", "dotted", "double", "none"], re = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], we = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], ve = () => ["", "0", ee], Ne = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], Ae = () => [ct, ee];
783
783
  return {
784
784
  cacheSize: 500,
785
785
  separator: ":",
@@ -909,21 +909,21 @@ const fe = (e) => {
909
909
  * @see https://tailwindcss.com/docs/overflow
910
910
  */
911
911
  overflow: [{
912
- overflow: le()
912
+ overflow: se()
913
913
  }],
914
914
  /**
915
915
  * Overflow X
916
916
  * @see https://tailwindcss.com/docs/overflow
917
917
  */
918
918
  "overflow-x": [{
919
- "overflow-x": le()
919
+ "overflow-x": se()
920
920
  }],
921
921
  /**
922
922
  * Overflow Y
923
923
  * @see https://tailwindcss.com/docs/overflow
924
924
  */
925
925
  "overflow-y": [{
926
- "overflow-y": le()
926
+ "overflow-y": se()
927
927
  }],
928
928
  /**
929
929
  * Overscroll Behavior
@@ -2417,21 +2417,21 @@ const fe = (e) => {
2417
2417
  * @see https://tailwindcss.com/docs/scale
2418
2418
  */
2419
2419
  scale: [{
2420
- scale: [S]
2420
+ scale: [T]
2421
2421
  }],
2422
2422
  /**
2423
2423
  * Scale X
2424
2424
  * @see https://tailwindcss.com/docs/scale
2425
2425
  */
2426
2426
  "scale-x": [{
2427
- "scale-x": [S]
2427
+ "scale-x": [T]
2428
2428
  }],
2429
2429
  /**
2430
2430
  * Scale Y
2431
2431
  * @see https://tailwindcss.com/docs/scale
2432
2432
  */
2433
2433
  "scale-y": [{
2434
- "scale-y": [S]
2434
+ "scale-y": [T]
2435
2435
  }],
2436
2436
  /**
2437
2437
  * Rotate
@@ -2459,14 +2459,14 @@ const fe = (e) => {
2459
2459
  * @see https://tailwindcss.com/docs/skew
2460
2460
  */
2461
2461
  "skew-x": [{
2462
- "skew-x": [D]
2462
+ "skew-x": [z]
2463
2463
  }],
2464
2464
  /**
2465
2465
  * Skew Y
2466
2466
  * @see https://tailwindcss.com/docs/skew
2467
2467
  */
2468
2468
  "skew-y": [{
2469
- "skew-y": [D]
2469
+ "skew-y": [z]
2470
2470
  }],
2471
2471
  /**
2472
2472
  * Transform Origin
@@ -2840,7 +2840,7 @@ function o2({ children: e }) {
2840
2840
  const c = i.current.getBoundingClientRect();
2841
2841
  let d = t.x, u = t.y;
2842
2842
  d + c.width > window.innerWidth - Lt && (d = Math.max(Lt, t.x - c.width)), u + c.height > window.innerHeight - Lt && (u = Math.max(Lt, t.y - c.height)), r({ left: d, top: u });
2843
- }, [t]), se(() => {
2843
+ }, [t]), ae(() => {
2844
2844
  if (!t.open) return;
2845
2845
  const c = (p) => {
2846
2846
  i.current && !i.current.contains(p.target) && s();
@@ -3318,7 +3318,7 @@ function ui(e, t) {
3318
3318
  function _e(e, t) {
3319
3319
  return di(ui(ln.getState().locale, e), t);
3320
3320
  }
3321
- function ae() {
3321
+ function le() {
3322
3322
  const e = ln((t) => t.locale);
3323
3323
  return (t, n) => di(ui(e, t), n);
3324
3324
  }
@@ -3402,41 +3402,41 @@ const Rn = (e) => (t) => {
3402
3402
  var w, $;
3403
3403
  if (!d) return;
3404
3404
  const k = ++a;
3405
- s = !1, l.forEach((S) => {
3405
+ s = !1, l.forEach((T) => {
3406
3406
  var I;
3407
- return S((I = o()) != null ? I : p);
3407
+ return T((I = o()) != null ? I : p);
3408
3408
  });
3409
3409
  const x = (($ = i.onRehydrateStorage) == null ? void 0 : $.call(i, (w = o()) != null ? w : p)) || void 0;
3410
- return Rn(d.getItem.bind(d))(i.name).then((S) => {
3411
- if (S)
3412
- if (typeof S.version == "number" && S.version !== i.version) {
3410
+ return Rn(d.getItem.bind(d))(i.name).then((T) => {
3411
+ if (T)
3412
+ if (typeof T.version == "number" && T.version !== i.version) {
3413
3413
  if (i.migrate) {
3414
3414
  const I = i.migrate(
3415
- S.state,
3416
- S.version
3415
+ T.state,
3416
+ T.version
3417
3417
  );
3418
- return I instanceof Promise ? I.then((D) => [!0, D]) : [!0, I];
3418
+ return I instanceof Promise ? I.then((z) => [!0, z]) : [!0, I];
3419
3419
  }
3420
3420
  console.error(
3421
3421
  "State loaded from storage couldn't be migrated since no migrate function was provided"
3422
3422
  );
3423
3423
  } else
3424
- return [!1, S.state];
3424
+ return [!1, T.state];
3425
3425
  return [!1, void 0];
3426
- }).then((S) => {
3426
+ }).then((T) => {
3427
3427
  var I;
3428
3428
  if (k !== a)
3429
3429
  return;
3430
- const [D, X] = S;
3430
+ const [z, X] = T;
3431
3431
  if (h = i.merge(
3432
3432
  X,
3433
3433
  (I = o()) != null ? I : p
3434
- ), n(h, !0), D)
3434
+ ), n(h, !0), z)
3435
3435
  return u();
3436
3436
  }).then(() => {
3437
- k === a && (x == null || x(o(), void 0), h = o(), s = !0, c.forEach((S) => S(h)));
3438
- }).catch((S) => {
3439
- k === a && (x == null || x(void 0, S));
3437
+ k === a && (x == null || x(o(), void 0), h = o(), s = !0, c.forEach((T) => T(h)));
3438
+ }).catch((T) => {
3439
+ k === a && (x == null || x(void 0, T));
3440
3440
  });
3441
3441
  };
3442
3442
  return r.persist = {
@@ -3613,53 +3613,53 @@ function b2(e) {
3613
3613
  var v;
3614
3614
  return (v = y.layout) == null ? void 0 : v.at;
3615
3615
  }).map((y) => y.id)
3616
- ), S = new hi();
3616
+ ), T = new hi();
3617
3617
  for (const y of r)
3618
- S.add(y.ends[0]), S.add(y.ends[1]), S.union(y.ends[0], y.ends[1]);
3618
+ T.add(y.ends[0]), T.add(y.ends[1]), T.union(y.ends[0], y.ends[1]);
3619
3619
  for (const y of t) {
3620
3620
  const v = i.get(y.kind);
3621
3621
  if (v)
3622
- for (const N of v.terminals) S.add(`${y.id}.${N.id}`);
3622
+ for (const S of v.terminals) T.add(`${y.id}.${S.id}`);
3623
3623
  }
3624
- for (const y of n) S.add(y.id);
3624
+ for (const y of n) T.add(y.id);
3625
3625
  const I = [];
3626
- for (const [, y] of S.groups())
3626
+ for (const [, y] of T.groups())
3627
3627
  y.length >= 2 && I.push(y);
3628
- const D = /* @__PURE__ */ new Map();
3628
+ const z = /* @__PURE__ */ new Map();
3629
3629
  for (const y of I)
3630
- for (const v of y) D.set(v, [y]);
3630
+ for (const v of y) z.set(v, [y]);
3631
3631
  const X = /* @__PURE__ */ new Map();
3632
3632
  for (const y of I) {
3633
3633
  const v = y.filter($);
3634
3634
  if (v.length !== 0)
3635
- for (const N of v) {
3636
- const M = y.filter((_) => _ !== N), E = X.get(N) ?? [];
3637
- E.push(...M), X.set(N, E);
3635
+ for (const S of v) {
3636
+ const E = y.filter((_) => _ !== S), N = X.get(S) ?? [];
3637
+ N.push(...E), X.set(S, N);
3638
3638
  }
3639
3639
  }
3640
3640
  {
3641
- const N = (C) => p.has(C) && !!g(C), M = (C) => {
3641
+ const S = (C) => p.has(C) && !!g(C), E = (C) => {
3642
3642
  if ($(C)) return null;
3643
3643
  if (k.has(C)) return C;
3644
- const T = C.indexOf(".");
3645
- return T > 0 ? C.slice(0, T) : null;
3646
- }, E = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), A = (C, T) => {
3647
- E.has(C) || E.set(C, /* @__PURE__ */ new Set()), E.has(T) || E.set(T, /* @__PURE__ */ new Set()), C !== T && (E.get(C).add(T), E.get(T).add(C));
3644
+ const M = C.indexOf(".");
3645
+ return M > 0 ? C.slice(0, M) : null;
3646
+ }, N = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Set(), A = (C, M) => {
3647
+ N.has(C) || N.set(C, /* @__PURE__ */ new Set()), N.has(M) || N.set(M, /* @__PURE__ */ new Set()), C !== M && (N.get(C).add(M), N.get(M).add(C));
3648
3648
  };
3649
3649
  for (const C of I) {
3650
- const T = [];
3650
+ const M = [];
3651
3651
  let B = !1;
3652
3652
  for (const H of C) {
3653
3653
  if ($(H)) {
3654
3654
  B = !0;
3655
3655
  continue;
3656
3656
  }
3657
- const J = M(H);
3658
- J && T.push(J);
3657
+ const J = E(H);
3658
+ J && M.push(J);
3659
3659
  }
3660
- const L = [...new Set(T)];
3660
+ const L = [...new Set(M)];
3661
3661
  for (const H of L)
3662
- E.has(H) || E.set(H, /* @__PURE__ */ new Set()), B && _.add(H);
3662
+ N.has(H) || N.set(H, /* @__PURE__ */ new Set()), B && _.add(H);
3663
3663
  const F = L.filter((H) => k.has(H)), q = L.filter((H) => !k.has(H));
3664
3664
  if (F.length > 0) {
3665
3665
  for (const H of F) for (const J of q) A(H, J);
@@ -3669,32 +3669,32 @@ function b2(e) {
3669
3669
  for (let H = 0; H < q.length; H++)
3670
3670
  for (let J = H + 1; J < q.length; J++) A(q[H], q[J]);
3671
3671
  }
3672
- const z = (C, T) => {
3672
+ const D = (C, M) => {
3673
3673
  const B = g(C);
3674
3674
  if (!B) return null;
3675
3675
  for (const L of B.terminals) {
3676
3676
  const F = `${C}.${L.id}`;
3677
- for (const q of D.get(F) ?? [])
3678
- for (const H of q) if (M(H) === T) return L;
3677
+ for (const q of z.get(F) ?? [])
3678
+ for (const H of q) if (E(H) === M) return L;
3679
3679
  }
3680
3680
  return null;
3681
3681
  }, P = (C) => {
3682
- const T = (K) => {
3682
+ const M = (K) => {
3683
3683
  var Q;
3684
- return ((Q = E.get(K)) == null ? void 0 : Q.size) ?? 0;
3684
+ return ((Q = N.get(K)) == null ? void 0 : Q.size) ?? 0;
3685
3685
  }, B = (K) => {
3686
3686
  var Q;
3687
3687
  return ((Q = g(K)) == null ? void 0 : Q.category) ?? "";
3688
3688
  }, L = (K) => {
3689
3689
  const Q = B(K);
3690
- return Q === "source" ? 0 : Q === "renewable" ? 1 : 2 + Math.min(T(K), 9) / 10;
3691
- }, F = C.filter(N).sort((K, Q) => L(K) - L(Q) || K.localeCompare(Q))[0];
3690
+ return Q === "source" ? 0 : Q === "renewable" ? 1 : 2 + Math.min(M(K), 9) / 10;
3691
+ }, F = C.filter(S).sort((K, Q) => L(K) - L(Q) || K.localeCompare(Q))[0];
3692
3692
  if (!F) return;
3693
3693
  const q = /* @__PURE__ */ new Map([[F, null]]), H = /* @__PURE__ */ new Map([[F, 0]]), J = /* @__PURE__ */ new Map(), Z = [], G = [F], Y = /* @__PURE__ */ new Set([F]);
3694
3694
  for (; G.length; ) {
3695
3695
  const K = G.shift();
3696
3696
  Z.push(K);
3697
- for (const Q of [...E.get(K) ?? []].sort((Ee, Me) => Ee.localeCompare(Me)))
3697
+ for (const Q of [...N.get(K) ?? []].sort((Ee, Me) => Ee.localeCompare(Me)))
3698
3698
  Y.has(Q) || (Y.add(Q), q.set(Q, K), H.set(Q, (H.get(K) ?? 0) + 1), J.has(K) || J.set(K, []), J.get(K).push(Q), G.push(Q));
3699
3699
  }
3700
3700
  let U = 0;
@@ -3718,45 +3718,45 @@ function b2(e) {
3718
3718
  let Me = 0;
3719
3719
  const Bt = q.get(K) ?? null;
3720
3720
  if (Bt) {
3721
- const bt = z(K, Bt);
3721
+ const bt = D(K, Bt);
3722
3722
  bt && (Me = zt(bt.orientation, "n"));
3723
3723
  } else {
3724
- const bt = (J.get(K) ?? [])[0], Mo = bt ? z(K, bt) : null;
3724
+ const bt = (J.get(K) ?? [])[0], Mo = bt ? D(K, bt) : null;
3725
3725
  Mo && (Me = zt(Mo.orientation, "s"));
3726
3726
  }
3727
3727
  l.set(K, { at: [Q, Ee], rot: Me, mirror: !1 }), u.add(K);
3728
3728
  }
3729
3729
  }, O = /* @__PURE__ */ new Set();
3730
- for (const C of E.keys()) {
3730
+ for (const C of N.keys()) {
3731
3731
  if (O.has(C)) continue;
3732
- const T = [], B = [C];
3732
+ const M = [], B = [C];
3733
3733
  for (O.add(C); B.length; ) {
3734
3734
  const L = B.pop();
3735
- T.push(L);
3736
- for (const F of E.get(L) ?? []) O.has(F) || (O.add(F), B.push(F));
3735
+ M.push(L);
3736
+ for (const F of N.get(L) ?? []) O.has(F) || (O.add(F), B.push(F));
3737
3737
  }
3738
- T.length < 2 || T.some((L) => _.has(L)) || T.some((L) => l.has(L) || x.has(L)) || T.some(N) && P(T);
3738
+ M.length < 2 || M.some((L) => _.has(L)) || M.some((L) => l.has(L) || x.has(L)) || M.some(S) && P(M);
3739
3739
  }
3740
3740
  }
3741
3741
  const V = /* @__PURE__ */ new Map();
3742
3742
  for (const y of I) {
3743
3743
  const v = y.filter($);
3744
3744
  if (v.length !== 0)
3745
- for (const N of y) {
3746
- if ($(N)) continue;
3747
- const M = N.indexOf(".");
3748
- if (M < 0) continue;
3749
- const E = N.slice(0, M), _ = N.slice(M + 1), A = V.get(E) ?? [];
3750
- for (const z of v)
3751
- A.some((P) => P.busId === z && P.pin === _) || A.push({ busId: z, pin: _ });
3752
- V.set(E, A);
3745
+ for (const S of y) {
3746
+ if ($(S)) continue;
3747
+ const E = S.indexOf(".");
3748
+ if (E < 0) continue;
3749
+ const N = S.slice(0, E), _ = S.slice(E + 1), A = V.get(N) ?? [];
3750
+ for (const D of v)
3751
+ A.some((P) => P.busId === D && P.pin === _) || A.push({ busId: D, pin: _ });
3752
+ V.set(N, A);
3753
3753
  }
3754
3754
  }
3755
- const te = [], le = /* @__PURE__ */ new Set();
3755
+ const te = [], se = /* @__PURE__ */ new Set();
3756
3756
  for (const [y, v] of V)
3757
- if (new Set(v.map((M) => M.busId)).size >= 2) {
3758
- const M = ((_o = i.get(((ko = p.get(y)) == null ? void 0 : ko.kind) ?? "")) == null ? void 0 : _o.category) === "transformer" ? "vertical" : "horizontal";
3759
- te.push({ elementId: y, attachments: v, orientation: M }), M === "vertical" && le.add(y);
3757
+ if (new Set(v.map((E) => E.busId)).size >= 2) {
3758
+ const E = ((_o = i.get(((ko = p.get(y)) == null ? void 0 : ko.kind) ?? "")) == null ? void 0 : _o.category) === "transformer" ? "vertical" : "horizontal";
3759
+ te.push({ elementId: y, attachments: v, orientation: E }), E === "vertical" && se.add(y);
3760
3760
  }
3761
3761
  const R = /* @__PURE__ */ new Map(), W = (y, v) => {
3762
3762
  y !== v && (R.has(y) || R.set(y, /* @__PURE__ */ new Set()), R.has(v) || R.set(v, /* @__PURE__ */ new Set()), R.get(y).add(v), R.get(v).add(y));
@@ -3766,92 +3766,92 @@ function b2(e) {
3766
3766
  for (const y of t) {
3767
3767
  const v = i.get(y.kind);
3768
3768
  if (!v || v.terminals.length < 2) continue;
3769
- const N = v.terminals.map(
3770
- (M) => `${y.id}.${M.id}`
3769
+ const S = v.terminals.map(
3770
+ (E) => `${y.id}.${E.id}`
3771
3771
  );
3772
- for (let M = 0; M < N.length; M++)
3773
- for (let E = M + 1; E < N.length; E++)
3774
- W(N[M], N[E]);
3772
+ for (let E = 0; E < S.length; E++)
3773
+ for (let N = E + 1; N < S.length; N++)
3774
+ W(S[E], S[N]);
3775
3775
  }
3776
3776
  for (const y of t) {
3777
- if (le.has(y.id)) continue;
3777
+ if (se.has(y.id)) continue;
3778
3778
  const v = i.get(y.kind);
3779
3779
  if (!v || v.category !== "transformer" || v.terminals.length < 2) continue;
3780
- const N = v.terminals.map(
3780
+ const S = v.terminals.map(
3781
3781
  (_) => `${y.id}.${_.id}`
3782
- ), M = /* @__PURE__ */ new Map();
3783
- for (const _ of N) {
3782
+ ), E = /* @__PURE__ */ new Map();
3783
+ for (const _ of S) {
3784
3784
  const A = _.slice(y.id.length + 1);
3785
- M.set(A, /* @__PURE__ */ new Set());
3786
- const z = new Set(N.filter((C) => C !== _)), P = /* @__PURE__ */ new Set([_]), O = [_];
3785
+ E.set(A, /* @__PURE__ */ new Set());
3786
+ const D = new Set(S.filter((C) => C !== _)), P = /* @__PURE__ */ new Set([_]), O = [_];
3787
3787
  for (; O.length > 0; ) {
3788
3788
  const C = O.shift();
3789
3789
  if ($(C)) {
3790
- M.get(A).add(C);
3790
+ E.get(A).add(C);
3791
3791
  continue;
3792
3792
  }
3793
- const T = R.get(C);
3794
- if (T)
3795
- for (const B of T)
3796
- P.has(B) || z.has(B) || (P.add(B), O.push(B));
3793
+ const M = R.get(C);
3794
+ if (M)
3795
+ for (const B of M)
3796
+ P.has(B) || D.has(B) || (P.add(B), O.push(B));
3797
3797
  }
3798
3798
  }
3799
- const E = /* @__PURE__ */ new Set();
3800
- for (const _ of M.values())
3801
- for (const A of _) E.add(A);
3802
- if (E.size >= 2) {
3799
+ const N = /* @__PURE__ */ new Set();
3800
+ for (const _ of E.values())
3801
+ for (const A of _) N.add(A);
3802
+ if (N.size >= 2) {
3803
3803
  const _ = [];
3804
- for (const [A, z] of M)
3805
- for (const P of z) _.push({ busId: P, pin: A });
3806
- te.push({ elementId: y.id, attachments: _, orientation: "vertical" }), le.add(y.id);
3804
+ for (const [A, D] of E)
3805
+ for (const P of D) _.push({ busId: P, pin: A });
3806
+ te.push({ elementId: y.id, attachments: _, orientation: "vertical" }), se.add(y.id);
3807
3807
  }
3808
3808
  }
3809
3809
  const xe = (y, v) => {
3810
- var z;
3811
- const N = g(v), M = N ? N.terminals.map((P) => `${v}.${P.id}`) : [], E = y, _ = /* @__PURE__ */ new Set([E, ...M]), A = [E];
3810
+ var D;
3811
+ const S = g(v), E = S ? S.terminals.map((P) => `${v}.${P.id}`) : [], N = y, _ = /* @__PURE__ */ new Set([N, ...E]), A = [N];
3812
3812
  for (; A.length > 0; ) {
3813
3813
  const P = A.shift(), O = P.indexOf(".");
3814
3814
  if (O > 0) {
3815
- const T = P.slice(0, O), B = p.get(T);
3815
+ const M = P.slice(0, O), B = p.get(M);
3816
3816
  if (B) {
3817
- const L = (z = i.get(B.kind)) == null ? void 0 : z.category;
3817
+ const L = (D = i.get(B.kind)) == null ? void 0 : D.category;
3818
3818
  if (L && Wo.has(L)) return !0;
3819
3819
  }
3820
3820
  }
3821
3821
  const C = R.get(P);
3822
3822
  if (C)
3823
- for (const T of C)
3824
- _.has(T) || (_.add(T), A.push(T));
3823
+ for (const M of C)
3824
+ _.has(M) || (_.add(M), A.push(M));
3825
3825
  }
3826
3826
  return !1;
3827
3827
  };
3828
3828
  for (const y of te) {
3829
3829
  if (y.orientation !== "horizontal") continue;
3830
- const v = new Set(y.attachments.map((M) => M.busId));
3831
- let N = 0;
3832
- for (const M of v)
3833
- xe(M, y.elementId) && N++;
3834
- N === 1 && (y.orientation = "vertical", le.add(y.elementId));
3830
+ const v = new Set(y.attachments.map((E) => E.busId));
3831
+ let S = 0;
3832
+ for (const E of v)
3833
+ xe(E, y.elementId) && S++;
3834
+ S === 1 && (y.orientation = "vertical", se.add(y.elementId));
3835
3835
  }
3836
3836
  for (const y of t) {
3837
- if (le.has(y.id) || y.kind !== "breaker") continue;
3837
+ if (se.has(y.id) || y.kind !== "breaker") continue;
3838
3838
  const v = i.get(y.kind);
3839
3839
  if (!v || v.terminals.length !== 2) continue;
3840
- const N = v.terminals.map(
3840
+ const S = v.terminals.map(
3841
3841
  (_) => `${y.id}.${_.id}`
3842
- ), M = /* @__PURE__ */ new Map();
3843
- for (const _ of N) {
3844
- const A = _.slice(y.id.length + 1), z = new Set(N.filter((C) => C !== _)), P = /* @__PURE__ */ new Set([_]), O = [_];
3842
+ ), E = /* @__PURE__ */ new Map();
3843
+ for (const _ of S) {
3844
+ const A = _.slice(y.id.length + 1), D = new Set(S.filter((C) => C !== _)), P = /* @__PURE__ */ new Set([_]), O = [_];
3845
3845
  for (; O.length > 0; ) {
3846
3846
  const C = O.shift();
3847
3847
  if ($(C)) {
3848
- M.set(A, C);
3848
+ E.set(A, C);
3849
3849
  break;
3850
3850
  }
3851
- const T = R.get(C);
3852
- if (T)
3853
- for (const B of T) {
3854
- if (P.has(B) || z.has(B)) continue;
3851
+ const M = R.get(C);
3852
+ if (M)
3853
+ for (const B of M) {
3854
+ if (P.has(B) || D.has(B)) continue;
3855
3855
  const L = B.indexOf(".");
3856
3856
  if (L > 0) {
3857
3857
  const F = B.slice(0, L);
@@ -3864,10 +3864,10 @@ function b2(e) {
3864
3864
  }
3865
3865
  }
3866
3866
  }
3867
- if (new Set(M.values()).size >= 2) {
3867
+ if (new Set(E.values()).size >= 2) {
3868
3868
  const _ = [];
3869
- for (const [A, z] of M)
3870
- _.push({ busId: z, pin: A });
3869
+ for (const [A, D] of E)
3870
+ _.push({ busId: D, pin: A });
3871
3871
  te.push({
3872
3872
  elementId: y.id,
3873
3873
  attachments: _,
@@ -3878,24 +3878,24 @@ function b2(e) {
3878
3878
  const me = /* @__PURE__ */ new Map();
3879
3879
  for (const y of n) me.set(y.id, /* @__PURE__ */ new Map());
3880
3880
  for (const y of te) {
3881
- const v = Array.from(new Set(y.attachments.map((N) => N.busId)));
3882
- for (const N of v)
3883
- for (const M of v)
3884
- N !== M && (($o = me.get(N)) == null || $o.set(M, y));
3881
+ const v = Array.from(new Set(y.attachments.map((S) => S.busId)));
3882
+ for (const S of v)
3883
+ for (const E of v)
3884
+ S !== E && (($o = me.get(S)) == null || $o.set(E, y));
3885
3885
  }
3886
3886
  const be = (y) => {
3887
- var N;
3888
- const v = (N = i.get(y)) == null ? void 0 : N.category;
3887
+ var S;
3888
+ const v = (S = i.get(y)) == null ? void 0 : S.category;
3889
3889
  return v ? Wo.has(v) : !1;
3890
3890
  }, ne = [];
3891
3891
  for (const y of n) {
3892
3892
  const v = X.get(y.id);
3893
3893
  if (v)
3894
- for (const N of v) {
3895
- if ($(N)) continue;
3896
- const M = N.indexOf(".");
3897
- if (M < 0) continue;
3898
- const E = N.slice(0, M), _ = p.get(E);
3894
+ for (const S of v) {
3895
+ if ($(S)) continue;
3896
+ const E = S.indexOf(".");
3897
+ if (E < 0) continue;
3898
+ const N = S.slice(0, E), _ = p.get(N);
3899
3899
  if (_ && be(_.kind)) {
3900
3900
  ne.push(y.id);
3901
3901
  break;
@@ -3908,12 +3908,12 @@ function b2(e) {
3908
3908
  {
3909
3909
  const y = [...ne];
3910
3910
  for (; y.length > 0; ) {
3911
- const v = y.shift(), N = re.get(v), M = me.get(v);
3912
- if (M)
3913
- for (const [E, _] of M) {
3914
- if (re.has(E)) continue;
3915
- const A = _.orientation === "horizontal" ? N : N + 1;
3916
- re.set(E, A), y.push(E);
3911
+ const v = y.shift(), S = re.get(v), E = me.get(v);
3912
+ if (E)
3913
+ for (const [N, _] of E) {
3914
+ if (re.has(N)) continue;
3915
+ const A = _.orientation === "horizontal" ? S : S + 1;
3916
+ re.set(N, A), y.push(N);
3917
3917
  }
3918
3918
  }
3919
3919
  }
@@ -3924,23 +3924,23 @@ function b2(e) {
3924
3924
  }
3925
3925
  const we = /* @__PURE__ */ new Map();
3926
3926
  for (const y of n) {
3927
- const v = re.get(y.id), N = we.get(v) ?? [];
3928
- N.push(y.id), we.set(v, N);
3927
+ const v = re.get(y.id), S = we.get(v) ?? [];
3928
+ S.push(y.id), we.set(v, S);
3929
3929
  }
3930
- const ve = [...we.keys()].sort((y, v) => y - v), Ne = (y, v, N) => {
3931
- const M = `${y.elementId}.${N}`, E = v, _ = g(y.elementId), A = /* @__PURE__ */ new Set();
3930
+ const ve = [...we.keys()].sort((y, v) => y - v), Ne = (y, v, S) => {
3931
+ const E = `${y.elementId}.${S}`, N = v, _ = g(y.elementId), A = /* @__PURE__ */ new Set();
3932
3932
  if (_)
3933
- for (const T of _.terminals)
3934
- T.id !== N && A.add(`${y.elementId}.${T.id}`);
3935
- const z = /* @__PURE__ */ new Set([M]), P = [
3936
- { ref: M, dist: 0 }
3937
- ], O = /* @__PURE__ */ new Map(), C = (T, B, L, F) => {
3938
- z.add(T), O.set(T, B), P.push({ ref: T, dist: F + L });
3933
+ for (const M of _.terminals)
3934
+ M.id !== S && A.add(`${y.elementId}.${M.id}`);
3935
+ const D = /* @__PURE__ */ new Set([E]), P = [
3936
+ { ref: E, dist: 0 }
3937
+ ], O = /* @__PURE__ */ new Map(), C = (M, B, L, F) => {
3938
+ D.add(M), O.set(M, B), P.push({ ref: M, dist: F + L });
3939
3939
  };
3940
3940
  for (; P.length > 0; ) {
3941
- const { ref: T, dist: B } = P.shift();
3942
- if (T === E) {
3943
- const H = O.get(E);
3941
+ const { ref: M, dist: B } = P.shift();
3942
+ if (M === N) {
3943
+ const H = O.get(N);
3944
3944
  let J;
3945
3945
  if (H) {
3946
3946
  const Z = H.indexOf(".");
@@ -3951,120 +3951,120 @@ function b2(e) {
3951
3951
  }
3952
3952
  return { extent: B, head: J };
3953
3953
  }
3954
- const L = T.indexOf(".");
3954
+ const L = M.indexOf(".");
3955
3955
  if (L < 0)
3956
3956
  continue;
3957
- const F = T.slice(0, L), q = T.slice(L + 1);
3958
- if (!$(F) && !le.has(F)) {
3957
+ const F = M.slice(0, L), q = M.slice(L + 1);
3958
+ if (!$(F) && !se.has(F)) {
3959
3959
  const H = g(F), J = H == null ? void 0 : H.terminals.find((Z) => Z.id === q);
3960
3960
  if (H && J)
3961
3961
  for (const Z of H.terminals) {
3962
3962
  if (Z.id === q) continue;
3963
3963
  const G = `${F}.${Z.id}`;
3964
- z.has(G) || A.has(G) || C(G, T, Math.abs(J.y - Z.y), B);
3964
+ D.has(G) || A.has(G) || C(G, M, Math.abs(J.y - Z.y), B);
3965
3965
  }
3966
3966
  }
3967
- for (const H of D.get(T) ?? [])
3967
+ for (const H of z.get(M) ?? [])
3968
3968
  for (const J of H) {
3969
- if (J === T || z.has(J) || A.has(J)) continue;
3970
- const Z = $(T) || $(J);
3971
- C(J, T, Z ? Ro : _t, B);
3969
+ if (J === M || D.has(J) || A.has(J)) continue;
3970
+ const Z = $(M) || $(J);
3971
+ C(J, M, Z ? Ro : _t, B);
3972
3972
  }
3973
3973
  }
3974
3974
  return { extent: 0 };
3975
3975
  }, Ae = (y, v) => {
3976
- var T, B, L;
3977
- const N = (T = me.get(y)) == null ? void 0 : T.get(v);
3978
- if (!N || N.orientation === "horizontal") return kt;
3979
- const M = g(N.elementId);
3980
- if (!M) return kt;
3981
- const E = (B = N.attachments.find((F) => F.busId === y)) == null ? void 0 : B.pin, _ = (L = N.attachments.find((F) => F.busId === v)) == null ? void 0 : L.pin;
3982
- if (!E || !_) return kt;
3983
- const A = M.terminals.find((F) => F.id === E), z = M.terminals.find((F) => F.id === _);
3984
- if (!A || !z) return kt;
3985
- const P = Math.abs(z.y - A.y), O = Ne(N, y, E).extent, C = Ne(N, v, _).extent;
3976
+ var M, B, L;
3977
+ const S = (M = me.get(y)) == null ? void 0 : M.get(v);
3978
+ if (!S || S.orientation === "horizontal") return kt;
3979
+ const E = g(S.elementId);
3980
+ if (!E) return kt;
3981
+ const N = (B = S.attachments.find((F) => F.busId === y)) == null ? void 0 : B.pin, _ = (L = S.attachments.find((F) => F.busId === v)) == null ? void 0 : L.pin;
3982
+ if (!N || !_) return kt;
3983
+ const A = E.terminals.find((F) => F.id === N), D = E.terminals.find((F) => F.id === _);
3984
+ if (!A || !D) return kt;
3985
+ const P = Math.abs(D.y - A.y), O = Ne(S, y, N).extent, C = Ne(S, v, _).extent;
3986
3986
  return O + P + C;
3987
3987
  }, yn = /* @__PURE__ */ new Map();
3988
3988
  for (const y of te) {
3989
3989
  if (y.orientation !== "vertical") continue;
3990
3990
  const v = y.attachments.slice().sort(
3991
- (z, P) => (re.get(z.busId) ?? 0) - (re.get(P.busId) ?? 0)
3991
+ (D, P) => (re.get(D.busId) ?? 0) - (re.get(P.busId) ?? 0)
3992
3992
  );
3993
3993
  if (v.length < 2) continue;
3994
- const N = v[0].busId, M = v[1].busId, E = v[0].pin, A = Ne(y, N, E).head ?? y.elementId;
3995
- yn.set(A, { lowerBusId: M });
3994
+ const S = v[0].busId, E = v[1].busId, N = v[0].pin, A = Ne(y, S, N).head ?? y.elementId;
3995
+ yn.set(A, { lowerBusId: E });
3996
3996
  }
3997
3997
  const lo = 30, co = (y) => {
3998
3998
  const v = g(y);
3999
3999
  return Math.max((v == null ? void 0 : v.width) ?? Ye, Ye);
4000
- }, qx = 2, uo = (y, v, N, M = 0) => {
4001
- const E = g(v);
4000
+ }, qx = 2, uo = (y, v, S, E = 0) => {
4001
+ const N = g(v);
4002
4002
  let _ = co(v);
4003
- if (E && !N.has(v) && M < qx) {
4004
- N.add(v);
4003
+ if (N && !S.has(v) && E < qx) {
4004
+ S.add(v);
4005
4005
  let A = 0;
4006
- for (const z of E.terminals) {
4007
- const P = `${v}.${z.id}`;
4006
+ for (const D of N.terminals) {
4007
+ const P = `${v}.${D.id}`;
4008
4008
  if (P !== y)
4009
- for (const O of D.get(P) ?? []) {
4009
+ for (const O of z.get(P) ?? []) {
4010
4010
  const C = /* @__PURE__ */ new Set();
4011
- let T = !1;
4011
+ let M = !1;
4012
4012
  for (const L of O) {
4013
4013
  if (L === P) continue;
4014
4014
  if ($(L)) {
4015
- T = !0;
4015
+ M = !0;
4016
4016
  continue;
4017
4017
  }
4018
4018
  const F = L.indexOf(".");
4019
4019
  if (F < 0) continue;
4020
4020
  const q = L.slice(0, F);
4021
- q === v || N.has(q) || le.has(q) || C.add(q);
4021
+ q === v || S.has(q) || se.has(q) || C.add(q);
4022
4022
  }
4023
- if (T || C.size === 0) continue;
4023
+ if (M || C.size === 0) continue;
4024
4024
  let B = 0;
4025
4025
  for (const L of C) {
4026
4026
  const F = [...O].find(
4027
4027
  (q) => q.indexOf(".") > 0 && q.slice(0, q.indexOf(".")) === L
4028
4028
  );
4029
- B += (F ? uo(F, L, N, M + 1) : co(L)) + lo;
4029
+ B += (F ? uo(F, L, S, E + 1) : co(L)) + lo;
4030
4030
  }
4031
4031
  A = Math.max(A, B - lo);
4032
4032
  }
4033
4033
  }
4034
- N.delete(v), _ = Math.max(_, A);
4034
+ S.delete(v), _ = Math.max(_, A);
4035
4035
  }
4036
4036
  return _;
4037
4037
  }, pt = 320, ot = /* @__PURE__ */ new Map(), mo = (y, v) => {
4038
- if (!le.has(y)) return !1;
4039
- const N = te.find((A) => A.elementId === y), M = N == null ? void 0 : N.attachments.find((A) => A.busId !== v);
4040
- if (!M) return !1;
4041
- const E = re.get(v) ?? 0;
4042
- return (re.get(M.busId) ?? 0) < E;
4043
- }, gt = (y, v, N) => {
4044
- const M = yn.get(y);
4045
- if (M) {
4046
- const _ = ot.get(M.lowerBusId);
4038
+ if (!se.has(y)) return !1;
4039
+ const S = te.find((A) => A.elementId === y), E = S == null ? void 0 : S.attachments.find((A) => A.busId !== v);
4040
+ if (!E) return !1;
4041
+ const N = re.get(v) ?? 0;
4042
+ return (re.get(E.busId) ?? 0) < N;
4043
+ }, gt = (y, v, S) => {
4044
+ const E = yn.get(y);
4045
+ if (E) {
4046
+ const _ = ot.get(E.lowerBusId);
4047
4047
  if (_ !== void 0)
4048
4048
  return Math.max(v, _ + Ye);
4049
4049
  }
4050
- let E = 0;
4051
- return N && (E = uo(N, y, /* @__PURE__ */ new Set())), Math.max(v, Ye, E);
4050
+ let N = 0;
4051
+ return S && (N = uo(S, y, /* @__PURE__ */ new Set())), Math.max(v, Ye, N);
4052
4052
  }, fo = (y, v) => {
4053
4053
  if (ot.has(y)) return ot.get(y);
4054
4054
  if (v.has(y)) return pt;
4055
4055
  v.add(y);
4056
- const N = X.get(y) ?? [];
4057
- let M = 0, E = 0;
4058
- for (const A of N) {
4056
+ const S = X.get(y) ?? [];
4057
+ let E = 0, N = 0;
4058
+ for (const A of S) {
4059
4059
  if ($(A)) continue;
4060
- const z = A.indexOf(".");
4061
- if (z < 0) continue;
4062
- const P = A.slice(0, z), O = A.slice(z + 1);
4060
+ const D = A.indexOf(".");
4061
+ if (D < 0) continue;
4062
+ const P = A.slice(0, D), O = A.slice(D + 1);
4063
4063
  if (mo(P, y)) continue;
4064
4064
  const C = g(P);
4065
4065
  if (!C) continue;
4066
- const T = C.terminals.find((F) => F.id === O);
4067
- if (!T) continue;
4066
+ const M = C.terminals.find((F) => F.id === O);
4067
+ if (!M) continue;
4068
4068
  const B = yn.get(P);
4069
4069
  B && fo(B.lowerBusId, v);
4070
4070
  const L = gt(
@@ -4072,39 +4072,39 @@ function b2(e) {
4072
4072
  C.width,
4073
4073
  `${P}.${O}`
4074
4074
  );
4075
- T.y > 0 ? M += L : E += L;
4075
+ M.y > 0 ? E += L : N += L;
4076
4076
  }
4077
4077
  const _ = Math.max(
4078
4078
  pt,
4079
- Math.max(M, E) + Ye
4079
+ Math.max(E, N) + Ye
4080
4080
  );
4081
4081
  return ot.set(y, _), v.delete(y), _;
4082
4082
  };
4083
4083
  for (const y of n) fo(y.id, /* @__PURE__ */ new Set());
4084
- const qe = /* @__PURE__ */ new Map(), Gx = (y, v, N) => {
4085
- const M = g(v);
4086
- if (!M) return;
4087
- const E = `${v}.${N}`, _ = M.terminals.filter((P) => P.id !== N).map((P) => `${v}.${P.id}`);
4084
+ const qe = /* @__PURE__ */ new Map(), Gx = (y, v, S) => {
4085
+ const E = g(v);
4086
+ if (!E) return;
4087
+ const N = `${v}.${S}`, _ = E.terminals.filter((P) => P.id !== S).map((P) => `${v}.${P.id}`);
4088
4088
  if (_.length === 0) return;
4089
- const A = /* @__PURE__ */ new Set([E, ..._]), z = _.slice();
4090
- for (; z.length > 0; ) {
4091
- const P = z.shift();
4089
+ const A = /* @__PURE__ */ new Set([N, ..._]), D = _.slice();
4090
+ for (; D.length > 0; ) {
4091
+ const P = D.shift();
4092
4092
  if ($(P) && P !== y) {
4093
4093
  const C = c.get(P);
4094
4094
  return C ? C.at[0] : void 0;
4095
4095
  }
4096
- for (const C of D.get(P) ?? [])
4097
- for (const T of C)
4098
- T === P || A.has(T) || (A.add(T), z.push(T));
4096
+ for (const C of z.get(P) ?? [])
4097
+ for (const M of C)
4098
+ M === P || A.has(M) || (A.add(M), D.push(M));
4099
4099
  const O = P.indexOf(".");
4100
4100
  if (O > 0) {
4101
4101
  const C = P.slice(0, O);
4102
4102
  if (!$(C)) {
4103
- const T = g(C);
4104
- if (T)
4105
- for (const B of T.terminals) {
4103
+ const M = g(C);
4104
+ if (M)
4105
+ for (const B of M.terminals) {
4106
4106
  const L = `${C}.${B.id}`;
4107
- A.has(L) || (A.add(L), z.push(L));
4107
+ A.has(L) || (A.add(L), D.push(L));
4108
4108
  }
4109
4109
  }
4110
4110
  }
@@ -4112,13 +4112,13 @@ function b2(e) {
4112
4112
  }, Xx = (y) => {
4113
4113
  const v = X.get(y);
4114
4114
  if (!v || v.length === 0) return;
4115
- const N = c.get(y);
4116
- if (!N) return;
4117
- const M = v.flatMap((T) => {
4118
- if ($(T)) return [];
4119
- const B = T.indexOf(".");
4115
+ const S = c.get(y);
4116
+ if (!S) return;
4117
+ const E = v.flatMap((M) => {
4118
+ if ($(M)) return [];
4119
+ const B = M.indexOf(".");
4120
4120
  if (B < 0) return [];
4121
- const L = T.slice(0, B), F = T.slice(B + 1);
4121
+ const L = M.slice(0, B), F = M.slice(B + 1);
4122
4122
  if (l.has(L)) return [];
4123
4123
  if (mo(L, y)) return [];
4124
4124
  const q = g(L);
@@ -4128,39 +4128,39 @@ function b2(e) {
4128
4128
  elId: L,
4129
4129
  lib: q,
4130
4130
  localTerm: H,
4131
- isLinker: le.has(L),
4131
+ isLinker: se.has(L),
4132
4132
  busFacingRef: `${L}.${F}`
4133
4133
  }] : [];
4134
4134
  });
4135
- if (M.length === 0) return;
4136
- const E = [], _ = [];
4137
- for (const T of M)
4138
- T.localTerm.y > 0 ? E.push(T) : _.push(T);
4139
- const A = (T) => T.reduce(
4135
+ if (E.length === 0) return;
4136
+ const N = [], _ = [];
4137
+ for (const M of E)
4138
+ M.localTerm.y > 0 ? N.push(M) : _.push(M);
4139
+ const A = (M) => M.reduce(
4140
4140
  (B, L) => B + gt(L.elId, L.lib.width, L.busFacingRef),
4141
4141
  0
4142
- ), z = Math.max(A(E), A(_)) + Ye, P = Math.max(N.span, z);
4143
- P !== N.span && !f.has(y) && c.set(y, { ...N, span: P });
4144
- const O = c.get(y), C = (T, B) => {
4145
- if (T.length === 0) return;
4142
+ ), D = Math.max(A(N), A(_)) + Ye, P = Math.max(S.span, D);
4143
+ P !== S.span && !f.has(y) && c.set(y, { ...S, span: P });
4144
+ const O = c.get(y), C = (M, B) => {
4145
+ if (M.length === 0) return;
4146
4146
  const L = /* @__PURE__ */ new Map();
4147
- for (const Y of T) {
4147
+ for (const Y of M) {
4148
4148
  const U = Gx(y, Y.elId, Y.localTerm.id);
4149
4149
  U !== void 0 && L.set(Y.elId, U);
4150
4150
  }
4151
- T.sort((Y, U) => {
4151
+ M.sort((Y, U) => {
4152
4152
  const ce = L.get(Y.elId) ?? O.at[0], ke = L.get(U.elId) ?? O.at[0];
4153
4153
  if (ce !== ke) return ce - ke;
4154
4154
  const K = gt(Y.elId, Y.lib.width, Y.busFacingRef);
4155
4155
  return gt(U.elId, U.lib.width, U.busFacingRef) - K;
4156
4156
  });
4157
- const F = T.map(
4157
+ const F = M.map(
4158
4158
  (Y) => gt(Y.elId, Y.lib.width, Y.busFacingRef)
4159
- ), q = F.reduce((Y, U) => Y + U, 0), H = Math.max(P, q), J = (H - q) / (T.length + 1);
4159
+ ), q = F.reduce((Y, U) => Y + U, 0), H = Math.max(P, q), J = (H - q) / (M.length + 1);
4160
4160
  let Z = O.at[0] - H / 2 + J;
4161
4161
  const G = O.at[1] + B * Ro;
4162
- for (let Y = 0; Y < T.length; Y++) {
4163
- const U = T[Y], ce = F[Y], ke = Z + ce / 2;
4162
+ for (let Y = 0; Y < M.length; Y++) {
4163
+ const U = M[Y], ce = F[Y], ke = Z + ce / 2;
4164
4164
  U.isLinker ? qe.has(U.elId) || qe.set(U.elId, ke) : l.set(U.elId, {
4165
4165
  at: [pe(ke - U.localTerm.x), pe(G - U.localTerm.y)],
4166
4166
  rot: 0,
@@ -4168,21 +4168,21 @@ function b2(e) {
4168
4168
  }), Z += ce + J;
4169
4169
  }
4170
4170
  };
4171
- C(E, -1), C(_, 1);
4171
+ C(N, -1), C(_, 1);
4172
4172
  }, Yx = (y) => {
4173
4173
  if (l.has(y.elementId) || y.orientation === "horizontal") return;
4174
4174
  const v = g(y.elementId);
4175
4175
  if (!v) return;
4176
- const N = y.attachments.filter(
4176
+ const S = y.attachments.filter(
4177
4177
  (Z) => c.has(Z.busId)
4178
4178
  );
4179
- if (N.length < 2) return;
4180
- const M = N.slice().sort(
4179
+ if (S.length < 2) return;
4180
+ const E = S.slice().sort(
4181
4181
  (Z, G) => (re.get(Z.busId) ?? 0) - (re.get(G.busId) ?? 0)
4182
- ), E = M[0].busId, _ = c.get(E), A = M[0].pin, z = M[M.length - 1].pin, P = v.terminals.find((Z) => Z.id === A), O = v.terminals.find((Z) => Z.id === z);
4182
+ ), N = E[0].busId, _ = c.get(N), A = E[0].pin, D = E[E.length - 1].pin, P = v.terminals.find((Z) => Z.id === A), O = v.terminals.find((Z) => Z.id === D);
4183
4183
  if (!P || !O) return;
4184
- const C = P.y <= O.y ? 0 : 180, T = re.get(E) ?? 0, B = N.filter(
4185
- (Z) => (re.get(Z.busId) ?? 0) === T
4184
+ const C = P.y <= O.y ? 0 : 180, M = re.get(N) ?? 0, B = S.filter(
4185
+ (Z) => (re.get(Z.busId) ?? 0) === M
4186
4186
  ), L = [];
4187
4187
  let F = 0;
4188
4188
  for (const Z of B) {
@@ -4209,11 +4209,11 @@ function b2(e) {
4209
4209
  q
4210
4210
  );
4211
4211
  }
4212
- }, Kx = (y, v, N, M) => {
4213
- const E = /* @__PURE__ */ new Set([y]);
4214
- let _ = y, A = v, z = N;
4212
+ }, Kx = (y, v, S, E) => {
4213
+ const N = /* @__PURE__ */ new Set([y]);
4214
+ let _ = y, A = v, D = S;
4215
4215
  for (; ; ) {
4216
- const P = D.get(_) ?? [];
4216
+ const P = z.get(_) ?? [];
4217
4217
  let O, C = !1;
4218
4218
  for (const Q of P) {
4219
4219
  if (Q.length >= 3) {
@@ -4221,7 +4221,7 @@ function b2(e) {
4221
4221
  break;
4222
4222
  }
4223
4223
  const Ee = Q.find((Me) => Me !== _);
4224
- if (!(!Ee || E.has(Ee))) {
4224
+ if (!(!Ee || N.has(Ee))) {
4225
4225
  if ($(Ee)) {
4226
4226
  C = !0;
4227
4227
  break;
@@ -4231,70 +4231,70 @@ function b2(e) {
4231
4231
  }
4232
4232
  }
4233
4233
  if (C || !O) break;
4234
- const T = O.indexOf(".");
4235
- if (T < 0) break;
4236
- const B = O.slice(0, T), L = O.slice(T + 1);
4237
- if ($(B) || le.has(B) || l.has(B)) break;
4234
+ const M = O.indexOf(".");
4235
+ if (M < 0) break;
4236
+ const B = O.slice(0, M), L = O.slice(M + 1);
4237
+ if ($(B) || se.has(B) || l.has(B)) break;
4238
4238
  const F = g(B);
4239
4239
  if (!F) break;
4240
4240
  const q = F.terminals.find((Q) => Q.id === L);
4241
4241
  if (!q) break;
4242
- const H = Lo(z), J = [
4242
+ const H = Lo(D), J = [
4243
4243
  A[0] + H[0] * _t,
4244
4244
  A[1] + H[1] * _t
4245
- ], Z = Do[z], G = zt(q.orientation, Z), Y = De([q.x, q.y], {
4245
+ ], Z = Do[D], G = zt(q.orientation, Z), Y = De([q.x, q.y], {
4246
4246
  at: [0, 0],
4247
4247
  rot: G,
4248
4248
  mirror: !1
4249
4249
  }), U = [
4250
- pe(M - Y[0]),
4250
+ pe(E - Y[0]),
4251
4251
  pe(J[1] - Y[1])
4252
4252
  ];
4253
- l.set(B, { at: U, rot: G, mirror: !1 }), E.add(O);
4253
+ l.set(B, { at: U, rot: G, mirror: !1 }), N.add(O);
4254
4254
  const ce = F.terminals.find((Q) => Q.id !== L);
4255
4255
  if (!ce) break;
4256
4256
  const ke = `${B}.${ce.id}`;
4257
- E.add(ke);
4257
+ N.add(ke);
4258
4258
  const K = { at: U, rot: G, mirror: !1 };
4259
- A = De([ce.x, ce.y], K), z = Xt(ce.orientation, K), _ = ke;
4259
+ A = De([ce.x, ce.y], K), D = Xt(ce.orientation, K), _ = ke;
4260
4260
  }
4261
4261
  }, Vx = (y) => {
4262
4262
  if (l.has(y.elementId) || y.orientation !== "horizontal") return;
4263
4263
  const v = g(y.elementId);
4264
4264
  if (!v) return;
4265
- const N = y.attachments.filter((B) => c.has(B.busId));
4266
- if (N.length < 2) return;
4267
- const M = N.map((B) => {
4265
+ const S = y.attachments.filter((B) => c.has(B.busId));
4266
+ if (S.length < 2) return;
4267
+ const E = S.map((B) => {
4268
4268
  const L = Ne(y, B.busId, B.pin), F = L.head ? l.get(L.head) : void 0, q = F ? F.at[0] : c.get(B.busId).at[0];
4269
4269
  return { att: B, x: q, extent: L.extent };
4270
4270
  });
4271
- M.sort((B, L) => B.x - L.x);
4272
- const E = M[0], _ = M[M.length - 1], A = v.terminals.find((B) => B.id === E.att.pin), z = v.terminals.find((B) => B.id === _.att.pin);
4273
- if (!A || !z) return;
4274
- const P = A.y <= z.y ? 270 : 90, O = (E.x + _.x) / 2, T = c.get(E.att.busId).at[1] + Math.max(E.extent, _.extent);
4271
+ E.sort((B, L) => B.x - L.x);
4272
+ const N = E[0], _ = E[E.length - 1], A = v.terminals.find((B) => B.id === N.att.pin), D = v.terminals.find((B) => B.id === _.att.pin);
4273
+ if (!A || !D) return;
4274
+ const P = A.y <= D.y ? 270 : 90, O = (N.x + _.x) / 2, M = c.get(N.att.busId).at[1] + Math.max(N.extent, _.extent);
4275
4275
  l.set(y.elementId, {
4276
- at: [pe(O), pe(T)],
4276
+ at: [pe(O), pe(M)],
4277
4277
  rot: P,
4278
4278
  mirror: !1
4279
4279
  });
4280
4280
  }, ho = 100;
4281
4281
  let Ot = Dt;
4282
4282
  for (let y = 0; y < ve.length; y++) {
4283
- const v = ve[y], N = we.get(v);
4284
- let M;
4283
+ const v = ve[y], S = we.get(v);
4284
+ let E;
4285
4285
  if (y === 0)
4286
- M = Dt;
4286
+ E = Dt;
4287
4287
  else {
4288
4288
  const _ = we.get(ve[y - 1]);
4289
4289
  let A = 0;
4290
- for (const z of _)
4291
- for (const P of N)
4292
- (So = me.get(z)) != null && So.get(P) && (A = Math.max(A, Ae(z, P)));
4293
- A === 0 && (A = kt), M = Ot + A;
4294
- }
4295
- Ot = M;
4296
- let E = $n;
4297
- for (const _ of N) {
4290
+ for (const D of _)
4291
+ for (const P of S)
4292
+ (So = me.get(D)) != null && So.get(P) && (A = Math.max(A, Ae(D, P)));
4293
+ A === 0 && (A = kt), E = Ot + A;
4294
+ }
4295
+ Ot = E;
4296
+ let N = $n;
4297
+ for (const _ of S) {
4298
4298
  if (c.has(_)) {
4299
4299
  Ot = Math.max(Ot, c.get(_).at[1]);
4300
4300
  continue;
@@ -4303,91 +4303,91 @@ function b2(e) {
4303
4303
  if (y > 0) {
4304
4304
  const P = we.get(ve[y - 1]), O = [];
4305
4305
  for (const C of P) {
4306
- const T = (No = me.get(C)) == null ? void 0 : No.get(_);
4307
- if (!T || T.orientation !== "vertical") continue;
4308
- const B = (Eo = T.attachments.find(
4306
+ const M = (No = me.get(C)) == null ? void 0 : No.get(_);
4307
+ if (!M || M.orientation !== "vertical") continue;
4308
+ const B = (Eo = M.attachments.find(
4309
4309
  (F) => F.busId === C
4310
4310
  )) == null ? void 0 : Eo.pin;
4311
4311
  if (!B) continue;
4312
- const L = Ne(T, C, B);
4313
- L.head && l.has(L.head) ? O.push(l.get(L.head).at[0]) : qe.has(T.elementId) ? O.push(qe.get(T.elementId)) : O.push(c.get(C).at[0]);
4312
+ const L = Ne(M, C, B);
4313
+ L.head && l.has(L.head) ? O.push(l.get(L.head).at[0]) : qe.has(M.elementId) ? O.push(qe.get(M.elementId)) : O.push(c.get(C).at[0]);
4314
4314
  }
4315
- O.length > 0 && (A = O.reduce((C, T) => C + T, 0) / O.length);
4315
+ O.length > 0 && (A = O.reduce((C, M) => C + M, 0) / O.length);
4316
4316
  }
4317
4317
  if (A === void 0) {
4318
4318
  const P = ot.get(_) ?? Sn;
4319
- A = E + P / 2, E += P + ho;
4319
+ A = N + P / 2, N += P + ho;
4320
4320
  }
4321
- const z = ot.get(_) ?? Sn;
4321
+ const D = ot.get(_) ?? Sn;
4322
4322
  c.set(_, {
4323
- at: [pe(A), pe(M)],
4323
+ at: [pe(A), pe(E)],
4324
4324
  rot: 0,
4325
- span: z,
4325
+ span: D,
4326
4326
  axis: Fn(0)
4327
4327
  });
4328
4328
  }
4329
- for (const _ of N)
4329
+ for (const _ of S)
4330
4330
  Xx(_);
4331
4331
  if (y > 0)
4332
4332
  for (const _ of te)
4333
4333
  l.has(_.elementId) || !_.attachments.some(
4334
- (z) => N.includes(z.busId)
4334
+ (D) => S.includes(D.busId)
4335
4335
  ) || Yx(_);
4336
4336
  for (const _ of te)
4337
4337
  _.orientation !== "horizontal" || l.has(_.elementId) || !_.attachments.every(
4338
- (z) => N.includes(z.busId)
4338
+ (D) => S.includes(D.busId)
4339
4339
  ) || Vx(_);
4340
4340
  }
4341
4341
  if (n.length === 0 && l.size < t.length) {
4342
- const y = (E) => {
4343
- const _ = /* @__PURE__ */ new Set(), A = g(E);
4342
+ const y = (N) => {
4343
+ const _ = /* @__PURE__ */ new Set(), A = g(N);
4344
4344
  if (!A) return _;
4345
- for (const z of A.terminals) {
4346
- const P = `${E}.${z.id}`;
4347
- for (const O of D.get(P) ?? [])
4345
+ for (const D of A.terminals) {
4346
+ const P = `${N}.${D.id}`;
4347
+ for (const O of z.get(P) ?? [])
4348
4348
  for (const C of O) {
4349
4349
  if (C === P || $(C)) continue;
4350
- const T = C.indexOf(".");
4351
- if (T < 0) continue;
4352
- const B = C.slice(0, T);
4353
- B !== E && _.add(B);
4350
+ const M = C.indexOf(".");
4351
+ if (M < 0) continue;
4352
+ const B = C.slice(0, M);
4353
+ B !== N && _.add(B);
4354
4354
  }
4355
4355
  }
4356
4356
  return _;
4357
- }, v = /* @__PURE__ */ new Set(), N = [];
4358
- for (const E of t) {
4359
- if (v.has(E.id) || !g(E.id)) continue;
4360
- const _ = [], A = [E.id];
4361
- for (v.add(E.id); A.length > 0; ) {
4362
- const z = A.pop();
4363
- _.push(z);
4364
- for (const P of y(z))
4357
+ }, v = /* @__PURE__ */ new Set(), S = [];
4358
+ for (const N of t) {
4359
+ if (v.has(N.id) || !g(N.id)) continue;
4360
+ const _ = [], A = [N.id];
4361
+ for (v.add(N.id); A.length > 0; ) {
4362
+ const D = A.pop();
4363
+ _.push(D);
4364
+ for (const P of y(D))
4365
4365
  v.has(P) || (v.add(P), A.push(P));
4366
4366
  }
4367
- _.length >= 2 && N.push(_);
4367
+ _.length >= 2 && S.push(_);
4368
4368
  }
4369
- let M = $n;
4370
- for (const E of N) {
4371
- if (E.some((O) => l.has(O))) continue;
4372
- E.sort((O, C) => {
4369
+ let E = $n;
4370
+ for (const N of S) {
4371
+ if (N.some((O) => l.has(O))) continue;
4372
+ N.sort((O, C) => {
4373
4373
  var q, H;
4374
- const T = be(((q = p.get(O)) == null ? void 0 : q.kind) ?? "") ? 0 : 1, B = be(((H = p.get(C)) == null ? void 0 : H.kind) ?? "") ? 0 : 1;
4375
- if (T !== B) return T - B;
4374
+ const M = be(((q = p.get(O)) == null ? void 0 : q.kind) ?? "") ? 0 : 1, B = be(((H = p.get(C)) == null ? void 0 : H.kind) ?? "") ? 0 : 1;
4375
+ if (M !== B) return M - B;
4376
4376
  const L = y(O).size, F = y(C).size;
4377
4377
  return L !== F ? L - F : O.localeCompare(C);
4378
4378
  });
4379
- const _ = E[0], A = g(_);
4379
+ const _ = N[0], A = g(_);
4380
4380
  if (!A) continue;
4381
- const z = A.terminals.slice().sort((O, C) => C.y - O.y)[0], P = z ? De([z.x, z.y], {
4381
+ const D = A.terminals.slice().sort((O, C) => C.y - O.y)[0], P = D ? De([D.x, D.y], {
4382
4382
  at: [0, 0],
4383
4383
  rot: 0,
4384
4384
  mirror: !1
4385
4385
  }) : [0, 0];
4386
4386
  l.set(_, {
4387
- at: [pe(M - P[0]), pe(Dt - P[1])],
4387
+ at: [pe(E - P[0]), pe(Dt - P[1])],
4388
4388
  rot: 0,
4389
4389
  mirror: !1
4390
- }), M += Math.max(Sn, E.length * Ye) + ho;
4390
+ }), E += Math.max(Sn, N.length * Ye) + ho;
4391
4391
  }
4392
4392
  }
4393
4393
  const Ux = (y) => {
@@ -4400,7 +4400,7 @@ function b2(e) {
4400
4400
  bn = !1;
4401
4401
  for (const y of I) {
4402
4402
  if (y.length < 2) continue;
4403
- const v = [], N = /* @__PURE__ */ new Map();
4403
+ const v = [], S = /* @__PURE__ */ new Map();
4404
4404
  for (const G of y) {
4405
4405
  if ($(G))
4406
4406
  continue;
@@ -4411,51 +4411,51 @@ function b2(e) {
4411
4411
  v.push(G);
4412
4412
  continue;
4413
4413
  }
4414
- if (le.has(U) || N.has(U)) continue;
4414
+ if (se.has(U) || S.has(U)) continue;
4415
4415
  const ke = g(U);
4416
4416
  if (!ke) continue;
4417
4417
  const K = ke.terminals.find((Q) => Q.id === ce);
4418
- K && N.set(U, {
4418
+ K && S.set(U, {
4419
4419
  ref: G,
4420
4420
  elId: U,
4421
4421
  lib: ke,
4422
4422
  localTerm: K
4423
4423
  });
4424
4424
  }
4425
- if (N.size === 0 || v.length === 0) continue;
4426
- const M = [...N.values()], E = /* @__PURE__ */ new Map();
4427
- for (const G of M)
4428
- for (const Y of D.get(G.ref) ?? [])
4425
+ if (S.size === 0 || v.length === 0) continue;
4426
+ const E = [...S.values()], N = /* @__PURE__ */ new Map();
4427
+ for (const G of E)
4428
+ for (const Y of z.get(G.ref) ?? [])
4429
4429
  for (const U of Y) {
4430
4430
  if (U === G.ref || $(U) || !Ux(U)) continue;
4431
4431
  const ce = U;
4432
- E.set(ce, (E.get(ce) ?? 0) + 1);
4432
+ N.set(ce, (N.get(ce) ?? 0) + 1);
4433
4433
  }
4434
4434
  let _;
4435
- if (E.size > 0) {
4435
+ if (N.size > 0) {
4436
4436
  let G = -1;
4437
- for (const [Y, U] of E)
4437
+ for (const [Y, U] of N)
4438
4438
  (U > G || U === G && (_ === void 0 || Y < _)) && (G = U, _ = Y);
4439
4439
  }
4440
4440
  if (_ || (_ = [...v].sort()[0]), !_) continue;
4441
- const A = _.indexOf("."), z = _.slice(0, A), P = _.slice(A + 1), O = g(z), C = l.get(z);
4441
+ const A = _.indexOf("."), D = _.slice(0, A), P = _.slice(A + 1), O = g(D), C = l.get(D);
4442
4442
  if (!O || !C) continue;
4443
- const T = O.terminals.find((G) => G.id === P);
4444
- if (!T) continue;
4443
+ const M = O.terminals.find((G) => G.id === P);
4444
+ if (!M) continue;
4445
4445
  const B = De(
4446
- [T.x, T.y],
4446
+ [M.x, M.y],
4447
4447
  C
4448
4448
  ), L = Xt(
4449
- T.orientation,
4449
+ M.orientation,
4450
4450
  C
4451
4451
  ), F = Lo(L), q = [-F[1], F[0]];
4452
- M.sort((G, Y) => G.elId.localeCompare(Y.elId));
4453
- const H = M.map(
4452
+ E.sort((G, Y) => G.elId.localeCompare(Y.elId));
4453
+ const H = E.map(
4454
4454
  (G) => Math.max(G.lib.width, Ye)
4455
4455
  );
4456
4456
  let Z = -H.reduce((G, Y) => G + Y, 0) / 2;
4457
- for (let G = 0; G < M.length; G++) {
4458
- const Y = M[G], U = H[G], ce = Z + U / 2;
4457
+ for (let G = 0; G < E.length; G++) {
4458
+ const Y = E[G], U = H[G], ce = Z + U / 2;
4459
4459
  Z += U;
4460
4460
  const ke = Do[L], K = zt(
4461
4461
  Y.localTerm.orientation,
@@ -4475,98 +4475,98 @@ function b2(e) {
4475
4475
  }
4476
4476
  }
4477
4477
  const yt = (y) => {
4478
- const v = l.get(y), N = g(y);
4479
- if (!v || !N) return null;
4480
- const M = N.viewBox.split(/\s+/).map(Number);
4481
- if (M.length < 4 || M.some((T) => Number.isNaN(T))) {
4482
- const T = N.width / 2;
4483
- return { min: v.at[0] - T, max: v.at[0] + T };
4484
- }
4485
- const [E, _, A, z] = M, P = [
4486
- [E, _],
4487
- [E + A, _],
4488
- [E, _ + z],
4489
- [E + A, _ + z]
4478
+ const v = l.get(y), S = g(y);
4479
+ if (!v || !S) return null;
4480
+ const E = S.viewBox.split(/\s+/).map(Number);
4481
+ if (E.length < 4 || E.some((M) => Number.isNaN(M))) {
4482
+ const M = S.width / 2;
4483
+ return { min: v.at[0] - M, max: v.at[0] + M };
4484
+ }
4485
+ const [N, _, A, D] = E, P = [
4486
+ [N, _],
4487
+ [N + A, _],
4488
+ [N, _ + D],
4489
+ [N + A, _ + D]
4490
4490
  ];
4491
4491
  let O = 1 / 0, C = -1 / 0;
4492
- for (const T of P) {
4493
- const B = De(T, v);
4492
+ for (const M of P) {
4493
+ const B = De(M, v);
4494
4494
  O = Math.min(O, B[0]), C = Math.max(C, B[0]);
4495
4495
  }
4496
4496
  return { min: O, max: C };
4497
4497
  }, wn = (y) => {
4498
- const v = /* @__PURE__ */ new Set(), N = g(y);
4499
- if (!N) return v;
4500
- for (const M of N.terminals) {
4501
- const E = `${y}.${M.id}`;
4502
- for (const _ of D.get(E) ?? [])
4498
+ const v = /* @__PURE__ */ new Set(), S = g(y);
4499
+ if (!S) return v;
4500
+ for (const E of S.terminals) {
4501
+ const N = `${y}.${E.id}`;
4502
+ for (const _ of z.get(N) ?? [])
4503
4503
  for (const A of _) {
4504
- if (A === E || $(A)) continue;
4505
- const z = A.indexOf(".");
4506
- if (z < 0) continue;
4507
- const P = A.slice(0, z);
4504
+ if (A === N || $(A)) continue;
4505
+ const D = A.indexOf(".");
4506
+ if (D < 0) continue;
4507
+ const P = A.slice(0, D);
4508
4508
  P !== y && v.add(P);
4509
4509
  }
4510
4510
  }
4511
4511
  return v;
4512
4512
  }, po = 40, xn = (y) => {
4513
- const v = l.get(y), N = g(y);
4514
- if (!v || !N) return null;
4515
- const M = N.viewBox.split(/\s+/).map(Number);
4516
- if (M.length < 4 || M.some((T) => Number.isNaN(T))) {
4517
- const T = N.height / 2;
4518
- return { min: v.at[1] - T, max: v.at[1] + T };
4519
- }
4520
- const [E, _, A, z] = M, P = [
4521
- [E, _],
4522
- [E + A, _],
4523
- [E, _ + z],
4524
- [E + A, _ + z]
4513
+ const v = l.get(y), S = g(y);
4514
+ if (!v || !S) return null;
4515
+ const E = S.viewBox.split(/\s+/).map(Number);
4516
+ if (E.length < 4 || E.some((M) => Number.isNaN(M))) {
4517
+ const M = S.height / 2;
4518
+ return { min: v.at[1] - M, max: v.at[1] + M };
4519
+ }
4520
+ const [N, _, A, D] = E, P = [
4521
+ [N, _],
4522
+ [N + A, _],
4523
+ [N, _ + D],
4524
+ [N + A, _ + D]
4525
4525
  ];
4526
4526
  let O = 1 / 0, C = -1 / 0;
4527
- for (const T of P) {
4528
- const B = De(T, v);
4527
+ for (const M of P) {
4528
+ const B = De(M, v);
4529
4529
  O = Math.min(O, B[1]), C = Math.max(C, B[1]);
4530
4530
  }
4531
4531
  return { min: O, max: C };
4532
4532
  }, Zx = (y, v) => {
4533
- const N = /* @__PURE__ */ new Set(), M = [];
4534
- for (const E of X.get(y) ?? []) {
4535
- if ($(E)) continue;
4536
- const _ = E.indexOf(".");
4533
+ const S = /* @__PURE__ */ new Set(), E = [];
4534
+ for (const N of X.get(y) ?? []) {
4535
+ if ($(N)) continue;
4536
+ const _ = N.indexOf(".");
4537
4537
  if (_ < 0) continue;
4538
- const A = E.slice(0, _), z = l.get(A);
4539
- !z || z.at[1] >= v - 1 || N.has(A) || (N.add(A), M.push(A));
4538
+ const A = N.slice(0, _), D = l.get(A);
4539
+ !D || D.at[1] >= v - 1 || S.has(A) || (S.add(A), E.push(A));
4540
4540
  }
4541
- for (; M.length > 0; ) {
4542
- const E = M.pop();
4543
- for (const _ of wn(E)) {
4544
- if (N.has(_)) continue;
4541
+ for (; E.length > 0; ) {
4542
+ const N = E.pop();
4543
+ for (const _ of wn(N)) {
4544
+ if (S.has(_)) continue;
4545
4545
  const A = l.get(_);
4546
- !A || A.at[1] >= v - 1 || (N.add(_), M.push(_));
4546
+ !A || A.at[1] >= v - 1 || (S.add(_), E.push(_));
4547
4547
  }
4548
4548
  }
4549
- return N;
4550
- }, go = (y, v, N) => {
4551
- const M = /* @__PURE__ */ new Set([y]), E = [y];
4552
- for (; E.length > 0; ) {
4553
- const _ = E.pop();
4549
+ return S;
4550
+ }, go = (y, v, S) => {
4551
+ const E = /* @__PURE__ */ new Set([y]), N = [y];
4552
+ for (; N.length > 0; ) {
4553
+ const _ = N.pop();
4554
4554
  for (const A of wn(_))
4555
- A === v || M.has(A) || !N.has(A) || (M.add(A), E.push(A));
4555
+ A === v || E.has(A) || !S.has(A) || (E.add(A), N.push(A));
4556
4556
  }
4557
- return M;
4557
+ return E;
4558
4558
  }, yo = (y, v) => {
4559
- let N = y.length * y.length + 8, M = !1, E = !0;
4560
- for (; E && N-- > 0; ) {
4561
- E = !1;
4562
- for (let _ = 0; _ < y.length && !E; _++)
4559
+ let S = y.length * y.length + 8, E = !1, N = !0;
4560
+ for (; N && S-- > 0; ) {
4561
+ N = !1;
4562
+ for (let _ = 0; _ < y.length && !N; _++)
4563
4563
  for (let A = _ + 1; A < y.length; A++) {
4564
- const z = y[_], P = y[A], O = yt(z), C = yt(P), T = xn(z), B = xn(P);
4565
- if (!O || !C || !T || !B) continue;
4566
- const L = Math.min(O.max, C.max) - Math.max(O.min, C.min), F = Math.min(T.max, B.max) - Math.max(T.min, B.min);
4564
+ const D = y[_], P = y[A], O = yt(D), C = yt(P), M = xn(D), B = xn(P);
4565
+ if (!O || !C || !M || !B) continue;
4566
+ const L = Math.min(O.max, C.max) - Math.max(O.min, C.min), F = Math.min(M.max, B.max) - Math.max(M.min, B.min);
4567
4567
  if (L <= 0 || F <= 0) continue;
4568
- const q = go(z, P, v), H = go(P, z, v);
4569
- if (q.has(P) || H.has(z)) continue;
4568
+ const q = go(D, P, v), H = go(P, D, v);
4569
+ if (q.has(P) || H.has(D)) continue;
4570
4570
  const J = ![...q].some((K) => u.has(K)), Z = ![...H].some((K) => u.has(K));
4571
4571
  if (!J && !Z) continue;
4572
4572
  const G = (O.min + O.max) / 2, Y = (C.min + C.max) / 2;
@@ -4581,33 +4581,33 @@ function b2(e) {
4581
4581
  at: [Q.at[0] + ke, Q.at[1]]
4582
4582
  });
4583
4583
  }
4584
- M = !0, E = !0;
4584
+ E = !0, N = !0;
4585
4585
  break;
4586
4586
  }
4587
4587
  }
4588
4588
  }
4589
- return M;
4589
+ return E;
4590
4590
  };
4591
4591
  for (const y of n) {
4592
4592
  const v = c.get(y.id);
4593
4593
  if (!v) continue;
4594
- const N = Zx(y.id, v.at[1]);
4595
- if (N.size < 2) continue;
4596
- const M = [...N];
4597
- if (yo(M, N)) {
4594
+ const S = Zx(y.id, v.at[1]);
4595
+ if (S.size < 2) continue;
4596
+ const E = [...S];
4597
+ if (yo(E, S)) {
4598
4598
  let _ = 1 / 0, A = -1 / 0;
4599
- for (const z of M) {
4600
- const P = yt(z);
4599
+ for (const D of E) {
4600
+ const P = yt(D);
4601
4601
  P && (_ = Math.min(_, P.min), A = Math.max(A, P.max));
4602
4602
  }
4603
4603
  if (Number.isFinite(_)) {
4604
- const P = M.some((C) => u.has(C)) ? 0 : pe(v.at[0] - (_ + A) / 2);
4604
+ const P = E.some((C) => u.has(C)) ? 0 : pe(v.at[0] - (_ + A) / 2);
4605
4605
  if (P !== 0)
4606
- for (const C of M) {
4607
- const T = l.get(C);
4608
- T && l.set(C, {
4609
- ...T,
4610
- at: [T.at[0] + P, T.at[1]]
4606
+ for (const C of E) {
4607
+ const M = l.get(C);
4608
+ M && l.set(C, {
4609
+ ...M,
4610
+ at: [M.at[0] + P, M.at[1]]
4611
4611
  });
4612
4612
  }
4613
4613
  const O = A - _ + po;
@@ -4619,14 +4619,14 @@ function b2(e) {
4619
4619
  }
4620
4620
  }
4621
4621
  const bo = () => {
4622
- const v = t.map((M) => M.id).filter((M) => l.has(M)).map((M) => ({ x: yt(M), y: xn(M) })).filter((M) => M.x && M.y);
4623
- let N = 0;
4624
- for (let M = 0; M < v.length; M++)
4625
- for (let E = M + 1; E < v.length; E++) {
4626
- const _ = Math.min(v[M].x.max, v[E].x.max) - Math.max(v[M].x.min, v[E].x.min), A = Math.min(v[M].y.max, v[E].y.max) - Math.max(v[M].y.min, v[E].y.min);
4627
- _ > 1 && A > 1 && N++;
4622
+ const v = t.map((E) => E.id).filter((E) => l.has(E)).map((E) => ({ x: yt(E), y: xn(E) })).filter((E) => E.x && E.y);
4623
+ let S = 0;
4624
+ for (let E = 0; E < v.length; E++)
4625
+ for (let N = E + 1; N < v.length; N++) {
4626
+ const _ = Math.min(v[E].x.max, v[N].x.max) - Math.max(v[E].x.min, v[N].x.min), A = Math.min(v[E].y.max, v[N].y.max) - Math.max(v[E].y.min, v[N].y.min);
4627
+ _ > 1 && A > 1 && S++;
4628
4628
  }
4629
- return N;
4629
+ return S;
4630
4630
  }, Qx = bo(), wo = /* @__PURE__ */ new Map();
4631
4631
  for (const [y, v] of l) wo.set(y, { ...v, at: [...v.at] });
4632
4632
  const xo = /* @__PURE__ */ new Map();
@@ -4634,62 +4634,62 @@ function b2(e) {
4634
4634
  xo.set(y, { ...v, at: [...v.at] });
4635
4635
  const vn = 120, vo = /* @__PURE__ */ new Map();
4636
4636
  {
4637
- const y = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), N = [];
4638
- for (const E of n)
4639
- for (const _ of X.get(E.id) ?? []) {
4637
+ const y = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), S = [];
4638
+ for (const N of n)
4639
+ for (const _ of X.get(N.id) ?? []) {
4640
4640
  if ($(_)) continue;
4641
4641
  const A = _.indexOf(".");
4642
4642
  if (A < 0) continue;
4643
- const z = _.slice(0, A);
4644
- l.has(z) && N.push({ el: z, bus: E.id, d: 1 });
4643
+ const D = _.slice(0, A);
4644
+ l.has(D) && S.push({ el: D, bus: N.id, d: 1 });
4645
4645
  }
4646
- N.sort((E, _) => E.d - _.d);
4647
- let M = 0;
4648
- for (; M < N.length; ) {
4649
- const { el: E, bus: _, d: A } = N[M++], z = y.get(E);
4650
- if (z === void 0)
4651
- y.set(E, A), v.set(E, _);
4652
- else if (A === z && v.get(E) !== _) {
4653
- v.set(E, null);
4646
+ S.sort((N, _) => N.d - _.d);
4647
+ let E = 0;
4648
+ for (; E < S.length; ) {
4649
+ const { el: N, bus: _, d: A } = S[E++], D = y.get(N);
4650
+ if (D === void 0)
4651
+ y.set(N, A), v.set(N, _);
4652
+ else if (A === D && v.get(N) !== _) {
4653
+ v.set(N, null);
4654
4654
  continue;
4655
4655
  } else
4656
4656
  continue;
4657
- for (const P of wn(E))
4658
- l.has(P) && (y.has(P) || N.push({ el: P, bus: _, d: A + 1 }));
4657
+ for (const P of wn(N))
4658
+ l.has(P) && (y.has(P) || S.push({ el: P, bus: _, d: A + 1 }));
4659
4659
  }
4660
- for (const [E, _] of v) _ && vo.set(E, _);
4660
+ for (const [N, _] of v) _ && vo.set(N, _);
4661
4661
  }
4662
4662
  for (const y of ve) {
4663
4663
  const v = (we.get(y) ?? []).filter(
4664
4664
  (O) => c.has(O)
4665
4665
  );
4666
4666
  if (v.length < 2 || v.some((O) => f.has(O))) continue;
4667
- const N = [];
4668
- let M = 0;
4667
+ const S = [];
4668
+ let E = 0;
4669
4669
  for (const O of v) {
4670
- const C = c.get(O), T = [];
4670
+ const C = c.get(O), M = [];
4671
4671
  let B = 1 / 0, L = -1 / 0;
4672
4672
  for (const [F, q] of vo) {
4673
4673
  if (q !== O) continue;
4674
4674
  const H = yt(F);
4675
- H && (T.push(F), B = Math.min(B, H.min), L = Math.max(L, H.max));
4675
+ H && (M.push(F), B = Math.min(B, H.min), L = Math.max(L, H.max));
4676
4676
  }
4677
- Number.isFinite(B) || (B = C.at[0] - pt / 2, L = C.at[0] + pt / 2), N.push({ busId: O, min: B, max: L, members: T }), M += L - B;
4677
+ Number.isFinite(B) || (B = C.at[0] - pt / 2, L = C.at[0] + pt / 2), S.push({ busId: O, min: B, max: L, members: M }), E += L - B;
4678
4678
  }
4679
- if (N.some((O) => O.members.some((C) => u.has(C))))
4679
+ if (S.some((O) => O.members.some((C) => u.has(C))))
4680
4680
  continue;
4681
- let E = 1 / 0, _ = -1 / 0;
4682
- for (const O of N)
4683
- E = Math.min(E, O.min), _ = Math.max(_, O.max);
4684
- const A = _ - E, z = M + vn * (N.length - 1);
4685
- if (!(A > z + vn)) continue;
4686
- N.sort((O, C) => (O.min + O.max) / 2 - (C.min + C.max) / 2);
4687
- let P = E;
4688
- for (const O of N) {
4681
+ let N = 1 / 0, _ = -1 / 0;
4682
+ for (const O of S)
4683
+ N = Math.min(N, O.min), _ = Math.max(_, O.max);
4684
+ const A = _ - N, D = E + vn * (S.length - 1);
4685
+ if (!(A > D + vn)) continue;
4686
+ S.sort((O, C) => (O.min + O.max) / 2 - (C.min + C.max) / 2);
4687
+ let P = N;
4688
+ for (const O of S) {
4689
4689
  const C = pe(P - O.min);
4690
4690
  if (C !== 0) {
4691
- const T = c.get(O.busId);
4692
- c.set(O.busId, { ...T, at: [T.at[0] + C, T.at[1]] });
4691
+ const M = c.get(O.busId);
4692
+ c.set(O.busId, { ...M, at: [M.at[0] + C, M.at[1]] });
4693
4693
  for (const B of O.members) {
4694
4694
  const L = l.get(B);
4695
4695
  L && l.set(B, { ...L, at: [L.at[0] + C, L.at[1]] });
@@ -4698,13 +4698,13 @@ function b2(e) {
4698
4698
  }
4699
4699
  P = O.max + vn;
4700
4700
  }
4701
- for (const O of N) {
4702
- const C = c.get(O.busId), T = Math.max(pt, O.max - O.min);
4703
- T < C.span && c.set(O.busId, { ...C, span: T });
4701
+ for (const O of S) {
4702
+ const C = c.get(O.busId), M = Math.max(pt, O.max - O.min);
4703
+ M < C.span && c.set(O.busId, { ...C, span: M });
4704
4704
  }
4705
4705
  }
4706
4706
  {
4707
- const y = t.map((N) => N.id).filter((N) => l.has(N)), v = new Set(y);
4707
+ const y = t.map((S) => S.id).filter((S) => l.has(S)), v = new Set(y);
4708
4708
  yo(y, v);
4709
4709
  }
4710
4710
  if (bo() > Qx) {
@@ -4716,11 +4716,11 @@ function b2(e) {
4716
4716
  let kn = 0;
4717
4717
  for (const y of t) {
4718
4718
  if (l.has(y.id)) continue;
4719
- const v = kn % Ho, N = Math.floor(kn / Ho);
4719
+ const v = kn % Ho, S = Math.floor(kn / Ho);
4720
4720
  l.set(y.id, {
4721
4721
  at: [
4722
4722
  pe(h2 + v * g2),
4723
- pe(p2 + N * y2)
4723
+ pe(p2 + S * y2)
4724
4724
  ],
4725
4725
  rot: 0,
4726
4726
  mirror: !1
@@ -7085,13 +7085,13 @@ const z$ = 320;
7085
7085
  function Ze(e) {
7086
7086
  var h, g, w, $, k;
7087
7087
  const t = d2(), n = /* @__PURE__ */ new Map();
7088
- e.elements.forEach((x, S) => {
7088
+ e.elements.forEach((x, T) => {
7089
7089
  if (n.has(x.id)) {
7090
7090
  t.diagnostics.push({
7091
7091
  code: "E001",
7092
7092
  severity: "error",
7093
7093
  message: _e("compile.duplicateId", { id: x.id }),
7094
- pointer: `/elements/${S}`
7094
+ pointer: `/elements/${T}`
7095
7095
  });
7096
7096
  return;
7097
7097
  }
@@ -7101,17 +7101,17 @@ function Ze(e) {
7101
7101
  code: "E003",
7102
7102
  severity: "error",
7103
7103
  message: `${_e("compile.unknownKind", { kind: x.kind })} (id=${x.id})`,
7104
- pointer: `/elements/${S}`
7104
+ pointer: `/elements/${T}`
7105
7105
  }), t.elements.set(x.id, { element: x, libraryDef: I });
7106
7106
  });
7107
7107
  const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
7108
- (e.buses ?? []).forEach((x, S) => {
7108
+ (e.buses ?? []).forEach((x, T) => {
7109
7109
  if (n.has(x.id) || o.has(x.id)) {
7110
7110
  t.diagnostics.push({
7111
7111
  code: "E001",
7112
7112
  severity: "error",
7113
7113
  message: _e("compile.duplicateId", { id: x.id }),
7114
- pointer: `/buses/${S}`
7114
+ pointer: `/buses/${T}`
7115
7115
  });
7116
7116
  return;
7117
7117
  }
@@ -7126,19 +7126,19 @@ function Ze(e) {
7126
7126
  }
7127
7127
  });
7128
7128
  const i = /* @__PURE__ */ new Map();
7129
- (e.junctions ?? []).forEach((x, S) => {
7129
+ (e.junctions ?? []).forEach((x, T) => {
7130
7130
  if (n.has(x.id) || o.has(x.id) || i.has(x.id)) {
7131
7131
  t.diagnostics.push({
7132
7132
  code: "E001",
7133
7133
  severity: "error",
7134
7134
  message: _e("compile.duplicateId", { id: x.id }),
7135
- pointer: `/junctions/${S}`
7135
+ pointer: `/junctions/${T}`
7136
7136
  });
7137
7137
  return;
7138
7138
  }
7139
7139
  i.set(x.id, x);
7140
7140
  });
7141
- const s = (x) => !x.includes(".") && o.has(x), a = (x) => !x.includes(".") && i.has(x), l = (x, S) => {
7141
+ const s = (x) => !x.includes(".") && o.has(x), a = (x) => !x.includes(".") && i.has(x), l = (x, T) => {
7142
7142
  if (s(x) || a(x)) return !0;
7143
7143
  const I = x.indexOf(".");
7144
7144
  if (I <= 0)
@@ -7146,41 +7146,41 @@ function Ze(e) {
7146
7146
  code: "E003",
7147
7147
  severity: "error",
7148
7148
  message: _e("compile.invalidTermRef", { ref: x }),
7149
- pointer: S
7149
+ pointer: T
7150
7150
  }), !1;
7151
- const D = x.slice(0, I), X = x.slice(I + 1), V = t.elements.get(D);
7151
+ const z = x.slice(0, I), X = x.slice(I + 1), V = t.elements.get(z);
7152
7152
  if (!V)
7153
7153
  return t.diagnostics.push({
7154
7154
  code: "E002",
7155
7155
  severity: "error",
7156
- message: _e("compile.elementMissing", { id: D }),
7157
- pointer: S
7156
+ message: _e("compile.elementMissing", { id: z }),
7157
+ pointer: T
7158
7158
  }), !1;
7159
7159
  if (!V.libraryDef) return !1;
7160
7160
  if (!V.libraryDef.terminals.find((te) => te.id === X)) {
7161
- const te = V.libraryDef.terminals.map((le) => le.id).join(", ");
7161
+ const te = V.libraryDef.terminals.map((se) => se.id).join(", ");
7162
7162
  return t.diagnostics.push({
7163
7163
  code: "E003",
7164
7164
  severity: "error",
7165
7165
  message: _e("compile.missingPin", {
7166
- id: D,
7166
+ id: z,
7167
7167
  kind: V.element.kind,
7168
7168
  pin: X,
7169
7169
  available: te
7170
7170
  }),
7171
- pointer: S
7171
+ pointer: T
7172
7172
  }), !1;
7173
7173
  }
7174
7174
  return !0;
7175
7175
  }, c = [];
7176
- (e.wires ?? []).forEach((x, S) => {
7177
- const I = `/wires/${S}`, D = l(x.ends[0], I), X = l(x.ends[1], I);
7178
- D && X && c.push(x);
7176
+ (e.wires ?? []).forEach((x, T) => {
7177
+ const I = `/wires/${T}`, z = l(x.ends[0], I), X = l(x.ends[1], I);
7178
+ z && X && c.push(x);
7179
7179
  });
7180
7180
  const d = /* @__PURE__ */ new Map();
7181
7181
  if (e.layout)
7182
- for (const [x, S] of Object.entries(e.layout))
7183
- t.elements.has(x) ? d.set(x, u2(S)) : t.diagnostics.push({
7182
+ for (const [x, T] of Object.entries(e.layout))
7183
+ t.elements.has(x) ? d.set(x, u2(T)) : t.diagnostics.push({
7184
7184
  code: "E004",
7185
7185
  severity: "error",
7186
7186
  message: _e("compile.layoutMissingElement", { id: x }),
@@ -7196,31 +7196,31 @@ function Ze(e) {
7196
7196
  userBusLayout: r
7197
7197
  });
7198
7198
  t.layout = u.devices;
7199
- for (const [x, S] of u.buses) {
7199
+ for (const [x, T] of u.buses) {
7200
7200
  const I = o.get(x);
7201
- I && t.buses.set(x, { bus: I, geometry: S });
7201
+ I && t.buses.set(x, { bus: I, geometry: T });
7202
7202
  }
7203
- for (const [x, S] of o)
7203
+ for (const [x, T] of o)
7204
7204
  t.buses.has(x) || t.buses.set(x, {
7205
- bus: S,
7205
+ bus: T,
7206
7206
  geometry: {
7207
- at: ((h = S.layout) == null ? void 0 : h.at) ?? [0, 0],
7208
- span: ((g = S.layout) == null ? void 0 : g.span) ?? z$,
7209
- rot: ((w = S.layout) == null ? void 0 : w.rot) ?? 0,
7210
- axis: Fn((($ = S.layout) == null ? void 0 : $.rot) ?? 0)
7207
+ at: ((h = T.layout) == null ? void 0 : h.at) ?? [0, 0],
7208
+ span: ((g = T.layout) == null ? void 0 : g.span) ?? z$,
7209
+ rot: ((w = T.layout) == null ? void 0 : w.rot) ?? 0,
7210
+ axis: Fn((($ = T.layout) == null ? void 0 : $.rot) ?? 0)
7211
7211
  }
7212
7212
  });
7213
7213
  for (const x of t.elements.values()) {
7214
7214
  if (!x.libraryDef) continue;
7215
- const S = t.layout.get(x.element.id);
7216
- if (!S) continue;
7215
+ const T = t.layout.get(x.element.id);
7216
+ if (!T) continue;
7217
7217
  const I = [];
7218
- for (const D of x.libraryDef.terminals) {
7219
- const X = `${x.element.id}.${D.id}`, V = De([D.x, D.y], S), te = Xt(D.orientation, S);
7218
+ for (const z of x.libraryDef.terminals) {
7219
+ const X = `${x.element.id}.${z.id}`, V = De([z.x, z.y], T), te = Xt(z.orientation, T);
7220
7220
  t.terminals.set(X, {
7221
7221
  ref: X,
7222
7222
  elementId: x.element.id,
7223
- pin: D.id,
7223
+ pin: z.id,
7224
7224
  world: V,
7225
7225
  orientation: te
7226
7226
  }), I.push(X);
@@ -7232,42 +7232,42 @@ function Ze(e) {
7232
7232
  const I = t.buses.get(x);
7233
7233
  return I ? I.geometry.at : null;
7234
7234
  }
7235
- const S = t.terminals.get(x);
7236
- return S ? S.world : null;
7235
+ const T = t.terminals.get(x);
7236
+ return T ? T.world : null;
7237
7237
  };
7238
- for (const [x, S] of i) {
7238
+ for (const [x, T] of i) {
7239
7239
  let I;
7240
- if ((k = S.layout) != null && k.at)
7241
- I = [S.layout.at[0], S.layout.at[1]];
7240
+ if ((k = T.layout) != null && k.at)
7241
+ I = [T.layout.at[0], T.layout.at[1]];
7242
7242
  else if (u.junctions.has(x))
7243
7243
  I = u.junctions.get(x);
7244
7244
  else {
7245
- const D = [];
7245
+ const z = [];
7246
7246
  for (const X of c) {
7247
- const [V, te] = X.ends, le = V === x ? te : te === x ? V : null;
7248
- if (le === null) continue;
7249
- const R = f(le);
7250
- R && D.push(R);
7247
+ const [V, te] = X.ends, se = V === x ? te : te === x ? V : null;
7248
+ if (se === null) continue;
7249
+ const R = f(se);
7250
+ R && z.push(R);
7251
7251
  }
7252
- I = D.length ? [
7253
- D.reduce((X, V) => X + V[0], 0) / D.length,
7254
- D.reduce((X, V) => X + V[1], 0) / D.length
7252
+ I = z.length ? [
7253
+ z.reduce((X, V) => X + V[0], 0) / z.length,
7254
+ z.reduce((X, V) => X + V[1], 0) / z.length
7255
7255
  ] : [0, 0];
7256
7256
  }
7257
- t.junctions.set(x, { junction: S, world: I });
7257
+ t.junctions.set(x, { junction: T, world: I });
7258
7258
  }
7259
7259
  const p = new hi();
7260
7260
  for (const x of c)
7261
7261
  p.add(x.ends[0]), p.add(x.ends[1]), p.union(x.ends[0], x.ends[1]);
7262
7262
  for (const [, x] of p.groups()) {
7263
- const S = L$(x);
7264
- t.nodes.set(S, { id: S, terminals: x });
7265
- for (const I of x) t.terminalToNode.set(I, S);
7263
+ const T = L$(x);
7264
+ t.nodes.set(T, { id: T, terminals: x });
7265
+ for (const I of x) t.terminalToNode.set(I, T);
7266
7266
  }
7267
7267
  for (const x of t.elements.values()) {
7268
- const S = t.elementToTerminals.get(x.element.id) ?? [];
7269
- if (S.length === 0) continue;
7270
- S.some((D) => t.terminalToNode.has(D)) || t.diagnostics.push({
7268
+ const T = t.elementToTerminals.get(x.element.id) ?? [];
7269
+ if (T.length === 0) continue;
7270
+ T.some((z) => t.terminalToNode.has(z)) || t.diagnostics.push({
7271
7271
  code: "W001",
7272
7272
  severity: "warning",
7273
7273
  message: _e("compile.elementUnconnected", { id: x.element.id })
@@ -7287,21 +7287,21 @@ function Ze(e) {
7287
7287
  });
7288
7288
  for (const x of c) {
7289
7289
  if (x.path && x.path.length >= 2) {
7290
- const I = x.path, D = I.length >= 2 ? I[1] : null, X = I.length >= 2 ? I[I.length - 2] : null, V = Go(x.ends[0], D, t), te = Go(x.ends[1], X, t);
7290
+ const I = x.path, z = I.length >= 2 ? I[1] : null, X = I.length >= 2 ? I[I.length - 2] : null, V = Go(x.ends[0], z, t), te = Go(x.ends[1], X, t);
7291
7291
  if (V && te) {
7292
- const le = [
7292
+ const se = [
7293
7293
  [V[0], V[1]],
7294
7294
  ...I.slice(1, -1).map((W) => [W[0], W[1]]),
7295
7295
  [te[0], te[1]]
7296
- ], R = fi(le);
7296
+ ], R = fi(se);
7297
7297
  if (R.length >= 2) {
7298
7298
  t.wireRenders.set(x.id, { wireId: x.id, path: R, userEdited: !0 });
7299
7299
  continue;
7300
7300
  }
7301
7301
  }
7302
7302
  }
7303
- const S = w2(x, t);
7304
- S && t.wireRenders.set(x.id, S);
7303
+ const T = w2(x, t);
7304
+ T && t.wireRenders.set(x.id, T);
7305
7305
  }
7306
7306
  return t;
7307
7307
  }
@@ -7632,10 +7632,10 @@ const b = an()(
7632
7632
  }), p = n.buses.map((k) => {
7633
7633
  const x = structuredClone(k);
7634
7634
  x.id = l.get(k.id);
7635
- const S = n.busLayouts[k.id];
7636
- return S && (x.layout = {
7637
- ...S,
7638
- at: [S.at[0] + s, S.at[1] + a]
7635
+ const T = n.busLayouts[k.id];
7636
+ return T && (x.layout = {
7637
+ ...T,
7638
+ at: [T.at[0] + s, T.at[1] + a]
7639
7639
  }), x;
7640
7640
  }), h = n.junctions.map((k) => {
7641
7641
  const x = structuredClone(k);
@@ -7644,10 +7644,10 @@ const b = an()(
7644
7644
  }), x;
7645
7645
  }), g = { ...u.layout ?? {} };
7646
7646
  for (const [k, x] of l) {
7647
- const S = n.placements[k];
7648
- S && (g[x] = {
7649
- ...S,
7650
- at: [S.at[0] + s, S.at[1] + a]
7647
+ const T = n.placements[k];
7648
+ T && (g[x] = {
7649
+ ...T,
7650
+ at: [T.at[0] + s, T.at[1] + a]
7651
7651
  });
7652
7652
  }
7653
7653
  const w = n.wires.map((k) => {
@@ -7995,9 +7995,9 @@ const b = an()(
7995
7995
  if ("junctionAt" in h) return l(h.junctionAt);
7996
7996
  const g = (i.wires ?? []).find((x) => x.id === h.onWire), w = l(h.at);
7997
7997
  if (!g) return w;
7998
- const $ = (i.wires ?? []).filter((x) => x.id !== h.onWire), k = (x, S) => ({
7999
- id: lt(x, S),
8000
- ends: [x, S]
7998
+ const $ = (i.wires ?? []).filter((x) => x.id !== h.onWire), k = (x, T) => ({
7999
+ id: lt(x, T),
8000
+ ends: [x, T]
8001
8001
  });
8002
8002
  return i = {
8003
8003
  ...i,
@@ -8251,14 +8251,14 @@ function V$(e, t, n) {
8251
8251
  ue(f[1] - u.y)
8252
8252
  ], h = Jt(i, e);
8253
8253
  return r.dispatch((g) => {
8254
- const w = { id: h, kind: e }, $ = { at: p }, k = `${h}.${u.id}`, x = s.isBus && s.busId ? s.busId : t, S = {
8254
+ const w = { id: h, kind: e }, $ = { at: p }, k = `${h}.${u.id}`, x = s.isBus && s.busId ? s.busId : t, T = {
8255
8255
  id: lt(x, k),
8256
8256
  ends: [x, k]
8257
8257
  };
8258
8258
  return {
8259
8259
  ...g,
8260
8260
  elements: [...g.elements, w],
8261
- wires: [...g.wires ?? [], S],
8261
+ wires: [...g.wires ?? [], T],
8262
8262
  layout: { ...g.layout ?? {}, [h]: $ }
8263
8263
  };
8264
8264
  }), r.setSelection([h]), { newElementId: h, attachedToBus: s.isBus };
@@ -8353,7 +8353,7 @@ function Z$({
8353
8353
  anchor: o
8354
8354
  }) {
8355
8355
  const r = he(null);
8356
- se(() => {
8356
+ ae(() => {
8357
8357
  const l = r.current;
8358
8358
  if (!l) return;
8359
8359
  l.focus();
@@ -8486,7 +8486,7 @@ function eS({
8486
8486
  }
8487
8487
  function tS({ ann: e }) {
8488
8488
  const t = he(null), n = e.fontSize ?? ux;
8489
- se(() => {
8489
+ ae(() => {
8490
8490
  const a = t.current;
8491
8491
  if (!a) return;
8492
8492
  a.focus();
@@ -8694,17 +8694,17 @@ function iS({
8694
8694
  if (!g || h.pointerId !== g.pointerId || !r) return;
8695
8695
  const w = r.screenToSvg(h.clientX, h.clientY), $ = g.startPath, k = g.index;
8696
8696
  if (k <= 0 || k >= $.length - 1) return;
8697
- const x = $[k], S = [
8697
+ const x = $[k], T = [
8698
8698
  g.xLocked ? x[0] : ue(x[0] + (w[0] - g.startSvg[0])),
8699
8699
  g.yLocked ? x[1] : ue(x[1] + (w[1] - g.startSvg[1]))
8700
8700
  ];
8701
- if (S[0] === x[0] && S[1] === x[1]) return;
8701
+ if (T[0] === x[0] && T[1] === x[1]) return;
8702
8702
  const I = $.map((V) => [V[0], V[1]]);
8703
- I[k] = S;
8704
- const D = Mt($[k - 1], $[k]);
8705
- k - 1 > 0 && (D === "h" ? I[k - 1] = [$[k - 1][0], S[1]] : I[k - 1] = [S[0], $[k - 1][1]]);
8703
+ I[k] = T;
8704
+ const z = Mt($[k - 1], $[k]);
8705
+ k - 1 > 0 && (z === "h" ? I[k - 1] = [$[k - 1][0], T[1]] : I[k - 1] = [T[0], $[k - 1][1]]);
8706
8706
  const X = Mt($[k], $[k + 1]);
8707
- k + 1 < $.length - 1 && (X === "h" ? I[k + 1] = [$[k + 1][0], S[1]] : I[k + 1] = [S[0], $[k + 1][1]]), b.getState().updateWirePath(e, I);
8707
+ k + 1 < $.length - 1 && (X === "h" ? I[k + 1] = [$[k + 1][0], T[1]] : I[k + 1] = [T[0], $[k + 1][1]]), b.getState().updateWirePath(e, I);
8708
8708
  }, f = (h) => {
8709
8709
  const g = i.current;
8710
8710
  !g || h.pointerId !== g.pointerId || (h.target.hasPointerCapture(h.pointerId) && h.target.releasePointerCapture(h.pointerId), i.current = null, document.body.style.cursor = "");
@@ -8756,16 +8756,16 @@ function sS({
8756
8756
  if (!g || h.pointerId !== g.pointerId || !o) return;
8757
8757
  const w = o.screenToSvg(h.clientX, h.clientY), $ = g.startPath, k = g.segIndex;
8758
8758
  if (k >= $.length - 1) return;
8759
- const x = $[k], S = $[k + 1], I = [];
8760
- for (let D = 0; D <= k; D++) I.push($[D]);
8759
+ const x = $[k], T = $[k + 1], I = [];
8760
+ for (let z = 0; z <= k; z++) I.push($[z]);
8761
8761
  if (g.axis === "h") {
8762
- const D = ue(x[1] + (w[1] - g.startSvg[1]));
8763
- I.push([x[0], D]), I.push([S[0], D]);
8762
+ const z = ue(x[1] + (w[1] - g.startSvg[1]));
8763
+ I.push([x[0], z]), I.push([T[0], z]);
8764
8764
  } else {
8765
- const D = ue(x[0] + (w[0] - g.startSvg[0]));
8766
- I.push([D, x[1]]), I.push([D, S[1]]);
8765
+ const z = ue(x[0] + (w[0] - g.startSvg[0]));
8766
+ I.push([z, x[1]]), I.push([z, T[1]]);
8767
8767
  }
8768
- for (let D = k + 1; D < $.length; D++) I.push($[D]);
8768
+ for (let z = k + 1; z < $.length; z++) I.push($[z]);
8769
8769
  b.getState().updateWirePath(e, I);
8770
8770
  }, p = (h) => {
8771
8771
  const g = r.current;
@@ -8815,7 +8815,7 @@ function lS() {
8815
8815
  !l.includes(".") && e.has(l) && s.add(l);
8816
8816
  }
8817
8817
  return /* @__PURE__ */ m("g", { className: "ole-bus-layer", children: Array.from(e.values()).map(({ bus: a, geometry: l }) => {
8818
- const { axis: c, at: d, span: u } = l, f = u / 2, p = c === "x" ? d[0] - f : d[0], h = c === "x" ? d[1] : d[1] - f, g = c === "x" ? d[0] + f : d[0], w = c === "x" ? d[1] : d[1] + f, $ = i.has(a.id), k = s.has(a.id), x = r.get(a.id) ?? void 0, S = An / 2, I = c === "x" ? d[0] - f : d[0] - S, D = c === "x" ? d[1] - S : d[1] - f, X = c === "x" ? u : An, V = c === "x" ? An : u;
8818
+ const { axis: c, at: d, span: u } = l, f = u / 2, p = c === "x" ? d[0] - f : d[0], h = c === "x" ? d[1] : d[1] - f, g = c === "x" ? d[0] + f : d[0], w = c === "x" ? d[1] : d[1] + f, $ = i.has(a.id), k = s.has(a.id), x = r.get(a.id) ?? void 0, T = An / 2, I = c === "x" ? d[0] - f : d[0] - T, z = c === "x" ? d[1] - T : d[1] - f, X = c === "x" ? u : An, V = c === "x" ? An : u;
8819
8819
  return /* @__PURE__ */ j(
8820
8820
  "g",
8821
8821
  {
@@ -8830,7 +8830,7 @@ function lS() {
8830
8830
  "rect",
8831
8831
  {
8832
8832
  x: I,
8833
- y: D,
8833
+ y: z,
8834
8834
  width: X,
8835
8835
  height: V,
8836
8836
  fill: "transparent",
@@ -9023,7 +9023,7 @@ function yS(e) {
9023
9023
  }
9024
9024
  function bS() {
9025
9025
  const [e, t] = ye(gS());
9026
- return se(() => yS(t), []), !e || e.w === 0 && e.h === 0 ? null : /* @__PURE__ */ m(
9026
+ return ae(() => yS(t), []), !e || e.w === 0 && e.h === 0 ? null : /* @__PURE__ */ m(
9027
9027
  "rect",
9028
9028
  {
9029
9029
  className: "ole-marquee",
@@ -9214,7 +9214,7 @@ function SS() {
9214
9214
  "data-manual": c.userEdited ? "true" : void 0,
9215
9215
  "data-selected": g,
9216
9216
  className: "ole-wire",
9217
- points: k.map((S) => `${S[0]},${S[1]}`).join(" ")
9217
+ points: k.map((T) => `${T[0]},${T[1]}`).join(" ")
9218
9218
  },
9219
9219
  `${c.wireId}-${x}`
9220
9220
  ))
@@ -9239,7 +9239,7 @@ function ES(e) {
9239
9239
  }
9240
9240
  function MS() {
9241
9241
  const e = b((l) => l.wireDragFrom), t = b((l) => l.cursorSvg), [n, o] = ye(NS());
9242
- if (se(() => ES(o), []), !e || !t) return null;
9242
+ if (ae(() => ES(o), []), !e || !t) return null;
9243
9243
  const r = e.world, i = (n == null ? void 0 : n.world[0]) ?? t[0], s = (n == null ? void 0 : n.world[1]) ?? t[1], a = (n == null ? void 0 : n.create) === "junction";
9244
9244
  return /* @__PURE__ */ j("g", { className: "ole-wire-preview", pointerEvents: "none", children: [
9245
9245
  /* @__PURE__ */ m(
@@ -9361,7 +9361,7 @@ function hx() {
9361
9361
  (e.selectedNode || e.selectedWire || e.selection.length > 0 || e.selectedAnnotation) && e.clearSelection();
9362
9362
  }
9363
9363
  function IS() {
9364
- se(() => {
9364
+ ae(() => {
9365
9365
  const e = (t) => {
9366
9366
  if (CS(t.target)) return;
9367
9367
  const n = t.metaKey || t.ctrlKey, o = b.getState();
@@ -9465,7 +9465,7 @@ function BS(e) {
9465
9465
  }
9466
9466
  const sr = "ole-hover-element-host", jS = "ole-hover-terminal-on", LS = "ole-hover-node-on";
9467
9467
  function zS(e) {
9468
- se(() => {
9468
+ ae(() => {
9469
9469
  const t = e.current;
9470
9470
  if (!t) return;
9471
9471
  let n = null, o = null;
@@ -9591,56 +9591,60 @@ const HS = {
9591
9591
  id: "select",
9592
9592
  cursor: "default",
9593
9593
  onPointerDown(e, t) {
9594
- var p, h, g, w, $, k, x;
9594
+ var p, h, g, w, $, k, x, T;
9595
9595
  if (e.button !== 0 || e.target instanceof Element && e.target.closest(".ole-bus-handle, .ole-wire-handle"))
9596
9596
  return;
9597
9597
  const n = b.getState(), o = tn(e.target);
9598
9598
  if (o) {
9599
9599
  e.preventDefault(), e.stopPropagation();
9600
- const S = (p = n.diagram.annotations) == null ? void 0 : p.find((I) => I.id === o);
9601
- if (!S) return;
9600
+ const I = (p = n.diagram.annotations) == null ? void 0 : p.find((z) => z.id === o);
9601
+ if (!I) return;
9602
9602
  n.setSelectedAnnotation(o), ge = {
9603
9603
  pointerId: e.pointerId,
9604
9604
  id: o,
9605
9605
  startSvg: t.viewport.screenToSvg(e.clientX, e.clientY),
9606
- origin: [S.at[0], S.at[1]],
9606
+ origin: [I.at[0], I.at[1]],
9607
9607
  moved: !1
9608
9608
  };
9609
9609
  return;
9610
9610
  }
9611
9611
  const i = (e.target instanceof Element ? (h = e.target.closest("[data-terminal-id]")) == null ? void 0 : h.getAttribute("data-terminal-id") : null) ? fn(e.target) : null;
9612
9612
  if (i) {
9613
- const S = i.indexOf("."), I = S > 0 ? i.slice(0, S) : "";
9614
- if (I && n.selection.includes(I)) {
9615
- e.preventDefault(), e.stopPropagation(), e.target instanceof Element && ((w = (g = e.target).hasPointerCapture) != null && w.call(g, e.pointerId)) && e.target.releasePointerCapture(e.pointerId), t.hostEl.classList.add("tool-wire"), n.setWireFromTerminal(i), n.setCursorSvg(t.viewport.screenToSvg(e.clientX, e.clientY)), Ie = { pointerId: e.pointerId, fromRef: i };
9613
+ const I = i.indexOf("."), z = I > 0 ? i.slice(0, I) : "";
9614
+ if (z && n.selection.includes(z)) {
9615
+ e.preventDefault(), e.stopPropagation(), e.target instanceof Element && ((w = (g = e.target).hasPointerCapture) != null && w.call(g, e.pointerId)) && e.target.releasePointerCapture(e.pointerId), t.hostEl.classList.add("tool-wire"), n.setWireFromTerminal(i);
9616
+ const X = ($ = n.internal.terminals.get(
9617
+ i
9618
+ )) == null ? void 0 : $.world;
9619
+ X && n.setWireDragFrom({ spec: { end: i }, world: X, ref: i }), n.setCursorSvg(t.viewport.screenToSvg(e.clientX, e.clientY)), Ie = { pointerId: e.pointerId, fromRef: i };
9616
9620
  return;
9617
9621
  }
9618
9622
  }
9619
9623
  let s = ut(e.target);
9620
9624
  if (!s) {
9621
- const S = Gn(e.target);
9622
- if (S && typeof document < "u") {
9623
- const I = document.elementsFromPoint(e.clientX, e.clientY);
9624
- for (const D of I) {
9625
- const X = (k = ($ = D.closest) == null ? void 0 : $.call(D, "[data-bus-id]")) == null ? void 0 : k.getAttribute("data-bus-id");
9626
- if (!X) continue;
9627
- const V = (x = n.diagram.wires) == null ? void 0 : x.find((te) => te.id === S);
9628
- V && (V.ends[0] === X || V.ends[1] === X) && (s = X);
9625
+ const I = Gn(e.target);
9626
+ if (I && typeof document < "u") {
9627
+ const z = document.elementsFromPoint(e.clientX, e.clientY);
9628
+ for (const X of z) {
9629
+ const V = (x = (k = X.closest) == null ? void 0 : k.call(X, "[data-bus-id]")) == null ? void 0 : x.getAttribute("data-bus-id");
9630
+ if (!V) continue;
9631
+ const te = (T = n.diagram.wires) == null ? void 0 : T.find((se) => se.id === I);
9632
+ te && (te.ends[0] === V || te.ends[1] === V) && (s = V);
9629
9633
  break;
9630
9634
  }
9631
9635
  }
9632
9636
  }
9633
9637
  if (!s) {
9634
- const S = Gn(e.target);
9635
- if (S) {
9638
+ const I = Gn(e.target);
9639
+ if (I) {
9636
9640
  if (e.preventDefault(), e.altKey) {
9637
- const I = hn(e.target);
9638
- if (I) {
9639
- n.setSelectedNode(I);
9641
+ const z = hn(e.target);
9642
+ if (z) {
9643
+ n.setSelectedNode(z);
9640
9644
  return;
9641
9645
  }
9642
9646
  }
9643
- n.setSelectedWire(S);
9647
+ n.setSelectedWire(I);
9644
9648
  return;
9645
9649
  }
9646
9650
  e.shiftKey || n.clearSelection(), Ce = {
@@ -9656,19 +9660,19 @@ const HS = {
9656
9660
  const l = e.shiftKey ? b.getState().selection : a.includes(s) ? a : [s];
9657
9661
  if (l.length === 0) return;
9658
9662
  const c = b.getState().internal, d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
9659
- for (const S of l) {
9660
- const I = c.buses.get(S);
9661
- if (I) {
9662
- u.set(S, [I.geometry.at[0], I.geometry.at[1]]);
9663
+ for (const I of l) {
9664
+ const z = c.buses.get(I);
9665
+ if (z) {
9666
+ u.set(I, [z.geometry.at[0], z.geometry.at[1]]);
9663
9667
  continue;
9664
9668
  }
9665
- const D = c.junctions.get(S);
9666
- if (D) {
9667
- f.set(S, [D.world[0], D.world[1]]);
9669
+ const X = c.junctions.get(I);
9670
+ if (X) {
9671
+ f.set(I, [X.world[0], X.world[1]]);
9668
9672
  continue;
9669
9673
  }
9670
- const X = c.layout.get(S);
9671
- X && d.set(S, { ...X });
9674
+ const V = c.layout.get(I);
9675
+ V && d.set(I, { ...V });
9672
9676
  }
9673
9677
  d.size === 0 && u.size === 0 && f.size === 0 || (de = {
9674
9678
  pointerId: e.pointerId,
@@ -9747,7 +9751,7 @@ const HS = {
9747
9751
  }
9748
9752
  if (Ie && e.pointerId === Ie.pointerId) {
9749
9753
  const n = b.getState(), o = Ie.fromRef;
9750
- Ie = null, t.hostEl.classList.remove("tool-wire"), n.setWireFromTerminal(null), n.setCursorSvg(null), Ke(null);
9754
+ Ie = null, t.hostEl.classList.remove("tool-wire"), n.setWireFromTerminal(null), n.setWireDragFrom(null), n.setCursorSvg(null), Ke(null);
9751
9755
  const r = t.viewport.screenToSvg(e.clientX, e.clientY), i = nn(e.clientX, e.clientY) ?? (e.target instanceof Element ? e.target : null), s = Tt(i, r, At(t, e.clientX, e.clientY));
9752
9756
  if (on({
9753
9757
  world: [0, 0],
@@ -9840,7 +9844,7 @@ const HS = {
9840
9844
  if (Ie && e.pointerId === Ie.pointerId) {
9841
9845
  t.hostEl.classList.remove("tool-wire");
9842
9846
  const l = b.getState();
9843
- l.setWireFromTerminal(null), l.setCursorSvg(null), Ke(null), Ie = null;
9847
+ l.setWireFromTerminal(null), l.setWireDragFrom(null), l.setCursorSvg(null), Ke(null), Ie = null;
9844
9848
  }
9845
9849
  if (Ce && e.pointerId === Ce.pointerId) {
9846
9850
  if ((a = (s = t.hostEl).hasPointerCapture) != null && a.call(s, e.pointerId))
@@ -9864,7 +9868,7 @@ const HS = {
9864
9868
  if (de = null, Ce = null, ge = null, Ie) {
9865
9869
  e.hostEl.classList.remove("tool-wire");
9866
9870
  const t = b.getState();
9867
- t.setWireFromTerminal(null), t.setCursorSvg(null), Ke(null), Ie = null;
9871
+ t.setWireFromTerminal(null), t.setWireDragFrom(null), t.setCursorSvg(null), Ke(null), Ie = null;
9868
9872
  }
9869
9873
  Ft(null);
9870
9874
  }
@@ -10297,7 +10301,7 @@ const e4 = {
10297
10301
  };
10298
10302
  function r4(e, t) {
10299
10303
  const n = b((o) => o.activeTool);
10300
- se(() => {
10304
+ ae(() => {
10301
10305
  var f;
10302
10306
  const o = e.current;
10303
10307
  if (!o) return;
@@ -10356,7 +10360,7 @@ function d4(e, t, n = { tx: 0, ty: 0, scale: 1 }) {
10356
10360
  for (const c of r.current) c(l);
10357
10361
  }
10358
10362
  };
10359
- return se(() => {
10363
+ return ae(() => {
10360
10364
  const s = e.current;
10361
10365
  if (!s) return;
10362
10366
  let a = !1, l = -1, c = 0, d = 0, u = 0, f = 0, p = !1;
@@ -10399,7 +10403,7 @@ function d4(e, t, n = { tx: 0, ty: 0, scale: 1 }) {
10399
10403
  if (W.length < 2) return;
10400
10404
  const xe = W[1].x - W[0].x, me = W[1].y - W[0].y, be = Math.hypot(xe, me) || 1, ne = s.getBoundingClientRect(), re = (W[0].x + W[1].x) / 2 - ne.left, we = (W[0].y + W[1].y) / 2 - ne.top, ve = be / g.startDist, Ne = Pn(g.startScale * ve, Cn, In), Ae = Ne / g.startScale;
10401
10405
  o.current.tx = g.startMidX - (g.startMidX - g.startTx) * Ae + (re - g.startMidX), o.current.ty = g.startMidY - (g.startMidY - g.startTy) * Ae + (we - g.startMidY), o.current.scale = Ne, i();
10402
- }, S = (R) => {
10406
+ }, T = (R) => {
10403
10407
  var W;
10404
10408
  if (R.pointerType === "touch" && h.has(R.pointerId) && (h.delete(R.pointerId), w)) {
10405
10409
  if (R.stopPropagation(), (W = s.hasPointerCapture) != null && W.call(s, R.pointerId))
@@ -10418,7 +10422,7 @@ function d4(e, t, n = { tx: 0, ty: 0, scale: 1 }) {
10418
10422
  } else
10419
10423
  o.current.tx -= R.deltaX, o.current.ty -= R.deltaY;
10420
10424
  i();
10421
- }, D = (R) => {
10425
+ }, z = (R) => {
10422
10426
  const W = R.button === 1, xe = p && R.button === 0;
10423
10427
  !W && !xe || (R.preventDefault(), a = !0, l = R.pointerId, c = R.clientX, d = R.clientY, u = o.current.tx, f = o.current.ty, s.setPointerCapture(R.pointerId), s.style.cursor = "grabbing");
10424
10428
  }, X = (R) => {
@@ -10431,11 +10435,11 @@ function d4(e, t, n = { tx: 0, ty: 0, scale: 1 }) {
10431
10435
  if (W && (W.tagName === "INPUT" || W.tagName === "TEXTAREA" || W.isContentEditable)) return;
10432
10436
  p = !0, s.style.cursor = "grab", R.preventDefault();
10433
10437
  }
10434
- }, le = (R) => {
10438
+ }, se = (R) => {
10435
10439
  R.code === "Space" && (p = !1, a || (s.style.cursor = ""));
10436
10440
  };
10437
- return s.addEventListener("wheel", I, { passive: !1 }), s.addEventListener("pointerdown", D), s.addEventListener("pointermove", X), s.addEventListener("pointerup", V), s.addEventListener("pointercancel", V), s.addEventListener("pointerdown", k, { capture: !0 }), s.addEventListener("pointermove", x, { capture: !0 }), s.addEventListener("pointerup", S, { capture: !0 }), s.addEventListener("pointercancel", S, { capture: !0 }), window.addEventListener("keydown", te), window.addEventListener("keyup", le), i(), () => {
10438
- s.removeEventListener("wheel", I), s.removeEventListener("pointerdown", D), s.removeEventListener("pointermove", X), s.removeEventListener("pointerup", V), s.removeEventListener("pointercancel", V), s.removeEventListener("pointerdown", k, { capture: !0 }), s.removeEventListener("pointermove", x, { capture: !0 }), s.removeEventListener("pointerup", S, { capture: !0 }), s.removeEventListener("pointercancel", S, { capture: !0 }), window.removeEventListener("keydown", te), window.removeEventListener("keyup", le);
10441
+ return s.addEventListener("wheel", I, { passive: !1 }), s.addEventListener("pointerdown", z), s.addEventListener("pointermove", X), s.addEventListener("pointerup", V), s.addEventListener("pointercancel", V), s.addEventListener("pointerdown", k, { capture: !0 }), s.addEventListener("pointermove", x, { capture: !0 }), s.addEventListener("pointerup", T, { capture: !0 }), s.addEventListener("pointercancel", T, { capture: !0 }), window.addEventListener("keydown", te), window.addEventListener("keyup", se), i(), () => {
10442
+ s.removeEventListener("wheel", I), s.removeEventListener("pointerdown", z), s.removeEventListener("pointermove", X), s.removeEventListener("pointerup", V), s.removeEventListener("pointercancel", V), s.removeEventListener("pointerdown", k, { capture: !0 }), s.removeEventListener("pointermove", x, { capture: !0 }), s.removeEventListener("pointerup", T, { capture: !0 }), s.removeEventListener("pointercancel", T, { capture: !0 }), window.removeEventListener("keydown", te), window.removeEventListener("keyup", se);
10439
10443
  };
10440
10444
  }, []), {
10441
10445
  screenToSvg(s, a) {
@@ -10467,8 +10471,8 @@ function f4(e) {
10467
10471
  return On[On.length - 1];
10468
10472
  }
10469
10473
  function h4() {
10470
- const e = ae(), t = he(null), n = he(null), o = he(null), r = d4(t, n);
10471
- r4(t, r), zS(t), se(() => (nr(r), () => nr(null)), [r]), se(() => {
10474
+ const e = le(), t = he(null), n = he(null), o = he(null), r = d4(t, n);
10475
+ r4(t, r), zS(t), ae(() => (nr(r), () => nr(null)), [r]), ae(() => {
10472
10476
  const d = (u) => {
10473
10477
  const f = o.current;
10474
10478
  if (!f) return;
@@ -10488,10 +10492,10 @@ function h4() {
10488
10492
  if (g)
10489
10493
  p.selection.includes(g) || p.setSelection([g]);
10490
10494
  else {
10491
- const D = hn(f);
10492
- D && p.selectedNode !== D && p.setSelectedNode(D);
10495
+ const z = hn(f);
10496
+ z && p.selectedNode !== z && p.setSelectedNode(z);
10493
10497
  }
10494
- const w = b.getState(), $ = w.selection.length > 0, k = w.selectedNode != null, x = !!w.clipboard, S = w.diagram.elements.length > 0, I = [
10498
+ const w = b.getState(), $ = w.selection.length > 0, k = w.selectedNode != null, x = !!w.clipboard, T = w.diagram.elements.length > 0, I = [
10495
10499
  {
10496
10500
  label: e("menu.undo"),
10497
10501
  shortcut: `${st}Z`,
@@ -10549,10 +10553,10 @@ function h4() {
10549
10553
  shortcut: `${st}A`,
10550
10554
  icon: _v,
10551
10555
  onSelect: () => {
10552
- const D = b.getState();
10553
- D.setSelection(D.diagram.elements.map((X) => X.id));
10556
+ const z = b.getState();
10557
+ z.setSelection(z.diagram.elements.map((X) => X.id));
10554
10558
  },
10555
- disabled: !S
10559
+ disabled: !T
10556
10560
  },
10557
10561
  { type: "separator" },
10558
10562
  {
@@ -10568,7 +10572,7 @@ function h4() {
10568
10572
  },
10569
10573
  [i, e]
10570
10574
  );
10571
- return se(() => {
10575
+ return ae(() => {
10572
10576
  const d = t.current;
10573
10577
  if (!d) return;
10574
10578
  const u = 700, f = 4;
@@ -10582,13 +10586,13 @@ function h4() {
10582
10586
  y: x.clientY,
10583
10587
  target: x.target
10584
10588
  }, p = window.setTimeout(() => {
10585
- const S = h;
10586
- h = null, p = void 0, S && (fx(d, S.pointerId), s(S.x, S.y, S.target));
10589
+ const T = h;
10590
+ h = null, p = void 0, T && (fx(d, T.pointerId), s(T.x, T.y, T.target));
10587
10591
  }, u));
10588
10592
  }, $ = (x) => {
10589
10593
  if (!h || x.pointerId !== h.pointerId) return;
10590
- const S = x.clientX - h.x, I = x.clientY - h.y;
10591
- Math.hypot(S, I) > f && g();
10594
+ const T = x.clientX - h.x, I = x.clientY - h.y;
10595
+ Math.hypot(T, I) > f && g();
10592
10596
  }, k = (x) => {
10593
10597
  !h || x.pointerId !== h.pointerId || g();
10594
10598
  };
@@ -10701,7 +10705,7 @@ function v4() {
10701
10705
  }
10702
10706
  function k4() {
10703
10707
  const [e, t] = ye(OS()), [n, o] = ye(!1), [r, i] = ye(null), s = he(null), a = he(void 0), [l] = ye(v4);
10704
- se(() => BS((h) => t(h)), []), se(() => {
10708
+ ae(() => BS((h) => t(h)), []), ae(() => {
10705
10709
  if (window.clearTimeout(a.current), o(!1), i(null), !!e)
10706
10710
  return a.current = window.setTimeout(() => o(!0), x4), () => window.clearTimeout(a.current);
10707
10711
  }, [e]);
@@ -10714,11 +10718,11 @@ function k4() {
10714
10718
  `[data-element-id="${_4(e)}"]`
10715
10719
  ), x = s.current;
10716
10720
  if (k && x) {
10717
- const S = k.getBoundingClientRect();
10718
- let I = S.bottom + wr;
10719
- I + x.offsetHeight > window.innerHeight - 4 && (I = S.top - x.offsetHeight - wr);
10720
- let D = S.left + S.width / 2 - x.offsetWidth / 2;
10721
- D = Math.max(4, Math.min(D, window.innerWidth - x.offsetWidth - 4)), (I !== g || D !== w) && (i({ top: I, left: D }), g = I, w = D);
10721
+ const T = k.getBoundingClientRect();
10722
+ let I = T.bottom + wr;
10723
+ I + x.offsetHeight > window.innerHeight - 4 && (I = T.top - x.offsetHeight - wr);
10724
+ let z = T.left + T.width / 2 - x.offsetWidth / 2;
10725
+ z = Math.max(4, Math.min(z, window.innerWidth - x.offsetWidth - 4)), (I !== g || z !== w) && (i({ top: I, left: z }), g = I, w = z);
10722
10726
  }
10723
10727
  h = requestAnimationFrame($);
10724
10728
  };
@@ -10913,11 +10917,11 @@ function Be({
10913
10917
  sn(() => {
10914
10918
  if (!s || !r.current || !i.current) return;
10915
10919
  const $ = r.current.getBoundingClientRect(), k = i.current.getBoundingClientRect(), x = 8;
10916
- let S = "top", I = $.top - k.height - x;
10917
- I < 4 && (S = "bottom", I = $.bottom + x);
10918
- let D = $.left + $.width / 2 - k.width / 2;
10919
- D = Math.max(4, Math.min(D, window.innerWidth - k.width - 4)), c({ top: I, left: D, side: S });
10920
- }, [s, e]), se(() => () => window.clearTimeout(u.current), []), se(() => {
10920
+ let T = "top", I = $.top - k.height - x;
10921
+ I < 4 && (T = "bottom", I = $.bottom + x);
10922
+ let z = $.left + $.width / 2 - k.width / 2;
10923
+ z = Math.max(4, Math.min(z, window.innerWidth - k.width - 4)), c({ top: I, left: z, side: T });
10924
+ }, [s, e]), ae(() => () => window.clearTimeout(u.current), []), ae(() => {
10921
10925
  if (!s) return;
10922
10926
  const $ = (x) => {
10923
10927
  x.key === "Escape" && a(!1);
@@ -10977,21 +10981,21 @@ function Be({
10977
10981
  const _r = 12, z4 = 56;
10978
10982
  function D4() {
10979
10983
  var $;
10980
- const e = ae(), t = b((k) => k.selection), n = b((k) => k.selectedNode), o = b((k) => k.selectedWire), r = b((k) => k.activeTool), i = b((k) => k.rotateSelection), s = b((k) => k.mirrorSelection), a = b((k) => k.deleteSelection), l = b((k) => k.deleteSelectedNode), c = b((k) => k.deleteSelectedWire), d = b((k) => k.resetWirePath), u = b((k) => k.internal.wireRenders), f = o != null && (($ = u.get(o)) == null ? void 0 : $.userEdited) === !0, p = he(null);
10981
- se(() => {
10984
+ const e = le(), t = b((k) => k.selection), n = b((k) => k.selectedNode), o = b((k) => k.selectedWire), r = b((k) => k.activeTool), i = b((k) => k.rotateSelection), s = b((k) => k.mirrorSelection), a = b((k) => k.deleteSelection), l = b((k) => k.deleteSelectedNode), c = b((k) => k.deleteSelectedWire), d = b((k) => k.resetWirePath), u = b((k) => k.internal.wireRenders), f = o != null && (($ = u.get(o)) == null ? void 0 : $.userEdited) === !0, p = he(null);
10985
+ ae(() => {
10982
10986
  const k = p.current;
10983
10987
  if (!k) return;
10984
- const x = t.length > 0, S = !x && o != null, I = !x && !S && n != null;
10985
- if (!((x || S || I) && (r === "select" || r === "pan"))) {
10988
+ const x = t.length > 0, T = !x && o != null, I = !x && !T && n != null;
10989
+ if (!((x || T || I) && (r === "select" || r === "pan"))) {
10986
10990
  k.style.display = "none";
10987
10991
  return;
10988
10992
  }
10989
10993
  k.style.display = "flex";
10990
10994
  let X = 0, V = "";
10991
10995
  const te = () => {
10992
- let le = 1 / 0, R = -1 / 0, W = 1 / 0, xe = -1 / 0, me = !1;
10996
+ let se = 1 / 0, R = -1 / 0, W = 1 / 0, xe = -1 / 0, me = !1;
10993
10997
  const be = (ne) => {
10994
- ne.width === 0 && ne.height === 0 || (ne.left < le && (le = ne.left), ne.right > R && (R = ne.right), ne.top < W && (W = ne.top), ne.bottom > xe && (xe = ne.bottom), me = !0);
10998
+ ne.width === 0 && ne.height === 0 || (ne.left < se && (se = ne.left), ne.right > R && (R = ne.right), ne.top < W && (W = ne.top), ne.bottom > xe && (xe = ne.bottom), me = !0);
10995
10999
  };
10996
11000
  if (x)
10997
11001
  for (const ne of t) {
@@ -11000,7 +11004,7 @@ function D4() {
11000
11004
  );
11001
11005
  re && be(re.getBoundingClientRect());
11002
11006
  }
11003
- else if (S && o) {
11007
+ else if (T && o) {
11004
11008
  const ne = document.querySelector(
11005
11009
  `polyline.ole-wire[data-wire-id="${CSS.escape(o)}"]`
11006
11010
  );
@@ -11012,7 +11016,7 @@ function D4() {
11012
11016
  for (const re of ne) be(re.getBoundingClientRect());
11013
11017
  }
11014
11018
  if (me) {
11015
- const ne = (le + R) / 2;
11019
+ const ne = (se + R) / 2;
11016
11020
  let re = W - _r, we = "-100%";
11017
11021
  re < z4 && (re = xe + _r, we = "0%");
11018
11022
  const ve = `translate3d(${ne}px, ${re}px, 0) translate(-50%, ${we})`;
@@ -11137,7 +11141,7 @@ function ro({
11137
11141
  children: o
11138
11142
  }) {
11139
11143
  const r = he(null);
11140
- return se(() => {
11144
+ return ae(() => {
11141
11145
  if (!e) return;
11142
11146
  const i = (a) => {
11143
11147
  r.current && !r.current.contains(a.target) && t(!1);
@@ -11250,10 +11254,10 @@ function Y4() {
11250
11254
  }
11251
11255
  function Mx() {
11252
11256
  const [e, t] = ye(() => F4());
11253
- return se(() => {
11257
+ return ae(() => {
11254
11258
  const n = Ex();
11255
11259
  n == null || n.classList.toggle("hide-grid", !e), H4(e);
11256
- }, [e]), se(() => {
11260
+ }, [e]), ae(() => {
11257
11261
  const n = (o) => {
11258
11262
  if (o.metaKey || o.ctrlKey || o.altKey || o.key !== "g" && o.key !== "G") return;
11259
11263
  const r = o.target;
@@ -11263,7 +11267,7 @@ function Mx() {
11263
11267
  }, []), [e, t];
11264
11268
  }
11265
11269
  function Tx() {
11266
- const e = ae();
11270
+ const e = le();
11267
11271
  return /* @__PURE__ */ m(
11268
11272
  Be,
11269
11273
  {
@@ -11285,7 +11289,7 @@ function Tx() {
11285
11289
  );
11286
11290
  }
11287
11291
  function Ax() {
11288
- const e = ae();
11292
+ const e = le();
11289
11293
  return /* @__PURE__ */ m(
11290
11294
  Be,
11291
11295
  {
@@ -11307,8 +11311,8 @@ function Ax() {
11307
11311
  );
11308
11312
  }
11309
11313
  function Cx() {
11310
- const e = ae(), [t, n] = ye(s4);
11311
- return se(() => a4(n), []), /* @__PURE__ */ m(
11314
+ const e = le(), [t, n] = ye(s4);
11315
+ return ae(() => a4(n), []), /* @__PURE__ */ m(
11312
11316
  Be,
11313
11317
  {
11314
11318
  content: /* @__PURE__ */ j("div", { className: "space-y-0.5", children: [
@@ -11332,7 +11336,7 @@ function Cx() {
11332
11336
  );
11333
11337
  }
11334
11338
  function Ix() {
11335
- const e = ae();
11339
+ const e = le();
11336
11340
  return /* @__PURE__ */ m(
11337
11341
  Be,
11338
11342
  {
@@ -11357,7 +11361,7 @@ function Px({
11357
11361
  grid: e,
11358
11362
  setGrid: t
11359
11363
  }) {
11360
- const n = ae();
11364
+ const n = le();
11361
11365
  return /* @__PURE__ */ m(
11362
11366
  Be,
11363
11367
  {
@@ -11384,7 +11388,7 @@ function Px({
11384
11388
  );
11385
11389
  }
11386
11390
  function Ox() {
11387
- const e = ae(), t = b(
11391
+ const e = le(), t = b(
11388
11392
  (n) => {
11389
11393
  var o;
11390
11394
  return ((o = n.diagram.meta) == null ? void 0 : o.labelMode) ?? "all";
@@ -11413,7 +11417,7 @@ function Ox() {
11413
11417
  );
11414
11418
  }
11415
11419
  function K4({ stacked: e } = {}) {
11416
- const t = ae(), [n, o] = ye(!1), [r, i] = Mx(), s = /* @__PURE__ */ j("div", { className: "space-y-0.5", children: [
11420
+ const t = le(), [n, o] = ye(!1), [r, i] = Mx(), s = /* @__PURE__ */ j("div", { className: "space-y-0.5", children: [
11417
11421
  /* @__PURE__ */ m("div", { className: "font-medium", children: t("view.menu") }),
11418
11422
  /* @__PURE__ */ m("div", { className: "text-muted-foreground", children: t("view.menuHint") })
11419
11423
  ] }), a = e ? /* @__PURE__ */ m(Be, { content: s, children: /* @__PURE__ */ j(
@@ -11555,7 +11559,7 @@ const Sr = [
11555
11559
  }
11556
11560
  ];
11557
11561
  function J4() {
11558
- const e = ae(), t = b((d) => d.activeTool), n = b((d) => d.placeKind), o = b((d) => d.placeFromTerminal), r = b((d) => d.wireDragFrom), i = b((d) => d.busbarDrawStart), s = b(
11562
+ const e = le(), t = b((d) => d.activeTool), n = b((d) => d.placeKind), o = b((d) => d.placeFromTerminal), r = b((d) => d.wireDragFrom), i = b((d) => d.busbarDrawStart), s = b(
11559
11563
  (d) => d.selection.length > 0 || d.selectedNode != null
11560
11564
  );
11561
11565
  let a = null, l = !1;
@@ -11593,7 +11597,7 @@ function J4() {
11593
11597
  ] });
11594
11598
  }
11595
11599
  function Z4() {
11596
- const e = ae(), t = b((h) => h.activeTool), n = b((h) => h.placeKind), o = b((h) => h.setActiveTool), r = b((h) => h.past.length), i = b((h) => h.future.length), s = b((h) => h.undo), a = b((h) => h.redo), l = Je(), c = Le(l, "tight"), d = !Le(l, "dense"), u = Le(l, "dense"), f = u ? Sr.filter((h) => h.id !== "select" && h.id !== "text") : Sr, p = (h) => t === h.switchTo;
11600
+ const e = le(), t = b((h) => h.activeTool), n = b((h) => h.placeKind), o = b((h) => h.setActiveTool), r = b((h) => h.past.length), i = b((h) => h.future.length), s = b((h) => h.undo), a = b((h) => h.redo), l = Je(), c = Le(l, "tight"), d = !Le(l, "dense"), u = Le(l, "dense"), f = u ? Sr.filter((h) => h.id !== "select" && h.id !== "text") : Sr, p = (h) => t === h.switchTo;
11597
11601
  return /* @__PURE__ */ j(
11598
11602
  "div",
11599
11603
  {
@@ -11671,7 +11675,7 @@ function Z4() {
11671
11675
  );
11672
11676
  }
11673
11677
  function Q4({ stacked: e }) {
11674
- const t = ae(), n = It((r) => r.outlineOpen), o = It((r) => r.toggleOutline);
11678
+ const t = le(), n = It((r) => r.outlineOpen), o = It((r) => r.toggleOutline);
11675
11679
  return /* @__PURE__ */ m(
11676
11680
  dt,
11677
11681
  {
@@ -11748,7 +11752,7 @@ function Bx() {
11748
11752
  };
11749
11753
  }
11750
11754
  function e6({ iconOnly: e }) {
11751
- const t = ae(), [n, o] = ye(!1), r = Bx(), i = (s) => () => {
11755
+ const t = le(), [n, o] = ye(!1), r = Bx(), i = (s) => () => {
11752
11756
  o(!1), s();
11753
11757
  };
11754
11758
  return /* @__PURE__ */ j(
@@ -11810,7 +11814,7 @@ function e6({ iconOnly: e }) {
11810
11814
  );
11811
11815
  }
11812
11816
  function t6({ stacked: e }) {
11813
- const t = ae(), [n, o] = ye(!1), r = b((f) => f.past.length), i = b((f) => f.future.length), s = b((f) => f.undo), a = b((f) => f.redo), l = b((f) => f.selection.length > 0), c = b((f) => f.clipboard != null), d = Bx(), u = (f) => () => {
11817
+ const t = le(), [n, o] = ye(!1), r = b((f) => f.past.length), i = b((f) => f.future.length), s = b((f) => f.undo), a = b((f) => f.redo), l = b((f) => f.selection.length > 0), c = b((f) => f.clipboard != null), d = Bx(), u = (f) => () => {
11814
11818
  o(!1), f();
11815
11819
  };
11816
11820
  return /* @__PURE__ */ j(
@@ -11969,7 +11973,7 @@ function n6() {
11969
11973
  );
11970
11974
  }
11971
11975
  function o6({ onClick: e }) {
11972
- const t = ae(), n = Je(), o = Le(n, "compact");
11976
+ const t = le(), n = Je(), o = Le(n, "compact");
11973
11977
  return /* @__PURE__ */ j(
11974
11978
  "button",
11975
11979
  {
@@ -11992,7 +11996,7 @@ function Nr({
11992
11996
  onClose: e,
11993
11997
  sheet: t
11994
11998
  }) {
11995
- const n = ae(), o = b((c) => c.diagram.elements), r = b((c) => c.activeTool === "place"), i = Je(), s = Le(i, "compact"), a = Le(i, "dense"), l = t ? "min(50vh, calc(100vh - 9rem))" : r ? "min(40vh, calc(100vh - 200px))" : "min(70vh, calc(100vh - 100px))";
11999
+ const n = le(), o = b((c) => c.diagram.elements), r = b((c) => c.activeTool === "place"), i = Je(), s = Le(i, "compact"), a = Le(i, "dense"), l = t ? "min(50vh, calc(100vh - 9rem))" : r ? "min(40vh, calc(100vh - 200px))" : "min(70vh, calc(100vh - 100px))";
11996
12000
  return /* @__PURE__ */ j(
11997
12001
  "aside",
11998
12002
  {
@@ -12401,7 +12405,7 @@ function m6(e) {
12401
12405
  }
12402
12406
  }
12403
12407
  function f6() {
12404
- const e = ae(), t = b((u) => u.activeTool === "place"), n = b((u) => u.placeKind), o = b((u) => u.setActiveTool), r = It((u) => u.outlineOpen), i = Je(), s = Le(i, "dense"), a = 68, c = s ? void 0 : `calc(100vh - ${a}px - ${r ? "calc(40vh + 20px)" : "68px"})`;
12408
+ const e = le(), t = b((u) => u.activeTool === "place"), n = b((u) => u.placeKind), o = b((u) => u.setActiveTool), r = It((u) => u.outlineOpen), i = Je(), s = Le(i, "dense"), a = 68, c = s ? void 0 : `calc(100vh - ${a}px - ${r ? "calc(40vh + 20px)" : "68px"})`;
12405
12409
  if (!t || s && n != null) return null;
12406
12410
  const d = s ? {
12407
12411
  top: `calc(${a}px + var(--ole-top-inset, 0px))`,
@@ -12444,7 +12448,7 @@ function f6() {
12444
12448
  );
12445
12449
  }
12446
12450
  function h6({ sheet: e }) {
12447
- const t = ae(), n = Pt(), [o, r] = ye(""), [i, s] = ye(
12451
+ const t = le(), n = Pt(), [o, r] = ye(""), [i, s] = ye(
12448
12452
  () => u6()
12449
12453
  ), a = Rr(() => {
12450
12454
  const u = o.trim().toLowerCase();
@@ -12500,7 +12504,7 @@ function p6({
12500
12504
  value: e,
12501
12505
  onChange: t
12502
12506
  }) {
12503
- const n = ae();
12507
+ const n = le();
12504
12508
  return /* @__PURE__ */ j("div", { className: "relative", children: [
12505
12509
  /* @__PURE__ */ m(vv, { className: "pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground" }),
12506
12510
  /* @__PURE__ */ m(
@@ -12530,12 +12534,12 @@ function g6({
12530
12534
  entry: e,
12531
12535
  sheet: t
12532
12536
  }) {
12533
- const n = ae(), o = Pt(), r = o(`${e.id}.name`, e.name), i = o(`${e.id}.desc`, e.description ?? ""), s = b((u) => u.setActiveTool), a = b(
12537
+ const n = le(), o = Pt(), r = o(`${e.id}.name`, e.name), i = o(`${e.id}.desc`, e.description ?? ""), s = b((u) => u.setActiveTool), a = b(
12534
12538
  (u) => u.activeTool === "place" && u.placeKind === e.id
12535
12539
  ), l = b(
12536
12540
  (u) => t && u.activeTool === "place" && u.placeKind == null && u.lastPlaceKind === e.id
12537
12541
  ), c = he(null);
12538
- return se(() => {
12542
+ return ae(() => {
12539
12543
  var u;
12540
12544
  l && ((u = c.current) == null || u.scrollIntoView({ block: "nearest" }));
12541
12545
  }, [l]), /* @__PURE__ */ j(
@@ -12609,7 +12613,7 @@ const Tr = an((e) => ({
12609
12613
  }
12610
12614
  }));
12611
12615
  function w6() {
12612
- const e = ae(), t = Tr((o) => o.dismissed), n = Tr((o) => o.dismiss);
12616
+ const e = le(), t = Tr((o) => o.dismissed), n = Tr((o) => o.dismiss);
12613
12617
  return t ? null : /* @__PURE__ */ j(
12614
12618
  "div",
12615
12619
  {
@@ -12697,7 +12701,7 @@ function Bn({
12697
12701
  ] });
12698
12702
  }
12699
12703
  function x6() {
12700
- const e = ae(), t = b((f) => f.selection), n = b((f) => f.diagram.elements), o = b((f) => f.diagram.buses), r = b((f) => f.diagram.junctions), i = b((f) => f.selectedNode), s = b((f) => f.selectedWire);
12704
+ const e = le(), t = b((f) => f.selection), n = b((f) => f.diagram.elements), o = b((f) => f.diagram.buses), r = b((f) => f.diagram.junctions), i = b((f) => f.selectedNode), s = b((f) => f.selectedWire);
12701
12705
  if (s) return /* @__PURE__ */ m(N6, { wireId: s });
12702
12706
  if (i) return /* @__PURE__ */ m(M6, { nodeId: i });
12703
12707
  if (t.length === 0)
@@ -12774,7 +12778,7 @@ function k6({
12774
12778
  field: n
12775
12779
  }) {
12776
12780
  var l;
12777
- const o = ae(), r = Pt(), i = ((l = t.params) == null ? void 0 : l[n.name]) ?? n.default, s = r(`${t.kind}.param.${n.name}`, n.label ?? n.name), a = (c) => {
12781
+ const o = le(), r = Pt(), i = ((l = t.params) == null ? void 0 : l[n.name]) ?? n.default, s = r(`${t.kind}.param.${n.name}`, n.label ?? n.name), a = (c) => {
12778
12782
  const d = { ...t.params ?? {} };
12779
12783
  c === void 0 || c === n.default ? delete d[n.name] : d[n.name] = c, b.getState().updateElement(e, {
12780
12784
  params: Object.keys(d).length > 0 ? d : void 0
@@ -12804,7 +12808,7 @@ function _6({
12804
12808
  fieldKey: n,
12805
12809
  value: o
12806
12810
  }) {
12807
- const r = ae(), i = (s) => {
12811
+ const r = le(), i = (s) => {
12808
12812
  const a = { ...t.params ?? {} };
12809
12813
  s === void 0 ? delete a[n] : a[n] = s, b.getState().updateElement(e, {
12810
12814
  params: Object.keys(a).length > 0 ? a : void 0
@@ -12820,7 +12824,7 @@ function _6({
12820
12824
  );
12821
12825
  }
12822
12826
  function $6({ bus: e }) {
12823
- const t = ae(), n = e.id, o = (r) => {
12827
+ const t = le(), n = e.id, o = (r) => {
12824
12828
  const i = r.trim();
12825
12829
  Jn(n, { name: i === "" ? void 0 : i });
12826
12830
  };
@@ -12869,18 +12873,18 @@ function Jn(e, t) {
12869
12873
  });
12870
12874
  }
12871
12875
  function N6({ wireId: e }) {
12872
- const t = ae(), n = b((w) => w.diagram.wires), o = b((w) => w.diagram.elements), r = b((w) => w.diagram.buses), i = b((w) => w.diagram.junctions), s = b((w) => w.internal.terminalToNode), a = b((w) => w.setSelectedNode), l = (n ?? []).find((w) => w.id === e);
12876
+ const t = le(), n = b((w) => w.diagram.wires), o = b((w) => w.diagram.elements), r = b((w) => w.diagram.buses), i = b((w) => w.diagram.junctions), s = b((w) => w.internal.terminalToNode), a = b((w) => w.setSelectedNode), l = (n ?? []).find((w) => w.id === e);
12873
12877
  if (!l)
12874
12878
  return /* @__PURE__ */ m("div", { className: "px-4 py-5 text-center text-xs text-muted-foreground", children: t("props.wireNotFound", { id: e }) });
12875
12879
  const c = s.get(l.ends[0]), d = new Map(o.map((w) => [w.id, w])), u = new Map((r ?? []).map((w) => [w.id, w])), f = new Map((i ?? []).map((w) => [w.id, w])), p = (w) => {
12876
12880
  if (!w.includes(".")) {
12877
12881
  const I = u.get(w);
12878
12882
  if (I) return { id: w, label: I.name ?? w };
12879
- const D = f.get(w);
12880
- return { id: w, label: (D == null ? void 0 : D.name) ?? w };
12883
+ const z = f.get(w);
12884
+ return { id: w, label: (z == null ? void 0 : z.name) ?? w };
12881
12885
  }
12882
- const $ = w.indexOf("."), k = w.slice(0, $), x = w.slice($ + 1), S = d.get(k);
12883
- return { id: k, label: (S == null ? void 0 : S.name) ?? k, pin: x };
12886
+ const $ = w.indexOf("."), k = w.slice(0, $), x = w.slice($ + 1), T = d.get(k);
12887
+ return { id: k, label: (T == null ? void 0 : T.name) ?? k, pin: x };
12884
12888
  }, h = p(l.ends[0]), g = p(l.ends[1]);
12885
12889
  return /* @__PURE__ */ j("div", { className: "flex flex-col gap-3 px-3 py-3 text-xs", children: [
12886
12890
  /* @__PURE__ */ j("div", { className: "space-y-1", children: [
@@ -12913,7 +12917,7 @@ function N6({ wireId: e }) {
12913
12917
  }
12914
12918
  function E6({ junction: e }) {
12915
12919
  var r;
12916
- const t = ae(), n = b((i) => {
12920
+ const t = le(), n = b((i) => {
12917
12921
  var s;
12918
12922
  return (s = i.internal.junctions.get(e.id)) == null ? void 0 : s.world;
12919
12923
  }), o = ((r = e.layout) == null ? void 0 : r.at) ?? n;
@@ -12950,7 +12954,7 @@ function E6({ junction: e }) {
12950
12954
  ] });
12951
12955
  }
12952
12956
  function M6({ nodeId: e }) {
12953
- const t = ae(), n = b((a) => a.internal.nodes.get(e)), o = b((a) => a.diagram.elements), r = b((a) => a.setSelection);
12957
+ const t = le(), n = b((a) => a.internal.nodes.get(e)), o = b((a) => a.diagram.elements), r = b((a) => a.setSelection);
12954
12958
  if (!n)
12955
12959
  return /* @__PURE__ */ m("div", { className: "px-4 py-5 text-center text-xs text-muted-foreground", children: t("props.nodeNotFound", { id: e }) });
12956
12960
  const i = /* @__PURE__ */ new Map();
@@ -13006,7 +13010,7 @@ function ht({
13006
13010
  onCommit: r
13007
13011
  }) {
13008
13012
  const [i, s] = ye(t), a = he(null);
13009
- return se(() => s(t), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ j("div", { className: "relative", children: [
13013
+ return ae(() => s(t), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ j("div", { className: "relative", children: [
13010
13014
  /* @__PURE__ */ m(
13011
13015
  "input",
13012
13016
  {
@@ -13037,7 +13041,7 @@ function so({
13037
13041
  onCommit: n
13038
13042
  }) {
13039
13043
  const [o, r] = ye(t);
13040
- return se(() => r(t), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ m(
13044
+ return ae(() => r(t), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ m(
13041
13045
  "textarea",
13042
13046
  {
13043
13047
  rows: 2,
@@ -13058,7 +13062,7 @@ function gn({
13058
13062
  onCommit: r
13059
13063
  }) {
13060
13064
  const [i, s] = ye(String(t)), a = he(null);
13061
- return se(() => s(String(t)), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ j("div", { className: "relative", children: [
13065
+ return ae(() => s(String(t)), [t]), /* @__PURE__ */ m(ft, { label: e, children: /* @__PURE__ */ j("div", { className: "relative", children: [
13062
13066
  /* @__PURE__ */ m(
13063
13067
  "input",
13064
13068
  {
@@ -13109,7 +13113,7 @@ function T6({
13109
13113
  field: n
13110
13114
  }) {
13111
13115
  var l;
13112
- const o = ae(), i = Pt()(`${t.kind}.state.${n.name}`, n.label ?? n.name), s = ((l = t.state) == null ? void 0 : l[n.name]) ?? n.default, a = (c) => {
13116
+ const o = le(), i = Pt()(`${t.kind}.state.${n.name}`, n.label ?? n.name), s = ((l = t.state) == null ? void 0 : l[n.name]) ?? n.default, a = (c) => {
13113
13117
  const d = { ...t.state ?? {} };
13114
13118
  c === void 0 || c === n.default ? delete d[n.name] : d[n.name] = c, b.getState().updateElement(e, {
13115
13119
  state: Object.keys(d).length > 0 ? d : void 0
@@ -13132,7 +13136,7 @@ function T6({
13132
13136
  );
13133
13137
  }
13134
13138
  function A6() {
13135
- const e = ae(), t = Pt(), n = b((u) => u.selection), o = b((u) => u.selectedNode), r = b((u) => u.selectedWire), i = b((u) => u.diagram.elements), s = b((u) => u.diagram.buses), a = Je(), l = Le(a, "dense");
13139
+ const e = le(), t = Pt(), n = b((u) => u.selection), o = b((u) => u.selectedNode), r = b((u) => u.selectedWire), i = b((u) => u.diagram.elements), s = b((u) => u.diagram.buses), a = Je(), l = Le(a, "dense");
13136
13140
  if (n.length === 0 && !o && !r) return null;
13137
13141
  let c = e("props.title"), d = null;
13138
13142
  if (r)
@@ -13175,7 +13179,7 @@ function A6() {
13175
13179
  );
13176
13180
  }
13177
13181
  function C6() {
13178
- se(() => {
13182
+ ae(() => {
13179
13183
  const e = (n) => {
13180
13184
  const o = n.target;
13181
13185
  if (!o || o.tagName === "INPUT" || o.tagName === "TEXTAREA" || o.isContentEditable)
@@ -13234,14 +13238,14 @@ function j6(e) {
13234
13238
  typeof document > "u" || document.documentElement.classList.toggle("dark", e === "dark");
13235
13239
  }
13236
13240
  function p5({ className: e, diagram: t, locale: n, theme: o }) {
13237
- return se(() => {
13241
+ return ae(() => {
13238
13242
  if (!t) return;
13239
13243
  b.getState().diagram.elements.length === 0 && b.getState().setDiagram(t);
13240
- }, [t]), se(() => {
13244
+ }, [t]), ae(() => {
13241
13245
  n && ln.getState().setLocale(n);
13242
- }, [n]), se(() => {
13246
+ }, [n]), ae(() => {
13243
13247
  o && j6(o);
13244
- }, [o]), se(() => {
13248
+ }, [o]), ae(() => {
13245
13249
  vx();
13246
13250
  }, []), IS(), /* @__PURE__ */ m("div", { className: `ole-root ${e ?? "h-full w-full"}`, children: /* @__PURE__ */ m(I6, {}) });
13247
13251
  }
@@ -13325,15 +13329,15 @@ async function Cr(e, t, n = {}) {
13325
13329
  return i.href = r, i.download = (t == null ? void 0 : t.name) ?? "diagram.json", i.click(), URL.revokeObjectURL(r), t ?? { name: "diagram.json" };
13326
13330
  }
13327
13331
  function g5() {
13328
- const e = ae(), t = b((u) => u.fileSession), n = (t == null ? void 0 : t.name) ?? e("common.unnamed"), { onNew: o, onOpen: r, onSave: i, onSaveAs: s } = D6(), [a, l] = ye(!1), c = he(null);
13329
- se(() => {
13332
+ const e = le(), t = b((u) => u.fileSession), n = (t == null ? void 0 : t.name) ?? e("common.unnamed"), { onNew: o, onOpen: r, onSave: i, onSaveAs: s } = D6(), [a, l] = ye(!1), c = he(null);
13333
+ ae(() => {
13330
13334
  const u = (f) => {
13331
13335
  if (!(f.metaKey || f.ctrlKey)) return;
13332
13336
  const p = f.key.toLowerCase();
13333
13337
  p === "o" ? (f.preventDefault(), r()) : p === "s" && (f.preventDefault(), f.shiftKey ? s() : i());
13334
13338
  };
13335
13339
  return window.addEventListener("keydown", u), () => window.removeEventListener("keydown", u);
13336
- }, [r, i, s]), se(() => {
13340
+ }, [r, i, s]), ae(() => {
13337
13341
  if (!a) return;
13338
13342
  const u = (p) => {
13339
13343
  c.current && !c.current.contains(p.target) && l(!1);
@@ -13401,7 +13405,7 @@ function qt({
13401
13405
  );
13402
13406
  }
13403
13407
  function D6() {
13404
- const e = ae(), t = b((l) => l.loadDiagramFromFile), n = b((l) => l.setFileSession), o = b((l) => l.setDiagram);
13408
+ const e = le(), t = b((l) => l.loadDiagramFromFile), n = b((l) => l.setFileSession), o = b((l) => l.setDiagram);
13405
13409
  return { onNew: () => {
13406
13410
  const { diagram: l } = b.getState();
13407
13411
  l.elements.length > 0 && !confirm(e("topbar.file.newConfirm")) || (o({ version: "1", elements: [] }), n(null));
@@ -13621,18 +13625,18 @@ function t5(e, t, n, o, r, i) {
13621
13625
  const W = Math.sqrt(w);
13622
13626
  f *= W, p *= W;
13623
13627
  }
13624
- const $ = r === i ? -1 : 1, k = f * f * p * p - f * f * u * u - p * p * d * d, x = f * f * u * u + p * p * d * d, S = $ * Math.sqrt(Math.max(0, k / x)), I = S * (f * u) / p, D = S * -(p * d) / f, X = I + (s + l) / 2, V = D + (a + c) / 2, te = (W, xe, me, be) => {
13628
+ const $ = r === i ? -1 : 1, k = f * f * p * p - f * f * u * u - p * p * d * d, x = f * f * u * u + p * p * d * d, T = $ * Math.sqrt(Math.max(0, k / x)), I = T * (f * u) / p, z = T * -(p * d) / f, X = I + (s + l) / 2, V = z + (a + c) / 2, te = (W, xe, me, be) => {
13625
13629
  const ne = W * me + xe * be, re = Math.hypot(W, xe) * Math.hypot(me, be);
13626
13630
  let we = Math.acos(Math.max(-1, Math.min(1, ne / re)));
13627
13631
  return W * be - xe * me < 0 && (we = -we), we;
13628
- }, le = te(1, 0, (d - I) / f, (u - D) / p);
13632
+ }, se = te(1, 0, (d - I) / f, (u - z) / p);
13629
13633
  let R = te(
13630
13634
  (d - I) / f,
13631
- (u - D) / p,
13635
+ (u - z) / p,
13632
13636
  (-d - I) / f,
13633
- (-u - D) / p
13637
+ (-u - z) / p
13634
13638
  );
13635
- return !i && R > 0 ? R -= 2 * Math.PI : i && R < 0 && (R += 2 * Math.PI), { cx: X, cy: V, theta1: le, delta: R };
13639
+ return !i && R > 0 ? R -= 2 * Math.PI : i && R < 0 && (R += 2 * Math.PI), { cx: X, cy: V, theta1: se, delta: R };
13636
13640
  }
13637
13641
  function He(e, t) {
13638
13642
  return De(e, t);
@@ -13720,9 +13724,9 @@ function Hx(e, t = {}) {
13720
13724
  }
13721
13725
  l.push(" </g>");
13722
13726
  for (const { bus: u, geometry: f } of e.buses.values()) {
13723
- const { axis: p, at: h, span: g } = f, w = g / 2, $ = p === "x" ? h[0] - w : h[0], k = p === "x" ? h[1] : h[1] - w, x = p === "x" ? h[0] + w : h[0], S = p === "x" ? h[1] : h[1] + w;
13727
+ const { axis: p, at: h, span: g } = f, w = g / 2, $ = p === "x" ? h[0] - w : h[0], k = p === "x" ? h[1] : h[1] - w, x = p === "x" ? h[0] + w : h[0], T = p === "x" ? h[1] : h[1] + w;
13724
13728
  l.push(
13725
- ` <line id="${at(u.id)}" x1="${$}" y1="${k}" x2="${x}" y2="${S}" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>`
13729
+ ` <line id="${at(u.id)}" x1="${$}" y1="${k}" x2="${x}" y2="${T}" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>`
13726
13730
  );
13727
13731
  }
13728
13732
  for (const { junction: u, world: f } of e.junctions.values())
@@ -13878,8 +13882,8 @@ function Wx(e, t) {
13878
13882
  o.href = n, o.download = t, o.click(), URL.revokeObjectURL(n);
13879
13883
  }
13880
13884
  function y5() {
13881
- const e = ae(), [t, n] = ye(!1), o = he(null);
13882
- se(() => {
13885
+ const e = le(), [t, n] = ye(!1), o = he(null);
13886
+ ae(() => {
13883
13887
  if (!t) return;
13884
13888
  const i = (a) => {
13885
13889
  o.current && !o.current.contains(a.target) && n(!1);