Skip to content

Commit

Permalink
feat(#132): pseudo-dynamically update mermaid theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Aug 26, 2024
1 parent 1d24c15 commit d3a77ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/routes/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ router.get(/.*/, async (req: Request, res: Response) => {
import mermaid from '/static/mermaid/mermaid.esm.min.mjs';
const darkModePreference = window.matchMedia("(prefers-color-scheme: dark)");
mermaid.initialize({ startOnLoad: true, theme: darkModePreference.matches ? 'dark' : 'default' })
function updateTheme() {
if (document.getElementsByClassName('mermaid').length > 0) {
window.location.reload()
}
}
darkModePreference.addEventListener("change", () => updateTheme());
// deprecated method for backward compatibility
darkModePreference.addEventListener(() => updateTheme());
</script>
<script type="text/javascript" src="/static/client.js"></script>
</html>
Expand Down

0 comments on commit d3a77ec

Please sign in to comment.