⬆️ Fix: bump Mermaid from 9.x to 10.x and fix error (#420)

This commit is contained in:
Cell
2024-03-08 00:04:07 +08:00
parent 063d8fa219
commit 3df577cb0d
10 changed files with 34 additions and 1617 deletions
+16 -18
View File
@@ -550,24 +550,23 @@ class FixIt {
}
}
switchMermaidTheme(theme) {
const $mermaidElements = document.getElementsByClassName('mermaid');
if ($mermaidElements.length) {
// TODO perf
const themes = this.config.mermaid.themes ?? ['default', 'dark', 'neutral'];
mermaid.initialize({ startOnLoad: false, theme: theme ?? (this.isDark ? themes[1] : themes[0]), securityLevel: 'loose' });
this.util.forEach($mermaidElements, $mermaid => {
mermaid.render('svg-' + $mermaid.id, this.data[$mermaid.id], svgCode => {
$mermaid.innerHTML = svgCode;
}, $mermaid);
});
}
};
initMermaid() {
this.switchMermaidTheme();
this.switchThemeEventSet.add(() => { this.switchMermaidTheme(); });
this.beforeprintEventSet.add(() => { this.switchMermaidTheme('neutral'); });
if (!window.mermaid) {
return;
}
const themes = window.mermaid.themes ?? ['default', 'dark'];
window.mermaid.initialize({
securityLevel: 'loose',
startOnLoad: true,
theme: this.isDark ? themes[1] : themes[0],
});
this.switchThemeEventSet.add(() => {
// Mermaid does not provide a method for switching yet. When switching themes, refresh the page.
window.location.reload();
});
this.beforeprintEventSet.add(() => {
// Set the theme to neutral when printing.
});
}
initEcharts() {
@@ -1101,7 +1100,6 @@ class FixIt {
event();
}
this.initToc();
this.switchMermaidTheme();
this.initSearch();
const isMobile = this.util.isMobile()