var _a;
import "./chunk-TCCFYFTB-d3HOqL2I.js";
import "./main-CThhXnXU.js";
import "./purify.es-DT70lfR0.js";
import { n as ordinal } from "./ordinal-B43ZeR68.js";
import { t as format } from "./defaultLocale-BpsHxBd7.js";
import { i as cleanAndMerge } from "./chunk-S3R3BYOJ-mQeCz5CE.js";
import { i as log, r as __name, t as select_default } from "./src-Bf2iLOlr.js";
import { p as hierarchy, t as treemap_default } from "./treemap-D-ka1hvx.js";
import { B as setAccTitle, C as getDiagramTitle, U as setDiagramTitle, _ as getAccDescription, a as clear, c as configureSvgSize, d as defaultConfig_default, v as getAccTitle, y as getConfig, z as setAccDescription } from "./chunk-ABZYJK2D-D0cLy8Bb.js";
import { t as selectSvgElement } from "./chunk-EXTU4WIE-BKNXdLmD.js";
import { i as styles2String, n as isLabelStyle } from "./chunk-ATLVNIR6-BXsEjlHF.js";
import "./dist-BGdYVvOu.js";
import "./chunk-UMXZTB3W-97iS1iEl.js";
import "./chunk-4F5CHEZ2-BZq7Kom7.js";
import "./chunk-FRFDVMJY-BSBUAX7r.js";
import "./chunk-SJTYNZTY-CEG4F0pB.js";
import "./chunk-PL6DKKU2-B0MTXvyc.js";
import "./chunk-TQ3KTPDO-DiCtqVSi.js";
import "./chunk-B2363JML-D9-XOau1.js";
import { t as populateCommonDb } from "./chunk-4BX2VUAB-CzXltWHN.js";
import { t as parse } from "./mermaid-parser.core-DreccfmS.js";
import { t as setupViewPortForSVG } from "./chunk-QN33PNHL-Bb-eUBW3.js";
var TreeMapDB = (_a = class {
  constructor() {
    this.nodes = [], this.levels = /* @__PURE__ */ new Map(), this.outerNodes = [], this.classes = /* @__PURE__ */ new Map(), this.setAccTitle = setAccTitle, this.getAccTitle = getAccTitle, this.setDiagramTitle = setDiagramTitle, this.getDiagramTitle = getDiagramTitle, this.getAccDescription = getAccDescription, this.setAccDescription = setAccDescription;
  }
  getNodes() {
    return this.nodes;
  }
  getConfig() {
    let e = defaultConfig_default, l = getConfig();
    return cleanAndMerge({
      ...e.treemap,
      ...l.treemap ?? {}
    });
  }
  addNode(e, l) {
    this.nodes.push(e), this.levels.set(e, l), l === 0 && (this.outerNodes.push(e), this.root ?? (this.root = e));
  }
  getRoot() {
    return {
      name: "",
      children: this.outerNodes
    };
  }
  addClass(e, l) {
    let u = this.classes.get(e) ?? {
      id: e,
      styles: [],
      textStyles: []
    }, d = l.replace(/\\,/g, "\xA7\xA7\xA7").replace(/,/g, ";").replace(/§§§/g, ",").split(";");
    d && d.forEach((e2) => {
      isLabelStyle(e2) && ((u == null ? void 0 : u.textStyles) ? u.textStyles.push(e2) : u.textStyles = [e2]), (u == null ? void 0 : u.styles) ? u.styles.push(e2) : u.styles = [e2];
    }), this.classes.set(e, u);
  }
  getClasses() {
    return this.classes;
  }
  getStylesForClass(e) {
    var _a2;
    return ((_a2 = this.classes.get(e)) == null ? void 0 : _a2.styles) ?? [];
  }
  clear() {
    clear(), this.nodes = [], this.levels = /* @__PURE__ */ new Map(), this.outerNodes = [], this.classes = /* @__PURE__ */ new Map(), this.root = void 0;
  }
}, __name(_a, "TreeMapDB"), _a);
function buildHierarchy(e) {
  if (!e.length) return [];
  let l = [], u = [];
  return e.forEach((e2) => {
    let d = {
      name: e2.name,
      children: e2.type === "Leaf" ? void 0 : []
    };
    for (d.classSelector = e2 == null ? void 0 : e2.classSelector, (e2 == null ? void 0 : e2.cssCompiledStyles) && (d.cssCompiledStyles = [e2.cssCompiledStyles]), e2.type === "Leaf" && e2.value !== void 0 && (d.value = e2.value); u.length > 0 && u[u.length - 1].level >= e2.level; ) u.pop();
    if (u.length === 0) l.push(d);
    else {
      let e3 = u[u.length - 1].node;
      e3.children ? e3.children.push(d) : e3.children = [d];
    }
    e2.type !== "Leaf" && u.push({
      node: d,
      level: e2.level
    });
  }), l;
}
__name(buildHierarchy, "buildHierarchy");
var populate = /* @__PURE__ */ __name((e, l) => {
  populateCommonDb(e, l);
  let u = [];
  for (let u2 of e.TreemapRows ?? []) u2.$type === "ClassDefStatement" && l.addClass(u2.className ?? "", u2.styleText ?? "");
  for (let d2 of e.TreemapRows ?? []) {
    let e2 = d2.item;
    if (!e2) continue;
    let f = d2.indent ? parseInt(d2.indent) : 0, p2 = getItemName(e2), m = e2.classSelector ? l.getStylesForClass(e2.classSelector) : [], h = m.length > 0 ? m.join(";") : void 0, g = {
      level: f,
      name: p2,
      type: e2.$type,
      value: e2.value,
      classSelector: e2.classSelector,
      cssCompiledStyles: h
    };
    u.push(g);
  }
  let d = buildHierarchy(u), p = /* @__PURE__ */ __name((e2, u2) => {
    for (let d2 of e2) l.addNode(d2, u2), d2.children && d2.children.length > 0 && p(d2.children, u2 + 1);
  }, "addNodesRecursively");
  p(d, 0);
}, "populate"), getItemName = /* @__PURE__ */ __name((e) => e.name ? String(e.name) : "", "getItemName"), parser = {
  parser: { yy: void 0 },
  parse: /* @__PURE__ */ __name(async (e) => {
    var _a2;
    try {
      let l = await parse("treemap", e);
      log.debug("Treemap AST:", l);
      let u = (_a2 = parser.parser) == null ? void 0 : _a2.yy;
      if (!(u instanceof TreeMapDB)) throw 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.");
      populate(l, u);
    } catch (e2) {
      throw log.error("Error parsing treemap:", e2), e2;
    }
  }, "parse")
}, DEFAULT_INNER_PADDING = 10, SECTION_INNER_PADDING = 10, SECTION_HEADER_HEIGHT = 25, renderer = {
  draw: /* @__PURE__ */ __name((u, g, _, v) => {
    let y = v.db, b = y.getConfig(), x = b.padding ?? DEFAULT_INNER_PADDING, S = y.getDiagramTitle(), C = y.getRoot(), { themeVariables: w } = getConfig();
    if (!C) return;
    let T = S ? 30 : 0, E = selectSvgElement(g), D = b.nodeWidth ? b.nodeWidth * SECTION_INNER_PADDING : 960, O = b.nodeHeight ? b.nodeHeight * SECTION_INNER_PADDING : 500, k = D, A = O + T;
    E.attr("viewBox", `0 0 ${k} ${A}`), configureSvgSize(E, A, k, b.useMaxWidth);
    let j;
    try {
      let e = b.valueFormat || ",";
      if (e === "$0,0") j = /* @__PURE__ */ __name((e2) => "$" + format(",")(e2), "valueFormat");
      else if (e.startsWith("$") && e.includes(",")) {
        let u2 = /\.\d+/.exec(e), d = u2 ? u2[0] : "";
        j = /* @__PURE__ */ __name((e2) => "$" + format("," + d)(e2), "valueFormat");
      } else if (e.startsWith("$")) {
        let u2 = e.substring(1);
        j = /* @__PURE__ */ __name((e2) => "$" + format(u2 || "")(e2), "valueFormat");
      } else j = format(e);
    } catch (e) {
      log.error("Error creating format function:", e), j = format(",");
    }
    let M = ordinal().range([
      "transparent",
      w.cScale0,
      w.cScale1,
      w.cScale2,
      w.cScale3,
      w.cScale4,
      w.cScale5,
      w.cScale6,
      w.cScale7,
      w.cScale8,
      w.cScale9,
      w.cScale10,
      w.cScale11
    ]), N = ordinal().range([
      "transparent",
      w.cScalePeer0,
      w.cScalePeer1,
      w.cScalePeer2,
      w.cScalePeer3,
      w.cScalePeer4,
      w.cScalePeer5,
      w.cScalePeer6,
      w.cScalePeer7,
      w.cScalePeer8,
      w.cScalePeer9,
      w.cScalePeer10,
      w.cScalePeer11
    ]), P = ordinal().range([
      w.cScaleLabel0,
      w.cScaleLabel1,
      w.cScaleLabel2,
      w.cScaleLabel3,
      w.cScaleLabel4,
      w.cScaleLabel5,
      w.cScaleLabel6,
      w.cScaleLabel7,
      w.cScaleLabel8,
      w.cScaleLabel9,
      w.cScaleLabel10,
      w.cScaleLabel11
    ]);
    S && E.append("text").attr("x", k / 2).attr("y", T / 2).attr("class", "treemapTitle").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(S);
    let F = E.append("g").attr("transform", `translate(0, ${T})`).attr("class", "treemapContainer"), I = hierarchy(C).sum((e) => e.value ?? 0).sort((e, l) => (l.value ?? 0) - (e.value ?? 0)), L = treemap_default().size([D, O]).paddingTop((e) => e.children && e.children.length > 0 ? SECTION_HEADER_HEIGHT + SECTION_INNER_PADDING : 0).paddingInner(x).paddingLeft((e) => e.children && e.children.length > 0 ? SECTION_INNER_PADDING : 0).paddingRight((e) => e.children && e.children.length > 0 ? SECTION_INNER_PADDING : 0).paddingBottom((e) => e.children && e.children.length > 0 ? SECTION_INNER_PADDING : 0).round(true)(I), R = L.descendants().filter((e) => e.children && e.children.length > 0), z = F.selectAll(".treemapSection").data(R).enter().append("g").attr("class", "treemapSection").attr("transform", (e) => `translate(${e.x0},${e.y0})`);
    z.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", SECTION_HEADER_HEIGHT).attr("class", "treemapSectionHeader").attr("fill", "none").attr("fill-opacity", 0.6).attr("stroke-width", 0.6).attr("style", (e) => e.depth === 0 ? "display: none;" : ""), z.append("clipPath").attr("id", (e, l) => `clip-section-${g}-${l}`).append("rect").attr("width", (e) => Math.max(0, e.x1 - e.x0 - 12)).attr("height", SECTION_HEADER_HEIGHT), z.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", (e) => e.y1 - e.y0).attr("class", (e, l) => `treemapSection section${l}`).attr("fill", (e) => M(e.data.name)).attr("fill-opacity", 0.6).attr("stroke", (e) => N(e.data.name)).attr("stroke-width", 2).attr("stroke-opacity", 0.4).attr("style", (e) => {
      if (e.depth === 0) return "display: none;";
      let l = styles2String({ cssCompiledStyles: e.data.cssCompiledStyles });
      return l.nodeStyles + ";" + l.borderStyles.join(";");
    }), z.append("text").attr("class", "treemapSectionLabel").attr("x", 6).attr("y", SECTION_HEADER_HEIGHT / 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:" + P(e.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" + styles2String({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).each(function(e) {
      if (e.depth === 0) return;
      let l = select_default(this), u2 = e.data.name;
      l.text(u2);
      let d = e.x1 - e.x0, f;
      f = b.showValues !== false && e.value ? d - 10 - 30 - 10 - 6 : d - 6 - 6;
      let m = Math.max(15, f), h = l.node();
      if (h.getComputedTextLength() > m) {
        let e2 = u2;
        for (; e2.length > 0; ) {
          if (e2 = u2.substring(0, e2.length - 1), e2.length === 0) {
            l.text("..."), h.getComputedTextLength() > m && l.text("");
            break;
          }
          if (l.text(e2 + "..."), h.getComputedTextLength() <= m) break;
        }
      }
    }), b.showValues !== false && z.append("text").attr("class", "treemapSectionValue").attr("x", (e) => e.x1 - e.x0 - 10).attr("y", SECTION_HEADER_HEIGHT / 2).attr("text-anchor", "end").attr("dominant-baseline", "middle").text((e) => e.value ? j(e.value) : "").attr("font-style", "italic").attr("style", (e) => e.depth === 0 ? "display: none;" : "text-anchor: end; dominant-baseline: middle; font-size: 10px; fill:" + P(e.data.name) + "; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" + styles2String({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:"));
    let B = L.leaves(), V = F.selectAll(".treemapLeafGroup").data(B).enter().append("g").attr("class", (e, l) => `treemapNode treemapLeafGroup leaf${l}${e.data.classSelector ? ` ${e.data.classSelector}` : ""}x`).attr("transform", (e) => `translate(${e.x0},${e.y0})`);
    V.append("rect").attr("width", (e) => e.x1 - e.x0).attr("height", (e) => e.y1 - e.y0).attr("class", "treemapLeaf").attr("fill", (e) => e.parent ? M(e.parent.data.name) : M(e.data.name)).attr("style", (e) => styles2String({ cssCompiledStyles: e.data.cssCompiledStyles }).nodeStyles).attr("fill-opacity", 0.3).attr("stroke", (e) => e.parent ? M(e.parent.data.name) : M(e.data.name)).attr("stroke-width", 3), V.append("clipPath").attr("id", (e, l) => `clip-${g}-${l}`).append("rect").attr("width", (e) => Math.max(0, e.x1 - e.x0 - 4)).attr("height", (e) => Math.max(0, e.y1 - e.y0 - 4)), V.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:" + P(e.data.name) + ";" + styles2String({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).attr("clip-path", (e, l) => `url(#clip-${g}-${l})`).text((e) => e.data.name).each(function(e) {
      let l = select_default(this), u2 = e.x1 - e.x0, d = e.y1 - e.y0, f = l.node(), m = u2 - 8, h = d - 8;
      if (m < 10 || h < 10) {
        l.style("display", "none");
        return;
      }
      let g2 = parseInt(l.style("font-size"), 10), _2 = 0.6;
      for (; f.getComputedTextLength() > m && g2 > 8; ) g2--, l.style("font-size", `${g2}px`);
      let v2 = Math.max(6, Math.min(28, Math.round(g2 * _2))), y2 = g2 + 2 + v2;
      for (; y2 > h && g2 > 8 && (g2--, v2 = Math.max(6, Math.min(28, Math.round(g2 * _2))), !(v2 < 6 && g2 === 8)); ) l.style("font-size", `${g2}px`), y2 = g2 + 2 + v2;
      l.style("font-size", `${g2}px`), (f.getComputedTextLength() > m || g2 < 8 || h < g2) && l.style("display", "none");
    }), b.showValues !== false && V.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:" + P(e.data.name) + ";" + styles2String({ cssCompiledStyles: e.data.cssCompiledStyles }).labelStyles.replace("color:", "fill:")).attr("clip-path", (e, l) => `url(#clip-${g}-${l})`).text((e) => e.value ? j(e.value) : "").each(function(e) {
      let l = select_default(this), u2 = this.parentNode;
      if (!u2) {
        l.style("display", "none");
        return;
      }
      let d = select_default(u2).select(".treemapLabel");
      if (d.empty() || d.style("display") === "none") {
        l.style("display", "none");
        return;
      }
      let f = parseFloat(d.style("font-size")), m = Math.max(6, Math.min(28, Math.round(f * 0.6)));
      l.style("font-size", `${m}px`);
      let h = (e.y1 - e.y0) / 2 + f / 2 + 2;
      l.attr("y", h);
      let g2 = e.x1 - e.x0, _2 = e.y1 - e.y0 - 4, v2 = g2 - 8;
      l.node().getComputedTextLength() > v2 || h + m > _2 || m < 6 ? l.style("display", "none") : l.style("display", null);
    }), setupViewPortForSVG(E, b.diagramPadding ?? 8, "flowchart", (b == null ? void 0 : b.useMaxWidth) || false);
  }, "draw"),
  getClasses: /* @__PURE__ */ __name(function(e, l) {
    return l.db.getClasses();
  }, "getClasses")
}, defaultTreemapStyleOptions = {
  sectionStrokeColor: "black",
  sectionStrokeWidth: "1",
  sectionFillColor: "#efefef",
  leafStrokeColor: "black",
  leafStrokeWidth: "1",
  leafFillColor: "#efefef",
  labelColor: "black",
  labelFontSize: "12px",
  valueFontSize: "10px",
  valueColor: "black",
  titleColor: "black",
  titleFontSize: "14px"
}, diagram = {
  parser,
  get db() {
    return new TreeMapDB();
  },
  renderer,
  styles: /* @__PURE__ */ __name(({ treemap: e } = {}) => {
    let l = cleanAndMerge(defaultTreemapStyleOptions, e);
    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: ${l.labelColor};
    font-size: ${l.labelFontSize};
  }
  .treemapValue {
    fill: ${l.valueColor};
    font-size: ${l.valueFontSize};
  }
  .treemapTitle {
    fill: ${l.titleColor};
    font-size: ${l.titleFontSize};
  }
  `;
  }, "getStyles")
};
export {
  diagram
};
