import { p as r, Z as ht, a1 as ut, a0 as dt, ba as yt, H as pt, a as ft, f as it, W as gt, U as mt, K as kt, G as xt, i as wt, A as bt } from "./index-CNUFa5l3.js";
var Q = function() {
  var e = /* @__PURE__ */ r(function(t, y, n, h) {
    for (n || (n = {}), h = t.length; h--; n[t[h]] = y) ;
    return n;
  }, "o"), l = [1, 4], a = [1, 14], s = [1, 12], i = [1, 13], d = [
    6,
    7,
    8
  ], f = [1, 20], u = [1, 18], p = [1, 19], g = [
    6,
    7,
    11
  ], x = [
    1,
    6,
    13,
    14
  ], m = [1, 23], S = [1, 24], $ = [
    1,
    6,
    7,
    11,
    13,
    14
  ], L = {
    trace: /* @__PURE__ */ r(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__ */ r(function(t, y, n, h, c, o, P) {
      var b = o.length - 1;
      switch (c) {
        case 6:
        case 7:
          return h;
        case 15:
          h.addNode(o[b - 1].length, o[b].trim());
          break;
        case 16:
          h.addNode(0, o[b].trim());
          break;
      }
    }, "anonymous"),
    table: [
      {
        3: 1,
        4: 2,
        5: 3,
        6: [1, 5],
        8: l
      },
      { 1: [3] },
      { 1: [2, 1] },
      {
        4: 6,
        6: [1, 7],
        7: [1, 8],
        8: l
      },
      {
        6: a,
        7: [1, 10],
        9: 9,
        12: 11,
        13: s,
        14: i
      },
      e(d, [2, 3]),
      { 1: [2, 2] },
      e(d, [2, 4]),
      e(d, [2, 5]),
      {
        1: [2, 6],
        6: a,
        12: 15,
        13: s,
        14: i
      },
      {
        6: a,
        9: 16,
        12: 11,
        13: s,
        14: i
      },
      {
        6: f,
        7: u,
        10: 17,
        11: p
      },
      e(g, [2, 18], { 14: [1, 21] }),
      e(g, [2, 16]),
      e(g, [2, 17]),
      {
        6: f,
        7: u,
        10: 22,
        11: p
      },
      {
        1: [2, 7],
        6: a,
        12: 15,
        13: s,
        14: i
      },
      e(x, [2, 14], {
        7: m,
        11: S
      }),
      e($, [2, 8]),
      e($, [2, 9]),
      e($, [2, 10]),
      e(g, [2, 15]),
      e(x, [2, 13], {
        7: m,
        11: S
      }),
      e($, [2, 11]),
      e($, [2, 12])
    ],
    defaultActions: {
      2: [2, 1],
      6: [2, 2]
    },
    parseError: /* @__PURE__ */ r(function(t, y) {
      if (y.recoverable) this.trace(t);
      else {
        var n = Error(t);
        throw n.hash = y, n;
      }
    }, "parseError"),
    parse: /* @__PURE__ */ r(function(t) {
      var y = this, n = [0], h = [], c = [null], o = [], P = this.table, b = "", w = 0, _ = 0, B = 0, v = 2, A = 1, M = o.slice.call(arguments, 1), k = Object.create(this.lexer), z = { yy: {} };
      for (var j in this.yy) Object.prototype.hasOwnProperty.call(this.yy, j) && (z.yy[j] = this.yy[j]);
      k.setInput(t, z.yy), z.yy.lexer = k, z.yy.parser = this, k.yylloc === void 0 && (k.yylloc = {});
      var E = k.yylloc;
      o.push(E);
      var O = k.options && k.options.ranges;
      typeof z.yy.parseError == "function" ? this.parseError = z.yy.parseError : this.parseError = Object.getPrototypeOf(this).parseError;
      function D(W) {
        n.length -= 2 * W, c.length -= W, o.length -= W;
      }
      r(D, "popStack");
      function F() {
        var W = h.pop() || k.lex() || A;
        return typeof W != "number" && (W instanceof Array && (h = W, W = h.pop()), W = y.symbols_[W] || W), W;
      }
      r(F, "lex");
      for (var C, q, T, N, Y, H = {}, U, R, tt, V; ; ) {
        if (T = n[n.length - 1], this.defaultActions[T] ? N = this.defaultActions[T] : (C ?? (C = F()), N = P[T] && P[T][C]), N === void 0 || !N.length || !N[0]) {
          var et = "";
          for (U in V = [], P[T]) this.terminals_[U] && U > v && V.push("'" + this.terminals_[U] + "'");
          et = k.showPosition ? "Parse error on line " + (w + 1) + `:
` + k.showPosition() + `
Expecting ` + V.join(", ") + ", got '" + (this.terminals_[C] || C) + "'" : "Parse error on line " + (w + 1) + ": Unexpected " + (C == A ? "end of input" : "'" + (this.terminals_[C] || C) + "'"), this.parseError(et, {
            text: k.match,
            token: this.terminals_[C] || C,
            line: k.yylineno,
            loc: E,
            expected: V
          });
        }
        if (N[0] instanceof Array && N.length > 1) throw Error("Parse Error: multiple actions possible at state: " + T + ", token: " + C);
        switch (N[0]) {
          case 1:
            n.push(C), c.push(k.yytext), o.push(k.yylloc), n.push(N[1]), C = null, q ? (C = q, q = null) : (_ = k.yyleng, b = k.yytext, w = k.yylineno, E = k.yylloc, B > 0);
            break;
          case 2:
            if (R = this.productions_[N[1]][1], H.$ = c[c.length - R], H._$ = {
              first_line: o[o.length - (R || 1)].first_line,
              last_line: o[o.length - 1].last_line,
              first_column: o[o.length - (R || 1)].first_column,
              last_column: o[o.length - 1].last_column
            }, O && (H._$.range = [o[o.length - (R || 1)].range[0], o[o.length - 1].range[1]]), Y = this.performAction.apply(H, [
              b,
              _,
              w,
              z.yy,
              N[1],
              c,
              o
            ].concat(M)), Y !== void 0) return Y;
            R && (n = n.slice(0, -1 * R * 2), c = c.slice(0, -1 * R), o = o.slice(0, -1 * R)), n.push(this.productions_[N[1]][0]), c.push(H.$), o.push(H._$), tt = P[n[n.length - 2]][n[n.length - 1]], n.push(tt);
            break;
          case 3:
            return !0;
        }
      }
      return !0;
    }, "parse")
  };
  L.lexer = /* @__PURE__ */ function() {
    return {
      EOF: 1,
      parseError: /* @__PURE__ */ r(function(t, y) {
        if (this.yy.parser) this.yy.parser.parseError(t, y);
        else throw Error(t);
      }, "parseError"),
      setInput: /* @__PURE__ */ r(function(t, y) {
        return this.yy = y || 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"),
      input: /* @__PURE__ */ r(function() {
        var t = this._input[0];
        return this.yytext += t, this.yyleng++, this.offset++, this.match += t, this.matched += t, t.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), t;
      }, "input"),
      unput: /* @__PURE__ */ r(function(t) {
        var y = t.length, n = t.split(/(?:\r\n?|\n)/g);
        this._input = t + this._input, this.yytext = this.yytext.substr(0, this.yytext.length - y), this.offset -= y;
        var h = 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), n.length - 1 && (this.yylineno -= n.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: n ? (n.length === h.length ? this.yylloc.first_column : 0) + h[h.length - n.length].length - n[0].length : this.yylloc.first_column - y
        }, this.options.ranges && (this.yylloc.range = [c[0], c[0] + this.yyleng - y]), this.yyleng = this.yytext.length, this;
      }, "unput"),
      more: /* @__PURE__ */ r(function() {
        return this._more = !0, this;
      }, "more"),
      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"),
      less: /* @__PURE__ */ r(function(t) {
        this.unput(this.match.slice(t));
      }, "less"),
      pastInput: /* @__PURE__ */ r(function() {
        var t = this.matched.substr(0, this.matched.length - this.match.length);
        return (t.length > 20 ? "..." : "") + t.substr(-20).replace(/\n/g, "");
      }, "pastInput"),
      upcomingInput: /* @__PURE__ */ r(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"),
      showPosition: /* @__PURE__ */ r(function() {
        var t = this.pastInput(), y = Array(t.length + 1).join("-");
        return t + this.upcomingInput() + `
` + y + "^";
      }, "showPosition"),
      test_match: /* @__PURE__ */ r(function(t, y) {
        var n, h, 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))), h = t[0].match(/(?:\r\n?|\n).*/g), h && (this.yylineno += h.length), this.yylloc = {
          first_line: this.yylloc.last_line,
          last_line: this.yylineno + 1,
          first_column: this.yylloc.last_column,
          last_column: h ? h[h.length - 1].length - h[h.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], n = this.performAction.call(this, this.yy, this, y, this.conditionStack[this.conditionStack.length - 1]), this.done && this._input && (this.done = !1), n) return n;
        if (this._backtrack) {
          for (var o in c) this[o] = c[o];
          return !1;
        }
        return !1;
      }, "test_match"),
      next: /* @__PURE__ */ r(function() {
        if (this.done) return this.EOF;
        this._input || (this.done = !0);
        var t, y, n, h;
        this._more || (this.yytext = "", this.match = "");
        for (var c = this._currentRules(), o = 0; o < c.length; o++) if (n = this._input.match(this.rules[c[o]]), n && (!y || n[0].length > y[0].length)) {
          if (y = n, h = o, this.options.backtrack_lexer) {
            if (t = this.test_match(n, c[o]), t !== !1) return t;
            if (this._backtrack) {
              y = !1;
              continue;
            } else return !1;
          } else if (!this.options.flex) break;
        }
        return y ? (t = this.test_match(y, c[h]), t === !1 ? !1 : t) : this._input === "" ? this.EOF : this.parseError("Lexical error on line " + (this.yylineno + 1) + `. Unrecognized text.
` + this.showPosition(), {
          text: "",
          token: null,
          line: this.yylineno
        });
      }, "next"),
      lex: /* @__PURE__ */ r(function() {
        return this.next() || this.lex();
      }, "lex"),
      begin: /* @__PURE__ */ r(function(t) {
        this.conditionStack.push(t);
      }, "begin"),
      popState: /* @__PURE__ */ r(function() {
        return this.conditionStack.length - 1 > 0 ? this.conditionStack.pop() : this.conditionStack[0];
      }, "popState"),
      _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"),
      topState: /* @__PURE__ */ r(function(t) {
        return t = this.conditionStack.length - 1 - Math.abs(t || 0), t >= 0 ? this.conditionStack[t] : "INITIAL";
      }, "topState"),
      pushState: /* @__PURE__ */ r(function(t) {
        this.begin(t);
      }, "pushState"),
      stateStackSize: /* @__PURE__ */ r(function() {
        return this.conditionStack.length;
      }, "stateStackSize"),
      options: { "case-insensitive": !0 },
      performAction: /* @__PURE__ */ r(function(t, y, n, h) {
        switch (n) {
          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
      } }
    };
  }();
  function I() {
    this.yy = {};
  }
  return r(I, "Parser"), I.prototype = L, L.Parser = I, new I();
}();
Q.parser = Q;
var _t = Q, K, vt = (K = 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, pt();
  }
  getRoot() {
    return this.root;
  }
  addNode(l, a) {
    let s = ft.sanitizeText(a, ht());
    if (!this.root) {
      this.root = {
        text: s,
        children: []
      }, this.stack = [{
        level: 0,
        node: this.root
      }], it(s);
      return;
    }
    this.baseLevel ?? (this.baseLevel = l);
    let i = l - this.baseLevel + 1;
    for (i <= 0 && (i = 1); this.stack.length > 1 && this.stack[this.stack.length - 1].level >= i; ) this.stack.pop();
    let d = this.stack[this.stack.length - 1].node, f = {
      text: s,
      children: []
    };
    d.children.push(f), this.stack.push({
      level: i,
      node: f
    });
  }
  getAccTitle() {
    return gt();
  }
  setAccTitle(l) {
    mt(l);
  }
  getAccDescription() {
    return kt();
  }
  setAccDescription(l) {
    xt(l);
  }
  getDiagramTitle() {
    return wt();
  }
  setDiagramTitle(l) {
    it(l);
  }
}, r(K, "IshikawaDB"), K), St = 14, Z = 250, $t = 30, It = 60, At = 5, ot = 82 * Math.PI / 180, st = Math.cos(ot), nt = Math.sin(ot), at = /* @__PURE__ */ r((e, l, a) => {
  let s = e.node().getBBox(), i = s.width + l * 2, d = s.height + l * 2;
  bt(e, d, i, a), e.attr("viewBox", `${s.x - l} ${s.y - l} ${i} ${d}`);
}, "applyPaddedViewBox"), Et = /* @__PURE__ */ r((e, l, a, s) => {
  var z, j;
  let i = s.db.getRoot();
  if (!i) return;
  let d = ht(), { look: f, handDrawnSeed: u, themeVariables: p } = d, g = ut(d.fontSize)[0] ?? St, x = f === "handDrawn", m = i.children ?? [], S = ((z = d.ishikawa) == null ? void 0 : z.diagramPadding) ?? 20, $ = ((j = d.ishikawa) == null ? void 0 : j.useMaxWidth) ?? !1, L = dt(l), I = L.append("g").attr("class", "ishikawa"), t = x ? yt.svg(L.node()) : void 0, y = t ? {
    roughSvg: t,
    seed: u ?? 0,
    lineColor: (p == null ? void 0 : p.lineColor) ?? "#333",
    fillColor: (p == null ? void 0 : p.mainBkg) ?? "#fff"
  } : void 0, n = `ishikawa-arrow-${l}`;
  x || I.append("defs").append("marker").attr("id", n).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 h = 0, c = Z, o = x ? void 0 : G(I, h, c, h, c, "ishikawa-spine");
  if (Ct(I, h, c, i.text, g, y), !m.length) {
    x && G(I, h, c, h, c, "ishikawa-spine", y), at(L, S, $);
    return;
  }
  h -= 20;
  let P = m.filter((E, O) => O % 2 == 0), b = m.filter((E, O) => O % 2 == 1), w = rt(P), _ = rt(b), B = w.total + _.total, v = Z, A = Z;
  if (B > 0) {
    let E = Z * 2, O = Z * 0.3;
    v = Math.max(O, E * (w.total / B)), A = Math.max(O, E * (_.total / B));
  }
  let M = g * 2;
  v = Math.max(v, w.max * M), A = Math.max(A, _.max * M), c = Math.max(v, Z), o && o.attr("y1", c).attr("y2", c), I.select(".ishikawa-head-group").attr("transform", `translate(0,${c})`);
  let k = Math.ceil(m.length / 2);
  for (let E = 0; E < k; E++) {
    let O = I.append("g").attr("class", "ishikawa-pair");
    for (let [D, F, C] of [[
      m[E * 2],
      -1,
      v
    ], [
      m[E * 2 + 1],
      1,
      A
    ]]) D && Pt(O, D, h, c, F, C, g, y);
    h = O.selectAll("text").nodes().reduce((D, F) => Math.min(D, F.getBBox().x), 1 / 0);
  }
  if (x) G(I, h, c, 0, c, "ishikawa-spine", y);
  else {
    o.attr("x1", h);
    let E = `url(#${n})`;
    I.selectAll("line.ishikawa-branch, line.ishikawa-sub-branch").attr("marker-start", E);
  }
  at(L, S, $);
}, "draw"), rt = /* @__PURE__ */ r((e) => {
  let l = /* @__PURE__ */ r((a) => a.children.reduce((s, i) => s + 1 + l(i), 0), "countDescendants");
  return e.reduce((a, s) => {
    let i = l(s);
    return a.total += i, a.max = Math.max(a.max, i), a;
  }, {
    total: 0,
    max: 0
  });
}, "sideStats"), Ct = /* @__PURE__ */ r((e, l, a, s, i, d) => {
  let f = Math.max(6, Math.floor(110 / (i * 0.6))), u = e.append("g").attr("class", "ishikawa-head-group").attr("transform", `translate(${l},${a})`), p = X(u, ct(s, f), 0, 0, "ishikawa-head-label", "start", i), g = p.node().getBBox(), x = Math.max(60, g.width + 6), m = Math.max(40, g.height * 2 + 40), S = `M 0 ${-m / 2} L 0 ${m / 2} Q ${x * 2.4} 0 0 ${-m / 2} Z`;
  if (d) {
    let $ = d.roughSvg.path(S, {
      roughness: 1.5,
      seed: d.seed,
      fill: d.fillColor,
      fillStyle: "hachure",
      fillWeight: 2.5,
      hachureGap: 5,
      stroke: d.lineColor,
      strokeWidth: 2
    });
    u.insert(() => $, ":first-child").attr("class", "ishikawa-head");
  } else u.insert("path", ":first-child").attr("class", "ishikawa-head").attr("d", S);
  p.attr("transform", `translate(${(x - g.width) / 2 - g.x + 3},${-g.y - g.height / 2})`);
}, "drawHead"), Lt = /* @__PURE__ */ r((e, l) => {
  let a = [], s = [], i = /* @__PURE__ */ r((d, f, u) => {
    let p = l === -1 ? [...d].reverse() : d;
    for (let g of p) {
      let x = a.length, m = g.children ?? [];
      a.push({
        depth: u,
        text: ct(g.text, 15),
        parentIndex: f,
        childCount: m.length
      }), u % 2 == 0 ? (s.push(x), m.length && i(m, x, u + 1)) : (m.length && i(m, x, u + 1), s.push(x));
    }
  }, "walk");
  return i(e, -1, 2), {
    entries: a,
    yOrder: s
  };
}, "flattenTree"), Mt = /* @__PURE__ */ r((e, l, a, s, i, d, f) => {
  let u = e.append("g").attr("class", "ishikawa-label-group"), p = X(u, l, a, s + 11 * i, "ishikawa-label cause", "middle", d).node().getBBox();
  if (f) {
    let g = f.roughSvg.rectangle(p.x - 20, p.y - 2, p.width + 40, p.height + 4, {
      roughness: 1.5,
      seed: f.seed,
      fill: f.fillColor,
      fillStyle: "hachure",
      fillWeight: 2.5,
      hachureGap: 5,
      stroke: f.lineColor,
      strokeWidth: 2
    });
    u.insert(() => g, ":first-child").attr("class", "ishikawa-label-box");
  } else u.insert("rect", ":first-child").attr("class", "ishikawa-label-box").attr("x", p.x - 20).attr("y", p.y - 2).attr("width", p.width + 40).attr("height", p.height + 4);
}, "drawCauseLabel"), J = /* @__PURE__ */ r((e, l, a, s, i, d) => {
  let f = Math.sqrt(s * s + i * i);
  if (f === 0) return;
  let u = s / f, p = i / f, g = -p * 6, x = u * 6, m = l, S = a, $ = `M ${m} ${S} L ${m - u * 6 * 2 + g} ${S - p * 6 * 2 + x} L ${m - u * 6 * 2 - g} ${S - p * 6 * 2 - x} Z`, L = d.roughSvg.path($, {
    roughness: 1,
    seed: d.seed,
    fill: d.lineColor,
    fillStyle: "solid",
    stroke: d.lineColor,
    strokeWidth: 1
  });
  e.append(() => L);
}, "drawArrowMarker"), Pt = /* @__PURE__ */ r((e, l, a, s, i, d, f, u) => {
  let p = l.children ?? [], g = d * (p.length ? 1 : 0.2), x = -st * g, m = nt * g * i, S = a + x, $ = s + m;
  if (G(e, a, s, S, $, "ishikawa-branch", u), u && J(e, a, s, a - S, s - $, u), Mt(e, l.text, S, $, i, f, u), !p.length) return;
  let { entries: L, yOrder: I } = Lt(p, i), t = L.length, y = Array(t);
  for (let [P, b] of I.entries()) y[b] = s + m * ((P + 1) / (t + 1));
  let n = /* @__PURE__ */ new Map();
  n.set(-1, {
    x0: a,
    y0: s,
    x1: S,
    y1: $,
    childCount: p.length,
    childrenDrawn: 0
  });
  let h = -st, c = nt * i, o = i < 0 ? "ishikawa-label up" : "ishikawa-label down";
  for (let [P, b] of L.entries()) {
    let w = y[P], _ = n.get(b.parentIndex), B = e.append("g").attr("class", "ishikawa-sub-group"), v = 0, A = 0, M = 0;
    if (b.depth % 2 == 0) {
      let k = _.y1 - _.y0;
      v = lt(_.x0, _.x1, k ? (w - _.y0) / k : 0.5), A = w, M = v - (b.childCount > 0 ? It + b.childCount * At : $t), G(B, v, w, M, w, "ishikawa-sub-branch", u), u && J(B, v, w, 1, 0, u), X(B, b.text, M, w, "ishikawa-label align", "end", f);
    } else {
      let k = _.childrenDrawn++;
      v = lt(_.x0, _.x1, (_.childCount - k) / (_.childCount + 1)), A = _.y0, M = v + h * ((w - A) / c), G(B, v, A, M, w, "ishikawa-sub-branch", u), u && J(B, v, A, v - M, A - w, u), X(B, b.text, M, w, o, "end", f);
    }
    b.childCount > 0 && n.set(P, {
      x0: v,
      y0: A,
      x1: M,
      y1: w,
      childCount: b.childCount,
      childrenDrawn: 0
    });
  }
}, "drawBranch"), Bt = /* @__PURE__ */ r((e) => e.split(/<br\s*\/?>|\n/), "splitLines"), ct = /* @__PURE__ */ r((e, l) => {
  if (e.length <= l) return e;
  let a = [];
  for (let s of e.split(/\s+/)) {
    let i = a.length - 1;
    i >= 0 && a[i].length + 1 + s.length <= l ? a[i] += " " + s : a.push(s);
  }
  return a.join(`
`);
}, "wrapText"), X = /* @__PURE__ */ r((e, l, a, s, i, d, f) => {
  let u = Bt(l), p = f * 1.05, g = e.append("text").attr("class", i).attr("text-anchor", d).attr("x", a).attr("y", s - (u.length - 1) * p / 2);
  for (let [x, m] of u.entries()) g.append("tspan").attr("x", a).attr("dy", x === 0 ? 0 : p).text(m);
  return g;
}, "drawMultilineText"), lt = /* @__PURE__ */ r((e, l, a) => e + (l - e) * a, "lerp"), G = /* @__PURE__ */ r((e, l, a, s, i, d, f) => {
  if (f) {
    let u = f.roughSvg.line(l, a, s, i, {
      roughness: 1.5,
      seed: f.seed,
      stroke: f.lineColor,
      strokeWidth: 2
    });
    e.append(() => u).attr("class", d);
    return;
  }
  return e.append("line").attr("class", d).attr("x1", l).attr("y1", a).attr("x2", s).attr("y2", i);
}, "drawLine"), Wt = {
  parser: _t,
  get db() {
    return new vt();
  },
  renderer: { draw: Et },
  styles: /* @__PURE__ */ r((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")
};
export {
  Wt as diagram
};
