Skip to content

Commit 2b240ed

Browse files
[getsentry/action-github-commit] Auto commit
1 parent a7bd26d commit 2b240ed

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/components/mermaid.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ export default function Mermaid() {
88

99
useEffect(() => {
1010
const renderMermaid = async () => {
11-
const mermaidBlocks = document.querySelectorAll<HTMLDivElement>('.language-mermaid');
11+
const mermaidBlocks =
12+
document.querySelectorAll<HTMLDivElement>('.language-mermaid');
1213
if (mermaidBlocks.length === 0) return;
1314

14-
const escapeHTML = (str: string) =>
15-
str.replace(/[&<>"']/g, (match) => ({
16-
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
17-
}[match] || match));
15+
const escapeHTML = (str: string) =>
16+
str.replace(
17+
/[&<>"']/g,
18+
match =>
19+
({
20+
'&': '&amp;',
21+
'<': '&lt;',
22+
'>': '&gt;',
23+
'"': '&quot;',
24+
"'": '&#39;',
25+
})[match] || match
26+
);
1827

1928
const {default: mermaid} = await import('mermaid/dist/mermaid.esm.min.mjs');
20-
29+
2130
// Create light and dark versions
2231
mermaidBlocks.forEach(block => {
2332
const code = block.textContent ?? '';
@@ -43,7 +52,7 @@ export default function Mermaid() {
4352
// Render both themes
4453
mermaid.initialize({startOnLoad: false, theme: 'default'});
4554
await mermaid.run({nodes: document.querySelectorAll('.language-mermaid.light')});
46-
55+
4756
mermaid.initialize({startOnLoad: false, theme: 'dark'});
4857
await mermaid.run({nodes: document.querySelectorAll('.language-mermaid.dark')});
4958

@@ -54,19 +63,19 @@ export default function Mermaid() {
5463

5564
const initializePanZoom = async () => {
5665
const svgPanZoom = (await import('svg-pan-zoom')).default;
57-
66+
5867
document.querySelectorAll('.language-mermaid svg').forEach(svg => {
5968
const svgElement = svg as SVGSVGElement;
6069
const container = svgElement.closest('.language-mermaid') as HTMLElement;
6170
const isVisible = window.getComputedStyle(container).display !== 'none';
62-
71+
6372
if (isVisible) {
6473
const rect = svgElement.getBoundingClientRect();
6574
if (rect.width > 0 && rect.height > 0) {
6675
svgElement.setAttribute('width', rect.width.toString());
6776
svgElement.setAttribute('height', rect.height.toString());
6877
}
69-
78+
7079
svgPanZoom(svgElement, {
7180
zoomEnabled: true,
7281
panEnabled: true,
@@ -89,23 +98,24 @@ export default function Mermaid() {
8998
// Initialize pan/zoom for newly visible SVGs on theme change
9099
useEffect(() => {
91100
if (!isDoneRendering) return;
92-
101+
93102
const initializeDelayedPanZoom = async () => {
94103
const svgPanZoom = (await import('svg-pan-zoom')).default;
95-
96-
document.querySelectorAll('.language-mermaid svg[data-needs-pan-zoom="true"]')
104+
105+
document
106+
.querySelectorAll('.language-mermaid svg[data-needs-pan-zoom="true"]')
97107
.forEach(svg => {
98108
const svgElement = svg as SVGSVGElement;
99109
const container = svgElement.closest('.language-mermaid') as HTMLElement;
100110
const isVisible = window.getComputedStyle(container).display !== 'none';
101-
111+
102112
if (isVisible) {
103113
const rect = svgElement.getBoundingClientRect();
104114
if (rect.width > 0 && rect.height > 0) {
105115
svgElement.setAttribute('width', rect.width.toString());
106116
svgElement.setAttribute('height', rect.height.toString());
107117
}
108-
118+
109119
svgPanZoom(svgElement, {
110120
zoomEnabled: true,
111121
panEnabled: true,
@@ -116,7 +126,7 @@ export default function Mermaid() {
116126
maxZoom: 10,
117127
zoomScaleSensitivity: 0.2,
118128
});
119-
129+
120130
svgElement.removeAttribute('data-needs-pan-zoom');
121131
}
122132
});
@@ -135,4 +145,4 @@ export default function Mermaid() {
135145
`}
136146
</style>
137147
) : null;
138-
}
148+
}

0 commit comments

Comments
 (0)