import { r as b } from "./chunk-5PVQY5BW.js";
import { n as s, r as k } from "./chunk-AGHRB4JF.js";
import { B as f, C as x, V as C, W as B, _ as T, a as V, c as y, d as N, v as S, y as _ } from "./chunk-ICPOFSXX.js";
import { t as D } from "./chunk-426QAEUC.js";
import { t as $ } from "./chunk-4BX2VUAB.js";
import { t as A } from "./mermaid-parser.core.js";
import { t as W } from "./chunk-QZHKN3VN.js";
var l = new W(() => ({
  cnt: 1,
  stack: [{
    id: 0,
    level: -1,
    name: "/",
    children: []
  }]
})), X = /* @__PURE__ */ s(() => {
  l.reset(), V();
}, "clear"), z = /* @__PURE__ */ s(() => l.records.stack[0], "getRoot"), H = /* @__PURE__ */ s(() => l.records.cnt, "getCount"), I = N.treeView, v = {
  clear: X,
  addNode: /* @__PURE__ */ s((e, t) => {
    for (; e <= l.records.stack[l.records.stack.length - 1].level; ) l.records.stack.pop();
    const r = {
      id: l.records.cnt++,
      level: e,
      name: t,
      children: []
    };
    l.records.stack[l.records.stack.length - 1].children.push(r), l.records.stack.push(r);
  }, "addNode"),
  getRoot: z,
  getCount: H,
  getConfig: /* @__PURE__ */ s(() => b(I, _().treeView), "getConfig"),
  getAccTitle: S,
  getAccDescription: T,
  getDiagramTitle: x,
  setAccDescription: f,
  setAccTitle: C,
  setDiagramTitle: B
}, L = /* @__PURE__ */ s((e) => {
  $(e, v), e.nodes.map((t) => v.addNode(t.indent ? parseInt(t.indent) : 0, t.name));
}, "populate"), R = { parse: /* @__PURE__ */ s(async (e) => {
  const t = await A("treeView", e);
  k.debug(t), L(t);
}, "parse") }, E = /* @__PURE__ */ s((e, t, r, o, i) => {
  const c = o.append("text").text(r.name).attr("dominant-baseline", "middle").attr("class", "treeView-node-label"), { height: p, width: a } = c.node().getBBox(), d = p + i.paddingY * 2, n = a + i.paddingX * 2;
  c.attr("x", e + i.paddingX), c.attr("y", t + d / 2), r.BBox = {
    x: e,
    y: t,
    width: n,
    height: d
  };
}, "positionLabel"), u = /* @__PURE__ */ s((e, t, r, o, i, c) => e.append("line").attr("x1", t).attr("y1", r).attr("x2", o).attr("y2", i).attr("stroke-width", c).attr("class", "treeView-node-line"), "positionLine"), M = /* @__PURE__ */ s((e, t, r) => {
  let o = 0, i = 0;
  const c = /* @__PURE__ */ s((a, d, n, h) => {
    const m = h * (n.rowIndent + n.paddingX);
    E(m, o, d, a, n);
    const { height: g, width: w } = d.BBox;
    u(a, m - n.rowIndent, o + g / 2, m, o + g / 2, n.lineThickness), i = Math.max(i, m + w), o += g;
  }, "drawNode"), p = /* @__PURE__ */ s((a, d = 0) => {
    c(e, a, r, d), a.children.forEach((g) => {
      p(g, d + 1);
    });
    const { x: n, y: h, height: m } = a.BBox;
    if (a.children.length) {
      const { y: g, height: w } = a.children[a.children.length - 1].BBox;
      u(e, n + r.paddingX, h + m, n + r.paddingX, g + w / 2 + r.lineThickness / 2, r.lineThickness);
    }
  }, "processNode");
  return p(t), {
    totalHeight: o,
    totalWidth: i
  };
}, "drawTree"), F = { draw: /* @__PURE__ */ s((e, t, r, o) => {
  k.debug(`Rendering treeView diagram
` + e);
  const i = o.db, c = i.getRoot(), p = i.getConfig(), a = D(t), d = a.append("g");
  d.attr("class", "tree-view");
  const { totalHeight: n, totalWidth: h } = M(d, c, p);
  a.attr("viewBox", `-${p.lineThickness / 2} 0 ${h} ${n}`), y(a, n, h, p.useMaxWidth);
}, "draw") }, Y = {
  labelFontSize: "16px",
  labelColor: "black",
  lineColor: "black"
}, Q = {
  db: v,
  renderer: F,
  parser: R,
  styles: /* @__PURE__ */ s(({ treeView: e }) => {
    const { labelFontSize: t, labelColor: r, lineColor: o } = b(Y, e);
    return `
    .treeView-node-label {
        font-size: ${t};
        fill: ${r};
    }
    .treeView-node-line {
        stroke: ${o};
    }
    `;
  }, "styles")
};
export {
  Q as diagram
};

//# sourceMappingURL=diagram-5BDNPKRD.js.map