import { _ as h, g as ht, aV as ct, aU as ut, bB as yt, av as dt, ah as pt, ao as et, a9 as gt, aa as ft, a8 as kt, a7 as mt, ap as wt, ab as xt } from "./index-Bh-wTBlD.js";
var V = function() {
  var e = /* @__PURE__ */ h(function(_, t, s, y) {
    for (s = s || {}, y = _.length; y--; s[_[y]] = t) ;
    return s;
  }, "o"), c = [1, 4], n = [1, 14], a = [1, 12], r = [1, 13], u = [6, 7, 8], d = [1, 20], o = [1, 18], g = [1, 19], p = [6, 7, 11], x = [1, 6, 13, 14], m = [1, 23], b = [1, 24], w = [1, 6, 7, 11, 13, 14], D = {
    trace: /* @__PURE__ */ h(function() {
    }, "trace"),
    yy: {},
    symbols_: { error: 2, start: 3, ishikawa: 4, spaceLines: 5, SPACELINE: 6, NL: 7, ISHIKAWA: 8, document: 9, stop: 10, EOF: 11, statement: 12, SPACELIST: 13, TEXT: 14, $accept: 0, $end: 1 },
    terminals_: { 2: "error", 6: "SPACELINE", 7: "NL", 8: "ISHIKAWA", 11: "EOF", 13: "SPACELIST", 14: "TEXT" },
    productions_: [0, [3, 1], [3, 2], [5, 1], [5, 2], [5, 2], [4, 2], [4, 3], [10, 1], [10, 1], [10, 1], [10, 2], [10, 2], [9, 3], [9, 2], [12, 2], [12, 1], [12, 1], [12, 1]],
    performAction: /* @__PURE__ */ h(function(_, t, s, y, l, i, f) {
      var v = i.length - 1;
      switch (l) {
        case 6:
        case 7:
          return y;
        case 15:
          y.addNode(i[v - 1].length, i[v].trim());
          break;
        case 16:
          y.addNode(0, i[v].trim());
          break;
      }
    }, "anonymous"),
    table: [{ 3: 1, 4: 2, 5: 3, 6: [1, 5], 8: c }, { 1: [3] }, { 1: [2, 1] }, { 4: 6, 6: [1, 7], 7: [1, 8], 8: c }, { 6: n, 7: [1, 10], 9: 9, 12: 11, 13: a, 14: r }, e(u, [2, 3]), { 1: [2, 2] }, e(u, [2, 4]), e(u, [2, 5]), { 1: [2, 6], 6: n, 12: 15, 13: a, 14: r }, { 6: n, 9: 16, 12: 11, 13: a, 14: r }, { 6: d, 7: o, 10: 17, 11: g }, e(p, [2, 18], { 14: [1, 21] }), e(p, [2, 16]), e(p, [2, 17]), { 6: d, 7: o, 10: 22, 11: g }, { 1: [2, 7], 6: n, 12: 15, 13: a, 14: r }, e(x, [2, 14], { 7: m, 11: b }), e(w, [2, 8]), e(w, [2, 9]), e(w, [2, 10]), e(p, [2, 15]), e(x, [2, 13], { 7: m, 11: b }), e(w, [2, 11]), e(w, [2, 12])],
    defaultActions: { 2: [2, 1], 6: [2, 2] },
    parseError: /* @__PURE__ */ h(function(_, t) {
      if (t.recoverable)
        this.trace(_);
      else {
        var s = new Error(_);
        throw s.hash = t, s;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ h(function(_) {
      var t = this, s = [0], y = [], l = [null], i = [], f = this.table, v = "", S = 0, T = 0, $ = 2, L = 1, I = i.slice.call(arguments, 1), k = Object.create(this.lexer), N = { yy: {} };
      for (var G in this.yy)
        Object.prototype.hasOwnProperty.call(this.yy, G) && (N.yy[G] = this.yy[G]);
      k.setInput(_, N.yy), N.yy.lexer = k, N.yy.parser = this, typeof k.yylloc > "u" && (k.yylloc = {});
      var C = k.yylloc;
      i.push(C);
      var O = k.options && k.options.ranges;
      typeof N.yy.parseError == "function" ? this.parseError = N.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function z(M) {
        s.length = s.length - 2 * M, l.length = l.length - M, i.length = i.length - M;
      }
      h(z, "popStack");
      function F() {
        var M;
        return M = y.pop() || k.lex() || L, typeof M != "number" && (M instanceof Array && (y = M, M = y.pop()), M = t.symbols_[M] || M), M;
      }
      h(F, "lex");
      for (var E, P, B, X, U = {}, q, R, tt, J; ; ) {
        if (P = s[s.length - 1], this.defaultActions[P] ? B = this.defaultActions[P] : ((E === null || typeof E > "u") && (E = F()), B = f[P] && f[P][E]), typeof B > "u" || !B.length || !B[0]) {
          var H = "";
          J = [];
          for (q in f[P])
            this.terminals_[q] && q > $ && J.push("'" + this.terminals_[q] + "'");
          k.showPosition ? H = "Parse error on line " + (S + 1) + `:
` + k.showPosition() + `
Expecting ` + J.join(", ") + ", got '" + (this.terminals_[E] || E) + "'" : H = "Parse error on line " + (S + 1) + ": Unexpected " + (E == L ? "end of input" : "'" + (this.terminals_[E] || E) + "'"), this.parseError(H, {
            text: k.match,
            token: this.terminals_[E] || E,
            line: k.yylineno,
            loc: C,
            expected: J
          });
        }
        if (B[0] instanceof Array && B.length > 1)
          throw new Error("Parse Error: multiple actions possible at state: " + P + ", token: " + E);
        switch (B[0]) {
          case 1:
            s.push(E), l.push(k.yytext), i.push(k.yylloc), s.push(B[1]), E = null, T = k.yyleng, v = k.yytext, S = k.yylineno, C = k.yylloc;
            break;
          case 2:
            if (R = this.productions_[B[1]][1], U.$ = l[l.length - R], U._$ = {
              first_line: i[i.length - (R || 1)].first_line,
              last_line: i[i.length - 1].last_line,
              first_column: i[i.length - (R || 1)].first_column,
              last_column: i[i.length - 1].last_column
            }, O && (U._$.range = [
              i[i.length - (R || 1)].range[0],
              i[i.length - 1].range[1]
            ]), X = this.performAction.apply(U, [
              v,
              T,
              S,
              N.yy,
              B[1],
              l,
              i
            ].concat(I)), typeof X < "u")
              return X;
            R && (s = s.slice(0, -1 * R * 2), l = l.slice(0, -1 * R), i = i.slice(0, -1 * R)), s.push(this.productions_[B[1]][0]), l.push(U.$), i.push(U._$), tt = f[s[s.length - 2]][s[s.length - 1]], s.push(tt);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  }, j = /* @__PURE__ */ function() {
    var _ = {
      EOF: 1,
      parseError: /* @__PURE__ */ h(function(t, s) {
        if (this.yy.parser)
          this.yy.parser.parseError(t, s);
        else
          throw new Error(t);
      }, "parseError"),
      // resets the lexer, sets new input
      setInput: /* @__PURE__ */ h(function(t, s) {
        return this.yy = s || this.yy || {}, this._input = t, this._more = this._backtrack = this.done = !1, this.yylineno = this.yyleng = 0, this.yytext = this.matched = this.match = "", this.conditionStack = ["INITIAL"], this.yylloc = {
          first_line: 1,
          first_column: 0,
          last_line: 1,
          last_column: 0
        }, this.options.ranges && (this.yylloc.range = [0, 0]), this.offset = 0, this;
      }, "setInput"),
      // consumes and returns one char from the input
      input: /* @__PURE__ */ h(function() {
        var t = this._input[0];
        this.yytext += t, this.yyleng++, this.offset++, this.match += t, this.matched += t;
        var s = t.match(/(?:\r\n?|\n).*/g);
        return s ? (this.yylineno++, this.yylloc.last_line++) : this.yylloc.last_column++, this.options.ranges && this.yylloc.range[1]++, this._input = this._input.slice(1), t;
      }, "input"),
      // unshifts one char (or a string) into the input
      unput: /* @__PURE__ */ h(function(t) {
        var s = t.length, y = t.split(/(?:\r\n?|\n)/g);
        this._input = t + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - s), this.offset -= s;
        var l = 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), y.length - 1 && (this.yylineno -= y.length - 1);
        var i = 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: y ? (y.length === l.length ? this.yylloc.first_column : 0) + l[l.length - y.length].length - y[0].length : this.yylloc.first_column - s
        }, this.options.ranges && (this.yylloc.range = [i[0], i[0] + this.yyleng - s]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      // When called from action, caches matched text and appends it on next action
      more: /* @__PURE__ */ h(function() {
        return this._more = !0, this;
      }, "more"),
      // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
      reject: /* @__PURE__ */ h(function() {
        if (this.options.backtrack_lexer)
          this._backtrack = !0;
        else
          return this.parseError("Lexical error on line " + (this.yylineno + 1) + `. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
` + this.showPosition(), {
            text: "",
            token: null,
            line: this.yylineno
          });
        return this;
      }, "reject"),
      // retain first n characters of the match
      less: /* @__PURE__ */ h(function(t) {
        this.unput(this.match.slice(t));
      }, "less"),
      // displays already matched input, i.e. for error messages
      pastInput: /* @__PURE__ */ h(function() {
        var t = this.matched.substr(0, this.matched.length - this.match.length);
        return (t.length > 20 ? "..." : "") + t.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      // displays upcoming input, i.e. for error messages
      upcomingInput: /* @__PURE__ */ h(function() {
        var t = this.match;
        return t.length < 20 && (t += this._input.substr(0, 20 - t.length)), (t.substr(0, 20) + (t.length > 20 ? "..." : "")).replace(/\n/g, "");
      }, "upcomingInput"),
      // displays the character position where the lexing error occurred, i.e. for error messages
      showPosition: /* @__PURE__ */ h(function() {
        var t = this.pastInput(), s = new Array(t.length + 1).join("-");
        return t + this.upcomingInput() + `
` + s + "^";
      }, "showPosition"),
      // test the lexed token: return FALSE when not a match, otherwise return token
      test_match: /* @__PURE__ */ h(function(t, s) {
        var y, l, i;
        if (this.options.backtrack_lexer && (i = {
          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 && (i.yylloc.range = this.yylloc.range.slice(0))), l = t[0].match(/(?:\r\n?|\n).*/g), l && (this.yylineno += l.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: l ? l[l.length - 1].length - l[l.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + t[0].length
        }, this.yytext += t[0], this.match += t[0], this.matches = t, this.yyleng = this.yytext.length, this.options.ranges && (this.yylloc.range = [this.offset, this.offset += this.yyleng]), this._more = !1, this._backtrack = !1, this._input = this._input.slice(t[0].length), this.matched += t[0], y = this.performAction.call(this, this.yy, this, s, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), y)
          return y;
        if (this._backtrack) {
          for (var f in i)
            this[f] = i[f];
          return !1;
        }
        return !1;
      }, "test_match"),
      // return next match in input
      next: /* @__PURE__ */ h(function() {
        if (this.done)
          return this.EOF;
        this._input || (this.done = !0);
        var t, s, y, l;
        this._more || (this.yytext = "", this.match = "");
        for (var i = this._currentRules(), f = 0; f < i.length; f++)
          if (y = this._input.match(this.rules[i[f]]), y && (!s || y[0].length > s[0].length)) {
            if (s = y, l = f, this.options.backtrack_lexer) {
              if (t = this.test_match(y, i[f]), t !== !1)
                return t;
              if (this._backtrack) {
                s = !1;
                continue;
              } else
                return !1;
            } else if (!this.options.flex)
              break;
          }
        return s ? (t = this.test_match(s, i[l]), t !== !1 ? t : !1) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      // return next match that has a token
      lex: /* @__PURE__ */ h(function() {
        var t = this.next();
        return t || this.lex();
      }, "lex"),
      // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
      begin: /* @__PURE__ */ h(function(t) {
        this.conditionStack.push(t);
      }, "begin"),
      // pop the previously active lexer condition state off the condition stack
      popState: /* @__PURE__ */ h(function() {
        var t = this.conditionStack.length - 1;
        return t > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      // produce the lexer rule set which is active for the currently active lexer condition state
      _currentRules: /* @__PURE__ */ h(function() {
        return this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1] ? this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules : this.conditions.INITIAL.rules;
      }, "_currentRules"),
      // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
      topState: /* @__PURE__ */ h(function(t) {
        return t = this.conditionStack.length - 1 - Math.abs(t || 0), t >= 0 ? this.conditionStack[t] : "INITIAL";
      }, "topState"),
      // alias for begin(condition)
      pushState: /* @__PURE__ */ h(function(t) {
        this.begin(t);
      }, "pushState"),
      // return the number of states currently on the stack
      stateStackSize: /* @__PURE__ */ h(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ h(function(t, s, y, l) {
        switch (y) {
          case 0:
            return 6;
          case 1:
            return 8;
          case 2:
            return 8;
          case 3:
            return 6;
          case 4:
            return 7;
          case 5:
            return 13;
          case 6:
            return 14;
          case 7:
            return 11;
        }
      }, "anonymous"),
      rules: [/^(?:\s*%%.*)/i, /^(?:ishikawa-beta\b)/i, /^(?:ishikawa\b)/i, /^(?:[\s]+[\n])/i, /^(?:[\n]+)/i, /^(?:[\s]+)/i, /^(?:[^\n]+)/i, /^(?:$)/i],
      conditions: { INITIAL: { rules: [0, 1, 2, 3, 4, 5, 6, 7], inclusive: !0 } }
    };
    return _;
  }();
  D.lexer = j;
  function A() {
    this.yy = {};
  }
  return h(A, "Parser"), A.prototype = D, D.Parser = A, new A();
}();
V.parser = V;
var _t = V, Q, bt = (Q = class {
  constructor() {
    this.stack = [], this.clear = this.clear.bind(this), this.addNode = this.addNode.bind(this), this.getRoot = this.getRoot.bind(this);
  }
  clear() {
    this.root = void 0, this.stack = [], this.baseLevel = void 0, dt();
  }
  getRoot() {
    return this.root;
  }
  addNode(e, c) {
    const n = pt.sanitizeText(c, ht());
    if (!this.root) {
      this.root = { text: n, children: [] }, this.stack = [{ level: 0, node: this.root }], et(n);
      return;
    }
    this.baseLevel ?? (this.baseLevel = e);
    let a = e - this.baseLevel + 1;
    for (a <= 0 && (a = 1); this.stack.length > 1 && this.stack[this.stack.length - 1].level >= a; )
      this.stack.pop();
    const r = this.stack[this.stack.length - 1].node, u = { text: n, children: [] };
    r.children.push(u), this.stack.push({ level: a, node: u });
  }
  getAccTitle() {
    return gt();
  }
  setAccTitle(e) {
    ft(e);
  }
  getAccDescription() {
    return kt();
  }
  setAccDescription(e) {
    mt(e);
  }
  getDiagramTitle() {
    return wt();
  }
  setDiagramTitle(e) {
    et(e);
  }
}, h(Q, "IshikawaDB"), Q), vt = 14, W = 250, St = 30, $t = 60, It = 5, lt = 82 * Math.PI / 180, it = Math.cos(lt), st = Math.sin(lt), nt = /* @__PURE__ */ h((e, c, n) => {
  const a = e.node().getBBox(), r = a.width + c * 2, u = a.height + c * 2;
  xt(e, u, r, n), e.attr("viewBox", `${a.x - c} ${a.y - c} ${r} ${u}`);
}, "applyPaddedViewBox"), Et = /* @__PURE__ */ h((e, c, n, a) => {
  var r, u;
  const d = a.db.getRoot();
  if (!d)
    return;
  const o = ht(), { look: g, handDrawnSeed: p, themeVariables: x } = o, m = ct(o.fontSize)[0] ?? vt, b = g === "handDrawn", w = d.children ?? [], D = ((r = o.ishikawa) == null ? void 0 : r.diagramPadding) ?? 20, j = ((u = o.ishikawa) == null ? void 0 : u.useMaxWidth) ?? !1, A = ut(c), _ = A.append("g").attr("class", "ishikawa"), t = b ? yt.svg(A.node()) : void 0, s = t ? {
    roughSvg: t,
    seed: p ?? 0,
    lineColor: (x == null ? void 0 : x.lineColor) ?? "#333",
    fillColor: (x == null ? void 0 : x.mainBkg) ?? "#fff"
  } : void 0, y = `ishikawa-arrow-${c}`;
  b || _.append("defs").append("marker").attr("id", y).attr("viewBox", "0 0 10 10").attr("refX", 0).attr("refY", 5).attr("markerWidth", 6).attr("markerHeight", 6).attr("orient", "auto").append("path").attr("d", "M 10 0 L 0 5 L 10 10 Z").attr("class", "ishikawa-arrow");
  let l = 0, i = W;
  const f = b ? void 0 : Z(_, l, i, l, i, "ishikawa-spine");
  if (Ct(_, l, i, d.text, m, s), !w.length) {
    b && Z(_, l, i, l, i, "ishikawa-spine", s), nt(A, D, j);
    return;
  }
  l -= 20;
  const v = w.filter((C, O) => O % 2 === 0), S = w.filter((C, O) => O % 2 === 1), T = at(v), $ = at(S), L = T.total + $.total;
  let I = W, k = W;
  if (L > 0) {
    const C = W * 2, O = W * 0.3;
    I = Math.max(O, C * (T.total / L)), k = Math.max(O, C * ($.total / L));
  }
  const N = m * 2;
  I = Math.max(I, T.max * N), k = Math.max(k, $.max * N), i = Math.max(I, W), f && f.attr("y1", i).attr("y2", i), _.select(".ishikawa-head-group").attr("transform", `translate(0,${i})`);
  const G = Math.ceil(w.length / 2);
  for (let C = 0; C < G; C++) {
    const O = _.append("g").attr("class", "ishikawa-pair");
    for (const [z, F, E] of [
      [w[C * 2], -1, I],
      [w[C * 2 + 1], 1, k]
    ])
      z && Mt(O, z, l, i, F, E, m, s);
    l = O.selectAll("text").nodes().reduce((z, F) => Math.min(z, F.getBBox().x), 1 / 0);
  }
  if (b)
    Z(_, l, i, 0, i, "ishikawa-spine", s);
  else {
    f.attr("x1", l);
    const C = `url(#${y})`;
    _.selectAll("line.ishikawa-branch, line.ishikawa-sub-branch").attr("marker-start", C);
  }
  nt(A, D, j);
}, "draw"), at = /* @__PURE__ */ h((e) => {
  const c = /* @__PURE__ */ h((n) => n.children.reduce((a, r) => a + 1 + c(r), 0), "countDescendants");
  return e.reduce(
    (n, a) => {
      const r = c(a);
      return n.total += r, n.max = Math.max(n.max, r), n;
    },
    { total: 0, max: 0 }
  );
}, "sideStats"), Ct = /* @__PURE__ */ h((e, c, n, a, r, u) => {
  const d = Math.max(6, Math.floor(110 / (r * 0.6))), o = e.append("g").attr("class", "ishikawa-head-group").attr("transform", `translate(${c},${n})`), g = K(
    o,
    ot(a, d),
    0,
    0,
    "ishikawa-head-label",
    "start",
    r
  ), p = g.node().getBBox(), x = Math.max(60, p.width + 6), m = Math.max(40, p.height * 2 + 40), b = `M 0 ${-m / 2} L 0 ${m / 2} Q ${x * 2.4} 0 0 ${-m / 2} Z`;
  if (u) {
    const w = u.roughSvg.path(b, {
      roughness: 1.5,
      seed: u.seed,
      fill: u.fillColor,
      fillStyle: "hachure",
      fillWeight: 2.5,
      hachureGap: 5,
      stroke: u.lineColor,
      strokeWidth: 2
    });
    o.insert(() => w, ":first-child").attr("class", "ishikawa-head");
  } else
    o.insert("path", ":first-child").attr("class", "ishikawa-head").attr("d", b);
  g.attr("transform", `translate(${(x - p.width) / 2 - p.x + 3},${-p.y - p.height / 2})`);
}, "drawHead"), Lt = /* @__PURE__ */ h((e, c) => {
  const n = [], a = [], r = /* @__PURE__ */ h((u, d, o) => {
    const g = c === -1 ? [...u].reverse() : u;
    for (const p of g) {
      const x = n.length, m = p.children ?? [];
      n.push({
        depth: o,
        text: ot(p.text, 15),
        parentIndex: d,
        childCount: m.length
      }), o % 2 === 0 ? (a.push(x), m.length && r(m, x, o + 1)) : (m.length && r(m, x, o + 1), a.push(x));
    }
  }, "walk");
  return r(e, -1, 2), { entries: n, yOrder: a };
}, "flattenTree"), Tt = /* @__PURE__ */ h((e, c, n, a, r, u, d) => {
  const o = e.append("g").attr("class", "ishikawa-label-group"), g = K(
    o,
    c,
    n,
    a + 11 * r,
    "ishikawa-label cause",
    "middle",
    u
  ).node().getBBox();
  if (d) {
    const p = d.roughSvg.rectangle(
      g.x - 20,
      g.y - 2,
      g.width + 40,
      g.height + 4,
      {
        roughness: 1.5,
        seed: d.seed,
        fill: d.fillColor,
        fillStyle: "hachure",
        fillWeight: 2.5,
        hachureGap: 5,
        stroke: d.lineColor,
        strokeWidth: 2
      }
    );
    o.insert(() => p, ":first-child").attr("class", "ishikawa-label-box");
  } else
    o.insert("rect", ":first-child").attr("class", "ishikawa-label-box").attr("x", g.x - 20).attr("y", g.y - 2).attr("width", g.width + 40).attr("height", g.height + 4);
}, "drawCauseLabel"), Y = /* @__PURE__ */ h((e, c, n, a, r, u) => {
  const d = Math.sqrt(a * a + r * r);
  if (d === 0)
    return;
  const o = a / d, g = r / d, p = 6, x = -g * p, m = o * p, b = c, w = n, D = `M ${b} ${w} L ${b - o * p * 2 + x} ${w - g * p * 2 + m} L ${b - o * p * 2 - x} ${w - g * p * 2 - m} Z`, j = u.roughSvg.path(D, {
    roughness: 1,
    seed: u.seed,
    fill: u.lineColor,
    fillStyle: "solid",
    stroke: u.lineColor,
    strokeWidth: 1
  });
  e.append(() => j);
}, "drawArrowMarker"), Mt = /* @__PURE__ */ h((e, c, n, a, r, u, d, o) => {
  const g = c.children ?? [], p = u * (g.length ? 1 : 0.2), x = -it * p, m = st * p * r, b = n + x, w = a + m;
  if (Z(e, n, a, b, w, "ishikawa-branch", o), o && Y(e, n, a, n - b, a - w, o), Tt(e, c.text, b, w, r, d, o), !g.length)
    return;
  const { entries: D, yOrder: j } = Lt(g, r), A = D.length, _ = new Array(A);
  for (const [i, f] of j.entries())
    _[f] = a + m * ((i + 1) / (A + 1));
  const t = /* @__PURE__ */ new Map();
  t.set(-1, {
    x0: n,
    y0: a,
    x1: b,
    y1: w,
    childCount: g.length,
    childrenDrawn: 0
  });
  const s = -it, y = st * r, l = r < 0 ? "ishikawa-label up" : "ishikawa-label down";
  for (const [i, f] of D.entries()) {
    const v = _[i], S = t.get(f.parentIndex), T = e.append("g").attr("class", "ishikawa-sub-group");
    let $ = 0, L = 0, I = 0;
    if (f.depth % 2 === 0) {
      const k = S.y1 - S.y0;
      $ = rt(S.x0, S.x1, k ? (v - S.y0) / k : 0.5), L = v, I = $ - (f.childCount > 0 ? $t + f.childCount * It : St), Z(T, $, v, I, v, "ishikawa-sub-branch", o), o && Y(T, $, v, 1, 0, o), K(T, f.text, I, v, "ishikawa-label align", "end", d);
    } else {
      const k = S.childrenDrawn++;
      $ = rt(S.x0, S.x1, (S.childCount - k) / (S.childCount + 1)), L = S.y0, I = $ + s * ((v - L) / y), Z(T, $, L, I, v, "ishikawa-sub-branch", o), o && Y(T, $, L, $ - I, L - v, o), K(T, f.text, I, v, l, "end", d);
    }
    f.childCount > 0 && t.set(i, {
      x0: $,
      y0: L,
      x1: I,
      y1: v,
      childCount: f.childCount,
      childrenDrawn: 0
    });
  }
}, "drawBranch"), At = /* @__PURE__ */ h((e) => e.split(/<br\s*\/?>|\n/), "splitLines"), ot = /* @__PURE__ */ h((e, c) => {
  if (e.length <= c)
    return e;
  const n = [];
  for (const a of e.split(/\s+/)) {
    const r = n.length - 1;
    r >= 0 && n[r].length + 1 + a.length <= c ? n[r] += " " + a : n.push(a);
  }
  return n.join(`
`);
}, "wrapText"), K = /* @__PURE__ */ h((e, c, n, a, r, u, d) => {
  const o = At(c), g = d * 1.05, p = e.append("text").attr("class", r).attr("text-anchor", u).attr("x", n).attr("y", a - (o.length - 1) * g / 2);
  for (const [x, m] of o.entries())
    p.append("tspan").attr("x", n).attr("dy", x === 0 ? 0 : g).text(m);
  return p;
}, "drawMultilineText"), rt = /* @__PURE__ */ h((e, c, n) => e + (c - e) * n, "lerp"), Z = /* @__PURE__ */ h((e, c, n, a, r, u, d) => {
  if (d) {
    const o = d.roughSvg.line(c, n, a, r, {
      roughness: 1.5,
      seed: d.seed,
      stroke: d.lineColor,
      strokeWidth: 2
    });
    e.append(() => o).attr("class", u);
    return;
  }
  return e.append("line").attr("class", u).attr("x1", c).attr("y1", n).attr("x2", a).attr("y2", r);
}, "drawLine"), Bt = { draw: Et }, Dt = /* @__PURE__ */ h((e) => `
.ishikawa .ishikawa-spine,
.ishikawa .ishikawa-branch,
.ishikawa .ishikawa-sub-branch {
  stroke: ${e.lineColor};
  stroke-width: 2;
  fill: none;
}

.ishikawa .ishikawa-sub-branch {
  stroke-width: 1;
}

.ishikawa .ishikawa-arrow {
  fill: ${e.lineColor};
}

.ishikawa .ishikawa-head {
  fill: ${e.mainBkg};
  stroke: ${e.lineColor};
  stroke-width: 2;
}

.ishikawa .ishikawa-label-box {
  fill: ${e.mainBkg};
  stroke: ${e.lineColor};
  stroke-width: 2;
}

.ishikawa text {
  font-family: ${e.fontFamily};
  font-size: ${e.fontSize};
  fill: ${e.textColor};
}

.ishikawa .ishikawa-head-label {
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  font-size: 14px;
}

.ishikawa .ishikawa-label {
  text-anchor: end;
}

.ishikawa .ishikawa-label.cause {
  text-anchor: middle;
  dominant-baseline: middle;
}

.ishikawa .ishikawa-label.align {
  text-anchor: end;
  dominant-baseline: middle;
}

.ishikawa .ishikawa-label.up {
  dominant-baseline: baseline;
}

.ishikawa .ishikawa-label.down {
  dominant-baseline: hanging;
}
`, "getStyles"), Ot = Dt, Rt = {
  parser: _t,
  get db() {
    return new bt();
  },
  renderer: Bt,
  styles: Ot
};
export {
  Rt as diagram
};
