diff --git a/src/components/Mermaid.astro b/src/components/Mermaid.astro index af3768e..313e254 100644 --- a/src/components/Mermaid.astro +++ b/src/components/Mermaid.astro @@ -6,30 +6,27 @@ const { default: mermaid } = await import('mermaid'); const draw = async () => { const dark = document.documentElement.dataset.theme === 'dark'; - // In the dark, the page's own soft greys rather than Mermaid's high-contrast dark theme. + // Both themes draw with the page's own colours. Each redraw sets every variable, since + // Mermaid keeps what an earlier initialize set: a dark redraw would leak into the light one. const color = (name: string) => getComputedStyle(document.documentElement).getPropertyValue(name).trim(); - mermaid.initialize( - dark - ? { - startOnLoad: false, - theme: 'base', - themeVariables: { - darkMode: true, - background: color('--surface'), - primaryColor: color('--code-bg'), - primaryTextColor: color('--text'), - primaryBorderColor: color('--border'), - secondaryColor: color('--accent-soft'), - tertiaryColor: color('--surface'), - lineColor: color('--muted'), - textColor: color('--text'), - clusterBkg: color('--bg'), - clusterBorder: color('--border'), - edgeLabelBackground: color('--surface'), - }, - } - : { startOnLoad: false, theme: 'default' }, - ); + mermaid.initialize({ + startOnLoad: false, + theme: 'base', + themeVariables: { + darkMode: dark, + background: color('--surface'), + primaryColor: color('--code-bg'), + primaryTextColor: color('--text'), + primaryBorderColor: color('--muted'), + secondaryColor: color('--accent-soft'), + tertiaryColor: color('--surface'), + lineColor: color('--muted'), + textColor: color('--text'), + clusterBkg: color('--bg'), + clusterBorder: color('--border'), + edgeLabelBackground: color('--surface'), + }, + }); for (const diagram of diagrams) { diagram.removeAttribute('data-processed'); diagram.textContent = diagram.dataset.source!;