import { useEffect, useRef, useState, useLayoutEffect } from 'react'; import Editor from '@monaco-editor/react'; import DemoSelector from './DemoSelector'; // Auto-scale Hook - simplified back to its original purpose function useAutoScale(iframeRef, wrapRef) { useLayoutEffect(() => { if (!iframeRef.current || !wrapRef.current) return; const calc = () => { const doc = iframeRef.current.contentDocument; if (!doc || !doc.body) return; // Inject base styles for responsive scaling, if not present if (!doc.querySelector('style[data-responsive-scale]')) { const style = doc.createElement('style'); style.setAttribute('data-responsive-scale', ''); style.innerHTML = ` html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } .container { position: relative; width: 100%; height: 100vh; box-sizing: border-box; } .box { position: absolute; box-sizing: border-box; overflow: hidden; } .box img { max-width: 100%; height: auto; } .box p, .box span:not(.sidebar-text) { font-size: max(16px, 1.2vw); line-height: 1.4; } .box button { font-size: max(14px, 1.0vw); padding: max(6px, 0.4vw) max(12px, 0.8vw); } .box input { font-size: max(16px, 1.2vw); padding: max(6px, 0.4vw) max(12px, 0.8vw); } .box svg { width: max(20px, 1.5vw); height: max(20px, 1.5vw); } `; doc.head.appendChild(style); } }; const iframe = iframeRef.current; iframe.addEventListener('load', calc); calc(); window.addEventListener('resize', calc); return () => { iframe.removeEventListener('load', calc); window.removeEventListener('resize', calc); }; }, [iframeRef, wrapRef]); } // Instagram-specific preview component function InstagramPreview({ code }) { const iframeRef = useRef(null); const wrapRef = useRef(null); useLayoutEffect(() => { if (!iframeRef.current || !wrapRef.current) return; const calc = () => { const doc = iframeRef.current.contentDocument; if (!doc || !doc.body) return; // Inject Instagram-specific responsive styles if (!doc.querySelector('style[data-instagram-responsive]')) { const style = doc.createElement('style'); style.setAttribute('data-instagram-responsive', ''); style.innerHTML = ` html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; } .container { position: relative; width: 100%; height: 100vh; box-sizing: border-box; overflow: hidden; } .box { position: absolute; box-sizing: border-box; overflow: hidden; } // .box img { max-width: 100%; height: auto; } // .box p, .box span { font-size: max(14px, 1.0vw); line-height: 1.4; } // .box button { font-size: max(12px, 0.9vw); padding: max(4px, 0.3vw) max(8px, 0.6vw); } // .box input { font-size: max(14px, 1.0vw); padding: max(4px, 0.3vw) max(8px, 0.6vw); } // .box svg { width: max(16px, 1.2vw); height: max(16px, 1.2vw); } `; doc.head.appendChild(style); } }; const iframe = iframeRef.current; iframe.addEventListener('load', calc); calc(); window.addEventListener('resize', calc); return () => { iframe.removeEventListener('load', calc); window.removeEventListener('resize', calc); }; }, [iframeRef, wrapRef]); return (