holostaff-widget 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/dist/{CanvasRenderer-J_XwG2_5.js → CanvasRenderer-DtJMGjQ-.js} +5 -5
  2. package/dist/{CanvasRenderer-J_XwG2_5.js.map → CanvasRenderer-DtJMGjQ-.js.map} +1 -1
  3. package/dist/{Filter-GqToX76B.js → Filter-BZ0p_cLc.js} +2 -2
  4. package/dist/{Filter-GqToX76B.js.map → Filter-BZ0p_cLc.js.map} +1 -1
  5. package/dist/{GpuStencilModesToPixi-Cc8Nerk4.js → GpuStencilModesToPixi-BhdxrQzF.js} +3 -3
  6. package/dist/{GpuStencilModesToPixi-Cc8Nerk4.js.map → GpuStencilModesToPixi-BhdxrQzF.js.map} +1 -1
  7. package/dist/{RenderTargetSystem-Bl4mRBf3.js → RenderTargetSystem-Cbru8Ci0.js} +3 -3
  8. package/dist/{RenderTargetSystem-Bl4mRBf3.js.map → RenderTargetSystem-Cbru8Ci0.js.map} +1 -1
  9. package/dist/{WebGLRenderer-BtNMOOvs.js → WebGLRenderer--845IaSu.js} +5 -5
  10. package/dist/{WebGLRenderer-BtNMOOvs.js.map → WebGLRenderer--845IaSu.js.map} +1 -1
  11. package/dist/{WebGPURenderer-89fMKfXn.js → WebGPURenderer-DBDzoMAw.js} +6 -6
  12. package/dist/{WebGPURenderer-89fMKfXn.js.map → WebGPURenderer-DBDzoMAw.js.map} +1 -1
  13. package/dist/{browserAll-B7LFPR0f.js → browserAll-CIOBMh08.js} +3 -3
  14. package/dist/{browserAll-B7LFPR0f.js.map → browserAll-CIOBMh08.js.map} +1 -1
  15. package/dist/{getTextureBatchBindGroup-CMmHwizJ.js → getTextureBatchBindGroup-DCKtteRk.js} +3 -3
  16. package/dist/{getTextureBatchBindGroup-CMmHwizJ.js.map → getTextureBatchBindGroup-DCKtteRk.js.map} +1 -1
  17. package/dist/hs-widget.es.js +1 -1
  18. package/dist/hs-widget.umd.js +1 -1
  19. package/dist/hs-widget.umd.js.map +1 -1
  20. package/dist/{index-BpOQ7Z5z.js → index-BbQvHSpa.js} +11 -7
  21. package/dist/index-BbQvHSpa.js.map +1 -0
  22. package/dist/{webworkerAll-CAG5YOrW.js → webworkerAll-EB5JX-2r.js} +3 -3
  23. package/dist/{webworkerAll-CAG5YOrW.js.map → webworkerAll-EB5JX-2r.js.map} +1 -1
  24. package/package.json +1 -1
  25. package/dist/index-BpOQ7Z5z.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { B as p } from "./Filter-GqToX76B.js";
2
- import { T as a } from "./index-BpOQ7Z5z.js";
1
+ import { B as p } from "./Filter-BZ0p_cLc.js";
2
+ import { T as a } from "./index-BbQvHSpa.js";
3
3
  const d = {};
4
4
  function G(t, o, u) {
5
5
  let e = 2166136261;
@@ -20,4 +20,4 @@ function f(t, o, u, e) {
20
20
  export {
21
21
  G as g
22
22
  };
23
- //# sourceMappingURL=getTextureBatchBindGroup-CMmHwizJ.js.map
23
+ //# sourceMappingURL=getTextureBatchBindGroup-DCKtteRk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTextureBatchBindGroup-CMmHwizJ.js","sources":["../node_modules/pixi.js/lib/rendering/batcher/gpu/getTextureBatchBindGroup.mjs"],"sourcesContent":["import { BindGroup } from '../../renderers/gpu/shader/BindGroup.mjs';\nimport { Texture } from '../../renderers/shared/texture/Texture.mjs';\n\n\"use strict\";\nconst cachedGroups = {};\nfunction getTextureBatchBindGroup(textures, size, maxTextures) {\n let uid = 2166136261;\n for (let i = 0; i < size; i++) {\n uid ^= textures[i].uid;\n uid = Math.imul(uid, 16777619);\n uid >>>= 0;\n }\n return cachedGroups[uid] || generateTextureBatchBindGroup(textures, size, uid, maxTextures);\n}\nfunction generateTextureBatchBindGroup(textures, size, key, maxTextures) {\n const bindGroupResources = {};\n let bindIndex = 0;\n for (let i = 0; i < maxTextures; i++) {\n const texture = i < size ? textures[i] : Texture.EMPTY.source;\n bindGroupResources[bindIndex++] = texture.source;\n bindGroupResources[bindIndex++] = texture.style;\n }\n const bindGroup = new BindGroup(bindGroupResources);\n cachedGroups[key] = bindGroup;\n return bindGroup;\n}\n\nexport { getTextureBatchBindGroup };\n//# sourceMappingURL=getTextureBatchBindGroup.mjs.map\n"],"names":["cachedGroups","getTextureBatchBindGroup","textures","size","maxTextures","uid","i","generateTextureBatchBindGroup","key","bindGroupResources","bindIndex","texture","Texture","bindGroup","BindGroup"],"mappings":";;AAIA,MAAMA,IAAe,CAAA;AACrB,SAASC,EAAyBC,GAAUC,GAAMC,GAAa;AAC7D,MAAIC,IAAM;AACV,WAASC,IAAI,GAAGA,IAAIH,GAAMG;AACxB,IAAAD,KAAOH,EAASI,CAAC,EAAE,KACnBD,IAAM,KAAK,KAAKA,GAAK,QAAQ,GAC7BA,OAAS;AAEX,SAAOL,EAAaK,CAAG,KAAKE,EAA8BL,GAAUC,GAAME,GAAKD,CAAW;AAC5F;AACA,SAASG,EAA8BL,GAAUC,GAAMK,GAAKJ,GAAa;AACvE,QAAMK,IAAqB,CAAA;AAC3B,MAAIC,IAAY;AAChB,WAASJ,IAAI,GAAGA,IAAIF,GAAaE,KAAK;AACpC,UAAMK,IAAUL,IAAIH,IAAOD,EAASI,CAAC,IAAIM,EAAQ,MAAM;AACvD,IAAAH,EAAmBC,GAAW,IAAIC,EAAQ,QAC1CF,EAAmBC,GAAW,IAAIC,EAAQ;AAAA,EAC5C;AACA,QAAME,IAAY,IAAIC,EAAUL,CAAkB;AAClD,SAAAT,EAAaQ,CAAG,IAAIK,GACbA;AACT;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"getTextureBatchBindGroup-DCKtteRk.js","sources":["../node_modules/pixi.js/lib/rendering/batcher/gpu/getTextureBatchBindGroup.mjs"],"sourcesContent":["import { BindGroup } from '../../renderers/gpu/shader/BindGroup.mjs';\nimport { Texture } from '../../renderers/shared/texture/Texture.mjs';\n\n\"use strict\";\nconst cachedGroups = {};\nfunction getTextureBatchBindGroup(textures, size, maxTextures) {\n let uid = 2166136261;\n for (let i = 0; i < size; i++) {\n uid ^= textures[i].uid;\n uid = Math.imul(uid, 16777619);\n uid >>>= 0;\n }\n return cachedGroups[uid] || generateTextureBatchBindGroup(textures, size, uid, maxTextures);\n}\nfunction generateTextureBatchBindGroup(textures, size, key, maxTextures) {\n const bindGroupResources = {};\n let bindIndex = 0;\n for (let i = 0; i < maxTextures; i++) {\n const texture = i < size ? textures[i] : Texture.EMPTY.source;\n bindGroupResources[bindIndex++] = texture.source;\n bindGroupResources[bindIndex++] = texture.style;\n }\n const bindGroup = new BindGroup(bindGroupResources);\n cachedGroups[key] = bindGroup;\n return bindGroup;\n}\n\nexport { getTextureBatchBindGroup };\n//# sourceMappingURL=getTextureBatchBindGroup.mjs.map\n"],"names":["cachedGroups","getTextureBatchBindGroup","textures","size","maxTextures","uid","i","generateTextureBatchBindGroup","key","bindGroupResources","bindIndex","texture","Texture","bindGroup","BindGroup"],"mappings":";;AAIA,MAAMA,IAAe,CAAA;AACrB,SAASC,EAAyBC,GAAUC,GAAMC,GAAa;AAC7D,MAAIC,IAAM;AACV,WAASC,IAAI,GAAGA,IAAIH,GAAMG;AACxB,IAAAD,KAAOH,EAASI,CAAC,EAAE,KACnBD,IAAM,KAAK,KAAKA,GAAK,QAAQ,GAC7BA,OAAS;AAEX,SAAOL,EAAaK,CAAG,KAAKE,EAA8BL,GAAUC,GAAME,GAAKD,CAAW;AAC5F;AACA,SAASG,EAA8BL,GAAUC,GAAMK,GAAKJ,GAAa;AACvE,QAAMK,IAAqB,CAAA;AAC3B,MAAIC,IAAY;AAChB,WAASJ,IAAI,GAAGA,IAAIF,GAAaE,KAAK;AACpC,UAAMK,IAAUL,IAAIH,IAAOD,EAASI,CAAC,IAAIM,EAAQ,MAAM;AACvD,IAAAH,EAAmBC,GAAW,IAAIC,EAAQ,QAC1CF,EAAmBC,GAAW,IAAIC,EAAQ;AAAA,EAC5C;AACA,QAAME,IAAY,IAAIC,EAAUL,CAAkB;AAClD,SAAAT,EAAaQ,CAAG,IAAIK,GACbA;AACT;","x_google_ignoreList":[0]}
@@ -1,4 +1,4 @@
1
- import { a7 as f } from "./index-BpOQ7Z5z.js";
1
+ import { a7 as f } from "./index-BbQvHSpa.js";
2
2
  export {
3
3
  f as HolostaffWidget
4
4
  };
@@ -894,7 +894,7 @@ fn mainFragment(
894
894
  fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
895
895
  return textureSample(img, imgSampler, texCoord);
896
896
  }
897
- `})),t=this.device.createRenderPipeline({layout:"auto",vertex:{module:this.mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this.mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this.pipelines[e]=t),t}generateMipmap(e){const t=this._getMipmapPipeline(e.format);if(e.dimension==="3d"||e.dimension==="1d")throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");let i=e;const r=e.depthOrArrayLayers||1,n=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const l={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};i=this.device.createTexture(l)}const o=this.device.createCommandEncoder({}),a=t.getBindGroupLayout(0);for(let l=0;l<r;++l){let c=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),h=n?1:0;for(let u=1;u<e.mipLevelCount;++u){const f=i.createView({baseMipLevel:h++,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),d=o.beginRenderPass({colorAttachments:[{view:f,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),g=this.device.createBindGroup({layout:a,entries:[{binding:0,resource:this.sampler},{binding:1,resource:c}]});d.setPipeline(t),d.setBindGroup(0,g),d.draw(3,1,0,0),d.end(),c=f}}if(!n){const l={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r};for(let c=1;c<e.mipLevelCount;++c)o.copyTextureToTexture({texture:i,mipLevel:c-1},{texture:e,mipLevel:c},l),l.width=Math.ceil(l.width/2),l.height=Math.ceil(l.height/2)}return this.device.queue.submit([o.finish()]),n||i.destroy(),e}}class nx{constructor(e){this.textureView=null,this.gpuTexture=e}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.gpuTexture=null}}class Eu{constructor(e){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=e,e.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new kt({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const t={image:Su,buffer:Qb,video:sx,compressed:tx};this._uploads={...t,cube:ix(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gpu=e}initSource(e){var t;return((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){const c=Math.max(e.pixelWidth,e.pixelHeight);e.mipLevelCount=Math.floor(Math.log2(c))+1}let t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST;e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC);const i=vu[e.format]||{blockWidth:1,blockHeight:1},r=Math.ceil(e.pixelWidth/i.blockWidth)*i.blockWidth,n=Math.ceil(e.pixelHeight/i.blockHeight)*i.blockHeight,o={label:e.label,size:{width:r,height:n,depthOrArrayLayers:e.arrayLayerCount},format:e.format,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},a=this._gpu.device.createTexture(o);return e._gpuData[this._renderer.uid]=new nx(a),this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),a}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onUpdateMipmaps(e){this._mipmapGenerator||(this._mipmapGenerator=new rx(this._gpu.device));const t=this.getGpuSource(e);this._mipmapGenerator.generateMipmap(t)}onSourceUnload(e){e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this)}onSourceResize(e){e._gcLastUsed=this._renderer.gc.now;const t=e._gpuData[this._renderer.uid],i=t==null?void 0:t.gpuTexture;i?(i.width!==e.pixelWidth||i.height!==e.pixelHeight)&&(t.destroy(),this._bindGroupHash[e.uid]=null,e._gpuData[this._renderer.uid]=null,this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){var t;return e._gcLastUsed=this._renderer.gc.now,((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]||this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new Gt({0:t,1:t.style,2:new ht({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e){const t=e.source;t._gcLastUsed=this._renderer.gc.now;let i=t._gpuData[this._renderer.uid];return i||(this.initSource(t),i=t._gpuData[this._renderer.uid]),i.textureView||(i.textureView=i.gpuTexture.createView({dimension:t.viewDimension})),i.textureView}generateCanvas(e){const t=this._renderer,i=t.gpu.device.createCommandEncoder(),r=pe.get().createCanvas();r.width=e.source.pixelWidth,r.height=e.source.pixelHeight;const n=r.getContext("webgpu");return n.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:pe.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),i.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:n.getCurrentTexture()},{width:r.width,height:r.height}),t.gpu.device.queue.submit([i.finish()]),r}getPixels(e){const t=this.generateCanvas(e),i=so.getOptimalCanvasAndContext(t.width,t.height),r=i.context;r.drawImage(t,0,0);const{width:n,height:o}=t,a=r.getImageData(0,0,n,o),l=new Uint8ClampedArray(a.data.buffer);return so.returnCanvasAndContext(i),{pixels:l,width:n,height:o}}destroy(){this._managedTextures.destroy();for(const e of Object.keys(this._bindGroupHash)){const t=Number(e),i=this._bindGroupHash[t];i==null||i.destroy()}this._renderer=null,this._gpu=null,this._mipmapGenerator=null,this._gpuSamplers=null,this._bindGroupHash=null}}Eu.extension={type:[A.WebGPUSystem],name:"texture"};class Tu{constructor(){this._maxTextures=0}contextChange(e){const t=new ht({uTransformMatrix:{value:new H,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const i=Gn({name:"graphics",bits:[vc,Sc(this._maxTextures),_y,Vn]});this.shader=new Mt({gpuProgram:i,resources:{localUniforms:t}})}execute(e,t){const i=t.context,r=i.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(i),c=n.encoder;c.setGeometry(a.geometry,r.gpuProgram);const h=n.globalUniforms.bindGroup;c.setBindGroup(0,h,r.gpuProgram);const u=n.renderPipes.uniformBatch.getUniformBindGroup(r.resources.localUniforms,!0);c.setBindGroup(2,u,r.gpuProgram);const f=l.instructions;let d=null;for(let g=0;g<l.instructionSize;g++){const _=f[g];if(_.topology!==d&&(d=_.topology,c.setPipelineFromGeometryProgramAndState(a.geometry,r.gpuProgram,e.state,_.topology)),r.groups[1]=_.bindGroup,!_.gpuBindGroup){const b=_.textures;_.bindGroup=Nn(b.textures,b.count,this._maxTextures),_.gpuBindGroup=n.bindGroup.getBindGroup(_.bindGroup,r.gpuProgram,1)}c.setBindGroup(1,_.bindGroup,r.gpuProgram),c.renderPassEncoder.drawIndexed(_.size,1,_.start)}}destroy(){this.shader.destroy(!0),this.shader=null}}Tu.extension={type:[A.WebGPUPipesAdaptor],name:"graphics"};class Au{init(){const e=Gn({name:"mesh",bits:[ur,vy,Vn]});this._shader=new Mt({gpuProgram:e,resources:{uTexture:j.EMPTY._source,uSampler:j.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new H}}}})}execute(e,t){const i=e.renderer;let r=t._shader;if(!r)r=this._shader,r.groups[2]=i.texture.getTextureBindGroup(t.texture);else if(!r.gpuProgram){se("Mesh shader has no gpuProgram",t.shader);return}const n=r.gpuProgram;if(n.autoAssignGlobalUniforms&&(r.groups[0]=i.globalUniforms.bindGroup),n.autoAssignLocalUniforms){const o=e.localUniforms;r.groups[1]=i.renderPipes.uniformBatch.getUniformBindGroup(o,!0)}i.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Au.extension={type:[A.WebGPUPipesAdaptor],name:"mesh"};const ox=[...Ao,qr,fu,Oo,pu,uu,Eu,yu,bu,xu,_u,du,mu,hu],ax=[...Fh,gu],lx=[yh,Au,Tu],wu=[],Iu=[],Ru=[];Q.handleByNamedList(A.WebGPUSystem,wu),Q.handleByNamedList(A.WebGPUPipes,Iu),Q.handleByNamedList(A.WebGPUPipesAdaptor,Ru),Q.add(...ox,...ax,...lx);class cx extends vi{constructor(){const e={name:"webgpu",type:bt.WEBGPU,systems:wu,renderPipes:Iu,renderPipeAdaptors:Ru};super(e)}}const hx=Object.freeze(Object.defineProperty({__proto__:null,WebGPURenderer:cx},Symbol.toStringTag,{value:"Module"}));Q.add(Rm,Mm);const Bi=480,xs=480;class ux{constructor(){this.container=null,this.resizeObserver=null,this.mode="floating",this.targetEl=null,this.app=new nc}async init(e="floating",t){this.mode=e,e==="inline"&&t&&(this.targetEl=document.querySelector(t),this.targetEl||(console.warn(`[HolostaffWidget] Container "${t}" not found, falling back to floating mode`),this.mode="floating")),await this.app.init({width:Bi,height:xs,backgroundAlpha:0,antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),this.container=document.createElement("div"),this.container.id="holostaff-widget-root",this.mode==="inline"&&this.targetEl?(Object.assign(this.container.style,{position:"relative",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"}),this.targetEl.style.position="relative",this.targetEl.style.cursor="pointer",this.targetEl.appendChild(this.container)):(Object.assign(this.container.style,{position:"fixed",bottom:"0",left:"50%",transform:"translateX(-50%)",width:`${Bi}px`,height:`${xs}px`,zIndex:"2147483646",pointerEvents:"none",overflow:"visible"}),document.body.appendChild(this.container));const i=this.app.canvas;return Object.assign(i.style,{width:"100%",height:"100%",display:"block",pointerEvents:"auto"}),this.container.appendChild(i),this.setupResize(),i}setupResize(){const e=()=>{if(this.mode==="inline"&&this.targetEl){const t=this.targetEl.getBoundingClientRect();this.container&&(this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`)}else{const t=window.innerWidth,i=Math.min(Bi,t),r=i/Bi,n=xs*r;this.container&&(this.container.style.width=`${i}px`,this.container.style.height=`${n}px`)}this.app.renderer.resize(Bi,xs)};window.addEventListener("resize",e),this.mode==="inline"&&this.targetEl&&(this.resizeObserver=new ResizeObserver(e),this.resizeObserver.observe(this.targetEl)),e()}get isInline(){return this.mode==="inline"&&this.targetEl!==null}get inlineTarget(){return this.targetEl}get rootElement(){return this.container}get stageWidth(){return Bi}get stageHeight(){return xs}getInlineRect(){var e;return((e=this.targetEl)==null?void 0:e.getBoundingClientRect())??null}destroy(){var e,t;window.removeEventListener("resize",this.setupResize),(e=this.resizeObserver)==null||e.disconnect(),(t=this.container)==null||t.remove(),this.app.destroy(!0)}}function dx(){var s,e;return((e=(s=globalThis.matchMedia)==null?void 0:s.call(globalThis,"(prefers-reduced-motion: reduce)"))==null?void 0:e.matches)??!1}const vs={easeOutCubic:s=>1-Math.pow(1-s,3),easeInCubic:s=>s*s*s,easeOutBack:s=>1+2.70158*Math.pow(s-1,3)+1.70158*Math.pow(s-1,2),easeInOutSine:s=>-(Math.cos(Math.PI*s)-1)/2};function gr(s){const{target:e,props:t,duration:i,easing:r=vs.easeOutCubic,delay:n=0,onComplete:o,ticker:a}=s;if(dx()){for(const f of Object.keys(t))e[f]=t[f];return o==null||o(),()=>{}}const l={};for(const f of Object.keys(t))l[f]=e[f];let c=-n,h=!1;const u=f=>{if(h||(c+=f.deltaMS,c<0))return;const d=Math.min(c/i,1),g=r(d);for(const _ of Object.keys(t))e[_]=l[_]+(t[_]-l[_])*g;d>=1&&(a.remove(u),o==null||o())};return a.add(u),()=>{h=!0,a.remove(u)}}const Cs=200,Vt=Cs*(480/854),Mu=280;class fx{constructor(e,t){this.idleVideoEl=null,this.idleGroup=null,this.liveSprite=null,this.cancelGlow=null,this.cancelEntrance=null,this.visible=!1,this.widgetRoot=null,this.stageWidth=e,this.stageHeight=t,this.container=new Ve,this.container.visible=!1,this.container.x=e/2,this.container.y=t+Vt}async loadIdleVideo(e,t){this.widgetRoot=t,this.idleVideoEl=document.createElement("video"),this.idleVideoEl.src=e,this.idleVideoEl.loop=!0,this.idleVideoEl.muted=!0,this.idleVideoEl.playsInline=!0,this.idleVideoEl.crossOrigin="anonymous",Object.assign(this.idleVideoEl.style,{position:"absolute",bottom:"10px",left:"50%",transform:"translateX(-50%) translateY(100%)",width:`${Cs}px`,height:"auto",pointerEvents:"none",zIndex:"0",transition:"none"}),t.insertBefore(this.idleVideoEl,t.firstChild),await this.idleVideoEl.play(),this.idleGroup=new Ve,this.container.addChild(this.idleGroup),this.container.x=this.stageWidth/2,this.container.y=this.stageHeight+Vt}async loadIdleImage(e){const t=j.from(e),i=new Ft(t);i.width=Cs,i.height=Vt,i.anchor.set(.5,1),this.idleGroup=new Ve,this.idleGroup.addChild(i),this.container.addChild(this.idleGroup),this.container.x=this.stageWidth/2,this.container.y=this.stageHeight+Vt}slideIn(e){if(this.visible)return;this.visible=!0;const t=this.stageHeight-10;this.container.alpha=1,this.container.visible=!0,this.container.y=this.stageHeight+Vt,this.cancelEntrance=gr({target:this.container,props:{y:t},duration:700,easing:vs.easeOutBack,ticker:e}),this.idleVideoEl&&(this.idleVideoEl.style.transition="transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1)",this.idleVideoEl.style.transform="translateX(-50%) translateY(0)")}slideOut(e){var t;this.visible&&(this.visible=!1,(t=this.cancelGlow)==null||t.call(this),this.cancelGlow=null,gr({target:this.container,props:{y:this.stageHeight+Vt},duration:450,easing:vs.easeInCubic,ticker:e,onComplete:()=>{this.container.visible=!1}}),this.idleVideoEl&&(this.idleVideoEl.style.transition="transform 0.45s cubic-bezier(0.32, 0, 0.67, 0)",this.idleVideoEl.style.transform="translateX(-50%) translateY(100%)"))}get isVisible(){return this.visible}setInteractive(e){this.container.eventMode="static",this.container.cursor="pointer",this.container.hitArea=new Se(-Cs/2,-Vt,Cs,Vt),this.container.on("pointertap",e),this.idleVideoEl&&(this.idleVideoEl.style.pointerEvents="auto",this.idleVideoEl.style.cursor="pointer",this.idleVideoEl.addEventListener("click",e))}setLiveVideo(e,t){const i=()=>{var l;const r=j.from(e);this.liveSprite=new Ft(r);const n=e.videoWidth||1,o=e.videoHeight||1,a=Mu/n;this.liveSprite.width=Mu,this.liveSprite.height=o*a,this.liveSprite.anchor.set(.5,1),this.liveSprite.alpha=0,this.container.addChild(this.liveSprite),this.idleVideoEl&&(this.idleVideoEl.style.display="none"),this.idleGroup&&(this.idleGroup.visible=!1),(l=this.cancelGlow)==null||l.call(this),this.cancelGlow=null,gr({target:this.liveSprite,props:{alpha:1},duration:500,easing:vs.easeInOutSine,ticker:t})};if(e.videoWidth>0&&e.videoHeight>0)i();else{const r=()=>{e.removeEventListener("loadeddata",r),e.removeEventListener("resize",r),i()};e.addEventListener("loadeddata",r),e.addEventListener("resize",r)}}clearLiveVideo(e){this.liveSprite&&gr({target:this.liveSprite,props:{alpha:0},duration:400,easing:vs.easeInCubic,ticker:e,onComplete:()=>{var t;(t=this.liveSprite)==null||t.destroy(),this.liveSprite=null}}),this.idleVideoEl&&(this.idleVideoEl.style.display=""),this.idleGroup&&(this.idleGroup.visible=!0)}destroy(){var e,t;(e=this.cancelGlow)==null||e.call(this),(t=this.cancelEntrance)==null||t.call(this),this.idleVideoEl&&(this.idleVideoEl.pause(),this.idleVideoEl.remove()),this.container.destroy({children:!0})}}const px=[{urls:"stun:stun.l.google.com:19302"}],mx=3e3,gx="oai-events";class _x{constructor(e){this.onConnected=null,this.onDisconnected=null,this.onRemoteTrack=null,this.onDataMessage=null,this.onError=null,this.pc=null,this.dc=null,this.micStream=null,this._remoteAudioStream=null,this._connected=!1,this.opts={model:"gpt-4o-realtime-preview",voice:"verse",instructions:"",tools:[],...e}}get isConnected(){return this._connected}get dataChannel(){return this.dc}get remoteAudioStream(){return this._remoteAudioStream}async connect(){var e,t;try{console.log("[RealtimeSession] Requesting microphone..."),this.micStream=await navigator.mediaDevices.getUserMedia({audio:!0}),console.log("[RealtimeSession] Microphone granted"),this.pc=new RTCPeerConnection({iceServers:px}),this.setupPeerConnectionHandlers();for(const o of this.micStream.getAudioTracks())this.pc.addTrack(o,this.micStream);this.dc=this.pc.createDataChannel(gx),this.setupDataChannelHandlers();const i=await this.pc.createOffer();await this.pc.setLocalDescription(i),await this.waitForIceGathering();const r=(e=this.pc.localDescription)==null?void 0:e.sdp;if(!r)throw new Error("No local SDP after ICE gathering");console.log("[RealtimeSession] Exchanging SDP...");const n=await this.exchangeSDP(r);await this.pc.setRemoteDescription({type:"answer",sdp:n}),console.log("[RealtimeSession] Remote description set")}catch(i){const r=i instanceof Error?i:new Error(String(i));throw console.error("[RealtimeSession] Connection failed:",r.message),(t=this.onError)==null||t.call(this,r),this.close(),r}}sendJSON(e){if(!this.dc||this.dc.readyState!=="open"){console.warn("[RealtimeSession] Data channel not open, cannot send:",e);return}this.dc.send(JSON.stringify(e))}close(){var e;if(console.log("[RealtimeSession] Closing..."),this.dc){try{this.dc.close()}catch{}this.dc=null}if(this.pc){try{this.pc.close()}catch{}this.pc=null}if(this.micStream){for(const t of this.micStream.getTracks())t.stop();this.micStream=null}this._remoteAudioStream=null,this._connected&&(this._connected=!1,(e=this.onDisconnected)==null||e.call(this))}setupPeerConnectionHandlers(){this.pc&&(this.pc.ontrack=e=>{var t;console.log("[RealtimeSession] Remote audio track received"),this._remoteAudioStream=e.streams[0]??new MediaStream([e.track]),(t=this.onRemoteTrack)==null||t.call(this,this._remoteAudioStream)},this.pc.onconnectionstatechange=()=>{var t,i,r,n;const e=(t=this.pc)==null?void 0:t.connectionState;console.log("[RealtimeSession] Connection state:",e),e==="connected"?(this._connected=!0,(i=this.onConnected)==null||i.call(this)):(e==="failed"||e==="closed"||e==="disconnected")&&(this._connected&&(this._connected=!1,(r=this.onDisconnected)==null||r.call(this)),e==="failed"&&((n=this.onError)==null||n.call(this,new Error("WebRTC connection failed"))))})}waitForIceGathering(){return!this.pc||this.pc.iceGatheringState==="complete"?Promise.resolve():new Promise(e=>{const t=this.pc;let i;const r=()=>{clearTimeout(i);try{t.removeEventListener("icegatheringstatechange",n)}catch{}e()},n=()=>{t.iceGatheringState==="complete"&&r()};t.addEventListener("icegatheringstatechange",n),i=setTimeout(r,mx)})}async exchangeSDP(e){const{webrtcUrl:t,ephemeralKey:i,model:r,voice:n}=this.opts,o=t.includes("?")?"&":"?",a=`${t}${o}model=${encodeURIComponent(r)}&voice=${encodeURIComponent(n)}`,l=await fetch(a,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/sdp",Accept:"application/sdp"},body:e});if(!l.ok){const c=await l.text().catch(()=>"");throw new Error(`SDP exchange failed (${l.status}): ${c}`)}return l.text()}setupDataChannelHandlers(){this.dc&&(this.dc.onopen=()=>{console.log("[RealtimeSession] Data channel open"),this.sendSessionUpdate(),this.sendJSON({type:"response.create"})},this.dc.onmessage=e=>{var t;try{const i=JSON.parse(e.data);(t=this.onDataMessage)==null||t.call(this,i)}catch(i){console.warn("[RealtimeSession] Failed to parse data channel message:",i)}},this.dc.onclose=()=>{console.log("[RealtimeSession] Data channel closed")},this.dc.onerror=e=>{console.error("[RealtimeSession] Data channel error:",e)})}sendSessionUpdate(){const e={instructions:this.opts.instructions,modalities:["audio","text"],input_audio_transcription:{model:"whisper-1"},turn_detection:{type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:700,create_response:!0}};this.opts.tools&&this.opts.tools.length>0&&(e.tools=this.opts.tools),this.sendJSON({type:"session.update",session:e})}}const yx=24e3,bx=`
897
+ `})),t=this.device.createRenderPipeline({layout:"auto",vertex:{module:this.mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this.mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this.pipelines[e]=t),t}generateMipmap(e){const t=this._getMipmapPipeline(e.format);if(e.dimension==="3d"||e.dimension==="1d")throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");let i=e;const r=e.depthOrArrayLayers||1,n=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const l={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};i=this.device.createTexture(l)}const o=this.device.createCommandEncoder({}),a=t.getBindGroupLayout(0);for(let l=0;l<r;++l){let c=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),h=n?1:0;for(let u=1;u<e.mipLevelCount;++u){const f=i.createView({baseMipLevel:h++,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),d=o.beginRenderPass({colorAttachments:[{view:f,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),g=this.device.createBindGroup({layout:a,entries:[{binding:0,resource:this.sampler},{binding:1,resource:c}]});d.setPipeline(t),d.setBindGroup(0,g),d.draw(3,1,0,0),d.end(),c=f}}if(!n){const l={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r};for(let c=1;c<e.mipLevelCount;++c)o.copyTextureToTexture({texture:i,mipLevel:c-1},{texture:e,mipLevel:c},l),l.width=Math.ceil(l.width/2),l.height=Math.ceil(l.height/2)}return this.device.queue.submit([o.finish()]),n||i.destroy(),e}}class nx{constructor(e){this.textureView=null,this.gpuTexture=e}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.gpuTexture=null}}class Eu{constructor(e){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=e,e.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new kt({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const t={image:Su,buffer:Qb,video:sx,compressed:tx};this._uploads={...t,cube:ix(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gpu=e}initSource(e){var t;return((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){const c=Math.max(e.pixelWidth,e.pixelHeight);e.mipLevelCount=Math.floor(Math.log2(c))+1}let t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST;e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC);const i=vu[e.format]||{blockWidth:1,blockHeight:1},r=Math.ceil(e.pixelWidth/i.blockWidth)*i.blockWidth,n=Math.ceil(e.pixelHeight/i.blockHeight)*i.blockHeight,o={label:e.label,size:{width:r,height:n,depthOrArrayLayers:e.arrayLayerCount},format:e.format,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},a=this._gpu.device.createTexture(o);return e._gpuData[this._renderer.uid]=new nx(a),this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),a}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onUpdateMipmaps(e){this._mipmapGenerator||(this._mipmapGenerator=new rx(this._gpu.device));const t=this.getGpuSource(e);this._mipmapGenerator.generateMipmap(t)}onSourceUnload(e){e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this)}onSourceResize(e){e._gcLastUsed=this._renderer.gc.now;const t=e._gpuData[this._renderer.uid],i=t==null?void 0:t.gpuTexture;i?(i.width!==e.pixelWidth||i.height!==e.pixelHeight)&&(t.destroy(),this._bindGroupHash[e.uid]=null,e._gpuData[this._renderer.uid]=null,this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){var t;return e._gcLastUsed=this._renderer.gc.now,((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]||this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new Gt({0:t,1:t.style,2:new ht({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e){const t=e.source;t._gcLastUsed=this._renderer.gc.now;let i=t._gpuData[this._renderer.uid];return i||(this.initSource(t),i=t._gpuData[this._renderer.uid]),i.textureView||(i.textureView=i.gpuTexture.createView({dimension:t.viewDimension})),i.textureView}generateCanvas(e){const t=this._renderer,i=t.gpu.device.createCommandEncoder(),r=pe.get().createCanvas();r.width=e.source.pixelWidth,r.height=e.source.pixelHeight;const n=r.getContext("webgpu");return n.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:pe.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),i.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:n.getCurrentTexture()},{width:r.width,height:r.height}),t.gpu.device.queue.submit([i.finish()]),r}getPixels(e){const t=this.generateCanvas(e),i=so.getOptimalCanvasAndContext(t.width,t.height),r=i.context;r.drawImage(t,0,0);const{width:n,height:o}=t,a=r.getImageData(0,0,n,o),l=new Uint8ClampedArray(a.data.buffer);return so.returnCanvasAndContext(i),{pixels:l,width:n,height:o}}destroy(){this._managedTextures.destroy();for(const e of Object.keys(this._bindGroupHash)){const t=Number(e),i=this._bindGroupHash[t];i==null||i.destroy()}this._renderer=null,this._gpu=null,this._mipmapGenerator=null,this._gpuSamplers=null,this._bindGroupHash=null}}Eu.extension={type:[A.WebGPUSystem],name:"texture"};class Tu{constructor(){this._maxTextures=0}contextChange(e){const t=new ht({uTransformMatrix:{value:new H,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const i=Gn({name:"graphics",bits:[vc,Sc(this._maxTextures),_y,Vn]});this.shader=new Mt({gpuProgram:i,resources:{localUniforms:t}})}execute(e,t){const i=t.context,r=i.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(i),c=n.encoder;c.setGeometry(a.geometry,r.gpuProgram);const h=n.globalUniforms.bindGroup;c.setBindGroup(0,h,r.gpuProgram);const u=n.renderPipes.uniformBatch.getUniformBindGroup(r.resources.localUniforms,!0);c.setBindGroup(2,u,r.gpuProgram);const f=l.instructions;let d=null;for(let g=0;g<l.instructionSize;g++){const _=f[g];if(_.topology!==d&&(d=_.topology,c.setPipelineFromGeometryProgramAndState(a.geometry,r.gpuProgram,e.state,_.topology)),r.groups[1]=_.bindGroup,!_.gpuBindGroup){const b=_.textures;_.bindGroup=Nn(b.textures,b.count,this._maxTextures),_.gpuBindGroup=n.bindGroup.getBindGroup(_.bindGroup,r.gpuProgram,1)}c.setBindGroup(1,_.bindGroup,r.gpuProgram),c.renderPassEncoder.drawIndexed(_.size,1,_.start)}}destroy(){this.shader.destroy(!0),this.shader=null}}Tu.extension={type:[A.WebGPUPipesAdaptor],name:"graphics"};class Au{init(){const e=Gn({name:"mesh",bits:[ur,vy,Vn]});this._shader=new Mt({gpuProgram:e,resources:{uTexture:j.EMPTY._source,uSampler:j.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new H}}}})}execute(e,t){const i=e.renderer;let r=t._shader;if(!r)r=this._shader,r.groups[2]=i.texture.getTextureBindGroup(t.texture);else if(!r.gpuProgram){se("Mesh shader has no gpuProgram",t.shader);return}const n=r.gpuProgram;if(n.autoAssignGlobalUniforms&&(r.groups[0]=i.globalUniforms.bindGroup),n.autoAssignLocalUniforms){const o=e.localUniforms;r.groups[1]=i.renderPipes.uniformBatch.getUniformBindGroup(o,!0)}i.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Au.extension={type:[A.WebGPUPipesAdaptor],name:"mesh"};const ox=[...Ao,qr,fu,Oo,pu,uu,Eu,yu,bu,xu,_u,du,mu,hu],ax=[...Fh,gu],lx=[yh,Au,Tu],wu=[],Iu=[],Ru=[];Q.handleByNamedList(A.WebGPUSystem,wu),Q.handleByNamedList(A.WebGPUPipes,Iu),Q.handleByNamedList(A.WebGPUPipesAdaptor,Ru),Q.add(...ox,...ax,...lx);class cx extends vi{constructor(){const e={name:"webgpu",type:bt.WEBGPU,systems:wu,renderPipes:Iu,renderPipeAdaptors:Ru};super(e)}}const hx=Object.freeze(Object.defineProperty({__proto__:null,WebGPURenderer:cx},Symbol.toStringTag,{value:"Module"}));Q.add(Rm,Mm);const Bi=480,xs=480;class ux{constructor(){this.container=null,this.resizeObserver=null,this.mode="floating",this.targetEl=null,this.app=new nc}async init(e="floating",t){this.mode=e,e==="inline"&&t&&(this.targetEl=document.querySelector(t),this.targetEl||(console.warn(`[HolostaffWidget] Container "${t}" not found, falling back to floating mode`),this.mode="floating")),await this.app.init({width:Bi,height:xs,backgroundAlpha:0,antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0,preference:"webgl"}),this.container=document.createElement("div"),this.container.id="holostaff-widget-root",this.mode==="inline"&&this.targetEl?(Object.assign(this.container.style,{position:"relative",width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"}),this.targetEl.style.position="relative",this.targetEl.style.cursor="pointer",this.targetEl.appendChild(this.container)):(Object.assign(this.container.style,{position:"fixed",bottom:"0",left:"50%",transform:"translateX(-50%)",width:`${Bi}px`,height:`${xs}px`,zIndex:"2147483646",pointerEvents:"none",overflow:"visible"}),document.body.appendChild(this.container));const i=this.app.canvas;return Object.assign(i.style,{width:"100%",height:"100%",display:"block",pointerEvents:"auto"}),this.container.appendChild(i),this.setupResize(),i}setupResize(){const e=()=>{if(this.mode==="inline"&&this.targetEl){const t=this.targetEl.getBoundingClientRect();this.container&&(this.container.style.width=`${t.width}px`,this.container.style.height=`${t.height}px`)}else{const t=window.innerWidth,i=Math.min(Bi,t),r=i/Bi,n=xs*r;this.container&&(this.container.style.width=`${i}px`,this.container.style.height=`${n}px`)}this.app.renderer.resize(Bi,xs)};window.addEventListener("resize",e),this.mode==="inline"&&this.targetEl&&(this.resizeObserver=new ResizeObserver(e),this.resizeObserver.observe(this.targetEl)),e()}get isInline(){return this.mode==="inline"&&this.targetEl!==null}get inlineTarget(){return this.targetEl}get rootElement(){return this.container}get stageWidth(){return Bi}get stageHeight(){return xs}getInlineRect(){var e;return((e=this.targetEl)==null?void 0:e.getBoundingClientRect())??null}destroy(){var e,t;window.removeEventListener("resize",this.setupResize),(e=this.resizeObserver)==null||e.disconnect(),(t=this.container)==null||t.remove(),this.app.destroy(!0)}}function dx(){var s,e;return((e=(s=globalThis.matchMedia)==null?void 0:s.call(globalThis,"(prefers-reduced-motion: reduce)"))==null?void 0:e.matches)??!1}const vs={easeOutCubic:s=>1-Math.pow(1-s,3),easeInCubic:s=>s*s*s,easeOutBack:s=>1+2.70158*Math.pow(s-1,3)+1.70158*Math.pow(s-1,2),easeInOutSine:s=>-(Math.cos(Math.PI*s)-1)/2};function gr(s){const{target:e,props:t,duration:i,easing:r=vs.easeOutCubic,delay:n=0,onComplete:o,ticker:a}=s;if(dx()){for(const f of Object.keys(t))e[f]=t[f];return o==null||o(),()=>{}}const l={};for(const f of Object.keys(t))l[f]=e[f];let c=-n,h=!1;const u=f=>{if(h||(c+=f.deltaMS,c<0))return;const d=Math.min(c/i,1),g=r(d);for(const _ of Object.keys(t))e[_]=l[_]+(t[_]-l[_])*g;d>=1&&(a.remove(u),o==null||o())};return a.add(u),()=>{h=!0,a.remove(u)}}const Cs=200,Vt=Cs*(480/854),Mu=280;class fx{constructor(e,t){this.idleVideoEl=null,this.idleGroup=null,this.liveSprite=null,this.cancelGlow=null,this.cancelEntrance=null,this.visible=!1,this.widgetRoot=null,this.stageWidth=e,this.stageHeight=t,this.container=new Ve,this.container.visible=!1,this.container.x=e/2,this.container.y=t+Vt}async loadIdleVideo(e,t){this.widgetRoot=t,this.idleVideoEl=document.createElement("video"),this.idleVideoEl.src=e,this.idleVideoEl.loop=!0,this.idleVideoEl.muted=!0,this.idleVideoEl.playsInline=!0,this.idleVideoEl.crossOrigin="anonymous",Object.assign(this.idleVideoEl.style,{position:"absolute",bottom:"10px",left:"50%",transform:"translateX(-50%) translateY(100%)",width:`${Cs}px`,height:"auto",pointerEvents:"none",zIndex:"0",transition:"none"}),t.insertBefore(this.idleVideoEl,t.firstChild),await this.idleVideoEl.play(),this.idleGroup=new Ve,this.container.addChild(this.idleGroup),this.container.x=this.stageWidth/2,this.container.y=this.stageHeight+Vt}async loadIdleImage(e){const t=j.from(e),i=new Ft(t);i.width=Cs,i.height=Vt,i.anchor.set(.5,1),this.idleGroup=new Ve,this.idleGroup.addChild(i),this.container.addChild(this.idleGroup),this.container.x=this.stageWidth/2,this.container.y=this.stageHeight+Vt}slideIn(e){if(this.visible)return;this.visible=!0;const t=this.stageHeight-10;this.container.alpha=1,this.container.visible=!0,this.container.y=this.stageHeight+Vt,this.cancelEntrance=gr({target:this.container,props:{y:t},duration:700,easing:vs.easeOutBack,ticker:e}),this.idleVideoEl&&(this.idleVideoEl.style.transition="transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1)",this.idleVideoEl.style.transform="translateX(-50%) translateY(0)")}slideOut(e){var t;this.visible&&(this.visible=!1,(t=this.cancelGlow)==null||t.call(this),this.cancelGlow=null,gr({target:this.container,props:{y:this.stageHeight+Vt},duration:450,easing:vs.easeInCubic,ticker:e,onComplete:()=>{this.container.visible=!1}}),this.idleVideoEl&&(this.idleVideoEl.style.transition="transform 0.45s cubic-bezier(0.32, 0, 0.67, 0)",this.idleVideoEl.style.transform="translateX(-50%) translateY(100%)"))}get isVisible(){return this.visible}setInteractive(e){this.container.eventMode="static",this.container.cursor="pointer",this.container.hitArea=new Se(-Cs/2,-Vt,Cs,Vt),this.container.on("pointertap",e),this.idleVideoEl&&(this.idleVideoEl.style.pointerEvents="auto",this.idleVideoEl.style.cursor="pointer",this.idleVideoEl.addEventListener("click",e))}setLiveVideo(e,t){const i=()=>{var l;const r=j.from(e);this.liveSprite=new Ft(r);const n=e.videoWidth||1,o=e.videoHeight||1,a=Mu/n;this.liveSprite.width=Mu,this.liveSprite.height=o*a,this.liveSprite.anchor.set(.5,1),this.liveSprite.alpha=0,this.container.addChild(this.liveSprite),this.idleVideoEl&&(this.idleVideoEl.style.display="none"),this.idleGroup&&(this.idleGroup.visible=!1),(l=this.cancelGlow)==null||l.call(this),this.cancelGlow=null,gr({target:this.liveSprite,props:{alpha:1},duration:500,easing:vs.easeInOutSine,ticker:t})};if(e.videoWidth>0&&e.videoHeight>0)i();else{const r=()=>{e.removeEventListener("loadeddata",r),e.removeEventListener("resize",r),i()};e.addEventListener("loadeddata",r),e.addEventListener("resize",r)}}clearLiveVideo(e){this.liveSprite&&gr({target:this.liveSprite,props:{alpha:0},duration:400,easing:vs.easeInCubic,ticker:e,onComplete:()=>{var t;(t=this.liveSprite)==null||t.destroy(),this.liveSprite=null}}),this.idleVideoEl&&(this.idleVideoEl.style.display=""),this.idleGroup&&(this.idleGroup.visible=!0)}destroy(){var e,t;(e=this.cancelGlow)==null||e.call(this),(t=this.cancelEntrance)==null||t.call(this),this.idleVideoEl&&(this.idleVideoEl.pause(),this.idleVideoEl.remove()),this.container.destroy({children:!0})}}const px=[{urls:"stun:stun.l.google.com:19302"}],mx=3e3,gx="oai-events";class _x{constructor(e){this.onConnected=null,this.onDisconnected=null,this.onRemoteTrack=null,this.onDataMessage=null,this.onError=null,this.pc=null,this.dc=null,this.micStream=null,this._remoteAudioStream=null,this._connected=!1,this.opts={model:"gpt-4o-realtime-preview",voice:"verse",instructions:"",tools:[],...e}}get isConnected(){return this._connected}get dataChannel(){return this.dc}get remoteAudioStream(){return this._remoteAudioStream}async connect(){var e,t;try{console.log("[RealtimeSession] Requesting microphone..."),this.micStream=await navigator.mediaDevices.getUserMedia({audio:!0}),console.log("[RealtimeSession] Microphone granted"),this.pc=new RTCPeerConnection({iceServers:px}),this.setupPeerConnectionHandlers();for(const o of this.micStream.getAudioTracks())this.pc.addTrack(o,this.micStream);this.dc=this.pc.createDataChannel(gx),this.setupDataChannelHandlers();const i=await this.pc.createOffer();await this.pc.setLocalDescription(i),await this.waitForIceGathering();const r=(e=this.pc.localDescription)==null?void 0:e.sdp;if(!r)throw new Error("No local SDP after ICE gathering");console.log("[RealtimeSession] Exchanging SDP...");const n=await this.exchangeSDP(r);await this.pc.setRemoteDescription({type:"answer",sdp:n}),console.log("[RealtimeSession] Remote description set")}catch(i){const r=i instanceof Error?i:new Error(String(i));throw console.error("[RealtimeSession] Connection failed:",r.message),(t=this.onError)==null||t.call(this,r),this.close(),r}}sendJSON(e){if(!this.dc||this.dc.readyState!=="open"){console.warn("[RealtimeSession] Data channel not open, cannot send:",e);return}this.dc.send(JSON.stringify(e))}close(){var e;if(console.log("[RealtimeSession] Closing..."),this.dc){try{this.dc.close()}catch{}this.dc=null}if(this.pc){try{this.pc.close()}catch{}this.pc=null}if(this.micStream){for(const t of this.micStream.getTracks())t.stop();this.micStream=null}this._remoteAudioStream=null,this._connected&&(this._connected=!1,(e=this.onDisconnected)==null||e.call(this))}setupPeerConnectionHandlers(){this.pc&&(this.pc.ontrack=e=>{var t;console.log("[RealtimeSession] Remote audio track received"),this._remoteAudioStream=e.streams[0]??new MediaStream([e.track]),(t=this.onRemoteTrack)==null||t.call(this,this._remoteAudioStream)},this.pc.onconnectionstatechange=()=>{var t,i,r,n;const e=(t=this.pc)==null?void 0:t.connectionState;console.log("[RealtimeSession] Connection state:",e),e==="connected"?(this._connected=!0,(i=this.onConnected)==null||i.call(this)):(e==="failed"||e==="closed"||e==="disconnected")&&(this._connected&&(this._connected=!1,(r=this.onDisconnected)==null||r.call(this)),e==="failed"&&((n=this.onError)==null||n.call(this,new Error("WebRTC connection failed"))))})}waitForIceGathering(){return!this.pc||this.pc.iceGatheringState==="complete"?Promise.resolve():new Promise(e=>{const t=this.pc;let i;const r=()=>{clearTimeout(i);try{t.removeEventListener("icegatheringstatechange",n)}catch{}e()},n=()=>{t.iceGatheringState==="complete"&&r()};t.addEventListener("icegatheringstatechange",n),i=setTimeout(r,mx)})}async exchangeSDP(e){const{webrtcUrl:t,ephemeralKey:i,model:r,voice:n}=this.opts,o=t.includes("?")?"&":"?",a=`${t}${o}model=${encodeURIComponent(r)}&voice=${encodeURIComponent(n)}`,l=await fetch(a,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/sdp",Accept:"application/sdp"},body:e});if(!l.ok){const c=await l.text().catch(()=>"");throw new Error(`SDP exchange failed (${l.status}): ${c}`)}return l.text()}setupDataChannelHandlers(){this.dc&&(this.dc.onopen=()=>{console.log("[RealtimeSession] Data channel open"),this.sendSessionUpdate(),this.sendJSON({type:"response.create"})},this.dc.onmessage=e=>{var t;try{const i=JSON.parse(e.data);(t=this.onDataMessage)==null||t.call(this,i)}catch(i){console.warn("[RealtimeSession] Failed to parse data channel message:",i)}},this.dc.onclose=()=>{console.log("[RealtimeSession] Data channel closed")},this.dc.onerror=e=>{console.error("[RealtimeSession] Data channel error:",e)})}sendSessionUpdate(){const e={instructions:this.opts.instructions,modalities:["audio","text"],input_audio_transcription:{model:"whisper-1"},turn_detection:{type:"server_vad",threshold:.5,prefix_padding_ms:300,silence_duration_ms:700,create_response:!0}};this.opts.tools&&this.opts.tools.length>0&&(e.tools=this.opts.tools),this.sendJSON({type:"session.update",session:e})}}const yx=24e3,bx=`
898
898
  class PcmBufferProcessor extends AudioWorkletProcessor {
899
899
  constructor() {
900
900
  super()