');
}
function onPreviewMessage(e){if(!e.data||e.data.type!=='select')return;state.selected=e.data;drawInspector();}
function drawInspector(){
const el=state.selected;const box=document.getElementById('inspector');if(!el){box.className='inspector-empty';box.innerHTML='Select an element
Click anything in the preview to edit its content and appearance.';return;}
box.className='';box.innerHTML=`
`; const send=()=>{const p=document.getElementById('preview').contentWindow;const style={fontSize:iFont.value,fontWeight:iWeight.value,color:iColor.value,background:iBg.value,padding:iPad.value,margin:iMargin.value,width:iWidth.value,height:iHeight.value,borderRadius:iRadius.value};p.postMessage({type:'edit',text:document.getElementById('iText').value,style},'*');}; ['iText','iFont','iWeight','iColor','iBg','iPad','iMargin','iWidth','iHeight','iRadius'].forEach(id=>document.getElementById(id).addEventListener('input',send)); document.getElementById('delete').onclick=()=>document.getElementById('preview').contentWindow.postMessage({type:'edit',text:'',style:{display:'none'}},'*'); document.getElementById('duplicate').onclick=()=>document.getElementById('preview').contentWindow.postMessage({type:'edit',text:el.text+'',style:{}},'*'); } function refreshSections(){ const list=document.getElementById('sections'); if(!list)return; const parser=new DOMParser();const d=parser.parseFromString(state.html,'text/html');const els=[...d.body.children].slice(0,30); list.innerHTML=els.map((x,i)=>``).join('')||'
'; }
function addElement(){ const p=document.getElementById('preview').contentWindow; p.postMessage({type:'edit',text:'New section',style:{display:'block',padding:'24px',background:'#f4f4f4',color:'#111'}},'*'); }
async function runExport(){
const modal=document.getElementById('modal'), progress=document.getElementById('progress'), finish=document.getElementById('finish'); modal.classList.add('open'); finish.classList.add('hidden');
const stages=['Saving latest changes','Synchronizing preview and source','Checking project structure','Validating HTML','Checking asset references','Preparing Cloudflare Pages files','Creating ZIP']; progress.innerHTML='';
for(let i=0;iSiteWright export