fix: improve mermaid fullscreen rendering and sizing logic for pan-zoom initialization

This commit is contained in:
Ümit Tunç
2026-05-25 07:43:08 +03:00
parent e9ddc3d332
commit 40fbb750db
+24 -18
View File
@@ -288,8 +288,8 @@
border-radius: 20px; border-radius: 20px;
overflow: hidden; overflow: hidden;
width: 92vw; width: 92vw;
max-width: 1200px; max-width: 1400px;
max-height: 90vh; height: 85vh;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
box-shadow: 0 40px 80px rgba(0,0,0,0.5); box-shadow: 0 40px 80px rgba(0,0,0,0.5);
@@ -299,17 +299,13 @@
} }
.mermaid-fullscreen-canvas { .mermaid-fullscreen-canvas {
flex: 1; flex: 1;
overflow: auto; overflow: hidden;
display: flex; position: relative;
align-items: center;
justify-content: center;
padding: 2rem;
cursor: grab; cursor: grab;
} }
.mermaid-fullscreen-canvas:active { cursor: grabbing; } .mermaid-fullscreen-canvas:active { cursor: grabbing; }
.mermaid-fullscreen-canvas svg { .mermaid-fullscreen-canvas svg {
width: 100%; display: block;
height: auto;
} }
/* Bullet lists */ /* Bullet lists */
@@ -1117,19 +1113,29 @@
if (!svg) return; if (!svg) return;
const fsCanvas = document.getElementById('mermaid-fs-canvas'); const fsCanvas = document.getElementById('mermaid-fs-canvas');
const svgClone = svg.cloneNode(true);
svgClone.id = 'mermaid-fs-svg-' + index;
svgClone.style.width = '100%';
svgClone.style.height = 'auto';
svgClone.removeAttribute('height');
fsCanvas.innerHTML = ''; fsCanvas.innerHTML = '';
fsCanvas.appendChild(svgClone);
// Show overlay first so fsCanvas has layout dimensions
document.getElementById('mermaid-fs-overlay').classList.add('active'); document.getElementById('mermaid-fs-overlay').classList.add('active');
document.body.style.overflow = 'hidden'; document.body.style.overflow = 'hidden';
// Init pan-zoom on cloned SVG // Init pan-zoom on cloned SVG after layout is available
setTimeout(() => { setTimeout(() => {
const svgClone = svg.cloneNode(true);
svgClone.id = 'mermaid-fs-svg-' + index;
// Get actual pixel dimensions of the fullscreen canvas
const fsW = fsCanvas.clientWidth || fsCanvas.offsetWidth || 1000;
const fsH = fsCanvas.clientHeight || fsCanvas.offsetHeight || 600;
// Set explicit dimensions on SVG for svg-pan-zoom
svgClone.setAttribute('width', fsW);
svgClone.setAttribute('height', fsH);
svgClone.style.width = fsW + 'px';
svgClone.style.height = fsH + 'px';
fsCanvas.appendChild(svgClone);
try { try {
fsActivePanZoom = svgPanZoom('#mermaid-fs-svg-' + index, { fsActivePanZoom = svgPanZoom('#mermaid-fs-svg-' + index, {
zoomEnabled: true, zoomEnabled: true,
@@ -1145,8 +1151,8 @@
} }
}); });
document.getElementById('mermaid-fs-pct').textContent = Math.round(fsActivePanZoom.getZoom() * 100) + '%'; document.getElementById('mermaid-fs-pct').textContent = Math.round(fsActivePanZoom.getZoom() * 100) + '%';
} catch(e) {} } catch(e) { console.warn('fs pan-zoom init error', e); }
}, 100); }, 150);
} }
function closeMermaidFullscreen() { function closeMermaidFullscreen() {
document.getElementById('mermaid-fs-overlay').classList.remove('active'); document.getElementById('mermaid-fs-overlay').classList.remove('active');