]> BookStack Code Mirror - hacks/blob - content/mermaid-viewer/head.html
refactor(mermaid-viewer): Use AbortController for event listener cleanup
[hacks] / content / mermaid-viewer / head.html
1 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"
2     integrity="sha512-Evv84Mr4kqVGRNSgIGL/F/aIDqQb7xQ2vcrdIwxfjThSH8CSR7PBEakCr51Ck+w+/U6swU2Im1vVX0SVk9ABhg=="
3     crossorigin="anonymous" referrerpolicy="no-referrer" />
4
5 <script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.7.0/mermaid.min.js"
6     integrity="sha512-ecc+vlmmc1f51s2l/AeIC552wULnv9Q8bYJ4FbODxsL6jGrFoLaKnGkN5JUZNH6LBjkAYy9Q4fKqyTuFUIvvFA=="
7     crossorigin="anonymous" referrerpolicy="no-referrer"></script>
8 <script type="module">
9     // Detect if BookStack's dark mode is enabled
10     const isDarkMode = document.documentElement.classList.contains('dark-mode');
11
12     // Initialize Mermaid.js, dynamically setting the theme based on BookStack's mode
13     mermaid.initialize({
14         startOnLoad: false,
15         securityLevel: 'loose',
16         theme: isDarkMode ? 'dark' : 'default'
17     });
18
19     // Zoom Level Configuration
20     const ZOOM_LEVEL_MIN = 0.5;
21     const ZOOM_LEVEL_MAX = 2.0;
22     const ZOOM_LEVEL_INCREMENT = 0.1;
23     const DEFAULT_ZOOM_SCALE = 1.0;
24
25     const DRAG_THRESHOLD_PIXELS = 3;
26     const ZOOM_ANIMATION_CLASS_TIMEOUT_MS = 200;
27
28     const CSS_CLASSES = {
29         CONTAINER: 'mermaid-container',
30         VIEWPORT: 'mermaid-viewport',
31         CONTENT: 'mermaid-content',
32         DIAGRAM: 'mermaid-diagram',
33         CONTROLS: 'mermaid-controls',
34         ZOOM_CONTROLS: 'mermaid-zoom-controls',
35         INTERACTION_ENABLED: 'interaction-enabled',
36         DRAGGING: 'dragging',
37         ZOOMING: 'zooming',
38         LOCK_ICON: 'fa fa-lock',
39         UNLOCK_ICON: 'fa fa-unlock',
40         INTERACTIVE_HOVER: 'interactive-hover', // Class for 'grab' cursor state
41         INTERACTIVE_PAN: 'interactive-pan',     // Class for 'grabbing' cursor state
42         BUTTON_BASE: 'mermaid-viewer-button-base' // Base class for all viewer buttons
43     };
44
45     class InteractiveMermaidViewer {
46         constructor(container, mermaidCode) {
47             this.container = container;
48             this.mermaidCode = mermaidCode;
49             this.scale = 1.0;
50             this.translateX = 0;
51             this.translateY = 0;
52             this.isDragging = false;
53             this.dragStarted = false;
54             this.startX = 0;
55             this.startY = 0;
56
57             const numDecimalPlaces = (ZOOM_LEVEL_INCREMENT.toString().split('.')[1] || '').length;
58             this.zoomLevels = Array.from(
59                 { length: Math.round((ZOOM_LEVEL_MAX - ZOOM_LEVEL_MIN) / ZOOM_LEVEL_INCREMENT) + 1 },
60                 (_, i) => parseFloat((ZOOM_LEVEL_MIN + i * ZOOM_LEVEL_INCREMENT).toFixed(numDecimalPlaces))
61             );
62
63             this.currentZoomIndex = this.zoomLevels.findIndex(level => Math.abs(level - DEFAULT_ZOOM_SCALE) < 1e-9);
64             if (this.currentZoomIndex === -1) {
65                 this.currentZoomIndex = Math.floor(this.zoomLevels.length / 2);
66             }
67             this.interactionEnabled = false;
68             this.initialContentOffset = { x: 0, y: 0 };
69
70             // Cache DOM elements
71             this.toggleInteractionBtn = null;
72             this.copyCodeBtn = null;
73             this.zoomInBtn = null;
74             this.zoomOutBtn = null;
75             this.zoomResetBtn = null;
76
77             // Use an AbortController for robust event listener cleanup.
78             this.abortController = new AbortController();
79
80             // Bind event handlers for proper addition and removal
81             this.boundMouseMoveHandler = this.handleMouseMove.bind(this);
82             this.boundMouseUpHandler = this.handleMouseUp.bind(this);
83             this.boundToggleInteraction = this.toggleInteraction.bind(this);
84             this.boundCopyCode = this.copyCode.bind(this);
85             this.boundZoomIn = this.handleZoomClick.bind(this, 1);
86             this.boundZoomOut = this.handleZoomClick.bind(this, -1);
87             this.boundResetZoom = this.resetZoom.bind(this);
88             this.boundHandleWheel = this.handleWheel.bind(this);
89             this.boundHandleMouseDown = this.handleMouseDown.bind(this);
90             this.boundPreventDefault = e => e.preventDefault();
91             this.boundPreventSelect = e => { if (this.isDragging || this.interactionEnabled) e.preventDefault(); };
92
93             this.setupViewer();
94             this.setupEventListeners();
95         }
96
97         /**
98          * Creates the DOM structure for the viewer programmatically.
99          * This is safer and more maintainable than using innerHTML with a large template string.
100          */
101         setupViewer() {
102             const createButton = (title, iconClass, ...extraClasses) => {
103                 const button = document.createElement('div');
104                 button.className = `${CSS_CLASSES.BUTTON_BASE} ${extraClasses.join(' ')}`;
105                 button.title = title;
106                 const icon = document.createElement('i');
107                 icon.className = iconClass;
108                 icon.setAttribute('aria-hidden', 'true');
109                 button.append(icon);
110                 return button;
111             };
112
113             const controls = document.createElement('div');
114             controls.className = CSS_CLASSES.CONTROLS;
115             this.toggleInteractionBtn = createButton('Toggle interaction', CSS_CLASSES.LOCK_ICON, 'mermaid-btn', 'toggle-interaction');
116             this.copyCodeBtn = createButton('Copy code', 'fa fa-copy', 'mermaid-btn');
117             controls.append(this.toggleInteractionBtn, this.copyCodeBtn);
118
119             const zoomControls = document.createElement('div');
120             zoomControls.className = CSS_CLASSES.ZOOM_CONTROLS;
121             this.zoomInBtn = createButton('Zoom in', 'fa fa-search-plus', 'mermaid-zoom-btn', 'zoom-in');
122             this.zoomOutBtn = createButton('Zoom out', 'fa fa-search-minus', 'mermaid-zoom-btn', 'zoom-out');
123             this.zoomResetBtn = createButton('Reset', 'fa fa-refresh', 'mermaid-zoom-btn', 'zoom-reset');
124             zoomControls.append(this.zoomInBtn, this.zoomOutBtn, this.zoomResetBtn);
125
126             this.diagram = document.createElement('div');
127             this.diagram.className = CSS_CLASSES.DIAGRAM;
128             // Use textContent for security, preventing any potential HTML injection.
129             // Mermaid will parse the text content safely.
130             this.diagram.textContent = this.mermaidCode;
131
132             this.content = document.createElement('div');
133             this.content.className = CSS_CLASSES.CONTENT;
134             this.content.append(this.diagram);
135
136             this.viewport = document.createElement('div');
137             this.viewport.className = CSS_CLASSES.VIEWPORT;
138             this.viewport.append(this.content);
139
140             // Clear the container and append the new structure
141             this.container.innerHTML = '';
142             this.container.append(controls, zoomControls, this.viewport);
143
144             // Function to render the diagram and perform post-render setup
145             const renderAndSetup = () => {
146                 mermaid.run({ nodes: [this.diagram] }).then(() => {
147                     this.adjustContainerHeight();
148                     this.calculateInitialOffset();
149                     this.centerDiagram();
150                 }).catch(error => {
151                     console.error("Mermaid rendering error for diagram:", this.mermaidCode, error);
152                     this.diagram.innerHTML = `<p style="color: red; padding: 10px;">Error rendering diagram. Check console.</p>`;
153                 });
154             };
155
156             // Check if Font Awesome is loaded before rendering
157             // This checks for the 'Font Awesome 6 Free' font family, which is common.
158             // Adjust if your Font Awesome version uses a different family name for its core icons.
159             if (document.fonts && typeof document.fonts.check === 'function' && document.fonts.check('1em "Font Awesome 6 Free"')) { // Check if Font Awesome is immediately available
160                 renderAndSetup();
161             } else if (document.fonts && document.fonts.ready) { // Simplified check for document.fonts.ready
162                 document.fonts.ready.then(renderAndSetup).catch(err => {
163                     renderAndSetup(); // Proceed with rendering even if font check fails after timeout/error
164                 });
165             } else {
166                 renderAndSetup();
167             }
168         }
169
170         adjustContainerHeight() {
171             const svgElement = this.content.querySelector('svg');
172             if (svgElement) {
173                 // Ensure the viewport takes up the height of the rendered SVG
174                 this.viewport.style.height = '100%';
175             }
176         }
177
178         calculateInitialOffset() {
179             const originalTransform = this.content.style.transform;
180             this.content.style.transform = '';
181             const contentRect = this.content.getBoundingClientRect();
182             const viewportRect = this.viewport.getBoundingClientRect();
183             this.initialContentOffset.x = contentRect.left - viewportRect.left;
184             this.initialContentOffset.y = contentRect.top - viewportRect.top;
185             this.content.style.transform = originalTransform;
186         }
187
188         _getViewportCenterClientCoords() {
189             const viewportRect = this.viewport.getBoundingClientRect();
190             return {
191                 clientX: viewportRect.left + viewportRect.width / 2,
192                 clientY: viewportRect.top + viewportRect.height / 2,
193             };
194         }
195
196         setupEventListeners() {
197             const { signal } = this.abortController;
198
199             this.toggleInteractionBtn.addEventListener('click', this.boundToggleInteraction, { signal });
200             this.copyCodeBtn.addEventListener('click', this.boundCopyCode, { signal });
201             this.zoomInBtn.addEventListener('click', this.boundZoomIn, { signal });
202             this.zoomOutBtn.addEventListener('click', this.boundZoomOut, { signal });
203             this.zoomResetBtn.addEventListener('click', this.boundResetZoom, { signal });
204
205             this.viewport.addEventListener('wheel', this.boundHandleWheel, { passive: false, signal });
206             this.viewport.addEventListener('mousedown', this.boundHandleMouseDown, { signal });
207
208             // Listen on document for mousemove to handle dragging outside viewport
209             document.addEventListener('mousemove', this.boundMouseMoveHandler, { signal });
210             // Listen on window for mouseup to ensure drag ends even if mouse is released outside
211             window.addEventListener('mouseup', this.boundMouseUpHandler, { signal, capture: true });
212
213             this.viewport.addEventListener('contextmenu', this.boundPreventDefault, { signal });
214             this.viewport.addEventListener('selectstart', this.boundPreventSelect, { signal });
215         }
216
217         toggleInteraction() {
218             this.interactionEnabled = !this.interactionEnabled;
219             const icon = this.toggleInteractionBtn.querySelector('i');
220             this.toggleInteractionBtn.setAttribute('aria-pressed', this.interactionEnabled.toString());
221
222             if (this.interactionEnabled) {
223                 icon.className = CSS_CLASSES.UNLOCK_ICON;
224                 this.toggleInteractionBtn.title = 'Disable manual interaction';
225                 this.viewport.classList.add(CSS_CLASSES.INTERACTION_ENABLED);
226                 this.viewport.classList.add(CSS_CLASSES.INTERACTIVE_HOVER); // Set grab cursor state
227                 this.viewport.classList.remove(CSS_CLASSES.INTERACTIVE_PAN); // Ensure pan cursor state is off
228             } else {
229                 icon.className = CSS_CLASSES.LOCK_ICON;
230                 this.toggleInteractionBtn.title = 'Enable manual interaction';
231                 this.viewport.classList.remove(CSS_CLASSES.INTERACTION_ENABLED);
232                 this.viewport.classList.remove(CSS_CLASSES.INTERACTIVE_HOVER);
233                 this.viewport.classList.remove(CSS_CLASSES.INTERACTIVE_PAN);
234                 this.isDragging = false; // Ensure dragging stops if interaction is disabled mid-drag
235                 this.dragStarted = false;
236                 this.viewport.classList.remove(CSS_CLASSES.DRAGGING);
237             }
238         }
239
240         updateTransform() {
241             this.content.style.transform = `translate(${this.translateX}px, ${this.translateY}px) scale(${this.scale})`;
242         }
243
244         handleZoomClick(direction) {
245             const { clientX, clientY } = this._getViewportCenterClientCoords();
246             this.zoom(direction, clientX, clientY);
247         }
248
249         handleWheel(e) {
250             if (!this.interactionEnabled) return;
251             // Prevent default browser scroll/zoom behavior when wheeling over the diagram
252             e.preventDefault();
253             this.content.classList.add(CSS_CLASSES.ZOOMING);
254             const clientX = e.clientX;
255             const clientY = e.clientY;
256             if (e.deltaY > 0) this.zoom(-1, clientX, clientY);
257             else this.zoom(1, clientX, clientY);
258             setTimeout(() => this.content.classList.remove(CSS_CLASSES.ZOOMING), ZOOM_ANIMATION_CLASS_TIMEOUT_MS);
259         }
260
261         handleMouseDown(e) {
262             if (!this.interactionEnabled || e.button !== 0) return;
263             e.preventDefault();
264             this.isDragging = true;
265             this.dragStarted = false;
266             this.startX = e.clientX;
267             this.startY = e.clientY;
268             this.dragBaseTranslateX = this.translateX;
269             this.dragBaseTranslateY = this.translateY;
270             this.viewport.classList.add(CSS_CLASSES.DRAGGING);
271             this.viewport.classList.remove(CSS_CLASSES.INTERACTIVE_HOVER);
272             this.viewport.classList.add(CSS_CLASSES.INTERACTIVE_PAN);
273             this.content.classList.remove(CSS_CLASSES.ZOOMING);
274         }
275
276         handleMouseMove(e) {
277             if (!this.isDragging) return;
278             // e.preventDefault() is called only after dragStarted is true to allow clicks if threshold isn't met.
279             const deltaX = e.clientX - this.startX;
280             const deltaY = e.clientY - this.startY;
281             if (!this.dragStarted && (Math.abs(deltaX) > DRAG_THRESHOLD_PIXELS || Math.abs(deltaY) > DRAG_THRESHOLD_PIXELS)) {
282                 this.dragStarted = true;
283             }
284             if (this.dragStarted) {
285                 e.preventDefault(); // Prevent text selection, etc., only when drag has truly started
286                 this.translateX = this.dragBaseTranslateX + deltaX;
287                 this.translateY = this.dragBaseTranslateY + deltaY;
288                 this.updateTransform();
289             }
290         }
291
292         handleMouseUp() {
293             if (this.isDragging) {
294                 this.isDragging = false;
295                 this.dragStarted = false;
296                 this.viewport.classList.remove(CSS_CLASSES.DRAGGING);
297                 this.viewport.classList.remove(CSS_CLASSES.INTERACTIVE_PAN);
298                 if (this.interactionEnabled) { // Revert to grab cursor if interaction is still enabled
299                     this.viewport.classList.add(CSS_CLASSES.INTERACTIVE_HOVER);
300                 }
301             }
302             this.content.style.transform = `translate(${this.translateX}px, ${this.translateY}px) scale(${this.scale})`;
303         }
304
305         centerDiagram() {
306             const svgElement = this.content.querySelector('svg');
307             if (svgElement) {
308                 const viewportRect = this.viewport.getBoundingClientRect();
309                 const svgIntrinsicWidth = svgElement.viewBox.baseVal.width || svgElement.clientWidth;
310                 const svgIntrinsicHeight = svgElement.viewBox.baseVal.height || svgElement.clientHeight;
311
312                 const targetContentLeftRelativeToViewport = (viewportRect.width - (svgIntrinsicWidth * this.scale)) / 2;
313                 const targetContentTopRelativeToViewport = (viewportRect.height - (svgIntrinsicHeight * this.scale)) / 2;
314
315                 this.translateX = targetContentLeftRelativeToViewport - this.initialContentOffset.x;
316                 this.translateY = targetContentTopRelativeToViewport - this.initialContentOffset.y;
317
318                 // Initial centering constraints; may need adjustment for very large diagrams.
319                 this.translateX = Math.max(0, this.translateX);
320                 this.translateY = Math.max(0, this.translateY);
321
322                 this.updateTransform();
323             }
324         }
325
326         zoom(direction, clientX, clientY) {
327             this.content.classList.add(CSS_CLASSES.ZOOMING);
328             const oldScale = this.scale;
329             let newZoomIndex = this.currentZoomIndex + direction;
330
331             if (newZoomIndex >= 0 && newZoomIndex < this.zoomLevels.length) {
332                 this.currentZoomIndex = newZoomIndex;
333                 const newScale = this.zoomLevels[this.currentZoomIndex];
334
335                 const viewportRect = this.viewport.getBoundingClientRect();
336                 const pointXInContent = (clientX - viewportRect.left - this.translateX) / oldScale;
337                 const pointYInContent = (clientY - viewportRect.top - this.translateY) / oldScale;
338
339                 this.translateX = (clientX - viewportRect.left) - (pointXInContent * newScale);
340                 this.translateY = (clientY - viewportRect.top) - (pointYInContent * newScale);
341                 this.scale = newScale;
342                 this.updateTransform();
343             }
344             setTimeout(() => this.content.classList.remove(CSS_CLASSES.ZOOMING), ZOOM_ANIMATION_CLASS_TIMEOUT_MS);
345         }
346
347         resetZoom() {
348             this.content.classList.add(CSS_CLASSES.ZOOMING);
349             this.currentZoomIndex = this.zoomLevels.findIndex(level => Math.abs(level - DEFAULT_ZOOM_SCALE) < 1e-9);
350             if (this.currentZoomIndex === -1) { // Fallback if default not exactly in levels
351                 this.currentZoomIndex = Math.floor(this.zoomLevels.length / 2);
352             }
353             this.scale = this.zoomLevels[this.currentZoomIndex];
354             // Use requestAnimationFrame to ensure layout is stable before centering
355             requestAnimationFrame(() => {
356                 this.centerDiagram();
357                 setTimeout(() => this.content.classList.remove(CSS_CLASSES.ZOOMING), ZOOM_ANIMATION_CLASS_TIMEOUT_MS);
358             });
359         }
360
361         async copyCode() {
362             try {
363                 await navigator.clipboard.writeText(this.mermaidCode);
364                 this.showNotification('Copied!');
365             } catch (_error) {
366                 // Fallback for older browsers or if clipboard API fails
367                 const textArea = document.createElement('textarea');
368                 textArea.value = this.mermaidCode;
369                 // Style to make it invisible
370                 textArea.style.position = 'fixed';
371                 textArea.style.top = '-9999px';
372                 textArea.style.left = '-9999px';
373                 document.body.appendChild(textArea);
374                 textArea.select();
375                 try {
376                     document.execCommand('copy');
377                     this.showNotification('Copied!');
378                 } catch (copyError) {
379                     console.error('Fallback copy failed:', copyError);
380                     this.showNotification('Copy failed.', true); // Error
381                 }
382                 document.body.removeChild(textArea);
383             }
384         }
385
386         showNotification(message, isError = false) {
387             if (window.$events) {
388                 const eventName = isError ? 'error' : 'success';
389                 window.$events.emit(eventName, message);
390             } else {
391                 // Fallback for if the event system is not available
392                 console.warn('BookStack event system not found, falling back to console log for notification.');
393                 if (isError) {
394                     console.error(message);
395                 } else {
396                     console.log(message);
397                 }
398             }
399         }
400
401         destroy() {
402             // Abort all listeners attached with this controller's signal.
403             this.abortController.abort();
404             this.container.innerHTML = ''; // Clear the container's content
405         }
406     }
407
408     const mermaidViewers = [];
409     function initializeMermaidViewers() {
410         // Adjust the selector if your CMS wraps mermaid code blocks differently
411         const codeBlocks = document.querySelectorAll('pre code.language-mermaid');
412         for (const codeBlock of codeBlocks) {
413             // Ensure we don't re-initialize if this script runs multiple times or content is dynamic
414             if (codeBlock.dataset.mermaidViewerInitialized) continue;
415
416             const mermaidCode = codeBlock.textContent || codeBlock.innerHTML; // textContent is usually better
417             const container = document.createElement('div');
418             container.className = CSS_CLASSES.CONTAINER;
419
420             const replaceTarget = (codeBlock.nodeName === 'CODE') ? codeBlock.parentElement : codeBlock;
421
422             // Check if replaceTarget is already a mermaid-container (e.g. from previous init)
423             if (replaceTarget.classList.contains(CSS_CLASSES.CONTAINER)) continue;
424
425             replaceTarget.after(container);
426             replaceTarget.remove(); // Remove the original <pre> or <pre><code> block
427
428             const viewer = new InteractiveMermaidViewer(container, mermaidCode);
429             mermaidViewers.push(viewer);
430             codeBlock.dataset.mermaidViewerInitialized = 'true'; // Mark as initialized
431         }
432     }
433
434     // Initialize on DOMContentLoaded
435     if (document.readyState === 'loading') {
436         document.addEventListener('DOMContentLoaded', initializeMermaidViewers);
437     } else {
438         // DOMContentLoaded has already fired
439         initializeMermaidViewers();
440     }
441
442     // Re-center diagrams on window load, as images/fonts inside SVG might affect size
443     window.addEventListener('load', () => {
444         mermaidViewers.forEach(viewer => {
445             // Delay slightly to ensure mermaid rendering is fully complete and dimensions are stable
446             setTimeout(() => viewer.centerDiagram(), 100);
447         });
448     });
449
450     // Optional: If your CMS dynamically adds content, you might need a way to re-run initialization
451     // For example, using a MutationObserver or a custom event.
452     // document.addEventListener('myCMSContentLoaded', () => initializeMermaidViewers());
453
454 </script>
455 <style>
456     /* Use BookStack's CSS variables for seamless theme integration */
457     .mermaid-container {
458         background: var(--color-bg-alt);
459         border: 1px solid #d0d7de;
460         border-radius: 6px;
461         position: relative;
462         margin: 20px 0;
463     }
464
465     .mermaid-viewport {
466         height: 100%;
467         /* This will now be 100% of the dynamically set container height */
468         overflow: hidden;
469         /* Keep this for panning/zooming when content exceeds viewport */
470         cursor: auto;
471         /* Default to normal system cursor */
472     }
473
474     /* Ensure viewport cursor is auto when locked, even if active.
475            The text selection (I-beam) cursor will still appear over selectable text within .mermaid-content. */
476     .mermaid-viewport:not(.interaction-enabled):active {
477         cursor: auto;
478     }
479
480     /* Set 'grab' cursor when the viewport has the 'interactive-hover' class. */
481     .mermaid-viewport.interactive-hover {
482         cursor: grab;
483     }
484
485     /* Set 'grabbing' cursor when the viewport has the 'interactive-pan' class. */
486     .mermaid-viewport.interactive-pan {
487         cursor: grabbing !important;
488     }
489
490     .mermaid-content {
491         transform-origin: 0 0;
492         /* Allow text selection by default (when interaction is locked) */
493         user-select: auto;
494         /* or 'text' */
495         will-change: transform;
496     }
497
498     /* Disable text selection ONLY when interaction is enabled on the viewport */
499     .mermaid-viewport.interaction-enabled .mermaid-content {
500         user-select: none;
501     }
502
503     /* SVG elements inherit cursor from the viewport when interaction is enabled. */
504     .mermaid-viewport.interaction-enabled .mermaid-content svg,
505     .mermaid-viewport.interaction-enabled .mermaid-content svg * {
506         cursor: inherit !important;
507         /* Force inheritance from the viewport's cursor */
508     }
509
510     .mermaid-content.zooming {
511         transition: transform 0.2s ease;
512     }
513
514     .mermaid-controls {
515         position: absolute;
516         top: 10px;
517         right: 10px;
518         display: flex;
519         gap: 5px;
520         z-index: 10;
521     }
522
523     .mermaid-viewer-button-base {
524         border: 1px solid #d0d7de;
525         border-radius: 6px;
526         cursor: pointer;
527         display: flex;
528         align-items: center;
529         justify-content: center;
530         user-select: none;
531         background: var(--color-bg);
532         width: 32px;
533         height: 32px;
534         color: var(--color-text);
535     }
536
537     .mermaid-viewer-button-base:hover {
538         background: #f6f8fa;
539     }
540
541     .dark-mode .mermaid-viewer-button-base:hover {
542         background: var(--color-bg-alt);
543     }
544
545     /* Override for pure white icons in dark mode */
546     .dark-mode .mermaid-viewer-button-base {
547         color: #fff;
548     }
549
550     .mermaid-zoom-controls {
551         position: absolute;
552         bottom: 10px;
553         left: 10px;
554         display: flex;
555         flex-direction: column;
556         gap: 5px;
557         z-index: 10;
558     }
559 </style>