import { Y as Yt, K as Kt, z as zt } from './styles-11e81fdd.esm.js';
import { g as ei, k as k_, a as L, V as Vn, b as bt, B as B0, x as x0, D as Df, $ as $n } from './index.esm2.js';
import { Z as Ze } from './graph-0ee63739.esm.js';
import { b as bt$1 } from './index-bb6d8841.esm.js';
import './layout-fd473db2.esm.js';
import './clone-afc2f047.esm.js';
import './edges-16357fde.esm.js';
import './createText-03b82060.esm.js';
import './line-24d93f1b.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 _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
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
        };
    }
}
var S = function(o) {
    return $n.sanitizeText(o, Vn());
};
var v = {
    dividerMargin: 10,
    padding: 5,
    textHeight: 10,
    curve: void 0
};
var P = function P(o, e, p, n) {
    var t = Object.keys(o);
    L.info("keys:", t), L.info(o), t.forEach(function(s) {
        var y, d;
        var _ref;
        var l = o[s], i = {
            shape: "rect",
            id: l.id,
            domId: l.domId,
            labelText: S(l.id),
            labelStyle: "",
            style: "fill: none; stroke: black",
            // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
            padding: (_ref = (y = Vn().flowchart) == null ? void 0 : y.padding) !== null && _ref !== void 0 ? _ref : (d = Vn().class) == null ? void 0 : d.padding
        };
        e.setNode(l.id, i), I(l.classes, e, p, n, l.id), L.info("setNode", i);
    });
}, I = function I(o, e, p, n, t) {
    var s = Object.keys(o);
    L.info("keys:", s), L.info(o), s.filter(function(l) {
        return o[l].parent == t;
    }).forEach(function(l) {
        var u, m;
        var _a_label, _ref;
        var a = o[l], i = a.cssClasses.join(" "), y = B0(a.styles), d = (_a_label = a.label) !== null && _a_label !== void 0 ? _a_label : a.id, f = 0, h = "class_box", b = {
            labelStyle: y.labelStyle,
            shape: h,
            labelText: S(d),
            classData: a,
            rx: f,
            ry: f,
            class: i,
            style: y.style,
            id: a.id,
            domId: a.domId,
            tooltip: n.db.getTooltip(a.id, t) || "",
            haveCallback: a.haveCallback,
            link: a.link,
            width: a.type === "group" ? 500 : void 0,
            type: a.type,
            // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
            padding: (_ref = (u = Vn().flowchart) == null ? void 0 : u.padding) !== null && _ref !== void 0 ? _ref : (m = Vn().class) == null ? void 0 : m.padding
        };
        e.setNode(a.id, b), t && e.setParent(a.id, t), L.info("setNode", b);
    });
}, F = function F(o, e, p, n) {
    L.info(o), o.forEach(function(t, s) {
        var m, g;
        var _ref;
        var l = t, a = "", i = {
            labelStyle: "",
            style: ""
        }, y = l.text, d = 0, f = "note", h = {
            labelStyle: i.labelStyle,
            shape: f,
            labelText: S(y),
            noteData: l,
            rx: d,
            ry: d,
            class: a,
            style: i.style,
            id: l.id,
            domId: l.id,
            tooltip: "",
            type: "note",
            // TODO V10: Flowchart ? Keeping flowchart for backwards compatibility. Remove in next major release
            padding: (_ref = (m = Vn().flowchart) == null ? void 0 : m.padding) !== null && _ref !== void 0 ? _ref : (g = Vn().class) == null ? void 0 : g.padding
        };
        if (e.setNode(l.id, h), L.info("setNode", h), !l.class || !(l.class in n)) return;
        var b = p + s, u = {
            id: "edgeNote".concat(b),
            //Set relationship style and line type
            classes: "relation",
            pattern: "dotted",
            // Set link type for rendering
            arrowhead: "none",
            //Set edge extra labels
            startLabelRight: "",
            endLabelLeft: "",
            //Set relation arrow types
            arrowTypeStart: "none",
            arrowTypeEnd: "none",
            style: "fill:none",
            labelStyle: "",
            curve: x0(v.curve, Df)
        };
        e.setEdge(l.id, l.class, u, b);
    });
}, H = function H(o, e) {
    var p = Vn().flowchart;
    var n = 0;
    o.forEach(function(t) {
        var l;
        n++;
        var s = {
            //Set relationship style and line type
            classes: "relation",
            pattern: t.relation.lineType == 1 ? "dashed" : "solid",
            id: "id_".concat(t.id1, "_").concat(t.id2, "_").concat(n),
            // Set link type for rendering
            arrowhead: t.type === "arrow_open" ? "none" : "normal",
            //Set edge extra labels
            startLabelRight: t.relationTitle1 === "none" ? "" : t.relationTitle1,
            endLabelLeft: t.relationTitle2 === "none" ? "" : t.relationTitle2,
            //Set relation arrow types
            arrowTypeStart: D(t.relation.type1),
            arrowTypeEnd: D(t.relation.type2),
            style: "fill:none",
            labelStyle: "",
            curve: x0(p == null ? void 0 : p.curve, Df)
        };
        if (L.info(s, t), t.style !== void 0) {
            var a = B0(t.style);
            s.style = a.style, s.labelStyle = a.labelStyle;
        }
        var _ref;
        t.text = t.title, t.text === void 0 ? t.style !== void 0 && (s.arrowheadStyle = "fill: #333") : (s.arrowheadStyle = "fill: #333", s.labelpos = "c", ((_ref = (l = Vn().flowchart) == null ? void 0 : l.htmlLabels) !== null && _ref !== void 0 ? _ref : Vn().htmlLabels) ? (s.labelType = "html", s.label = '<span class="edgeLabel">' + t.text + "</span>") : (s.labelType = "text", s.label = t.text.replace($n.lineBreakRegex, "\n"), t.style === void 0 && (s.style = s.style || "stroke: #333; stroke-width: 1.5px;fill:none"), s.labelStyle = s.labelStyle.replace("color:", "fill:"))), e.setEdge(t.id1, t.id2, s, n);
    });
}, V = function V(o) {
    v = _object_spread({}, v, o);
}, W = function() {
    var _ref = _async_to_generator(function(o, e, p, n) {
        var _r_flowchart, t, s, _ref, _ref1, l, a, i, y, d, f, h, b, u, m, g, _ref2, T, M, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, w, L$1, x;
        return _ts_generator(this, function(_state) {
            switch(_state.label){
                case 0:
                    L.info("Drawing class - ", e);
                    t = (_r_flowchart = Vn().flowchart) !== null && _r_flowchart !== void 0 ? _r_flowchart : Vn().class, s = Vn().securityLevel;
                    L.info("config:", t);
                    l = (_ref = t == null ? void 0 : t.nodeSpacing) !== null && _ref !== void 0 ? _ref : 50, a = (_ref1 = t == null ? void 0 : t.rankSpacing) !== null && _ref1 !== void 0 ? _ref1 : 50, i = new Ze({
                        multigraph: true,
                        compound: true
                    }).setGraph({
                        rankdir: n.db.getDirection(),
                        nodesep: l,
                        ranksep: a,
                        marginx: 8,
                        marginy: 8
                    }).setDefaultEdgeLabel(function() {
                        return {};
                    }), y = n.db.getNamespaces(), d = n.db.getClasses(), f = n.db.getRelations(), h = n.db.getNotes();
                    L.info(f), P(y, i, e, n), I(d, i, e, n), H(f, i), F(h, i, f.length + 1, d);
                    s === "sandbox" && (b = bt("#i" + e));
                    u = s === "sandbox" ? bt(b.nodes()[0].contentDocument.body) : bt("body"), m = u.select('[id="'.concat(e, '"]')), g = u.select("#" + e + " g");
                    return [
                        4,
                        bt$1(g, i, [
                            "aggregation",
                            "extension",
                            "composition",
                            "dependency",
                            "lollipop"
                        ], "classDiagram", e)
                    ];
                case 1:
                    if (_state.sent(), ei.insertTitle(m, "classTitleText", (_ref2 = t == null ? void 0 : t.titleTopMargin) !== null && _ref2 !== void 0 ? _ref2 : 5, n.db.getDiagramTitle()), k_(i, m, t == null ? void 0 : t.diagramPadding, t == null ? void 0 : t.useMaxWidth), !(t != null && t.htmlLabels)) {
                        T = s === "sandbox" ? b.nodes()[0].contentDocument : document, M = T.querySelectorAll('[id="' + e + '"] .edgeLabel .label');
                        _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                        try {
                            for(_iterator = M[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                                w = _step.value;
                                L$1 = w.getBBox(), x = T.createElementNS("http://www.w3.org/2000/svg", "rect");
                                x.setAttribute("rx", 0), x.setAttribute("ry", 0), x.setAttribute("width", L$1.width), x.setAttribute("height", L$1.height), w.insertBefore(x, w.firstChild);
                            }
                        } catch (err) {
                            _didIteratorError = true;
                            _iteratorError = err;
                        } finally{
                            try {
                                if (!_iteratorNormalCompletion && _iterator.return != null) {
                                    _iterator.return();
                                }
                            } finally{
                                if (_didIteratorError) {
                                    throw _iteratorError;
                                }
                            }
                        }
                    }
                    return [
                        2
                    ];
            }
        });
    });
    return function W(o, e, p, n) {
        return _ref.apply(this, arguments);
    };
}();
function D(o) {
    var e;
    switch(o){
        case 0:
            e = "aggregation";
            break;
        case 1:
            e = "extension";
            break;
        case 2:
            e = "composition";
            break;
        case 3:
            e = "dependency";
            break;
        case 4:
            e = "lollipop";
            break;
        default:
            e = "none";
    }
    return e;
}
var J = {
    setConf: V,
    draw: W
}, ot = {
    parser: zt,
    db: Kt,
    renderer: J,
    styles: Yt,
    init: function(o) {
        o.class || (o.class = {}), o.class.arrowMarkerAbsolute = o.arrowMarkerAbsolute, Kt.clear();
    }
};

export { ot as diagram };
