import { f as $, p as kt } from "./flowDb-c6c81e3f-DnVrIVtg.mjs";
import { d as m, n as G, l as M, g as D, o as St, p as z, q as W, r as Z, t as tt, k as et } from "./index-B4uS92Er.mjs";
import { G as Lt } from "./graph-B9GBc3rj.mjs";
import { u as Et, r as _t, p as Tt, l as Nt, d as I } from "./layout-BUJf-1Jb.mjs";
import { a as T, b as rt, i as at, c as E, e as nt, d as st, f as At, g as Pt, s as Ct } from "./styles-d45a18b0-Cx7oeddZ.mjs";
import { l as It } from "./line-uLxZxf3W.mjs";
function Bt(r) {
  if (!r.ok) throw new Error(r.status + " " + r.statusText);
  return r.text();
}
function Mt(r, e) {
  return fetch(r, e).then(Bt);
}
function Dt(r) {
  return (e, t) => Mt(e, t).then((n) => new DOMParser().parseFromString(n, r));
}
var Rt = Dt("image/svg+xml"), V = {
  normal: Ot,
  vee: Ut,
  undirected: $t
};
function Gt(r) {
  V = r;
}
function Ot(r, e, t, n) {
  var a = r.append("marker").attr("id", e).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), s = a.append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  T(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function Ut(r, e, t, n) {
  var a = r.append("marker").attr("id", e).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), s = a.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");
  T(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function $t(r, e, t, n) {
  var a = r.append("marker").attr("id", e).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto"), s = a.append("path").attr("d", "M 0 5 L 10 5").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  T(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function Wt(r, e) {
  var t = r;
  return t.node().appendChild(e.label), T(t, e.labelStyle), t;
}
function zt(r, e) {
  for (var t = r.append("text"), n = Vt(e.label).split(`
`), a = 0; a < n.length; a++)
    t.append("tspan").attr("xml:space", "preserve").attr("dy", "1em").attr("x", "1").text(n[a]);
  return T(t, e.labelStyle), t;
}
function Vt(r) {
  for (var e = "", t = !1, n, a = 0; a < r.length; ++a)
    if (n = r[a], t) {
      switch (n) {
        case "n":
          e += `
`;
          break;
        default:
          e += n;
      }
      t = !1;
    } else n === "\\" ? t = !0 : e += n;
  return e;
}
function q(r, e, t) {
  var n = e.label, a = r.append("g");
  e.labelType === "svg" ? Wt(a, e) : typeof n != "string" || e.labelType === "html" ? rt(a, e) : zt(a, e);
  var s = a.node().getBBox(), i;
  switch (t) {
    case "top":
      i = -e.height / 2;
      break;
    case "bottom":
      i = e.height / 2 - s.height;
      break;
    default:
      i = -s.height / 2;
  }
  return a.attr("transform", "translate(" + -s.width / 2 + "," + i + ")"), a;
}
var Y = function(r, e) {
  var t = e.nodes().filter(function(s) {
    return at(e, s);
  }), n = r.selectAll("g.cluster").data(t, function(s) {
    return s;
  });
  E(n.exit(), e).style("opacity", 0).remove();
  var a = n.enter().append("g").attr("class", "cluster").attr("id", function(s) {
    var i = e.node(s);
    return i.id;
  }).style("opacity", 0).each(function(s) {
    var i = e.node(s), o = m(this);
    m(this).append("rect");
    var c = o.append("g").attr("class", "label");
    q(c, i, i.clusterLabelPos);
  });
  return n = n.merge(a), n = E(n, e).style("opacity", 1), n.selectAll("rect").each(function(s) {
    var i = e.node(s), o = m(this);
    T(o, i.style);
  }), n;
};
function Yt(r) {
  Y = r;
}
let H = function(r, e) {
  var t = r.selectAll("g.edgeLabel").data(e.edges(), function(a) {
    return nt(a);
  }).classed("update", !0);
  t.exit().remove(), t.enter().append("g").classed("edgeLabel", !0).style("opacity", 0), t = r.selectAll("g.edgeLabel"), t.each(function(a) {
    var s = m(this);
    s.select(".label").remove();
    var i = e.edge(a), o = q(s, e.edge(a), 0).classed("label", !0), c = o.node().getBBox();
    i.labelId && o.attr("id", i.labelId), Object.prototype.hasOwnProperty.call(i, "width") || (i.width = c.width), Object.prototype.hasOwnProperty.call(i, "height") || (i.height = c.height);
  });
  var n;
  return t.exit ? n = t.exit() : n = t.selectAll(null), E(n, e).style("opacity", 0).remove(), t;
};
function Ht(r) {
  H = r;
}
function K(r, e) {
  return r.intersect(e);
}
var X = function(r, e, t) {
  var n = r.selectAll("g.edgePath").data(e.edges(), function(i) {
    return nt(i);
  }).classed("update", !0), a = Qt(n, e);
  Kt(n, e);
  var s = n.merge !== void 0 ? n.merge(a) : n;
  return E(s, e).style("opacity", 1), s.each(function(i) {
    var o = m(this), c = e.edge(i);
    c.elem = this, c.id && o.attr("id", c.id), st(
      o,
      c.class,
      (o.classed("update") ? "update " : "") + "edgePath"
    );
  }), s.selectAll("path.path").each(function(i) {
    var o = e.edge(i);
    o.arrowheadId = Et("arrowhead");
    var c = m(this).attr("marker-end", function() {
      return "url(" + Ft(location.href, o.arrowheadId) + ")";
    }).style("fill", "none");
    E(c, e).attr("d", function(d) {
      return jt(e, d);
    }), T(c, o.style);
  }), s.selectAll("defs *").remove(), s.selectAll("defs").each(function(i) {
    var o = e.edge(i), c = t[o.arrowhead];
    c(m(this), o.arrowheadId, o, "arrowhead");
  }), s;
};
function Xt(r) {
  X = r;
}
function Ft(r, e) {
  var t = r.split("#")[0];
  return t + "#" + e;
}
function jt(r, e) {
  var t = r.edge(e), n = r.node(e.v), a = r.node(e.w), s = t.points.slice(1, t.points.length - 1);
  return s.unshift(K(n, s[0])), s.push(K(a, s[s.length - 1])), it(t, s);
}
function it(r, e) {
  var t = (It || Rt.line)().x(function(n) {
    return n.x;
  }).y(function(n) {
    return n.y;
  });
  return (t.curve || t.interpolate)(r.curve), t(e);
}
function qt(r) {
  var e = r.getBBox(), t = r.ownerSVGElement.getScreenCTM().inverse().multiply(r.getScreenCTM()).translate(e.width / 2, e.height / 2);
  return { x: t.e, y: t.f };
}
function Qt(r, e) {
  var t = r.enter().append("g").attr("class", "edgePath").style("opacity", 0);
  return t.append("path").attr("class", "path").attr("d", function(n) {
    var a = e.edge(n), s = e.node(n.v).elem, i = _t(a.points.length).map(function() {
      return qt(s);
    });
    return it(a, i);
  }), t.append("defs"), t;
}
function Kt(r, e) {
  var t = r.exit();
  E(t, e).style("opacity", 0).remove();
}
var F = function(r, e, t) {
  var n = e.nodes().filter(function(i) {
    return !at(e, i);
  }), a = r.selectAll("g.node").data(n, function(i) {
    return i;
  }).classed("update", !0);
  a.exit().remove(), a.enter().append("g").attr("class", "node").style("opacity", 0), a = r.selectAll("g.node"), a.each(function(i) {
    var o = e.node(i), c = m(this);
    st(
      c,
      o.class,
      (c.classed("update") ? "update " : "") + "node"
    ), c.select("g.label").remove();
    var d = c.append("g").attr("class", "label"), l = q(d, o), y = t[o.shape], h = Tt(l.node().getBBox(), "width", "height");
    o.elem = this, o.id && c.attr("id", o.id), o.labelId && d.attr("id", o.labelId), Object.prototype.hasOwnProperty.call(o, "width") && (h.width = o.width), Object.prototype.hasOwnProperty.call(o, "height") && (h.height = o.height), h.width += o.paddingLeft + o.paddingRight, h.height += o.paddingTop + o.paddingBottom, d.attr(
      "transform",
      "translate(" + (o.paddingLeft - o.paddingRight) / 2 + "," + (o.paddingTop - o.paddingBottom) / 2 + ")"
    );
    var u = m(this);
    u.select(".label-container").remove();
    var f = y(u, h, o).classed("label-container", !0);
    T(f, o.style);
    var g = f.node().getBBox();
    o.width = g.width, o.height = g.height;
  });
  var s;
  return a.exit ? s = a.exit() : s = a.selectAll(null), E(s, e).style("opacity", 0).remove(), a;
};
function Jt(r) {
  F = r;
}
function Zt(r, e) {
  var t = r.filter(function() {
    return !m(this).classed("update");
  });
  function n(a) {
    var s = e.node(a);
    return "translate(" + s.x + "," + s.y + ")";
  }
  t.attr("transform", n), E(r, e).style("opacity", 1).attr("transform", n), E(t.selectAll("rect"), e).attr("width", function(a) {
    return e.node(a).width;
  }).attr("height", function(a) {
    return e.node(a).height;
  }).attr("x", function(a) {
    var s = e.node(a);
    return -s.width / 2;
  }).attr("y", function(a) {
    var s = e.node(a);
    return -s.height / 2;
  });
}
function te(r, e) {
  var t = r.filter(function() {
    return !m(this).classed("update");
  });
  function n(a) {
    var s = e.edge(a);
    return Object.prototype.hasOwnProperty.call(s, "x") ? "translate(" + s.x + "," + s.y + ")" : "";
  }
  t.attr("transform", n), E(r, e).style("opacity", 1).attr("transform", n);
}
function ee(r, e) {
  var t = r.filter(function() {
    return !m(this).classed("update");
  });
  function n(a) {
    var s = e.node(a);
    return "translate(" + s.x + "," + s.y + ")";
  }
  t.attr("transform", n), E(r, e).style("opacity", 1).attr("transform", n);
}
function ot(r, e, t, n) {
  var a = r.x, s = r.y, i = a - n.x, o = s - n.y, c = Math.sqrt(e * e * o * o + t * t * i * i), d = Math.abs(e * t * i / c);
  n.x < a && (d = -d);
  var l = Math.abs(e * t * o / c);
  return n.y < s && (l = -l), { x: a + d, y: s + l };
}
function re(r, e, t) {
  return ot(r, e, e, t);
}
function ae(r, e, t, n) {
  var a, s, i, o, c, d, l, y, h, u, f, g, p, v, k;
  if (a = e.y - r.y, i = r.x - e.x, c = e.x * r.y - r.x * e.y, h = a * t.x + i * t.y + c, u = a * n.x + i * n.y + c, !(h !== 0 && u !== 0 && J(h, u)) && (s = n.y - t.y, o = t.x - n.x, d = n.x * t.y - t.x * n.y, l = s * r.x + o * r.y + d, y = s * e.x + o * e.y + d, !(l !== 0 && y !== 0 && J(l, y)) && (f = a * o - s * i, f !== 0)))
    return g = Math.abs(f / 2), p = i * d - o * c, v = p < 0 ? (p - g) / f : (p + g) / f, p = s * c - a * d, k = p < 0 ? (p - g) / f : (p + g) / f, { x: v, y: k };
}
function J(r, e) {
  return r * e > 0;
}
function _(r, e, t) {
  var n = r.x, a = r.y, s = [], i = Number.POSITIVE_INFINITY, o = Number.POSITIVE_INFINITY;
  e.forEach(function(f) {
    i = Math.min(i, f.x), o = Math.min(o, f.y);
  });
  for (var c = n - r.width / 2 - i, d = a - r.height / 2 - o, l = 0; l < e.length; l++) {
    var y = e[l], h = e[l < e.length - 1 ? l + 1 : 0], u = ae(
      r,
      t,
      { x: c + y.x, y: d + y.y },
      { x: c + h.x, y: d + h.y }
    );
    u && s.push(u);
  }
  return s.length ? (s.length > 1 && s.sort(function(f, g) {
    var p = f.x - t.x, v = f.y - t.y, k = Math.sqrt(p * p + v * v), P = g.x - t.x, L = g.y - t.y, O = Math.sqrt(P * P + L * L);
    return k < O ? -1 : k === O ? 0 : 1;
  }), s[0]) : (console.log("NO INTERSECTION FOUND, RETURN NODE CENTER", r), r);
}
function Q(r, e) {
  var t = r.x, n = r.y, a = e.x - t, s = e.y - n, i = r.width / 2, o = r.height / 2, c, d;
  return Math.abs(s) * i > Math.abs(a) * o ? (s < 0 && (o = -o), c = s === 0 ? 0 : o * a / s, d = o) : (a < 0 && (i = -i), c = i, d = a === 0 ? 0 : i * s / a), { x: t + c, y: n + d };
}
var j = {
  rect: se,
  ellipse: ie,
  circle: oe,
  diamond: le
};
function ne(r) {
  j = r;
}
function se(r, e, t) {
  var n = r.insert("rect", ":first-child").attr("rx", t.rx).attr("ry", t.ry).attr("x", -e.width / 2).attr("y", -e.height / 2).attr("width", e.width).attr("height", e.height);
  return t.intersect = function(a) {
    return Q(t, a);
  }, n;
}
function ie(r, e, t) {
  var n = e.width / 2, a = e.height / 2, s = r.insert("ellipse", ":first-child").attr("x", -e.width / 2).attr("y", -e.height / 2).attr("rx", n).attr("ry", a);
  return t.intersect = function(i) {
    return ot(t, n, a, i);
  }, s;
}
function oe(r, e, t) {
  var n = Math.max(e.width, e.height) / 2, a = r.insert("circle", ":first-child").attr("x", -e.width / 2).attr("y", -e.height / 2).attr("r", n);
  return t.intersect = function(s) {
    return re(t, n, s);
  }, a;
}
function le(r, e, t) {
  var n = e.width * Math.SQRT2 / 2, a = e.height * Math.SQRT2 / 2, s = [
    { x: 0, y: -a },
    { x: -n, y: 0 },
    { x: 0, y: a },
    { x: n, y: 0 }
  ], i = r.insert("polygon", ":first-child").attr(
    "points",
    s.map(function(o) {
      return o.x + "," + o.y;
    }).join(" ")
  );
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function ce() {
  var r = function(e, t) {
    ue(t);
    var n = B(e, "output"), a = B(n, "clusters"), s = B(n, "edgePaths"), i = H(B(n, "edgeLabels"), t), o = F(B(n, "nodes"), t, j);
    Nt(t), ee(o, t), te(i, t), X(s, t, V);
    var c = Y(a, t);
    Zt(c, t), pe(t);
  };
  return r.createNodes = function(e) {
    return arguments.length ? (Jt(e), r) : F;
  }, r.createClusters = function(e) {
    return arguments.length ? (Yt(e), r) : Y;
  }, r.createEdgeLabels = function(e) {
    return arguments.length ? (Ht(e), r) : H;
  }, r.createEdgePaths = function(e) {
    return arguments.length ? (Xt(e), r) : X;
  }, r.shapes = function(e) {
    return arguments.length ? (ne(e), r) : j;
  }, r.arrows = function(e) {
    return arguments.length ? (Gt(e), r) : V;
  }, r;
}
var de = {
  paddingLeft: 10,
  paddingRight: 10,
  paddingTop: 10,
  paddingBottom: 10,
  rx: 0,
  ry: 0,
  shape: "rect"
}, he = {
  arrowhead: "normal",
  curve: G
};
function ue(r) {
  r.nodes().forEach((e) => {
    const t = r.node(e);
    !Object.prototype.hasOwnProperty.call(t, "label") && !r.children(e).length && (t.label = e), Object.prototype.hasOwnProperty.call(t, "paddingX") && I(t, {
      paddingLeft: t.paddingX,
      paddingRight: t.paddingX
    }), Object.prototype.hasOwnProperty.call(t, "paddingY") && I(t, {
      paddingTop: t.paddingY,
      paddingBottom: t.paddingY
    }), Object.prototype.hasOwnProperty.call(t, "padding") && I(t, {
      paddingLeft: t.padding,
      paddingRight: t.padding,
      paddingTop: t.padding,
      paddingBottom: t.padding
    }), I(t, de), ["paddingLeft", "paddingRight", "paddingTop", "paddingBottom"].forEach((n) => {
      t[n] = Number(t[n]);
    }), Object.prototype.hasOwnProperty.call(t, "width") && (t._prevWidth = t.width), Object.prototype.hasOwnProperty.call(t, "height") && (t._prevHeight = t.height);
  }), r.edges().forEach(function(e) {
    var t = r.edge(e);
    Object.prototype.hasOwnProperty.call(t, "label") || (t.label = ""), I(t, he);
  });
}
function pe(r) {
  r.nodes().forEach((e) => {
    var t = r.node(e);
    Object.prototype.hasOwnProperty.call(t, "_prevWidth") ? t.width = t._prevWidth : delete t.width, Object.prototype.hasOwnProperty.call(t, "_prevHeight") ? t.height = t._prevHeight : delete t.height, delete t._prevWidth, delete t._prevHeight;
  });
}
function B(r, e) {
  var t = r.select("g." + e);
  return t.empty() && (t = r.append("g").attr("class", e)), t;
}
function lt(r, e, t) {
  const n = e.width, a = e.height, s = (n + a) * 0.9, i = [
    { x: s / 2, y: 0 },
    { x: s, y: -s / 2 },
    { x: s / 2, y: -s },
    { x: 0, y: -s / 2 }
  ], o = N(r, s, s, i);
  return t.intersect = function(c) {
    return _(t, i, c);
  }, o;
}
function ct(r, e, t) {
  const a = e.height, s = a / 4, i = e.width + 2 * s, o = [
    { x: s, y: 0 },
    { x: i - s, y: 0 },
    { x: i, y: -a / 2 },
    { x: i - s, y: -a },
    { x: s, y: -a },
    { x: 0, y: -a / 2 }
  ], c = N(r, i, a, o);
  return t.intersect = function(d) {
    return _(t, o, d);
  }, c;
}
function dt(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: -a / 2, y: 0 },
    { x: n, y: 0 },
    { x: n, y: -a },
    { x: -a / 2, y: -a },
    { x: 0, y: -a / 2 }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function ht(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: -2 * a / 6, y: 0 },
    { x: n - a / 6, y: 0 },
    { x: n + 2 * a / 6, y: -a },
    { x: a / 6, y: -a }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function ut(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: 2 * a / 6, y: 0 },
    { x: n + a / 6, y: 0 },
    { x: n - 2 * a / 6, y: -a },
    { x: -a / 6, y: -a }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function pt(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: -2 * a / 6, y: 0 },
    { x: n + 2 * a / 6, y: 0 },
    { x: n - a / 6, y: -a },
    { x: a / 6, y: -a }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function ft(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: a / 6, y: 0 },
    { x: n - a / 6, y: 0 },
    { x: n + 2 * a / 6, y: -a },
    { x: -2 * a / 6, y: -a }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function yt(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: 0, y: 0 },
    { x: n + a / 2, y: 0 },
    { x: n, y: -a / 2 },
    { x: n + a / 2, y: -a },
    { x: 0, y: -a }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function vt(r, e, t) {
  const n = e.height, a = e.width + n / 4, s = r.insert("rect", ":first-child").attr("rx", n / 2).attr("ry", n / 2).attr("x", -a / 2).attr("y", -n / 2).attr("width", a).attr("height", n);
  return t.intersect = function(i) {
    return Q(t, i);
  }, s;
}
function gt(r, e, t) {
  const n = e.width, a = e.height, s = [
    { x: 0, y: 0 },
    { x: n, y: 0 },
    { x: n, y: -a },
    { x: 0, y: -a },
    { x: 0, y: 0 },
    { x: -8, y: 0 },
    { x: n + 8, y: 0 },
    { x: n + 8, y: -a },
    { x: -8, y: -a },
    { x: -8, y: 0 }
  ], i = N(r, n, a, s);
  return t.intersect = function(o) {
    return _(t, s, o);
  }, i;
}
function wt(r, e, t) {
  const n = e.width, a = n / 2, s = a / (2.5 + n / 50), i = e.height + s, o = "M 0," + s + " a " + a + "," + s + " 0,0,0 " + n + " 0 a " + a + "," + s + " 0,0,0 " + -n + " 0 l 0," + i + " a " + a + "," + s + " 0,0,0 " + n + " 0 l 0," + -i, c = r.attr("label-offset-y", s).insert("path", ":first-child").attr("d", o).attr("transform", "translate(" + -n / 2 + "," + -(i / 2 + s) + ")");
  return t.intersect = function(d) {
    const l = Q(t, d), y = l.x - t.x;
    if (a != 0 && (Math.abs(y) < t.width / 2 || Math.abs(y) == t.width / 2 && Math.abs(l.y - t.y) > t.height / 2 - s)) {
      let h = s * s * (1 - y * y / (a * a));
      h != 0 && (h = Math.sqrt(h)), h = s - h, d.y - t.y > 0 && (h = -h), l.y += h;
    }
    return l;
  }, c;
}
function fe(r) {
  r.shapes().question = lt, r.shapes().hexagon = ct, r.shapes().stadium = vt, r.shapes().subroutine = gt, r.shapes().cylinder = wt, r.shapes().rect_left_inv_arrow = dt, r.shapes().lean_right = ht, r.shapes().lean_left = ut, r.shapes().trapezoid = pt, r.shapes().inv_trapezoid = ft, r.shapes().rect_right_inv_arrow = yt;
}
function ye(r) {
  r({ question: lt }), r({ hexagon: ct }), r({ stadium: vt }), r({ subroutine: gt }), r({ cylinder: wt }), r({ rect_left_inv_arrow: dt }), r({ lean_right: ht }), r({ lean_left: ut }), r({ trapezoid: pt }), r({ inv_trapezoid: ft }), r({ rect_right_inv_arrow: yt });
}
function N(r, e, t, n) {
  return r.insert("polygon", ":first-child").attr(
    "points",
    n.map(function(a) {
      return a.x + "," + a.y;
    }).join(" ")
  ).attr("transform", "translate(" + -e / 2 + "," + t / 2 + ")");
}
const ve = {
  addToRender: fe,
  addToRenderV2: ye
}, xt = {}, ge = function(r) {
  const e = Object.keys(r);
  for (const t of e)
    xt[t] = r[t];
}, mt = async function(r, e, t, n, a, s) {
  const i = n ? n.select(`[id="${t}"]`) : m(`[id="${t}"]`), o = a || document, c = Object.keys(r);
  for (const d of c) {
    const l = r[d];
    let y = "default";
    l.classes.length > 0 && (y = l.classes.join(" "));
    const h = z(l.styles);
    let u = l.text !== void 0 ? l.text : l.id, f;
    if (Z(D().flowchart.htmlLabels)) {
      const v = {
        label: await tt(
          u.replace(
            /fa[blrs]?:fa-[\w-]+/g,
            // cspell:disable-line
            (k) => `<i class='${k.replace(":", " ")}'></i>`
          ),
          D()
        )
      };
      f = rt(i, v).node(), f.parentNode.removeChild(f);
    } else {
      const v = o.createElementNS("http://www.w3.org/2000/svg", "text");
      v.setAttribute("style", h.labelStyle.replace("color:", "fill:"));
      const k = u.split(et.lineBreakRegex);
      for (const P of k) {
        const L = o.createElementNS("http://www.w3.org/2000/svg", "tspan");
        L.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), L.setAttribute("dy", "1em"), L.setAttribute("x", "1"), L.textContent = P, v.appendChild(L);
      }
      f = v;
    }
    let g = 0, p = "";
    switch (l.type) {
      case "round":
        g = 5, p = "rect";
        break;
      case "square":
        p = "rect";
        break;
      case "diamond":
        p = "question";
        break;
      case "hexagon":
        p = "hexagon";
        break;
      case "odd":
        p = "rect_left_inv_arrow";
        break;
      case "lean_right":
        p = "lean_right";
        break;
      case "lean_left":
        p = "lean_left";
        break;
      case "trapezoid":
        p = "trapezoid";
        break;
      case "inv_trapezoid":
        p = "inv_trapezoid";
        break;
      case "odd_right":
        p = "rect_left_inv_arrow";
        break;
      case "circle":
        p = "circle";
        break;
      case "ellipse":
        p = "ellipse";
        break;
      case "stadium":
        p = "stadium";
        break;
      case "subroutine":
        p = "subroutine";
        break;
      case "cylinder":
        p = "cylinder";
        break;
      case "group":
        p = "rect";
        break;
      default:
        p = "rect";
    }
    M.warn("Adding node", l.id, l.domId), e.setNode(s.db.lookUpDomId(l.id), {
      labelType: "svg",
      labelStyle: h.labelStyle,
      shape: p,
      label: f,
      rx: g,
      ry: g,
      class: y,
      style: h.style,
      id: s.db.lookUpDomId(l.id)
    });
  }
}, bt = async function(r, e, t) {
  let n = 0, a, s;
  if (r.defaultStyle !== void 0) {
    const i = z(r.defaultStyle);
    a = i.style, s = i.labelStyle;
  }
  for (const i of r) {
    n++;
    const o = "L-" + i.start + "-" + i.end, c = "LS-" + i.start, d = "LE-" + i.end, l = {};
    i.type === "arrow_open" ? l.arrowhead = "none" : l.arrowhead = "normal";
    let y = "", h = "";
    if (i.style !== void 0) {
      const u = z(i.style);
      y = u.style, h = u.labelStyle;
    } else
      switch (i.stroke) {
        case "normal":
          y = "fill:none", a !== void 0 && (y = a), s !== void 0 && (h = s);
          break;
        case "dotted":
          y = "fill:none;stroke-width:2px;stroke-dasharray:3;";
          break;
        case "thick":
          y = " stroke-width: 3.5px;fill:none";
          break;
      }
    l.style = y, l.labelStyle = h, i.interpolate !== void 0 ? l.curve = W(i.interpolate, G) : r.defaultInterpolate !== void 0 ? l.curve = W(r.defaultInterpolate, G) : l.curve = W(xt.curve, G), i.text === void 0 ? i.style !== void 0 && (l.arrowheadStyle = "fill: #333") : (l.arrowheadStyle = "fill: #333", l.labelpos = "c", Z(D().flowchart.htmlLabels) ? (l.labelType = "html", l.label = `<span id="L-${o}" class="edgeLabel L-${c}' L-${d}" style="${l.labelStyle}">${await tt(
      i.text.replace(
        /fa[blrs]?:fa-[\w-]+/g,
        // cspell:disable-line
        (u) => `<i class='${u.replace(":", " ")}'></i>`
      ),
      D()
    )}</span>`) : (l.labelType = "text", l.label = i.text.replace(et.lineBreakRegex, `
`), i.style === void 0 && (l.style = l.style || "stroke: #333; stroke-width: 1.5px;fill:none"), l.labelStyle = l.labelStyle.replace("color:", "fill:"))), l.id = o, l.class = c + " " + d, l.minlen = i.length || 1, e.setEdge(t.db.lookUpDomId(i.start), t.db.lookUpDomId(i.end), l, n);
  }
}, we = function(r, e) {
  return M.info("Extracting classes"), e.db.getClasses();
}, xe = async function(r, e, t, n) {
  M.info("Drawing flowchart");
  const { securityLevel: a, flowchart: s } = D();
  let i;
  a === "sandbox" && (i = m("#i" + e));
  const o = a === "sandbox" ? m(i.nodes()[0].contentDocument.body) : m("body"), c = a === "sandbox" ? i.nodes()[0].contentDocument : document;
  let d = n.db.getDirection();
  d === void 0 && (d = "TD");
  const l = s.nodeSpacing || 50, y = s.rankSpacing || 50, h = new Lt({
    multigraph: !0,
    compound: !0
  }).setGraph({
    rankdir: d,
    nodesep: l,
    ranksep: y,
    marginx: 8,
    marginy: 8
  }).setDefaultEdgeLabel(function() {
    return {};
  });
  let u;
  const f = n.db.getSubGraphs();
  for (let w = f.length - 1; w >= 0; w--)
    u = f[w], n.db.addVertex(u.id, u.title, "group", void 0, u.classes);
  const g = n.db.getVertices();
  M.warn("Get vertices", g);
  const p = n.db.getEdges();
  let v = 0;
  for (v = f.length - 1; v >= 0; v--) {
    u = f[v], Ct("cluster").append("text");
    for (let w = 0; w < u.nodes.length; w++)
      M.warn(
        "Setting subgraph",
        u.nodes[w],
        n.db.lookUpDomId(u.nodes[w]),
        n.db.lookUpDomId(u.id)
      ), h.setParent(n.db.lookUpDomId(u.nodes[w]), n.db.lookUpDomId(u.id));
  }
  await mt(g, h, e, o, c, n), await bt(p, h, n);
  const k = new ce();
  ve.addToRender(k), k.arrows().none = function(b, S, x, C) {
    const A = b.append("marker").attr("id", S).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto").append("path").attr("d", "M 0 0 L 0 0 L 0 0 z");
    T(A, x[C + "Style"]);
  }, k.arrows().normal = function(b, S) {
    b.append("marker").attr("id", S).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerUnits", "strokeWidth").attr("markerWidth", 8).attr("markerHeight", 6).attr("orient", "auto").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("class", "arrowheadPath").style("stroke-width", 1).style("stroke-dasharray", "1,0");
  };
  const P = o.select(`[id="${e}"]`), L = o.select("#" + e + " g");
  for (k(L, h), L.selectAll("g.node").attr("title", function() {
    return n.db.getTooltip(this.id);
  }), n.db.indexNodes("subGraph" + v), v = 0; v < f.length; v++)
    if (u = f[v], u.title !== "undefined") {
      const w = c.querySelectorAll(
        "#" + e + ' [id="' + n.db.lookUpDomId(u.id) + '"] rect'
      ), b = c.querySelectorAll(
        "#" + e + ' [id="' + n.db.lookUpDomId(u.id) + '"]'
      ), S = w[0].x.baseVal.value, x = w[0].y.baseVal.value, C = w[0].width.baseVal.value, A = m(b[0]).select(".label");
      A.attr("transform", `translate(${S + C / 2}, ${x + 14})`), A.attr("id", e + "Text");
      for (let U = 0; U < u.classes.length; U++)
        b[0].classList.add(u.classes[U]);
    }
  if (!s.htmlLabels) {
    const w = c.querySelectorAll('[id="' + e + '"] .edgeLabel .label');
    for (const b of w) {
      const S = b.getBBox(), x = c.createElementNS("http://www.w3.org/2000/svg", "rect");
      x.setAttribute("rx", 0), x.setAttribute("ry", 0), x.setAttribute("width", S.width), x.setAttribute("height", S.height), b.insertBefore(x, b.firstChild);
    }
  }
  St(h, P, s.diagramPadding, s.useMaxWidth), Object.keys(g).forEach(function(w) {
    const b = g[w];
    if (b.link) {
      const S = o.select("#" + e + ' [id="' + n.db.lookUpDomId(w) + '"]');
      if (S) {
        const x = c.createElementNS("http://www.w3.org/2000/svg", "a");
        x.setAttributeNS("http://www.w3.org/2000/svg", "class", b.classes.join(" ")), x.setAttributeNS("http://www.w3.org/2000/svg", "href", b.link), x.setAttributeNS("http://www.w3.org/2000/svg", "rel", "noopener"), a === "sandbox" ? x.setAttributeNS("http://www.w3.org/2000/svg", "target", "_top") : b.linkTarget && x.setAttributeNS("http://www.w3.org/2000/svg", "target", b.linkTarget);
        const C = S.insert(function() {
          return x;
        }, ":first-child"), R = S.select(".label-container");
        R && C.append(function() {
          return R.node();
        });
        const A = S.select(".label");
        A && C.append(function() {
          return A.node();
        });
      }
    }
  });
}, me = {
  setConf: ge,
  addVertices: mt,
  addEdges: bt,
  getClasses: we,
  draw: xe
}, Te = {
  parser: kt,
  db: $,
  renderer: Pt,
  styles: At,
  init: (r) => {
    r.flowchart || (r.flowchart = {}), r.flowchart.arrowMarkerAbsolute = r.arrowMarkerAbsolute, me.setConf(r.flowchart), $.clear(), $.setGen("gen-1");
  }
};
export {
  Te as diagram
};
