import { n as e, t } from "../../utils-C_mWfcFX.js";
//#region src/visualization/mermaid-diagram/index.ts
var n = null, r = 0;
async function i() {
	return n === null && (n = import("../../mermaid.core-beWmNAWY.js").then((e) => (e.default.initialize({
		startOnLoad: !1,
		securityLevel: "strict",
		theme: "base",
		fontFamily: "inherit",
		logLevel: "error"
	}), e))), n;
}
function a(e) {
	let t = e === "dark" || e === "auto" && document.documentElement.classList.contains("dark"), n = e === "auto" ? getComputedStyle(document.documentElement) : null, r = (e, t) => {
		if (n !== null) {
			let t = n.getPropertyValue(e).trim();
			if (t !== "") return `hsl(${t})`;
		}
		return t;
	};
	return t ? {
		primaryColor: r("--primary", "#0ea5e9"),
		primaryTextColor: r("--primary-foreground", "#ffffff"),
		primaryBorderColor: r("--border", "#374151"),
		secondaryColor: r("--secondary", "#1f2937"),
		secondaryTextColor: r("--secondary-foreground", "#f3f4f6"),
		secondaryBorderColor: r("--border", "#374151"),
		tertiaryColor: r("--muted", "#374151"),
		tertiaryTextColor: r("--muted-foreground", "#9ca3af"),
		tertiaryBorderColor: r("--border", "#374151"),
		lineColor: r("--border", "#374151"),
		textColor: r("--foreground", "#f9fafb"),
		mainBkg: r("--background", "#111827"),
		nodeBkg: r("--card", "#1f2937"),
		nodeBorder: r("--border", "#374151"),
		clusterBkg: r("--muted", "#1f2937"),
		clusterBorder: r("--border", "#374151"),
		defaultLinkColor: r("--primary", "#0ea5e9"),
		titleColor: r("--foreground", "#f9fafb"),
		edgeLabelBackground: r("--background", "#111827"),
		actorBkg: r("--card", "#1f2937"),
		actorBorder: r("--border", "#374151"),
		actorTextColor: r("--foreground", "#f9fafb"),
		actorLineColor: r("--border", "#374151"),
		signalColor: r("--foreground", "#f9fafb"),
		signalTextColor: r("--foreground", "#f9fafb"),
		labelBoxBkgColor: r("--card", "#1f2937"),
		labelBoxBorderColor: r("--border", "#374151"),
		labelTextColor: r("--foreground", "#f9fafb"),
		loopTextColor: r("--foreground", "#f9fafb"),
		noteBorderColor: r("--border", "#374151"),
		noteBkgColor: r("--muted", "#374151"),
		noteTextColor: r("--muted-foreground", "#9ca3af"),
		activationBorderColor: r("--primary", "#0ea5e9"),
		activationBkgColor: r("--primary", "#0ea5e9"),
		sequenceNumberColor: r("--primary-foreground", "#ffffff"),
		sectionBkgColor: r("--muted", "#1f2937"),
		altSectionBkgColor: r("--card", "#1f2937"),
		sectionBkgColor2: r("--muted", "#374151"),
		taskBorderColor: r("--primary", "#0ea5e9"),
		taskBkgColor: r("--primary", "#0ea5e9"),
		taskTextColor: r("--primary-foreground", "#ffffff"),
		taskTextLightColor: r("--primary-foreground", "#ffffff"),
		taskTextOutsideColor: r("--foreground", "#f9fafb"),
		taskTextClickableColor: r("--primary", "#0ea5e9"),
		activeTaskBorderColor: r("--primary", "#0ea5e9"),
		activeTaskBkgColor: r("--primary", "#0ea5e9"),
		gridColor: r("--border", "#374151"),
		doneTaskBkgColor: r("--muted", "#374151"),
		doneTaskBorderColor: r("--border", "#374151"),
		critBorderColor: r("--destructive", "#ef4444"),
		critBkgColor: r("--destructive", "#ef4444"),
		todayLineColor: r("--primary", "#0ea5e9"),
		personBorder: r("--border", "#374151"),
		personBkg: r("--card", "#1f2937")
	} : {
		primaryColor: r("--primary", "#0ea5e9"),
		primaryTextColor: r("--foreground", "#1e293b"),
		primaryBorderColor: r("--border", "#cbd5e1"),
		secondaryColor: r("--secondary", "#f1f5f9"),
		secondaryTextColor: r("--secondary-foreground", "#1e293b"),
		secondaryBorderColor: r("--border", "#cbd5e1"),
		tertiaryColor: r("--muted", "#f8fafc"),
		tertiaryTextColor: r("--muted-foreground", "#64748b"),
		tertiaryBorderColor: r("--border", "#cbd5e1"),
		lineColor: r("--border", "#94a3b8"),
		textColor: r("--foreground", "#1e293b"),
		mainBkg: r("--background", "#ffffff"),
		nodeBkg: r("--card", "#f8fafc"),
		nodeBorder: r("--border", "#cbd5e1"),
		clusterBkg: r("--muted", "#f9fafb"),
		clusterBorder: r("--border", "#e5e7eb"),
		defaultLinkColor: r("--primary", "#0ea5e9"),
		titleColor: r("--foreground", "#111827"),
		edgeLabelBackground: r("--background", "#ffffff"),
		actorBkg: r("--card", "#ffffff"),
		actorBorder: r("--border", "#e5e7eb"),
		actorTextColor: r("--foreground", "#111827"),
		actorLineColor: r("--border", "#e5e7eb"),
		signalColor: r("--foreground", "#111827"),
		signalTextColor: r("--foreground", "#111827"),
		labelBoxBkgColor: r("--card", "#ffffff"),
		labelBoxBorderColor: r("--border", "#e5e7eb"),
		labelTextColor: r("--foreground", "#111827"),
		loopTextColor: r("--foreground", "#111827"),
		noteBorderColor: r("--border", "#e5e7eb"),
		noteBkgColor: r("--muted", "#f9fafb"),
		noteTextColor: r("--muted-foreground", "#6b7280"),
		activationBorderColor: r("--primary", "#0ea5e9"),
		activationBkgColor: r("--primary", "#0ea5e9"),
		sequenceNumberColor: r("--primary-foreground", "#ffffff"),
		sectionBkgColor: r("--muted", "#f9fafb"),
		altSectionBkgColor: r("--card", "#ffffff"),
		sectionBkgColor2: r("--muted", "#f3f4f6"),
		taskBorderColor: r("--primary", "#0ea5e9"),
		taskBkgColor: r("--primary", "#0ea5e9"),
		taskTextColor: r("--primary-foreground", "#ffffff"),
		taskTextLightColor: r("--primary-foreground", "#ffffff"),
		taskTextOutsideColor: r("--foreground", "#111827"),
		taskTextClickableColor: r("--primary", "#0ea5e9"),
		activeTaskBorderColor: r("--primary", "#0ea5e9"),
		activeTaskBkgColor: r("--primary", "#0ea5e9"),
		gridColor: r("--border", "#e5e7eb"),
		doneTaskBkgColor: r("--muted", "#f3f4f6"),
		doneTaskBorderColor: r("--border", "#e5e7eb"),
		critBorderColor: r("--destructive", "#ef4444"),
		critBkgColor: r("--destructive", "#ef4444"),
		todayLineColor: r("--primary", "#0ea5e9"),
		personBorder: r("--border", "#e5e7eb"),
		personBkg: r("--card", "#ffffff")
	};
}
var o = class {
	el;
	diagramId;
	theme;
	onRenderStart;
	onRenderComplete;
	onRenderError;
	content;
	svgElement = null;
	destroyed = !1;
	constructor(n) {
		r += 1, this.diagramId = e(`cmm-mermaid-${String(r)}`), this.content = n.content, this.theme = n.theme ?? "auto", this.onRenderStart = n.onRenderStart, this.onRenderComplete = n.onRenderComplete, this.onRenderError = n.onRenderError, this.el = document.createElement("div"), this.el.id = this.diagramId, this.el.className = this.buildClassName(n.className), this.showLoading(), t(n.container).appendChild(this.el), this.render();
	}
	async update(e) {
		this.isDestroyed() || (this.content = e, this.showLoading(), await this.render());
	}
	destroy() {
		this.destroyed = !0, this.svgElement = null, this.el.remove();
	}
	getSvg() {
		return this.svgElement;
	}
	toSvgString() {
		return this.svgElement === null ? null : this.svgElement.outerHTML;
	}
	toDataUrl() {
		let e = this.toSvgString();
		return e === null ? null : `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`;
	}
	async render() {
		if (this.isDestroyed()) return;
		this.onRenderStart?.();
		let e = `${this.diagramId}-svg`;
		try {
			let t = await i();
			if (this.isDestroyed()) return;
			let n = a(this.theme);
			t.default.initialize({
				startOnLoad: !1,
				securityLevel: "strict",
				theme: "base",
				themeVariables: n,
				fontFamily: "inherit",
				logLevel: "error"
			});
			let { svg: r } = await t.default.render(e, this.content);
			if (this.isDestroyed()) return;
			this.el.innerHTML = "", this.el.innerHTML = r;
			let o = this.el.querySelector("svg");
			o !== null && (this.svgElement = o, o.classList.add("cmm-mermaid-diagram__svg"), o.removeAttribute("height"), o.style.maxWidth = "100%", o.style.height = "auto", this.onRenderComplete?.(o));
		} catch (t) {
			if (this.isDestroyed()) return;
			c(e);
			let n = t instanceof Error ? t : Error(String(t));
			this.showError(n), this.onRenderError?.(n);
		}
	}
	showLoading() {
		this.el.innerHTML = "\n      <div class=\"cmm-mermaid-diagram__loading\">\n        <div class=\"cmm-mermaid-diagram__spinner\"></div>\n        <span class=\"cmm-mermaid-diagram__loading-text\">Rendering diagram...</span>\n      </div>\n    ";
	}
	showError(e) {
		let t = this.escapeHtml(e.message);
		this.el.innerHTML = `
      <div class="cmm-mermaid-diagram__error">
        <div class="cmm-mermaid-diagram__error-icon">
          <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <circle cx="12" cy="12" r="10"/>
            <line x1="12" y1="8" x2="12" y2="12"/>
            <line x1="12" y1="16" x2="12.01" y2="16"/>
          </svg>
        </div>
        <div class="cmm-mermaid-diagram__error-title">Failed to render diagram</div>
        <div class="cmm-mermaid-diagram__error-message">${t}</div>
        <pre class="cmm-mermaid-diagram__error-source">${this.escapeHtml(this.content)}</pre>
      </div>
    `;
	}
	escapeHtml(e) {
		return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
	}
	buildClassName(e) {
		let t = ["cmm-mermaid-diagram"];
		return e !== void 0 && t.push(e), t.join(" ");
	}
	isDestroyed() {
		return this.destroyed;
	}
};
async function s(e, t = "auto") {
	let n = await i(), o = a(t);
	n.default.initialize({
		startOnLoad: !1,
		securityLevel: "strict",
		theme: "base",
		themeVariables: o,
		fontFamily: "inherit",
		logLevel: "error"
	}), r += 1;
	let s = `cmm-mermaid-render-${String(r)}`;
	try {
		let { svg: t } = await n.default.render(s, e);
		return t;
	} catch (e) {
		throw c(s), e;
	}
}
function c(e) {
	let t = [
		e,
		`d${e}`,
		`${e}-d`
	];
	for (let e of t) {
		let t = document.getElementById(e);
		t && t.parentElement === document.body && t.remove();
	}
}
//#endregion
export { o as MermaidDiagram, s as renderMermaidToString };

//# sourceMappingURL=index.js.map