diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-16 01:30:44 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-16 01:39:26 -0400 |
| commit | 56e16e29db55dae84549229d24b971f8bcf7da21 (patch) | |
| tree | 675c22c953eca3257ad5011ba35a8add35d34d9f /docs/api/mermaid/mermaid-init.js | |
| parent | 54a62a3ff06fc132b3ea8506efbce06c5e0869fe (diff) | |
API docs rewrite.
Having the whole API in a single file was starting to feel very cramped and constraining. This rewrite breaks it out into sections; as a side effect, the docs are now about 2.5x as long as they were, as the rewrite allows more space for each idea without crowding the page.
The docs are best read by running `tools/docs-api`.
Diffstat (limited to 'docs/api/mermaid/mermaid-init.js')
| -rw-r--r-- | docs/api/mermaid/mermaid-init.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/docs/api/mermaid/mermaid-init.js b/docs/api/mermaid/mermaid-init.js new file mode 100644 index 0000000..15a7f4e --- /dev/null +++ b/docs/api/mermaid/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(); + } + }); + } +})(); |
