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