Skip to content

Commit af6061b

Browse files
committed
fix: Ensure Mermaid diagrams are visible in fullscreen mode
- Added explicit visibility styles with !important flags - Increased timeout to ensure Mermaid finishes rendering - Added error handling for Mermaid rendering failures - Ensured SVG elements are always visible in fullscreen - Fixed width/height auto settings for proper display
1 parent b320bec commit af6061b

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

docs_site/_layouts/default.html

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@
622622
mermaidDiv.style.display = 'block';
623623
mermaidDiv.style.visibility = 'visible';
624624
mermaidDiv.style.opacity = '1';
625+
mermaidDiv.style.width = 'auto';
626+
mermaidDiv.style.height = 'auto';
625627
wrapper.appendChild(mermaidDiv);
626628

627629
// Re-render with Mermaid
@@ -630,14 +632,45 @@
630632
if (svg) {
631633
svg.style.display = 'block';
632634
svg.style.visibility = 'visible';
635+
svg.style.opacity = '1';
636+
svg.style.width = 'auto';
637+
svg.style.height = 'auto';
638+
svg.style.maxWidth = 'none';
639+
svg.style.maxHeight = 'none';
640+
svg.removeAttribute('style'); // Remove any inline styles that might hide it
641+
svg.setAttribute('style', 'display: block !important; visibility: visible !important; opacity: 1 !important; width: auto !important; height: auto !important;');
633642
}
643+
644+
// Also ensure the mermaid div itself is visible
645+
mermaidDiv.style.display = 'block';
646+
mermaidDiv.style.visibility = 'visible';
647+
mermaidDiv.style.opacity = '1';
648+
}).catch((err) => {
649+
console.error('Mermaid rendering error:', err);
650+
// Fallback: clone the existing diagram
651+
const clone = diagramElement.cloneNode(true);
652+
clone.style.display = 'block';
653+
clone.style.visibility = 'visible';
654+
clone.style.opacity = '1';
655+
wrapper.appendChild(clone);
634656
});
635657
} else {
636658
// Fallback: clone the existing diagram
637659
const clone = diagramElement.cloneNode(true);
638660
clone.style.display = 'block';
639661
clone.style.visibility = 'visible';
640662
clone.style.opacity = '1';
663+
664+
// Ensure SVG in clone is visible
665+
const svg = clone.querySelector('svg');
666+
if (svg) {
667+
svg.style.display = 'block';
668+
svg.style.visibility = 'visible';
669+
svg.style.opacity = '1';
670+
svg.style.width = 'auto';
671+
svg.style.height = 'auto';
672+
}
673+
641674
wrapper.appendChild(clone);
642675
}
643676

@@ -669,19 +702,29 @@
669702
wrapper.style.display = 'flex';
670703
wrapper.style.visibility = 'visible';
671704
wrapper.style.opacity = '1';
705+
wrapper.style.width = 'fit-content';
706+
wrapper.style.height = 'fit-content';
672707

673708
const mermaidEl = wrapper.querySelector('.mermaid');
674709
if (mermaidEl) {
675710
mermaidEl.style.display = 'block';
676711
mermaidEl.style.visibility = 'visible';
677712
mermaidEl.style.opacity = '1';
713+
mermaidEl.style.width = 'auto';
714+
mermaidEl.style.height = 'auto';
678715
}
679716

680717
const svg = wrapper.querySelector('svg');
681718
if (svg) {
682719
svg.style.display = 'block';
683720
svg.style.visibility = 'visible';
684721
svg.style.opacity = '1';
722+
svg.style.width = 'auto';
723+
svg.style.height = 'auto';
724+
svg.style.maxWidth = 'none';
725+
svg.style.maxHeight = 'none';
726+
// Force visibility with important
727+
svg.setAttribute('style', 'display: block !important; visibility: visible !important; opacity: 1 !important; width: auto !important; height: auto !important; max-width: none !important; max-height: none !important;');
685728
}
686729

687730
// Center scroll position
@@ -693,7 +736,7 @@
693736
content.scrollLeft = (content.scrollWidth - content.clientWidth) / 2;
694737
}
695738
}, 200);
696-
}, 300);
739+
}, 500); // Increased timeout to ensure Mermaid has finished rendering
697740

698741
// Focus on close button for accessibility
699742
const closeBtn = overlay.querySelector('.close-fullscreen-btn');

0 commit comments

Comments
 (0)