| |
| |
| |
| |
|
|
| |
| const MERMAID_ZOOM_ENABLED = false; |
|
|
| console.log("🚀 Mermaid Zoom Script v20.0 loaded - DISABLED"); |
|
|
| |
| if (!MERMAID_ZOOM_ENABLED) { |
| console.log("🚫 Mermaid zoom is disabled, skipping initialization"); |
| |
| window.mermaidZoom = { |
| init: () => { }, |
| cleanup: () => { }, |
| convertSvgToImage: () => { }, |
| openZoom: () => { }, |
| closeZoom: () => { } |
| }; |
| |
| |
| } else { |
|
|
| |
| function applyMermaidStylesToSvg(svgElement) { |
| try { |
| const isDark = document.documentElement.getAttribute("data-theme") === "dark"; |
| console.log(`🎨 Applying Mermaid styles for theme: ${isDark ? 'dark' : 'light'}`); |
|
|
| |
| const colors = isDark ? { |
| nodeFill: '#1a1a1a', |
| nodeStroke: '#ffffff', |
| nodeStrokeWidth: '2', |
| clusterFill: '#2a2a2a', |
| clusterStroke: '#ffffff', |
| clusterStrokeWidth: '2', |
| pathStroke: '#ffffff', |
| pathStrokeWidth: '2', |
| textColor: '#ffffff', |
| linkColor: '#ffffff' |
| } : { |
| nodeFill: '#ffffff', |
| nodeStroke: '#000000', |
| nodeStrokeWidth: '2', |
| clusterFill: '#f9f9f9', |
| clusterStroke: '#000000', |
| clusterStrokeWidth: '2', |
| pathStroke: '#000000', |
| pathStrokeWidth: '2', |
| textColor: '#000000', |
| linkColor: '#000000' |
| }; |
|
|
| |
| const rects = svgElement.querySelectorAll('rect:not(.flowchart-link), .node rect, .nodeLabel rect'); |
| rects.forEach(rect => { |
| rect.setAttribute('rx', '8'); |
| rect.setAttribute('ry', '8'); |
| rect.setAttribute('fill', colors.nodeFill); |
| rect.setAttribute('stroke', colors.nodeStroke); |
| rect.setAttribute('stroke-width', colors.nodeStrokeWidth); |
| }); |
|
|
| |
| const clusterRects = svgElement.querySelectorAll('.cluster rect'); |
| clusterRects.forEach(rect => { |
| rect.setAttribute('rx', '8'); |
| rect.setAttribute('ry', '8'); |
| rect.setAttribute('fill', colors.clusterFill); |
| rect.setAttribute('stroke', colors.clusterStroke); |
| rect.setAttribute('stroke-width', colors.clusterStrokeWidth); |
| }); |
|
|
| |
| const nodes = svgElement.querySelectorAll('.node'); |
| nodes.forEach(node => { |
| const rect = node.querySelector('rect'); |
| if (rect) { |
| rect.setAttribute('fill', colors.nodeFill); |
| rect.setAttribute('stroke', colors.nodeStroke); |
| rect.setAttribute('stroke-width', colors.nodeStrokeWidth); |
| } |
| }); |
|
|
| |
| const clusters = svgElement.querySelectorAll('.cluster'); |
| clusters.forEach(cluster => { |
| const rect = cluster.querySelector('rect'); |
| if (rect) { |
| rect.setAttribute('fill', colors.clusterFill); |
| rect.setAttribute('stroke', colors.clusterStroke); |
| rect.setAttribute('stroke-width', colors.clusterStrokeWidth); |
| } |
| }); |
|
|
| |
| const paths = svgElement.querySelectorAll('.edgePath, path, .flowchart-link'); |
| paths.forEach(path => { |
| path.setAttribute('stroke', colors.pathStroke); |
| path.setAttribute('stroke-width', colors.pathStrokeWidth); |
| }); |
|
|
| |
| const links = svgElement.querySelectorAll('.flowchart-link, .edgeLabel'); |
| links.forEach(link => { |
| link.setAttribute('stroke', colors.linkColor); |
| link.setAttribute('fill', colors.linkColor); |
| }); |
|
|
| |
| const textElements = svgElement.querySelectorAll('text, .nodeLabel text, .edgeLabel text'); |
| textElements.forEach(text => { |
| text.setAttribute('fill', colors.textColor); |
| }); |
|
|
| |
| const markers = svgElement.querySelectorAll('marker, marker path'); |
| markers.forEach(marker => { |
| marker.setAttribute('fill', colors.pathStroke); |
| marker.setAttribute('stroke', colors.pathStroke); |
| }); |
|
|
| console.log(`🎨 Applied Mermaid styles: ${rects.length} rects, ${clusters.length} clusters, ${paths.length} paths, ${textElements.length} text elements`); |
|
|
| } catch (error) { |
| console.error('❌ Error applying styles to SVG:', error); |
| } |
| } |
|
|
| |
| function getComputedStylesForMermaid(mermaidElement) { |
| try { |
| |
| const essentialStyles = ` |
| .mermaid rect:not(.flowchart-link), |
| .mermaid .node rect, |
| .mermaid .nodeLabel rect { |
| rx: 8px !important; |
| ry: 8px !important; |
| } |
| |
| .mermaid .cluster rect { |
| rx: 8px !important; |
| ry: 8px !important; |
| } |
| |
| .mermaid .nodeLabel p { |
| color: black !important; |
| } |
| |
| .mermaid .edgeLabel { |
| color: black !important; |
| } |
| |
| .mermaid .edgePath { |
| stroke: #333 !important; |
| } |
| |
| .mermaid .node { |
| fill: #fff !important; |
| stroke: #333 !important; |
| } |
| |
| .mermaid .cluster { |
| fill: #f9f9f9 !important; |
| stroke: #333 !important; |
| } |
| `; |
|
|
| console.log(`🎨 Using essential CSS styles for Mermaid`); |
| return essentialStyles; |
|
|
| } catch (error) { |
| console.error('❌ Error getting CSS styles:', error); |
| return null; |
| } |
| } |
|
|
| |
| function forceMermaidThemeUpdate(mermaidElement) { |
| try { |
| |
| const currentTheme = document.documentElement.getAttribute("data-theme"); |
| console.log(`🎨 Forcing Mermaid theme update to: ${currentTheme}`); |
|
|
| |
| const mermaidCode = mermaidElement.textContent || mermaidElement.innerText; |
| if (!mermaidCode) { |
| console.log(`❌ No Mermaid code found to re-render`); |
| return false; |
| } |
|
|
| |
| if (window.mermaid) { |
| |
| const config = { |
| theme: currentTheme === 'dark' ? 'dark' : 'neutral', |
| autoTheme: true |
| }; |
|
|
| console.log(`🔄 Re-rendering Mermaid with config:`, config); |
|
|
| |
| mermaid.init(undefined, mermaidElement); |
|
|
| return true; |
| } else { |
| console.log(`❌ Mermaid API not available`); |
| return false; |
| } |
| } catch (error) { |
| console.error(`❌ Error forcing Mermaid theme update:`, error); |
| return false; |
| } |
| } |
|
|
| |
| function convertSvgToImagePreservingDimensions(svgElement, wrapper, originalMermaid) { |
| console.log(`🔄 Converting SVG to image with EXACT dimension preservation`); |
|
|
| try { |
| |
| const wrapperRect = wrapper.getBoundingClientRect(); |
| const wrapperWidth = Math.round(wrapperRect.width); |
| const wrapperHeight = Math.round(wrapperRect.height); |
|
|
| console.log(`📏 Wrapper dimensions:`, { width: wrapperWidth, height: wrapperHeight }); |
|
|
| |
| const clonedSvg = svgElement.cloneNode(true); |
|
|
| |
| applyMermaidStylesToSvg(clonedSvg); |
|
|
| |
| const zoomFactor = 2; |
| const imageWidth = wrapperWidth * zoomFactor; |
| const imageHeight = wrapperHeight * zoomFactor; |
|
|
| |
| clonedSvg.setAttribute('width', imageWidth); |
| clonedSvg.setAttribute('height', imageHeight); |
| clonedSvg.style.width = `${imageWidth}px`; |
| clonedSvg.style.height = `${imageHeight}px`; |
|
|
| console.log(`🔍 Creating zoomable image:`, { |
| original: { width: wrapperWidth, height: wrapperHeight }, |
| zoomed: { width: imageWidth, height: imageHeight }, |
| factor: zoomFactor |
| }); |
|
|
| |
| const svgData = new XMLSerializer().serializeToString(clonedSvg); |
| const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); |
| const svgUrl = URL.createObjectURL(svgBlob); |
|
|
| |
| const imgElement = document.createElement('img'); |
| imgElement.src = svgUrl; |
| imgElement.style.width = `${wrapperWidth}px`; |
| imgElement.style.height = `${wrapperHeight}px`; |
| imgElement.style.display = 'block'; |
| imgElement.setAttribute('data-zoomable', '1'); |
| imgElement.classList.add('mermaid-zoom-image'); |
|
|
| |
| imgElement.setAttribute('data-zoom-width', imageWidth); |
| imgElement.setAttribute('data-zoom-height', imageHeight); |
|
|
| console.log(`🖼️ Image created with exact dimensions:`, { width: wrapperWidth, height: wrapperHeight }); |
|
|
| |
| wrapper.innerHTML = ''; |
| wrapper.appendChild(imgElement); |
|
|
| |
| wrapper.classList.remove("converting"); |
|
|
| |
| imgElement.onload = () => { |
| console.log(`✅ Image loaded, initializing REAL medium-zoom`); |
|
|
| const isDark = document.documentElement.getAttribute("data-theme") === "dark"; |
| const background = isDark ? "rgba(0,0,0,.9)" : "rgba(0,0,0,.85)"; |
|
|
| |
| const zoomInstance = window.mediumZoom(imgElement, { |
| background, |
| margin: 24, |
| scrollOffset: 0, |
| }); |
|
|
| console.log(`🎉 REAL medium-zoom initialized with exact dimensions!`); |
|
|
| |
| const forceCorrectColors = () => { |
| |
| const zoomedImage = document.querySelector('.medium-zoom-image--opened'); |
| if (zoomedImage && zoomedImage.classList.contains('mermaid-zoom-image')) { |
| console.log(`🎨 Forcing correct colors for Mermaid zoom image`); |
| zoomedImage.style.filter = 'none'; |
| zoomedImage.style.setProperty('filter', 'none', 'important'); |
| } |
|
|
| |
| const overlay = document.querySelector('.medium-zoom-overlay'); |
| if (overlay) { |
| console.log(`🔝 Forcing high z-index for overlay`); |
| overlay.style.zIndex = '9999999'; |
| overlay.style.setProperty('z-index', '9999999', 'important'); |
| } |
|
|
| if (zoomedImage) { |
| console.log(`🔝 Forcing high z-index for zoomed image`); |
| zoomedImage.style.zIndex = '10000000'; |
| zoomedImage.style.setProperty('z-index', '10000000', 'important'); |
| } |
| }; |
|
|
| |
| imgElement.addEventListener('zoom:open', forceCorrectColors); |
| imgElement.addEventListener('zoom:opened', forceCorrectColors); |
|
|
| |
| const themeObserver = new MutationObserver(() => { |
| console.log(`🎨 Theme changed, forcing Mermaid re-render with new theme`); |
|
|
| |
| const currentTheme = document.documentElement.getAttribute("data-theme"); |
| console.log(`🎨 Current theme: ${currentTheme}`); |
|
|
| |
| setTimeout(() => { |
| |
| const themeUpdated = forceMermaidThemeUpdate(originalMermaid); |
|
|
| if (themeUpdated) { |
| |
| setTimeout(() => { |
| |
| const updatedSvgElement = originalMermaid.querySelector("svg"); |
| if (updatedSvgElement) { |
| console.log(`🔄 Re-converting with updated SVG for theme: ${currentTheme}`); |
| convertSvgToImagePreservingDimensions(updatedSvgElement, wrapper, originalMermaid); |
| } else { |
| console.log(`❌ No updated SVG found after theme change`); |
| } |
| }, 200); |
| } else { |
| console.log(`❌ Failed to update Mermaid theme, using current SVG`); |
| |
| const currentSvgElement = originalMermaid.querySelector("svg"); |
| if (currentSvgElement) { |
| convertSvgToImagePreservingDimensions(currentSvgElement, wrapper, originalMermaid); |
| } |
| } |
| }, 100); |
| }); |
|
|
| themeObserver.observe(document.documentElement, { |
| attributes: true, |
| attributeFilter: ["data-theme"], |
| }); |
|
|
| wrapper._themeObserver = themeObserver; |
| }; |
|
|
| imgElement.onerror = (error) => { |
| console.error(`❌ Error loading SVG as image:`, error); |
| |
| wrapper.innerHTML = ''; |
| wrapper.appendChild(originalMermaid); |
| wrapper.classList.remove("converting"); |
| wrapper.addEventListener("click", (e) => { |
| e.preventDefault(); |
| e.stopPropagation(); |
| openMermaidZoom(wrapper, originalMermaid); |
| }); |
| }; |
|
|
| } catch (error) { |
| console.error("❌ Error converting SVG to image:", error); |
| |
| wrapper.classList.remove("converting"); |
| wrapper.addEventListener("click", (e) => { |
| e.preventDefault(); |
| e.stopPropagation(); |
| openMermaidZoom(wrapper, originalMermaid); |
| }); |
| } |
| } |
|
|
| |
| function initializeMediumZoomOnSvg(svgElement, wrapper, originalMermaid) { |
| try { |
| |
| const bbox = svgElement.getBBox(); |
| const width = bbox.width || svgElement.clientWidth || 800; |
| const height = bbox.height || svgElement.clientHeight || 600; |
|
|
| |
| svgElement.setAttribute('width', width); |
| svgElement.setAttribute('height', height); |
| svgElement.style.width = '100%'; |
| svgElement.style.height = 'auto'; |
| svgElement.style.display = 'block'; |
|
|
| |
| wrapper.classList.remove("converting"); |
|
|
| console.log(`📏 SVG dimensions fixed:`, { width, height }); |
|
|
| |
| const isDark = document.documentElement.getAttribute("data-theme") === "dark"; |
| const background = isDark ? "rgba(0,0,0,.9)" : "rgba(0,0,0,.85)"; |
|
|
| |
| window.mediumZoom(wrapper, { |
| background, |
| margin: 24, |
| scrollOffset: 0, |
| }); |
|
|
| console.log(`🎉 Medium-zoom initialized directly on SVG wrapper!`); |
|
|
| |
| const themeObserver = new MutationObserver(() => { |
| console.log(`🎨 Theme changed, updating medium-zoom background`); |
| |
| initializeMediumZoomOnSvg(svgElement, wrapper, originalMermaid); |
| }); |
|
|
| themeObserver.observe(document.documentElement, { |
| attributes: true, |
| attributeFilter: ["data-theme"], |
| }); |
|
|
| |
| wrapper._themeObserver = themeObserver; |
|
|
| } catch (error) { |
| console.error("❌ Error initializing medium-zoom on SVG:", error); |
| |
| wrapper.classList.remove("converting"); |
| wrapper.addEventListener("click", (e) => { |
| e.preventDefault(); |
| e.stopPropagation(); |
| openMermaidZoom(wrapper, originalMermaid); |
| }); |
| } |
| } |
|
|
| |
| function waitForMermaidStable(mermaidEl, wrapper, index) { |
| |
| console.log(`⏳ Waiting for Mermaid ${index} to stabilize...`); |
|
|
| setTimeout(() => { |
| const svgElement = mermaidEl.querySelector("svg"); |
| if (svgElement) { |
| console.log(`🎯 Converting Mermaid ${index} to image`); |
| convertSvgToImageForMediumZoom(svgElement, wrapper, mermaidEl); |
| } else { |
| console.log(`❌ No SVG found in Mermaid element ${index}`); |
| } |
| }, 2000); |
| } |
|
|
| |
| function convertSvgToImageForMediumZoom(svgElement, wrapper, originalMermaid) { |
| console.log(`🔄 Converting SVG to image for REAL medium-zoom`); |
|
|
| try { |
| |
| const clonedSvg = svgElement.cloneNode(true); |
|
|
| |
| applyMermaidStylesToSvg(clonedSvg); |
|
|
| |
| const bbox = clonedSvg.getBBox(); |
| const width = bbox.width || clonedSvg.clientWidth || 800; |
| const height = bbox.height || clonedSvg.clientHeight || 600; |
|
|
| console.log(`📏 SVG dimensions:`, { width, height }); |
|
|
| |
| const svgData = new XMLSerializer().serializeToString(clonedSvg); |
|
|
| |
| clonedSvg.setAttribute("width", width); |
| clonedSvg.setAttribute("height", height); |
| const svgWithDimensions = new XMLSerializer().serializeToString(clonedSvg); |
|
|
| |
| const svgBlob = new Blob([svgWithDimensions], { |
| type: "image/svg+xml;charset=utf-8", |
| }); |
| const svgUrl = URL.createObjectURL(svgBlob); |
|
|
| |
| const imgElement = document.createElement("img"); |
| imgElement.src = svgUrl; |
| imgElement.style.width = "100%"; |
| imgElement.style.height = "auto"; |
| imgElement.style.display = "block"; |
| imgElement.setAttribute("data-zoomable", "1"); |
|
|
| |
| wrapper.innerHTML = ""; |
| wrapper.appendChild(imgElement); |
|
|
| |
| wrapper.classList.remove("converting"); |
|
|
| console.log(`🖼️ SVG converted to img element`); |
|
|
| |
| imgElement.onload = () => { |
| console.log(`✅ Image loaded, initializing REAL medium-zoom`); |
|
|
| const isDark = document.documentElement.getAttribute("data-theme") === "dark"; |
| const background = isDark ? "rgba(0,0,0,.9)" : "rgba(0,0,0,.85)"; |
|
|
| |
| window.mediumZoom(imgElement, { |
| background, |
| margin: 24, |
| scrollOffset: 0, |
| }); |
|
|
| console.log(`🎉 REAL medium-zoom initialized on Mermaid!`); |
|
|
| |
| const themeObserver = new MutationObserver(() => { |
| console.log(`🎨 Theme changed, reconverting Mermaid image`); |
| |
| convertSvgToImageForMediumZoom(svgElement, wrapper, originalMermaid); |
| }); |
|
|
| themeObserver.observe(document.documentElement, { |
| attributes: true, |
| attributeFilter: ["data-theme"], |
| }); |
|
|
| |
| wrapper._themeObserver = themeObserver; |
| }; |
|
|
| imgElement.onerror = (error) => { |
| console.error(`❌ Error loading SVG as image:`, error); |
| |
| wrapper.innerHTML = ""; |
| wrapper.appendChild(originalMermaid); |
| wrapper.addEventListener("click", (e) => { |
| e.preventDefault(); |
| e.stopPropagation(); |
| openMermaidZoom(wrapper, originalMermaid); |
| }); |
| }; |
|
|
| } catch (error) { |
| console.error("❌ Error converting SVG to image:", error); |
| |
| wrapper.addEventListener("click", (e) => { |
| e.preventDefault(); |
| e.stopPropagation(); |
| openMermaidZoom(wrapper, originalMermaid); |
| }); |
| } |
| } |
|
|
| |
| function openMermaidZoom(wrapper, mermaidElement) { |
| |
| const overlay = document.createElement("div"); |
| overlay.className = "medium-zoom-overlay"; |
| overlay.style.cssText = ` |
| position: fixed; |
| top: 0; |
| left: 0; |
| width: 100%; |
| height: 100%; |
| background: rgba(0, 0, 0, 0.85); |
| z-index: 9999; |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| cursor: zoom-out; |
| opacity: 0; |
| transition: opacity 0.3s ease; |
| `; |
|
|
| |
| const zoomImage = document.createElement("div"); |
| zoomImage.className = "medium-zoom-image"; |
| zoomImage.style.cssText = ` |
| max-width: 90%; |
| max-height: 90%; |
| background: white; |
| border-radius: 8px; |
| padding: 20px; |
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5); |
| transform: scale(0.8); |
| transition: transform 0.3s ease; |
| overflow: auto; |
| `; |
|
|
| |
| const clonedMermaid = mermaidElement.cloneNode(true); |
| clonedMermaid.style.cssText = ` |
| width: 100%; |
| height: auto; |
| max-width: none; |
| display: block; |
| `; |
|
|
| zoomImage.appendChild(clonedMermaid); |
| overlay.appendChild(zoomImage); |
|
|
| |
| document.body.appendChild(overlay); |
|
|
| |
| requestAnimationFrame(() => { |
| overlay.style.opacity = "1"; |
| zoomImage.style.transform = "scale(1)"; |
| }); |
|
|
| |
| overlay.addEventListener("click", (e) => { |
| if (e.target === overlay) { |
| closeMermaidZoom(overlay); |
| } |
| }); |
|
|
| |
| const handleEscape = (e) => { |
| if (e.key === "Escape") { |
| closeMermaidZoom(overlay); |
| document.removeEventListener("keydown", handleEscape); |
| } |
| }; |
| document.addEventListener("keydown", handleEscape); |
|
|
| |
| const handleScroll = () => { |
| closeMermaidZoom(overlay); |
| }; |
| window.addEventListener("wheel", handleScroll, { passive: true }); |
| window.addEventListener("touchmove", handleScroll, { passive: true }); |
| window.addEventListener("scroll", handleScroll, { passive: true }); |
|
|
| |
| overlay._handlers = { handleEscape, handleScroll }; |
| } |
|
|
| function closeMermaidZoom(overlay) { |
| |
| overlay.style.opacity = "0"; |
| const zoomImage = overlay.querySelector(".medium-zoom-image"); |
| if (zoomImage) { |
| zoomImage.style.transform = "scale(0.8)"; |
| } |
|
|
| |
| if (overlay._handlers) { |
| document.removeEventListener("keydown", overlay._handlers.handleEscape); |
| window.removeEventListener("wheel", overlay._handlers.handleScroll); |
| window.removeEventListener("touchmove", overlay._handlers.handleScroll); |
| window.removeEventListener("scroll", overlay._handlers.handleScroll); |
| } |
|
|
| |
| setTimeout(() => { |
| if (document.body.contains(overlay)) { |
| document.body.removeChild(overlay); |
| } |
| }, 300); |
| } |
|
|
| |
| function cleanupMermaidObservers(wrapper) { |
| if (wrapper._themeObserver) { |
| wrapper._themeObserver.disconnect(); |
| wrapper._themeObserver = null; |
| } |
| } |
|
|
| |
| function setupMermaidZoom() { |
| console.log(`🎯 setupMermaidZoom called`); |
| const mermaidElements = document.querySelectorAll(".mermaid"); |
| console.log(`🔍 Found ${mermaidElements.length} Mermaid elements`); |
|
|
| let processedCount = 0; |
| mermaidElements.forEach((mermaidEl, index) => { |
| |
| if ( |
| mermaidEl.parentElement && |
| mermaidEl.parentElement.classList.contains("mermaid-zoom-wrapper") |
| ) { |
| console.log(`📦 Mermaid ${index} already wrapped`); |
| processedCount++; |
| return; |
| } |
|
|
| console.log(`📦 Wrapping Mermaid element ${index}`); |
|
|
| |
| const wrapper = document.createElement("div"); |
| wrapper.className = "mermaid-zoom-wrapper"; |
| wrapper.setAttribute("data-zoomable", "1"); |
|
|
| |
| mermaidEl.parentNode.insertBefore(wrapper, mermaidEl); |
|
|
| |
| wrapper.appendChild(mermaidEl); |
|
|
| |
| wrapper.style.display = "block"; |
| wrapper.style.width = "100%"; |
| wrapper.style.maxWidth = "100%"; |
|
|
| |
| wrapper.classList.add("converting"); |
|
|
| |
| console.log(`✅ Converting Mermaid to image for REAL medium-zoom`); |
|
|
| |
| console.log(`✅ Setting up REAL medium-zoom for Mermaid ${index}`); |
|
|
| |
| setTimeout(() => { |
| const svgElement = mermaidEl.querySelector("svg"); |
| if (svgElement) { |
| console.log(`🎯 Converting SVG to image with dimension preservation`); |
| convertSvgToImagePreservingDimensions(svgElement, wrapper, mermaidEl); |
| } else { |
| console.log(`❌ No SVG found in Mermaid element ${index}`); |
| } |
| }, 1000); |
| }); |
|
|
| console.log(`✅ Processed ${processedCount} already wrapped, ${mermaidElements.length - processedCount} new diagrams`); |
| } |
|
|
| |
| function setupGlobalMermaidColorFix() { |
| const observer = new MutationObserver((mutations) => { |
| mutations.forEach((mutation) => { |
| if (mutation.type === 'childList') { |
| |
| const zoomedMermaidImage = document.querySelector('.medium-zoom-image--opened.mermaid-zoom-image'); |
| if (zoomedMermaidImage) { |
| console.log(`🎨 Global fix: Found zoomed Mermaid image, forcing correct colors and z-index`); |
| zoomedMermaidImage.style.filter = 'none'; |
| zoomedMermaidImage.style.setProperty('filter', 'none', 'important'); |
| zoomedMermaidImage.style.zIndex = '10000000'; |
| zoomedMermaidImage.style.setProperty('z-index', '10000000', 'important'); |
| } |
|
|
| |
| const overlay = document.querySelector('.medium-zoom-overlay'); |
| if (overlay) { |
| console.log(`🔝 Global fix: Found medium-zoom overlay, forcing high z-index`); |
| overlay.style.zIndex = '9999999'; |
| overlay.style.setProperty('z-index', '9999999', 'important'); |
| } |
| } |
| }); |
| }); |
|
|
| observer.observe(document.body, { |
| childList: true, |
| subtree: true |
| }); |
|
|
| console.log(`🎨 Global Mermaid color and z-index fix observer started`); |
| } |
|
|
| |
| function initMermaidZoom() { |
| console.log("🎯 initMermaidZoom called"); |
|
|
| |
| const checkMediumZoom = () => { |
| if (window.mediumZoom) { |
| console.log("✅ mediumZoom found, initializing Mermaid zoom"); |
| setupMermaidZoom(); |
| } else { |
| console.log("⏳ Waiting for mediumZoom..."); |
| setTimeout(checkMediumZoom, 100); |
| } |
| }; |
|
|
| checkMediumZoom(); |
| } |
|
|
| |
| window.MermaidZoom = { |
| init: initMermaidZoom, |
| setup: setupMermaidZoom, |
| cleanup: cleanupMermaidObservers, |
| convertSvgToImage: convertSvgToImageForMediumZoom, |
| openZoom: openMermaidZoom, |
| closeZoom: closeMermaidZoom |
| }; |
|
|
| |
| if (document.readyState === "loading") { |
| document.addEventListener("DOMContentLoaded", () => { |
| initMermaidZoom(); |
| setupGlobalMermaidColorFix(); |
| }); |
| } else { |
| initMermaidZoom(); |
| setupGlobalMermaidColorFix(); |
| } |
|
|
| |
| window.addEventListener("load", () => { |
| setTimeout(() => { |
| initMermaidZoom(); |
| setupGlobalMermaidColorFix(); |
| }, 1000); |
| }); |
|
|
| |
| let resizeTimeout; |
| const observer = new MutationObserver(() => { |
| |
| clearTimeout(resizeTimeout); |
| resizeTimeout = setTimeout(() => { |
| |
| const mermaidElements = document.querySelectorAll(".mermaid"); |
| const wrappedElements = document.querySelectorAll(".mermaid-zoom-wrapper"); |
|
|
| |
| if (mermaidElements.length > wrappedElements.length) { |
| console.log(`🔄 New Mermaid diagrams detected: ${mermaidElements.length} total, ${wrappedElements.length} wrapped`); |
| initMermaidZoom(); |
| } |
| }, 500); |
| }); |
|
|
| observer.observe(document.body, { |
| childList: true, |
| subtree: true, |
| }); |
|
|
| console.log("🚀 Mermaid Zoom Script v19.0 loaded - DEBOUNCED observer to prevent resize loops"); |
| } |
|
|