import "./purify.es-DT70lfR0.js";
import { t as arc_default } from "./arc-DfkSnvZm.js";
import { i as log, n as __export, r as __name, t as select_default } from "./src-Bf2iLOlr.js";
import { G as setupGraphViewbox, Q as is_dark_default, X as darken_default, Z as lighten_default, a as clear, b as getConfig2, o as commonDb_exports } from "./chunk-ABZYJK2D-D0cLy8Bb.js";
var parser = (function() {
  var t = /* @__PURE__ */ __name(function(t2, S2, C2, w) {
    for (C2 || (C2 = {}), w = t2.length; w--; C2[t2[w]] = S2) ;
    return C2;
  }, "o"), S = [
    6,
    8,
    10,
    11,
    12,
    14,
    16,
    17,
    20,
    21
  ], C = [1, 9], T = [1, 10], E = [1, 11], D = [1, 12], O = [1, 13], k = [1, 16], A = [1, 17], j = {
    trace: /* @__PURE__ */ __name(function() {
    }, "trace"),
    yy: {},
    symbols_: {
      error: 2,
      start: 3,
      timeline: 4,
      document: 5,
      EOF: 6,
      line: 7,
      SPACE: 8,
      statement: 9,
      NEWLINE: 10,
      title: 11,
      acc_title: 12,
      acc_title_value: 13,
      acc_descr: 14,
      acc_descr_value: 15,
      acc_descr_multiline_value: 16,
      section: 17,
      period_statement: 18,
      event_statement: 19,
      period: 20,
      event: 21,
      $accept: 0,
      $end: 1
    },
    terminals_: {
      2: "error",
      4: "timeline",
      6: "EOF",
      8: "SPACE",
      10: "NEWLINE",
      11: "title",
      12: "acc_title",
      13: "acc_title_value",
      14: "acc_descr",
      15: "acc_descr_value",
      16: "acc_descr_multiline_value",
      17: "section",
      20: "period",
      21: "event"
    },
    productions_: [
      0,
      [3, 3],
      [5, 0],
      [5, 2],
      [7, 2],
      [7, 1],
      [7, 1],
      [7, 1],
      [9, 1],
      [9, 2],
      [9, 2],
      [9, 1],
      [9, 1],
      [9, 1],
      [9, 1],
      [18, 1],
      [19, 1]
    ],
    performAction: /* @__PURE__ */ __name(function(t2, S2, C2, w, T2, E2, D2) {
      var O2 = E2.length - 1;
      switch (T2) {
        case 1:
          return E2[O2 - 1];
        case 2:
          this.$ = [];
          break;
        case 3:
          E2[O2 - 1].push(E2[O2]), this.$ = E2[O2 - 1];
          break;
        case 4:
        case 5:
          this.$ = E2[O2];
          break;
        case 6:
        case 7:
          this.$ = [];
          break;
        case 8:
          w.getCommonDb().setDiagramTitle(E2[O2].substr(6)), this.$ = E2[O2].substr(6);
          break;
        case 9:
          this.$ = E2[O2].trim(), w.getCommonDb().setAccTitle(this.$);
          break;
        case 10:
        case 11:
          this.$ = E2[O2].trim(), w.getCommonDb().setAccDescription(this.$);
          break;
        case 12:
          w.addSection(E2[O2].substr(8)), this.$ = E2[O2].substr(8);
          break;
        case 15:
          w.addTask(E2[O2], 0, ""), this.$ = E2[O2];
          break;
        case 16:
          w.addEvent(E2[O2].substr(2)), this.$ = E2[O2];
          break;
      }
    }, "anonymous"),
    table: [
      {
        3: 1,
        4: [1, 2]
      },
      { 1: [3] },
      t(S, [2, 2], { 5: 3 }),
      {
        6: [1, 4],
        7: 5,
        8: [1, 6],
        9: 7,
        10: [1, 8],
        11: C,
        12: T,
        14: E,
        16: D,
        17: O,
        18: 14,
        19: 15,
        20: k,
        21: A
      },
      t(S, [2, 7], { 1: [2, 1] }),
      t(S, [2, 3]),
      {
        9: 18,
        11: C,
        12: T,
        14: E,
        16: D,
        17: O,
        18: 14,
        19: 15,
        20: k,
        21: A
      },
      t(S, [2, 5]),
      t(S, [2, 6]),
      t(S, [2, 8]),
      { 13: [1, 19] },
      { 15: [1, 20] },
      t(S, [2, 11]),
      t(S, [2, 12]),
      t(S, [2, 13]),
      t(S, [2, 14]),
      t(S, [2, 15]),
      t(S, [2, 16]),
      t(S, [2, 4]),
      t(S, [2, 9]),
      t(S, [2, 10])
    ],
    defaultActions: {},
    parseError: /* @__PURE__ */ __name(function(t2, S2) {
      if (S2.recoverable) this.trace(t2);
      else {
        var C2 = Error(t2);
        throw C2.hash = S2, C2;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ __name(function(t2) {
      var S2 = this, C2 = [0], T2 = [], E2 = [null], D2 = [], O2 = this.table, k2 = "", A2 = 0, j2 = 0, M2 = 0, N = 2, P = 1, F = D2.slice.call(arguments, 1), I = Object.create(this.lexer), L = { yy: {} };
      for (var R in this.yy) Object.prototype.hasOwnProperty.call(this.yy, R) && (L.yy[R] = this.yy[R]);
      I.setInput(t2, L.yy), L.yy.lexer = I, L.yy.parser = this, I.yylloc === void 0 && (I.yylloc = {});
      var z = I.yylloc;
      D2.push(z);
      var B = I.options && I.options.ranges;
      typeof L.yy.parseError == "function" ? this.parseError = L.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function V(t3) {
        C2.length -= 2 * t3, E2.length -= t3, D2.length -= t3;
      }
      __name(V, "popStack");
      function H() {
        var t3 = T2.pop() || I.lex() || P;
        return typeof t3 != "number" && (t3 instanceof Array && (T2 = t3, t3 = T2.pop()), t3 = S2.symbols_[t3] || t3), t3;
      }
      __name(H, "lex");
      for (var U, W, G, K, q, J = {}, Y, X, Z, Q; ; ) {
        if (G = C2[C2.length - 1], this.defaultActions[G] ? K = this.defaultActions[G] : (U ?? (U = H()), K = O2[G] && O2[G][U]), K === void 0 || !K.length || !K[0]) {
          var $ = "";
          for (Y in Q = [], O2[G]) this.terminals_[Y] && Y > N && Q.push("'" + this.terminals_[Y] + "'");
          $ = I.showPosition ? "Parse error on line " + (A2 + 1) + ":\n" + I.showPosition() + "\nExpecting " + Q.join(", ") + ", got '" + (this.terminals_[U] || U) + "'" : "Parse error on line " + (A2 + 1) + ": Unexpected " + (U == P ? "end of input" : "'" + (this.terminals_[U] || U) + "'"), this.parseError($, {
            text: I.match,
            token: this.terminals_[U] || U,
            line: I.yylineno,
            loc: z,
            expected: Q
          });
        }
        if (K[0] instanceof Array && K.length > 1) throw Error("Parse Error: multiple actions possible at state: " + G + ", token: " + U);
        switch (K[0]) {
          case 1:
            C2.push(U), E2.push(I.yytext), D2.push(I.yylloc), C2.push(K[1]), U = null, W ? (U = W, W = null) : (j2 = I.yyleng, k2 = I.yytext, A2 = I.yylineno, z = I.yylloc, M2 > 0 && M2--);
            break;
          case 2:
            if (X = this.productions_[K[1]][1], J.$ = E2[E2.length - X], J._$ = {
              first_line: D2[D2.length - (X || 1)].first_line,
              last_line: D2[D2.length - 1].last_line,
              first_column: D2[D2.length - (X || 1)].first_column,
              last_column: D2[D2.length - 1].last_column
            }, B && (J._$.range = [D2[D2.length - (X || 1)].range[0], D2[D2.length - 1].range[1]]), q = this.performAction.apply(J, [
              k2,
              j2,
              A2,
              L.yy,
              K[1],
              E2,
              D2
            ].concat(F)), q !== void 0) return q;
            X && (C2 = C2.slice(0, -1 * X * 2), E2 = E2.slice(0, -1 * X), D2 = D2.slice(0, -1 * X)), C2.push(this.productions_[K[1]][0]), E2.push(J.$), D2.push(J._$), Z = O2[C2[C2.length - 2]][C2[C2.length - 1]], C2.push(Z);
            break;
          case 3:
            return true;
        }
      }
      return true;
    }, "parse")
  };
  j.lexer = /* @__PURE__ */ (function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ __name(function(t2, S2) {
        if (this.yy.parser) this.yy.parser.parseError(t2, S2);
        else throw Error(t2);
      }, "parseError"),
      setInput: /* @__PURE__ */ __name(function(t2, S2) {
        return this.yy = S2 || this.yy || {}, this._input = t2, 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 t2 = this._input[0];
        return this.yytext += t2, this.yyleng++, this.offset++, this.match += t2, this.matched += t2, t2.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), t2;
      }, "input"),
      unput: /* @__PURE__ */ __name(function(t2) {
        var S2 = t2.length, C2 = t2.split(/(?:\r\n?|\n)/g);
        this._input = t2 + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - S2), this.offset -= S2;
        var w = 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), C2.length - 1 && (this.yylineno -= C2.length - 1);
        var T2 = 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: C2 ? (C2.length === w.length ? this.yylloc.first_column : 0) + w[w.length - C2.length].length - C2[0].length : this.yylloc.first_column - S2
        }, this.options.ranges && (this.yylloc.range = [T2[0], T2[0] + this.yyleng - S2]), 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(t2) {
        this.unput(this.match.slice(t2));
      }, "less"),
      pastInput: /* @__PURE__ */ __name(function() {
        var t2 = this.matched.substr(0, this.matched.length - this.match.length);
        return (t2.length > 20 ? "..." : "") + t2.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ __name(function() {
        var t2 = this.match;
        return t2.length < 20 && (t2 += this._input.substr(0, 20 - t2.length)), (t2.substr(0, 20) + (t2.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      showPosition: /* @__PURE__ */ __name(function() {
        var t2 = this.pastInput(), S2 = Array(t2.length + 1).join("-");
        return t2 + this.upcomingInput() + "\n" + S2 + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ __name(function(t2, S2) {
        var C2, w, T2;
        if (this.options.backtrack_lexer && (T2 = {
          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 && (T2.yylloc.range = this.yylloc.range.slice(0))), w = t2[0].match(/(?:\r\n?|\n).*/g), w && (this.yylineno += w.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: w ? w[w.length - 1].length - w[w.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + t2[0].length
        }, this.yytext += t2[0], this.match += t2[0], this.matches = t2, 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(t2[0].length), this.matched += t2[0], C2 = this.performAction.call(this, this.yy, this, S2, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = false), C2) return C2;
        if (this._backtrack) {
          for (var E2 in T2) this[E2] = T2[E2];
          return false;
        }
        return false;
      }, "test_match"),
      next: /* @__PURE__ */ __name(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = true);
        var t2, S2, C2, w;
        this._more || (this.yytext = "", this.match = "");
        for (var T2 = this._currentRules(), E2 = 0; E2 < T2.length; E2++) if (C2 = this._input.match(this.rules[T2[E2]]), C2 && (!S2 || C2[0].length > S2[0].length)) {
          if (S2 = C2, w = E2, this.options.backtrack_lexer) {
            if (t2 = this.test_match(C2, T2[E2]), t2 !== false) return t2;
            if (this._backtrack) {
              S2 = false;
              continue;
            } else return false;
          } else if (!this.options.flex) break;
        }
        return S2 ? (t2 = this.test_match(S2, T2[w]), t2 === false ? false : t2) : 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(t2) {
        this.conditionStack.push(t2);
      }, "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(t2) {
        return t2 = this.conditionStack.length - 1 - Math.abs(t2 || 0), t2 >= 0 ? this.conditionStack[t2] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ __name(function(t2) {
        this.begin(t2);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ __name(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": true },
      performAction: /* @__PURE__ */ __name(function(t2, S2, C2, w) {
        switch (C2) {
          case 0:
            break;
          case 1:
            break;
          case 2:
            return 10;
          case 3:
            break;
          case 4:
            break;
          case 5:
            return 4;
          case 6:
            return 11;
          case 7:
            return this.begin("acc_title"), 12;
          case 8:
            return this.popState(), "acc_title_value";
          case 9:
            return this.begin("acc_descr"), 14;
          case 10:
            return this.popState(), "acc_descr_value";
          case 11:
            this.begin("acc_descr_multiline");
            break;
          case 12:
            this.popState();
            break;
          case 13:
            return "acc_descr_multiline_value";
          case 14:
            return 17;
          case 15:
            return 21;
          case 16:
            return 20;
          case 17:
            return 6;
          case 18:
            return "INVALID";
        }
      }, "anonymous"),
      rules: [
        /^(?:%(?!\{)[^\n]*)/i,
        /^(?:[^\}]%%[^\n]*)/i,
        /^(?:[\n]+)/i,
        /^(?:\s+)/i,
        /^(?:#[^\n]*)/i,
        /^(?:timeline\b)/i,
        /^(?:title\s[^\n]+)/i,
        /^(?:accTitle\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*:\s*)/i,
        /^(?:(?!\n||)*[^\n]*)/i,
        /^(?:accDescr\s*\{\s*)/i,
        /^(?:[\}])/i,
        /^(?:[^\}]*)/i,
        /^(?:section\s[^:\n]+)/i,
        /^(?::\s(?:[^:\n]|:(?!\s))+)/i,
        /^(?:[^#:\n]+)/i,
        /^(?:$)/i,
        /^(?:.)/i
      ],
      conditions: {
        acc_descr_multiline: {
          rules: [12, 13],
          inclusive: false
        },
        acc_descr: {
          rules: [10],
          inclusive: false
        },
        acc_title: {
          rules: [8],
          inclusive: false
        },
        INITIAL: {
          rules: [
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            9,
            11,
            14,
            15,
            16,
            17,
            18
          ],
          inclusive: true
        }
      }
    };
  })();
  function M() {
    this.yy = {};
  }
  return __name(M, "Parser"), M.prototype = j, j.Parser = M, new M();
})();
parser.parser = parser;
var timeline_default = parser, timelineDb_exports = {};
__export(timelineDb_exports, {
  addEvent: () => addEvent,
  addSection: () => addSection,
  addTask: () => addTask,
  addTaskOrg: () => addTaskOrg,
  clear: () => clear2,
  default: () => timelineDb_default,
  getCommonDb: () => getCommonDb,
  getSections: () => getSections,
  getTasks: () => getTasks
});
var currentSection = "", currentTaskId = 0, sections = [], tasks = [], rawTasks = [], getCommonDb = /* @__PURE__ */ __name(() => commonDb_exports, "getCommonDb"), clear2 = /* @__PURE__ */ __name(function() {
  sections.length = 0, tasks.length = 0, currentSection = "", rawTasks.length = 0, clear();
}, "clear"), addSection = /* @__PURE__ */ __name(function(t) {
  currentSection = t, sections.push(t);
}, "addSection"), getSections = /* @__PURE__ */ __name(function() {
  return sections;
}, "getSections"), getTasks = /* @__PURE__ */ __name(function() {
  let t = compileTasks(), S = 0;
  for (; !t && S < 100; ) t = compileTasks(), S++;
  return tasks.push(...rawTasks), tasks;
}, "getTasks"), addTask = /* @__PURE__ */ __name(function(t, S, C) {
  let w = {
    id: currentTaskId++,
    section: currentSection,
    type: currentSection,
    task: t,
    score: S || 0,
    events: C ? [C] : []
  };
  rawTasks.push(w);
}, "addTask"), addEvent = /* @__PURE__ */ __name(function(t) {
  rawTasks.find((t2) => t2.id === currentTaskId - 1).events.push(t);
}, "addEvent"), addTaskOrg = /* @__PURE__ */ __name(function(t) {
  let S = {
    section: currentSection,
    type: currentSection,
    description: t,
    task: t,
    classes: []
  };
  tasks.push(S);
}, "addTaskOrg"), compileTasks = /* @__PURE__ */ __name(function() {
  let t = /* @__PURE__ */ __name(function(t2) {
    return rawTasks[t2].processed;
  }, "compileTask"), S = true;
  for (let [C, w] of rawTasks.entries()) t(C), S && (S = w.processed);
  return S;
}, "compileTasks"), timelineDb_default = {
  clear: clear2,
  getCommonDb,
  addSection,
  getSections,
  getTasks,
  addTask,
  addTaskOrg,
  addEvent
}, MAX_SECTIONS = 12, drawRect = /* @__PURE__ */ __name(function(t, S) {
  let C = t.append("rect");
  return C.attr("x", S.x), C.attr("y", S.y), C.attr("fill", S.fill), C.attr("stroke", S.stroke), C.attr("width", S.width), C.attr("height", S.height), C.attr("rx", S.rx), C.attr("ry", S.ry), S.class !== void 0 && C.attr("class", S.class), C;
}, "drawRect"), drawFace = /* @__PURE__ */ __name(function(S, C) {
  let T = S.append("circle").attr("cx", C.cx).attr("cy", C.cy).attr("class", "face").attr("r", 15).attr("stroke-width", 2).attr("overflow", "visible"), E = S.append("g");
  E.append("circle").attr("cx", C.cx - 15 / 3).attr("cy", C.cy - 15 / 3).attr("r", 1.5).attr("stroke-width", 2).attr("fill", "#666").attr("stroke", "#666"), E.append("circle").attr("cx", C.cx + 15 / 3).attr("cy", C.cy - 15 / 3).attr("r", 1.5).attr("stroke-width", 2).attr("fill", "#666").attr("stroke", "#666");
  function D(S2) {
    let w = arc_default().startAngle(Math.PI / 2).endAngle(3 * (Math.PI / 2)).innerRadius(15 / 2).outerRadius(15 / 2.2);
    S2.append("path").attr("class", "mouth").attr("d", w).attr("transform", "translate(" + C.cx + "," + (C.cy + 2) + ")");
  }
  __name(D, "smile");
  function O(S2) {
    let w = arc_default().startAngle(3 * Math.PI / 2).endAngle(5 * (Math.PI / 2)).innerRadius(15 / 2).outerRadius(15 / 2.2);
    S2.append("path").attr("class", "mouth").attr("d", w).attr("transform", "translate(" + C.cx + "," + (C.cy + 7) + ")");
  }
  __name(O, "sad");
  function k(t) {
    t.append("line").attr("class", "mouth").attr("stroke", 2).attr("x1", C.cx - 5).attr("y1", C.cy + 7).attr("x2", C.cx + 5).attr("y2", C.cy + 7).attr("class", "mouth").attr("stroke-width", "1px").attr("stroke", "#666");
  }
  return __name(k, "ambivalent"), C.score > 3 ? D(E) : C.score < 3 ? O(E) : k(E), T;
}, "drawFace"), drawCircle = /* @__PURE__ */ __name(function(t, S) {
  let C = t.append("circle");
  return C.attr("cx", S.cx), C.attr("cy", S.cy), C.attr("class", "actor-" + S.pos), C.attr("fill", S.fill), C.attr("stroke", S.stroke), C.attr("r", S.r), C.class !== void 0 && C.attr("class", C.class), S.title !== void 0 && C.append("title").text(S.title), C;
}, "drawCircle"), drawText = /* @__PURE__ */ __name(function(t, S) {
  let C = S.text.replace(/<br\s*\/?>/gi, " "), w = t.append("text");
  w.attr("x", S.x), w.attr("y", S.y), w.attr("class", "legend"), w.style("text-anchor", S.anchor), S.class !== void 0 && w.attr("class", S.class);
  let T = w.append("tspan");
  return T.attr("x", S.x + S.textMargin * 2), T.text(C), w;
}, "drawText"), drawLabel = /* @__PURE__ */ __name(function(t, S) {
  function C(t2, S2, C2, w, T2) {
    return t2 + "," + S2 + " " + (t2 + C2) + "," + S2 + " " + (t2 + C2) + "," + (S2 + w - T2) + " " + (t2 + C2 - T2 * 1.2) + "," + (S2 + w) + " " + t2 + "," + (S2 + w);
  }
  __name(C, "genPoints");
  let T = t.append("polygon");
  T.attr("points", C(S.x, S.y, 50, 20, 7)), T.attr("class", "labelBox"), S.y += S.labelMargin, S.x += 0.5 * S.labelMargin, drawText(t, S);
}, "drawLabel"), drawSection = /* @__PURE__ */ __name(function(t, S, C) {
  let w = t.append("g"), T = getNoteRect();
  T.x = S.x, T.y = S.y, T.fill = S.fill, T.width = C.width, T.height = C.height, T.class = "journey-section section-type-" + S.num, T.rx = 3, T.ry = 3, drawRect(w, T), _drawTextCandidateFunc(C)(S.text, w, T.x, T.y, T.width, T.height, { class: "journey-section section-type-" + S.num }, C, S.colour);
}, "drawSection"), taskCount = -1, drawTask = /* @__PURE__ */ __name(function(t, S, C) {
  let w = S.x + C.width / 2, T = t.append("g");
  taskCount++, T.append("line").attr("id", "task" + taskCount).attr("x1", w).attr("y1", S.y).attr("x2", w).attr("y2", 450).attr("class", "task-line").attr("stroke-width", "1px").attr("stroke-dasharray", "4 2").attr("stroke", "#666"), drawFace(T, {
    cx: w,
    cy: 300 + (5 - S.score) * 30,
    score: S.score
  });
  let E = getNoteRect();
  E.x = S.x, E.y = S.y, E.fill = S.fill, E.width = C.width, E.height = C.height, E.class = "task task-type-" + S.num, E.rx = 3, E.ry = 3, drawRect(T, E), _drawTextCandidateFunc(C)(S.task, T, E.x, E.y, E.width, E.height, { class: "task" }, C, S.colour);
}, "drawTask"), drawBackgroundRect = /* @__PURE__ */ __name(function(t, S) {
  drawRect(t, {
    x: S.startx,
    y: S.starty,
    width: S.stopx - S.startx,
    height: S.stopy - S.starty,
    fill: S.fill,
    class: "rect"
  }).lower();
}, "drawBackgroundRect"), getTextObj = /* @__PURE__ */ __name(function() {
  return {
    x: 0,
    y: 0,
    fill: void 0,
    "text-anchor": "start",
    width: 100,
    height: 100,
    textMargin: 0,
    rx: 0,
    ry: 0
  };
}, "getTextObj"), getNoteRect = /* @__PURE__ */ __name(function() {
  return {
    x: 0,
    y: 0,
    width: 100,
    anchor: "start",
    height: 100,
    rx: 0,
    ry: 0
  };
}, "getNoteRect"), _drawTextCandidateFunc = /* @__PURE__ */ (function() {
  function t(t2, S2, C2, w, E, D, O, k) {
    T(S2.append("text").attr("x", C2 + E / 2).attr("y", w + D / 2 + 5).style("font-color", k).style("text-anchor", "middle").text(t2), O);
  }
  __name(t, "byText");
  function S(t2, S2, C2, w, E, D, O, k, A) {
    let { taskFontSize: j, taskFontFamily: M } = k, N = t2.split(/<br\s*\/?>/gi);
    for (let t3 = 0; t3 < N.length; t3++) {
      let k2 = t3 * j - j * (N.length - 1) / 2, P = S2.append("text").attr("x", C2 + E / 2).attr("y", w).attr("fill", A).style("text-anchor", "middle").style("font-size", j).style("font-family", M);
      P.append("tspan").attr("x", C2 + E / 2).attr("dy", k2).text(N[t3]), P.attr("y", w + D / 2).attr("dominant-baseline", "central").attr("alignment-baseline", "central"), T(P, O);
    }
  }
  __name(S, "byTspan");
  function C(t2, C2, w, E, D, O, k, A) {
    let j = C2.append("switch"), M = j.append("foreignObject").attr("x", w).attr("y", E).attr("width", D).attr("height", O).attr("position", "fixed").append("xhtml:div").style("display", "table").style("height", "100%").style("width", "100%");
    M.append("div").attr("class", "label").style("display", "table-cell").style("text-align", "center").style("vertical-align", "middle").text(t2), S(t2, j, w, E, D, O, k, A), T(M, k);
  }
  __name(C, "byFo");
  function T(t2, S2) {
    for (let C2 in S2) C2 in S2 && t2.attr(C2, S2[C2]);
  }
  return __name(T, "_setTextAttrs"), function(w) {
    return w.textPlacement === "fo" ? C : w.textPlacement === "old" ? t : S;
  };
})(), initGraphics = /* @__PURE__ */ __name(function(t) {
  t.append("defs").append("marker").attr("id", "arrowhead").attr("refX", 5).attr("refY", 2).attr("markerWidth", 6).attr("markerHeight", 4).attr("orient", "auto").append("path").attr("d", "M 0,0 V 4 L6,2 Z");
}, "initGraphics");
function wrap(t, S) {
  t.each(function() {
    var t2 = select_default(this), C = t2.text().split(/(\s+|<br>)/).reverse(), w, E = [], D = 1.1, O = t2.attr("y"), k = parseFloat(t2.attr("dy")), A = t2.text(null).append("tspan").attr("x", 0).attr("y", O).attr("dy", k + "em");
    for (let T = 0; T < C.length; T++) w = C[C.length - 1 - T], E.push(w), A.text(E.join(" ").trim()), (A.node().getComputedTextLength() > S || w === "<br>") && (E.pop(), A.text(E.join(" ").trim()), E = w === "<br>" ? [""] : [w], A = t2.append("tspan").attr("x", 0).attr("y", O).attr("dy", D + "em").text(w));
  });
}
__name(wrap, "wrap");
var drawNode = /* @__PURE__ */ __name(function(t, S, C, w) {
  var _a;
  let T = C % MAX_SECTIONS - 1, E = t.append("g");
  S.section = T, E.attr("class", (S.class ? S.class + " " : "") + "timeline-node " + ("section-" + T));
  let D = E.append("g"), O = E.append("g"), k = O.append("text").text(S.descr).attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle").call(wrap, S.width).node().getBBox(), A = ((_a = w.fontSize) == null ? void 0 : _a.replace) ? w.fontSize.replace("px", "") : w.fontSize;
  return S.height = k.height + A * 1.1 * 0.5 + S.padding, S.height = Math.max(S.height, S.maxHeight), S.width += 2 * S.padding, O.attr("transform", "translate(" + S.width / 2 + ", " + S.padding / 2 + ")"), defaultBkg(D, S, T, w), S;
}, "drawNode"), getVirtualNodeHeight = /* @__PURE__ */ __name(function(t, S, C) {
  var _a;
  let w = t.append("g"), T = w.append("text").text(S.descr).attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle").call(wrap, S.width).node().getBBox(), E = ((_a = C.fontSize) == null ? void 0 : _a.replace) ? C.fontSize.replace("px", "") : C.fontSize;
  return w.remove(), T.height + E * 1.1 * 0.5 + S.padding;
}, "getVirtualNodeHeight"), defaultBkg = /* @__PURE__ */ __name(function(t, S, C) {
  t.append("path").attr("id", "node-" + S.id).attr("class", "node-bkg node-" + S.type).attr("d", `M0 ${S.height - 5} v${-S.height + 10} q0,-5 5,-5 h${S.width - 10} q5,0 5,5 v${S.height - 5} H0 Z`), t.append("line").attr("class", "node-line-" + C).attr("x1", 0).attr("y1", S.height).attr("x2", S.width).attr("y2", S.height);
}, "defaultBkg"), svgDraw_default = {
  drawRect,
  drawCircle,
  drawSection,
  drawText,
  drawLabel,
  drawTask,
  drawBackgroundRect,
  getTextObj,
  getNoteRect,
  initGraphics,
  drawNode,
  getVirtualNodeHeight
}, draw = /* @__PURE__ */ __name(function(t, C, w, D) {
  var _a, _b, _c;
  let O = getConfig2(), k = ((_a = O.timeline) == null ? void 0 : _a.leftMargin) ?? 50;
  log.debug("timeline", D.db);
  let A = O.securityLevel, M;
  A === "sandbox" && (M = select_default("#i" + C));
  let N = select_default(A === "sandbox" ? M.nodes()[0].contentDocument.body : "body").select("#" + C);
  N.append("g");
  let P = D.db.getTasks(), F = D.db.getCommonDb().getDiagramTitle();
  log.debug("task", P), svgDraw_default.initGraphics(N);
  let I = D.db.getSections();
  log.debug("sections", I);
  let L = 0, R = 0, z = 0, B = 0, V = 50 + k, H = 50;
  B = 50;
  let U = 0, W = true;
  I.forEach(function(t2) {
    let C2 = {
      number: U,
      descr: t2,
      section: U,
      width: 150,
      padding: 20,
      maxHeight: L
    }, w2 = svgDraw_default.getVirtualNodeHeight(N, C2, O);
    log.debug("sectionHeight before draw", w2), L = Math.max(L, w2 + 20);
  });
  let G = 0, K = 0;
  log.debug("tasks.length", P.length);
  for (let [t2, C2] of P.entries()) {
    let w2 = {
      number: t2,
      descr: C2,
      section: C2.section,
      width: 150,
      padding: 20,
      maxHeight: R
    }, T = svgDraw_default.getVirtualNodeHeight(N, w2, O);
    log.debug("taskHeight before draw", T), R = Math.max(R, T + 20), G = Math.max(G, C2.events.length);
    let E = 0;
    for (let t3 of C2.events) {
      let S = {
        descr: t3,
        section: C2.section,
        number: C2.section,
        width: 150,
        padding: 20,
        maxHeight: 50
      };
      E += svgDraw_default.getVirtualNodeHeight(N, S, O);
    }
    C2.events.length > 0 && (E += (C2.events.length - 1) * 10), K = Math.max(K, E);
  }
  log.debug("maxSectionHeight before draw", L), log.debug("maxTaskHeight before draw", R), I && I.length > 0 ? I.forEach((t2) => {
    let C2 = P.filter((S) => S.section === t2), w2 = {
      number: U,
      descr: t2,
      section: U,
      width: 200 * Math.max(C2.length, 1) - 50,
      padding: 20,
      maxHeight: L
    };
    log.debug("sectionNode", w2);
    let T = N.append("g"), E = svgDraw_default.drawNode(T, w2, U, O);
    log.debug("sectionNode output", E), T.attr("transform", `translate(${V}, ${B})`), H += L + 50, C2.length > 0 && drawTasks(N, C2, U, V, H, R, O, G, K, L, false), V += 200 * Math.max(C2.length, 1), H = B, U++;
  }) : (W = false, drawTasks(N, P, U, V, H, R, O, G, K, L, true));
  let q = N.node().getBBox();
  log.debug("bounds", q), F && N.append("text").text(F).attr("x", q.width / 2 - k).attr("font-size", "4ex").attr("font-weight", "bold").attr("y", 20), z = W ? L + R + 150 : R + 100, N.append("g").attr("class", "lineWrapper").append("line").attr("x1", k).attr("y1", z).attr("x2", q.width + 3 * k).attr("y2", z).attr("stroke-width", 4).attr("stroke", "black").attr("marker-end", "url(#arrowhead)"), setupGraphViewbox(void 0, N, ((_b = O.timeline) == null ? void 0 : _b.padding) ?? 50, ((_c = O.timeline) == null ? void 0 : _c.useMaxWidth) ?? false);
}, "draw"), drawTasks = /* @__PURE__ */ __name(function(t, C, w, T, E, D, O, k, A, j, M) {
  var _a;
  for (let k2 of C) {
    let C2 = {
      descr: k2.task,
      section: w,
      number: w,
      width: 150,
      padding: 20,
      maxHeight: D
    };
    log.debug("taskNode", C2);
    let j2 = t.append("g").attr("class", "taskWrapper"), N = svgDraw_default.drawNode(j2, C2, w, O).height;
    if (log.debug("taskHeight after draw", N), j2.attr("transform", `translate(${T}, ${E})`), D = Math.max(D, N), k2.events) {
      let S = t.append("g").attr("class", "lineWrapper"), C3 = D;
      E += 100, C3 += drawEvents(t, k2.events, w, T, E, O), E -= 100, S.append("line").attr("x1", T + 190 / 2).attr("y1", E + D).attr("x2", T + 190 / 2).attr("y2", E + D + 100 + A + 100).attr("stroke-width", 2).attr("stroke", "black").attr("marker-end", "url(#arrowhead)").attr("stroke-dasharray", "5,5");
    }
    T += 200, M && !((_a = O.timeline) == null ? void 0 : _a.disableMulticolor) && w++;
  }
  E -= 10;
}, "drawTasks"), drawEvents = /* @__PURE__ */ __name(function(t, C, w, T, E, D) {
  let O = 0, k = E;
  E += 100;
  for (let k2 of C) {
    let C2 = {
      descr: k2,
      section: w,
      number: w,
      width: 150,
      padding: 20,
      maxHeight: 50
    };
    log.debug("eventNode", C2);
    let A = t.append("g").attr("class", "eventWrapper"), j = svgDraw_default.drawNode(A, C2, w, D).height;
    O += j, A.attr("transform", `translate(${T}, ${E})`), E = E + 10 + j;
  }
  return E = k, O;
}, "drawEvents"), timelineRenderer_default = {
  setConf: /* @__PURE__ */ __name(() => {
  }, "setConf"),
  draw
}, genSections = /* @__PURE__ */ __name((t) => {
  let S = "";
  for (let S2 = 0; S2 < t.THEME_COLOR_LIMIT; S2++) t["lineColor" + S2] = t["lineColor" + S2] || t["cScaleInv" + S2], is_dark_default(t["lineColor" + S2]) ? t["lineColor" + S2] = lighten_default(t["lineColor" + S2], 20) : t["lineColor" + S2] = darken_default(t["lineColor" + S2], 20);
  for (let C = 0; C < t.THEME_COLOR_LIMIT; C++) {
    let w = "" + (17 - 3 * C);
    S += `
    .section-${C - 1} rect, .section-${C - 1} path, .section-${C - 1} circle, .section-${C - 1} path  {
      fill: ${t["cScale" + C]};
    }
    .section-${C - 1} text {
     fill: ${t["cScaleLabel" + C]};
    }
    .node-icon-${C - 1} {
      font-size: 40px;
      color: ${t["cScaleLabel" + C]};
    }
    .section-edge-${C - 1}{
      stroke: ${t["cScale" + C]};
    }
    .edge-depth-${C - 1}{
      stroke-width: ${w};
    }
    .section-${C - 1} line {
      stroke: ${t["cScaleInv" + C]} ;
      stroke-width: 3;
    }

    .lineWrapper line{
      stroke: ${t["cScaleLabel" + C]} ;
    }

    .disabled, .disabled circle, .disabled text {
      fill: lightgray;
    }
    .disabled text {
      fill: #efefef;
    }
    `;
  }
  return S;
}, "genSections"), diagram = {
  db: timelineDb_exports,
  renderer: timelineRenderer_default,
  parser: timeline_default,
  styles: /* @__PURE__ */ __name((t) => `
  .edge {
    stroke-width: 3;
  }
  ${genSections(t)}
  .section-root rect, .section-root path, .section-root circle  {
    fill: ${t.git0};
  }
  .section-root text {
    fill: ${t.gitBranchLabel0};
  }
  .icon-container {
    height:100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .edge {
    fill: none;
  }
  .eventWrapper  {
   filter: brightness(120%);
  }
`, "getStyles")
};
export {
  diagram
};
