hanc-webrtc-widgets 2.2.5 → 2.2.6

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.
@@ -38196,7 +38196,7 @@ class Hd {
38196
38196
  mid: 0,
38197
38197
  treble: 0,
38198
38198
  level: 0
38199
- }, this.resizeTimeoutId = null, this.isContextLost = !1, this.animate = () => {
38199
+ }, this.resizeObserver = null, this.resizeTimeoutId = null, this.isContextLost = !1, this.animate = () => {
38200
38200
  if (this.isContextLost)
38201
38201
  return;
38202
38202
  this.animationId = requestAnimationFrame(this.animate);
@@ -38215,9 +38215,11 @@ class Hd {
38215
38215
  }, this.handleResize = () => {
38216
38216
  this.resizeTimeoutId !== null && clearTimeout(this.resizeTimeoutId), this.resizeTimeoutId = setTimeout(() => {
38217
38217
  this.resizeTimeoutId = null;
38218
- const u = this.container.clientWidth * this.canvasPadding, h = this.container.clientHeight * this.canvasPadding;
38219
- this.camera.aspect = u / h, this.camera.updateProjectionMatrix(), this.renderer.setSize(u, h);
38220
- }, 150);
38218
+ const u = this.container.clientWidth, h = this.container.clientHeight;
38219
+ if (u === 0 || h === 0) return;
38220
+ const f = u * this.canvasPadding, g = h * this.canvasPadding;
38221
+ this.camera.aspect = f / g, this.camera.updateProjectionMatrix(), this.renderer.setSize(f, g);
38222
+ }, 100);
38221
38223
  }, this.handleMouseMove = (u) => {
38222
38224
  const h = this.container.getBoundingClientRect(), f = (u.clientX - h.left) / h.width * 2 - 1, g = -((u.clientY - h.top) / h.height) * 2 + 1;
38223
38225
  this.targetRotation.x = g * 0.3, this.targetRotation.y = f * 0.3;
@@ -38235,19 +38237,19 @@ class Hd {
38235
38237
  powerPreference: "high-performance"
38236
38238
  }), this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)), this.renderer.setSize(r, a), this.renderer.setClearColor(0, 0);
38237
38239
  const d = this.renderer.domElement;
38238
- d.style.position = "absolute", d.style.left = "50%", d.style.top = "50%", d.style.transform = "translate(-50%, -50%)", d.style.pointerEvents = "none", e.appendChild(d), d.addEventListener("webglcontextlost", this.boundHandleContextLost), d.addEventListener("webglcontextrestored", this.boundHandleContextRestored), this.createOrb(), window.addEventListener("resize", this.handleResize), e.addEventListener("mousemove", this.handleMouseMove), e.addEventListener("mouseleave", this.handleMouseLeave);
38240
+ d.style.position = "absolute", d.style.left = "50%", d.style.top = "50%", d.style.transform = "translate(-50%, -50%)", d.style.pointerEvents = "none", e.appendChild(d), d.addEventListener("webglcontextlost", this.boundHandleContextLost), d.addEventListener("webglcontextrestored", this.boundHandleContextRestored), this.createOrb(), window.addEventListener("resize", this.handleResize), this.resizeObserver = new ResizeObserver(this.handleResize), this.resizeObserver.observe(e), e.addEventListener("mousemove", this.handleMouseMove), e.addEventListener("mouseleave", this.handleMouseLeave);
38239
38241
  }
38240
38242
  /**
38241
38243
  * Handle WebGL context loss (iOS background transition)
38242
38244
  */
38243
38245
  handleContextLost(e) {
38244
- e.preventDefault(), console.log("[OrbRenderer] WebGL context lost"), this.isContextLost = !0, this.stop();
38246
+ e.preventDefault(), this.isContextLost = !0, this.stop();
38245
38247
  }
38246
38248
  /**
38247
38249
  * Handle WebGL context restoration (iOS foreground transition)
38248
38250
  */
38249
38251
  handleContextRestored(e) {
38250
- console.log("[OrbRenderer] WebGL context restored"), this.isContextLost = !1, this.recreateAfterContextLoss(), this.start();
38252
+ this.isContextLost = !1, this.recreateAfterContextLoss(), this.start();
38251
38253
  }
38252
38254
  /**
38253
38255
  * Recreate WebGL resources after context loss
@@ -38363,7 +38365,7 @@ class Hd {
38363
38365
  * Cleanup resources
38364
38366
  */
38365
38367
  destroy() {
38366
- this.stop(), this.resizeTimeoutId !== null && (clearTimeout(this.resizeTimeoutId), this.resizeTimeoutId = null), window.removeEventListener("resize", this.handleResize), this.container.removeEventListener("mousemove", this.handleMouseMove), this.container.removeEventListener("mouseleave", this.handleMouseLeave);
38368
+ this.stop(), this.resizeTimeoutId !== null && (clearTimeout(this.resizeTimeoutId), this.resizeTimeoutId = null), window.removeEventListener("resize", this.handleResize), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), this.container.removeEventListener("mousemove", this.handleMouseMove), this.container.removeEventListener("mouseleave", this.handleMouseLeave);
38367
38369
  const e = this.renderer.domElement;
38368
38370
  e.removeEventListener("webglcontextlost", this.boundHandleContextLost), e.removeEventListener("webglcontextrestored", this.boundHandleContextRestored), this.orb && (this.orb.geometry.dispose(), this.scene.remove(this.orb), this.orb = null), this.glowMesh && (this.glowMesh.geometry.dispose(), this.scene.remove(this.glowMesh), this.glowMesh = null), this.orbMaterial && (this.orbMaterial.dispose(), this.orbMaterial = null), this.glowMaterial && (this.glowMaterial.dispose(), this.glowMaterial = null), this.renderer.dispose(), e.parentNode && e.parentNode.removeChild(e);
38369
38371
  }
@@ -4468,7 +4468,7 @@ void main() {
4468
4468
  // Softer alpha for more diffuse appearance
4469
4469
  gl_FragColor = vec4(glowColor, glow * 0.4);
4470
4470
  }
4471
- `,Ss={primary:"#6366f1",secondary:"#8b5cf6",accent:"#06b6d4",glow:"#818cf8",atmosphere:"#c4b5fd",depth:"#312e81",highlight:"#e0e7ff"},VC={size:1,segments:128,colors:Ss,morphStrength:1,noiseScale:1.5,noiseSpeed:.3,glowIntensity:.8,idleGlowMultiplier:.4,fresnelPower:2.5,rotationSpeed:.1,audioReactivity:3,audioSmoothing:.9,idleMorphMultiplier:.25,colorContrast:1.5};class Bd{constructor(e,t={}){this.orb=null,this.glowMesh=null,this.orbMaterial=null,this.glowMaterial=null,this.animationId=null,this.isActive=!1,this.targetRotation={x:0,y:0},this.currentRotation={x:0,y:0},this.audioValues={bass:0,mid:0,treble:0,level:0},this.resizeTimeoutId=null,this.isContextLost=!1,this.animate=()=>{if(this.isContextLost)return;this.animationId=requestAnimationFrame(this.animate);const u=this.clock.getElapsedTime();if(this.clock.getDelta(),this.orbMaterial){this.orbMaterial.uniforms.uTime.value=u,this.orbMaterial.uniforms.uAudioBass.value=this.audioValues.bass,this.orbMaterial.uniforms.uAudioMid.value=this.audioValues.mid,this.orbMaterial.uniforms.uAudioTreble.value=this.audioValues.treble,this.orbMaterial.uniforms.uAudioLevel.value=this.audioValues.level;const h=this.isActive?this.config.morphStrength*1.5:this.config.morphStrength*this.config.idleMorphMultiplier,f=this.orbMaterial.uniforms.uMorphStrength.value;this.orbMaterial.uniforms.uMorphStrength.value+=(h-f)*.05}if(this.glowMaterial){this.glowMaterial.uniforms.uTime.value=u,this.glowMaterial.uniforms.uAudioLevel.value=this.audioValues.level;const h=this.isActive?this.config.glowIntensity*1.5:this.config.glowIntensity*this.config.idleGlowMultiplier,f=this.glowMaterial.uniforms.uGlowIntensity.value;this.glowMaterial.uniforms.uGlowIntensity.value+=(h-f)*.05}this.currentRotation.x+=(this.targetRotation.x-this.currentRotation.x)*.05,this.currentRotation.y+=(this.targetRotation.y-this.currentRotation.y)*.05,this.orb&&(this.orb.rotation.x=this.currentRotation.x+u*this.config.rotationSpeed*.3,this.orb.rotation.y=this.currentRotation.y+u*this.config.rotationSpeed),this.glowMesh&&(this.glowMesh.rotation.x=this.currentRotation.x+u*this.config.rotationSpeed*.3,this.glowMesh.rotation.y=this.currentRotation.y+u*this.config.rotationSpeed),this.renderer.render(this.scene,this.camera)},this.handleResize=()=>{this.resizeTimeoutId!==null&&clearTimeout(this.resizeTimeoutId),this.resizeTimeoutId=setTimeout(()=>{this.resizeTimeoutId=null;const u=this.container.clientWidth*this.canvasPadding,h=this.container.clientHeight*this.canvasPadding;this.camera.aspect=u/h,this.camera.updateProjectionMatrix(),this.renderer.setSize(u,h)},150)},this.handleMouseMove=u=>{const h=this.container.getBoundingClientRect(),f=(u.clientX-h.left)/h.width*2-1,g=-((u.clientY-h.top)/h.height)*2+1;this.targetRotation.x=g*.3,this.targetRotation.y=f*.3},this.handleMouseLeave=()=>{this.targetRotation.x=0,this.targetRotation.y=0},this.container=e,this.config={...VC,...t},this.clock=new _y;const n=/iPhone|iPad|iPod/i.test(navigator.userAgent),s=/Android/i.test(navigator.userAgent);this.canvasPadding=n?1.5:s?2:3,this.boundHandleContextLost=this.handleContextLost.bind(this),this.boundHandleContextRestored=this.handleContextRestored.bind(this),this.scene=new ly;const r=e.clientWidth*this.canvasPadding,a=e.clientHeight*this.canvasPadding,o=r/a;this.camera=new Cn(45,o,.1,100);const c=3,l=9;this.camera.position.z=l*(this.canvasPadding/c),this.renderer=new NC({antialias:!0,alpha:!0,powerPreference:"high-performance"}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(r,a),this.renderer.setClearColor(0,0);const d=this.renderer.domElement;d.style.position="absolute",d.style.left="50%",d.style.top="50%",d.style.transform="translate(-50%, -50%)",d.style.pointerEvents="none",e.appendChild(d),d.addEventListener("webglcontextlost",this.boundHandleContextLost),d.addEventListener("webglcontextrestored",this.boundHandleContextRestored),this.createOrb(),window.addEventListener("resize",this.handleResize),e.addEventListener("mousemove",this.handleMouseMove),e.addEventListener("mouseleave",this.handleMouseLeave)}handleContextLost(e){e.preventDefault(),console.log("[OrbRenderer] WebGL context lost"),this.isContextLost=!0,this.stop()}handleContextRestored(e){console.log("[OrbRenderer] WebGL context restored"),this.isContextLost=!1,this.recreateAfterContextLoss(),this.start()}recreateAfterContextLoss(){this.orb&&(this.orb.geometry.dispose(),this.scene.remove(this.orb),this.orb=null),this.glowMesh&&(this.glowMesh.geometry.dispose(),this.scene.remove(this.glowMesh),this.glowMesh=null),this.orbMaterial&&(this.orbMaterial.dispose(),this.orbMaterial=null),this.glowMaterial&&(this.glowMaterial.dispose(),this.glowMaterial=null),this.createOrb()}createOrb(){const e={...Ss,...this.config.colors},t=new Rd(this.config.size,this.config.segments/4);this.orbMaterial=new Tn({vertexShader:UC,fragmentShader:OC,uniforms:{uTime:{value:0},uAudioBass:{value:0},uAudioMid:{value:0},uAudioTreble:{value:0},uAudioLevel:{value:0},uMorphStrength:{value:this.config.morphStrength},uNoiseScale:{value:this.config.noiseScale},uNoiseSpeed:{value:this.config.noiseSpeed},uAudioReactivity:{value:this.config.audioReactivity},uColorPrimary:{value:new Ze(e.primary)},uColorSecondary:{value:new Ze(e.secondary)},uColorAccent:{value:new Ze(e.accent)},uColorDepth:{value:new Ze(e.depth||Ss.depth)},uColorHighlight:{value:new Ze(e.highlight||Ss.highlight)},uFresnelPower:{value:this.config.fresnelPower},uGlowIntensity:{value:this.config.glowIntensity},uColorContrast:{value:this.config.colorContrast}},transparent:!0,side:mi}),this.orb=new Vn(t,this.orbMaterial),this.scene.add(this.orb);const n=new Pd(this.config.size,64,64);this.glowMaterial=new Tn({vertexShader:FC,fragmentShader:BC,uniforms:{uTime:{value:0},uAudioLevel:{value:0},uGlowColor:{value:new Ze(e.glow)},uGlowIntensity:{value:this.config.glowIntensity*.6},uPulseSpeed:{value:2}},transparent:!0,side:Zt,blending:el,depthWrite:!1}),this.glowMesh=new Vn(n,this.glowMaterial),this.scene.add(this.glowMesh)}updateAudio(e){const t=this.config.audioSmoothing;this.audioValues.bass+=(e.bass-this.audioValues.bass)*t,this.audioValues.mid+=(e.mid-this.audioValues.mid)*t,this.audioValues.treble+=(e.treble-this.audioValues.treble)*t,this.audioValues.level+=(e.level-this.audioValues.level)*t}setSimulatedAudio(e,t,n,s){const r=this.config.audioSmoothing;this.audioValues.bass+=(e-this.audioValues.bass)*r,this.audioValues.mid+=(t-this.audioValues.mid)*r,this.audioValues.treble+=(n-this.audioValues.treble)*r,this.audioValues.level+=(s-this.audioValues.level)*r}setActive(e){this.isActive=e}setColors(e){const t={...Ss,...this.config.colors,...e};this.orbMaterial&&(this.orbMaterial.uniforms.uColorPrimary.value.set(t.primary),this.orbMaterial.uniforms.uColorSecondary.value.set(t.secondary),this.orbMaterial.uniforms.uColorAccent.value.set(t.accent),this.orbMaterial.uniforms.uColorDepth.value.set(t.depth||Ss.depth),this.orbMaterial.uniforms.uColorHighlight.value.set(t.highlight||Ss.highlight)),this.glowMaterial&&this.glowMaterial.uniforms.uGlowColor.value.set(t.glow)}setGlowSettings(e,t){this.config.glowIntensity=e,this.config.idleGlowMultiplier=t}start(){this.animationId===null&&(this.clock.start(),this.animate())}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}getCanvas(){return this.renderer.domElement}destroy(){this.stop(),this.resizeTimeoutId!==null&&(clearTimeout(this.resizeTimeoutId),this.resizeTimeoutId=null),window.removeEventListener("resize",this.handleResize),this.container.removeEventListener("mousemove",this.handleMouseMove),this.container.removeEventListener("mouseleave",this.handleMouseLeave);const e=this.renderer.domElement;e.removeEventListener("webglcontextlost",this.boundHandleContextLost),e.removeEventListener("webglcontextrestored",this.boundHandleContextRestored),this.orb&&(this.orb.geometry.dispose(),this.scene.remove(this.orb),this.orb=null),this.glowMesh&&(this.glowMesh.geometry.dispose(),this.scene.remove(this.glowMesh),this.glowMesh=null),this.orbMaterial&&(this.orbMaterial.dispose(),this.orbMaterial=null),this.glowMaterial&&(this.glowMaterial.dispose(),this.glowMaterial=null),this.renderer.dispose(),e.parentNode&&e.parentNode.removeChild(e)}}class lr{constructor(){this.audioContext=null,this.refCount=0,this.resumePromise=null}static getInstance(){return lr.instance||(lr.instance=new lr),lr.instance}async acquire(){if(this.refCount++,!this.audioContext)try{const e=window.AudioContext||window.webkitAudioContext;if(!e)return console.warn("[SharedAudioContext] Web Audio API not supported"),null;this.audioContext=new e,console.log("[SharedAudioContext] Created shared AudioContext")}catch(e){return console.warn("[SharedAudioContext] Failed to create AudioContext:",e),null}return await this.ensureResumed(),this.audioContext}release(){this.refCount=Math.max(0,this.refCount-1),this.refCount===0&&console.log("[SharedAudioContext] All references released, context kept alive for reuse")}forceClose(){if(this.audioContext){try{this.audioContext.close()}catch{}this.audioContext=null,this.refCount=0,console.log("[SharedAudioContext] Force closed")}}getContext(){return this.audioContext}async ensureResumed(){if(!this.audioContext)return!1;if(this.audioContext.state==="suspended"){this.resumePromise||(this.resumePromise=this.audioContext.resume().finally(()=>{this.resumePromise=null}));try{await this.resumePromise}catch{return!1}}return this.audioContext.state==="running"}isRunning(){return this.audioContext!==null&&this.audioContext.state==="running"}getState(){var e;return((e=this.audioContext)==null?void 0:e.state)??null}getSampleRate(){var e;return((e=this.audioContext)==null?void 0:e.sampleRate)??44100}getCurrentTime(){var e;return((e=this.audioContext)==null?void 0:e.currentTime)??0}getDestination(){var e;return((e=this.audioContext)==null?void 0:e.destination)??null}}const dr=lr.getInstance();typeof window<"u"&&window.addEventListener("pagehide",()=>{dr.forceClose()});class Vd{constructor(e={}){this.audioContext=null,this.analyser=null,this.source=null,this.localSource=null,this.mixer=null,this.frequencyData=new Uint8Array(0),this.waveformData=new Float32Array(0),this.hasAcquiredContext=!1,this.smoothedBass=0,this.smoothedMid=0,this.smoothedTreble=0,this.smoothedLevel=0,this.smoothingFactor=.3,this.options={fftSize:e.fftSize??2048,smoothingTimeConstant:e.smoothingTimeConstant??.8,minDecibels:e.minDecibels??-90,maxDecibels:e.maxDecibels??-10}}async ensureAudioContext(){if(!this.audioContext)this.audioContext=await dr.acquire(),this.audioContext&&(this.hasAcquiredContext=!0);else if(!await dr.ensureResumed())return null;return this.audioContext}async connectStream(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.source)try{this.source.disconnect()}catch{}this.source=t.createMediaStreamSource(e),this.setupMixerAndAnalyser(),this.mixer&&this.source.connect(this.mixer)}async connectLocalStream(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.localSource)try{this.localSource.disconnect()}catch{}this.localSource=t.createMediaStreamSource(e),this.setupMixerAndAnalyser(),this.mixer&&this.localSource.connect(this.mixer)}setupMixerAndAnalyser(){this.audioContext&&(this.mixer||(this.mixer=this.audioContext.createGain(),this.mixer.gain.value=1),this.analyser||(this.analyser=this.audioContext.createAnalyser()),this.analyser.fftSize=this.options.fftSize,this.analyser.smoothingTimeConstant=this.options.smoothingTimeConstant,this.analyser.minDecibels=this.options.minDecibels,this.analyser.maxDecibels=this.options.maxDecibels,this.mixer.disconnect(),this.mixer.connect(this.analyser),this.frequencyData=new Uint8Array(this.analyser.frequencyBinCount),this.waveformData=new Float32Array(this.analyser.fftSize))}async connectAudioElement(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.source)try{this.source.disconnect()}catch{}const n=t.createMediaElementSource(e);this.analyser||(this.analyser=t.createAnalyser()),this.analyser.fftSize=this.options.fftSize,this.analyser.smoothingTimeConstant=this.options.smoothingTimeConstant,this.analyser.minDecibels=this.options.minDecibels,this.analyser.maxDecibels=this.options.maxDecibels,n.connect(this.analyser),this.analyser.connect(t.destination),this.frequencyData=new Uint8Array(this.analyser.frequencyBinCount),this.waveformData=new Float32Array(this.analyser.fftSize)}getAudioData(){if(!this.analyser)return{bass:0,mid:0,treble:0,level:0,waveform:new Float32Array(0),frequency:new Uint8Array(0)};this.analyser.getByteFrequencyData(this.frequencyData),this.analyser.getFloatTimeDomainData(this.waveformData);const{bass:e,mid:t,treble:n}=this.calculateFrequencyBands(),s=this.calculateOverallLevel();return this.smoothedBass+=(e-this.smoothedBass)*this.smoothingFactor,this.smoothedMid+=(t-this.smoothedMid)*this.smoothingFactor,this.smoothedTreble+=(n-this.smoothedTreble)*this.smoothingFactor,this.smoothedLevel+=(s-this.smoothedLevel)*this.smoothingFactor,{bass:this.smoothedBass,mid:this.smoothedMid,treble:this.smoothedTreble,level:this.smoothedLevel,waveform:this.waveformData,frequency:this.frequencyData}}calculateFrequencyBands(){if(!this.audioContext||this.frequencyData.length===0)return{bass:0,mid:0,treble:0};const e=this.audioContext.sampleRate,t=this.frequencyData.length,n=e/(t*2),s=Math.floor(250/n),r=Math.floor(2e3/n);let a=0,o=0,c=0;for(let h=0;h<t;h++){const f=this.frequencyData[h]/255;h<s?a+=f:h<r?o+=f:c+=f}const l=s>0?a/s:0,d=r-s>0?o/(r-s):0,u=t-r>0?c/(t-r):0;return{bass:Math.pow(l,.8),mid:Math.pow(d,.9),treble:Math.pow(u,1.1)}}calculateOverallLevel(){if(this.frequencyData.length===0)return 0;let e=0;for(let n=0;n<this.frequencyData.length;n++)e+=this.frequencyData[n];const t=e/this.frequencyData.length/255;return Math.pow(t,.8)}getPeakLevel(){if(this.frequencyData.length===0)return 0;let e=0;for(let t=0;t<this.frequencyData.length;t++)this.frequencyData[t]>e&&(e=this.frequencyData[t]);return e/255}isActive(){return this.audioContext!==null&&this.audioContext.state==="running"}disconnect(){if(this.source){try{this.source.disconnect()}catch{}this.source=null}if(this.localSource){try{this.localSource.disconnect()}catch{}this.localSource=null}if(this.mixer){try{this.mixer.disconnect()}catch{}this.mixer=null}if(this.analyser){try{this.analyser.disconnect()}catch{}this.analyser=null}this.hasAcquiredContext&&(dr.release(),this.hasAcquiredContext=!1),this.audioContext=null,this.smoothedBass=0,this.smoothedMid=0,this.smoothedTreble=0,this.smoothedLevel=0}getAudioContext(){return this.audioContext}getAnalyser(){return this.analyser}}class bo{constructor(e={}){this.hasAcquired=!1,this.config={enabled:!0,volume:.3,preset:"1",...e}}async ensureContext(){if(!this.config.enabled||this.config.preset==="none")return null;const e=await dr.acquire();return e&&(this.hasAcquired=!0),e}async prewarm(){await this.ensureContext()}async playDrop(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?900:700,a=e?500:400,o=t.createOscillator(),c=t.createGain();o.type="sine",o.frequency.setValueAtTime(r,n),o.frequency.exponentialRampToValueAtTime(a,n+.15),c.gain.setValueAtTime(0,n),c.gain.linearRampToValueAtTime(s*.3,n+.015),c.gain.linearRampToValueAtTime(s*.2,n+.1),c.gain.exponentialRampToValueAtTime(.001,n+.35),o.connect(c).connect(t.destination),o.start(n),o.stop(n+.4)}async playGlassTap(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?2200:1760,a=t.createOscillator(),o=t.createGain();a.type="sine",a.frequency.setValueAtTime(r,n),o.gain.setValueAtTime(0,n),o.gain.linearRampToValueAtTime(s*.25,n+.002),o.gain.exponentialRampToValueAtTime(s*.1,n+.08),o.gain.exponentialRampToValueAtTime(.001,n+.3),a.connect(o).connect(t.destination),a.start(n),a.stop(n+.35);const c=t.createOscillator(),l=t.createGain();c.type="sine",c.frequency.setValueAtTime(r*2.5,n),l.gain.setValueAtTime(0,n),l.gain.linearRampToValueAtTime(s*.08,n+.001),l.gain.exponentialRampToValueAtTime(.001,n+.12),c.connect(l).connect(t.destination),c.start(n),c.stop(n+.15)}async playWhoosh(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=t.sampleRate*.5,a=t.createBuffer(1,r,t.sampleRate),o=a.getChannelData(0);for(let f=0;f<r;f++)o[f]=Math.random()*2-1;const c=t.createBufferSource();c.buffer=a;const l=t.createBiquadFilter();l.type="bandpass",l.Q.setValueAtTime(2,n);const d=t.createGain();e?(l.frequency.setValueAtTime(300,n),l.frequency.exponentialRampToValueAtTime(2e3,n+.15),l.frequency.exponentialRampToValueAtTime(800,n+.35),d.gain.setValueAtTime(0,n),d.gain.linearRampToValueAtTime(s*.3,n+.05),d.gain.linearRampToValueAtTime(s*.4,n+.15),d.gain.exponentialRampToValueAtTime(.001,n+.4)):(l.frequency.setValueAtTime(1500,n),l.frequency.exponentialRampToValueAtTime(200,n+.3),d.gain.setValueAtTime(0,n),d.gain.linearRampToValueAtTime(s*.35,n+.05),d.gain.exponentialRampToValueAtTime(.001,n+.35));const u=t.createOscillator(),h=t.createGain();u.type="sine",e?(u.frequency.setValueAtTime(300,n),u.frequency.linearRampToValueAtTime(500,n+.2)):(u.frequency.setValueAtTime(400,n),u.frequency.linearRampToValueAtTime(200,n+.25)),h.gain.setValueAtTime(0,n),h.gain.linearRampToValueAtTime(s*.15,n+.05),h.gain.exponentialRampToValueAtTime(.001,n+.35),c.connect(l).connect(d).connect(t.destination),u.connect(h).connect(t.destination),c.start(n),c.stop(n+.5),u.start(n),u.stop(n+.4)}async playGentleNote(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?659.25:523.25,a=t.createOscillator(),o=t.createGain();a.type="sine",a.frequency.setValueAtTime(r,n),o.gain.setValueAtTime(0,n),o.gain.linearRampToValueAtTime(s*.3,n+.02),o.gain.linearRampToValueAtTime(s*.25,n+.1),o.gain.exponentialRampToValueAtTime(s*.08,n+.3),o.gain.exponentialRampToValueAtTime(.001,n+.5),a.connect(o).connect(t.destination),a.start(n),a.stop(n+.55);const c=t.createOscillator(),l=t.createGain();c.type="sine",c.frequency.setValueAtTime(r*2,n),l.gain.setValueAtTime(0,n),l.gain.linearRampToValueAtTime(s*.06,n+.02),l.gain.exponentialRampToValueAtTime(.001,n+.2),c.connect(l).connect(t.destination),c.start(n),c.stop(n+.25)}async playCallStartSound(){if(!(!this.config.enabled||this.config.preset==="none"))switch(this.config.preset){case"1":await this.playDrop(!0);break;case"2":await this.playGlassTap(!0);break;case"3":await this.playWhoosh(!0);break;case"4":await this.playGentleNote(!0);break}}async playCallEndSound(){if(!(!this.config.enabled||this.config.preset==="none"))switch(this.config.preset){case"1":await this.playDrop(!1);break;case"2":await this.playGlassTap(!1);break;case"3":await this.playWhoosh(!1);break;case"4":await this.playGentleNote(!1);break}}setConfig(e){this.config={...this.config,...e}}setEnabled(e){this.config.enabled=e}setVolume(e){this.config.volume=Math.max(0,Math.min(1,e))}setPreset(e){this.config.preset=e}getConfig(){return{...this.config}}isEnabled(){return this.config.enabled&&this.config.preset!=="none"}destroy(){this.hasAcquired&&(dr.release(),this.hasAcquired=!1)}}const ii={default:{primary:"#6366f1",secondary:"#8b5cf6",accent:"#06b6d4",glow:"#818cf8",atmosphere:"#c4b5fd",depth:"#312e81",highlight:"#e0e7ff"},emerald:{primary:"#10b981",secondary:"#34d399",accent:"#6ee7b7",glow:"#34d399",atmosphere:"#a7f3d0",depth:"#064e3b",highlight:"#d1fae5"},rose:{primary:"#f43f5e",secondary:"#fb7185",accent:"#fda4af",glow:"#fb7185",atmosphere:"#fecdd3",depth:"#881337",highlight:"#ffe4e6"},amber:{primary:"#f59e0b",secondary:"#fbbf24",accent:"#fcd34d",glow:"#fbbf24",atmosphere:"#fde68a",depth:"#78350f",highlight:"#fef3c7"},cyan:{primary:"#06b6d4",secondary:"#22d3ee",accent:"#67e8f9",glow:"#22d3ee",atmosphere:"#a5f3fc",depth:"#164e63",highlight:"#cffafe"},purple:{primary:"#9333ea",secondary:"#a855f7",accent:"#c084fc",glow:"#a855f7",atmosphere:"#d8b4fe",depth:"#581c87",highlight:"#f3e8ff"},blue:{primary:"#2563eb",secondary:"#3b82f6",accent:"#60a5fa",glow:"#3b82f6",atmosphere:"#93c5fd",depth:"#1e3a8a",highlight:"#dbeafe"}},si={indigo:{primary:"#3730a3",secondary:"#4338ca",accent:"#4f46e5",glow:"#3730a3",atmosphere:"#4338ca",depth:"#1e1b4b",highlight:"#a5b4fc"},violet:{primary:"#5b21b6",secondary:"#6d28d9",accent:"#7c3aed",glow:"#5b21b6",atmosphere:"#6d28d9",depth:"#2e1065",highlight:"#c4b5fd"},teal:{primary:"#0f766e",secondary:"#0d9488",accent:"#14b8a6",glow:"#0f766e",atmosphere:"#0d9488",depth:"#042f2e",highlight:"#5eead4"},orange:{primary:"#c2410c",secondary:"#ea580c",accent:"#f97316",glow:"#c2410c",atmosphere:"#ea580c",depth:"#431407",highlight:"#fed7aa"},blue:{primary:"#1d4ed8",secondary:"#2563eb",accent:"#3b82f6",glow:"#1d4ed8",atmosphere:"#2563eb",depth:"#1e3a8a",highlight:"#93c5fd"},pink:{primary:"#be185d",secondary:"#db2777",accent:"#ec4899",glow:"#be185d",atmosphere:"#db2777",depth:"#500724",highlight:"#f9a8d4"}};function zC(i,e="dark"){const t=e==="dark"?ii:si;return t[i]||t[Object.keys(t)[0]]}function GC(i="dark"){return Object.keys(i==="dark"?ii:si)}const ur={default:{dark:{colors:ii.default,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.indigo,glowIntensity:1.8,idleGlowMultiplier:1.2}},emerald:{dark:{colors:ii.emerald,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.teal,glowIntensity:1.8,idleGlowMultiplier:1.2}},rose:{dark:{colors:ii.rose,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.pink,glowIntensity:1.8,idleGlowMultiplier:1.2}},amber:{dark:{colors:ii.amber,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.orange,glowIntensity:1.8,idleGlowMultiplier:1.2}},cyan:{dark:{colors:ii.cyan,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.blue,glowIntensity:1.8,idleGlowMultiplier:1.2}},purple:{dark:{colors:ii.purple,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.violet,glowIntensity:1.8,idleGlowMultiplier:1.2}},blue:{dark:{colors:ii.blue,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.blue,glowIntensity:1.8,idleGlowMultiplier:1.2}}},HC=Object.fromEntries(Object.entries(ur).map(([i,e])=>[i,e.dark])),WC=Object.fromEntries(Object.entries(ur).map(([i,e])=>[i,e.light]));function Mm(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function ea(i,e="auto"){const t=ur[i]||ur.default,n=e==="auto"?Mm():e;return t[n]}function qC(){return Object.keys(ur)}function wm(i,e,t="auto"){const n=ea(e,t);i.orbColors=n.colors,i.glowIntensity=n.glowIntensity,i.idleGlowMultiplier=n.idleGlowMultiplier}function jC(i,e){if(typeof window>"u")return()=>{};const t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>{const s=t.matches?"dark":"light";wm(i,e,s)};return n(),t.addEventListener("change",n),()=>{t.removeEventListener("change",n)}}var $C=Object.defineProperty,XC=Object.getOwnPropertyDescriptor,mt=(i,e,t,n)=>{for(var s=n>1?void 0:n?XC(e,t):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(n?a(e,t,s):a(s))||s);return n&&s&&$C(e,t,s),s};Y.InlineCall=class extends ts{constructor(){super(),this.callManager=new Jc,this.healthMonitor=new Zc,this.orbRenderer=null,this.audioAnalyzer=null,this.soundManager=null,this.orbContainerRef=ko(),this.animationId=null,this.pendingTimers=new Set,this.isPageVisible=!0,this.animationStartTime=0,this.intersectionObserver=null,this.isOrbInitialized=!1,this.callStatus="idle",this.microphoneEnabled=!1,this.serviceUnavailable=!1,this.buttonStartText="Try to call",this.buttonConnectingText="Connecting...",this.size=370,this.containerPadding=45,this.theme="default",this.themeMode="auto",this.orbColors={},this.glowIntensity=.8,this.idleGlowMultiplier=.4,this.morphStrength=1,this.noiseScale=1.5,this.noiseSpeed=.3,this.fresnelPower=2.5,this.rotationSpeed=.1,this.audioReactivity=3,this.audioSmoothing=.9,this.idleMorphMultiplier=.25,this.colorContrast=1.5,this.soundEnabled=!0,this.soundVolume=.25,this.soundPreset="1",this.handleAudioTrack=async e=>{const n=e.detail;if(!(!n||!this.audioAnalyzer))try{const s=new MediaStream([n]);await this.audioAnalyzer.connectStream(s)}catch(s){console.error("Failed to connect audio stream:",s)}},this.handleLocalAudioTrack=async e=>{const n=e.detail;if(!(!n||!this.audioAnalyzer))try{const s=new MediaStream([n]);await this.audioAnalyzer.connectLocalStream(s)}catch(s){console.error("Failed to connect local audio stream:",s)}},this.handleMicrophoneEnabled=()=>{this.microphoneEnabled=!0},this.handleMicrophoneDisabled=()=>{this.microphoneEnabled=!1},this.handleHealthChange=e=>{const t=e.detail;this.serviceUnavailable=t==="unhealthy"},this.handleStatusChange=e=>{var n,s,r,a,o;switch(e.detail){case"connecting":this.callStatus="connecting";break;case"connected":this.callStatus="connected",(n=this.orbRenderer)==null||n.setActive(!0),this.startRealAudioLoop(),this.scheduleTimer(()=>{var c;(c=this.soundManager)==null||c.playCallStartSound()},300),this.dispatchEvent(new Event("call-start",{bubbles:!0,composed:!0}));break;case"disconnected":this.callStatus="idle",(s=this.orbRenderer)==null||s.setActive(!1),(r=this.audioAnalyzer)==null||r.disconnect(),this.startIdleAnimation(),this.scheduleTimer(()=>{var c;(c=this.soundManager)==null||c.playCallEndSound()},150),this.dispatchEvent(new Event("call-end",{bubbles:!0,composed:!0}));break;case"error":this.callStatus="error",(a=this.orbRenderer)==null||a.setActive(!1),(o=this.audioAnalyzer)==null||o.disconnect(),this.scheduleTimer(()=>{this.callStatus==="error"&&(this.callStatus="idle",this.startIdleAnimation())},3e3);break}},this.toggleCall=async()=>{var e;this.agentId&&(this.callStatus==="idle"&&!this.healthMonitor.isHealthy||(await((e=this.soundManager)==null?void 0:e.prewarm()),this.callStatus==="idle"?(this.callStatus="connecting",await this.callManager.makeCall({agentId:this.agentId})):this.callStatus==="connected"&&this.callManager.hangUp()))},this.boundHandleVisibilityChange=this.handleVisibilityChange.bind(this)}connectedCallback(){super.connectedCallback(),document.addEventListener("visibilitychange",this.boundHandleVisibilityChange),this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl),this.soundManager=new bo({enabled:this.soundEnabled,volume:this.soundVolume,preset:this.soundPreset}),this.callManager.addEventListener("status-changed",this.handleStatusChange),this.callManager.addEventListener("audio-track",this.handleAudioTrack),this.callManager.addEventListener("local-audio-track",this.handleLocalAudioTrack),this.callManager.addEventListener("microphone-enabled",this.handleMicrophoneEnabled),this.callManager.addEventListener("microphone-disabled",this.handleMicrophoneDisabled),this.healthMonitor.serviceUrl=this.callManager.serviceUrl,this.healthMonitor.addEventListener("health-changed",this.handleHealthChange),this.healthMonitor.start()}disconnectedCallback(){var e;super.disconnectedCallback(),document.removeEventListener("visibilitychange",this.boundHandleVisibilityChange),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.clearAllTimers(),this.callManager.removeEventListener("status-changed",this.handleStatusChange),this.callManager.removeEventListener("audio-track",this.handleAudioTrack),this.callManager.removeEventListener("local-audio-track",this.handleLocalAudioTrack),this.callManager.removeEventListener("microphone-enabled",this.handleMicrophoneEnabled),this.callManager.removeEventListener("microphone-disabled",this.handleMicrophoneDisabled),this.healthMonitor.stop(),this.healthMonitor.removeEventListener("health-changed",this.handleHealthChange),this.callManager.destroy(),this.cleanupOrb(),(e=this.soundManager)==null||e.destroy(),this.soundManager=null}handleVisibilityChange(){const e=this.isPageVisible;this.isPageVisible=document.visibilityState==="visible",!this.isPageVisible&&e?this.stopAnimation():this.isPageVisible&&!e&&this.resumeAnimation()}stopAnimation(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}resumeAnimation(){this.callStatus==="idle"?this.startIdleAnimation():this.callStatus==="connected"&&this.startRealAudioLoop()}scheduleTimer(e,t){const n=setTimeout(()=>{this.pendingTimers.delete(n),e()},t);return this.pendingTimers.add(n),n}clearAllTimers(){this.pendingTimers.forEach(e=>clearTimeout(e)),this.pendingTimers.clear()}firstUpdated(){this.applyTheme(),this.setupLazyInitialization()}setupLazyInitialization(){const e=this.orbContainerRef.value;if(!e){this.initializeOrb();return}if(!("IntersectionObserver"in window)){this.initializeOrb();return}this.intersectionObserver=new IntersectionObserver(t=>{var n;for(const s of t)s.isIntersecting&&!this.isOrbInitialized&&(this.initializeOrb(),this.isOrbInitialized=!0,(n=this.intersectionObserver)==null||n.disconnect(),this.intersectionObserver=null)},{threshold:.1}),this.intersectionObserver.observe(e)}updated(e){var t,n,s;super.updated(e),e.has("agentId")&&(this.callManager.hangUp(),this.callStatus="idle"),e.has("voiceServiceUrl")&&this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl,this.healthMonitor.serviceUrl=this.voiceServiceUrl),(e.has("theme")||e.has("themeMode"))&&this.applyTheme(),e.has("soundEnabled")&&((t=this.soundManager)==null||t.setEnabled(this.soundEnabled)),e.has("soundVolume")&&((n=this.soundManager)==null||n.setVolume(this.soundVolume)),e.has("soundPreset")&&((s=this.soundManager)==null||s.setPreset(this.soundPreset))}applyTheme(){if(this.theme){const e=ea(this.theme,this.themeMode);this.orbColors=e.colors,this.glowIntensity=e.glowIntensity,this.idleGlowMultiplier=e.idleGlowMultiplier,this.orbRenderer&&(this.orbRenderer.setColors(this.orbColors),this.orbRenderer.setGlowSettings(this.glowIntensity,this.idleGlowMultiplier))}}initializeOrb(){const e=this.orbContainerRef.value;e&&(this.orbRenderer=new Bd(e,{size:1,colors:this.orbColors,glowIntensity:this.glowIntensity,idleGlowMultiplier:this.idleGlowMultiplier,morphStrength:this.morphStrength,noiseScale:this.noiseScale,noiseSpeed:this.noiseSpeed,fresnelPower:this.fresnelPower,rotationSpeed:this.rotationSpeed,audioReactivity:this.audioReactivity,audioSmoothing:this.audioSmoothing,idleMorphMultiplier:this.idleMorphMultiplier,colorContrast:this.colorContrast}),this.audioAnalyzer=new Vd,this.orbRenderer.start(),this.startIdleAnimation())}cleanupOrb(){var e,t;this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),(e=this.audioAnalyzer)==null||e.disconnect(),(t=this.orbRenderer)==null||t.destroy(),this.audioAnalyzer=null,this.orbRenderer=null}startIdleAnimation(){if(this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),!this.isPageVisible)return;this.animationStartTime=performance.now();const e=t=>{if(this.callStatus!=="idle"||!this.orbRenderer||!this.isPageVisible){this.animationId=null;return}const n=(t-this.animationStartTime)/1e3,s=Math.sin(n*.5)*.15+.15,r=Math.sin(n*.7+1)*.12+.12,a=Math.sin(n*.9+2)*.08+.08,o=(s+r+a)/3;this.orbRenderer.setSimulatedAudio(s,r,a,o),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}startRealAudioLoop(){if(this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),!this.isPageVisible)return;const e=()=>{var n;if(this.callStatus!=="connected"||!this.orbRenderer||!this.isPageVisible){this.animationId=null;return}const t=(n=this.audioAnalyzer)==null?void 0:n.getAudioData();t&&this.orbRenderer.updateAudio(t),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}getButtonIcon(){return this.callStatus==="connecting"?Gt`
4471
+ `,Ss={primary:"#6366f1",secondary:"#8b5cf6",accent:"#06b6d4",glow:"#818cf8",atmosphere:"#c4b5fd",depth:"#312e81",highlight:"#e0e7ff"},VC={size:1,segments:128,colors:Ss,morphStrength:1,noiseScale:1.5,noiseSpeed:.3,glowIntensity:.8,idleGlowMultiplier:.4,fresnelPower:2.5,rotationSpeed:.1,audioReactivity:3,audioSmoothing:.9,idleMorphMultiplier:.25,colorContrast:1.5};class Bd{constructor(e,t={}){this.orb=null,this.glowMesh=null,this.orbMaterial=null,this.glowMaterial=null,this.animationId=null,this.isActive=!1,this.targetRotation={x:0,y:0},this.currentRotation={x:0,y:0},this.audioValues={bass:0,mid:0,treble:0,level:0},this.resizeObserver=null,this.resizeTimeoutId=null,this.isContextLost=!1,this.animate=()=>{if(this.isContextLost)return;this.animationId=requestAnimationFrame(this.animate);const u=this.clock.getElapsedTime();if(this.clock.getDelta(),this.orbMaterial){this.orbMaterial.uniforms.uTime.value=u,this.orbMaterial.uniforms.uAudioBass.value=this.audioValues.bass,this.orbMaterial.uniforms.uAudioMid.value=this.audioValues.mid,this.orbMaterial.uniforms.uAudioTreble.value=this.audioValues.treble,this.orbMaterial.uniforms.uAudioLevel.value=this.audioValues.level;const h=this.isActive?this.config.morphStrength*1.5:this.config.morphStrength*this.config.idleMorphMultiplier,f=this.orbMaterial.uniforms.uMorphStrength.value;this.orbMaterial.uniforms.uMorphStrength.value+=(h-f)*.05}if(this.glowMaterial){this.glowMaterial.uniforms.uTime.value=u,this.glowMaterial.uniforms.uAudioLevel.value=this.audioValues.level;const h=this.isActive?this.config.glowIntensity*1.5:this.config.glowIntensity*this.config.idleGlowMultiplier,f=this.glowMaterial.uniforms.uGlowIntensity.value;this.glowMaterial.uniforms.uGlowIntensity.value+=(h-f)*.05}this.currentRotation.x+=(this.targetRotation.x-this.currentRotation.x)*.05,this.currentRotation.y+=(this.targetRotation.y-this.currentRotation.y)*.05,this.orb&&(this.orb.rotation.x=this.currentRotation.x+u*this.config.rotationSpeed*.3,this.orb.rotation.y=this.currentRotation.y+u*this.config.rotationSpeed),this.glowMesh&&(this.glowMesh.rotation.x=this.currentRotation.x+u*this.config.rotationSpeed*.3,this.glowMesh.rotation.y=this.currentRotation.y+u*this.config.rotationSpeed),this.renderer.render(this.scene,this.camera)},this.handleResize=()=>{this.resizeTimeoutId!==null&&clearTimeout(this.resizeTimeoutId),this.resizeTimeoutId=setTimeout(()=>{this.resizeTimeoutId=null;const u=this.container.clientWidth,h=this.container.clientHeight;if(u===0||h===0)return;const f=u*this.canvasPadding,g=h*this.canvasPadding;this.camera.aspect=f/g,this.camera.updateProjectionMatrix(),this.renderer.setSize(f,g)},100)},this.handleMouseMove=u=>{const h=this.container.getBoundingClientRect(),f=(u.clientX-h.left)/h.width*2-1,g=-((u.clientY-h.top)/h.height)*2+1;this.targetRotation.x=g*.3,this.targetRotation.y=f*.3},this.handleMouseLeave=()=>{this.targetRotation.x=0,this.targetRotation.y=0},this.container=e,this.config={...VC,...t},this.clock=new _y;const n=/iPhone|iPad|iPod/i.test(navigator.userAgent),s=/Android/i.test(navigator.userAgent);this.canvasPadding=n?1.5:s?2:3,this.boundHandleContextLost=this.handleContextLost.bind(this),this.boundHandleContextRestored=this.handleContextRestored.bind(this),this.scene=new ly;const r=e.clientWidth*this.canvasPadding,a=e.clientHeight*this.canvasPadding,o=r/a;this.camera=new Cn(45,o,.1,100);const c=3,l=9;this.camera.position.z=l*(this.canvasPadding/c),this.renderer=new NC({antialias:!0,alpha:!0,powerPreference:"high-performance"}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.renderer.setSize(r,a),this.renderer.setClearColor(0,0);const d=this.renderer.domElement;d.style.position="absolute",d.style.left="50%",d.style.top="50%",d.style.transform="translate(-50%, -50%)",d.style.pointerEvents="none",e.appendChild(d),d.addEventListener("webglcontextlost",this.boundHandleContextLost),d.addEventListener("webglcontextrestored",this.boundHandleContextRestored),this.createOrb(),window.addEventListener("resize",this.handleResize),this.resizeObserver=new ResizeObserver(this.handleResize),this.resizeObserver.observe(e),e.addEventListener("mousemove",this.handleMouseMove),e.addEventListener("mouseleave",this.handleMouseLeave)}handleContextLost(e){e.preventDefault(),this.isContextLost=!0,this.stop()}handleContextRestored(e){this.isContextLost=!1,this.recreateAfterContextLoss(),this.start()}recreateAfterContextLoss(){this.orb&&(this.orb.geometry.dispose(),this.scene.remove(this.orb),this.orb=null),this.glowMesh&&(this.glowMesh.geometry.dispose(),this.scene.remove(this.glowMesh),this.glowMesh=null),this.orbMaterial&&(this.orbMaterial.dispose(),this.orbMaterial=null),this.glowMaterial&&(this.glowMaterial.dispose(),this.glowMaterial=null),this.createOrb()}createOrb(){const e={...Ss,...this.config.colors},t=new Rd(this.config.size,this.config.segments/4);this.orbMaterial=new Tn({vertexShader:UC,fragmentShader:OC,uniforms:{uTime:{value:0},uAudioBass:{value:0},uAudioMid:{value:0},uAudioTreble:{value:0},uAudioLevel:{value:0},uMorphStrength:{value:this.config.morphStrength},uNoiseScale:{value:this.config.noiseScale},uNoiseSpeed:{value:this.config.noiseSpeed},uAudioReactivity:{value:this.config.audioReactivity},uColorPrimary:{value:new Ze(e.primary)},uColorSecondary:{value:new Ze(e.secondary)},uColorAccent:{value:new Ze(e.accent)},uColorDepth:{value:new Ze(e.depth||Ss.depth)},uColorHighlight:{value:new Ze(e.highlight||Ss.highlight)},uFresnelPower:{value:this.config.fresnelPower},uGlowIntensity:{value:this.config.glowIntensity},uColorContrast:{value:this.config.colorContrast}},transparent:!0,side:mi}),this.orb=new Vn(t,this.orbMaterial),this.scene.add(this.orb);const n=new Pd(this.config.size,64,64);this.glowMaterial=new Tn({vertexShader:FC,fragmentShader:BC,uniforms:{uTime:{value:0},uAudioLevel:{value:0},uGlowColor:{value:new Ze(e.glow)},uGlowIntensity:{value:this.config.glowIntensity*.6},uPulseSpeed:{value:2}},transparent:!0,side:Zt,blending:el,depthWrite:!1}),this.glowMesh=new Vn(n,this.glowMaterial),this.scene.add(this.glowMesh)}updateAudio(e){const t=this.config.audioSmoothing;this.audioValues.bass+=(e.bass-this.audioValues.bass)*t,this.audioValues.mid+=(e.mid-this.audioValues.mid)*t,this.audioValues.treble+=(e.treble-this.audioValues.treble)*t,this.audioValues.level+=(e.level-this.audioValues.level)*t}setSimulatedAudio(e,t,n,s){const r=this.config.audioSmoothing;this.audioValues.bass+=(e-this.audioValues.bass)*r,this.audioValues.mid+=(t-this.audioValues.mid)*r,this.audioValues.treble+=(n-this.audioValues.treble)*r,this.audioValues.level+=(s-this.audioValues.level)*r}setActive(e){this.isActive=e}setColors(e){const t={...Ss,...this.config.colors,...e};this.orbMaterial&&(this.orbMaterial.uniforms.uColorPrimary.value.set(t.primary),this.orbMaterial.uniforms.uColorSecondary.value.set(t.secondary),this.orbMaterial.uniforms.uColorAccent.value.set(t.accent),this.orbMaterial.uniforms.uColorDepth.value.set(t.depth||Ss.depth),this.orbMaterial.uniforms.uColorHighlight.value.set(t.highlight||Ss.highlight)),this.glowMaterial&&this.glowMaterial.uniforms.uGlowColor.value.set(t.glow)}setGlowSettings(e,t){this.config.glowIntensity=e,this.config.idleGlowMultiplier=t}start(){this.animationId===null&&(this.clock.start(),this.animate())}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}getCanvas(){return this.renderer.domElement}destroy(){this.stop(),this.resizeTimeoutId!==null&&(clearTimeout(this.resizeTimeoutId),this.resizeTimeoutId=null),window.removeEventListener("resize",this.handleResize),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.container.removeEventListener("mousemove",this.handleMouseMove),this.container.removeEventListener("mouseleave",this.handleMouseLeave);const e=this.renderer.domElement;e.removeEventListener("webglcontextlost",this.boundHandleContextLost),e.removeEventListener("webglcontextrestored",this.boundHandleContextRestored),this.orb&&(this.orb.geometry.dispose(),this.scene.remove(this.orb),this.orb=null),this.glowMesh&&(this.glowMesh.geometry.dispose(),this.scene.remove(this.glowMesh),this.glowMesh=null),this.orbMaterial&&(this.orbMaterial.dispose(),this.orbMaterial=null),this.glowMaterial&&(this.glowMaterial.dispose(),this.glowMaterial=null),this.renderer.dispose(),e.parentNode&&e.parentNode.removeChild(e)}}class lr{constructor(){this.audioContext=null,this.refCount=0,this.resumePromise=null}static getInstance(){return lr.instance||(lr.instance=new lr),lr.instance}async acquire(){if(this.refCount++,!this.audioContext)try{const e=window.AudioContext||window.webkitAudioContext;if(!e)return console.warn("[SharedAudioContext] Web Audio API not supported"),null;this.audioContext=new e,console.log("[SharedAudioContext] Created shared AudioContext")}catch(e){return console.warn("[SharedAudioContext] Failed to create AudioContext:",e),null}return await this.ensureResumed(),this.audioContext}release(){this.refCount=Math.max(0,this.refCount-1),this.refCount===0&&console.log("[SharedAudioContext] All references released, context kept alive for reuse")}forceClose(){if(this.audioContext){try{this.audioContext.close()}catch{}this.audioContext=null,this.refCount=0,console.log("[SharedAudioContext] Force closed")}}getContext(){return this.audioContext}async ensureResumed(){if(!this.audioContext)return!1;if(this.audioContext.state==="suspended"){this.resumePromise||(this.resumePromise=this.audioContext.resume().finally(()=>{this.resumePromise=null}));try{await this.resumePromise}catch{return!1}}return this.audioContext.state==="running"}isRunning(){return this.audioContext!==null&&this.audioContext.state==="running"}getState(){var e;return((e=this.audioContext)==null?void 0:e.state)??null}getSampleRate(){var e;return((e=this.audioContext)==null?void 0:e.sampleRate)??44100}getCurrentTime(){var e;return((e=this.audioContext)==null?void 0:e.currentTime)??0}getDestination(){var e;return((e=this.audioContext)==null?void 0:e.destination)??null}}const dr=lr.getInstance();typeof window<"u"&&window.addEventListener("pagehide",()=>{dr.forceClose()});class Vd{constructor(e={}){this.audioContext=null,this.analyser=null,this.source=null,this.localSource=null,this.mixer=null,this.frequencyData=new Uint8Array(0),this.waveformData=new Float32Array(0),this.hasAcquiredContext=!1,this.smoothedBass=0,this.smoothedMid=0,this.smoothedTreble=0,this.smoothedLevel=0,this.smoothingFactor=.3,this.options={fftSize:e.fftSize??2048,smoothingTimeConstant:e.smoothingTimeConstant??.8,minDecibels:e.minDecibels??-90,maxDecibels:e.maxDecibels??-10}}async ensureAudioContext(){if(!this.audioContext)this.audioContext=await dr.acquire(),this.audioContext&&(this.hasAcquiredContext=!0);else if(!await dr.ensureResumed())return null;return this.audioContext}async connectStream(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.source)try{this.source.disconnect()}catch{}this.source=t.createMediaStreamSource(e),this.setupMixerAndAnalyser(),this.mixer&&this.source.connect(this.mixer)}async connectLocalStream(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.localSource)try{this.localSource.disconnect()}catch{}this.localSource=t.createMediaStreamSource(e),this.setupMixerAndAnalyser(),this.mixer&&this.localSource.connect(this.mixer)}setupMixerAndAnalyser(){this.audioContext&&(this.mixer||(this.mixer=this.audioContext.createGain(),this.mixer.gain.value=1),this.analyser||(this.analyser=this.audioContext.createAnalyser()),this.analyser.fftSize=this.options.fftSize,this.analyser.smoothingTimeConstant=this.options.smoothingTimeConstant,this.analyser.minDecibels=this.options.minDecibels,this.analyser.maxDecibels=this.options.maxDecibels,this.mixer.disconnect(),this.mixer.connect(this.analyser),this.frequencyData=new Uint8Array(this.analyser.frequencyBinCount),this.waveformData=new Float32Array(this.analyser.fftSize))}async connectAudioElement(e){const t=await this.ensureAudioContext();if(!t){console.warn("[AudioAnalyzer] Could not acquire AudioContext");return}if(this.source)try{this.source.disconnect()}catch{}const n=t.createMediaElementSource(e);this.analyser||(this.analyser=t.createAnalyser()),this.analyser.fftSize=this.options.fftSize,this.analyser.smoothingTimeConstant=this.options.smoothingTimeConstant,this.analyser.minDecibels=this.options.minDecibels,this.analyser.maxDecibels=this.options.maxDecibels,n.connect(this.analyser),this.analyser.connect(t.destination),this.frequencyData=new Uint8Array(this.analyser.frequencyBinCount),this.waveformData=new Float32Array(this.analyser.fftSize)}getAudioData(){if(!this.analyser)return{bass:0,mid:0,treble:0,level:0,waveform:new Float32Array(0),frequency:new Uint8Array(0)};this.analyser.getByteFrequencyData(this.frequencyData),this.analyser.getFloatTimeDomainData(this.waveformData);const{bass:e,mid:t,treble:n}=this.calculateFrequencyBands(),s=this.calculateOverallLevel();return this.smoothedBass+=(e-this.smoothedBass)*this.smoothingFactor,this.smoothedMid+=(t-this.smoothedMid)*this.smoothingFactor,this.smoothedTreble+=(n-this.smoothedTreble)*this.smoothingFactor,this.smoothedLevel+=(s-this.smoothedLevel)*this.smoothingFactor,{bass:this.smoothedBass,mid:this.smoothedMid,treble:this.smoothedTreble,level:this.smoothedLevel,waveform:this.waveformData,frequency:this.frequencyData}}calculateFrequencyBands(){if(!this.audioContext||this.frequencyData.length===0)return{bass:0,mid:0,treble:0};const e=this.audioContext.sampleRate,t=this.frequencyData.length,n=e/(t*2),s=Math.floor(250/n),r=Math.floor(2e3/n);let a=0,o=0,c=0;for(let h=0;h<t;h++){const f=this.frequencyData[h]/255;h<s?a+=f:h<r?o+=f:c+=f}const l=s>0?a/s:0,d=r-s>0?o/(r-s):0,u=t-r>0?c/(t-r):0;return{bass:Math.pow(l,.8),mid:Math.pow(d,.9),treble:Math.pow(u,1.1)}}calculateOverallLevel(){if(this.frequencyData.length===0)return 0;let e=0;for(let n=0;n<this.frequencyData.length;n++)e+=this.frequencyData[n];const t=e/this.frequencyData.length/255;return Math.pow(t,.8)}getPeakLevel(){if(this.frequencyData.length===0)return 0;let e=0;for(let t=0;t<this.frequencyData.length;t++)this.frequencyData[t]>e&&(e=this.frequencyData[t]);return e/255}isActive(){return this.audioContext!==null&&this.audioContext.state==="running"}disconnect(){if(this.source){try{this.source.disconnect()}catch{}this.source=null}if(this.localSource){try{this.localSource.disconnect()}catch{}this.localSource=null}if(this.mixer){try{this.mixer.disconnect()}catch{}this.mixer=null}if(this.analyser){try{this.analyser.disconnect()}catch{}this.analyser=null}this.hasAcquiredContext&&(dr.release(),this.hasAcquiredContext=!1),this.audioContext=null,this.smoothedBass=0,this.smoothedMid=0,this.smoothedTreble=0,this.smoothedLevel=0}getAudioContext(){return this.audioContext}getAnalyser(){return this.analyser}}class bo{constructor(e={}){this.hasAcquired=!1,this.config={enabled:!0,volume:.3,preset:"1",...e}}async ensureContext(){if(!this.config.enabled||this.config.preset==="none")return null;const e=await dr.acquire();return e&&(this.hasAcquired=!0),e}async prewarm(){await this.ensureContext()}async playDrop(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?900:700,a=e?500:400,o=t.createOscillator(),c=t.createGain();o.type="sine",o.frequency.setValueAtTime(r,n),o.frequency.exponentialRampToValueAtTime(a,n+.15),c.gain.setValueAtTime(0,n),c.gain.linearRampToValueAtTime(s*.3,n+.015),c.gain.linearRampToValueAtTime(s*.2,n+.1),c.gain.exponentialRampToValueAtTime(.001,n+.35),o.connect(c).connect(t.destination),o.start(n),o.stop(n+.4)}async playGlassTap(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?2200:1760,a=t.createOscillator(),o=t.createGain();a.type="sine",a.frequency.setValueAtTime(r,n),o.gain.setValueAtTime(0,n),o.gain.linearRampToValueAtTime(s*.25,n+.002),o.gain.exponentialRampToValueAtTime(s*.1,n+.08),o.gain.exponentialRampToValueAtTime(.001,n+.3),a.connect(o).connect(t.destination),a.start(n),a.stop(n+.35);const c=t.createOscillator(),l=t.createGain();c.type="sine",c.frequency.setValueAtTime(r*2.5,n),l.gain.setValueAtTime(0,n),l.gain.linearRampToValueAtTime(s*.08,n+.001),l.gain.exponentialRampToValueAtTime(.001,n+.12),c.connect(l).connect(t.destination),c.start(n),c.stop(n+.15)}async playWhoosh(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=t.sampleRate*.5,a=t.createBuffer(1,r,t.sampleRate),o=a.getChannelData(0);for(let f=0;f<r;f++)o[f]=Math.random()*2-1;const c=t.createBufferSource();c.buffer=a;const l=t.createBiquadFilter();l.type="bandpass",l.Q.setValueAtTime(2,n);const d=t.createGain();e?(l.frequency.setValueAtTime(300,n),l.frequency.exponentialRampToValueAtTime(2e3,n+.15),l.frequency.exponentialRampToValueAtTime(800,n+.35),d.gain.setValueAtTime(0,n),d.gain.linearRampToValueAtTime(s*.3,n+.05),d.gain.linearRampToValueAtTime(s*.4,n+.15),d.gain.exponentialRampToValueAtTime(.001,n+.4)):(l.frequency.setValueAtTime(1500,n),l.frequency.exponentialRampToValueAtTime(200,n+.3),d.gain.setValueAtTime(0,n),d.gain.linearRampToValueAtTime(s*.35,n+.05),d.gain.exponentialRampToValueAtTime(.001,n+.35));const u=t.createOscillator(),h=t.createGain();u.type="sine",e?(u.frequency.setValueAtTime(300,n),u.frequency.linearRampToValueAtTime(500,n+.2)):(u.frequency.setValueAtTime(400,n),u.frequency.linearRampToValueAtTime(200,n+.25)),h.gain.setValueAtTime(0,n),h.gain.linearRampToValueAtTime(s*.15,n+.05),h.gain.exponentialRampToValueAtTime(.001,n+.35),c.connect(l).connect(d).connect(t.destination),u.connect(h).connect(t.destination),c.start(n),c.stop(n+.5),u.start(n),u.stop(n+.4)}async playGentleNote(e){const t=await this.ensureContext();if(!t)return;const n=t.currentTime,s=this.config.volume,r=e?659.25:523.25,a=t.createOscillator(),o=t.createGain();a.type="sine",a.frequency.setValueAtTime(r,n),o.gain.setValueAtTime(0,n),o.gain.linearRampToValueAtTime(s*.3,n+.02),o.gain.linearRampToValueAtTime(s*.25,n+.1),o.gain.exponentialRampToValueAtTime(s*.08,n+.3),o.gain.exponentialRampToValueAtTime(.001,n+.5),a.connect(o).connect(t.destination),a.start(n),a.stop(n+.55);const c=t.createOscillator(),l=t.createGain();c.type="sine",c.frequency.setValueAtTime(r*2,n),l.gain.setValueAtTime(0,n),l.gain.linearRampToValueAtTime(s*.06,n+.02),l.gain.exponentialRampToValueAtTime(.001,n+.2),c.connect(l).connect(t.destination),c.start(n),c.stop(n+.25)}async playCallStartSound(){if(!(!this.config.enabled||this.config.preset==="none"))switch(this.config.preset){case"1":await this.playDrop(!0);break;case"2":await this.playGlassTap(!0);break;case"3":await this.playWhoosh(!0);break;case"4":await this.playGentleNote(!0);break}}async playCallEndSound(){if(!(!this.config.enabled||this.config.preset==="none"))switch(this.config.preset){case"1":await this.playDrop(!1);break;case"2":await this.playGlassTap(!1);break;case"3":await this.playWhoosh(!1);break;case"4":await this.playGentleNote(!1);break}}setConfig(e){this.config={...this.config,...e}}setEnabled(e){this.config.enabled=e}setVolume(e){this.config.volume=Math.max(0,Math.min(1,e))}setPreset(e){this.config.preset=e}getConfig(){return{...this.config}}isEnabled(){return this.config.enabled&&this.config.preset!=="none"}destroy(){this.hasAcquired&&(dr.release(),this.hasAcquired=!1)}}const ii={default:{primary:"#6366f1",secondary:"#8b5cf6",accent:"#06b6d4",glow:"#818cf8",atmosphere:"#c4b5fd",depth:"#312e81",highlight:"#e0e7ff"},emerald:{primary:"#10b981",secondary:"#34d399",accent:"#6ee7b7",glow:"#34d399",atmosphere:"#a7f3d0",depth:"#064e3b",highlight:"#d1fae5"},rose:{primary:"#f43f5e",secondary:"#fb7185",accent:"#fda4af",glow:"#fb7185",atmosphere:"#fecdd3",depth:"#881337",highlight:"#ffe4e6"},amber:{primary:"#f59e0b",secondary:"#fbbf24",accent:"#fcd34d",glow:"#fbbf24",atmosphere:"#fde68a",depth:"#78350f",highlight:"#fef3c7"},cyan:{primary:"#06b6d4",secondary:"#22d3ee",accent:"#67e8f9",glow:"#22d3ee",atmosphere:"#a5f3fc",depth:"#164e63",highlight:"#cffafe"},purple:{primary:"#9333ea",secondary:"#a855f7",accent:"#c084fc",glow:"#a855f7",atmosphere:"#d8b4fe",depth:"#581c87",highlight:"#f3e8ff"},blue:{primary:"#2563eb",secondary:"#3b82f6",accent:"#60a5fa",glow:"#3b82f6",atmosphere:"#93c5fd",depth:"#1e3a8a",highlight:"#dbeafe"}},si={indigo:{primary:"#3730a3",secondary:"#4338ca",accent:"#4f46e5",glow:"#3730a3",atmosphere:"#4338ca",depth:"#1e1b4b",highlight:"#a5b4fc"},violet:{primary:"#5b21b6",secondary:"#6d28d9",accent:"#7c3aed",glow:"#5b21b6",atmosphere:"#6d28d9",depth:"#2e1065",highlight:"#c4b5fd"},teal:{primary:"#0f766e",secondary:"#0d9488",accent:"#14b8a6",glow:"#0f766e",atmosphere:"#0d9488",depth:"#042f2e",highlight:"#5eead4"},orange:{primary:"#c2410c",secondary:"#ea580c",accent:"#f97316",glow:"#c2410c",atmosphere:"#ea580c",depth:"#431407",highlight:"#fed7aa"},blue:{primary:"#1d4ed8",secondary:"#2563eb",accent:"#3b82f6",glow:"#1d4ed8",atmosphere:"#2563eb",depth:"#1e3a8a",highlight:"#93c5fd"},pink:{primary:"#be185d",secondary:"#db2777",accent:"#ec4899",glow:"#be185d",atmosphere:"#db2777",depth:"#500724",highlight:"#f9a8d4"}};function zC(i,e="dark"){const t=e==="dark"?ii:si;return t[i]||t[Object.keys(t)[0]]}function GC(i="dark"){return Object.keys(i==="dark"?ii:si)}const ur={default:{dark:{colors:ii.default,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.indigo,glowIntensity:1.8,idleGlowMultiplier:1.2}},emerald:{dark:{colors:ii.emerald,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.teal,glowIntensity:1.8,idleGlowMultiplier:1.2}},rose:{dark:{colors:ii.rose,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.pink,glowIntensity:1.8,idleGlowMultiplier:1.2}},amber:{dark:{colors:ii.amber,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.orange,glowIntensity:1.8,idleGlowMultiplier:1.2}},cyan:{dark:{colors:ii.cyan,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.blue,glowIntensity:1.8,idleGlowMultiplier:1.2}},purple:{dark:{colors:ii.purple,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.violet,glowIntensity:1.8,idleGlowMultiplier:1.2}},blue:{dark:{colors:ii.blue,glowIntensity:1.2,idleGlowMultiplier:.6},light:{colors:si.blue,glowIntensity:1.8,idleGlowMultiplier:1.2}}},HC=Object.fromEntries(Object.entries(ur).map(([i,e])=>[i,e.dark])),WC=Object.fromEntries(Object.entries(ur).map(([i,e])=>[i,e.light]));function Mm(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function ea(i,e="auto"){const t=ur[i]||ur.default,n=e==="auto"?Mm():e;return t[n]}function qC(){return Object.keys(ur)}function wm(i,e,t="auto"){const n=ea(e,t);i.orbColors=n.colors,i.glowIntensity=n.glowIntensity,i.idleGlowMultiplier=n.idleGlowMultiplier}function jC(i,e){if(typeof window>"u")return()=>{};const t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>{const s=t.matches?"dark":"light";wm(i,e,s)};return n(),t.addEventListener("change",n),()=>{t.removeEventListener("change",n)}}var $C=Object.defineProperty,XC=Object.getOwnPropertyDescriptor,mt=(i,e,t,n)=>{for(var s=n>1?void 0:n?XC(e,t):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(n?a(e,t,s):a(s))||s);return n&&s&&$C(e,t,s),s};Y.InlineCall=class extends ts{constructor(){super(),this.callManager=new Jc,this.healthMonitor=new Zc,this.orbRenderer=null,this.audioAnalyzer=null,this.soundManager=null,this.orbContainerRef=ko(),this.animationId=null,this.pendingTimers=new Set,this.isPageVisible=!0,this.animationStartTime=0,this.intersectionObserver=null,this.isOrbInitialized=!1,this.callStatus="idle",this.microphoneEnabled=!1,this.serviceUnavailable=!1,this.buttonStartText="Try to call",this.buttonConnectingText="Connecting...",this.size=370,this.containerPadding=45,this.theme="default",this.themeMode="auto",this.orbColors={},this.glowIntensity=.8,this.idleGlowMultiplier=.4,this.morphStrength=1,this.noiseScale=1.5,this.noiseSpeed=.3,this.fresnelPower=2.5,this.rotationSpeed=.1,this.audioReactivity=3,this.audioSmoothing=.9,this.idleMorphMultiplier=.25,this.colorContrast=1.5,this.soundEnabled=!0,this.soundVolume=.25,this.soundPreset="1",this.handleAudioTrack=async e=>{const n=e.detail;if(!(!n||!this.audioAnalyzer))try{const s=new MediaStream([n]);await this.audioAnalyzer.connectStream(s)}catch(s){console.error("Failed to connect audio stream:",s)}},this.handleLocalAudioTrack=async e=>{const n=e.detail;if(!(!n||!this.audioAnalyzer))try{const s=new MediaStream([n]);await this.audioAnalyzer.connectLocalStream(s)}catch(s){console.error("Failed to connect local audio stream:",s)}},this.handleMicrophoneEnabled=()=>{this.microphoneEnabled=!0},this.handleMicrophoneDisabled=()=>{this.microphoneEnabled=!1},this.handleHealthChange=e=>{const t=e.detail;this.serviceUnavailable=t==="unhealthy"},this.handleStatusChange=e=>{var n,s,r,a,o;switch(e.detail){case"connecting":this.callStatus="connecting";break;case"connected":this.callStatus="connected",(n=this.orbRenderer)==null||n.setActive(!0),this.startRealAudioLoop(),this.scheduleTimer(()=>{var c;(c=this.soundManager)==null||c.playCallStartSound()},300),this.dispatchEvent(new Event("call-start",{bubbles:!0,composed:!0}));break;case"disconnected":this.callStatus="idle",(s=this.orbRenderer)==null||s.setActive(!1),(r=this.audioAnalyzer)==null||r.disconnect(),this.startIdleAnimation(),this.scheduleTimer(()=>{var c;(c=this.soundManager)==null||c.playCallEndSound()},150),this.dispatchEvent(new Event("call-end",{bubbles:!0,composed:!0}));break;case"error":this.callStatus="error",(a=this.orbRenderer)==null||a.setActive(!1),(o=this.audioAnalyzer)==null||o.disconnect(),this.scheduleTimer(()=>{this.callStatus==="error"&&(this.callStatus="idle",this.startIdleAnimation())},3e3);break}},this.toggleCall=async()=>{var e;this.agentId&&(this.callStatus==="idle"&&!this.healthMonitor.isHealthy||(await((e=this.soundManager)==null?void 0:e.prewarm()),this.callStatus==="idle"?(this.callStatus="connecting",await this.callManager.makeCall({agentId:this.agentId})):this.callStatus==="connected"&&this.callManager.hangUp()))},this.boundHandleVisibilityChange=this.handleVisibilityChange.bind(this)}connectedCallback(){super.connectedCallback(),document.addEventListener("visibilitychange",this.boundHandleVisibilityChange),this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl),this.soundManager=new bo({enabled:this.soundEnabled,volume:this.soundVolume,preset:this.soundPreset}),this.callManager.addEventListener("status-changed",this.handleStatusChange),this.callManager.addEventListener("audio-track",this.handleAudioTrack),this.callManager.addEventListener("local-audio-track",this.handleLocalAudioTrack),this.callManager.addEventListener("microphone-enabled",this.handleMicrophoneEnabled),this.callManager.addEventListener("microphone-disabled",this.handleMicrophoneDisabled),this.healthMonitor.serviceUrl=this.callManager.serviceUrl,this.healthMonitor.addEventListener("health-changed",this.handleHealthChange),this.healthMonitor.start()}disconnectedCallback(){var e;super.disconnectedCallback(),document.removeEventListener("visibilitychange",this.boundHandleVisibilityChange),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.clearAllTimers(),this.callManager.removeEventListener("status-changed",this.handleStatusChange),this.callManager.removeEventListener("audio-track",this.handleAudioTrack),this.callManager.removeEventListener("local-audio-track",this.handleLocalAudioTrack),this.callManager.removeEventListener("microphone-enabled",this.handleMicrophoneEnabled),this.callManager.removeEventListener("microphone-disabled",this.handleMicrophoneDisabled),this.healthMonitor.stop(),this.healthMonitor.removeEventListener("health-changed",this.handleHealthChange),this.callManager.destroy(),this.cleanupOrb(),(e=this.soundManager)==null||e.destroy(),this.soundManager=null}handleVisibilityChange(){const e=this.isPageVisible;this.isPageVisible=document.visibilityState==="visible",!this.isPageVisible&&e?this.stopAnimation():this.isPageVisible&&!e&&this.resumeAnimation()}stopAnimation(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}resumeAnimation(){this.callStatus==="idle"?this.startIdleAnimation():this.callStatus==="connected"&&this.startRealAudioLoop()}scheduleTimer(e,t){const n=setTimeout(()=>{this.pendingTimers.delete(n),e()},t);return this.pendingTimers.add(n),n}clearAllTimers(){this.pendingTimers.forEach(e=>clearTimeout(e)),this.pendingTimers.clear()}firstUpdated(){this.applyTheme(),this.setupLazyInitialization()}setupLazyInitialization(){const e=this.orbContainerRef.value;if(!e){this.initializeOrb();return}if(!("IntersectionObserver"in window)){this.initializeOrb();return}this.intersectionObserver=new IntersectionObserver(t=>{var n;for(const s of t)s.isIntersecting&&!this.isOrbInitialized&&(this.initializeOrb(),this.isOrbInitialized=!0,(n=this.intersectionObserver)==null||n.disconnect(),this.intersectionObserver=null)},{threshold:.1}),this.intersectionObserver.observe(e)}updated(e){var t,n,s;super.updated(e),e.has("agentId")&&(this.callManager.hangUp(),this.callStatus="idle"),e.has("voiceServiceUrl")&&this.voiceServiceUrl&&(this.callManager.serviceUrl=this.voiceServiceUrl,this.healthMonitor.serviceUrl=this.voiceServiceUrl),(e.has("theme")||e.has("themeMode"))&&this.applyTheme(),e.has("soundEnabled")&&((t=this.soundManager)==null||t.setEnabled(this.soundEnabled)),e.has("soundVolume")&&((n=this.soundManager)==null||n.setVolume(this.soundVolume)),e.has("soundPreset")&&((s=this.soundManager)==null||s.setPreset(this.soundPreset))}applyTheme(){if(this.theme){const e=ea(this.theme,this.themeMode);this.orbColors=e.colors,this.glowIntensity=e.glowIntensity,this.idleGlowMultiplier=e.idleGlowMultiplier,this.orbRenderer&&(this.orbRenderer.setColors(this.orbColors),this.orbRenderer.setGlowSettings(this.glowIntensity,this.idleGlowMultiplier))}}initializeOrb(){const e=this.orbContainerRef.value;e&&(this.orbRenderer=new Bd(e,{size:1,colors:this.orbColors,glowIntensity:this.glowIntensity,idleGlowMultiplier:this.idleGlowMultiplier,morphStrength:this.morphStrength,noiseScale:this.noiseScale,noiseSpeed:this.noiseSpeed,fresnelPower:this.fresnelPower,rotationSpeed:this.rotationSpeed,audioReactivity:this.audioReactivity,audioSmoothing:this.audioSmoothing,idleMorphMultiplier:this.idleMorphMultiplier,colorContrast:this.colorContrast}),this.audioAnalyzer=new Vd,this.orbRenderer.start(),this.startIdleAnimation())}cleanupOrb(){var e,t;this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),(e=this.audioAnalyzer)==null||e.disconnect(),(t=this.orbRenderer)==null||t.destroy(),this.audioAnalyzer=null,this.orbRenderer=null}startIdleAnimation(){if(this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),!this.isPageVisible)return;this.animationStartTime=performance.now();const e=t=>{if(this.callStatus!=="idle"||!this.orbRenderer||!this.isPageVisible){this.animationId=null;return}const n=(t-this.animationStartTime)/1e3,s=Math.sin(n*.5)*.15+.15,r=Math.sin(n*.7+1)*.12+.12,a=Math.sin(n*.9+2)*.08+.08,o=(s+r+a)/3;this.orbRenderer.setSimulatedAudio(s,r,a,o),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}startRealAudioLoop(){if(this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null),!this.isPageVisible)return;const e=()=>{var n;if(this.callStatus!=="connected"||!this.orbRenderer||!this.isPageVisible){this.animationId=null;return}const t=(n=this.audioAnalyzer)==null?void 0:n.getAudioData();t&&this.orbRenderer.updateAudio(t),this.animationId=requestAnimationFrame(e)};this.animationId=requestAnimationFrame(e)}getButtonIcon(){return this.callStatus==="connecting"?Gt`
4472
4472
  <svg width="16" height="16" viewBox="0 0 16 16" fill="none" class="hanc-spinner">
4473
4473
  <circle
4474
4474
  cx="8"
@@ -41,6 +41,7 @@ export declare class OrbRenderer {
41
41
  private currentRotation;
42
42
  private audioValues;
43
43
  private readonly canvasPadding;
44
+ private resizeObserver;
44
45
  private resizeTimeoutId;
45
46
  private isContextLost;
46
47
  private boundHandleContextLost;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hanc-webrtc-widgets",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "type": "module",
5
5
  "main": "dist/hanc-webrtc-widgets.umd.js",
6
6
  "module": "dist/hanc-webrtc-widgets.es.js",