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