import{n as e}from"./rolldown-runtime-DAXXjFlN.js";import{Hn as t,Un as n,dn as r,gr as i,yn as a}from"./vendor-Dnfj1twE.js";import{Ht as o,nn as s}from"./ws-Dl8XkIy4.js";import{c,d as l}from"./client-api-D-UNvPyj.js";import{a as u,i as d}from"./uiLogic-C8mcxylk.js";function f(e,t={},n){let r=new m;return Object.assign(r,n),r.show(),r.loadComponent(e,t),r}function p(){return t()?.vnode?.windowContext??window}var m,h=e((()=>{r(),l(),o(),d(),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=[];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);let n=u;if(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 {
              ${n.value?`background: white!important;`:c()==`linux`?``:`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 r=this.window?.document.createElement(`div`);if(this.window&&r&&e){let o=document.querySelector(`[sfc-name="SVGEffects"]`),c=n(e,{...t}),l=i(()=>s().visual,e=>{this.syncStyling()},{deep:!0});if(c.windowContext=this.window,c.appContext=window.CiderApp.app._context,this.window.document.body.appendChild(r),o){let e=o.cloneNode(!0);this.body.appendChild(e)}Object.assign(r.style,{position:`fixed`,inset:0,overflow:`hidden`}),a(c,r),this.window.addEventListener(`beforeunload`,()=>{a(null,r),l()})}}close(){this.window?.close()}}}));export{h as n,p as r,f as t};