import { Z as Ze } from './graph-0ee63739.esm.js';
import { J as Je, V as Vn, a as L, B as B0, e as La, $ as $n, f as Od, x as x0, D as Df, g as ei, k as k_, b as bt, y as yt, Z as Zs, h as Fh, i as sm, j as In } from './index.esm2.js';
import { b as bt$1 } from './index-bb6d8841.esm.js';
import { e } from './channel-ebbc4130.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 _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
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 Z(e) {
    return typeof e == "string" ? new yt([
        document.querySelectorAll(e)
    ], [
        document.documentElement
    ]) : new yt([
        Fh(e)
    ], Zs);
}
function fe(e, l) {
    return !!e.children(l).length;
}
function pe(e) {
    return A(e.v) + ":" + A(e.w) + ":" + A(e.name);
}
var O = /:/g;
function A(e) {
    return e ? String(e).replace(O, "\\:") : "";
}
function ee(e, l) {
    l && e.attr("style", l);
}
function be(e, l, c) {
    l && e.attr("class", l).attr("class", c + " " + e.attr("class"));
}
function ue(e, l) {
    var c = l.graph();
    if (sm(c)) {
        var a = c.transition;
        if (In(a)) return a(e);
    }
    return e;
}
function te(e, l) {
    var c = e.append("foreignObject").attr("width", "100000"), a = c.append("xhtml:div");
    a.attr("xmlns", "http://www.w3.org/1999/xhtml");
    var i = l.label;
    switch(typeof i === "undefined" ? "undefined" : _type_of(i)){
        case "function":
            a.insert(i);
            break;
        case "object":
            a.insert(function() {
                return i;
            });
            break;
        default:
            a.html(i);
    }
    ee(a, l.labelStyle), a.style("display", "inline-block"), a.style("white-space", "nowrap");
    var d = a.node().getBoundingClientRect();
    return c.attr("width", d.width).attr("height", d.height), c;
}
var P = {}, re = function re(e) {
    var l = Object.keys(e);
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    try {
        for(var _iterator = l[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var c = _step.value;
            P[c] = e[c];
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
}, V = function() {
    var _ref = _async_to_generator(function(e, l, c, a, i, d) {
        var u, o, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, f, r, y, w, t, s, k, _, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, $, S, p, n, T, err;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    u = a.select('[id="'.concat(c, '"]')), o = Object.keys(e);
                    _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                    _state.label = 1;
                case 1:
                    _state.trys.push([
                        1,
                        6,
                        7,
                        8
                    ]);
                    _iterator = o[Symbol.iterator]();
                    _state.label = 2;
                case 2:
                    if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
                        3,
                        5
                    ];
                    f = _step.value;
                    r = e[f];
                    y = "default";
                    r.classes.length > 0 && (y = r.classes.join(" ")), y = y + " flowchart-label";
                    w = B0(r.styles);
                    t = r.text !== void 0 ? r.text : r.id, s = void 0;
                    if (L.info("vertex", r, r.labelType), r.labelType === "markdown") L.info("vertex", r, r.labelType);
                    else if (La(Vn().flowchart.htmlLabels)) s = te(u, {
                        label: t
                    }).node(), s.parentNode.removeChild(s);
                    else {
                        k = i.createElementNS("http://www.w3.org/2000/svg", "text");
                        k.setAttribute("style", w.labelStyle.replace("color:", "fill:"));
                        _ = t.split($n.lineBreakRegex);
                        _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                        try {
                            for(_iterator1 = _[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                                $ = _step1.value;
                                S = i.createElementNS("http://www.w3.org/2000/svg", "tspan");
                                S.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), S.setAttribute("dy", "1em"), S.setAttribute("x", "1"), S.textContent = $, k.appendChild(S);
                            }
                        } catch (err) {
                            _didIteratorError1 = true;
                            _iteratorError1 = err;
                        } finally{
                            try {
                                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                                    _iterator1.return();
                                }
                            } finally{
                                if (_didIteratorError1) {
                                    throw _iteratorError1;
                                }
                            }
                        }
                        s = k;
                    }
                    p = 0, n = "";
                    switch(r.type){
                        case "round":
                            p = 5, n = "rect";
                            break;
                        case "square":
                            n = "rect";
                            break;
                        case "diamond":
                            n = "question";
                            break;
                        case "hexagon":
                            n = "hexagon";
                            break;
                        case "odd":
                            n = "rect_left_inv_arrow";
                            break;
                        case "lean_right":
                            n = "lean_right";
                            break;
                        case "lean_left":
                            n = "lean_left";
                            break;
                        case "trapezoid":
                            n = "trapezoid";
                            break;
                        case "inv_trapezoid":
                            n = "inv_trapezoid";
                            break;
                        case "odd_right":
                            n = "rect_left_inv_arrow";
                            break;
                        case "circle":
                            n = "circle";
                            break;
                        case "ellipse":
                            n = "ellipse";
                            break;
                        case "stadium":
                            n = "stadium";
                            break;
                        case "subroutine":
                            n = "subroutine";
                            break;
                        case "cylinder":
                            n = "cylinder";
                            break;
                        case "group":
                            n = "rect";
                            break;
                        case "doublecircle":
                            n = "doublecircle";
                            break;
                        default:
                            n = "rect";
                    }
                    return [
                        4,
                        Od(t, Vn())
                    ];
                case 3:
                    T = _state.sent();
                    l.setNode(r.id, {
                        labelStyle: w.labelStyle,
                        shape: n,
                        labelText: T,
                        labelType: r.labelType,
                        rx: p,
                        ry: p,
                        class: y,
                        style: w.style,
                        id: r.id,
                        link: r.link,
                        linkTarget: r.linkTarget,
                        tooltip: d.db.getTooltip(r.id) || "",
                        domId: d.db.lookUpDomId(r.id),
                        haveCallback: r.haveCallback,
                        width: r.type === "group" ? 500 : void 0,
                        dir: r.dir,
                        type: r.type,
                        props: r.props,
                        padding: Vn().flowchart.padding
                    }), L.info("setNode", {
                        labelStyle: w.labelStyle,
                        labelType: r.labelType,
                        shape: n,
                        labelText: T,
                        rx: p,
                        ry: p,
                        class: y,
                        style: w.style,
                        id: r.id,
                        domId: d.db.lookUpDomId(r.id),
                        width: r.type === "group" ? 500 : void 0,
                        type: r.type,
                        dir: r.dir,
                        props: r.props,
                        padding: Vn().flowchart.padding
                    });
                    _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 V(e, l, c, a, i, d) {
        return _ref.apply(this, arguments);
    };
}(), M = function() {
    var _ref = _async_to_generator(function(e, l, c) {
        var a, i, d, u, o, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, o1, f, r, y, w, t, s, p, n, err;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    L.info("abc78 edges = ", e);
                    a = 0, i = {};
                    if (e.defaultStyle !== void 0) {
                        o = B0(e.defaultStyle);
                        d = o.style, u = o.labelStyle;
                    }
                    _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                    _state.label = 1;
                case 1:
                    _state.trys.push([
                        1,
                        6,
                        7,
                        8
                    ]);
                    _iterator = e[Symbol.iterator]();
                    _state.label = 2;
                case 2:
                    if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
                        3,
                        5
                    ];
                    o1 = _step.value;
                    a++;
                    f = "L-" + o1.start + "-" + o1.end;
                    i[f] === void 0 ? (i[f] = 0, L.info("abc78 new entry", f, i[f])) : (i[f]++, L.info("abc78 new entry", f, i[f]));
                    r = f + "-" + i[f];
                    L.info("abc78 new link id to be used is", f, r, i[f]);
                    y = "LS-" + o1.start, w = "LE-" + o1.end, t = {
                        style: "",
                        labelStyle: ""
                    };
                    switch(t.minlen = o1.length || 1, o1.type === "arrow_open" ? t.arrowhead = "none" : t.arrowhead = "normal", t.arrowTypeStart = "arrow_open", t.arrowTypeEnd = "arrow_open", o1.type){
                        case "double_arrow_cross":
                            t.arrowTypeStart = "arrow_cross";
                        case "arrow_cross":
                            t.arrowTypeEnd = "arrow_cross";
                            break;
                        case "double_arrow_point":
                            t.arrowTypeStart = "arrow_point";
                        case "arrow_point":
                            t.arrowTypeEnd = "arrow_point";
                            break;
                        case "double_arrow_circle":
                            t.arrowTypeStart = "arrow_circle";
                        case "arrow_circle":
                            t.arrowTypeEnd = "arrow_circle";
                            break;
                    }
                    s = "", p = "";
                    switch(o1.stroke){
                        case "normal":
                            s = "fill:none;", d !== void 0 && (s = d), u !== void 0 && (p = u), t.thickness = "normal", t.pattern = "solid";
                            break;
                        case "dotted":
                            t.thickness = "normal", t.pattern = "dotted", t.style = "fill:none;stroke-width:2px;stroke-dasharray:3;";
                            break;
                        case "thick":
                            t.thickness = "thick", t.pattern = "solid", t.style = "stroke-width: 3.5px;fill:none;";
                            break;
                        case "invisible":
                            t.thickness = "invisible", t.pattern = "solid", t.style = "stroke-width: 0;fill:none;";
                            break;
                    }
                    if (o1.style !== void 0) {
                        n = B0(o1.style);
                        s = n.style, p = n.labelStyle;
                    }
                    t.style = t.style += s, t.labelStyle = t.labelStyle += p, o1.interpolate !== void 0 ? t.curve = x0(o1.interpolate, Df) : e.defaultInterpolate !== void 0 ? t.curve = x0(e.defaultInterpolate, Df) : t.curve = x0(P.curve, Df), o1.text === void 0 ? o1.style !== void 0 && (t.arrowheadStyle = "fill: #333") : (t.arrowheadStyle = "fill: #333", t.labelpos = "c"), t.labelType = o1.labelType;
                    return [
                        4,
                        Od(o1.text.replace($n.lineBreakRegex, "\n"), Vn())
                    ];
                case 3:
                    t.label = _state.sent(), o1.style === void 0 && (t.style = t.style || "stroke: #333; stroke-width: 1.5px;fill:none;"), t.labelStyle = t.labelStyle.replace("color:", "fill:"), t.id = r, t.classes = "flowchart-link " + y + " " + w, l.setEdge(o1.start, o1.end, t, a);
                    _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 M(e, l, c) {
        return _ref.apply(this, arguments);
    };
}(), le = function le(e, l) {
    return l.db.getClasses();
}, ae = function() {
    var _ref = _async_to_generator(function(e, l, c, a) {
        var i, _v, d, u, o, f, r, y, w, t, s, p, b, n, T, k, b1, _, $, b2, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, x, m, h;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    L.info("Drawing flowchart");
                    i = a.db.getDirection();
                    i === void 0 && (i = "TD");
                    _v = Vn(), d = _v.securityLevel, u = _v.flowchart, o = u.nodeSpacing || 50, f = u.rankSpacing || 50;
                    d === "sandbox" && (r = bt("#i" + l));
                    y = d === "sandbox" ? bt(r.nodes()[0].contentDocument.body) : bt("body"), w = d === "sandbox" ? r.nodes()[0].contentDocument : document, t = new Ze({
                        multigraph: true,
                        compound: true
                    }).setGraph({
                        rankdir: i,
                        nodesep: o,
                        ranksep: f,
                        marginx: 0,
                        marginy: 0
                    }).setDefaultEdgeLabel(function() {
                        return {};
                    });
                    p = a.db.getSubGraphs();
                    L.info("Subgraphs - ", p);
                    for(b = p.length - 1; b >= 0; b--)s = p[b], L.info("Subgraph - ", s), a.db.addVertex(s.id, {
                        text: s.title,
                        type: s.labelType
                    }, "group", void 0, s.classes, s.dir);
                    n = a.db.getVertices(), T = a.db.getEdges();
                    L.info("Edges", T);
                    k = 0;
                    for(k = p.length - 1; k >= 0; k--){
                        s = p[k], Z("cluster").append("text");
                        for(b1 = 0; b1 < s.nodes.length; b1++)L.info("Setting up subgraphs", s.nodes[b1], s.id), t.setParent(s.nodes[b1], s.id);
                    }
                    return [
                        4,
                        V(n, t, l, y, w, a)
                    ];
                case 1:
                    _state.sent();
                    return [
                        4,
                        M(T, t)
                    ];
                case 2:
                    _state.sent();
                    _ = y.select('[id="'.concat(l, '"]')), $ = y.select("#" + l + " g");
                    return [
                        4,
                        bt$1($, t, [
                            "point",
                            "circle",
                            "cross"
                        ], "flowchart", l)
                    ];
                case 3:
                    if (_state.sent(), ei.insertTitle(_, "flowchartTitleText", u.titleTopMargin, a.db.getDiagramTitle()), k_(t, _, u.diagramPadding, u.useMaxWidth), a.db.indexNodes("subGraph" + k), !u.htmlLabels) {
                        b2 = w.querySelectorAll('[id="' + l + '"] .edgeLabel .label');
                        _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                        try {
                            for(_iterator = b2[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                                x = _step.value;
                                m = x.getBBox(), h = w.createElementNS("http://www.w3.org/2000/svg", "rect");
                                h.setAttribute("rx", 0), h.setAttribute("ry", 0), h.setAttribute("width", m.width), h.setAttribute("height", m.height), x.insertBefore(h, x.firstChild);
                            }
                        } catch (err) {
                            _didIteratorError = true;
                            _iteratorError = err;
                        } finally{
                            try {
                                if (!_iteratorNormalCompletion && _iterator.return != null) {
                                    _iterator.return();
                                }
                            } finally{
                                if (_didIteratorError) {
                                    throw _iteratorError;
                                }
                            }
                        }
                    }
                    Object.keys(n).forEach(function(b) {
                        var x = n[b];
                        if (x.link) {
                            var m = bt("#" + l + ' [id="' + b + '"]');
                            if (m) {
                                var h = w.createElementNS("http://www.w3.org/2000/svg", "a");
                                h.setAttributeNS("http://www.w3.org/2000/svg", "class", x.classes.join(" ")), h.setAttributeNS("http://www.w3.org/2000/svg", "href", x.link), h.setAttributeNS("http://www.w3.org/2000/svg", "rel", "noopener"), d === "sandbox" ? h.setAttributeNS("http://www.w3.org/2000/svg", "target", "_top") : x.linkTarget && h.setAttributeNS("http://www.w3.org/2000/svg", "target", x.linkTarget);
                                var B = m.insert(function() {
                                    return h;
                                }, ":first-child"), I = m.select(".label-container");
                                I && B.append(function() {
                                    return I.node();
                                });
                                var D = m.select(".label");
                                D && B.append(function() {
                                    return D.node();
                                });
                            }
                        }
                    });
                    return [
                        2
                    ];
            }
        });
    });
    return function ae(e, l, c, a) {
        return _ref.apply(this, arguments);
    };
}(), we = {
    setConf: re,
    addVertices: V,
    addEdges: M,
    getClasses: le,
    draw: ae
}, ne = function(e$1, l) {
    var c = e, a = c(e$1, "r"), i = c(e$1, "g"), d = c(e$1, "b");
    return Je(a, i, d, l);
}, oe = function(e) {
    return ".label {\n    font-family: ".concat(e.fontFamily, ";\n    color: ").concat(e.nodeTextColor || e.textColor, ";\n  }\n  .cluster-label text {\n    fill: ").concat(e.titleColor, ";\n  }\n  .cluster-label span,p {\n    color: ").concat(e.titleColor, ";\n  }\n\n  .label text,span,p {\n    fill: ").concat(e.nodeTextColor || e.textColor, ";\n    color: ").concat(e.nodeTextColor || e.textColor, ";\n  }\n\n  .node rect,\n  .node circle,\n  .node ellipse,\n  .node polygon,\n  .node path {\n    fill: ").concat(e.mainBkg, ";\n    stroke: ").concat(e.nodeBorder, ";\n    stroke-width: 1px;\n  }\n  .flowchart-label text {\n    text-anchor: middle;\n  }\n  // .flowchart-label .text-outer-tspan {\n  //   text-anchor: middle;\n  // }\n  // .flowchart-label .text-inner-tspan {\n  //   text-anchor: start;\n  // }\n\n  .node .katex path {\n    fill: #000;\n    stroke: #000;\n    stroke-width: 1px;\n  }\n\n  .node .label {\n    text-align: center;\n  }\n  .node.clickable {\n    cursor: pointer;\n  }\n\n  .arrowheadPath {\n    fill: ").concat(e.arrowheadColor, ";\n  }\n\n  .edgePath .path {\n    stroke: ").concat(e.lineColor, ";\n    stroke-width: 2.0px;\n  }\n\n  .flowchart-link {\n    stroke: ").concat(e.lineColor, ";\n    fill: none;\n  }\n\n  .edgeLabel {\n    background-color: ").concat(e.edgeLabelBackground, ";\n    rect {\n      opacity: 0.5;\n      background-color: ").concat(e.edgeLabelBackground, ";\n      fill: ").concat(e.edgeLabelBackground, ";\n    }\n    text-align: center;\n  }\n\n  /* For html labels only */\n  .labelBkg {\n    background-color: ").concat(ne(e.edgeLabelBackground, 0.5), ";\n    // background-color: \n  }\n\n  .cluster rect {\n    fill: ").concat(e.clusterBkg, ";\n    stroke: ").concat(e.clusterBorder, ";\n    stroke-width: 1px;\n  }\n\n  .cluster text {\n    fill: ").concat(e.titleColor, ";\n  }\n\n  .cluster span,p {\n    color: ").concat(e.titleColor, ";\n  }\n  /* .cluster div {\n    color: ").concat(e.titleColor, ";\n  } */\n\n  div.mermaidTooltip {\n    position: absolute;\n    text-align: center;\n    max-width: 200px;\n    padding: 2px;\n    font-family: ").concat(e.fontFamily, ";\n    font-size: 12px;\n    background: ").concat(e.tertiaryColor, ";\n    border: 1px solid ").concat(e.border2, ";\n    border-radius: 2px;\n    pointer-events: none;\n    z-index: 100;\n  }\n\n  .flowchartTitleText {\n    text-anchor: middle;\n    font-size: 18px;\n    fill: ").concat(e.textColor, ";\n  }\n");
}, he = oe;

export { Z, be as b, ee as e, fe as f, he as h, pe as p, te as t, ue as u, we as w };
