import * as i from "lodash-es";
import { G as w } from "./layers.BJDrjORS.js";
class ae {
  constructor() {
    var n = {};
    n._next = n._prev = n, this._sentinel = n;
  }
  dequeue() {
    var n = this._sentinel, r = n._prev;
    if (r !== n)
      return j(r), r;
  }
  enqueue(n) {
    var r = this._sentinel;
    n._prev && n._next && j(n), n._next = r._next, r._next._prev = n, r._next = n, n._prev = r;
  }
  toString() {
    for (var n = [], r = this._sentinel, a = r._prev; a !== r; )
      n.push(JSON.stringify(a, te)), a = a._prev;
    return "[" + n.join(", ") + "]";
  }
}
function j(e) {
  e._prev._next = e._next, e._next._prev = e._prev, delete e._next, delete e._prev;
}
function te(e, n) {
  if (e !== "_next" && e !== "_prev")
    return n;
}
var oe = i.constant(1);
function ie(e, n) {
  if (e.nodeCount() <= 1)
    return [];
  var r = fe(e, n || oe), a = de(r.graph, r.buckets, r.zeroIdx);
  return i.flatten(
    i.map(a, function(t) {
      return e.outEdges(t.v, t.w);
    })
  );
}
function de(e, n, r) {
  for (var a = [], t = n[n.length - 1], d = n[0], o; e.nodeCount(); ) {
    for (; o = d.dequeue(); )
      x(e, n, r, o);
    for (; o = t.dequeue(); )
      x(e, n, r, o);
    if (e.nodeCount()) {
      for (var f = n.length - 2; f > 0; --f)
        if (o = n[f].dequeue(), o) {
          a = a.concat(x(e, n, r, o, !0));
          break;
        }
    }
  }
  return a;
}
function x(e, n, r, a, t) {
  var d = t ? [] : void 0;
  return i.forEach(e.inEdges(a.v), function(o) {
    var f = e.edge(o), u = e.node(o.v);
    t && d.push({ v: o.v, w: o.w }), u.out -= f, P(n, r, u);
  }), i.forEach(e.outEdges(a.v), function(o) {
    var f = e.edge(o), u = o.w, c = e.node(u);
    c.in -= f, P(n, r, c);
  }), e.removeNode(a.v), d;
}
function fe(e, n) {
  var r = new w(), a = 0, t = 0;
  i.forEach(e.nodes(), function(f) {
    r.setNode(f, { v: f, in: 0, out: 0 });
  }), i.forEach(e.edges(), function(f) {
    var u = r.edge(f.v, f.w) || 0, c = n(f), s = u + c;
    r.setEdge(f.v, f.w, s), t = Math.max(t, r.node(f.v).out += c), a = Math.max(a, r.node(f.w).in += c);
  });
  var d = i.range(t + a + 3).map(function() {
    return new ae();
  }), o = a + 1;
  return i.forEach(r.nodes(), function(f) {
    P(d, o, r.node(f));
  }), { graph: r, buckets: d, zeroIdx: o };
}
function P(e, n, r) {
  r.out ? r.in ? e[r.out - r.in + n].enqueue(r) : e[e.length - 1].enqueue(r) : e[0].enqueue(r);
}
function ue(e) {
  var n = e.graph().acyclicer === "greedy" ? ie(e, r(e)) : ce(e);
  i.forEach(n, function(a) {
    var t = e.edge(a);
    e.removeEdge(a), t.forwardName = a.name, t.reversed = !0, e.setEdge(a.w, a.v, t, i.uniqueId("rev"));
  });
  function r(a) {
    return function(t) {
      return a.edge(t).weight;
    };
  }
}
function ce(e) {
  var n = [], r = {}, a = {};
  function t(d) {
    Object.prototype.hasOwnProperty.call(a, d) || (a[d] = !0, r[d] = !0, i.forEach(e.outEdges(d), function(o) {
      Object.prototype.hasOwnProperty.call(r, o.w) ? n.push(o) : t(o.w);
    }), delete r[d]);
  }
  return i.forEach(e.nodes(), t), n;
}
function se(e) {
  i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    if (r.reversed) {
      e.removeEdge(n);
      var a = r.forwardName;
      delete r.reversed, delete r.forwardName, e.setEdge(n.w, n.v, r, a);
    }
  });
}
function E(e, n, r, a) {
  var t;
  do
    t = i.uniqueId(a);
  while (e.hasNode(t));
  return r.dummy = n, e.setNode(t, r), t;
}
function he(e) {
  var n = new w().setGraph(e.graph());
  return i.forEach(e.nodes(), function(r) {
    n.setNode(r, e.node(r));
  }), i.forEach(e.edges(), function(r) {
    var a = n.edge(r.v, r.w) || { weight: 0, minlen: 1 }, t = e.edge(r);
    n.setEdge(r.v, r.w, {
      weight: a.weight + t.weight,
      minlen: Math.max(a.minlen, t.minlen)
    });
  }), n;
}
function U(e) {
  var n = new w({ multigraph: e.isMultigraph() }).setGraph(e.graph());
  return i.forEach(e.nodes(), function(r) {
    e.children(r).length || n.setNode(r, e.node(r));
  }), i.forEach(e.edges(), function(r) {
    n.setEdge(r, e.edge(r));
  }), n;
}
function S(e, n) {
  var r = e.x, a = e.y, t = n.x - r, d = n.y - a, o = e.width / 2, f = e.height / 2;
  if (!t && !d)
    throw new Error("Not possible to find intersection inside of the rectangle");
  var u, c;
  return Math.abs(d) * o > Math.abs(t) * f ? (d < 0 && (f = -f), u = f * t / d, c = f) : (t < 0 && (o = -o), u = o, c = o * d / t), { x: r + u, y: a + c };
}
function k(e) {
  var n = i.map(i.range(q(e) + 1), function() {
    return [];
  });
  return i.forEach(e.nodes(), function(r) {
    var a = e.node(r), t = a.rank;
    i.isUndefined(t) || (n[t][a.order] = r);
  }), n;
}
function le(e) {
  var n = i.min(
    i.map(e.nodes(), function(r) {
      return e.node(r).rank;
    })
  );
  i.forEach(e.nodes(), function(r) {
    var a = e.node(r);
    i.has(a, "rank") && (a.rank -= n);
  });
}
function ve(e) {
  var n = i.min(
    i.map(e.nodes(), function(d) {
      return e.node(d).rank;
    })
  ), r = [];
  i.forEach(e.nodes(), function(d) {
    var o = e.node(d).rank - n;
    r[o] || (r[o] = []), r[o].push(d);
  });
  var a = 0, t = e.graph().nodeRankFactor;
  i.forEach(r, function(d, o) {
    i.isUndefined(d) && o % t !== 0 ? --a : a && i.forEach(d, function(f) {
      e.node(f).rank += a;
    });
  });
}
function M(e, n, r, a) {
  var t = {
    width: 0,
    height: 0
  };
  return arguments.length >= 4 && (t.rank = r, t.order = a), E(e, "border", t, n);
}
function q(e) {
  return i.max(
    i.map(e.nodes(), function(n) {
      var r = e.node(n).rank;
      if (!i.isUndefined(r))
        return r;
    })
  );
}
function pe(e, n) {
  var r = { lhs: [], rhs: [] };
  return i.forEach(e, function(a) {
    n(a) ? r.lhs.push(a) : r.rhs.push(a);
  }), r;
}
function me(e, n) {
  return n();
}
function we(e) {
  function n(r) {
    var a = e.children(r), t = e.node(r);
    if (a.length && i.forEach(a, n), Object.prototype.hasOwnProperty.call(t, "minRank")) {
      t.borderLeft = [], t.borderRight = [];
      for (var d = t.minRank, o = t.maxRank + 1; d < o; ++d)
        V(e, "borderLeft", "_bl", r, t, d), V(e, "borderRight", "_br", r, t, d);
    }
  }
  i.forEach(e.children(), n);
}
function V(e, n, r, a, t, d) {
  var o = { width: 0, height: 0, rank: d, borderType: n }, f = t[n][d - 1], u = E(e, "border", o, r);
  t[n][d] = u, e.setParent(u, a), f && e.setEdge(f, u, { weight: 1 });
}
function be(e) {
  var n = e.graph().rankdir.toLowerCase();
  (n === "lr" || n === "rl") && W(e);
}
function Ee(e) {
  var n = e.graph().rankdir.toLowerCase();
  (n === "bt" || n === "rl") && ye(e), (n === "lr" || n === "rl") && (ge(e), W(e));
}
function W(e) {
  i.forEach(e.nodes(), function(n) {
    B(e.node(n));
  }), i.forEach(e.edges(), function(n) {
    B(e.edge(n));
  });
}
function B(e) {
  var n = e.width;
  e.width = e.height, e.height = n;
}
function ye(e) {
  i.forEach(e.nodes(), function(n) {
    O(e.node(n));
  }), i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    i.forEach(r.points, O), Object.prototype.hasOwnProperty.call(r, "y") && O(r);
  });
}
function O(e) {
  e.y = -e.y;
}
function ge(e) {
  i.forEach(e.nodes(), function(n) {
    N(e.node(n));
  }), i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    i.forEach(r.points, N), Object.prototype.hasOwnProperty.call(r, "x") && N(r);
  });
}
function N(e) {
  var n = e.x;
  e.x = e.y, e.y = n;
}
function ke(e) {
  e.graph().dummyChains = [], i.forEach(e.edges(), function(n) {
    xe(e, n);
  });
}
function xe(e, n) {
  var r = n.v, a = e.node(r).rank, t = n.w, d = e.node(t).rank, o = n.name, f = e.edge(n), u = f.labelRank;
  if (d !== a + 1) {
    e.removeEdge(n);
    var c = void 0, s, h;
    for (h = 0, ++a; a < d; ++h, ++a)
      f.points = [], c = {
        width: 0,
        height: 0,
        edgeLabel: f,
        edgeObj: n,
        rank: a
      }, s = E(e, "edge", c, "_d"), a === u && (c.width = f.width, c.height = f.height, c.dummy = "edge-label", c.labelpos = f.labelpos), e.setEdge(r, s, { weight: f.weight }, o), h === 0 && e.graph().dummyChains.push(s), r = s;
    e.setEdge(r, t, { weight: f.weight }, o);
  }
}
function Oe(e) {
  i.forEach(e.graph().dummyChains, function(n) {
    var r = e.node(n), a = r.edgeLabel, t;
    for (e.setEdge(r.edgeObj, a); r.dummy; )
      t = e.successors(n)[0], e.removeNode(n), a.points.push({ x: r.x, y: r.y }), r.dummy === "edge-label" && (a.x = r.x, a.y = r.y, a.width = r.width, a.height = r.height), n = t, r = e.node(n);
  });
}
function _(e) {
  var n = {};
  function r(a) {
    var t = e.node(a);
    if (Object.prototype.hasOwnProperty.call(n, a))
      return t.rank;
    n[a] = !0;
    var d = i.min(
      i.map(e.outEdges(a), function(o) {
        return r(o.w) - e.edge(o).minlen;
      })
    );
    return (d === Number.POSITIVE_INFINITY || // return value of _.map([]) for Lodash 3
    d === void 0 || // return value of _.map([]) for Lodash 4
    d === null) && (d = 0), t.rank = d;
  }
  i.forEach(e.sources(), r);
}
function g(e, n) {
  return e.node(n.w).rank - e.node(n.v).rank - e.edge(n).minlen;
}
function $(e) {
  var n = new w({ directed: !1 }), r = e.nodes()[0], a = e.nodeCount();
  n.setNode(r, {});
  for (var t, d; Ne(n, e) < a; )
    t = Le(n, e), d = n.hasNode(t.v) ? g(e, t) : -g(e, t), Ie(n, e, d);
  return n;
}
function Ne(e, n) {
  function r(a) {
    i.forEach(n.nodeEdges(a), function(t) {
      var d = t.v, o = a === d ? t.w : d;
      !e.hasNode(o) && !g(n, t) && (e.setNode(o, {}), e.setEdge(a, o, {}), r(o));
    });
  }
  return i.forEach(e.nodes(), r), e.nodeCount();
}
function Le(e, n) {
  return i.minBy(n.edges(), function(r) {
    if (e.hasNode(r.v) !== e.hasNode(r.w))
      return g(n, r);
  });
}
function Ie(e, n, r) {
  i.forEach(e.nodes(), function(a) {
    n.node(a).rank += r;
  });
}
i.constant(1);
i.constant(1);
function Pe() {
}
Pe.prototype = new Error();
function z(e, n, r) {
  i.isArray(n) || (n = [n]);
  var a = (e.isDirected() ? e.successors : e.neighbors).bind(e), t = [], d = {};
  return i.each(n, function(o) {
    if (!e.hasNode(o))
      throw new Error("Graph does not have node: " + o);
    X(e, o, r === "post", d, a, t);
  }), t;
}
function X(e, n, r, a, t, d) {
  Object.prototype.hasOwnProperty.call(a, n) || (a[n] = !0, r || d.push(n), i.each(t(n), function(o) {
    X(e, o, r, a, t, d);
  }), r && d.push(n));
}
function _e(e, n) {
  return z(e, n, "post");
}
function Re(e, n) {
  return z(e, n, "pre");
}
b.initLowLimValues = C;
b.initCutValues = R;
b.calcCutValue = H;
b.leaveEdge = K;
b.enterEdge = Q;
b.exchangeEdges = Z;
function b(e) {
  e = he(e), _(e);
  var n = $(e);
  C(n), R(n, e);
  for (var r, a; r = K(n); )
    a = Q(n, e, r), Z(n, e, r, a);
}
function R(e, n) {
  var r = _e(e, e.nodes());
  r = r.slice(0, r.length - 1), i.forEach(r, function(a) {
    Ce(e, n, a);
  });
}
function Ce(e, n, r) {
  var a = e.node(r), t = a.parent;
  e.edge(r, t).cutvalue = H(e, n, r);
}
function H(e, n, r) {
  var a = e.node(r), t = a.parent, d = !0, o = n.edge(r, t), f = 0;
  return o || (d = !1, o = n.edge(t, r)), f = o.weight, i.forEach(n.nodeEdges(r), function(u) {
    var c = u.v === r, s = c ? u.w : u.v;
    if (s !== t) {
      var h = c === d, l = n.edge(u).weight;
      if (f += h ? l : -l, je(e, r, s)) {
        var v = e.edge(r, s).cutvalue;
        f += h ? -v : v;
      }
    }
  }), f;
}
function C(e, n) {
  arguments.length < 2 && (n = e.nodes()[0]), J(e, {}, 1, n);
}
function J(e, n, r, a, t) {
  var d = r, o = e.node(a);
  return n[a] = !0, i.forEach(e.neighbors(a), function(f) {
    Object.prototype.hasOwnProperty.call(n, f) || (r = J(e, n, r, f, a));
  }), o.low = d, o.lim = r++, t ? o.parent = t : delete o.parent, r;
}
function K(e) {
  return i.find(e.edges(), function(n) {
    return e.edge(n).cutvalue < 0;
  });
}
function Q(e, n, r) {
  var a = r.v, t = r.w;
  n.hasEdge(a, t) || (a = r.w, t = r.v);
  var d = e.node(a), o = e.node(t), f = d, u = !1;
  d.lim > o.lim && (f = o, u = !0);
  var c = i.filter(n.edges(), function(s) {
    return u === F(e, e.node(s.v), f) && u !== F(e, e.node(s.w), f);
  });
  return i.minBy(c, function(s) {
    return g(n, s);
  });
}
function Z(e, n, r, a) {
  var t = r.v, d = r.w;
  e.removeEdge(t, d), e.setEdge(a.v, a.w, {}), C(e), R(e, n), Te(e, n);
}
function Te(e, n) {
  var r = i.find(e.nodes(), function(t) {
    return !n.node(t).parent;
  }), a = Re(e, r);
  a = a.slice(1), i.forEach(a, function(t) {
    var d = e.node(t).parent, o = n.edge(t, d), f = !1;
    o || (o = n.edge(d, t), f = !0), n.node(t).rank = n.node(d).rank + (f ? o.minlen : -o.minlen);
  });
}
function je(e, n, r) {
  return e.hasEdge(n, r);
}
function F(e, n, r) {
  return r.low <= n.lim && n.lim <= r.lim;
}
function Se(e) {
  switch (e.graph().ranker) {
    case "network-simplex":
      A(e);
      break;
    case "tight-tree":
      Ve(e);
      break;
    case "longest-path":
      Me(e);
      break;
    default:
      A(e);
  }
}
var Me = _;
function Ve(e) {
  _(e), $(e);
}
function A(e) {
  b(e);
}
function Be(e) {
  var n = E(e, "root", {}, "_root"), r = Fe(e), a = i.max(i.values(r)) - 1, t = 2 * a + 1;
  e.graph().nestingRoot = n, i.forEach(e.edges(), function(o) {
    e.edge(o).minlen *= t;
  });
  var d = Ae(e) + 1;
  i.forEach(e.children(), function(o) {
    ee(e, n, t, d, a, r, o);
  }), e.graph().nodeRankFactor = t;
}
function ee(e, n, r, a, t, d, o) {
  var f = e.children(o);
  if (!f.length) {
    o !== n && e.setEdge(n, o, { weight: 0, minlen: r });
    return;
  }
  var u = M(e, "_bt"), c = M(e, "_bb"), s = e.node(o);
  e.setParent(u, o), s.borderTop = u, e.setParent(c, o), s.borderBottom = c, i.forEach(f, function(h) {
    ee(e, n, r, a, t, d, h);
    var l = e.node(h), v = l.borderTop ? l.borderTop : h, p = l.borderBottom ? l.borderBottom : h, m = l.borderTop ? a : 2 * a, y = v !== p ? 1 : t - d[o] + 1;
    e.setEdge(u, v, {
      weight: m,
      minlen: y,
      nestingEdge: !0
    }), e.setEdge(p, c, {
      weight: m,
      minlen: y,
      nestingEdge: !0
    });
  }), e.parent(o) || e.setEdge(n, u, { weight: 0, minlen: t + d[o] });
}
function Fe(e) {
  var n = {};
  function r(a, t) {
    var d = e.children(a);
    d && d.length && i.forEach(d, function(o) {
      r(o, t + 1);
    }), n[a] = t;
  }
  return i.forEach(e.children(), function(a) {
    r(a, 1);
  }), n;
}
function Ae(e) {
  return i.reduce(
    e.edges(),
    function(n, r) {
      return n + e.edge(r).weight;
    },
    0
  );
}
function Ye(e) {
  var n = e.graph();
  e.removeNode(n.nestingRoot), delete n.nestingRoot, i.forEach(e.edges(), function(r) {
    var a = e.edge(r);
    a.nestingEdge && e.removeEdge(r);
  });
}
function De(e, n, r) {
  var a = {}, t;
  i.forEach(r, function(d) {
    for (var o = e.parent(d), f, u; o; ) {
      if (f = e.parent(o), f ? (u = a[f], a[f] = o) : (u = t, t = o), u && u !== o) {
        n.setEdge(u, o);
        return;
      }
      o = f;
    }
  });
}
function Ge(e, n, r) {
  var a = Ue(e), t = new w({ compound: !0 }).setGraph({ root: a }).setDefaultNodeLabel(function(d) {
    return e.node(d);
  });
  return i.forEach(e.nodes(), function(d) {
    var o = e.node(d), f = e.parent(d);
    (o.rank === n || o.minRank <= n && n <= o.maxRank) && (t.setNode(d), t.setParent(d, f || a), i.forEach(e[r](d), function(u) {
      var c = u.v === d ? u.w : u.v, s = t.edge(c, d), h = i.isUndefined(s) ? 0 : s.weight;
      t.setEdge(c, d, { weight: e.edge(u).weight + h });
    }), Object.prototype.hasOwnProperty.call(o, "minRank") && t.setNode(d, {
      borderLeft: o.borderLeft[n],
      borderRight: o.borderRight[n]
    }));
  }), t;
}
function Ue(e) {
  for (var n; e.hasNode(n = i.uniqueId("_root")); ) ;
  return n;
}
function qe(e, n) {
  for (var r = 0, a = 1; a < n.length; ++a)
    r += We(e, n[a - 1], n[a]);
  return r;
}
function We(e, n, r) {
  for (var a = i.zipObject(
    r,
    i.map(r, function(c, s) {
      return s;
    })
  ), t = i.flatten(
    i.map(n, function(c) {
      return i.sortBy(
        i.map(e.outEdges(c), function(s) {
          return { pos: a[s.w], weight: e.edge(s).weight };
        }),
        "pos"
      );
    })
  ), d = 1; d < r.length; ) d <<= 1;
  var o = 2 * d - 1;
  d -= 1;
  var f = i.map(new Array(o), function() {
    return 0;
  }), u = 0;
  return i.forEach(
    // @ts-expect-error
    t.forEach(function(c) {
      var s = c.pos + d;
      f[s] += c.weight;
      for (var h = 0; s > 0; )
        s % 2 && (h += f[s + 1]), s = s - 1 >> 1, f[s] += c.weight;
      u += c.weight * h;
    })
  ), u;
}
function $e(e) {
  var n = {}, r = i.filter(e.nodes(), function(f) {
    return !e.children(f).length;
  }), a = i.max(
    i.map(r, function(f) {
      return e.node(f).rank;
    })
  ), t = i.map(i.range(a + 1), function() {
    return [];
  });
  function d(f) {
    if (!i.has(n, f)) {
      n[f] = !0;
      var u = e.node(f);
      t[u.rank].push(f), i.forEach(e.successors(f), d);
    }
  }
  var o = i.sortBy(r, function(f) {
    return e.node(f).rank;
  });
  return i.forEach(o, d), t;
}
function ze(e, n) {
  return i.map(n, function(r) {
    var a = e.inEdges(r);
    if (a.length) {
      var t = i.reduce(
        a,
        function(d, o) {
          var f = e.edge(o), u = e.node(o.v);
          return {
            sum: d.sum + f.weight * u.order,
            weight: d.weight + f.weight
          };
        },
        { sum: 0, weight: 0 }
      );
      return {
        v: r,
        barycenter: t.sum / t.weight,
        weight: t.weight
      };
    } else
      return { v: r };
  });
}
function Xe(e, n) {
  var r = {};
  i.forEach(e, function(t, d) {
    var o = r[t.v] = {
      indegree: 0,
      in: [],
      out: [],
      vs: [t.v],
      i: d
    };
    i.isUndefined(t.barycenter) || (o.barycenter = t.barycenter, o.weight = t.weight);
  }), i.forEach(n.edges(), function(t) {
    var d = r[t.v], o = r[t.w];
    !i.isUndefined(d) && !i.isUndefined(o) && (o.indegree++, d.out.push(r[t.w]));
  });
  var a = i.filter(r, function(t) {
    return !t.indegree;
  });
  return He(a);
}
function He(e) {
  var n = [];
  function r(d) {
    return function(o) {
      o.merged || (i.isUndefined(o.barycenter) || i.isUndefined(d.barycenter) || o.barycenter >= d.barycenter) && Je(d, o);
    };
  }
  function a(d) {
    return function(o) {
      o.in.push(d), --o.indegree === 0 && e.push(o);
    };
  }
  for (; e.length; ) {
    var t = e.pop();
    n.push(t), i.forEach(t.in.reverse(), r(t)), i.forEach(t.out, a(t));
  }
  return i.map(
    i.filter(n, function(d) {
      return !d.merged;
    }),
    function(d) {
      return i.pick(d, ["vs", "i", "barycenter", "weight"]);
    }
  );
}
function Je(e, n) {
  var r = 0, a = 0;
  e.weight && (r += e.barycenter * e.weight, a += e.weight), n.weight && (r += n.barycenter * n.weight, a += n.weight), e.vs = n.vs.concat(e.vs), e.barycenter = r / a, e.weight = a, e.i = Math.min(n.i, e.i), n.merged = !0;
}
function Ke(e, n) {
  var r = pe(e, function(s) {
    return Object.prototype.hasOwnProperty.call(s, "barycenter");
  }), a = r.lhs, t = i.sortBy(r.rhs, function(s) {
    return -s.i;
  }), d = [], o = 0, f = 0, u = 0;
  a.sort(Qe(!!n)), u = Y(d, t, u), i.forEach(a, function(s) {
    u += s.vs.length, d.push(s.vs), o += s.barycenter * s.weight, f += s.weight, u = Y(d, t, u);
  });
  var c = { vs: i.flatten(d) };
  return f && (c.barycenter = o / f, c.weight = f), c;
}
function Y(e, n, r) {
  for (var a; n.length && (a = i.last(n)).i <= r; )
    n.pop(), e.push(a.vs), r++;
  return r;
}
function Qe(e) {
  return function(n, r) {
    return n.barycenter < r.barycenter ? -1 : n.barycenter > r.barycenter ? 1 : e ? r.i - n.i : n.i - r.i;
  };
}
function ne(e, n, r, a) {
  var t = e.children(n), d = e.node(n), o = d ? d.borderLeft : void 0, f = d ? d.borderRight : void 0, u = {};
  o && (t = i.filter(t, function(p) {
    return p !== o && p !== f;
  }));
  var c = ze(e, t);
  i.forEach(c, function(p) {
    if (e.children(p.v).length) {
      var m = ne(e, p.v, r, a);
      u[p.v] = m, Object.prototype.hasOwnProperty.call(m, "barycenter") && en(p, m);
    }
  });
  var s = Xe(c, r);
  Ze(s, u);
  var h = Ke(s, a);
  if (o && (h.vs = i.flatten([o, h.vs, f]), e.predecessors(o).length)) {
    var l = e.node(e.predecessors(o)[0]), v = e.node(e.predecessors(f)[0]);
    Object.prototype.hasOwnProperty.call(h, "barycenter") || (h.barycenter = 0, h.weight = 0), h.barycenter = (h.barycenter * h.weight + l.order + v.order) / (h.weight + 2), h.weight += 2;
  }
  return h;
}
function Ze(e, n) {
  i.forEach(e, function(r) {
    r.vs = i.flatten(
      r.vs.map(function(a) {
        return n[a] ? n[a].vs : a;
      })
    );
  });
}
function en(e, n) {
  i.isUndefined(e.barycenter) ? (e.barycenter = n.barycenter, e.weight = n.weight) : (e.barycenter = (e.barycenter * e.weight + n.barycenter * n.weight) / (e.weight + n.weight), e.weight += n.weight);
}
function nn(e) {
  var n = q(e), r = D(e, i.range(1, n + 1), "inEdges"), a = D(e, i.range(n - 1, -1, -1), "outEdges"), t = $e(e);
  G(e, t);
  for (var d = Number.POSITIVE_INFINITY, o, f = 0, u = 0; u < 4; ++f, ++u) {
    rn(f % 2 ? r : a, f % 4 >= 2), t = k(e);
    var c = qe(e, t);
    c < d && (u = 0, o = i.cloneDeep(t), d = c);
  }
  G(e, o);
}
function D(e, n, r) {
  return i.map(n, function(a) {
    return Ge(e, a, r);
  });
}
function rn(e, n) {
  var r = new w();
  i.forEach(e, function(a) {
    var t = a.graph().root, d = ne(a, t, r, n);
    i.forEach(d.vs, function(o, f) {
      a.node(o).order = f;
    }), De(a, r, d.vs);
  });
}
function G(e, n) {
  i.forEach(n, function(r) {
    i.forEach(r, function(a, t) {
      e.node(a).order = t;
    });
  });
}
function an(e) {
  var n = on(e);
  i.forEach(e.graph().dummyChains, function(r) {
    for (var a = e.node(r), t = a.edgeObj, d = tn(e, n, t.v, t.w), o = d.path, f = d.lca, u = 0, c = o[u], s = !0; r !== t.w; ) {
      if (a = e.node(r), s) {
        for (; (c = o[u]) !== f && e.node(c).maxRank < a.rank; )
          u++;
        c === f && (s = !1);
      }
      if (!s) {
        for (; u < o.length - 1 && e.node(c = o[u + 1]).minRank <= a.rank; )
          u++;
        c = o[u];
      }
      e.setParent(r, c), r = e.successors(r)[0];
    }
  });
}
function tn(e, n, r, a) {
  var t = [], d = [], o = Math.min(n[r].low, n[a].low), f = Math.max(n[r].lim, n[a].lim), u, c;
  u = r;
  do
    u = e.parent(u), t.push(u);
  while (u && (n[u].low > o || f > n[u].lim));
  for (c = u, u = a; (u = e.parent(u)) !== c; )
    d.push(u);
  return { path: t.concat(d.reverse()), lca: c };
}
function on(e) {
  var n = {}, r = 0;
  function a(t) {
    var d = r;
    i.forEach(e.children(t), a), n[t] = { low: d, lim: r++ };
  }
  return i.forEach(e.children(), a), n;
}
function dn(e, n) {
  var r = {};
  function a(t, d) {
    var o = 0, f = 0, u = t.length, c = i.last(d);
    return i.forEach(d, function(s, h) {
      var l = un(e, s), v = l ? e.node(l).order : u;
      (l || s === c) && (i.forEach(d.slice(f, h + 1), function(p) {
        i.forEach(e.predecessors(p), function(m) {
          var y = e.node(m), T = y.order;
          (T < o || v < T) && !(y.dummy && e.node(p).dummy) && re(r, m, p);
        });
      }), f = h + 1, o = v);
    }), d;
  }
  return i.reduce(n, a), r;
}
function fn(e, n) {
  var r = {};
  function a(d, o, f, u, c) {
    var s;
    i.forEach(i.range(o, f), function(h) {
      s = d[h], e.node(s).dummy && i.forEach(e.predecessors(s), function(l) {
        var v = e.node(l);
        v.dummy && (v.order < u || v.order > c) && re(r, l, s);
      });
    });
  }
  function t(d, o) {
    var f = -1, u, c = 0;
    return i.forEach(o, function(s, h) {
      if (e.node(s).dummy === "border") {
        var l = e.predecessors(s);
        l.length && (u = e.node(l[0]).order, a(o, c, h, f, u), c = h, f = u);
      }
      a(o, c, o.length, u, d.length);
    }), o;
  }
  return i.reduce(n, t), r;
}
function un(e, n) {
  if (e.node(n).dummy)
    return i.find(e.predecessors(n), function(r) {
      return e.node(r).dummy;
    });
}
function re(e, n, r) {
  if (n > r) {
    var a = n;
    n = r, r = a;
  }
  Object.prototype.hasOwnProperty.call(e, n) || Object.defineProperty(e, n, {
    enumerable: !0,
    configurable: !0,
    value: {},
    writable: !0
  });
  var t = e[n];
  Object.defineProperty(t, r, {
    enumerable: !0,
    configurable: !0,
    value: !0,
    writable: !0
  });
}
function cn(e, n, r) {
  if (n > r) {
    var a = n;
    n = r, r = a;
  }
  return !!e[n] && Object.prototype.hasOwnProperty.call(e[n], r);
}
function sn(e, n, r, a) {
  var t = {}, d = {}, o = {};
  return i.forEach(n, function(f) {
    i.forEach(f, function(u, c) {
      t[u] = u, d[u] = u, o[u] = c;
    });
  }), i.forEach(n, function(f) {
    var u = -1;
    i.forEach(f, function(c) {
      var s = a(c);
      if (s.length) {
        s = i.sortBy(s, function(m) {
          return o[m];
        });
        for (var h = (s.length - 1) / 2, l = Math.floor(h), v = Math.ceil(h); l <= v; ++l) {
          var p = s[l];
          d[c] === c && u < o[p] && !cn(r, c, p) && (d[p] = c, d[c] = t[c] = t[p], u = o[p]);
        }
      }
    });
  }), { root: t, align: d };
}
function hn(e, n, r, a, t) {
  var d = {}, o = ln(e, n, r, t), f = t ? "borderLeft" : "borderRight";
  function u(h, l) {
    for (var v = o.nodes(), p = v.pop(), m = {}; p; )
      m[p] ? h(p) : (m[p] = !0, v.push(p), v = v.concat(l(p))), p = v.pop();
  }
  function c(h) {
    d[h] = o.inEdges(h).reduce(function(l, v) {
      return Math.max(l, d[v.v] + o.edge(v));
    }, 0);
  }
  function s(h) {
    var l = o.outEdges(h).reduce(function(p, m) {
      return Math.min(p, d[m.w] - o.edge(m));
    }, Number.POSITIVE_INFINITY), v = e.node(h);
    l !== Number.POSITIVE_INFINITY && v.borderType !== f && (d[h] = Math.max(d[h], l));
  }
  return u(c, o.predecessors.bind(o)), u(s, o.successors.bind(o)), i.forEach(a, function(h) {
    d[h] = d[r[h]];
  }), d;
}
function ln(e, n, r, a) {
  var t = new w(), d = e.graph(), o = bn(d.nodesep, d.edgesep, a);
  return i.forEach(n, function(f) {
    var u;
    i.forEach(f, function(c) {
      var s = r[c];
      if (t.setNode(s), u) {
        var h = r[u], l = t.edge(h, s);
        t.setEdge(h, s, Math.max(o(e, c, u), l || 0));
      }
      u = c;
    });
  }), t;
}
function vn(e, n) {
  return i.minBy(i.values(n), function(r) {
    var a = Number.NEGATIVE_INFINITY, t = Number.POSITIVE_INFINITY;
    return i.forIn(r, function(d, o) {
      var f = En(e, o) / 2;
      a = Math.max(d + f, a), t = Math.min(d - f, t);
    }), a - t;
  });
}
function pn(e, n) {
  var r = i.values(n), a = i.min(r), t = i.max(r);
  i.forEach(["u", "d"], function(d) {
    i.forEach(["l", "r"], function(o) {
      var f = d + o, u = e[f], c;
      if (u !== n) {
        var s = i.values(u);
        c = o === "l" ? a - i.min(s) : t - i.max(s), c && (e[f] = i.mapValues(u, function(h) {
          return h + c;
        }));
      }
    });
  });
}
function mn(e, n) {
  return i.mapValues(e.ul, function(r, a) {
    if (n)
      return e[n.toLowerCase()][a];
    var t = i.sortBy(i.map(e, a));
    return (t[1] + t[2]) / 2;
  });
}
function wn(e) {
  var n = k(e), r = i.merge(dn(e, n), fn(e, n)), a = {}, t;
  i.forEach(["u", "d"], function(o) {
    t = o === "u" ? n : i.values(n).reverse(), i.forEach(["l", "r"], function(f) {
      f === "r" && (t = i.map(t, function(h) {
        return i.values(h).reverse();
      }));
      var u = (o === "u" ? e.predecessors : e.successors).bind(e), c = sn(e, t, r, u), s = hn(e, t, c.root, c.align, f === "r");
      f === "r" && (s = i.mapValues(s, function(h) {
        return -h;
      })), a[o + f] = s;
    });
  });
  var d = vn(e, a);
  return pn(a, d), mn(a, e.graph().align);
}
function bn(e, n, r) {
  return function(a, t, d) {
    var o = a.node(t), f = a.node(d), u = 0, c;
    if (u += o.width / 2, Object.prototype.hasOwnProperty.call(o, "labelpos"))
      switch (o.labelpos.toLowerCase()) {
        case "l":
          c = -o.width / 2;
          break;
        case "r":
          c = o.width / 2;
          break;
      }
    if (c && (u += r ? c : -c), c = 0, u += (o.dummy ? n : e) / 2, u += (f.dummy ? n : e) / 2, u += f.width / 2, Object.prototype.hasOwnProperty.call(f, "labelpos"))
      switch (f.labelpos.toLowerCase()) {
        case "l":
          c = f.width / 2;
          break;
        case "r":
          c = -f.width / 2;
          break;
      }
    return c && (u += r ? c : -c), c = 0, u;
  };
}
function En(e, n) {
  return e.node(n).width;
}
function yn(e) {
  e = U(e), gn(e), i.forOwn(wn(e), function(n, r) {
    e.node(r).x = n;
  });
}
function gn(e) {
  var n = k(e), r = e.graph().ranksep, a = 0;
  i.forEach(n, function(t) {
    var d = i.max(
      i.map(t, function(o) {
        return e.node(o).height;
      })
    );
    i.forEach(t, function(o) {
      e.node(o).y = a + d / 2;
    }), a += d + r;
  });
}
function $n(e, n) {
  var r = me;
  r("layout", () => {
    var a = r("  buildLayoutGraph", () => Tn(e));
    r("  runLayout", () => kn(a, r)), r("  updateInputGraph", () => xn(e, a));
  });
}
function kn(e, n) {
  n("    makeSpaceForEdgeLabels", () => jn(e)), n("    removeSelfEdges", () => Gn(e)), n("    acyclic", () => ue(e)), n("    nestingGraph.run", () => Be(e)), n("    rank", () => Se(U(e))), n("    injectEdgeLabelProxies", () => Sn(e)), n("    removeEmptyRanks", () => ve(e)), n("    nestingGraph.cleanup", () => Ye(e)), n("    normalizeRanks", () => le(e)), n("    assignRankMinMax", () => Mn(e)), n("    removeEdgeLabelProxies", () => Vn(e)), n("    normalize.run", () => ke(e)), n("    parentDummyChains", () => an(e)), n("    addBorderSegments", () => we(e)), n("    order", () => nn(e)), n("    insertSelfEdges", () => Un(e)), n("    adjustCoordinateSystem", () => be(e)), n("    position", () => yn(e)), n("    positionSelfEdges", () => qn(e)), n("    removeBorderNodes", () => Dn(e)), n("    normalize.undo", () => Oe(e)), n("    fixupEdgeLabelCoords", () => An(e)), n("    undoCoordinateSystem", () => Ee(e)), n("    translateGraph", () => Bn(e)), n("    assignNodeIntersects", () => Fn(e)), n("    reversePoints", () => Yn(e)), n("    acyclic.undo", () => se(e));
}
function xn(e, n) {
  i.forEach(e.nodes(), function(r) {
    var a = e.node(r), t = n.node(r);
    a && (a.x = t.x, a.y = t.y, n.children(r).length && (a.width = t.width, a.height = t.height));
  }), i.forEach(e.edges(), function(r) {
    var a = e.edge(r), t = n.edge(r);
    a.points = t.points, Object.prototype.hasOwnProperty.call(t, "x") && (a.x = t.x, a.y = t.y);
  }), e.graph().width = n.graph().width, e.graph().height = n.graph().height;
}
var On = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"], Nn = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "tb" }, Ln = ["acyclicer", "ranker", "rankdir", "align"], In = ["width", "height"], Pn = { width: 0, height: 0 }, _n = ["minlen", "weight", "width", "height", "labeloffset"], Rn = {
  minlen: 1,
  weight: 1,
  width: 0,
  height: 0,
  labeloffset: 10,
  labelpos: "r"
}, Cn = ["labelpos"];
function Tn(e) {
  var n = new w({ multigraph: !0, compound: !0 }), r = I(e.graph());
  return n.setGraph(
    i.merge({}, Nn, L(r, On), i.pick(r, Ln))
  ), i.forEach(e.nodes(), function(a) {
    var t = I(e.node(a));
    n.setNode(a, i.defaults(L(t, In), Pn)), n.setParent(a, e.parent(a));
  }), i.forEach(e.edges(), function(a) {
    var t = I(e.edge(a));
    n.setEdge(
      a,
      i.merge({}, Rn, L(t, _n), i.pick(t, Cn))
    );
  }), n;
}
function jn(e) {
  var n = e.graph();
  n.ranksep /= 2, i.forEach(e.edges(), function(r) {
    var a = e.edge(r);
    a.minlen *= 2, a.labelpos.toLowerCase() !== "c" && (n.rankdir === "TB" || n.rankdir === "BT" ? a.width += a.labeloffset : a.height += a.labeloffset);
  });
}
function Sn(e) {
  i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    if (r.width && r.height) {
      var a = e.node(n.v), t = e.node(n.w), d = { rank: (t.rank - a.rank) / 2 + a.rank, e: n };
      E(e, "edge-proxy", d, "_ep");
    }
  });
}
function Mn(e) {
  var n = 0;
  i.forEach(e.nodes(), function(r) {
    var a = e.node(r);
    a.borderTop && (a.minRank = e.node(a.borderTop).rank, a.maxRank = e.node(a.borderBottom).rank, n = i.max(n, a.maxRank));
  }), e.graph().maxRank = n;
}
function Vn(e) {
  i.forEach(e.nodes(), function(n) {
    var r = e.node(n);
    r.dummy === "edge-proxy" && (e.edge(r.e).labelRank = r.rank, e.removeNode(n));
  });
}
function Bn(e) {
  var n = Number.POSITIVE_INFINITY, r = 0, a = Number.POSITIVE_INFINITY, t = 0, d = e.graph(), o = d.marginx || 0, f = d.marginy || 0;
  function u(c) {
    var s = c.x, h = c.y, l = c.width, v = c.height;
    n = Math.min(n, s - l / 2), r = Math.max(r, s + l / 2), a = Math.min(a, h - v / 2), t = Math.max(t, h + v / 2);
  }
  i.forEach(e.nodes(), function(c) {
    u(e.node(c));
  }), i.forEach(e.edges(), function(c) {
    var s = e.edge(c);
    Object.prototype.hasOwnProperty.call(s, "x") && u(s);
  }), n -= o, a -= f, i.forEach(e.nodes(), function(c) {
    var s = e.node(c);
    s.x -= n, s.y -= a;
  }), i.forEach(e.edges(), function(c) {
    var s = e.edge(c);
    i.forEach(s.points, function(h) {
      h.x -= n, h.y -= a;
    }), Object.prototype.hasOwnProperty.call(s, "x") && (s.x -= n), Object.prototype.hasOwnProperty.call(s, "y") && (s.y -= a);
  }), d.width = r - n + o, d.height = t - a + f;
}
function Fn(e) {
  i.forEach(e.edges(), function(n) {
    var r = e.edge(n), a = e.node(n.v), t = e.node(n.w), d, o;
    r.points ? (d = r.points[0], o = r.points[r.points.length - 1]) : (r.points = [], d = t, o = a), r.points.unshift(S(a, d)), r.points.push(S(t, o));
  });
}
function An(e) {
  i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    if (Object.prototype.hasOwnProperty.call(r, "x"))
      switch ((r.labelpos === "l" || r.labelpos === "r") && (r.width -= r.labeloffset), r.labelpos) {
        case "l":
          r.x -= r.width / 2 + r.labeloffset;
          break;
        case "r":
          r.x += r.width / 2 + r.labeloffset;
          break;
      }
  });
}
function Yn(e) {
  i.forEach(e.edges(), function(n) {
    var r = e.edge(n);
    r.reversed && r.points.reverse();
  });
}
function Dn(e) {
  i.forEach(e.nodes(), function(n) {
    if (e.children(n).length) {
      var r = e.node(n), a = e.node(r.borderTop), t = e.node(r.borderBottom), d = e.node(i.last(r.borderLeft)), o = e.node(i.last(r.borderRight));
      r.width = Math.abs(o.x - d.x), r.height = Math.abs(t.y - a.y), r.x = d.x + r.width / 2, r.y = a.y + r.height / 2;
    }
  }), i.forEach(e.nodes(), function(n) {
    e.node(n).dummy === "border" && e.removeNode(n);
  });
}
function Gn(e) {
  i.forEach(e.edges(), function(n) {
    if (n.v === n.w) {
      var r = e.node(n.v);
      r.selfEdges || (r.selfEdges = []), r.selfEdges.push({ e: n, label: e.edge(n) }), e.removeEdge(n);
    }
  });
}
function Un(e) {
  var n = k(e);
  i.forEach(n, function(r) {
    var a = 0;
    i.forEach(r, function(t, d) {
      var o = e.node(t);
      o.order = d + a, i.forEach(o.selfEdges, function(f) {
        E(
          e,
          "selfedge",
          {
            width: f.label.width,
            height: f.label.height,
            rank: o.rank,
            order: d + ++a,
            e: f.e,
            label: f.label
          },
          "_se"
        );
      }), delete o.selfEdges;
    });
  });
}
function qn(e) {
  i.forEach(e.nodes(), function(n) {
    var r = e.node(n);
    if (r.dummy === "selfedge") {
      var a = e.node(r.e.v), t = a.x + a.width / 2, d = a.y, o = r.x - t, f = a.height / 2;
      e.setEdge(r.e, r.label), e.removeNode(n), r.label.points = [
        { x: t + 2 * o / 3, y: d - f },
        { x: t + 5 * o / 6, y: d - f },
        { x: t + o, y: d },
        { x: t + 5 * o / 6, y: d + f },
        { x: t + 2 * o / 3, y: d + f }
      ], r.label.x = r.x, r.label.y = r.y;
    }
  });
}
function L(e, n) {
  return i.mapValues(i.pick(e, n), Number);
}
function I(e) {
  var n = {};
  return i.forEach(e, function(r, a) {
    n[a.toLowerCase()] = r;
  }), n;
}
export {
  $n as l
};
