Skip to content

Commit

Permalink
deploy: 1fbc4d8
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Sep 9, 2024
1 parent 56e6462 commit 80aa000
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion mermaid-init.js
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
mermaid.initialize({startOnLoad:true});
(() => {
const darkThemes = ['ayu', 'navy', 'coal'];
const lightThemes = ['light', 'rust'];

const classList = document.getElementsByTagName('html')[0].classList;

let lastThemeWasLight = true;
for (const cssClass of classList) {
if (darkThemes.includes(cssClass)) {
lastThemeWasLight = false;
break;
}
}

const theme = lastThemeWasLight ? 'default' : 'dark';
mermaid.initialize({ startOnLoad: true, theme });

// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page

for (const darkTheme of darkThemes) {
document.getElementById(darkTheme).addEventListener('click', () => {
if (lastThemeWasLight) {
window.location.reload();
}
});
}

for (const lightTheme of lightThemes) {
document.getElementById(lightTheme).addEventListener('click', () => {
if (!lastThemeWasLight) {
window.location.reload();
}
});
}
})();

0 comments on commit 80aa000

Please sign in to comment.