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