import { c as e } from "../../sanitize-uWpY18N9.js";
import { n as t, t as n } from "../../utils-CSEWuKHo.js";
import { n as r } from "../../svg-C7L0aW2M.js";
//#region src/visualization/mermaid-diagram/index.ts
var i = null, a = 0;
async function o() {
	return i === null && (i = import("../../mermaid.core-BExDWHo9.js").then((e) => (e.default.initialize({
		startOnLoad: !1,
		securityLevel: "strict",
		theme: "base",
		fontFamily: "inherit",
		logLevel: "error"
	}), e))), i;
}
function s(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 c = class {
	el;
	diagramId;
	theme;
	onRenderStart;
	onRenderComplete;
	onRenderError;
	content;
	svgElement = null;
	destroyed = !1;
	constructor(e) {
		a += 1, this.diagramId = t(`cmm-mermaid-${String(a)}`), this.content = e.content, this.theme = e.theme ?? "auto", this.onRenderStart = e.onRenderStart, this.onRenderComplete = e.onRenderComplete, this.onRenderError = e.onRenderError, this.el = document.createElement("div"), this.el.id = this.diagramId, this.el.className = this.buildClassName(e.className), this.showLoading(), n(e.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 t = `${this.diagramId}-svg`;
		try {
			let n = await o();
			if (this.isDestroyed()) return;
			let r = s(this.theme);
			n.default.initialize({
				startOnLoad: !1,
				securityLevel: "strict",
				theme: "base",
				themeVariables: r,
				fontFamily: "inherit",
				logLevel: "error"
			});
			let { svg: i } = await n.default.render(t, this.content);
			if (this.isDestroyed()) return;
			e(this.el, i, { allowSvg: !0 });
			let a = this.el.querySelector("svg");
			a !== null && (this.svgElement = a, a.classList.add("cmm-mermaid-diagram__svg"), a.removeAttribute("height"), a.style.maxWidth = "100%", a.style.height = "auto", this.onRenderComplete?.(a));
		} catch (e) {
			if (this.isDestroyed()) return;
			u(t);
			let n = e instanceof Error ? e : Error(String(e));
			this.showError(n), this.onRenderError?.(n);
		}
	}
	showLoading() {
		let e = document.createElement("div");
		e.className = "cmm-mermaid-diagram__loading";
		let t = document.createElement("div");
		t.className = "cmm-mermaid-diagram__spinner";
		let n = document.createElement("span");
		n.className = "cmm-mermaid-diagram__loading-text", n.textContent = "Rendering diagram...", e.append(t, n), this.el.replaceChildren(e);
	}
	showError(e) {
		let t = document.createElement("div");
		t.className = "cmm-mermaid-diagram__error";
		let n = document.createElement("div");
		n.className = "cmm-mermaid-diagram__error-icon", r(n, {
			width: 24,
			height: 24,
			viewBox: "0 0 24 24",
			fill: "none",
			stroke: "currentColor",
			"stroke-width": 2
		}, [
			{
				tag: "circle",
				attrs: {
					cx: 12,
					cy: 12,
					r: 10
				},
				children: []
			},
			{
				tag: "line",
				attrs: {
					x1: 12,
					y1: 8,
					x2: 12,
					y2: 12
				},
				children: []
			},
			{
				tag: "line",
				attrs: {
					x1: 12,
					y1: 16,
					x2: 12.01,
					y2: 16
				},
				children: []
			}
		]);
		let i = document.createElement("div");
		i.className = "cmm-mermaid-diagram__error-title", i.textContent = "Failed to render diagram";
		let a = document.createElement("div");
		a.className = "cmm-mermaid-diagram__error-message", a.textContent = e.message;
		let o = document.createElement("pre");
		o.className = "cmm-mermaid-diagram__error-source", o.textContent = this.content, t.append(n, i, a, o), this.el.replaceChildren(t);
	}
	buildClassName(e) {
		let t = ["cmm-mermaid-diagram"];
		return e !== void 0 && t.push(e), t.join(" ");
	}
	isDestroyed() {
		return this.destroyed;
	}
};
async function l(e, t = "auto") {
	let n = await o(), r = s(t);
	n.default.initialize({
		startOnLoad: !1,
		securityLevel: "strict",
		theme: "base",
		themeVariables: r,
		fontFamily: "inherit",
		logLevel: "error"
	}), a += 1;
	let i = `cmm-mermaid-render-${String(a)}`;
	try {
		let { svg: t } = await n.default.render(i, e);
		return t;
	} catch (e) {
		throw u(i), e;
	}
}
function u(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 { c as MermaidDiagram, l as renderMermaidToString };

//# sourceMappingURL=index.js.map