import { d as le } from "./chunk-55IACEB6-FAGpaDxG-BTfPS-CU.js";
import { d as ce } from "./chunk-EDXVE4YY-JJVh1SXw-B-sKHFur.js";
import { _ as l, l as C, al as he, am as de, aB as ge, aE as j, g as U, ae as G, bq as ue, bl as pe, bm as ye, bn as me } from "./index-Bh-wTBlD.js";
const f = [];
for (let e = 0; e < 256; ++e)
  f.push((e + 256).toString(16).slice(1));
function fe(e, i = 0) {
  return (f[e[i + 0]] + f[e[i + 1]] + f[e[i + 2]] + f[e[i + 3]] + "-" + f[e[i + 4]] + f[e[i + 5]] + "-" + f[e[i + 6]] + f[e[i + 7]] + "-" + f[e[i + 8]] + f[e[i + 9]] + "-" + f[e[i + 10]] + f[e[i + 11]] + f[e[i + 12]] + f[e[i + 13]] + f[e[i + 14]] + f[e[i + 15]]).toLowerCase();
}
let Y;
const Ee = new Uint8Array(16);
function _e() {
  if (!Y) {
    if (typeof crypto > "u" || !crypto.getRandomValues)
      throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
    Y = crypto.getRandomValues.bind(crypto);
  }
  return Y(Ee);
}
const be = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), ne = { randomUUID: be };
function ke(e, i, h) {
  var a;
  if (ne.randomUUID && !e)
    return ne.randomUUID();
  e = e || {};
  const n = e.random ?? ((a = e.rng) == null ? void 0 : a.call(e)) ?? _e();
  if (n.length < 16)
    throw new Error("Random bytes length must be >= 16");
  return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, fe(n);
}
var Q = function() {
  var e = /* @__PURE__ */ l(function(x, t, o, r) {
    for (o = o || {}, r = x.length; r--; o[x[r]] = t) ;
    return o;
  }, "o"), i = [1, 4], h = [1, 13], a = [1, 12], n = [1, 15], u = [1, 16], p = [1, 20], c = [1, 19], _ = [6, 7, 8], S = [1, 26], O = [1, 24], w = [1, 25], E = [6, 7, 11], y = [1, 6, 13, 15, 16, 19, 22], R = [1, 33], Z = [1, 34], A = [1, 6, 7, 11, 13, 15, 16, 19, 22], H = {
    trace: /* @__PURE__ */ l(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__ */ l(function(x, t, o, r, d, s, b) {
      var g = s.length - 1;
      switch (d) {
        case 6:
        case 7:
          return r;
        case 8:
          r.getLogger().trace("Stop NL ");
          break;
        case 9:
          r.getLogger().trace("Stop EOF ");
          break;
        case 11:
          r.getLogger().trace("Stop NL2 ");
          break;
        case 12:
          r.getLogger().trace("Stop EOF2 ");
          break;
        case 15:
          r.getLogger().info("Node: ", s[g].id), r.addNode(s[g - 1].length, s[g].id, s[g].descr, s[g].type);
          break;
        case 16:
          r.getLogger().trace("Icon: ", s[g]), r.decorateNode({ icon: s[g] });
          break;
        case 17:
        case 21:
          r.decorateNode({ class: s[g] });
          break;
        case 18:
          r.getLogger().trace("SPACELIST");
          break;
        case 19:
          r.getLogger().trace("Node: ", s[g].id), r.addNode(0, s[g].id, s[g].descr, s[g].type);
          break;
        case 20:
          r.decorateNode({ icon: s[g] });
          break;
        case 25:
          r.getLogger().trace("node found ..", s[g - 2]), this.$ = { id: s[g - 1], descr: s[g - 1], type: r.getType(s[g - 2], s[g]) };
          break;
        case 26:
          this.$ = { id: s[g], descr: s[g], type: r.nodeType.DEFAULT };
          break;
        case 27:
          r.getLogger().trace("node found ..", s[g - 3]), this.$ = { id: s[g - 3], descr: s[g - 1], type: r.getType(s[g - 2], s[g]) };
          break;
      }
    }, "anonymous"),
    table: [{ 3: 1, 4: 2, 5: 3, 6: [1, 5], 8: i }, { 1: [3] }, { 1: [2, 1] }, { 4: 6, 6: [1, 7], 7: [1, 8], 8: i }, { 6: h, 7: [1, 10], 9: 9, 12: 11, 13: a, 14: 14, 15: n, 16: u, 17: 17, 18: 18, 19: p, 22: c }, e(_, [2, 3]), { 1: [2, 2] }, e(_, [2, 4]), e(_, [2, 5]), { 1: [2, 6], 6: h, 12: 21, 13: a, 14: 14, 15: n, 16: u, 17: 17, 18: 18, 19: p, 22: c }, { 6: h, 9: 22, 12: 11, 13: a, 14: 14, 15: n, 16: u, 17: 17, 18: 18, 19: p, 22: c }, { 6: S, 7: O, 10: 23, 11: w }, e(E, [2, 22], { 17: 17, 18: 18, 14: 27, 15: [1, 28], 16: [1, 29], 19: p, 22: c }), e(E, [2, 18]), e(E, [2, 19]), e(E, [2, 20]), e(E, [2, 21]), e(E, [2, 23]), e(E, [2, 24]), e(E, [2, 26], { 19: [1, 30] }), { 20: [1, 31] }, { 6: S, 7: O, 10: 32, 11: w }, { 1: [2, 7], 6: h, 12: 21, 13: a, 14: 14, 15: n, 16: u, 17: 17, 18: 18, 19: p, 22: c }, e(y, [2, 14], { 7: R, 11: Z }), e(A, [2, 8]), e(A, [2, 9]), e(A, [2, 10]), e(E, [2, 15]), e(E, [2, 16]), e(E, [2, 17]), { 20: [1, 35] }, { 21: [1, 36] }, e(y, [2, 13], { 7: R, 11: Z }), e(A, [2, 11]), e(A, [2, 12]), { 21: [1, 37] }, e(E, [2, 25]), e(E, [2, 27])],
    defaultActions: { 2: [2, 1], 6: [2, 2] },
    parseError: /* @__PURE__ */ l(function(x, t) {
      if (t.recoverable)
        this.trace(x);
      else {
        var o = new Error(x);
        throw o.hash = t, o;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ l(function(x) {
      var t = this, o = [0], r = [], d = [null], s = [], b = this.table, g = "", P = 0, q = 0, se = 2, J = 1, oe = s.slice.call(arguments, 1), m = Object.create(this.lexer), I = { yy: {} };
      for (var W in this.yy)
        Object.prototype.hasOwnProperty.call(this.yy, W) && (I.yy[W] = this.yy[W]);
      m.setInput(x, I.yy), I.yy.lexer = m, I.yy.parser = this, typeof m.yylloc > "u" && (m.yylloc = {});
      var X = m.yylloc;
      s.push(X);
      var re = m.options && m.options.ranges;
      typeof I.yy.parseError == "function" ? this.parseError = I.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function ae(N) {
        o.length = o.length - 2 * N, d.length = d.length - N, s.length = s.length - N;
      }
      l(ae, "popStack");
      function ee() {
        var N;
        return N = r.pop() || m.lex() || J, typeof N != "number" && (N instanceof Array && (r = N, N = r.pop()), N = t.symbols_[N] || N), N;
      }
      l(ee, "lex");
      for (var k, T, L, V, v = {}, M, D, te, F; ; ) {
        if (T = o[o.length - 1], this.defaultActions[T] ? L = this.defaultActions[T] : ((k === null || typeof k > "u") && (k = ee()), L = b[T] && b[T][k]), typeof L > "u" || !L.length || !L[0]) {
          var z = "";
          F = [];
          for (M in b[T])
            this.terminals_[M] && M > se && F.push("'" + this.terminals_[M] + "'");
          m.showPosition ? z = "Parse error on line " + (P + 1) + `:
` + m.showPosition() + `
Expecting ` + F.join(", ") + ", got '" + (this.terminals_[k] || k) + "'" : z = "Parse error on line " + (P + 1) + ": Unexpected " + (k == J ? "end of input" : "'" + (this.terminals_[k] || k) + "'"), this.parseError(z, {
            text: m.match,
            token: this.terminals_[k] || k,
            line: m.yylineno,
            loc: X,
            expected: F
          });
        }
        if (L[0] instanceof Array && L.length > 1)
          throw new Error("Parse Error: multiple actions possible at state: " + T + ", token: " + k);
        switch (L[0]) {
          case 1:
            o.push(k), d.push(m.yytext), s.push(m.yylloc), o.push(L[1]), k = null, q = m.yyleng, g = m.yytext, P = m.yylineno, X = m.yylloc;
            break;
          case 2:
            if (D = this.productions_[L[1]][1], v.$ = d[d.length - D], v._$ = {
              first_line: s[s.length - (D || 1)].first_line,
              last_line: s[s.length - 1].last_line,
              first_column: s[s.length - (D || 1)].first_column,
              last_column: s[s.length - 1].last_column
            }, re && (v._$.range = [
              s[s.length - (D || 1)].range[0],
              s[s.length - 1].range[1]
            ]), V = this.performAction.apply(v, [
              g,
              q,
              P,
              I.yy,
              L[1],
              d,
              s
            ].concat(oe)), typeof V < "u")
              return V;
            D && (o = o.slice(0, -1 * D * 2), d = d.slice(0, -1 * D), s = s.slice(0, -1 * D)), o.push(this.productions_[L[1]][0]), d.push(v.$), s.push(v._$), te = b[o[o.length - 2]][o[o.length - 1]], o.push(te);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  }, ie = /* @__PURE__ */ function() {
    var x = {
      EOF: 1,
      parseError: /* @__PURE__ */ l(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__ */ l(function(t, o) {
        return this.yy = o || this.yy || {}, this._input = t, 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__ */ l(function() {
        var t = this._input[0];
        this.yytext += t, this.yyleng++, this.offset++, this.match += t, this.matched += t;
        var o = t.match(/(?:\r\n?|\n).*/g);
        return o ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), t;
      }, "input"),
      // unshifts one char (or a string) into the input
      unput: /* @__PURE__ */ l(function(t) {
        var o = t.length, r = t.split(/(?:\r\n?|\n)/g);
        this._input = t + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - o), this.offset -= o;
        var d = 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), r.length - 1 && (this.yylineno -= r.length - 1);
        var s = 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: r ? (r.length === d.length ? this.yylloc.first_column : 0) + d[d.length - r.length].length - r[0].length : this.yylloc.first_column - o
        }, this.options.ranges && (this.yylloc.range = [s[0], s[0] + this.yyleng - o]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      // When called from action, caches matched text and appends it on next action
      more: /* @__PURE__ */ l(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__ */ l(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__ */ l(function(t) {
        this.unput(this.match.slice(t));
      }, "less"),
      // displays already matched input, i.e. for error messages
      pastInput: /* @__PURE__ */ l(function() {
        var t = this.matched.substr(0, this.matched.length - this.match.length);
        return (t.length > 20 ? "..." : "") + t.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      // displays upcoming input, i.e. for error messages
      upcomingInput: /* @__PURE__ */ l(function() {
        var t = this.match;
        return t.length < 20 && (t += this._input.substr(0, 20 - t.length)), (t.substr(0, 20) + (t.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      // displays the character position where the lexing error occurred, i.e. for error messages
      showPosition: /* @__PURE__ */ l(function() {
        var t = this.pastInput(), o = new Array(t.length + 1).join("-");
        return t + this.upcomingInput() + `
` + o + "^";
      }, "showPosition"),
      // test the lexed token: return FALSE when not a match, otherwise return token
      test_match: /* @__PURE__ */ l(function(t, o) {
        var r, d, s;
        if (this.options.backtrack_lexer && (s = {
          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 && (s.yylloc.range = this.yylloc.range.slice(0))), d = t[0].match(/(?:\r\n?|\n).*/g), d && (this.yylineno += d.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: d ? d[d.length - 1].length - d[d.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + t[0].length
        }, this.yytext += t[0], this.match += t[0], this.matches = t, 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(t[0].length), this.matched += t[0], r = this.performAction.call(this, this.yy, this, o, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), r)
          return r;
        if (this._backtrack) {
          for (var b in s)
            this[b] = s[b];
          return !1;
        }
        return !1;
      }, "test_match"),
      // return next match in input
      next: /* @__PURE__ */ l(function() {
        if (this.done)
          return this.EOF;
        this._input || (this.done = !0);
        var t, o, r, d;
        this._more || (this.yytext = "", this.match = "");
        for (var s = this._currentRules(), b = 0; b < s.length; b++)
          if (r = this._input.match(this.rules[s[b]]), r && (!o || r[0].length > o[0].length)) {
            if (o = r, d = b, this.options.backtrack_lexer) {
              if (t = this.test_match(r, s[b]), t !== !1)
                return t;
              if (this._backtrack) {
                o = !1;
                continue;
              } else
                return !1;
            } else if (!this.options.flex)
              break;
          }
        return o ? (t = this.test_match(o, s[d]), t !== !1 ? t : !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__ */ l(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__ */ l(function(t) {
        this.conditionStack.push(t);
      }, "begin"),
      // pop the previously active lexer condition state off the condition stack
      popState: /* @__PURE__ */ l(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__ */ l(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__ */ l(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__ */ l(function(t) {
        this.begin(t);
      }, "pushState"),
      // return the number of states currently on the stack
      stateStackSize: /* @__PURE__ */ l(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ l(function(t, o, r, d) {
        switch (r) {
          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;
  }();
  H.lexer = ie;
  function B() {
    this.yy = {};
  }
  return l(B, "Parser"), B.prototype = H, H.Parser = B, new B();
}();
Q.parser = Q;
var Ne = Q, Le = 12, $ = {
  DEFAULT: 0,
  NO_BORDER: 0,
  ROUNDED_RECT: 1,
  RECT: 2,
  CIRCLE: 3,
  CLOUD: 4,
  BANG: 5,
  HEXAGON: 6
}, K, Se = (K = class {
  constructor() {
    this.nodes = [], this.count = 0, this.elements = {}, this.getLogger = this.getLogger.bind(this), this.nodeType = $, 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, h, a) {
    var n, u;
    C.info("addNode", e, i, h, a);
    let p = !1;
    this.nodes.length === 0 ? (this.baseLevel = e, e = 0, p = !0) : this.baseLevel !== void 0 && (e = e - this.baseLevel, p = !1);
    const c = U();
    let _ = ((n = c.mindmap) == null ? void 0 : n.padding) ?? j.mindmap.padding;
    switch (a) {
      case this.nodeType.ROUNDED_RECT:
      case this.nodeType.RECT:
      case this.nodeType.HEXAGON:
        _ *= 2;
        break;
    }
    const S = {
      id: this.count++,
      nodeId: G(i, c),
      level: e,
      descr: G(h, c),
      type: a,
      children: [],
      width: ((u = c.mindmap) == null ? void 0 : u.maxNodeWidth) ?? j.mindmap.maxNodeWidth,
      padding: _,
      isRoot: p
    }, O = this.getParent(e);
    if (O)
      O.children.push(S), this.nodes.push(S);
    else if (p)
      this.nodes.push(S);
    else
      throw new Error(
        `There can be only one root. No parent could be found for ("${S.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 = U(), h = this.nodes[this.nodes.length - 1];
    e.icon && (h.icon = G(e.icon, i)), e.class && (h.class = G(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";
      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 [h, a] of e.children.entries()) {
        const n = e.level === 0 ? h % (Le - 1) : i;
        this.assignSections(a, n);
      }
  }
  /**
   * 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 h = U(), a = ["mindmap-node"];
    e.isRoot === !0 ? a.push("section-root", "section--1") : e.section !== void 0 && a.push(`section-${e.section}`), e.class && a.push(e.class);
    const n = a.join(" "), u = /* @__PURE__ */ l((c) => {
      var _;
      const S = (((_ = h.theme) == null ? void 0 : _.toLowerCase()) ?? "").includes("redux");
      switch (c) {
        case $.CIRCLE:
          return "mindmapCircle";
        case $.RECT:
          return "rect";
        case $.ROUNDED_RECT:
          return "rounded";
        case $.CLOUD:
          return "cloud";
        case $.BANG:
          return "bang";
        case $.HEXAGON:
          return "hexagon";
        case $.DEFAULT:
          return S ? "rounded" : "defaultMindmapNode";
        case $.NO_BORDER:
        default:
          return "rect";
      }
    }, "getShapeFromType"), p = {
      id: e.id.toString(),
      domId: "node_" + e.id.toString(),
      label: e.descr,
      labelType: "markdown",
      isGroup: !1,
      shape: u(e.type),
      width: e.width,
      height: e.height ?? 0,
      padding: e.padding,
      cssClasses: n,
      cssStyles: [],
      look: h.look,
      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(p), e.children)
      for (const c of e.children)
        this.flattenNodes(c, 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)
      return;
    const h = U();
    for (const a of e.children) {
      let n = "edge";
      a.section !== void 0 && (n += ` section-edge-${a.section}`);
      const u = e.level + 1;
      n += ` edge-depth-${u}`;
      const p = {
        id: `edge_${e.id}_${a.id}`,
        start: e.id.toString(),
        end: a.id.toString(),
        type: "normal",
        curve: "basis",
        thickness: "normal",
        look: h.look,
        classes: n,
        // Store mindmap-specific data
        depth: e.level,
        section: a.section
      };
      i.push(p), this.generateEdges(a, 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 = U(), h = ue().layout !== void 0, a = i;
    if (h || (a.layout = "cose-bilkent"), !e)
      return {
        nodes: [],
        edges: [],
        config: a
      };
    C.debug("getData: mindmapRoot", e, i), this.assignSections(e);
    const n = [], u = [];
    this.flattenNodes(e, n), this.generateEdges(e, u), C.debug(
      `getData: processed ${n.length} nodes and ${u.length} edges`
    );
    const p = /* @__PURE__ */ new Map();
    for (const c of n)
      p.set(c.id, {
        shape: c.shape,
        width: c.width,
        height: c.height,
        padding: c.padding
      });
    return {
      nodes: n,
      edges: u,
      config: a,
      // 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(p),
      // Additional properties that layout algorithms might expect
      type: "mindmap",
      diagramId: "mindmap-" + ke()
    };
  }
  // Expose logger to grammar
  getLogger() {
    return C;
  }
}, l(K, "MindmapDB"), K), xe = /* @__PURE__ */ l(async (e, i, h, a) => {
  var n, u;
  C.debug(`Rendering mindmap diagram
` + e);
  const p = a.db, c = p.getData(), _ = le(i, c.config.securityLevel);
  if (c.type = a.type, c.layoutAlgorithm = he(c.config.layout, {
    fallback: "cose-bilkent"
  }), c.diagramId = i, !p.getMindmap())
    return;
  c.nodes.forEach((y) => {
    y.shape === "rounded" ? (y.radius = 15, y.taper = 15, y.stroke = "none", y.width = 0, y.padding = 15) : y.shape === "circle" ? y.padding = 10 : y.shape === "rect" ? (y.width = 0, y.padding = 10) : y.shape === "hexagon" && (y.width = 0, y.height = 0);
  }), await de(c, _);
  const { themeVariables: S } = ge(), { useGradient: O, gradientStart: w, gradientStop: E } = S;
  if (O && w && E) {
    const y = _.attr("id"), R = _.append("defs").append("linearGradient").attr("id", `${y}-gradient`).attr("gradientUnits", "objectBoundingBox").attr("x1", "0%").attr("y1", "0%").attr("x2", "100%").attr("y2", "0%");
    R.append("stop").attr("offset", "0%").attr("stop-color", w).attr("stop-opacity", 1), R.append("stop").attr("offset", "100%").attr("stop-color", E).attr("stop-opacity", 1);
  }
  ce(
    _,
    ((n = c.config.mindmap) == null ? void 0 : n.padding) ?? j.mindmap.padding,
    "mindmapDiagram",
    ((u = c.config.mindmap) == null ? void 0 : u.useMaxWidth) ?? j.mindmap.useMaxWidth
  );
}, "draw"), De = {
  draw: xe
}, $e = /* @__PURE__ */ l((e) => {
  const { theme: i, look: h } = e;
  let a = "";
  for (let n = 0; n < e.THEME_COLOR_LIMIT; n++)
    e["lineColor" + n] = e["lineColor" + n] || e["cScaleInv" + n], pe(e["lineColor" + n]) ? e["lineColor" + n] = ye(e["lineColor" + n], 20) : e["lineColor" + n] = me(e["lineColor" + n], 20);
  for (let n = 0; n < e.THEME_COLOR_LIMIT; n++) {
    const u = "" + (h === "neo" ? Math.max(10 - (n - 1) * 2, 2) : 17 - 3 * n);
    a += `
    .section-${n - 1} rect, .section-${n - 1} path, .section-${n - 1} circle, .section-${n - 1} polygon, .section-${n - 1} path  {
      fill: ${e["cScale" + n]};
    }
    .section-${n - 1} text {
     fill: ${e["cScaleLabel" + n]};
    }
     .section-${n - 1} span {
     color: ${e["cScaleLabel" + n]};
    }
    .node-icon-${n - 1} {
      font-size: 40px;
      color: ${e["cScaleLabel" + n]};
    }
    .section-edge-${n - 1}{
      stroke: ${e["cScale" + n]};
    }
    .edge-depth-${n - 1}{
      stroke-width: ${u};
    }
    .section-${n - 1} line {
      stroke: ${e["cScaleInv" + n]} ;
      stroke-width: 3;
    }

    .disabled, .disabled circle, .disabled text {
      fill: lightgray;
    }
    .disabled text {
      fill: #efefef;
    }
    [data-look="neo"].mindmap-node.section-${n - 1} rect, [data-look="neo"].mindmap-node.section-${n - 1} path, [data-look="neo"].mindmap-node.section-${n - 1} circle, [data-look="neo"].mindmap-node.section-${n - 1} polygon {
      fill: ${i === "redux" || i === "redux-dark" || i === "neutral" ? e.mainBkg : e["cScale" + n]};
      stroke: ${i === "redux" || i === "redux-dark" ? e.nodeBorder : e["cScale" + n]};
      stroke-width: ${e.strokeWidth ?? 2}px;
    }
    [data-look="neo"].section-edge-${n - 1}{
      stroke: ${i != null && i.includes("redux") || i === "neo-dark" ? e.nodeBorder : e["cScale" + n]};
    }
    [data-look="neo"].mindmap-node.section-${n - 1} text {
     fill: ${i === "redux" || i === "redux-dark" ? e.nodeBorder : e["cScaleLabel" + (i === "neutral" ? 1 : n)]};
    }
    `;
  }
  return a;
}, "genSections"), Oe = /* @__PURE__ */ l((e, i, h) => {
  let a = "";
  for (let n = 0; n < e; n++)
    a += `
    [data-look="neo"].mindmap-node.section-${n - 1} rect, [data-look="neo"].mindmap-node.section-${n - 1} path, [data-look="neo"].mindmap-node.section-${n - 1} circle, [data-look="neo"].mindmap-node.section-${n - 1} polygon {
      stroke: url(${i}-gradient);
      fill: ${h};
    }
    .section-${n - 1} line {
      stroke-width: 0;
    }`;
  return a;
}, "genGradient"), Ie = /* @__PURE__ */ l((e) => {
  const { theme: i } = e, h = e.svgId, a = e.dropShadow ? e.dropShadow.replace("url(#drop-shadow)", `url(${h}-drop-shadow)`) : "none";
  return `
  .edge {
    stroke-width: 3;
  }
  ${$e(e)}
  .section-root rect, .section-root path, .section-root circle, .section-root polygon  {
    fill: ${e.git0};
  }
  .section-root text {
    fill: ${e.gitBranchLabel0};
  }
  .section-root span {
    color: ${i != null && i.includes("redux") ? e.nodeBorder : e.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;
  }
  [data-look="neo"].mindmap-node  {
    filter: ${a};
  }
  [data-look="neo"].mindmap-node.section-root rect, [data-look="neo"].mindmap-node.section-root path, [data-look="neo"].mindmap-node.section-root circle, [data-look="neo"].mindmap-node.section-root polygon  {
    fill: ${i != null && i.includes("redux") ? e.mainBkg : e.git0};
  }
  [data-look="neo"].mindmap-node.section-root .text-inner-tspan {
    fill:  ${i != null && i.includes("redux") ? e.nodeBorder : e["cScaleLabel" + (i === "neutral" ? 1 : 0)]};
  }
  ${e.useGradient && h && e.mainBkg ? Oe(e.THEME_COLOR_LIMIT, h, e.mainBkg) : ""}
`;
}, "getStyles"), Te = Ie, Re = {
  get db() {
    return new Se();
  },
  renderer: De,
  parser: Ne,
  styles: Te
};
export {
  Re as diagram
};
