let _initialized = false; export async function renderMermaid(def: string): Promise { const mermaid = (await import("mermaid")).default; if (!_initialized) { mermaid.initialize({ startOnLoad: false, theme: "default" }); _initialized = true; } const id = `mermaid-${Math.random().toString(36).slice(2)}`; const container = document.createElement("div"); container.style.position = "absolute"; container.style.left = "-9999px"; document.body.appendChild(container); try { const { svg } = await mermaid.render(id, def, container); return svg; } finally { container.remove(); document.getElementById(id)?.remove(); } }