import { s as p, l as X, g as $ } from "./transform-QfIdy88w.js";
import { G as F } from "./graph-DiZQNfv4.js";
import { u as V, r as Q, p as J, l as K } from "./index-BhhXoa2I.js";
import { o as Z, a as q } from "./merge-iQ3lovbX.js";
import { d as O } from "./_basePickBy-Lezj_ebM.js";
function tt(r) {
  if (!r.ok) throw new Error(r.status + " " + r.statusText);
  return r.text();
}
function et(r, t) {
  return fetch(r, t).then(tt);
}
function rt(r) {
  return (t, e) => et(t, e).then((a) => new DOMParser().parseFromString(a, r));
}
var at = rt("image/svg+xml");
const nt = "2.1.9-pre", $t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Graph: F,
  version: nt
}, Symbol.toStringTag, { value: "Module" }));
function G(r, t) {
  return !!r.children(t).length;
}
function W(r) {
  return _(r.v) + ":" + _(r.w) + ":" + _(r.name);
}
var it = /:/g;
function _(r) {
  return r ? String(r).replace(it, "\\:") : "";
}
function m(r, t) {
  t && r.attr("style", t);
}
function D(r, t, e) {
  t && r.attr("class", t).attr("class", e + " " + r.attr("class"));
}
function g(r, t) {
  var e = t.graph();
  if (Z(e)) {
    var a = e.transition;
    if (q(a))
      return a(r);
  }
  return r;
}
var P = {
  normal: lt,
  vee: ot,
  undirected: dt
};
function st(r) {
  P = r;
}
function lt(r, t, e, a) {
  var i = r.append("marker").attr("id", t).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), n = i.append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  m(n, e[a + "Style"]), e[a + "Class"] && n.attr("class", e[a + "Class"]);
}
function ot(r, t, e, a) {
  var i = r.append("marker").attr("id", t).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), n = i.append("path").attr("d", "M 0 0 L 10 5 L 0 10 L 4 5 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  m(n, e[a + "Style"]), e[a + "Class"] && n.attr("class", e[a + "Class"]);
}
function dt(r, t, e, a) {
  var i = r.append("marker").attr("id", t).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), n = i.append("path").attr("d", "M 0 5 L 10 5").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  m(n, e[a + "Style"]), e[a + "Class"] && n.attr("class", e[a + "Class"]);
}
function ct(r, t) {
  var e = r.append("foreignObject").attr("width", "100000"), a = e.append("xhtml:div");
  a.attr("xmlns", "http://www.w3.org/1999/xhtml");
  var i = t.label;
  switch (typeof i) {
    case "function":
      a.insert(i);
      break;
    case "object":
      a.insert(function() {
        return i;
      });
      break;
    default:
      a.html(i);
  }
  m(a, t.labelStyle), a.style("display", "inline-block"), a.style("white-space", "nowrap");
  var n = a.node();
  return e.attr("width", n.offsetWidth).attr("height", n.offsetHeight), e;
}
function ut(r, t) {
  var e = r;
  return e.node().appendChild(t.label), m(e, t.labelStyle), e;
}
function ht(r, t) {
  for (var e = r.append("text"), a = pt(t.label).split(`
`), i = 0; i < a.length; i++)
    e.append("tspan").attr("xml:space", "preserve").attr("dy", "1em").attr("x", "1").text(a[i]);
  return m(e, t.labelStyle), e;
}
function pt(r) {
  for (var t = "", e = !1, a, i = 0; i < r.length; ++i)
    if (a = r[i], e) {
      switch (a) {
        case "n":
          t += `
`;
          break;
        default:
          t += a;
      }
      e = !1;
    } else a === "\\" ? e = !0 : t += a;
  return t;
}
function C(r, t, e) {
  var a = t.label, i = r.append("g");
  t.labelType === "svg" ? ut(i, t) : typeof a != "string" || t.labelType === "html" ? ct(i, t) : ht(i, t);
  var n = i.node().getBBox(), l;
  switch (e) {
    case "top":
      l = -t.height / 2;
      break;
    case "bottom":
      l = t.height / 2 - n.height;
      break;
    default:
      l = -n.height / 2;
  }
  return i.attr("transform", "translate(" + -n.width / 2 + "," + l + ")"), i;
}
var T = function(r, t) {
  var e = t.nodes().filter(function(n) {
    return G(t, n);
  }), a = r.selectAll("g.cluster").data(e, function(n) {
    return n;
  });
  g(a.exit(), t).style("opacity", 0).remove();
  var i = a.enter().append("g").attr("class", "cluster").attr("id", function(n) {
    var l = t.node(n);
    return l.id;
  }).style("opacity", 0).each(function(n) {
    var l = t.node(n), s = p(this);
    p(this).append("rect");
    var o = s.append("g").attr("class", "label");
    C(o, l, l.clusterLabelPos);
  });
  return a = a.merge(i), a = g(a, t).style("opacity", 1), a.selectAll("rect").each(function(n) {
    var l = t.node(n), s = p(this);
    m(s, l.style);
  }), a;
};
function ft(r) {
  T = r;
}
let E = function(r, t) {
  var e = r.selectAll("g.edgeLabel").data(t.edges(), function(i) {
    return W(i);
  }).classed("update", !0);
  e.exit().remove(), e.enter().append("g").classed("edgeLabel", !0).style("opacity", 0), e = r.selectAll("g.edgeLabel"), e.each(function(i) {
    var n = p(this);
    n.select(".label").remove();
    var l = t.edge(i), s = C(n, t.edge(i), 0).classed("label", !0), o = s.node().getBBox();
    l.labelId && s.attr("id", l.labelId), Object.prototype.hasOwnProperty.call(l, "width") || (l.width = o.width), Object.prototype.hasOwnProperty.call(l, "height") || (l.height = o.height);
  });
  var a;
  return e.exit ? a = e.exit() : a = e.selectAll(null), g(a, t).style("opacity", 0).remove(), e;
};
function vt(r) {
  E = r;
}
function k(r, t) {
  return r.intersect(t);
}
const gt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  intersectNode: k
}, Symbol.toStringTag, { value: "Module" }));
var L = function(r, t, e) {
  var a = r.selectAll("g.edgePath").data(t.edges(), function(l) {
    return W(l);
  }).classed("update", !0), i = wt(a, t);
  Ot(a, t);
  var n = a.merge !== void 0 ? a.merge(i) : a;
  return g(n, t).style("opacity", 1), n.each(function(l) {
    var s = p(this), o = t.edge(l);
    o.elem = this, o.id && s.attr("id", o.id), D(
      s,
      o.class,
      (s.classed("update") ? "update " : "") + "edgePath"
    );
  }), n.selectAll("path.path").each(function(l) {
    var s = t.edge(l);
    s.arrowheadId = V("arrowhead");
    var o = p(this).attr("marker-end", function() {
      return "url(" + mt(location.href, s.arrowheadId) + ")";
    }).style("fill", "none");
    g(o, t).attr("d", function(d) {
      return bt(t, d);
    }), m(o, s.style);
  }), n.selectAll("defs *").remove(), n.selectAll("defs").each(function(l) {
    var s = t.edge(l), o = e[s.arrowhead];
    o(p(this), s.arrowheadId, s, "arrowhead");
  }), n;
};
function yt(r) {
  L = r;
}
function mt(r, t) {
  var e = r.split("#")[0];
  return e + "#" + t;
}
function bt(r, t) {
  var e = r.edge(t), a = r.node(t.v), i = r.node(t.w), n = e.points.slice(1, e.points.length - 1);
  return n.unshift(k(a, n[0])), n.push(k(i, n[n.length - 1])), z(e, n);
}
function z(r, t) {
  var e = (X || at.line)().x(function(a) {
    return a.x;
  }).y(function(a) {
    return a.y;
  });
  return (e.curve || e.interpolate)(r.curve), e(t);
}
function xt(r) {
  var t = r.getBBox(), e = r.ownerSVGElement.getScreenCTM().inverse().multiply(r.getScreenCTM()).translate(t.width / 2, t.height / 2);
  return { x: e.e, y: e.f };
}
function wt(r, t) {
  var e = r.enter().append("g").attr("class", "edgePath").style("opacity", 0);
  return e.append("path").attr("class", "path").attr("d", function(a) {
    var i = t.edge(a), n = t.node(a.v).elem, l = Q(i.points.length).map(function() {
      return xt(n);
    });
    return z(i, l);
  }), e.append("defs"), e;
}
function Ot(r, t) {
  var e = r.exit();
  g(e, t).style("opacity", 0).remove();
}
var j = function(r, t, e) {
  var a = t.nodes().filter(function(l) {
    return !G(t, l);
  }), i = r.selectAll("g.node").data(a, function(l) {
    return l;
  }).classed("update", !0);
  i.exit().remove(), i.enter().append("g").attr("class", "node").style("opacity", 0), i = r.selectAll("g.node"), i.each(function(l) {
    var s = t.node(l), o = p(this);
    D(
      o,
      s.class,
      (o.classed("update") ? "update " : "") + "node"
    ), o.select("g.label").remove();
    var d = o.append("g").attr("class", "label"), u = C(d, s), b = e[s.shape], h = J(u.node().getBBox(), "width", "height");
    s.elem = this, s.id && o.attr("id", s.id), s.labelId && d.attr("id", s.labelId), Object.prototype.hasOwnProperty.call(s, "width") && (h.width = s.width), Object.prototype.hasOwnProperty.call(s, "height") && (h.height = s.height), h.width += s.paddingLeft + s.paddingRight, h.height += s.paddingTop + s.paddingBottom, d.attr(
      "transform",
      "translate(" + (s.paddingLeft - s.paddingRight) / 2 + "," + (s.paddingTop - s.paddingBottom) / 2 + ")"
    );
    var y = p(this);
    y.select(".label-container").remove();
    var c = b(y, h, s).classed("label-container", !0);
    m(c, s.style);
    var f = c.node().getBBox();
    s.width = f.width, s.height = f.height;
  });
  var n;
  return i.exit ? n = i.exit() : n = i.selectAll(null), g(n, t).style("opacity", 0).remove(), i;
};
function St(r) {
  j = r;
}
function _t(r, t) {
  var e = r.filter(function() {
    return !p(this).classed("update");
  });
  function a(i) {
    var n = t.node(i);
    return "translate(" + n.x + "," + n.y + ")";
  }
  e.attr("transform", a), g(r, t).style("opacity", 1).attr("transform", a), g(e.selectAll("rect"), t).attr("width", function(i) {
    return t.node(i).width;
  }).attr("height", function(i) {
    return t.node(i).height;
  }).attr("x", function(i) {
    var n = t.node(i);
    return -n.width / 2;
  }).attr("y", function(i) {
    var n = t.node(i);
    return -n.height / 2;
  });
}
function Pt(r, t) {
  var e = r.filter(function() {
    return !p(this).classed("update");
  });
  function a(i) {
    var n = t.edge(i);
    return Object.prototype.hasOwnProperty.call(n, "x") ? "translate(" + n.x + "," + n.y + ")" : "";
  }
  e.attr("transform", a), g(r, t).style("opacity", 1).attr("transform", a);
}
function Tt(r, t) {
  var e = r.filter(function() {
    return !p(this).classed("update");
  });
  function a(i) {
    var n = t.node(i);
    return "translate(" + n.x + "," + n.y + ")";
  }
  e.attr("transform", a), g(r, t).style("opacity", 1).attr("transform", a);
}
function N(r, t, e, a) {
  var i = r.x, n = r.y, l = i - a.x, s = n - a.y, o = Math.sqrt(t * t * s * s + e * e * l * l), d = Math.abs(t * e * l / o);
  a.x < i && (d = -d);
  var u = Math.abs(t * e * s / o);
  return a.y < n && (u = -u), { x: i + d, y: n + u };
}
const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  intersectEllipse: N
}, Symbol.toStringTag, { value: "Module" }));
function H(r, t, e) {
  return N(r, t, t, e);
}
const kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  intersectCircle: H
}, Symbol.toStringTag, { value: "Module" }));
function Lt(r, t, e, a) {
  var i, n, l, s, o, d, u, b, h, y, c, f, v, x, w;
  if (i = t.y - r.y, l = r.x - t.x, o = t.x * r.y - r.x * t.y, h = i * e.x + l * e.y + o, y = i * a.x + l * a.y + o, !(h !== 0 && y !== 0 && R(h, y)) && (n = a.y - e.y, s = e.x - a.x, d = a.x * e.y - e.x * a.y, u = n * r.x + s * r.y + d, b = n * t.x + s * t.y + d, !(u !== 0 && b !== 0 && R(u, b)) && (c = i * s - n * l, c !== 0)))
    return f = Math.abs(c / 2), v = l * d - s * o, x = v < 0 ? (v - f) / c : (v + f) / c, v = n * o - i * d, w = v < 0 ? (v - f) / c : (v + f) / c, { x, y: w };
}
function R(r, t) {
  return r * t > 0;
}
function Y(r, t, e) {
  var a = r.x, i = r.y, n = [], l = Number.POSITIVE_INFINITY, s = Number.POSITIVE_INFINITY;
  t.forEach(function(c) {
    l = Math.min(l, c.x), s = Math.min(s, c.y);
  });
  for (var o = a - r.width / 2 - l, d = i - r.height / 2 - s, u = 0; u < t.length; u++) {
    var b = t[u], h = t[u < t.length - 1 ? u + 1 : 0], y = Lt(
      r,
      e,
      { x: o + b.x, y: d + b.y },
      { x: o + h.x, y: d + h.y }
    );
    y && n.push(y);
  }
  return n.length ? (n.length > 1 && n.sort(function(c, f) {
    var v = c.x - e.x, x = c.y - e.y, w = Math.sqrt(v * v + x * x), I = f.x - e.x, B = f.y - e.y, A = Math.sqrt(I * I + B * B);
    return w < A ? -1 : w === A ? 0 : 1;
  }), n[0]) : (console.log("NO INTERSECTION FOUND, RETURN NODE CENTER", r), r);
}
const jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  intersectPolygon: Y
}, Symbol.toStringTag, { value: "Module" }));
function U(r, t) {
  var e = r.x, a = r.y, i = t.x - e, n = t.y - a, l = r.width / 2, s = r.height / 2, o, d;
  return Math.abs(n) * l > Math.abs(i) * s ? (n < 0 && (s = -s), o = n === 0 ? 0 : s * i / n, d = s) : (i < 0 && (l = -l), o = l, d = i === 0 ? 0 : l * n / i), { x: e + o, y: a + d };
}
const Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  intersectRect: U
}, Symbol.toStringTag, { value: "Module" }));
var M = {
  rect: Nt,
  ellipse: It,
  circle: Bt,
  diamond: At
};
function Ct(r) {
  M = r;
}
function Nt(r, t, e) {
  var a = r.insert("rect", ":first-child").attr("rx", e.rx).attr("ry", e.ry).attr("x", -t.width / 2).attr("y", -t.height / 2).attr("width", t.width).attr("height", t.height);
  return e.intersect = function(i) {
    return U(e, i);
  }, a;
}
function It(r, t, e) {
  var a = t.width / 2, i = t.height / 2, n = r.insert("ellipse", ":first-child").attr("x", -t.width / 2).attr("y", -t.height / 2).attr("rx", a).attr("ry", i);
  return e.intersect = function(l) {
    return N(e, a, i, l);
  }, n;
}
function Bt(r, t, e) {
  var a = Math.max(t.width, t.height) / 2, i = r.insert("circle", ":first-child").attr("x", -t.width / 2).attr("y", -t.height / 2).attr("r", a);
  return e.intersect = function(n) {
    return H(e, a, n);
  }, i;
}
function At(r, t, e) {
  var a = t.width * Math.SQRT2 / 2, i = t.height * Math.SQRT2 / 2, n = [
    { x: 0, y: -i },
    { x: -a, y: 0 },
    { x: 0, y: i },
    { x: a, y: 0 }
  ], l = r.insert("polygon", ":first-child").attr(
    "points",
    n.map(function(s) {
      return s.x + "," + s.y;
    }).join(" ")
  );
  return e.intersect = function(s) {
    return Y(e, n, s);
  }, l;
}
function Ft() {
  var r = function(t, e) {
    Wt(e);
    var a = S(t, "output"), i = S(a, "clusters"), n = S(a, "edgePaths"), l = E(S(a, "edgeLabels"), e), s = j(S(a, "nodes"), e, M);
    K(e), Tt(s, e), Pt(l, e), L(n, e, P);
    var o = T(i, e);
    _t(o, e), Dt(e);
  };
  return r.createNodes = function(t) {
    return arguments.length ? (St(t), r) : j;
  }, r.createClusters = function(t) {
    return arguments.length ? (ft(t), r) : T;
  }, r.createEdgeLabels = function(t) {
    return arguments.length ? (vt(t), r) : E;
  }, r.createEdgePaths = function(t) {
    return arguments.length ? (yt(t), r) : L;
  }, r.shapes = function(t) {
    return arguments.length ? (Ct(t), r) : M;
  }, r.arrows = function(t) {
    return arguments.length ? (st(t), r) : P;
  }, r;
}
var Rt = {
  paddingLeft: 10,
  paddingRight: 10,
  paddingTop: 10,
  paddingBottom: 10,
  rx: 0,
  ry: 0,
  shape: "rect"
}, Gt = {
  arrowhead: "normal",
  curve: $
};
function Wt(r) {
  r.nodes().forEach((t) => {
    const e = r.node(t);
    !Object.prototype.hasOwnProperty.call(e, "label") && !r.children(t).length && (e.label = t), Object.prototype.hasOwnProperty.call(e, "paddingX") && O(e, {
      paddingLeft: e.paddingX,
      paddingRight: e.paddingX
    }), Object.prototype.hasOwnProperty.call(e, "paddingY") && O(e, {
      paddingTop: e.paddingY,
      paddingBottom: e.paddingY
    }), Object.prototype.hasOwnProperty.call(e, "padding") && O(e, {
      paddingLeft: e.padding,
      paddingRight: e.padding,
      paddingTop: e.padding,
      paddingBottom: e.padding
    }), O(e, Rt), ["paddingLeft", "paddingRight", "paddingTop", "paddingBottom"].forEach((a) => {
      e[a] = Number(e[a]);
    }), Object.prototype.hasOwnProperty.call(e, "width") && (e._prevWidth = e.width), Object.prototype.hasOwnProperty.call(e, "height") && (e._prevHeight = e.height);
  }), r.edges().forEach(function(t) {
    var e = r.edge(t);
    Object.prototype.hasOwnProperty.call(e, "label") || (e.label = ""), O(e, Gt);
  });
}
function Dt(r) {
  r.nodes().forEach((t) => {
    var e = r.node(t);
    Object.prototype.hasOwnProperty.call(e, "_prevWidth") ? e.width = e._prevWidth : delete e.width, Object.prototype.hasOwnProperty.call(e, "_prevHeight") ? e.height = e._prevHeight : delete e.height, delete e._prevWidth, delete e._prevHeight;
  });
}
function S(r, t) {
  var e = r.select("g." + t);
  return e.empty() && (e = r.append("g").attr("class", t)), e;
}
const Vt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  circle: kt,
  ellipse: Et,
  node: gt,
  polygon: jt,
  rect: Mt
}, Symbol.toStringTag, { value: "Module" }));
export {
  $t as graphlib,
  Vt as intersect,
  Ft as render
};
