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