@telnyx/ai-agent-widget 0.18.0 → 0.19.0

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.
@@ -13,7 +13,7 @@
13
13
  * @version 4.5.1
14
14
  * @author Henrique Avila Vianna <hvianna@gmail.com> <https://henriquevianna.com>
15
15
  * @license AGPL-3.0-or-later
16
- */const $g="4.5.1",Tr=Math.PI,sn=2*Tr,Er=Tr/2,eu=8.17579892,nu="dual-combined",Ri="dual-horizontal",me="single",oe="dual-vertical",iu="bar-index",su="bar-level",Ii="gradient",ru=60,ou="click",Ug="fullscreenchange",au="resize",Hg="#111",lu="",cu="A",uu="B",du="C",hu="D",fu="468",Pi="sans-serif",Gg="#0f0",Wg="#7f7f7f22",rn=10,pu="create",mu="fschange",zg="lores",qg=au,Ar="user",Kg="#000c",gu="#fff",Xg="#4f4",vu="#888",Yg="#555",Rr="bark",Un="linear",on="log",Ir="mel",_u=["#a35","#c66","#e94","#ed0","#9d5","#4d8","#2cb","#0bc","#09c","#36b"],yu=[["classic",{colorStops:["red",{color:"yellow",level:.85,pos:.6},{color:"lime",level:.475}]}],["prism",{colorStops:_u}],["rainbow",{dir:"h",colorStops:["#817",..._u,"#639"]}],["orangered",{bgColor:"#3e2f29",colorStops:["OrangeRed"]}],["steelblue",{bgColor:"#222c35",colorStops:["SteelBlue"]}]],Hn={alphaBars:!1,ansiBands:!1,barSpace:.1,bgAlpha:.7,channelLayout:me,colorMode:Ii,fadePeaks:!1,fftSize:8192,fillAlpha:1,frequencyScale:on,gradient:yu[0][0],gravity:3.8,height:void 0,ledBars:!1,linearAmplitude:!1,linearBoost:1,lineWidth:0,loRes:!1,lumiBars:!1,maxDecibels:-25,maxFPS:0,maxFreq:22e3,minDecibels:-85,minFreq:20,mirror:0,mode:0,noteLabels:!1,outlineBars:!1,overlay:!1,peakFadeTime:750,peakHoldTime:500,peakLine:!1,radial:!1,radialInvert:!1,radius:.3,reflexAlpha:.15,reflexBright:1,reflexFit:!0,reflexRatio:0,roundBars:!1,showBgColor:!0,showFPS:!1,showPeaks:!0,showScaleX:!0,showScaleY:!1,smoothing:.5,spinSpeed:0,splitGradient:!1,start:!0,trueLeds:!1,useCanvas:!0,volume:1,weightingFilter:lu,width:void 0},Zg=["ERR_AUDIO_CONTEXT_FAIL","Could not create audio context. Web Audio API not supported?"],Jg=["ERR_INVALID_AUDIO_CONTEXT","Provided audio context is not valid"],Qg=["ERR_UNKNOWN_GRADIENT","Unknown gradient"],Pr=["ERR_FREQUENCY_TOO_LOW","Frequency values must be >= 1"],tv=["ERR_INVALID_MODE","Invalid mode"],ev=["ERR_REFLEX_OUT_OF_RANGE","Reflex ratio must be >= 0 and < 1"],nv=["ERR_INVALID_AUDIO_SOURCE","Audio source must be an instance of HTMLMediaElement or AudioNode"],iv=["ERR_GRADIENT_INVALID_NAME","Gradient name must be a non-empty string"],sv=["ERR_GRADIENT_NOT_AN_OBJECT","Gradient options must be an object"],rv=["ERR_GRADIENT_MISSING_COLOR","Gradient colorStops must be a non-empty array"];class Wt extends Error{constructor(t,n){const[i,s]=t;super(s+(n!==void 0?`: ${n}`:"")),this.name="AudioMotionError",this.code=i}}const bu=(e,t)=>console.warn(`${e} is deprecated. Use ${t} instead.`),wu=e=>{for(const t in e)return!1;return!0},Mi=(e,t,n="toLowerCase")=>t[Math.max(0,t.indexOf((""+e)[n]()))],ov=(e,t,n,i,s)=>t+(i-t)*(s-e)/(n-e);Array.prototype.findLastIndex||(Array.prototype.findLastIndex=function(e){let t=this.length;for(;t-- >0;)if(e(this[t]))return t;return-1});class av{constructor(t,n={}){this._ready=!1,this._aux={},this._canvasGradients=[],this._destroyed=!1,this._energy={val:0,peak:0,hold:0},this._flg={},this._fps=0,this._gradients={},this._last=0,this._outNodes=[],this._ownContext=!1,this._selectedGrads=[],this._sources=[],t instanceof Element||(wu(n)&&!wu(t)&&(n=t),t=null),this._ownCanvas=!(n.canvas instanceof HTMLCanvasElement);const i=this._ownCanvas?document.createElement("canvas"):n.canvas;i.style="max-width: 100%;",this._ctx=i.getContext("2d");for(const[u,p]of yu)this.registerGradient(u,p);this._container=t||!this._ownCanvas&&i.parentElement||document.body,this._defaultWidth=this._container.clientWidth||640,this._defaultHeight=this._container.clientHeight||270;let s;if(!(n.source&&(s=n.source.context))){if(!(s=n.audioCtx))try{s=new(window.AudioContext||window.webkitAudioContext),this._ownContext=!0}catch{throw new Wt(Zg)}}if(!s.createGain)throw new Wt(Jg);const o=this._analyzer=[s.createAnalyser(),s.createAnalyser()],r=this._splitter=s.createChannelSplitter(2),a=this._merger=s.createChannelMerger(2);this._input=s.createGain(),this._output=s.createGain(),n.source&&this.connectInput(n.source);for(const u of[0,1])r.connect(o[u],u);a.connect(this._output),n.connectSpeakers!==!1&&this.connectOutput();for(const u of["_scaleX","_scaleR"])this[u]=document.createElement("canvas").getContext("2d");this._fsEl=n.fsElement||i;const l=()=>{this._fsTimeout||(this._fsTimeout=window.setTimeout(()=>{this._fsChanging||(this._setCanvas(qg),this._fsTimeout=0)},ru))};window.ResizeObserver&&(this._observer=new ResizeObserver(l),this._observer.observe(this._container)),this._controller=new AbortController;const c=this._controller.signal;window.addEventListener(au,l,{signal:c}),i.addEventListener(Ug,()=>{this._fsChanging=!0,this._fsTimeout&&window.clearTimeout(this._fsTimeout),this._setCanvas(mu),this._fsTimeout=window.setTimeout(()=>{this._fsChanging=!1,this._fsTimeout=0},ru)},{signal:c});const d=()=>{s.state=="suspended"&&s.resume().then(()=>window.removeEventListener(ou,d))};window.addEventListener(ou,d),document.addEventListener("visibilitychange",()=>{document.visibilityState!="hidden"&&(this._frames=0,this._time=performance.now())},{signal:c}),this._setProps(n,!0),this.useCanvas&&this._ownCanvas&&this._container.appendChild(i),this._ready=!0,this._setCanvas(pu)}get alphaBars(){return this._alphaBars}set alphaBars(t){this._alphaBars=!!t,this._calcBars()}get ansiBands(){return this._ansiBands}set ansiBands(t){this._ansiBands=!!t,this._calcBars()}get barSpace(){return this._barSpace}set barSpace(t){this._barSpace=+t||0,this._calcBars()}get channelLayout(){return this._chLayout}set channelLayout(t){this._chLayout=Mi(t,[me,Ri,oe,nu]),this._input.disconnect(),this._input.connect(this._chLayout!=me?this._splitter:this._analyzer[0]),this._analyzer[0].disconnect(),this._outNodes.length&&this._analyzer[0].connect(this._chLayout!=me?this._merger:this._output),this._calcBars(),this._makeGrad()}get colorMode(){return this._colorMode}set colorMode(t){this._colorMode=Mi(t,[Ii,iu,su])}get fadePeaks(){return this._fadePeaks}set fadePeaks(t){this._fadePeaks=!!t}get fftSize(){return this._analyzer[0].fftSize}set fftSize(t){for(const i of[0,1])this._analyzer[i].fftSize=t;const n=this._analyzer[0].frequencyBinCount;this._fftData=[new Float32Array(n),new Float32Array(n)],this._calcBars()}get frequencyScale(){return this._frequencyScale}set frequencyScale(t){this._frequencyScale=Mi(t,[on,Rr,Ir,Un]),this._calcBars()}get gradient(){return this._selectedGrads[0]}set gradient(t){this._setGradient(t)}get gradientLeft(){return this._selectedGrads[0]}set gradientLeft(t){this._setGradient(t,0)}get gradientRight(){return this._selectedGrads[1]}set gradientRight(t){this._setGradient(t,1)}get gravity(){return this._gravity}set gravity(t){this._gravity=t>0?+t:this._gravity||Hn.gravity}get height(){return this._height}set height(t){this._height=t,this._setCanvas(Ar)}get ledBars(){return this._showLeds}set ledBars(t){this._showLeds=!!t,this._calcBars()}get linearAmplitude(){return this._linearAmplitude}set linearAmplitude(t){this._linearAmplitude=!!t}get linearBoost(){return this._linearBoost}set linearBoost(t){this._linearBoost=t>=1?+t:1}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=+t||0}get loRes(){return this._loRes}set loRes(t){this._loRes=!!t,this._setCanvas(zg)}get lumiBars(){return this._lumiBars}set lumiBars(t){this._lumiBars=!!t,this._calcBars(),this._makeGrad()}get maxDecibels(){return this._analyzer[0].maxDecibels}set maxDecibels(t){for(const n of[0,1])this._analyzer[n].maxDecibels=t}get maxFPS(){return this._maxFPS}set maxFPS(t){this._maxFPS=t<0?0:+t||0}get maxFreq(){return this._maxFreq}set maxFreq(t){if(t<1)throw new Wt(Pr);this._maxFreq=Math.min(t,this.audioCtx.sampleRate/2),this._calcBars()}get minDecibels(){return this._analyzer[0].minDecibels}set minDecibels(t){for(const n of[0,1])this._analyzer[n].minDecibels=t}get minFreq(){return this._minFreq}set minFreq(t){if(t<1)throw new Wt(Pr);this._minFreq=+t,this._calcBars()}get mirror(){return this._mirror}set mirror(t){this._mirror=Math.sign(t)|0,this._calcBars(),this._makeGrad()}get mode(){return this._mode}set mode(t){const n=t|0;if(n>=0&&n<=10&&n!=9)this._mode=n,this._calcBars(),this._makeGrad();else throw new Wt(tv,t)}get noteLabels(){return this._noteLabels}set noteLabels(t){this._noteLabels=!!t,this._createScales()}get outlineBars(){return this._outlineBars}set outlineBars(t){this._outlineBars=!!t,this._calcBars()}get peakFadeTime(){return this._peakFadeTime}set peakFadeTime(t){this._peakFadeTime=t>=0?+t:this._peakFadeTime||Hn.peakFadeTime}get peakHoldTime(){return this._peakHoldTime}set peakHoldTime(t){this._peakHoldTime=+t||0}get peakLine(){return this._peakLine}set peakLine(t){this._peakLine=!!t}get radial(){return this._radial}set radial(t){this._radial=!!t,this._calcBars(),this._makeGrad()}get radialInvert(){return this._radialInvert}set radialInvert(t){this._radialInvert=!!t,this._calcBars(),this._makeGrad()}get radius(){return this._radius}set radius(t){this._radius=+t||0,this._calcBars(),this._makeGrad()}get reflexRatio(){return this._reflexRatio}set reflexRatio(t){if(t=+t||0,t<0||t>=1)throw new Wt(ev);this._reflexRatio=t,this._calcBars(),this._makeGrad()}get roundBars(){return this._roundBars}set roundBars(t){this._roundBars=!!t,this._calcBars()}get smoothing(){return this._analyzer[0].smoothingTimeConstant}set smoothing(t){for(const n of[0,1])this._analyzer[n].smoothingTimeConstant=t}get spinSpeed(){return this._spinSpeed}set spinSpeed(t){t=+t||0,(this._spinSpeed===void 0||t==0)&&(this._spinAngle=-Er),this._spinSpeed=t}get splitGradient(){return this._splitGradient}set splitGradient(t){this._splitGradient=!!t,this._makeGrad()}get stereo(){return bu("stereo","channelLayout"),this._chLayout!=me}set stereo(t){bu("stereo","channelLayout"),this.channelLayout=t?oe:me}get trueLeds(){return this._trueLeds}set trueLeds(t){this._trueLeds=!!t}get volume(){return this._output.gain.value}set volume(t){this._output.gain.value=t}get weightingFilter(){return this._weightingFilter}set weightingFilter(t){this._weightingFilter=Mi(t,[lu,cu,uu,du,hu,fu],"toUpperCase")}get width(){return this._width}set width(t){this._width=t,this._setCanvas(Ar)}get audioCtx(){return this._input.context}get canvas(){return this._ctx.canvas}get canvasCtx(){return this._ctx}get connectedSources(){return this._sources}get connectedTo(){return this._outNodes}get fps(){return this._fps}get fsHeight(){return this._fsHeight}get fsWidth(){return this._fsWidth}get isAlphaBars(){return this._flg.isAlpha}get isBandsMode(){return this._flg.isBands}get isDestroyed(){return this._destroyed}get isFullscreen(){return this._fsEl&&(document.fullscreenElement||document.webkitFullscreenElement)===this._fsEl}get isLedBars(){return this._flg.isLeds}get isLumiBars(){return this._flg.isLumi}get isOctaveBands(){return this._flg.isOctaves}get isOn(){return!!this._runId}get isOutlineBars(){return this._flg.isOutline}get pixelRatio(){return this._pixelRatio}get isRoundBars(){return this._flg.isRound}static get version(){return $g}connectInput(t){const n=t instanceof HTMLMediaElement;if(!(n||t.connect))throw new Wt(nv);const i=n?this.audioCtx.createMediaElementSource(t):t;return this._sources.includes(i)||(i.connect(this._input),this._sources.push(i)),i}connectOutput(t=this.audioCtx.destination){if(!this._outNodes.includes(t)&&(this._output.connect(t),this._outNodes.push(t),this._outNodes.length==1))for(const n of[0,1])this._analyzer[n].connect(this._chLayout==me&&!n?this._output:this._merger,0,n)}destroy(){if(!this._ready)return;const{audioCtx:t,canvas:n,_controller:i,_input:s,_merger:o,_observer:r,_ownCanvas:a,_ownContext:l,_splitter:c}=this;this._destroyed=!0,this._ready=!1,this.stop(),i.abort(),r&&r.disconnect(),this.onCanvasResize=null,this.onCanvasDraw=null,this._fsEl=null,this.disconnectInput(),this.disconnectOutput(),s.disconnect(),c.disconnect(),o.disconnect(),l&&t.close(),a&&n.remove(),this._calcBars()}disconnectInput(t,n){t?Array.isArray(t)||(t=[t]):t=Array.from(this._sources);for(const i of t){const s=this._sources.indexOf(i);if(n&&i.mediaStream)for(const o of i.mediaStream.getAudioTracks())o.stop();s>=0&&(i.disconnect(this._input),this._sources.splice(s,1))}}disconnectOutput(t){if(!(t&&!this._outNodes.includes(t))&&(this._output.disconnect(t),this._outNodes=t?this._outNodes.filter(n=>n!==t):[],this._outNodes.length==0))for(const n of[0,1])this._analyzer[n].disconnect()}getBars(){return Array.from(this._bars,({posX:t,freq:n,freqLo:i,freqHi:s,hold:o,peak:r,value:a})=>({posX:t,freq:n,freqLo:i,freqHi:s,hold:o,peak:r,value:a}))}getEnergy(t,n){if(t===void 0)return this._energy.val;if(t!=+t){if(t=="peak")return this._energy.peak;const a={bass:[20,250],lowMid:[250,500],mid:[500,2e3],highMid:[2e3,4e3],treble:[4e3,16e3]};if(!a[t])return null;[t,n]=a[t]}const i=this._freqToBin(t),s=n?this._freqToBin(n):i,o=this._chLayout==me?1:2;let r=0;for(let a=0;a<o;a++)for(let l=i;l<=s;l++)r+=this._normalizedB(this._fftData[a][l]);return r/(s-i+1)/o}getOptions(t){Array.isArray(t)||(t=[t]);let n={};for(const i of Object.keys(Hn))t.includes(i)||(i=="gradient"&&this.gradientLeft!=this.gradientRight?(n.gradientLeft=this.gradientLeft,n.gradientRight=this.gradientRight):i!="start"&&(n[i]=this[i]));return n}registerGradient(t,n){if(typeof t!="string"||t.trim().length==0)throw new Wt(iv);if(typeof n!="object")throw new Wt(sv);const{colorStops:i}=n;if(!Array.isArray(i)||!i.length)throw new Wt(rv);const s=i.length,o=r=>+r!=r||r<0||r>1;i.forEach((r,a)=>{const l=a/Math.max(1,s-1);typeof r!="object"?i[a]={pos:l,color:r}:o(r.pos)&&(r.pos=l),o(r.level)&&(i[a].level=1-a/s)}),i.sort((r,a)=>r.level<a.level?1:r.level>a.level?-1:0),i[0].level=1,this._gradients[t]={bgColor:n.bgColor||Hg,dir:n.dir,colorStops:i},this._selectedGrads.includes(t)&&this._makeGrad()}setCanvasSize(t,n){this._width=t,this._height=n,this._setCanvas(Ar)}setFreqRange(t,n){if(t<1||n<1)throw new Wt(Pr);this._minFreq=Math.min(t,n),this.maxFreq=Math.max(t,n)}setLedParams(t){let n,i,s;t&&(n=t.maxLeds|0,i=+t.spaceV,s=+t.spaceH),this._ledParams=n>0&&i>0&&s>=0?[n,i,s]:void 0,this._calcBars()}setOptions(t){this._setProps(t)}setSensitivity(t,n){for(const i of[0,1])this._analyzer[i].minDecibels=Math.min(t,n),this._analyzer[i].maxDecibels=Math.max(t,n)}start(){this.toggleAnalyzer(!0)}stop(){this.toggleAnalyzer(!1)}toggleAnalyzer(t){const n=this.isOn;return t===void 0&&(t=!n),n&&!t?(cancelAnimationFrame(this._runId),this._runId=0):!n&&t&&!this._destroyed&&(this._frames=0,this._time=performance.now(),this._runId=requestAnimationFrame(i=>this._draw(i))),this.isOn}toggleFullscreen(){if(this.isFullscreen)document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen();else{const t=this._fsEl;if(!t)return;t.requestFullscreen?t.requestFullscreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen()}}_binToFreq(t){return t*this.audioCtx.sampleRate/this.fftSize||1}_calcBars(){const t=this._bars=[];if(!this._ready){this._flg={isAlpha:!1,isBands:!1,isLeds:!1,isLumi:!1,isOctaves:!1,isOutline:!1,isRound:!1,noLedGap:!1};return}const{_ansiBands:n,_barSpace:i,canvas:s,_chLayout:o,_maxFreq:r,_minFreq:a,_mirror:l,_mode:c,_radial:d,_radialInvert:u,_reflexRatio:p}=this,g=s.width>>1,_=s.height>>1,b=o==oe&&!d,w=o==Ri,y=c%10!=0,S=y&&this._frequencyScale==on,C=this._showLeds&&y&&!d,P=this._lumiBars&&y&&!d,L=this._alphaBars&&!P&&c!=rn,D=this._outlineBars&&y&&!P&&!C,x=this._roundBars&&y&&!P&&!C,k=o!=oe||p>0&&!P,f=s.height-(b&&!C?.5:0)>>b,m=f*(P||d?1:1-p)|0,h=s.width-g*(w||l!=0),v=b?s.height-f*2:0,T=g*(l==-1&&!w&&!d);let R=Math.min(s.width,s.height)*.375*(o==oe?1:this._radius)|0,A=Math.min(g,_);u&&o!=oe&&([R,A]=[A,R]);const M=W=>t.push({...W,peak:[0,0],hold:[0],alpha:[0],value:[0]}),I=W=>{const Y=this._freqToBin(W,"floor"),Z=this._binToFreq(Y),tt=this._binToFreq(Y+1),dt=Math.log2(W/Z)/Math.log2(tt/Z);return[Y,dt]};let N,K,F;if(S){const W=(st,ft,it)=>+st.toPrecision(it?Math.max(ft,1+Math.log10(st)|0):ft),Y=st=>{const ft=[1,1.12,1.25,1.4,1.6,1.8,2,2.24,2.5,2.8,3.15,3.55,4,4.5,5,5.6,6.3,7.1,8,9,10],it=Math.log10(st)|0,ce=st/10**it;let Zt=1;for(;Zt<ft.length&&ce>ft[Zt];)Zt++;return ce-ft[Zt-1]<ft[Zt]-ce&&Zt--,(ft[Zt]*10**(it+5)|0)/1e5},Z=[0,24,12,8,6,4,3,2,1][c],tt=n?10**(3/(Z*10)):2**(1/Z),dt=tt**.5;let It=n?7.94328235/(Z%2?1:dt):eu;do{let st=It;const ft=W(st/dt,4,!0),it=W(st*dt,4,!0),[ce,Zt]=I(ft),[Yn,ue]=I(it);n?st=Z<4?Y(st):W(st,st.toString()[0]<5?3:2):st=W(st,4,!0),st>=a&&M({posX:0,freq:st,freqLo:ft,freqHi:it,binLo:ce,binHi:Yn,ratioLo:Zt,ratioHi:ue}),It*=tt}while(It<=r);N=h/t.length,t.forEach((st,ft)=>st.posX=T+ft*N);const ht=t[0],Tt=t[t.length-1];K=this._freqScaling(ht.freqLo),F=h/(this._freqScaling(Tt.freqHi)-K),ht.freqLo<a&&(ht.freqLo=a,[ht.binLo,ht.ratioLo]=I(a)),Tt.freqHi>r&&(Tt.freqHi=r,[Tt.binHi,Tt.ratioHi]=I(r))}else if(y){const W=[0,24,12,8,6,4,3,2,1][c]*10,Y=Z=>{switch(this._frequencyScale){case Rr:return 1960/(26.81/(Z+.53)-1);case Ir:return 700*(2**Z-1);case Un:return Z}};N=h/W,K=this._freqScaling(a),F=h/(this._freqScaling(r)-K);for(let Z=0,tt=0;Z<W;Z++,tt+=N){const dt=Y(K+tt/F),It=Y(K+(tt+N/2)/F),ht=Y(K+(tt+N)/F),[Tt,st]=I(dt),[ft,it]=I(ht);M({posX:T+tt,freq:It,freqLo:dt,freqHi:ht,binLo:Tt,binHi:ft,ratioLo:st,ratioHi:it})}}else{N=1,K=this._freqScaling(a),F=h/(this._freqScaling(r)-K);const W=this._freqToBin(a,"floor"),Y=this._freqToBin(r);let Z=-999;for(let tt=W;tt<=Y;tt++){const dt=this._binToFreq(tt),It=T+Math.round(F*(this._freqScaling(dt)-K));if(It>Z)M({posX:It,freq:dt,freqLo:dt,freqHi:dt,binLo:tt,binHi:tt,ratioLo:0,ratioHi:0}),Z=It;else if(t.length){const ht=t[t.length-1];ht.binHi=tt,ht.freqHi=dt,ht.freq=(ht.freqLo*dt)**.5}}}let rt=0,Q=0;if(C){const W=this._pixelRatio/(window.devicePixelRatio>1&&window.screen.height<=540?2:1),Y=[[],[128,3,.45],[128,4,.225],[96,6,.225],[80,6,.225],[80,6,.125],[64,6,.125],[48,8,.125],[24,16,.125]],Z=this._ledParams,[tt,dt,It]=Z||Y[c];let ht,Tt=m;if(Z){const st=2*W;let ft;ht=tt+1;do ht--,ft=Tt/ht/(1+dt),Q=ft*dt;while((ft<st||Q<st)&&ht>1)}else{const st=540/dt;Q=Math.min(dt*W,Math.max(2,Tt/st+.1|0))}k&&(Tt+=Q),Z||(ht=Math.min(tt,Tt/(Q*2)|0)),rt=It>=1?It:N*It,this._leds=[ht,rt,Q,Tt/ht-Q]}const j=Math.min(N-1,i*(i>0&&i<1?N:1));y&&(N-=Math.max(C?rt:0,j)),t.forEach((W,Y)=>{let Z=W.posX,tt=N;y&&(i==0&&!C?(Z|=0,tt|=0,Y>0&&Z>t[Y-1].posX+t[Y-1].width&&(Z--,tt++)):Z+=Math.max(C?rt:0,j)/2,W.posX=Z),W.barCenter=Z+(N==1?0:tt/2),W.width=tt});const lt=[];for(const W of[0,1]){const Y=o==oe?(f+v)*W:0,Z=Y+f,tt=Y+m-(!C||k?0:Q);lt.push({channelTop:Y,channelBottom:Z,analyzerBottom:tt})}this._aux={analyzerHeight:m,analyzerWidth:h,centerX:g,centerY:_,channelCoords:lt,channelHeight:f,channelGap:v,initialX:T,innerRadius:R,outerRadius:A,scaleMin:K,unitWidth:F},this._flg={isAlpha:L,isBands:y,isLeds:C,isLumi:P,isOctaves:S,isOutline:D,isRound:x,noLedGap:k},this._createScales()}_createScales(){if(!this._ready)return;const{analyzerWidth:t,initialX:n,innerRadius:i,scaleMin:s,unitWidth:o}=this._aux,{canvas:r,_frequencyScale:a,_mirror:l,_noteLabels:c,_radial:d,_scaleX:u,_scaleR:p}=this,g=u.canvas,_=p.canvas,b=[],w=this._chLayout==Ri,y=this._chLayout==oe,S=Math.min(r.width,r.height),C=["C",,"D",,"E","F",,"G",,"A",,"B"],P=S/34|0,L=g.height>>1,D=P>>1,x=L*(c?.7:1.5),k=D*(c?1:2),f=2**(1/12);if(!c&&(this._ansiBands||a!=on))b.push(16,31.5,63,125,250,500,1e3,2e3,4e3),a==Un?b.push(6e3,8e3,1e4,12e3,14e3,16e3,18e3,2e4,22e3):b.push(8e3,16e3);else{let A=eu;for(let M=-1;M<11;M++)for(let I=0;I<12;I++){if(A>=this._minFreq&&A<=this._maxFreq){const N=C[I],K=N=="C";(N&&c&&!l&&!w||K)&&b.push(c?[A,N+(K?M:"")]:A)}A*=f}}_.width=_.height=Math.max(S*.15,(i<<1)+y*P);const m=_.width>>1,h=m-P*.7,v=(A,M)=>{const I=sn*(A/r.width),N=I-Er,K=h*Math.cos(N),F=h*Math.sin(N);p.save(),p.translate(m+K,m+F),p.rotate(I),p.fillText(M,0,0),p.restore()};g.width|=0,u.fillStyle=p.strokeStyle=Kg,u.fillRect(0,0,g.width,g.height),p.arc(m,m,m-P/2,0,sn),p.lineWidth=P,p.stroke(),u.fillStyle=p.fillStyle=gu,u.font=`${L}px ${Pi}`,p.font=`${D}px ${Pi}`,u.textAlign=p.textAlign="center";let T=-x/4,R=-k;for(const A of b){const[M,I]=Array.isArray(A)?A:[A,A<1e3?A|0:`${(A/100|0)/10}k`],N=o*(this._freqScaling(M)-s),K=g.height*.75,F=I[0]=="C",rt=L*(c&&!l&&!w?F?1.2:.6:3);if(u.fillStyle=p.fillStyle=F&&!l&&!w?Xg:gu,c){const Q=a==on,j=a==Un;let lt=["C"];if((Q||M>2e3||!j&&M>250||(!d||y)&&(!j&&M>125||M>1e3))&&lt.push("G"),(Q||M>4e3||!j&&M>500||(!d||y)&&(!j&&M>250||M>2e3))&&lt.push("E"),(j&&M>4e3||(!d||y)&&(Q||M>2e3||!j&&M>500))&&lt.push("D","F","A","B"),!lt.includes(I[0]))continue}N>=T+x/2&&N<=t&&(u.fillText(I,w&&l==-1?t-N:n+N,K,rt),(w||l&&(N>x||l==1))&&u.fillText(I,w&&l!=1?t+N:(n||r.width)-N,K,rt),T=N+Math.min(rt,u.measureText(I).width)/2),N>=R+k&&N<t-k&&(v(w&&l==1?t-N:N,I),(w||l&&(N>k||l==1))&&v(w&&l!=-1?t+N:-N,I),R=N)}}_draw(t){this._runId=requestAnimationFrame(O=>this._draw(O));const n=t-this._time,i=t-this._last,s=this._maxFPS?975/this._maxFPS:0;if(i<s)return;this._last=t-(s?i%s:0),this._frames++,n>=1e3&&(this._fps=this._frames/n*1e3,this._frames=0,this._time=t);const{isAlpha:o,isBands:r,isLeds:a,isLumi:l,isOctaves:c,isOutline:d,isRound:u,noLedGap:p}=this._flg,{analyzerHeight:g,centerX:_,centerY:b,channelCoords:w,channelHeight:y,channelGap:S,initialX:C,innerRadius:P,outerRadius:L}=this._aux,{_bars:D,canvas:x,_canvasGradients:k,_chLayout:f,_colorMode:m,_ctx:h,_energy:v,_fadePeaks:T,fillAlpha:R,_fps:A,_linearAmplitude:M,_lineWidth:I,maxDecibels:N,minDecibels:K,_mirror:F,_mode:rt,overlay:Q,_radial:j,showBgColor:lt,showPeaks:W,useCanvas:Y,_weightingFilter:Z}=this,tt=this._scaleX.canvas,dt=this._scaleR.canvas,It=A*this._peakFadeTime/1e3,ht=A**2,Tt=this._gravity*1e3,st=A*this._peakHoldTime/1e3,ft=f==nu,it=f==Ri,ce=f==oe,Zt=f==me,Yn=a&&this._trueLeds&&m==Ii,ue=j?x.width:this._aux.analyzerWidth,Hr=C+ue,Zn=W&&this._peakLine&&rt==rn,Ce=j?L-P:g,$_=Ce/this._pixelRatio,[U_,Y_,Jn,Gr]=this._leds||[];v.val>0&&A>0&&(this._spinAngle+=this._spinSpeed*sn/60/A);const H_=O=>{if(this._reflexRatio>0&&!l&&!j){let et,de;this.reflexFit||ce?(et=ce&&O==0?y+S:0,de=y-g):(et=x.height-g*2,de=g),h.save(),h.globalAlpha=this.reflexAlpha,this.reflexBright!=1&&(h.filter=`brightness(${this.reflexBright})`),h.setTransform(1,0,0,-1,0,x.height),h.drawImage(x,0,w[O].channelTop,x.width,g,0,et,x.width,de),h.restore()}},G_=()=>{this.showScaleX&&(j?(h.save(),h.translate(_,b),this._spinSpeed&&h.rotate(this._spinAngle+Er),h.drawImage(dt,-dt.width>>1,-dt.width>>1),h.restore()):h.drawImage(tt,0,x.height-tt.height))},W_=O=>{const et=O**2,de=424.36,Ct=11599.29,Ui=25122.25,ke=544496.41,ge=148693636,je=$e=>20*Math.log10($e);switch(Z){case cu:const $e=ge*et**2/((et+de)*Math.sqrt((et+Ct)*(et+ke))*(et+ge));return 2+je($e);case uu:const Ue=ge*et*O/((et+de)*Math.sqrt(et+Ui)*(et+ge));return .17+je(Ue);case du:const qr=ge*et/((et+de)*(et+ge));return .06+je(qr);case hu:const Hi=((103791848e-2-et)**2+108076816e-2*et)/((9837328-et)**2+11723776*et),Kr=O/68966888496476e-18*Math.sqrt(Hi/((et+79919.29)*(et+1345600)));return je(Kr);case fu:const Gi=-4737338981378384e-39*O**6+2043828333606125e-30*O**4-1363894795463638e-22*et+1,He=1306612257412824e-34*O**5-2118150887518656e-26*O**3+.0005559488023498642*O,Bt=.0001246332637532143*O/Math.hypot(Gi,He);return 18.2+je(Bt)}return 0},Wr=(O,et,de)=>{h.beginPath(),h.moveTo(O,et),h.lineTo(O,de),h.stroke()},zr=O=>{if(O&&I){const et=h.globalAlpha;h.globalAlpha=1,h.stroke(),h.globalAlpha=et}},Be=O=>Math.max(0,(O*U_|0)*(Gr+Jn)-Jn),z_=O=>{v.val=O,v.peak>0&&(v.hold--,v.hold<0&&(v.peak+=v.hold*Tt/ht/x.height*this._pixelRatio)),O>=v.peak&&(v.peak=O,v.hold=st)};Q&&h.clearRect(0,0,x.width,x.height);let cd=0;const ud=D.length,dd=Zt?1:2;for(let O=0;O<dd;O++){const{channelTop:et,channelBottom:de,analyzerBottom:Ct}=w[O],Ui=this._gradients[this._selectedGrads[O]],ke=Ui.colorStops,ge=ke.length,je=!lt||a&&!Q?"#000":Ui.bgColor,$e=ce&&j&&O?-1:1,Ue=!O&&F==-1||O&&F==1,qr=!it||O&&F!=1?0:ue>>(O||!Ue),Hi=it&&Ue?-1:1,Kr=()=>{const $=tt.height,G=$>>1,z=M?100:N,ct=M?0:K,bt=M?20:5,Nt=g/(z-ct),he=F!=-1&&(!it||O==0||F==1),Te=F!=1&&(!it||O!=F);h.save(),h.fillStyle=vu,h.font=`${G}px ${Pi}`,h.textAlign="right",h.lineWidth=1;for(let Ee=z;Ee>ct;Ee-=bt){const fn=et+(z-Ee)*Nt,xt=Ee%2==0|0;if(xt){const Pt=fn+G*(fn==et?.8:.35);he&&h.fillText(Ee,$*.85,Pt),Te&&h.fillText(Ee,(it?ue:x.width)-$*.1,Pt),h.strokeStyle=vu,h.setLineDash([2,4]),h.lineDashOffset=0}else h.strokeStyle=Yg,h.setLineDash([2,8]),h.lineDashOffset=1;h.beginPath(),h.moveTo(C+$*xt*he,~~fn+.5),h.lineTo(Hr-$*xt*Te,~~fn+.5),h.stroke()}h.restore()},Gi=($,G)=>{const z=Jt[$]+($<Jt.length-1?(Jt[$+1]-Jt[$])*G:0);return isNaN(z)?-1/0:z},He=($,G=Hi)=>G*sn*(($+qr)/x.width)+this._spinAngle,Bt=($,G,z)=>{const ct=P+G*$e,bt=He($,z);return[_+ct*Math.cos(bt),b+ct*Math.sin(bt)]},Xr=($,G,z,ct,bt)=>{h.beginPath();for(const Nt of F&&!it?[1,-1]:[Hi]){const[he,Te]=u?[He($,Nt),He($+z,Nt)]:[];h.moveTo(...Bt($,G,Nt)),h.lineTo(...Bt($,G+ct,Nt)),u?h.arc(_,b,P+(G+ct)*$e,he,Te,Nt!=1):h.lineTo(...Bt($+z,G+ct,Nt)),h.lineTo(...Bt($+z,G,Nt)),u&&!bt&&h.arc(_,b,P+G*$e,Te,he,Nt==1)}zr(bt),h.fill()},Yr=($=0,G=0)=>{let z;if(m==Ii&&!Yn||rt==rn)z=k[O];else{const ct=m==iu?G%ge:ke.findLastIndex(bt=>a?Be($)<=Be(bt.level):$<=bt.level);z=ke[ct].color}h.fillStyle=h.strokeStyle=z};if(Y){if(it&&!j){const $=ue*(O+Ue),G=Ue?-1:1;h.setTransform(G,0,0,1,$,0)}if((!Q||lt)&&(Q&&(h.globalAlpha=this.bgAlpha),h.fillStyle=je,(O==0||!j&&!ft)&&h.fillRect(C,et-S,ue,(Q&&this.reflexAlpha==1?g:y)+S),h.globalAlpha=1),this.showScaleY&&!l&&!j&&(O==0||!ft)&&Kr(),a?(h.setLineDash([Gr,Jn]),h.lineWidth=D[0].width):h.lineWidth=d?Math.min(I,D[0].width/2):I,h.save(),!j){const $=new Path2D;$.rect(0,et,x.width,g),h.clip($)}}let Jt=this._fftData[O];this._analyzer[O].getFloatFrequencyData(Jt),Z&&(Jt=Jt.map(($,G)=>$+W_(this._binToFreq(G)))),h.beginPath();let Qn=[];for(let $=0;$<ud;$++){const G=D[$],{posX:z,barCenter:ct,width:bt,freq:Nt,binLo:he,binHi:Te,ratioLo:Ee,ratioHi:fn}=G;let xt=Math.max(Gi(he,Ee),Gi(Te,fn));for(let ot=he+1;ot<Te;ot++)Jt[ot]>xt&&(xt=Jt[ot]);if(xt=this._normalizedB(xt),G.value[O]=xt,cd+=xt,G.peak[O]>0&&G.alpha[O]>0&&(G.hold[O]--,G.hold[O]<0)){if(T&&!Zn){const ot=!o||d&&I>0?1:o?G.peak[O]:R;G.alpha[O]=ot*(1+G.hold[O]/It)}else G.peak[O]+=G.hold[O]*Tt/ht/$_;G.alpha[O]<=0&&(G.peak[O]=0)}if(xt>=G.peak[O]&&(G.peak[O]=xt,G.hold[O]=st,G.alpha[O]=!o||d&&I>0?1:o?xt:R),!Y)continue;h.globalAlpha=l||o?xt:d?R:1,Yr(xt,$);const Pt=l?Ce:a?Be(xt):xt*Ce|0;if(rt==rn){const ot=$?0:(this._normalizedB(Jt[D[1].binLo])*Ce+Pt)/2;if(j){if($==0&&(it&&h.moveTo(...Bt(0,0)),h.lineTo(...Bt(0,z<0?ot:Pt))),z>=0){const qt=[z,Pt];h.lineTo(...Bt(...qt)),Qn.push(qt)}}else{if($==0)if(F==-1&&!it)h.moveTo(C,Ct-(z<C?ot:Pt));else{const qt=he?this._normalizedB(Jt[he-1])*Ce:Pt;h.moveTo(C-I,Ct-qt)}(it||F!=-1||z>=C)&&h.lineTo(z,Ct-Pt)}}else if(a){if(lt&&!Q&&(O==0||!ft)){const ot=h.globalAlpha;h.strokeStyle=Wg,h.globalAlpha=1,Wr(ct,et,Ct),h.strokeStyle=h.fillStyle,h.globalAlpha=ot}if(Yn){const ot=l?0:ke.findLastIndex(Ge=>Be(xt)<=Be(Ge.level));let qt=Ct;for(let Ge=ge-1;Ge>=ot;Ge--){h.strokeStyle=ke[Ge].color;let fd=Ct-(Ge==ot?Pt:Be(ke[Ge].level));Wr(ct,qt,fd),qt=fd-Jn}}else Wr(ct,Ct,Ct-Pt)}else if(z>=C)if(j)Xr(z,0,bt,Pt,d);else if(u){const ot=bt/2,qt=Ct+ot;h.beginPath(),h.moveTo(z,qt),h.lineTo(z,qt-Pt),h.arc(ct,qt-Pt,ot,Tr,sn),h.lineTo(z+bt,qt),zr(d),h.fill()}else{const ot=d?h.lineWidth:0;h.beginPath(),h.rect(z,Ct+ot,bt,-Pt-ot),zr(d),h.fill()}const pn=G.peak[O],hd=G.alpha[O];if(pn>0&&hd>0&&W&&!Zn&&!l&&z>=C&&z<Hr){if(T?h.globalAlpha=hd:d&&I>0?h.globalAlpha=1:o&&(h.globalAlpha=pn),(m==su||Yn)&&Yr(pn),a){const ot=Be(pn);ot>=Jn&&h.fillRect(z,Ct-ot,bt,Gr)}else if(!j)h.fillRect(z,Ct-pn*Ce,bt,2);else if(rt!=rn){const ot=pn*Ce;Xr(z,ot,bt,!this._radialInvert||ce||ot+P>=2?-2:2)}}}if(Y){if(h.globalAlpha=1,rt==rn){if(Yr(),j&&!it){if(F){let $;for(;$=Qn.pop();)h.lineTo(...Bt(...$,-1))}h.closePath()}if(I>0&&h.stroke(),R>0){if(j){const $=it?He(ue>>1):0,G=it?He(ue):sn;h.moveTo(...Bt(it?ue>>1:0,0)),h.arc(_,b,P,$,G,it?!Ue:!0)}else h.lineTo(Hr,Ct),h.lineTo(C,Ct);h.globalAlpha=R,h.fill(),h.globalAlpha=1}if((Zn||j&&W)&&(Qn=[],h.beginPath(),D.forEach(($,G)=>{let z=$.posX,ct=$.peak[O],bt=G?"lineTo":"moveTo";if(j&&z<0){const Nt=D[G+1];ct=ov(z,ct,Nt.posX,Nt.peak[O],0),z=0}ct*=Ce,Zn?(h[bt](...j?Bt(z,ct):[z,Ct-ct]),j&&F&&!it&&Qn.push([z,ct])):ct>0&&Xr(z,ct,1,-2)}),Zn)){let $;for(;$=Qn.pop();)h.lineTo(...Bt(...$,-1));h.lineWidth=1,h.stroke()}}h.restore(),it&&!j&&h.setTransform(1,0,0,1,0,0),(!it&&!ft||O)&&H_(O)}}if(z_(cd/(ud<<dd-1)),Y&&(F&&!j&&!it&&(h.setTransform(-1,0,0,1,x.width-C,0),h.drawImage(x,C,0,_,x.height,0,0,_,x.height),h.setTransform(1,0,0,1,0,0)),h.setLineDash([]),G_()),this.showFPS){const O=tt.height;h.font=`bold ${O}px ${Pi}`,h.fillStyle=Gg,h.textAlign="right",h.fillText(Math.round(A),x.width-O,O*2)}this.onCanvasDraw&&(h.save(),h.fillStyle=h.strokeStyle=k[0],this.onCanvasDraw(this,{timestamp:t,canvasGradients:k}),h.restore())}_freqScaling(t){switch(this._frequencyScale){case on:return Math.log2(t);case Rr:return 26.81*t/(1960+t)-.53;case Ir:return Math.log2(1+t/700);case Un:return t}}_freqToBin(t,n="round"){const i=this._analyzer[0].frequencyBinCount-1,s=Math[n](t*this.fftSize/this.audioCtx.sampleRate);return s<i?s:i}_makeGrad(){if(!this._ready)return;const{canvas:t,_ctx:n,_radial:i,_reflexRatio:s}=this,{analyzerWidth:o,centerX:r,centerY:a,initialX:l,innerRadius:c,outerRadius:d}=this._aux,{isLumi:u}=this._flg,p=this._chLayout==oe,g=1-s,_=u?t.height:t.height*(1-s*!p)|0;for(const b of[0,1]){const w=this._gradients[this._selectedGrads[b]],y=w.colorStops,S=w.dir=="h";let C;if(i?C=n.createRadialGradient(r,a,d,r,a,c-(d-c)*p):C=n.createLinearGradient(...S?[l,0,l+o,0]:[0,0,0,_]),y){const P=p&&!this._splitGradient&&(!S||i);for(let L=0;L<1+P;L++){const D=y.length-1;y.forEach((x,k)=>{let f=x.pos;if(P&&(f/=2),p&&!u&&!i&&!S&&(f*=g,!P&&f>.5*g&&(f+=.5*s)),L==1)if(i||u){const m=D-k;x=y[m],f=1-x.pos/2}else k==0&&f>0&&C.addColorStop(.5,x.color),f+=.5;C.addColorStop(f,x.color),p&&k==D&&f<.5&&C.addColorStop(.5,x.color)})}}this._canvasGradients[b]=C}}_normalizedB(t){const n=this._linearAmplitude,i=n?1/this._linearBoost:1,s=(l,c,d)=>l<=c?c:l>=d?d:l,o=l=>10**(l/20);let r=this.maxDecibels,a=this.minDecibels;return n&&(r=o(r),a=o(a),t=o(t)**i),s((t-a)/(r-a)**i,0,1)}_setCanvas(t){if(!this._ready)return;const{canvas:n,_ctx:i}=this,s=this._scaleX.canvas,o=window.devicePixelRatio/(this._loRes+1);let r=window.screen.width*o,a=window.screen.height*o;Math.abs(window.orientation)==90&&r<a&&([r,a]=[a,r]);const l=this.isFullscreen,c=l&&this._fsEl==n,d=c?r:(this._width||this._container.clientWidth||this._defaultWidth)*o|0,u=c?a:(this._height||this._container.clientHeight||this._defaultHeight)*o|0;this._pixelRatio=o,this._fsWidth=r,this._fsHeight=a,!(t!=pu&&n.width==d&&n.height==u)&&(n.width=d,n.height=u,this.overlay||(i.fillStyle="#000",i.fillRect(0,0,d,u)),i.lineJoin="bevel",s.width=d,s.height=Math.max(20*o,Math.min(d,u)/32|0),this._calcBars(),this._makeGrad(),this._fsStatus!==void 0&&this._fsStatus!==l&&(t=mu),this._fsStatus=l,this.onCanvasResize&&this.onCanvasResize(t,this))}_setGradient(t,n){if(!this._gradients.hasOwnProperty(t))throw new Wt(Qg,t);[0,1].includes(n)||(this._selectedGrads[1]=t,n=0),this._selectedGrads[n]=t,this._makeGrad()}_setProps(t,n){const i=["onCanvasDraw","onCanvasResize"],s=["gradientLeft","gradientRight","stereo"],o=Object.keys(Hn).filter(r=>r!="start").concat(i,s);(n||t===void 0)&&(t={...Hn,...t});for(const r of Object.keys(t))i.includes(r)&&typeof t[r]!="function"?this[r]=void 0:o.includes(r)&&(this[r]=t[r]);t.start!==void 0&&this.toggleAnalyzer(t.start)}}const lv={verdant:{colorStops:[{color:"#D3FFA6",pos:0},{color:"#036B5B",pos:.5},{color:"#D3FFA6",pos:1}]},twilight:{colorStops:[{color:"#81B9FF",pos:0},{color:"#371A5E",pos:.5},{color:"#81B9FF",pos:1}]},bloom:{colorStops:[{color:"#FFD4FE",pos:0},{color:"#FD05F9",pos:.5},{color:"#FFD4FE",pos:1}]},mystic:{colorStops:[{color:"#1F023A",pos:0},{color:"#CA76FF",pos:.5},{color:"#1F023A",pos:1}]},flare:{colorStops:[{color:"#FFFFFF",pos:0},{color:"#FC5F00",pos:.5},{color:"#FFFFFF",pos:1}]},glacier:{colorStops:[{color:"#4CE5F2",pos:0},{color:"#005A98",pos:.5},{color:"#4CE5F2",pos:1}]}},xu=({stream:e,className:t,onClick:n})=>{var o;const i=Mt(null),s=Ne();return $t(()=>{var c;if(!i.current||!e)return;const r=new AudioContext,a=r.createMediaStreamSource(e),l=new av(i.current,{source:a,audioCtx:r,alphaBars:!1,ansiBands:!1,barSpace:.25,bgAlpha:0,channelLayout:"single",colorMode:"gradient",fadePeaks:!1,fftSize:2048,fillAlpha:0,frequencyScale:"log",gravity:3.8,ledBars:!1,linearAmplitude:!0,linearBoost:2,lineWidth:1.5,loRes:!1,lumiBars:!1,maxDecibels:-20,maxFPS:0,maxFreq:16e3,minDecibels:-90,minFreq:30,mirror:0,mode:7,noteLabels:!1,outlineBars:!1,overlay:!0,peakFadeTime:750,peakHoldTime:500,peakLine:!1,radial:!1,radialInvert:!1,radius:.7,reflexAlpha:1,reflexBright:1,reflexFit:!0,reflexRatio:.5,roundBars:!0,showBgColor:!1,showFPS:!1,showPeaks:!1,showScaleX:!1,showScaleY:!1,smoothing:.7,spinSpeed:0,splitGradient:!1,trueLeds:!1,useCanvas:!0,volume:1,weightingFilter:"D"});return l.registerGradient("gradient",lv[((c=s.audio_visualizer_config)==null?void 0:c.color)||"verdant"]),l.gradient="gradient",()=>{l.destroy()}},[(o=s.audio_visualizer_config)==null?void 0:o.color,e]),E("div",{onClick:n,className:xe("w-full",t),ref:i})};/**
16
+ */const $g="4.5.1",Tr=Math.PI,sn=2*Tr,Er=Tr/2,eu=8.17579892,nu="dual-combined",Ri="dual-horizontal",me="single",oe="dual-vertical",iu="bar-index",su="bar-level",Ii="gradient",ru=60,ou="click",Ug="fullscreenchange",au="resize",Hg="#111",lu="",cu="A",uu="B",du="C",hu="D",fu="468",Pi="sans-serif",Gg="#0f0",Wg="#7f7f7f22",rn=10,pu="create",mu="fschange",zg="lores",qg=au,Ar="user",Kg="#000c",gu="#fff",Xg="#4f4",vu="#888",Yg="#555",Rr="bark",Un="linear",on="log",Ir="mel",_u=["#a35","#c66","#e94","#ed0","#9d5","#4d8","#2cb","#0bc","#09c","#36b"],yu=[["classic",{colorStops:["red",{color:"yellow",level:.85,pos:.6},{color:"lime",level:.475}]}],["prism",{colorStops:_u}],["rainbow",{dir:"h",colorStops:["#817",..._u,"#639"]}],["orangered",{bgColor:"#3e2f29",colorStops:["OrangeRed"]}],["steelblue",{bgColor:"#222c35",colorStops:["SteelBlue"]}]],Hn={alphaBars:!1,ansiBands:!1,barSpace:.1,bgAlpha:.7,channelLayout:me,colorMode:Ii,fadePeaks:!1,fftSize:8192,fillAlpha:1,frequencyScale:on,gradient:yu[0][0],gravity:3.8,height:void 0,ledBars:!1,linearAmplitude:!1,linearBoost:1,lineWidth:0,loRes:!1,lumiBars:!1,maxDecibels:-25,maxFPS:0,maxFreq:22e3,minDecibels:-85,minFreq:20,mirror:0,mode:0,noteLabels:!1,outlineBars:!1,overlay:!1,peakFadeTime:750,peakHoldTime:500,peakLine:!1,radial:!1,radialInvert:!1,radius:.3,reflexAlpha:.15,reflexBright:1,reflexFit:!0,reflexRatio:0,roundBars:!1,showBgColor:!0,showFPS:!1,showPeaks:!0,showScaleX:!0,showScaleY:!1,smoothing:.5,spinSpeed:0,splitGradient:!1,start:!0,trueLeds:!1,useCanvas:!0,volume:1,weightingFilter:lu,width:void 0},Zg=["ERR_AUDIO_CONTEXT_FAIL","Could not create audio context. Web Audio API not supported?"],Jg=["ERR_INVALID_AUDIO_CONTEXT","Provided audio context is not valid"],Qg=["ERR_UNKNOWN_GRADIENT","Unknown gradient"],Pr=["ERR_FREQUENCY_TOO_LOW","Frequency values must be >= 1"],tv=["ERR_INVALID_MODE","Invalid mode"],ev=["ERR_REFLEX_OUT_OF_RANGE","Reflex ratio must be >= 0 and < 1"],nv=["ERR_INVALID_AUDIO_SOURCE","Audio source must be an instance of HTMLMediaElement or AudioNode"],iv=["ERR_GRADIENT_INVALID_NAME","Gradient name must be a non-empty string"],sv=["ERR_GRADIENT_NOT_AN_OBJECT","Gradient options must be an object"],rv=["ERR_GRADIENT_MISSING_COLOR","Gradient colorStops must be a non-empty array"];class Wt extends Error{constructor(t,n){const[i,s]=t;super(s+(n!==void 0?`: ${n}`:"")),this.name="AudioMotionError",this.code=i}}const bu=(e,t)=>console.warn(`${e} is deprecated. Use ${t} instead.`),wu=e=>{for(const t in e)return!1;return!0},Mi=(e,t,n="toLowerCase")=>t[Math.max(0,t.indexOf((""+e)[n]()))],ov=(e,t,n,i,s)=>t+(i-t)*(s-e)/(n-e);Array.prototype.findLastIndex||(Array.prototype.findLastIndex=function(e){let t=this.length;for(;t-- >0;)if(e(this[t]))return t;return-1});class av{constructor(t,n={}){this._ready=!1,this._aux={},this._canvasGradients=[],this._destroyed=!1,this._energy={val:0,peak:0,hold:0},this._flg={},this._fps=0,this._gradients={},this._last=0,this._outNodes=[],this._ownContext=!1,this._selectedGrads=[],this._sources=[],t instanceof Element||(wu(n)&&!wu(t)&&(n=t),t=null),this._ownCanvas=!(n.canvas instanceof HTMLCanvasElement);const i=this._ownCanvas?document.createElement("canvas"):n.canvas;i.style="max-width: 100%;",this._ctx=i.getContext("2d");for(const[u,p]of yu)this.registerGradient(u,p);this._container=t||!this._ownCanvas&&i.parentElement||document.body,this._defaultWidth=this._container.clientWidth||640,this._defaultHeight=this._container.clientHeight||270;let s;if(!(n.source&&(s=n.source.context))){if(!(s=n.audioCtx))try{s=new(window.AudioContext||window.webkitAudioContext),this._ownContext=!0}catch{throw new Wt(Zg)}}if(!s.createGain)throw new Wt(Jg);const o=this._analyzer=[s.createAnalyser(),s.createAnalyser()],r=this._splitter=s.createChannelSplitter(2),a=this._merger=s.createChannelMerger(2);this._input=s.createGain(),this._output=s.createGain(),n.source&&this.connectInput(n.source);for(const u of[0,1])r.connect(o[u],u);a.connect(this._output),n.connectSpeakers!==!1&&this.connectOutput();for(const u of["_scaleX","_scaleR"])this[u]=document.createElement("canvas").getContext("2d");this._fsEl=n.fsElement||i;const l=()=>{this._fsTimeout||(this._fsTimeout=window.setTimeout(()=>{this._fsChanging||(this._setCanvas(qg),this._fsTimeout=0)},ru))};window.ResizeObserver&&(this._observer=new ResizeObserver(l),this._observer.observe(this._container)),this._controller=new AbortController;const c=this._controller.signal;window.addEventListener(au,l,{signal:c}),i.addEventListener(Ug,()=>{this._fsChanging=!0,this._fsTimeout&&window.clearTimeout(this._fsTimeout),this._setCanvas(mu),this._fsTimeout=window.setTimeout(()=>{this._fsChanging=!1,this._fsTimeout=0},ru)},{signal:c});const d=()=>{s.state=="suspended"&&s.resume().then(()=>window.removeEventListener(ou,d))};window.addEventListener(ou,d),document.addEventListener("visibilitychange",()=>{document.visibilityState!="hidden"&&(this._frames=0,this._time=performance.now())},{signal:c}),this._setProps(n,!0),this.useCanvas&&this._ownCanvas&&this._container.appendChild(i),this._ready=!0,this._setCanvas(pu)}get alphaBars(){return this._alphaBars}set alphaBars(t){this._alphaBars=!!t,this._calcBars()}get ansiBands(){return this._ansiBands}set ansiBands(t){this._ansiBands=!!t,this._calcBars()}get barSpace(){return this._barSpace}set barSpace(t){this._barSpace=+t||0,this._calcBars()}get channelLayout(){return this._chLayout}set channelLayout(t){this._chLayout=Mi(t,[me,Ri,oe,nu]),this._input.disconnect(),this._input.connect(this._chLayout!=me?this._splitter:this._analyzer[0]),this._analyzer[0].disconnect(),this._outNodes.length&&this._analyzer[0].connect(this._chLayout!=me?this._merger:this._output),this._calcBars(),this._makeGrad()}get colorMode(){return this._colorMode}set colorMode(t){this._colorMode=Mi(t,[Ii,iu,su])}get fadePeaks(){return this._fadePeaks}set fadePeaks(t){this._fadePeaks=!!t}get fftSize(){return this._analyzer[0].fftSize}set fftSize(t){for(const i of[0,1])this._analyzer[i].fftSize=t;const n=this._analyzer[0].frequencyBinCount;this._fftData=[new Float32Array(n),new Float32Array(n)],this._calcBars()}get frequencyScale(){return this._frequencyScale}set frequencyScale(t){this._frequencyScale=Mi(t,[on,Rr,Ir,Un]),this._calcBars()}get gradient(){return this._selectedGrads[0]}set gradient(t){this._setGradient(t)}get gradientLeft(){return this._selectedGrads[0]}set gradientLeft(t){this._setGradient(t,0)}get gradientRight(){return this._selectedGrads[1]}set gradientRight(t){this._setGradient(t,1)}get gravity(){return this._gravity}set gravity(t){this._gravity=t>0?+t:this._gravity||Hn.gravity}get height(){return this._height}set height(t){this._height=t,this._setCanvas(Ar)}get ledBars(){return this._showLeds}set ledBars(t){this._showLeds=!!t,this._calcBars()}get linearAmplitude(){return this._linearAmplitude}set linearAmplitude(t){this._linearAmplitude=!!t}get linearBoost(){return this._linearBoost}set linearBoost(t){this._linearBoost=t>=1?+t:1}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=+t||0}get loRes(){return this._loRes}set loRes(t){this._loRes=!!t,this._setCanvas(zg)}get lumiBars(){return this._lumiBars}set lumiBars(t){this._lumiBars=!!t,this._calcBars(),this._makeGrad()}get maxDecibels(){return this._analyzer[0].maxDecibels}set maxDecibels(t){for(const n of[0,1])this._analyzer[n].maxDecibels=t}get maxFPS(){return this._maxFPS}set maxFPS(t){this._maxFPS=t<0?0:+t||0}get maxFreq(){return this._maxFreq}set maxFreq(t){if(t<1)throw new Wt(Pr);this._maxFreq=Math.min(t,this.audioCtx.sampleRate/2),this._calcBars()}get minDecibels(){return this._analyzer[0].minDecibels}set minDecibels(t){for(const n of[0,1])this._analyzer[n].minDecibels=t}get minFreq(){return this._minFreq}set minFreq(t){if(t<1)throw new Wt(Pr);this._minFreq=+t,this._calcBars()}get mirror(){return this._mirror}set mirror(t){this._mirror=Math.sign(t)|0,this._calcBars(),this._makeGrad()}get mode(){return this._mode}set mode(t){const n=t|0;if(n>=0&&n<=10&&n!=9)this._mode=n,this._calcBars(),this._makeGrad();else throw new Wt(tv,t)}get noteLabels(){return this._noteLabels}set noteLabels(t){this._noteLabels=!!t,this._createScales()}get outlineBars(){return this._outlineBars}set outlineBars(t){this._outlineBars=!!t,this._calcBars()}get peakFadeTime(){return this._peakFadeTime}set peakFadeTime(t){this._peakFadeTime=t>=0?+t:this._peakFadeTime||Hn.peakFadeTime}get peakHoldTime(){return this._peakHoldTime}set peakHoldTime(t){this._peakHoldTime=+t||0}get peakLine(){return this._peakLine}set peakLine(t){this._peakLine=!!t}get radial(){return this._radial}set radial(t){this._radial=!!t,this._calcBars(),this._makeGrad()}get radialInvert(){return this._radialInvert}set radialInvert(t){this._radialInvert=!!t,this._calcBars(),this._makeGrad()}get radius(){return this._radius}set radius(t){this._radius=+t||0,this._calcBars(),this._makeGrad()}get reflexRatio(){return this._reflexRatio}set reflexRatio(t){if(t=+t||0,t<0||t>=1)throw new Wt(ev);this._reflexRatio=t,this._calcBars(),this._makeGrad()}get roundBars(){return this._roundBars}set roundBars(t){this._roundBars=!!t,this._calcBars()}get smoothing(){return this._analyzer[0].smoothingTimeConstant}set smoothing(t){for(const n of[0,1])this._analyzer[n].smoothingTimeConstant=t}get spinSpeed(){return this._spinSpeed}set spinSpeed(t){t=+t||0,(this._spinSpeed===void 0||t==0)&&(this._spinAngle=-Er),this._spinSpeed=t}get splitGradient(){return this._splitGradient}set splitGradient(t){this._splitGradient=!!t,this._makeGrad()}get stereo(){return bu("stereo","channelLayout"),this._chLayout!=me}set stereo(t){bu("stereo","channelLayout"),this.channelLayout=t?oe:me}get trueLeds(){return this._trueLeds}set trueLeds(t){this._trueLeds=!!t}get volume(){return this._output.gain.value}set volume(t){this._output.gain.value=t}get weightingFilter(){return this._weightingFilter}set weightingFilter(t){this._weightingFilter=Mi(t,[lu,cu,uu,du,hu,fu],"toUpperCase")}get width(){return this._width}set width(t){this._width=t,this._setCanvas(Ar)}get audioCtx(){return this._input.context}get canvas(){return this._ctx.canvas}get canvasCtx(){return this._ctx}get connectedSources(){return this._sources}get connectedTo(){return this._outNodes}get fps(){return this._fps}get fsHeight(){return this._fsHeight}get fsWidth(){return this._fsWidth}get isAlphaBars(){return this._flg.isAlpha}get isBandsMode(){return this._flg.isBands}get isDestroyed(){return this._destroyed}get isFullscreen(){return this._fsEl&&(document.fullscreenElement||document.webkitFullscreenElement)===this._fsEl}get isLedBars(){return this._flg.isLeds}get isLumiBars(){return this._flg.isLumi}get isOctaveBands(){return this._flg.isOctaves}get isOn(){return!!this._runId}get isOutlineBars(){return this._flg.isOutline}get pixelRatio(){return this._pixelRatio}get isRoundBars(){return this._flg.isRound}static get version(){return $g}connectInput(t){const n=t instanceof HTMLMediaElement;if(!(n||t.connect))throw new Wt(nv);const i=n?this.audioCtx.createMediaElementSource(t):t;return this._sources.includes(i)||(i.connect(this._input),this._sources.push(i)),i}connectOutput(t=this.audioCtx.destination){if(!this._outNodes.includes(t)&&(this._output.connect(t),this._outNodes.push(t),this._outNodes.length==1))for(const n of[0,1])this._analyzer[n].connect(this._chLayout==me&&!n?this._output:this._merger,0,n)}destroy(){if(!this._ready)return;const{audioCtx:t,canvas:n,_controller:i,_input:s,_merger:o,_observer:r,_ownCanvas:a,_ownContext:l,_splitter:c}=this;this._destroyed=!0,this._ready=!1,this.stop(),i.abort(),r&&r.disconnect(),this.onCanvasResize=null,this.onCanvasDraw=null,this._fsEl=null,this.disconnectInput(),this.disconnectOutput(),s.disconnect(),c.disconnect(),o.disconnect(),l&&t.close(),a&&n.remove(),this._calcBars()}disconnectInput(t,n){t?Array.isArray(t)||(t=[t]):t=Array.from(this._sources);for(const i of t){const s=this._sources.indexOf(i);if(n&&i.mediaStream)for(const o of i.mediaStream.getAudioTracks())o.stop();s>=0&&(i.disconnect(this._input),this._sources.splice(s,1))}}disconnectOutput(t){if(!(t&&!this._outNodes.includes(t))&&(this._output.disconnect(t),this._outNodes=t?this._outNodes.filter(n=>n!==t):[],this._outNodes.length==0))for(const n of[0,1])this._analyzer[n].disconnect()}getBars(){return Array.from(this._bars,({posX:t,freq:n,freqLo:i,freqHi:s,hold:o,peak:r,value:a})=>({posX:t,freq:n,freqLo:i,freqHi:s,hold:o,peak:r,value:a}))}getEnergy(t,n){if(t===void 0)return this._energy.val;if(t!=+t){if(t=="peak")return this._energy.peak;const a={bass:[20,250],lowMid:[250,500],mid:[500,2e3],highMid:[2e3,4e3],treble:[4e3,16e3]};if(!a[t])return null;[t,n]=a[t]}const i=this._freqToBin(t),s=n?this._freqToBin(n):i,o=this._chLayout==me?1:2;let r=0;for(let a=0;a<o;a++)for(let l=i;l<=s;l++)r+=this._normalizedB(this._fftData[a][l]);return r/(s-i+1)/o}getOptions(t){Array.isArray(t)||(t=[t]);let n={};for(const i of Object.keys(Hn))t.includes(i)||(i=="gradient"&&this.gradientLeft!=this.gradientRight?(n.gradientLeft=this.gradientLeft,n.gradientRight=this.gradientRight):i!="start"&&(n[i]=this[i]));return n}registerGradient(t,n){if(typeof t!="string"||t.trim().length==0)throw new Wt(iv);if(typeof n!="object")throw new Wt(sv);const{colorStops:i}=n;if(!Array.isArray(i)||!i.length)throw new Wt(rv);const s=i.length,o=r=>+r!=r||r<0||r>1;i.forEach((r,a)=>{const l=a/Math.max(1,s-1);typeof r!="object"?i[a]={pos:l,color:r}:o(r.pos)&&(r.pos=l),o(r.level)&&(i[a].level=1-a/s)}),i.sort((r,a)=>r.level<a.level?1:r.level>a.level?-1:0),i[0].level=1,this._gradients[t]={bgColor:n.bgColor||Hg,dir:n.dir,colorStops:i},this._selectedGrads.includes(t)&&this._makeGrad()}setCanvasSize(t,n){this._width=t,this._height=n,this._setCanvas(Ar)}setFreqRange(t,n){if(t<1||n<1)throw new Wt(Pr);this._minFreq=Math.min(t,n),this.maxFreq=Math.max(t,n)}setLedParams(t){let n,i,s;t&&(n=t.maxLeds|0,i=+t.spaceV,s=+t.spaceH),this._ledParams=n>0&&i>0&&s>=0?[n,i,s]:void 0,this._calcBars()}setOptions(t){this._setProps(t)}setSensitivity(t,n){for(const i of[0,1])this._analyzer[i].minDecibels=Math.min(t,n),this._analyzer[i].maxDecibels=Math.max(t,n)}start(){this.toggleAnalyzer(!0)}stop(){this.toggleAnalyzer(!1)}toggleAnalyzer(t){const n=this.isOn;return t===void 0&&(t=!n),n&&!t?(cancelAnimationFrame(this._runId),this._runId=0):!n&&t&&!this._destroyed&&(this._frames=0,this._time=performance.now(),this._runId=requestAnimationFrame(i=>this._draw(i))),this.isOn}toggleFullscreen(){if(this.isFullscreen)document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen&&document.webkitExitFullscreen();else{const t=this._fsEl;if(!t)return;t.requestFullscreen?t.requestFullscreen():t.webkitRequestFullscreen&&t.webkitRequestFullscreen()}}_binToFreq(t){return t*this.audioCtx.sampleRate/this.fftSize||1}_calcBars(){const t=this._bars=[];if(!this._ready){this._flg={isAlpha:!1,isBands:!1,isLeds:!1,isLumi:!1,isOctaves:!1,isOutline:!1,isRound:!1,noLedGap:!1};return}const{_ansiBands:n,_barSpace:i,canvas:s,_chLayout:o,_maxFreq:r,_minFreq:a,_mirror:l,_mode:c,_radial:d,_radialInvert:u,_reflexRatio:p}=this,g=s.width>>1,_=s.height>>1,b=o==oe&&!d,w=o==Ri,y=c%10!=0,S=y&&this._frequencyScale==on,C=this._showLeds&&y&&!d,P=this._lumiBars&&y&&!d,L=this._alphaBars&&!P&&c!=rn,D=this._outlineBars&&y&&!P&&!C,x=this._roundBars&&y&&!P&&!C,k=o!=oe||p>0&&!P,f=s.height-(b&&!C?.5:0)>>b,m=f*(P||d?1:1-p)|0,h=s.width-g*(w||l!=0),v=b?s.height-f*2:0,T=g*(l==-1&&!w&&!d);let R=Math.min(s.width,s.height)*.375*(o==oe?1:this._radius)|0,A=Math.min(g,_);u&&o!=oe&&([R,A]=[A,R]);const M=W=>t.push({...W,peak:[0,0],hold:[0],alpha:[0],value:[0]}),I=W=>{const Y=this._freqToBin(W,"floor"),Z=this._binToFreq(Y),tt=this._binToFreq(Y+1),dt=Math.log2(W/Z)/Math.log2(tt/Z);return[Y,dt]};let N,K,F;if(S){const W=(st,ft,it)=>+st.toPrecision(it?Math.max(ft,1+Math.log10(st)|0):ft),Y=st=>{const ft=[1,1.12,1.25,1.4,1.6,1.8,2,2.24,2.5,2.8,3.15,3.55,4,4.5,5,5.6,6.3,7.1,8,9,10],it=Math.log10(st)|0,ce=st/10**it;let Zt=1;for(;Zt<ft.length&&ce>ft[Zt];)Zt++;return ce-ft[Zt-1]<ft[Zt]-ce&&Zt--,(ft[Zt]*10**(it+5)|0)/1e5},Z=[0,24,12,8,6,4,3,2,1][c],tt=n?10**(3/(Z*10)):2**(1/Z),dt=tt**.5;let It=n?7.94328235/(Z%2?1:dt):eu;do{let st=It;const ft=W(st/dt,4,!0),it=W(st*dt,4,!0),[ce,Zt]=I(ft),[Yn,ue]=I(it);n?st=Z<4?Y(st):W(st,st.toString()[0]<5?3:2):st=W(st,4,!0),st>=a&&M({posX:0,freq:st,freqLo:ft,freqHi:it,binLo:ce,binHi:Yn,ratioLo:Zt,ratioHi:ue}),It*=tt}while(It<=r);N=h/t.length,t.forEach((st,ft)=>st.posX=T+ft*N);const ht=t[0],Tt=t[t.length-1];K=this._freqScaling(ht.freqLo),F=h/(this._freqScaling(Tt.freqHi)-K),ht.freqLo<a&&(ht.freqLo=a,[ht.binLo,ht.ratioLo]=I(a)),Tt.freqHi>r&&(Tt.freqHi=r,[Tt.binHi,Tt.ratioHi]=I(r))}else if(y){const W=[0,24,12,8,6,4,3,2,1][c]*10,Y=Z=>{switch(this._frequencyScale){case Rr:return 1960/(26.81/(Z+.53)-1);case Ir:return 700*(2**Z-1);case Un:return Z}};N=h/W,K=this._freqScaling(a),F=h/(this._freqScaling(r)-K);for(let Z=0,tt=0;Z<W;Z++,tt+=N){const dt=Y(K+tt/F),It=Y(K+(tt+N/2)/F),ht=Y(K+(tt+N)/F),[Tt,st]=I(dt),[ft,it]=I(ht);M({posX:T+tt,freq:It,freqLo:dt,freqHi:ht,binLo:Tt,binHi:ft,ratioLo:st,ratioHi:it})}}else{N=1,K=this._freqScaling(a),F=h/(this._freqScaling(r)-K);const W=this._freqToBin(a,"floor"),Y=this._freqToBin(r);let Z=-999;for(let tt=W;tt<=Y;tt++){const dt=this._binToFreq(tt),It=T+Math.round(F*(this._freqScaling(dt)-K));if(It>Z)M({posX:It,freq:dt,freqLo:dt,freqHi:dt,binLo:tt,binHi:tt,ratioLo:0,ratioHi:0}),Z=It;else if(t.length){const ht=t[t.length-1];ht.binHi=tt,ht.freqHi=dt,ht.freq=(ht.freqLo*dt)**.5}}}let rt=0,Q=0;if(C){const W=this._pixelRatio/(window.devicePixelRatio>1&&window.screen.height<=540?2:1),Y=[[],[128,3,.45],[128,4,.225],[96,6,.225],[80,6,.225],[80,6,.125],[64,6,.125],[48,8,.125],[24,16,.125]],Z=this._ledParams,[tt,dt,It]=Z||Y[c];let ht,Tt=m;if(Z){const st=2*W;let ft;ht=tt+1;do ht--,ft=Tt/ht/(1+dt),Q=ft*dt;while((ft<st||Q<st)&&ht>1)}else{const st=540/dt;Q=Math.min(dt*W,Math.max(2,Tt/st+.1|0))}k&&(Tt+=Q),Z||(ht=Math.min(tt,Tt/(Q*2)|0)),rt=It>=1?It:N*It,this._leds=[ht,rt,Q,Tt/ht-Q]}const j=Math.min(N-1,i*(i>0&&i<1?N:1));y&&(N-=Math.max(C?rt:0,j)),t.forEach((W,Y)=>{let Z=W.posX,tt=N;y&&(i==0&&!C?(Z|=0,tt|=0,Y>0&&Z>t[Y-1].posX+t[Y-1].width&&(Z--,tt++)):Z+=Math.max(C?rt:0,j)/2,W.posX=Z),W.barCenter=Z+(N==1?0:tt/2),W.width=tt});const lt=[];for(const W of[0,1]){const Y=o==oe?(f+v)*W:0,Z=Y+f,tt=Y+m-(!C||k?0:Q);lt.push({channelTop:Y,channelBottom:Z,analyzerBottom:tt})}this._aux={analyzerHeight:m,analyzerWidth:h,centerX:g,centerY:_,channelCoords:lt,channelHeight:f,channelGap:v,initialX:T,innerRadius:R,outerRadius:A,scaleMin:K,unitWidth:F},this._flg={isAlpha:L,isBands:y,isLeds:C,isLumi:P,isOctaves:S,isOutline:D,isRound:x,noLedGap:k},this._createScales()}_createScales(){if(!this._ready)return;const{analyzerWidth:t,initialX:n,innerRadius:i,scaleMin:s,unitWidth:o}=this._aux,{canvas:r,_frequencyScale:a,_mirror:l,_noteLabels:c,_radial:d,_scaleX:u,_scaleR:p}=this,g=u.canvas,_=p.canvas,b=[],w=this._chLayout==Ri,y=this._chLayout==oe,S=Math.min(r.width,r.height),C=["C",,"D",,"E","F",,"G",,"A",,"B"],P=S/34|0,L=g.height>>1,D=P>>1,x=L*(c?.7:1.5),k=D*(c?1:2),f=2**(1/12);if(!c&&(this._ansiBands||a!=on))b.push(16,31.5,63,125,250,500,1e3,2e3,4e3),a==Un?b.push(6e3,8e3,1e4,12e3,14e3,16e3,18e3,2e4,22e3):b.push(8e3,16e3);else{let A=eu;for(let M=-1;M<11;M++)for(let I=0;I<12;I++){if(A>=this._minFreq&&A<=this._maxFreq){const N=C[I],K=N=="C";(N&&c&&!l&&!w||K)&&b.push(c?[A,N+(K?M:"")]:A)}A*=f}}_.width=_.height=Math.max(S*.15,(i<<1)+y*P);const m=_.width>>1,h=m-P*.7,v=(A,M)=>{const I=sn*(A/r.width),N=I-Er,K=h*Math.cos(N),F=h*Math.sin(N);p.save(),p.translate(m+K,m+F),p.rotate(I),p.fillText(M,0,0),p.restore()};g.width|=0,u.fillStyle=p.strokeStyle=Kg,u.fillRect(0,0,g.width,g.height),p.arc(m,m,m-P/2,0,sn),p.lineWidth=P,p.stroke(),u.fillStyle=p.fillStyle=gu,u.font=`${L}px ${Pi}`,p.font=`${D}px ${Pi}`,u.textAlign=p.textAlign="center";let T=-x/4,R=-k;for(const A of b){const[M,I]=Array.isArray(A)?A:[A,A<1e3?A|0:`${(A/100|0)/10}k`],N=o*(this._freqScaling(M)-s),K=g.height*.75,F=I[0]=="C",rt=L*(c&&!l&&!w?F?1.2:.6:3);if(u.fillStyle=p.fillStyle=F&&!l&&!w?Xg:gu,c){const Q=a==on,j=a==Un;let lt=["C"];if((Q||M>2e3||!j&&M>250||(!d||y)&&(!j&&M>125||M>1e3))&&lt.push("G"),(Q||M>4e3||!j&&M>500||(!d||y)&&(!j&&M>250||M>2e3))&&lt.push("E"),(j&&M>4e3||(!d||y)&&(Q||M>2e3||!j&&M>500))&&lt.push("D","F","A","B"),!lt.includes(I[0]))continue}N>=T+x/2&&N<=t&&(u.fillText(I,w&&l==-1?t-N:n+N,K,rt),(w||l&&(N>x||l==1))&&u.fillText(I,w&&l!=1?t+N:(n||r.width)-N,K,rt),T=N+Math.min(rt,u.measureText(I).width)/2),N>=R+k&&N<t-k&&(v(w&&l==1?t-N:N,I),(w||l&&(N>k||l==1))&&v(w&&l!=-1?t+N:-N,I),R=N)}}_draw(t){this._runId=requestAnimationFrame(O=>this._draw(O));const n=t-this._time,i=t-this._last,s=this._maxFPS?975/this._maxFPS:0;if(i<s)return;this._last=t-(s?i%s:0),this._frames++,n>=1e3&&(this._fps=this._frames/n*1e3,this._frames=0,this._time=t);const{isAlpha:o,isBands:r,isLeds:a,isLumi:l,isOctaves:c,isOutline:d,isRound:u,noLedGap:p}=this._flg,{analyzerHeight:g,centerX:_,centerY:b,channelCoords:w,channelHeight:y,channelGap:S,initialX:C,innerRadius:P,outerRadius:L}=this._aux,{_bars:D,canvas:x,_canvasGradients:k,_chLayout:f,_colorMode:m,_ctx:h,_energy:v,_fadePeaks:T,fillAlpha:R,_fps:A,_linearAmplitude:M,_lineWidth:I,maxDecibels:N,minDecibels:K,_mirror:F,_mode:rt,overlay:Q,_radial:j,showBgColor:lt,showPeaks:W,useCanvas:Y,_weightingFilter:Z}=this,tt=this._scaleX.canvas,dt=this._scaleR.canvas,It=A*this._peakFadeTime/1e3,ht=A**2,Tt=this._gravity*1e3,st=A*this._peakHoldTime/1e3,ft=f==nu,it=f==Ri,ce=f==oe,Zt=f==me,Yn=a&&this._trueLeds&&m==Ii,ue=j?x.width:this._aux.analyzerWidth,Hr=C+ue,Zn=W&&this._peakLine&&rt==rn,Ce=j?L-P:g,j_=Ce/this._pixelRatio,[$_,X_,Jn,Gr]=this._leds||[];v.val>0&&A>0&&(this._spinAngle+=this._spinSpeed*sn/60/A);const U_=O=>{if(this._reflexRatio>0&&!l&&!j){let et,de;this.reflexFit||ce?(et=ce&&O==0?y+S:0,de=y-g):(et=x.height-g*2,de=g),h.save(),h.globalAlpha=this.reflexAlpha,this.reflexBright!=1&&(h.filter=`brightness(${this.reflexBright})`),h.setTransform(1,0,0,-1,0,x.height),h.drawImage(x,0,w[O].channelTop,x.width,g,0,et,x.width,de),h.restore()}},H_=()=>{this.showScaleX&&(j?(h.save(),h.translate(_,b),this._spinSpeed&&h.rotate(this._spinAngle+Er),h.drawImage(dt,-dt.width>>1,-dt.width>>1),h.restore()):h.drawImage(tt,0,x.height-tt.height))},G_=O=>{const et=O**2,de=424.36,Ct=11599.29,Ui=25122.25,ke=544496.41,ge=148693636,je=$e=>20*Math.log10($e);switch(Z){case cu:const $e=ge*et**2/((et+de)*Math.sqrt((et+Ct)*(et+ke))*(et+ge));return 2+je($e);case uu:const Ue=ge*et*O/((et+de)*Math.sqrt(et+Ui)*(et+ge));return .17+je(Ue);case du:const qr=ge*et/((et+de)*(et+ge));return .06+je(qr);case hu:const Hi=((103791848e-2-et)**2+108076816e-2*et)/((9837328-et)**2+11723776*et),Kr=O/68966888496476e-18*Math.sqrt(Hi/((et+79919.29)*(et+1345600)));return je(Kr);case fu:const Gi=-4737338981378384e-39*O**6+2043828333606125e-30*O**4-1363894795463638e-22*et+1,He=1306612257412824e-34*O**5-2118150887518656e-26*O**3+.0005559488023498642*O,Bt=.0001246332637532143*O/Math.hypot(Gi,He);return 18.2+je(Bt)}return 0},Wr=(O,et,de)=>{h.beginPath(),h.moveTo(O,et),h.lineTo(O,de),h.stroke()},zr=O=>{if(O&&I){const et=h.globalAlpha;h.globalAlpha=1,h.stroke(),h.globalAlpha=et}},Be=O=>Math.max(0,(O*$_|0)*(Gr+Jn)-Jn),W_=O=>{v.val=O,v.peak>0&&(v.hold--,v.hold<0&&(v.peak+=v.hold*Tt/ht/x.height*this._pixelRatio)),O>=v.peak&&(v.peak=O,v.hold=st)};Q&&h.clearRect(0,0,x.width,x.height);let cd=0;const ud=D.length,dd=Zt?1:2;for(let O=0;O<dd;O++){const{channelTop:et,channelBottom:de,analyzerBottom:Ct}=w[O],Ui=this._gradients[this._selectedGrads[O]],ke=Ui.colorStops,ge=ke.length,je=!lt||a&&!Q?"#000":Ui.bgColor,$e=ce&&j&&O?-1:1,Ue=!O&&F==-1||O&&F==1,qr=!it||O&&F!=1?0:ue>>(O||!Ue),Hi=it&&Ue?-1:1,Kr=()=>{const $=tt.height,G=$>>1,z=M?100:N,ct=M?0:K,bt=M?20:5,Nt=g/(z-ct),he=F!=-1&&(!it||O==0||F==1),Te=F!=1&&(!it||O!=F);h.save(),h.fillStyle=vu,h.font=`${G}px ${Pi}`,h.textAlign="right",h.lineWidth=1;for(let Ee=z;Ee>ct;Ee-=bt){const fn=et+(z-Ee)*Nt,xt=Ee%2==0|0;if(xt){const Pt=fn+G*(fn==et?.8:.35);he&&h.fillText(Ee,$*.85,Pt),Te&&h.fillText(Ee,(it?ue:x.width)-$*.1,Pt),h.strokeStyle=vu,h.setLineDash([2,4]),h.lineDashOffset=0}else h.strokeStyle=Yg,h.setLineDash([2,8]),h.lineDashOffset=1;h.beginPath(),h.moveTo(C+$*xt*he,~~fn+.5),h.lineTo(Hr-$*xt*Te,~~fn+.5),h.stroke()}h.restore()},Gi=($,G)=>{const z=Jt[$]+($<Jt.length-1?(Jt[$+1]-Jt[$])*G:0);return isNaN(z)?-1/0:z},He=($,G=Hi)=>G*sn*(($+qr)/x.width)+this._spinAngle,Bt=($,G,z)=>{const ct=P+G*$e,bt=He($,z);return[_+ct*Math.cos(bt),b+ct*Math.sin(bt)]},Xr=($,G,z,ct,bt)=>{h.beginPath();for(const Nt of F&&!it?[1,-1]:[Hi]){const[he,Te]=u?[He($,Nt),He($+z,Nt)]:[];h.moveTo(...Bt($,G,Nt)),h.lineTo(...Bt($,G+ct,Nt)),u?h.arc(_,b,P+(G+ct)*$e,he,Te,Nt!=1):h.lineTo(...Bt($+z,G+ct,Nt)),h.lineTo(...Bt($+z,G,Nt)),u&&!bt&&h.arc(_,b,P+G*$e,Te,he,Nt==1)}zr(bt),h.fill()},Yr=($=0,G=0)=>{let z;if(m==Ii&&!Yn||rt==rn)z=k[O];else{const ct=m==iu?G%ge:ke.findLastIndex(bt=>a?Be($)<=Be(bt.level):$<=bt.level);z=ke[ct].color}h.fillStyle=h.strokeStyle=z};if(Y){if(it&&!j){const $=ue*(O+Ue),G=Ue?-1:1;h.setTransform(G,0,0,1,$,0)}if((!Q||lt)&&(Q&&(h.globalAlpha=this.bgAlpha),h.fillStyle=je,(O==0||!j&&!ft)&&h.fillRect(C,et-S,ue,(Q&&this.reflexAlpha==1?g:y)+S),h.globalAlpha=1),this.showScaleY&&!l&&!j&&(O==0||!ft)&&Kr(),a?(h.setLineDash([Gr,Jn]),h.lineWidth=D[0].width):h.lineWidth=d?Math.min(I,D[0].width/2):I,h.save(),!j){const $=new Path2D;$.rect(0,et,x.width,g),h.clip($)}}let Jt=this._fftData[O];this._analyzer[O].getFloatFrequencyData(Jt),Z&&(Jt=Jt.map(($,G)=>$+G_(this._binToFreq(G)))),h.beginPath();let Qn=[];for(let $=0;$<ud;$++){const G=D[$],{posX:z,barCenter:ct,width:bt,freq:Nt,binLo:he,binHi:Te,ratioLo:Ee,ratioHi:fn}=G;let xt=Math.max(Gi(he,Ee),Gi(Te,fn));for(let ot=he+1;ot<Te;ot++)Jt[ot]>xt&&(xt=Jt[ot]);if(xt=this._normalizedB(xt),G.value[O]=xt,cd+=xt,G.peak[O]>0&&G.alpha[O]>0&&(G.hold[O]--,G.hold[O]<0)){if(T&&!Zn){const ot=!o||d&&I>0?1:o?G.peak[O]:R;G.alpha[O]=ot*(1+G.hold[O]/It)}else G.peak[O]+=G.hold[O]*Tt/ht/j_;G.alpha[O]<=0&&(G.peak[O]=0)}if(xt>=G.peak[O]&&(G.peak[O]=xt,G.hold[O]=st,G.alpha[O]=!o||d&&I>0?1:o?xt:R),!Y)continue;h.globalAlpha=l||o?xt:d?R:1,Yr(xt,$);const Pt=l?Ce:a?Be(xt):xt*Ce|0;if(rt==rn){const ot=$?0:(this._normalizedB(Jt[D[1].binLo])*Ce+Pt)/2;if(j){if($==0&&(it&&h.moveTo(...Bt(0,0)),h.lineTo(...Bt(0,z<0?ot:Pt))),z>=0){const qt=[z,Pt];h.lineTo(...Bt(...qt)),Qn.push(qt)}}else{if($==0)if(F==-1&&!it)h.moveTo(C,Ct-(z<C?ot:Pt));else{const qt=he?this._normalizedB(Jt[he-1])*Ce:Pt;h.moveTo(C-I,Ct-qt)}(it||F!=-1||z>=C)&&h.lineTo(z,Ct-Pt)}}else if(a){if(lt&&!Q&&(O==0||!ft)){const ot=h.globalAlpha;h.strokeStyle=Wg,h.globalAlpha=1,Wr(ct,et,Ct),h.strokeStyle=h.fillStyle,h.globalAlpha=ot}if(Yn){const ot=l?0:ke.findLastIndex(Ge=>Be(xt)<=Be(Ge.level));let qt=Ct;for(let Ge=ge-1;Ge>=ot;Ge--){h.strokeStyle=ke[Ge].color;let fd=Ct-(Ge==ot?Pt:Be(ke[Ge].level));Wr(ct,qt,fd),qt=fd-Jn}}else Wr(ct,Ct,Ct-Pt)}else if(z>=C)if(j)Xr(z,0,bt,Pt,d);else if(u){const ot=bt/2,qt=Ct+ot;h.beginPath(),h.moveTo(z,qt),h.lineTo(z,qt-Pt),h.arc(ct,qt-Pt,ot,Tr,sn),h.lineTo(z+bt,qt),zr(d),h.fill()}else{const ot=d?h.lineWidth:0;h.beginPath(),h.rect(z,Ct+ot,bt,-Pt-ot),zr(d),h.fill()}const pn=G.peak[O],hd=G.alpha[O];if(pn>0&&hd>0&&W&&!Zn&&!l&&z>=C&&z<Hr){if(T?h.globalAlpha=hd:d&&I>0?h.globalAlpha=1:o&&(h.globalAlpha=pn),(m==su||Yn)&&Yr(pn),a){const ot=Be(pn);ot>=Jn&&h.fillRect(z,Ct-ot,bt,Gr)}else if(!j)h.fillRect(z,Ct-pn*Ce,bt,2);else if(rt!=rn){const ot=pn*Ce;Xr(z,ot,bt,!this._radialInvert||ce||ot+P>=2?-2:2)}}}if(Y){if(h.globalAlpha=1,rt==rn){if(Yr(),j&&!it){if(F){let $;for(;$=Qn.pop();)h.lineTo(...Bt(...$,-1))}h.closePath()}if(I>0&&h.stroke(),R>0){if(j){const $=it?He(ue>>1):0,G=it?He(ue):sn;h.moveTo(...Bt(it?ue>>1:0,0)),h.arc(_,b,P,$,G,it?!Ue:!0)}else h.lineTo(Hr,Ct),h.lineTo(C,Ct);h.globalAlpha=R,h.fill(),h.globalAlpha=1}if((Zn||j&&W)&&(Qn=[],h.beginPath(),D.forEach(($,G)=>{let z=$.posX,ct=$.peak[O],bt=G?"lineTo":"moveTo";if(j&&z<0){const Nt=D[G+1];ct=ov(z,ct,Nt.posX,Nt.peak[O],0),z=0}ct*=Ce,Zn?(h[bt](...j?Bt(z,ct):[z,Ct-ct]),j&&F&&!it&&Qn.push([z,ct])):ct>0&&Xr(z,ct,1,-2)}),Zn)){let $;for(;$=Qn.pop();)h.lineTo(...Bt(...$,-1));h.lineWidth=1,h.stroke()}}h.restore(),it&&!j&&h.setTransform(1,0,0,1,0,0),(!it&&!ft||O)&&U_(O)}}if(W_(cd/(ud<<dd-1)),Y&&(F&&!j&&!it&&(h.setTransform(-1,0,0,1,x.width-C,0),h.drawImage(x,C,0,_,x.height,0,0,_,x.height),h.setTransform(1,0,0,1,0,0)),h.setLineDash([]),H_()),this.showFPS){const O=tt.height;h.font=`bold ${O}px ${Pi}`,h.fillStyle=Gg,h.textAlign="right",h.fillText(Math.round(A),x.width-O,O*2)}this.onCanvasDraw&&(h.save(),h.fillStyle=h.strokeStyle=k[0],this.onCanvasDraw(this,{timestamp:t,canvasGradients:k}),h.restore())}_freqScaling(t){switch(this._frequencyScale){case on:return Math.log2(t);case Rr:return 26.81*t/(1960+t)-.53;case Ir:return Math.log2(1+t/700);case Un:return t}}_freqToBin(t,n="round"){const i=this._analyzer[0].frequencyBinCount-1,s=Math[n](t*this.fftSize/this.audioCtx.sampleRate);return s<i?s:i}_makeGrad(){if(!this._ready)return;const{canvas:t,_ctx:n,_radial:i,_reflexRatio:s}=this,{analyzerWidth:o,centerX:r,centerY:a,initialX:l,innerRadius:c,outerRadius:d}=this._aux,{isLumi:u}=this._flg,p=this._chLayout==oe,g=1-s,_=u?t.height:t.height*(1-s*!p)|0;for(const b of[0,1]){const w=this._gradients[this._selectedGrads[b]],y=w.colorStops,S=w.dir=="h";let C;if(i?C=n.createRadialGradient(r,a,d,r,a,c-(d-c)*p):C=n.createLinearGradient(...S?[l,0,l+o,0]:[0,0,0,_]),y){const P=p&&!this._splitGradient&&(!S||i);for(let L=0;L<1+P;L++){const D=y.length-1;y.forEach((x,k)=>{let f=x.pos;if(P&&(f/=2),p&&!u&&!i&&!S&&(f*=g,!P&&f>.5*g&&(f+=.5*s)),L==1)if(i||u){const m=D-k;x=y[m],f=1-x.pos/2}else k==0&&f>0&&C.addColorStop(.5,x.color),f+=.5;C.addColorStop(f,x.color),p&&k==D&&f<.5&&C.addColorStop(.5,x.color)})}}this._canvasGradients[b]=C}}_normalizedB(t){const n=this._linearAmplitude,i=n?1/this._linearBoost:1,s=(l,c,d)=>l<=c?c:l>=d?d:l,o=l=>10**(l/20);let r=this.maxDecibels,a=this.minDecibels;return n&&(r=o(r),a=o(a),t=o(t)**i),s((t-a)/(r-a)**i,0,1)}_setCanvas(t){if(!this._ready)return;const{canvas:n,_ctx:i}=this,s=this._scaleX.canvas,o=window.devicePixelRatio/(this._loRes+1);let r=window.screen.width*o,a=window.screen.height*o;Math.abs(window.orientation)==90&&r<a&&([r,a]=[a,r]);const l=this.isFullscreen,c=l&&this._fsEl==n,d=c?r:(this._width||this._container.clientWidth||this._defaultWidth)*o|0,u=c?a:(this._height||this._container.clientHeight||this._defaultHeight)*o|0;this._pixelRatio=o,this._fsWidth=r,this._fsHeight=a,!(t!=pu&&n.width==d&&n.height==u)&&(n.width=d,n.height=u,this.overlay||(i.fillStyle="#000",i.fillRect(0,0,d,u)),i.lineJoin="bevel",s.width=d,s.height=Math.max(20*o,Math.min(d,u)/32|0),this._calcBars(),this._makeGrad(),this._fsStatus!==void 0&&this._fsStatus!==l&&(t=mu),this._fsStatus=l,this.onCanvasResize&&this.onCanvasResize(t,this))}_setGradient(t,n){if(!this._gradients.hasOwnProperty(t))throw new Wt(Qg,t);[0,1].includes(n)||(this._selectedGrads[1]=t,n=0),this._selectedGrads[n]=t,this._makeGrad()}_setProps(t,n){const i=["onCanvasDraw","onCanvasResize"],s=["gradientLeft","gradientRight","stereo"],o=Object.keys(Hn).filter(r=>r!="start").concat(i,s);(n||t===void 0)&&(t={...Hn,...t});for(const r of Object.keys(t))i.includes(r)&&typeof t[r]!="function"?this[r]=void 0:o.includes(r)&&(this[r]=t[r]);t.start!==void 0&&this.toggleAnalyzer(t.start)}}const lv={verdant:{colorStops:[{color:"#D3FFA6",pos:0},{color:"#036B5B",pos:.5},{color:"#D3FFA6",pos:1}]},twilight:{colorStops:[{color:"#81B9FF",pos:0},{color:"#371A5E",pos:.5},{color:"#81B9FF",pos:1}]},bloom:{colorStops:[{color:"#FFD4FE",pos:0},{color:"#FD05F9",pos:.5},{color:"#FFD4FE",pos:1}]},mystic:{colorStops:[{color:"#1F023A",pos:0},{color:"#CA76FF",pos:.5},{color:"#1F023A",pos:1}]},flare:{colorStops:[{color:"#FFFFFF",pos:0},{color:"#FC5F00",pos:.5},{color:"#FFFFFF",pos:1}]},glacier:{colorStops:[{color:"#4CE5F2",pos:0},{color:"#005A98",pos:.5},{color:"#4CE5F2",pos:1}]}},xu=({stream:e,className:t,onClick:n})=>{var o;const i=Mt(null),s=Ne();return $t(()=>{var c;if(!i.current||!e)return;const r=new AudioContext,a=r.createMediaStreamSource(e),l=new av(i.current,{source:a,audioCtx:r,alphaBars:!1,ansiBands:!1,barSpace:.25,bgAlpha:0,channelLayout:"single",colorMode:"gradient",fadePeaks:!1,fftSize:2048,fillAlpha:0,frequencyScale:"log",gravity:3.8,ledBars:!1,linearAmplitude:!0,linearBoost:2,lineWidth:1.5,loRes:!1,lumiBars:!1,maxDecibels:-20,maxFPS:0,maxFreq:16e3,minDecibels:-90,minFreq:30,mirror:0,mode:7,noteLabels:!1,outlineBars:!1,overlay:!0,peakFadeTime:750,peakHoldTime:500,peakLine:!1,radial:!1,radialInvert:!1,radius:.7,reflexAlpha:1,reflexBright:1,reflexFit:!0,reflexRatio:.5,roundBars:!0,showBgColor:!1,showFPS:!1,showPeaks:!1,showScaleX:!1,showScaleY:!1,smoothing:.7,spinSpeed:0,splitGradient:!1,trueLeds:!1,useCanvas:!0,volume:1,weightingFilter:"D"});return l.registerGradient("gradient",lv[((c=s.audio_visualizer_config)==null?void 0:c.color)||"verdant"]),l.gradient="gradient",()=>{l.destroy()}},[(o=s.audio_visualizer_config)==null?void 0:o.color,e]),E("div",{onClick:n,className:xe("w-full",t),ref:i})};/**
17
17
  * @license lucide-preact v0.515.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
@@ -114,4 +114,4 @@ b=`+c+":"+d+`\r
114
114
  `),void this._requestAnotherLocalDescription();(i=(n=this.peer)===null||n===void 0?void 0:n.instance)===null||i===void 0||i.removeEventListener("icecandidate",this._onIce);let r=null;const a={sessid:this.session.sessionid,sdp:s,dialogParams:this.options,"User-Agent":`Web-${p_}`};switch(o){case Ft.Offer:this.setState(X.Requesting),r=new Jv(a);break;case Ft.Answer:this.setState(X.Answering),r=this.options.attach===!0?new t_(a):new Qv(a);break;default:return B.error(`${this.id} - Unknown local SDP type:`,t),this.hangup({},!1)}this._execute(r).then(l=>{const{node_id:c=null}=l;this._targetNodeId=c,o===Ft.Offer?this.setState(X.Trying):this.setState(X.Active)}).catch(l=>{B.error(`${this.id} - Sending ${o} error:`,l),this.hangup()}),console.timeEnd(Pu)}_onIce(t){const{instance:n}=this.peer;this._iceTimeout===null&&(this._iceTimeout=setTimeout(()=>this._onIceSdp(n.localDescription),1e3)),t.candidate?B.debug("RTCPeer Candidate:",t.candidate):this._onIceSdp(n.localDescription)}_registerPeerEvents(){const{instance:t}=this.peer;this._iceDone=!1,t.onicecandidate=n=>{this._iceDone||this._onIce(n)},t.addEventListener("addstream",n=>{this.options.remoteStream=n.stream}),t.addEventListener("track",n=>{this.options.remoteStream=n.streams[0];const{remoteElement:i,remoteStream:s,screenShare:o}=this.options;o===!1&&Vi(i,s)})}_onMediaError(t){this._dispatchNotification({type:ae.userMediaError,error:t}),this.hangup({},!1)}_dispatchConferenceUpdate(t){this._dispatchNotification(Object.assign({type:ae.conferenceUpdate,call:this},t))}_dispatchNotification(t){this.options.screenShare!==!0&&(J(V.Notification,t,this.id,!1)||J(V.Notification,t,this.session.uuid))}_execute(t){return this.nodeId&&(t.targetNodeId=this.nodeId),this.session.execute(t)}_init(){const{id:t,userVariables:n,remoteCallerNumber:i,onNotification:s}=this.options;t||(this.options.id=an()),this.id=this.options.id,n&&!Ou(n)||(this.options.userVariables=this.session.options.userVariables||{}),i||(this.options.remoteCallerNumber=this.options.destinationNumber),this.session.calls[this.id]=this,un(V.MediaError,this._onMediaError,this.id),ln(s)&&un(V.Notification,s.bind(this),this.id),this.setState(X.New),B.info("New Call with Options:",this.options)}_finalize(){this._stopStats(),this.peer&&this.peer.instance&&(this.peer.instance.close(),this.peer=null);const{remoteStream:t,localStream:n}=this.options;Kn(t),Kn(n),dn(V.MediaError,null,this.id),this.session.calls[this.id]=null,delete this.session.calls[this.id]}_startStats(t){this._statsIntervalId=setInterval(this._doStats,t),B.info("Stats started")}_stopStats(){this._statsIntervalId&&(clearInterval(this._statsIntervalId),this._statsIntervalId=null),B.info("Stats stopped")}}od.setStateTelnyx=e=>{if(e){switch(e._state){case X.Requesting:case X.Recovering:case X.Trying:case X.Early:e.state="connecting";break;case X.Active:e.state="active";break;case X.Held:e.state="held";break;case X.Hangup:case X.Destroy:e.state="done";break;case X.Answering:e.state="ringing";break;case X.New:e.state="new"}return e}};class Fe extends od{constructor(){super(...arguments),this._statsInterval=null,this.sendConversationMessage=(t,n)=>this.session.execute(new r_(t,n))}hangup(t={},n=!0){this.screenShare instanceof Fe&&this.screenShare.hangup(t,n),super.hangup(t,n)}startScreenShare(t){return H(this,void 0,void 0,function*(){const n=yield(i={video:!0},navigator.mediaDevices.getDisplayMedia(i));var i;n.getTracks().forEach(c=>{c.addEventListener("ended",()=>{this.screenShare&&this.screenShare.hangup()})});const{remoteCallerName:s,remoteCallerNumber:o,callerName:r,callerNumber:a}=this.options,l=Object.assign({screenShare:!0,localStream:n,destinationNumber:`${this.extension}-screen`,remoteCallerName:s,remoteCallerNumber:`${o}-screen`,callerName:`${r} (Screen)`,callerNumber:`${a} (Screen)`},t);return this.screenShare=new Fe(this.session,l),this.screenShare.invite(),this.screenShare})}stopScreenShare(){this.screenShare instanceof Fe&&this.screenShare.hangup()}setAudioOutDevice(t){return H(this,void 0,void 0,function*(){this.options.speakerId=t;const{remoteElement:n,speakerId:i}=this.options;return!(!n||!i)&&Wu(n,i)})}_finalize(){this._stats(!1),super._finalize()}_stats(t=!0){if(t===!1)return clearInterval(this._statsInterval);B.setLevel(2),this._statsInterval=window.setInterval(()=>H(this,void 0,void 0,function*(){const n=yield this.peer.instance.getStats(null);let i="";const s=["certificate","codec","peer-connection","stream","local-candidate","remote-candidate"],o=["id","type","timestamp"];n.forEach(r=>{s.includes(r.type)||(i+=`
115
115
  ${r.type}
116
116
  `,Object.keys(r).forEach(a=>{o.includes(a)||(i+=` ${a}: ${r[a]}
117
- `)}))}),B.info(i)}),2e3)}}class m_ extends qv{constructor(t){super(t),this.calls={},this.autoRecoverCalls=!0,this._iceServers=[],this._localElement=null,this._remoteElement=null,this._jwtAuth=!0,this._audioConstraints=!0,this._videoConstraints=!1,this._speaker=null,this.iceServers=t.iceServers,this.ringtoneFile=t.ringtoneFile,this.ringbackFile=t.ringbackFile}get reconnectDelay(){return 1e3}connect(){const t=Object.create(null,{connect:{get:()=>super.connect}});return H(this,void 0,void 0,function*(){t.connect.call(this)})}checkPermissions(t=!0,n=!0){return H(this,void 0,void 0,function*(){try{const i=yield Fi({audio:t,video:n});return Kn(i),!0}catch{return!1}})}logout(){this.disconnect()}disconnect(){const t=Object.create(null,{disconnect:{get:()=>super.disconnect}});return H(this,void 0,void 0,function*(){Object.keys(this.calls).forEach(n=>this.calls[n].setState(X.Purge)),this.calls={},yield t.disconnect.call(this)})}speedTest(t){return new Promise((n,i)=>{if($u(V.SpeedTest,r=>{const{upDur:a,downDur:l}=r,c=l?8*t/(l/1e3)/1024:0;n({upDur:a,downDur:l,upKps:(a?8*t/(a/1e3)/1024:0).toFixed(0),downKps:c.toFixed(0)})},this.uuid),!(t=Number(t)))return i(`Invalid parameter 'bytes': ${t}`);this.executeRaw(`#SPU ${t}`);let s=t/1024;t%1024&&s++;const o=".".repeat(1024);for(let r=0;r<s;r++)this.executeRaw(`#SPB ${o}`);this.executeRaw("#SPE")})}getDevices(){return Xn().catch(t=>(J(V.MediaError,t,this.uuid),[]))}getVideoDevices(){return Xn(le.Video).catch(t=>(J(V.MediaError,t,this.uuid),[]))}getAudioInDevices(){return Xn(le.AudioIn).catch(t=>(J(V.MediaError,t,this.uuid),[]))}getAudioOutDevices(){return Xn(le.AudioOut).catch(t=>(console.error("getAudioOutDevices",t),J(V.MediaError,t,this.uuid),[]))}validateDeviceId(t,n,i){return Bi(t,n,i)}getDeviceResolutions(t){return H(this,void 0,void 0,function*(){try{return yield(n=>H(void 0,void 0,void 0,function*(){const i=[],s=yield Fi({video:{deviceId:{exact:n}}}),o=s.getVideoTracks()[0];for(let r=0;r<zu.length;r++){const[a,l]=zu[r];(yield o.applyConstraints({width:{exact:a},height:{exact:l}}).then(()=>!0).catch(()=>!1))&&i.push({resolution:`${a}x${l}`,width:a,height:l})}return Kn(s),i}))(t)}catch(n){throw n}})}get mediaConstraints(){return{audio:this._audioConstraints,video:this._videoConstraints}}setAudioSettings(t){return H(this,void 0,void 0,function*(){if(!t)throw new Error("You need to provide the settings object");const{micId:n,micLabel:i}=t,s=Mr(t,["micId","micLabel"]);return qu(s),this._audioConstraints=yield Ku(n,i,"audioinput",s),this.micId=n,this.micLabel=i,this._audioConstraints})}disableMicrophone(){this._audioConstraints=!1}enableMicrophone(){this._audioConstraints=!0}setVideoSettings(t){return H(this,void 0,void 0,function*(){if(!t)throw new Error("You need to provide the settings object");const{camId:n,camLabel:i}=t,s=Mr(t,["camId","camLabel"]);return qu(s),this._videoConstraints=yield Ku(n,i,"videoinput",s),this.camId=n,this.camLabel=i,this._videoConstraints})}disableWebcam(){this._videoConstraints=!1}enableWebcam(){this._videoConstraints=!0}set iceServers(t){const n={urls:["stun:stun.l.google.com:19302"]};this._iceServers=typeof t=="boolean"?t?[n]:[]:t||[Lu,Dv,n]}get iceServers(){return this._iceServers}set speaker(t){this._speaker=t}get speaker(){return this._speaker}set localElement(t){this._localElement=Gn(t)}get localElement(){return this._localElement}set remoteElement(t){this._remoteElement=Gn(t)}get remoteElement(){return this._remoteElement}vertoBroadcast({nodeId:t,channel:n="",data:i}){if(!n)throw new Error(`Invalid channel for broadcast: ${n}`);const s=new n_({sessid:this.sessionid,eventChannel:n,data:i});t&&(s.targetNodeId=t),this.execute(s).catch(o=>o)}vertoSubscribe({nodeId:t,channels:n=[],handler:i}){return H(this,void 0,void 0,function*(){if(!(n=n.filter(l=>l&&!this._existsSubscription(this.relayProtocol,l))).length)return{};const s=new i_({sessid:this.sessionid,eventChannel:n});t&&(s.targetNodeId=t);const o=yield this.execute(s),{unauthorized:r=[],subscribed:a=[]}=Br(o);return r.length&&r.forEach(l=>this._removeSubscription(this.relayProtocol,l)),a.forEach(l=>this._addSubscription(this.relayProtocol,i,l)),o})}vertoUnsubscribe({nodeId:t,channels:n=[]}){return H(this,void 0,void 0,function*(){if(!(n=n.filter(a=>a&&this._existsSubscription(this.relayProtocol,a))).length)return{};const i=new s_({sessid:this.sessionid,eventChannel:n});t&&(i.targetNodeId=t);const s=yield this.execute(i),{unsubscribed:o=[],notSubscribed:r=[]}=Br(s);return o.forEach(a=>this._removeSubscription(this.relayProtocol,a)),r.forEach(a=>this._removeSubscription(this.relayProtocol,a)),s})}static telnyxStateCall(t){return Fe.setStateTelnyx(t)}}class ad{constructor(t,n){this.code=n,this.message=t}}class g_ extends Ot{constructor(){super(),this.method=nt.Ping,this.buildRequest({method:this.method,params:{}})}}class zt{constructor(t){this.session=t}_ack(t,n){const i=new Zv(t,n);this.nodeId&&(i.targetNodeId=this.nodeId),this.session.execute(i)}reconnectDelay(){return 1e3*Fu(2,6)}handleMessage(t){const{session:n}=this,{id:i,method:s,params:o={}}=t,r=o==null?void 0:o.callID,a=o==null?void 0:o.eventChannel,l=o==null?void 0:o.eventType,c=s===nt.Attach;if(l==="channelPvtData")return this._handlePvtEvent(o.pvtData);if(r&&n.calls.hasOwnProperty(r)){if(!c)return n.calls[r].handleMessage(t),void this._ack(i,s);n.calls[r].hangup({},!1)}const d=()=>{var g,_,b,w;const y={id:r,remoteSdp:o.sdp,destinationNumber:o.callee_id_number,remoteCallerName:o.caller_id_name,remoteCallerNumber:o.caller_id_number,callerName:o.callee_id_name,callerNumber:o.callee_id_number,attach:c,mediaSettings:o.mediaSettings,debug:(g=n.options.debug)!==null&&g!==void 0&&g,debugOutput:(_=n.options.debugOutput)!==null&&_!==void 0?_:"socket",prefetchIceCandidates:(b=n.options.prefetchIceCandidates)!==null&&b!==void 0&&b,forceRelayCandidate:(w=n.options.forceRelayCandidate)!==null&&w!==void 0&&w};o.telnyx_call_control_id&&(y.telnyxCallControlId=o.telnyx_call_control_id),o.telnyx_session_id&&(y.telnyxSessionId=o.telnyx_session_id),o.telnyx_leg_id&&(y.telnyxLegId=o.telnyx_leg_id),o.client_state&&(y.clientState=o.client_state),o.dialogParams&&o.dialogParams.custom_headers&&o.dialogParams.custom_headers.length&&(y.customHeaders=o.dialogParams.custom_headers);const S=new Fe(n,y);return S.nodeId=this.nodeId,S},u=new Gu,p=new g_;switch(s){case nt.Ping:this.session.execute(p);break;case nt.Punt:n.disconnect();break;case nt.Invite:{const b=d();b.playRingtone(),b.setState(X.Ringing),b.direction=Se.Inbound,this._ack(i,s);break}case nt.Attach:{const b=d();this.session.autoRecoverCalls?b.answer():b.setState(X.Recovering),b.handleMessage(t);break}case nt.Event:case"webrtc.event":if(!a)return void B.error("Verto received an unknown event:",o);const g=n.relayProtocol,_=a.split(".")[0];n._existsSubscription(g,a)?J(g,o,a):a===n.sessionid?this._handleSessionEvent(o.eventData):n._existsSubscription(g,_)?J(g,o,_):n.calls.hasOwnProperty(a)?n.calls[a].handleMessage(t):J(V.Notification,o,n.uuid);break;case nt.Info:o.type=ae.generic,J(V.Notification,o,n.uuid);break;case nt.ClientReady:this.session.execute(u);break;default:{const b=Dr(t);if(b){switch(b){case Rt.REGISTER:case Rt.REGED:n.connection.previousGatewayState!==Rt.REGED&&n.connection.previousGatewayState!==Rt.REGISTER&&(zt.retriedRegister=0,o.type=ae.vertoClientReady,J(V.Ready,o,n.uuid));break;case Rt.UNREGED:case Rt.NOREG:if(zt.retriedRegister+=1,zt.retriedRegister===5){zt.retriedRegister=0,J(V.Error,{error:new ad("Fail to register the user, the server tried 5 times","UNREGED|NOREG"),sessionId:n.sessionid},n.uuid);break}setTimeout(()=>{this.session.execute(u)},this.reconnectDelay());break;case Rt.FAILED:case Rt.FAIL_WAIT:if(n.connection.previousGatewayState!==Rt.FAILED&&n.connection.previousGatewayState!==Rt.FAIL_WAIT){if(!this.session.hasAutoReconnect()){zt.retriedConnect=0,J(V.Error,{error:new ad("Fail to connect the server, the server tried 5 times","FAILED|FAIL_WAIT"),sessionId:n.sessionid},n.uuid);break}if(zt.retriedConnect+=1,zt.retriedConnect===5){zt.retriedConnect=0,J(V.Error,{error:new Error("Connection Retry Failed"),sessionId:n.sessionid},n.uuid);break}setTimeout(()=>{this.session.disconnect().then(()=>{this.session.clearConnection(),this.session.connect()})},this.reconnectDelay())}break;default:B.warn("GatewayState message unknown method:",t)}break}B.debug("Verto message unknown method:",t);break}}}_retrieveCallId(t,n){const i=Object.keys(this.session.calls);if(t.action!=="bootObj")return i.find(s=>this.session.calls[s].channels.includes(n));{const s=t.data.find(o=>i.includes(o[0]));if(s instanceof Array)return s[0]}}_handlePvtEvent(t){return H(this,void 0,void 0,function*(){const{session:n}=this,i=n.relayProtocol,{action:s,laChannel:o,laName:r,chatChannel:a,infoChannel:l,modChannel:c,conferenceMemberID:d,role:u,callID:p}=t;switch(s){case"conference-liveArray-join":{const g=()=>{n.vertoBroadcast({nodeId:this.nodeId,channel:o,data:{liveArray:{command:"bootstrap",context:o,name:r}}})},_={nodeId:this.nodeId,channels:[o],handler:({data:w})=>{const y=p||this._retrieveCallId(w,o);if(y&&n.calls.hasOwnProperty(y)){const S=n.calls[y];S._addChannel(o),S.extension=r,S.handleConferenceUpdate(w,t).then(C=>{C==="INVALID_PACKET"&&g()})}}},b=yield n.vertoSubscribe(_).catch(w=>{B.error("liveArray subscription error:",w)});ji(b,o)&&g();break}case"conference-liveArray-part":{let g=null;if(o&&n._existsSubscription(i,o)){const{callId:b=null}=n.subscriptions[i][o];if(g=n.calls[b]||null,b!==null){const w={type:ae.conferenceUpdate,action:At.Leave,conferenceName:r,participantId:Number(d),role:u};J(V.Notification,w,b,!1)||J(V.Notification,w,n.uuid),g===null&&dn(V.Notification,null,b)}}const _=[o,a,l,c];n.vertoUnsubscribe({nodeId:this.nodeId,channels:_}).then(({unsubscribedChannels:b=[]})=>{g&&(g.channels=g.channels.filter(w=>!b.includes(w)))}).catch(b=>{B.error("liveArray unsubscribe error:",b)});break}}})}_handleSessionEvent(t){switch(t.contentType){case"layout-info":case"layer-info":id(this.session,t);break;case"logo-info":{const n={type:ae.conferenceUpdate,action:At.LogoInfo,logo:t.logoURL};J(V.Notification,n,this.session.uuid);break}}}}zt.retriedConnect=0,zt.retriedRegister=0;class v_ extends Ot{constructor(t){super(),this.method="anonymous_login";const{target_type:n,target_id:i,target_version_id:s,userVariables:o,sessionId:r,reconnection:a}=t,l={target_type:n,target_id:i,userVariables:o,reconnection:a,"User-Agent":{sdkVersion:jr,data:navigator.userAgent}};r&&(l.sessid=r),s&&(l.target_version_id=s),this.buildRequest({method:this.method,params:l})}}class __ extends m_{constructor(t){super(t),this.relayProtocol="verto-protocol",this.timeoutErrorCode=-329990,this.handleLoginOnSocketOpen=()=>H(this,void 0,void 0,function*(){this._idle=!1;const{login:n,password:i,passwd:s,login_token:o,userVariables:r,autoReconnect:a=!0}=this.options,l=new Yv(n,i||s,o,this.sessionid,r,!!Nr()),c=yield this.execute(l).catch(this._handleLoginError);c&&(this._autoReconnect=a,this.sessionid=c.sessid)}),this.handleAnonymousLoginOnSocketOpen=()=>H(this,void 0,void 0,function*(){this._idle=!1;const{anonymous_login:n}=this.options,i=new v_({target_id:n.target_id,target_type:n.target_type,target_version_id:n.target_version_id,sessionId:this.sessionid,userVariables:this.options.userVariables,reconnection:!!Nr()}),s=yield this.execute(i).catch(this._handleLoginError);s&&(this.sessionid=s.sessid)}),window.addEventListener("beforeunload",n=>{this.calls&&Object.keys(this.calls).forEach(i=>{this.calls[i]&&this.calls[i].hangup({},!0)})})}validateOptions(){return Lr(this.options)||Oi(this.options)}newCall(t){if(!this.validateCallOptions(t))throw new Error("Verto.newCall() error: destinationNumber is required.");console.time(Pu);const n=new Fe(this,t);return n.invite(),n}broadcast(t){return this.vertoBroadcast(t)}subscribe(t){return this.vertoSubscribe(t)}unsubscribe(t){return this.vertoUnsubscribe(t)}validateCallOptions(t){return!!Oi(this.options)||!!t.destinationNumber}_onSocketOpen(){return H(this,void 0,void 0,function*(){return Lr(this.options)?this.handleLoginOnSocketOpen():Oi(this.options)?this.handleAnonymousLoginOnSocketOpen():void 0})}_onSocketMessage(t){new zt(this).handleMessage(t)}}class y_ extends __{constructor(t){super(t),console.log(`SDK version: ${ed}`)}newCall(t){return super.newCall(t)}static webRTCInfo(){return Xv()}static webRTCSupportedBrowserList(){return[{operationSystem:"Android",supported:[{browserName:"Chrome",features:["audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"iOS",supported:[{browserName:"Chrome",supported:vt.not_supported},{browserName:"Firefox",supported:vt.not_supported},{browserName:"Safari",features:["video","audio"],supported:vt.full},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"Linux",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"MacOS",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",features:["video","audio"],supported:vt.full},{browserName:"Edge",features:["audio"],supported:vt.partial}]},{operationSystem:"Windows",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",features:["audio"],supported:vt.partial}]}]}}function b_(e){if(!e||typeof e!="object")return!1;const t=e;return t.method==="ai_conversation"&&typeof t.params=="object"}function w_(e){if(!e||typeof e!="object")return!1;const t=e;return t.params.type!=="response.text.delta"?!1:!!t.params.delta}function x_(e){if(!e||typeof e!="object")return!1;const t=e;return t.params.type!=="conversation.item.created"?!1:!!t.params.item.content}function S_(e){return w_(e)?{id:e.params.item_id,role:"assistant",content:e.params.delta,timestamp:new Date}:null}function C_(e){if(!x_(e)||e.params.item.role!=="user"||e.params.item.status!=="completed")return null;let t="",n=[];return Array.isArray(e.params.item.content)?(t=e.params.item.content.reduce((i,s)=>(s.type==="text"&&(i+=s.text),i),""),n=e.params.item.content.reduce((i,s)=>(s.type==="image_url"&&s.image_url.url&&i.push({type:"image",url:s.image_url.url}),i),[])):t=e.params.item.content,{id:e.params.item.id,role:e.params.item.role,timestamp:new Date,content:t,attachments:n}}function k_(e){const[t,n]=Xt([]),[,i]=Zc();return $t(()=>{if(!e)return;const s=o=>{if(b_(o))switch(o.params.type){case"response.text.delta":{const r=S_(o);r&&n(a=>[...a,r]),i("waiting");return}case"conversation.item.created":{const r=C_(o);r&&(i("thinking"),n(a=>[...a,r]));return}}};return e.on(V.SocketMessage,s),()=>{e.off(V.SocketMessage,s)}},[e,i]),t}const T_=({call:e,client:t})=>{const n=Ne(),[i,s]=Xt(n.default_state),o=()=>s("expanded"),r=()=>s("collapsed"),a=k_(t);switch(i){case"collapsed":return E(Au,{onExpand:o,call:e,client:t});case"expanded":return E(Iv,{transcript:a,onCollapse:r,call:e});default:return E(Au,{onExpand:o,call:e,client:t})}},Ur=()=>E(Bn.div,{layoutId:Ci,className:"bg-[#FEFDF5] text-black dark:bg-black gap-3 dark:text-white w-[240px] max-w-full rounded-4xl p-4 text-center flex items-center justify-center flex-col shadow-lg shadow-[#38383878]",children:E("div",{className:"rounded-full animate-spin",children:E(mv,{})})}),E_=({call:e,client:t})=>{switch(e==null?void 0:e.state){case"new":case"trying":case"requesting":return E(Ur,{});case"done":case"purged":case"destroy":return null;case"active":return E(T_,{client:t,call:e});default:return E(Ur,{})}},A_=(e,t,n)=>{const[i,s]=Xt(null);return $t(()=>{if(!e)return;const o=new y_({env:t||"production",anonymous_login:{target_id:e,target_type:"ai_assistant",target_version_id:n}});s(o)},[e,t,n]),i},R_=(e,{onReady:t,onNotification:n,onError:i,onSocketMessage:s})=>($t(()=>{if(e)return e.connect().then().catch(console.error),e.on(V.Ready,t),e.on(V.Notification,n),e.on(V.Error,i),e.on(V.SocketMessage,s),()=>{e.off(V.Ready,t),e.off(V.Notification,n),e.off(V.Error,i),e.off(V.SocketMessage,s),e.disconnect()}},[e]),null),I_=({className:e})=>E("svg",{className:e,width:"236",height:"211",viewBox:"0 0 236 211",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[E("g",{clipPath:"url(#:R5lfm:)",children:[E("path",{d:"M231.927 194.514C235.881 187.393 237.006 179.067 235.083 171.168C234.531 168.984 233.769 166.858 232.806 164.819C232.502 164.15 232.156 163.501 231.771 162.874L200.418 104.252H168.341L201.143 165.69C202.172 167.475 202.714 169.496 202.714 171.552C202.714 173.608 202.172 175.628 201.143 177.414C200.139 179.082 198.715 180.464 197.01 181.424C195.305 182.385 193.378 182.89 191.416 182.892H154.009C153.595 188.612 151.801 194.15 148.776 199.041C145.751 203.931 141.584 208.033 136.625 211H205.385C209.975 210.698 214.443 209.405 218.475 207.211C224.164 204.438 228.859 200.007 231.927 194.514Z",fill:"currentColor"}),E("path",{d:"M56.0698 65.9049H88.1473L104.134 36.466C105.487 33.9253 107.515 31.7984 109.999 30.3146C112.484 28.8309 115.331 28.0467 118.233 28.0467C121.135 28.0467 123.982 28.8309 126.466 30.3146C128.951 31.7984 130.979 33.9253 132.331 36.466L147.853 65.9049H179.93L157.166 23.3081C153.391 16.2702 147.751 10.3822 140.851 6.27586C133.951 2.16956 126.052 0 118 0C109.948 0 102.049 2.16956 95.1487 6.27586C88.2488 10.3822 82.6089 16.2702 78.8345 23.3081L56.0698 65.9049Z",fill:"currentColor"}),E("path",{d:"M81.9387 99.1324C82.275 93.4362 83.9987 87.9051 86.9627 83.0107C89.9266 78.1164 94.0429 74.0041 98.9604 71.0247H36.875V99.1324H81.9387Z",fill:"currentColor"}),E("path",{d:"M87.0591 101.18V177.977H101.649C104.692 177.944 107.64 176.924 110.041 175.075C112.443 173.226 114.165 170.648 114.946 167.738C115.26 166.621 115.416 165.467 115.411 164.308V118.229C115.425 113.227 117.432 108.432 120.997 104.885C124.561 101.338 129.396 99.3264 134.451 99.286H199.382V71.0247H117.481C109.408 71.0382 101.67 74.2213 95.9663 79.8751C90.2626 85.5289 87.0591 93.1914 87.0591 101.18Z",fill:"currentColor"}),E("path",{d:"M3.1927 164.819C2.23008 166.858 1.46775 168.984 0.916237 171.168C-1.00574 179.084 0.119328 187.425 4.07225 194.565C7.14854 200.039 11.8422 204.452 17.5241 207.211C21.5555 209.405 26.0233 210.698 30.6138 211H117.999C126.232 211 134.128 207.764 139.949 202.003C145.771 196.242 149.042 188.428 149.042 180.281V104.201H134.245C130.607 104.294 127.148 105.782 124.6 108.352C122.051 110.922 120.611 114.372 120.586 117.973V164.051C120.572 169.053 118.555 173.845 114.976 177.377C111.397 180.909 106.549 182.892 101.495 182.892H44.8417C42.8798 182.89 40.9521 182.385 39.2471 181.424C37.5421 180.464 36.1182 179.082 35.1149 177.414C34.0855 175.619 33.5443 173.59 33.5443 171.526C33.5443 169.462 34.0855 167.434 35.1149 165.638L67.9167 104.201H35.5806L4.22746 162.823C3.86529 163.539 3.50313 164.154 3.1927 164.819Z",fill:"currentColor"})]}),E("defs",{children:E("clipPath",{id:":R5lfm:",children:E("rect",{width:"236",height:"211",fill:"currentColor"})})})]});function P_(){const e=Ne();return e.logo_icon_url?E("div",{className:"object-center w-8 h-8 mr-2 overflow-hidden rounded-full",children:E("img",{src:e.logo_icon_url,className:"object-cover w-full h-full",alt:"Logo"})}):E(I_,{className:"w-8 h-8 mr-2"})}const M_=({client:e,versionId:t,callProps:n})=>{const i=Ne(),s=()=>{var d;if(!e){console.error("Client is not initialized.");return}const o=(d=RTCRtpReceiver.getCapabilities("audio"))==null?void 0:d.codecs,r=o==null?void 0:o.find(u=>u.mimeType.toLowerCase().includes("opus")),{customHeaders:a,...l}=n||{},c=a?[...a]:[];t&&c.push({name:"X-AI-Assistant-Version-ID",value:t}),e.newCall({destinationNumber:"xxx",...l,preferred_codecs:[r],customHeaders:c.length>0?c:void 0})};return E(Bn.button,{layoutId:Ci,onClick:s,className:"bg-[#FEFDF5] text-black flex items-center px-4 py-2 text-xl font-medium rounded-full shadow-lg cursor-pointer dark:bg-black dark:text-white ",children:[E(P_,{}),i.start_call_text]})},L_='@layer components;/*! tailwindcss v4.1.11 | MIT License | https://tailwindcss.com */@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-green-400:oklch(79.2% .209 151.711);--color-black:#000;--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--font-weight-medium:500;--font-weight-semibold:600;--radius-md:.375rem;--radius-lg:.5rem;--radius-2xl:1rem;--radius-3xl:1.5rem;--radius-4xl:2rem;--animate-spin:spin 1s linear infinite;--blur-xs:4px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){-webkit-appearance:button;-moz-appearance:button;appearance:button}::file-selector-button{-webkit-appearance:button;-moz-appearance:button;appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.pointer-events-auto{pointer-events:auto}.pointer-events-none{pointer-events:none}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.inset-0{inset:calc(var(--spacing)*0)}.-top-1{top:calc(var(--spacing)*-1)}.top-0{top:calc(var(--spacing)*0)}.-right-1{right:calc(var(--spacing)*-1)}.right-0{right:calc(var(--spacing)*0)}.bottom-0{bottom:calc(var(--spacing)*0)}.left-0{left:calc(var(--spacing)*0)}.z-10{z-index:10}.z-\\[9999\\]{z-index:9999}.mt-2{margin-top:calc(var(--spacing)*2)}.mr-2{margin-right:calc(var(--spacing)*2)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.ml-4{margin-left:calc(var(--spacing)*4)}.ml-auto{margin-left:auto}.flex{display:flex}.hidden{display:none}.inline-flex{display:inline-flex}.h-3{height:calc(var(--spacing)*3)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-8{height:calc(var(--spacing)*8)}.h-16{height:calc(var(--spacing)*16)}.h-\\[72px\\]{height:72px}.h-\\[144px\\]{height:144px}.h-\\[300px\\]{height:300px}.h-full{height:100%}.max-h-32{max-height:calc(var(--spacing)*32)}.min-h-\\[180px\\]{min-height:180px}.w-3{width:calc(var(--spacing)*3)}.w-4{width:calc(var(--spacing)*4)}.w-5{width:calc(var(--spacing)*5)}.w-8{width:calc(var(--spacing)*8)}.w-16{width:calc(var(--spacing)*16)}.w-\\[200px\\]{width:200px}.w-\\[240px\\]{width:240px}.w-\\[250px\\]{width:250px}.w-\\[344px\\]{width:344px}.w-full{width:100%}.max-w-32{max-width:calc(var(--spacing)*32)}.max-w-full{max-width:100%}.flex-1{flex:1}.animate-spin{animation:var(--animate-spin)}.cursor-pointer{cursor:pointer}.list-disc{list-style-type:disc}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-end{align-items:flex-end}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-1{gap:calc(var(--spacing)*1)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-\\[\\#3D3D46\\]>:not(:last-child)){border-color:#3d3d46}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-3xl{border-radius:var(--radius-3xl)}.rounded-4xl{border-radius:var(--radius-4xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-t-3xl{border-top-left-radius:var(--radius-3xl);border-top-right-radius:var(--radius-3xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-solid{--tw-border-style:solid;border-style:solid}.border-\\[\\#969696\\]{border-color:#969696}.bg-\\[\\#E6E3D3\\]{background-color:#e6e3d3}.bg-\\[\\#F36666\\]{background-color:#f36666}.bg-\\[\\#FEFDF5\\]{background-color:#fefdf5}.bg-\\[\\#FEFDF599\\]{background-color:#fefdf599}.bg-red-500{background-color:var(--color-red-500)}.bg-transparent{background-color:#0000}.object-cover{object-fit:cover}.object-center{object-position:center}.p-2{padding:calc(var(--spacing)*2)}.p-4{padding:calc(var(--spacing)*4)}.px-2\\.5{padding-inline:calc(var(--spacing)*2.5)}.px-4{padding-inline:calc(var(--spacing)*4)}.py-2{padding-block:calc(var(--spacing)*2)}.py-3{padding-block:calc(var(--spacing)*3)}.text-center{text-align:center}.text-left{text-align:left}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-\\[\\#969696\\]{color:#969696}.text-black{color:var(--color-black)}.text-green-400{color:var(--color-green-400)}.text-red-400{color:var(--color-red-400)}.text-white{color:var(--color-white)}.underline{text-decoration-line:underline}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\\[\\#38383878\\]{--tw-shadow-color:#38383878}@supports (color:color-mix(in lab,red,red)){.shadow-\\[\\#38383878\\]{--tw-shadow-color:color-mix(in oklab,#38383878 var(--tw-shadow-alpha),transparent)}}.backdrop-blur-xs{--tw-backdrop-blur:blur(var(--blur-xs));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,visibility,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.outline-none{--tw-outline-style:none;outline-style:none}@media (hover:hover){.hover\\:bg-red-600:hover{background-color:var(--color-red-600)}}@media (min-width:40rem){.sm\\:h-\\[386px\\]{height:386px}.sm\\:w-\\[400px\\]{width:400px}.sm\\:rounded-3xl{border-radius:var(--radius-3xl)}}@media (min-width:48rem){.md\\:right-10{right:calc(var(--spacing)*10)}.md\\:bottom-10{bottom:calc(var(--spacing)*10)}}.dark\\:border-\\[\\#3D3D46\\]:where(.dark,.dark *){border-color:#3d3d46}.dark\\:bg-\\[\\#3C3C3C\\]:where(.dark,.dark *){background-color:#3c3c3c}.dark\\:bg-\\[\\#38383C96\\]:where(.dark,.dark *){background-color:#38383c96}.dark\\:bg-\\[\\#38383C\\]:where(.dark,.dark *){background-color:#38383c}.dark\\:bg-\\[\\#222227\\]:where(.dark,.dark *){background-color:#222227}.dark\\:bg-\\[\\#750000\\]:where(.dark,.dark *){background-color:#750000}.dark\\:bg-black:where(.dark,.dark *){background-color:var(--color-black)}.dark\\:text-black:where(.dark,.dark *){color:var(--color-black)}.dark\\:text-white:where(.dark,.dark *){color:var(--color-white)}}::-webkit-scrollbar{width:8px;height:8px}::-webkit-scrollbar-track{background:0 0}::-webkit-scrollbar-thumb{background-color:#888;background-clip:content-box;border:2px solid #0000;border-radius:4px}::-webkit-scrollbar-thumb:hover{background-color:#555}html{scrollbar-width:thin;scrollbar-color:#888 transparent}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}',D_=({children:e})=>E("main",{className:"fixed inset-0 z-[9999] pointer-events-none",children:E("div",{className:"absolute bottom-0 right-0 pointer-events-auto md:bottom-10 md:right-10",children:e})}),O_={duration:.1,ease:"circOut"},N_=({children:e,position:t="fixed"})=>{const n=Ne(),s=(t??n.position??"fixed")==="fixed"?E(D_,{children:e}):e;return E("div",{className:xe(n.theme==="dark"&&"dark"),children:E(qf,{transition:O_,children:[E("style",{children:L_}),s]})})},V_=e=>E(Bn.div,{layoutId:Ci,className:"bg-[#FEFDF5] text-black dark:bg-black rounded-2xl p-4 flex flex-col items-center justify-center dark:text-white w-[344px] max-w-full",children:[E(fv,{className:"w-8 h-8 text-red-400"}),E("h1",{className:"mt-2 mb-4 text-2xl font-medium",children:"An error occurred"}),E("ul",{className:"gap-4 ml-4 text-sm list-disc",children:[E("li",{children:"Failed to initialize the Telnyx AI Agent client. Please check your agent ID and ensure that you are connected to the internet."}),E("li",{children:["Make sure that the"," ",E("a",{href:`https://portal.telnyx.com/#/ai/assistants/edit/${e.agentId}?tab=telephony`,className:"inline-flex items-center gap-1 font-medium text-green-400 underline",target:"_blank",rel:"noopener noreferrer",children:["Support Unauthenticated Web Calls"," ",E(wv,{className:"w-4 h-4"})]})," ","option is enabled in your Telnyx agent settings."]})]})]});function F_(e){return Object.keys(e).length===0}function ld(e){var n;if(typeof e!="object"||e===null)return!1;const t=e;return t.method==="ai_conversation"&&((n=t.params)==null?void 0:n.type)==="widget_settings"&&typeof t.params.widget_settings=="object"}const B_=({client:e})=>{const t=jg();return es(()=>{if(!e)return;const n=i=>{if(ld(i)&&!F_(i.params.widget_settings)){const s=i.params.widget_settings;t(s)}};return e.on(V.SocketMessage,n),()=>{e.off(V.SocketMessage,n)}},[e,t]),null};function j_({"agent-id":e,"call-destination-number":t,"call-caller-number":n,"call-caller-name":i,"call-custom-headers":s,environment:o,position:r="fixed","version-id":a}){const l=A_(e,o,a),[c,d]=Xt(null),[u,p]=Xt(!1),[g,_]=Xt(!1),[b,w]=Xt(!1),y={};if(t&&(y.destinationNumber=t),n&&(y.callerNumber=n),i&&(y.callerName=i),s)try{y.customHeaders=JSON.parse(s)}catch{console.error("Invalid JSON for call-custom-headers attribute:",s)}return R_(l,{onReady:()=>p(!1),onNotification:x=>{var k;if(((k=x.call)==null?void 0:k.state)==="destroy")return d(null);d(x)},onError:()=>{p(!1),_(!0)},onSocketMessage:x=>{ld(x)&&w(!0)}}),E(te,{children:[E(N_,{position:r,children:e?g?E(V_,{agentId:e}):u?E(Ur,{}):c!=null&&c.call?E(E_,{call:c.call,client:l}):b?E(M_,{versionId:a,client:l,callProps:y}):null:E("div",{children:"Please provide an assistant ID."})}),E(B_,{client:l})]})}kd(j_,"telnyx-ai-agent",Cg,{shadow:!0})})();
117
+ `)}))}),B.info(i)}),2e3)}}class m_ extends qv{constructor(t){super(t),this.calls={},this.autoRecoverCalls=!0,this._iceServers=[],this._localElement=null,this._remoteElement=null,this._jwtAuth=!0,this._audioConstraints=!0,this._videoConstraints=!1,this._speaker=null,this.iceServers=t.iceServers,this.ringtoneFile=t.ringtoneFile,this.ringbackFile=t.ringbackFile}get reconnectDelay(){return 1e3}connect(){const t=Object.create(null,{connect:{get:()=>super.connect}});return H(this,void 0,void 0,function*(){t.connect.call(this)})}checkPermissions(t=!0,n=!0){return H(this,void 0,void 0,function*(){try{const i=yield Fi({audio:t,video:n});return Kn(i),!0}catch{return!1}})}logout(){this.disconnect()}disconnect(){const t=Object.create(null,{disconnect:{get:()=>super.disconnect}});return H(this,void 0,void 0,function*(){Object.keys(this.calls).forEach(n=>this.calls[n].setState(X.Purge)),this.calls={},yield t.disconnect.call(this)})}speedTest(t){return new Promise((n,i)=>{if($u(V.SpeedTest,r=>{const{upDur:a,downDur:l}=r,c=l?8*t/(l/1e3)/1024:0;n({upDur:a,downDur:l,upKps:(a?8*t/(a/1e3)/1024:0).toFixed(0),downKps:c.toFixed(0)})},this.uuid),!(t=Number(t)))return i(`Invalid parameter 'bytes': ${t}`);this.executeRaw(`#SPU ${t}`);let s=t/1024;t%1024&&s++;const o=".".repeat(1024);for(let r=0;r<s;r++)this.executeRaw(`#SPB ${o}`);this.executeRaw("#SPE")})}getDevices(){return Xn().catch(t=>(J(V.MediaError,t,this.uuid),[]))}getVideoDevices(){return Xn(le.Video).catch(t=>(J(V.MediaError,t,this.uuid),[]))}getAudioInDevices(){return Xn(le.AudioIn).catch(t=>(J(V.MediaError,t,this.uuid),[]))}getAudioOutDevices(){return Xn(le.AudioOut).catch(t=>(console.error("getAudioOutDevices",t),J(V.MediaError,t,this.uuid),[]))}validateDeviceId(t,n,i){return Bi(t,n,i)}getDeviceResolutions(t){return H(this,void 0,void 0,function*(){try{return yield(n=>H(void 0,void 0,void 0,function*(){const i=[],s=yield Fi({video:{deviceId:{exact:n}}}),o=s.getVideoTracks()[0];for(let r=0;r<zu.length;r++){const[a,l]=zu[r];(yield o.applyConstraints({width:{exact:a},height:{exact:l}}).then(()=>!0).catch(()=>!1))&&i.push({resolution:`${a}x${l}`,width:a,height:l})}return Kn(s),i}))(t)}catch(n){throw n}})}get mediaConstraints(){return{audio:this._audioConstraints,video:this._videoConstraints}}setAudioSettings(t){return H(this,void 0,void 0,function*(){if(!t)throw new Error("You need to provide the settings object");const{micId:n,micLabel:i}=t,s=Mr(t,["micId","micLabel"]);return qu(s),this._audioConstraints=yield Ku(n,i,"audioinput",s),this.micId=n,this.micLabel=i,this._audioConstraints})}disableMicrophone(){this._audioConstraints=!1}enableMicrophone(){this._audioConstraints=!0}setVideoSettings(t){return H(this,void 0,void 0,function*(){if(!t)throw new Error("You need to provide the settings object");const{camId:n,camLabel:i}=t,s=Mr(t,["camId","camLabel"]);return qu(s),this._videoConstraints=yield Ku(n,i,"videoinput",s),this.camId=n,this.camLabel=i,this._videoConstraints})}disableWebcam(){this._videoConstraints=!1}enableWebcam(){this._videoConstraints=!0}set iceServers(t){const n={urls:["stun:stun.l.google.com:19302"]};this._iceServers=typeof t=="boolean"?t?[n]:[]:t||[Lu,Dv,n]}get iceServers(){return this._iceServers}set speaker(t){this._speaker=t}get speaker(){return this._speaker}set localElement(t){this._localElement=Gn(t)}get localElement(){return this._localElement}set remoteElement(t){this._remoteElement=Gn(t)}get remoteElement(){return this._remoteElement}vertoBroadcast({nodeId:t,channel:n="",data:i}){if(!n)throw new Error(`Invalid channel for broadcast: ${n}`);const s=new n_({sessid:this.sessionid,eventChannel:n,data:i});t&&(s.targetNodeId=t),this.execute(s).catch(o=>o)}vertoSubscribe({nodeId:t,channels:n=[],handler:i}){return H(this,void 0,void 0,function*(){if(!(n=n.filter(l=>l&&!this._existsSubscription(this.relayProtocol,l))).length)return{};const s=new i_({sessid:this.sessionid,eventChannel:n});t&&(s.targetNodeId=t);const o=yield this.execute(s),{unauthorized:r=[],subscribed:a=[]}=Br(o);return r.length&&r.forEach(l=>this._removeSubscription(this.relayProtocol,l)),a.forEach(l=>this._addSubscription(this.relayProtocol,i,l)),o})}vertoUnsubscribe({nodeId:t,channels:n=[]}){return H(this,void 0,void 0,function*(){if(!(n=n.filter(a=>a&&this._existsSubscription(this.relayProtocol,a))).length)return{};const i=new s_({sessid:this.sessionid,eventChannel:n});t&&(i.targetNodeId=t);const s=yield this.execute(i),{unsubscribed:o=[],notSubscribed:r=[]}=Br(s);return o.forEach(a=>this._removeSubscription(this.relayProtocol,a)),r.forEach(a=>this._removeSubscription(this.relayProtocol,a)),s})}static telnyxStateCall(t){return Fe.setStateTelnyx(t)}}class ad{constructor(t,n){this.code=n,this.message=t}}class g_ extends Ot{constructor(){super(),this.method=nt.Ping,this.buildRequest({method:this.method,params:{}})}}class zt{constructor(t){this.session=t}_ack(t,n){const i=new Zv(t,n);this.nodeId&&(i.targetNodeId=this.nodeId),this.session.execute(i)}reconnectDelay(){return 1e3*Fu(2,6)}handleMessage(t){const{session:n}=this,{id:i,method:s,params:o={}}=t,r=o==null?void 0:o.callID,a=o==null?void 0:o.eventChannel,l=o==null?void 0:o.eventType,c=s===nt.Attach;if(l==="channelPvtData")return this._handlePvtEvent(o.pvtData);if(r&&n.calls.hasOwnProperty(r)){if(!c)return n.calls[r].handleMessage(t),void this._ack(i,s);n.calls[r].hangup({},!1)}const d=()=>{var g,_,b,w;const y={id:r,remoteSdp:o.sdp,destinationNumber:o.callee_id_number,remoteCallerName:o.caller_id_name,remoteCallerNumber:o.caller_id_number,callerName:o.callee_id_name,callerNumber:o.callee_id_number,attach:c,mediaSettings:o.mediaSettings,debug:(g=n.options.debug)!==null&&g!==void 0&&g,debugOutput:(_=n.options.debugOutput)!==null&&_!==void 0?_:"socket",prefetchIceCandidates:(b=n.options.prefetchIceCandidates)!==null&&b!==void 0&&b,forceRelayCandidate:(w=n.options.forceRelayCandidate)!==null&&w!==void 0&&w};o.telnyx_call_control_id&&(y.telnyxCallControlId=o.telnyx_call_control_id),o.telnyx_session_id&&(y.telnyxSessionId=o.telnyx_session_id),o.telnyx_leg_id&&(y.telnyxLegId=o.telnyx_leg_id),o.client_state&&(y.clientState=o.client_state),o.dialogParams&&o.dialogParams.custom_headers&&o.dialogParams.custom_headers.length&&(y.customHeaders=o.dialogParams.custom_headers);const S=new Fe(n,y);return S.nodeId=this.nodeId,S},u=new Gu,p=new g_;switch(s){case nt.Ping:this.session.execute(p);break;case nt.Punt:n.disconnect();break;case nt.Invite:{const b=d();b.playRingtone(),b.setState(X.Ringing),b.direction=Se.Inbound,this._ack(i,s);break}case nt.Attach:{const b=d();this.session.autoRecoverCalls?b.answer():b.setState(X.Recovering),b.handleMessage(t);break}case nt.Event:case"webrtc.event":if(!a)return void B.error("Verto received an unknown event:",o);const g=n.relayProtocol,_=a.split(".")[0];n._existsSubscription(g,a)?J(g,o,a):a===n.sessionid?this._handleSessionEvent(o.eventData):n._existsSubscription(g,_)?J(g,o,_):n.calls.hasOwnProperty(a)?n.calls[a].handleMessage(t):J(V.Notification,o,n.uuid);break;case nt.Info:o.type=ae.generic,J(V.Notification,o,n.uuid);break;case nt.ClientReady:this.session.execute(u);break;default:{const b=Dr(t);if(b){switch(b){case Rt.REGISTER:case Rt.REGED:n.connection.previousGatewayState!==Rt.REGED&&n.connection.previousGatewayState!==Rt.REGISTER&&(zt.retriedRegister=0,o.type=ae.vertoClientReady,J(V.Ready,o,n.uuid));break;case Rt.UNREGED:case Rt.NOREG:if(zt.retriedRegister+=1,zt.retriedRegister===5){zt.retriedRegister=0,J(V.Error,{error:new ad("Fail to register the user, the server tried 5 times","UNREGED|NOREG"),sessionId:n.sessionid},n.uuid);break}setTimeout(()=>{this.session.execute(u)},this.reconnectDelay());break;case Rt.FAILED:case Rt.FAIL_WAIT:if(n.connection.previousGatewayState!==Rt.FAILED&&n.connection.previousGatewayState!==Rt.FAIL_WAIT){if(!this.session.hasAutoReconnect()){zt.retriedConnect=0,J(V.Error,{error:new ad("Fail to connect the server, the server tried 5 times","FAILED|FAIL_WAIT"),sessionId:n.sessionid},n.uuid);break}if(zt.retriedConnect+=1,zt.retriedConnect===5){zt.retriedConnect=0,J(V.Error,{error:new Error("Connection Retry Failed"),sessionId:n.sessionid},n.uuid);break}setTimeout(()=>{this.session.disconnect().then(()=>{this.session.clearConnection(),this.session.connect()})},this.reconnectDelay())}break;default:B.warn("GatewayState message unknown method:",t)}break}B.debug("Verto message unknown method:",t);break}}}_retrieveCallId(t,n){const i=Object.keys(this.session.calls);if(t.action!=="bootObj")return i.find(s=>this.session.calls[s].channels.includes(n));{const s=t.data.find(o=>i.includes(o[0]));if(s instanceof Array)return s[0]}}_handlePvtEvent(t){return H(this,void 0,void 0,function*(){const{session:n}=this,i=n.relayProtocol,{action:s,laChannel:o,laName:r,chatChannel:a,infoChannel:l,modChannel:c,conferenceMemberID:d,role:u,callID:p}=t;switch(s){case"conference-liveArray-join":{const g=()=>{n.vertoBroadcast({nodeId:this.nodeId,channel:o,data:{liveArray:{command:"bootstrap",context:o,name:r}}})},_={nodeId:this.nodeId,channels:[o],handler:({data:w})=>{const y=p||this._retrieveCallId(w,o);if(y&&n.calls.hasOwnProperty(y)){const S=n.calls[y];S._addChannel(o),S.extension=r,S.handleConferenceUpdate(w,t).then(C=>{C==="INVALID_PACKET"&&g()})}}},b=yield n.vertoSubscribe(_).catch(w=>{B.error("liveArray subscription error:",w)});ji(b,o)&&g();break}case"conference-liveArray-part":{let g=null;if(o&&n._existsSubscription(i,o)){const{callId:b=null}=n.subscriptions[i][o];if(g=n.calls[b]||null,b!==null){const w={type:ae.conferenceUpdate,action:At.Leave,conferenceName:r,participantId:Number(d),role:u};J(V.Notification,w,b,!1)||J(V.Notification,w,n.uuid),g===null&&dn(V.Notification,null,b)}}const _=[o,a,l,c];n.vertoUnsubscribe({nodeId:this.nodeId,channels:_}).then(({unsubscribedChannels:b=[]})=>{g&&(g.channels=g.channels.filter(w=>!b.includes(w)))}).catch(b=>{B.error("liveArray unsubscribe error:",b)});break}}})}_handleSessionEvent(t){switch(t.contentType){case"layout-info":case"layer-info":id(this.session,t);break;case"logo-info":{const n={type:ae.conferenceUpdate,action:At.LogoInfo,logo:t.logoURL};J(V.Notification,n,this.session.uuid);break}}}}zt.retriedConnect=0,zt.retriedRegister=0;class v_ extends Ot{constructor(t){super(),this.method="anonymous_login";const{target_type:n,target_id:i,target_version_id:s,userVariables:o,sessionId:r,reconnection:a}=t,l={target_type:n,target_id:i,userVariables:o,reconnection:a,"User-Agent":{sdkVersion:jr,data:navigator.userAgent}};r&&(l.sessid=r),s&&(l.target_version_id=s),this.buildRequest({method:this.method,params:l})}}class __ extends m_{constructor(t){super(t),this.relayProtocol="verto-protocol",this.timeoutErrorCode=-329990,this.handleLoginOnSocketOpen=()=>H(this,void 0,void 0,function*(){this._idle=!1;const{login:n,password:i,passwd:s,login_token:o,userVariables:r,autoReconnect:a=!0}=this.options,l=new Yv(n,i||s,o,this.sessionid,r,!!Nr()),c=yield this.execute(l).catch(this._handleLoginError);c&&(this._autoReconnect=a,this.sessionid=c.sessid)}),this.handleAnonymousLoginOnSocketOpen=()=>H(this,void 0,void 0,function*(){this._idle=!1;const{anonymous_login:n}=this.options,i=new v_({target_id:n.target_id,target_type:n.target_type,target_version_id:n.target_version_id,sessionId:this.sessionid,userVariables:this.options.userVariables,reconnection:!!Nr()}),s=yield this.execute(i).catch(this._handleLoginError);s&&(this.sessionid=s.sessid)}),window.addEventListener("beforeunload",n=>{this.calls&&Object.keys(this.calls).forEach(i=>{this.calls[i]&&this.calls[i].hangup({},!0)})})}validateOptions(){return Lr(this.options)||Oi(this.options)}newCall(t){if(!this.validateCallOptions(t))throw new Error("Verto.newCall() error: destinationNumber is required.");console.time(Pu);const n=new Fe(this,t);return n.invite(),n}broadcast(t){return this.vertoBroadcast(t)}subscribe(t){return this.vertoSubscribe(t)}unsubscribe(t){return this.vertoUnsubscribe(t)}validateCallOptions(t){return!!Oi(this.options)||!!t.destinationNumber}_onSocketOpen(){return H(this,void 0,void 0,function*(){return Lr(this.options)?this.handleLoginOnSocketOpen():Oi(this.options)?this.handleAnonymousLoginOnSocketOpen():void 0})}_onSocketMessage(t){new zt(this).handleMessage(t)}}class y_ extends __{constructor(t){super(t),console.log(`SDK version: ${ed}`)}newCall(t){return super.newCall(t)}static webRTCInfo(){return Xv()}static webRTCSupportedBrowserList(){return[{operationSystem:"Android",supported:[{browserName:"Chrome",features:["audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"iOS",supported:[{browserName:"Chrome",supported:vt.not_supported},{browserName:"Firefox",supported:vt.not_supported},{browserName:"Safari",features:["video","audio"],supported:vt.full},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"Linux",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",supported:vt.not_supported}]},{operationSystem:"MacOS",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",features:["video","audio"],supported:vt.full},{browserName:"Edge",features:["audio"],supported:vt.partial}]},{operationSystem:"Windows",supported:[{browserName:"Chrome",features:["video","audio"],supported:vt.full},{browserName:"Firefox",features:["audio"],supported:vt.partial},{browserName:"Safari",supported:vt.not_supported},{browserName:"Edge",features:["audio"],supported:vt.partial}]}]}}function b_(e){if(!e||typeof e!="object")return!1;const t=e;return t.method==="ai_conversation"&&typeof t.params=="object"}function w_(e){if(!e||typeof e!="object")return!1;const t=e;return t.params.type!=="response.text.delta"?!1:!!t.params.delta}function x_(e){if(!e||typeof e!="object")return!1;const t=e;return t.params.type!=="conversation.item.created"?!1:!!t.params.item.content}function S_(e){if(!x_(e)||e.params.item.role!=="user"||e.params.item.status!=="completed")return null;let t="",n=[];return Array.isArray(e.params.item.content)?(t=e.params.item.content.reduce((i,s)=>(s.type==="text"&&(i+=s.text),i),""),n=e.params.item.content.reduce((i,s)=>(s.type==="image_url"&&s.image_url.url&&i.push({type:"image",url:s.image_url.url}),i),[])):t=e.params.item.content,{id:e.params.item.id,role:e.params.item.role,timestamp:new Date,content:t,attachments:n}}function C_(e){const[t,n]=Xt([]),[,i]=Zc();return $t(()=>{if(!e)return;const s=o=>{if(b_(o))switch(o.params.type){case"response.text.delta":{w_(o)&&n(r=>{const a=r[r.length-1];if(a&&a.id===o.params.item_id&&a.role==="assistant"){const l={...a,content:a.content+o.params.delta};return[...r.slice(0,-1),l]}else{const l={id:o.params.item_id,role:"assistant",content:o.params.delta,timestamp:new Date};return[...r,l]}}),i("waiting");return}case"conversation.item.created":{const r=S_(o);r&&(i("thinking"),n(a=>{const l=a[a.length-1];if(l&&l.role==="user"&&r.role==="user"&&r.timestamp.getTime()-l.timestamp.getTime()<2e3){const d={...l,id:r.id,content:l.content+" "+r.content,timestamp:r.timestamp,attachments:[...l.attachments||[],...r.attachments||[]]};return[...a.slice(0,-1),d]}return[...a,r]}));return}}};return e.on(V.SocketMessage,s),()=>{e.off(V.SocketMessage,s)}},[e,i]),t}const k_=({call:e,client:t})=>{const n=Ne(),[i,s]=Xt(n.default_state),o=()=>s("expanded"),r=()=>s("collapsed"),a=C_(t);switch(i){case"collapsed":return E(Au,{onExpand:o,call:e,client:t});case"expanded":return E(Iv,{transcript:a,onCollapse:r,call:e});default:return E(Au,{onExpand:o,call:e,client:t})}},Ur=()=>E(Bn.div,{layoutId:Ci,className:"bg-[#FEFDF5] text-black dark:bg-black gap-3 dark:text-white w-[240px] max-w-full rounded-4xl p-4 text-center flex items-center justify-center flex-col shadow-lg shadow-[#38383878]",children:E("div",{className:"rounded-full animate-spin",children:E(mv,{})})}),T_=({call:e,client:t})=>{switch(e==null?void 0:e.state){case"new":case"trying":case"requesting":return E(Ur,{});case"done":case"purged":case"destroy":return null;case"active":return E(k_,{client:t,call:e});default:return E(Ur,{})}},E_=(e,t,n)=>{const[i,s]=Xt(null);return $t(()=>{if(!e)return;const o=new y_({env:t||"production",anonymous_login:{target_id:e,target_type:"ai_assistant",target_version_id:n}});s(o)},[e,t,n]),i},A_=(e,{onReady:t,onNotification:n,onError:i,onSocketMessage:s})=>($t(()=>{if(e)return e.connect().then().catch(console.error),e.on(V.Ready,t),e.on(V.Notification,n),e.on(V.Error,i),e.on(V.SocketMessage,s),()=>{e.off(V.Ready,t),e.off(V.Notification,n),e.off(V.Error,i),e.off(V.SocketMessage,s),e.disconnect()}},[e]),null),R_=({className:e})=>E("svg",{className:e,width:"236",height:"211",viewBox:"0 0 236 211",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[E("g",{clipPath:"url(#:R5lfm:)",children:[E("path",{d:"M231.927 194.514C235.881 187.393 237.006 179.067 235.083 171.168C234.531 168.984 233.769 166.858 232.806 164.819C232.502 164.15 232.156 163.501 231.771 162.874L200.418 104.252H168.341L201.143 165.69C202.172 167.475 202.714 169.496 202.714 171.552C202.714 173.608 202.172 175.628 201.143 177.414C200.139 179.082 198.715 180.464 197.01 181.424C195.305 182.385 193.378 182.89 191.416 182.892H154.009C153.595 188.612 151.801 194.15 148.776 199.041C145.751 203.931 141.584 208.033 136.625 211H205.385C209.975 210.698 214.443 209.405 218.475 207.211C224.164 204.438 228.859 200.007 231.927 194.514Z",fill:"currentColor"}),E("path",{d:"M56.0698 65.9049H88.1473L104.134 36.466C105.487 33.9253 107.515 31.7984 109.999 30.3146C112.484 28.8309 115.331 28.0467 118.233 28.0467C121.135 28.0467 123.982 28.8309 126.466 30.3146C128.951 31.7984 130.979 33.9253 132.331 36.466L147.853 65.9049H179.93L157.166 23.3081C153.391 16.2702 147.751 10.3822 140.851 6.27586C133.951 2.16956 126.052 0 118 0C109.948 0 102.049 2.16956 95.1487 6.27586C88.2488 10.3822 82.6089 16.2702 78.8345 23.3081L56.0698 65.9049Z",fill:"currentColor"}),E("path",{d:"M81.9387 99.1324C82.275 93.4362 83.9987 87.9051 86.9627 83.0107C89.9266 78.1164 94.0429 74.0041 98.9604 71.0247H36.875V99.1324H81.9387Z",fill:"currentColor"}),E("path",{d:"M87.0591 101.18V177.977H101.649C104.692 177.944 107.64 176.924 110.041 175.075C112.443 173.226 114.165 170.648 114.946 167.738C115.26 166.621 115.416 165.467 115.411 164.308V118.229C115.425 113.227 117.432 108.432 120.997 104.885C124.561 101.338 129.396 99.3264 134.451 99.286H199.382V71.0247H117.481C109.408 71.0382 101.67 74.2213 95.9663 79.8751C90.2626 85.5289 87.0591 93.1914 87.0591 101.18Z",fill:"currentColor"}),E("path",{d:"M3.1927 164.819C2.23008 166.858 1.46775 168.984 0.916237 171.168C-1.00574 179.084 0.119328 187.425 4.07225 194.565C7.14854 200.039 11.8422 204.452 17.5241 207.211C21.5555 209.405 26.0233 210.698 30.6138 211H117.999C126.232 211 134.128 207.764 139.949 202.003C145.771 196.242 149.042 188.428 149.042 180.281V104.201H134.245C130.607 104.294 127.148 105.782 124.6 108.352C122.051 110.922 120.611 114.372 120.586 117.973V164.051C120.572 169.053 118.555 173.845 114.976 177.377C111.397 180.909 106.549 182.892 101.495 182.892H44.8417C42.8798 182.89 40.9521 182.385 39.2471 181.424C37.5421 180.464 36.1182 179.082 35.1149 177.414C34.0855 175.619 33.5443 173.59 33.5443 171.526C33.5443 169.462 34.0855 167.434 35.1149 165.638L67.9167 104.201H35.5806L4.22746 162.823C3.86529 163.539 3.50313 164.154 3.1927 164.819Z",fill:"currentColor"})]}),E("defs",{children:E("clipPath",{id:":R5lfm:",children:E("rect",{width:"236",height:"211",fill:"currentColor"})})})]});function I_(){const e=Ne();return e.logo_icon_url?E("div",{className:"object-center w-8 h-8 mr-2 overflow-hidden rounded-full",children:E("img",{src:e.logo_icon_url,className:"object-cover w-full h-full",alt:"Logo"})}):E(R_,{className:"w-8 h-8 mr-2"})}const P_=({client:e,versionId:t,callProps:n})=>{const i=Ne(),s=()=>{var d;if(!e){console.error("Client is not initialized.");return}const o=(d=RTCRtpReceiver.getCapabilities("audio"))==null?void 0:d.codecs,r=o==null?void 0:o.find(u=>u.mimeType.toLowerCase().includes("opus")),{customHeaders:a,...l}=n||{},c=a?[...a]:[];t&&c.push({name:"X-AI-Assistant-Version-ID",value:t}),e.newCall({destinationNumber:"xxx",...l,preferred_codecs:[r],customHeaders:c.length>0?c:void 0})};return E(Bn.button,{layoutId:Ci,onClick:s,className:"bg-[#FEFDF5] text-black flex items-center px-4 py-2 text-xl font-medium rounded-full shadow-lg cursor-pointer dark:bg-black dark:text-white ",children:[E(I_,{}),i.start_call_text]})},M_='@layer components;/*! tailwindcss v4.1.11 | MIT License | https://tailwindcss.com */@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-divide-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-green-400:oklch(79.2% .209 151.711);--color-black:#000;--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--font-weight-medium:500;--font-weight-semibold:600;--radius-md:.375rem;--radius-lg:.5rem;--radius-2xl:1rem;--radius-3xl:1.5rem;--radius-4xl:2rem;--animate-spin:spin 1s linear infinite;--blur-xs:4px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){-webkit-appearance:button;-moz-appearance:button;appearance:button}::file-selector-button{-webkit-appearance:button;-moz-appearance:button;appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer utilities{.pointer-events-auto{pointer-events:auto}.pointer-events-none{pointer-events:none}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.inset-0{inset:calc(var(--spacing)*0)}.-top-1{top:calc(var(--spacing)*-1)}.top-0{top:calc(var(--spacing)*0)}.-right-1{right:calc(var(--spacing)*-1)}.right-0{right:calc(var(--spacing)*0)}.bottom-0{bottom:calc(var(--spacing)*0)}.left-0{left:calc(var(--spacing)*0)}.z-10{z-index:10}.z-\\[9999\\]{z-index:9999}.mt-2{margin-top:calc(var(--spacing)*2)}.mr-2{margin-right:calc(var(--spacing)*2)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.ml-4{margin-left:calc(var(--spacing)*4)}.ml-auto{margin-left:auto}.flex{display:flex}.hidden{display:none}.inline-flex{display:inline-flex}.h-3{height:calc(var(--spacing)*3)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-8{height:calc(var(--spacing)*8)}.h-16{height:calc(var(--spacing)*16)}.h-\\[72px\\]{height:72px}.h-\\[144px\\]{height:144px}.h-\\[300px\\]{height:300px}.h-full{height:100%}.max-h-32{max-height:calc(var(--spacing)*32)}.min-h-\\[180px\\]{min-height:180px}.w-3{width:calc(var(--spacing)*3)}.w-4{width:calc(var(--spacing)*4)}.w-5{width:calc(var(--spacing)*5)}.w-8{width:calc(var(--spacing)*8)}.w-16{width:calc(var(--spacing)*16)}.w-\\[200px\\]{width:200px}.w-\\[240px\\]{width:240px}.w-\\[250px\\]{width:250px}.w-\\[344px\\]{width:344px}.w-full{width:100%}.max-w-32{max-width:calc(var(--spacing)*32)}.max-w-full{max-width:100%}.flex-1{flex:1}.animate-spin{animation:var(--animate-spin)}.cursor-pointer{cursor:pointer}.list-disc{list-style-type:disc}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.items-end{align-items:flex-end}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.gap-1{gap:calc(var(--spacing)*1)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}:where(.divide-y>:not(:last-child)){--tw-divide-y-reverse:0;border-bottom-style:var(--tw-border-style);border-top-style:var(--tw-border-style);border-top-width:calc(1px*var(--tw-divide-y-reverse));border-bottom-width:calc(1px*calc(1 - var(--tw-divide-y-reverse)))}:where(.divide-\\[\\#3D3D46\\]>:not(:last-child)){border-color:#3d3d46}.overflow-hidden{overflow:hidden}.overflow-y-auto{overflow-y:auto}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-3xl{border-radius:var(--radius-3xl)}.rounded-4xl{border-radius:var(--radius-4xl)}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius-lg)}.rounded-md{border-radius:var(--radius-md)}.rounded-t-3xl{border-top-left-radius:var(--radius-3xl);border-top-right-radius:var(--radius-3xl)}.border{border-style:var(--tw-border-style);border-width:1px}.border-solid{--tw-border-style:solid;border-style:solid}.border-\\[\\#969696\\]{border-color:#969696}.bg-\\[\\#E6E3D3\\]{background-color:#e6e3d3}.bg-\\[\\#F36666\\]{background-color:#f36666}.bg-\\[\\#FEFDF5\\]{background-color:#fefdf5}.bg-\\[\\#FEFDF599\\]{background-color:#fefdf599}.bg-red-500{background-color:var(--color-red-500)}.bg-transparent{background-color:#0000}.object-cover{object-fit:cover}.object-center{object-position:center}.p-2{padding:calc(var(--spacing)*2)}.p-4{padding:calc(var(--spacing)*4)}.px-2\\.5{padding-inline:calc(var(--spacing)*2.5)}.px-4{padding-inline:calc(var(--spacing)*4)}.py-2{padding-block:calc(var(--spacing)*2)}.py-3{padding-block:calc(var(--spacing)*3)}.text-center{text-align:center}.text-left{text-align:left}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.text-\\[\\#969696\\]{color:#969696}.text-black{color:var(--color-black)}.text-green-400{color:var(--color-green-400)}.text-red-400{color:var(--color-red-400)}.text-white{color:var(--color-white)}.underline{text-decoration-line:underline}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-\\[\\#38383878\\]{--tw-shadow-color:#38383878}@supports (color:color-mix(in lab,red,red)){.shadow-\\[\\#38383878\\]{--tw-shadow-color:color-mix(in oklab,#38383878 var(--tw-shadow-alpha),transparent)}}.backdrop-blur-xs{--tw-backdrop-blur:blur(var(--blur-xs));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to,opacity,box-shadow,transform,translate,scale,rotate,filter,-webkit-backdrop-filter,backdrop-filter,display,visibility,content-visibility,overlay,pointer-events;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.outline-none{--tw-outline-style:none;outline-style:none}@media (hover:hover){.hover\\:bg-red-600:hover{background-color:var(--color-red-600)}}@media (min-width:40rem){.sm\\:h-\\[386px\\]{height:386px}.sm\\:w-\\[400px\\]{width:400px}.sm\\:rounded-3xl{border-radius:var(--radius-3xl)}}@media (min-width:48rem){.md\\:right-10{right:calc(var(--spacing)*10)}.md\\:bottom-10{bottom:calc(var(--spacing)*10)}}.dark\\:border-\\[\\#3D3D46\\]:where(.dark,.dark *){border-color:#3d3d46}.dark\\:bg-\\[\\#3C3C3C\\]:where(.dark,.dark *){background-color:#3c3c3c}.dark\\:bg-\\[\\#38383C96\\]:where(.dark,.dark *){background-color:#38383c96}.dark\\:bg-\\[\\#38383C\\]:where(.dark,.dark *){background-color:#38383c}.dark\\:bg-\\[\\#222227\\]:where(.dark,.dark *){background-color:#222227}.dark\\:bg-\\[\\#750000\\]:where(.dark,.dark *){background-color:#750000}.dark\\:bg-black:where(.dark,.dark *){background-color:var(--color-black)}.dark\\:text-black:where(.dark,.dark *){color:var(--color-black)}.dark\\:text-white:where(.dark,.dark *){color:var(--color-white)}}::-webkit-scrollbar{width:8px;height:8px}::-webkit-scrollbar-track{background:0 0}::-webkit-scrollbar-thumb{background-color:#888;background-clip:content-box;border:2px solid #0000;border-radius:4px}::-webkit-scrollbar-thumb:hover{background-color:#555}html{scrollbar-width:thin;scrollbar-color:#888 transparent}@property --tw-divide-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}',L_=({children:e})=>E("main",{className:"fixed inset-0 z-[9999] pointer-events-none",children:E("div",{className:"absolute bottom-0 right-0 pointer-events-auto md:bottom-10 md:right-10",children:e})}),D_={duration:.1,ease:"circOut"},O_=({children:e,position:t="fixed"})=>{const n=Ne(),s=(t??n.position??"fixed")==="fixed"?E(L_,{children:e}):e;return E("div",{className:xe(n.theme==="dark"&&"dark"),children:E(qf,{transition:D_,children:[E("style",{children:M_}),s]})})},N_=e=>E(Bn.div,{layoutId:Ci,className:"bg-[#FEFDF5] text-black dark:bg-black rounded-2xl p-4 flex flex-col items-center justify-center dark:text-white w-[344px] max-w-full",children:[E(fv,{className:"w-8 h-8 text-red-400"}),E("h1",{className:"mt-2 mb-4 text-2xl font-medium",children:"An error occurred"}),E("ul",{className:"gap-4 ml-4 text-sm list-disc",children:[E("li",{children:"Failed to initialize the Telnyx AI Agent client. Please check your agent ID and ensure that you are connected to the internet."}),E("li",{children:["Make sure that the"," ",E("a",{href:`https://portal.telnyx.com/#/ai/assistants/edit/${e.agentId}?tab=telephony`,className:"inline-flex items-center gap-1 font-medium text-green-400 underline",target:"_blank",rel:"noopener noreferrer",children:["Support Unauthenticated Web Calls"," ",E(wv,{className:"w-4 h-4"})]})," ","option is enabled in your Telnyx agent settings."]})]})]});function V_(e){return Object.keys(e).length===0}function ld(e){var n;if(typeof e!="object"||e===null)return!1;const t=e;return t.method==="ai_conversation"&&((n=t.params)==null?void 0:n.type)==="widget_settings"&&typeof t.params.widget_settings=="object"}const F_=({client:e})=>{const t=jg();return es(()=>{if(!e)return;const n=i=>{if(ld(i)&&!V_(i.params.widget_settings)){const s=i.params.widget_settings;t(s)}};return e.on(V.SocketMessage,n),()=>{e.off(V.SocketMessage,n)}},[e,t]),null};function B_({"agent-id":e,"call-destination-number":t,"call-caller-number":n,"call-caller-name":i,"call-custom-headers":s,environment:o,position:r="fixed","version-id":a}){const l=E_(e,o,a),[c,d]=Xt(null),[u,p]=Xt(!1),[g,_]=Xt(!1),[b,w]=Xt(!1),y={};if(t&&(y.destinationNumber=t),n&&(y.callerNumber=n),i&&(y.callerName=i),s)try{y.customHeaders=JSON.parse(s)}catch{console.error("Invalid JSON for call-custom-headers attribute:",s)}return A_(l,{onReady:()=>p(!1),onNotification:x=>{var k;if(((k=x.call)==null?void 0:k.state)==="destroy")return d(null);d(x)},onError:()=>{p(!1),_(!0)},onSocketMessage:x=>{ld(x)&&w(!0)}}),E(te,{children:[E(O_,{position:r,children:e?g?E(N_,{agentId:e}):u?E(Ur,{}):c!=null&&c.call?E(T_,{call:c.call,client:l}):b?E(P_,{versionId:a,client:l,callProps:y}):null:E("div",{children:"Please provide an assistant ID."})}),E(F_,{client:l})]})}kd(B_,"telnyx-ai-agent",Cg,{shadow:!0})})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@telnyx/ai-agent-widget",
3
3
  "private": false,
4
- "version": "0.18.0",
4
+ "version": "0.19.0",
5
5
  "description": "A widget for Telnyx AI Agent",
6
6
  "type": "module",
7
7
  "author": "Telnyx",