@accurix/centrinfo-widget 5.0.0 → 5.1.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.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./styles-BgWsSZsR.cjs`);let t=require(`preact`),n=require(`preact/hooks`),r=require(`preact/jsx-runtime`);const i=e=>e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:`other`,a=({state:t,onClose:a})=>{let o=e.z(),s=(0,n.useRef)(null);(0,n.useEffect)(()=>{s.current?.focus();let e=e=>{e.key===`Escape`&&(e.stopPropagation(),a())};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[a]);let c=t.status===`ready`?i(t.mimeType):`other`;return(0,r.jsx)(`div`,{class:`cf-preview`,role:`dialog`,"aria-modal":`true`,"aria-label":e.R(o.attachPreviewTitle,{name:t.name}),onClick:e=>{e.target===e.currentTarget&&a()},children:(0,r.jsxs)(`div`,{class:`cf-preview__frame`,children:[(0,r.jsxs)(`div`,{class:`cf-preview__bar`,children:[(0,r.jsx)(`span`,{class:`cf-preview__name`,title:t.name,children:t.name}),t.status===`ready`&&(0,r.jsx)(`a`,{class:`cf-preview__btn`,href:t.url,download:t.name,children:o.attachDownload}),(0,r.jsx)(`button`,{ref:s,type:`button`,class:`cf-preview__btn cf-preview__close`,"aria-label":o.attachPreviewClose,onClick:a,children:`✕`})]}),(0,r.jsxs)(`div`,{class:`cf-preview__body`,children:[t.status===`loading`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewLoading}),t.status===`error`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewFailed}),t.status===`ready`&&c===`image`&&(0,r.jsx)(`img`,{class:`cf-preview__image`,src:t.url,alt:t.name}),t.status===`ready`&&c===`pdf`&&(0,r.jsx)(`iframe`,{class:`cf-preview__pdf`,src:t.url,title:t.name}),t.status===`ready`&&c===`other`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewUnsupported})]})]})})},o=({name:t,greeting:n})=>{let i=e.z();return(0,r.jsxs)(`section`,{class:`cf-empty-welcome`,"aria-label":e.R(i.welcomeLabel,{name:t}),children:[(0,r.jsx)(`span`,{class:`cf-empty-welcome__eyebrow`,children:i.welcomeEyebrow}),(0,r.jsx)(`h2`,{children:t}),(0,r.jsx)(`p`,{children:n||i.welcomePrompt})]})},s=(e,t,n)=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),n();return}if(e.key!==`Tab`)return;let r=Array.from(t.querySelectorAll(`button, [href], textarea, input, select, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`&&e.tabIndex>=0);if(r.length===0)return;let i=t.getRootNode(),a=e.composedPath()[0],o=a instanceof HTMLElement?a:`activeElement`in i?i.activeElement:document.activeElement,s=r[0],c=r[r.length-1];e.shiftKey&&(o===s||!t.contains(o))?(e.preventDefault(),e.stopPropagation(),c.focus()):!e.shiftKey&&(o===c||!t.contains(o))&&(e.preventDefault(),e.stopPropagation(),s.focus())},c=new Map,ee=e=>{if(!e||typeof document>`u`||typeof CanvasRenderingContext2D>`u`)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.fillStyle=`#010203`,t.fillStyle=e;let n=t.fillStyle;if(n===`#010203`&&e.trim().toLowerCase()!==`#010203`)return;let r=n.match(/^#([\da-f]{6})$/i)?.[1];if(r)return[Number.parseInt(r.slice(0,2),16),Number.parseInt(r.slice(2,4),16),Number.parseInt(r.slice(4,6),16),1];let i=n.match(/^rgba?\(([\d.]+)[, ]+([\d.]+)[, ]+([\d.]+)(?:[, /]+([\d.]+))?\)$/i);if(!i)return;let a=i.slice(1,5).map(Number);if(!a.some(e=>!Number.isFinite(e)))return[a[0],a[1],a[2],a[3]??1]},te=(e,t=`#ffffff`)=>{let n=`${e??``}|${t}`;if(c.has(n))return c.get(n);let r=ee(e),i=ee(t)??[255,255,255,1];if(!r){c.set(n,void 0);return}let a=r[3],o=r.slice(0,3).map((e,t)=>e*a+i[t]*(1-a)).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}),s=o[0]*.2126+o[1]*.7152+o[2]*.0722,te=1.05/(s+.05)>=(s+.05)/.059?`#ffffff`:`#0f1e2a`;return c.set(n,te),te},ne=e=>{let[t,r]=(0,n.useState)(`light`);return(0,n.useEffect)(()=>{if(e!==`auto`||typeof matchMedia>`u`)return;let t=matchMedia(`(prefers-color-scheme: dark)`),n=()=>r(t.matches?`dark`:`light`);return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[e]),e===`auto`?t:e},l=6e4,u=90,re={end:`end the call`,mute:`mute your microphone`,minimize:`minimize the chat`,expand:`expand the view`,shrink:`exit the expanded view`},ie=e=>e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s']/gu,` `).replace(/\s+/g,` `).trim(),ae=[{action:`shrink`,re:/\b(?:exit|leave|quit|close)\b[\s\w]*\b(?:full ?screen|expanded|theat(?:er|re))\b|\bshrink\b|\bsmaller view\b/},{action:`end`,re:/\b(?:end|close|stop|finish|hang ?up|quit|exit)\b[\s\w]*\b(?:call|chat|conversation|convo|session|talking)\b|\bhang ?up\b|\bgood ?bye\b|^bye(?: bye)?$/},{action:`mute`,re:/\bmute\b|\bstop listening\b/},{action:`minimize`,re:/\bminimi[sz]e\b|\bhide\b[\s\w]*\b(?:chat|call|window|widget)\b/},{action:`expand`,re:/\bexpand\b|\bmaximi[sz]e\b|\bfull ?screen\b|\btheat(?:er|re) mode\b|\bbigger view\b/}],oe=/^(?:yes|yeah|yep|yup|sure|correct|confirm|affirmative|go ahead|do it|please do|ok(?:ay)?)\b/,se=/^(?:no|nope|nah|cancel|never ?mind|don'?t|stop)\b/,ce=/^(?:end|close|stop|finish|hang ?up|quit|exit|bye|good ?bye)\b/,le=e=>{let t=ie(e);if(!t)return null;for(let{action:e,re:n}of ae)if(n.test(t)){let n=t.split(` `).length;return{action:e,confident:e===`end`?n<=10:n<=6}}return null},ue=e=>`I didn't catch yes or no. Say yes to ${re[e]}, or no to keep talking.`,d=({transport:t,config:i,bindControls:c,composerDraftStore:ee})=>{let l=i.strings,[u,ae]=(0,n.useState)(i.openByDefault),{persona:d,messages:f,sending:p,assistantSpeaking:m,visitor:de,hasEmail:fe,liveMode:h,assignedAgentName:pe,agentTypingName:me,starters:he,featuredLinks:ge,send:g,sendGif:_e,notifyTyping:ve,stop:ye,amend:be,hold:xe,resumeHeld:Se,duckSpeaking:Ce,retry:we,rateMessage:Te,injectAssistant:Ee,reconnectSupport:De,appendUserDraft:Oe,patchMessage:_,removeMessage:ke,submitCsat:Ae,submitForm:je,confirmHostedBooking:Me,transcribe:Ne,uploadAttachment:Pe,loadAttachment:Fe,searchGifs:Ie,demoSlots:Le,gifEnabled:Re,identify:ze,ended:v,endConversation:Be,startNew:Ve,history:He,viewingSessionId:Ue,viewMessages:We,openConversation:Ge,closeHistoryView:Ke,shutdown:qe,stopSpeaking:y,speakAssistantText:Je}=e.a(t,i,u),Ye=e.i(f,h),[Xe,Ze]=(0,n.useState)(null),Qe=(0,n.useRef)(0),$e=(0,n.useCallback)((e,t,n)=>{n===Qe.current&&Ze({status:`ready`,name:t,url:URL.createObjectURL(e),mimeType:e.type||`application/octet-stream`})},[]),et=(0,n.useCallback)((e,t,n)=>{let r=t.name,i=++Qe.current;Ze({status:`loading`,name:r}),Fe(e,t,n).then(e=>$e(e,r,i),()=>{i===Qe.current&&Ze({status:`error`,name:r})})},[Fe,$e]),tt=(0,n.useCallback)((e,t)=>$e(e,t,++Qe.current),[$e]),nt=(0,n.useCallback)(()=>{Qe.current+=1,Ze(null)},[]);(0,n.useEffect)(()=>()=>{Xe?.status===`ready`&&URL.revokeObjectURL(Xe.url)},[Xe]);let rt=!!e.r(d?.actions),[b,it]=(0,n.useState)(0),[x,at]=(0,n.useState)({mic:`off`,processing:!1}),[ot,st]=(0,n.useState)(null),[ct,lt]=(0,n.useState)(!1),[S,ut]=(0,n.useState)(!1),[dt,ft]=(0,n.useState)(!1),[pt,mt]=(0,n.useState)(!1),[ht,gt]=(0,n.useState)(0),[C,w]=(0,n.useState)(!1),[_t,T]=(0,n.useState)(null),[vt,yt]=(0,n.useState)([]),[bt,xt]=(0,n.useState)(``),[St,Ct]=(0,n.useState)(()=>{try{return localStorage.getItem(`centrinfo:muted`)===`1`}catch{return!1}}),wt=ne(i.theme),Tt=d?.soundEnabled??!0;(0,n.useEffect)(()=>{e.d(i.sound&&Tt&&!St)},[i.sound,Tt,St]);let Et=(0,n.useCallback)(()=>{Ct(e=>{let t=!e;try{localStorage.setItem(`centrinfo:muted`,t?`1`:`0`)}catch{}return t})},[]),E=(0,n.useRef)(null),Dt=(0,n.useRef)(null),Ot=(0,n.useRef)(null),kt=(0,n.useRef)(0),D=(0,n.useRef)(!1),O=(0,n.useRef)(!1),k=(0,n.useRef)(null),A=(0,n.useRef)(0),j=(0,n.useRef)(void 0),At=(0,n.useRef)(0),M=(0,n.useRef)(null),N=(0,n.useRef)(!1),P=(0,n.useRef)(null),F=(0,n.useRef)(``),jt=(0,n.useRef)(()=>{}),Mt=(0,n.useRef)(``),Nt=(0,n.useRef)(p),Pt=(0,n.useRef)(g);Pt.current=g;let Ft=(0,n.useRef)(be);Ft.current=be;let It=(0,n.useRef)(Ne);It.current=Ne;let I=(0,n.useRef)(!1),L=(0,n.useRef)(!1),Lt=(0,n.useRef)(``);Lt.current=[...f].reverse().find(e=>e.role===`assistant`)?.content??``;let Rt=(0,n.useRef)(m);Nt.current=p,Rt.current=m;let R=S?ct?`timeout`:pt||x.mic===`muted`?`muted`:x.mic===`unavailable`?x.reason===`permission-denied`||x.reason===`unsupported`?`denied`:`unavailable`:x.mic===`off`||x.mic===`starting`?`connecting`:x.mic===`hearing`?`hearing`:m?`speaking`:ot??(x.processing||p?`processing`:`listening`):`idle`,[zt,Bt]=(0,n.useState)(!0),[Vt,z]=(0,n.useState)(!1),Ht=(0,n.useRef)(0),[B,V]=(0,n.useState)(!1),[H,U]=(0,n.useState)(!1),Ut=(0,n.useRef)(null),[W,G]=(0,n.useState)(!1),Wt=(0,n.useRef)({value:``}),Gt=ee??Wt.current,Kt=(0,n.useRef)({confirmEnd:B,confirmClear:H,showHistory:W});Kt.current={confirmEnd:B,confirmClear:H,showHistory:W};let[qt,Jt]=(0,n.useState)(!1),K=!!Ue,Yt=K?We:f,Xt=Yt.find(e=>e.id===_t&&e.visualization)?.visualization;(0,n.useEffect)(()=>{!_t||Xt||(T(null),w(!1))},[Xt,_t]);let q=(0,n.useCallback)(()=>{ae(!0),it(0),e.u(`open`),i.onOpen?.(),i.onShow?.()},[i]),J=(0,n.useCallback)(()=>{ae(!1),w(!1),T(null),i.onClose?.(),i.onHide?.(),Dt.current?.focus()},[i]),Zt=(0,n.useCallback)(()=>u?J():q(),[u,q,J]),Qt=(0,n.useCallback)(()=>V(!0),[]),$t=(0,n.useCallback)(()=>{Be(),V(!1)},[Be]),en=(0,n.useCallback)(()=>{Ve(),z(!1),Bt(!0)},[Ve]);(0,n.useEffect)(()=>{B&&Ut.current?.focus()},[B]),(0,n.useEffect)(()=>{c({open:q,close:J,toggle:Zt,identify:ze,startNew:Ve,endConversation:Be,shutdown:qe})},[c,q,J,Zt,ze,Ve,Be,qe]),(0,n.useEffect)(()=>{let e=f.filter(e=>e.role===`assistant`&&!e.pending).length;if(u){kt.current=e;return}e>kt.current&&it(e-kt.current)},[f,u]),(0,n.useEffect)(()=>{i.onUnreadChange?.(b)},[b,i]),(0,n.useEffect)(()=>{let e=i.sessionDurationMinutes;if(!e||e<=0)return;let t=setTimeout(()=>qe(),e*60*1e3);return()=>clearTimeout(t)},[i.sessionDurationMinutes,f,u,qe]),(0,n.useEffect)(()=>{let e=i.customLauncherSelector;if(!e||typeof document>`u`)return;let t=[];try{t=Array.from(document.querySelectorAll(e))}catch{return}let n=e=>{e.preventDefault(),Zt()};return t.forEach(e=>e.addEventListener(`click`,n)),()=>t.forEach(e=>e.removeEventListener(`click`,n))},[i.customLauncherSelector,Zt]);let tn=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=i.proactiveMessage?.trim();if(!e||tn.current)return;let t=i.proactiveOnPaths??[],n=typeof location<`u`?location.pathname:``;if(t.length>0&&!t.some(e=>n.includes(e)))return;let r=`centrinfo:proactive:${i.token.slice(0,12)}`;try{if(sessionStorage.getItem(r)===`1`)return}catch{}let a=setTimeout(()=>{if(!(u||v||f.some(e=>e.role===`user`))){tn.current=!0;try{sessionStorage.setItem(r,`1`)}catch{}Ee(e),q()}},Math.max(0,i.proactiveDelaySeconds)*1e3);return()=>clearTimeout(a)},[i.proactiveMessage]),(0,n.useEffect)(()=>{let e=Ot.current;if(!u||!e)return;let t=f[f.length-1],n=Date.now()<Ht.current;t?.role===`user`||zt||n?(requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight}),z(!1),n&&Bt(!0)):z(!0)},[f,u,p,zt]);let nn=(0,n.useCallback)(()=>{let e=Ot.current;if(!e)return;if(D.current&&!K){Bt(!0),z(!1);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;Bt(t),t&&z(!1)},[K]),Y=(0,n.useCallback)(()=>{let e=Ot.current;e&&(e.scrollTop=e.scrollHeight),z(!1),Bt(!0)},[]),rn=(0,n.useCallback)(()=>{Ht.current=Date.now()+3e3,requestAnimationFrame(Y)},[Y]);(0,n.useEffect)(()=>{if(!u||K||!S||R===`connecting`)return;Ht.current=Date.now()+6e4,Y();let e=requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)}),t=[80,180,360].map(e=>window.setTimeout(Y,e));return()=>{cancelAnimationFrame(e),t.forEach(e=>window.clearTimeout(e))}},[m,f,u,Y,p,S,K,R]);let an=(0,n.useCallback)(()=>{E.current?.querySelector(`.cf-textarea`)?.focus()},[]),on=(0,n.useCallback)((e,t)=>{st(e),j.current&&window.clearTimeout(j.current),j.current=window.setTimeout(()=>st(null),3e3),t&&!O.current&&Je(t)},[Je]),sn=(0,n.useCallback)(e=>{let t=P.current;if(t)return t;rn();let n=Oe(e);return P.current=n,_(n,{content:F.current||e,pending:!0,streaming:!1}),n},[Oe,rn,_]),X=(0,n.useCallback)(()=>{let e=P.current;if(e){if(F.current){_(e,{content:F.current,pending:!0});return}P.current=null,ke(e)}},[_,ke]),Z=(0,n.useCallback)(()=>{L.current&&(L.current=!1,Ce(!1)),I.current&&(I.current=!1,Se())},[Ce,Se]),Q=(0,n.useCallback)(()=>{D.current=!1,k.current?.stop(`call-ended`),k.current=null,I.current=!1,L.current=!1,O.current=!1,M.current=null,N.current=!1;let e=P.current;P.current=null,F.current=``,e&&ke(e),j.current&&window.clearTimeout(j.current),st(null),lt(!1),at({mic:`off`,processing:!1}),gt(0),ut(!1),ft(!1),mt(!1),w(!1),T(null),y()},[ke,y]),cn=(0,n.useCallback)(()=>{C&&T(null),w(!C)},[C]),ln=(0,n.useCallback)(e=>{T(e),w(!0)},[]),un=(0,n.useCallback)(()=>{let e=_t;T(null),w(!1),window.requestAnimationFrame(()=>{Array.from(E.current?.querySelectorAll(`[data-visualization-message]`)??[]).find(t=>t.dataset.visualizationMessage===e)?.focus()})},[_t]),dn=(0,n.useCallback)(()=>{T(null),w(!1)},[]),fn=(0,n.useCallback)((e,t,n=!1)=>{if(rn(),t&&(_(t,{content:e,pending:!1,streaming:!1}),P.current===t&&(P.current=null)),F.current=``,n){y(),Ft.current(e,{forceVoicePlayback:!0,userMessageId:t});return}D.current&&(xe()?Ft.current(e,{forceVoicePlayback:!0,userMessageId:t}):Pt.current(e,{forceVoicePlayback:!0,userMessageId:t}))},[rn,xe,_,y]),$=(0,n.useCallback)(e=>{Ee(e),Je(e)},[Ee,Je]),pn=(0,n.useCallback)(()=>{if(A.current=Date.now(),st(null),Rt.current){L.current=!0,Ce(!0);return}I.current||(I.current=xe()),sn(`Listening...`)},[Ce,sn,xe]),mn=(0,n.useCallback)(e=>{let t=P.current;!t||L.current||_(t,{content:`${[F.current,e].filter(Boolean).join(` `)} ...`,pending:!0})},[_]),hn=(0,n.useCallback)(t=>{A.current=Date.now();let n=[F.current,t.text].map(e=>e.trim()).filter(Boolean).join(` `).replace(/\s+/g,` `).trim();if((L.current||t.overlappedOutput)&&e.V(t.text,Lt.current)){X(),Z();return}if(!n||e.p(n)||e.m(n)){let e=L.current||I.current;X(),Z(),e||on(`misunderstood`);return}L.current&&(L.current=!1,ye(),y());let r=M.current;if(r){F.current=``,X();let e=ie(n);if(oe.test(e)||r===`end`&&ce.test(e)){M.current=null,jt.current(r);return}if(se.test(e)){M.current=null,$(`Okay, never mind — what would you like to know?`);return}$(ue(r));return}let i=le(n);if(i){if(F.current=``,X(),Z(),i.confident){jt.current(i.action);return}M.current=i.action,$(`Just to confirm — you want me to ${re[i.action]}? Please say yes or no.`);return}let a=sn(n);_(a,{content:n,pending:!0});let o=I.current;I.current=!1,fn(n,a,o)},[sn,_,Z,fn,X,on,$,ye,y]),gn=(0,n.useCallback)(e=>{A.current=Date.now();let t=L.current||I.current;if(X(),Z(),!(t||e.overlappedOutput||e.reason===`too-short`)){if(e.reason===`transcribe-failed`){on(`misunderstood`,`I couldn't transcribe that. Please try again, or type your question.`);return}on(`noise`)}},[Z,X,on]),_n=(0,n.useRef)({speechStart:pn,partial:mn,turn:hn,noise:gn});_n.current={speechStart:pn,partial:mn,turn:hn,noise:gn};let vn=(0,n.useCallback)(()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{yt(e.filter(e=>e.kind===`audioinput`).map((e,t)=>({deviceId:e.deviceId,label:e.label||`Microphone ${t+1}`})))}).catch(()=>{})},[]),yn=(0,n.useCallback)(()=>{if(D.current){Q();return}if(an(),!d?.allowVoiceInput||!d.talkbackMode||d.talkbackMode===`text`||Nt.current||v||K)return;A.current=Date.now(),O.current=!1,D.current=!0,mt(!1),ut(!0),ft(!1),lt(!1);let t=!1,n=new e.B({deviceId:Mt.current||void 0,transcribe:async({audio:t,mimeType:n,durationSeconds:r})=>{let i=typeof navigator<`u`&&(navigator.languages?.[0]||navigator.language)||void 0;return e.h(await It.current(t,n,i,r))},listener:{state:e=>{at(e),e.mic!==`starting`&&e.mic!==`off`&&ft(!0),!t&&e.mic===`listening`&&(t=!0,vn())},speechStart:()=>_n.current.speechStart(),partial:({text:e})=>_n.current.partial(e),turn:e=>_n.current.turn(e),noise:e=>_n.current.noise(e),level:e=>{let t=performance.now();t-At.current<90||(At.current=t,gt(e))}}});k.current=n,n.setOutputActive(Rt.current),n.start()},[Q,v,an,d,vn,K]),bn=(0,n.useCallback)(()=>{let e=!O.current;O.current=e,mt(e),k.current?.setMuted(e),e?(F.current=``,X(),Z()):A.current=Date.now()},[Z,X]),xn=(0,n.useCallback)(e=>{switch(A.current=Date.now(),e){case`end`:N.current=!0,$(`Okay — ending our call now. Goodbye!`),window.setTimeout(()=>{N.current&&(N.current=!1,Q())},2e3);break;case`mute`:O.current||bn(),$(`Muted. Tap the mic button when you want me to listen again.`);break;case`minimize`:J(),$(`Minimized — I'm still listening. Tap the call pill to bring the chat back.`);break;case`expand`:w(!0),$(`Sure — expanding the view.`);break;case`shrink`:T(null),w(!1),$(`Okay — back to the smaller view.`);break}},[J,Q,$,bn]);(0,n.useEffect)(()=>{jt.current=xn},[xn]);let Sn=(0,n.useRef)(!1);(0,n.useEffect)(()=>{Sn.current&&!m&&N.current&&(N.current=!1,Q()),Sn.current=m},[m,Q]);let Cn=(0,n.useCallback)(e=>{Mt.current=e,xt(e),k.current?.selectDevice(e||void 0)},[]),wn=(0,n.useCallback)(()=>{!D.current||O.current||(L.current=!1,I.current=!1,ye(),y(),A.current=Date.now())},[ye,y]);(0,n.useEffect)(()=>{k.current?.setOutputActive(m),A.current=Date.now()},[m]),(0,n.useEffect)(()=>{if(R!==`denied`)return;let e=window.setTimeout(()=>Q(),3500);return()=>window.clearTimeout(e)},[Q,R]),(0,n.useEffect)(()=>{if(!S)return;let e=window.setInterval(()=>{let e=k.current;!e||O.current||Nt.current||Rt.current||e.snapshot.mic===`hearing`||e.snapshot.processing||Date.now()-A.current<6e4||(k.current?.log.add(`call-timeout`),lt(!0),window.setTimeout(()=>Q(),2400))},5e3);return()=>window.clearInterval(e)},[Q,S]);let Tn=S&&!pt&&(p||m);(0,n.useEffect)(()=>()=>Q(),[Q]);let[En,Dn]=(0,n.useState)(``),On=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(On.current&&!p){let e=[...f].reverse().find(e=>e.role===`assistant`&&!e.streaming&&!e.pending&&e.content);e&&Dn(e.content)}On.current=p},[p,f]),(0,n.useLayoutEffect)(()=>{if(!u)return;let e=E.current,t=B||H?e?.querySelector(`.cf-confirm__card`):W?e?.querySelector(`.cf-history`):null;if(!t)return;let n=t.getRootNode(),r=`activeElement`in n?n.activeElement:document.activeElement;(!r||!t.contains(r))&&t.querySelector(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`)?.focus()},[H,B,u,W]),(0,n.useEffect)(()=>{if(!u)return;let e=E.current,t=B||H?e?.querySelector(`.cf-confirm__card`):W?e?.querySelector(`.cf-history`):null,n=e?.querySelectorAll(`:scope > .cf-header, :scope > .cf-panel__video, :scope > .cf-panel__chat`);n?.forEach(e=>{t?(e.setAttribute(`inert`,``),e.setAttribute(`aria-hidden`,`true`)):(e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`))}),t||requestAnimationFrame(()=>e?.querySelector(`.cf-textarea`)?.focus());let r=e=>{if(e.key===`Escape`){e.preventDefault();let t=Kt.current;if(t.confirmEnd){V(!1);return}if(t.confirmClear){U(!1);return}if(t.showHistory){G(!1);return}J();return}if(e.key!==`Tab`||!t)return;let n=t.querySelectorAll(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`),r=Array.from(n).filter(e=>!e.hasAttribute(`disabled`));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=t.getRootNode()instanceof ShadowRoot?t.getRootNode().activeElement:document.activeElement;e.shiftKey&&o===i?(e.preventDefault(),a.focus()):!e.shiftKey&&o===a&&(e.preventDefault(),i.focus())};return e?.addEventListener(`keydown`,r),()=>{e?.removeEventListener(`keydown`,r),n?.forEach(e=>{e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`)})}},[u,J,B,H,W]),(0,n.useEffect)(()=>{let e=E.current;e&&(u?e.removeAttribute(`inert`):e.setAttribute(`inert`,``))},[u]);let kn=i.accentColor??i.themeTokens?.accent??d?.accentColor,An=i.themeTokens?.accentText??te(kn,i.themeTokens?.background??(wt===`dark`?`#0f1c27`:`#ffffff`)),jn={zIndex:i.zIndex,"--cf-h-pad":`${i.horizontalPadding}px`,"--cf-v-pad":`${i.verticalPadding}px`,...An?{"--cf-accent-ink":An}:{},...i.themeTokens?.accentStrong?{"--cf-accent-2":i.themeTokens.accentStrong}:{},...i.themeTokens?.background?{"--cf-bg":i.themeTokens.background}:{},...i.themeTokens?.surface?{"--cf-surface":i.themeTokens.surface}:{},...i.themeTokens?.surfaceMuted?{"--cf-surface-2":i.themeTokens.surfaceMuted}:{},...i.themeTokens?.text?{"--cf-text":i.themeTokens.text}:{},...i.themeTokens?.mutedText?{"--cf-muted":i.themeTokens.mutedText}:{},...i.themeTokens?.border?{"--cf-border":i.themeTokens.border}:{},...i.themeTokens?.shadow?{"--cf-shadow":i.themeTokens.shadow}:{},...i.themeTokens?.radius?{"--cf-radius":i.themeTokens.radius}:{},...i.themeTokens?.fontFamily?{"--cf-font":i.themeTokens.fontFamily}:{},...i.themeTokens?.success?{"--cf-success":i.themeTokens.success}:{},...i.themeTokens?.warning?{"--cf-warning":i.themeTokens.warning}:{},...i.themeTokens?.danger?{"--cf-danger":i.themeTokens.danger}:{},...kn?{"--cf-accent":kn,"--cf-accent-2":i.themeTokens?.accentStrong??`color-mix(in oklab, ${kn} 76%, #14141f)`}:{}},Mn=e=>g(e),Nn=[...f].reverse().find(e=>e.role===`user`&&e.content.trim())?.content??``,Pn=f.some(e=>e.role===`user`),Fn=!!(d?.allowVoiceInput&&d?.talkbackMode&&d.talkbackMode!==`text`),In=Fn,Ln=!K&&In&&!Pn?Yt.filter((e,t)=>!(t===0&&e.role===`assistant`)):Yt,Rn=h===`human`&&pe?pe:d?.agentName??l.chatName,zn=h===`human`?l.liveSupport:h===`queued`?l.waitingForTeam:d?.offline?l.statusOffline:l.statusOnline,Bn=!v&&!K?d?.availableActions:void 0,Vn=!v&&!K?d?.actions:void 0,Hn=S&&!dt&&R===`connecting`&&!K;return(0,r.jsx)(e.L,{value:l,children:(0,r.jsxs)(`div`,{class:`cf-root`,"data-theme":wt,"data-align":i.alignment,"data-display":`floating`,style:jn,children:[C&&u&&(0,r.jsx)(`div`,{class:`cf-theater-backdrop`,onClick:dn}),(0,r.jsxs)(`div`,{ref:E,class:`cf-panel ${u?`is-open`:``} ${S?`cf-panel--call`:``} ${Hn?`cf-panel--voice-connecting`:``} ${C&&u?`cf-panel--theater`:``} ${Xt?`cf-panel--analytics-focus`:``}`,role:`dialog`,"aria-modal":`false`,"aria-label":`${l.chatName}: ${d?.agentName??l.assistantName}`,"aria-hidden":!u,children:[Xe&&u&&(0,r.jsx)(a,{state:Xe,onClose:nt}),(0,r.jsxs)(`div`,{class:`cf-header`,children:[(0,r.jsx)(e.v,{persona:d,hideWhenMissing:!0}),(0,r.jsxs)(`div`,{class:`cf-header__meta`,children:[(0,r.jsx)(`div`,{class:`cf-header__name`,children:Rn}),(0,r.jsx)(`div`,{class:`cf-header__status ${h===`ai`&&d?.offline?`cf-header__status--offline`:``}`,children:(0,r.jsx)(`span`,{class:`cf-header__status-text`,children:zn})})]}),(0,r.jsxs)(`div`,{class:`cf-header__actions`,children:[He.length>0&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":l.pastConversations,title:l.pastConversations,"aria-pressed":W,onClick:()=>G(e=>!e),children:(0,r.jsx)(e.j,{})}),Pn&&!v&&!K&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":l.endChat,title:l.endChat,onClick:Qt,children:(0,r.jsx)(e.A,{})}),i.sound&&Tt&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":St?l.unmuteSounds:l.muteSounds,"aria-pressed":St,onClick:Et,children:St?(0,r.jsx)(e.M,{}):(0,r.jsx)(e.N,{})}),(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn cf-header__close`,"aria-label":l.closeChat,onClick:J,children:(0,r.jsx)(e.k,{})})]})]}),(0,r.jsx)(`div`,{class:`cf-panel__video`,children:Xt?(0,r.jsx)(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":l.expandedAnalyticsResult,children:(0,r.jsx)(e.T,{visualization:Xt,expanded:!0,onClose:un})}):!K&&In?(0,r.jsx)(e.y,{persona:d,starters:[],onPick:g,onFocusComposer:yn,speaking:m,voiceState:R,replyPending:S&&p&&!m,pinned:!0,muted:pt,onToggleMute:bn,onEndCall:Q,onTalkNow:wn,showTalkNow:Tn,micLevel:ht,theaterMode:C,onToggleTheater:cn,onMinimize:J,audioDevices:vt,selectedAudioDeviceId:bt,onSelectAudioDevice:Cn,connectingOnly:Hn}):null}),!Hn&&(0,r.jsxs)(`div`,{class:`cf-panel__chat`,children:[i.preview&&(0,r.jsx)(`div`,{class:`cf-preview-banner`,children:l.previewBanner}),K&&(0,r.jsx)(`div`,{class:`cf-viewing-banner`,children:l.viewingPast}),(0,r.jsxs)(`div`,{class:`cf-body`,ref:Ot,role:`log`,onScroll:nn,children:[Ln.map((t,n)=>(0,r.jsx)(e.C,{msg:t,persona:d,isLast:!K&&n===Ln.length-1,visitor:de,hasEmail:fe,lastQuestion:Nn,showActions:!K&&n===Ln.length-1&&!!(t.handoffOffered||t.selectedAction),onPickReply:Mn,onSubmitForm:je,onDemoSlots:Le,onConfirmHostedBooking:Me,onRetry:we,ratable:!K&&Ln.slice(0,n).some(e=>e.role===`user`),onRate:Te,onExpandVisualization:K?void 0:ln,onOpenAttachment:et,onReconnect:!K&&!v&&rt&&t.id===Ye?De:void 0},t.id)),!Pn&&!K&&(0,r.jsxs)(r.Fragment,{children:[Ln.length===0&&(0,r.jsx)(o,{name:d?.agentName??l.assistantName,greeting:d?.greeting}),(0,r.jsx)(e.w,{items:he,onPick:g}),(0,r.jsx)(e.x,{items:ge})]}),Vt&&(0,r.jsxs)(`button`,{type:`button`,class:`cf-newmsg`,onClick:Y,children:[(0,r.jsx)(e.D,{}),l.newMessages]})]}),(0,r.jsx)(`div`,{class:`cf-sr-live`,"aria-live":`polite`,"aria-atomic":`true`,children:En}),p&&!v&&!K&&(0,r.jsx)(`div`,{class:`cf-stopbar`,children:(0,r.jsxs)(`button`,{type:`button`,class:`cf-stop`,onClick:ye,children:[(0,r.jsx)(e.P,{}),l.stop]})}),K?(0,r.jsx)(`div`,{class:`cf-ended`,children:(0,r.jsx)(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Ke,children:l.backToChat})}):v?(0,r.jsxs)(`div`,{class:`cf-ended`,children:[(0,r.jsx)(`p`,{class:`cf-ended__text`,children:l.conversationEnded}),i.csat&&Pn?qt?(0,r.jsx)(`p`,{class:`cf-ended__text`,children:l.feedbackThanks}):(0,r.jsxs)(`div`,{class:`cf-csat`,children:[(0,r.jsx)(`span`,{class:`cf-csat__q`,children:l.csatPrompt}),(0,r.jsx)(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":l.feedbackHelpful,onClick:()=>{Ae(`up`),Jt(!0)},children:(0,r.jsx)(e.I,{})}),(0,r.jsx)(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":l.feedbackNotHelpful,onClick:()=>{Ae(`down`),Jt(!0)},children:(0,r.jsx)(e.F,{})})]}):null,(0,r.jsx)(`button`,{type:`button`,class:`cf-ended__btn`,onClick:en,children:l.startNewChat})]}):(0,r.jsxs)(r.Fragment,{children:[me?(0,r.jsx)(`div`,{class:`cf-live-typing`,"aria-live":`polite`,children:e.R(l.agentTyping,{name:me})}):null,Bn&&Bn.length>0&&(0,r.jsx)(`div`,{class:`cf-footer-actions`,children:(0,r.jsx)(e._,{actions:Bn,descriptors:Vn,visitor:de,onSubmitForm:je,onDemoSlots:Le,onConfirmHostedBooking:Me,scheduler:d?.scheduler,translations:i.actionTranslations})},`footer-actions`),(0,r.jsx)(e.b,{draftStore:Gt,onSend:g,onSendGif:_e,onTyping:ve,disabled:p,allowVoice:Fn,onTranscribe:Ne,gifEnabled:Re,onSearchGifs:Ie,allowAttach:i.attachments,analyzeAttachments:!0,onUpload:Pe,onPreviewAttachment:tt},`composer`)]}),!v&&d?.disclaimerText&&(0,r.jsx)(`div`,{class:`cf-disclaimer`,children:d.disclaimerText}),(0,r.jsxs)(`div`,{class:`cf-footer`,children:[(0,r.jsx)(`button`,{type:`button`,class:`cf-footer__privacy`,"aria-label":l.clearDeviceData,onClick:()=>U(!0),children:l.privacyAndData}),(0,r.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),l.poweredBy,` `,(0,r.jsx)(`a`,{href:`https://accurix.tech/centrinfo`,target:`_blank`,rel:`noopener noreferrer`,children:`Centrinfo`})]})]}),B&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>V(!1),children:(0,r.jsxs)(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":l.endChatConfirm,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>s(e,e.currentTarget,()=>V(!1)),children:[(0,r.jsx)(`div`,{class:`cf-confirm__title`,children:l.endChatConfirm}),(0,r.jsx)(`div`,{class:`cf-confirm__body`,children:l.endChatConfirmBody}),(0,r.jsxs)(`div`,{class:`cf-confirm__actions`,children:[(0,r.jsx)(`button`,{ref:Ut,type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>V(!1),children:l.cancel}),(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:$t,children:l.endConfirmCta})]})]})},`confirm-end`),W&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>G(!1),children:(0,r.jsxs)(`div`,{class:`cf-history`,role:`dialog`,"aria-modal":`true`,"aria-label":l.pastConversations,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>s(e,e.currentTarget,()=>G(!1)),children:[(0,r.jsxs)(`div`,{class:`cf-history__head`,children:[(0,r.jsx)(`span`,{children:l.pastConversations}),(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":l.closeHistory,onClick:()=>G(!1),children:(0,r.jsx)(e.k,{})})]}),(0,r.jsx)(`div`,{class:`cf-history__list`,children:He.map(e=>(0,r.jsxs)(`button`,{type:`button`,class:`cf-history__item ${e.sessionId===Ue?`is-active`:``}`,onClick:()=>{Ge(e.sessionId),G(!1)},children:[(0,r.jsx)(`span`,{class:`cf-history__title`,children:e.title}),(0,r.jsxs)(`span`,{class:`cf-history__meta`,children:[new Date(e.ts).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),e.ended?` · ${l.historyEnded}`:``]})]},e.sessionId))}),(0,r.jsx)(`div`,{class:`cf-history__footer`,children:(0,r.jsx)(`button`,{type:`button`,class:`cf-history__clear`,onClick:()=>{G(!1),U(!0)},children:l.clearDeviceData})})]})},`history`),H&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>U(!1),children:(0,r.jsxs)(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":l.clearDeviceData,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>s(e,e.currentTarget,()=>U(!1)),children:[(0,r.jsx)(`div`,{class:`cf-confirm__title`,children:l.clearDeviceData}),(0,r.jsx)(`div`,{class:`cf-confirm__body`,children:l.clearDeviceDataBody}),(0,r.jsxs)(`div`,{class:`cf-confirm__actions`,children:[(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>U(!1),children:l.cancel}),(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:()=>{U(!1),qe()},children:l.clearDeviceDataCta})]})]})},`confirm-clear`)]}),S&&!u?(0,r.jsx)(e.S,{persona:d,voiceState:R,muted:pt,onToggleMute:bn,onEndCall:Q,micLevel:ht,onExpand:q}):C&&u?null:!i.hideDefaultLauncher&&(0,r.jsxs)(`button`,{ref:Dt,type:`button`,class:`cf-launcher`,"aria-label":u?l.closeChat:b>0?`${l.openChat}. ${b===1?l.unreadMessage:e.R(l.unreadMessages,{count:String(b)})}`:l.openChat,"aria-expanded":u,onClick:Zt,children:[i.launcherIcon?(0,r.jsx)(`img`,{class:`cf-launcher__img`,src:i.launcherIcon,alt:``}):(0,r.jsx)(e.O,{}),!u&&b>0&&(0,r.jsx)(`span`,{class:`cf-launcher__badge`,"aria-hidden":`true`,children:b>99?`99+`:b})]})]})})},f=`centrinfo-widget`;var p=class extends HTMLElement{constructor(...t){super(...t),e.H(this,`controls`,null),e.H(this,`composerDraftStore`,{value:``})}mountWith(n){let i=e.n(n),a=this.shadowRoot??this.attachShadow({mode:`open`});if(this.style.zIndex=String(i.zIndex),`adoptedStyleSheets`in Document.prototype&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`){let t=new CSSStyleSheet;t.replaceSync(e.t),a.adoptedStyleSheets=[t]}else{let t=document.createElement(`style`);i.styleNonce&&(t.nonce=i.styleNonce),t.textContent=e.t,a.appendChild(t)}(0,t.render)((0,r.jsx)(d,{transport:i.demo?new e.Y:i.preview?new e.J(new e.X(i.apiBaseUrl,i.token,i.gifApiKey,i.analyticsContextToken,{agentName:i.agentName,agentAvatarUrl:i.agentAvatarUrl},i.identityToken,i.getIdentityToken,i.chatSurface),i.strings):new e.X(i.apiBaseUrl,i.token,i.gifApiKey,i.analyticsContextToken,{agentName:i.agentName,agentAvatarUrl:i.agentAvatarUrl},i.identityToken,i.getIdentityToken,i.chatSurface),config:i,bindControls:e=>this.controls=e,composerDraftStore:this.composerDraftStore}),a)}open(){this.controls?.open()}close(){this.controls?.close()}toggle(){this.controls?.toggle()}identify(e){this.controls?.identify(e)}clear(){this.controls?.startNew()}shutdown(){this.controls?.shutdown()}unmount(){this.shadowRoot&&(0,t.render)(null,this.shadowRoot)}};typeof customElements<`u`&&!customElements.get(f)&&customElements.define(f,p);const m=(e,t=document.body)=>{if(typeof document>`u`)throw Error(`[centrinfo-widget] createWidget must run in a browser.`);let n=document.createElement(f);return n.style.pointerEvents=`none`,n.style.position=`fixed`,n.style.inset=`0`,n.style.width=`0`,n.style.height=`0`,t.appendChild(n),n.mountWith(e),{open:()=>n.open(),close:()=>n.close(),toggle:()=>n.toggle(),show:()=>n.open(),hide:()=>n.close(),identify:e=>n.identify(e),update:e=>n.identify(e),clear:()=>n.clear(),shutdown:()=>n.shutdown(),logout:()=>n.shutdown(),destroy:()=>{n.unmount(),n.remove()}}},de=e=>m(e);let fe=null;const h=e=>{fe?.destroy();let t=de(e);return fe=t,t},pe={init:h,createWidget:de};exports.Centrinfo=pe,exports.createWidget=de,exports.init=h;
1
+ const e=require(`./styles-BH7P8Q_3.cjs`);let t=require(`preact`),n=require(`preact/hooks`),r=require(`preact/jsx-runtime`);const i=(e,t)=>{if(typeof MutationObserver>`u`)return()=>void 0;let n=e.scrollHeight,r=0,i=()=>{r=0;let i=e.scrollHeight,a=i>n,o=t.isAtBottom();n=i,a&&(o?(e.scrollTop=e.scrollHeight,t.onFollow?.()):t.onUnseen?.())},a=new MutationObserver(()=>{r||(r=typeof requestAnimationFrame==`function`?requestAnimationFrame(i):setTimeout(i,0))});return a.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{a.disconnect(),r&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(r)}},a=e=>e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:`other`,o=({state:t,onClose:i})=>{let o=e.V(),s=(0,n.useRef)(null);(0,n.useEffect)(()=>{s.current?.focus();let e=e=>{e.key===`Escape`&&(e.stopPropagation(),i())};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i]);let c=t.status===`ready`?a(t.mimeType):`other`;return(0,r.jsx)(`div`,{class:`cf-preview`,role:`dialog`,"aria-modal":`true`,"aria-label":e.B(o.attachPreviewTitle,{name:t.name}),onClick:e=>{e.target===e.currentTarget&&i()},children:(0,r.jsxs)(`div`,{class:`cf-preview__frame`,children:[(0,r.jsxs)(`div`,{class:`cf-preview__bar`,children:[(0,r.jsx)(`span`,{class:`cf-preview__name`,title:t.name,children:t.name}),t.status===`ready`&&(0,r.jsx)(`a`,{class:`cf-preview__btn`,href:t.url,download:t.name,children:o.attachDownload}),(0,r.jsx)(`button`,{ref:s,type:`button`,class:`cf-preview__btn cf-preview__close`,"aria-label":o.attachPreviewClose,onClick:i,children:`✕`})]}),(0,r.jsxs)(`div`,{class:`cf-preview__body`,children:[t.status===`loading`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewLoading}),t.status===`error`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewFailed}),t.status===`ready`&&c===`image`&&(0,r.jsx)(`img`,{class:`cf-preview__image`,src:t.url,alt:t.name}),t.status===`ready`&&c===`pdf`&&(0,r.jsx)(`iframe`,{class:`cf-preview__pdf`,src:t.url,title:t.name}),t.status===`ready`&&c===`other`&&(0,r.jsx)(`p`,{class:`cf-preview__note`,children:o.attachPreviewUnsupported})]})]})})},s=({name:t,greeting:n})=>{let i=e.V();return(0,r.jsxs)(`section`,{class:`cf-empty-welcome`,"aria-label":e.B(i.welcomeLabel,{name:t}),children:[(0,r.jsx)(`span`,{class:`cf-empty-welcome__eyebrow`,children:i.welcomeEyebrow}),(0,r.jsx)(`h2`,{children:t}),(0,r.jsx)(`p`,{children:n||i.welcomePrompt})]})},c=(e,t,n)=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),n();return}if(e.key!==`Tab`)return;let r=Array.from(t.querySelectorAll(`button, [href], textarea, input, select, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`&&e.tabIndex>=0);if(r.length===0)return;let i=t.getRootNode(),a=e.composedPath()[0],o=a instanceof HTMLElement?a:`activeElement`in i?i.activeElement:document.activeElement,s=r[0],c=r[r.length-1];e.shiftKey&&(o===s||!t.contains(o))?(e.preventDefault(),e.stopPropagation(),c.focus()):!e.shiftKey&&(o===c||!t.contains(o))&&(e.preventDefault(),e.stopPropagation(),s.focus())},l=new Map,ee=e=>{if(!e||typeof document>`u`||typeof CanvasRenderingContext2D>`u`)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.fillStyle=`#010203`,t.fillStyle=e;let n=t.fillStyle;if(n===`#010203`&&e.trim().toLowerCase()!==`#010203`)return;let r=n.match(/^#([\da-f]{6})$/i)?.[1];if(r)return[Number.parseInt(r.slice(0,2),16),Number.parseInt(r.slice(2,4),16),Number.parseInt(r.slice(4,6),16),1];let i=n.match(/^rgba?\(([\d.]+)[, ]+([\d.]+)[, ]+([\d.]+)(?:[, /]+([\d.]+))?\)$/i);if(!i)return;let a=i.slice(1,5).map(Number);if(!a.some(e=>!Number.isFinite(e)))return[a[0],a[1],a[2],a[3]??1]},te=(e,t=`#ffffff`)=>{let n=`${e??``}|${t}`;if(l.has(n))return l.get(n);let r=ee(e),i=ee(t)??[255,255,255,1];if(!r){l.set(n,void 0);return}let a=r[3],o=r.slice(0,3).map((e,t)=>e*a+i[t]*(1-a)).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}),s=o[0]*.2126+o[1]*.7152+o[2]*.0722,c=1.05/(s+.05)>=(s+.05)/.059?`#ffffff`:`#0f1e2a`;return l.set(n,c),c},ne=e=>{let[t,r]=(0,n.useState)(`light`);return(0,n.useEffect)(()=>{if(e!==`auto`||typeof matchMedia>`u`)return;let t=matchMedia(`(prefers-color-scheme: dark)`),n=()=>r(t.matches?`dark`:`light`);return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},[e]),e===`auto`?t:e},u=6e4,d=90,re={end:`end the call`,mute:`mute your microphone`,minimize:`minimize the chat`,expand:`expand the view`,shrink:`exit the expanded view`},ie=e=>e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s']/gu,` `).replace(/\s+/g,` `).trim(),ae=[{action:`shrink`,re:/\b(?:exit|leave|quit|close)\b[\s\w]*\b(?:full ?screen|expanded|theat(?:er|re))\b|\bshrink\b|\bsmaller view\b/},{action:`end`,re:/\b(?:end|close|stop|finish|hang ?up|quit|exit)\b[\s\w]*\b(?:call|chat|conversation|convo|session|talking)\b|\bhang ?up\b|\bgood ?bye\b|^bye(?: bye)?$/},{action:`mute`,re:/\bmute\b|\bstop listening\b/},{action:`minimize`,re:/\bminimi[sz]e\b|\bhide\b[\s\w]*\b(?:chat|call|window|widget)\b/},{action:`expand`,re:/\bexpand\b|\bmaximi[sz]e\b|\bfull ?screen\b|\btheat(?:er|re) mode\b|\bbigger view\b/}],oe=/^(?:yes|yeah|yep|yup|sure|correct|confirm|affirmative|go ahead|do it|please do|ok(?:ay)?)\b/,se=/^(?:no|nope|nah|cancel|never ?mind|don'?t|stop)\b/,ce=/^(?:end|close|stop|finish|hang ?up|quit|exit|bye|good ?bye)\b/,le=e=>{let t=ie(e);if(!t)return null;for(let{action:e,re:n}of ae)if(n.test(t)){let n=t.split(` `).length;return{action:e,confident:e===`end`?n<=10:n<=6}}return null},ue=e=>`I didn't catch yes or no. Say yes to ${re[e]}, or no to keep talking.`,f=({transport:t,config:a,bindControls:l,composerDraftStore:ee})=>{let u=a.strings,[d,ae]=(0,n.useState)(a.openByDefault),{persona:f,messages:p,sending:m,assistantSpeaking:h,visitor:de,hasEmail:fe,liveMode:g,assignedAgentName:pe,agentTypingName:me,starters:he,featuredLinks:ge,send:_,sendGif:_e,notifyTyping:ve,stop:ye,amend:be,hold:xe,resumeHeld:Se,duckSpeaking:Ce,retry:we,rateMessage:Te,rateExplanation:Ee,explanationTransport:De,injectAssistant:Oe,reconnectSupport:ke,appendUserDraft:Ae,patchMessage:v,removeMessage:je,submitCsat:Me,submitForm:Ne,confirmHostedBooking:Pe,transcribe:Fe,uploadAttachment:Ie,loadAttachment:Le,searchGifs:Re,demoSlots:ze,gifEnabled:Be,identify:Ve,ended:y,endConversation:He,startNew:Ue,history:We,viewingSessionId:Ge,viewMessages:Ke,openConversation:qe,closeHistoryView:Je,shutdown:Ye,stopSpeaking:b,speakAssistantText:Xe}=e.a(t,a,d),Ze=e.i(p,g),[Qe,$e]=(0,n.useState)(null),et=(0,n.useRef)(0),tt=(0,n.useCallback)((e,t,n)=>{n===et.current&&$e({status:`ready`,name:t,url:URL.createObjectURL(e),mimeType:e.type||`application/octet-stream`})},[]),nt=(0,n.useCallback)((e,t,n)=>{let r=t.name,i=++et.current;$e({status:`loading`,name:r}),Le(e,t,n).then(e=>tt(e,r,i),()=>{i===et.current&&$e({status:`error`,name:r})})},[Le,tt]),rt=(0,n.useCallback)((e,t)=>tt(e,t,++et.current),[tt]),it=(0,n.useCallback)(()=>{et.current+=1,$e(null)},[]);(0,n.useEffect)(()=>()=>{Qe?.status===`ready`&&URL.revokeObjectURL(Qe.url)},[Qe]);let at=!!e.r(f?.actions),[x,ot]=(0,n.useState)(0),[S,st]=(0,n.useState)({mic:`off`,processing:!1}),[ct,lt]=(0,n.useState)(null),[ut,dt]=(0,n.useState)(!1),[C,ft]=(0,n.useState)(!1),[pt,mt]=(0,n.useState)(!1),[ht,gt]=(0,n.useState)(!1),[_t,vt]=(0,n.useState)(0),[w,T]=(0,n.useState)(!1),[yt,E]=(0,n.useState)(null),[bt,xt]=(0,n.useState)(null),[St,Ct]=(0,n.useState)([]),[wt,Tt]=(0,n.useState)(``),[Et,Dt]=(0,n.useState)(()=>{try{return localStorage.getItem(`centrinfo:muted`)===`1`}catch{return!1}}),Ot=ne(a.theme),kt=f?.soundEnabled??!0;(0,n.useEffect)(()=>{e.d(a.sound&&kt&&!Et)},[a.sound,kt,Et]);let At=(0,n.useCallback)(()=>{Dt(e=>{let t=!e;try{localStorage.setItem(`centrinfo:muted`,t?`1`:`0`)}catch{}return t})},[]),D=(0,n.useRef)(null),jt=(0,n.useRef)(null),Mt=(0,n.useRef)(null),Nt=(0,n.useRef)(0),O=(0,n.useRef)(!1),k=(0,n.useRef)(!1),A=(0,n.useRef)(null),j=(0,n.useRef)(0),Pt=(0,n.useRef)(void 0),Ft=(0,n.useRef)(0),It=(0,n.useRef)(null),M=(0,n.useRef)(!1),N=(0,n.useRef)(null),P=(0,n.useRef)(``),Lt=(0,n.useRef)(()=>{}),Rt=(0,n.useRef)(``),zt=(0,n.useRef)(m),Bt=(0,n.useRef)(_);Bt.current=_;let Vt=(0,n.useRef)(be);Vt.current=be;let Ht=(0,n.useRef)(Fe);Ht.current=Fe;let F=(0,n.useRef)(!1),I=(0,n.useRef)(!1),Ut=(0,n.useRef)(``);Ut.current=[...p].reverse().find(e=>e.role===`assistant`)?.content??``;let Wt=(0,n.useRef)(h);zt.current=m,Wt.current=h;let L=C?ut?`timeout`:ht||S.mic===`muted`?`muted`:S.mic===`unavailable`?S.reason===`permission-denied`||S.reason===`unsupported`?`denied`:`unavailable`:S.mic===`off`||S.mic===`starting`?`connecting`:S.mic===`hearing`?`hearing`:h?`speaking`:ct??(S.processing||m?`processing`:`listening`):`idle`,[Gt,Kt]=(0,n.useState)(!0),[qt,R]=(0,n.useState)(!1),Jt=(0,n.useRef)(0),[z,B]=(0,n.useState)(!1),[V,H]=(0,n.useState)(!1),Yt=(0,n.useRef)(null),[U,W]=(0,n.useState)(!1),Xt=(0,n.useRef)({value:``}),Zt=ee??Xt.current,Qt=(0,n.useRef)({confirmEnd:z,confirmClear:V,showHistory:U});Qt.current={confirmEnd:z,confirmClear:V,showHistory:U};let[$t,en]=(0,n.useState)(!1),G=!!Ge,tn=G?Ke:p,nn=tn.find(e=>e.id===yt&&e.visualization)?.visualization,rn=tn.find(e=>e.id===bt&&e.visualization);(0,n.useEffect)(()=>{!bt||rn||(xt(null),T(!1))},[bt,rn]),(0,n.useEffect)(()=>{!yt||nn||(E(null),T(!1))},[nn,yt]);let K=(0,n.useCallback)(()=>{ae(!0),ot(0),e.u(`open`),a.onOpen?.(),a.onShow?.()},[a]),q=(0,n.useCallback)(()=>{ae(!1),T(!1),E(null),a.onClose?.(),a.onHide?.(),jt.current?.focus()},[a]),an=(0,n.useCallback)(()=>d?q():K(),[d,K,q]),on=(0,n.useCallback)(()=>B(!0),[]),sn=(0,n.useCallback)(()=>{He(),B(!1)},[He]),cn=(0,n.useCallback)(()=>{Ue(),R(!1),Kt(!0)},[Ue]);(0,n.useEffect)(()=>{z&&Yt.current?.focus()},[z]),(0,n.useEffect)(()=>{l({open:K,close:q,toggle:an,identify:Ve,startNew:Ue,endConversation:He,shutdown:Ye})},[l,K,q,an,Ve,Ue,He,Ye]),(0,n.useEffect)(()=>{let e=p.filter(e=>e.role===`assistant`&&!e.pending).length;if(d){Nt.current=e;return}e>Nt.current&&ot(e-Nt.current)},[p,d]),(0,n.useEffect)(()=>{a.onUnreadChange?.(x)},[x,a]),(0,n.useEffect)(()=>{let e=a.sessionDurationMinutes;if(!e||e<=0)return;let t=setTimeout(()=>Ye(),e*60*1e3);return()=>clearTimeout(t)},[a.sessionDurationMinutes,p,d,Ye]),(0,n.useEffect)(()=>{let e=a.customLauncherSelector;if(!e||typeof document>`u`)return;let t=[];try{t=Array.from(document.querySelectorAll(e))}catch{return}let n=e=>{e.preventDefault(),an()};return t.forEach(e=>e.addEventListener(`click`,n)),()=>t.forEach(e=>e.removeEventListener(`click`,n))},[a.customLauncherSelector,an]);let ln=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=a.proactiveMessage?.trim();if(!e||ln.current)return;let t=a.proactiveOnPaths??[],n=typeof location<`u`?location.pathname:``;if(t.length>0&&!t.some(e=>n.includes(e)))return;let r=`centrinfo:proactive:${a.token.slice(0,12)}`;try{if(sessionStorage.getItem(r)===`1`)return}catch{}let i=setTimeout(()=>{if(!(d||y||p.some(e=>e.role===`user`))){ln.current=!0;try{sessionStorage.setItem(r,`1`)}catch{}Oe(e),K()}},Math.max(0,a.proactiveDelaySeconds)*1e3);return()=>clearTimeout(i)},[a.proactiveMessage]),(0,n.useEffect)(()=>{let e=Mt.current;if(!d||!e)return;let t=p[p.length-1],n=Date.now()<Jt.current;t?.role===`user`||Gt||n?(requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight}),R(!1),n&&Kt(!0)):R(!0)},[p,d,m,Gt]);let un=(0,n.useRef)(!0);un.current=Gt,(0,n.useEffect)(()=>{let e=Mt.current;if(!(!d||!e))return i(e,{isAtBottom:()=>un.current,onUnseen:()=>R(!0)})},[d,G]);let dn=(0,n.useCallback)(()=>{let e=Mt.current;if(!e)return;if(O.current&&!G){Kt(!0),R(!1);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;Kt(t),t&&R(!1)},[G]),J=(0,n.useCallback)(()=>{let e=Mt.current;e&&(e.scrollTop=e.scrollHeight),R(!1),Kt(!0)},[]),fn=(0,n.useCallback)(()=>{Jt.current=Date.now()+3e3,requestAnimationFrame(J)},[J]);(0,n.useEffect)(()=>{if(!d||G||!C||L===`connecting`)return;Jt.current=Date.now()+6e4,J();let e=requestAnimationFrame(()=>{J(),requestAnimationFrame(J)}),t=[80,180,360].map(e=>window.setTimeout(J,e));return()=>{cancelAnimationFrame(e),t.forEach(e=>window.clearTimeout(e))}},[h,p,d,J,m,C,G,L]);let pn=(0,n.useCallback)(()=>{D.current?.querySelector(`.cf-textarea`)?.focus()},[]),Y=(0,n.useCallback)((e,t)=>{lt(e),Pt.current&&window.clearTimeout(Pt.current),Pt.current=window.setTimeout(()=>lt(null),3e3),t&&!k.current&&Xe(t)},[Xe]),mn=(0,n.useCallback)(e=>{let t=N.current;if(t)return t;fn();let n=Ae(e);return N.current=n,v(n,{content:P.current||e,pending:!0,streaming:!1}),n},[Ae,fn,v]),X=(0,n.useCallback)(()=>{let e=N.current;if(e){if(P.current){v(e,{content:P.current,pending:!0});return}N.current=null,je(e)}},[v,je]),Z=(0,n.useCallback)(()=>{I.current&&(I.current=!1,Ce(!1)),F.current&&(F.current=!1,Se())},[Ce,Se]),Q=(0,n.useCallback)(()=>{O.current=!1,A.current?.stop(`call-ended`),A.current=null,F.current=!1,I.current=!1,k.current=!1,It.current=null,M.current=!1;let e=N.current;N.current=null,P.current=``,e&&je(e),Pt.current&&window.clearTimeout(Pt.current),lt(null),dt(!1),st({mic:`off`,processing:!1}),vt(0),ft(!1),mt(!1),gt(!1),T(!1),E(null),b()},[je,b]),hn=(0,n.useCallback)(()=>{w&&E(null),T(!w)},[w]),gn=(0,n.useCallback)(e=>{E(e),T(!0)},[]),_n=(0,n.useCallback)(e=>{xt(e),T(!0)},[]),vn=(0,n.useCallback)(()=>{let e=yt,t=bt;E(null),xt(null),T(!1),window.requestAnimationFrame(()=>{(t?D.current?.querySelector(`[data-explanation-message="${t}"]`)?.querySelector(`[data-testid="analytics-explanation-expand"]`):Array.from(D.current?.querySelectorAll(`[data-visualization-message]`)??[]).find(t=>t.dataset.visualizationMessage===e))?.focus()})},[yt,bt]),yn=(0,n.useCallback)(()=>{E(null),xt(null),T(!1)},[]),bn=(0,n.useCallback)((e,t,n=!1)=>{if(fn(),t&&(v(t,{content:e,pending:!1,streaming:!1}),N.current===t&&(N.current=null)),P.current=``,n){b(),Vt.current(e,{forceVoicePlayback:!0,userMessageId:t});return}O.current&&(xe()?Vt.current(e,{forceVoicePlayback:!0,userMessageId:t}):Bt.current(e,{forceVoicePlayback:!0,userMessageId:t}))},[fn,xe,v,b]),$=(0,n.useCallback)(e=>{Oe(e),Xe(e)},[Oe,Xe]),xn=(0,n.useCallback)(()=>{if(j.current=Date.now(),lt(null),Wt.current){I.current=!0,Ce(!0);return}F.current||(F.current=xe()),mn(`Listening...`)},[Ce,mn,xe]),Sn=(0,n.useCallback)(e=>{let t=N.current;!t||I.current||v(t,{content:`${[P.current,e].filter(Boolean).join(` `)} ...`,pending:!0})},[v]),Cn=(0,n.useCallback)(t=>{j.current=Date.now();let n=[P.current,t.text].map(e=>e.trim()).filter(Boolean).join(` `).replace(/\s+/g,` `).trim();if((I.current||t.overlappedOutput)&&e.U(t.text,Ut.current)){X(),Z();return}if(!n||e.p(n)||e.m(n)){let e=I.current||F.current;X(),Z(),e||Y(`misunderstood`);return}I.current&&(I.current=!1,ye(),b());let r=It.current;if(r){P.current=``,X();let e=ie(n);if(oe.test(e)||r===`end`&&ce.test(e)){It.current=null,Lt.current(r);return}if(se.test(e)){It.current=null,$(`Okay, never mind — what would you like to know?`);return}$(ue(r));return}let i=le(n);if(i){if(P.current=``,X(),Z(),i.confident){Lt.current(i.action);return}It.current=i.action,$(`Just to confirm — you want me to ${re[i.action]}? Please say yes or no.`);return}let a=mn(n);v(a,{content:n,pending:!0});let o=F.current;F.current=!1,bn(n,a,o)},[mn,v,Z,bn,X,Y,$,ye,b]),wn=(0,n.useCallback)(e=>{j.current=Date.now();let t=I.current||F.current;if(X(),Z(),!(t||e.overlappedOutput||e.reason===`too-short`)){if(e.reason===`transcribe-failed`){Y(`misunderstood`,`I couldn't transcribe that. Please try again, or type your question.`);return}Y(`noise`)}},[Z,X,Y]),Tn=(0,n.useRef)({speechStart:xn,partial:Sn,turn:Cn,noise:wn});Tn.current={speechStart:xn,partial:Sn,turn:Cn,noise:wn};let En=(0,n.useCallback)(()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{Ct(e.filter(e=>e.kind===`audioinput`).map((e,t)=>({deviceId:e.deviceId,label:e.label||`Microphone ${t+1}`})))}).catch(()=>{})},[]),Dn=(0,n.useCallback)(()=>{if(O.current){Q();return}if(pn(),!f?.allowVoiceInput||!f.talkbackMode||f.talkbackMode===`text`||zt.current||y||G)return;j.current=Date.now(),k.current=!1,O.current=!0,gt(!1),ft(!0),mt(!1),dt(!1);let t=!1,n=new e.H({deviceId:Rt.current||void 0,transcribe:async({audio:t,mimeType:n,durationSeconds:r})=>{let i=typeof navigator<`u`&&(navigator.languages?.[0]||navigator.language)||void 0;return e.h(await Ht.current(t,n,i,r))},listener:{state:e=>{st(e),e.mic!==`starting`&&e.mic!==`off`&&mt(!0),!t&&e.mic===`listening`&&(t=!0,En())},speechStart:()=>Tn.current.speechStart(),partial:({text:e})=>Tn.current.partial(e),turn:e=>Tn.current.turn(e),noise:e=>Tn.current.noise(e),level:e=>{let t=performance.now();t-Ft.current<90||(Ft.current=t,vt(e))}}});A.current=n,n.setOutputActive(Wt.current),n.start()},[Q,y,pn,f,En,G]),On=(0,n.useCallback)(()=>{let e=!k.current;k.current=e,gt(e),A.current?.setMuted(e),e?(P.current=``,X(),Z()):j.current=Date.now()},[Z,X]),kn=(0,n.useCallback)(e=>{switch(j.current=Date.now(),e){case`end`:M.current=!0,$(`Okay — ending our call now. Goodbye!`),window.setTimeout(()=>{M.current&&(M.current=!1,Q())},2e3);break;case`mute`:k.current||On(),$(`Muted. Tap the mic button when you want me to listen again.`);break;case`minimize`:q(),$(`Minimized — I'm still listening. Tap the call pill to bring the chat back.`);break;case`expand`:T(!0),$(`Sure — expanding the view.`);break;case`shrink`:E(null),T(!1),$(`Okay — back to the smaller view.`);break}},[q,Q,$,On]);(0,n.useEffect)(()=>{Lt.current=kn},[kn]);let An=(0,n.useRef)(!1);(0,n.useEffect)(()=>{An.current&&!h&&M.current&&(M.current=!1,Q()),An.current=h},[h,Q]);let jn=(0,n.useCallback)(e=>{Rt.current=e,Tt(e),A.current?.selectDevice(e||void 0)},[]),Mn=(0,n.useCallback)(()=>{!O.current||k.current||(I.current=!1,F.current=!1,ye(),b(),j.current=Date.now())},[ye,b]);(0,n.useEffect)(()=>{A.current?.setOutputActive(h),j.current=Date.now()},[h]),(0,n.useEffect)(()=>{if(L!==`denied`)return;let e=window.setTimeout(()=>Q(),3500);return()=>window.clearTimeout(e)},[Q,L]),(0,n.useEffect)(()=>{if(!C)return;let e=window.setInterval(()=>{let e=A.current;!e||k.current||zt.current||Wt.current||e.snapshot.mic===`hearing`||e.snapshot.processing||Date.now()-j.current<6e4||(A.current?.log.add(`call-timeout`),dt(!0),window.setTimeout(()=>Q(),2400))},5e3);return()=>window.clearInterval(e)},[Q,C]);let Nn=C&&!ht&&(m||h);(0,n.useEffect)(()=>()=>Q(),[Q]);let[Pn,Fn]=(0,n.useState)(``),In=(0,n.useRef)(!1);(0,n.useEffect)(()=>{if(In.current&&!m){let e=[...p].reverse().find(e=>e.role===`assistant`&&!e.streaming&&!e.pending&&e.content);e&&Fn(e.content)}In.current=m},[m,p]),(0,n.useLayoutEffect)(()=>{if(!d)return;let e=D.current,t=z||V?e?.querySelector(`.cf-confirm__card`):U?e?.querySelector(`.cf-history`):null;if(!t)return;let n=t.getRootNode(),r=`activeElement`in n?n.activeElement:document.activeElement;(!r||!t.contains(r))&&t.querySelector(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`)?.focus()},[V,z,d,U]),(0,n.useEffect)(()=>{if(!d)return;let e=D.current,t=z||V?e?.querySelector(`.cf-confirm__card`):U?e?.querySelector(`.cf-history`):null,n=e?.querySelectorAll(`:scope > .cf-header, :scope > .cf-panel__video, :scope > .cf-panel__chat`);n?.forEach(e=>{t?(e.setAttribute(`inert`,``),e.setAttribute(`aria-hidden`,`true`)):(e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`))}),t||requestAnimationFrame(()=>e?.querySelector(`.cf-textarea`)?.focus());let r=e=>{if(e.key===`Escape`){e.preventDefault();let t=Qt.current;if(t.confirmEnd){B(!1);return}if(t.confirmClear){H(!1);return}if(t.showHistory){W(!1);return}q();return}if(e.key!==`Tab`||!t)return;let n=t.querySelectorAll(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`),r=Array.from(n).filter(e=>!e.hasAttribute(`disabled`));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=t.getRootNode()instanceof ShadowRoot?t.getRootNode().activeElement:document.activeElement;e.shiftKey&&o===i?(e.preventDefault(),a.focus()):!e.shiftKey&&o===a&&(e.preventDefault(),i.focus())};return e?.addEventListener(`keydown`,r),()=>{e?.removeEventListener(`keydown`,r),n?.forEach(e=>{e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`)})}},[d,q,z,V,U]),(0,n.useEffect)(()=>{let e=D.current;e&&(d?e.removeAttribute(`inert`):e.setAttribute(`inert`,``))},[d]);let Ln=a.accentColor??a.themeTokens?.accent??f?.accentColor,Rn=a.themeTokens?.accentText??te(Ln,a.themeTokens?.background??(Ot===`dark`?`#0f1c27`:`#ffffff`)),zn={zIndex:a.zIndex,"--cf-h-pad":`${a.horizontalPadding}px`,"--cf-v-pad":`${a.verticalPadding}px`,...Rn?{"--cf-accent-ink":Rn}:{},...a.themeTokens?.accentStrong?{"--cf-accent-2":a.themeTokens.accentStrong}:{},...a.themeTokens?.background?{"--cf-bg":a.themeTokens.background}:{},...a.themeTokens?.surface?{"--cf-surface":a.themeTokens.surface}:{},...a.themeTokens?.surfaceMuted?{"--cf-surface-2":a.themeTokens.surfaceMuted}:{},...a.themeTokens?.text?{"--cf-text":a.themeTokens.text}:{},...a.themeTokens?.mutedText?{"--cf-muted":a.themeTokens.mutedText}:{},...a.themeTokens?.border?{"--cf-border":a.themeTokens.border}:{},...a.themeTokens?.shadow?{"--cf-shadow":a.themeTokens.shadow}:{},...a.themeTokens?.radius?{"--cf-radius":a.themeTokens.radius}:{},...a.themeTokens?.fontFamily?{"--cf-font":a.themeTokens.fontFamily}:{},...a.themeTokens?.success?{"--cf-success":a.themeTokens.success}:{},...a.themeTokens?.warning?{"--cf-warning":a.themeTokens.warning}:{},...a.themeTokens?.danger?{"--cf-danger":a.themeTokens.danger}:{},...Ln?{"--cf-accent":Ln,"--cf-accent-2":a.themeTokens?.accentStrong??`color-mix(in oklab, ${Ln} 76%, #14141f)`}:{}},Bn=e=>_(e),Vn=[...p].reverse().find(e=>e.role===`user`&&e.content.trim())?.content??``,Hn=p.some(e=>e.role===`user`),Un=!!(f?.allowVoiceInput&&f?.talkbackMode&&f.talkbackMode!==`text`),Wn=Un,Gn=!G&&Wn&&!Hn?tn.filter((e,t)=>!(t===0&&e.role===`assistant`)):tn,Kn=g===`human`&&pe?pe:f?.agentName??u.chatName,qn=g===`human`?u.liveSupport:g===`queued`?u.waitingForTeam:f?.offline?u.statusOffline:u.statusOnline,Jn=!y&&!G?f?.availableActions:void 0,Yn=!y&&!G?f?.actions:void 0,Xn=C&&!pt&&L===`connecting`&&!G;return(0,r.jsx)(e.z,{value:u,children:(0,r.jsx)(e.R,{value:a.locale,children:(0,r.jsxs)(`div`,{class:`cf-root`,dir:a.dir,"data-theme":Ot,"data-align":a.alignment,"data-display":`floating`,style:zn,children:[w&&d&&(0,r.jsx)(`div`,{class:`cf-theater-backdrop`,onClick:yn}),(0,r.jsxs)(`div`,{ref:D,class:`cf-panel ${d?`is-open`:``} ${C?`cf-panel--call`:``} ${Xn?`cf-panel--voice-connecting`:``} ${w&&d?`cf-panel--theater`:``} ${nn||rn?`cf-panel--analytics-focus`:``}`,role:`dialog`,"aria-modal":`false`,"aria-label":`${u.chatName}: ${f?.agentName??u.assistantName}`,"aria-hidden":!d,children:[Qe&&d&&(0,r.jsx)(o,{state:Qe,onClose:it}),(0,r.jsxs)(`div`,{class:`cf-header`,children:[(0,r.jsx)(e.v,{persona:f,hideWhenMissing:!0}),(0,r.jsxs)(`div`,{class:`cf-header__meta`,children:[(0,r.jsx)(`div`,{class:`cf-header__name`,children:Kn}),(0,r.jsx)(`div`,{class:`cf-header__status ${g===`ai`&&f?.offline?`cf-header__status--offline`:``}`,children:(0,r.jsx)(`span`,{class:`cf-header__status-text`,children:qn})})]}),(0,r.jsxs)(`div`,{class:`cf-header__actions`,children:[We.length>0&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":u.pastConversations,title:u.pastConversations,"aria-pressed":U,onClick:()=>W(e=>!e),children:(0,r.jsx)(e.M,{})}),Hn&&!y&&!G&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":u.endChat,title:u.endChat,onClick:on,children:(0,r.jsx)(e.j,{})}),a.sound&&kt&&(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":Et?u.unmuteSounds:u.muteSounds,"aria-pressed":Et,onClick:At,children:Et?(0,r.jsx)(e.N,{}):(0,r.jsx)(e.P,{})}),(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn cf-header__close`,"aria-label":u.closeChat,onClick:q,children:(0,r.jsx)(e.A,{})})]})]}),(0,r.jsx)(`div`,{class:`cf-panel__video`,children:nn?(0,r.jsx)(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":u.expandedAnalyticsResult,children:(0,r.jsx)(e.E,{visualization:nn,expanded:!0,onFollowUp:e=>{vn(),_(e)},onClose:vn})}):rn?.visualization?(0,r.jsx)(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":u.expandedAnalyticsResult,children:(0,r.jsx)(e.T,{visualization:rn.visualization,onClose:vn,onFollowUp:e=>{vn(),_(e)},onFeedback:G?void 0:Ee,transport:G?void 0:De(`widget`),onOpenSource:a.onOpenAnalyticsSource})}):!G&&Wn?(0,r.jsx)(e.y,{persona:f,starters:[],onPick:_,onFocusComposer:Dn,speaking:h,voiceState:L,replyPending:C&&m&&!h,pinned:!0,muted:ht,onToggleMute:On,onEndCall:Q,onTalkNow:Mn,showTalkNow:Nn,micLevel:_t,theaterMode:w,onToggleTheater:hn,onMinimize:q,audioDevices:St,selectedAudioDeviceId:wt,onSelectAudioDevice:jn,connectingOnly:Xn}):null}),!Xn&&(0,r.jsxs)(`div`,{class:`cf-panel__chat`,children:[a.preview&&(0,r.jsx)(`div`,{class:`cf-preview-banner`,children:u.previewBanner}),G&&(0,r.jsx)(`div`,{class:`cf-viewing-banner`,children:u.viewingPast}),(0,r.jsxs)(`div`,{class:`cf-body`,ref:Mt,role:`log`,onScroll:dn,children:[Gn.map((t,n)=>(0,r.jsx)(e.C,{msg:t,persona:f,isLast:!G&&n===Gn.length-1,visitor:de,hasEmail:fe,lastQuestion:Vn,showActions:!G&&n===Gn.length-1&&!!(t.handoffOffered||t.selectedAction),onPickReply:Bn,onSubmitForm:Ne,onDemoSlots:ze,onConfirmHostedBooking:Pe,onRetry:we,ratable:!G&&Gn.slice(0,n).some(e=>e.role===`user`),onRate:Te,onExplanationFeedback:G?void 0:Ee,explanationTransport:G?void 0:De(`widget`),onOpenAnalyticsSource:a.onOpenAnalyticsSource,onExpandVisualization:G?void 0:gn,onExpandExplanation:G?void 0:_n,onOpenAttachment:nt,onReconnect:!G&&!y&&at&&t.id===Ze?ke:void 0},t.id)),!Hn&&!G&&(0,r.jsxs)(r.Fragment,{children:[Gn.length===0&&(0,r.jsx)(s,{name:f?.agentName??u.assistantName,greeting:f?.greeting}),(0,r.jsx)(e.w,{items:he,onPick:_}),(0,r.jsx)(e.x,{items:ge})]}),qt&&(0,r.jsxs)(`button`,{type:`button`,class:`cf-newmsg`,onClick:J,children:[(0,r.jsx)(e.O,{}),u.newMessages]})]}),(0,r.jsx)(`div`,{class:`cf-sr-live`,"aria-live":`polite`,"aria-atomic":`true`,children:Pn}),m&&!y&&!G&&(0,r.jsx)(`div`,{class:`cf-stopbar`,children:(0,r.jsxs)(`button`,{type:`button`,class:`cf-stop`,onClick:ye,children:[(0,r.jsx)(e.F,{}),u.stop]})}),G?(0,r.jsx)(`div`,{class:`cf-ended`,children:(0,r.jsx)(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Je,children:u.backToChat})}):y?(0,r.jsxs)(`div`,{class:`cf-ended`,children:[(0,r.jsx)(`p`,{class:`cf-ended__text`,children:u.conversationEnded}),a.csat&&Hn?$t?(0,r.jsx)(`p`,{class:`cf-ended__text`,children:u.feedbackThanks}):(0,r.jsxs)(`div`,{class:`cf-csat`,children:[(0,r.jsx)(`span`,{class:`cf-csat__q`,children:u.csatPrompt}),(0,r.jsx)(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":u.feedbackHelpful,onClick:()=>{Me(`up`),en(!0)},children:(0,r.jsx)(e.L,{})}),(0,r.jsx)(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":u.feedbackNotHelpful,onClick:()=>{Me(`down`),en(!0)},children:(0,r.jsx)(e.I,{})})]}):null,(0,r.jsx)(`button`,{type:`button`,class:`cf-ended__btn`,onClick:cn,children:u.startNewChat})]}):(0,r.jsxs)(r.Fragment,{children:[me?(0,r.jsx)(`div`,{class:`cf-live-typing`,"aria-live":`polite`,children:e.B(u.agentTyping,{name:me})}):null,Jn&&Jn.length>0&&(0,r.jsx)(`div`,{class:`cf-footer-actions`,children:(0,r.jsx)(e._,{actions:Jn,descriptors:Yn,visitor:de,onSubmitForm:Ne,onDemoSlots:ze,onConfirmHostedBooking:Pe,scheduler:f?.scheduler,translations:a.actionTranslations})},`footer-actions`),(0,r.jsx)(e.b,{draftStore:Zt,onSend:_,onSendGif:_e,onTyping:ve,disabled:m,allowVoice:Un,onTranscribe:Fe,gifEnabled:Be,onSearchGifs:Re,allowAttach:a.attachments,analyzeAttachments:!0,onUpload:Ie,onPreviewAttachment:rt},`composer`)]}),!y&&f?.disclaimerText&&(0,r.jsx)(`div`,{class:`cf-disclaimer`,children:f.disclaimerText}),(0,r.jsxs)(`div`,{class:`cf-footer`,children:[(0,r.jsx)(`button`,{type:`button`,class:`cf-footer__privacy`,"aria-label":u.clearDeviceData,onClick:()=>H(!0),children:u.privacyAndData}),(0,r.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),u.poweredBy,` `,(0,r.jsx)(`a`,{href:`https://accurix.tech/centrinfo`,target:`_blank`,rel:`noopener noreferrer`,children:`Centrinfo`})]})]}),z&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>B(!1),children:(0,r.jsxs)(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":u.endChatConfirm,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>c(e,e.currentTarget,()=>B(!1)),children:[(0,r.jsx)(`div`,{class:`cf-confirm__title`,children:u.endChatConfirm}),(0,r.jsx)(`div`,{class:`cf-confirm__body`,children:u.endChatConfirmBody}),(0,r.jsxs)(`div`,{class:`cf-confirm__actions`,children:[(0,r.jsx)(`button`,{ref:Yt,type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>B(!1),children:u.cancel}),(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:sn,children:u.endConfirmCta})]})]})},`confirm-end`),U&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>W(!1),children:(0,r.jsxs)(`div`,{class:`cf-history`,role:`dialog`,"aria-modal":`true`,"aria-label":u.pastConversations,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>c(e,e.currentTarget,()=>W(!1)),children:[(0,r.jsxs)(`div`,{class:`cf-history__head`,children:[(0,r.jsx)(`span`,{children:u.pastConversations}),(0,r.jsx)(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":u.closeHistory,onClick:()=>W(!1),children:(0,r.jsx)(e.A,{})})]}),(0,r.jsx)(`div`,{class:`cf-history__list`,children:We.map(e=>(0,r.jsxs)(`button`,{type:`button`,class:`cf-history__item ${e.sessionId===Ge?`is-active`:``}`,onClick:()=>{qe(e.sessionId),W(!1)},children:[(0,r.jsx)(`span`,{class:`cf-history__title`,children:e.title}),(0,r.jsxs)(`span`,{class:`cf-history__meta`,children:[new Date(e.ts).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),e.ended?` · ${u.historyEnded}`:``]})]},e.sessionId))}),(0,r.jsx)(`div`,{class:`cf-history__footer`,children:(0,r.jsx)(`button`,{type:`button`,class:`cf-history__clear`,onClick:()=>{W(!1),H(!0)},children:u.clearDeviceData})})]})},`history`),V&&(0,r.jsx)(`div`,{class:`cf-confirm`,onClick:()=>H(!1),children:(0,r.jsxs)(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":u.clearDeviceData,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>c(e,e.currentTarget,()=>H(!1)),children:[(0,r.jsx)(`div`,{class:`cf-confirm__title`,children:u.clearDeviceData}),(0,r.jsx)(`div`,{class:`cf-confirm__body`,children:u.clearDeviceDataBody}),(0,r.jsxs)(`div`,{class:`cf-confirm__actions`,children:[(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>H(!1),children:u.cancel}),(0,r.jsx)(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:()=>{H(!1),Ye()},children:u.clearDeviceDataCta})]})]})},`confirm-clear`)]}),C&&!d?(0,r.jsx)(e.S,{persona:f,voiceState:L,muted:ht,onToggleMute:On,onEndCall:Q,micLevel:_t,onExpand:K}):w&&d?null:!a.hideDefaultLauncher&&(0,r.jsxs)(`button`,{ref:jt,type:`button`,class:`cf-launcher`,"aria-label":d?u.closeChat:x>0?`${u.openChat}. ${x===1?u.unreadMessage:e.B(u.unreadMessages,{count:String(x)})}`:u.openChat,"aria-expanded":d,onClick:an,children:[a.launcherIcon?(0,r.jsx)(`img`,{class:`cf-launcher__img`,src:a.launcherIcon,alt:``}):(0,r.jsx)(e.k,{}),!d&&x>0&&(0,r.jsx)(`span`,{class:`cf-launcher__badge`,"aria-hidden":`true`,children:x>99?`99+`:x})]})]})})})},p=`centrinfo-widget`;var m=class extends HTMLElement{constructor(...t){super(...t),e.Z(this,`controls`,null),e.Z(this,`composerDraftStore`,{value:``})}mountWith(n){let i=e.n(n),a=this.shadowRoot??this.attachShadow({mode:`open`});if(this.style.zIndex=String(i.zIndex),`adoptedStyleSheets`in Document.prototype&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`){let t=new CSSStyleSheet;t.replaceSync(e.t),a.adoptedStyleSheets=[t]}else{let t=document.createElement(`style`);i.styleNonce&&(t.nonce=i.styleNonce),t.textContent=e.t,a.appendChild(t)}(0,t.render)((0,r.jsx)(f,{transport:e.X(i),config:i,bindControls:e=>this.controls=e,composerDraftStore:this.composerDraftStore}),a)}open(){this.controls?.open()}close(){this.controls?.close()}toggle(){this.controls?.toggle()}identify(e){this.controls?.identify(e)}clear(){this.controls?.startNew()}shutdown(){this.controls?.shutdown()}unmount(){this.shadowRoot&&(0,t.render)(null,this.shadowRoot)}};typeof customElements<`u`&&!customElements.get(p)&&customElements.define(p,m);const h=(e,t=document.body)=>{if(typeof document>`u`)throw Error(`[centrinfo-widget] createWidget must run in a browser.`);let n=document.createElement(p);return n.style.pointerEvents=`none`,n.style.position=`fixed`,n.style.inset=`0`,n.style.width=`0`,n.style.height=`0`,t.appendChild(n),n.mountWith(e),{open:()=>n.open(),close:()=>n.close(),toggle:()=>n.toggle(),show:()=>n.open(),hide:()=>n.close(),identify:e=>n.identify(e),update:e=>n.identify(e),clear:()=>n.clear(),shutdown:()=>n.shutdown(),logout:()=>n.shutdown(),destroy:()=>{n.unmount(),n.remove()}}},de=e=>h(e);let fe=null;const g=e=>{fe?.destroy();let t=de(e);return fe=t,t},pe={init:g,createWidget:de};exports.Centrinfo=pe,exports.createWidget=de,exports.init=g;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as WidgetStrings, d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig } from "./types-BGKFxmKB.cjs";
1
+ import { d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig, w as WidgetStrings } from "./types-CYFMH8yg.cjs";
2
2
 
3
3
  //#region src/mount.d.ts
4
4
  /** Create + mount the floating public messenger. */
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as WidgetStrings, d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig } from "./types-DhmmWqaj.mjs";
1
+ import { d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig, w as WidgetStrings } from "./types-D82dr33R.mjs";
2
2
 
3
3
  //#region src/mount.d.ts
4
4
  /** Create + mount the floating public messenger. */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as WidgetStrings, d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig } from "./types-DhmmWqaj.mjs";
1
+ import { d as WidgetHandle, f as WidgetThemeTokens, p as WidgetUser, u as WidgetConfig, w as WidgetStrings } from "./types-D82dr33R.mjs";
2
2
 
3
3
  //#region src/mount.d.ts
4
4
  /** Create + mount the floating public messenger. */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{A as e,B as t,C as n,D as r,F as i,H as a,I as o,J as s,L as ee,M as te,N as ne,O as re,P as ie,R as ae,S as oe,T as se,V as ce,X as le,Y as ue,_ as de,a as fe,b as pe,d as me,h as he,i as ge,j as _e,k as ve,m as ye,n as c,p as be,r as xe,t as l,u as Se,v as Ce,w as we,x as Te,y as Ee,z as De}from"./styles-CIJFMOKa.mjs";import{render as u}from"preact";import{useCallback as d,useEffect as f,useLayoutEffect as Oe,useRef as p,useState as m}from"preact/hooks";import{Fragment as ke,jsx as h,jsxs as g}from"preact/jsx-runtime";const _=e=>e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:`other`,Ae=({state:e,onClose:t})=>{let n=De(),r=p(null);f(()=>{r.current?.focus();let e=e=>{e.key===`Escape`&&(e.stopPropagation(),t())};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[t]);let i=e.status===`ready`?_(e.mimeType):`other`;return h(`div`,{class:`cf-preview`,role:`dialog`,"aria-modal":`true`,"aria-label":ae(n.attachPreviewTitle,{name:e.name}),onClick:e=>{e.target===e.currentTarget&&t()},children:g(`div`,{class:`cf-preview__frame`,children:[g(`div`,{class:`cf-preview__bar`,children:[h(`span`,{class:`cf-preview__name`,title:e.name,children:e.name}),e.status===`ready`&&h(`a`,{class:`cf-preview__btn`,href:e.url,download:e.name,children:n.attachDownload}),h(`button`,{ref:r,type:`button`,class:`cf-preview__btn cf-preview__close`,"aria-label":n.attachPreviewClose,onClick:t,children:`✕`})]}),g(`div`,{class:`cf-preview__body`,children:[e.status===`loading`&&h(`p`,{class:`cf-preview__note`,children:n.attachPreviewLoading}),e.status===`error`&&h(`p`,{class:`cf-preview__note`,children:n.attachPreviewFailed}),e.status===`ready`&&i===`image`&&h(`img`,{class:`cf-preview__image`,src:e.url,alt:e.name}),e.status===`ready`&&i===`pdf`&&h(`iframe`,{class:`cf-preview__pdf`,src:e.url,title:e.name}),e.status===`ready`&&i===`other`&&h(`p`,{class:`cf-preview__note`,children:n.attachPreviewUnsupported})]})]})})},je=({name:e,greeting:t})=>{let n=De();return g(`section`,{class:`cf-empty-welcome`,"aria-label":ae(n.welcomeLabel,{name:e}),children:[h(`span`,{class:`cf-empty-welcome__eyebrow`,children:n.welcomeEyebrow}),h(`h2`,{children:e}),h(`p`,{children:t||n.welcomePrompt})]})},Me=(e,t,n)=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),n();return}if(e.key!==`Tab`)return;let r=Array.from(t.querySelectorAll(`button, [href], textarea, input, select, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`&&e.tabIndex>=0);if(r.length===0)return;let i=t.getRootNode(),a=e.composedPath()[0],o=a instanceof HTMLElement?a:`activeElement`in i?i.activeElement:document.activeElement,s=r[0],ee=r[r.length-1];e.shiftKey&&(o===s||!t.contains(o))?(e.preventDefault(),e.stopPropagation(),ee.focus()):!e.shiftKey&&(o===ee||!t.contains(o))&&(e.preventDefault(),e.stopPropagation(),s.focus())},v=new Map,y=e=>{if(!e||typeof document>`u`||typeof CanvasRenderingContext2D>`u`)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.fillStyle=`#010203`,t.fillStyle=e;let n=t.fillStyle;if(n===`#010203`&&e.trim().toLowerCase()!==`#010203`)return;let r=n.match(/^#([\da-f]{6})$/i)?.[1];if(r)return[Number.parseInt(r.slice(0,2),16),Number.parseInt(r.slice(2,4),16),Number.parseInt(r.slice(4,6),16),1];let i=n.match(/^rgba?\(([\d.]+)[, ]+([\d.]+)[, ]+([\d.]+)(?:[, /]+([\d.]+))?\)$/i);if(!i)return;let a=i.slice(1,5).map(Number);if(!a.some(e=>!Number.isFinite(e)))return[a[0],a[1],a[2],a[3]??1]},Ne=(e,t=`#ffffff`)=>{let n=`${e??``}|${t}`;if(v.has(n))return v.get(n);let r=y(e),i=y(t)??[255,255,255,1];if(!r){v.set(n,void 0);return}let a=r[3],o=r.slice(0,3).map((e,t)=>e*a+i[t]*(1-a)).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}),s=o[0]*.2126+o[1]*.7152+o[2]*.0722,ee=1.05/(s+.05)>=(s+.05)/.059?`#ffffff`:`#0f1e2a`;return v.set(n,ee),ee},Pe=e=>{let[t,n]=m(`light`);return f(()=>{if(e!==`auto`||typeof matchMedia>`u`)return;let t=matchMedia(`(prefers-color-scheme: dark)`),r=()=>n(t.matches?`dark`:`light`);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),e===`auto`?t:e},Fe={end:`end the call`,mute:`mute your microphone`,minimize:`minimize the chat`,expand:`expand the view`,shrink:`exit the expanded view`},Ie=e=>e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s']/gu,` `).replace(/\s+/g,` `).trim(),Le=[{action:`shrink`,re:/\b(?:exit|leave|quit|close)\b[\s\w]*\b(?:full ?screen|expanded|theat(?:er|re))\b|\bshrink\b|\bsmaller view\b/},{action:`end`,re:/\b(?:end|close|stop|finish|hang ?up|quit|exit)\b[\s\w]*\b(?:call|chat|conversation|convo|session|talking)\b|\bhang ?up\b|\bgood ?bye\b|^bye(?: bye)?$/},{action:`mute`,re:/\bmute\b|\bstop listening\b/},{action:`minimize`,re:/\bminimi[sz]e\b|\bhide\b[\s\w]*\b(?:chat|call|window|widget)\b/},{action:`expand`,re:/\bexpand\b|\bmaximi[sz]e\b|\bfull ?screen\b|\btheat(?:er|re) mode\b|\bbigger view\b/}],Re=/^(?:yes|yeah|yep|yup|sure|correct|confirm|affirmative|go ahead|do it|please do|ok(?:ay)?)\b/,ze=/^(?:no|nope|nah|cancel|never ?mind|don'?t|stop)\b/,Be=/^(?:end|close|stop|finish|hang ?up|quit|exit|bye|good ?bye)\b/,Ve=e=>{let t=Ie(e);if(!t)return null;for(let{action:e,re:n}of Le)if(n.test(t)){let n=t.split(` `).length;return{action:e,confident:e===`end`?n<=10:n<=6}}return null},He=e=>`I didn't catch yes or no. Say yes to ${Fe[e]}, or no to keep talking.`,Ue=({transport:a,config:s,bindControls:le,composerDraftStore:ue})=>{let c=s.strings,[l,De]=m(s.openByDefault),{persona:u,messages:_,sending:v,assistantSpeaking:y,visitor:Le,hasEmail:Ue,liveMode:b,assignedAgentName:We,agentTypingName:Ge,starters:Ke,featuredLinks:qe,send:x,sendGif:Je,notifyTyping:Ye,stop:Xe,amend:Ze,hold:Qe,resumeHeld:$e,duckSpeaking:et,retry:tt,rateMessage:nt,injectAssistant:rt,reconnectSupport:it,appendUserDraft:at,patchMessage:S,removeMessage:ot,submitCsat:st,submitForm:ct,confirmHostedBooking:lt,transcribe:ut,uploadAttachment:dt,loadAttachment:ft,searchGifs:pt,demoSlots:mt,gifEnabled:ht,identify:gt,ended:C,endConversation:_t,startNew:vt,history:yt,viewingSessionId:bt,viewMessages:xt,openConversation:St,closeHistoryView:Ct,shutdown:wt,stopSpeaking:w,speakAssistantText:Tt}=fe(a,s,l),Et=ge(_,b),[Dt,Ot]=m(null),kt=p(0),At=d((e,t,n)=>{n===kt.current&&Ot({status:`ready`,name:t,url:URL.createObjectURL(e),mimeType:e.type||`application/octet-stream`})},[]),jt=d((e,t,n)=>{let r=t.name,i=++kt.current;Ot({status:`loading`,name:r}),ft(e,t,n).then(e=>At(e,r,i),()=>{i===kt.current&&Ot({status:`error`,name:r})})},[ft,At]),Mt=d((e,t)=>At(e,t,++kt.current),[At]),Nt=d(()=>{kt.current+=1,Ot(null)},[]);f(()=>()=>{Dt?.status===`ready`&&URL.revokeObjectURL(Dt.url)},[Dt]);let Pt=!!xe(u?.actions),[T,Ft]=m(0),[E,It]=m({mic:`off`,processing:!1}),[Lt,Rt]=m(null),[zt,Bt]=m(!1),[D,Vt]=m(!1),[Ht,Ut]=m(!1),[Wt,Gt]=m(!1),[Kt,qt]=m(0),[O,k]=m(!1),[Jt,A]=m(null),[Yt,Xt]=m([]),[Zt,Qt]=m(``),[$t,en]=m(()=>{try{return localStorage.getItem(`centrinfo:muted`)===`1`}catch{return!1}}),tn=Pe(s.theme),nn=u?.soundEnabled??!0;f(()=>{me(s.sound&&nn&&!$t)},[s.sound,nn,$t]);let rn=d(()=>{en(e=>{let t=!e;try{localStorage.setItem(`centrinfo:muted`,t?`1`:`0`)}catch{}return t})},[]),an=p(null),on=p(null),sn=p(null),cn=p(0),j=p(!1),M=p(!1),N=p(null),P=p(0),ln=p(void 0),un=p(0),dn=p(null),fn=p(!1),F=p(null),I=p(``),pn=p(()=>{}),mn=p(``),hn=p(v),gn=p(x);gn.current=x;let _n=p(Ze);_n.current=Ze;let vn=p(ut);vn.current=ut;let L=p(!1),R=p(!1),yn=p(``);yn.current=[..._].reverse().find(e=>e.role===`assistant`)?.content??``;let bn=p(y);hn.current=v,bn.current=y;let z=D?zt?`timeout`:Wt||E.mic===`muted`?`muted`:E.mic===`unavailable`?E.reason===`permission-denied`||E.reason===`unsupported`?`denied`:`unavailable`:E.mic===`off`||E.mic===`starting`?`connecting`:E.mic===`hearing`?`hearing`:y?`speaking`:Lt??(E.processing||v?`processing`:`listening`):`idle`,[xn,Sn]=m(!0),[Cn,B]=m(!1),wn=p(0),[V,H]=m(!1),[U,W]=m(!1),Tn=p(null),[G,K]=m(!1),En=p({value:``}),Dn=ue??En.current,On=p({confirmEnd:V,confirmClear:U,showHistory:G});On.current={confirmEnd:V,confirmClear:U,showHistory:G};let[kn,An]=m(!1),q=!!bt,jn=q?xt:_,Mn=jn.find(e=>e.id===Jt&&e.visualization)?.visualization;f(()=>{!Jt||Mn||(A(null),k(!1))},[Mn,Jt]);let Nn=d(()=>{De(!0),Ft(0),Se(`open`),s.onOpen?.(),s.onShow?.()},[s]),J=d(()=>{De(!1),k(!1),A(null),s.onClose?.(),s.onHide?.(),on.current?.focus()},[s]),Pn=d(()=>l?J():Nn(),[l,Nn,J]),Fn=d(()=>H(!0),[]),In=d(()=>{_t(),H(!1)},[_t]),Ln=d(()=>{vt(),B(!1),Sn(!0)},[vt]);f(()=>{V&&Tn.current?.focus()},[V]),f(()=>{le({open:Nn,close:J,toggle:Pn,identify:gt,startNew:vt,endConversation:_t,shutdown:wt})},[le,Nn,J,Pn,gt,vt,_t,wt]),f(()=>{let e=_.filter(e=>e.role===`assistant`&&!e.pending).length;if(l){cn.current=e;return}e>cn.current&&Ft(e-cn.current)},[_,l]),f(()=>{s.onUnreadChange?.(T)},[T,s]),f(()=>{let e=s.sessionDurationMinutes;if(!e||e<=0)return;let t=setTimeout(()=>wt(),e*60*1e3);return()=>clearTimeout(t)},[s.sessionDurationMinutes,_,l,wt]),f(()=>{let e=s.customLauncherSelector;if(!e||typeof document>`u`)return;let t=[];try{t=Array.from(document.querySelectorAll(e))}catch{return}let n=e=>{e.preventDefault(),Pn()};return t.forEach(e=>e.addEventListener(`click`,n)),()=>t.forEach(e=>e.removeEventListener(`click`,n))},[s.customLauncherSelector,Pn]);let Rn=p(!1);f(()=>{let e=s.proactiveMessage?.trim();if(!e||Rn.current)return;let t=s.proactiveOnPaths??[],n=typeof location<`u`?location.pathname:``;if(t.length>0&&!t.some(e=>n.includes(e)))return;let r=`centrinfo:proactive:${s.token.slice(0,12)}`;try{if(sessionStorage.getItem(r)===`1`)return}catch{}let i=setTimeout(()=>{if(!(l||C||_.some(e=>e.role===`user`))){Rn.current=!0;try{sessionStorage.setItem(r,`1`)}catch{}rt(e),Nn()}},Math.max(0,s.proactiveDelaySeconds)*1e3);return()=>clearTimeout(i)},[s.proactiveMessage]),f(()=>{let e=sn.current;if(!l||!e)return;let t=_[_.length-1],n=Date.now()<wn.current;t?.role===`user`||xn||n?(requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight}),B(!1),n&&Sn(!0)):B(!0)},[_,l,v,xn]);let zn=d(()=>{let e=sn.current;if(!e)return;if(j.current&&!q){Sn(!0),B(!1);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;Sn(t),t&&B(!1)},[q]),Y=d(()=>{let e=sn.current;e&&(e.scrollTop=e.scrollHeight),B(!1),Sn(!0)},[]),Bn=d(()=>{wn.current=Date.now()+3e3,requestAnimationFrame(Y)},[Y]);f(()=>{if(!l||q||!D||z===`connecting`)return;wn.current=Date.now()+6e4,Y();let e=requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)}),t=[80,180,360].map(e=>window.setTimeout(Y,e));return()=>{cancelAnimationFrame(e),t.forEach(e=>window.clearTimeout(e))}},[y,_,l,Y,v,D,q,z]);let Vn=d(()=>{an.current?.querySelector(`.cf-textarea`)?.focus()},[]),Hn=d((e,t)=>{Rt(e),ln.current&&window.clearTimeout(ln.current),ln.current=window.setTimeout(()=>Rt(null),3e3),t&&!M.current&&Tt(t)},[Tt]),Un=d(e=>{let t=F.current;if(t)return t;Bn();let n=at(e);return F.current=n,S(n,{content:I.current||e,pending:!0,streaming:!1}),n},[at,Bn,S]),X=d(()=>{let e=F.current;if(e){if(I.current){S(e,{content:I.current,pending:!0});return}F.current=null,ot(e)}},[S,ot]),Z=d(()=>{R.current&&(R.current=!1,et(!1)),L.current&&(L.current=!1,$e())},[et,$e]),Q=d(()=>{j.current=!1,N.current?.stop(`call-ended`),N.current=null,L.current=!1,R.current=!1,M.current=!1,dn.current=null,fn.current=!1;let e=F.current;F.current=null,I.current=``,e&&ot(e),ln.current&&window.clearTimeout(ln.current),Rt(null),Bt(!1),It({mic:`off`,processing:!1}),qt(0),Vt(!1),Ut(!1),Gt(!1),k(!1),A(null),w()},[ot,w]),Wn=d(()=>{O&&A(null),k(!O)},[O]),Gn=d(e=>{A(e),k(!0)},[]),Kn=d(()=>{let e=Jt;A(null),k(!1),window.requestAnimationFrame(()=>{Array.from(an.current?.querySelectorAll(`[data-visualization-message]`)??[]).find(t=>t.dataset.visualizationMessage===e)?.focus()})},[Jt]),qn=d(()=>{A(null),k(!1)},[]),Jn=d((e,t,n=!1)=>{if(Bn(),t&&(S(t,{content:e,pending:!1,streaming:!1}),F.current===t&&(F.current=null)),I.current=``,n){w(),_n.current(e,{forceVoicePlayback:!0,userMessageId:t});return}j.current&&(Qe()?_n.current(e,{forceVoicePlayback:!0,userMessageId:t}):gn.current(e,{forceVoicePlayback:!0,userMessageId:t}))},[Bn,Qe,S,w]),$=d(e=>{rt(e),Tt(e)},[rt,Tt]),Yn=d(()=>{if(P.current=Date.now(),Rt(null),bn.current){R.current=!0,et(!0);return}L.current||(L.current=Qe()),Un(`Listening...`)},[et,Un,Qe]),Xn=d(e=>{let t=F.current;!t||R.current||S(t,{content:`${[I.current,e].filter(Boolean).join(` `)} ...`,pending:!0})},[S]),Zn=d(e=>{P.current=Date.now();let t=[I.current,e.text].map(e=>e.trim()).filter(Boolean).join(` `).replace(/\s+/g,` `).trim();if((R.current||e.overlappedOutput)&&ce(e.text,yn.current)){X(),Z();return}if(!t||be(t)||ye(t)){let e=R.current||L.current;X(),Z(),e||Hn(`misunderstood`);return}R.current&&(R.current=!1,Xe(),w());let n=dn.current;if(n){I.current=``,X();let e=Ie(t);if(Re.test(e)||n===`end`&&Be.test(e)){dn.current=null,pn.current(n);return}if(ze.test(e)){dn.current=null,$(`Okay, never mind — what would you like to know?`);return}$(He(n));return}let r=Ve(t);if(r){if(I.current=``,X(),Z(),r.confident){pn.current(r.action);return}dn.current=r.action,$(`Just to confirm — you want me to ${Fe[r.action]}? Please say yes or no.`);return}let i=Un(t);S(i,{content:t,pending:!0});let a=L.current;L.current=!1,Jn(t,i,a)},[Un,S,Z,Jn,X,Hn,$,Xe,w]),Qn=d(e=>{P.current=Date.now();let t=R.current||L.current;if(X(),Z(),!(t||e.overlappedOutput||e.reason===`too-short`)){if(e.reason===`transcribe-failed`){Hn(`misunderstood`,`I couldn't transcribe that. Please try again, or type your question.`);return}Hn(`noise`)}},[Z,X,Hn]),$n=p({speechStart:Yn,partial:Xn,turn:Zn,noise:Qn});$n.current={speechStart:Yn,partial:Xn,turn:Zn,noise:Qn};let er=d(()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{Xt(e.filter(e=>e.kind===`audioinput`).map((e,t)=>({deviceId:e.deviceId,label:e.label||`Microphone ${t+1}`})))}).catch(()=>{})},[]),tr=d(()=>{if(j.current){Q();return}if(Vn(),!u?.allowVoiceInput||!u.talkbackMode||u.talkbackMode===`text`||hn.current||C||q)return;P.current=Date.now(),M.current=!1,j.current=!0,Gt(!1),Vt(!0),Ut(!1),Bt(!1);let e=!1,n=new t({deviceId:mn.current||void 0,transcribe:async({audio:e,mimeType:t,durationSeconds:n})=>{let r=typeof navigator<`u`&&(navigator.languages?.[0]||navigator.language)||void 0;return he(await vn.current(e,t,r,n))},listener:{state:t=>{It(t),t.mic!==`starting`&&t.mic!==`off`&&Ut(!0),!e&&t.mic===`listening`&&(e=!0,er())},speechStart:()=>$n.current.speechStart(),partial:({text:e})=>$n.current.partial(e),turn:e=>$n.current.turn(e),noise:e=>$n.current.noise(e),level:e=>{let t=performance.now();t-un.current<90||(un.current=t,qt(e))}}});N.current=n,n.setOutputActive(bn.current),n.start()},[Q,C,Vn,u,er,q]),nr=d(()=>{let e=!M.current;M.current=e,Gt(e),N.current?.setMuted(e),e?(I.current=``,X(),Z()):P.current=Date.now()},[Z,X]),rr=d(e=>{switch(P.current=Date.now(),e){case`end`:fn.current=!0,$(`Okay — ending our call now. Goodbye!`),window.setTimeout(()=>{fn.current&&(fn.current=!1,Q())},2e3);break;case`mute`:M.current||nr(),$(`Muted. Tap the mic button when you want me to listen again.`);break;case`minimize`:J(),$(`Minimized — I'm still listening. Tap the call pill to bring the chat back.`);break;case`expand`:k(!0),$(`Sure — expanding the view.`);break;case`shrink`:A(null),k(!1),$(`Okay — back to the smaller view.`);break}},[J,Q,$,nr]);f(()=>{pn.current=rr},[rr]);let ir=p(!1);f(()=>{ir.current&&!y&&fn.current&&(fn.current=!1,Q()),ir.current=y},[y,Q]);let ar=d(e=>{mn.current=e,Qt(e),N.current?.selectDevice(e||void 0)},[]),or=d(()=>{!j.current||M.current||(R.current=!1,L.current=!1,Xe(),w(),P.current=Date.now())},[Xe,w]);f(()=>{N.current?.setOutputActive(y),P.current=Date.now()},[y]),f(()=>{if(z!==`denied`)return;let e=window.setTimeout(()=>Q(),3500);return()=>window.clearTimeout(e)},[Q,z]),f(()=>{if(!D)return;let e=window.setInterval(()=>{let e=N.current;!e||M.current||hn.current||bn.current||e.snapshot.mic===`hearing`||e.snapshot.processing||Date.now()-P.current<6e4||(N.current?.log.add(`call-timeout`),Bt(!0),window.setTimeout(()=>Q(),2400))},5e3);return()=>window.clearInterval(e)},[Q,D]);let sr=D&&!Wt&&(v||y);f(()=>()=>Q(),[Q]);let[cr,lr]=m(``),ur=p(!1);f(()=>{if(ur.current&&!v){let e=[..._].reverse().find(e=>e.role===`assistant`&&!e.streaming&&!e.pending&&e.content);e&&lr(e.content)}ur.current=v},[v,_]),Oe(()=>{if(!l)return;let e=an.current,t=V||U?e?.querySelector(`.cf-confirm__card`):G?e?.querySelector(`.cf-history`):null;if(!t)return;let n=t.getRootNode(),r=`activeElement`in n?n.activeElement:document.activeElement;(!r||!t.contains(r))&&t.querySelector(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`)?.focus()},[U,V,l,G]),f(()=>{if(!l)return;let e=an.current,t=V||U?e?.querySelector(`.cf-confirm__card`):G?e?.querySelector(`.cf-history`):null,n=e?.querySelectorAll(`:scope > .cf-header, :scope > .cf-panel__video, :scope > .cf-panel__chat`);n?.forEach(e=>{t?(e.setAttribute(`inert`,``),e.setAttribute(`aria-hidden`,`true`)):(e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`))}),t||requestAnimationFrame(()=>e?.querySelector(`.cf-textarea`)?.focus());let r=e=>{if(e.key===`Escape`){e.preventDefault();let t=On.current;if(t.confirmEnd){H(!1);return}if(t.confirmClear){W(!1);return}if(t.showHistory){K(!1);return}J();return}if(e.key!==`Tab`||!t)return;let n=t.querySelectorAll(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`),r=Array.from(n).filter(e=>!e.hasAttribute(`disabled`));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=t.getRootNode()instanceof ShadowRoot?t.getRootNode().activeElement:document.activeElement;e.shiftKey&&o===i?(e.preventDefault(),a.focus()):!e.shiftKey&&o===a&&(e.preventDefault(),i.focus())};return e?.addEventListener(`keydown`,r),()=>{e?.removeEventListener(`keydown`,r),n?.forEach(e=>{e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`)})}},[l,J,V,U,G]),f(()=>{let e=an.current;e&&(l?e.removeAttribute(`inert`):e.setAttribute(`inert`,``))},[l]);let dr=s.accentColor??s.themeTokens?.accent??u?.accentColor,fr=s.themeTokens?.accentText??Ne(dr,s.themeTokens?.background??(tn===`dark`?`#0f1c27`:`#ffffff`)),pr={zIndex:s.zIndex,"--cf-h-pad":`${s.horizontalPadding}px`,"--cf-v-pad":`${s.verticalPadding}px`,...fr?{"--cf-accent-ink":fr}:{},...s.themeTokens?.accentStrong?{"--cf-accent-2":s.themeTokens.accentStrong}:{},...s.themeTokens?.background?{"--cf-bg":s.themeTokens.background}:{},...s.themeTokens?.surface?{"--cf-surface":s.themeTokens.surface}:{},...s.themeTokens?.surfaceMuted?{"--cf-surface-2":s.themeTokens.surfaceMuted}:{},...s.themeTokens?.text?{"--cf-text":s.themeTokens.text}:{},...s.themeTokens?.mutedText?{"--cf-muted":s.themeTokens.mutedText}:{},...s.themeTokens?.border?{"--cf-border":s.themeTokens.border}:{},...s.themeTokens?.shadow?{"--cf-shadow":s.themeTokens.shadow}:{},...s.themeTokens?.radius?{"--cf-radius":s.themeTokens.radius}:{},...s.themeTokens?.fontFamily?{"--cf-font":s.themeTokens.fontFamily}:{},...s.themeTokens?.success?{"--cf-success":s.themeTokens.success}:{},...s.themeTokens?.warning?{"--cf-warning":s.themeTokens.warning}:{},...s.themeTokens?.danger?{"--cf-danger":s.themeTokens.danger}:{},...dr?{"--cf-accent":dr,"--cf-accent-2":s.themeTokens?.accentStrong??`color-mix(in oklab, ${dr} 76%, #14141f)`}:{}},mr=e=>x(e),hr=[..._].reverse().find(e=>e.role===`user`&&e.content.trim())?.content??``,gr=_.some(e=>e.role===`user`),_r=!!(u?.allowVoiceInput&&u?.talkbackMode&&u.talkbackMode!==`text`),vr=_r,yr=!q&&vr&&!gr?jn.filter((e,t)=>!(t===0&&e.role===`assistant`)):jn,br=b===`human`&&We?We:u?.agentName??c.chatName,xr=b===`human`?c.liveSupport:b===`queued`?c.waitingForTeam:u?.offline?c.statusOffline:c.statusOnline,Sr=!C&&!q?u?.availableActions:void 0,Cr=!C&&!q?u?.actions:void 0,wr=D&&!Ht&&z===`connecting`&&!q;return h(ee,{value:c,children:g(`div`,{class:`cf-root`,"data-theme":tn,"data-align":s.alignment,"data-display":`floating`,style:pr,children:[O&&l&&h(`div`,{class:`cf-theater-backdrop`,onClick:qn}),g(`div`,{ref:an,class:`cf-panel ${l?`is-open`:``} ${D?`cf-panel--call`:``} ${wr?`cf-panel--voice-connecting`:``} ${O&&l?`cf-panel--theater`:``} ${Mn?`cf-panel--analytics-focus`:``}`,role:`dialog`,"aria-modal":`false`,"aria-label":`${c.chatName}: ${u?.agentName??c.assistantName}`,"aria-hidden":!l,children:[Dt&&l&&h(Ae,{state:Dt,onClose:Nt}),g(`div`,{class:`cf-header`,children:[h(Ce,{persona:u,hideWhenMissing:!0}),g(`div`,{class:`cf-header__meta`,children:[h(`div`,{class:`cf-header__name`,children:br}),h(`div`,{class:`cf-header__status ${b===`ai`&&u?.offline?`cf-header__status--offline`:``}`,children:h(`span`,{class:`cf-header__status-text`,children:xr})})]}),g(`div`,{class:`cf-header__actions`,children:[yt.length>0&&h(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.pastConversations,title:c.pastConversations,"aria-pressed":G,onClick:()=>K(e=>!e),children:h(_e,{})}),gr&&!C&&!q&&h(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.endChat,title:c.endChat,onClick:Fn,children:h(e,{})}),s.sound&&nn&&h(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":$t?c.unmuteSounds:c.muteSounds,"aria-pressed":$t,onClick:rn,children:h($t?te:ne,{})}),h(`button`,{type:`button`,class:`cf-header__btn cf-header__close`,"aria-label":c.closeChat,onClick:J,children:h(ve,{})})]})]}),h(`div`,{class:`cf-panel__video`,children:Mn?h(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":c.expandedAnalyticsResult,children:h(se,{visualization:Mn,expanded:!0,onClose:Kn})}):!q&&vr?h(Ee,{persona:u,starters:[],onPick:x,onFocusComposer:tr,speaking:y,voiceState:z,replyPending:D&&v&&!y,pinned:!0,muted:Wt,onToggleMute:nr,onEndCall:Q,onTalkNow:or,showTalkNow:sr,micLevel:Kt,theaterMode:O,onToggleTheater:Wn,onMinimize:J,audioDevices:Yt,selectedAudioDeviceId:Zt,onSelectAudioDevice:ar,connectingOnly:wr}):null}),!wr&&g(`div`,{class:`cf-panel__chat`,children:[s.preview&&h(`div`,{class:`cf-preview-banner`,children:c.previewBanner}),q&&h(`div`,{class:`cf-viewing-banner`,children:c.viewingPast}),g(`div`,{class:`cf-body`,ref:sn,role:`log`,onScroll:zn,children:[yr.map((e,t)=>h(n,{msg:e,persona:u,isLast:!q&&t===yr.length-1,visitor:Le,hasEmail:Ue,lastQuestion:hr,showActions:!q&&t===yr.length-1&&!!(e.handoffOffered||e.selectedAction),onPickReply:mr,onSubmitForm:ct,onDemoSlots:mt,onConfirmHostedBooking:lt,onRetry:tt,ratable:!q&&yr.slice(0,t).some(e=>e.role===`user`),onRate:nt,onExpandVisualization:q?void 0:Gn,onOpenAttachment:jt,onReconnect:!q&&!C&&Pt&&e.id===Et?it:void 0},e.id)),!gr&&!q&&g(ke,{children:[yr.length===0&&h(je,{name:u?.agentName??c.assistantName,greeting:u?.greeting}),h(we,{items:Ke,onPick:x}),h(Te,{items:qe})]}),Cn&&g(`button`,{type:`button`,class:`cf-newmsg`,onClick:Y,children:[h(r,{}),c.newMessages]})]}),h(`div`,{class:`cf-sr-live`,"aria-live":`polite`,"aria-atomic":`true`,children:cr}),v&&!C&&!q&&h(`div`,{class:`cf-stopbar`,children:g(`button`,{type:`button`,class:`cf-stop`,onClick:Xe,children:[h(ie,{}),c.stop]})}),q?h(`div`,{class:`cf-ended`,children:h(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Ct,children:c.backToChat})}):C?g(`div`,{class:`cf-ended`,children:[h(`p`,{class:`cf-ended__text`,children:c.conversationEnded}),s.csat&&gr?kn?h(`p`,{class:`cf-ended__text`,children:c.feedbackThanks}):g(`div`,{class:`cf-csat`,children:[h(`span`,{class:`cf-csat__q`,children:c.csatPrompt}),h(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":c.feedbackHelpful,onClick:()=>{st(`up`),An(!0)},children:h(o,{})}),h(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":c.feedbackNotHelpful,onClick:()=>{st(`down`),An(!0)},children:h(i,{})})]}):null,h(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Ln,children:c.startNewChat})]}):g(ke,{children:[Ge?h(`div`,{class:`cf-live-typing`,"aria-live":`polite`,children:ae(c.agentTyping,{name:Ge})}):null,Sr&&Sr.length>0&&h(`div`,{class:`cf-footer-actions`,children:h(de,{actions:Sr,descriptors:Cr,visitor:Le,onSubmitForm:ct,onDemoSlots:mt,onConfirmHostedBooking:lt,scheduler:u?.scheduler,translations:s.actionTranslations})},`footer-actions`),h(pe,{draftStore:Dn,onSend:x,onSendGif:Je,onTyping:Ye,disabled:v,allowVoice:_r,onTranscribe:ut,gifEnabled:ht,onSearchGifs:pt,allowAttach:s.attachments,analyzeAttachments:!0,onUpload:dt,onPreviewAttachment:Mt},`composer`)]}),!C&&u?.disclaimerText&&h(`div`,{class:`cf-disclaimer`,children:u.disclaimerText}),g(`div`,{class:`cf-footer`,children:[h(`button`,{type:`button`,class:`cf-footer__privacy`,"aria-label":c.clearDeviceData,onClick:()=>W(!0),children:c.privacyAndData}),h(`span`,{"aria-hidden":`true`,children:`·`}),c.poweredBy,` `,h(`a`,{href:`https://accurix.tech/centrinfo`,target:`_blank`,rel:`noopener noreferrer`,children:`Centrinfo`})]})]}),V&&h(`div`,{class:`cf-confirm`,onClick:()=>H(!1),children:g(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":c.endChatConfirm,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Me(e,e.currentTarget,()=>H(!1)),children:[h(`div`,{class:`cf-confirm__title`,children:c.endChatConfirm}),h(`div`,{class:`cf-confirm__body`,children:c.endChatConfirmBody}),g(`div`,{class:`cf-confirm__actions`,children:[h(`button`,{ref:Tn,type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>H(!1),children:c.cancel}),h(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:In,children:c.endConfirmCta})]})]})},`confirm-end`),G&&h(`div`,{class:`cf-confirm`,onClick:()=>K(!1),children:g(`div`,{class:`cf-history`,role:`dialog`,"aria-modal":`true`,"aria-label":c.pastConversations,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Me(e,e.currentTarget,()=>K(!1)),children:[g(`div`,{class:`cf-history__head`,children:[h(`span`,{children:c.pastConversations}),h(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.closeHistory,onClick:()=>K(!1),children:h(ve,{})})]}),h(`div`,{class:`cf-history__list`,children:yt.map(e=>g(`button`,{type:`button`,class:`cf-history__item ${e.sessionId===bt?`is-active`:``}`,onClick:()=>{St(e.sessionId),K(!1)},children:[h(`span`,{class:`cf-history__title`,children:e.title}),g(`span`,{class:`cf-history__meta`,children:[new Date(e.ts).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),e.ended?` · ${c.historyEnded}`:``]})]},e.sessionId))}),h(`div`,{class:`cf-history__footer`,children:h(`button`,{type:`button`,class:`cf-history__clear`,onClick:()=>{K(!1),W(!0)},children:c.clearDeviceData})})]})},`history`),U&&h(`div`,{class:`cf-confirm`,onClick:()=>W(!1),children:g(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":c.clearDeviceData,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Me(e,e.currentTarget,()=>W(!1)),children:[h(`div`,{class:`cf-confirm__title`,children:c.clearDeviceData}),h(`div`,{class:`cf-confirm__body`,children:c.clearDeviceDataBody}),g(`div`,{class:`cf-confirm__actions`,children:[h(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>W(!1),children:c.cancel}),h(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:()=>{W(!1),wt()},children:c.clearDeviceDataCta})]})]})},`confirm-clear`)]}),D&&!l?h(oe,{persona:u,voiceState:z,muted:Wt,onToggleMute:nr,onEndCall:Q,micLevel:Kt,onExpand:Nn}):O&&l?null:!s.hideDefaultLauncher&&g(`button`,{ref:on,type:`button`,class:`cf-launcher`,"aria-label":l?c.closeChat:T>0?`${c.openChat}. ${T===1?c.unreadMessage:ae(c.unreadMessages,{count:String(T)})}`:c.openChat,"aria-expanded":l,onClick:Pn,children:[s.launcherIcon?h(`img`,{class:`cf-launcher__img`,src:s.launcherIcon,alt:``}):h(re,{}),!l&&T>0&&h(`span`,{class:`cf-launcher__badge`,"aria-hidden":`true`,children:T>99?`99+`:T})]})]})})},b=`centrinfo-widget`;var We=class extends HTMLElement{constructor(...e){super(...e),a(this,`controls`,null),a(this,`composerDraftStore`,{value:``})}mountWith(e){let t=c(e),n=this.shadowRoot??this.attachShadow({mode:`open`});if(this.style.zIndex=String(t.zIndex),`adoptedStyleSheets`in Document.prototype&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`){let e=new CSSStyleSheet;e.replaceSync(l),n.adoptedStyleSheets=[e]}else{let e=document.createElement(`style`);t.styleNonce&&(e.nonce=t.styleNonce),e.textContent=l,n.appendChild(e)}u(h(Ue,{transport:t.demo?new ue:t.preview?new s(new le(t.apiBaseUrl,t.token,t.gifApiKey,t.analyticsContextToken,{agentName:t.agentName,agentAvatarUrl:t.agentAvatarUrl},t.identityToken,t.getIdentityToken,t.chatSurface),t.strings):new le(t.apiBaseUrl,t.token,t.gifApiKey,t.analyticsContextToken,{agentName:t.agentName,agentAvatarUrl:t.agentAvatarUrl},t.identityToken,t.getIdentityToken,t.chatSurface),config:t,bindControls:e=>this.controls=e,composerDraftStore:this.composerDraftStore}),n)}open(){this.controls?.open()}close(){this.controls?.close()}toggle(){this.controls?.toggle()}identify(e){this.controls?.identify(e)}clear(){this.controls?.startNew()}shutdown(){this.controls?.shutdown()}unmount(){this.shadowRoot&&u(null,this.shadowRoot)}};typeof customElements<`u`&&!customElements.get(b)&&customElements.define(b,We);const Ge=(e,t=document.body)=>{if(typeof document>`u`)throw Error(`[centrinfo-widget] createWidget must run in a browser.`);let n=document.createElement(b);return n.style.pointerEvents=`none`,n.style.position=`fixed`,n.style.inset=`0`,n.style.width=`0`,n.style.height=`0`,t.appendChild(n),n.mountWith(e),{open:()=>n.open(),close:()=>n.close(),toggle:()=>n.toggle(),show:()=>n.open(),hide:()=>n.close(),identify:e=>n.identify(e),update:e=>n.identify(e),clear:()=>n.clear(),shutdown:()=>n.shutdown(),logout:()=>n.shutdown(),destroy:()=>{n.unmount(),n.remove()}}},Ke=e=>Ge(e);let qe=null;const x=e=>{qe?.destroy();let t=Ke(e);return qe=t,t},Je={init:x,createWidget:Ke};export{Je as Centrinfo,Ke as createWidget,x as init};
1
+ import{A as e,B as t,C as n,E as r,F as i,H as a,I as o,L as ee,M as te,N as ne,O as re,P as ie,R as ae,S as oe,T as se,U as ce,V as le,X as s,Z as ue,_ as de,a as fe,b as pe,d as me,h as he,i as ge,j as _e,k as ve,m as ye,n as be,p as xe,r as Se,t as c,u as Ce,v as we,w as Te,x as Ee,y as De,z as Oe}from"./styles-DwSTSmZb.mjs";import{render as l}from"preact";import{useCallback as u,useEffect as d,useLayoutEffect as ke,useRef as f,useState as p}from"preact/hooks";import{Fragment as Ae,jsx as m,jsxs as h}from"preact/jsx-runtime";const je=(e,t)=>{if(typeof MutationObserver>`u`)return()=>void 0;let n=e.scrollHeight,r=0,i=()=>{r=0;let i=e.scrollHeight,a=i>n,o=t.isAtBottom();n=i,a&&(o?(e.scrollTop=e.scrollHeight,t.onFollow?.()):t.onUnseen?.())},a=new MutationObserver(()=>{r||(r=typeof requestAnimationFrame==`function`?requestAnimationFrame(i):setTimeout(i,0))});return a.observe(e,{childList:!0,subtree:!0,characterData:!0}),()=>{a.disconnect(),r&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(r)}},Me=e=>e.startsWith(`image/`)?`image`:e===`application/pdf`?`pdf`:`other`,Ne=({state:e,onClose:n})=>{let r=le(),i=f(null);d(()=>{i.current?.focus();let e=e=>{e.key===`Escape`&&(e.stopPropagation(),n())};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[n]);let a=e.status===`ready`?Me(e.mimeType):`other`;return m(`div`,{class:`cf-preview`,role:`dialog`,"aria-modal":`true`,"aria-label":t(r.attachPreviewTitle,{name:e.name}),onClick:e=>{e.target===e.currentTarget&&n()},children:h(`div`,{class:`cf-preview__frame`,children:[h(`div`,{class:`cf-preview__bar`,children:[m(`span`,{class:`cf-preview__name`,title:e.name,children:e.name}),e.status===`ready`&&m(`a`,{class:`cf-preview__btn`,href:e.url,download:e.name,children:r.attachDownload}),m(`button`,{ref:i,type:`button`,class:`cf-preview__btn cf-preview__close`,"aria-label":r.attachPreviewClose,onClick:n,children:`✕`})]}),h(`div`,{class:`cf-preview__body`,children:[e.status===`loading`&&m(`p`,{class:`cf-preview__note`,children:r.attachPreviewLoading}),e.status===`error`&&m(`p`,{class:`cf-preview__note`,children:r.attachPreviewFailed}),e.status===`ready`&&a===`image`&&m(`img`,{class:`cf-preview__image`,src:e.url,alt:e.name}),e.status===`ready`&&a===`pdf`&&m(`iframe`,{class:`cf-preview__pdf`,src:e.url,title:e.name}),e.status===`ready`&&a===`other`&&m(`p`,{class:`cf-preview__note`,children:r.attachPreviewUnsupported})]})]})})},Pe=({name:e,greeting:n})=>{let r=le();return h(`section`,{class:`cf-empty-welcome`,"aria-label":t(r.welcomeLabel,{name:e}),children:[m(`span`,{class:`cf-empty-welcome__eyebrow`,children:r.welcomeEyebrow}),m(`h2`,{children:e}),m(`p`,{children:n||r.welcomePrompt})]})},Fe=(e,t,n)=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),n();return}if(e.key!==`Tab`)return;let r=Array.from(t.querySelectorAll(`button, [href], textarea, input, select, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hasAttribute(`disabled`)&&e.getAttribute(`aria-hidden`)!==`true`&&e.tabIndex>=0);if(r.length===0)return;let i=t.getRootNode(),a=e.composedPath()[0],o=a instanceof HTMLElement?a:`activeElement`in i?i.activeElement:document.activeElement,ee=r[0],te=r[r.length-1];e.shiftKey&&(o===ee||!t.contains(o))?(e.preventDefault(),e.stopPropagation(),te.focus()):!e.shiftKey&&(o===te||!t.contains(o))&&(e.preventDefault(),e.stopPropagation(),ee.focus())},g=new Map,_=e=>{if(!e||typeof document>`u`||typeof CanvasRenderingContext2D>`u`)return;let t=document.createElement(`canvas`).getContext(`2d`);if(!t)return;t.fillStyle=`#010203`,t.fillStyle=e;let n=t.fillStyle;if(n===`#010203`&&e.trim().toLowerCase()!==`#010203`)return;let r=n.match(/^#([\da-f]{6})$/i)?.[1];if(r)return[Number.parseInt(r.slice(0,2),16),Number.parseInt(r.slice(2,4),16),Number.parseInt(r.slice(4,6),16),1];let i=n.match(/^rgba?\(([\d.]+)[, ]+([\d.]+)[, ]+([\d.]+)(?:[, /]+([\d.]+))?\)$/i);if(!i)return;let a=i.slice(1,5).map(Number);if(!a.some(e=>!Number.isFinite(e)))return[a[0],a[1],a[2],a[3]??1]},Ie=(e,t=`#ffffff`)=>{let n=`${e??``}|${t}`;if(g.has(n))return g.get(n);let r=_(e),i=_(t)??[255,255,255,1];if(!r){g.set(n,void 0);return}let a=r[3],o=r.slice(0,3).map((e,t)=>e*a+i[t]*(1-a)).map(e=>{let t=e/255;return t<=.04045?t/12.92:((t+.055)/1.055)**2.4}),ee=o[0]*.2126+o[1]*.7152+o[2]*.0722,te=1.05/(ee+.05)>=(ee+.05)/.059?`#ffffff`:`#0f1e2a`;return g.set(n,te),te},Le=e=>{let[t,n]=p(`light`);return d(()=>{if(e!==`auto`||typeof matchMedia>`u`)return;let t=matchMedia(`(prefers-color-scheme: dark)`),r=()=>n(t.matches?`dark`:`light`);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),e===`auto`?t:e},Re={end:`end the call`,mute:`mute your microphone`,minimize:`minimize the chat`,expand:`expand the view`,shrink:`exit the expanded view`},ze=e=>e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s']/gu,` `).replace(/\s+/g,` `).trim(),v=[{action:`shrink`,re:/\b(?:exit|leave|quit|close)\b[\s\w]*\b(?:full ?screen|expanded|theat(?:er|re))\b|\bshrink\b|\bsmaller view\b/},{action:`end`,re:/\b(?:end|close|stop|finish|hang ?up|quit|exit)\b[\s\w]*\b(?:call|chat|conversation|convo|session|talking)\b|\bhang ?up\b|\bgood ?bye\b|^bye(?: bye)?$/},{action:`mute`,re:/\bmute\b|\bstop listening\b/},{action:`minimize`,re:/\bminimi[sz]e\b|\bhide\b[\s\w]*\b(?:chat|call|window|widget)\b/},{action:`expand`,re:/\bexpand\b|\bmaximi[sz]e\b|\bfull ?screen\b|\btheat(?:er|re) mode\b|\bbigger view\b/}],Be=/^(?:yes|yeah|yep|yup|sure|correct|confirm|affirmative|go ahead|do it|please do|ok(?:ay)?)\b/,Ve=/^(?:no|nope|nah|cancel|never ?mind|don'?t|stop)\b/,He=/^(?:end|close|stop|finish|hang ?up|quit|exit|bye|good ?bye)\b/,Ue=e=>{let t=ze(e);if(!t)return null;for(let{action:e,re:n}of v)if(n.test(t)){let n=t.split(` `).length;return{action:e,confident:e===`end`?n<=10:n<=6}}return null},We=e=>`I didn't catch yes or no. Say yes to ${Re[e]}, or no to keep talking.`,y=({transport:le,config:s,bindControls:ue,composerDraftStore:be})=>{let c=s.strings,[l,Me]=p(s.openByDefault),{persona:g,messages:_,sending:v,assistantSpeaking:y,visitor:Ge,hasEmail:Ke,liveMode:b,assignedAgentName:qe,agentTypingName:Je,starters:Ye,featuredLinks:Xe,send:x,sendGif:Ze,notifyTyping:Qe,stop:$e,amend:et,hold:tt,resumeHeld:nt,duckSpeaking:rt,retry:it,rateMessage:at,rateExplanation:ot,explanationTransport:st,injectAssistant:ct,reconnectSupport:lt,appendUserDraft:ut,patchMessage:S,removeMessage:dt,submitCsat:ft,submitForm:pt,confirmHostedBooking:mt,transcribe:ht,uploadAttachment:gt,loadAttachment:_t,searchGifs:vt,demoSlots:yt,gifEnabled:bt,identify:xt,ended:C,endConversation:St,startNew:Ct,history:wt,viewingSessionId:Tt,viewMessages:Et,openConversation:Dt,closeHistoryView:Ot,shutdown:kt,stopSpeaking:w,speakAssistantText:At}=fe(le,s,l),jt=ge(_,b),[Mt,Nt]=p(null),Pt=f(0),Ft=u((e,t,n)=>{n===Pt.current&&Nt({status:`ready`,name:t,url:URL.createObjectURL(e),mimeType:e.type||`application/octet-stream`})},[]),It=u((e,t,n)=>{let r=t.name,i=++Pt.current;Nt({status:`loading`,name:r}),_t(e,t,n).then(e=>Ft(e,r,i),()=>{i===Pt.current&&Nt({status:`error`,name:r})})},[_t,Ft]),Lt=u((e,t)=>Ft(e,t,++Pt.current),[Ft]),Rt=u(()=>{Pt.current+=1,Nt(null)},[]);d(()=>()=>{Mt?.status===`ready`&&URL.revokeObjectURL(Mt.url)},[Mt]);let zt=!!Se(g?.actions),[T,Bt]=p(0),[E,Vt]=p({mic:`off`,processing:!1}),[Ht,Ut]=p(null),[Wt,Gt]=p(!1),[D,Kt]=p(!1),[qt,Jt]=p(!1),[Yt,Xt]=p(!1),[Zt,Qt]=p(0),[O,k]=p(!1),[$t,A]=p(null),[en,tn]=p(null),[nn,rn]=p([]),[an,on]=p(``),[sn,cn]=p(()=>{try{return localStorage.getItem(`centrinfo:muted`)===`1`}catch{return!1}}),ln=Le(s.theme),un=g?.soundEnabled??!0;d(()=>{me(s.sound&&un&&!sn)},[s.sound,un,sn]);let dn=u(()=>{cn(e=>{let t=!e;try{localStorage.setItem(`centrinfo:muted`,t?`1`:`0`)}catch{}return t})},[]),j=f(null),fn=f(null),pn=f(null),mn=f(0),M=f(!1),N=f(!1),P=f(null),F=f(0),hn=f(void 0),gn=f(0),_n=f(null),vn=f(!1),I=f(null),L=f(``),yn=f(()=>{}),bn=f(``),xn=f(v),Sn=f(x);Sn.current=x;let Cn=f(et);Cn.current=et;let wn=f(ht);wn.current=ht;let R=f(!1),z=f(!1),Tn=f(``);Tn.current=[..._].reverse().find(e=>e.role===`assistant`)?.content??``;let En=f(y);xn.current=v,En.current=y;let B=D?Wt?`timeout`:Yt||E.mic===`muted`?`muted`:E.mic===`unavailable`?E.reason===`permission-denied`||E.reason===`unsupported`?`denied`:`unavailable`:E.mic===`off`||E.mic===`starting`?`connecting`:E.mic===`hearing`?`hearing`:y?`speaking`:Ht??(E.processing||v?`processing`:`listening`):`idle`,[Dn,On]=p(!0),[kn,V]=p(!1),An=f(0),[H,jn]=p(!1),[U,W]=p(!1),Mn=f(null),[G,K]=p(!1),Nn=f({value:``}),Pn=be??Nn.current,Fn=f({confirmEnd:H,confirmClear:U,showHistory:G});Fn.current={confirmEnd:H,confirmClear:U,showHistory:G};let[In,Ln]=p(!1),q=!!Tt,Rn=q?Et:_,zn=Rn.find(e=>e.id===$t&&e.visualization)?.visualization,Bn=Rn.find(e=>e.id===en&&e.visualization);d(()=>{!en||Bn||(tn(null),k(!1))},[en,Bn]),d(()=>{!$t||zn||(A(null),k(!1))},[zn,$t]);let Vn=u(()=>{Me(!0),Bt(0),Ce(`open`),s.onOpen?.(),s.onShow?.()},[s]),J=u(()=>{Me(!1),k(!1),A(null),s.onClose?.(),s.onHide?.(),fn.current?.focus()},[s]),Hn=u(()=>l?J():Vn(),[l,Vn,J]),Un=u(()=>jn(!0),[]),Wn=u(()=>{St(),jn(!1)},[St]),Gn=u(()=>{Ct(),V(!1),On(!0)},[Ct]);d(()=>{H&&Mn.current?.focus()},[H]),d(()=>{ue({open:Vn,close:J,toggle:Hn,identify:xt,startNew:Ct,endConversation:St,shutdown:kt})},[ue,Vn,J,Hn,xt,Ct,St,kt]),d(()=>{let e=_.filter(e=>e.role===`assistant`&&!e.pending).length;if(l){mn.current=e;return}e>mn.current&&Bt(e-mn.current)},[_,l]),d(()=>{s.onUnreadChange?.(T)},[T,s]),d(()=>{let e=s.sessionDurationMinutes;if(!e||e<=0)return;let t=setTimeout(()=>kt(),e*60*1e3);return()=>clearTimeout(t)},[s.sessionDurationMinutes,_,l,kt]),d(()=>{let e=s.customLauncherSelector;if(!e||typeof document>`u`)return;let t=[];try{t=Array.from(document.querySelectorAll(e))}catch{return}let n=e=>{e.preventDefault(),Hn()};return t.forEach(e=>e.addEventListener(`click`,n)),()=>t.forEach(e=>e.removeEventListener(`click`,n))},[s.customLauncherSelector,Hn]);let Kn=f(!1);d(()=>{let e=s.proactiveMessage?.trim();if(!e||Kn.current)return;let t=s.proactiveOnPaths??[],n=typeof location<`u`?location.pathname:``;if(t.length>0&&!t.some(e=>n.includes(e)))return;let r=`centrinfo:proactive:${s.token.slice(0,12)}`;try{if(sessionStorage.getItem(r)===`1`)return}catch{}let i=setTimeout(()=>{if(!(l||C||_.some(e=>e.role===`user`))){Kn.current=!0;try{sessionStorage.setItem(r,`1`)}catch{}ct(e),Vn()}},Math.max(0,s.proactiveDelaySeconds)*1e3);return()=>clearTimeout(i)},[s.proactiveMessage]),d(()=>{let e=pn.current;if(!l||!e)return;let t=_[_.length-1],n=Date.now()<An.current;t?.role===`user`||Dn||n?(requestAnimationFrame(()=>{e.scrollTop=e.scrollHeight}),V(!1),n&&On(!0)):V(!0)},[_,l,v,Dn]);let qn=f(!0);qn.current=Dn,d(()=>{let e=pn.current;if(!(!l||!e))return je(e,{isAtBottom:()=>qn.current,onUnseen:()=>V(!0)})},[l,q]);let Jn=u(()=>{let e=pn.current;if(!e)return;if(M.current&&!q){On(!0),V(!1);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;On(t),t&&V(!1)},[q]),Y=u(()=>{let e=pn.current;e&&(e.scrollTop=e.scrollHeight),V(!1),On(!0)},[]),Yn=u(()=>{An.current=Date.now()+3e3,requestAnimationFrame(Y)},[Y]);d(()=>{if(!l||q||!D||B===`connecting`)return;An.current=Date.now()+6e4,Y();let e=requestAnimationFrame(()=>{Y(),requestAnimationFrame(Y)}),t=[80,180,360].map(e=>window.setTimeout(Y,e));return()=>{cancelAnimationFrame(e),t.forEach(e=>window.clearTimeout(e))}},[y,_,l,Y,v,D,q,B]);let Xn=u(()=>{j.current?.querySelector(`.cf-textarea`)?.focus()},[]),Zn=u((e,t)=>{Ut(e),hn.current&&window.clearTimeout(hn.current),hn.current=window.setTimeout(()=>Ut(null),3e3),t&&!N.current&&At(t)},[At]),Qn=u(e=>{let t=I.current;if(t)return t;Yn();let n=ut(e);return I.current=n,S(n,{content:L.current||e,pending:!0,streaming:!1}),n},[ut,Yn,S]),X=u(()=>{let e=I.current;if(e){if(L.current){S(e,{content:L.current,pending:!0});return}I.current=null,dt(e)}},[S,dt]),Z=u(()=>{z.current&&(z.current=!1,rt(!1)),R.current&&(R.current=!1,nt())},[rt,nt]),Q=u(()=>{M.current=!1,P.current?.stop(`call-ended`),P.current=null,R.current=!1,z.current=!1,N.current=!1,_n.current=null,vn.current=!1;let e=I.current;I.current=null,L.current=``,e&&dt(e),hn.current&&window.clearTimeout(hn.current),Ut(null),Gt(!1),Vt({mic:`off`,processing:!1}),Qt(0),Kt(!1),Jt(!1),Xt(!1),k(!1),A(null),w()},[dt,w]),$n=u(()=>{O&&A(null),k(!O)},[O]),er=u(e=>{A(e),k(!0)},[]),tr=u(e=>{tn(e),k(!0)},[]),nr=u(()=>{let e=$t,t=en;A(null),tn(null),k(!1),window.requestAnimationFrame(()=>{(t?j.current?.querySelector(`[data-explanation-message="${t}"]`)?.querySelector(`[data-testid="analytics-explanation-expand"]`):Array.from(j.current?.querySelectorAll(`[data-visualization-message]`)??[]).find(t=>t.dataset.visualizationMessage===e))?.focus()})},[$t,en]),rr=u(()=>{A(null),tn(null),k(!1)},[]),ir=u((e,t,n=!1)=>{if(Yn(),t&&(S(t,{content:e,pending:!1,streaming:!1}),I.current===t&&(I.current=null)),L.current=``,n){w(),Cn.current(e,{forceVoicePlayback:!0,userMessageId:t});return}M.current&&(tt()?Cn.current(e,{forceVoicePlayback:!0,userMessageId:t}):Sn.current(e,{forceVoicePlayback:!0,userMessageId:t}))},[Yn,tt,S,w]),$=u(e=>{ct(e),At(e)},[ct,At]),ar=u(()=>{if(F.current=Date.now(),Ut(null),En.current){z.current=!0,rt(!0);return}R.current||(R.current=tt()),Qn(`Listening...`)},[rt,Qn,tt]),or=u(e=>{let t=I.current;!t||z.current||S(t,{content:`${[L.current,e].filter(Boolean).join(` `)} ...`,pending:!0})},[S]),sr=u(e=>{F.current=Date.now();let t=[L.current,e.text].map(e=>e.trim()).filter(Boolean).join(` `).replace(/\s+/g,` `).trim();if((z.current||e.overlappedOutput)&&ce(e.text,Tn.current)){X(),Z();return}if(!t||xe(t)||ye(t)){let e=z.current||R.current;X(),Z(),e||Zn(`misunderstood`);return}z.current&&(z.current=!1,$e(),w());let n=_n.current;if(n){L.current=``,X();let e=ze(t);if(Be.test(e)||n===`end`&&He.test(e)){_n.current=null,yn.current(n);return}if(Ve.test(e)){_n.current=null,$(`Okay, never mind — what would you like to know?`);return}$(We(n));return}let r=Ue(t);if(r){if(L.current=``,X(),Z(),r.confident){yn.current(r.action);return}_n.current=r.action,$(`Just to confirm — you want me to ${Re[r.action]}? Please say yes or no.`);return}let i=Qn(t);S(i,{content:t,pending:!0});let a=R.current;R.current=!1,ir(t,i,a)},[Qn,S,Z,ir,X,Zn,$,$e,w]),cr=u(e=>{F.current=Date.now();let t=z.current||R.current;if(X(),Z(),!(t||e.overlappedOutput||e.reason===`too-short`)){if(e.reason===`transcribe-failed`){Zn(`misunderstood`,`I couldn't transcribe that. Please try again, or type your question.`);return}Zn(`noise`)}},[Z,X,Zn]),lr=f({speechStart:ar,partial:or,turn:sr,noise:cr});lr.current={speechStart:ar,partial:or,turn:sr,noise:cr};let ur=u(()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{rn(e.filter(e=>e.kind===`audioinput`).map((e,t)=>({deviceId:e.deviceId,label:e.label||`Microphone ${t+1}`})))}).catch(()=>{})},[]),dr=u(()=>{if(M.current){Q();return}if(Xn(),!g?.allowVoiceInput||!g.talkbackMode||g.talkbackMode===`text`||xn.current||C||q)return;F.current=Date.now(),N.current=!1,M.current=!0,Xt(!1),Kt(!0),Jt(!1),Gt(!1);let e=!1,t=new a({deviceId:bn.current||void 0,transcribe:async({audio:e,mimeType:t,durationSeconds:n})=>{let r=typeof navigator<`u`&&(navigator.languages?.[0]||navigator.language)||void 0;return he(await wn.current(e,t,r,n))},listener:{state:t=>{Vt(t),t.mic!==`starting`&&t.mic!==`off`&&Jt(!0),!e&&t.mic===`listening`&&(e=!0,ur())},speechStart:()=>lr.current.speechStart(),partial:({text:e})=>lr.current.partial(e),turn:e=>lr.current.turn(e),noise:e=>lr.current.noise(e),level:e=>{let t=performance.now();t-gn.current<90||(gn.current=t,Qt(e))}}});P.current=t,t.setOutputActive(En.current),t.start()},[Q,C,Xn,g,ur,q]),fr=u(()=>{let e=!N.current;N.current=e,Xt(e),P.current?.setMuted(e),e?(L.current=``,X(),Z()):F.current=Date.now()},[Z,X]),pr=u(e=>{switch(F.current=Date.now(),e){case`end`:vn.current=!0,$(`Okay — ending our call now. Goodbye!`),window.setTimeout(()=>{vn.current&&(vn.current=!1,Q())},2e3);break;case`mute`:N.current||fr(),$(`Muted. Tap the mic button when you want me to listen again.`);break;case`minimize`:J(),$(`Minimized — I'm still listening. Tap the call pill to bring the chat back.`);break;case`expand`:k(!0),$(`Sure — expanding the view.`);break;case`shrink`:A(null),k(!1),$(`Okay — back to the smaller view.`);break}},[J,Q,$,fr]);d(()=>{yn.current=pr},[pr]);let mr=f(!1);d(()=>{mr.current&&!y&&vn.current&&(vn.current=!1,Q()),mr.current=y},[y,Q]);let hr=u(e=>{bn.current=e,on(e),P.current?.selectDevice(e||void 0)},[]),gr=u(()=>{!M.current||N.current||(z.current=!1,R.current=!1,$e(),w(),F.current=Date.now())},[$e,w]);d(()=>{P.current?.setOutputActive(y),F.current=Date.now()},[y]),d(()=>{if(B!==`denied`)return;let e=window.setTimeout(()=>Q(),3500);return()=>window.clearTimeout(e)},[Q,B]),d(()=>{if(!D)return;let e=window.setInterval(()=>{let e=P.current;!e||N.current||xn.current||En.current||e.snapshot.mic===`hearing`||e.snapshot.processing||Date.now()-F.current<6e4||(P.current?.log.add(`call-timeout`),Gt(!0),window.setTimeout(()=>Q(),2400))},5e3);return()=>window.clearInterval(e)},[Q,D]);let _r=D&&!Yt&&(v||y);d(()=>()=>Q(),[Q]);let[vr,yr]=p(``),br=f(!1);d(()=>{if(br.current&&!v){let e=[..._].reverse().find(e=>e.role===`assistant`&&!e.streaming&&!e.pending&&e.content);e&&yr(e.content)}br.current=v},[v,_]),ke(()=>{if(!l)return;let e=j.current,t=H||U?e?.querySelector(`.cf-confirm__card`):G?e?.querySelector(`.cf-history`):null;if(!t)return;let n=t.getRootNode(),r=`activeElement`in n?n.activeElement:document.activeElement;(!r||!t.contains(r))&&t.querySelector(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`)?.focus()},[U,H,l,G]),d(()=>{if(!l)return;let e=j.current,t=H||U?e?.querySelector(`.cf-confirm__card`):G?e?.querySelector(`.cf-history`):null,n=e?.querySelectorAll(`:scope > .cf-header, :scope > .cf-panel__video, :scope > .cf-panel__chat`);n?.forEach(e=>{t?(e.setAttribute(`inert`,``),e.setAttribute(`aria-hidden`,`true`)):(e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`))}),t||requestAnimationFrame(()=>e?.querySelector(`.cf-textarea`)?.focus());let r=e=>{if(e.key===`Escape`){e.preventDefault();let t=Fn.current;if(t.confirmEnd){jn(!1);return}if(t.confirmClear){W(!1);return}if(t.showHistory){K(!1);return}J();return}if(e.key!==`Tab`||!t)return;let n=t.querySelectorAll(`button, [href], textarea, input, [tabindex]:not([tabindex="-1"])`),r=Array.from(n).filter(e=>!e.hasAttribute(`disabled`));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=t.getRootNode()instanceof ShadowRoot?t.getRootNode().activeElement:document.activeElement;e.shiftKey&&o===i?(e.preventDefault(),a.focus()):!e.shiftKey&&o===a&&(e.preventDefault(),i.focus())};return e?.addEventListener(`keydown`,r),()=>{e?.removeEventListener(`keydown`,r),n?.forEach(e=>{e.removeAttribute(`inert`),e.removeAttribute(`aria-hidden`)})}},[l,J,H,U,G]),d(()=>{let e=j.current;e&&(l?e.removeAttribute(`inert`):e.setAttribute(`inert`,``))},[l]);let xr=s.accentColor??s.themeTokens?.accent??g?.accentColor,Sr=s.themeTokens?.accentText??Ie(xr,s.themeTokens?.background??(ln===`dark`?`#0f1c27`:`#ffffff`)),Cr={zIndex:s.zIndex,"--cf-h-pad":`${s.horizontalPadding}px`,"--cf-v-pad":`${s.verticalPadding}px`,...Sr?{"--cf-accent-ink":Sr}:{},...s.themeTokens?.accentStrong?{"--cf-accent-2":s.themeTokens.accentStrong}:{},...s.themeTokens?.background?{"--cf-bg":s.themeTokens.background}:{},...s.themeTokens?.surface?{"--cf-surface":s.themeTokens.surface}:{},...s.themeTokens?.surfaceMuted?{"--cf-surface-2":s.themeTokens.surfaceMuted}:{},...s.themeTokens?.text?{"--cf-text":s.themeTokens.text}:{},...s.themeTokens?.mutedText?{"--cf-muted":s.themeTokens.mutedText}:{},...s.themeTokens?.border?{"--cf-border":s.themeTokens.border}:{},...s.themeTokens?.shadow?{"--cf-shadow":s.themeTokens.shadow}:{},...s.themeTokens?.radius?{"--cf-radius":s.themeTokens.radius}:{},...s.themeTokens?.fontFamily?{"--cf-font":s.themeTokens.fontFamily}:{},...s.themeTokens?.success?{"--cf-success":s.themeTokens.success}:{},...s.themeTokens?.warning?{"--cf-warning":s.themeTokens.warning}:{},...s.themeTokens?.danger?{"--cf-danger":s.themeTokens.danger}:{},...xr?{"--cf-accent":xr,"--cf-accent-2":s.themeTokens?.accentStrong??`color-mix(in oklab, ${xr} 76%, #14141f)`}:{}},wr=e=>x(e),Tr=[..._].reverse().find(e=>e.role===`user`&&e.content.trim())?.content??``,Er=_.some(e=>e.role===`user`),Dr=!!(g?.allowVoiceInput&&g?.talkbackMode&&g.talkbackMode!==`text`),Or=Dr,kr=!q&&Or&&!Er?Rn.filter((e,t)=>!(t===0&&e.role===`assistant`)):Rn,Ar=b===`human`&&qe?qe:g?.agentName??c.chatName,jr=b===`human`?c.liveSupport:b===`queued`?c.waitingForTeam:g?.offline?c.statusOffline:c.statusOnline,Mr=!C&&!q?g?.availableActions:void 0,Nr=!C&&!q?g?.actions:void 0,Pr=D&&!qt&&B===`connecting`&&!q;return m(Oe,{value:c,children:m(ae,{value:s.locale,children:h(`div`,{class:`cf-root`,dir:s.dir,"data-theme":ln,"data-align":s.alignment,"data-display":`floating`,style:Cr,children:[O&&l&&m(`div`,{class:`cf-theater-backdrop`,onClick:rr}),h(`div`,{ref:j,class:`cf-panel ${l?`is-open`:``} ${D?`cf-panel--call`:``} ${Pr?`cf-panel--voice-connecting`:``} ${O&&l?`cf-panel--theater`:``} ${zn||Bn?`cf-panel--analytics-focus`:``}`,role:`dialog`,"aria-modal":`false`,"aria-label":`${c.chatName}: ${g?.agentName??c.assistantName}`,"aria-hidden":!l,children:[Mt&&l&&m(Ne,{state:Mt,onClose:Rt}),h(`div`,{class:`cf-header`,children:[m(we,{persona:g,hideWhenMissing:!0}),h(`div`,{class:`cf-header__meta`,children:[m(`div`,{class:`cf-header__name`,children:Ar}),m(`div`,{class:`cf-header__status ${b===`ai`&&g?.offline?`cf-header__status--offline`:``}`,children:m(`span`,{class:`cf-header__status-text`,children:jr})})]}),h(`div`,{class:`cf-header__actions`,children:[wt.length>0&&m(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.pastConversations,title:c.pastConversations,"aria-pressed":G,onClick:()=>K(e=>!e),children:m(te,{})}),Er&&!C&&!q&&m(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.endChat,title:c.endChat,onClick:Un,children:m(_e,{})}),s.sound&&un&&m(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":sn?c.unmuteSounds:c.muteSounds,"aria-pressed":sn,onClick:dn,children:m(sn?ne:ie,{})}),m(`button`,{type:`button`,class:`cf-header__btn cf-header__close`,"aria-label":c.closeChat,onClick:J,children:m(e,{})})]})]}),m(`div`,{class:`cf-panel__video`,children:zn?m(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":c.expandedAnalyticsResult,children:m(r,{visualization:zn,expanded:!0,onFollowUp:e=>{nr(),x(e)},onClose:nr})}):Bn?.visualization?m(`div`,{class:`cf-analytics-focus`,role:`region`,"aria-label":c.expandedAnalyticsResult,children:m(se,{visualization:Bn.visualization,onClose:nr,onFollowUp:e=>{nr(),x(e)},onFeedback:q?void 0:ot,transport:q?void 0:st(`widget`),onOpenSource:s.onOpenAnalyticsSource})}):!q&&Or?m(De,{persona:g,starters:[],onPick:x,onFocusComposer:dr,speaking:y,voiceState:B,replyPending:D&&v&&!y,pinned:!0,muted:Yt,onToggleMute:fr,onEndCall:Q,onTalkNow:gr,showTalkNow:_r,micLevel:Zt,theaterMode:O,onToggleTheater:$n,onMinimize:J,audioDevices:nn,selectedAudioDeviceId:an,onSelectAudioDevice:hr,connectingOnly:Pr}):null}),!Pr&&h(`div`,{class:`cf-panel__chat`,children:[s.preview&&m(`div`,{class:`cf-preview-banner`,children:c.previewBanner}),q&&m(`div`,{class:`cf-viewing-banner`,children:c.viewingPast}),h(`div`,{class:`cf-body`,ref:pn,role:`log`,onScroll:Jn,children:[kr.map((e,t)=>m(n,{msg:e,persona:g,isLast:!q&&t===kr.length-1,visitor:Ge,hasEmail:Ke,lastQuestion:Tr,showActions:!q&&t===kr.length-1&&!!(e.handoffOffered||e.selectedAction),onPickReply:wr,onSubmitForm:pt,onDemoSlots:yt,onConfirmHostedBooking:mt,onRetry:it,ratable:!q&&kr.slice(0,t).some(e=>e.role===`user`),onRate:at,onExplanationFeedback:q?void 0:ot,explanationTransport:q?void 0:st(`widget`),onOpenAnalyticsSource:s.onOpenAnalyticsSource,onExpandVisualization:q?void 0:er,onExpandExplanation:q?void 0:tr,onOpenAttachment:It,onReconnect:!q&&!C&&zt&&e.id===jt?lt:void 0},e.id)),!Er&&!q&&h(Ae,{children:[kr.length===0&&m(Pe,{name:g?.agentName??c.assistantName,greeting:g?.greeting}),m(Te,{items:Ye,onPick:x}),m(Ee,{items:Xe})]}),kn&&h(`button`,{type:`button`,class:`cf-newmsg`,onClick:Y,children:[m(re,{}),c.newMessages]})]}),m(`div`,{class:`cf-sr-live`,"aria-live":`polite`,"aria-atomic":`true`,children:vr}),v&&!C&&!q&&m(`div`,{class:`cf-stopbar`,children:h(`button`,{type:`button`,class:`cf-stop`,onClick:$e,children:[m(i,{}),c.stop]})}),q?m(`div`,{class:`cf-ended`,children:m(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Ot,children:c.backToChat})}):C?h(`div`,{class:`cf-ended`,children:[m(`p`,{class:`cf-ended__text`,children:c.conversationEnded}),s.csat&&Er?In?m(`p`,{class:`cf-ended__text`,children:c.feedbackThanks}):h(`div`,{class:`cf-csat`,children:[m(`span`,{class:`cf-csat__q`,children:c.csatPrompt}),m(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":c.feedbackHelpful,onClick:()=>{ft(`up`),Ln(!0)},children:m(ee,{})}),m(`button`,{type:`button`,class:`cf-csat__btn`,"aria-label":c.feedbackNotHelpful,onClick:()=>{ft(`down`),Ln(!0)},children:m(o,{})})]}):null,m(`button`,{type:`button`,class:`cf-ended__btn`,onClick:Gn,children:c.startNewChat})]}):h(Ae,{children:[Je?m(`div`,{class:`cf-live-typing`,"aria-live":`polite`,children:t(c.agentTyping,{name:Je})}):null,Mr&&Mr.length>0&&m(`div`,{class:`cf-footer-actions`,children:m(de,{actions:Mr,descriptors:Nr,visitor:Ge,onSubmitForm:pt,onDemoSlots:yt,onConfirmHostedBooking:mt,scheduler:g?.scheduler,translations:s.actionTranslations})},`footer-actions`),m(pe,{draftStore:Pn,onSend:x,onSendGif:Ze,onTyping:Qe,disabled:v,allowVoice:Dr,onTranscribe:ht,gifEnabled:bt,onSearchGifs:vt,allowAttach:s.attachments,analyzeAttachments:!0,onUpload:gt,onPreviewAttachment:Lt},`composer`)]}),!C&&g?.disclaimerText&&m(`div`,{class:`cf-disclaimer`,children:g.disclaimerText}),h(`div`,{class:`cf-footer`,children:[m(`button`,{type:`button`,class:`cf-footer__privacy`,"aria-label":c.clearDeviceData,onClick:()=>W(!0),children:c.privacyAndData}),m(`span`,{"aria-hidden":`true`,children:`·`}),c.poweredBy,` `,m(`a`,{href:`https://accurix.tech/centrinfo`,target:`_blank`,rel:`noopener noreferrer`,children:`Centrinfo`})]})]}),H&&m(`div`,{class:`cf-confirm`,onClick:()=>jn(!1),children:h(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":c.endChatConfirm,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Fe(e,e.currentTarget,()=>jn(!1)),children:[m(`div`,{class:`cf-confirm__title`,children:c.endChatConfirm}),m(`div`,{class:`cf-confirm__body`,children:c.endChatConfirmBody}),h(`div`,{class:`cf-confirm__actions`,children:[m(`button`,{ref:Mn,type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>jn(!1),children:c.cancel}),m(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:Wn,children:c.endConfirmCta})]})]})},`confirm-end`),G&&m(`div`,{class:`cf-confirm`,onClick:()=>K(!1),children:h(`div`,{class:`cf-history`,role:`dialog`,"aria-modal":`true`,"aria-label":c.pastConversations,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Fe(e,e.currentTarget,()=>K(!1)),children:[h(`div`,{class:`cf-history__head`,children:[m(`span`,{children:c.pastConversations}),m(`button`,{type:`button`,class:`cf-header__btn`,"aria-label":c.closeHistory,onClick:()=>K(!1),children:m(e,{})})]}),m(`div`,{class:`cf-history__list`,children:wt.map(e=>h(`button`,{type:`button`,class:`cf-history__item ${e.sessionId===Tt?`is-active`:``}`,onClick:()=>{Dt(e.sessionId),K(!1)},children:[m(`span`,{class:`cf-history__title`,children:e.title}),h(`span`,{class:`cf-history__meta`,children:[new Date(e.ts).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),e.ended?` · ${c.historyEnded}`:``]})]},e.sessionId))}),m(`div`,{class:`cf-history__footer`,children:m(`button`,{type:`button`,class:`cf-history__clear`,onClick:()=>{K(!1),W(!0)},children:c.clearDeviceData})})]})},`history`),U&&m(`div`,{class:`cf-confirm`,onClick:()=>W(!1),children:h(`div`,{class:`cf-confirm__card`,role:`alertdialog`,"aria-modal":`true`,"aria-label":c.clearDeviceData,onClick:e=>e.stopPropagation(),onKeyDownCapture:e=>Fe(e,e.currentTarget,()=>W(!1)),children:[m(`div`,{class:`cf-confirm__title`,children:c.clearDeviceData}),m(`div`,{class:`cf-confirm__body`,children:c.clearDeviceDataBody}),h(`div`,{class:`cf-confirm__actions`,children:[m(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--cancel`,onClick:()=>W(!1),children:c.cancel}),m(`button`,{type:`button`,class:`cf-confirm__btn cf-confirm__btn--danger`,onClick:()=>{W(!1),kt()},children:c.clearDeviceDataCta})]})]})},`confirm-clear`)]}),D&&!l?m(oe,{persona:g,voiceState:B,muted:Yt,onToggleMute:fr,onEndCall:Q,micLevel:Zt,onExpand:Vn}):O&&l?null:!s.hideDefaultLauncher&&h(`button`,{ref:fn,type:`button`,class:`cf-launcher`,"aria-label":l?c.closeChat:T>0?`${c.openChat}. ${T===1?c.unreadMessage:t(c.unreadMessages,{count:String(T)})}`:c.openChat,"aria-expanded":l,onClick:Hn,children:[s.launcherIcon?m(`img`,{class:`cf-launcher__img`,src:s.launcherIcon,alt:``}):m(ve,{}),!l&&T>0&&m(`span`,{class:`cf-launcher__badge`,"aria-hidden":`true`,children:T>99?`99+`:T})]})]})})})},Ge=`centrinfo-widget`;var Ke=class extends HTMLElement{constructor(...e){super(...e),ue(this,`controls`,null),ue(this,`composerDraftStore`,{value:``})}mountWith(e){let t=be(e),n=this.shadowRoot??this.attachShadow({mode:`open`});if(this.style.zIndex=String(t.zIndex),`adoptedStyleSheets`in Document.prototype&&typeof CSSStyleSheet<`u`&&typeof CSSStyleSheet.prototype.replaceSync==`function`){let e=new CSSStyleSheet;e.replaceSync(c),n.adoptedStyleSheets=[e]}else{let e=document.createElement(`style`);t.styleNonce&&(e.nonce=t.styleNonce),e.textContent=c,n.appendChild(e)}l(m(y,{transport:s(t),config:t,bindControls:e=>this.controls=e,composerDraftStore:this.composerDraftStore}),n)}open(){this.controls?.open()}close(){this.controls?.close()}toggle(){this.controls?.toggle()}identify(e){this.controls?.identify(e)}clear(){this.controls?.startNew()}shutdown(){this.controls?.shutdown()}unmount(){this.shadowRoot&&l(null,this.shadowRoot)}};typeof customElements<`u`&&!customElements.get(Ge)&&customElements.define(Ge,Ke);const b=(e,t=document.body)=>{if(typeof document>`u`)throw Error(`[centrinfo-widget] createWidget must run in a browser.`);let n=document.createElement(Ge);return n.style.pointerEvents=`none`,n.style.position=`fixed`,n.style.inset=`0`,n.style.width=`0`,n.style.height=`0`,t.appendChild(n),n.mountWith(e),{open:()=>n.open(),close:()=>n.close(),toggle:()=>n.toggle(),show:()=>n.open(),hide:()=>n.close(),identify:e=>n.identify(e),update:e=>n.identify(e),clear:()=>n.clear(),shutdown:()=>n.shutdown(),logout:()=>n.shutdown(),destroy:()=>{n.unmount(),n.remove()}}},qe=e=>b(e);let Je=null;const Ye=e=>{Je?.destroy();let t=qe(e);return Je=t,t},Xe={init:Ye,createWidget:qe};export{Xe as Centrinfo,qe as createWidget,Ye as init};
package/dist/runtime.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require(`./styles-BgWsSZsR.cjs`),t=(e,n)=>{let r=e.replace(/\/\*[\s\S]*?\*\//g,``),i=e=>n.some(t=>e.includes(t)),a=[],o=0;for(;o<r.length;){let e=r.indexOf(`{`,o);if(e<0)break;let s=r.slice(o,e).trim(),c=1,l=e+1;for(;l<r.length&&c>0;)r[l]===`{`?c++:r[l]===`}`&&c--,l++;let u=r.slice(e+1,l-1);if(s.startsWith(`@`))if(/^@(media|supports|container)\b/.test(s)){let e=t(u,n);e&&a.push(`${s} {\n${e}\n}`)}else /^@keyframes\b/.test(s)&&i(s)&&a.push(`${s} {${u}}`);else i(s)&&a.push(`${s} {${u}}`);o=l}return a.join(`
2
- `)},n=t(e.t,[`.cf-action`,`.cf-form`,`.cf-booking`]),r=t=>t.demo?new e.Y:t.preview?new e.J(new e.X(t.apiBaseUrl,t.token,t.gifApiKey,t.analyticsContextToken,{agentName:t.agentName,agentAvatarUrl:t.agentAvatarUrl},t.identityToken,t.getIdentityToken,t.chatSurface),t.strings):new e.X(t.apiBaseUrl,t.token,t.gifApiKey,t.analyticsContextToken,{agentName:t.agentName,agentAvatarUrl:t.agentAvatarUrl},t.identityToken,t.getIdentityToken,t.chatSurface);exports.ActionsArea=e._,exports.ResultTable=e.U,exports.StringsProvider=e.L,exports.WIDGET_ACTION_STYLES=n,exports.WidgetAnalyticsChart=e.K,exports.buildWidgetAnalyticsChartModel=e.q,exports.createAdaptiveVoiceActivityDetector=e.o,exports.createChatTransport=r,exports.createPreferredAudioRecorder=e.s,exports.createVoiceAudioConstraints=e.c,exports.findLiveSupportAction=e.r,exports.formatResultCell=e.W,exports.looksLikeEcho=e.f,exports.reconnectableHandbackId=e.i,exports.renderRich=e.E,exports.resolveConfig=e.n,exports.selectStyleRules=t,exports.serializeResultCsv=e.G,exports.stopRecorderWithFlush=e.l,exports.usableTranscript=e.g,exports.useChat=e.a;
1
+ const e=require(`./styles-BH7P8Q_3.cjs`),t=(e,n)=>{let r=e.replace(/\/\*[\s\S]*?\*\//g,``),i=e=>n.some(t=>e.includes(t)),a=[],o=0;for(;o<r.length;){let e=r.indexOf(`{`,o);if(e<0)break;let s=r.slice(o,e).trim(),c=1,l=e+1;for(;l<r.length&&c>0;)r[l]===`{`?c++:r[l]===`}`&&c--,l++;let u=r.slice(e+1,l-1);if(s.startsWith(`@`))if(/^@(media|supports|container)\b/.test(s)){let e=t(u,n);e&&a.push(`${s} {\n${e}\n}`)}else /^@keyframes\b/.test(s)&&i(s)&&a.push(`${s} {${u}}`);else i(s)&&a.push(`${s} {${u}}`);o=l}return a.join(`
2
+ `)},n=(t,n,r)=>e.W(t,n,r),r=t(e.t,[`.cf-action`,`.cf-form`,`.cf-booking`]);exports.ActionsArea=e._,exports.ResultTable=e.G,exports.StringsProvider=e.z,exports.WIDGET_ACTION_STYLES=r,exports.WidgetAnalyticsChart=e.J,exports.analyticsResultDetails=n,exports.buildWidgetAnalyticsChartModel=e.Y,exports.createAdaptiveVoiceActivityDetector=e.o,exports.createChatTransport=e.X,exports.createPreferredAudioRecorder=e.s,exports.createVoiceAudioConstraints=e.c,exports.findLiveSupportAction=e.r,exports.formatResultCell=e.K,exports.looksLikeEcho=e.f,exports.reconnectableHandbackId=e.i,exports.renderRich=e.D,exports.resolveConfig=e.n,exports.selectStyleRules=t,exports.serializeResultCsv=e.q,exports.stopRecorderWithFlush=e.l,exports.usableTranscript=e.g,exports.useChat=e.a;