var _a;
import { g as utils_default, s as generateId } from "./chunk-S3R3BYOJ-mQeCz5CE.js";
import { i as log, r as __name } from "./src-Bf2iLOlr.js";
import { B as setAccTitle, C as getDiagramTitle, U as setDiagramTitle, _ as getAccDescription, a as clear, b as getConfig2, s as common_default, v as getAccTitle, z as setAccDescription } from "./chunk-ABZYJK2D-D0cLy8Bb.js";
import { r as render } from "./chunk-N4CR4FBY-8ycT-O9a.js";
import { t as getDiagramElement } from "./chunk-55IACEB6-B-1mjMMC.js";
import { t as setupViewPortForSVG } from "./chunk-QN33PNHL-Bb-eUBW3.js";
var parser = (function() {
  var e = /* @__PURE__ */ __name(function(e2, b2, x2, S) {
    for (x2 || (x2 = {}), S = e2.length; S--; x2[e2[S]] = b2) ;
    return x2;
  }, "o"), b = [1, 2], x = [1, 3], C = [1, 4], w = [2, 4], T = [1, 9], E = [1, 11], D = [1, 16], O = [1, 17], k = [1, 18], A = [1, 19], j = [1, 33], M = [1, 20], N = [1, 21], P = [1, 22], F = [1, 23], I = [1, 24], L = [1, 26], R = [1, 27], z = [1, 28], B = [1, 29], V = [1, 30], H = [1, 31], U = [1, 32], W = [1, 35], G = [1, 36], K = [1, 37], q = [1, 38], J = [1, 34], Y = [
    1,
    4,
    5,
    16,
    17,
    19,
    21,
    22,
    24,
    25,
    26,
    27,
    28,
    29,
    33,
    35,
    37,
    38,
    41,
    45,
    48,
    51,
    52,
    53,
    54,
    57
  ], X = [
    1,
    4,
    5,
    14,
    15,
    16,
    17,
    19,
    21,
    22,
    24,
    25,
    26,
    27,
    28,
    29,
    33,
    35,
    37,
    38,
    39,
    40,
    41,
    45,
    48,
    51,
    52,
    53,
    54,
    57
  ], Z = [
    4,
    5,
    16,
    17,
    19,
    21,
    22,
    24,
    25,
    26,
    27,
    28,
    29,
    33,
    35,
    37,
    38,
    41,
    45,
    48,
    51,
    52,
    53,
    54,
    57
  ], Q = {
    trace: /* @__PURE__ */ __name(function() {
    }, "trace"),
    yy: {},
    symbols_: {
      error: 2,
      start: 3,
      SPACE: 4,
      NL: 5,
      SD: 6,
      document: 7,
      line: 8,
      statement: 9,
      classDefStatement: 10,
      styleStatement: 11,
      cssClassStatement: 12,
      idStatement: 13,
      DESCR: 14,
      "-->": 15,
      HIDE_EMPTY: 16,
      scale: 17,
      WIDTH: 18,
      COMPOSIT_STATE: 19,
      STRUCT_START: 20,
      STRUCT_STOP: 21,
      STATE_DESCR: 22,
      AS: 23,
      ID: 24,
      FORK: 25,
      JOIN: 26,
      CHOICE: 27,
      CONCURRENT: 28,
      note: 29,
      notePosition: 30,
      NOTE_TEXT: 31,
      direction: 32,
      acc_title: 33,
      acc_title_value: 34,
      acc_descr: 35,
      acc_descr_value: 36,
      acc_descr_multiline_value: 37,
      CLICK: 38,
      STRING: 39,
      HREF: 40,
      classDef: 41,
      CLASSDEF_ID: 42,
      CLASSDEF_STYLEOPTS: 43,
      DEFAULT: 44,
      style: 45,
      STYLE_IDS: 46,
      STYLEDEF_STYLEOPTS: 47,
      class: 48,
      CLASSENTITY_IDS: 49,
      STYLECLASS: 50,
      direction_tb: 51,
      direction_bt: 52,
      direction_rl: 53,
      direction_lr: 54,
      eol: 55,
      ";": 56,
      EDGE_STATE: 57,
      STYLE_SEPARATOR: 58,
      left_of: 59,
      right_of: 60,
      $accept: 0,
      $end: 1
    },
    terminals_: {
      2: "error",
      4: "SPACE",
      5: "NL",
      6: "SD",
      14: "DESCR",
      15: "-->",
      16: "HIDE_EMPTY",
      17: "scale",
      18: "WIDTH",
      19: "COMPOSIT_STATE",
      20: "STRUCT_START",
      21: "STRUCT_STOP",
      22: "STATE_DESCR",
      23: "AS",
      24: "ID",
      25: "FORK",
      26: "JOIN",
      27: "CHOICE",
      28: "CONCURRENT",
      29: "note",
      31: "NOTE_TEXT",
      33: "acc_title",
      34: "acc_title_value",
      35: "acc_descr",
      36: "acc_descr_value",
      37: "acc_descr_multiline_value",
      38: "CLICK",
      39: "STRING",
      40: "HREF",
      41: "classDef",
      42: "CLASSDEF_ID",
      43: "CLASSDEF_STYLEOPTS",
      44: "DEFAULT",
      45: "style",
      46: "STYLE_IDS",
      47: "STYLEDEF_STYLEOPTS",
      48: "class",
      49: "CLASSENTITY_IDS",
      50: "STYLECLASS",
      51: "direction_tb",
      52: "direction_bt",
      53: "direction_rl",
      54: "direction_lr",
      56: ";",
      57: "EDGE_STATE",
      58: "STYLE_SEPARATOR",
      59: "left_of",
      60: "right_of"
    },
    productions_: [
      0,
      [3, 2],
      [3, 2],
      [3, 2],
      [7, 0],
      [7, 2],
      [8, 2],
      [8, 1],
      [8, 1],
      [9, 1],
      [9, 1],
      [9, 1],
      [9, 1],
      [9, 2],
      [9, 3],
      [9, 4],
      [9, 1],
      [9, 2],
      [9, 1],
      [9, 4],
      [9, 3],
      [9, 6],
      [9, 1],
      [9, 1],
      [9, 1],
      [9, 1],
      [9, 4],
      [9, 4],
      [9, 1],
      [9, 2],
      [9, 2],
      [9, 1],
      [9, 5],
      [9, 5],
      [10, 3],
      [10, 3],
      [11, 3],
      [12, 3],
      [32, 1],
      [32, 1],
      [32, 1],
      [32, 1],
      [55, 1],
      [55, 1],
      [13, 1],
      [13, 1],
      [13, 3],
      [13, 3],
      [30, 1],
      [30, 1]
    ],
    performAction: /* @__PURE__ */ __name(function(e2, b2, x2, S, C2, w2, T2) {
      var E2 = w2.length - 1;
      switch (C2) {
        case 3:
          return S.setRootDoc(w2[E2]), w2[E2];
        case 4:
          this.$ = [];
          break;
        case 5:
          w2[E2] != "nl" && (w2[E2 - 1].push(w2[E2]), this.$ = w2[E2 - 1]);
          break;
        case 6:
        case 7:
          this.$ = w2[E2];
          break;
        case 8:
          this.$ = "nl";
          break;
        case 12:
          this.$ = w2[E2];
          break;
        case 13:
          let e3 = w2[E2 - 1];
          e3.description = S.trimColon(w2[E2]), this.$ = e3;
          break;
        case 14:
          this.$ = {
            stmt: "relation",
            state1: w2[E2 - 2],
            state2: w2[E2]
          };
          break;
        case 15:
          let b3 = S.trimColon(w2[E2]);
          this.$ = {
            stmt: "relation",
            state1: w2[E2 - 3],
            state2: w2[E2 - 1],
            description: b3
          };
          break;
        case 19:
          this.$ = {
            stmt: "state",
            id: w2[E2 - 3],
            type: "default",
            description: "",
            doc: w2[E2 - 1]
          };
          break;
        case 20:
          var D2 = w2[E2], O2 = w2[E2 - 2].trim();
          if (w2[E2].match(":")) {
            var k2 = w2[E2].split(":");
            D2 = k2[0], O2 = [O2, k2[1]];
          }
          this.$ = {
            stmt: "state",
            id: D2,
            type: "default",
            description: O2
          };
          break;
        case 21:
          this.$ = {
            stmt: "state",
            id: w2[E2 - 3],
            type: "default",
            description: w2[E2 - 5],
            doc: w2[E2 - 1]
          };
          break;
        case 22:
          this.$ = {
            stmt: "state",
            id: w2[E2],
            type: "fork"
          };
          break;
        case 23:
          this.$ = {
            stmt: "state",
            id: w2[E2],
            type: "join"
          };
          break;
        case 24:
          this.$ = {
            stmt: "state",
            id: w2[E2],
            type: "choice"
          };
          break;
        case 25:
          this.$ = {
            stmt: "state",
            id: S.getDividerId(),
            type: "divider"
          };
          break;
        case 26:
          this.$ = {
            stmt: "state",
            id: w2[E2 - 1].trim(),
            note: {
              position: w2[E2 - 2].trim(),
              text: w2[E2].trim()
            }
          };
          break;
        case 29:
          this.$ = w2[E2].trim(), S.setAccTitle(this.$);
          break;
        case 30:
        case 31:
          this.$ = w2[E2].trim(), S.setAccDescription(this.$);
          break;
        case 32:
          this.$ = {
            stmt: "click",
            id: w2[E2 - 3],
            url: w2[E2 - 2],
            tooltip: w2[E2 - 1]
          };
          break;
        case 33:
          this.$ = {
            stmt: "click",
            id: w2[E2 - 3],
            url: w2[E2 - 1],
            tooltip: ""
          };
          break;
        case 34:
        case 35:
          this.$ = {
            stmt: "classDef",
            id: w2[E2 - 1].trim(),
            classes: w2[E2].trim()
          };
          break;
        case 36:
          this.$ = {
            stmt: "style",
            id: w2[E2 - 1].trim(),
            styleClass: w2[E2].trim()
          };
          break;
        case 37:
          this.$ = {
            stmt: "applyClass",
            id: w2[E2 - 1].trim(),
            styleClass: w2[E2].trim()
          };
          break;
        case 38:
          S.setDirection("TB"), this.$ = {
            stmt: "dir",
            value: "TB"
          };
          break;
        case 39:
          S.setDirection("BT"), this.$ = {
            stmt: "dir",
            value: "BT"
          };
          break;
        case 40:
          S.setDirection("RL"), this.$ = {
            stmt: "dir",
            value: "RL"
          };
          break;
        case 41:
          S.setDirection("LR"), this.$ = {
            stmt: "dir",
            value: "LR"
          };
          break;
        case 44:
        case 45:
          this.$ = {
            stmt: "state",
            id: w2[E2].trim(),
            type: "default",
            description: ""
          };
          break;
        case 46:
          this.$ = {
            stmt: "state",
            id: w2[E2 - 2].trim(),
            classes: [w2[E2].trim()],
            type: "default",
            description: ""
          };
          break;
        case 47:
          this.$ = {
            stmt: "state",
            id: w2[E2 - 2].trim(),
            classes: [w2[E2].trim()],
            type: "default",
            description: ""
          };
          break;
      }
    }, "anonymous"),
    table: [
      {
        3: 1,
        4: b,
        5: x,
        6: C
      },
      { 1: [3] },
      {
        3: 5,
        4: b,
        5: x,
        6: C
      },
      {
        3: 6,
        4: b,
        5: x,
        6: C
      },
      e([
        1,
        4,
        5,
        16,
        17,
        19,
        22,
        24,
        25,
        26,
        27,
        28,
        29,
        33,
        35,
        37,
        38,
        41,
        45,
        48,
        51,
        52,
        53,
        54,
        57
      ], w, { 7: 7 }),
      { 1: [2, 1] },
      { 1: [2, 2] },
      {
        1: [2, 3],
        4: T,
        5: E,
        8: 8,
        9: 10,
        10: 12,
        11: 13,
        12: 14,
        13: 15,
        16: D,
        17: O,
        19: k,
        22: A,
        24: j,
        25: M,
        26: N,
        27: P,
        28: F,
        29: I,
        32: 25,
        33: L,
        35: R,
        37: z,
        38: B,
        41: V,
        45: H,
        48: U,
        51: W,
        52: G,
        53: K,
        54: q,
        57: J
      },
      e(Y, [2, 5]),
      {
        9: 39,
        10: 12,
        11: 13,
        12: 14,
        13: 15,
        16: D,
        17: O,
        19: k,
        22: A,
        24: j,
        25: M,
        26: N,
        27: P,
        28: F,
        29: I,
        32: 25,
        33: L,
        35: R,
        37: z,
        38: B,
        41: V,
        45: H,
        48: U,
        51: W,
        52: G,
        53: K,
        54: q,
        57: J
      },
      e(Y, [2, 7]),
      e(Y, [2, 8]),
      e(Y, [2, 9]),
      e(Y, [2, 10]),
      e(Y, [2, 11]),
      e(Y, [2, 12], {
        14: [1, 40],
        15: [1, 41]
      }),
      e(Y, [2, 16]),
      { 18: [1, 42] },
      e(Y, [2, 18], { 20: [1, 43] }),
      { 23: [1, 44] },
      e(Y, [2, 22]),
      e(Y, [2, 23]),
      e(Y, [2, 24]),
      e(Y, [2, 25]),
      {
        30: 45,
        31: [1, 46],
        59: [1, 47],
        60: [1, 48]
      },
      e(Y, [2, 28]),
      { 34: [1, 49] },
      { 36: [1, 50] },
      e(Y, [2, 31]),
      {
        13: 51,
        24: j,
        57: J
      },
      {
        42: [1, 52],
        44: [1, 53]
      },
      { 46: [1, 54] },
      { 49: [1, 55] },
      e(X, [2, 44], { 58: [1, 56] }),
      e(X, [2, 45], { 58: [1, 57] }),
      e(Y, [2, 38]),
      e(Y, [2, 39]),
      e(Y, [2, 40]),
      e(Y, [2, 41]),
      e(Y, [2, 6]),
      e(Y, [2, 13]),
      {
        13: 58,
        24: j,
        57: J
      },
      e(Y, [2, 17]),
      e(Z, w, { 7: 59 }),
      { 24: [1, 60] },
      { 24: [1, 61] },
      { 23: [1, 62] },
      { 24: [2, 48] },
      { 24: [2, 49] },
      e(Y, [2, 29]),
      e(Y, [2, 30]),
      {
        39: [1, 63],
        40: [1, 64]
      },
      { 43: [1, 65] },
      { 43: [1, 66] },
      { 47: [1, 67] },
      { 50: [1, 68] },
      { 24: [1, 69] },
      { 24: [1, 70] },
      e(Y, [2, 14], { 14: [1, 71] }),
      {
        4: T,
        5: E,
        8: 8,
        9: 10,
        10: 12,
        11: 13,
        12: 14,
        13: 15,
        16: D,
        17: O,
        19: k,
        21: [1, 72],
        22: A,
        24: j,
        25: M,
        26: N,
        27: P,
        28: F,
        29: I,
        32: 25,
        33: L,
        35: R,
        37: z,
        38: B,
        41: V,
        45: H,
        48: U,
        51: W,
        52: G,
        53: K,
        54: q,
        57: J
      },
      e(Y, [2, 20], { 20: [1, 73] }),
      { 31: [1, 74] },
      { 24: [1, 75] },
      { 39: [1, 76] },
      { 39: [1, 77] },
      e(Y, [2, 34]),
      e(Y, [2, 35]),
      e(Y, [2, 36]),
      e(Y, [2, 37]),
      e(X, [2, 46]),
      e(X, [2, 47]),
      e(Y, [2, 15]),
      e(Y, [2, 19]),
      e(Z, w, { 7: 78 }),
      e(Y, [2, 26]),
      e(Y, [2, 27]),
      { 5: [1, 79] },
      { 5: [1, 80] },
      {
        4: T,
        5: E,
        8: 8,
        9: 10,
        10: 12,
        11: 13,
        12: 14,
        13: 15,
        16: D,
        17: O,
        19: k,
        21: [1, 81],
        22: A,
        24: j,
        25: M,
        26: N,
        27: P,
        28: F,
        29: I,
        32: 25,
        33: L,
        35: R,
        37: z,
        38: B,
        41: V,
        45: H,
        48: U,
        51: W,
        52: G,
        53: K,
        54: q,
        57: J
      },
      e(Y, [2, 32]),
      e(Y, [2, 33]),
      e(Y, [2, 21])
    ],
    defaultActions: {
      5: [2, 1],
      6: [2, 2],
      47: [2, 48],
      48: [2, 49]
    },
    parseError: /* @__PURE__ */ __name(function(e2, b2) {
      if (b2.recoverable) this.trace(e2);
      else {
        var x2 = Error(e2);
        throw x2.hash = b2, x2;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ __name(function(e2) {
      var b2 = this, x2 = [0], C2 = [], w2 = [null], T2 = [], E2 = this.table, D2 = "", O2 = 0, k2 = 0, A2 = 0, j2 = 2, M2 = 1, N2 = T2.slice.call(arguments, 1), P2 = Object.create(this.lexer), F2 = { yy: {} };
      for (var I2 in this.yy) Object.prototype.hasOwnProperty.call(this.yy, I2) && (F2.yy[I2] = this.yy[I2]);
      P2.setInput(e2, F2.yy), F2.yy.lexer = P2, F2.yy.parser = this, P2.yylloc === void 0 && (P2.yylloc = {});
      var L2 = P2.yylloc;
      T2.push(L2);
      var R2 = P2.options && P2.options.ranges;
      typeof F2.yy.parseError == "function" ? this.parseError = F2.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function z2(e3) {
        x2.length -= 2 * e3, w2.length -= e3, T2.length -= e3;
      }
      __name(z2, "popStack");
      function B2() {
        var e3 = C2.pop() || P2.lex() || M2;
        return typeof e3 != "number" && (e3 instanceof Array && (C2 = e3, e3 = C2.pop()), e3 = b2.symbols_[e3] || e3), e3;
      }
      __name(B2, "lex");
      for (var V2, H2, U2, W2, G2, K2 = {}, q2, J2, Y2, X2; ; ) {
        if (U2 = x2[x2.length - 1], this.defaultActions[U2] ? W2 = this.defaultActions[U2] : (V2 ?? (V2 = B2()), W2 = E2[U2] && E2[U2][V2]), W2 === void 0 || !W2.length || !W2[0]) {
          var Z2 = "";
          for (q2 in X2 = [], E2[U2]) this.terminals_[q2] && q2 > j2 && X2.push("'" + this.terminals_[q2] + "'");
          Z2 = P2.showPosition ? "Parse error on line " + (O2 + 1) + ":\n" + P2.showPosition() + "\nExpecting " + X2.join(", ") + ", got '" + (this.terminals_[V2] || V2) + "'" : "Parse error on line " + (O2 + 1) + ": Unexpected " + (V2 == M2 ? "end of input" : "'" + (this.terminals_[V2] || V2) + "'"), this.parseError(Z2, {
            text: P2.match,
            token: this.terminals_[V2] || V2,
            line: P2.yylineno,
            loc: L2,
            expected: X2
          });
        }
        if (W2[0] instanceof Array && W2.length > 1) throw Error("Parse Error: multiple actions possible at state: " + U2 + ", token: " + V2);
        switch (W2[0]) {
          case 1:
            x2.push(V2), w2.push(P2.yytext), T2.push(P2.yylloc), x2.push(W2[1]), V2 = null, H2 ? (V2 = H2, H2 = null) : (k2 = P2.yyleng, D2 = P2.yytext, O2 = P2.yylineno, L2 = P2.yylloc, A2 > 0 && A2--);
            break;
          case 2:
            if (J2 = this.productions_[W2[1]][1], K2.$ = w2[w2.length - J2], K2._$ = {
              first_line: T2[T2.length - (J2 || 1)].first_line,
              last_line: T2[T2.length - 1].last_line,
              first_column: T2[T2.length - (J2 || 1)].first_column,
              last_column: T2[T2.length - 1].last_column
            }, R2 && (K2._$.range = [T2[T2.length - (J2 || 1)].range[0], T2[T2.length - 1].range[1]]), G2 = this.performAction.apply(K2, [
              D2,
              k2,
              O2,
              F2.yy,
              W2[1],
              w2,
              T2
            ].concat(N2)), G2 !== void 0) return G2;
            J2 && (x2 = x2.slice(0, -1 * J2 * 2), w2 = w2.slice(0, -1 * J2), T2 = T2.slice(0, -1 * J2)), x2.push(this.productions_[W2[1]][0]), w2.push(K2.$), T2.push(K2._$), Y2 = E2[x2[x2.length - 2]][x2[x2.length - 1]], x2.push(Y2);
            break;
          case 3:
            return true;
        }
      }
      return true;
    }, "parse")
  };
  Q.lexer = /* @__PURE__ */ (function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ __name(function(e2, b2) {
        if (this.yy.parser) this.yy.parser.parseError(e2, b2);
        else throw Error(e2);
      }, "parseError"),
      setInput: /* @__PURE__ */ __name(function(e2, b2) {
        return this.yy = b2 || this.yy || {}, this._input = e2, this._more = this._backtrack = this.done = false, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
          first_line: 1,
          first_column: 0,
          last_line: 1,
          last_column: 0
        }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
      }, "setInput"),
      input: /* @__PURE__ */ __name(function() {
        var e2 = this._input[0];
        return this.yytext += e2, this.yyleng++, this.offset++, this.match += e2, this.matched += e2, e2.match(/(?:\r\n?|\n).*/g) ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), e2;
      }, "input"),
      unput: /* @__PURE__ */ __name(function(e2) {
        var b2 = e2.length, x2 = e2.split(/(?:\r\n?|\n)/g);
        this._input = e2 + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - b2), this.offset -= b2;
        var S = 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), x2.length - 1 && (this.yylineno -= x2.length - 1);
        var C2 = 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: x2 ? (x2.length === S.length ? this.yylloc.first_column : 0) + S[S.length - x2.length].length - x2[0].length : this.yylloc.first_column - b2
        }, this.options.ranges && (this.yylloc.range = [C2[0], C2[0] + this.yyleng - b2]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ __name(function() {
        return this._more = true, this;
      }, "more"),
      reject: /* @__PURE__ */ __name(function() {
        if (this.options.backtrack_lexer) this._backtrack = true;
        else return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
        return this;
      }, "reject"),
      less: /* @__PURE__ */ __name(function(e2) {
        this.unput(this.match.slice(e2));
      }, "less"),
      pastInput: /* @__PURE__ */ __name(function() {
        var e2 = this.matched.substr(0, this.matched.length - this.match.length);
        return (e2.length > 20 ? "..." : "") + e2.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ __name(function() {
        var e2 = this.match;
        return e2.length < 20 && (e2 += this._input.substr(0, 20 - e2.length)), (e2.substr(0, 20) + (e2.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ __name(function() {
        var e2 = this.pastInput(), b2 = Array(e2.length + 1).join("-");
        return e2 + this.upcomingInput() + "\n" + b2 + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ __name(function(e2, b2) {
        var x2, S, C2;
        if (this.options.backtrack_lexer && (C2 = {
          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 && (C2.yylloc.range = this.yylloc.range.slice(0))), S = e2[0].match(/(?:\r\n?|\n).*/g), S && (this.yylineno += S.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: S ? S[S.length - 1].length - S[S.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + e2[0].length
        }, this.yytext += e2[0], this.match += e2[0], this.matches = e2, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = false, this._backtrack = false, this._input = this._input.slice(e2[0].length), this.matched += e2[0], x2 = this.performAction.call(this, this.yy, this, b2, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = false), x2) return x2;
        if (this._backtrack) {
          for (var w2 in C2) this[w2] = C2[w2];
          return false;
        }
        return false;
      }, "test_match"),
      next: /* @__PURE__ */ __name(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = true);
        var e2, b2, x2, S;
        this._more || (this.yytext = "", this.match = "");
        for (var C2 = this._currentRules(), w2 = 0; w2 < C2.length; w2++) if (x2 = this._input.match(this.rules[C2[w2]]), x2 && (!b2 || x2[0].length > b2[0].length)) {
          if (b2 = x2, S = w2, this.options.backtrack_lexer) {
            if (e2 = this.test_match(x2, C2[w2]), e2 !== false) return e2;
            if (this._backtrack) {
              b2 = false;
              continue;
            } else return false;
          } else if (!this.options.flex) break;
        }
        return b2 ? (e2 = this.test_match(b2, C2[S]), e2 === false ? false : e2) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      lex: /* @__PURE__ */ __name(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ __name(function(e2) {
        this.conditionStack.push(e2);
      }, "begin"),
      popState: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _currentRules: /* @__PURE__ */ __name(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"),
      topState: /* @__PURE__ */ __name(function(e2) {
        return e2 = this.conditionStack.length - 1 - Math.abs(e2 || 0), e2 >= 0 ? this.conditionStack[e2] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ __name(function(e2) {
        this.begin(e2);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": true },
      performAction: /* @__PURE__ */ __name(function(e2, b2, x2, S) {
        switch (x2) {
          case 0:
            return 38;
          case 1:
            return 40;
          case 2:
            return 39;
          case 3:
            return 44;
          case 4:
            return 51;
          case 5:
            return 52;
          case 6:
            return 53;
          case 7:
            return 54;
          case 8:
            break;
          case 9:
            break;
          case 10:
            return 5;
          case 11:
            break;
          case 12:
            break;
          case 13:
            break;
          case 14:
            break;
          case 15:
            return this.pushState("SCALE"), 17;
          case 16:
            return 18;
          case 17:
            this.popState();
            break;
          case 18:
            return this.begin("acc_title"), 33;
          case 19:
            return this.popState(), "acc_title_value";
          case 20:
            return this.begin("acc_descr"), 35;
          case 21:
            return this.popState(), "acc_descr_value";
          case 22:
            this.begin("acc_descr_multiline");
            break;
          case 23:
            this.popState();
            break;
          case 24:
            return "acc_descr_multiline_value";
          case 25:
            return this.pushState("CLASSDEF"), 41;
          case 26:
            return this.popState(), this.pushState("CLASSDEFID"), "DEFAULT_CLASSDEF_ID";
          case 27:
            return this.popState(), this.pushState("CLASSDEFID"), 42;
          case 28:
            return this.popState(), 43;
          case 29:
            return this.pushState("CLASS"), 48;
          case 30:
            return this.popState(), this.pushState("CLASS_STYLE"), 49;
          case 31:
            return this.popState(), 50;
          case 32:
            return this.pushState("STYLE"), 45;
          case 33:
            return this.popState(), this.pushState("STYLEDEF_STYLES"), 46;
          case 34:
            return this.popState(), 47;
          case 35:
            return this.pushState("SCALE"), 17;
          case 36:
            return 18;
          case 37:
            this.popState();
            break;
          case 38:
            this.pushState("STATE");
            break;
          case 39:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -8).trim(), 25;
          case 40:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -8).trim(), 26;
          case 41:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -10).trim(), 27;
          case 42:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -8).trim(), 25;
          case 43:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -8).trim(), 26;
          case 44:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -10).trim(), 27;
          case 45:
            return 51;
          case 46:
            return 52;
          case 47:
            return 53;
          case 48:
            return 54;
          case 49:
            this.pushState("STATE_STRING");
            break;
          case 50:
            return this.pushState("STATE_ID"), "AS";
          case 51:
            return this.popState(), "ID";
          case 52:
            this.popState();
            break;
          case 53:
            return "STATE_DESCR";
          case 54:
            return 19;
          case 55:
            this.popState();
            break;
          case 56:
            return this.popState(), this.pushState("struct"), 20;
          case 57:
            break;
          case 58:
            return this.popState(), 21;
          case 59:
            break;
          case 60:
            return this.begin("NOTE"), 29;
          case 61:
            return this.popState(), this.pushState("NOTE_ID"), 59;
          case 62:
            return this.popState(), this.pushState("NOTE_ID"), 60;
          case 63:
            this.popState(), this.pushState("FLOATING_NOTE");
            break;
          case 64:
            return this.popState(), this.pushState("FLOATING_NOTE_ID"), "AS";
          case 65:
            break;
          case 66:
            return "NOTE_TEXT";
          case 67:
            return this.popState(), "ID";
          case 68:
            return this.popState(), this.pushState("NOTE_TEXT"), 24;
          case 69:
            return this.popState(), b2.yytext = b2.yytext.substr(2).trim(), 31;
          case 70:
            return this.popState(), b2.yytext = b2.yytext.slice(0, -8).trim(), 31;
          case 71:
            return 6;
          case 72:
            return 6;
          case 73:
            return 16;
          case 74:
            return 57;
          case 75:
            return 24;
          case 76:
            return b2.yytext = b2.yytext.trim(), 14;
          case 77:
            return 15;
          case 78:
            return 28;
          case 79:
            return 58;
          case 80:
            return 5;
          case 81:
            return "INVALID";
        }
      }, "anonymous"),
      rules: [
        /^(?:click\b)/i,
        /^(?:href\b)/i,
        /^(?:"[^"]*")/i,
        /^(?:default\b)/i,
        /^(?:.*direction\s+TB[^\n]*)/i,
        /^(?:.*direction\s+BT[^\n]*)/i,
        /^(?:.*direction\s+RL[^\n]*)/i,
        /^(?:.*direction\s+LR[^\n]*)/i,
        /^(?:%%(?!\{)[^\n]*)/i,
        /^(?:[^\}]%%[^\n]*)/i,
        /^(?:[\n]+)/i,
        /^(?:[\s]+)/i,
        /^(?:((?!\n)\s)+)/i,
        /^(?:#[^\n]*)/i,
        /^(?:%[^\n]*)/i,
        /^(?:scale\s+)/i,
        /^(?:\d+)/i,
        /^(?:\s+width\b)/i,
        /^(?:accTitle\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*\{\s*)/i,
        /^(?:[\}])/i,
        /^(?:[^\}]*)/i,
        /^(?:classDef\s+)/i,
        /^(?:DEFAULT\s+)/i,
        /^(?:\w+\s+)/i,
        /^(?:[^\n]*)/i,
        /^(?:class\s+)/i,
        /^(?:(\w+)+((,\s*\w+)*))/i,
        /^(?:[^\n]*)/i,
        /^(?:style\s+)/i,
        /^(?:[\w,]+\s+)/i,
        /^(?:[^\n]*)/i,
        /^(?:scale\s+)/i,
        /^(?:\d+)/i,
        /^(?:\s+width\b)/i,
        /^(?:state\s+)/i,
        /^(?:.*<<fork>>)/i,
        /^(?:.*<<join>>)/i,
        /^(?:.*<<choice>>)/i,
        /^(?:.*\[\[fork\]\])/i,
        /^(?:.*\[\[join\]\])/i,
        /^(?:.*\[\[choice\]\])/i,
        /^(?:.*direction\s+TB[^\n]*)/i,
        /^(?:.*direction\s+BT[^\n]*)/i,
        /^(?:.*direction\s+RL[^\n]*)/i,
        /^(?:.*direction\s+LR[^\n]*)/i,
        /^(?:["])/i,
        /^(?:\s*as\s+)/i,
        /^(?:[^\n\{]*)/i,
        /^(?:["])/i,
        /^(?:[^"]*)/i,
        /^(?:[^\n\s\{]+)/i,
        /^(?:\n)/i,
        /^(?:\{)/i,
        /^(?:%%(?!\{)[^\n]*)/i,
        /^(?:\})/i,
        /^(?:[\n])/i,
        /^(?:note\s+)/i,
        /^(?:left of\b)/i,
        /^(?:right of\b)/i,
        /^(?:")/i,
        /^(?:\s*as\s*)/i,
        /^(?:["])/i,
        /^(?:[^"]*)/i,
        /^(?:[^\n]*)/i,
        /^(?:\s*[^:\n\s\-]+)/i,
        /^(?:\s*:[^:\n;]+)/i,
        /^(?:[\s\S]*?end note\b)/i,
        /^(?:stateDiagram\s+)/i,
        /^(?:stateDiagram-v2\s+)/i,
        /^(?:hide empty description\b)/i,
        /^(?:\[\*\])/i,
        /^(?:[^:\n\s\-\{]+)/i,
        /^(?:\s*:[^:\n;]+)/i,
        /^(?:-->)/i,
        /^(?:--)/i,
        /^(?::::)/i,
        /^(?:$)/i,
        /^(?:.)/i
      ],
      conditions: {
        LINE: {
          rules: [12, 13],
          inclusive: false
        },
        struct: {
          rules: [
            12,
            13,
            25,
            29,
            32,
            38,
            45,
            46,
            47,
            48,
            57,
            58,
            59,
            60,
            74,
            75,
            76,
            77,
            78
          ],
          inclusive: false
        },
        FLOATING_NOTE_ID: {
          rules: [67],
          inclusive: false
        },
        FLOATING_NOTE: {
          rules: [
            64,
            65,
            66
          ],
          inclusive: false
        },
        NOTE_TEXT: {
          rules: [69, 70],
          inclusive: false
        },
        NOTE_ID: {
          rules: [68],
          inclusive: false
        },
        NOTE: {
          rules: [
            61,
            62,
            63
          ],
          inclusive: false
        },
        STYLEDEF_STYLEOPTS: {
          rules: [],
          inclusive: false
        },
        STYLEDEF_STYLES: {
          rules: [34],
          inclusive: false
        },
        STYLE_IDS: {
          rules: [],
          inclusive: false
        },
        STYLE: {
          rules: [33],
          inclusive: false
        },
        CLASS_STYLE: {
          rules: [31],
          inclusive: false
        },
        CLASS: {
          rules: [30],
          inclusive: false
        },
        CLASSDEFID: {
          rules: [28],
          inclusive: false
        },
        CLASSDEF: {
          rules: [26, 27],
          inclusive: false
        },
        acc_descr_multiline: {
          rules: [23, 24],
          inclusive: false
        },
        acc_descr: {
          rules: [21],
          inclusive: false
        },
        acc_title: {
          rules: [19],
          inclusive: false
        },
        SCALE: {
          rules: [
            16,
            17,
            36,
            37
          ],
          inclusive: false
        },
        ALIAS: {
          rules: [],
          inclusive: false
        },
        STATE_ID: {
          rules: [51],
          inclusive: false
        },
        STATE_STRING: {
          rules: [52, 53],
          inclusive: false
        },
        FORK_STATE: {
          rules: [],
          inclusive: false
        },
        STATE: {
          rules: [
            12,
            13,
            39,
            40,
            41,
            42,
            43,
            44,
            49,
            50,
            54,
            55,
            56
          ],
          inclusive: false
        },
        ID: {
          rules: [12, 13],
          inclusive: false
        },
        INITIAL: {
          rules: [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            13,
            14,
            15,
            18,
            20,
            22,
            25,
            29,
            32,
            35,
            38,
            56,
            60,
            71,
            72,
            73,
            74,
            75,
            76,
            77,
            79,
            80,
            81
          ],
          inclusive: true
        }
      }
    };
  })();
  function $() {
    this.yy = {};
  }
  return __name($, "Parser"), $.prototype = Q, Q.Parser = $, new $();
})();
parser.parser = parser;
var stateDiagram_default = parser, DEFAULT_DIAGRAM_DIRECTION = "TB", DEFAULT_NESTED_DOC_DIR = "TB", STMT_DIRECTION = "dir", STMT_STATE = "state", STMT_ROOT = "root", STMT_RELATION = "relation", STMT_CLASSDEF = "classDef", STMT_STYLEDEF = "style", STMT_APPLYCLASS = "applyClass", DEFAULT_STATE_TYPE = "default", DIVIDER_TYPE = "divider", G_EDGE_STYLE = "fill:none", G_EDGE_ARROWHEADSTYLE = "fill: #333", G_EDGE_LABELPOS = "c", G_EDGE_LABELTYPE = "text", G_EDGE_THICKNESS = "normal", SHAPE_STATE = "rect", SHAPE_STATE_WITH_DESC = "rectWithTitle", SHAPE_START = "stateStart", SHAPE_END = "stateEnd", SHAPE_DIVIDER = "divider", SHAPE_GROUP = "roundedWithTitle", SHAPE_NOTE = "note", SHAPE_NOTEGROUP = "noteGroup", CSS_DIAGRAM = "statediagram", CSS_DIAGRAM_STATE = `${CSS_DIAGRAM}-state`, CSS_EDGE = "transition", CSS_NOTE = "note", CSS_EDGE_NOTE_EDGE = `${CSS_EDGE} note-edge`, CSS_DIAGRAM_NOTE = `${CSS_DIAGRAM}-${CSS_NOTE}`, CSS_DIAGRAM_CLUSTER = `${CSS_DIAGRAM}-cluster`, CSS_DIAGRAM_CLUSTER_ALT = `${CSS_DIAGRAM}-cluster-alt`, PARENT = "parent", NOTE = "note", DOMID_STATE = "state", DOMID_TYPE_SPACER = "----", NOTE_ID = `${DOMID_TYPE_SPACER}${NOTE}`, PARENT_ID = `${DOMID_TYPE_SPACER}${PARENT}`, getDir = /* @__PURE__ */ __name((e, b = DEFAULT_NESTED_DOC_DIR) => {
  if (!e.doc) return b;
  let x = b;
  for (let b2 of e.doc) b2.stmt === "dir" && (x = b2.value);
  return x;
}, "getDir"), stateRenderer_v3_unified_default = {
  getClasses: /* @__PURE__ */ __name(function(e, b) {
    return b.db.getClasses();
  }, "getClasses"),
  draw: /* @__PURE__ */ __name(async function(b, S, C, w) {
    log.info("REF0:"), log.info("Drawing state diagram (v2)", S);
    let { securityLevel: T, state: E, layout: D } = getConfig2();
    w.db.extract(w.db.getRootDocV2());
    let k = w.db.getData(), A = getDiagramElement(S, T);
    k.type = w.type, k.layoutAlgorithm = D, k.nodeSpacing = (E == null ? void 0 : E.nodeSpacing) || 50, k.rankSpacing = (E == null ? void 0 : E.rankSpacing) || 50, k.markers = ["barb"], k.diagramId = S, await render(k, A);
    try {
      (typeof w.db.getLinks == "function" ? w.db.getLinks() : /* @__PURE__ */ new Map()).forEach((e, b2) => {
        var _a2;
        let S2 = typeof b2 == "string" ? b2 : typeof (b2 == null ? void 0 : b2.id) == "string" ? b2.id : "";
        if (!S2) {
          log.warn("\u26A0\uFE0F Invalid or missing stateId from key:", JSON.stringify(b2));
          return;
        }
        let C2 = (_a2 = A.node()) == null ? void 0 : _a2.querySelectorAll("g"), w2;
        if (C2 == null ? void 0 : C2.forEach((e2) => {
          var _a3;
          ((_a3 = e2.textContent) == null ? void 0 : _a3.trim()) === S2 && (w2 = e2);
        }), !w2) {
          log.warn("\u26A0\uFE0F Could not find node matching text:", S2);
          return;
        }
        let T2 = w2.parentNode;
        if (!T2) {
          log.warn("\u26A0\uFE0F Node has no parent, cannot wrap:", S2);
          return;
        }
        let E2 = document.createElementNS("http://www.w3.org/2000/svg", "a"), D2 = e.url.replace(/^"+|"+$/g, "");
        if (E2.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", D2), E2.setAttribute("target", "_blank"), e.tooltip) {
          let b3 = e.tooltip.replace(/^"+|"+$/g, "");
          E2.setAttribute("title", b3);
        }
        T2.replaceChild(E2, w2), E2.appendChild(w2), log.info("\u{1F517} Wrapped node in <a> tag for:", S2, e.url);
      });
    } catch (e) {
      log.error("\u274C Error injecting clickable links:", e);
    }
    utils_default.insertTitle(A, "statediagramTitleText", (E == null ? void 0 : E.titleTopMargin) ?? 25, w.db.getDiagramTitle()), setupViewPortForSVG(A, 8, CSS_DIAGRAM, (E == null ? void 0 : E.useMaxWidth) ?? true);
  }, "draw"),
  getDir
}, nodeDb = /* @__PURE__ */ new Map(), graphItemCount = 0;
function stateDomId(e = "", b = 0, x = "", S = DOMID_TYPE_SPACER) {
  return `${DOMID_STATE}-${e}${x !== null && x.length > 0 ? `${S}${x}` : ""}-${b}`;
}
__name(stateDomId, "stateDomId");
var setupDoc = /* @__PURE__ */ __name((e, b, S, C, w, T, E, D) => {
  log.trace("items", b), b.forEach((b2) => {
    switch (b2.stmt) {
      case STMT_STATE:
        dataFetcher(e, b2, S, C, w, T, E, D);
        break;
      case DEFAULT_STATE_TYPE:
        dataFetcher(e, b2, S, C, w, T, E, D);
        break;
      case STMT_RELATION:
        {
          dataFetcher(e, b2.state1, S, C, w, T, E, D), dataFetcher(e, b2.state2, S, C, w, T, E, D);
          let x = {
            id: "edge" + graphItemCount,
            start: b2.state1.id,
            end: b2.state2.id,
            arrowhead: "normal",
            arrowTypeEnd: "arrow_barb",
            style: G_EDGE_STYLE,
            labelStyle: "",
            label: common_default.sanitizeText(b2.description ?? "", getConfig2()),
            arrowheadStyle: G_EDGE_ARROWHEADSTYLE,
            labelpos: G_EDGE_LABELPOS,
            labelType: G_EDGE_LABELTYPE,
            thickness: G_EDGE_THICKNESS,
            classes: CSS_EDGE,
            look: E
          };
          w.push(x), graphItemCount++;
        }
        break;
    }
  });
}, "setupDoc"), getDir2 = /* @__PURE__ */ __name((e, b = DEFAULT_NESTED_DOC_DIR) => {
  let x = b;
  if (e.doc) for (let b2 of e.doc) b2.stmt === "dir" && (x = b2.value);
  return x;
}, "getDir");
function insertOrUpdateNode(e, b, x) {
  if (!b.id || b.id === "</join></fork>" || b.id === "</choice>") return;
  b.cssClasses && (Array.isArray(b.cssCompiledStyles) || (b.cssCompiledStyles = []), b.cssClasses.split(" ").forEach((e2) => {
    let S2 = x.get(e2);
    S2 && (b.cssCompiledStyles = [...b.cssCompiledStyles ?? [], ...S2.styles]);
  }));
  let S = e.find((e2) => e2.id === b.id);
  S ? Object.assign(S, b) : e.push(b);
}
__name(insertOrUpdateNode, "insertOrUpdateNode");
function getClassesFromDbInfo(e) {
  var _a2;
  return ((_a2 = e == null ? void 0 : e.classes) == null ? void 0 : _a2.join(" ")) ?? "";
}
__name(getClassesFromDbInfo, "getClassesFromDbInfo");
function getStylesFromDbInfo(e) {
  return (e == null ? void 0 : e.styles) ?? [];
}
__name(getStylesFromDbInfo, "getStylesFromDbInfo");
var dataFetcher = /* @__PURE__ */ __name((e, b, S, C, w, T, E, D) => {
  var _a2, _b, _c;
  let A = b.id, j = S.get(A), M = getClassesFromDbInfo(j), N = getStylesFromDbInfo(j), P = getConfig2();
  if (log.info("dataFetcher parsedItem", b, j, N), A !== "root") {
    let S2 = SHAPE_STATE;
    b.start === true ? S2 = SHAPE_START : b.start === false && (S2 = SHAPE_END), b.type !== DEFAULT_STATE_TYPE && (S2 = b.type), nodeDb.get(A) || nodeDb.set(A, {
      id: A,
      shape: S2,
      description: common_default.sanitizeText(A, P),
      cssClasses: `${M} ${CSS_DIAGRAM_STATE}`,
      cssStyles: N
    });
    let O = nodeDb.get(A);
    b.description && (Array.isArray(O.description) ? (O.shape = SHAPE_STATE_WITH_DESC, O.description.push(b.description)) : ((_a2 = O.description) == null ? void 0 : _a2.length) && O.description.length > 0 ? (O.shape = SHAPE_STATE_WITH_DESC, O.description === A ? O.description = [b.description] : O.description = [O.description, b.description]) : (O.shape = SHAPE_STATE, O.description = b.description), O.description = common_default.sanitizeTextOrArray(O.description, P)), ((_b = O.description) == null ? void 0 : _b.length) === 1 && O.shape === SHAPE_STATE_WITH_DESC && (O.type === "group" ? O.shape = SHAPE_GROUP : O.shape = SHAPE_STATE), !O.type && b.doc && (log.info("Setting cluster for XCX", A, getDir2(b)), O.type = "group", O.isGroup = true, O.dir = getDir2(b), O.shape = b.type === DIVIDER_TYPE ? SHAPE_DIVIDER : SHAPE_GROUP, O.cssClasses = `${O.cssClasses} ${CSS_DIAGRAM_CLUSTER} ${T ? CSS_DIAGRAM_CLUSTER_ALT : ""}`);
    let j2 = {
      labelStyle: "",
      shape: O.shape,
      label: O.description,
      cssClasses: O.cssClasses,
      cssCompiledStyles: [],
      cssStyles: O.cssStyles,
      id: A,
      dir: O.dir,
      domId: stateDomId(A, graphItemCount),
      type: O.type,
      isGroup: O.type === "group",
      padding: 8,
      rx: 10,
      ry: 10,
      look: E
    };
    if (j2.shape === SHAPE_DIVIDER && (j2.label = ""), e && e.id !== "root" && (log.trace("Setting node ", A, " to be child of its parent ", e.id), j2.parentId = e.id), j2.centerLabel = true, b.note) {
      let e2 = {
        labelStyle: "",
        shape: SHAPE_NOTE,
        label: b.note.text,
        cssClasses: CSS_DIAGRAM_NOTE,
        cssStyles: [],
        cssCompiledStyles: [],
        id: A + NOTE_ID + "-" + graphItemCount,
        domId: stateDomId(A, graphItemCount, NOTE),
        type: O.type,
        isGroup: O.type === "group",
        padding: (_c = P.flowchart) == null ? void 0 : _c.padding,
        look: E,
        position: b.note.position
      }, x = A + PARENT_ID, S3 = {
        labelStyle: "",
        shape: SHAPE_NOTEGROUP,
        label: b.note.text,
        cssClasses: O.cssClasses,
        cssStyles: [],
        id: A + PARENT_ID,
        domId: stateDomId(A, graphItemCount, PARENT),
        type: "group",
        isGroup: true,
        padding: 16,
        look: E,
        position: b.note.position
      };
      graphItemCount++, S3.id = x, e2.parentId = x, insertOrUpdateNode(C, S3, D), insertOrUpdateNode(C, e2, D), insertOrUpdateNode(C, j2, D);
      let T2 = A, k = e2.id;
      b.note.position === "left of" && (T2 = e2.id, k = A), w.push({
        id: T2 + "-" + k,
        start: T2,
        end: k,
        arrowhead: "none",
        arrowTypeEnd: "",
        style: G_EDGE_STYLE,
        labelStyle: "",
        classes: CSS_EDGE_NOTE_EDGE,
        arrowheadStyle: G_EDGE_ARROWHEADSTYLE,
        labelpos: G_EDGE_LABELPOS,
        labelType: G_EDGE_LABELTYPE,
        thickness: G_EDGE_THICKNESS,
        look: E
      });
    } else insertOrUpdateNode(C, j2, D);
  }
  b.doc && (log.trace("Adding nodes children "), setupDoc(b, b.doc, S, C, w, !T, E, D));
}, "dataFetcher"), reset = /* @__PURE__ */ __name(() => {
  nodeDb.clear(), graphItemCount = 0;
}, "reset"), CONSTANTS = {
  START_NODE: "[*]",
  START_TYPE: "start",
  END_NODE: "[*]",
  END_TYPE: "end",
  COLOR_KEYWORD: "color",
  FILL_KEYWORD: "fill",
  BG_FILL: "bgFill",
  STYLECLASS_SEP: ","
}, newClassesList = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "newClassesList"), newDoc = /* @__PURE__ */ __name(() => ({
  relations: [],
  states: /* @__PURE__ */ new Map(),
  documents: {}
}), "newDoc"), clone = /* @__PURE__ */ __name((e) => JSON.parse(JSON.stringify(e)), "clone"), StateDB = (_a = class {
  constructor(e) {
    this.version = e, this.nodes = [], this.edges = [], this.rootDoc = [], this.classes = newClassesList(), this.documents = { root: newDoc() }, this.currentDocument = this.documents.root, this.startEndCount = 0, this.dividerCnt = 0, this.links = /* @__PURE__ */ new Map(), this.getAccTitle = getAccTitle, this.setAccTitle = setAccTitle, this.getAccDescription = getAccDescription, this.setAccDescription = setAccDescription, this.setDiagramTitle = setDiagramTitle, this.getDiagramTitle = getDiagramTitle, this.clear(), this.setRootDoc = this.setRootDoc.bind(this), this.getDividerId = this.getDividerId.bind(this), this.setDirection = this.setDirection.bind(this), this.trimColon = this.trimColon.bind(this);
  }
  extract(e) {
    this.clear(true);
    for (let b2 of Array.isArray(e) ? e : e.doc) switch (b2.stmt) {
      case STMT_STATE:
        this.addState(b2.id.trim(), b2.type, b2.doc, b2.description, b2.note);
        break;
      case STMT_RELATION:
        this.addRelation(b2.state1, b2.state2, b2.description);
        break;
      case STMT_CLASSDEF:
        this.addStyleClass(b2.id.trim(), b2.classes);
        break;
      case STMT_STYLEDEF:
        this.handleStyleDef(b2);
        break;
      case STMT_APPLYCLASS:
        this.setCssClass(b2.id.trim(), b2.styleClass);
        break;
      case "click":
        this.addLink(b2.id, b2.url, b2.tooltip);
        break;
    }
    let b = this.getStates(), x = getConfig2();
    reset(), dataFetcher(void 0, this.getRootDocV2(), b, this.nodes, this.edges, true, x.look, this.classes);
    for (let e2 of this.nodes) if (Array.isArray(e2.label)) {
      if (e2.description = e2.label.slice(1), e2.isGroup && e2.description.length > 0) throw Error(`Group nodes can only have label. Remove the additional description for node [${e2.id}]`);
      e2.label = e2.label[0];
    }
  }
  handleStyleDef(e) {
    let b = e.id.trim().split(","), x = e.styleClass.split(",");
    for (let e2 of b) {
      let b2 = this.getState(e2);
      if (!b2) {
        let x2 = e2.trim();
        this.addState(x2), b2 = this.getState(x2);
      }
      b2 && (b2.styles = x.map((e3) => {
        var _a2;
        return (_a2 = e3.replace(/;/g, "")) == null ? void 0 : _a2.trim();
      }));
    }
  }
  setRootDoc(e) {
    log.info("Setting root doc", e), this.rootDoc = e, this.version === 1 ? this.extract(e) : this.extract(this.getRootDocV2());
  }
  docTranslator(e, x, S) {
    if (x.stmt === STMT_RELATION) {
      this.docTranslator(e, x.state1, true), this.docTranslator(e, x.state2, false);
      return;
    }
    if (x.stmt === STMT_STATE && (x.id === CONSTANTS.START_NODE ? (x.id = e.id + (S ? "_start" : "_end"), x.start = S) : x.id = x.id.trim()), x.stmt !== STMT_ROOT && x.stmt !== STMT_STATE || !x.doc) return;
    let C = [], w = [];
    for (let e2 of x.doc) if (e2.type === DIVIDER_TYPE) {
      let b = clone(e2);
      b.doc = clone(w), C.push(b), w = [];
    } else w.push(e2);
    if (C.length > 0 && w.length > 0) {
      let e2 = {
        stmt: STMT_STATE,
        id: generateId(),
        type: "divider",
        doc: clone(w)
      };
      C.push(clone(e2)), x.doc = C;
    }
    x.doc.forEach((e2) => this.docTranslator(x, e2, true));
  }
  getRootDocV2() {
    return this.docTranslator({
      id: STMT_ROOT,
      stmt: STMT_ROOT
    }, {
      id: STMT_ROOT,
      stmt: STMT_ROOT,
      doc: this.rootDoc
    }, true), {
      id: STMT_ROOT,
      doc: this.rootDoc
    };
  }
  addState(e, b = DEFAULT_STATE_TYPE, S = void 0, C = void 0, w = void 0, T = void 0, E = void 0, D = void 0) {
    let A = e == null ? void 0 : e.trim();
    if (!this.currentDocument.states.has(A)) log.info("Adding state ", A, C), this.currentDocument.states.set(A, {
      stmt: STMT_STATE,
      id: A,
      descriptions: [],
      type: b,
      doc: S,
      note: w,
      classes: [],
      styles: [],
      textStyles: []
    });
    else {
      let e2 = this.currentDocument.states.get(A);
      if (!e2) throw Error(`State not found: ${A}`);
      e2.doc || (e2.doc = S), e2.type || (e2.type = b);
    }
    if (C && (log.info("Setting state description", A, C), (Array.isArray(C) ? C : [C]).forEach((e2) => this.addDescription(A, e2.trim()))), w) {
      let e2 = this.currentDocument.states.get(A);
      if (!e2) throw Error(`State not found: ${A}`);
      e2.note = w, e2.note.text = common_default.sanitizeText(e2.note.text, getConfig2());
    }
    T && (log.info("Setting state classes", A, T), (Array.isArray(T) ? T : [T]).forEach((e2) => this.setCssClass(A, e2.trim()))), E && (log.info("Setting state styles", A, E), (Array.isArray(E) ? E : [E]).forEach((e2) => this.setStyle(A, e2.trim()))), D && (log.info("Setting state styles", A, E), (Array.isArray(D) ? D : [D]).forEach((e2) => this.setTextStyle(A, e2.trim())));
  }
  clear(e) {
    this.nodes = [], this.edges = [], this.documents = { root: newDoc() }, this.currentDocument = this.documents.root, this.startEndCount = 0, this.classes = newClassesList(), e || (this.links = /* @__PURE__ */ new Map(), clear());
  }
  getState(e) {
    return this.currentDocument.states.get(e);
  }
  getStates() {
    return this.currentDocument.states;
  }
  logDocuments() {
    log.info("Documents = ", this.documents);
  }
  getRelations() {
    return this.currentDocument.relations;
  }
  addLink(e, b, S) {
    this.links.set(e, {
      url: b,
      tooltip: S
    }), log.warn("Adding link", e, b, S);
  }
  getLinks() {
    return this.links;
  }
  startIdIfNeeded(e = "") {
    return e === CONSTANTS.START_NODE ? (this.startEndCount++, `${CONSTANTS.START_TYPE}${this.startEndCount}`) : e;
  }
  startTypeIfNeeded(e = "", b = DEFAULT_STATE_TYPE) {
    return e === CONSTANTS.START_NODE ? CONSTANTS.START_TYPE : b;
  }
  endIdIfNeeded(e = "") {
    return e === CONSTANTS.END_NODE ? (this.startEndCount++, `${CONSTANTS.END_TYPE}${this.startEndCount}`) : e;
  }
  endTypeIfNeeded(e = "", b = DEFAULT_STATE_TYPE) {
    return e === CONSTANTS.END_NODE ? CONSTANTS.END_TYPE : b;
  }
  addRelationObjs(e, b, x = "") {
    let S = this.startIdIfNeeded(e.id.trim()), C = this.startTypeIfNeeded(e.id.trim(), e.type), w = this.startIdIfNeeded(b.id.trim()), T = this.startTypeIfNeeded(b.id.trim(), b.type);
    this.addState(S, C, e.doc, e.description, e.note, e.classes, e.styles, e.textStyles), this.addState(w, T, b.doc, b.description, b.note, b.classes, b.styles, b.textStyles), this.currentDocument.relations.push({
      id1: S,
      id2: w,
      relationTitle: common_default.sanitizeText(x, getConfig2())
    });
  }
  addRelation(e, b, x) {
    if (typeof e == "object" && typeof b == "object") this.addRelationObjs(e, b, x);
    else if (typeof e == "string" && typeof b == "string") {
      let S = this.startIdIfNeeded(e.trim()), C = this.startTypeIfNeeded(e), w = this.endIdIfNeeded(b.trim()), T = this.endTypeIfNeeded(b);
      this.addState(S, C), this.addState(w, T), this.currentDocument.relations.push({
        id1: S,
        id2: w,
        relationTitle: x ? common_default.sanitizeText(x, getConfig2()) : void 0
      });
    }
  }
  addDescription(e, b) {
    var _a2;
    let x = this.currentDocument.states.get(e), S = b.startsWith(":") ? b.replace(":", "").trim() : b;
    (_a2 = x == null ? void 0 : x.descriptions) == null ? void 0 : _a2.push(common_default.sanitizeText(S, getConfig2()));
  }
  cleanupLabel(e) {
    return e.startsWith(":") ? e.slice(2).trim() : e.trim();
  }
  getDividerId() {
    return this.dividerCnt++, `divider-id-${this.dividerCnt}`;
  }
  addStyleClass(e, b = "") {
    this.classes.has(e) || this.classes.set(e, {
      id: e,
      styles: [],
      textStyles: []
    });
    let x = this.classes.get(e);
    b && x && b.split(CONSTANTS.STYLECLASS_SEP).forEach((e2) => {
      let b2 = e2.replace(/([^;]*);/, "$1").trim();
      if (RegExp(CONSTANTS.COLOR_KEYWORD).exec(e2)) {
        let e3 = b2.replace(CONSTANTS.FILL_KEYWORD, CONSTANTS.BG_FILL).replace(CONSTANTS.COLOR_KEYWORD, CONSTANTS.FILL_KEYWORD);
        x.textStyles.push(e3);
      }
      x.styles.push(b2);
    });
  }
  getClasses() {
    return this.classes;
  }
  setCssClass(e, b) {
    e.split(",").forEach((e2) => {
      var _a2;
      let x = this.getState(e2);
      if (!x) {
        let b2 = e2.trim();
        this.addState(b2), x = this.getState(b2);
      }
      (_a2 = x == null ? void 0 : x.classes) == null ? void 0 : _a2.push(b);
    });
  }
  setStyle(e, b) {
    var _a2, _b;
    (_b = (_a2 = this.getState(e)) == null ? void 0 : _a2.styles) == null ? void 0 : _b.push(b);
  }
  setTextStyle(e, b) {
    var _a2, _b;
    (_b = (_a2 = this.getState(e)) == null ? void 0 : _a2.textStyles) == null ? void 0 : _b.push(b);
  }
  getDirectionStatement() {
    return this.rootDoc.find((e) => e.stmt === STMT_DIRECTION);
  }
  getDirection() {
    var _a2;
    return ((_a2 = this.getDirectionStatement()) == null ? void 0 : _a2.value) ?? DEFAULT_DIAGRAM_DIRECTION;
  }
  setDirection(e) {
    let b = this.getDirectionStatement();
    b ? b.value = e : this.rootDoc.unshift({
      stmt: STMT_DIRECTION,
      value: e
    });
  }
  trimColon(e) {
    return e.startsWith(":") ? e.slice(1).trim() : e.trim();
  }
  getData() {
    let e = getConfig2();
    return {
      nodes: this.nodes,
      edges: this.edges,
      other: {},
      config: e,
      direction: getDir(this.getRootDocV2())
    };
  }
  getConfig() {
    return getConfig2().state;
  }
}, __name(_a, "StateDB"), _a.relationType = {
  AGGREGATION: 0,
  EXTENSION: 1,
  COMPOSITION: 2,
  DEPENDENCY: 3
}, _a), styles_default = /* @__PURE__ */ __name((e) => `
defs #statediagram-barbEnd {
    fill: ${e.transitionColor};
    stroke: ${e.transitionColor};
  }
g.stateGroup text {
  fill: ${e.nodeBorder};
  stroke: none;
  font-size: 10px;
}
g.stateGroup text {
  fill: ${e.textColor};
  stroke: none;
  font-size: 10px;

}
g.stateGroup .state-title {
  font-weight: bolder;
  fill: ${e.stateLabelColor};
}

g.stateGroup rect {
  fill: ${e.mainBkg};
  stroke: ${e.nodeBorder};
}

g.stateGroup line {
  stroke: ${e.lineColor};
  stroke-width: 1;
}

.transition {
  stroke: ${e.transitionColor};
  stroke-width: 1;
  fill: none;
}

.stateGroup .composit {
  fill: ${e.background};
  border-bottom: 1px
}

.stateGroup .alt-composit {
  fill: #e0e0e0;
  border-bottom: 1px
}

.state-note {
  stroke: ${e.noteBorderColor};
  fill: ${e.noteBkgColor};

  text {
    fill: ${e.noteTextColor};
    stroke: none;
    font-size: 10px;
  }
}

.stateLabel .box {
  stroke: none;
  stroke-width: 0;
  fill: ${e.mainBkg};
  opacity: 0.5;
}

.edgeLabel .label rect {
  fill: ${e.labelBackgroundColor};
  opacity: 0.5;
}
.edgeLabel {
  background-color: ${e.edgeLabelBackground};
  p {
    background-color: ${e.edgeLabelBackground};
  }
  rect {
    opacity: 0.5;
    background-color: ${e.edgeLabelBackground};
    fill: ${e.edgeLabelBackground};
  }
  text-align: center;
}
.edgeLabel .label text {
  fill: ${e.transitionLabelColor || e.tertiaryTextColor};
}
.label div .edgeLabel {
  color: ${e.transitionLabelColor || e.tertiaryTextColor};
}

.stateLabel text {
  fill: ${e.stateLabelColor};
  font-size: 10px;
  font-weight: bold;
}

.node circle.state-start {
  fill: ${e.specialStateColor};
  stroke: ${e.specialStateColor};
}

.node .fork-join {
  fill: ${e.specialStateColor};
  stroke: ${e.specialStateColor};
}

.node circle.state-end {
  fill: ${e.innerEndBackground};
  stroke: ${e.background};
  stroke-width: 1.5
}
.end-state-inner {
  fill: ${e.compositeBackground || e.background};
  // stroke: ${e.background};
  stroke-width: 1.5
}

.node rect {
  fill: ${e.stateBkg || e.mainBkg};
  stroke: ${e.stateBorder || e.nodeBorder};
  stroke-width: 1px;
}
.node polygon {
  fill: ${e.mainBkg};
  stroke: ${e.stateBorder || e.nodeBorder};;
  stroke-width: 1px;
}
#statediagram-barbEnd {
  fill: ${e.lineColor};
}

.statediagram-cluster rect {
  fill: ${e.compositeTitleBackground};
  stroke: ${e.stateBorder || e.nodeBorder};
  stroke-width: 1px;
}

.cluster-label, .nodeLabel {
  color: ${e.stateLabelColor};
  // line-height: 1;
}

.statediagram-cluster rect.outer {
  rx: 5px;
  ry: 5px;
}
.statediagram-state .divider {
  stroke: ${e.stateBorder || e.nodeBorder};
}

.statediagram-state .title-state {
  rx: 5px;
  ry: 5px;
}
.statediagram-cluster.statediagram-cluster .inner {
  fill: ${e.compositeBackground || e.background};
}
.statediagram-cluster.statediagram-cluster-alt .inner {
  fill: ${e.altBackground ? e.altBackground : "#efefef"};
}

.statediagram-cluster .inner {
  rx:0;
  ry:0;
}

.statediagram-state rect.basic {
  rx: 5px;
  ry: 5px;
}
.statediagram-state rect.divider {
  stroke-dasharray: 10,10;
  fill: ${e.altBackground ? e.altBackground : "#efefef"};
}

.note-edge {
  stroke-dasharray: 5;
}

.statediagram-note rect {
  fill: ${e.noteBkgColor};
  stroke: ${e.noteBorderColor};
  stroke-width: 1px;
  rx: 0;
  ry: 0;
}
.statediagram-note rect {
  fill: ${e.noteBkgColor};
  stroke: ${e.noteBorderColor};
  stroke-width: 1px;
  rx: 0;
  ry: 0;
}

.statediagram-note text {
  fill: ${e.noteTextColor};
}

.statediagram-note .nodeLabel {
  color: ${e.noteTextColor};
}
.statediagram .edgeLabel {
  color: red; // ${e.noteTextColor};
}

#dependencyStart, #dependencyEnd {
  fill: ${e.lineColor};
  stroke: ${e.lineColor};
  stroke-width: 1;
}

.statediagramTitleText {
  text-anchor: middle;
  font-size: 18px;
  fill: ${e.textColor};
}
`, "getStyles");
export {
  styles_default as i,
  stateDiagram_default as n,
  stateRenderer_v3_unified_default as r,
  StateDB as t
};
