import { package_default as Q } from "./chunks/mermaid.core/chunk-XAJISQIX.js";
import { selectSvgElement as rr } from "./chunks/mermaid.core/chunk-EXTU4WIE.js";
import { load as tr, JSON_SCHEMA as ar } from "./chunks/mermaid.core/chunk-MI3HLSF2.js";
import { registerLayoutLoaders as ir } from "./chunks/mermaid.core/chunk-N4CR4FBY.js";
import "./chunks/mermaid.core/chunk-QXUST7PY.js";
import "./chunks/mermaid.core/chunk-HN2XXSSU.js";
import "./chunks/mermaid.core/chunk-JZLCHNYA.js";
import { __name as a, log as l, setLogLevel as te } from "./chunks/mermaid.core/chunk-AGHRB4JF.js";
import { detectType as ae, detectors as $, registerLazyLoadedDiagrams as k, defaultConfig as W, updateSiteConfig as or, getSiteConfig as ie, setConfig as dr, getConfig as E, reset as _, registerDiagram as x, getDiagram as z, assignWithDepth_default as nr, saveConfigFromInitialize as sr, themes_default as R, setSiteConfig as cr, evaluate as lr, configureSvgSize as mr, getDiagramLoader as ur, UnknownDiagramError as pr, addDirective as gr, styles_default as vr, frontMatterRegex as fr } from "./chunks/mermaid.core/chunk-ABZYJK2D.js";
import { registerIconPacks as hr } from "./chunks/mermaid.core/chunk-JA3XYJ7Z.js";
import { isDetailedError as oe, utils_default as S, cleanAndMerge as yr, encodeEntities as wr, decodeEntities as Dr, removeDirectives as br } from "./chunks/mermaid.core/chunk-S3R3BYOJ.js";
import { dedent as Sr } from "../../../../ts-dedent@2.2.0/node_modules/ts-dedent/esm/index.js";
import "../../../../d3-transition@3.0.1_d3-selection@3.0.0/node_modules/d3-transition/src/selection/index.js";
import "../../../../d3-zoom@3.0.0/node_modules/d3-zoom/src/transform.js";
import Er from "../../../../dompurify@3.3.1/node_modules/dompurify/dist/purify.es.js";
import J from "../../../../lodash-es@4.17.22/node_modules/lodash-es/isEmpty.js";
import { serialize as _r, stringify as xr } from "../../../../stylis@4.3.6/node_modules/stylis/src/Serializer.js";
import { compile as Tr } from "../../../../stylis@4.3.6/node_modules/stylis/src/Parser.js";
import y from "../../../../d3-selection@3.0.0/node_modules/d3-selection/src/select.js";
var de = "c4", Lr = /* @__PURE__ */ a((e) => /^\s*C4Context|C4Container|C4Component|C4Dynamic|C4Deployment/.test(e), "detector"), Ir = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/c4Diagram-YG6GDRKO.js");
  return { id: de, diagram: e };
}, "loader"), Mr = {
  id: de,
  detector: Lr,
  loader: Ir
}, Ar = Mr, ne = "flowchart", Fr = /* @__PURE__ */ a((e, r) => {
  var t, i;
  return ((t = r == null ? void 0 : r.flowchart) == null ? void 0 : t.defaultRenderer) === "dagre-wrapper" || ((i = r == null ? void 0 : r.flowchart) == null ? void 0 : i.defaultRenderer) === "elk" ? !1 : /^\s*graph/.test(e);
}, "detector"), Rr = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/flowDiagram-NV44I4VS.js");
  return { id: ne, diagram: e };
}, "loader"), Cr = {
  id: ne,
  detector: Fr,
  loader: Rr
}, $r = Cr, se = "flowchart-v2", kr = /* @__PURE__ */ a((e, r) => {
  var t, i, o;
  return ((t = r == null ? void 0 : r.flowchart) == null ? void 0 : t.defaultRenderer) === "dagre-d3" ? !1 : (((i = r == null ? void 0 : r.flowchart) == null ? void 0 : i.defaultRenderer) === "elk" && (r.layout = "elk"), /^\s*graph/.test(e) && ((o = r == null ? void 0 : r.flowchart) == null ? void 0 : o.defaultRenderer) === "dagre-wrapper" ? !0 : /^\s*flowchart/.test(e));
}, "detector"), zr = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/flowDiagram-NV44I4VS.js");
  return { id: se, diagram: e };
}, "loader"), Or = {
  id: se,
  detector: kr,
  loader: zr
}, Vr = Or, ce = "er", Gr = /* @__PURE__ */ a((e) => /^\s*erDiagram/.test(e), "detector"), Pr = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/erDiagram-Q2GNP2WA.js");
  return { id: ce, diagram: e };
}, "loader"), Hr = {
  id: ce,
  detector: Gr,
  loader: Pr
}, qr = Hr, le = "gitGraph", Nr = /* @__PURE__ */ a((e) => /^\s*gitGraph/.test(e), "detector"), Br = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/gitGraphDiagram-NY62KEGX.js");
  return { id: le, diagram: e };
}, "loader"), Ur = {
  id: le,
  detector: Nr,
  loader: Br
}, jr = Ur, me = "gantt", Xr = /* @__PURE__ */ a((e) => /^\s*gantt/.test(e), "detector"), Yr = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/ganttDiagram-JELNMOA3.js");
  return { id: me, diagram: e };
}, "loader"), Qr = {
  id: me,
  detector: Xr,
  loader: Yr
}, Wr = Qr, ue = "info", Jr = /* @__PURE__ */ a((e) => /^\s*info/.test(e), "detector"), Kr = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/infoDiagram-WHAUD3N6.js");
  return { id: ue, diagram: e };
}, "loader"), Zr = {
  id: ue,
  detector: Jr,
  loader: Kr
}, pe = "pie", et = /* @__PURE__ */ a((e) => /^\s*pie/.test(e), "detector"), rt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/pieDiagram-ADFJNKIX.js");
  return { id: pe, diagram: e };
}, "loader"), tt = {
  id: pe,
  detector: et,
  loader: rt
}, ge = "quadrantChart", at = /* @__PURE__ */ a((e) => /^\s*quadrantChart/.test(e), "detector"), it = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/quadrantDiagram-AYHSOK5B.js");
  return { id: ge, diagram: e };
}, "loader"), ot = {
  id: ge,
  detector: at,
  loader: it
}, dt = ot, ve = "xychart", nt = /* @__PURE__ */ a((e) => /^\s*xychart(-beta)?/.test(e), "detector"), st = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/xychartDiagram-PRI3JC2R.js");
  return { id: ve, diagram: e };
}, "loader"), ct = {
  id: ve,
  detector: nt,
  loader: st
}, lt = ct, fe = "requirement", mt = /* @__PURE__ */ a((e) => /^\s*requirement(Diagram)?/.test(e), "detector"), ut = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/requirementDiagram-UZGBJVZJ.js");
  return { id: fe, diagram: e };
}, "loader"), pt = {
  id: fe,
  detector: mt,
  loader: ut
}, gt = pt, he = "sequence", vt = /* @__PURE__ */ a((e) => /^\s*sequenceDiagram/.test(e), "detector"), ft = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/sequenceDiagram-WL72ISMW.js");
  return { id: he, diagram: e };
}, "loader"), ht = {
  id: he,
  detector: vt,
  loader: ft
}, yt = ht, ye = "class", wt = /* @__PURE__ */ a((e, r) => {
  var t;
  return ((t = r == null ? void 0 : r.class) == null ? void 0 : t.defaultRenderer) === "dagre-wrapper" ? !1 : /^\s*classDiagram/.test(e);
}, "detector"), Dt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/classDiagram-2ON5EDUG.js");
  return { id: ye, diagram: e };
}, "loader"), bt = {
  id: ye,
  detector: wt,
  loader: Dt
}, St = bt, we = "classDiagram", Et = /* @__PURE__ */ a((e, r) => {
  var t;
  return /^\s*classDiagram/.test(e) && ((t = r == null ? void 0 : r.class) == null ? void 0 : t.defaultRenderer) === "dagre-wrapper" ? !0 : /^\s*classDiagram-v2/.test(e);
}, "detector"), _t = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/classDiagram-v2-WZHVMYZB.js");
  return { id: we, diagram: e };
}, "loader"), xt = {
  id: we,
  detector: Et,
  loader: _t
}, Tt = xt, De = "state", Lt = /* @__PURE__ */ a((e, r) => {
  var t;
  return ((t = r == null ? void 0 : r.state) == null ? void 0 : t.defaultRenderer) === "dagre-wrapper" ? !1 : /^\s*stateDiagram/.test(e);
}, "detector"), It = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/stateDiagram-FKZM4ZOC.js");
  return { id: De, diagram: e };
}, "loader"), Mt = {
  id: De,
  detector: Lt,
  loader: It
}, At = Mt, be = "stateDiagram", Ft = /* @__PURE__ */ a((e, r) => {
  var t;
  return !!(/^\s*stateDiagram-v2/.test(e) || /^\s*stateDiagram/.test(e) && ((t = r == null ? void 0 : r.state) == null ? void 0 : t.defaultRenderer) === "dagre-wrapper");
}, "detector"), Rt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/stateDiagram-v2-4FDKWEC3.js");
  return { id: be, diagram: e };
}, "loader"), Ct = {
  id: be,
  detector: Ft,
  loader: Rt
}, $t = Ct, Se = "journey", kt = /* @__PURE__ */ a((e) => /^\s*journey/.test(e), "detector"), zt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/journeyDiagram-XKPGCS4Q.js");
  return { id: Se, diagram: e };
}, "loader"), Ot = {
  id: Se,
  detector: kt,
  loader: zt
}, Vt = Ot, Gt = /* @__PURE__ */ a((e, r, t) => {
  l.debug(`rendering svg for syntax error
`);
  const i = rr(r), o = i.append("g");
  i.attr("viewBox", "0 0 2412 512"), mr(i, 100, 512, !0), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m411.313,123.313c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32-9.375,9.375-20.688-20.688c-12.484-12.5-32.766-12.5-45.25,0l-16,16c-1.261,1.261-2.304,2.648-3.31,4.051-21.739-8.561-45.324-13.426-70.065-13.426-105.867,0-192,86.133-192,192s86.133,192 192,192 192-86.133 192-192c0-24.741-4.864-48.327-13.426-70.065 1.402-1.007 2.79-2.049 4.051-3.31l16-16c12.5-12.492 12.5-32.758 0-45.25l-20.688-20.688 9.375-9.375 32.001-31.999zm-219.313,100.687c-52.938,0-96,43.063-96,96 0,8.836-7.164,16-16,16s-16-7.164-16-16c0-70.578 57.422-128 128-128 8.836,0 16,7.164 16,16s-7.164,16-16,16z"
  ), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m459.02,148.98c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l16,16c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16.001-16z"
  ), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m340.395,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688 6.25-6.25 6.25-16.375 0-22.625l-16-16c-6.25-6.25-16.375-6.25-22.625,0s-6.25,16.375 0,22.625l15.999,16z"
  ), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m400,64c8.844,0 16-7.164 16-16v-32c0-8.836-7.156-16-16-16-8.844,0-16,7.164-16,16v32c0,8.836 7.156,16 16,16z"
  ), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m496,96.586h-32c-8.844,0-16,7.164-16,16 0,8.836 7.156,16 16,16h32c8.844,0 16-7.164 16-16 0-8.836-7.156-16-16-16z"
  ), o.append("path").attr("class", "error-icon").attr(
    "d",
    "m436.98,75.605c3.125,3.125 7.219,4.688 11.313,4.688 4.094,0 8.188-1.563 11.313-4.688l32-32c6.25-6.25 6.25-16.375 0-22.625s-16.375-6.25-22.625,0l-32,32c-6.251,6.25-6.251,16.375-0.001,22.625z"
  ), o.append("text").attr("class", "error-text").attr("x", 1440).attr("y", 250).attr("font-size", "150px").style("text-anchor", "middle").text("Syntax error in text"), o.append("text").attr("class", "error-text").attr("x", 1250).attr("y", 400).attr("font-size", "100px").style("text-anchor", "middle").text(`mermaid version ${t}`);
}, "draw"), Ee = { draw: Gt }, Pt = Ee, Ht = {
  db: {},
  renderer: Ee,
  parser: {
    parse: /* @__PURE__ */ a(() => {
    }, "parse")
  }
}, qt = Ht, _e = "flowchart-elk", Nt = /* @__PURE__ */ a((e, r = {}) => {
  var t;
  return (
    // If diagram explicitly states flowchart-elk
    /^\s*flowchart-elk/.test(e) || // If a flowchart/graph diagram has their default renderer set to elk
    /^\s*(flowchart|graph)/.test(e) && ((t = r == null ? void 0 : r.flowchart) == null ? void 0 : t.defaultRenderer) === "elk" ? (r.layout = "elk", !0) : !1
  );
}, "detector"), Bt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/flowDiagram-NV44I4VS.js");
  return { id: _e, diagram: e };
}, "loader"), Ut = {
  id: _e,
  detector: Nt,
  loader: Bt
}, jt = Ut, xe = "timeline", Xt = /* @__PURE__ */ a((e) => /^\s*timeline/.test(e), "detector"), Yt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/timeline-definition-IT6M3QCI.js");
  return { id: xe, diagram: e };
}, "loader"), Qt = {
  id: xe,
  detector: Xt,
  loader: Yt
}, Wt = Qt, Te = "mindmap", Jt = /* @__PURE__ */ a((e) => /^\s*mindmap/.test(e), "detector"), Kt = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/mindmap-definition-VGOIOE7T.js");
  return { id: Te, diagram: e };
}, "loader"), Zt = {
  id: Te,
  detector: Jt,
  loader: Kt
}, ea = Zt, Le = "kanban", ra = /* @__PURE__ */ a((e) => /^\s*kanban/.test(e), "detector"), ta = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/kanban-definition-3W4ZIXB7.js");
  return { id: Le, diagram: e };
}, "loader"), aa = {
  id: Le,
  detector: ra,
  loader: ta
}, ia = aa, Ie = "sankey", oa = /* @__PURE__ */ a((e) => /^\s*sankey(-beta)?/.test(e), "detector"), da = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/sankeyDiagram-TZEHDZUN.js");
  return { id: Ie, diagram: e };
}, "loader"), na = {
  id: Ie,
  detector: oa,
  loader: da
}, sa = na, Me = "packet", ca = /* @__PURE__ */ a((e) => /^\s*packet(-beta)?/.test(e), "detector"), la = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/diagram-S2PKOQOG.js");
  return { id: Me, diagram: e };
}, "loader"), ma = {
  id: Me,
  detector: ca,
  loader: la
}, Ae = "radar", ua = /* @__PURE__ */ a((e) => /^\s*radar-beta/.test(e), "detector"), pa = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/diagram-QEK2KX5R.js");
  return { id: Ae, diagram: e };
}, "loader"), ga = {
  id: Ae,
  detector: ua,
  loader: pa
}, Fe = "block", va = /* @__PURE__ */ a((e) => /^\s*block(-beta)?/.test(e), "detector"), fa = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/blockDiagram-VD42YOAC.js");
  return { id: Fe, diagram: e };
}, "loader"), ha = {
  id: Fe,
  detector: va,
  loader: fa
}, ya = ha, Re = "architecture", wa = /* @__PURE__ */ a((e) => /^\s*architecture/.test(e), "detector"), Da = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/architectureDiagram-VXUJARFQ.js");
  return { id: Re, diagram: e };
}, "loader"), ba = {
  id: Re,
  detector: wa,
  loader: Da
}, Sa = ba, Ce = "treemap", Ea = /* @__PURE__ */ a((e) => /^\s*treemap/.test(e), "detector"), _a = /* @__PURE__ */ a(async () => {
  const { diagram: e } = await import("./chunks/mermaid.core/diagram-PSM6KHXK.js");
  return { id: Ce, diagram: e };
}, "loader"), xa = {
  id: Ce,
  detector: Ea,
  loader: _a
}, K = !1, L = /* @__PURE__ */ a(() => {
  K || (K = !0, x("error", qt, (e) => e.toLowerCase().trim() === "error"), x(
    "---",
    // --- diagram type may appear if YAML front-matter is not parsed correctly
    {
      db: {
        clear: /* @__PURE__ */ a(() => {
        }, "clear")
      },
      styles: {},
      // should never be used
      renderer: {
        draw: /* @__PURE__ */ a(() => {
        }, "draw")
      },
      parser: {
        parse: /* @__PURE__ */ a(() => {
          throw new Error(
            "Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks"
          );
        }, "parse")
      },
      init: /* @__PURE__ */ a(() => null, "init")
      // no op
    },
    (e) => e.toLowerCase().trimStart().startsWith("---")
  ), k(jt, ea, Sa), k(
    Ar,
    ia,
    Tt,
    St,
    qr,
    Wr,
    Zr,
    tt,
    gt,
    yt,
    Vr,
    $r,
    Wt,
    jr,
    $t,
    At,
    Vt,
    dt,
    sa,
    ma,
    lt,
    ya,
    ga,
    xa
  ));
}, "addDiagrams"), Ta = /* @__PURE__ */ a(async () => {
  l.debug("Loading registered diagrams");
  const r = (await Promise.allSettled(
    Object.entries($).map(async ([t, { detector: i, loader: o }]) => {
      if (o)
        try {
          z(t);
        } catch {
          try {
            const { diagram: d, id: s } = await o();
            x(s, d, i);
          } catch (d) {
            throw l.error(`Failed to load external diagram with key ${t}. Removing from detectors.`), delete $[t], d;
          }
        }
    })
  )).filter((t) => t.status === "rejected");
  if (r.length > 0) {
    l.error(`Failed to load ${r.length} external diagrams`);
    for (const t of r)
      l.error(t);
    throw new Error(`Failed to load ${r.length} external diagrams`);
  }
}, "loadRegisteredDiagrams"), La = "graphics-document document";
function $e(e, r) {
  e.attr("role", La), r !== "" && e.attr("aria-roledescription", r);
}
a($e, "setA11yDiagramInfo");
function ke(e, r, t, i) {
  if (e.insert !== void 0) {
    if (t) {
      const o = `chart-desc-${i}`;
      e.attr("aria-describedby", o), e.insert("desc", ":first-child").attr("id", o).text(t);
    }
    if (r) {
      const o = `chart-title-${i}`;
      e.attr("aria-labelledby", o), e.insert("title", ":first-child").attr("id", o).text(r);
    }
  }
}
a(ke, "addSVGa11yTitleDescription");
var D, O = (D = class {
  constructor(r, t, i, o, d) {
    this.type = r, this.text = t, this.db = i, this.parser = o, this.renderer = d;
  }
  static async fromText(r, t = {}) {
    var u, h;
    const i = E(), o = ae(r, i);
    r = wr(r) + `
`;
    try {
      z(o);
    } catch {
      const c = ur(o);
      if (!c)
        throw new pr(`Diagram ${o} not found.`);
      const { id: v, diagram: I } = await c();
      x(v, I);
    }
    const { db: d, parser: s, renderer: m, init: n } = z(o);
    return s.parser && (s.parser.yy = d), (u = d.clear) == null || u.call(d), n == null || n(i), t.title && ((h = d.setDiagramTitle) == null || h.call(d, t.title)), await s.parse(r), new D(o, r, d, s, m);
  }
  async render(r, t) {
    await this.renderer.draw(this.text, r, t, this);
  }
  getParser() {
    return this.parser;
  }
  getType() {
    return this.type;
  }
}, a(D, "Diagram"), D), Z = [], Ia = /* @__PURE__ */ a(() => {
  Z.forEach((e) => {
    e();
  }), Z = [];
}, "attachFunctions"), Ma = /* @__PURE__ */ a((e) => e.replace(/^\s*%%(?!{)[^\n]+\n?/gm, "").trimStart(), "cleanupComments");
function ze(e) {
  const r = e.match(fr);
  if (!r)
    return {
      text: e,
      metadata: {}
    };
  let t = tr(r[1], {
    // To support config, we need JSON schema.
    // https://www.yaml.org/spec/1.2/spec.html#id2803231
    schema: ar
  }) ?? {};
  t = typeof t == "object" && !Array.isArray(t) ? t : {};
  const i = {};
  return t.displayMode && (i.displayMode = t.displayMode.toString()), t.title && (i.title = t.title.toString()), t.config && (i.config = t.config), {
    text: e.slice(r[0].length),
    metadata: i
  };
}
a(ze, "extractFrontMatter");
var Aa = /* @__PURE__ */ a((e) => e.replace(/\r\n?/g, `
`).replace(
  /<(\w+)([^>]*)>/g,
  (r, t, i) => "<" + t + i.replace(/="([^"]*)"/g, "='$1'") + ">"
), "cleanupText"), Fa = /* @__PURE__ */ a((e) => {
  const { text: r, metadata: t } = ze(e), { displayMode: i, title: o, config: d = {} } = t;
  return i && (d.gantt || (d.gantt = {}), d.gantt.displayMode = i), { title: o, config: d, text: r };
}, "processFrontmatter"), Ra = /* @__PURE__ */ a((e) => {
  const r = S.detectInit(e) ?? {}, t = S.detectDirective(e, "wrap");
  return Array.isArray(t) ? r.wrap = t.some(({ type: i }) => i === "wrap") : (t == null ? void 0 : t.type) === "wrap" && (r.wrap = !0), {
    text: br(e),
    directive: r
  };
}, "processDirectives");
function G(e) {
  const r = Aa(e), t = Fa(r), i = Ra(t.text), o = yr(t.config, i.directive);
  return e = Ma(i.text), {
    code: e,
    title: t.title,
    config: o
  };
}
a(G, "preprocessDiagram");
function Oe(e) {
  const r = new TextEncoder().encode(e), t = Array.from(r, (i) => String.fromCodePoint(i)).join("");
  return btoa(t);
}
a(Oe, "toBase64");
var Ca = 5e4, $a = "graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa", ka = "sandbox", za = "loose", Oa = "http://www.w3.org/2000/svg", Va = "http://www.w3.org/1999/xlink", Ga = "http://www.w3.org/1999/xhtml", Pa = "100%", Ha = "100%", qa = "border:0;margin:0;", Na = "margin:0", Ba = "allow-top-navigation-by-user-activation allow-popups", Ua = 'The "iframe" tag is not supported by your browser.', ja = ["foreignobject"], Xa = ["dominant-baseline"];
function P(e) {
  const r = G(e);
  return _(), gr(r.config ?? {}), r;
}
a(P, "processAndSetConfigs");
async function Ve(e, r) {
  L();
  try {
    const { code: t, config: i } = P(e);
    return { diagramType: (await Pe(t)).type, config: i };
  } catch (t) {
    if (r != null && r.suppressErrors)
      return !1;
    throw t;
  }
}
a(Ve, "parse");
var ee = /* @__PURE__ */ a((e, r, t = []) => `
.${e} ${r} { ${t.join(" !important; ")} !important; }`, "cssImportantStyles"), Ya = /* @__PURE__ */ a((e, r = /* @__PURE__ */ new Map()) => {
  var i;
  let t = "";
  if (e.themeCSS !== void 0 && (t += `
${e.themeCSS}`), e.fontFamily !== void 0 && (t += `
:root { --mermaid-font-family: ${e.fontFamily}}`), e.altFontFamily !== void 0 && (t += `
:root { --mermaid-alt-font-family: ${e.altFontFamily}}`), r instanceof Map) {
    const m = e.htmlLabels ?? ((i = e.flowchart) == null ? void 0 : i.htmlLabels) ? ["> *", "span"] : ["rect", "polygon", "ellipse", "circle", "path"];
    r.forEach((n) => {
      J(n.styles) || m.forEach((u) => {
        t += ee(n.id, u, n.styles);
      }), J(n.textStyles) || (t += ee(
        n.id,
        "tspan",
        ((n == null ? void 0 : n.textStyles) || []).map((u) => u.replace("color", "fill"))
      ));
    });
  }
  return t;
}, "createCssStyles"), Qa = /* @__PURE__ */ a((e, r, t, i) => {
  const o = Ya(e, t), d = vr(r, o, e.themeVariables);
  return _r(Tr(`${i}{${d}}`), xr);
}, "createUserStyles"), Wa = /* @__PURE__ */ a((e = "", r, t) => {
  let i = e;
  return !t && !r && (i = i.replace(
    /marker-end="url\([\d+./:=?A-Za-z-]*?#/g,
    'marker-end="url(#'
  )), i = Dr(i), i = i.replace(/<br>/g, "<br/>"), i;
}, "cleanUpSvgCode"), Ja = /* @__PURE__ */ a((e = "", r) => {
  var o, d;
  const t = (d = (o = r == null ? void 0 : r.viewBox) == null ? void 0 : o.baseVal) != null && d.height ? r.viewBox.baseVal.height + "px" : Ha, i = Oe(`<body style="${Na}">${e}</body>`);
  return `<iframe style="width:${Pa};height:${t};${qa}" src="data:text/html;charset=UTF-8;base64,${i}" sandbox="${Ba}">
  ${Ua}
</iframe>`;
}, "putIntoIFrame"), re = /* @__PURE__ */ a((e, r, t, i, o) => {
  const d = e.append("div");
  d.attr("id", t), i && d.attr("style", i);
  const s = d.append("svg").attr("id", r).attr("width", "100%").attr("xmlns", Oa);
  return o && s.attr("xmlns:xlink", o), s.append("g"), e;
}, "appendDivSvgG");
function V(e, r) {
  return e.append("iframe").attr("id", r).attr("style", "width: 100%; height: 100%;").attr("sandbox", "");
}
a(V, "sandboxedIframe");
var Ka = /* @__PURE__ */ a((e, r, t, i) => {
  var o, d, s;
  (o = e.getElementById(r)) == null || o.remove(), (d = e.getElementById(t)) == null || d.remove(), (s = e.getElementById(i)) == null || s.remove();
}, "removeExistingElements"), Za = /* @__PURE__ */ a(async function(e, r, t) {
  var N, B, U, j, X, Y;
  L();
  const i = P(r);
  r = i.code;
  const o = E();
  l.debug(o), r.length > ((o == null ? void 0 : o.maxTextSize) ?? Ca) && (r = $a);
  const d = "#" + e, s = "i" + e, m = "#" + s, n = "d" + e, u = "#" + n, h = /* @__PURE__ */ a(() => {
    const F = y(v ? m : u).node();
    F && "remove" in F && F.remove();
  }, "removeTempElements");
  let c = y("body");
  const v = o.securityLevel === ka, I = o.securityLevel === za, Xe = o.fontFamily;
  if (t !== void 0) {
    if (t && (t.innerHTML = ""), v) {
      const g = V(y(t), s);
      c = y(g.nodes()[0].contentDocument.body), c.node().style.margin = 0;
    } else
      c = y(t);
    re(c, e, n, `font-family: ${Xe}`, Va);
  } else {
    if (Ka(document, e, n, s), v) {
      const g = V(y("body"), s);
      c = y(g.nodes()[0].contentDocument.body), c.node().style.margin = 0;
    } else
      c = y("body");
    re(c, e, n);
  }
  let f, M;
  try {
    f = await O.fromText(r, { title: i.title });
  } catch (g) {
    if (o.suppressErrorRendering)
      throw h(), g;
    f = await O.fromText("error"), M = g;
  }
  const Ye = c.select(u).node(), A = f.type, H = Ye.firstChild, Qe = H.firstChild, We = (B = (N = f.renderer).getClasses) == null ? void 0 : B.call(N, r, f), Je = Qa(o, A, We, d), q = document.createElement("style");
  q.innerHTML = Je, H.insertBefore(q, Qe);
  try {
    await f.renderer.draw(r, e, Q.version, f);
  } catch (g) {
    throw o.suppressErrorRendering ? h() : Pt.draw(r, e, Q.version), g;
  }
  const Ke = c.select(`${u} svg`), Ze = (j = (U = f.db).getAccTitle) == null ? void 0 : j.call(U), er = (Y = (X = f.db).getAccDescription) == null ? void 0 : Y.call(X);
  He(A, Ke, Ze, er), c.select(`[id="${e}"]`).selectAll("foreignobject > *").attr("xmlns", Ga);
  let w = c.select(u).node().innerHTML;
  if (l.debug("config.arrowMarkerAbsolute", o.arrowMarkerAbsolute), w = Wa(w, v, lr(o.arrowMarkerAbsolute)), v) {
    const g = c.select(u + " svg").node();
    w = Ja(w, g);
  } else I || (w = Er.sanitize(w, {
    ADD_TAGS: ja,
    ADD_ATTR: Xa,
    HTML_INTEGRATION_POINTS: { foreignobject: !0 }
  }));
  if (Ia(), M)
    throw M;
  return h(), {
    diagramType: A,
    svg: w,
    bindFunctions: f.db.bindFunctions
  };
}, "render");
function Ge(e = {}) {
  var i;
  const r = nr({}, e);
  r != null && r.fontFamily && !((i = r.themeVariables) != null && i.fontFamily) && (r.themeVariables || (r.themeVariables = {}), r.themeVariables.fontFamily = r.fontFamily), sr(r), r != null && r.theme && r.theme in R ? r.themeVariables = R[r.theme].getThemeVariables(
    r.themeVariables
  ) : r && (r.themeVariables = R.default.getThemeVariables(r.themeVariables));
  const t = typeof r == "object" ? cr(r) : ie();
  te(t.logLevel), L();
}
a(Ge, "initialize");
var Pe = /* @__PURE__ */ a((e, r = {}) => {
  const { code: t } = G(e);
  return O.fromText(t, r);
}, "getDiagramFromText");
function He(e, r, t, i) {
  $e(r, e), ke(r, t, i, r.attr("id"));
}
a(He, "addA11yInfo");
var b = Object.freeze({
  render: Za,
  parse: Ve,
  getDiagramFromText: Pe,
  initialize: Ge,
  getConfig: E,
  setConfig: dr,
  getSiteConfig: ie,
  updateSiteConfig: or,
  reset: /* @__PURE__ */ a(() => {
    _();
  }, "reset"),
  globalReset: /* @__PURE__ */ a(() => {
    _(W);
  }, "globalReset"),
  defaultConfig: W
});
te(E().logLevel);
_(E());
var ei = /* @__PURE__ */ a((e, r, t) => {
  l.warn(e), oe(e) ? (t && t(e.str, e.hash), r.push({ ...e, message: e.str, error: e })) : (t && t(e), e instanceof Error && r.push({
    str: e.message,
    message: e.message,
    hash: e.name,
    error: e
  }));
}, "handleError"), qe = /* @__PURE__ */ a(async function(e = {
  querySelector: ".mermaid"
}) {
  try {
    await ri(e);
  } catch (r) {
    if (oe(r) && l.error(r.str), p.parseError && p.parseError(r), !e.suppressErrors)
      throw l.error("Use the suppressErrors option to suppress these errors"), r;
  }
}, "run"), ri = /* @__PURE__ */ a(async function({ postRenderCallback: e, querySelector: r, nodes: t } = {
  querySelector: ".mermaid"
}) {
  const i = b.getConfig();
  l.debug(`${e ? "" : "No "}Callback function found`);
  let o;
  if (t)
    o = t;
  else if (r)
    o = document.querySelectorAll(r);
  else
    throw new Error("Nodes and querySelector are both undefined");
  l.debug(`Found ${o.length} diagrams`), (i == null ? void 0 : i.startOnLoad) !== void 0 && (l.debug("Start On Load: " + (i == null ? void 0 : i.startOnLoad)), b.updateSiteConfig({ startOnLoad: i == null ? void 0 : i.startOnLoad }));
  const d = new S.InitIDGenerator(i.deterministicIds, i.deterministicIDSeed);
  let s;
  const m = [];
  for (const n of Array.from(o)) {
    if (l.info("Rendering diagram: " + n.id), n.getAttribute("data-processed"))
      continue;
    n.setAttribute("data-processed", "true");
    const u = `mermaid-${d.next()}`;
    s = n.innerHTML, s = Sr(S.entityDecode(s)).trim().replace(/<br\s*\/?>/gi, "<br/>");
    const h = S.detectInit(s);
    h && l.debug("Detected early reinit: ", h);
    try {
      const { svg: c, bindFunctions: v } = await je(u, s, n);
      n.innerHTML = c, e && await e(u), v && v(n);
    } catch (c) {
      ei(c, m, p.parseError);
    }
  }
  if (m.length > 0)
    throw m[0];
}, "runThrowsErrors"), Ne = /* @__PURE__ */ a(function(e) {
  b.initialize(e);
}, "initialize"), ti = /* @__PURE__ */ a(async function(e, r, t) {
  l.warn("mermaid.init is deprecated. Please use run instead."), e && Ne(e);
  const i = { postRenderCallback: t, querySelector: ".mermaid" };
  typeof r == "string" ? i.querySelector = r : r && (r instanceof HTMLElement ? i.nodes = [r] : i.nodes = r), await qe(i);
}, "init"), ai = /* @__PURE__ */ a(async (e, {
  lazyLoad: r = !0
} = {}) => {
  L(), k(...e), r === !1 && await Ta();
}, "registerExternalDiagrams"), Be = /* @__PURE__ */ a(function() {
  if (p.startOnLoad) {
    const { startOnLoad: e } = b.getConfig();
    e && p.run().catch((r) => l.error("Mermaid failed to initialize", r));
  }
}, "contentLoaded");
typeof document < "u" && window.addEventListener("load", Be, !1);
var ii = /* @__PURE__ */ a(function(e) {
  p.parseError = e;
}, "setParseErrorHandler"), T = [], C = !1, Ue = /* @__PURE__ */ a(async () => {
  if (!C) {
    for (C = !0; T.length > 0; ) {
      const e = T.shift();
      if (e)
        try {
          await e();
        } catch (r) {
          l.error("Error executing queue", r);
        }
    }
    C = !1;
  }
}, "executeQueue"), oi = /* @__PURE__ */ a(async (e, r) => new Promise((t, i) => {
  const o = /* @__PURE__ */ a(() => new Promise((d, s) => {
    b.parse(e, r).then(
      (m) => {
        d(m), t(m);
      },
      (m) => {
        var n;
        l.error("Error parsing", m), (n = p.parseError) == null || n.call(p, m), s(m), i(m);
      }
    );
  }), "performCall");
  T.push(o), Ue().catch(i);
}), "parse"), je = /* @__PURE__ */ a((e, r, t) => new Promise((i, o) => {
  const d = /* @__PURE__ */ a(() => new Promise((s, m) => {
    b.render(e, r, t).then(
      (n) => {
        s(n), i(n);
      },
      (n) => {
        var u;
        l.error("Error parsing", n), (u = p.parseError) == null || u.call(p, n), m(n), o(n);
      }
    );
  }), "performCall");
  T.push(d), Ue().catch(o);
}), "render"), di = /* @__PURE__ */ a(() => Object.keys($).map((e) => ({
  id: e
})), "getRegisteredDiagramsMetadata"), p = {
  startOnLoad: !0,
  mermaidAPI: b,
  parse: oi,
  render: je,
  init: ti,
  run: qe,
  registerExternalDiagrams: ai,
  registerLayoutLoaders: ir,
  initialize: Ne,
  parseError: void 0,
  contentLoaded: Be,
  setParseErrorHandler: ii,
  detectType: ae,
  registerIconPacks: hr,
  getRegisteredDiagramsMetadata: di
}, Ti = p;
/*! Check if previously processed */
/*!
 * Wait for document loaded before starting the execution
 */
export {
  Ti as default
};
