var j=Object.defineProperty;var A=(r,t,e)=>t in r?j(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var h=(r,t,e)=>A(r,typeof t!="symbol"?t+"":t,e);import{a as R,W as z,S as W,A as G,H as V,V as y,C as L}from"./state-B_bTBsCz.js";const k=1080,x=1920,v={};function B(r){if(v[r])return v[r];const t=document.createElement("canvas");t.width=540,t.height=960;const e=t.getContext("2d"),n={lab:["#123257","#081a33","#020711"],warm:["#3a2a3f","#1b1426","#07050c"],red:["#4a1626","#1e0b19","#06030a"],clean:["#1d4a6e","#0b2441","#030b18"]},[s,a,i]=n[r]??n.lab,o=e.createRadialGradient(270,400,20,270,480,620);o.addColorStop(0,s),o.addColorStop(.5,a),o.addColorStop(1,i),e.fillStyle=o,e.fillRect(0,0,540,960),e.strokeStyle="rgba(120,190,255,0.05)",e.lineWidth=1;for(let l=0;l<=540;l+=30)e.beginPath(),e.moveTo(l,0),e.lineTo(l,960),e.stroke();for(let l=0;l<=960;l+=30)e.beginPath(),e.moveTo(0,l),e.lineTo(540,l),e.stroke();const c=new L(t);return c.colorSpace=W,v[r]=c,c}class q{constructor(){h(this,"gl");h(this,"renderer");h(this,"model");h(this,"camera",new R(35,9/16,.05,100));h(this,"cams",[]);h(this,"W",1080);h(this,"H",1920);this.gl=document.createElement("canvas"),this.renderer=new z({canvas:this.gl,antialias:!0,preserveDrawingBuffer:!0,alpha:!1,powerPreference:"high-performance"}),this.renderer.outputColorSpace=W,this.renderer.toneMapping=G,this.renderer.toneMappingExposure=1.05,this.renderer.setPixelRatio(1),this.model=new V(this.renderer),this.setSize(1080,1920)}setSize(t,e){this.W=t,this.H=e,this.renderer.setSize(t,e,!1)}setupCam(t,e,n){t.aspect=n,t.fov=e.cam.fov,t.position.set(...e.cam.pos);const s=new y(...e.cam.target),a=e.cam.follow??0;if(a>0){const o=this.model.anchors.pain.clone().sub(s).multiplyScalar(a);t.position.add(o),s.add(o)}t.up.set(0,1,0),e.cam.roll&&t.up.applyAxisAngle(new y(0,0,1),e.cam.roll),t.lookAt(s),t.updateProjectionMatrix();const i=e.cam.shift;i&&(t.projectionMatrix.elements[8]-=2*i[0]-1,t.projectionMatrix.elements[9]-=1-2*i[1],t.projectionMatrixInverse.copy(t.projectionMatrix).invert()),t.updateMatrixWorld()}render(t,e,n,s={w:k,h:x}){const{W:a,H:i,renderer:o}=this;for(o.setScissorTest(!0),o.autoClear=!1,o.setClearColor("#02060d",1),o.setViewport(0,0,a,i),o.setScissor(0,0,a,i),o.clear();this.cams.length{const[p,u,M,m]=d.rect,S=Math.round(p*a),b=Math.round(u*i),g=Math.round(M*a),f=Math.round(m*i);this.model.apply(d.state),this.model.scene.background=B(d.bg??"lab");const T=this.cams[w];this.setupCam(T,d.state,g/f),o.setViewport(S,i-b-f,g,f),o.setScissor(S,i-b-f,g,f),o.render(this.model.scene,T);const P={};for(const[E,H]of Object.entries(this.model.anchors))P[E]=H.clone();c.push(P)}),o.setScissorTest(!1),e.save(),e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,a,i),e.drawImage(this.gl,0,0,a,i);const l=a/s.w,C=i/s.h;if(e.setTransform(l,0,0,C,0,0),I(e,n,s.w,s.h),t.overlay){const d={W:s.w,H:s.h,t:n,model:this.model,world:(w,p=0)=>{const u=t.views[p],M=this.cams[p],m=w.clone().project(M),[S,b,g,f]=u.rect;return{x:(S+(m.x+1)/2*g)*s.w,y:(b+(1-m.y)/2*f)*s.h,z:m.z}},anchor:(w,p=0)=>{var u;return d.world(((u=c[p])==null?void 0:u[w])??new y,p)}};t.overlay(e,d)}t.fade&&t.fade>0&&(e.fillStyle=`rgba(0,0,0,${Math.min(1,t.fade)})`,e.fillRect(0,0,s.w,s.h)),e.restore()}}function I(r,t,e,n){r.save(),r.globalCompositeOperation="lighter";for(let a=0;a<40;a++){const i=Math.sin(a*91.7)*.5+.5,o=Math.sin(a*37.3+1)*.5+.5,c=Math.sin(a*13.1+2)*.5+.5,l=(i*e+Math.sin(t*.2+a)*30)%e,C=((o*n-t*(8+c*18))%n+n)%n,d=1.2+c*2.4;r.fillStyle=`rgba(120,200,255,${.05+c*.12})`,r.beginPath(),r.arc(l,C,d,0,Math.PI*2),r.fill()}r.restore();const s=r.createRadialGradient(e/2,n*.45,n*.3,e/2,n*.5,n*.78);s.addColorStop(0,"rgba(0,0,0,0)"),s.addColorStop(1,"rgba(0,0,0,0.55)"),r.fillStyle=s,r.fillRect(0,0,e,n)}export{q as E,k as L,x as a};