import { j as je, X as Xe } from './flowDb-9a89ea33.esm.js';
import { Z as Ze, E, m } from './graph-0ee63739.esm.js';
import { a as L, $ as $n, B as B0, e as La, V as Vn, f as Od, b as bt$1, x as x0, D as Df, k as k_ } from './index.esm2.js';
import { Y as Yt$1, G, e as en, _ as _e, N } from './layout-fd473db2.esm.js';
import { h as he$1, w as we$1, t as te$1, e as ee$1, Z as Z$1, f as fe$1, b as be$1, u as ue$1, p as pe$1 } from './styles-e75131e4.esm.js';
import { P } from './line-24d93f1b.esm.js';
import './index-bb6d8841.esm.js';
import './clone-afc2f047.esm.js';
import './edges-16357fde.esm.js';
import './createText-03b82060.esm.js';
import './channel-ebbc4130.esm.js';
import './array-2ff2c7a6.esm.js';
import './path-428ebac9.esm.js';

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
function _ts_generator(thisArg, body) {
    var f, y, t, g, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    };
    return g = {
        next: verb(0),
        "throw": verb(1),
        "return": verb(2)
    }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
        return this;
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(_)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
function _ts_values(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function() {
            if (o && i >= o.length) o = void 0;
            return {
                value: o && o[i++],
                done: !o
            };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function Rt(r) {
    if (!r.ok) throw new Error(r.status + " " + r.statusText);
    return r.text();
}
function Gt(r, e) {
    return fetch(r, e).then(Rt);
}
function Pt(r) {
    return function(e, t) {
        return Gt(e, t).then(function(n) {
            return new DOMParser().parseFromString(n, r);
        });
    };
}
var Ut = Pt("image/svg+xml"), H = {
    normal: $t,
    vee: Vt,
    undirected: zt
};
function Wt(r) {
    H = r;
}
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 0 L 10 5 L 0 10 z").style("stroke-width", 1).style("stroke-dasharray", "1,0");
    ee$1(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function Vt(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");
    ee$1(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function zt(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");
    ee$1(s, t[n + "Style"]), t[n + "Class"] && s.attr("class", t[n + "Class"]);
}
function Yt(r, e) {
    var t = r;
    return t.node().appendChild(e.label), ee$1(t, e.labelStyle), t;
}
function Ht(r, e) {
    for(var t = r.append("text"), n = Xt(e.label).split("\n"), a = 0; a < n.length; a++)t.append("tspan").attr("xml:space", "preserve").attr("dy", "1em").attr("x", "1").text(n[a]);
    return ee$1(t, e.labelStyle), t;
}
function Xt(r) {
    for(var e = "", t = false, n, a = 0; a < r.length; ++a)if (n = r[a], t) {
        switch(n){
            case "n":
                e += "\n";
                break;
            default:
                e += n;
        }
        t = false;
    } else n === "\\" ? t = true : e += n;
    return e;
}
function J(r, e, t) {
    var n = e.label, a = r.append("g");
    e.labelType === "svg" ? Yt(a, e) : typeof n != "string" || e.labelType === "html" ? te$1(a, e) : Ht(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 X = function X(r, e) {
    var t = e.nodes().filter(function(s) {
        return fe$1(e, s);
    }), n = r.selectAll("g.cluster").data(t, function(s) {
        return s;
    });
    ue$1(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 = bt$1(this);
        bt$1(this).append("rect");
        var c = o.append("g").attr("class", "label");
        J(c, i, i.clusterLabelPos);
    });
    return n = n.merge(a), n = ue$1(n, e).style("opacity", 1), n.selectAll("rect").each(function(s) {
        var i = e.node(s), o = bt$1(this);
        ee$1(o, i.style);
    }), n;
};
function Ft(r) {
    X = r;
}
var F = function F(r, e) {
    var t = r.selectAll("g.edgeLabel").data(e.edges(), function(a) {
        return pe$1(a);
    }).classed("update", true);
    t.exit().remove(), t.enter().append("g").classed("edgeLabel", true).style("opacity", 0), t = r.selectAll("g.edgeLabel"), t.each(function(a) {
        var s = bt$1(this);
        s.select(".label").remove();
        var i = e.edge(a), o = J(s, e.edge(a), 0).classed("label", true), c = o.node().getBBox();
        i.labelId && o.attr("id", i.labelId), E(i, "width") || (i.width = c.width), E(i, "height") || (i.height = c.height);
    });
    var n;
    return t.exit ? n = t.exit() : n = t.selectAll(null), ue$1(n, e).style("opacity", 0).remove(), t;
};
function qt(r) {
    F = r;
}
function O(r, e) {
    return r.intersect(e);
}
var q = function q(r, e, t) {
    var n = r.selectAll("g.edgePath").data(e.edges(), function(i) {
        return pe$1(i);
    }).classed("update", true), a = Ot(n, e);
    jt(n, e);
    var s = n.merge !== void 0 ? n.merge(a) : n;
    return ue$1(s, e).style("opacity", 1), s.each(function(i) {
        var o = bt$1(this), c = e.edge(i);
        c.elem = this, c.id && o.attr("id", c.id), be$1(o, c.class, (o.classed("update") ? "update " : "") + "edgePath");
    }), s.selectAll("path.path").each(function(i) {
        var o = e.edge(i);
        o.arrowheadId = en("arrowhead");
        var c = bt$1(this).attr("marker-end", function() {
            return "url(" + Kt(location.href, o.arrowheadId) + ")";
        }).style("fill", "none");
        ue$1(c, e).attr("d", function(d) {
            return Jt(e, d);
        }), ee$1(c, o.style);
    }), s.selectAll("defs *").remove(), s.selectAll("defs").each(function(i) {
        var o = e.edge(i), c = t[o.arrowhead];
        c(bt$1(this), o.arrowheadId, o, "arrowhead");
    }), s;
};
function Qt(r) {
    q = r;
}
function Kt(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(O(n, s[0])), s.push(O(a, s[s.length - 1])), lt(t, s);
}
function lt(r, e) {
    var t = (P || Ut.line)().x(function(n) {
        return n.x;
    }).y(function(n) {
        return n.y;
    });
    return (t.curve || t.interpolate)(r.curve), t(e);
}
function Zt(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 Ot(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 = N(a.points.length).map(function() {
            return Zt(s);
        });
        return lt(a, i);
    }), t.append("defs"), t;
}
function jt(r, e) {
    var t = r.exit();
    ue$1(t, e).style("opacity", 0).remove();
}
var Q = function Q(r, e, t) {
    var n = e.nodes().filter(function(i) {
        return !fe$1(e, i);
    }), a = r.selectAll("g.node").data(n, function(i) {
        return i;
    }).classed("update", true);
    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 = bt$1(this);
        be$1(c, o.class, (c.classed("update") ? "update " : "") + "node"), c.select("g.label").remove();
        var d = c.append("g").attr("class", "label"), l = J(d, o), g = t[o.shape], h = G(l.node().getBBox(), "width", "height");
        o.elem = this, o.id && c.attr("id", o.id), o.labelId && d.attr("id", o.labelId), E(o, "width") && (h.width = o.width), E(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 = bt$1(this);
        u.select(".label-container").remove();
        var p = g(u, h, o).classed("label-container", true);
        ee$1(p, o.style);
        var v = p.node().getBBox();
        o.width = v.width, o.height = v.height;
    });
    var s;
    return a.exit ? s = a.exit() : s = a.selectAll(null), ue$1(s, e).style("opacity", 0).remove(), a;
};
function te(r) {
    Q = r;
}
function ee(r, e) {
    var t = r.filter(function() {
        return !bt$1(this).classed("update");
    });
    function n(a) {
        var s = e.node(a);
        return "translate(" + s.x + "," + s.y + ")";
    }
    t.attr("transform", n), ue$1(r, e).style("opacity", 1).attr("transform", n), ue$1(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 re(r, e) {
    var t = r.filter(function() {
        return !bt$1(this).classed("update");
    });
    function n(a) {
        var s = e.edge(a);
        return E(s, "x") ? "translate(" + s.x + "," + s.y + ")" : "";
    }
    t.attr("transform", n), ue$1(r, e).style("opacity", 1).attr("transform", n);
}
function ae(r, e) {
    var t = r.filter(function() {
        return !bt$1(this).classed("update");
    });
    function n(a) {
        var s = e.node(a);
        return "translate(" + s.x + "," + s.y + ")";
    }
    t.attr("transform", n), ue$1(r, e).style("opacity", 1).attr("transform", n);
}
function ct(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 ne(r, e, t) {
    return ct(r, e, e, t);
}
function se(r, e, t, n) {
    var a, s, i, o, c, d, l, g, h, u, p, v, f, y, 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, g = s * e.x + o * e.y + d, !(l !== 0 && g !== 0 && j(l, g)) && (p = a * o - s * i, p !== 0))) return v = Math.abs(p / 2), f = i * d - o * c, y = f < 0 ? (f - v) / p : (f + v) / p, f = s * c - a * d, k = f < 0 ? (f - v) / p : (f + v) / p, {
        x: y,
        y: k
    };
}
function j(r, e) {
    return r * e > 0;
}
function T(r, e, t) {
    var n = r.x, a = r.y, s = [], i = Number.POSITIVE_INFINITY, o = Number.POSITIVE_INFINITY;
    e.forEach(function(p) {
        i = Math.min(i, p.x), o = Math.min(o, p.y);
    });
    for(var c = n - r.width / 2 - i, d = a - r.height / 2 - o, l = 0; l < e.length; l++){
        var g = e[l], h = e[l < e.length - 1 ? l + 1 : 0], u = se(r, t, {
            x: c + g.x,
            y: d + g.y
        }, {
            x: c + h.x,
            y: d + h.y
        });
        u && s.push(u);
    }
    return s.length ? (s.length > 1 && s.sort(function(p, v) {
        var f = p.x - t.x, y = p.y - t.y, k = Math.sqrt(f * f + y * y), I = v.x - t.x, _ = v.y - t.y, W = Math.sqrt(I * I + _ * _);
        return k < W ? -1 : k === W ? 0 : 1;
    }), s[0]) : (console.log("NO INTERSECTION FOUND, RETURN NODE CENTER", r), r);
}
function Z(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 K = {
    rect: oe,
    ellipse: le,
    circle: ce,
    diamond: de
};
function ie(r) {
    K = r;
}
function oe(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 Z(t, a);
    }, n;
}
function le(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 ct(t, n, a, i);
    }, s;
}
function ce(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 ne(t, n, s);
    }, a;
}
function de(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(t, s, o);
    }, i;
}
function he() {
    var r = function r(e, t) {
        pe(t);
        var n = D(e, "output"), a = D(n, "clusters"), s = D(n, "edgePaths"), i = F(D(n, "edgeLabels"), t), o = Q(D(n, "nodes"), t, K);
        Yt$1(t), ae(o, t), re(i, t), q(s, t, H);
        var c = X(a, t);
        ee(c, t), ge(t);
    };
    return r.createNodes = function(e) {
        return arguments.length ? (te(e), r) : Q;
    }, r.createClusters = function(e) {
        return arguments.length ? (Ft(e), r) : X;
    }, r.createEdgeLabels = function(e) {
        return arguments.length ? (qt(e), r) : F;
    }, r.createEdgePaths = function(e) {
        return arguments.length ? (Qt(e), r) : q;
    }, r.shapes = function(e) {
        return arguments.length ? (ie(e), r) : K;
    }, r.arrows = function(e) {
        return arguments.length ? (Wt(e), r) : H;
    }, r;
}
var ue = {
    paddingLeft: 10,
    paddingRight: 10,
    paddingTop: 10,
    paddingBottom: 10,
    rx: 0,
    ry: 0,
    shape: "rect"
}, fe = {
    arrowhead: "normal",
    curve: Df
};
function pe(r) {
    r.nodes().forEach(function(e) {
        var t = r.node(e);
        !E(t, "label") && !r.children(e).length && (t.label = e), E(t, "paddingX") && _e(t, {
            paddingLeft: t.paddingX,
            paddingRight: t.paddingX
        }), E(t, "paddingY") && _e(t, {
            paddingTop: t.paddingY,
            paddingBottom: t.paddingY
        }), E(t, "padding") && _e(t, {
            paddingLeft: t.padding,
            paddingRight: t.padding,
            paddingTop: t.padding,
            paddingBottom: t.padding
        }), _e(t, ue), m([
            "paddingLeft",
            "paddingRight",
            "paddingTop",
            "paddingBottom"
        ], function(n) {
            t[n] = Number(t[n]);
        }), E(t, "width") && (t._prevWidth = t.width), E(t, "height") && (t._prevHeight = t.height);
    }), r.edges().forEach(function(e) {
        var t = r.edge(e);
        E(t, "label") || (t.label = ""), _e(t, fe);
    });
}
function ge(r) {
    m(r.nodes(), function(e) {
        var t = r.node(e);
        E(t, "_prevWidth") ? t.width = t._prevWidth : delete t.width, E(t, "_prevHeight") ? t.height = t._prevHeight : delete t.height, delete t._prevWidth, delete t._prevHeight;
    });
}
function D(r, e) {
    var t = r.select("g." + e);
    return t.empty() && (t = r.append("g").attr("class", e)), t;
}
function dt(r, e, t) {
    var 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 = A(r, s, s, i);
    return t.intersect = function(c) {
        return T(t, i, c);
    }, o;
}
function ht(r, e, t) {
    var 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 = A(r, i, a, o);
    return t.intersect = function(d) {
        return T(t, o, d);
    }, c;
}
function ut(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function ft(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function pt(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function gt(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function yt(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function vt(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function wt(r, e, t) {
    var 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 Z(t, i);
    }, s;
}
function mt(r, e, t) {
    var 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 = A(r, n, a, s);
    return t.intersect = function(o) {
        return T(t, s, o);
    }, i;
}
function xt(r, e, t) {
    var 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) {
        var l = Z(t, d), g = l.x - t.x;
        if (a != 0 && (Math.abs(g) < t.width / 2 || Math.abs(g) == t.width / 2 && Math.abs(l.y - t.y) > t.height / 2 - s)) {
            var h = s * s * (1 - g * g / (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 ye(r) {
    r.shapes().question = dt, r.shapes().hexagon = ht, r.shapes().stadium = wt, r.shapes().subroutine = mt, r.shapes().cylinder = xt, r.shapes().rect_left_inv_arrow = ut, r.shapes().lean_right = ft, r.shapes().lean_left = pt, r.shapes().trapezoid = gt, r.shapes().inv_trapezoid = yt, r.shapes().rect_right_inv_arrow = vt;
}
function ve(r) {
    r({
        question: dt
    }), r({
        hexagon: ht
    }), r({
        stadium: wt
    }), r({
        subroutine: mt
    }), r({
        cylinder: xt
    }), r({
        rect_left_inv_arrow: ut
    }), r({
        lean_right: ft
    }), r({
        lean_left: pt
    }), r({
        trapezoid: gt
    }), r({
        inv_trapezoid: yt
    }), r({
        rect_right_inv_arrow: vt
    });
}
function A(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 + ")");
}
var we = {
    addToRender: ye,
    addToRenderV2: ve
}, bt = {}, me = function me(r) {
    var e = Object.keys(r);
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    try {
        for(var _iterator = e[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var t = _step.value;
            bt[t] = r[t];
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
}, kt = function() {
    var _ref = _async_to_generator(function(r, e, t, n, a, s) {
        var i, o, c, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step, err;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    i = n ? n.select('[id="'.concat(t, '"]')) : bt$1('[id="'.concat(t, '"]')), o = a || document, c = Object.keys(r);
                    _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                    _state.label = 1;
                case 1:
                    _state.trys.push([
                        1,
                        6,
                        7,
                        8
                    ]);
                    _loop = function() {
                        var d, l, g, h, u, p, y, _tmp, y1, k, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step1, I, _, v, f;
                        return _ts_generator(this, function(_state) {
                            switch(_state.label){
                                case 0:
                                    d = _step.value;
                                    l = r[d];
                                    g = "default";
                                    l.classes.length > 0 && (g = l.classes.join(" "));
                                    h = B0(l.styles);
                                    u = l.text !== void 0 ? l.text : l.id, p = void 0;
                                    if (!La(Vn().flowchart.htmlLabels)) return [
                                        3,
                                        2
                                    ];
                                    _tmp = {};
                                    return [
                                        4,
                                        Od(u.replace(/fa[blrs]?:fa-[\w-]+/g, // cspell:disable-line
                                        function(k) {
                                            return "<i class='".concat(k.replace(":", " "), "'></i>");
                                        }), Vn())
                                    ];
                                case 1:
                                    y = (_tmp.label = _state.sent(), _tmp);
                                    p = te$1(i, y).node(), p.parentNode.removeChild(p);
                                    return [
                                        3,
                                        3
                                    ];
                                case 2:
                                    y1 = o.createElementNS("http://www.w3.org/2000/svg", "text");
                                    y1.setAttribute("style", h.labelStyle.replace("color:", "fill:"));
                                    k = u.split($n.lineBreakRegex);
                                    _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                                    try {
                                        for(_iterator = k[Symbol.iterator](); !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true){
                                            I = _step1.value;
                                            _ = o.createElementNS("http://www.w3.org/2000/svg", "tspan");
                                            _.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), _.setAttribute("dy", "1em"), _.setAttribute("x", "1"), _.textContent = I, y1.appendChild(_);
                                        }
                                    } catch (err) {
                                        _didIteratorError = true;
                                        _iteratorError = err;
                                    } finally{
                                        try {
                                            if (!_iteratorNormalCompletion && _iterator.return != null) {
                                                _iterator.return();
                                            }
                                        } finally{
                                            if (_didIteratorError) {
                                                throw _iteratorError;
                                            }
                                        }
                                    }
                                    p = y1;
                                    _state.label = 3;
                                case 3:
                                    v = 0, f = "";
                                    switch(l.type){
                                        case "round":
                                            v = 5, f = "rect";
                                            break;
                                        case "square":
                                            f = "rect";
                                            break;
                                        case "diamond":
                                            f = "question";
                                            break;
                                        case "hexagon":
                                            f = "hexagon";
                                            break;
                                        case "odd":
                                            f = "rect_left_inv_arrow";
                                            break;
                                        case "lean_right":
                                            f = "lean_right";
                                            break;
                                        case "lean_left":
                                            f = "lean_left";
                                            break;
                                        case "trapezoid":
                                            f = "trapezoid";
                                            break;
                                        case "inv_trapezoid":
                                            f = "inv_trapezoid";
                                            break;
                                        case "odd_right":
                                            f = "rect_left_inv_arrow";
                                            break;
                                        case "circle":
                                            f = "circle";
                                            break;
                                        case "ellipse":
                                            f = "ellipse";
                                            break;
                                        case "stadium":
                                            f = "stadium";
                                            break;
                                        case "subroutine":
                                            f = "subroutine";
                                            break;
                                        case "cylinder":
                                            f = "cylinder";
                                            break;
                                        case "group":
                                            f = "rect";
                                            break;
                                        default:
                                            f = "rect";
                                    }
                                    L.warn("Adding node", l.id, l.domId), e.setNode(s.db.lookUpDomId(l.id), {
                                        labelType: "svg",
                                        labelStyle: h.labelStyle,
                                        shape: f,
                                        label: p,
                                        rx: v,
                                        ry: v,
                                        class: g,
                                        style: h.style,
                                        id: s.db.lookUpDomId(l.id)
                                    });
                                    return [
                                        2
                                    ];
                            }
                        });
                    };
                    _iterator = c[Symbol.iterator]();
                    _state.label = 2;
                case 2:
                    if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
                        3,
                        5
                    ];
                    return [
                        5,
                        _ts_values(_loop())
                    ];
                case 3:
                    _state.sent();
                    _state.label = 4;
                case 4:
                    _iteratorNormalCompletion = true;
                    return [
                        3,
                        2
                    ];
                case 5:
                    return [
                        3,
                        8
                    ];
                case 6:
                    err = _state.sent();
                    _didIteratorError = true;
                    _iteratorError = err;
                    return [
                        3,
                        8
                    ];
                case 7:
                    try {
                        if (!_iteratorNormalCompletion && _iterator.return != null) {
                            _iterator.return();
                        }
                    } finally{
                        if (_didIteratorError) {
                            throw _iteratorError;
                        }
                    }
                    return [
                        7
                    ];
                case 8:
                    return [
                        2
                    ];
            }
        });
    });
    return function kt(r, e, t, n, a, s) {
        return _ref.apply(this, arguments);
    };
}(), St = function() {
    var _ref = _async_to_generator(function(r, e, t) {
        var n, a, s, i, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, i1, o, c, d, l, g, h, u, _, _1, err;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    n = 0;
                    if (r.defaultStyle !== void 0) {
                        i = B0(r.defaultStyle);
                        a = i.style, s = i.labelStyle;
                    }
                    _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                    _state.label = 1;
                case 1:
                    _state.trys.push([
                        1,
                        10,
                        11,
                        12
                    ]);
                    _iterator = r[Symbol.iterator]();
                    _state.label = 2;
                case 2:
                    if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
                        3,
                        9
                    ];
                    i1 = _step.value;
                    n++;
                    o = "L-" + i1.start + "-" + i1.end, c = "LS-" + i1.start, d = "LE-" + i1.end, l = {};
                    i1.type === "arrow_open" ? l.arrowhead = "none" : l.arrowhead = "normal";
                    g = "", h = "";
                    if (i1.style !== void 0) {
                        u = B0(i1.style);
                        g = u.style, h = u.labelStyle;
                    } else switch(i1.stroke){
                        case "normal":
                            g = "fill:none", a !== void 0 && (g = a), s !== void 0 && (h = s);
                            break;
                        case "dotted":
                            g = "fill:none;stroke-width:2px;stroke-dasharray:3;";
                            break;
                        case "thick":
                            g = " stroke-width: 3.5px;fill:none";
                            break;
                    }
                    l.style = g, l.labelStyle = h, i1.interpolate !== void 0 ? l.curve = x0(i1.interpolate, Df) : r.defaultInterpolate !== void 0 ? l.curve = x0(r.defaultInterpolate, Df) : l.curve = x0(bt.curve, Df);
                    if (!(i1.text === void 0)) return [
                        3,
                        3
                    ];
                    i1.style !== void 0 && (l.arrowheadStyle = "fill: #333");
                    return [
                        3,
                        7
                    ];
                case 3:
                    l.arrowheadStyle = "fill: #333", l.labelpos = "c";
                    if (!La(Vn().flowchart.htmlLabels)) return [
                        3,
                        5
                    ];
                    l.labelType = "html";
                    _1 = (_ = '<span id="L-'.concat(o, '" class="edgeLabel L-').concat(c, "' L-").concat(d, '" style="').concat(l.labelStyle, '">')).concat;
                    return [
                        4,
                        Od(i1.text.replace(/fa[blrs]?:fa-[\w-]+/g, // cspell:disable-line
                        function(u) {
                            return "<i class='".concat(u.replace(":", " "), "'></i>");
                        }), Vn())
                    ];
                case 4:
                    l.label = _1.apply(_, [
                        _state.sent(),
                        "</span>"
                    ]);
                    return [
                        3,
                        6
                    ];
                case 5:
                    (l.labelType = "text", l.label = i1.text.replace($n.lineBreakRegex, "\n"), i1.style === void 0 && (l.style = l.style || "stroke: #333; stroke-width: 1.5px;fill:none"), l.labelStyle = l.labelStyle.replace("color:", "fill:"));
                    _state.label = 6;
                case 6:
                    _state.label = 7;
                case 7:
                    l.id = o, l.class = c + " " + d, l.minlen = i1.length || 1, e.setEdge(t.db.lookUpDomId(i1.start), t.db.lookUpDomId(i1.end), l, n);
                    _state.label = 8;
                case 8:
                    _iteratorNormalCompletion = true;
                    return [
                        3,
                        2
                    ];
                case 9:
                    return [
                        3,
                        12
                    ];
                case 10:
                    err = _state.sent();
                    _didIteratorError = true;
                    _iteratorError = err;
                    return [
                        3,
                        12
                    ];
                case 11:
                    try {
                        if (!_iteratorNormalCompletion && _iterator.return != null) {
                            _iterator.return();
                        }
                    } finally{
                        if (_didIteratorError) {
                            throw _iteratorError;
                        }
                    }
                    return [
                        7
                    ];
                case 12:
                    return [
                        2
                    ];
            }
        });
    });
    return function St(r, e, t) {
        return _ref.apply(this, arguments);
    };
}(), xe = function xe(r, e) {
    return L.info("Extracting classes"), e.db.getClasses();
}, be = function() {
    var _ref = _async_to_generator(function(r, e, t, n) {
        var _G, a, s, i, o, c, d, l, g, h, u, p, w, v, f, y, w1, k, I, _, w2, b, L$1, m, B, C, $, w3, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, b1, L1, m1;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    L.info("Drawing flowchart");
                    _G = Vn(), a = _G.securityLevel, s = _G.flowchart;
                    a === "sandbox" && (i = bt$1("#i" + e));
                    o = a === "sandbox" ? bt$1(i.nodes()[0].contentDocument.body) : bt$1("body"), c = a === "sandbox" ? i.nodes()[0].contentDocument : document;
                    d = n.db.getDirection();
                    d === void 0 && (d = "TD");
                    l = s.nodeSpacing || 50, g = s.rankSpacing || 50, h = new Ze({
                        multigraph: true,
                        compound: true
                    }).setGraph({
                        rankdir: d,
                        nodesep: l,
                        ranksep: g,
                        marginx: 8,
                        marginy: 8
                    }).setDefaultEdgeLabel(function() {
                        return {};
                    });
                    p = n.db.getSubGraphs();
                    for(w = p.length - 1; w >= 0; w--)u = p[w], n.db.addVertex(u.id, u.title, "group", void 0, u.classes);
                    v = n.db.getVertices();
                    L.warn("Get vertices", v);
                    f = n.db.getEdges();
                    y = 0;
                    for(y = p.length - 1; y >= 0; y--){
                        u = p[y], Z$1("cluster").append("text");
                        for(w1 = 0; w1 < u.nodes.length; w1++)L.warn("Setting subgraph", u.nodes[w1], n.db.lookUpDomId(u.nodes[w1]), n.db.lookUpDomId(u.id)), h.setParent(n.db.lookUpDomId(u.nodes[w1]), n.db.lookUpDomId(u.id));
                    }
                    return [
                        4,
                        kt(v, h, e, o, c, n)
                    ];
                case 1:
                    _state.sent();
                    return [
                        4,
                        St(f, h, n)
                    ];
                case 2:
                    _state.sent();
                    k = new he();
                    we.addToRender(k), k.arrows().none = function(b, L, m, B) {
                        var C = b.append("marker").attr("id", L).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");
                        ee$1(C, m[B + "Style"]);
                    }, k.arrows().normal = function(b, L) {
                        b.append("marker").attr("id", L).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");
                    };
                    I = o.select('[id="'.concat(e, '"]')), _ = o.select("#" + e + " g");
                    for(k(_, h), _.selectAll("g.node").attr("title", function() {
                        return n.db.getTooltip(this.id);
                    }), n.db.indexNodes("subGraph" + y), y = 0; y < p.length; y++)if (u = p[y], u.title !== "undefined") {
                        w2 = c.querySelectorAll("#" + e + ' [id="' + n.db.lookUpDomId(u.id) + '"] rect'), b = c.querySelectorAll("#" + e + ' [id="' + n.db.lookUpDomId(u.id) + '"]'), L$1 = w2[0].x.baseVal.value, m = w2[0].y.baseVal.value, B = w2[0].width.baseVal.value, C = bt$1(b[0]).select(".label");
                        C.attr("transform", "translate(".concat(L$1 + B / 2, ", ").concat(m + 14, ")")), C.attr("id", e + "Text");
                        for($ = 0; $ < u.classes.length; $++)b[0].classList.add(u.classes[$]);
                    }
                    if (!s.htmlLabels) {
                        w3 = c.querySelectorAll('[id="' + e + '"] .edgeLabel .label');
                        _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                        try {
                            for(_iterator = w3[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                                b1 = _step.value;
                                L1 = b1.getBBox(), m1 = c.createElementNS("http://www.w3.org/2000/svg", "rect");
                                m1.setAttribute("rx", 0), m1.setAttribute("ry", 0), m1.setAttribute("width", L1.width), m1.setAttribute("height", L1.height), b1.insertBefore(m1, b1.firstChild);
                            }
                        } catch (err) {
                            _didIteratorError = true;
                            _iteratorError = err;
                        } finally{
                            try {
                                if (!_iteratorNormalCompletion && _iterator.return != null) {
                                    _iterator.return();
                                }
                            } finally{
                                if (_didIteratorError) {
                                    throw _iteratorError;
                                }
                            }
                        }
                    }
                    k_(h, I, s.diagramPadding, s.useMaxWidth), Object.keys(v).forEach(function(w) {
                        var b = v[w];
                        if (b.link) {
                            var L = o.select("#" + e + ' [id="' + n.db.lookUpDomId(w) + '"]');
                            if (L) {
                                var m = c.createElementNS("http://www.w3.org/2000/svg", "a");
                                m.setAttributeNS("http://www.w3.org/2000/svg", "class", b.classes.join(" ")), m.setAttributeNS("http://www.w3.org/2000/svg", "href", b.link), m.setAttributeNS("http://www.w3.org/2000/svg", "rel", "noopener"), a === "sandbox" ? m.setAttributeNS("http://www.w3.org/2000/svg", "target", "_top") : b.linkTarget && m.setAttributeNS("http://www.w3.org/2000/svg", "target", b.linkTarget);
                                var B = L.insert(function() {
                                    return m;
                                }, ":first-child"), P = L.select(".label-container");
                                P && B.append(function() {
                                    return P.node();
                                });
                                var C = L.select(".label");
                                C && B.append(function() {
                                    return C.node();
                                });
                            }
                        }
                    });
                    return [
                        2
                    ];
            }
        });
    });
    return function be(r, e, t, n) {
        return _ref.apply(this, arguments);
    };
}(), ke = {
    setConf: me,
    addVertices: kt,
    addEdges: St,
    getClasses: xe,
    draw: be
}, Ge = {
    parser: Xe,
    db: je,
    renderer: we$1,
    styles: he$1,
    init: function(r) {
        r.flowchart || (r.flowchart = {}), r.flowchart.arrowMarkerAbsolute = r.arrowMarkerAbsolute, ke.setConf(r.flowchart), je.clear(), je.setGen("gen-1");
    }
};

export { Ge as diagram };
