2023-03-22 20:29:17 +03:00
|
|
|
|
<!-- mermaid-js loader -->
|
|
|
|
|
<script type="text/javascript">
|
2022-11-04 23:28:44 +03:00
|
|
|
|
(function () {
|
2021-12-12 21:37:10 +03:00
|
|
|
|
function updateMermaid(event) {
|
2023-03-22 20:29:17 +03:00
|
|
|
|
if (event.source === window && event.data && event.data.direction === ModeToggle.ID) {
|
2021-12-12 21:37:10 +03:00
|
|
|
|
const mode = event.data.message;
|
|
|
|
|
|
2023-03-22 20:29:17 +03:00
|
|
|
|
if (typeof mermaid === 'undefined') {
|
2021-12-12 21:37:10 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 20:29:17 +03:00
|
|
|
|
let expectedTheme = mode === ModeToggle.DARK_MODE ? 'dark' : 'default';
|
|
|
|
|
let config = { theme: expectedTheme };
|
2021-12-12 21:37:10 +03:00
|
|
|
|
|
|
|
|
|
/* Re-render the SVG › <https://github.com/mermaid-js/mermaid/issues/311#issuecomment-332557344> */
|
2023-03-22 20:29:17 +03:00
|
|
|
|
$('.mermaid').each(function () {
|
2021-12-12 21:37:10 +03:00
|
|
|
|
let svgCode = $(this).prev().children().html();
|
2023-03-22 20:29:17 +03:00
|
|
|
|
$(this).removeAttr('data-processed');
|
2021-12-12 21:37:10 +03:00
|
|
|
|
$(this).html(svgCode);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mermaid.initialize(config);
|
2023-03-22 20:29:17 +03:00
|
|
|
|
mermaid.init(undefined, '.mermaid');
|
2021-12-12 21:37:10 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 20:29:17 +03:00
|
|
|
|
let initTheme = 'default';
|
|
|
|
|
const html = document.documentElement;
|
2020-12-09 21:42:46 +03:00
|
|
|
|
|
2023-03-22 20:29:17 +03:00
|
|
|
|
if (
|
|
|
|
|
(html.hasAttribute('data-mode') && html.getAttribute('data-mode') === 'dark') ||
|
|
|
|
|
(!html.hasAttribute('data-mode') && window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
|
|
|
) {
|
|
|
|
|
initTheme = 'dark';
|
2020-12-10 14:49:43 +03:00
|
|
|
|
}
|
2020-12-09 21:42:46 +03:00
|
|
|
|
|
2020-12-10 14:49:43 +03:00
|
|
|
|
let mermaidConf = {
|
2023-03-22 20:29:17 +03:00
|
|
|
|
theme: initTheme /* <default|dark|forest|neutral> */
|
2020-12-10 14:49:43 +03:00
|
|
|
|
};
|
2020-12-09 21:42:46 +03:00
|
|
|
|
|
2022-11-04 23:28:44 +03:00
|
|
|
|
/* Create mermaid tag */
|
2023-03-22 20:29:17 +03:00
|
|
|
|
document.querySelectorAll('pre>code.language-mermaid').forEach((elem) => {
|
|
|
|
|
const svgCode = elem.textContent;
|
|
|
|
|
const backup = elem.parentElement;
|
|
|
|
|
backup.classList.add('unloaded');
|
|
|
|
|
/* create mermaid node */
|
|
|
|
|
let mermaid = document.createElement('pre');
|
|
|
|
|
mermaid.classList.add('mermaid');
|
|
|
|
|
const text = document.createTextNode(svgCode);
|
|
|
|
|
mermaid.appendChild(text);
|
|
|
|
|
backup.after(mermaid);
|
2020-12-10 14:49:43 +03:00
|
|
|
|
});
|
2020-12-09 21:42:46 +03:00
|
|
|
|
|
2020-12-10 14:49:43 +03:00
|
|
|
|
mermaid.initialize(mermaidConf);
|
2021-12-12 21:37:10 +03:00
|
|
|
|
|
2023-03-22 20:29:17 +03:00
|
|
|
|
window.addEventListener('message', updateMermaid);
|
2022-11-04 23:28:44 +03:00
|
|
|
|
})();
|
2020-12-09 21:42:46 +03:00
|
|
|
|
</script>
|