summaryrefslogtreecommitdiffstats
path: root/docs/book/mermaid-init.js
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-07-12 10:51:21 +0200
committerrtkay123 <dev@kanjala.com>2025-07-12 10:51:21 +0200
commit1dc7dccb7536f6831de570f535e6911384e1a7e4 (patch)
treeffa5dcfafa5a8807bc94948e02c831c2896e3ee7 /docs/book/mermaid-init.js
parent757458695c7bef1a395babb47f28cccf19066672 (diff)
downloadsellershut-1dc7dccb7536f6831de570f535e6911384e1a7e4.tar.bz2
sellershut-1dc7dccb7536f6831de570f535e6911384e1a7e4.zip
docs: book
Diffstat (limited to 'docs/book/mermaid-init.js')
-rw-r--r--docs/book/mermaid-init.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/book/mermaid-init.js b/docs/book/mermaid-init.js
new file mode 100644
index 0000000..15a7f4e
--- /dev/null
+++ b/docs/book/mermaid-init.js
@@ -0,0 +1,35 @@
+(() => {
+ 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();
+ }
+ });
+ }
+})();