import { a as _, v as T, Z as N, b as j, W as cn, O as Zn, V as Hn, z as Cr, A as Ir, E as D, q as Sr, K as Kn, L as Xn, M as fn, c as dn, d as W, n as Br, F as Tr, S as Fr, P as Gr, e as Ur, r as On, $ as En, j as U, h as sn, f as _n, H as vn, T as Yn, J as s, y as x, R as Qn, k as qr, g as zr, x as hn, i as nr, X as $, l as m, m as rr, _ as Vr, o as J, U as Dr, Y as I, p as Wr, s as tr, t as er, u as q, w as Jr, B as Zr, D as $n, C as Hr, G as or, I as Kr, N as Xr, Q as Yr, a0 as Qr, a1 as nt } from "./graphlib-D2YdGpuK-CM8PX5pf.js";
var rt = /\s/;
function tt(n) {
  for (var r = n.length; r-- && rt.test(n.charAt(r)); ) ;
  return r;
}
var et = /^\s+/;
function ot(n) {
  return n && n.slice(0, tt(n) + 1).replace(et, "");
}
var Pn = NaN, it = /^[-+]0x[0-9a-f]+$/i, at = /^0b[01]+$/i, ut = /^0o[0-7]+$/i, ct = parseInt;
function ft(n) {
  if (typeof n == "number") return n;
  if (q(n)) return Pn;
  if (j(n)) {
    var r = typeof n.valueOf == "function" ? n.valueOf() : n;
    n = j(r) ? r + "" : r;
  }
  if (typeof n != "string") return n === 0 ? n : +n;
  n = ot(n);
  var t = at.test(n);
  return t || ut.test(n) ? ct(n.slice(2), t ? 2 : 8) : it.test(n) ? Pn : +n;
}
var Nn = 1 / 0, dt = 17976931348623157e292;
function F(n) {
  return n ? (n = ft(n), n === Nn || n === -Nn ? (n < 0 ? -1 : 1) * dt : n === n ? n : 0) : n === 0 ? n : 0;
}
function st(n) {
  var r = F(n), t = r % 1;
  return r === r ? t ? r - t : r : 0;
}
var Mn = Object.create, vt = /* @__PURE__ */ function() {
  function n() {
  }
  return function(r) {
    if (!j(r)) return {};
    if (Mn) return Mn(r);
    n.prototype = r;
    var t = new n();
    return n.prototype = void 0, t;
  };
}();
function ir(n, r) {
  var t = -1, e = n.length;
  for (r || (r = Array(e)); ++t < e; ) r[t] = n[t];
  return r;
}
function Z(n, r, t) {
  r == "__proto__" && _n ? _n(n, r, {
    configurable: !0,
    enumerable: !0,
    value: t,
    writable: !0
  }) : n[r] = t;
}
var ht = Object.prototype.hasOwnProperty;
function H(n, r, t) {
  var e = n[r];
  (!(ht.call(n, r) && W(e, t)) || t === void 0 && !(r in n)) && Z(n, r, t);
}
function S(n, r, t, e) {
  var o = !t;
  t || (t = {});
  for (var i = -1, a = r.length; ++i < a; ) {
    var u = r[i], c = void 0;
    c === void 0 && (c = n[u]), o ? Z(t, u, c) : H(t, u, c);
  }
  return t;
}
function L(n, r, t) {
  if (!j(t)) return !1;
  var e = typeof r;
  return (e == "number" ? D(t) && Qn(r, t.length) : e == "string" && r in t) ? W(t[r], n) : !1;
}
function lt(n) {
  return vn(function(r, t) {
    var e = -1, o = t.length, i = o > 1 ? t[o - 1] : void 0, a = o > 2 ? t[2] : void 0;
    for (i = n.length > 3 && typeof i == "function" ? (o--, i) : void 0, a && L(t[0], t[1], a) && (i = o < 3 ? void 0 : i, o = 1), r = Object(r); ++e < o; ) {
      var u = t[e];
      u && n(r, u, e, i);
    }
    return r;
  });
}
function gt(n) {
  var r = [];
  if (n != null) for (var t in Object(n)) r.push(t);
  return r;
}
var pt = Object.prototype.hasOwnProperty;
function bt(n) {
  if (!j(n)) return gt(n);
  var r = Kn(n), t = [];
  for (var e in n) e == "constructor" && (r || !pt.call(n, e)) || t.push(e);
  return t;
}
function E(n) {
  return D(n) ? Ur(n, !0) : bt(n);
}
function M(n) {
  return n != null && n.length ? Yn(n) : [];
}
function yt(n) {
  return qr(zr(n, void 0, M), n + "");
}
var ln = Tr(Object.getPrototypeOf, Object), wt = "[object Object]", mt = Function.prototype, jt = Object.prototype, ar = mt.toString, xt = jt.hasOwnProperty, kt = ar.call(Object);
function Ot(n) {
  if (!sn(n) || Kr(n) != wt) return !1;
  var r = ln(n);
  if (r === null) return !0;
  var t = xt.call(r, "constructor") && r.constructor;
  return typeof t == "function" && t instanceof t && ar.call(t) == kt;
}
function Et(n, r) {
  return n && S(r, fn(r), n);
}
function _t(n, r) {
  return n && S(r, E(r), n);
}
var ur = typeof exports == "object" && exports && !exports.nodeType && exports, Rn = ur && typeof module == "object" && module && !module.nodeType && module, Ln = Rn && Rn.exports === ur ? Br.Buffer : void 0, An = Ln ? Ln.allocUnsafe : void 0;
function cr(n, r) {
  if (r) return n.slice();
  var t = n.length, e = An ? An(t) : new n.constructor(t);
  return n.copy(e), e;
}
function $t(n, r) {
  return S(n, Xn(n), r);
}
var fr = Object.getOwnPropertySymbols ? function(n) {
  for (var r = []; n; ) Fr(r, Xn(n)), n = ln(n);
  return r;
} : Gr;
function Pt(n, r) {
  return S(n, fr(n), r);
}
function Nt(n) {
  return Wr(n, E, fr);
}
var Mt = Object.prototype.hasOwnProperty;
function Rt(n) {
  var r = n.length, t = new n.constructor(r);
  return r && typeof n[0] == "string" && Mt.call(n, "index") && (t.index = n.index, t.input = n.input), t;
}
function gn(n) {
  var r = new n.constructor(n.byteLength);
  return new En(r).set(new En(n)), r;
}
function Lt(n, r) {
  var t = r ? gn(n.buffer) : n.buffer;
  return new n.constructor(t, n.byteOffset, n.byteLength);
}
var At = /\w*$/;
function Ct(n) {
  var r = new n.constructor(n.source, At.exec(n));
  return r.lastIndex = n.lastIndex, r;
}
var Cn = On ? On.prototype : void 0, In = Cn ? Cn.valueOf : void 0;
function It(n) {
  return In ? Object(In.call(n)) : {};
}
function dr(n, r) {
  var t = r ? gn(n.buffer) : n.buffer;
  return new n.constructor(t, n.byteOffset, n.length);
}
var St = "[object Boolean]", Bt = "[object Date]", Tt = "[object Map]", Ft = "[object Number]", Gt = "[object RegExp]", Ut = "[object Set]", qt = "[object String]", zt = "[object Symbol]", Vt = "[object ArrayBuffer]", Dt = "[object DataView]", Wt = "[object Float32Array]", Jt = "[object Float64Array]", Zt = "[object Int8Array]", Ht = "[object Int16Array]", Kt = "[object Int32Array]", Xt = "[object Uint8Array]", Yt = "[object Uint8ClampedArray]", Qt = "[object Uint16Array]", ne = "[object Uint32Array]";
function re(n, r, t) {
  var e = n.constructor;
  switch (r) {
    case Vt:
      return gn(n);
    case St:
    case Bt:
      return new e(+n);
    case Dt:
      return Lt(n, t);
    case Wt:
    case Jt:
    case Zt:
    case Ht:
    case Kt:
    case Xt:
    case Yt:
    case Qt:
    case ne:
      return dr(n, t);
    case Tt:
      return new e();
    case Ft:
    case qt:
      return new e(n);
    case Gt:
      return Ct(n);
    case Ut:
      return new e();
    case zt:
      return It(n);
  }
}
function sr(n) {
  return typeof n.constructor == "function" && !Kn(n) ? vt(ln(n)) : {};
}
var te = "[object Map]";
function ee(n) {
  return sn(n) && cn(n) == te;
}
var Sn = U && U.isMap, oe = Sn ? dn(Sn) : ee, ie = "[object Set]";
function ae(n) {
  return sn(n) && cn(n) == ie;
}
var Bn = U && U.isSet, ue = Bn ? dn(Bn) : ae, ce = 1, fe = 2, de = 4, vr = "[object Arguments]", se = "[object Array]", ve = "[object Boolean]", he = "[object Date]", le = "[object Error]", hr = "[object Function]", ge = "[object GeneratorFunction]", pe = "[object Map]", be = "[object Number]", lr = "[object Object]", ye = "[object RegExp]", we = "[object Set]", me = "[object String]", je = "[object Symbol]", xe = "[object WeakMap]", ke = "[object ArrayBuffer]", Oe = "[object DataView]", Ee = "[object Float32Array]", _e = "[object Float64Array]", $e = "[object Int8Array]", Pe = "[object Int16Array]", Ne = "[object Int32Array]", Me = "[object Uint8Array]", Re = "[object Uint8ClampedArray]", Le = "[object Uint16Array]", Ae = "[object Uint32Array]", b = {};
b[vr] = b[se] = b[ke] = b[Oe] = b[ve] = b[he] = b[Ee] = b[_e] = b[$e] = b[Pe] = b[Ne] = b[pe] = b[be] = b[lr] = b[ye] = b[we] = b[me] = b[je] = b[Me] = b[Re] = b[Le] = b[Ae] = !0, b[le] = b[hr] = b[xe] = !1;
function G(n, r, t, e, o, i) {
  var a, u = r & ce, c = r & fe, f = r & de;
  if (a !== void 0) return a;
  if (!j(n)) return n;
  var d = _(n);
  if (d) {
    if (a = Rt(n), !u) return ir(n, a);
  } else {
    var v = cn(n), h = v == hr || v == ge;
    if (Zn(n)) return cr(n, u);
    if (v == lr || v == vr || h && !o) {
      if (a = c || h ? {} : sr(n), !u) return c ? Pt(n, _t(a, n)) : $t(n, Et(a, n));
    } else {
      if (!b[v]) return o ? n : {};
      a = re(n, v, u);
    }
  }
  i || (i = new Hn());
  var g = i.get(n);
  if (g) return g;
  i.set(n, a), ue(n) ? n.forEach(function(p) {
    a.add(G(p, r, t, p, n, i));
  }) : oe(n) && n.forEach(function(p, w) {
    a.set(w, G(p, r, t, w, n, i));
  });
  var l = d ? void 0 : (f ? c ? Nt : Cr : c ? E : fn)(n);
  return Ir(l || n, function(p, w) {
    l && (w = p, p = n[w]), H(a, w, G(p, r, t, w, n, i));
  }), a;
}
var Ce = 1, Ie = 4;
function Se(n) {
  return G(n, Ce | Ie);
}
var gr = Object.prototype, Be = gr.hasOwnProperty, Te = vn(function(n, r) {
  n = Object(n);
  var t = -1, e = r.length, o = e > 2 ? r[2] : void 0;
  for (o && L(r[0], r[1], o) && (e = 1); ++t < e; ) for (var i = r[t], a = E(i), u = -1, c = a.length; ++u < c; ) {
    var f = a[u], d = n[f];
    (d === void 0 || W(d, gr[f]) && !Be.call(n, f)) && (n[f] = i[f]);
  }
  return n;
});
function en(n, r, t) {
  (t !== void 0 && !W(n[r], t) || t === void 0 && !(r in n)) && Z(n, r, t);
}
function on(n, r) {
  if (!(r === "constructor" && typeof n[r] == "function") && r != "__proto__") return n[r];
}
function Fe(n) {
  return S(n, E(n));
}
function Ge(n, r, t, e, o, i, a) {
  var u = on(n, t), c = on(r, t), f = a.get(c);
  if (f) {
    en(n, t, f);
    return;
  }
  var d = i ? i(u, c, t + "", n, r, a) : void 0, v = d === void 0;
  if (v) {
    var h = _(c), g = !h && Zn(c), l = !h && !g && Jr(c);
    d = c, h || g || l ? _(u) ? d = u : Zr(u) ? d = ir(u) : g ? (v = !1, d = cr(c, !0)) : l ? (v = !1, d = dr(c, !0)) : d = [] : Ot(c) || $n(c) ? (d = u, $n(u) ? d = Fe(u) : (!j(u) || Hr(u)) && (d = sr(c))) : v = !1;
  }
  v && (a.set(c, d), o(d, c, e, i, a), a.delete(c)), en(n, t, d);
}
function pr(n, r, t, e, o) {
  n !== r && er(r, function(i, a) {
    if (o || (o = new Hn()), j(i)) Ge(n, r, a, t, pr, e, o);
    else {
      var u = e ? e(on(n, a), i, a + "", n, r, o) : void 0;
      u === void 0 && (u = i), en(n, a, u);
    }
  }, E);
}
function z(n) {
  var r = n == null ? 0 : n.length;
  return r ? n[r - 1] : void 0;
}
function Ue(n) {
  return function(r, t, e) {
    var o = Object(r);
    if (!D(r)) {
      var i = N(t);
      r = fn(r), t = function(u) {
        return i(o[u], u, o);
      };
    }
    var a = n(r, t, e);
    return a > -1 ? o[i ? r[a] : a] : void 0;
  };
}
var qe = Math.max;
function ze(n, r, t) {
  var e = n == null ? 0 : n.length;
  if (!e) return -1;
  var o = t == null ? 0 : st(t);
  return o < 0 && (o = qe(e + o, 0)), Qr(n, N(r), o);
}
var pn = Ue(ze);
function br(n, r) {
  var t = -1, e = D(n) ? Array(n.length) : [];
  return Sr(n, function(o, i, a) {
    e[++t] = r(o, i, a);
  }), e;
}
function y(n, r) {
  return (_(n) ? T : br)(n, N(r));
}
function Ve(n, r) {
  return n == null ? n : er(n, tr(r), E);
}
function De(n, r) {
  return n && rr(n, tr(r));
}
function We(n, r) {
  return n > r;
}
var Je = Object.prototype.hasOwnProperty;
function Ze(n, r) {
  return n != null && Je.call(n, r);
}
function yr(n, r) {
  return n != null && Dr(n, r, Ze);
}
function wr(n, r) {
  return n < r;
}
function K(n, r) {
  var t = {};
  return r = N(r), rr(n, function(e, o, i) {
    Z(t, o, r(e, o, i));
  }), t;
}
function bn(n, r, t) {
  for (var e = -1, o = n.length; ++e < o; ) {
    var i = n[e], a = r(i);
    if (a != null && (u === void 0 ? a === a && !q(a) : t(a, u))) var u = a, c = i;
  }
  return c;
}
function O(n) {
  return n && n.length ? bn(n, hn, We) : void 0;
}
var an = lt(function(n, r, t) {
  pr(n, r, t);
});
function A(n) {
  return n && n.length ? bn(n, hn, wr) : void 0;
}
function yn(n, r) {
  return n && n.length ? bn(n, N(r), wr) : void 0;
}
function He(n, r, t, e) {
  if (!j(n)) return n;
  r = or(r, n);
  for (var o = -1, i = r.length, a = i - 1, u = n; u != null && ++o < i; ) {
    var c = Xr(r[o]), f = t;
    if (c === "__proto__" || c === "constructor" || c === "prototype") return n;
    if (o != a) {
      var d = u[c];
      f = void 0, f === void 0 && (f = j(d) ? d : Qn(r[o + 1]) ? [] : {});
    }
    H(u, c, f), u = u[c];
  }
  return n;
}
function Ke(n, r, t) {
  for (var e = -1, o = r.length, i = {}; ++e < o; ) {
    var a = r[e], u = nr(n, a);
    t(u, a) && He(i, or(a, n), u);
  }
  return i;
}
function Xe(n, r) {
  var t = n.length;
  for (n.sort(r); t--; ) n[t] = n[t].value;
  return n;
}
function Ye(n, r) {
  if (n !== r) {
    var t = n !== void 0, e = n === null, o = n === n, i = q(n), a = r !== void 0, u = r === null, c = r === r, f = q(r);
    if (!u && !f && !i && n > r || i && a && c && !u && !f || e && a && c || !t && c || !o) return 1;
    if (!e && !i && !f && n < r || f && t && o && !e && !i || u && t && o || !a && o || !c) return -1;
  }
  return 0;
}
function Qe(n, r, t) {
  for (var e = -1, o = n.criteria, i = r.criteria, a = o.length, u = t.length; ++e < a; ) {
    var c = Ye(o[e], i[e]);
    if (c) return e >= u ? c : c * (t[e] == "desc" ? -1 : 1);
  }
  return n.index - r.index;
}
function no(n, r, t) {
  r = r.length ? T(r, function(o) {
    return _(o) ? function(i) {
      return nr(i, o.length === 1 ? o[0] : o);
    } : o;
  }) : [hn];
  var e = -1;
  return r = T(r, dn(N)), Xe(br(n, function(o, i, a) {
    return {
      criteria: T(r, function(u) {
        return u(o);
      }),
      index: ++e,
      value: o
    };
  }), function(o, i) {
    return Qe(o, i, t);
  });
}
function ro(n, r) {
  return Ke(n, r, function(t, e) {
    return Yr(n, e);
  });
}
var V = yt(function(n, r) {
  return n == null ? {} : ro(n, r);
}), to = Math.ceil, eo = Math.max;
function oo(n, r, t, e) {
  for (var o = -1, i = eo(to((r - n) / (t || 1)), 0), a = Array(i); i--; ) a[++o] = n, n += t;
  return a;
}
function io(n) {
  return function(r, t, e) {
    return e && typeof e != "number" && L(r, t, e) && (t = e = void 0), r = F(r), t === void 0 ? (t = r, r = 0) : t = F(t), e = e === void 0 ? r < t ? 1 : -1 : F(e), oo(r, t, e);
  };
}
var P = io(), B = vn(function(n, r) {
  if (n == null) return [];
  var t = r.length;
  return t > 1 && L(n, r[0], r[1]) ? r = [] : t > 2 && L(r[0], r[1], r[2]) && (r = [r[0]]), no(n, Yn(r), []);
}), ao = 0;
function wn(n) {
  var r = ++ao;
  return Vr(n) + r;
}
function uo(n, r, t) {
  for (var e = -1, o = n.length, i = r.length, a = {}; ++e < o; ) {
    var u = e < i ? r[e] : void 0;
    t(a, n[e], u);
  }
  return a;
}
function co(n, r) {
  return uo(n || [], r || [], H);
}
var fo = class {
  constructor() {
    var n = {};
    n._next = n._prev = n, this._sentinel = n;
  }
  dequeue() {
    var n = this._sentinel, r = n._prev;
    if (r !== n) return Tn(r), r;
  }
  enqueue(n) {
    var r = this._sentinel;
    n._prev && n._next && Tn(n), n._next = r._next, r._next._prev = n, r._next = n, n._prev = r;
  }
  toString() {
    for (var n = [], r = this._sentinel, t = r._prev; t !== r; ) n.push(JSON.stringify(t, so)), t = t._prev;
    return "[" + n.join(", ") + "]";
  }
};
function Tn(n) {
  n._prev._next = n._next, n._next._prev = n._prev, delete n._next, delete n._prev;
}
function so(n, r) {
  if (n !== "_next" && n !== "_prev") return r;
}
var vo = nt(1);
function ho(n, r) {
  if (n.nodeCount() <= 1) return [];
  var t = go(n, r || vo);
  return M(y(lo(t.graph, t.buckets, t.zeroIdx), function(e) {
    return n.outEdges(e.v, e.w);
  }));
}
function lo(n, r, t) {
  for (var e = [], o = r[r.length - 1], i = r[0], a; n.nodeCount(); ) {
    for (; a = i.dequeue(); ) Y(n, r, t, a);
    for (; a = o.dequeue(); ) Y(n, r, t, a);
    if (n.nodeCount()) {
      for (var u = r.length - 2; u > 0; --u) if (a = r[u].dequeue(), a) {
        e = e.concat(Y(n, r, t, a, !0));
        break;
      }
    }
  }
  return e;
}
function Y(n, r, t, e, o) {
  var i = o ? [] : void 0;
  return s(n.inEdges(e.v), function(a) {
    var u = n.edge(a), c = n.node(a.v);
    o && i.push({
      v: a.v,
      w: a.w
    }), c.out -= u, un(r, t, c);
  }), s(n.outEdges(e.v), function(a) {
    var u = n.edge(a), c = a.w, f = n.node(c);
    f.in -= u, un(r, t, f);
  }), n.removeNode(e.v), i;
}
function go(n, r) {
  var t = new x(), e = 0, o = 0;
  s(n.nodes(), function(u) {
    t.setNode(u, {
      v: u,
      in: 0,
      out: 0
    });
  }), s(n.edges(), function(u) {
    var c = t.edge(u.v, u.w) || 0, f = r(u), d = c + f;
    t.setEdge(u.v, u.w, d), o = Math.max(o, t.node(u.v).out += f), e = Math.max(e, t.node(u.w).in += f);
  });
  var i = P(o + e + 3).map(function() {
    return new fo();
  }), a = e + 1;
  return s(t.nodes(), function(u) {
    un(i, a, t.node(u));
  }), {
    graph: t,
    buckets: i,
    zeroIdx: a
  };
}
function un(n, r, t) {
  t.out ? t.in ? n[t.out - t.in + r].enqueue(t) : n[n.length - 1].enqueue(t) : n[0].enqueue(t);
}
function po(n) {
  s(n.graph().acyclicer === "greedy" ? ho(n, r(n)) : bo(n), function(t) {
    var e = n.edge(t);
    n.removeEdge(t), e.forwardName = t.name, e.reversed = !0, n.setEdge(t.w, t.v, e, wn("rev"));
  });
  function r(t) {
    return function(e) {
      return t.edge(e).weight;
    };
  }
}
function bo(n) {
  var r = [], t = {}, e = {};
  function o(i) {
    Object.prototype.hasOwnProperty.call(e, i) || (e[i] = !0, t[i] = !0, s(n.outEdges(i), function(a) {
      Object.prototype.hasOwnProperty.call(t, a.w) ? r.push(a) : o(a.w);
    }), delete t[i]);
  }
  return s(n.nodes(), o), r;
}
function yo(n) {
  s(n.edges(), function(r) {
    var t = n.edge(r);
    if (t.reversed) {
      n.removeEdge(r);
      var e = t.forwardName;
      delete t.reversed, delete t.forwardName, n.setEdge(r.w, r.v, t, e);
    }
  });
}
function R(n, r, t, e) {
  var o;
  do
    o = wn(e);
  while (n.hasNode(o));
  return t.dummy = r, n.setNode(o, t), o;
}
function wo(n) {
  var r = new x().setGraph(n.graph());
  return s(n.nodes(), function(t) {
    r.setNode(t, n.node(t));
  }), s(n.edges(), function(t) {
    var e = r.edge(t.v, t.w) || {
      weight: 0,
      minlen: 1
    }, o = n.edge(t);
    r.setEdge(t.v, t.w, {
      weight: e.weight + o.weight,
      minlen: Math.max(e.minlen, o.minlen)
    });
  }), r;
}
function mr(n) {
  var r = new x({ multigraph: n.isMultigraph() }).setGraph(n.graph());
  return s(n.nodes(), function(t) {
    n.children(t).length || r.setNode(t, n.node(t));
  }), s(n.edges(), function(t) {
    r.setEdge(t, n.edge(t));
  }), r;
}
function Fn(n, r) {
  var t = n.x, e = n.y, o = r.x - t, i = r.y - e, a = n.width / 2, u = n.height / 2;
  if (!o && !i) throw Error("Not possible to find intersection inside of the rectangle");
  var c, f;
  return Math.abs(i) * a > Math.abs(o) * u ? (i < 0 && (u = -u), c = u * o / i, f = u) : (o < 0 && (a = -a), c = a, f = a * i / o), {
    x: t + c,
    y: e + f
  };
}
function X(n) {
  var r = y(P(jr(n) + 1), function() {
    return [];
  });
  return s(n.nodes(), function(t) {
    var e = n.node(t), o = e.rank;
    m(o) || (r[o][e.order] = t);
  }), r;
}
function mo(n) {
  var r = A(y(n.nodes(), function(t) {
    return n.node(t).rank;
  }));
  s(n.nodes(), function(t) {
    var e = n.node(t);
    yr(e, "rank") && (e.rank -= r);
  });
}
function jo(n) {
  var r = A(y(n.nodes(), function(i) {
    return n.node(i).rank;
  })), t = [];
  s(n.nodes(), function(i) {
    var a = n.node(i).rank - r;
    t[a] || (t[a] = []), t[a].push(i);
  });
  var e = 0, o = n.graph().nodeRankFactor;
  s(t, function(i, a) {
    m(i) && a % o !== 0 ? --e : e && s(i, function(u) {
      n.node(u).rank += e;
    });
  });
}
function Gn(n, r, t, e) {
  var o = {
    width: 0,
    height: 0
  };
  return arguments.length >= 4 && (o.rank = t, o.order = e), R(n, "border", o, r);
}
function jr(n) {
  return O(y(n.nodes(), function(r) {
    var t = n.node(r).rank;
    if (!m(t)) return t;
  }));
}
function xo(n, r) {
  var t = {
    lhs: [],
    rhs: []
  };
  return s(n, function(e) {
    r(e) ? t.lhs.push(e) : t.rhs.push(e);
  }), t;
}
function ko(n, r) {
  return r();
}
function Oo(n) {
  function r(t) {
    var e = n.children(t), o = n.node(t);
    if (e.length && s(e, r), Object.prototype.hasOwnProperty.call(o, "minRank")) {
      o.borderLeft = [], o.borderRight = [];
      for (var i = o.minRank, a = o.maxRank + 1; i < a; ++i) Un(n, "borderLeft", "_bl", t, o, i), Un(n, "borderRight", "_br", t, o, i);
    }
  }
  s(n.children(), r);
}
function Un(n, r, t, e, o, i) {
  var a = {
    width: 0,
    height: 0,
    rank: i,
    borderType: r
  }, u = o[r][i - 1], c = R(n, "border", a, t);
  o[r][i] = c, n.setParent(c, e), u && n.setEdge(u, c, { weight: 1 });
}
function Eo(n) {
  var r = n.graph().rankdir.toLowerCase();
  (r === "lr" || r === "rl") && xr(n);
}
function _o(n) {
  var r = n.graph().rankdir.toLowerCase();
  (r === "bt" || r === "rl") && $o(n), (r === "lr" || r === "rl") && (Po(n), xr(n));
}
function xr(n) {
  s(n.nodes(), function(r) {
    qn(n.node(r));
  }), s(n.edges(), function(r) {
    qn(n.edge(r));
  });
}
function qn(n) {
  var r = n.width;
  n.width = n.height, n.height = r;
}
function $o(n) {
  s(n.nodes(), function(r) {
    Q(n.node(r));
  }), s(n.edges(), function(r) {
    var t = n.edge(r);
    s(t.points, Q), Object.prototype.hasOwnProperty.call(t, "y") && Q(t);
  });
}
function Q(n) {
  n.y = -n.y;
}
function Po(n) {
  s(n.nodes(), function(r) {
    nn(n.node(r));
  }), s(n.edges(), function(r) {
    var t = n.edge(r);
    s(t.points, nn), Object.prototype.hasOwnProperty.call(t, "x") && nn(t);
  });
}
function nn(n) {
  var r = n.x;
  n.x = n.y, n.y = r;
}
function No(n) {
  n.graph().dummyChains = [], s(n.edges(), function(r) {
    Mo(n, r);
  });
}
function Mo(n, r) {
  var t = r.v, e = n.node(t).rank, o = r.w, i = n.node(o).rank, a = r.name, u = n.edge(r), c = u.labelRank;
  if (i !== e + 1) {
    n.removeEdge(r);
    var f = void 0, d, v;
    for (v = 0, ++e; e < i; ++v, ++e) u.points = [], f = {
      width: 0,
      height: 0,
      edgeLabel: u,
      edgeObj: r,
      rank: e
    }, d = R(n, "edge", f, "_d"), e === c && (f.width = u.width, f.height = u.height, f.dummy = "edge-label", f.labelpos = u.labelpos), n.setEdge(t, d, { weight: u.weight }, a), v === 0 && n.graph().dummyChains.push(d), t = d;
    n.setEdge(t, o, { weight: u.weight }, a);
  }
}
function Ro(n) {
  s(n.graph().dummyChains, function(r) {
    var t = n.node(r), e = t.edgeLabel, o;
    for (n.setEdge(t.edgeObj, e); t.dummy; ) o = n.successors(r)[0], n.removeNode(r), e.points.push({
      x: t.x,
      y: t.y
    }), t.dummy === "edge-label" && (e.x = t.x, e.y = t.y, e.width = t.width, e.height = t.height), r = o, t = n.node(r);
  });
}
function mn(n) {
  var r = {};
  function t(e) {
    var o = n.node(e);
    if (Object.prototype.hasOwnProperty.call(r, e)) return o.rank;
    r[e] = !0;
    var i = A(y(n.outEdges(e), function(a) {
      return t(a.w) - n.edge(a).minlen;
    }));
    return (i === 1 / 0 || i == null) && (i = 0), o.rank = i;
  }
  s(n.sources(), t);
}
function C(n, r) {
  return n.node(r.w).rank - n.node(r.v).rank - n.edge(r).minlen;
}
function kr(n) {
  var r = new x({ directed: !1 }), t = n.nodes()[0], e = n.nodeCount();
  r.setNode(t, {});
  for (var o, i; Lo(r, n) < e; ) o = Ao(r, n), i = r.hasNode(o.v) ? C(n, o) : -C(n, o), Co(r, n, i);
  return r;
}
function Lo(n, r) {
  function t(e) {
    s(r.nodeEdges(e), function(o) {
      var i = o.v, a = e === i ? o.w : i;
      !n.hasNode(a) && !C(r, o) && (n.setNode(a, {}), n.setEdge(e, a, {}), t(a));
    });
  }
  return s(n.nodes(), t), n.nodeCount();
}
function Ao(n, r) {
  return yn(r.edges(), function(t) {
    if (n.hasNode(t.v) !== n.hasNode(t.w)) return C(r, t);
  });
}
function Co(n, r, t) {
  s(n.nodes(), function(e) {
    r.node(e).rank += t;
  });
}
function Io() {
}
Io.prototype = /* @__PURE__ */ Error();
function Or(n, r, t) {
  _(r) || (r = [r]);
  var e = (n.isDirected() ? n.successors : n.neighbors).bind(n), o = [], i = {};
  return s(r, function(a) {
    if (!n.hasNode(a)) throw Error("Graph does not have node: " + a);
    Er(n, a, t === "post", i, e, o);
  }), o;
}
function Er(n, r, t, e, o, i) {
  Object.prototype.hasOwnProperty.call(e, r) || (e[r] = !0, t || i.push(r), s(o(r), function(a) {
    Er(n, a, t, e, o, i);
  }), t && i.push(r));
}
function So(n, r) {
  return Or(n, r, "post");
}
function Bo(n, r) {
  return Or(n, r, "pre");
}
k.initLowLimValues = xn, k.initCutValues = jn, k.calcCutValue = _r, k.leaveEdge = Pr, k.enterEdge = Nr, k.exchangeEdges = Mr;
function k(n) {
  n = wo(n), mn(n);
  var r = kr(n);
  xn(r), jn(r, n);
  for (var t, e; t = Pr(r); ) e = Nr(r, n, t), Mr(r, n, t, e);
}
function jn(n, r) {
  var t = So(n, n.nodes());
  t = t.slice(0, t.length - 1), s(t, function(e) {
    To(n, r, e);
  });
}
function To(n, r, t) {
  var e = n.node(t).parent;
  n.edge(t, e).cutvalue = _r(n, r, t);
}
function _r(n, r, t) {
  var e = n.node(t).parent, o = !0, i = r.edge(t, e), a = 0;
  return i || (i = (o = !1, r.edge(e, t))), a = i.weight, s(r.nodeEdges(t), function(u) {
    var c = u.v === t, f = c ? u.w : u.v;
    if (f !== e) {
      var d = c === o, v = r.edge(u).weight;
      if (a += d ? v : -v, Go(n, t, f)) {
        var h = n.edge(t, f).cutvalue;
        a += d ? -h : h;
      }
    }
  }), a;
}
function xn(n, r) {
  arguments.length < 2 && (r = n.nodes()[0]), $r(n, {}, 1, r);
}
function $r(n, r, t, e, o) {
  var i = t, a = n.node(e);
  return r[e] = !0, s(n.neighbors(e), function(u) {
    Object.prototype.hasOwnProperty.call(r, u) || (t = $r(n, r, t, u, e));
  }), a.low = i, a.lim = t++, o ? a.parent = o : delete a.parent, t;
}
function Pr(n) {
  return pn(n.edges(), function(r) {
    return n.edge(r).cutvalue < 0;
  });
}
function Nr(n, r, t) {
  var e = t.v, o = t.w;
  r.hasEdge(e, o) || (e = t.w, o = t.v);
  var i = n.node(e), a = n.node(o), u = i, c = !1;
  return i.lim > a.lim && (u = a, c = !0), yn(I(r.edges(), function(f) {
    return c === zn(n, n.node(f.v), u) && c !== zn(n, n.node(f.w), u);
  }), function(f) {
    return C(r, f);
  });
}
function Mr(n, r, t, e) {
  var o = t.v, i = t.w;
  n.removeEdge(o, i), n.setEdge(e.v, e.w, {}), xn(n), jn(n, r), Fo(n, r);
}
function Fo(n, r) {
  var t = Bo(n, pn(n.nodes(), function(e) {
    return !r.node(e).parent;
  }));
  t = t.slice(1), s(t, function(e) {
    var o = n.node(e).parent, i = r.edge(e, o), a = !1;
    i || (i = r.edge(o, e), a = !0), r.node(e).rank = r.node(o).rank + (a ? i.minlen : -i.minlen);
  });
}
function Go(n, r, t) {
  return n.hasEdge(r, t);
}
function zn(n, r, t) {
  return t.low <= r.lim && r.lim <= t.lim;
}
function Uo(n) {
  switch (n.graph().ranker) {
    case "network-simplex":
      Vn(n);
      break;
    case "tight-tree":
      zo(n);
      break;
    case "longest-path":
      qo(n);
      break;
    default:
      Vn(n);
  }
}
var qo = mn;
function zo(n) {
  mn(n), kr(n);
}
function Vn(n) {
  k(n);
}
function Vo(n) {
  var r = R(n, "root", {}, "_root"), t = Do(n), e = O($(t)) - 1, o = 2 * e + 1;
  n.graph().nestingRoot = r, s(n.edges(), function(a) {
    n.edge(a).minlen *= o;
  });
  var i = Wo(n) + 1;
  s(n.children(), function(a) {
    Rr(n, r, o, i, e, t, a);
  }), n.graph().nodeRankFactor = o;
}
function Rr(n, r, t, e, o, i, a) {
  var u = n.children(a);
  if (!u.length) {
    a !== r && n.setEdge(r, a, {
      weight: 0,
      minlen: t
    });
    return;
  }
  var c = Gn(n, "_bt"), f = Gn(n, "_bb"), d = n.node(a);
  n.setParent(c, a), d.borderTop = c, n.setParent(f, a), d.borderBottom = f, s(u, function(v) {
    Rr(n, r, t, e, o, i, v);
    var h = n.node(v), g = h.borderTop ? h.borderTop : v, l = h.borderBottom ? h.borderBottom : v, p = h.borderTop ? e : 2 * e, w = g === l ? o - i[a] + 1 : 1;
    n.setEdge(c, g, {
      weight: p,
      minlen: w,
      nestingEdge: !0
    }), n.setEdge(l, f, {
      weight: p,
      minlen: w,
      nestingEdge: !0
    });
  }), n.parent(a) || n.setEdge(r, c, {
    weight: 0,
    minlen: o + i[a]
  });
}
function Do(n) {
  var r = {};
  function t(e, o) {
    var i = n.children(e);
    i && i.length && s(i, function(a) {
      t(a, o + 1);
    }), r[e] = o;
  }
  return s(n.children(), function(e) {
    t(e, 1);
  }), r;
}
function Wo(n) {
  return J(n.edges(), function(r, t) {
    return r + n.edge(t).weight;
  }, 0);
}
function Jo(n) {
  var r = n.graph();
  n.removeNode(r.nestingRoot), delete r.nestingRoot, s(n.edges(), function(t) {
    n.edge(t).nestingEdge && n.removeEdge(t);
  });
}
function Zo(n, r, t) {
  var e = {}, o;
  s(t, function(i) {
    for (var a = n.parent(i), u, c; a; ) {
      if (u = n.parent(a), u ? (c = e[u], e[u] = a) : (c = o, o = a), c && c !== a) {
        r.setEdge(c, a);
        return;
      }
      a = u;
    }
  });
}
function Ho(n, r, t) {
  var e = Ko(n), o = new x({ compound: !0 }).setGraph({ root: e }).setDefaultNodeLabel(function(i) {
    return n.node(i);
  });
  return s(n.nodes(), function(i) {
    var a = n.node(i), u = n.parent(i);
    (a.rank === r || a.minRank <= r && r <= a.maxRank) && (o.setNode(i), o.setParent(i, u || e), s(n[t](i), function(c) {
      var f = c.v === i ? c.w : c.v, d = o.edge(f, i), v = m(d) ? 0 : d.weight;
      o.setEdge(f, i, { weight: n.edge(c).weight + v });
    }), Object.prototype.hasOwnProperty.call(a, "minRank") && o.setNode(i, {
      borderLeft: a.borderLeft[r],
      borderRight: a.borderRight[r]
    }));
  }), o;
}
function Ko(n) {
  for (var r; n.hasNode(r = wn("_root")); ) ;
  return r;
}
function Xo(n, r) {
  for (var t = 0, e = 1; e < r.length; ++e) t += Yo(n, r[e - 1], r[e]);
  return t;
}
function Yo(n, r, t) {
  for (var e = co(t, y(t, function(f, d) {
    return d;
  })), o = M(y(r, function(f) {
    return B(y(n.outEdges(f), function(d) {
      return {
        pos: e[d.w],
        weight: n.edge(d).weight
      };
    }), "pos");
  })), i = 1; i < t.length; ) i <<= 1;
  var a = 2 * i - 1;
  --i;
  var u = y(Array(a), function() {
    return 0;
  }), c = 0;
  return s(o.forEach(function(f) {
    var d = f.pos + i;
    u[d] += f.weight;
    for (var v = 0; d > 0; ) d % 2 && (v += u[d + 1]), d = d - 1 >> 1, u[d] += f.weight;
    c += f.weight * v;
  })), c;
}
function Qo(n) {
  var r = {}, t = I(n.nodes(), function(i) {
    return !n.children(i).length;
  }), e = y(P(O(y(t, function(i) {
    return n.node(i).rank;
  })) + 1), function() {
    return [];
  });
  function o(i) {
    yr(r, i) || (r[i] = !0, e[n.node(i).rank].push(i), s(n.successors(i), o));
  }
  return s(B(t, function(i) {
    return n.node(i).rank;
  }), o), e;
}
function ni(n, r) {
  return y(r, function(t) {
    var e = n.inEdges(t);
    if (e.length) {
      var o = J(e, function(i, a) {
        var u = n.edge(a), c = n.node(a.v);
        return {
          sum: i.sum + u.weight * c.order,
          weight: i.weight + u.weight
        };
      }, {
        sum: 0,
        weight: 0
      });
      return {
        v: t,
        barycenter: o.sum / o.weight,
        weight: o.weight
      };
    } else return { v: t };
  });
}
function ri(n, r) {
  var t = {};
  return s(n, function(e, o) {
    var i = t[e.v] = {
      indegree: 0,
      in: [],
      out: [],
      vs: [e.v],
      i: o
    };
    m(e.barycenter) || (i.barycenter = e.barycenter, i.weight = e.weight);
  }), s(r.edges(), function(e) {
    var o = t[e.v], i = t[e.w];
    !m(o) && !m(i) && (i.indegree++, o.out.push(t[e.w]));
  }), ti(I(t, function(e) {
    return !e.indegree;
  }));
}
function ti(n) {
  var r = [];
  function t(i) {
    return function(a) {
      a.merged || (m(a.barycenter) || m(i.barycenter) || a.barycenter >= i.barycenter) && ei(i, a);
    };
  }
  function e(i) {
    return function(a) {
      a.in.push(i), --a.indegree === 0 && n.push(a);
    };
  }
  for (; n.length; ) {
    var o = n.pop();
    r.push(o), s(o.in.reverse(), t(o)), s(o.out, e(o));
  }
  return y(I(r, function(i) {
    return !i.merged;
  }), function(i) {
    return V(i, [
      "vs",
      "i",
      "barycenter",
      "weight"
    ]);
  });
}
function ei(n, r) {
  var t = 0, e = 0;
  n.weight && (t += n.barycenter * n.weight, e += n.weight), r.weight && (t += r.barycenter * r.weight, e += r.weight), n.vs = r.vs.concat(n.vs), n.barycenter = t / e, n.weight = e, n.i = Math.min(r.i, n.i), r.merged = !0;
}
function oi(n, r) {
  var t = xo(n, function(d) {
    return Object.prototype.hasOwnProperty.call(d, "barycenter");
  }), e = t.lhs, o = B(t.rhs, function(d) {
    return -d.i;
  }), i = [], a = 0, u = 0, c = 0;
  e.sort(ii(!!r)), c = Dn(i, o, c), s(e, function(d) {
    c += d.vs.length, i.push(d.vs), a += d.barycenter * d.weight, u += d.weight, c = Dn(i, o, c);
  });
  var f = { vs: M(i) };
  return u && (f.barycenter = a / u, f.weight = u), f;
}
function Dn(n, r, t) {
  for (var e; r.length && (e = z(r)).i <= t; ) r.pop(), n.push(e.vs), t++;
  return t;
}
function ii(n) {
  return function(r, t) {
    return r.barycenter < t.barycenter ? -1 : r.barycenter > t.barycenter ? 1 : n ? t.i - r.i : r.i - t.i;
  };
}
function Lr(n, r, t, e) {
  var o = n.children(r), i = n.node(r), a = i ? i.borderLeft : void 0, u = i ? i.borderRight : void 0, c = {};
  a && (o = I(o, function(l) {
    return l !== a && l !== u;
  }));
  var f = ni(n, o);
  s(f, function(l) {
    if (n.children(l.v).length) {
      var p = Lr(n, l.v, t, e);
      c[l.v] = p, Object.prototype.hasOwnProperty.call(p, "barycenter") && ui(l, p);
    }
  });
  var d = ri(f, t);
  ai(d, c);
  var v = oi(d, e);
  if (a && (v.vs = M([
    a,
    v.vs,
    u
  ]), n.predecessors(a).length)) {
    var h = n.node(n.predecessors(a)[0]), g = n.node(n.predecessors(u)[0]);
    Object.prototype.hasOwnProperty.call(v, "barycenter") || (v.barycenter = 0, v.weight = 0), v.barycenter = (v.barycenter * v.weight + h.order + g.order) / (v.weight + 2), v.weight += 2;
  }
  return v;
}
function ai(n, r) {
  s(n, function(t) {
    t.vs = M(t.vs.map(function(e) {
      return r[e] ? r[e].vs : e;
    }));
  });
}
function ui(n, r) {
  m(n.barycenter) ? (n.barycenter = r.barycenter, n.weight = r.weight) : (n.barycenter = (n.barycenter * n.weight + r.barycenter * r.weight) / (n.weight + r.weight), n.weight += r.weight);
}
function ci(n) {
  var r = jr(n), t = Wn(n, P(1, r + 1), "inEdges"), e = Wn(n, P(r - 1, -1, -1), "outEdges"), o = Qo(n);
  Jn(n, o);
  for (var i = 1 / 0, a, u = 0, c = 0; c < 4; ++u, ++c) {
    fi(u % 2 ? t : e, u % 4 >= 2), o = X(n);
    var f = Xo(n, o);
    f < i && (c = 0, a = Se(o), i = f);
  }
  Jn(n, a);
}
function Wn(n, r, t) {
  return y(r, function(e) {
    return Ho(n, e, t);
  });
}
function fi(n, r) {
  var t = new x();
  s(n, function(e) {
    var o = e.graph().root, i = Lr(e, o, t, r);
    s(i.vs, function(a, u) {
      e.node(a).order = u;
    }), Zo(e, t, i.vs);
  });
}
function Jn(n, r) {
  s(r, function(t) {
    s(t, function(e, o) {
      n.node(e).order = o;
    });
  });
}
function di(n) {
  var r = vi(n);
  s(n.graph().dummyChains, function(t) {
    for (var e = n.node(t), o = e.edgeObj, i = si(n, r, o.v, o.w), a = i.path, u = i.lca, c = 0, f = a[c], d = !0; t !== o.w; ) {
      if (e = n.node(t), d) {
        for (; (f = a[c]) !== u && n.node(f).maxRank < e.rank; ) c++;
        f === u && (d = !1);
      }
      if (!d) {
        for (; c < a.length - 1 && n.node(f = a[c + 1]).minRank <= e.rank; ) c++;
        f = a[c];
      }
      n.setParent(t, f), t = n.successors(t)[0];
    }
  });
}
function si(n, r, t, e) {
  var o = [], i = [], a = Math.min(r[t].low, r[e].low), u = Math.max(r[t].lim, r[e].lim), c = t, f;
  do
    c = n.parent(c), o.push(c);
  while (c && (r[c].low > a || u > r[c].lim));
  for (f = c, c = e; (c = n.parent(c)) !== f; ) i.push(c);
  return {
    path: o.concat(i.reverse()),
    lca: f
  };
}
function vi(n) {
  var r = {}, t = 0;
  function e(o) {
    var i = t;
    s(n.children(o), e), r[o] = {
      low: i,
      lim: t++
    };
  }
  return s(n.children(), e), r;
}
function hi(n, r) {
  var t = {};
  function e(o, i) {
    var a = 0, u = 0, c = o.length, f = z(i);
    return s(i, function(d, v) {
      var h = gi(n, d), g = h ? n.node(h).order : c;
      (h || d === f) && (s(i.slice(u, v + 1), function(l) {
        s(n.predecessors(l), function(p) {
          var w = n.node(p), kn = w.order;
          (kn < a || g < kn) && !(w.dummy && n.node(l).dummy) && Ar(t, p, l);
        });
      }), u = v + 1, a = g);
    }), i;
  }
  return J(r, e), t;
}
function li(n, r) {
  var t = {};
  function e(i, a, u, c, f) {
    var d;
    s(P(a, u), function(v) {
      d = i[v], n.node(d).dummy && s(n.predecessors(d), function(h) {
        var g = n.node(h);
        g.dummy && (g.order < c || g.order > f) && Ar(t, h, d);
      });
    });
  }
  function o(i, a) {
    var u = -1, c, f = 0;
    return s(a, function(d, v) {
      if (n.node(d).dummy === "border") {
        var h = n.predecessors(d);
        h.length && (c = n.node(h[0]).order, e(a, f, v, u, c), f = v, u = c);
      }
      e(a, f, a.length, c, i.length);
    }), a;
  }
  return J(r, o), t;
}
function gi(n, r) {
  if (n.node(r).dummy) return pn(n.predecessors(r), function(t) {
    return n.node(t).dummy;
  });
}
function Ar(n, r, t) {
  if (r > t) {
    var e = r;
    r = t, t = e;
  }
  Object.prototype.hasOwnProperty.call(n, r) || Object.defineProperty(n, r, {
    enumerable: !0,
    configurable: !0,
    value: {},
    writable: !0
  });
  var o = n[r];
  Object.defineProperty(o, t, {
    enumerable: !0,
    configurable: !0,
    value: !0,
    writable: !0
  });
}
function pi(n, r, t) {
  if (r > t) {
    var e = r;
    r = t, t = e;
  }
  return !!n[r] && Object.prototype.hasOwnProperty.call(n[r], t);
}
function bi(n, r, t, e) {
  var o = {}, i = {}, a = {};
  return s(r, function(u) {
    s(u, function(c, f) {
      o[c] = c, i[c] = c, a[c] = f;
    });
  }), s(r, function(u) {
    var c = -1;
    s(u, function(f) {
      var d = e(f);
      if (d.length) {
        d = B(d, function(p) {
          return a[p];
        });
        for (var v = (d.length - 1) / 2, h = Math.floor(v), g = Math.ceil(v); h <= g; ++h) {
          var l = d[h];
          i[f] === f && c < a[l] && !pi(t, f, l) && (i[l] = f, i[f] = o[f] = o[l], c = a[l]);
        }
      }
    });
  }), {
    root: o,
    align: i
  };
}
function yi(n, r, t, e, o) {
  var i = {}, a = wi(n, r, t, o), u = o ? "borderLeft" : "borderRight";
  function c(v, h) {
    for (var g = a.nodes(), l = g.pop(), p = {}; l; ) p[l] ? v(l) : (p[l] = !0, g.push(l), g = g.concat(h(l))), l = g.pop();
  }
  function f(v) {
    i[v] = a.inEdges(v).reduce(function(h, g) {
      return Math.max(h, i[g.v] + a.edge(g));
    }, 0);
  }
  function d(v) {
    var h = a.outEdges(v).reduce(function(l, p) {
      return Math.min(l, i[p.w] - a.edge(p));
    }, 1 / 0), g = n.node(v);
    h !== 1 / 0 && g.borderType !== u && (i[v] = Math.max(i[v], h));
  }
  return c(f, a.predecessors.bind(a)), c(d, a.successors.bind(a)), s(e, function(v) {
    i[v] = i[t[v]];
  }), i;
}
function wi(n, r, t, e) {
  var o = new x(), i = n.graph(), a = Oi(i.nodesep, i.edgesep, e);
  return s(r, function(u) {
    var c;
    s(u, function(f) {
      var d = t[f];
      if (o.setNode(d), c) {
        var v = t[c], h = o.edge(v, d);
        o.setEdge(v, d, Math.max(a(n, f, c), h || 0));
      }
      c = f;
    });
  }), o;
}
function mi(n, r) {
  return yn($(r), function(t) {
    var e = -1 / 0, o = 1 / 0;
    return Ve(t, function(i, a) {
      var u = Ei(n, a) / 2;
      e = Math.max(i + u, e), o = Math.min(i - u, o);
    }), e - o;
  });
}
function ji(n, r) {
  var t = $(r), e = A(t), o = O(t);
  s(["u", "d"], function(i) {
    s(["l", "r"], function(a) {
      var u = i + a, c = n[u], f;
      if (c !== r) {
        var d = $(c);
        f = a === "l" ? e - A(d) : o - O(d), f && (n[u] = K(c, function(v) {
          return v + f;
        }));
      }
    });
  });
}
function xi(n, r) {
  return K(n.ul, function(t, e) {
    if (r) return n[r.toLowerCase()][e];
    var o = B(y(n, e));
    return (o[1] + o[2]) / 2;
  });
}
function ki(n) {
  var r = X(n), t = an(hi(n, r), li(n, r)), e = {}, o;
  return s(["u", "d"], function(i) {
    o = i === "u" ? r : $(r).reverse(), s(["l", "r"], function(a) {
      a === "r" && (o = y(o, function(d) {
        return $(d).reverse();
      }));
      var u = (i === "u" ? n.predecessors : n.successors).bind(n), c = bi(n, o, t, u), f = yi(n, o, c.root, c.align, a === "r");
      a === "r" && (f = K(f, function(d) {
        return -d;
      })), e[i + a] = f;
    });
  }), ji(e, mi(n, e)), xi(e, n.graph().align);
}
function Oi(n, r, t) {
  return function(e, o, i) {
    var a = e.node(o), u = e.node(i), c = 0, f;
    if (c += a.width / 2, Object.prototype.hasOwnProperty.call(a, "labelpos")) switch (a.labelpos.toLowerCase()) {
      case "l":
        f = -a.width / 2;
        break;
      case "r":
        f = a.width / 2;
        break;
    }
    if (f && (c += t ? f : -f), f = 0, c += (a.dummy ? r : n) / 2, c += (u.dummy ? r : n) / 2, c += u.width / 2, Object.prototype.hasOwnProperty.call(u, "labelpos")) switch (u.labelpos.toLowerCase()) {
      case "l":
        f = u.width / 2;
        break;
      case "r":
        f = -u.width / 2;
        break;
    }
    return f && (c += t ? f : -f), f = 0, c;
  };
}
function Ei(n, r) {
  return n.node(r).width;
}
function _i(n) {
  n = mr(n), $i(n), De(ki(n), function(r, t) {
    n.node(t).x = r;
  });
}
function $i(n) {
  var r = X(n), t = n.graph().ranksep, e = 0;
  s(r, function(o) {
    var i = O(y(o, function(a) {
      return n.node(a).height;
    }));
    s(o, function(a) {
      n.node(a).y = e + i / 2;
    }), e += i + t;
  });
}
function Yi(n, r) {
  var t = ko;
  t("layout", () => {
    var e = t("  buildLayoutGraph", () => Ti(n));
    t("  runLayout", () => Pi(e, t)), t("  updateInputGraph", () => Ni(n, e));
  });
}
function Pi(n, r) {
  r("    makeSpaceForEdgeLabels", () => Fi(n)), r("    removeSelfEdges", () => Zi(n)), r("    acyclic", () => po(n)), r("    nestingGraph.run", () => Vo(n)), r("    rank", () => Uo(mr(n))), r("    injectEdgeLabelProxies", () => Gi(n)), r("    removeEmptyRanks", () => jo(n)), r("    nestingGraph.cleanup", () => Jo(n)), r("    normalizeRanks", () => mo(n)), r("    assignRankMinMax", () => Ui(n)), r("    removeEdgeLabelProxies", () => qi(n)), r("    normalize.run", () => No(n)), r("    parentDummyChains", () => di(n)), r("    addBorderSegments", () => Oo(n)), r("    order", () => ci(n)), r("    insertSelfEdges", () => Hi(n)), r("    adjustCoordinateSystem", () => Eo(n)), r("    position", () => _i(n)), r("    positionSelfEdges", () => Ki(n)), r("    removeBorderNodes", () => Ji(n)), r("    normalize.undo", () => Ro(n)), r("    fixupEdgeLabelCoords", () => Di(n)), r("    undoCoordinateSystem", () => _o(n)), r("    translateGraph", () => zi(n)), r("    assignNodeIntersects", () => Vi(n)), r("    reversePoints", () => Wi(n)), r("    acyclic.undo", () => yo(n));
}
function Ni(n, r) {
  s(n.nodes(), function(t) {
    var e = n.node(t), o = r.node(t);
    e && (e.x = o.x, e.y = o.y, r.children(t).length && (e.width = o.width, e.height = o.height));
  }), s(n.edges(), function(t) {
    var e = n.edge(t), o = r.edge(t);
    e.points = o.points, Object.prototype.hasOwnProperty.call(o, "x") && (e.x = o.x, e.y = o.y);
  }), n.graph().width = r.graph().width, n.graph().height = r.graph().height;
}
var Mi = [
  "nodesep",
  "edgesep",
  "ranksep",
  "marginx",
  "marginy"
], Ri = {
  ranksep: 50,
  edgesep: 20,
  nodesep: 50,
  rankdir: "tb"
}, Li = [
  "acyclicer",
  "ranker",
  "rankdir",
  "align"
], Ai = ["width", "height"], Ci = {
  width: 0,
  height: 0
}, Ii = [
  "minlen",
  "weight",
  "width",
  "height",
  "labeloffset"
], Si = {
  minlen: 1,
  weight: 1,
  width: 0,
  height: 0,
  labeloffset: 10,
  labelpos: "r"
}, Bi = ["labelpos"];
function Ti(n) {
  var r = new x({
    multigraph: !0,
    compound: !0
  }), t = tn(n.graph());
  return r.setGraph(an({}, Ri, rn(t, Mi), V(t, Li))), s(n.nodes(), function(e) {
    var o = tn(n.node(e));
    r.setNode(e, Te(rn(o, Ai), Ci)), r.setParent(e, n.parent(e));
  }), s(n.edges(), function(e) {
    var o = tn(n.edge(e));
    r.setEdge(e, an({}, Si, rn(o, Ii), V(o, Bi)));
  }), r;
}
function Fi(n) {
  var r = n.graph();
  r.ranksep /= 2, s(n.edges(), function(t) {
    var e = n.edge(t);
    e.minlen *= 2, e.labelpos.toLowerCase() !== "c" && (r.rankdir === "TB" || r.rankdir === "BT" ? e.width += e.labeloffset : e.height += e.labeloffset);
  });
}
function Gi(n) {
  s(n.edges(), function(r) {
    var t = n.edge(r);
    if (t.width && t.height) {
      var e = n.node(r.v);
      R(n, "edge-proxy", {
        rank: (n.node(r.w).rank - e.rank) / 2 + e.rank,
        e: r
      }, "_ep");
    }
  });
}
function Ui(n) {
  var r = 0;
  s(n.nodes(), function(t) {
    var e = n.node(t);
    e.borderTop && (e.minRank = n.node(e.borderTop).rank, e.maxRank = n.node(e.borderBottom).rank, r = O(r, e.maxRank));
  }), n.graph().maxRank = r;
}
function qi(n) {
  s(n.nodes(), function(r) {
    var t = n.node(r);
    t.dummy === "edge-proxy" && (n.edge(t.e).labelRank = t.rank, n.removeNode(r));
  });
}
function zi(n) {
  var r = 1 / 0, t = 0, e = 1 / 0, o = 0, i = n.graph(), a = i.marginx || 0, u = i.marginy || 0;
  function c(f) {
    var d = f.x, v = f.y, h = f.width, g = f.height;
    r = Math.min(r, d - h / 2), t = Math.max(t, d + h / 2), e = Math.min(e, v - g / 2), o = Math.max(o, v + g / 2);
  }
  s(n.nodes(), function(f) {
    c(n.node(f));
  }), s(n.edges(), function(f) {
    var d = n.edge(f);
    Object.prototype.hasOwnProperty.call(d, "x") && c(d);
  }), r -= a, e -= u, s(n.nodes(), function(f) {
    var d = n.node(f);
    d.x -= r, d.y -= e;
  }), s(n.edges(), function(f) {
    var d = n.edge(f);
    s(d.points, function(v) {
      v.x -= r, v.y -= e;
    }), Object.prototype.hasOwnProperty.call(d, "x") && (d.x -= r), Object.prototype.hasOwnProperty.call(d, "y") && (d.y -= e);
  }), i.width = t - r + a, i.height = o - e + u;
}
function Vi(n) {
  s(n.edges(), function(r) {
    var t = n.edge(r), e = n.node(r.v), o = n.node(r.w), i, a;
    t.points ? (i = t.points[0], a = t.points[t.points.length - 1]) : (t.points = [], i = o, a = e), t.points.unshift(Fn(e, i)), t.points.push(Fn(o, a));
  });
}
function Di(n) {
  s(n.edges(), function(r) {
    var t = n.edge(r);
    if (Object.prototype.hasOwnProperty.call(t, "x")) switch ((t.labelpos === "l" || t.labelpos === "r") && (t.width -= t.labeloffset), t.labelpos) {
      case "l":
        t.x -= t.width / 2 + t.labeloffset;
        break;
      case "r":
        t.x += t.width / 2 + t.labeloffset;
        break;
    }
  });
}
function Wi(n) {
  s(n.edges(), function(r) {
    var t = n.edge(r);
    t.reversed && t.points.reverse();
  });
}
function Ji(n) {
  s(n.nodes(), function(r) {
    if (n.children(r).length) {
      var t = n.node(r), e = n.node(t.borderTop), o = n.node(t.borderBottom), i = n.node(z(t.borderLeft)), a = n.node(z(t.borderRight));
      t.width = Math.abs(a.x - i.x), t.height = Math.abs(o.y - e.y), t.x = i.x + t.width / 2, t.y = e.y + t.height / 2;
    }
  }), s(n.nodes(), function(r) {
    n.node(r).dummy === "border" && n.removeNode(r);
  });
}
function Zi(n) {
  s(n.edges(), function(r) {
    if (r.v === r.w) {
      var t = n.node(r.v);
      t.selfEdges || (t.selfEdges = []), t.selfEdges.push({
        e: r,
        label: n.edge(r)
      }), n.removeEdge(r);
    }
  });
}
function Hi(n) {
  s(X(n), function(r) {
    var t = 0;
    s(r, function(e, o) {
      var i = n.node(e);
      i.order = o + t, s(i.selfEdges, function(a) {
        R(n, "selfedge", {
          width: a.label.width,
          height: a.label.height,
          rank: i.rank,
          order: o + ++t,
          e: a.e,
          label: a.label
        }, "_se");
      }), delete i.selfEdges;
    });
  });
}
function Ki(n) {
  s(n.nodes(), function(r) {
    var t = n.node(r);
    if (t.dummy === "selfedge") {
      var e = n.node(t.e.v), o = e.x + e.width / 2, i = e.y, a = t.x - o, u = e.height / 2;
      n.setEdge(t.e, t.label), n.removeNode(r), t.label.points = [
        {
          x: o + 2 * a / 3,
          y: i - u
        },
        {
          x: o + 5 * a / 6,
          y: i - u
        },
        {
          x: o + a,
          y: i
        },
        {
          x: o + 5 * a / 6,
          y: i + u
        },
        {
          x: o + 2 * a / 3,
          y: i + u
        }
      ], t.label.x = t.x, t.label.y = t.y;
    }
  });
}
function rn(n, r) {
  return K(V(n, r), Number);
}
function tn(n) {
  var r = {};
  return s(n, function(t, e) {
    r[e.toLowerCase()] = t;
  }), r;
}
export {
  y as V,
  G as a,
  Yi as z
};
