Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions src/components/Mermaid.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down