import { getDiagramElement as oe } from "./chunk-55IACEB6.js";
import { setupViewPortForSVG as ae } from "./chunk-QN33PNHL.js";
import { getRegisteredLayoutAlgorithm as ce, render as le } from "./chunk-N4CR4FBY.js";
import "./chunk-QXUST7PY.js";
import "./chunk-HN2XXSSU.js";
import "./chunk-JZLCHNYA.js";
import { __name as c, log as C } from "./chunk-AGHRB4JF.js";
import { defaultConfig_default as V, getConfig2 as W, sanitizeText as F, getUserDefinedConfig as he } from "./chunk-ABZYJK2D.js";
import "./chunk-JA3XYJ7Z.js";
import "./chunk-S3R3BYOJ.js";
import ge from "../../../../../../uuid@11.1.0/node_modules/uuid/dist/esm-browser/v4.js";
import de from "../../../../../../khroma@2.1.0/node_modules/khroma/dist/methods/is_dark.js";
import ue from "../../../../../../khroma@2.1.0/node_modules/khroma/dist/methods/lighten.js";
import pe from "../../../../../../khroma@2.1.0/node_modules/khroma/dist/methods/darken.js";
var X = (function() {
  var r = /* @__PURE__ */ c(function(x, s, t, o) {
    for (t = t || {}, o = x.length; o--; t[x[o]] = s) ;
    return t;
  }, "o"), e = [1, 4], i = [1, 13], l = [1, 12], p = [1, 15], h = [1, 16], u = [1, 20], y = [1, 19], E = [6, 7, 8], _ = [1, 26], m = [1, 24], R = [1, 25], S = [6, 7, 11], Y = [1, 6, 13, 15, 16, 19, 22], q = [1, 33], J = [1, 34], A = [1, 6, 7, 11, 13, 15, 16, 19, 22], G = {
    trace: /* @__PURE__ */ c(function() {
    }, "trace"),
    yy: {},
    symbols_: { error: 2, start: 3, mindMap: 4, spaceLines: 5, SPACELINE: 6, NL: 7, MINDMAP: 8, document: 9, stop: 10, EOF: 11, statement: 12, SPACELIST: 13, node: 14, ICON: 15, CLASS: 16, nodeWithId: 17, nodeWithoutId: 18, NODE_DSTART: 19, NODE_DESCR: 20, NODE_DEND: 21, NODE_ID: 22, $accept: 0, $end: 1 },
    terminals_: { 2: "error", 6: "SPACELINE", 7: "NL", 8: "MINDMAP", 11: "EOF", 13: "SPACELIST", 15: "ICON", 16: "CLASS", 19: "NODE_DSTART", 20: "NODE_DESCR", 21: "NODE_DEND", 22: "NODE_ID" },
    productions_: [0, [3, 1], [3, 2], [5, 1], [5, 2], [5, 2], [4, 2], [4, 3], [10, 1], [10, 1], [10, 1], [10, 2], [10, 2], [9, 3], [9, 2], [12, 2], [12, 2], [12, 2], [12, 1], [12, 1], [12, 1], [12, 1], [12, 1], [14, 1], [14, 1], [18, 3], [17, 1], [17, 4]],
    performAction: /* @__PURE__ */ c(function(s, t, o, a, d, n, w) {
      var g = n.length - 1;
      switch (d) {
        case 6:
        case 7:
          return a;
        case 8:
          a.getLogger().trace("Stop NL ");
          break;
        case 9:
          a.getLogger().trace("Stop EOF ");
          break;
        case 11:
          a.getLogger().trace("Stop NL2 ");
          break;
        case 12:
          a.getLogger().trace("Stop EOF2 ");
          break;
        case 15:
          a.getLogger().info("Node: ", n[g].id), a.addNode(n[g - 1].length, n[g].id, n[g].descr, n[g].type);
          break;
        case 16:
          a.getLogger().trace("Icon: ", n[g]), a.decorateNode({ icon: n[g] });
          break;
        case 17:
        case 21:
          a.decorateNode({ class: n[g] });
          break;
        case 18:
          a.getLogger().trace("SPACELIST");
          break;
        case 19:
          a.getLogger().trace("Node: ", n[g].id), a.addNode(0, n[g].id, n[g].descr, n[g].type);
          break;
        case 20:
          a.decorateNode({ icon: n[g] });
          break;
        case 25:
          a.getLogger().trace("node found ..", n[g - 2]), this.$ = { id: n[g - 1], descr: n[g - 1], type: a.getType(n[g - 2], n[g]) };
          break;
        case 26:
          this.$ = { id: n[g], descr: n[g], type: a.nodeType.DEFAULT };
          break;
        case 27:
          a.getLogger().trace("node found ..", n[g - 3]), this.$ = { id: n[g - 3], descr: n[g - 1], type: a.getType(n[g - 2], n[g]) };
          break;
      }
    }, "anonymous"),
    table: [{ 3: 1, 4: 2, 5: 3, 6: [1, 5], 8: e }, { 1: [3] }, { 1: [2, 1] }, { 4: 6, 6: [1, 7], 7: [1, 8], 8: e }, { 6: i, 7: [1, 10], 9: 9, 12: 11, 13: l, 14: 14, 15: p, 16: h, 17: 17, 18: 18, 19: u, 22: y }, r(E, [2, 3]), { 1: [2, 2] }, r(E, [2, 4]), r(E, [2, 5]), { 1: [2, 6], 6: i, 12: 21, 13: l, 14: 14, 15: p, 16: h, 17: 17, 18: 18, 19: u, 22: y }, { 6: i, 9: 22, 12: 11, 13: l, 14: 14, 15: p, 16: h, 17: 17, 18: 18, 19: u, 22: y }, { 6: _, 7: m, 10: 23, 11: R }, r(S, [2, 22], { 17: 17, 18: 18, 14: 27, 15: [1, 28], 16: [1, 29], 19: u, 22: y }), r(S, [2, 18]), r(S, [2, 19]), r(S, [2, 20]), r(S, [2, 21]), r(S, [2, 23]), r(S, [2, 24]), r(S, [2, 26], { 19: [1, 30] }), { 20: [1, 31] }, { 6: _, 7: m, 10: 32, 11: R }, { 1: [2, 7], 6: i, 12: 21, 13: l, 14: 14, 15: p, 16: h, 17: 17, 18: 18, 19: u, 22: y }, r(Y, [2, 14], { 7: q, 11: J }), r(A, [2, 8]), r(A, [2, 9]), r(A, [2, 10]), r(S, [2, 15]), r(S, [2, 16]), r(S, [2, 17]), { 20: [1, 35] }, { 21: [1, 36] }, r(Y, [2, 13], { 7: q, 11: J }), r(A, [2, 11]), r(A, [2, 12]), { 21: [1, 37] }, r(S, [2, 25]), r(S, [2, 27])],
    defaultActions: { 2: [2, 1], 6: [2, 2] },
    parseError: /* @__PURE__ */ c(function(s, t) {
      if (t.recoverable)
        this.trace(s);
      else {
        var o = new Error(s);
        throw o.hash = t, o;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ c(function(s) {
      var t = this, o = [0], a = [], d = [null], n = [], w = this.table, g = "", M = 0, K = 0, ie = 2, Q = 1, se = n.slice.call(arguments, 1), f = Object.create(this.lexer), v = { yy: {} };
      for (var j in this.yy)
        Object.prototype.hasOwnProperty.call(this.yy, j) && (v.yy[j] = this.yy[j]);
      f.setInput(s, v.yy), v.yy.lexer = f, v.yy.parser = this, typeof f.yylloc > "u" && (f.yylloc = {});
      var $ = f.yylloc;
      n.push($);
      var ne = f.options && f.options.ranges;
      typeof v.yy.parseError == "function" ? this.parseError = v.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function re(N) {
        o.length = o.length - 2 * N, d.length = d.length - N, n.length = n.length - N;
      }
      c(re, "popStack");
      function Z() {
        var N;
        return N = a.pop() || f.lex() || Q, typeof N != "number" && (N instanceof Array && (a = N, N = a.pop()), N = t.symbols_[N] || N), N;
      }
      c(Z, "lex");
      for (var b, T, D, H, O = {}, U, k, ee, B; ; ) {
        if (T = o[o.length - 1], this.defaultActions[T] ? D = this.defaultActions[T] : ((b === null || typeof b > "u") && (b = Z()), D = w[T] && w[T][b]), typeof D > "u" || !D.length || !D[0]) {
          var z = "";
          B = [];
          for (U in w[T])
            this.terminals_[U] && U > ie && B.push("'" + this.terminals_[U] + "'");
          f.showPosition ? z = "Parse error on line " + (M + 1) + `:
` + f.showPosition() + `
Expecting ` + B.join(", ") + ", got '" + (this.terminals_[b] || b) + "'" : z = "Parse error on line " + (M + 1) + ": Unexpected " + (b == Q ? "end of input" : "'" + (this.terminals_[b] || b) + "'"), this.parseError(z, {
            text: f.match,
            token: this.terminals_[b] || b,
            line: f.yylineno,
            loc: $,
            expected: B
          });
        }
        if (D[0] instanceof Array && D.length > 1)
          throw new Error("Parse Error: multiple actions possible at state: " + T + ", token: " + b);
        switch (D[0]) {
          case 1:
            o.push(b), d.push(f.yytext), n.push(f.yylloc), o.push(D[1]), b = null, K = f.yyleng, g = f.yytext, M = f.yylineno, $ = f.yylloc;
            break;
          case 2:
            if (k = this.productions_[D[1]][1], O.$ = d[d.length - k], O._$ = {
              first_line: n[n.length - (k || 1)].first_line,
              last_line: n[n.length - 1].last_line,
              first_column: n[n.length - (k || 1)].first_column,
              last_column: n[n.length - 1].last_column
            }, ne && (O._$.range = [
              n[n.length - (k || 1)].range[0],
              n[n.length - 1].range[1]
            ]), H = this.performAction.apply(O, [
              g,
              K,
              M,
              v.yy,
              D[1],
              d,
              n
            ].concat(se)), typeof H < "u")
              return H;
            k && (o = o.slice(0, -1 * k * 2), d = d.slice(0, -1 * k), n = n.slice(0, -1 * k)), o.push(this.productions_[D[1]][0]), d.push(O.$), n.push(O._$), ee = w[o[o.length - 2]][o[o.length - 1]], o.push(ee);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  }, te = /* @__PURE__ */ (function() {
    var x = {
      EOF: 1,
      parseError: /* @__PURE__ */ c(function(t, o) {
        if (this.yy.parser)
          this.yy.parser.parseError(t, o);
        else
          throw new Error(t);
      }, "parseError"),
      // resets the lexer, sets new input
      setInput: /* @__PURE__ */ c(function(s, t) {
        return this.yy = t || this.yy || {}, this._input = s, this._more = this._backtrack = this.done = !1, 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;
      }, "setInput"),
      // consumes and returns one char from the input
      input: /* @__PURE__ */ c(function() {
        var s = this._input[0];
        this.yytext += s, this.yyleng++, this.offset++, this.match += s, this.matched += s;
        var t = s.match(/(?:\r\n?|\n).*/g);
        return t ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), s;
      }, "input"),
      // unshifts one char (or a string) into the input
      unput: /* @__PURE__ */ c(function(s) {
        var t = s.length, o = s.split(/(?:\r\n?|\n)/g);
        this._input = s + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - t), this.offset -= t;
        var a = 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), o.length - 1 && (this.yylineno -= o.length - 1);
        var d = 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: o ? (o.length === a.length ? this.yylloc.first_column : 0) + a[a.length - o.length].length - o[0].length : this.yylloc.first_column - t
        }, this.options.ranges && (this.yylloc.range = [d[0], d[0] + this.yyleng - t]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      // When called from action, caches matched text and appends it on next action
      more: /* @__PURE__ */ c(function() {
        return this._more = !0, this;
      }, "more"),
      // 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: /* @__PURE__ */ c(function() {
        if (this.options.backtrack_lexer)
          this._backtrack = !0;
        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).
` + this.showPosition(), {
            text: "",
            token: null,
            line: this.yylineno
          });
        return this;
      }, "reject"),
      // retain first n characters of the match
      less: /* @__PURE__ */ c(function(s) {
        this.unput(this.match.slice(s));
      }, "less"),
      // displays already matched input, i.e. for error messages
      pastInput: /* @__PURE__ */ c(function() {
        var s = this.matched.substr(0, this.matched.length - this.match.length);
        return (s.length > 20 ? "..." : "") + s.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      // displays upcoming input, i.e. for error messages
      upcomingInput: /* @__PURE__ */ c(function() {
        var s = this.match;
        return s.length < 20 && (s += this._input.substr(0, 20 - s.length)), (s.substr(0, 20) + (s.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      // displays the character position where the lexing error occurred, i.e. for error messages
      showPosition: /* @__PURE__ */ c(function() {
        var s = this.pastInput(), t = new Array(s.length + 1).join("-");
        return s + this.upcomingInput() + `
` + t + "^";
      }, "showPosition"),
      // test the lexed token: return FALSE when not a match, otherwise return token
      test_match: /* @__PURE__ */ c(function(s, t) {
        var o, a, d;
        if (this.options.backtrack_lexer && (d = {
          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 && (d.yylloc.range = this.yylloc.range.slice(0))), a = s[0].match(/(?:\r\n?|\n).*/g), a && (this.yylineno += a.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: a ? a[a.length - 1].length - a[a.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + s[0].length
        }, this.yytext += s[0], this.match += s[0], this.matches = s, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = !1, this._backtrack = !1, this._input = this._input.slice(s[0].length), this.matched += s[0], o = this.performAction.call(this, this.yy, this, t, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), o)
          return o;
        if (this._backtrack) {
          for (var n in d)
            this[n] = d[n];
          return !1;
        }
        return !1;
      }, "test_match"),
      // return next match in input
      next: /* @__PURE__ */ c(function() {
        if (this.done)
          return this.EOF;
        this._input || (this.done = !0);
        var s, t, o, a;
        this._more || (this.yytext = "", this.match = "");
        for (var d = this._currentRules(), n = 0; n < d.length; n++)
          if (o = this._input.match(this.rules[d[n]]), o && (!t || o[0].length > t[0].length)) {
            if (t = o, a = n, this.options.backtrack_lexer) {
              if (s = this.test_match(o, d[n]), s !== !1)
                return s;
              if (this._backtrack) {
                t = !1;
                continue;
              } else
                return !1;
            } else if (!this.options.flex)
              break;
          }
        return t ? (s = this.test_match(t, d[a]), s !== !1 ? s : !1) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      // return next match that has a token
      lex: /* @__PURE__ */ c(function() {
        var t = this.next();
        return t || this.lex();
      }, "lex"),
      // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
      begin: /* @__PURE__ */ c(function(t) {
        this.conditionStack.push(t);
      }, "begin"),
      // pop the previously active lexer condition state off the condition stack
      popState: /* @__PURE__ */ c(function() {
        var t = this.conditionStack.length - 1;
        return t > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      // produce the lexer rule set which is active for the currently active lexer condition state
      _currentRules: /* @__PURE__ */ c(function() {
        return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
      }, "_currentRules"),
      // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
      topState: /* @__PURE__ */ c(function(t) {
        return t = this.conditionStack.length - 1 - Math.abs(t || 0), t >= 0 ? this.conditionStack[t] : "INITIAL";
      }, "topState"),
      // alias for begin(condition)
      pushState: /* @__PURE__ */ c(function(t) {
        this.begin(t);
      }, "pushState"),
      // return the number of states currently on the stack
      stateStackSize: /* @__PURE__ */ c(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ c(function(t, o, a, d) {
        switch (a) {
          case 0:
            return t.getLogger().trace("Found comment", o.yytext), 6;
          case 1:
            return 8;
          case 2:
            this.begin("CLASS");
            break;
          case 3:
            return this.popState(), 16;
          case 4:
            this.popState();
            break;
          case 5:
            t.getLogger().trace("Begin icon"), this.begin("ICON");
            break;
          case 6:
            return t.getLogger().trace("SPACELINE"), 6;
          case 7:
            return 7;
          case 8:
            return 15;
          case 9:
            t.getLogger().trace("end icon"), this.popState();
            break;
          case 10:
            return t.getLogger().trace("Exploding node"), this.begin("NODE"), 19;
          case 11:
            return t.getLogger().trace("Cloud"), this.begin("NODE"), 19;
          case 12:
            return t.getLogger().trace("Explosion Bang"), this.begin("NODE"), 19;
          case 13:
            return t.getLogger().trace("Cloud Bang"), this.begin("NODE"), 19;
          case 14:
            return this.begin("NODE"), 19;
          case 15:
            return this.begin("NODE"), 19;
          case 16:
            return this.begin("NODE"), 19;
          case 17:
            return this.begin("NODE"), 19;
          case 18:
            return 13;
          case 19:
            return 22;
          case 20:
            return 11;
          case 21:
            this.begin("NSTR2");
            break;
          case 22:
            return "NODE_DESCR";
          case 23:
            this.popState();
            break;
          case 24:
            t.getLogger().trace("Starting NSTR"), this.begin("NSTR");
            break;
          case 25:
            return t.getLogger().trace("description:", o.yytext), "NODE_DESCR";
          case 26:
            this.popState();
            break;
          case 27:
            return this.popState(), t.getLogger().trace("node end ))"), "NODE_DEND";
          case 28:
            return this.popState(), t.getLogger().trace("node end )"), "NODE_DEND";
          case 29:
            return this.popState(), t.getLogger().trace("node end ...", o.yytext), "NODE_DEND";
          case 30:
            return this.popState(), t.getLogger().trace("node end (("), "NODE_DEND";
          case 31:
            return this.popState(), t.getLogger().trace("node end (-"), "NODE_DEND";
          case 32:
            return this.popState(), t.getLogger().trace("node end (-"), "NODE_DEND";
          case 33:
            return this.popState(), t.getLogger().trace("node end (("), "NODE_DEND";
          case 34:
            return this.popState(), t.getLogger().trace("node end (("), "NODE_DEND";
          case 35:
            return t.getLogger().trace("Long description:", o.yytext), 20;
          case 36:
            return t.getLogger().trace("Long description:", o.yytext), 20;
        }
      }, "anonymous"),
      rules: [/^(?:\s*%%.*)/i, /^(?:mindmap\b)/i, /^(?::::)/i, /^(?:.+)/i, /^(?:\n)/i, /^(?:::icon\()/i, /^(?:[\s]+[\n])/i, /^(?:[\n]+)/i, /^(?:[^\)]+)/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, /^(?:\(\()/i, /^(?:\()/i, /^(?:[^\)\]\(\}]+)/i, /^(?:.+(?!\(\())/i],
      conditions: { CLASS: { rules: [3, 4], inclusive: !1 }, ICON: { rules: [8, 9], inclusive: !1 }, NSTR2: { rules: [22, 23], inclusive: !1 }, NSTR: { rules: [25, 26], inclusive: !1 }, NODE: { rules: [21, 24, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36], inclusive: !1 }, INITIAL: { rules: [0, 1, 2, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], inclusive: !0 } }
    };
    return x;
  })();
  G.lexer = te;
  function P() {
    this.yy = {};
  }
  return c(P, "Parser"), P.prototype = G, G.Parser = P, new P();
})();
X.parser = X;
var fe = X, L = {
  DEFAULT: 0,
  NO_BORDER: 0,
  ROUNDED_RECT: 1,
  RECT: 2,
  CIRCLE: 3,
  CLOUD: 4,
  BANG: 5,
  HEXAGON: 6
}, I, ye = (I = class {
  constructor() {
    this.nodes = [], this.count = 0, this.elements = {}, this.getLogger = this.getLogger.bind(this), this.nodeType = L, this.clear(), this.getType = this.getType.bind(this), this.getElementById = this.getElementById.bind(this), this.getParent = this.getParent.bind(this), this.getMindmap = this.getMindmap.bind(this), this.addNode = this.addNode.bind(this), this.decorateNode = this.decorateNode.bind(this);
  }
  clear() {
    this.nodes = [], this.count = 0, this.elements = {}, this.baseLevel = void 0;
  }
  getParent(e) {
    for (let i = this.nodes.length - 1; i >= 0; i--)
      if (this.nodes[i].level < e)
        return this.nodes[i];
    return null;
  }
  getMindmap() {
    return this.nodes.length > 0 ? this.nodes[0] : null;
  }
  addNode(e, i, l, p) {
    var m, R;
    C.info("addNode", e, i, l, p);
    let h = !1;
    this.nodes.length === 0 ? (this.baseLevel = e, e = 0, h = !0) : this.baseLevel !== void 0 && (e = e - this.baseLevel, h = !1);
    const u = W();
    let y = ((m = u.mindmap) == null ? void 0 : m.padding) ?? V.mindmap.padding;
    switch (p) {
      case this.nodeType.ROUNDED_RECT:
      case this.nodeType.RECT:
      case this.nodeType.HEXAGON:
        y *= 2;
        break;
    }
    const E = {
      id: this.count++,
      nodeId: F(i, u),
      level: e,
      descr: F(l, u),
      type: p,
      children: [],
      width: ((R = u.mindmap) == null ? void 0 : R.maxNodeWidth) ?? V.mindmap.maxNodeWidth,
      padding: y,
      isRoot: h
    }, _ = this.getParent(e);
    if (_)
      _.children.push(E), this.nodes.push(E);
    else if (h)
      this.nodes.push(E);
    else
      throw new Error(
        `There can be only one root. No parent could be found for ("${E.descr}")`
      );
  }
  getType(e, i) {
    switch (C.debug("In get type", e, i), e) {
      case "[":
        return this.nodeType.RECT;
      case "(":
        return i === ")" ? this.nodeType.ROUNDED_RECT : this.nodeType.CLOUD;
      case "((":
        return this.nodeType.CIRCLE;
      case ")":
        return this.nodeType.CLOUD;
      case "))":
        return this.nodeType.BANG;
      case "{{":
        return this.nodeType.HEXAGON;
      default:
        return this.nodeType.DEFAULT;
    }
  }
  setElementForId(e, i) {
    this.elements[e] = i;
  }
  getElementById(e) {
    return this.elements[e];
  }
  decorateNode(e) {
    if (!e)
      return;
    const i = W(), l = this.nodes[this.nodes.length - 1];
    e.icon && (l.icon = F(e.icon, i)), e.class && (l.class = F(e.class, i));
  }
  type2Str(e) {
    switch (e) {
      case this.nodeType.DEFAULT:
        return "no-border";
      case this.nodeType.RECT:
        return "rect";
      case this.nodeType.ROUNDED_RECT:
        return "rounded-rect";
      case this.nodeType.CIRCLE:
        return "circle";
      case this.nodeType.CLOUD:
        return "cloud";
      case this.nodeType.BANG:
        return "bang";
      case this.nodeType.HEXAGON:
        return "hexgon";
      // cspell: disable-line
      default:
        return "no-border";
    }
  }
  /**
   * Assign section numbers to nodes based on their position relative to root
   * @param node - The mindmap node to process
   * @param sectionNumber - The section number to assign (undefined for root)
   */
  assignSections(e, i) {
    if (e.level === 0 ? e.section = void 0 : e.section = i, e.children)
      for (const [l, p] of e.children.entries()) {
        const h = e.level === 0 ? l : i;
        this.assignSections(p, h);
      }
  }
  /**
   * Convert mindmap tree structure to flat array of nodes
   * @param node - The mindmap node to process
   * @param processedNodes - Array to collect processed nodes
   */
  flattenNodes(e, i) {
    const l = ["mindmap-node"];
    e.isRoot === !0 ? l.push("section-root", "section--1") : e.section !== void 0 && l.push(`section-${e.section}`), e.class && l.push(e.class);
    const p = l.join(" "), h = /* @__PURE__ */ c((y) => {
      switch (y) {
        case L.CIRCLE:
          return "mindmapCircle";
        case L.RECT:
          return "rect";
        case L.ROUNDED_RECT:
          return "rounded";
        case L.CLOUD:
          return "cloud";
        case L.BANG:
          return "bang";
        case L.HEXAGON:
          return "hexagon";
        case L.DEFAULT:
          return "defaultMindmapNode";
        case L.NO_BORDER:
        default:
          return "rect";
      }
    }, "getShapeFromType"), u = {
      id: e.id.toString(),
      domId: "node_" + e.id.toString(),
      label: e.descr,
      isGroup: !1,
      shape: h(e.type),
      width: e.width,
      height: e.height ?? 0,
      padding: e.padding,
      cssClasses: p,
      cssStyles: [],
      look: "default",
      icon: e.icon,
      x: e.x,
      y: e.y,
      // Mindmap-specific properties
      level: e.level,
      nodeId: e.nodeId,
      type: e.type,
      section: e.section
    };
    if (i.push(u), e.children)
      for (const y of e.children)
        this.flattenNodes(y, i);
  }
  /**
   * Generate edges from parent-child relationships in mindmap tree
   * @param node - The mindmap node to process
   * @param edges - Array to collect edges
   */
  generateEdges(e, i) {
    if (e.children)
      for (const l of e.children) {
        let p = "edge";
        l.section !== void 0 && (p += ` section-edge-${l.section}`);
        const h = e.level + 1;
        p += ` edge-depth-${h}`;
        const u = {
          id: `edge_${e.id}_${l.id}`,
          start: e.id.toString(),
          end: l.id.toString(),
          type: "normal",
          curve: "basis",
          thickness: "normal",
          look: "default",
          classes: p,
          // Store mindmap-specific data
          depth: e.level,
          section: l.section
        };
        i.push(u), this.generateEdges(l, i);
      }
  }
  /**
   * Get structured data for layout algorithms
   * Following the pattern established by ER diagrams
   * @returns Structured data containing nodes, edges, and config
   */
  getData() {
    const e = this.getMindmap(), i = W(), p = he().layout !== void 0, h = i;
    if (p || (h.layout = "cose-bilkent"), !e)
      return {
        nodes: [],
        edges: [],
        config: h
      };
    C.debug("getData: mindmapRoot", e, i), this.assignSections(e);
    const u = [], y = [];
    this.flattenNodes(e, u), this.generateEdges(e, y), C.debug(
      `getData: processed ${u.length} nodes and ${y.length} edges`
    );
    const E = /* @__PURE__ */ new Map();
    for (const _ of u)
      E.set(_.id, {
        shape: _.shape,
        width: _.width,
        height: _.height,
        padding: _.padding
      });
    return {
      nodes: u,
      edges: y,
      config: h,
      // Store the root node for mindmap-specific layout algorithms
      rootNode: e,
      // Properties required by dagre layout algorithm
      markers: ["point"],
      // Mindmaps don't use markers
      direction: "TB",
      // Top-to-bottom direction for mindmaps
      nodeSpacing: 50,
      // Default spacing between nodes
      rankSpacing: 50,
      // Default spacing between ranks
      // Add shapes for ELK compatibility
      shapes: Object.fromEntries(E),
      // Additional properties that layout algorithms might expect
      type: "mindmap",
      diagramId: "mindmap-" + ge()
    };
  }
  // Expose logger to grammar
  getLogger() {
    return C;
  }
}, c(I, "MindmapDB"), I), me = /* @__PURE__ */ c(async (r, e, i, l) => {
  var E, _;
  C.debug(`Rendering mindmap diagram
` + r);
  const p = l.db, h = p.getData(), u = oe(e, h.config.securityLevel);
  h.type = l.type, h.layoutAlgorithm = ce(h.config.layout, {
    fallback: "cose-bilkent"
  }), h.diagramId = e, p.getMindmap() && (h.nodes.forEach((m) => {
    m.shape === "rounded" ? (m.radius = 15, m.taper = 15, m.stroke = "none", m.width = 0, m.padding = 15) : m.shape === "circle" ? m.padding = 10 : m.shape === "rect" && (m.width = 0, m.padding = 10);
  }), await le(h, u), ae(
    u,
    ((E = h.config.mindmap) == null ? void 0 : E.padding) ?? V.mindmap.padding,
    "mindmapDiagram",
    ((_ = h.config.mindmap) == null ? void 0 : _.useMaxWidth) ?? V.mindmap.useMaxWidth
  ));
}, "draw"), Ee = {
  draw: me
}, _e = /* @__PURE__ */ c((r) => {
  let e = "";
  for (let i = 0; i < r.THEME_COLOR_LIMIT; i++)
    r["lineColor" + i] = r["lineColor" + i] || r["cScaleInv" + i], de(r["lineColor" + i]) ? r["lineColor" + i] = ue(r["lineColor" + i], 20) : r["lineColor" + i] = pe(r["lineColor" + i], 20);
  for (let i = 0; i < r.THEME_COLOR_LIMIT; i++) {
    const l = "" + (17 - 3 * i);
    e += `
    .section-${i - 1} rect, .section-${i - 1} path, .section-${i - 1} circle, .section-${i - 1} polygon, .section-${i - 1} path  {
      fill: ${r["cScale" + i]};
    }
    .section-${i - 1} text {
     fill: ${r["cScaleLabel" + i]};
    }
    .node-icon-${i - 1} {
      font-size: 40px;
      color: ${r["cScaleLabel" + i]};
    }
    .section-edge-${i - 1}{
      stroke: ${r["cScale" + i]};
    }
    .edge-depth-${i - 1}{
      stroke-width: ${l};
    }
    .section-${i - 1} line {
      stroke: ${r["cScaleInv" + i]} ;
      stroke-width: 3;
    }

    .disabled, .disabled circle, .disabled text {
      fill: lightgray;
    }
    .disabled text {
      fill: #efefef;
    }
    `;
  }
  return e;
}, "genSections"), be = /* @__PURE__ */ c((r) => `
  .edge {
    stroke-width: 3;
  }
  ${_e(r)}
  .section-root rect, .section-root path, .section-root circle, .section-root polygon  {
    fill: ${r.git0};
  }
  .section-root text {
    fill: ${r.gitBranchLabel0};
  }
  .section-root span {
    color: ${r.gitBranchLabel0};
  }
  .section-2 span {
    color: ${r.gitBranchLabel0};
  }
  .icon-container {
    height:100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .edge {
    fill: none;
  }
  .mindmap-node-label {
    dy: 1em;
    alignment-baseline: middle;
    text-anchor: middle;
    dominant-baseline: middle;
    text-align: center;
  }
`, "getStyles"), Se = be, Me = {
  get db() {
    return new ye();
  },
  renderer: Ee,
  parser: fe,
  styles: Se
};
export {
  Me as diagram
};
