Skip to content

Commit

Permalink
refactor(#194): mermaid in client script file
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Jan 21, 2025
1 parent 1385a85 commit eb1bc83
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/routes/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ router.get(/.*/, async (req: Request, res: Response) => {
${config.scripts ? `<script type="text/javascript">${config.scripts}</script>` : ''}
<script type="module">
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="module" src="/static/client.mjs"></script>
</html>
`);
Expand Down
19 changes: 19 additions & 0 deletions static/client.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
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();
}
}
try {
darkModePreference.addEventListener('change', () => updateTheme());
} catch {
try {
// deprecated method for backward compatibility
darkModePreference.addEventListener(() => updateTheme());
} catch {}
}

function viv_scrollTo(value) {
let line = parseInt(value);
while (line) {
Expand Down

0 comments on commit eb1bc83

Please sign in to comment.