hanc-webrtc-widgets 2.2.9 → 2.2.11
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.
|
@@ -39070,7 +39070,7 @@ var IE = Object.defineProperty, DE = Object.getOwnPropertyDescriptor, _t = (i, e
|
|
|
39070
39070
|
};
|
|
39071
39071
|
let dt = class extends gs {
|
|
39072
39072
|
constructor() {
|
|
39073
|
-
super(), this.callManager = new wd(), this.healthMonitor = new Ad(), this.orbRenderer = null, this.audioAnalyzer = null, this.soundManager = null, this.orbContainerRef = ad(), this.animationId = null, this.pendingTimers = /* @__PURE__ */ 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 = 0.8, this.idleGlowMultiplier = 0.4, this.morphStrength = 1, this.noiseScale = 1.5, this.noiseSpeed = 0.3, this.fresnelPower = 2.5, this.rotationSpeed = 0.1, this.audioReactivity = 3, this.audioSmoothing = 0.9, this.idleMorphMultiplier = 0.25, this.colorContrast = 1.5, this.soundEnabled = !0, this.soundVolume = 0.25, this.soundPreset = "1", this.handleAudioTrack = async (i) => {
|
|
39073
|
+
super(), this.callManager = new wd(), this.healthMonitor = new Ad(), this.orbRenderer = null, this.audioAnalyzer = null, this.soundManager = null, this.orbContainerRef = ad(), this.animationId = null, this.pendingTimers = /* @__PURE__ */ new Set(), this.isPageVisible = !0, this.animationStartTime = 0, this.intersectionObserver = null, this.isOrbInitialized = !1, this.intersectionTimeoutId = null, 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 = 0.8, this.idleGlowMultiplier = 0.4, this.morphStrength = 1, this.noiseScale = 1.5, this.noiseSpeed = 0.3, this.fresnelPower = 2.5, this.rotationSpeed = 0.1, this.audioReactivity = 3, this.audioSmoothing = 0.9, this.idleMorphMultiplier = 0.25, this.colorContrast = 1.5, this.soundEnabled = !0, this.soundVolume = 0.25, this.soundPreset = "1", this.handleAudioTrack = async (i) => {
|
|
39074
39074
|
const t = i.detail;
|
|
39075
39075
|
if (!(!t || !this.audioAnalyzer))
|
|
39076
39076
|
try {
|
|
@@ -39200,12 +39200,14 @@ let dt = class extends gs {
|
|
|
39200
39200
|
}
|
|
39201
39201
|
this.intersectionObserver = new IntersectionObserver(
|
|
39202
39202
|
(e) => {
|
|
39203
|
-
|
|
39204
|
-
|
|
39205
|
-
|
|
39203
|
+
for (const t of e)
|
|
39204
|
+
t.isIntersecting && !this.isOrbInitialized ? this.intersectionTimeoutId || (this.intersectionTimeoutId = setTimeout(() => {
|
|
39205
|
+
var n;
|
|
39206
|
+
this.initializeOrb(), this.isOrbInitialized = !0, (n = this.intersectionObserver) == null || n.disconnect(), this.intersectionObserver = null, this.intersectionTimeoutId = null;
|
|
39207
|
+
}, 200), this.pendingTimers.add(this.intersectionTimeoutId)) : !t.isIntersecting && this.intersectionTimeoutId && (clearTimeout(this.intersectionTimeoutId), this.pendingTimers.delete(this.intersectionTimeoutId), this.intersectionTimeoutId = null);
|
|
39206
39208
|
},
|
|
39207
|
-
{ threshold: 0.
|
|
39208
|
-
// Trigger when
|
|
39209
|
+
{ threshold: 0.5 }
|
|
39210
|
+
// Trigger when 50% visible
|
|
39209
39211
|
), this.intersectionObserver.observe(i);
|
|
39210
39212
|
}
|
|
39211
39213
|
updated(i) {
|
|
@@ -39822,7 +39824,7 @@ let ut = class extends gs {
|
|
|
39822
39824
|
for (const n of e)
|
|
39823
39825
|
n.isIntersecting && !this.isOrbInitialized && (this.initializeOrb(), this.isOrbInitialized = !0, (t = this.intersectionObserver) == null || t.disconnect(), this.intersectionObserver = null);
|
|
39824
39826
|
},
|
|
39825
|
-
{ threshold: 0.
|
|
39827
|
+
{ threshold: 0.5 }
|
|
39826
39828
|
), this.intersectionObserver.observe(i);
|
|
39827
39829
|
}
|
|
39828
39830
|
updated(i) {
|
|
@@ -40423,7 +40425,7 @@ let ht = class extends gs {
|
|
|
40423
40425
|
for (const n of e)
|
|
40424
40426
|
n.isIntersecting && !this.isOrbInitialized && (this.initializeOrb(), this.isOrbInitialized = !0, (t = this.intersectionObserver) == null || t.disconnect(), this.intersectionObserver = null);
|
|
40425
40427
|
},
|
|
40426
|
-
{ threshold: 0.
|
|
40428
|
+
{ threshold: 0.5 }
|
|
40427
40429
|
), this.intersectionObserver.observe(i);
|
|
40428
40430
|
}
|
|
40429
40431
|
updated(i) {
|
|
@@ -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.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`
|
|
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.intersectionTimeoutId=null,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=>{for(const n of t)n.isIntersecting&&!this.isOrbInitialized?this.intersectionTimeoutId||(this.intersectionTimeoutId=setTimeout(()=>{var s;this.initializeOrb(),this.isOrbInitialized=!0,(s=this.intersectionObserver)==null||s.disconnect(),this.intersectionObserver=null,this.intersectionTimeoutId=null},200),this.pendingTimers.add(this.intersectionTimeoutId)):!n.isIntersecting&&this.intersectionTimeoutId&&(clearTimeout(this.intersectionTimeoutId),this.pendingTimers.delete(this.intersectionTimeoutId),this.intersectionTimeoutId=null)},{threshold:.5}),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"
|
|
@@ -4781,7 +4781,7 @@ void main() {
|
|
|
4781
4781
|
display: inline-block;
|
|
4782
4782
|
contain: layout style;
|
|
4783
4783
|
}
|
|
4784
|
-
`,mt([Se({type:String,attribute:"agent-id"})],Y.InlineCall.prototype,"agentId",2),mt([Se({type:String,attribute:"voice-service-url"})],Y.InlineCall.prototype,"voiceServiceUrl",2),mt([ai()],Y.InlineCall.prototype,"callStatus",2),mt([ai()],Y.InlineCall.prototype,"microphoneEnabled",2),mt([ai()],Y.InlineCall.prototype,"serviceUnavailable",2),mt([Se({type:String,attribute:"button-start-text"})],Y.InlineCall.prototype,"buttonStartText",2),mt([Se({type:String,attribute:"button-connecting-text"})],Y.InlineCall.prototype,"buttonConnectingText",2),mt([Se({type:Number,attribute:"size"})],Y.InlineCall.prototype,"size",2),mt([Se({type:Number,attribute:"container-padding"})],Y.InlineCall.prototype,"containerPadding",2),mt([Se({type:String,attribute:"theme",reflect:!0})],Y.InlineCall.prototype,"theme",2),mt([Se({type:String,attribute:"theme-mode"})],Y.InlineCall.prototype,"themeMode",2),mt([Se({type:Object,attribute:"orb-colors"})],Y.InlineCall.prototype,"orbColors",2),mt([Se({type:Number,attribute:"glow-intensity"})],Y.InlineCall.prototype,"glowIntensity",2),mt([Se({type:Number,attribute:"idle-glow-multiplier"})],Y.InlineCall.prototype,"idleGlowMultiplier",2),mt([Se({type:Number,attribute:"morph-strength"})],Y.InlineCall.prototype,"morphStrength",2),mt([Se({type:Number,attribute:"noise-scale"})],Y.InlineCall.prototype,"noiseScale",2),mt([Se({type:Number,attribute:"noise-speed"})],Y.InlineCall.prototype,"noiseSpeed",2),mt([Se({type:Number,attribute:"fresnel-power"})],Y.InlineCall.prototype,"fresnelPower",2),mt([Se({type:Number,attribute:"rotation-speed"})],Y.InlineCall.prototype,"rotationSpeed",2),mt([Se({type:Number,attribute:"audio-reactivity"})],Y.InlineCall.prototype,"audioReactivity",2),mt([Se({type:Number,attribute:"audio-smoothing"})],Y.InlineCall.prototype,"audioSmoothing",2),mt([Se({type:Number,attribute:"idle-morph-multiplier"})],Y.InlineCall.prototype,"idleMorphMultiplier",2),mt([Se({type:Number,attribute:"color-contrast"})],Y.InlineCall.prototype,"colorContrast",2),mt([Se({type:Boolean,attribute:"sound-enabled"})],Y.InlineCall.prototype,"soundEnabled",2),mt([Se({type:Number,attribute:"sound-volume"})],Y.InlineCall.prototype,"soundVolume",2),mt([Se({type:String,attribute:"sound-preset"})],Y.InlineCall.prototype,"soundPreset",2),Y.InlineCall=mt([Po("hanc-ai-inline-call")],Y.InlineCall);var KC=Object.defineProperty,YC=Object.getOwnPropertyDescriptor,gt=(i,e,t,n)=>{for(var s=n>1?void 0:n?YC(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&&KC(e,t,s),s};Y.FloatingCall=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="Call",this.buttonConnectingText="Connecting...",this.position="bottom-right",this.size=120,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`
|
|
4784
|
+
`,mt([Se({type:String,attribute:"agent-id"})],Y.InlineCall.prototype,"agentId",2),mt([Se({type:String,attribute:"voice-service-url"})],Y.InlineCall.prototype,"voiceServiceUrl",2),mt([ai()],Y.InlineCall.prototype,"callStatus",2),mt([ai()],Y.InlineCall.prototype,"microphoneEnabled",2),mt([ai()],Y.InlineCall.prototype,"serviceUnavailable",2),mt([Se({type:String,attribute:"button-start-text"})],Y.InlineCall.prototype,"buttonStartText",2),mt([Se({type:String,attribute:"button-connecting-text"})],Y.InlineCall.prototype,"buttonConnectingText",2),mt([Se({type:Number,attribute:"size"})],Y.InlineCall.prototype,"size",2),mt([Se({type:Number,attribute:"container-padding"})],Y.InlineCall.prototype,"containerPadding",2),mt([Se({type:String,attribute:"theme",reflect:!0})],Y.InlineCall.prototype,"theme",2),mt([Se({type:String,attribute:"theme-mode"})],Y.InlineCall.prototype,"themeMode",2),mt([Se({type:Object,attribute:"orb-colors"})],Y.InlineCall.prototype,"orbColors",2),mt([Se({type:Number,attribute:"glow-intensity"})],Y.InlineCall.prototype,"glowIntensity",2),mt([Se({type:Number,attribute:"idle-glow-multiplier"})],Y.InlineCall.prototype,"idleGlowMultiplier",2),mt([Se({type:Number,attribute:"morph-strength"})],Y.InlineCall.prototype,"morphStrength",2),mt([Se({type:Number,attribute:"noise-scale"})],Y.InlineCall.prototype,"noiseScale",2),mt([Se({type:Number,attribute:"noise-speed"})],Y.InlineCall.prototype,"noiseSpeed",2),mt([Se({type:Number,attribute:"fresnel-power"})],Y.InlineCall.prototype,"fresnelPower",2),mt([Se({type:Number,attribute:"rotation-speed"})],Y.InlineCall.prototype,"rotationSpeed",2),mt([Se({type:Number,attribute:"audio-reactivity"})],Y.InlineCall.prototype,"audioReactivity",2),mt([Se({type:Number,attribute:"audio-smoothing"})],Y.InlineCall.prototype,"audioSmoothing",2),mt([Se({type:Number,attribute:"idle-morph-multiplier"})],Y.InlineCall.prototype,"idleMorphMultiplier",2),mt([Se({type:Number,attribute:"color-contrast"})],Y.InlineCall.prototype,"colorContrast",2),mt([Se({type:Boolean,attribute:"sound-enabled"})],Y.InlineCall.prototype,"soundEnabled",2),mt([Se({type:Number,attribute:"sound-volume"})],Y.InlineCall.prototype,"soundVolume",2),mt([Se({type:String,attribute:"sound-preset"})],Y.InlineCall.prototype,"soundPreset",2),Y.InlineCall=mt([Po("hanc-ai-inline-call")],Y.InlineCall);var KC=Object.defineProperty,YC=Object.getOwnPropertyDescriptor,gt=(i,e,t,n)=>{for(var s=n>1?void 0:n?YC(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&&KC(e,t,s),s};Y.FloatingCall=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="Call",this.buttonConnectingText="Connecting...",this.position="bottom-right",this.size=120,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:.5}),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`
|
|
4785
4785
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" class="hanc-spinner">
|
|
4786
4786
|
<circle
|
|
4787
4787
|
cx="8"
|
|
@@ -5079,7 +5079,7 @@ void main() {
|
|
|
5079
5079
|
:host {
|
|
5080
5080
|
display: block;
|
|
5081
5081
|
}
|
|
5082
|
-
`,gt([Se({type:String,attribute:"agent-id"})],Y.FloatingCall.prototype,"agentId",2),gt([Se({type:String,attribute:"voice-service-url"})],Y.FloatingCall.prototype,"voiceServiceUrl",2),gt([ai()],Y.FloatingCall.prototype,"callStatus",2),gt([ai()],Y.FloatingCall.prototype,"microphoneEnabled",2),gt([ai()],Y.FloatingCall.prototype,"serviceUnavailable",2),gt([Se({type:String,attribute:"button-start-text"})],Y.FloatingCall.prototype,"buttonStartText",2),gt([Se({type:String,attribute:"button-connecting-text"})],Y.FloatingCall.prototype,"buttonConnectingText",2),gt([Se({type:String,attribute:"position"})],Y.FloatingCall.prototype,"position",2),gt([Se({type:Number,attribute:"size"})],Y.FloatingCall.prototype,"size",2),gt([Se({type:String,attribute:"theme"})],Y.FloatingCall.prototype,"theme",2),gt([Se({type:String,attribute:"theme-mode"})],Y.FloatingCall.prototype,"themeMode",2),gt([Se({type:Object,attribute:"orb-colors"})],Y.FloatingCall.prototype,"orbColors",2),gt([Se({type:Number,attribute:"glow-intensity"})],Y.FloatingCall.prototype,"glowIntensity",2),gt([Se({type:Number,attribute:"idle-glow-multiplier"})],Y.FloatingCall.prototype,"idleGlowMultiplier",2),gt([Se({type:Number,attribute:"morph-strength"})],Y.FloatingCall.prototype,"morphStrength",2),gt([Se({type:Number,attribute:"noise-scale"})],Y.FloatingCall.prototype,"noiseScale",2),gt([Se({type:Number,attribute:"noise-speed"})],Y.FloatingCall.prototype,"noiseSpeed",2),gt([Se({type:Number,attribute:"fresnel-power"})],Y.FloatingCall.prototype,"fresnelPower",2),gt([Se({type:Number,attribute:"rotation-speed"})],Y.FloatingCall.prototype,"rotationSpeed",2),gt([Se({type:Number,attribute:"audio-reactivity"})],Y.FloatingCall.prototype,"audioReactivity",2),gt([Se({type:Number,attribute:"audio-smoothing"})],Y.FloatingCall.prototype,"audioSmoothing",2),gt([Se({type:Number,attribute:"idle-morph-multiplier"})],Y.FloatingCall.prototype,"idleMorphMultiplier",2),gt([Se({type:Number,attribute:"color-contrast"})],Y.FloatingCall.prototype,"colorContrast",2),gt([Se({type:Boolean,attribute:"sound-enabled"})],Y.FloatingCall.prototype,"soundEnabled",2),gt([Se({type:Number,attribute:"sound-volume"})],Y.FloatingCall.prototype,"soundVolume",2),gt([Se({type:String,attribute:"sound-preset"})],Y.FloatingCall.prototype,"soundPreset",2),Y.FloatingCall=gt([Po("hanc-ai-floating-call")],Y.FloatingCall);var JC=Object.defineProperty,ZC=Object.getOwnPropertyDescriptor,vt=(i,e,t,n)=>{for(var s=n>1?void 0:n?ZC(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&&JC(e,t,s),s};Y.PillCall=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="Talk to AI Agent",this.buttonConnectingText="Connecting...",this.buttonEndText="End call",this.orbSize=48,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`
|
|
5082
|
+
`,gt([Se({type:String,attribute:"agent-id"})],Y.FloatingCall.prototype,"agentId",2),gt([Se({type:String,attribute:"voice-service-url"})],Y.FloatingCall.prototype,"voiceServiceUrl",2),gt([ai()],Y.FloatingCall.prototype,"callStatus",2),gt([ai()],Y.FloatingCall.prototype,"microphoneEnabled",2),gt([ai()],Y.FloatingCall.prototype,"serviceUnavailable",2),gt([Se({type:String,attribute:"button-start-text"})],Y.FloatingCall.prototype,"buttonStartText",2),gt([Se({type:String,attribute:"button-connecting-text"})],Y.FloatingCall.prototype,"buttonConnectingText",2),gt([Se({type:String,attribute:"position"})],Y.FloatingCall.prototype,"position",2),gt([Se({type:Number,attribute:"size"})],Y.FloatingCall.prototype,"size",2),gt([Se({type:String,attribute:"theme"})],Y.FloatingCall.prototype,"theme",2),gt([Se({type:String,attribute:"theme-mode"})],Y.FloatingCall.prototype,"themeMode",2),gt([Se({type:Object,attribute:"orb-colors"})],Y.FloatingCall.prototype,"orbColors",2),gt([Se({type:Number,attribute:"glow-intensity"})],Y.FloatingCall.prototype,"glowIntensity",2),gt([Se({type:Number,attribute:"idle-glow-multiplier"})],Y.FloatingCall.prototype,"idleGlowMultiplier",2),gt([Se({type:Number,attribute:"morph-strength"})],Y.FloatingCall.prototype,"morphStrength",2),gt([Se({type:Number,attribute:"noise-scale"})],Y.FloatingCall.prototype,"noiseScale",2),gt([Se({type:Number,attribute:"noise-speed"})],Y.FloatingCall.prototype,"noiseSpeed",2),gt([Se({type:Number,attribute:"fresnel-power"})],Y.FloatingCall.prototype,"fresnelPower",2),gt([Se({type:Number,attribute:"rotation-speed"})],Y.FloatingCall.prototype,"rotationSpeed",2),gt([Se({type:Number,attribute:"audio-reactivity"})],Y.FloatingCall.prototype,"audioReactivity",2),gt([Se({type:Number,attribute:"audio-smoothing"})],Y.FloatingCall.prototype,"audioSmoothing",2),gt([Se({type:Number,attribute:"idle-morph-multiplier"})],Y.FloatingCall.prototype,"idleMorphMultiplier",2),gt([Se({type:Number,attribute:"color-contrast"})],Y.FloatingCall.prototype,"colorContrast",2),gt([Se({type:Boolean,attribute:"sound-enabled"})],Y.FloatingCall.prototype,"soundEnabled",2),gt([Se({type:Number,attribute:"sound-volume"})],Y.FloatingCall.prototype,"soundVolume",2),gt([Se({type:String,attribute:"sound-preset"})],Y.FloatingCall.prototype,"soundPreset",2),Y.FloatingCall=gt([Po("hanc-ai-floating-call")],Y.FloatingCall);var JC=Object.defineProperty,ZC=Object.getOwnPropertyDescriptor,vt=(i,e,t,n)=>{for(var s=n>1?void 0:n?ZC(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&&JC(e,t,s),s};Y.PillCall=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="Talk to AI Agent",this.buttonConnectingText="Connecting...",this.buttonEndText="End call",this.orbSize=48,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:.5}),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`
|
|
5083
5083
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" class="hanc-spinner">
|
|
5084
5084
|
<circle
|
|
5085
5085
|
cx="8"
|