import{u as f,r as a,j as c}from"./components-xz3w7t4N.js";const d="preview-updates";function w(){const{previewId:s}=f(),e=a.useRef(null),t=a.useRef(),[r,u]=a.useState(""),l=a.useCallback(()=>{e.current&&r&&(e.current.src="",requestAnimationFrame(()=>{e.current&&(e.current.src=r)}))},[r]),n=a.useCallback(()=>{t.current&&r&&t.current.postMessage({type:"preview-ready",previewId:s,url:r,timestamp:Date.now()})},[s,r]);return a.useEffect(()=>{t.current=new BroadcastChannel(d),t.current.onmessage=o=>{o.data.previewId===s&&(o.data.type==="refresh-preview"||o.data.type==="file-change")&&l()};const i=`https://${s}.local-credentialless.webcontainer-api.io`;return u(i),e.current&&(e.current.src=i),n(),()=>{t.current?.close()}},[s,l,n]),c.jsx("div",{className:"w-full h-full",children:c.jsx("iframe",{ref:e,title:"WebContainer Preview",className:"w-full h-full border-none",sandbox:"allow-scripts allow-forms allow-popups allow-modals allow-storage-access-by-user-activation allow-same-origin",allow:"cross-origin-isolated",loading:"eager",onLoad:n})})}export{w as default};
