UNPKG

@mermaid-js/mermaid-mindmap

Version:

Mindmap diagram module for MermaidJS.

1,445 lines (1,437 loc) 1.02 MB
import { select } from "d3"; import { isDark, lighten, darken } from "khroma"; 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 error3 = new Error(str); error3.hash = hash; throw error3; } }, parse: function parse3(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 i = 0; i < rules.length; i++) { tempMatch = this._input.match(this.rules[rules[i]]); if (tempMatch && (!match2 || tempMatch[0].length > match2[0].length)) { match2 = tempMatch; index = i; if (this.options.backtrack_lexer) { token = this.test_match(tempMatch, rules[i]); 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 i = nodes.length - 1; i >= 0; i--) { if (nodes[i].level < level) { return nodes[i]; } } 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 parent4 = getParent(level); if (parent4) { parent4.children.push(node); nodes.push(node); } else { if (nodes.length === 0) { nodes.push(node); } else { let error3 = new Error( 'There can be only one root. No parent could be found for ("' + node.descr + '")' ); error3.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 error3; } } }; 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, element3) => { elements[id2] = element3; }; 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" })); const MAX_SECTIONS = 12; function wrap(text, width2) { text.each(function() { var text2 = select(this), words = text2.text().split(/(\s+|<br>)/).reverse(), word, line = [], lineHeight = 1.1, y = text2.attr("y"), dy = parseFloat(text2.attr("dy")), tspan = text2.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em"); for (let j = 0; j < words.length; j++) { word = words[words.length - 1 - j]; line.push(word); tspan.text(line.join(" ").trim()); if (tspan.node().getComputedTextLength() > width2 || word === "<br>") { line.pop(); tspan.text(line.join(" ").trim()); if (word === "<br>") { line = [""]; } else { line = [word]; } tspan = text2.append("tspan").attr("x", 0).attr("y", y).attr("dy", lineHeight + "em").text(word); } } }); } const defaultBkg = function(elem, node, section) { const rd = 5; elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr( "d", `M0 ${node.height - rd} v${-node.height + 2 * rd} q0,-5 5,-5 h${node.width - 2 * rd} q5,0 5,5 v${node.height - rd} H0 Z` ); elem.append("line").attr("class", "node-line-" + section).attr("x1", 0).attr("y1", node.height).attr("x2", node.width).attr("y2", node.height); }; const rectBkg = function(elem, node) { elem.append("rect").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("height", node.height).attr("width", node.width); }; const cloudBkg = function(elem, node) { const w = node.width; const h = node.height; const r1 = 0.15 * w; const r2 = 0.25 * w; const r3 = 0.35 * w; const r4 = 0.2 * w; elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr( "d", `M0 0 a${r1},${r1} 0 0,1 ${w * 0.25},${-1 * w * 0.1} a${r3},${r3} 1 0,1 ${w * 0.4},${-1 * w * 0.1} a${r2},${r2} 1 0,1 ${w * 0.35},${1 * w * 0.2} a${r1},${r1} 1 0,1 ${w * 0.15},${1 * h * 0.35} a${r4},${r4} 1 0,1 ${-1 * w * 0.15},${1 * h * 0.65} a${r2},${r1} 1 0,1 ${-1 * w * 0.25},${w * 0.15} a${r3},${r3} 1 0,1 ${-1 * w * 0.5},${0} a${r1},${r1} 1 0,1 ${-1 * w * 0.25},${-1 * w * 0.15} a${r1},${r1} 1 0,1 ${-1 * w * 0.1},${-1 * h * 0.35} a${r4},${r4} 1 0,1 ${w * 0.1},${-1 * h * 0.65} H0 V0 Z` ); }; const bangBkg = function(elem, node) { const w = node.width; const h = node.height; const r = 0.15 * w; elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr( "d", `M0 0 a${r},${r} 1 0,0 ${w * 0.25},${-1 * h * 0.1} a${r},${r} 1 0,0 ${w * 0.25},${0} a${r},${r} 1 0,0 ${w * 0.25},${0} a${r},${r} 1 0,0 ${w * 0.25},${1 * h * 0.1} a${r},${r} 1 0,0 ${w * 0.15},${1 * h * 0.33} a${r * 0.8},${r * 0.8} 1 0,0 ${0},${1 * h * 0.34} a${r},${r} 1 0,0 ${-1 * w * 0.15},${1 * h * 0.33} a${r},${r} 1 0,0 ${-1 * w * 0.25},${h * 0.15} a${r},${r} 1 0,0 ${-1 * w * 0.25},${0} a${r},${r} 1 0,0 ${-1 * w * 0.25},${0} a${r},${r} 1 0,0 ${-1 * w * 0.25},${-1 * h * 0.15} a${r},${r} 1 0,0 ${-1 * w * 0.1},${-1 * h * 0.33} a${r * 0.8},${r * 0.8} 1 0,0 ${0},${-1 * h * 0.34} a${r},${r} 1 0,0 ${w * 0.1},${-1 * h * 0.33} H0 V0 Z` ); }; const circleBkg = function(elem, node) { elem.append("circle").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("r", node.width / 2); }; const roundedRectBkg = function(elem, node) { elem.append("rect").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("height", node.height).attr("rx", node.padding).attr("ry", node.padding).attr("width", node.width); }; const drawNode = function(elem, node, fullSection, conf) { const section = fullSection % MAX_SECTIONS - 1; const nodeElem = elem.append("g"); node.section = section; nodeElem.attr( "class", (node.class ? node.class + " " : "") + "mindmap-node " + (section < 0 ? "section-root" : "section-" + section) ); const bkgElem = nodeElem.append("g"); const textElem = nodeElem.append("g"); const txt = textElem.append("text").text(node.descr).attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle").call(wrap, node.width); const bbox = txt.node().getBBox(); const fontSize = conf.fontSize.replace ? conf.fontSize.replace("px", "") : conf.fontSize; node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding; node.width = bbox.width + 2 * node.padding; if (node.icon) { if (node.type === nodeType.CIRCLE) { node.height += 50; node.width += 50; const icon = nodeElem.append("foreignObject").attr("height", "50px").attr("width", node.width).attr("style", "text-align: center;"); icon.append("div").attr("class", "icon-container").append("i").attr("class", "node-icon-" + section + " " + node.icon); textElem.attr( "transform", "translate(" + node.width / 2 + ", " + (node.height / 2 - 1.5 * node.padding) + ")" ); } else { node.width += 50; const orgHeight = node.height; node.height = Math.max(orgHeight, 60); const heightDiff = Math.abs(node.height - orgHeight); const icon = nodeElem.append("foreignObject").attr("width", "60px").attr("height", node.height).attr("style", "text-align: center;margin-top:" + heightDiff / 2 + "px;"); icon.append("div").attr("class", "icon-container").append("i").attr("class", "node-icon-" + section + " " + node.icon); textElem.attr( "transform", "translate(" + (25 + node.width / 2) + ", " + (heightDiff / 2 + node.padding / 2) + ")" ); } } else { textElem.attr("transform", "translate(" + node.width / 2 + ", " + node.padding / 2 + ")"); } switch (node.type) { case nodeType.DEFAULT: defaultBkg(bkgElem, node, section); break; case nodeType.ROUNDED_RECT: roundedRectBkg(bkgElem, node); break; case nodeType.RECT: rectBkg(bkgElem, node); break; case nodeType.CIRCLE: bkgElem.attr("transform", "translate(" + node.width / 2 + ", " + +node.height / 2 + ")"); circleBkg(bkgElem, node); break; case nodeType.CLOUD: cloudBkg(bkgElem, node); break; case nodeType.BANG: bangBkg(bkgElem, node); break; } setElementForId(node.id, nodeElem); return node.height; }; const drawEdge = function drawEdge2(edgesElem, mindmap, parent4, depth, fullSection) { const section = fullSection % MAX_SECTIONS - 1; const sx = parent4.x + parent4.width / 2; const sy = parent4.y + parent4.height / 2; const ex = mindmap.x + mindmap.width / 2; const ey = mindmap.y + mindmap.height / 2; const mx = ex > sx ? sx + Math.abs(sx - ex) / 2 : sx - Math.abs(sx - ex) / 2; const my = ey > sy ? sy + Math.abs(sy - ey) / 2 : sy - Math.abs(sy - ey) / 2; const qx = ex > sx ? Math.abs(sx - mx) / 2 + sx : -Math.abs(sx - mx) / 2 + sx; const qy = ey > sy ? Math.abs(sy - my) / 2 + sy : -Math.abs(sy - my) / 2 + sy; edgesElem.append("path").attr( "d", parent4.direction === "TB" || parent4.direction === "BT" ? `M${sx},${sy} Q${sx},${qy} ${mx},${my} T${ex},${ey}` : `M${sx},${sy} Q${qx},${sy} ${mx},${my} T${ex},${ey}` ).attr("class", "edge section-edge-" + section + " edge-depth-" + depth); }; const positionNode = function(node) { const nodeElem = getElementById(node.id); const x = node.x || 0; const y = node.y || 0; nodeElem.attr("transform", "translate(" + x + "," + y + ")"); }; const svgDraw = { drawNode, positionNode, drawEdge }; var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getDefaultExportFromCjs(x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; } function isObject$5(value) { var type = typeof value; return value != null && (type == "object" || type == "function"); } var isObject_1 = isObject$5; var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; var _freeGlobal = freeGlobal$1; var freeGlobal = _freeGlobal; var freeSelf = typeof self == "object" && self && self.Object === Object && self; var root$4 = freeGlobal || freeSelf || Function("return this")(); var _root = root$4; var root$3 = _root; var now$1 = function() { return root$3.Date.now(); }; var now_1 = now$1; var reWhitespace = /\s/; function trimmedEndIndex$1(string3) { var index = string3.length; while (index-- && reWhitespace.test(string3.charAt(index))) { } return index; } var _trimmedEndIndex = trimmedEndIndex$1; var trimmedEndIndex = _trimmedEndIndex; var reTrimStart = /^\s+/; function baseTrim$1(string3) { return string3 ? string3.slice(0, trimmedEndIndex(string3) + 1).replace(reTrimStart, "") : string3; } var _baseTrim = baseTrim$1; var root$2 = _root; var Symbol$4 = root$2.Symbol; var _Symbol = Symbol$4; var Symbol$3 = _Symbol; var objectProto$5 = Object.prototype; var hasOwnProperty$4 = objectProto$5.hasOwnProperty; var nativeObjectToString$1 = objectProto$5.toString; var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : void 0; function getRawTag$1(value) { var isOwn = hasOwnProperty$4.call(value, symToStringTag$1), tag = value[symToStringTag$1]; try { value[symToStringTag$1] = void 0; var unmasked = true; } catch (e) { } var result = nativeObjectToString$1.call(value); if (unmasked) { if (isOwn) { value[symToStringTag$1] = tag; } else { delete value[symToStringTag$1]; } } return result; } var _getRawTag = getRawTag$1; var objectProto$4 = Object.prototype; var nativeObjectToString = objectProto$4.toString; function objectToString$1(value) { return nativeObjectToString.call(value); } var _objectToString = objectToString$1; var Symbol$2 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString; var nullTag = "[object Null]", undefinedTag = "[object Undefined]"; var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0; function baseGetTag$2(value) { if (value == null) { return value === void 0 ? undefinedTag : nullTag; } return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value); } var _baseGetTag = baseGetTag$2; function isObjectLike$1(value) { return value != null && typeof value == "object"; } var isObjectLike_1 = isObjectLike$1; var baseGetTag$1 = _baseGetTag, isObjectLike = isObjectLike_1; var symbolTag = "[object Symbol]"; function isSymbol$5(value) { return typeof value == "symbol" || isObjectLike(value) && baseGetTag$1(value) == symbolTag; } var isSymbol_1 = isSymbol$5; var baseTrim = _baseTrim, isObject$4 = isObject_1, isSymbol$4 = isSymbol_1; var NAN = 0 / 0; var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; var reIsBinary = /^0b[01]+$/i; var reIsOctal = /^0o[0-7]+$/i; var freeParseInt = parseInt; function toNumber$1(value) { if (typeof value == "number") { return value; } if (isSymbol$4(value)) { return NAN; } if (isObject$4(value)) { var other = typeof value.valueOf == "function" ? value.valueOf() : value; value = isObject$4(other) ? other + "" : other; } if (typeof value != "string") { return value === 0 ? value : +value; } value = baseTrim(value); var isBinary = reIsBinary.test(value); return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value; } var toNumber_1 = toNumber$1; var isObject$3 = isObject_1, now = now_1, toNumber = toNumber_1; var FUNC_ERROR_TEXT$1 = "Expected a function"; var nativeMax = Math.max, nativeMin = Math.min; function debounce$1(func, wait, options2) { var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true; if (typeof func != "function") { throw new TypeError(FUNC_ERROR_TEXT$1); } wait = toNumber(wait) || 0; if (isObject$3(options2)) { leading = !!options2.leading; maxing = "maxWait" in options2; maxWait = maxing ? nativeMax(toNumber(options2.maxWait) || 0, wait) : maxWait; trailing = "trailing" in options2 ? !!options2.trailing : trailing; } function invokeFunc(time2) { var args = lastArgs, thisArg = lastThis; lastArgs = lastThis = void 0; lastInvokeTime = time2; result = func.apply(thisArg, args); return result; } function leadingEdge(time2) { lastInvokeTime = time2; timerId = setTimeout(timerExpired, wait); return leading ? invokeFunc(time2) : result; } function remainingWait(time2) { var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime, timeWaiting = wait - timeSinceLastCall; return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting; } function shouldInvoke(time2) { var timeSinceLastCall = time2 - lastCallTime, timeSinceLastInvoke = time2 - lastInvokeTime; return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; } function timerExpired() { var time2 = now(); if (shouldInvoke(time2)) { return trailingEdge(time2); } timerId = setTimeout(timerExpired, remainingWait(time2)); } function trailingEdge(time2) { timerId = void 0; if (trailing && lastArgs) { return invokeFunc(time2); } lastArgs = lastThis = void 0; return result; } function cancel() { if (timerId !== void 0) { clearTimeout(timerId); } lastInvokeTime = 0; lastArgs = lastCallTime = lastThis = timerId = void 0; } function flush() { return timerId === void 0 ? result : trailingEdge(now()); } function debounced() { var time2 = now(), isInvoking = shouldInvoke(time2); lastArgs = arguments; lastThis = this; lastCallTime = time2; if (isInvoking) { if (timerId === void 0) { return leadingEdge(lastCallTime); } if (maxing) { clearTimeout(timerId); timerId = setTimeout(timerExpired, wait); return invokeFunc(lastCallTime); } } if (timerId === void 0) { timerId = setTimeout(timerExpired, wait); } return result; } debounced.cancel = cancel; debounced.flush = flush; return debounced; } var debounce_1 = debounce$1; var heap$1 = { exports: {} }; var heap = { exports: {} }; (function(module, exports) { (function() { var Heap2, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min4, nlargest, nsmallest, updateItem, _siftdown, _siftup; floor = Math.floor, min4 = Math.min; defaultCmp = function(x, y) { if (x < y) { return -1; } if (x > y) { return 1; } return 0; }; insort = function(a, x, lo, hi, cmp) { var mid; if (lo == null) { lo = 0; } if (cmp == null) { cmp = defaultCmp; } if (lo < 0) { throw new Error("lo must be non-negative"); } if (hi == null) { hi = a.length; } while (lo < hi) { mid = floor((lo + hi) / 2); if (cmp(x, a[mid]) < 0) { hi = mid; } else { lo = mid + 1; } } return [].splice.apply(a, [lo, lo - lo].concat(x)), x; }; heappush = function(array3, item, cmp) { if (cmp == null) { cmp = defaultCmp; } array3.push(item); return _siftdown(array3, 0, array3.length - 1, cmp); }; heappop = function(array3, cmp) { var lastelt, returnitem; if (cmp == null) { cmp = defaultCmp; } lastelt = array3.pop(); if (array3.length) { returnitem = array3[0]; array3[0] = lastelt; _siftup(array3, 0, cmp); } else { returnitem = lastelt; } return returnitem; }; heapreplace = function(array3, item, cmp) { var returnitem; if (cmp == null) { cmp = defaultCmp; } returnitem = array3[0]; array3[0] = item; _siftup(array3, 0, cmp); return returnitem; }; heappushpop = function(array3, item, cmp) { var _ref; if (cmp == null) { cmp = defaultCmp; } if (array3.length && cmp(array3[0], item) < 0) { _ref = [array3[0], item], item = _ref[0], array3[0] = _ref[1]; _siftup(array3, 0, cmp); } return item; }; heapify = function(array3, cmp) { var i, _i, _len, _ref1, _results, _results1; if (cmp == null) { cmp = defaultCmp; } _ref1 = function() { _results1 = []; for (var _j = 0, _ref = floor(array3.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--) { _results1.push(_j); } return _results1; }.apply(this).reverse(); _results = []; for (_i = 0, _len = _ref1.length; _i < _len; _i++) { i = _ref1[_i]; _results.push(_siftup(array3, i, cmp)); } return _results; }; updateItem = function(array3, item, cmp) { var pos; if (cmp == null) { cmp = defaultCmp; } pos = array3.indexOf(item); if (pos === -1) { return; } _siftdown(array3, 0, pos, cmp); return _siftup(array3, pos, cmp); }; nlargest = function(array3, n, cmp) { var elem, result, _i, _len, _ref; if (cmp == null) { cmp = defaultCmp; } result = array3.slice(0, n); if (!result.length) { return result; } heapify(result, cmp); _ref = array3.slice(n); for (_i = 0, _len = _ref.length; _i < _len; _i++) { elem = _ref[_i]; heappushpop(result, elem, cmp); } return result.sort(cmp).reverse(); }; nsmallest = function(array3, n, cmp) { var elem, los, result, _i, _j, _len, _ref, _ref1, _results; if (cmp == null) { cmp = defaultCmp; } if (n * 10 <= array3.length) { result = array3.slice(0, n).sort(cmp); if (!result.length) { return result; } los = result[result.length - 1]; _ref = array3.slice(n); for (_i = 0, _len = _ref.length; _i < _len; _i++) { elem = _ref[_i]; if (cmp(elem, los) < 0) { insort(result, elem, 0, null, cmp); result.pop(); los = result[result.length - 1]; } } return result; } heapify(array3, cmp); _results = []; for (_j = 0, _ref1 = min4(n, array3.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; 0 <= _ref1 ? ++_j : --_j) { _results.push(heappop(array3, cmp)); } return _results; }; _siftdown = function(array3, startpos, pos, cmp) { var newitem, parent4, parentpos; if (cmp == null) { cmp = defaultCmp; } newitem = array3[pos]; while (pos > startpos) { parentpos = pos - 1 >> 1; parent4 = array3[parentpos]; if (cmp(newitem, parent4) < 0) { array3[pos] = parent4; pos = parentpos; continue; } break; } return array3[pos] = newitem; }; _siftup = function(array3, pos, cmp) { var childpos, endpos, newitem, rightpos, startpos; if (cmp == null) { cmp = defaultCmp; } endpos = array3.length; startpos = pos; newitem = array3[pos]; childpos = 2 * pos + 1; while (childpos < endpos) { rightpos = childpos + 1; if (rightpos < endpos && !(cmp(array3[childpos], array3[rightpos]) < 0)) { childpos = rightpos; } array3[pos] = array3[childpos]; pos = childpos; childpos = 2 * pos + 1; } array3[pos] = newitem; return _siftdown(array3, startpos, pos, cmp); }; Heap2 = function() { Heap3.push = heappush; Heap3.pop = heappop; Heap3.replace = heapreplace; Heap3.pushpop = heappushpop; Heap3.heapify = heapify; Heap3.updateItem = updateItem; Heap3.nlargest = nlargest; Heap3.nsmallest = nsmallest; function Heap3(cmp) { this.cmp = cmp != null ? cmp : defaultCmp; this.nodes = []; } Heap3.prototype.push = function(x) { return heappush(this.nodes, x, this.cmp); }; Heap3.prototype.pop = function() { return heappop(this.nodes, this.cmp); }; Heap3.prototype.peek = function() { return this.nodes[0]; }; Heap3.prototype.contains = function(x) { return this.nodes.indexOf(x) !== -1; }; Heap3.prototype.replace = function(x) { return heapreplace(this.nodes, x, this.cmp); }; Heap3.prototype.pushpop = function(x) { return heappushpop(this.nodes, x, this.cmp); }; Heap3.prototype.heapify = function() { return heapify(this.nodes, this.cmp); }; Heap3.prototype.updateItem = function(x) { return updateItem(this.nodes, x, this.cmp); }; Heap3.prototype.clear = function() { return this.nodes = []; }; Heap3.prototype.empty = function() { return this.nodes.length === 0; }; Heap3.prototype.size = function() { return this.nodes.length; }; Heap3.prototype.clone = function() { var heap2; heap2 = new Heap3(); heap2.nodes = this.nodes.slice(0); return heap2; }; Heap3.prototype.toArray = function() { return this.nodes.slice(0); }; Heap3.prototype.insert = Heap3.prototype.push; Heap3.prototype.top = Heap3.prototype.peek; Heap3.prototype.front = Heap3.prototype.peek; Heap3.prototype.has = Heap3.prototype.contains; Heap3.prototype.copy = Heap3.prototype.clone; return Heap3; }(); (function(root2, factory) { { return module.exports = factory(); } })(this, function() { return Heap2; }); }).call(commonjsGlobal); })(heap); (function(module) { module.exports = heap.exports; })(heap$1); var isArray$4 = Array.isArray; var isArray_1 = isArray$4; var isArray$3 = isArray_1, isSymbol$3 = isSymbol_1; var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/; function isKey$1(value, object3) { if (isArray$3(value)) { return false; } var type = typeof value; if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol$3(value)) { return true; } return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object3 != null && value in Object(object3); } var _isKey = isKey$1; var baseGetTag = _baseGetTag, isObject$2 = isObject_1; var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]"; function isFunction$1(value) { if (!isObject$2(value)) { return false; } var tag = baseGetTag(value); return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; } var isFunction_1 = isFunction$1; var root$1 = _root; var coreJsData$1 = root$1["__core-js_shared__"]; var _coreJsData = coreJsData$1; var coreJsData = _coreJsData; var maskSrcKey = function() { var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ""); return uid ? "Symbol(src)_1." + uid : ""; }(); function isMasked$1(func) { return !!maskSrcKey && maskSrcKey in func; } var _isMasked = isMasked$1; var funcProto$1 = Function.prototype; var funcToString$1 = funcProto$1.toString; function toSource$1(func) { if (func != null)