import { M as M_, l as O_, L as L_, E as E_, F as F_, A as A_, V as Vn, aq as w1, b as bt, k as k_, m as B_, $ as $n } from './index.esm2.js';
import { h } from './ordinal-5695958c.esm.js';
import { r } from './Tableau10-558cc280.esm.js';
import './init-f9637058.esm.js';

function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var tt = function() {
    var t = function t(m, i, o, c) {
        for(o = o || {}, c = m.length; c--; o[m[c]] = i);
        return o;
    }, n = [
        1,
        9
    ], s = [
        1,
        10
    ], a = [
        1,
        5,
        10,
        12
    ], u = {
        trace: function trace() {},
        yy: {},
        symbols_: {
            error: 2,
            start: 3,
            SANKEY: 4,
            NEWLINE: 5,
            csv: 6,
            opt_eof: 7,
            record: 8,
            csv_tail: 9,
            EOF: 10,
            "field[source]": 11,
            COMMA: 12,
            "field[target]": 13,
            "field[value]": 14,
            field: 15,
            escaped: 16,
            non_escaped: 17,
            DQUOTE: 18,
            ESCAPED_TEXT: 19,
            NON_ESCAPED_TEXT: 20,
            $accept: 0,
            $end: 1
        },
        terminals_: {
            2: "error",
            4: "SANKEY",
            5: "NEWLINE",
            10: "EOF",
            11: "field[source]",
            12: "COMMA",
            13: "field[target]",
            14: "field[value]",
            18: "DQUOTE",
            19: "ESCAPED_TEXT",
            20: "NON_ESCAPED_TEXT"
        },
        productions_: [
            0,
            [
                3,
                4
            ],
            [
                6,
                2
            ],
            [
                9,
                2
            ],
            [
                9,
                0
            ],
            [
                7,
                1
            ],
            [
                7,
                0
            ],
            [
                8,
                5
            ],
            [
                15,
                1
            ],
            [
                15,
                1
            ],
            [
                16,
                3
            ],
            [
                17,
                1
            ]
        ],
        performAction: function performAction(i, o, c, k, b, d, x) {
            var E = d.length - 1;
            switch(b){
                case 7:
                    var L = k.findOrCreateNode(d[E - 4].trim().replaceAll('""', '"')), A = k.findOrCreateNode(d[E - 2].trim().replaceAll('""', '"')), N = parseFloat(d[E].trim());
                    k.addLink(L, A, N);
                    break;
                case 8:
                case 9:
                case 11:
                    this.$ = d[E];
                    break;
                case 10:
                    this.$ = d[E - 1];
                    break;
            }
        },
        table: [
            {
                3: 1,
                4: [
                    1,
                    2
                ]
            },
            {
                1: [
                    3
                ]
            },
            {
                5: [
                    1,
                    3
                ]
            },
            {
                6: 4,
                8: 5,
                15: 6,
                16: 7,
                17: 8,
                18: n,
                20: s
            },
            {
                1: [
                    2,
                    6
                ],
                7: 11,
                10: [
                    1,
                    12
                ]
            },
            t(s, [
                2,
                4
            ], {
                9: 13,
                5: [
                    1,
                    14
                ]
            }),
            {
                12: [
                    1,
                    15
                ]
            },
            t(a, [
                2,
                8
            ]),
            t(a, [
                2,
                9
            ]),
            {
                19: [
                    1,
                    16
                ]
            },
            t(a, [
                2,
                11
            ]),
            {
                1: [
                    2,
                    1
                ]
            },
            {
                1: [
                    2,
                    5
                ]
            },
            t(s, [
                2,
                2
            ]),
            {
                6: 17,
                8: 5,
                15: 6,
                16: 7,
                17: 8,
                18: n,
                20: s
            },
            {
                15: 18,
                16: 7,
                17: 8,
                18: n,
                20: s
            },
            {
                18: [
                    1,
                    19
                ]
            },
            t(s, [
                2,
                3
            ]),
            {
                12: [
                    1,
                    20
                ]
            },
            t(a, [
                2,
                10
            ]),
            {
                15: 21,
                16: 7,
                17: 8,
                18: n,
                20: s
            },
            t([
                1,
                5,
                10
            ], [
                2,
                7
            ])
        ],
        defaultActions: {
            11: [
                2,
                1
            ],
            12: [
                2,
                5
            ]
        },
        parseError: function parseError(i, o) {
            if (o.recoverable) this.trace(i);
            else {
                var c = new Error(i);
                throw c.hash = o, c;
            }
        },
        parse: function parse(i) {
            var o = this, c = [
                0
            ], k = [], b = [
                null
            ], d = [], x = this.table, E = "", L = 0, A = 0, N = 2, C = 1, j = d.slice.call(arguments, 1), S = Object.create(this.lexer), M = {
                yy: {}
            };
            for(var $ in this.yy)Object.prototype.hasOwnProperty.call(this.yy, $) && (M.yy[$] = this.yy[$]);
            S.setInput(i, M.yy), M.yy.lexer = S, M.yy.parser = this, _type_of(S.yylloc) > "u" && (S.yylloc = {});
            var P = S.yylloc;
            d.push(P);
            var I = S.options && S.options.ranges;
            typeof M.yy.parseError == "function" ? this.parseError = M.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
            function g() {
                var v;
                return v = k.pop() || S.lex() || C, typeof v != "number" && (_instanceof(v, Array) && (k = v, v = k.pop()), v = o.symbols_[v] || v), v;
            }
            for(var w, O, T, V, e = {}, f, l, h, r;;){
                if (O = c[c.length - 1], this.defaultActions[O] ? T = this.defaultActions[O] : ((w === null || (typeof w === "undefined" ? "undefined" : _type_of(w)) > "u") && (w = g()), T = x[O] && x[O][w]), (typeof T === "undefined" ? "undefined" : _type_of(T)) > "u" || !T.length || !T[0]) {
                    var _ = "";
                    r = [];
                    for(f in x[O])this.terminals_[f] && f > N && r.push("'" + this.terminals_[f] + "'");
                    S.showPosition ? _ = "Parse error on line " + (L + 1) + ":\n" + S.showPosition() + "\nExpecting " + r.join(", ") + ", got '" + (this.terminals_[w] || w) + "'" : _ = "Parse error on line " + (L + 1) + ": Unexpected " + (w == C ? "end of input" : "'" + (this.terminals_[w] || w) + "'"), this.parseError(_, {
                        text: S.match,
                        token: this.terminals_[w] || w,
                        line: S.yylineno,
                        loc: P,
                        expected: r
                    });
                }
                if (_instanceof(T[0], Array) && T.length > 1) throw new Error("Parse Error: multiple actions possible at state: " + O + ", token: " + w);
                switch(T[0]){
                    case 1:
                        c.push(w), b.push(S.yytext), d.push(S.yylloc), c.push(T[1]), w = null, A = S.yyleng, E = S.yytext, L = S.yylineno, P = S.yylloc;
                        break;
                    case 2:
                        if (l = this.productions_[T[1]][1], e.$ = b[b.length - l], e._$ = {
                            first_line: d[d.length - (l || 1)].first_line,
                            last_line: d[d.length - 1].last_line,
                            first_column: d[d.length - (l || 1)].first_column,
                            last_column: d[d.length - 1].last_column
                        }, I && (e._$.range = [
                            d[d.length - (l || 1)].range[0],
                            d[d.length - 1].range[1]
                        ]), V = this.performAction.apply(e, [
                            E,
                            A,
                            L,
                            M.yy,
                            T[1],
                            b,
                            d
                        ].concat(j)), (typeof V === "undefined" ? "undefined" : _type_of(V)) < "u") return V;
                        l && (c = c.slice(0, -1 * l * 2), b = b.slice(0, -1 * l), d = d.slice(0, -1 * l)), c.push(this.productions_[T[1]][0]), b.push(e.$), d.push(e._$), h = x[c[c.length - 2]][c[c.length - 1]], c.push(h);
                        break;
                    case 3:
                        return true;
                }
            }
            return true;
        }
    }, y = function() {
        var m = {
            EOF: 1,
            parseError: function parseError(o, c) {
                if (this.yy.parser) this.yy.parser.parseError(o, c);
                else throw new Error(o);
            },
            // resets the lexer, sets new input
            setInput: function setInput(i, o) {
                return this.yy = o || this.yy || {}, this._input = i, this._more = this._backtrack = this.done = false, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = [
                    "INITIAL"
                ], this.yylloc = {
                    first_line: 1,
                    first_column: 0,
                    last_line: 1,
                    last_column: 0
                }, this.options.ranges && (this.yylloc.range = [
                    0,
                    0
                ]), this.offset = 0, this;
            },
            // consumes and returns one char from the input
            input: function input() {
                var i = this._input[0];
                this.yytext += i, this.yyleng++, this.offset++, this.match += i, this.matched += i;
                var o = i.match(/(?:\r\n?|\n).*/g);
                return o ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), i;
            },
            // unshifts one char (or a string) into the input
            unput: function unput(i) {
                var o = i.length, c = i.split(/(?:\r\n?|\n)/g);
                this._input = i + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - o), this.offset -= o;
                var k = this.match.split(/(?:\r\n?|\n)/g);
                this.match = this.match.substr(0, this.match.length - 1), this.matched = this.matched.substr(0, this.matched.length - 1), c.length - 1 && (this.yylineno -= c.length - 1);
                var b = this.yylloc.range;
                return this.yylloc = {
                    first_line: this.yylloc.first_line,
                    last_line: this.yylineno + 1,
                    first_column: this.yylloc.first_column,
                    last_column: c ? (c.length === k.length ? this.yylloc.first_column : 0) + k[k.length - c.length].length - c[0].length : this.yylloc.first_column - o
                }, this.options.ranges && (this.yylloc.range = [
                    b[0],
                    b[0] + this.yyleng - o
                ]), this.yyleng = this.yytext.length, this;
            },
            // When called from action, caches matched text and appends it on next action
            more: function more() {
                return this._more = true, this;
            },
            // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
            reject: function reject() {
                if (this.options.backtrack_lexer) this._backtrack = true;
                else return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
                    text: "",
                    token: null,
                    line: this.yylineno
                });
                return this;
            },
            // retain first n characters of the match
            less: function less(i) {
                this.unput(this.match.slice(i));
            },
            // displays already matched input, i.e. for error messages
            pastInput: function pastInput() {
                var i = this.matched.substr(0, this.matched.length - this.match.length);
                return (i.length > 20 ? "..." : "") + i.substr(-20).replace(/\n/g, "");
            },
            // displays upcoming input, i.e. for error messages
            upcomingInput: function upcomingInput() {
                var i = this.match;
                return i.length < 20 && (i += this._input.substr(0, 20 - i.length)), (i.substr(0, 20) + (i.length > 20 ? "..." : "")).replace(/\n/g, "");
            },
            // displays the character position where the lexing error occurred, i.e. for error messages
            showPosition: function showPosition() {
                var i = this.pastInput(), o = new Array(i.length + 1).join("-");
                return i + this.upcomingInput() + "\n" + o + "^";
            },
            // test the lexed token: return FALSE when not a match, otherwise return token
            test_match: function test_match(i, o) {
                var c, k, b;
                if (this.options.backtrack_lexer && (b = {
                    yylineno: this.yylineno,
                    yylloc: {
                        first_line: this.yylloc.first_line,
                        last_line: this.last_line,
                        first_column: this.yylloc.first_column,
                        last_column: this.yylloc.last_column
                    },
                    yytext: this.yytext,
                    match: this.match,
                    matches: this.matches,
                    matched: this.matched,
                    yyleng: this.yyleng,
                    offset: this.offset,
                    _more: this._more,
                    _input: this._input,
                    yy: this.yy,
                    conditionStack: this.conditionStack.slice(0),
                    done: this.done
                }, this.options.ranges && (b.yylloc.range = this.yylloc.range.slice(0))), k = i[0].match(/(?:\r\n?|\n).*/g), k && (this.yylineno += k.length), this.yylloc = {
                    first_line: this.yylloc.last_line,
                    last_line: this.yylineno + 1,
                    first_column: this.yylloc.last_column,
                    last_column: k ? k[k.length - 1].length - k[k.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + i[0].length
                }, this.yytext += i[0], this.match += i[0], this.matches = i, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [
                    this.offset,
                    this.offset += this.yyleng
                ]), this._more = false, this._backtrack = false, this._input = this._input.slice(i[0].length), this.matched += i[0], c = this.performAction.call(this, this.yy, this, o, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = false), c) return c;
                if (this._backtrack) {
                    for(var d in b)this[d] = b[d];
                    return false;
                }
                return false;
            },
            // return next match in input
            next: function next() {
                if (this.done) return this.EOF;
                this._input || (this.done = true);
                var i, o, c, k;
                this._more || (this.yytext = "", this.match = "");
                for(var b = this._currentRules(), d = 0; d < b.length; d++)if (c = this._input.match(this.rules[b[d]]), c && (!o || c[0].length > o[0].length)) {
                    if (o = c, k = d, this.options.backtrack_lexer) {
                        if (i = this.test_match(c, b[d]), i !== false) return i;
                        if (this._backtrack) {
                            o = false;
                            continue;
                        } else return false;
                    } else if (!this.options.flex) break;
                }
                return o ? (i = this.test_match(o, b[k]), i !== false ? i : false) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
                    text: "",
                    token: null,
                    line: this.yylineno
                });
            },
            // return next match that has a token
            lex: function lex() {
                var o = this.next();
                return o || this.lex();
            },
            // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
            begin: function begin(o) {
                this.conditionStack.push(o);
            },
            // pop the previously active lexer condition state off the condition stack
            popState: function popState() {
                var o = this.conditionStack.length - 1;
                return o > 0 ? this.conditionStack.pop() : this.conditionStack[0];
            },
            // produce the lexer rule set which is active for the currently active lexer condition state
            _currentRules: function _currentRules() {
                return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
            },
            // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
            topState: function topState(o) {
                return o = this.conditionStack.length - 1 - Math.abs(o || 0), o >= 0 ? this.conditionStack[o] : "INITIAL";
            },
            // alias for begin(condition)
            pushState: function pushState(o) {
                this.begin(o);
            },
            // return the number of states currently on the stack
            stateStackSize: function stateStackSize() {
                return this.conditionStack.length;
            },
            options: {
                "case-insensitive": true
            },
            performAction: function performAction(o, c, k, b) {
                switch(k){
                    case 0:
                        return this.pushState("csv"), 4;
                    case 1:
                        return 10;
                    case 2:
                        return 5;
                    case 3:
                        return 12;
                    case 4:
                        return this.pushState("escaped_text"), 18;
                    case 5:
                        return 20;
                    case 6:
                        return this.popState("escaped_text"), 18;
                    case 7:
                        return 19;
                }
            },
            rules: [
                /^(?:sankey-beta\b)/i,
                /^(?:$)/i,
                /^(?:((\u000D\u000A)|(\u000A)))/i,
                /^(?:(\u002C))/i,
                /^(?:(\u0022))/i,
                /^(?:([\u0020-\u0021\u0023-\u002B\u002D-\u007E])*)/i,
                /^(?:(\u0022)(?!(\u0022)))/i,
                /^(?:(([\u0020-\u0021\u0023-\u002B\u002D-\u007E])|(\u002C)|(\u000D)|(\u000A)|(\u0022)(\u0022))*)/i
            ],
            conditions: {
                csv: {
                    rules: [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7
                    ],
                    inclusive: false
                },
                escaped_text: {
                    rules: [
                        6,
                        7
                    ],
                    inclusive: false
                },
                INITIAL: {
                    rules: [
                        0,
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7
                    ],
                    inclusive: true
                }
            }
        };
        return m;
    }();
    u.lexer = y;
    function p() {
        this.yy = {};
    }
    return p.prototype = u, u.Parser = p, new p();
}();
tt.parser = tt;
var H = tt;
var q = [], Q = [], B = {};
var Mt = function() {
    q = [], Q = [], B = {}, B_();
};
var Nt = function Nt(n, s) {
    var a = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
    _class_call_check(this, Nt);
    this.source = n, this.target = s, this.value = a;
};
var Ct = function(t, n, s) {
    q.push(new Nt(t, n, s));
};
var Pt = function Pt(n) {
    _class_call_check(this, Pt);
    this.ID = n;
};
var It = function(t) {
    return t = $n.sanitizeText(t, Vn()), B[t] || (B[t] = new Pt(t), Q.push(B[t])), B[t];
}, Ot = function() {
    return Q;
}, $t = function() {
    return q;
}, jt = function() {
    return {
        nodes: Q.map(function(t) {
            return {
                id: t.ID
            };
        }),
        links: q.map(function(t) {
            return {
                source: t.source.ID,
                target: t.target.ID,
                value: t.value
            };
        })
    };
}, zt = {
    nodesMap: B,
    getConfig: function() {
        return Vn().sankey;
    },
    getNodes: Ot,
    getLinks: $t,
    getGraph: jt,
    addLink: Ct,
    findOrCreateNode: It,
    getAccTitle: A_,
    setAccTitle: F_,
    getAccDescription: E_,
    setAccDescription: L_,
    getDiagramTitle: O_,
    setDiagramTitle: M_,
    clear: Mt
};
function ot(t, n) {
    var s;
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    if (n === void 0) try {
        for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var a = _step.value;
            a != null && (s < a || s === void 0 && a >= a) && (s = a);
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
    else {
        var a1 = -1;
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = t[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var u = _step1.value;
                (u = n(u, ++a1, t)) != null && (s < u || s === void 0 && u >= u) && (s = u);
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
    }
    return s;
}
function yt(t, n) {
    var s;
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    if (n === void 0) try {
        for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var a = _step.value;
            a != null && (s > a || s === void 0 && a >= a) && (s = a);
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
    else {
        var a1 = -1;
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = t[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var u = _step1.value;
                (u = n(u, ++a1, t)) != null && (s > u || s === void 0 && u >= u) && (s = u);
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
    }
    return s;
}
function Z(t, n) {
    var s = 0;
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    if (n === void 0) try {
        for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var a = _step.value;
            (a = +a) && (s += a);
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
    else {
        var a1 = -1;
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = t[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var u = _step1.value;
                (u = +n(u, ++a1, t)) && (s += u);
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
    }
    return s;
}
function Dt(t) {
    return t.target.depth;
}
function Bt(t) {
    return t.depth;
}
function Vt(t, n) {
    return n - 1 - t.height;
}
function dt(t, n) {
    return t.sourceLinks.length ? t.depth : n - 1;
}
function Rt(t) {
    return t.targetLinks.length ? t.depth : t.sourceLinks.length ? yt(t.sourceLinks, Dt) - 1 : 0;
}
function Y(t) {
    return function() {
        return t;
    };
}
function lt(t, n) {
    return X(t.source, n.source) || t.index - n.index;
}
function at(t, n) {
    return X(t.target, n.target) || t.index - n.index;
}
function X(t, n) {
    return t.y0 - n.y0;
}
function J(t) {
    return t.value;
}
function Ut(t) {
    return t.index;
}
function Ft(t) {
    return t.nodes;
}
function Wt(t) {
    return t.links;
}
function ct(t, n) {
    var s = t.get(n);
    if (!s) throw new Error("missing: " + n);
    return s;
}
function ut(param) {
    var t = param.nodes;
    var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
    try {
        for(var _iterator = t[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
            var n = _step.value;
            var s = n.y0, a = s;
            var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
            try {
                for(var _iterator1 = n.sourceLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                    var u = _step1.value;
                    u.y0 = s + u.width / 2, s += u.width;
                }
            } catch (err) {
                _didIteratorError1 = true;
                _iteratorError1 = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                        _iterator1.return();
                    }
                } finally{
                    if (_didIteratorError1) {
                        throw _iteratorError1;
                    }
                }
            }
            var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
            try {
                for(var _iterator2 = n.targetLinks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
                    var u1 = _step2.value;
                    u1.y1 = a + u1.width / 2, a += u1.width;
                }
            } catch (err) {
                _didIteratorError2 = true;
                _iteratorError2 = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
                        _iterator2.return();
                    }
                } finally{
                    if (_didIteratorError2) {
                        throw _iteratorError2;
                    }
                }
            }
        }
    } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
    } finally{
        try {
            if (!_iteratorNormalCompletion && _iterator.return != null) {
                _iterator.return();
            }
        } finally{
            if (_didIteratorError) {
                throw _iteratorError;
            }
        }
    }
}
function Gt() {
    var t = 0, n = 0, s = 1, a = 1, u = 24, y = 8, p, m = Ut, i = dt, o, c, k = Ft, b = Wt, d = 6;
    function x() {
        var e = {
            nodes: k.apply(null, arguments),
            links: b.apply(null, arguments)
        };
        return E(e), L(e), A(e), N(e), S(e), ut(e), e;
    }
    x.update = function(e) {
        return ut(e), e;
    }, x.nodeId = function(e) {
        return arguments.length ? (m = typeof e == "function" ? e : Y(e), x) : m;
    }, x.nodeAlign = function(e) {
        return arguments.length ? (i = typeof e == "function" ? e : Y(e), x) : i;
    }, x.nodeSort = function(e) {
        return arguments.length ? (o = e, x) : o;
    }, x.nodeWidth = function(e) {
        return arguments.length ? (u = +e, x) : u;
    }, x.nodePadding = function(e) {
        return arguments.length ? (y = p = +e, x) : y;
    }, x.nodes = function(e) {
        return arguments.length ? (k = typeof e == "function" ? e : Y(e), x) : k;
    }, x.links = function(e) {
        return arguments.length ? (b = typeof e == "function" ? e : Y(e), x) : b;
    }, x.linkSort = function(e) {
        return arguments.length ? (c = e, x) : c;
    }, x.size = function(e) {
        return arguments.length ? (t = n = 0, s = +e[0], a = +e[1], x) : [
            s - t,
            a - n
        ];
    }, x.extent = function(e) {
        return arguments.length ? (t = +e[0][0], s = +e[1][0], n = +e[0][1], a = +e[1][1], x) : [
            [
                t,
                n
            ],
            [
                s,
                a
            ]
        ];
    }, x.iterations = function(e) {
        return arguments.length ? (d = +e, x) : d;
    };
    function E(param) {
        var e = param.nodes, f = param.links;
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = e.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var _step_value = _sliced_to_array(_step.value, 2), h = _step_value[0], r = _step_value[1];
                r.index = h, r.sourceLinks = [], r.targetLinks = [];
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        var l = new Map(e.map(function(h, r) {
            return [
                m(h, r, e),
                h
            ];
        }));
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = f.entries()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var _step_value1 = _sliced_to_array(_step1.value, 2), h1 = _step_value1[0], r1 = _step_value1[1];
                r1.index = h1;
                var _ = r1.source, v = r1.target;
                (typeof _ === "undefined" ? "undefined" : _type_of(_)) != "object" && (_ = r1.source = ct(l, _)), (typeof v === "undefined" ? "undefined" : _type_of(v)) != "object" && (v = r1.target = ct(l, v)), _.sourceLinks.push(r1), v.targetLinks.push(r1);
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
        var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
        if (c != null) try {
            for(var _iterator2 = e[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
                var _step_value2 = _step2.value, h2 = _step_value2.sourceLinks, r2 = _step_value2.targetLinks;
                h2.sort(c), r2.sort(c);
            }
        } catch (err) {
            _didIteratorError2 = true;
            _iteratorError2 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
                    _iterator2.return();
                }
            } finally{
                if (_didIteratorError2) {
                    throw _iteratorError2;
                }
            }
        }
    }
    function L(param) {
        var e = param.nodes;
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = e[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var f = _step.value;
                f.value = f.fixedValue === void 0 ? Math.max(Z(f.sourceLinks, J), Z(f.targetLinks, J)) : f.fixedValue;
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
    }
    function A(param) {
        var e = param.nodes;
        var f = e.length;
        var l = new Set(e), h = /* @__PURE__ */ new Set(), r = 0;
        for(; l.size;){
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = l[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var _ = _step.value;
                    _.depth = r;
                    var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                    try {
                        for(var _iterator1 = _.sourceLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                            var _step_value = _step1.value, v = _step_value.target;
                            h.add(v);
                        }
                    } catch (err) {
                        _didIteratorError1 = true;
                        _iteratorError1 = err;
                    } finally{
                        try {
                            if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                                _iterator1.return();
                            }
                        } finally{
                            if (_didIteratorError1) {
                                throw _iteratorError1;
                            }
                        }
                    }
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            if (++r > f) throw new Error("circular link");
            l = h, h = /* @__PURE__ */ new Set();
        }
    }
    function N(param) {
        var e = param.nodes;
        var f = e.length;
        var l = new Set(e), h = /* @__PURE__ */ new Set(), r = 0;
        for(; l.size;){
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = l[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var _ = _step.value;
                    _.height = r;
                    var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                    try {
                        for(var _iterator1 = _.targetLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                            var _step_value = _step1.value, v = _step_value.source;
                            h.add(v);
                        }
                    } catch (err) {
                        _didIteratorError1 = true;
                        _iteratorError1 = err;
                    } finally{
                        try {
                            if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                                _iterator1.return();
                            }
                        } finally{
                            if (_didIteratorError1) {
                                throw _iteratorError1;
                            }
                        }
                    }
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            if (++r > f) throw new Error("circular link");
            l = h, h = /* @__PURE__ */ new Set();
        }
    }
    function C(param) {
        var e = param.nodes;
        var f = ot(e, function(r) {
            return r.depth;
        }) + 1, l = (s - t - u) / (f - 1), h = new Array(f);
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = e[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var r = _step.value;
                var _ = Math.max(0, Math.min(f - 1, Math.floor(i.call(null, r, f))));
                r.layer = _, r.x0 = t + _ * l, r.x1 = r.x0 + u, h[_] ? h[_].push(r) : h[_] = [
                    r
                ];
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        if (o) try {
            for(var _iterator1 = h[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var r1 = _step1.value;
                r1.sort(o);
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
        return h;
    }
    function j(e) {
        var f = yt(e, function(l) {
            return (a - n - (l.length - 1) * p) / Z(l, J);
        });
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = e[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var l = _step.value;
                var h = n;
                var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                try {
                    for(var _iterator1 = l[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                        var r = _step1.value;
                        r.y0 = h, r.y1 = h + r.value * f, h = r.y1 + p;
                        var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
                        try {
                            for(var _iterator2 = r.sourceLinks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
                                var _ = _step2.value;
                                _.width = _.value * f;
                            }
                        } catch (err) {
                            _didIteratorError2 = true;
                            _iteratorError2 = err;
                        } finally{
                            try {
                                if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
                                    _iterator2.return();
                                }
                            } finally{
                                if (_didIteratorError2) {
                                    throw _iteratorError2;
                                }
                            }
                        }
                    }
                } catch (err) {
                    _didIteratorError1 = true;
                    _iteratorError1 = err;
                } finally{
                    try {
                        if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                            _iterator1.return();
                        }
                    } finally{
                        if (_didIteratorError1) {
                            throw _iteratorError1;
                        }
                    }
                }
                h = (a - h + p) / (l.length + 1);
                for(var r1 = 0; r1 < l.length; ++r1){
                    var _1 = l[r1];
                    _1.y0 += h * (r1 + 1), _1.y1 += h * (r1 + 1);
                }
                O(l);
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
    }
    function S(e) {
        var f = C(e);
        p = Math.min(y, (a - n) / (ot(f, function(l) {
            return l.length;
        }) - 1)), j(f);
        for(var l = 0; l < d; ++l){
            var h = Math.pow(0.99, l), r = Math.max(1 - h, (l + 1) / d);
            $(f, h, r), M(f, h, r);
        }
    }
    function M(e, f, l) {
        for(var h = 1, r = e.length; h < r; ++h){
            var _ = e[h];
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = _[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var v = _step.value;
                    var R = 0, z = 0;
                    var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                    try {
                        for(var _iterator1 = v.targetLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                            var _step_value = _step1.value, F = _step_value.source, K = _step_value.value;
                            var W = K * (v.layer - F.layer);
                            R += T(F, v) * W, z += W;
                        }
                    } catch (err) {
                        _didIteratorError1 = true;
                        _iteratorError1 = err;
                    } finally{
                        try {
                            if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                                _iterator1.return();
                            }
                        } finally{
                            if (_didIteratorError1) {
                                throw _iteratorError1;
                            }
                        }
                    }
                    if (!(z > 0)) continue;
                    var U = (R / z - v.y0) * f;
                    v.y0 += U, v.y1 += U, w(v);
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            o === void 0 && _.sort(X), P(_, l);
        }
    }
    function $(e, f, l) {
        for(var h = e.length, r = h - 2; r >= 0; --r){
            var _ = e[r];
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = _[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var v = _step.value;
                    var R = 0, z = 0;
                    var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
                    try {
                        for(var _iterator1 = v.sourceLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                            var _step_value = _step1.value, F = _step_value.target, K = _step_value.value;
                            var W = K * (F.layer - v.layer);
                            R += V(v, F) * W, z += W;
                        }
                    } catch (err) {
                        _didIteratorError1 = true;
                        _iteratorError1 = err;
                    } finally{
                        try {
                            if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                                _iterator1.return();
                            }
                        } finally{
                            if (_didIteratorError1) {
                                throw _iteratorError1;
                            }
                        }
                    }
                    if (!(z > 0)) continue;
                    var U = (R / z - v.y0) * f;
                    v.y0 += U, v.y1 += U, w(v);
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            o === void 0 && _.sort(X), P(_, l);
        }
    }
    function P(e, f) {
        var l = e.length >> 1, h = e[l];
        g(e, h.y0 - p, l - 1, f), I(e, h.y1 + p, l + 1, f), g(e, a, e.length - 1, f), I(e, n, 0, f);
    }
    function I(e, f, l, h) {
        for(; l < e.length; ++l){
            var r = e[l], _ = (f - r.y0) * h;
            _ > 1e-6 && (r.y0 += _, r.y1 += _), f = r.y1 + p;
        }
    }
    function g(e, f, l, h) {
        for(; l >= 0; --l){
            var r = e[l], _ = (r.y1 - f) * h;
            _ > 1e-6 && (r.y0 -= _, r.y1 -= _), f = r.y0 - p;
        }
    }
    function w(param) {
        var e = param.sourceLinks, f = param.targetLinks;
        if (c === void 0) {
            var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
            try {
                for(var _iterator = f[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                    var _step_value = _step.value, _step_value_source = _step_value.source, l = _step_value_source.sourceLinks;
                    l.sort(at);
                }
            } catch (err) {
                _didIteratorError = true;
                _iteratorError = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                        _iterator.return();
                    }
                } finally{
                    if (_didIteratorError) {
                        throw _iteratorError;
                    }
                }
            }
            var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
            try {
                for(var _iterator1 = e[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                    var _step_value1 = _step1.value, _step_value_target = _step_value1.target, l1 = _step_value_target.targetLinks;
                    l1.sort(lt);
                }
            } catch (err) {
                _didIteratorError1 = true;
                _iteratorError1 = err;
            } finally{
                try {
                    if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                        _iterator1.return();
                    }
                } finally{
                    if (_didIteratorError1) {
                        throw _iteratorError1;
                    }
                }
            }
        }
    }
    function O(e) {
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        if (c === void 0) try {
            for(var _iterator = e[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var _step_value = _step.value, f = _step_value.sourceLinks, l = _step_value.targetLinks;
                f.sort(at), l.sort(lt);
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
    }
    function T(e, f) {
        var l = e.y0 - (e.sourceLinks.length - 1) * p / 2;
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = e.sourceLinks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var _step_value = _step.value, h = _step_value.target, r = _step_value.width;
                if (h === f) break;
                l += r + p;
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = f.targetLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var _step_value1 = _step1.value, h1 = _step_value1.source, r1 = _step_value1.width;
                if (h1 === e) break;
                l -= r1;
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
        return l;
    }
    function V(e, f) {
        var l = f.y0 - (f.targetLinks.length - 1) * p / 2;
        var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
        try {
            for(var _iterator = f.targetLinks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
                var _step_value = _step.value, h = _step_value.source, r = _step_value.width;
                if (h === e) break;
                l += r + p;
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion && _iterator.return != null) {
                    _iterator.return();
                }
            } finally{
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
        try {
            for(var _iterator1 = e.sourceLinks[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
                var _step_value1 = _step1.value, h1 = _step_value1.target, r1 = _step_value1.width;
                if (h1 === f) break;
                l -= r1;
            }
        } catch (err) {
            _didIteratorError1 = true;
            _iteratorError1 = err;
        } finally{
            try {
                if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
                    _iterator1.return();
                }
            } finally{
                if (_didIteratorError1) {
                    throw _iteratorError1;
                }
            }
        }
        return l;
    }
    return x;
}
var et = Math.PI, nt = 2 * et, D = 1e-6, Yt = nt - D;
function it() {
    this._x0 = this._y0 = this._x1 = this._y1 = null, this._ = "";
}
function gt() {
    return new it();
}
it.prototype = gt.prototype = {
    constructor: it,
    moveTo: function moveTo(t, n) {
        this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +n);
    },
    closePath: function closePath() {
        this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._ += "Z");
    },
    lineTo: function lineTo(t, n) {
        this._ += "L" + (this._x1 = +t) + "," + (this._y1 = +n);
    },
    quadraticCurveTo: function quadraticCurveTo(t, n, s, a) {
        this._ += "Q" + +t + "," + +n + "," + (this._x1 = +s) + "," + (this._y1 = +a);
    },
    bezierCurveTo: function bezierCurveTo(t, n, s, a, u, y) {
        this._ += "C" + +t + "," + +n + "," + +s + "," + +a + "," + (this._x1 = +u) + "," + (this._y1 = +y);
    },
    arcTo: function arcTo(t, n, s, a, u) {
        t = +t, n = +n, s = +s, a = +a, u = +u;
        var y = this._x1, p = this._y1, m = s - t, i = a - n, o = y - t, c = p - n, k = o * o + c * c;
        if (u < 0) throw new Error("negative radius: " + u);
        if (this._x1 === null) this._ += "M" + (this._x1 = t) + "," + (this._y1 = n);
        else if (k > D) if (!(Math.abs(c * m - i * o) > D) || !u) this._ += "L" + (this._x1 = t) + "," + (this._y1 = n);
        else {
            var b = s - y, d = a - p, x = m * m + i * i, E = b * b + d * d, L = Math.sqrt(x), A = Math.sqrt(k), N = u * Math.tan((et - Math.acos((x + k - E) / (2 * L * A))) / 2), C = N / A, j = N / L;
            Math.abs(C - 1) > D && (this._ += "L" + (t + C * o) + "," + (n + C * c)), this._ += "A" + u + "," + u + ",0,0," + +(c * b > o * d) + "," + (this._x1 = t + j * m) + "," + (this._y1 = n + j * i);
        }
    },
    arc: function arc(t, n, s, a, u, y) {
        t = +t, n = +n, s = +s, y = !!y;
        var p = s * Math.cos(a), m = s * Math.sin(a), i = t + p, o = n + m, c = 1 ^ y, k = y ? a - u : u - a;
        if (s < 0) throw new Error("negative radius: " + s);
        this._x1 === null ? this._ += "M" + i + "," + o : (Math.abs(this._x1 - i) > D || Math.abs(this._y1 - o) > D) && (this._ += "L" + i + "," + o), s && (k < 0 && (k = k % nt + nt), k > Yt ? this._ += "A" + s + "," + s + ",0,1," + c + "," + (t - p) + "," + (n - m) + "A" + s + "," + s + ",0,1," + c + "," + (this._x1 = i) + "," + (this._y1 = o) : k > D && (this._ += "A" + s + "," + s + ",0," + +(k >= et) + "," + c + "," + (this._x1 = t + s * Math.cos(u)) + "," + (this._y1 = n + s * Math.sin(u))));
    },
    rect: function rect(t, n, s, a) {
        this._ += "M" + (this._x0 = this._x1 = +t) + "," + (this._y0 = this._y1 = +n) + "h" + +s + "v" + +a + "h" + -s + "Z";
    },
    toString: function toString() {
        return this._;
    }
};
function ht(t) {
    return function() {
        return t;
    };
}
function Ht(t) {
    return t[0];
}
function Xt(t) {
    return t[1];
}
var qt = Array.prototype.slice;
function Qt(t) {
    return t.source;
}
function Kt(t) {
    return t.target;
}
function Zt(t) {
    var n = Qt, s = Kt, a = Ht, u = Xt, y = null;
    function p() {
        var m, i = qt.call(arguments), o = n.apply(this, i), c = s.apply(this, i);
        if (y || (y = m = gt()), t(y, +a.apply(this, (i[0] = o, i)), +u.apply(this, i), +a.apply(this, (i[0] = c, i)), +u.apply(this, i)), m) return y = null, m + "" || null;
    }
    return p.source = function(m) {
        return arguments.length ? (n = m, p) : n;
    }, p.target = function(m) {
        return arguments.length ? (s = m, p) : s;
    }, p.x = function(m) {
        return arguments.length ? (a = typeof m == "function" ? m : ht(+m), p) : a;
    }, p.y = function(m) {
        return arguments.length ? (u = typeof m == "function" ? m : ht(+m), p) : u;
    }, p.context = function(m) {
        return arguments.length ? (y = m !== null && m !== void 0 ? m : null, p) : y;
    }, p;
}
function Jt(t, n, s, a, u) {
    t.moveTo(n, s), t.bezierCurveTo(n = (n + a) / 2, s, n, u, a, u);
}
function te() {
    return Zt(Jt);
}
function ee(t) {
    return [
        t.source.x1,
        t.y0
    ];
}
function ne(t) {
    return [
        t.target.x0,
        t.y1
    ];
}
function ie() {
    return te().source(ee).target(ne);
}
var pt = /*#__PURE__*/ function() {
    function st(n) {
        _class_call_check(this, st);
        this.id = n, this.href = "#".concat(n);
    }
    _create_class(st, [
        {
            key: "toString",
            value: function toString() {
                return "url(" + this.href + ")";
            }
        }
    ], [
        {
            key: "next",
            value: function next(n) {
                return new st(n + ++st.count);
            }
        }
    ]);
    return st;
}();
pt.count = 0;
var ft = pt;
var se = {
    left: Bt,
    right: Vt,
    center: Rt,
    justify: dt
}, re = function re(t, n, s, a) {
    var _rt = Vn(), u = _rt.securityLevel, y = _rt.sankey, p = w1.sankey;
    var m;
    u === "sandbox" && (m = bt("#i" + n));
    var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
    var i = u === "sandbox" ? bt(m.nodes()[0].contentDocument.body) : bt("body"), o = u === "sandbox" ? i.select('[id="'.concat(n, '"]')) : bt('[id="'.concat(n, '"]')), c = (_ref = y == null ? void 0 : y.width) !== null && _ref !== void 0 ? _ref : p.width, k = (_ref1 = y == null ? void 0 : y.height) !== null && _ref1 !== void 0 ? _ref1 : p.width, b = (_ref2 = y == null ? void 0 : y.useMaxWidth) !== null && _ref2 !== void 0 ? _ref2 : p.useMaxWidth, d = (_ref3 = y == null ? void 0 : y.nodeAlignment) !== null && _ref3 !== void 0 ? _ref3 : p.nodeAlignment, x = (_ref4 = y == null ? void 0 : y.prefix) !== null && _ref4 !== void 0 ? _ref4 : p.prefix, E = (_ref5 = y == null ? void 0 : y.suffix) !== null && _ref5 !== void 0 ? _ref5 : p.suffix, L = (_ref6 = y == null ? void 0 : y.showValues) !== null && _ref6 !== void 0 ? _ref6 : p.showValues, A = a.db.getGraph(), N = se[d], C = 10;
    Gt().nodeId(function(g) {
        return g.id;
    }).nodeWidth(C).nodePadding(10 + (L ? 15 : 0)).nodeAlign(N).extent([
        [
            0,
            0
        ],
        [
            c,
            k
        ]
    ])(A);
    var S = h(r);
    o.append("g").attr("class", "nodes").selectAll(".node").data(A.nodes).join("g").attr("class", "node").attr("id", function(g) {
        return (g.uid = ft.next("node-")).id;
    }).attr("transform", function(g) {
        return "translate(" + g.x0 + "," + g.y0 + ")";
    }).attr("x", function(g) {
        return g.x0;
    }).attr("y", function(g) {
        return g.y0;
    }).append("rect").attr("height", function(g) {
        return g.y1 - g.y0;
    }).attr("width", function(g) {
        return g.x1 - g.x0;
    }).attr("fill", function(g) {
        return S(g.id);
    });
    var M = function(param) {
        var g = param.id, w = param.value;
        return L ? "".concat(g, "\n").concat(x).concat(Math.round(w * 100) / 100).concat(E) : g;
    };
    o.append("g").attr("class", "node-labels").attr("font-family", "sans-serif").attr("font-size", 14).selectAll("text").data(A.nodes).join("text").attr("x", function(g) {
        return g.x0 < c / 2 ? g.x1 + 6 : g.x0 - 6;
    }).attr("y", function(g) {
        return (g.y1 + g.y0) / 2;
    }).attr("dy", "".concat(L ? "0" : "0.35", "em")).attr("text-anchor", function(g) {
        return g.x0 < c / 2 ? "start" : "end";
    }).text(M);
    var $ = o.append("g").attr("class", "links").attr("fill", "none").attr("stroke-opacity", 0.5).selectAll(".link").data(A.links).join("g").attr("class", "link").style("mix-blend-mode", "multiply"), P = (y == null ? void 0 : y.linkColor) || "gradient";
    if (P === "gradient") {
        var g = $.append("linearGradient").attr("id", function(w) {
            return (w.uid = ft.next("linearGradient-")).id;
        }).attr("gradientUnits", "userSpaceOnUse").attr("x1", function(w) {
            return w.source.x1;
        }).attr("x2", function(w) {
            return w.target.x0;
        });
        g.append("stop").attr("offset", "0%").attr("stop-color", function(w) {
            return S(w.source.id);
        }), g.append("stop").attr("offset", "100%").attr("stop-color", function(w) {
            return S(w.target.id);
        });
    }
    var I;
    switch(P){
        case "gradient":
            I = function(g) {
                return g.uid;
            };
            break;
        case "source":
            I = function(g) {
                return S(g.source.id);
            };
            break;
        case "target":
            I = function(g) {
                return S(g.target.id);
            };
            break;
        default:
            I = P;
    }
    $.append("path").attr("d", ie()).attr("stroke", I).attr("stroke-width", function(g) {
        return Math.max(1, g.width);
    }), k_(void 0, o, 0, b);
}, oe = {
    draw: re
}, le = function(t) {
    return t.replaceAll(/^[^\S\n\r]+|[^\S\n\r]+$/g, "").replaceAll(/([\n\r])+/g, "\n").trim();
}, ae = H.parse.bind(H);
H.parse = function(t) {
    return ae(le(t));
};
var ye = {
    parser: H,
    db: zt,
    renderer: oe
};

export { ye as diagram };
