import { _ as r, g as mt, l as $, a9 as V, bm as xt, bn as bt, bo as kt, bp as _t, ay as vt, bq as wt, at as St } from "./index-BDD0CD9m.js";
import { h as et } from "./arc-DYb5Ak6k-js8YHzj6.js";
var J = function() {
  var n = /* @__PURE__ */ r(function(f, s, l, h) {
    for (l = l || {}, h = f.length; h--; l[f[h]] = s) ;
    return l;
  }, "o"), t = [6, 8, 10, 11, 12, 14, 16, 17, 20, 21], e = [1, 9], a = [1, 10], i = [1, 11], o = [1, 12], u = [1, 13], p = [1, 16], y = [1, 17], m = {
    trace: /* @__PURE__ */ r(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__ */ r(function(f, s, l, h, d, c, k) {
      var x = c.length - 1;
      switch (d) {
        case 1:
          return c[x - 1];
        case 2:
          this.$ = [];
          break;
        case 3:
          c[x - 1].push(c[x]), this.$ = c[x - 1];
          break;
        case 4:
        case 5:
          this.$ = c[x];
          break;
        case 6:
        case 7:
          this.$ = [];
          break;
        case 8:
          h.getCommonDb().setDiagramTitle(c[x].substr(6)), this.$ = c[x].substr(6);
          break;
        case 9:
          this.$ = c[x].trim(), h.getCommonDb().setAccTitle(this.$);
          break;
        case 10:
        case 11:
          this.$ = c[x].trim(), h.getCommonDb().setAccDescription(this.$);
          break;
        case 12:
          h.addSection(c[x].substr(8)), this.$ = c[x].substr(8);
          break;
        case 15:
          h.addTask(c[x], 0, ""), this.$ = c[x];
          break;
        case 16:
          h.addEvent(c[x].substr(2)), this.$ = c[x];
          break;
      }
    }, "anonymous"),
    table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, n(t, [2, 2], { 5: 3 }), { 6: [1, 4], 7: 5, 8: [1, 6], 9: 7, 10: [1, 8], 11: e, 12: a, 14: i, 16: o, 17: u, 18: 14, 19: 15, 20: p, 21: y }, n(t, [2, 7], { 1: [2, 1] }), n(t, [2, 3]), { 9: 18, 11: e, 12: a, 14: i, 16: o, 17: u, 18: 14, 19: 15, 20: p, 21: y }, n(t, [2, 5]), n(t, [2, 6]), n(t, [2, 8]), { 13: [1, 19] }, { 15: [1, 20] }, n(t, [2, 11]), n(t, [2, 12]), n(t, [2, 13]), n(t, [2, 14]), n(t, [2, 15]), n(t, [2, 16]), n(t, [2, 4]), n(t, [2, 9]), n(t, [2, 10])],
    defaultActions: {},
    parseError: /* @__PURE__ */ r(function(f, s) {
      if (s.recoverable)
        this.trace(f);
      else {
        var l = new Error(f);
        throw l.hash = s, l;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ r(function(f) {
      var s = this, l = [0], h = [], d = [null], c = [], k = this.table, x = "", N = 0, M = 0, F = 2, I = 1, H = c.slice.call(arguments, 1), _ = Object.create(this.lexer), S = { yy: {} };
      for (var v in this.yy)
        Object.prototype.hasOwnProperty.call(this.yy, v) && (S.yy[v] = this.yy[v]);
      _.setInput(f, S.yy), S.yy.lexer = _, S.yy.parser = this, typeof _.yylloc > "u" && (_.yylloc = {});
      var A = _.yylloc;
      c.push(A);
      var O = _.options && _.options.ranges;
      typeof S.yy.parseError == "function" ? this.parseError = S.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function L(E) {
        l.length = l.length - 2 * E, d.length = d.length - E, c.length = c.length - E;
      }
      r(L, "popStack");
      function z() {
        var E;
        return E = h.pop() || _.lex() || I, typeof E != "number" && (E instanceof Array && (h = E, E = h.pop()), E = s.symbols_[E] || E), E;
      }
      r(z, "lex");
      for (var w, R, T, Z, P = {}, W, C, tt, q; ; ) {
        if (R = l[l.length - 1], this.defaultActions[R] ? T = this.defaultActions[R] : ((w === null || typeof w > "u") && (w = z()), T = k[R] && k[R][w]), typeof T > "u" || !T.length || !T[0]) {
          var G = "";
          q = [];
          for (W in k[R])
            this.terminals_[W] && W > F && q.push("'" + this.terminals_[W] + "'");
          _.showPosition ? G = "Parse error on line " + (N + 1) + `:
` + _.showPosition() + `
Expecting ` + q.join(", ") + ", got '" + (this.terminals_[w] || w) + "'" : G = "Parse error on line " + (N + 1) + ": Unexpected " + (w == I ? "end of input" : "'" + (this.terminals_[w] || w) + "'"), this.parseError(G, {
            text: _.match,
            token: this.terminals_[w] || w,
            line: _.yylineno,
            loc: A,
            expected: q
          });
        }
        if (T[0] instanceof Array && T.length > 1)
          throw new Error("Parse Error: multiple actions possible at state: " + R + ", token: " + w);
        switch (T[0]) {
          case 1:
            l.push(w), d.push(_.yytext), c.push(_.yylloc), l.push(T[1]), w = null, M = _.yyleng, x = _.yytext, N = _.yylineno, A = _.yylloc;
            break;
          case 2:
            if (C = this.productions_[T[1]][1], P.$ = d[d.length - C], P._$ = {
              first_line: c[c.length - (C || 1)].first_line,
              last_line: c[c.length - 1].last_line,
              first_column: c[c.length - (C || 1)].first_column,
              last_column: c[c.length - 1].last_column
            }, O && (P._$.range = [
              c[c.length - (C || 1)].range[0],
              c[c.length - 1].range[1]
            ]), Z = this.performAction.apply(P, [
              x,
              M,
              N,
              S.yy,
              T[1],
              d,
              c
            ].concat(H)), typeof Z < "u")
              return Z;
            C && (l = l.slice(0, -1 * C * 2), d = d.slice(0, -1 * C), c = c.slice(0, -1 * C)), l.push(this.productions_[T[1]][0]), d.push(P.$), c.push(P._$), tt = k[l[l.length - 2]][l[l.length - 1]], l.push(tt);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  }, b = /* @__PURE__ */ function() {
    var f = {
      EOF: 1,
      parseError: /* @__PURE__ */ r(function(s, l) {
        if (this.yy.parser)
          this.yy.parser.parseError(s, l);
        else
          throw new Error(s);
      }, "parseError"),
      // resets the lexer, sets new input
      setInput: /* @__PURE__ */ r(function(s, l) {
        return this.yy = l || this.yy || {}, this._input = s, this._more = this._backtrack = this.done = !1, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
          first_line: 1,
          first_column: 0,
          last_line: 1,
          last_column: 0
        }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
      }, "setInput"),
      // consumes and returns one char from the input
      input: /* @__PURE__ */ r(function() {
        var s = this._input[0];
        this.yytext += s, this.yyleng++, this.offset++, this.match += s, this.matched += s;
        var l = s.match(/(?:\r\n?|\n).*/g);
        return l ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), s;
      }, "input"),
      // unshifts one char (or a string) into the input
      unput: /* @__PURE__ */ r(function(s) {
        var l = s.length, h = s.split(/(?:\r\n?|\n)/g);
        this._input = s + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - l), this.offset -= l;
        var d = this.match.split(/(?:\r\n?|\n)/g);
        this.match = this.match.substr(0, this.match.length - 1), this.matched = this.matched.substr(0, this.matched.length - 1), h.length - 1 && (this.yylineno -= h.length - 1);
        var c = 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: h ? (h.length === d.length ? this.yylloc.first_column : 0) + d[d.length - h.length].length - h[0].length : this.yylloc.first_column - l
        }, this.options.ranges && (this.yylloc.range = [c[0], c[0] + this.yyleng - l]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      // When called from action, caches matched text and appends it on next action
      more: /* @__PURE__ */ r(function() {
        return this._more = !0, this;
      }, "more"),
      // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
      reject: /* @__PURE__ */ r(function() {
        if (this.options.backtrack_lexer)
          this._backtrack = !0;
        else
          return this.parseError("Lexical error on line " + (this.yylineno + 1) + `. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
` + this.showPosition(), {
            text: "",
            token: null,
            line: this.yylineno
          });
        return this;
      }, "reject"),
      // retain first n characters of the match
      less: /* @__PURE__ */ r(function(s) {
        this.unput(this.match.slice(s));
      }, "less"),
      // displays already matched input, i.e. for error messages
      pastInput: /* @__PURE__ */ r(function() {
        var s = this.matched.substr(0, this.matched.length - this.match.length);
        return (s.length > 20 ? "..." : "") + s.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      // displays upcoming input, i.e. for error messages
      upcomingInput: /* @__PURE__ */ r(function() {
        var s = this.match;
        return s.length < 20 && (s += this._input.substr(0, 20 - s.length)), (s.substr(0, 20) + (s.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      // displays the character position where the lexing error occurred, i.e. for error messages
      showPosition: /* @__PURE__ */ r(function() {
        var s = this.pastInput(), l = new Array(s.length + 1).join("-");
        return s + this.upcomingInput() + `
` + l + "^";
      }, "showPosition"),
      // test the lexed token: return FALSE when not a match, otherwise return token
      test_match: /* @__PURE__ */ r(function(s, l) {
        var h, d, c;
        if (this.options.backtrack_lexer && (c = {
          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 && (c.yylloc.range = this.yylloc.range.slice(0))), d = s[0].match(/(?:\r\n?|\n).*/g), d && (this.yylineno += d.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: d ? d[d.length - 1].length - d[d.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + s[0].length
        }, this.yytext += s[0], this.match += s[0], this.matches = s, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = !1, this._backtrack = !1, this._input = this._input.slice(s[0].length), this.matched += s[0], h = this.performAction.call(this, this.yy, this, l, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), h)
          return h;
        if (this._backtrack) {
          for (var k in c)
            this[k] = c[k];
          return !1;
        }
        return !1;
      }, "test_match"),
      // return next match in input
      next: /* @__PURE__ */ r(function() {
        if (this.done)
          return this.EOF;
        this._input || (this.done = !0);
        var s, l, h, d;
        this._more || (this.yytext = "", this.match = "");
        for (var c = this._currentRules(), k = 0; k < c.length; k++)
          if (h = this._input.match(this.rules[c[k]]), h && (!l || h[0].length > l[0].length)) {
            if (l = h, d = k, this.options.backtrack_lexer) {
              if (s = this.test_match(h, c[k]), s !== !1)
                return s;
              if (this._backtrack) {
                l = !1;
                continue;
              } else
                return !1;
            } else if (!this.options.flex)
              break;
          }
        return l ? (s = this.test_match(l, c[d]), s !== !1 ? s : !1) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      // return next match that has a token
      lex: /* @__PURE__ */ r(function() {
        var s = this.next();
        return s || this.lex();
      }, "lex"),
      // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
      begin: /* @__PURE__ */ r(function(s) {
        this.conditionStack.push(s);
      }, "begin"),
      // pop the previously active lexer condition state off the condition stack
      popState: /* @__PURE__ */ r(function() {
        var s = this.conditionStack.length - 1;
        return s > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      // produce the lexer rule set which is active for the currently active lexer condition state
      _currentRules: /* @__PURE__ */ r(function() {
        return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
      }, "_currentRules"),
      // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
      topState: /* @__PURE__ */ r(function(s) {
        return s = this.conditionStack.length - 1 - Math.abs(s || 0), s >= 0 ? this.conditionStack[s] : "INITIAL";
      }, "topState"),
      // alias for begin(condition)
      pushState: /* @__PURE__ */ r(function(s) {
        this.begin(s);
      }, "pushState"),
      // return the number of states currently on the stack
      stateStackSize: /* @__PURE__ */ r(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ r(function(s, l, h, d) {
        switch (h) {
          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: !1 }, acc_descr: { rules: [10], inclusive: !1 }, acc_title: { rules: [8], inclusive: !1 }, INITIAL: { rules: [0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 14, 15, 16, 17, 18], inclusive: !0 } }
    };
    return f;
  }();
  m.lexer = b;
  function g() {
    this.yy = {};
  }
  return r(g, "Parser"), g.prototype = m, m.Parser = g, new g();
}();
J.parser = J;
var $t = J, rt = {};
vt(rt, {
  addEvent: () => pt,
  addSection: () => lt,
  addTask: () => ut,
  addTaskOrg: () => yt,
  clear: () => ct,
  default: () => Et,
  getCommonDb: () => ot,
  getSections: () => ht,
  getTasks: () => dt
});
var j = "", at = 0, X = [], U = [], B = [], ot = /* @__PURE__ */ r(() => wt, "getCommonDb"), ct = /* @__PURE__ */ r(function() {
  X.length = 0, U.length = 0, j = "", B.length = 0, St();
}, "clear"), lt = /* @__PURE__ */ r(function(n) {
  j = n, X.push(n);
}, "addSection"), ht = /* @__PURE__ */ r(function() {
  return X;
}, "getSections"), dt = /* @__PURE__ */ r(function() {
  let n = nt();
  const t = 100;
  let e = 0;
  for (; !n && e < t; )
    n = nt(), e++;
  return U.push(...B), U;
}, "getTasks"), ut = /* @__PURE__ */ r(function(n, t, e) {
  const a = {
    id: at++,
    section: j,
    type: j,
    task: n,
    score: t || 0,
    //if event is defined, then add it the events array
    events: e ? [e] : []
  };
  B.push(a);
}, "addTask"), pt = /* @__PURE__ */ r(function(n) {
  B.find((t) => t.id === at - 1).events.push(n);
}, "addEvent"), yt = /* @__PURE__ */ r(function(n) {
  const t = {
    section: j,
    type: j,
    description: n,
    task: n,
    classes: []
  };
  U.push(t);
}, "addTaskOrg"), nt = /* @__PURE__ */ r(function() {
  const n = /* @__PURE__ */ r(function(e) {
    return B[e].processed;
  }, "compileTask");
  let t = !0;
  for (const [e, a] of B.entries())
    n(e), t = t && a.processed;
  return t;
}, "compileTasks"), Et = {
  clear: ct,
  getCommonDb: ot,
  addSection: lt,
  getSections: ht,
  getTasks: dt,
  addTask: ut,
  addTaskOrg: yt,
  addEvent: pt
}, Tt = 12, Y = /* @__PURE__ */ r(function(n, t) {
  const e = n.append("rect");
  return e.attr("x", t.x), e.attr("y", t.y), e.attr("fill", t.fill), e.attr("stroke", t.stroke), e.attr("width", t.width), e.attr("height", t.height), e.attr("rx", t.rx), e.attr("ry", t.ry), t.class !== void 0 && e.attr("class", t.class), e;
}, "drawRect"), Mt = /* @__PURE__ */ r(function(n, t) {
  const e = n.append("circle").attr("cx", t.cx).attr("cy", t.cy).attr("class", "face").attr("r", 15).attr("stroke-width", 2).attr("overflow", "visible"), a = n.append("g");
  a.append("circle").attr("cx", t.cx - 15 / 3).attr("cy", t.cy - 15 / 3).attr("r", 1.5).attr("stroke-width", 2).attr("fill", "#666").attr("stroke", "#666"), a.append("circle").attr("cx", t.cx + 15 / 3).attr("cy", t.cy - 15 / 3).attr("r", 1.5).attr("stroke-width", 2).attr("fill", "#666").attr("stroke", "#666");
  function i(p) {
    const y = et().startAngle(Math.PI / 2).endAngle(3 * (Math.PI / 2)).innerRadius(7.5).outerRadius(6.8181818181818175);
    p.append("path").attr("class", "mouth").attr("d", y).attr("transform", "translate(" + t.cx + "," + (t.cy + 2) + ")");
  }
  r(i, "smile");
  function o(p) {
    const y = et().startAngle(3 * Math.PI / 2).endAngle(5 * (Math.PI / 2)).innerRadius(7.5).outerRadius(6.8181818181818175);
    p.append("path").attr("class", "mouth").attr("d", y).attr("transform", "translate(" + t.cx + "," + (t.cy + 7) + ")");
  }
  r(o, "sad");
  function u(p) {
    p.append("line").attr("class", "mouth").attr("stroke", 2).attr("x1", t.cx - 5).attr("y1", t.cy + 7).attr("x2", t.cx + 5).attr("y2", t.cy + 7).attr("class", "mouth").attr("stroke-width", "1px").attr("stroke", "#666");
  }
  return r(u, "ambivalent"), t.score > 3 ? i(a) : t.score < 3 ? o(a) : u(a), e;
}, "drawFace"), At = /* @__PURE__ */ r(function(n, t) {
  const e = n.append("circle");
  return e.attr("cx", t.cx), e.attr("cy", t.cy), e.attr("class", "actor-" + t.pos), e.attr("fill", t.fill), e.attr("stroke", t.stroke), e.attr("r", t.r), e.class !== void 0 && e.attr("class", e.class), t.title !== void 0 && e.append("title").text(t.title), e;
}, "drawCircle"), gt = /* @__PURE__ */ r(function(n, t) {
  const e = t.text.replace(/<br\s*\/?>/gi, " "), a = n.append("text");
  a.attr("x", t.x), a.attr("y", t.y), a.attr("class", "legend"), a.style("text-anchor", t.anchor), t.class !== void 0 && a.attr("class", t.class);
  const i = a.append("tspan");
  return i.attr("x", t.x + t.textMargin * 2), i.text(e), a;
}, "drawText"), Nt = /* @__PURE__ */ r(function(n, t) {
  function e(i, o, u, p, y) {
    return i + "," + o + " " + (i + u) + "," + o + " " + (i + u) + "," + (o + p - y) + " " + (i + u - y * 1.2) + "," + (o + p) + " " + i + "," + (o + p);
  }
  r(e, "genPoints");
  const a = n.append("polygon");
  a.attr("points", e(t.x, t.y, 50, 20, 7)), a.attr("class", "labelBox"), t.y = t.y + t.labelMargin, t.x = t.x + 0.5 * t.labelMargin, gt(n, t);
}, "drawLabel"), Ct = /* @__PURE__ */ r(function(n, t, e) {
  const a = n.append("g"), i = K();
  i.x = t.x, i.y = t.y, i.fill = t.fill, i.width = e.width, i.height = e.height, i.class = "journey-section section-type-" + t.num, i.rx = 3, i.ry = 3, Y(a, i), ft(e)(
    t.text,
    a,
    i.x,
    i.y,
    i.width,
    i.height,
    { class: "journey-section section-type-" + t.num },
    e,
    t.colour
  );
}, "drawSection"), it = -1, It = /* @__PURE__ */ r(function(n, t, e) {
  const a = t.x + e.width / 2, i = n.append("g");
  it++, i.append("line").attr("id", "task" + it).attr("x1", a).attr("y1", t.y).attr("x2", a).attr("y2", 450).attr("class", "task-line").attr("stroke-width", "1px").attr("stroke-dasharray", "4 2").attr("stroke", "#666"), Mt(i, {
    cx: a,
    cy: 300 + (5 - t.score) * 30,
    score: t.score
  });
  const o = K();
  o.x = t.x, o.y = t.y, o.fill = t.fill, o.width = e.width, o.height = e.height, o.class = "task task-type-" + t.num, o.rx = 3, o.ry = 3, Y(i, o), ft(e)(
    t.task,
    i,
    o.x,
    o.y,
    o.width,
    o.height,
    { class: "task" },
    e,
    t.colour
  );
}, "drawTask"), Ot = /* @__PURE__ */ r(function(n, t) {
  Y(n, {
    x: t.startx,
    y: t.starty,
    width: t.stopx - t.startx,
    height: t.stopy - t.starty,
    fill: t.fill,
    class: "rect"
  }).lower();
}, "drawBackgroundRect"), Lt = /* @__PURE__ */ r(function() {
  return {
    x: 0,
    y: 0,
    fill: void 0,
    "text-anchor": "start",
    width: 100,
    height: 100,
    textMargin: 0,
    rx: 0,
    ry: 0
  };
}, "getTextObj"), K = /* @__PURE__ */ r(function() {
  return {
    x: 0,
    y: 0,
    width: 100,
    anchor: "start",
    height: 100,
    rx: 0,
    ry: 0
  };
}, "getNoteRect"), ft = /* @__PURE__ */ function() {
  function n(i, o, u, p, y, m, b, g) {
    const f = o.append("text").attr("x", u + y / 2).attr("y", p + m / 2 + 5).style("font-color", g).style("text-anchor", "middle").text(i);
    a(f, b);
  }
  r(n, "byText");
  function t(i, o, u, p, y, m, b, g, f) {
    const { taskFontSize: s, taskFontFamily: l } = g, h = i.split(/<br\s*\/?>/gi);
    for (let d = 0; d < h.length; d++) {
      const c = d * s - s * (h.length - 1) / 2, k = o.append("text").attr("x", u + y / 2).attr("y", p).attr("fill", f).style("text-anchor", "middle").style("font-size", s).style("font-family", l);
      k.append("tspan").attr("x", u + y / 2).attr("dy", c).text(h[d]), k.attr("y", p + m / 2).attr("dominant-baseline", "central").attr("alignment-baseline", "central"), a(k, b);
    }
  }
  r(t, "byTspan");
  function e(i, o, u, p, y, m, b, g) {
    const f = o.append("switch"), s = f.append("foreignObject").attr("x", u).attr("y", p).attr("width", y).attr("height", m).attr("position", "fixed").append("xhtml:div").style("display", "table").style("height", "100%").style("width", "100%");
    s.append("div").attr("class", "label").style("display", "table-cell").style("text-align", "center").style("vertical-align", "middle").text(i), t(i, f, u, p, y, m, b, g), a(s, b);
  }
  r(e, "byFo");
  function a(i, o) {
    for (const u in o)
      u in o && i.attr(u, o[u]);
  }
  return r(a, "_setTextAttrs"), function(i) {
    return i.textPlacement === "fo" ? e : i.textPlacement === "old" ? n : t;
  };
}(), Rt = /* @__PURE__ */ r(function(n) {
  n.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 Q(n, t) {
  n.each(function() {
    var e = V(this), a = e.text().split(/(\s+|<br>)/).reverse(), i, o = [], u = 1.1, p = e.attr("y"), y = parseFloat(e.attr("dy")), m = e.text(null).append("tspan").attr("x", 0).attr("y", p).attr("dy", y + "em");
    for (let b = 0; b < a.length; b++)
      i = a[a.length - 1 - b], o.push(i), m.text(o.join(" ").trim()), (m.node().getComputedTextLength() > t || i === "<br>") && (o.pop(), m.text(o.join(" ").trim()), i === "<br>" ? o = [""] : o = [i], m = e.append("tspan").attr("x", 0).attr("y", p).attr("dy", u + "em").text(i));
  });
}
r(Q, "wrap");
var Dt = /* @__PURE__ */ r(function(n, t, e, a) {
  var i;
  const o = e % Tt - 1, u = n.append("g");
  t.section = o, u.attr(
    "class",
    (t.class ? t.class + " " : "") + "timeline-node " + ("section-" + o)
  );
  const p = u.append("g"), y = u.append("g"), m = y.append("text").text(t.descr).attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle").call(Q, t.width).node().getBBox(), b = (i = a.fontSize) != null && i.replace ? a.fontSize.replace("px", "") : a.fontSize;
  return t.height = m.height + b * 1.1 * 0.5 + t.padding, t.height = Math.max(t.height, t.maxHeight), t.width = t.width + 2 * t.padding, y.attr("transform", "translate(" + t.width / 2 + ", " + t.padding / 2 + ")"), zt(p, t, o, a), t;
}, "drawNode"), Ht = /* @__PURE__ */ r(function(n, t, e) {
  var a;
  const i = n.append("g"), o = i.append("text").text(t.descr).attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle").call(Q, t.width).node().getBBox(), u = (a = e.fontSize) != null && a.replace ? e.fontSize.replace("px", "") : e.fontSize;
  return i.remove(), o.height + u * 1.1 * 0.5 + t.padding;
}, "getVirtualNodeHeight"), zt = /* @__PURE__ */ r(function(n, t, e) {
  n.append("path").attr("id", "node-" + t.id).attr("class", "node-bkg node-" + t.type).attr(
    "d",
    `M0 ${t.height - 5} v${-t.height + 10} q0,-5 5,-5 h${t.width - 10} q5,0 5,5 v${t.height - 5} H0 Z`
  ), n.append("line").attr("class", "node-line-" + e).attr("x1", 0).attr("y1", t.height).attr("x2", t.width).attr("y2", t.height);
}, "defaultBkg"), D = {
  drawRect: Y,
  drawCircle: At,
  drawSection: Ct,
  drawText: gt,
  drawLabel: Nt,
  drawTask: It,
  drawBackgroundRect: Ot,
  getTextObj: Lt,
  getNoteRect: K,
  initGraphics: Rt,
  drawNode: Dt,
  getVirtualNodeHeight: Ht
}, Pt = /* @__PURE__ */ r(function(n, t, e, a) {
  var i, o, u;
  const p = mt(), y = ((i = p.timeline) == null ? void 0 : i.leftMargin) ?? 50;
  $.debug("timeline", a.db);
  const m = p.securityLevel;
  let b;
  m === "sandbox" && (b = V("#i" + t));
  const g = (m === "sandbox" ? V(b.nodes()[0].contentDocument.body) : V("body")).select("#" + t);
  g.append("g");
  const f = a.db.getTasks(), s = a.db.getCommonDb().getDiagramTitle();
  $.debug("task", f), D.initGraphics(g);
  const l = a.db.getSections();
  $.debug("sections", l);
  let h = 0, d = 0, c = 0, k = 0, x = 50 + y, N = 50;
  k = 50;
  let M = 0, F = !0;
  l.forEach(function(S) {
    const v = {
      number: M,
      descr: S,
      section: M,
      width: 150,
      padding: 20,
      maxHeight: h
    }, A = D.getVirtualNodeHeight(g, v, p);
    $.debug("sectionHeight before draw", A), h = Math.max(h, A + 20);
  });
  let I = 0, H = 0;
  $.debug("tasks.length", f.length);
  for (const [S, v] of f.entries()) {
    const A = {
      number: S,
      descr: v,
      section: v.section,
      width: 150,
      padding: 20,
      maxHeight: d
    }, O = D.getVirtualNodeHeight(g, A, p);
    $.debug("taskHeight before draw", O), d = Math.max(d, O + 20), I = Math.max(I, v.events.length);
    let L = 0;
    for (const z of v.events) {
      const w = {
        descr: z,
        section: v.section,
        number: v.section,
        width: 150,
        padding: 20,
        maxHeight: 50
      };
      L += D.getVirtualNodeHeight(g, w, p);
    }
    v.events.length > 0 && (L += (v.events.length - 1) * 10), H = Math.max(H, L);
  }
  $.debug("maxSectionHeight before draw", h), $.debug("maxTaskHeight before draw", d), l && l.length > 0 ? l.forEach((S) => {
    const v = f.filter((z) => z.section === S), A = {
      number: M,
      descr: S,
      section: M,
      width: 200 * Math.max(v.length, 1) - 50,
      padding: 20,
      maxHeight: h
    };
    $.debug("sectionNode", A);
    const O = g.append("g"), L = D.drawNode(O, A, M, p);
    $.debug("sectionNode output", L), O.attr("transform", `translate(${x}, ${k})`), N += h + 50, v.length > 0 && st(
      g,
      v,
      M,
      x,
      N,
      d,
      p,
      I,
      H,
      h,
      !1
    ), x += 200 * Math.max(v.length, 1), N = k, M++;
  }) : (F = !1, st(
    g,
    f,
    M,
    x,
    N,
    d,
    p,
    I,
    H,
    h,
    !0
  ));
  const _ = g.node().getBBox();
  $.debug("bounds", _), s && g.append("text").text(s).attr("x", _.width / 2 - y).attr("font-size", "4ex").attr("font-weight", "bold").attr("y", 20), c = F ? h + d + 150 : d + 100, g.append("g").attr("class", "lineWrapper").append("line").attr("x1", y).attr("y1", c).attr("x2", _.width + 3 * y).attr("y2", c).attr("stroke-width", 4).attr("stroke", "black").attr("marker-end", "url(#arrowhead)"), xt(
    void 0,
    g,
    ((o = p.timeline) == null ? void 0 : o.padding) ?? 50,
    ((u = p.timeline) == null ? void 0 : u.useMaxWidth) ?? !1
  );
}, "draw"), st = /* @__PURE__ */ r(function(n, t, e, a, i, o, u, p, y, m, b) {
  var g;
  for (const f of t) {
    const s = {
      descr: f.task,
      section: e,
      number: e,
      width: 150,
      padding: 20,
      maxHeight: o
    };
    $.debug("taskNode", s);
    const l = n.append("g").attr("class", "taskWrapper"), h = D.drawNode(l, s, e, u).height;
    if ($.debug("taskHeight after draw", h), l.attr("transform", `translate(${a}, ${i})`), o = Math.max(o, h), f.events) {
      const d = n.append("g").attr("class", "lineWrapper");
      let c = o;
      i += 100, c = c + jt(n, f.events, e, a, i, u), i -= 100, d.append("line").attr("x1", a + 190 / 2).attr("y1", i + o).attr("x2", a + 190 / 2).attr("y2", i + o + 100 + y + 100).attr("stroke-width", 2).attr("stroke", "black").attr("marker-end", "url(#arrowhead)").attr("stroke-dasharray", "5,5");
    }
    a = a + 200, b && !((g = u.timeline) != null && g.disableMulticolor) && e++;
  }
  i = i - 10;
}, "drawTasks"), jt = /* @__PURE__ */ r(function(n, t, e, a, i, o) {
  let u = 0;
  const p = i;
  i = i + 100;
  for (const y of t) {
    const m = {
      descr: y,
      section: e,
      number: e,
      width: 150,
      padding: 20,
      maxHeight: 50
    };
    $.debug("eventNode", m);
    const b = n.append("g").attr("class", "eventWrapper"), g = D.drawNode(b, m, e, o).height;
    u = u + g, b.attr("transform", `translate(${a}, ${i})`), i = i + 10 + g;
  }
  return i = p, u;
}, "drawEvents"), Bt = {
  setConf: /* @__PURE__ */ r(() => {
  }, "setConf"),
  draw: Pt
}, Ft = /* @__PURE__ */ r((n) => {
  let t = "";
  for (let e = 0; e < n.THEME_COLOR_LIMIT; e++)
    n["lineColor" + e] = n["lineColor" + e] || n["cScaleInv" + e], bt(n["lineColor" + e]) ? n["lineColor" + e] = kt(n["lineColor" + e], 20) : n["lineColor" + e] = _t(n["lineColor" + e], 20);
  for (let e = 0; e < n.THEME_COLOR_LIMIT; e++) {
    const a = "" + (17 - 3 * e);
    t += `
    .section-${e - 1} rect, .section-${e - 1} path, .section-${e - 1} circle, .section-${e - 1} path  {
      fill: ${n["cScale" + e]};
    }
    .section-${e - 1} text {
     fill: ${n["cScaleLabel" + e]};
    }
    .node-icon-${e - 1} {
      font-size: 40px;
      color: ${n["cScaleLabel" + e]};
    }
    .section-edge-${e - 1}{
      stroke: ${n["cScale" + e]};
    }
    .edge-depth-${e - 1}{
      stroke-width: ${a};
    }
    .section-${e - 1} line {
      stroke: ${n["cScaleInv" + e]} ;
      stroke-width: 3;
    }

    .lineWrapper line{
      stroke: ${n["cScaleLabel" + e]} ;
    }

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