UNPKG

@mermaid-js/mermaid-mindmap

Version:

Mindmap diagram module for MermaidJS.

1,423 lines 1.17 MB
(function(global2, factory) { typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2["mermaid-mindmap-detector"] = {})); })(this, function(exports2) { "use strict"; const id$1 = "mindmap"; const detector = (txt) => { return txt.match(/^\s*mindmap/) !== null; }; const loadDiagram = async () => { const { diagram: diagram2 } = await Promise.resolve().then(() => diagramDefinition); return { id: id$1, diagram: diagram2 }; }; var parser = function() { var o = function(k, v, o2, l) { for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v) ; return o2; }, $V0 = [1, 7], $V1 = [1, 9], $V2 = [1, 10], $V3 = [1, 14], $V4 = [1, 13], $V5 = [1, 19], $V6 = [1, 20], $V7 = [6, 9], $V8 = [1, 7, 12, 13, 16, 19], $V9 = [1, 28], $Va = [1, 29], $Vb = [1, 6, 7, 9, 12, 13, 16, 19]; var parser2 = { trace: function trace() { }, yy: {}, symbols_: { "error": 2, "start": 3, "MINDMAP": 4, "document": 5, "NL": 6, "SPACELIST": 7, "stop": 8, "EOF": 9, "statement": 10, "node": 11, "ICON": 12, "CLASS": 13, "nodeWithId": 14, "nodeWithoutId": 15, "NODE_DSTART": 16, "NODE_DESCR": 17, "NODE_DEND": 18, "NODE_ID": 19, "$accept": 0, "$end": 1 }, terminals_: { 2: "error", 4: "MINDMAP", 6: "NL", 7: "SPACELIST", 9: "EOF", 12: "ICON", 13: "CLASS", 16: "NODE_DSTART", 17: "NODE_DESCR", 18: "NODE_DEND", 19: "NODE_ID" }, productions_: [0, [3, 2], [3, 3], [3, 3], [8, 1], [8, 1], [8, 2], [8, 2], [5, 3], [5, 2], [10, 2], [10, 2], [10, 2], [10, 1], [10, 1], [10, 1], [10, 1], [11, 1], [11, 1], [15, 3], [14, 1], [14, 4]], performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) { var $0 = $$.length - 1; switch (yystate) { case 1: case 2: case 3: return yy; case 4: yy.getLogger().trace("Stop NL "); break; case 5: yy.getLogger().trace("Stop EOF "); break; case 6: yy.getLogger().trace("Stop NL2 "); break; case 7: yy.getLogger().trace("Stop EOF2 "); break; case 10: yy.getLogger().trace("Node: ", $$[$0].id); yy.addNode($$[$0 - 1].length, $$[$0].id, $$[$0].descr, $$[$0].type); break; case 11: yy.getLogger().trace("Icon: ", $$[$0]); yy.decorateNode({ icon: $$[$0] }); break; case 12: case 15: yy.decorateNode({ class: $$[$0] }); break; case 13: yy.getLogger().trace("Node: ", $$[$0].id); yy.addNode(0, $$[$0].id, $$[$0].descr, $$[$0].type); break; case 14: yy.decorateNode({ icon: $$[$0] }); break; case 19: yy.getLogger().trace("node found ..", $$[$0 - 2]); this.$ = { id: $$[$0 - 1], descr: $$[$0 - 1], type: yy.getType($$[$0 - 2], $$[$0]) }; break; case 20: this.$ = { id: $$[$0], descr: $$[$0], type: yy.nodeType.DEFAULT }; break; case 21: yy.getLogger().trace("node found ..", $$[$0 - 3]); this.$ = { id: $$[$0 - 3], descr: $$[$0 - 1], type: yy.getType($$[$0 - 2], $$[$0]) }; break; } }, table: [{ 3: 1, 4: [1, 2], 7: [1, 3] }, { 1: [3] }, { 5: 4, 6: [1, 5], 7: $V0, 10: 6, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, { 4: [1, 15] }, { 1: [2, 1], 7: $V0, 10: 16, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, { 5: 17, 7: $V0, 10: 6, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, { 6: $V5, 8: 18, 9: $V6 }, o($V7, [2, 16], { 14: 11, 15: 12, 11: 21, 12: [1, 22], 13: [1, 23], 16: $V3, 19: $V4 }), o($V7, [2, 13]), o($V7, [2, 14]), o($V7, [2, 15]), o($V7, [2, 17]), o($V7, [2, 18]), o($V7, [2, 20], { 16: [1, 24] }), { 17: [1, 25] }, { 5: 26, 7: $V0, 10: 6, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, { 6: $V5, 8: 27, 9: $V6 }, { 1: [2, 2], 7: $V0, 10: 16, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, o($V8, [2, 9], { 6: $V9, 9: $Va }), o($Vb, [2, 4]), o($Vb, [2, 5]), o($V7, [2, 10]), o($V7, [2, 11]), o($V7, [2, 12]), { 17: [1, 30] }, { 18: [1, 31] }, { 1: [2, 3], 7: $V0, 10: 16, 11: 8, 12: $V1, 13: $V2, 14: 11, 15: 12, 16: $V3, 19: $V4 }, o($V8, [2, 8], { 6: $V9, 9: $Va }), o($Vb, [2, 6]), o($Vb, [2, 7]), { 18: [1, 32] }, o($V7, [2, 19]), o($V7, [2, 21])], defaultActions: {}, parseError: function parseError2(str, hash) { if (hash.recoverable) { this.trace(str); } else { var error2 = new Error(str); error2.hash = hash; throw error2; } }, parse: function parse2(input) { var self2 = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, TERROR = 2, EOF = 1; var args = lstack.slice.call(arguments, 1); var lexer2 = Object.create(this.lexer); var sharedState = { yy: {} }; for (var k in this.yy) { if (Object.prototype.hasOwnProperty.call(this.yy, k)) { sharedState.yy[k] = this.yy[k]; } } lexer2.setInput(input, sharedState.yy); sharedState.yy.lexer = lexer2; sharedState.yy.parser = this; if (typeof lexer2.yylloc == "undefined") { lexer2.yylloc = {}; } var yyloc = lexer2.yylloc; lstack.push(yyloc); var ranges = lexer2.options && lexer2.options.ranges; if (typeof sharedState.yy.parseError === "function") { this.parseError = sharedState.yy.parseError; } else { this.parseError = Object.getPrototypeOf(this).parseError; } function lex() { var token; token = tstack.pop() || lexer2.lex() || EOF; if (typeof token !== "number") { if (token instanceof Array) { tstack = token; token = tstack.pop(); } token = self2.symbols_[token] || token; } return token; } var symbol, state, action, r, yyval = {}, p2, len, newState, expected; while (true) { state = stack[stack.length - 1]; if (this.defaultActions[state]) { action = this.defaultActions[state]; } else { if (symbol === null || typeof symbol == "undefined") { symbol = lex(); } action = table[state] && table[state][symbol]; } if (typeof action === "undefined" || !action.length || !action[0]) { var errStr = ""; expected = []; for (p2 in table[state]) { if (this.terminals_[p2] && p2 > TERROR) { expected.push("'" + this.terminals_[p2] + "'"); } } if (lexer2.showPosition) { errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'"; } else { errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'"); } this.parseError(errStr, { text: lexer2.match, token: this.terminals_[symbol] || symbol, line: lexer2.yylineno, loc: yyloc, expected }); } if (action[0] instanceof Array && action.length > 1) { throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); } switch (action[0]) { case 1: stack.push(symbol); vstack.push(lexer2.yytext); lstack.push(lexer2.yylloc); stack.push(action[1]); symbol = null; { yyleng = lexer2.yyleng; yytext = lexer2.yytext; yylineno = lexer2.yylineno; yyloc = lexer2.yylloc; } break; case 2: len = this.productions_[action[1]][1]; yyval.$ = vstack[vstack.length - len]; yyval._$ = { first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column }; if (ranges) { yyval._$.range = [ lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1] ]; } r = this.performAction.apply(yyval, [ yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack ].concat(args)); if (typeof r !== "undefined") { return r; } if (len) { stack = stack.slice(0, -1 * len * 2); vstack = vstack.slice(0, -1 * len); lstack = lstack.slice(0, -1 * len); } stack.push(this.productions_[action[1]][0]); vstack.push(yyval.$); lstack.push(yyval._$); newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; stack.push(newState); break; case 3: return true; } } return true; } }; var lexer = function() { var lexer2 = { EOF: 1, parseError: function parseError2(str, hash) { if (this.yy.parser) { this.yy.parser.parseError(str, hash); } else { throw new Error(str); } }, setInput: function(input, yy) { this.yy = yy || this.yy || {}; this._input = input; 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 }; if (this.options.ranges) { this.yylloc.range = [0, 0]; } this.offset = 0; return this; }, input: function() { var ch = this._input[0]; this.yytext += ch; this.yyleng++; this.offset++; this.match += ch; this.matched += ch; var lines = ch.match(/(?:\r\n?|\n).*/g); if (lines) { this.yylineno++; this.yylloc.last_line++; } else { this.yylloc.last_column++; } if (this.options.ranges) { this.yylloc.range[1]++; } this._input = this._input.slice(1); return ch; }, unput: function(ch) { var len = ch.length; var lines = ch.split(/(?:\r\n?|\n)/g); this._input = ch + this._input; this.yytext = this.yytext.substr(0, this.yytext.length - len); this.offset -= len; var oldLines = 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); if (lines.length - 1) { this.yylineno -= lines.length - 1; } var r = this.yylloc.range; this.yylloc = { first_line: this.yylloc.first_line, last_line: this.yylineno + 1, first_column: this.yylloc.first_column, last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len }; if (this.options.ranges) { this.yylloc.range = [r[0], r[0] + this.yyleng - len]; } this.yyleng = this.yytext.length; return this; }, more: function() { this._more = true; return this; }, reject: function() { 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; }, less: function(n) { this.unput(this.match.slice(n)); }, pastInput: function() { var past = this.matched.substr(0, this.matched.length - this.match.length); return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, ""); }, upcomingInput: function() { var next2 = this.match; if (next2.length < 20) { next2 += this._input.substr(0, 20 - next2.length); } return (next2.substr(0, 20) + (next2.length > 20 ? "..." : "")).replace(/\n/g, ""); }, showPosition: function() { var pre = this.pastInput(); var c = new Array(pre.length + 1).join("-"); return pre + this.upcomingInput() + "\n" + c + "^"; }, test_match: function(match2, indexed_rule) { var token, lines, backup; if (this.options.backtrack_lexer) { backup = { 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 }; if (this.options.ranges) { backup.yylloc.range = this.yylloc.range.slice(0); } } lines = match2[0].match(/(?:\r\n?|\n).*/g); if (lines) { this.yylineno += lines.length; } this.yylloc = { first_line: this.yylloc.last_line, last_line: this.yylineno + 1, first_column: this.yylloc.last_column, last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match2[0].length }; this.yytext += match2[0]; this.match += match2[0]; this.matches = match2; this.yyleng = this.yytext.length; if (this.options.ranges) { this.yylloc.range = [this.offset, this.offset += this.yyleng]; } this._more = false; this._backtrack = false; this._input = this._input.slice(match2[0].length); this.matched += match2[0]; token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]); if (this.done && this._input) { this.done = false; } if (token) { return token; } else if (this._backtrack) { for (var k in backup) { this[k] = backup[k]; } return false; } return false; }, next: function() { if (this.done) { return this.EOF; } if (!this._input) { this.done = true; } var token, match2, tempMatch, index; if (!this._more) { this.yytext = ""; this.match = ""; } var rules = this._currentRules(); for (var i2 = 0; i2 < rules.length; i2++) { tempMatch = this._input.match(this.rules[rules[i2]]); if (tempMatch && (!match2 || tempMatch[0].length > match2[0].length)) { match2 = tempMatch; index = i2; if (this.options.backtrack_lexer) { token = this.test_match(tempMatch, rules[i2]); if (token !== false) { return token; } else if (this._backtrack) { match2 = false; continue; } else { return false; } } else if (!this.options.flex) { break; } } } if (match2) { token = this.test_match(match2, rules[index]); if (token !== false) { return token; } return false; } if (this._input === "") { return this.EOF; } else { return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), { text: "", token: null, line: this.yylineno }); } }, lex: function lex() { var r = this.next(); if (r) { return r; } else { return this.lex(); } }, begin: function begin(condition) { this.conditionStack.push(condition); }, popState: function popState() { var n = this.conditionStack.length - 1; if (n > 0) { return this.conditionStack.pop(); } else { return this.conditionStack[0]; } }, _currentRules: function _currentRules() { if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) { return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules; } else { return this.conditions["INITIAL"].rules; } }, topState: function topState(n) { n = this.conditionStack.length - 1 - Math.abs(n || 0); if (n >= 0) { return this.conditionStack[n]; } else { return "INITIAL"; } }, pushState: function pushState(condition) { this.begin(condition); }, stateStackSize: function stateStackSize() { return this.conditionStack.length; }, options: { "case-insensitive": true }, performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) { switch ($avoiding_name_collisions) { case 0: yy.getLogger().trace("Found comment", yy_.yytext); break; case 1: return 4; case 2: this.begin("CLASS"); break; case 3: this.popState(); return 13; case 4: this.popState(); break; case 5: yy.getLogger().trace("Begin icon"); this.begin("ICON"); break; case 6: return 6; case 7: return 12; case 8: yy.getLogger().trace("end icon"); this.popState(); break; case 9: yy.getLogger().trace("Exploding node"); this.begin("NODE"); return 16; case 10: yy.getLogger().trace("Cloud"); this.begin("NODE"); return 16; case 11: yy.getLogger().trace("Explosion Bang"); this.begin("NODE"); return 16; case 12: yy.getLogger().trace("Cloud Bang"); this.begin("NODE"); return 16; case 13: this.begin("NODE"); return 16; case 14: this.begin("NODE"); return 16; case 15: this.begin("NODE"); return 16; case 16: return 7; case 17: return 19; case 18: return 9; case 19: yy.getLogger().trace("Starting NSTR"); this.begin("NSTR"); break; case 20: yy.getLogger().trace("description:", yy_.yytext); return "NODE_DESCR"; case 21: this.popState(); break; case 22: this.popState(); yy.getLogger().trace("node end ))"); return "NODE_DEND"; case 23: this.popState(); yy.getLogger().trace("node end )"); return "NODE_DEND"; case 24: this.popState(); yy.getLogger().trace("node end ...", yy_.yytext); return "NODE_DEND"; case 25: this.popState(); yy.getLogger().trace("node end (-"); return "NODE_DEND"; case 26: this.popState(); yy.getLogger().trace("node end (-"); return "NODE_DEND"; case 27: this.popState(); yy.getLogger().trace("node end (("); return "NODE_DEND"; case 28: this.popState(); yy.getLogger().trace("node end (("); return "NODE_DEND"; case 29: yy.getLogger().trace("Long description:", yy_.yytext); return 17; case 30: yy.getLogger().trace("Long description:", yy_.yytext); return 17; } }, rules: [/^(?:\s*%%.*)/i, /^(?:mindmap\b)/i, /^(?::::)/i, /^(?:.+)/i, /^(?:\n)/i, /^(?:::icon\()/i, /^(?:[\n]+)/i, /^(?:[^\)]+)/i, /^(?:\))/i, /^(?:-\))/i, /^(?:\(-)/i, /^(?:\)\))/i, /^(?:\))/i, /^(?:\(\()/i, /^(?:\()/i, /^(?:\[)/i, /^(?:[\s]+)/i, /^(?:[^\(\[\n\-\)]+)/i, /^(?:$)/i, /^(?:["])/i, /^(?:[^"]+)/i, /^(?:["])/i, /^(?:[\)]\))/i, /^(?:[\)])/i, /^(?:[\]])/i, /^(?:\(-)/i, /^(?:-\))/i, /^(?:\(\()/i, /^(?:\()/i, /^(?:[^\)\]\(]+)/i, /^(?:.+(?!\(\())/i], conditions: { "CLASS": { "rules": [3, 4], "inclusive": false }, "ICON": { "rules": [7, 8], "inclusive": false }, "NSTR": { "rules": [20, 21], "inclusive": false }, "NODE": { "rules": [19, 22, 23, 24, 25, 26, 27, 28, 29, 30], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], "inclusive": true } } }; return lexer2; }(); parser2.lexer = lexer; function Parser() { this.yy = {}; } Parser.prototype = parser2; parser2.Parser = Parser; return new Parser(); }(); parser.parser = parser; const mindmapParser = parser; const warning = (s) => { console.error("Log function was called before initialization", s); }; const log = { trace: warning, debug: warning, info: warning, warn: warning, error: warning, fatal: warning }; let getConfig; let sanitizeText; let setupGraphViewbox; const injectUtils = (_log, _setLogLevel, _getConfig, _sanitizeText, _setupGraphViewbox) => { _log.info("Mermaid utils injected"); log.trace = _log.trace; log.debug = _log.debug; log.info = _log.info; log.warn = _log.warn; log.error = _log.error; log.fatal = _log.fatal; getConfig = _getConfig; sanitizeText = _sanitizeText; setupGraphViewbox = _setupGraphViewbox; }; let nodes = []; let cnt = 0; let elements = {}; const clear = () => { nodes = []; cnt = 0; elements = {}; }; const getParent = function(level) { for (let i2 = nodes.length - 1; i2 >= 0; i2--) { if (nodes[i2].level < level) { return nodes[i2]; } } return null; }; const getMindmap = () => { return nodes.length > 0 ? nodes[0] : null; }; const addNode = (level, id2, descr, type) => { log.info("addNode", level, id2, descr, type); const conf = getConfig(); const node = { id: cnt++, nodeId: sanitizeText(id2), level, descr: sanitizeText(descr), type, children: [], width: getConfig().mindmap.maxNodeWidth }; switch (node.type) { case nodeType.ROUNDED_RECT: node.padding = 2 * conf.mindmap.padding; break; case nodeType.RECT: node.padding = 2 * conf.mindmap.padding; break; default: node.padding = conf.mindmap.padding; } const parent = getParent(level); if (parent) { parent.children.push(node); nodes.push(node); } else { if (nodes.length === 0) { nodes.push(node); } else { let error2 = new Error( 'There can be only one root. No parent could be found for ("' + node.descr + '")' ); error2.hash = { text: "branch " + name, token: "branch " + name, line: "1", loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 }, expected: ['"checkout ' + name + '"'] }; throw error2; } } }; const nodeType = { DEFAULT: 0, NO_BORDER: 0, ROUNDED_RECT: 1, RECT: 2, CIRCLE: 3, CLOUD: 4, BANG: 5 }; const getType = (startStr, endStr) => { log.debug("In get type", startStr, endStr); switch (startStr) { case "[": return nodeType.RECT; case "(": return endStr === ")" ? nodeType.ROUNDED_RECT : nodeType.CLOUD; case "((": return nodeType.CIRCLE; case ")": return nodeType.CLOUD; case "))": return nodeType.BANG; default: return nodeType.DEFAULT; } }; const setElementForId = (id2, element2) => { elements[id2] = element2; }; const decorateNode = (decoration) => { const node = nodes[nodes.length - 1]; if (decoration && decoration.icon) { node.icon = sanitizeText(decoration.icon); } if (decoration && decoration.class) { node.class = sanitizeText(decoration.class); } }; const type2Str = (type) => { switch (type) { case nodeType.DEFAULT: return "no-border"; case nodeType.RECT: return "rect"; case nodeType.ROUNDED_RECT: return "rounded-rect"; case nodeType.CIRCLE: return "circle"; case nodeType.CLOUD: return "cloud"; case nodeType.BANG: return "bang"; default: return "no-border"; } }; let parseError; const setErrorHandler = (handler) => { parseError = handler; }; const getLogger = () => log; const getNodeById = (id2) => nodes[id2]; const getElementById = (id2) => elements[id2]; const mindmapDb = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, clear, getMindmap, addNode, nodeType, getType, setElementForId, decorateNode, type2Str, get parseError() { return parseError; }, setErrorHandler, getLogger, getNodeById, getElementById }, Symbol.toStringTag, { value: "Module" })); var noop$2 = { value: () => { } }; function dispatch() { for (var i2 = 0, n = arguments.length, _2 = {}, t; i2 < n; ++i2) { if (!(t = arguments[i2] + "") || t in _2 || /[\s.]/.test(t)) throw new Error("illegal type: " + t); _2[t] = []; } return new Dispatch(_2); } function Dispatch(_2) { this._ = _2; } function parseTypenames$1(typenames, types) { return typenames.trim().split(/^|\s+/).map(function(t) { var name2 = "", i2 = t.indexOf("."); if (i2 >= 0) name2 = t.slice(i2 + 1), t = t.slice(0, i2); if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t); return { type: t, name: name2 }; }); } Dispatch.prototype = dispatch.prototype = { constructor: Dispatch, on: function(typename, callback) { var _2 = this._, T = parseTypenames$1(typename + "", _2), t, i2 = -1, n = T.length; if (arguments.length < 2) { while (++i2 < n) if ((t = (typename = T[i2]).type) && (t = get$3(_2[t], typename.name))) return t; return; } if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback); while (++i2 < n) { if (t = (typename = T[i2]).type) _2[t] = set$3(_2[t], typename.name, callback); else if (callback == null) for (t in _2) _2[t] = set$3(_2[t], typename.name, null); } return this; }, copy: function() { var copy2 = {}, _2 = this._; for (var t in _2) copy2[t] = _2[t].slice(); return new Dispatch(copy2); }, call: function(type, that) { if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i2 = 0, n, t; i2 < n; ++i2) args[i2] = arguments[i2 + 2]; if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); for (t = this._[type], i2 = 0, n = t.length; i2 < n; ++i2) t[i2].value.apply(that, args); }, apply: function(type, that, args) { if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); for (var t = this._[type], i2 = 0, n = t.length; i2 < n; ++i2) t[i2].value.apply(that, args); } }; function get$3(type, name2) { for (var i2 = 0, n = type.length, c; i2 < n; ++i2) { if ((c = type[i2]).name === name2) { return c.value; } } } function set$3(type, name2, callback) { for (var i2 = 0, n = type.length; i2 < n; ++i2) { if (type[i2].name === name2) { type[i2] = noop$2, type = type.slice(0, i2).concat(type.slice(i2 + 1)); break; } } if (callback != null) type.push({ name: name2, value: callback }); return type; } var xhtml = "http://www.w3.org/1999/xhtml"; const namespaces = { svg: "http://www.w3.org/2000/svg", xhtml, xlink: "http://www.w3.org/1999/xlink", xml: "http://www.w3.org/XML/1998/namespace", xmlns: "http://www.w3.org/2000/xmlns/" }; function namespace(name2) { var prefix = name2 += "", i2 = prefix.indexOf(":"); if (i2 >= 0 && (prefix = name2.slice(0, i2)) !== "xmlns") name2 = name2.slice(i2 + 1); return namespaces.hasOwnProperty(prefix) ? { space: namespaces[prefix], local: name2 } : name2; } function creatorInherit(name2) { return function() { var document2 = this.ownerDocument, uri = this.namespaceURI; return uri === xhtml && document2.documentElement.namespaceURI === xhtml ? document2.createElement(name2) : document2.createElementNS(uri, name2); }; } function creatorFixed(fullname) { return function() { return this.ownerDocument.createElementNS(fullname.space, fullname.local); }; } function creator(name2) { var fullname = namespace(name2); return (fullname.local ? creatorFixed : creatorInherit)(fullname); } function none() { } function selector(selector2) { return selector2 == null ? none : function() { return this.querySelector(selector2); }; } function selection_select(select2) { if (typeof select2 !== "function") select2 = selector(select2); for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i2 = 0; i2 < n; ++i2) { if ((node = group[i2]) && (subnode = select2.call(node, node.__data__, i2, group))) { if ("__data__" in node) subnode.__data__ = node.__data__; subgroup[i2] = subnode; } } } return new Selection$1(subgroups, this._parents); } function array$1(x) { return x == null ? [] : Array.isArray(x) ? x : Array.from(x); } function empty() { return []; } function selectorAll(selector2) { return selector2 == null ? empty : function() { return this.querySelectorAll(selector2); }; } function arrayAll(select2) { return function() { return array$1(select2.apply(this, arguments)); }; } function selection_selectAll(select2) { if (typeof select2 === "function") select2 = arrayAll(select2); else select2 = selectorAll(select2); for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, node, i2 = 0; i2 < n; ++i2) { if (node = group[i2]) { subgroups.push(select2.call(node, node.__data__, i2, group)); parents.push(node); } } } return new Selection$1(subgroups, parents); } function matcher(selector2) { return function() { return this.matches(selector2); }; } function childMatcher(selector2) { return function(node) { return node.matches(selector2); }; } var find = Array.prototype.find; function childFind(match2) { return function() { return find.call(this.children, match2); }; } function childFirst() { return this.firstElementChild; } function selection_selectChild(match2) { return this.select(match2 == null ? childFirst : childFind(typeof match2 === "function" ? match2 : childMatcher(match2))); } var filter$1 = Array.prototype.filter; function children() { return Array.from(this.children); } function childrenFilter(match2) { return function() { return filter$1.call(this.children, match2); }; } function selection_selectChildren(match2) { return this.selectAll(match2 == null ? children : childrenFilter(typeof match2 === "function" ? match2 : childMatcher(match2))); } function selection_filter(match2) { if (typeof match2 !== "function") match2 = matcher(match2); for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i2 = 0; i2 < n; ++i2) { if ((node = group[i2]) && match2.call(node, node.__data__, i2, group)) { subgroup.push(node); } } } return new Selection$1(subgroups, this._parents); } function sparse(update2) { return new Array(update2.length); } function selection_enter() { return new Selection$1(this._enter || this._groups.map(sparse), this._parents); } function EnterNode(parent, datum2) { this.ownerDocument = parent.ownerDocument; this.namespaceURI = parent.namespaceURI; this._next = null; this._parent = parent; this.__data__ = datum2; } EnterNode.prototype = { constructor: EnterNode, appendChild: function(child) { return this._parent.insertBefore(child, this._next); }, insertBefore: function(child, next2) { return this._parent.insertBefore(child, next2); }, querySelector: function(selector2) { return this._parent.querySelector(selector2); }, querySelectorAll: function(selector2) { return this._parent.querySelectorAll(selector2); } }; function constant$1(x) { return function() { return x; }; } function bindIndex(parent, group, enter, update2, exit, data2) { var i2 = 0, node, groupLength = group.length, dataLength = data2.length; for (; i2 < dataLength; ++i2) { if (node = group[i2]) { node.__data__ = data2[i2]; update2[i2] = node; } else { enter[i2] = new EnterNode(parent, data2[i2]); } } for (; i2 < groupLength; ++i2) { if (node = group[i2]) { exit[i2] = node; } } } function bindKey(parent, group, enter, update2, exit, data2, key) { var i2, node, nodeByKeyValue = /* @__PURE__ */ new Map(), groupLength = group.length, dataLength = data2.length, keyValues = new Array(groupLength), keyValue; for (i2 = 0; i2 < groupLength; ++i2) { if (node = group[i2]) { keyValues[i2] = keyValue = key.call(node, node.__data__, i2, group) + ""; if (nodeByKeyValue.has(keyValue)) { exit[i2] = node; } else { nodeByKeyValue.set(keyValue, node); } } } for (i2 = 0; i2 < dataLength; ++i2) { keyValue = key.call(parent, data2[i2], i2, data2) + ""; if (node = nodeByKeyValue.get(keyValue)) { update2[i2] = node; node.__data__ = data2[i2]; nodeByKeyValue.delete(keyValue); } else { enter[i2] = new EnterNode(parent, data2[i2]); } } for (i2 = 0; i2 < groupLength; ++i2) { if ((node = group[i2]) && nodeByKeyValue.get(keyValues[i2]) === node) { exit[i2] = node; } } } function datum(node) { return node.__data__; } function selection_data(value, key) { if (!arguments.length) return Array.from(this, datum); var bind = key ? bindKey : bindIndex, parents = this._parents, groups = this._groups; if (typeof value !== "function") value = constant$1(value); for (var m = groups.length, update2 = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) { var parent = parents[j], group = groups[j], groupLength = group.length, data2 = arraylike(value.call(parent, parent && parent.__data__, j, parents)), dataLength = data2.length, enterGroup = enter[j] = new Array(dataLength), updateGroup = update2[j] = new Array(dataLength), exitGroup = exit[j] = new Array(groupLength); bind(parent, group, enterGroup, updateGroup, exitGroup, data2, key); for (var i0 = 0, i1 = 0, previous, next2; i0 < dataLength; ++i0) { if (previous = enterGroup[i0]) { if (i0 >= i1) i1 = i0 + 1; while (!(next2 = updateGroup[i1]) && ++i1 < dataLength) ; previous._next = next2 || null; } } } update2 = new Selection$1(update2, parents); update2._enter = enter; update2._exit = exit; return update2; } function arraylike(data2) { return typeof data2 === "object" && "length" in data2 ? data2 : Array.from(data2); } function selection_exit() { return new Selection$1(this._exit || this._groups.map(sparse), this._parents); } function selection_join(onenter, onupdate, onexit) { var enter = this.enter(), update2 = this, exit = this.exit(); if (typeof onenter === "function") { enter = onenter(enter); if (enter) enter = enter.selection(); } else { enter = enter.append(onenter + ""); } if (onupdate != null) { update2 = onupdate(update2); if (update2) update2 = update2.selection(); } if (onexit == null) exit.remove(); else onexit(exit); return enter && update2 ? enter.merge(update2).order() : update2; } function selection_merge(context) { var selection2 = context.selection ? context.selection() : context; for (var groups0 = this._groups, groups1 = selection2._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) { for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i2 = 0; i2 < n; ++i2) { if (node = group0[i2] || group1[i2]) { merge[i2] = node; } } } for (; j < m0; ++j) { merges[j] = groups0[j]; } return new Selection$1(merges, this._parents); } function selection_order() { for (var groups = this._groups, j = -1, m = groups.length; ++j < m; ) { for (var group = groups[j], i2 = group.length - 1, next2 = group[i2], node; --i2 >= 0; ) { if (node = group[i2]) { if (next2 && node.compareDocumentPosition(next2) ^ 4) next2.parentNode.insertBefore(node, next2); next2 = node; } } } return this; } function selection_sort(compare) { if (!compare) compare = ascending$1; function compareNode(a, b) { return a && b ? compare(a.__data__, b.__data__) : !a - !b; } for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) { for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i2 = 0; i2 < n; ++i2) { if (node = group[i2]) { sortgroup[i2] = node; } } sortgroup.sort(compareNode); } return new Selection$1(sortgroups, this._parents).order(); } function ascending$1(a, b) { return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; } function selection_call() { var callback = arguments[0]; arguments[0] = this; callback.apply(null, arguments); return this; } function selection_nodes() { return Array.from(this); } function selection_node() { for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { for (var group = groups[j], i2 = 0, n = group.length; i2 < n; ++i2) { var node = group[i2]; if (node) return node; } } return null; } function selection_size() { let size = 0; for (const node of this) ++size; return size; } function selection_empty() { return !this.node(); } function selection_each(callback) { for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { for (var group = groups[j], i2 = 0, n = group.length, node; i2 < n; ++i2) { if (node = group[i2]) callback.call(node, node.__data__, i2, group); } } return this; } function attrRemove$1(name2) { return function() { this.removeAttribute(name2); }; } function attrRemoveNS$1(fullname) { return function() { this.removeAttributeNS(fullname.space, fullname.local); }; } function attrConstant$1(name2, value) { return function() { this.setAttribute(name2, value); }; } function attrConstantNS$1(fullname, value) { return function() { this.setAttributeNS(fullname.space, fullname.local, value); }; } function attrFunction$1(name2, value) { return function() { var v = value.apply(this, arguments); if (v == null) this.removeAttribute(name2); else this.setAttribute(name2, v); }; } function attrFunctionNS$1(fullname, value) { return function() { var v = value.apply(this, arguments); if (v == null) this.removeAttributeNS(fullname.space, fullname.local); else this.setAttributeNS(fullname.space, fullname.local, v); }; } function selection_attr(name2, value) { var fullname = namespace(name2); if (arguments.length < 2) { var node = this.node(); return fullname.local ? node.getAttributeNS(fullname.space, fullname.local) : node.getAttribute(fullname); } return this.each((value == null ? fullname.local ? attrRemoveNS$1 : attrRemove$1 : typeof value === "function" ? fullname.local ? attrFunctionNS$1 : attrFunction$1 : fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, value)); } function defaultView(node) { return node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView; } function styleRemove$1(name2) { return function() { this.style.removeProperty(name2); }; } function styleConstant$1(name2, value, priority) { return function() { this.style.setProperty(name2, value, priority); }; } function styleFunction$1(name2, value, priority) { return function() { var v = value.apply(this, arguments); if (v == null) this.style.removeProperty(name2); else this.style.setProperty(name2, v, priority); }; } function selection_style(name2, value, priority) { return arguments.length > 1 ? this.each((value == null ? styleRemove$1 : typeof value === "function" ? styleFunction$1 : styleConstant$1)(name2, value, priority == null ? "" : priority)) : styleValue(this.node(), name2); } function styleValue(node, name2) { return node.style.getPropertyValue(name2) || defaultView(node).getComputedStyle(node, null).getPropertyValue(name2); } function propertyRemove(name2) { return function() { delete this[name2]; }; } function propertyConstant(name2, value) { return function() { this[name2] = value; }; } function propertyFunction(name2, value) { return function() { var v = value.apply(this, arguments); if (v == null) delete this[name2]; else this[name2] = v; }; } function selection_property(name2, value) { return arguments.length > 1 ? this.each((value == null ? propertyRemove : typeof value === "function" ? propertyFunction : propertyConstant)(name2, value)) : this.node()[name2]; } function classArray(string2) { return string2.trim().split(/^|\s+/); } function classList(node) { return node.classList || new ClassList(node); } function ClassList(node) { this._node = node; this._names = classArray(node.getAttribute("class") || ""); } ClassList.prototype = { add: function(name2) { var i2 = this._names.indexOf(name2); if (i2 < 0) { this._names.push(name2); this._node.setAttribute("class", this._names.join(" ")); } }, remove: function(name2) { var i2 = this._names.indexOf(name2); if (i2 >= 0) { this._names.splice(i2, 1); this._node.setAttribute("class", this._names.join(" ")); } }, contains: function(name2) { return this._names.indexOf(name2) >= 0; } }; function classedAdd(node, names) { var list = classList(node), i2 = -1, n = names.length; while (++i2 < n) list.add(names[i2]); } function classedRemove(node, names) { var list = classList(node), i2 = -1, n = names.length; while (++i2 < n) list.remove(names[i2]); } function classedTrue(names) { return function() { classedAdd(this, names); }; } function classedFalse(names) { return function() { classedRemove(this, names); }; } function classedFunction(names, value) { return function() { (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names); }; } function selection_classed(name2, value) { var names = classArray(name2 + ""); if (arguments.length < 2) { var list = classList(this.node()), i2 = -1, n = names.length; while (++i2 < n) if (!list.contains(names[i2])) return false; return true; } return this.each((typeof value === "function" ? classedFunction : value ? classedTrue : classedFalse)(names, value)); } function textRemove() { this.textContent = ""; } function textConstant$1(value) { return function() { this.textContent = value; }; } function textFunction$1(value) { return function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; }; } function selection_text(value) { return arguments.length ? this.each(value == null ? textRemove : (typeof value === "function" ? textFunction$1 : textConstant$1)(value)) : this.node().textContent; } function htmlRemove() { this.innerHTML = ""; } function htmlConstant(value) { return function() { this.innerHTML = value; }; } function htmlFunction(value) { return function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; }; } function selection_html(value) { return arguments.length ? this.each(value == null ? htmlRemove : (typeof value === "function" ? htmlFunction : htmlConstant)(value)) : this.node().innerHTML; } function raise() { if (this.nextSibling) this.parentNode.appendChild(this); } function selection_raise() { return this.each(raise); } function lower() { if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild); } function selection_lower() { return this.each(lower); } function selection_append(name2) { var create2 = typeof name2 === "function" ? name2 : creator(name2); return this.select(function() { return this.appendChild(create2.apply(this, arguments)); }); } function constantNull() { return null; } function selection_insert(name2, before) { var create2 = typeof name2 === "function" ? name2 : creator(name2), select2 = before == null ? constantNull : typeof before === "function" ? before : selector(before); return this.select(function() { return this.insertBefore(create2.apply(this, arguments), select2.apply(this, arguments) || null); }); } function remove() { var parent = this.parentNode; if (parent) parent.removeChild(this); } function selection_remove() { return t