import{n as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{Tn as n,Xn as r,qt as i,tn as a,wn as o}from"./vendor-C4JLrdLj.js";import{E as s,Mi as c,Ni as l,x as u}from"./ws-JRT2XE7Y.js";var d=t({PopoutWindow:()=>m,createWindow:()=>f,useWindowContext:()=>p});function f(e,t={},n){let r=new m;return Object.assign(r,n),r.show(),r.loadComponent(e,t),r}function p(){return o()?.vnode?.windowContext??window}var m,h=e((()=>{i(),l(),u(),m=class{window=null;_title=`Cider`;get title(){return this._title}set title(e){this._title=e,this.window&&(this.window.document.title=e)}get body(){return this.window?.document.body}get document(){return this.window?.document}width=400;height=600;top;left;maxWidth;maxHeight;minWidth;minHeight;hideTitlebar=!1;disableResize=!1;alwaysOnTop=!1;inlineTitlebar=!1;vibrancyType=null;syncStyling(){if(!this.window)return;let e=document.body.className,t=document.body.attributes;this.window.document.body.className=e,this.document.documentElement.setAttribute(`style`,document.documentElement.getAttribute(`style`)||``),Array.from(t).forEach(e=>{e.name!==`class`&&this.window.document.body.setAttribute(e.name,e.value)});let n=Array.from(this.window.document.querySelectorAll(`link[rel="stylesheet"]`)),r=Array.from(this.window.document.head.querySelectorAll(`style`));n.forEach(e=>e.remove()),r.forEach(e=>e.remove()),Array.from(document.styleSheets).forEach(e=>{try{if(e.href){let t=this.window.document.createElement(`link`);t.rel=`stylesheet`,t.href=e.href,this.window.document.head.appendChild(t)}else if(e.ownerNode?.textContent){let t=this.window.document.createElement(`style`);t.textContent=e.ownerNode.textContent,this.window.document.head.appendChild(t)}}catch(e){console.error(`Error transferring stylesheet:`,e)}}),Array.from(document.querySelectorAll(`style`)).forEach(e=>{let t=this.window.document.createElement(`style`);t.textContent=e.textContent,this.window.document.head.appendChild(t)})}show(){let e=new URLSearchParams;this.disableResize&&e.append(`disableresize`,`1`),this.alwaysOnTop&&e.append(`alwaysontop`,`1`),this.inlineTitlebar&&c()==`darwin`&&e.append(`inlinetitlebar`,`1`),this.hideTitlebar&&e.append(`hidetitlebar`,`1`),this.vibrancyType&&e.append(`vibrancy`,this.vibrancyType),this.maxWidth!==void 0&&e.append(`maxwidth`,String(this.maxWidth)),this.maxHeight!==void 0&&e.append(`maxheight`,String(this.maxHeight)),this.minWidth!==void 0&&e.append(`minwidth`,String(this.minWidth)),this.minHeight!==void 0&&e.append(`minheight`,String(this.minHeight)),c()==`darwin`&&this.hideTitlebar&&this.inlineTitlebar&&e.delete(`hidetitlebar`);let t=[];if(this.width!==void 0&&(t.push(`width=${this.width}`),e.set(`width`,String(this.width))),this.height!==void 0&&(t.push(`height=${this.height}`),e.set(`height`,String(this.height))),this.top!==void 0&&(t.push(`top=${this.top}`),e.set(`top`,String(this.top))),this.left!==void 0&&(t.push(`left=${this.left}`),e.set(`left`,String(this.left))),e.set(`title`,this.title),this.window=window.open(`about:blank#/?`+e.toString(),``,t.join(`,`)),this.window){let e=document.body.className;document.body.attributes,this.window.document.write(`
        <!DOCTYPE html><html>
        <head>
        <title>${this.title}</title>
        </head>
        <body class="${e}" not-ready="1">
          <style>
            body, html {
              background: transparent!important;
              transition: opacity 0.3s ease;
            }

            body[not-ready="1"] {
              opacity: 0;
            }
          </style>
        </body>
        </html>
      `),this.syncStyling(),setTimeout(()=>{this.window?.document.body.removeAttribute(`not-ready`)},50)}}loadComponent(e,t={}){let i=this.window?.document.createElement(`div`);if(this.window&&i&&e){let o=document.querySelector(`[sfc-name="SVGEffects"]`),c=n(e,{...t}),l=r(()=>s().visual,e=>{this.syncStyling()},{deep:!0});if(c.windowContext=this.window,c.appContext=window.CiderApp.app._context,this.window.document.body.appendChild(i),o){let e=o.cloneNode(!0);this.body.appendChild(e)}Object.assign(i.style,{position:`fixed`,inset:0,overflow:`hidden`}),a(c,i),this.window.addEventListener(`beforeunload`,()=>{a(null,i),l()})}}close(){this.window?.close()}}}));export{d as i,h as n,p as r,f as t};