Skip to content

Commit ca2b034

Browse files
ertime037claude
andcommitted
fix: preserve diagram colors in lightbox
- Use cloneNode instead of outerHTML to preserve styles - Apply dark/light theme class to lightbox container - Match lightbox background to current theme Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ba8d23c commit ca2b034

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

assets/js/mermaid-init.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
document.body.appendChild(overlay);
3434

3535
var style = document.createElement('style');
36-
style.textContent = '#mermaid-lightbox{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.9);z-index:9999;display:none;align-items:center;justify-content:center;cursor:zoom-out}#mermaid-lightbox.active{display:flex}.mermaid-lightbox-content{max-width:95vw;max-height:90vh;overflow:auto;background:var(--code-bg,#1e1e1e);padding:2rem;border-radius:12px}.mermaid-lightbox-content svg{max-width:none!important;width:auto;height:auto;min-width:60vw}.mermaid-lightbox-close{position:absolute;top:20px;right:30px;font-size:40px;color:#fff;cursor:pointer}.mermaid-lightbox-hint{position:absolute;bottom:20px;color:rgba(255,255,255,.5);font-size:14px}.mermaid{cursor:zoom-in}';
36+
style.textContent = '#mermaid-lightbox{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.85);z-index:9999;display:none;align-items:center;justify-content:center;cursor:zoom-out}#mermaid-lightbox.active{display:flex}.mermaid-lightbox-content{max-width:95vw;max-height:90vh;overflow:auto;background:#1d1e20;padding:2rem;border-radius:12px}.mermaid-lightbox-content svg{max-width:none!important;width:auto;height:auto}.mermaid-lightbox-close{position:absolute;top:20px;right:30px;font-size:40px;color:#fff;cursor:pointer}.mermaid-lightbox-hint{position:absolute;bottom:20px;color:rgba(255,255,255,.5);font-size:14px}.mermaid{cursor:zoom-in}#mermaid-lightbox:not(.dark) .mermaid-lightbox-content{background:#f8f8f8}#mermaid-lightbox:not(.dark) .mermaid-lightbox-close{color:#333}';
3737
document.head.appendChild(style);
3838

3939
overlay.addEventListener('click', closeLightbox);
@@ -45,7 +45,18 @@
4545
function openLightbox(svg) {
4646
var lightbox = document.getElementById('mermaid-lightbox');
4747
var content = lightbox.querySelector('.mermaid-lightbox-content');
48-
content.innerHTML = svg.outerHTML.replace(/max-width:\s*100%/g, 'max-width:none');
48+
// Клонируем SVG чтобы сохранить все стили
49+
var clone = svg.cloneNode(true);
50+
clone.style.maxWidth = 'none';
51+
clone.style.minWidth = '60vw';
52+
content.innerHTML = '';
53+
content.appendChild(clone);
54+
// Применяем тему к lightbox
55+
if (document.body.classList.contains('dark')) {
56+
lightbox.classList.add('dark');
57+
} else {
58+
lightbox.classList.remove('dark');
59+
}
4960
lightbox.classList.add('active');
5061
document.body.style.overflow = 'hidden';
5162
}

0 commit comments

Comments
 (0)