import { J as k, Z as I, c as ae, l as le, u as W } from "./vendor/recharts.js";
import { r as R } from "./chunk-5PVQY5BW.js";
import { n as m, r as B } from "./chunk-AGHRB4JF.js";
import { B as se, C as re, E as oe, V as ne, W as ie, _ as ce, a as pe, c as de, d as he, v as me, y as G } from "./chunk-ICPOFSXX.js";
import { t as fe } from "./chunk-426QAEUC.js";
import { t as ue } from "./chunk-4BX2VUAB.js";
import { t as ye } from "./mermaid-parser.core.js";
import { t as ge } from "./chunk-EDXVE4YY.js";
import { i as w, n as Se } from "./chunk-X2U36JSP.js";
var X = class {
  constructor() {
    this.nodes = [], this.levels = /* @__PURE__ */ new Map(), this.outerNodes = [], this.classes = /* @__PURE__ */ new Map(), this.setAccTitle = ne, this.getAccTitle = me, this.setDiagramTitle = ie, this.getDiagramTitle = re, this.getAccDescription = ce, this.setAccDescription = se;
  }
  static {
    m(this, "TreeMapDB");
  }
  getNodes() {
    return this.nodes;
  }
  getConfig() {
    const r = he, s = G();
    return R({
      ...r.treemap,
      ...s.treemap ?? {}
    });
  }
  addNode(r, s) {
    this.nodes.push(r), this.levels.set(r, s), s === 0 && (this.outerNodes.push(r), this.root ??= r);
  }
  getRoot() {
    return {
      name: "",
      children: this.outerNodes
    };
  }
  addClass(r, s) {
    const l = this.classes.get(r) ?? {
      id: r,
      styles: [],
      textStyles: []
    }, i = s.replace(/\\,/g, "§§§").replace(/,/g, ";").replace(/§§§/g, ",").split(";");
    i && i.forEach((n) => {
      Se(n) && (l?.textStyles ? l.textStyles.push(n) : l.textStyles = [n]), l?.styles ? l.styles.push(n) : l.styles = [n];
    }), this.classes.set(r, l);
  }
  getClasses() {
    return this.classes;
  }
  getStylesForClass(r) {
    return this.classes.get(r)?.styles ?? [];
  }
  clear() {
    pe(), this.nodes = [], this.levels = /* @__PURE__ */ new Map(), this.outerNodes = [], this.classes = /* @__PURE__ */ new Map(), this.root = void 0;
  }
};
function Z(r) {
  if (!r.length) return [];
  const s = [], l = [];
  return r.forEach((i) => {
    const n = {
      name: i.name,
      children: i.type === "Leaf" ? void 0 : []
    };
    for (n.classSelector = i?.classSelector, i?.cssCompiledStyles && (n.cssCompiledStyles = i.cssCompiledStyles), i.type === "Leaf" && i.value !== void 0 && (n.value = i.value); l.length > 0 && l[l.length - 1].level >= i.level; ) l.pop();
    if (l.length === 0) s.push(n);
    else {
      const o = l[l.length - 1].node;
      o.children ? o.children.push(n) : o.children = [n];
    }
    i.type !== "Leaf" && l.push({
      node: n,
      level: i.level
    });
  }), s;
}
m(Z, "buildHierarchy");
var xe = /* @__PURE__ */ m((r, s) => {
  ue(r, s);
  const l = [];
  for (const o of r.TreemapRows ?? []) o.$type === "ClassDefStatement" && s.addClass(o.className ?? "", o.styleText ?? "");
  for (const o of r.TreemapRows ?? []) {
    const d = o.item;
    if (!d) continue;
    const u = o.indent ? parseInt(o.indent) : 0, M = be(d), a = d.classSelector ? s.getStylesForClass(d.classSelector) : [], T = a.length > 0 ? a : void 0, b = {
      level: u,
      name: M,
      type: d.$type,
      value: d.value,
      classSelector: d.classSelector,
      cssCompiledStyles: T
    };
    l.push(b);
  }
  const i = Z(l), n = /* @__PURE__ */ m((o, d) => {
    for (const u of o)
      s.addNode(u, d), u.children && u.children.length > 0 && n(u.children, d + 1);
  }, "addNodesRecursively");
  n(i, 0);
}, "populate"), be = /* @__PURE__ */ m((r) => r.name ? String(r.name) : "", "getItemName"), q = {
  parser: { yy: void 0 },
  parse: /* @__PURE__ */ m(async (r) => {
    try {
      const s = await ye("treemap", r);
      B.debug("Treemap AST:", s);
      const l = q.parser?.yy;
      if (!(l instanceof X)) throw new Error("parser.parser?.yy was not a TreemapDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");
      xe(s, l);
    } catch (s) {
      throw B.error("Error parsing treemap:", s), s;
    }
  }, "parse")
}, ve = 10, $ = 10, D = 25, Ce = {
  draw: /* @__PURE__ */ m((r, s, l, i) => {
    const n = i.db, o = n.getConfig(), d = o.padding ?? ve, u = n.getDiagramTitle(), M = n.getRoot(), { themeVariables: a } = G();
    if (!M) return;
    const T = u ? 30 : 0, b = fe(s), O = o.nodeWidth ? o.nodeWidth * $ : 960, j = o.nodeHeight ? o.nodeHeight * $ : 500, E = O, Y = j + T;
    b.attr("viewBox", `0 0 ${E} ${Y}`), de(b, Y, E, o.useMaxWidth);
    let v;
    try {
      const e = o.valueFormat || ",";
      if (e === "$0,0") v = /* @__PURE__ */ m((t) => "$" + k(",")(t), "valueFormat");
      else if (e.startsWith("$") && e.includes(",")) {
        const t = /\.\d+/.exec(e), h = t ? t[0] : "";
        v = /* @__PURE__ */ m((y) => "$" + k("," + h)(y), "valueFormat");
      } else if (e.startsWith("$")) {
        const t = e.substring(1);
        v = /* @__PURE__ */ m((h) => "$" + k(t || "")(h), "valueFormat");
      } else v = k(e);
    } catch (e) {
      B.error("Error creating format function:", e), v = k(",");
    }
    const L = I().range([
      "transparent",
      a.cScale0,
      a.cScale1,
      a.cScale2,
      a.cScale3,
      a.cScale4,
      a.cScale5,
      a.cScale6,
      a.cScale7,
      a.cScale8,
      a.cScale9,
      a.cScale10,
      a.cScale11
    ]), K = I().range([
      "transparent",
      a.cScalePeer0,
      a.cScalePeer1,
      a.cScalePeer2,
      a.cScalePeer3,
      a.cScalePeer4,
      a.cScalePeer5,
      a.cScalePeer6,
      a.cScalePeer7,
      a.cScalePeer8,
      a.cScalePeer9,
      a.cScalePeer10,
      a.cScalePeer11
    ]), V = I().range([
      a.cScaleLabel0,
      a.cScaleLabel1,
      a.cScaleLabel2,
      a.cScaleLabel3,
      a.cScaleLabel4,
      a.cScaleLabel5,
      a.cScaleLabel6,
      a.cScaleLabel7,
      a.cScaleLabel8,
      a.cScaleLabel9,
      a.cScaleLabel10,
      a.cScaleLabel11
    ]);
    u && b.append("text").attr("x", E / 2).attr("y", T / 2).attr("class", "treemapTitle").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(u);
    const J = b.append("g").attr("transform", `translate(0, ${T})`).attr("class", "treemapContainer"), Q = le(M).sum((e) => e.value ?? 0).sort((e, t) => (t.value ?? 0) - (e.value ?? 0)), U = ae().size([O, j]).paddingTop((e) => e.children && e.children.length > 0 ? D + $ : 0).paddingInner(d).paddingLeft((e) => e.children && e.children.length > 0 ? $ : 0).paddingRight((e) => e.children && e.children.length > 0 ? $ : 0).paddingBottom((e) => e.children && e.children.length > 0 ? $ : 0).round(!0)(Q), ee = U.descendants().filter((e) => e.children && e.children.length > 0), F = J.selectAll(".treemapSection").data(ee).enter().append("g").attr("class", "treemapSection").attr("transform", (e) => `translate(${e.x0},${e.y0})`);
    F.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", D).attr("class", "treemapSectionHeader").attr("fill", "none").attr("fill-opacity", 0.6).attr("stroke-width", 0.6).attr("style", (e) => e.depth === 0 ? "display: none;" : ""), F.append("clipPath").attr("id", (e, t) => `clip-section-${s}-${t}`).append("rect").attr("width", (e) => Math.max(0, e.x1 - e.x0 - 12)).attr("height", D), F.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", (e) => e.y1 - e.y0).attr("class", (e, t) => `treemapSection section${t}`).attr("fill", (e) => L(e.data.name)).attr("fill-opacity", 0.6).attr("stroke", (e) => K(e.data.name)).attr("stroke-width", 2).attr("stroke-opacity", 0.4).attr("style", (e) => {
      if (e.depth === 0) return "display: none;";
      const t = w({ cssCompiledStyles: e.data.cssCompiledStyles });
      return t.nodeStyles + ";" + t.borderStyles.join(";");
    }), F.append("text").attr("class", "treemapSectionLabel").attr("x", 6).attr("y", D / 2).attr("dominant-baseline", "middle").text((e) => e.depth === 0 ? "" : e.data.name).attr("font-weight", "bold").attr("style", (e) => e.depth === 0 ? "display: none;" : "dominant-baseline: middle; font-size: 12px; fill:" + V(e.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" + w({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).each(function(e) {
      if (e.depth === 0) return;
      const t = W(this), h = e.data.name;
      t.text(h);
      const y = e.x1 - e.x0, S = 6;
      let x;
      o.showValues !== !1 && e.value ? x = y - 10 - 30 - 10 - S : x = y - S - 6;
      const g = Math.max(15, x), f = t.node();
      if (f.getComputedTextLength() > g) {
        let p = h;
        for (; p.length > 0; ) {
          if (p = h.substring(0, p.length - 1), p.length === 0) {
            t.text("..."), f.getComputedTextLength() > g && t.text("");
            break;
          }
          if (t.text(p + "..."), f.getComputedTextLength() <= g) break;
        }
      }
    }), o.showValues !== !1 && F.append("text").attr("class", "treemapSectionValue").attr("x", (e) => e.x1 - e.x0 - 10).attr("y", D / 2).attr("text-anchor", "end").attr("dominant-baseline", "middle").text((e) => e.value ? v(e.value) : "").attr("font-style", "italic").attr("style", (e) => e.depth === 0 ? "display: none;" : "text-anchor: end; dominant-baseline: middle; font-size: 10px; fill:" + V(e.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" + w({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:"));
    const te = U.leaves(), P = J.selectAll(".treemapLeafGroup").data(te).enter().append("g").attr("class", (e, t) => `treemapNode treemapLeafGroup leaf${t}${e.data.classSelector ? ` ${e.data.classSelector}` : ""}x`).attr("transform", (e) => `translate(${e.x0},${e.y0})`);
    P.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", (e) => e.y1 - e.y0).attr("class", "treemapLeaf").attr("fill", (e) => e.parent ? L(e.parent.data.name) : L(e.data.name)).attr("style", (e) => w({ cssCompiledStyles: e.data.cssCompiledStyles }).nodeStyles).attr("fill-opacity", 0.3).attr("stroke", (e) => e.parent ? L(e.parent.data.name) : L(e.data.name)).attr("stroke-width", 3), P.append("clipPath").attr("id", (e, t) => `clip-${s}-${t}`).append("rect").attr("width", (e) => Math.max(0, e.x1 - e.x0 - 4)).attr("height", (e) => Math.max(0, e.y1 - e.y0 - 4)), P.append("text").attr("class", "treemapLabel").attr("x", (e) => (e.x1 - e.x0) / 2).attr("y", (e) => (e.y1 - e.y0) / 2).attr("style", (e) => "text-anchor: middle; dominant-baseline: middle; font-size: 38px;fill:" + V(e.data.name) + ";" + w({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).attr("clip-path", (e, t) => `url(#clip-${s}-${t})`).text((e) => e.data.name).each(function(e) {
      const t = W(this), h = e.x1 - e.x0, y = e.y1 - e.y0, S = t.node(), x = 4, g = h - 2 * x, f = y - 2 * x;
      if (g < 10 || f < 10) {
        t.style("display", "none");
        return;
      }
      let c = parseInt(t.style("font-size"), 10);
      const p = 8, z = 28, A = 0.6, C = 6, _ = 2;
      for (; S.getComputedTextLength() > g && c > p; )
        c--, t.style("font-size", `${c}px`);
      let N = Math.max(C, Math.min(z, Math.round(c * A))), H = c + _ + N;
      for (; H > f && c > p && (c--, N = Math.max(C, Math.min(z, Math.round(c * A))), !(N < C && c === p)); )
        t.style("font-size", `${c}px`), H = c + _ + N, N <= C && H > f;
      t.style("font-size", `${c}px`), (S.getComputedTextLength() > g || c < p || f < c) && t.style("display", "none");
    }), o.showValues !== !1 && P.append("text").attr("class", "treemapValue").attr("x", (e) => (e.x1 - e.x0) / 2).attr("y", function(e) {
      return (e.y1 - e.y0) / 2;
    }).attr("style", (e) => "text-anchor: middle; dominant-baseline: hanging; font-size: 28px;fill:" + V(e.data.name) + ";" + w({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).attr("clip-path", (e, t) => `url(#clip-${s}-${t})`).text((e) => e.value ? v(e.value) : "").each(function(e) {
      const t = W(this), h = this.parentNode;
      if (!h) {
        t.style("display", "none");
        return;
      }
      const y = W(h).select(".treemapLabel");
      if (y.empty() || y.style("display") === "none") {
        t.style("display", "none");
        return;
      }
      const S = parseFloat(y.style("font-size")), x = 28, g = 0.6, f = 6, c = 2, p = Math.max(f, Math.min(x, Math.round(S * g)));
      t.style("font-size", `${p}px`);
      const z = (e.y1 - e.y0) / 2 + S / 2 + c;
      t.attr("y", z);
      const A = e.x1 - e.x0, C = e.y1 - e.y0 - 4, _ = A - 8;
      t.node().getComputedTextLength() > _ || z + p > C || p < f ? t.style("display", "none") : t.style("display", null);
    }), ge(b, o.diagramPadding ?? 8, "flowchart", o?.useMaxWidth || !1);
  }, "draw"),
  getClasses: /* @__PURE__ */ m(function(r, s) {
    return s.db.getClasses();
  }, "getClasses")
}, we = {
  sectionStrokeColor: "black",
  sectionStrokeWidth: "1",
  sectionFillColor: "#efefef",
  leafStrokeColor: "black",
  leafStrokeWidth: "1",
  leafFillColor: "#efefef",
  labelFontSize: "12px",
  valueFontSize: "10px",
  titleFontSize: "14px"
}, Ve = {
  parser: q,
  get db() {
    return new X();
  },
  renderer: Ce,
  styles: /* @__PURE__ */ m(({ treemap: r } = {}) => {
    const s = R(oe(), G().themeVariables), l = R(we, r), i = l.titleColor ?? s.titleColor, n = l.labelColor ?? s.textColor, o = l.valueColor ?? s.textColor;
    return `
  .treemapNode.section {
    stroke: ${l.sectionStrokeColor};
    stroke-width: ${l.sectionStrokeWidth};
    fill: ${l.sectionFillColor};
  }
  .treemapNode.leaf {
    stroke: ${l.leafStrokeColor};
    stroke-width: ${l.leafStrokeWidth};
    fill: ${l.leafFillColor};
  }
  .treemapLabel {
    fill: ${n};
    font-size: ${l.labelFontSize};
  }
  .treemapValue {
    fill: ${o};
    font-size: ${l.valueFontSize};
  }
  .treemapTitle {
    fill: ${i};
    font-size: ${l.titleFontSize};
  }
  `;
  }, "getStyles")
};
export {
  Ve as diagram
};

//# sourceMappingURL=diagram-G4DWMVQ6.js.map