import { md5Base64 } from "../../lib/utils"; import CacheLRU from "../../lib/cache_lru"; let idCount = 0; let getId = () => `mermaid-graph-${idCount++}`; const fontAwesomeVersion = "5.15.4"; const cache = new CacheLRU(25); /** * Renders SVG graph from mermaid definition. */ export function renderMermaid(definition, options) { const hash = md5Base64(definition); const svg = cache.get(hash); if (svg) { return Promise.resolve(svg); } return importMermaid().then((mermaid) => { injectFontAwesomeIfNeeded(definition); // There is no way to specify options for individual render, so // we call initialize every time to set the global options. // See https://github.com/mermaid-js/mermaid/issues/5427 mermaid.initialize({ startOnLoad: false, ...options }); return mermaid .render(getId(), definition) .then(({ svg }) => { cache.set(hash, svg); return svg; }) .catch((error) => { return `