⬆️ 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
+1 -1
View File
@@ -18,7 +18,7 @@ code {
}
// indented code
pre {
pre:not(.mermaid[data-processed='true']) {
margin: 0;
line-height: 1.45em;
padding: 0.5rem;
+3 -1
View File
@@ -1,5 +1,7 @@
.mermaid {
text-align: center;
&[data-processed='true'] {
text-align: center;
}
svg {
max-width: 100%;
-3
View File
@@ -57,9 +57,6 @@ libFiles:
# TODO update to 3.x
mapboxGLCSS: mapbox-gl@2.10.0/dist/mapbox-gl.css
mapboxGLJS: mapbox-gl@2.10.0/dist/mapbox-gl.js
# mermaid@9.4.3 https://github.com/mermaid-js/mermaid
# TODO bump Mermaid from 9.x to 10.x
mermaidJS: mermaid@9.4.3/dist/mermaid.min.js
# meting@2.0.1 https://github.com/metowolf/MetingJS
metingJS: meting@2.0.1/dist/Meting.min.js
# object-fit-images@3.2.4 https://github.com/fregante/object-fit-images
-3
View File
@@ -57,9 +57,6 @@ libFiles:
# TODO update to 3.x
mapboxGLCSS: mapbox-gl@2.10.0/dist/mapbox-gl.css
mapboxGLJS: mapbox-gl@2.10.0/dist/mapbox-gl.js
# mermaid@9.4.3 https://github.com/mermaid-js/mermaid
# TODO bump Mermaid from 9.x to 10.x
mermaidJS: mermaid@9.4.3/dist/mermaid.min.js
# meting@2.0.1 https://github.com/metowolf/MetingJS
metingJS: meting@2.0.1/dist/Meting.min.js
# object-fit-images@3.2.4 https://github.com/fregante/object-fit-images
+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()
-1
View File
@@ -17,7 +17,6 @@ instant.page@5.2.0 https://github.com/instantpage/instant.page
katex@0.16.9 https://github.com/KaTeX/KaTeX
lightgallery@2.7.2 https://github.com/sachinchoolur/lightgallery
mapbox-gl@2.10.0 https://github.com/mapbox/mapbox-gl-js
mermaid@9.4.3 https://github.com/mermaid-js/mermaid
meting@2.0.1 https://github.com/metowolf/MetingJS
normalize.css@8.0.1 https://github.com/necolas/normalize.css
object-fit-images@3.2.4 https://github.com/fregante/object-fit-images [archived]
-1580
View File
File diff suppressed because one or more lines are too long
@@ -1,3 +1,4 @@
{{- $id := dict "Content" (trim (partial "function/dos2unix.html" .Inner) "\n") "Scratch" .Page.Scratch | partial "function/id.html" -}}
<div class="mermaid" id="{{ $id }}"></div>
{{- .Page.Scratch.SetInMap "this" "mermaid" true -}}
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{- .Page.Store.Set "hasMermaid" true -}}
+6 -5
View File
@@ -114,11 +114,12 @@
{{- end -}}
{{- /* mermaid */ -}}
{{- if (.HasShortcode "mermaid") | or (.Scratch.Get "this").mermaid -}}
{{- $source := $cdn.mermaidJS | default "lib/mermaid/mermaid.min.js" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $mermaid := .Site.Params.mermaid -}}
{{- $config = dict "themes" $mermaid.themes | dict "mermaid" | merge $config -}}
{{- if .Store.Get "hasMermaid" -}}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
window.mermaid = mermaid;
window.mermaid.themes = {{ .Site.Params.mermaid.themes }};
</script>
{{- end -}}
{{- /* ECharts */ -}}
+4 -2
View File
@@ -1,3 +1,5 @@
{{- $id := dict "Content" (trim (partial "function/dos2unix.html" .Inner) "\n") "Scratch" .Page.Scratch | partial "function/id.html" -}}
<div class="mermaid" id="{{ $id }}"></div>
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{- .Page.Store.Set "hasMermaid" true -}}
{{- /* EOF */ -}}