mermaid.js 656 B

12345678910111213141516171819202122232425262728293031
  1. import mermaid from "mermaid";
  2. let initialized = false;
  3. export function initMermaid() {
  4. if (initialized) return;
  5. mermaid.initialize({
  6. startOnLoad: false,
  7. theme: "base",
  8. securityLevel: "loose",
  9. flowchart: {
  10. curve: "basis",
  11. htmlLabels: true,
  12. useMaxWidth: false,
  13. },
  14. themeVariables: {
  15. primaryColor: "#dbeafe",
  16. primaryBorderColor: "#2563eb",
  17. lineColor: "#1f2937",
  18. fontFamily: "IBM Plex Sans",
  19. textColor: "#0f172a",
  20. },
  21. });
  22. initialized = true;
  23. }
  24. export async function renderMermaid(code) {
  25. initMermaid();
  26. const id = `m-${Date.now()}`;
  27. return mermaid.render(id, code);
  28. }