@webority/chat-elements 0.151.2 → 0.152.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/chat-elements.js +1 -1
- package/dist/chat.global.js +23 -23
- package/dist/types/dom.d.ts +1 -0
- package/dist/web-CEXzR2DU.js +1 -0
- package/dist/web.js +1 -1
- package/package.json +5 -5
- package/dist/web-CWwNklk-.js +0 -1
package/dist/types/dom.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare const BUTTON_VARIANTS: {
|
|
|
10
10
|
readonly neutral: "btn-soft-neutral";
|
|
11
11
|
readonly danger: "btn-danger";
|
|
12
12
|
};
|
|
13
|
+
export declare function hasOwn(target: object, key: PropertyKey): boolean;
|
|
13
14
|
export declare function el<K extends keyof HTMLElementTagNameMap>(tag: K, className?: string | null, attrs?: Readonly<Record<string, string | null | undefined>> | null): HTMLElementTagNameMap[K];
|
|
14
15
|
export declare function iconNode(name: string, size?: number): Element;
|
|
15
16
|
export declare function buttonClass(variant?: keyof typeof BUTTON_VARIANTS, size?: "md" | "sm"): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ChatSpeechError as e,ChatSpeechError as t,createExplain as n,mergeLabels as r}from"@webority/chat-core";import{glyphNode as i}from"@webority/ui-elements/helpers";var a=`(prefers-reduced-motion: reduce)`;function o(e,t){let n=e.style.animation;e.style.animation=`none`;let r=e.getBoundingClientRect();e.style.animation=n,e.style.transformOrigin=`${t.left+t.width/2-r.left}px ${t.top+t.height/2-r.top}px`}function s(e,t){let n=typeof window.matchMedia==`function`?window.matchMedia(a):null,r=/* @__PURE__ */ new Set,i=()=>e.motion===`Reduced`||t?.motion===!1||n?.matches===!0,o=i();function s(){let e=i();if(e!==o){o=e;for(let e of r)e(o)}}return n?.addEventListener(`change`,s),{get reduced(){return o},subscribe(e){return r.add(e),()=>{r.delete(e)}},destroy(){n?.removeEventListener(`change`,s),r.clear()}}}var c=`AppButton`,l={primary:`btn-primary`,secondary:`btn-soft-primary`,ghost:`btn-ghost-primary`,outline:`btn-outline-primary`,neutral:`btn-soft-neutral`,danger:`btn-danger`};function u(e,t){return Object.getOwnPropertyDescriptor(e,t)!==void 0}function d(e,t,n){let r=document.createElement(e);if(t&&(r.className=t),n)for(let[e,t]of Object.entries(n))t!=null&&r.setAttribute(e,t);return r}function f(e,t=16){return i(e,{size:t})??d(`span`,`d-inline-flex`)}function p(e=`primary`,t=`md`){if(!u(l,e))throw Error(`Unknown button variant "${e}". Use one of ${Object.keys(l).join(`, `)}.`);return`btn ${l[e]}${t===`sm`?` btn-sm`:``}`}function m(e,t,n,r){let i=d(`button`,`${p(e,`sm`)} wui-chat-action-btn`,{type:`button`});return i.dataset.wui=c,n&&i.append(f(n,14)),i.append(document.createTextNode(t)),i.addEventListener(`click`,r),i}function h(e,t,n){let r=d(`button`,`wui-chat-icon-btn`,{type:`button`,"aria-label":e,title:e});return r.append(f(t,20)),r.addEventListener(`click`,n),r}function g(e,t){let n=e.getAttribute(t);if(n!=null&&n!==``)try{return JSON.parse(n)}catch{throw Error(`<wui-chat ${t}> must be valid JSON.`)}}function _(e){let t;return n=>{let r=e.dataset.state;if((!n||r!==`open`&&r!==`opening`)&&(n||r!==`closed`&&r!==`closing`)){if(clearTimeout(t),n)e.dataset.state=`opening`,t=setTimeout(()=>{e.dataset.state=`open`},620);else{e.dataset.state=`closing`;let n=e.classList.contains(`wui-chat--panel-motion-none`)?0:300;t=setTimeout(()=>{e.dataset.state=`closed`},n)}}}}function v(e,t){t.position!==void 0&&(e.classList.toggle(`wui-chat--end`,t.position===`end`),e.classList.toggle(`wui-chat--start`,t.position===`start`)),t.reduced!==void 0&&e.classList.toggle(`wui-chat--reduced`,!!t.reduced),t.expressive!==void 0&&e.classList.toggle(`wui-chat--expressive`,t.expressive===!0),t.sendReveal!==void 0&&e.classList.toggle(`wui-chat--send-always`,t.sendReveal===`Always`),t.inputRing!==void 0&&e.classList.toggle(`wui-chat--input-ring-off`,t.inputRing===!1),t.panelMotion!==void 0&&(e.classList.toggle(`wui-chat--panel-motion-gentle`,t.panelMotion===`Gentle`),e.classList.toggle(`wui-chat--panel-motion-none`,t.panelMotion===`None`)),t.offsetX!==void 0&&e.style.setProperty(`--wui-chat-offset-x`,`${t.offsetX}px`),t.offsetY!==void 0&&e.style.setProperty(`--wui-chat-offset-y`,`${t.offsetY}px`),t.width!==void 0&&e.style.setProperty(`--wui-chat-width`,t.width),t.maxHeight!==void 0&&e.style.setProperty(`--wui-chat-panel-max-height`,`${t.maxHeight}px`),t.bottomGap!==void 0&&e.style.setProperty(`--wui-chat-bottom-gap`,`${t.bottomGap}px`),t.panelHeight!==void 0&&e.classList.toggle(`wui-chat--panel-height-content`,t.panelHeight===`Content`),t.avatar!==void 0&&(t.avatar?(e.style.setProperty(`--wui-chat-avatar`,`url(${JSON.stringify(t.avatar)})`),e.style.setProperty(`--wui-chat-typing-mark`,`url(${JSON.stringify(t.avatar)})`)):(e.style.removeProperty(`--wui-chat-avatar`),e.style.removeProperty(`--wui-chat-typing-mark`))),t.replyAvatars!==void 0&&e.classList.toggle(`wui-chat--reply-avatars-off`,t.replyAvatars===!1)}var y=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],b={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function x(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function S({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a}){let s=d(`div`,`wui-chat ${b[t]} wui-chat--${n}`),c=d(`section`,`wui-chat-panel`,{id:e,role:r}),l=i?_(s):null;s.dataset.state=i?`closed`:`open`;let u=null,p=null,m=null,h=null,g=null,y=null,S=null,C=`round`,w=!1,T=`bubble`,E=null,D=null,O=!1,k=`icon`,A=!1;function j(){if(!u)return;let e=u.dataset.launcher,t=[`wui-chat-launcher-wrap`];e===`entering`&&E&&t.push(`wui-chat-launcher--entrance-${E}`),e===`idle`&&D&&D!==`none`&&(D!==`ring`||C===`pill`)&&t.push(`wui-chat-launcher--idle-${D}`),u.className=t.join(` `)}function M(){if(!p)return;let e=[...p.classList].filter(e=>e.endsWith(`--opening`)||e.endsWith(`--closing`)),t=[`wui-chat-launcher`,`wui-chat-launcher--${C}`];C===`pill`&&w&&t.push(`wui-chat-launcher--compact`),k!==`icon`&&t.push(`wui-chat-launcher--mark-${k}`),t.push(`wui-chat-launcher--reveal-${T}`,...e),p.className=t.join(` `)}function N(){g&&y&&(g.textContent=S||y.launcher)}function P(){if(!p||!h||!y)return;let e=A?y.launcherClose:S||y.launcher;p.setAttribute(`aria-label`,e),h.textContent=e}if(i){let t=d(`div`,`wui-chat-launcher-wrap`);u=t,t.dataset.launcher=`idle`;let n=d(`button`,`wui-chat-launcher`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-controls":e});p=n;let r=d(`span`,`wui-chat-launcher-icon`,{"aria-hidden":`true`});m=r,r.append(f(`chat`,24));let i=d(`span`,`wui-chat-launcher-close`,{"aria-hidden":`true`});i.append(f(`x`,24));let o=d(`span`,`wui-chat-launcher-label`);h=o,n.append(r,i,o),n.addEventListener(`click`,()=>a()),n.addEventListener(`animationend`,e=>{e.target===n&&n.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`)});let l=d(`span`,`wui-chat-launcher-bubble`,{"aria-hidden":`true`});g=l,t.append(n,l),t.addEventListener(`animationend`,e=>{e.target===t&&t.dataset.launcher===`entering`&&(t.dataset.launcher=`idle`,j())}),M(),j(),s.append(t,c)}else s.append(c);function F(e){if(!l)return;let t=e&&!A&&p!==null&&p?p.getBoundingClientRect():null;e!==A&&p&&(p.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`),p.classList.add(e?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`)),A=e,l(e),t&&o(c,t),p&&(p.setAttribute(`aria-expanded`,String(e)),P())}function I(e){y=e,p&&(P(),N())}function L(e){if(v(s,e),e.theme!==void 0&&(e.theme===`light`||e.theme===`dark`?s.dataset.theme=e.theme:delete s.dataset.theme),!p||!u||!m)return;e.launcherStyle!==void 0&&(C=e.launcherStyle===`Pill`?`pill`:`round`),e.compact!==void 0&&(w=e.compact),e.labelReveal!==void 0&&(T=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(E=e.entrance===`None`?null:x(e.entrance)),e.idle!==void 0&&(D=e.idle===`None`?`none`:x(e.idle)),e.phone!==void 0&&(O=e.phone),e.hoverLabel!==void 0&&(S=e.hoverLabel||null),e.launcherMark!==void 0&&(k=x(e.launcherMark)),e.icon!==void 0&&e.icon!==m.dataset.icon&&(m.dataset.icon=e.icon,m.replaceChildren(f(e.icon,24)));let t=e.launcherState??u.dataset.launcher;O&&t===`entering`&&(t=`idle`),t===`entering`&&!E&&(t=`idle`),u.dataset.launcher=t,M(),j(),N(),P()}return{root:s,panel:c,setOpen:F,setLabels:I,setAppearance:L,nudgeHost:u,launcherButton:p,role:r}}var C=1e4,w=2e3,T=3e5,E=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),D=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function O(e){return E.has(A(e,`name`))?new t(`Blocked`,j(e)):D.has(A(e,`name`))?new t(`NoMicrophone`,j(e)):k(e)}function k(e){return e instanceof t?e:new t(`Failed`,j(e)??String(e))}function A(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function j(e){let t=A(e,`message`);return t==null?void 0:String(t)}function M(e){return typeof e==`object`&&!!e}function N(e){let t=A(e,`SpeechConfig`),n=A(e,`AudioConfig`),r=A(e,`NoMatchDetails`);return typeof A(t,`fromAuthorizationToken`)==`function`&&typeof A(n,`fromDefaultMicrophoneInput`)==`function`&&typeof A(n,`fromSpeakerOutput`)==`function`&&typeof A(r,`fromResult`)==`function`&&typeof A(e,`SpeechRecognizer`)==`function`&&typeof A(e,`SpeakerAudioDestination`)==`function`&&typeof A(e,`SpeechSynthesizer`)==`function`&&M(A(e,`PropertyId`))&&M(A(e,`ResultReason`))&&M(A(e,`NoMatchReason`))&&M(A(e,`CancellationReason`))}function P(e){if(!N(e))throw new t(`Unavailable`,`Speech is not available in this browser.`);return e}var F=null;function I(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(P(t)):(F===null&&(F=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>P(A(e,`SpeechConfig`)?e:A(e,`default`))).catch(e=>{throw F=null,e})),F)}function L(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function R(e){let n=e.getToken,r=e.loadSdk??I,i=e.getLanguage??L,a=typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,o=typeof window<`u`&&window.isSecureContext===!0,s=a&&o,c=typeof window<`u`,l=null,u=null,d=null;function f(){return l!==null&&Date.parse(l.expiresDateTimeUtc)-Date.now()>6e4?Promise.resolve(l):(u===null&&(u=Promise.resolve().then(()=>n()).then(e=>(l=e,u=null,e),e=>{throw u=null,k(e)})),u)}function p(){return d===null&&(d=Promise.resolve().then(()=>r()).then(e=>{if(!e?.SpeechConfig)throw new t(`Unavailable`,`Speech is not available in this browser.`);return e}).catch(e=>{throw d=null,k(e)})),d}function m(e={}){let{signal:n,onText:r,onEnd:a}=e;if(n?.aborted)return a?.(),Promise.resolve();let o=()=>{},c=()=>{},l=new Promise((e,t)=>{o=e,c=t}),u=!1,d=!1,m=null,h=!1,g=``,_=[],v,y,b,x=()=>{clearTimeout(v),clearTimeout(y),clearTimeout(b)},S=e=>{if(!u){u=!0,x(),n?.removeEventListener(`abort`,E);try{m?.close()}finally{try{a?.()}finally{e?c(e):o()}}}};async function E(){if(!(u||d)){d=!0,x();try{let e=m;e!==null&&await new Promise(t=>e.stopContinuousRecognitionAsync(()=>t(),()=>t()))}finally{S(null)}}}let D=()=>[..._,g].filter(e=>e!==``).join(` `).trim(),A=(e,t)=>{h||(h=!0,clearTimeout(v)),clearTimeout(y),y=setTimeout(E,w),r?.(D(),t)};async function j(){if(n?.addEventListener(`abort`,E),!s){S(new t(`Unavailable`,`Dictation is not available in this browser.`));return}let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){S(O(e));return}for(let e of r.getTracks())e.stop();if(!u)try{let n=await p(),r=await f();if(u)return;let a=n.SpeechConfig.fromAuthorizationToken(r.token,r.region);a.speechRecognitionLanguage=e.language||i(),a.setProperty(n.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,String(C));let o=new n.SpeechRecognizer(a,n.AudioConfig.fromDefaultMicrophoneInput());if(m=o,o.recognizing=(e,t)=>{if(u)return;let n=t.result?.text;n&&(g=n,A(n,!1))},o.recognized=(e,r)=>{if(u)return;let{reason:i,text:a}=r.result;i===n.ResultReason.RecognizedSpeech&&a?(_.push(a),g=``,A(a,!0)):i===n.ResultReason.NoMatch&&n.NoMatchDetails.fromResult(r.result).reason===n.NoMatchReason.InitialSilenceTimeout&&S(new t(`NoSpeech`,`No speech was heard.`))},o.canceled=(e,r)=>{u||(r.reason===n.CancellationReason.Error?S(new t(`Failed`,r.errorDetails)):S(null))},o.sessionStopped=()=>S(null),await new Promise((e,t)=>o.startContinuousRecognitionAsync(()=>e(),t)),u)return;e.onStarted?.(),v=setTimeout(()=>{h||S(new t(`NoSpeech`,`No speech was heard.`))},C),b=setTimeout(E,T)}catch(e){S(k(e))}}return j(),l}async function h(e,n={}){let{signal:r}=n;if(!r?.aborted)try{let a=await p(),o=await f();if(r?.aborted)return;let s=a.SpeechConfig.fromAuthorizationToken(o.token,o.region);s.speechSynthesisLanguage=n.language||i();let c=new a.SpeakerAudioDestination,l=new a.SpeechSynthesizer(s,a.AudioConfig.fromSpeakerOutput(c));await new Promise((n,i)=>{let o=!1,s=()=>{r?.removeEventListener(`abort`,f),l.close(),c.close()},u=()=>{o||(o=!0,s(),n())},d=e=>{o||(o=!0,s(),i(k(e)))};function f(){c.pause(),u()}r?.addEventListener(`abort`,f),c.onAudioEnd=u;try{l.speakTextAsync(e,e=>{e.reason!==a.ResultReason.SynthesizingAudioCompleted&&d(new t(`Failed`,`The reply could not be synthesised.`))},e=>d(e))}catch(e){d(e)}})}catch(e){throw k(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var z=6e4,B=60*z,ee=48*B;function V(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function H(e,t=Date.now(),n){let r=V(e);if(r===null)return``;let i=t-r,a=Math.abs(i),o=i>=0,s=new Intl.RelativeTimeFormat(n,{numeric:`auto`});if(a<z)return s.format(0,`second`);if(a<B){let e=Math.floor(a/z);return s.format(o?-e:e,`minute`)}if(a<ee){let e=Math.floor(a/B);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function te(e,t){let n=V(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var U=`data-wchat-printing`,W=`data-wchat-print-hide`,G=`data-wchat-print-path`,ne=`data-wchat-print-target`,re=/* @__PURE__ */ new Set([`script`,`style`,`link`,`template`]),K=null;function q(){if(K!==null){for(let e of K.marked)e.removeAttribute(W),e.removeAttribute(G),e.removeAttribute(ne);K.heading.remove(),document.documentElement.removeAttribute(U),window.removeEventListener(`afterprint`,K.onAfterPrint),K=null}}function ie(e,t,n,r,i){q();let a=e.querySelector(`.wui-chat-panel`);if(a===null)throw Error(`print needs the wui-chat root`);let o=[],s=a;for(;s!==null&&s!==document.documentElement;){s.setAttribute(G,``),o.push(s);let e=s.parentElement;if(e===null)throw Error(`print walk left the chat root`);for(let t of e.children)t===s||re.has(t.localName)||(t.setAttribute(W,``),o.push(t));s=e}for(let e of n)e.setAttribute(W,``),o.push(e);r!==null&&(r.setAttribute(ne,``),o.push(r));let c=document.createElement(`div`);c.className=`wui-chat-print-heading`;let l=document.createElement(`h1`);l.textContent=i.title;let u=document.createElement(`p`);u.textContent=i.printedOn,c.append(l,u),a.prepend(c),document.documentElement.setAttribute(U,t);let d=()=>q();window.addEventListener(`afterprint`,d,{once:!0}),K={marked:o,heading:c,onAfterPrint:d};try{window.print()}catch(e){throw q(),e}}function ae(e,t){ie(e,`conversation`,[],null,t)}function oe(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);ie(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function se(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function ce({title:e,text:t}){if(!se())return`failed`;try{return await navigator.share({title:e,text:t}),`shared`}catch(e){return typeof e==`object`&&e&&`name`in e&&e.name===`AbortError`?`cancelled`:`failed`}}var le=`wchat:auto-opened`,ue=`wchat:dismissed`,de=`button, a[href], input, select, textarea`,fe=`input, textarea`;function J(e){return!e.closest(`.wui-chat`)}function pe(e){return e instanceof Element&&e.matches(fe)&&J(e)}function me(){return[...document.querySelectorAll(fe)].some(e=>J(e)&&e.value!==e.defaultValue)}function he(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function ge(e){return e?[...document.querySelectorAll(de)].some(t=>{if(!J(t))return!1;let n=t.getBoundingClientRect();return n.width===0||n.height===0?!1:n.left<e.right&&n.right>e.left&&n.top<e.bottom&&n.bottom>e.top}):!1}function _e(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(le)||e.rememberDismissal&&sessionStorage.getItem(ue)||window.innerWidth<e.skipBelowWidthPx)return!0;let r=window.location.pathname;if(e.skipPathPrefixes.some(e=>r.startsWith(e)))return!0;let i=t.avoid.autoOpenOptOutSelector;return i&&document.querySelector(i)||e.skipWhenFormTouched&&me()||n.isOpen()?!0:e.skipWhenCoversControl&&ge(n.panelRect())}function ve(e){return pe(document.activeElement)||he(e.avoid.menuSelectors)||he(e.avoid.autoOpenBusySelectors)}function ye(e,t,n){let r;function i(){r=void 0,_e(e,t,n)||(ve(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(le,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var be=.4,xe=20;function Y(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Se(e){let t=e.match(/[\d.]+/g);if(!t||t.length<3)return null;let[n=0,r=0,i=0]=t.slice(0,3).map(Number);return{r:n,g:r,b:i,alpha:t.length>3?Number(t[3])/(e.includes(`%`)?100:1):1}}function Ce({r:e,g:t,b:n}){return .2126*Y(e)+.7152*Y(t)+.0722*Y(n)}function we(e,t){let n=e.getBoundingClientRect(),r=document.elementsFromPoint?.(n.left+n.width/2,n.top+n.height/2)??[],i=t.length?t.join(`,`):null;for(let t of r){if(e.contains(t))continue;if(i&&t.closest(i))return!0;let n=Se(getComputedStyle(t).backgroundColor);if(n&&n.alpha>0)return Ce(n)<be}return!1}function Te(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function Ee(e){let t=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&(t=Math.max(t,window.innerHeight-e.top))}return t>0?t+xe:0}function De(e){if(e.length===0)return!1;for(let t of document.querySelectorAll(e.join(`,`))){let e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return!0}return!1}function Oe(e,t,n){let r=n.ownerDocument.documentElement,i=0,a=!1,o=null;function s(){i=0;let s=t.liftAboveFooter?Te(e.liftSelectors):[];if(o)for(let e of s)o.observe(e);n.style.setProperty(`--wui-chat-lift`,`${Ee(s)}px`);let c=n.getBoundingClientRect(),l=c.height===0?0:Math.round(window.innerHeight-c.top);r.style.setProperty(`--wui-chat-launcher-block`,`${l}px`);let u=t.stepAsideForMenus&&De(e.menuSelectors);u&&!a?(n.dataset.launcher=`hidden`,n.inert=!0,a=!0):!u&&a&&(n.dataset.launcher=`idle`,n.inert=!1,a=!1);let d=t.switchOnDark&&we(n,e.darkSelectors);d&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!d&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function c(){i||=requestAnimationFrame(s)}typeof ResizeObserver==`function`&&(o=new ResizeObserver(c));let l=new MutationObserver(c);return l.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,c,{capture:!0,passive:!0}),window.addEventListener(`resize`,c),window.addEventListener(`load`,c),n.addEventListener(`animationend`,c),c(),{destroy(){i&&cancelAnimationFrame(i),i=0,o?.disconnect(),l.disconnect(),document.removeEventListener(`scroll`,c,{capture:!0}),window.removeEventListener(`resize`,c),window.removeEventListener(`load`,c),n.removeEventListener(`animationend`,c),a&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),r.style.removeProperty(`--wui-chat-launcher-block`)}}}var X=`wchat:session-start`,ke=`wchat:pages`,Ae=`wchat:services`;function je(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function Me(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function Ne(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function Pe(e){sessionStorage.getItem(X)||sessionStorage.setItem(X,String(Date.now()));let t=0;function n(){let e=document.documentElement.scrollHeight;if(e<=0)return;let n=(window.scrollY+window.innerHeight)/e*100;n>t&&(t=n)}return window.addEventListener(`scroll`,n,{passive:!0}),function(){n();let r=window.location.pathname,i=je(ke);i.includes(r)||(i.push(r),Me(ke,i));let a=Ne(r,e),o=je(Ae);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),Me(Ae,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(X)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var Z=8,Fe=`(min-width: 992px)`,Ie=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,Le=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Re=0;function ze(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function Be(e){let{trigger:t,request:i,isEmpty:a,renderAnswer:o,renderFooter:s,session:c,timings:l,onStateChange:u,returnFocusTo:f}=e??{};if(!(t instanceof HTMLElement))throw TypeError(`createExplainPopover needs a "trigger" element.`);if(typeof i!=`function`)throw TypeError(`createExplainPopover needs a "request" function.`);if(typeof o!=`function`)throw TypeError(`createExplainPopover needs a "renderAnswer" function.`);Re+=1;let p=e.title??``,g=e.showNotCounted??!0,_=`wui-chat-explain-${Re}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:H}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(Le.map(e=>[e,t.getAttribute(e)])),S=t.hidden,C;t.setAttribute(`aria-haspopup`,`dialog`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,_);let w=null,T=null,E=null,D,O=null,k=[],A=[],j=()=>c?.getState().features.Explain===!1;function M(){b.getSnapshot().offline?(C===void 0&&(C=t.getAttribute(`title`)),t.setAttribute(`title`,v().explainOffline),t.setAttribute(`aria-disabled`,`true`),t.setAttribute(`data-offline`,``)):(C!==void 0&&ze(t,`title`,C),C=void 0,t.removeAttribute(`aria-disabled`),t.removeAttribute(`data-offline`)),c&&(t.hidden=j())}function N(e){if(T?.replaceChildren(),e.pillVisible){let t=d(`span`,`wui-chat-explain-pill`),n=d(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=d(`span`);r.textContent=e.state===`slow`?v().explainSlow:v().thinking,t.append(n,r);let i=d(`div`,`wui-chat-explain-thinking`,{role:`status`});i.append(t),T?.append(i)}else if(e.state===`answered`){e.answer!==D&&(E=o(e.answer,y())??null,D=e.answer);let t=d(`div`,`wui-chat-explain-answer`);E&&t.append(E),T?.append(t)}else if(e.state===`empty`){let e=d(`p`,`wui-chat-explain-text`);e.textContent=v().explainEmpty,T?.append(e)}else if(e.state===`capacity`){let t=d(`div`,`wui-chat-explain-alert wui-chat-explain-alert--warning`,{role:`status`}),n=d(`p`);n.textContent=e.resetsDateTimeUtc?v().explainCapacity(te(e.resetsDateTimeUtc)):v().explainCapacityNoDate,t.append(n),T?.append(t)}else if(e.state===`error`){let e=d(`div`,`wui-chat-explain-alert wui-chat-explain-alert--error`,{role:`alert`}),t=d(`p`);t.textContent=v().explainError,e.append(t,m(`ghost`,v().retry,`rotate-ccw`,()=>b.ask())),T?.append(e)}}function P(){let e=w?.querySelector(`.wui-chat-explain-foot`);e?.replaceChildren();let t=s?.(y());if(t&&e?.append(t),g){let t=d(`p`,`wui-chat-explain-note`);t.textContent=v().explainNotCounted,e?.append(t)}}function F(){if(!w)return;let e=b.getSnapshot();w.dataset.state=e.state,N(e),P(),u?.(e)}function I(){if(!w)return;if(!t.isConnected){H({restoreFocus:!1});return}let e=document.documentElement.getAttribute(`data-wchat-docked`);if((e===`end`||e===`start`)&&globalThis.matchMedia?.(Fe)?.matches===!0){w.dataset.beside=e,w.style.left=``,w.style.top=``,w.style.maxHeight=``;return}delete w.dataset.beside,w.style.position=`fixed`;let n=t.getBoundingClientRect(),r=w.offsetWidth,i=w.offsetHeight,a=globalThis.innerHeight-n.bottom-Z,o=a<i&&n.top>a,s=o?n.top-Z:a,c=o?Math.max(Z,n.top-i-Z):n.bottom+Z,l=Math.max(Z,Math.min(n.left,globalThis.innerWidth-r-Z));w.style.top=`${c}px`,w.style.left=`${l}px`,w.style.maxHeight=s<i?`${Math.max(0,s)}px`:``}function L(e){e.key===`Escape`&&(document.documentElement.hasAttribute(`data-wchat-docked`)||(e.stopPropagation(),H()))}function R(e){let n=e.target;n instanceof Node&&(w?.contains(n)||t.contains(n))||n instanceof Element&&n.closest(`.wui-chat-panel`)||H({restoreFocus:!1})}function z(e){e.target instanceof Node&&w?.contains(e.target)||I()}function B(){b.getSnapshot().offline||U()}function ee(){for(let[e,t,n,r]of k)e.removeEventListener(t,n,r);k=[];for(let e of A)e.disconnect();A=[]}function V(){if(w||j()||b.getSnapshot().offline)return;w=d(`div`,`wui-chat-explain`,{role:`dialog`,"aria-label":p,popover:`manual`,id:_});let e=d(`header`,`wui-chat-explain-head`),n=d(`strong`,`wui-chat-explain-title`);n.textContent=p,O=h(v().close,`x`,()=>H()),O.classList.add(`wui-chat-explain-close`),e.append(n,O),T=d(`div`,`wui-chat-explain-body`,{"aria-live":`polite`}),w.append(e,T,d(`div`,`wui-chat-explain-foot`)),w.dataset.state=b.getSnapshot().state,document.body.append(w),w.showPopover?.(),t.setAttribute(`aria-expanded`,`true`),b.ask(),I(),(w.querySelector(Ie)??O).focus({preventScroll:!0}),k=[[document,`keydown`,L,!0],[document,`pointerdown`,R,!0],[window,`resize`,I,!1],[document,`scroll`,z,!0]];for(let[e,t,n,r]of k)e.addEventListener(t,n,r);if(typeof ResizeObserver==`function`){let e=new ResizeObserver(()=>I());e.observe(w),A.push(e)}let r=new MutationObserver(()=>I());r.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-wchat-docked`]}),A.push(r)}function H(e={restoreFocus:!0}){w&&(b.reset(),ee(),w.remove(),w=null,T=null,E=null,D=void 0,O=null,t.setAttribute(`aria-expanded`,`false`),M(),e?.restoreFocus!==!1&&(f?.()??t).focus({preventScroll:!0}))}function U(){w?H():V()}let W=b.subscribe(()=>{M(),b.getSnapshot().offline&&w?H():F()}),G=c?.subscribe(()=>{M(),j()&&w&&H({restoreFocus:!1})});return t.addEventListener(`click`,B),M(),{open:V,close:H,toggle:U,isOpen:()=>w!==null,destroy(){H({restoreFocus:!1}),W(),G?.(),b.dispose(),t.removeEventListener(`click`,B);for(let e of Le)ze(t,e,x[e]);t.hidden=S}}}var Ve=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function He(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(Ve)].filter(e=>e.tabIndex>=0&&!e.hidden),r=n[0],i=n[n.length-1];if(!r||!i){t.preventDefault();return}let a=e.ownerDocument.activeElement,o=e.contains(a);t.shiftKey?o&&a!==r||(t.preventDefault(),i.focus()):o&&a!==i||(t.preventDefault(),r.focus())}function Ue(e){e?.isConnected&&e.focus()}function We(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var Ge=`wui-chat-lock`,Q=`wui-chat-scroll-lock`;function Ke(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(Ge);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(Q,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(Ge);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(Q,{detail:{locked:!1}}))}}}var qe={open:{from:420,to:920,seconds:.16,peak:.16},reply:{from:680,to:540,seconds:.11,peak:.06},sent:{from:540,to:760,seconds:.09,peak:.05}},Je=[`pointerdown`,`keydown`,`touchstart`],Ye=`wchat:muted`,Xe=1e-4;function Ze(e,t){let n=t.get(Ye)===`1`,r=null;function i(){for(let e of Je)document.removeEventListener(e,a)}function a(){let e=globalThis.AudioContext||globalThis.webkitAudioContext;!r&&e&&(r=new e),r?.state===`suspended`&&r.resume().catch(e=>globalThis.reportError?.(e)),i()}for(let e of Je)document.addEventListener(e,a);return{play(t){let i=qe[t];if(!i||n||!r||!e[t]||!(e.volume>0))return;let a=r.currentTime,o=r.createOscillator(),s=r.createGain();o.type=`sine`,o.frequency.setValueAtTime(i.from,a),o.frequency.linearRampToValueAtTime(i.to,a+i.seconds),s.gain.setValueAtTime(i.peak*e.volume,a),s.gain.exponentialRampToValueAtTime(Xe,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(Ye,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function Qe(e,t={}){let n=t.language;return R({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var $e=2e3,et=500,tt=32,$=16,nt=`data-wchat-switching`;function rt(e){return new Promise(t=>setTimeout(t,e))}function it(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=$,setTimeout(i,$))};setTimeout(i,$)})}async function at(e,t={}){let n=t.reduced??globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches===!0;if(typeof document.startViewTransition!=`function`||n){await e();return}let r=document.documentElement;r.setAttribute(nt,``);try{let n=()=>!t.target||document.querySelector(`.wui-chat--${t.target}`)!==null,r=()=>(typeof t.pageReady!=`function`||t.pageReady())&&n(),i=document.startViewTransition(async()=>{await e(),await it(t.routeReady,$e),await it(r,et),await rt(tt)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(nt)}}var ot=100,st=12,ct=220,lt=640;function ut(e,t){let n=t.phone.mode===`Sheet`,r=window.visualViewport,i;function a(){e.style.removeProperty(`bottom`),e.style.removeProperty(`max-height`)}function o(){if(i=void 0,window.innerWidth>t.phone.maxWidthPx){a();return}if(!r)return;let o=Math.max(0,window.innerHeight-r.height-r.offsetTop),s=r.height-st;n&&(s=Math.min(lt,Math.max(ct,s))),e.style.bottom=`${o}px`,e.style.maxHeight=`${s}px`}function s(){clearTimeout(i),i=setTimeout(o,ot)}return r?.addEventListener(`resize`,s),r?.addEventListener(`scroll`,s),window.addEventListener(`resize`,s),window.addEventListener(`orientationchange`,s),o(),{destroy(){clearTimeout(i),r?.removeEventListener(`resize`,s),r?.removeEventListener(`scroll`,s),window.removeEventListener(`resize`,s),window.removeEventListener(`orientationchange`,s),a()}}}export{f as A,O as C,d as D,S as E,m as M,o as N,u as O,s as P,R as S,p as T,ae as _,Ze as a,H as b,Ue as c,Pe as d,Oe as f,q as g,ce as h,Qe as i,g as j,h as k,He as l,se as m,ut as n,Ke as o,ye as p,at as r,We as s,e as t,Be as u,oe as v,y as w,t as x,te as y};
|
package/dist/web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as ChatSpeechError,m as canShareText,f as createAvoidance,S as createAzureSpeech,d as createBehaviourCollector,u as createExplainPopover,a as createSound,i as createWebSpeech,g as endPrint,n as fitToViewport,y as fullMoment,
|
|
1
|
+
export{t as ChatSpeechError,m as canShareText,f as createAvoidance,S as createAzureSpeech,d as createBehaviourCollector,u as createExplainPopover,a as createSound,i as createWebSpeech,g as endPrint,n as fitToViewport,y as fullMoment,N as growFromButton,o as lockPageScroll,C as microphoneError,_ as printConversation,v as printReply,b as relativeMoment,c as returnFocus,h as shareText,r as switchPanel,l as trapTab,s as vibrate,p as watchAutoOpen,P as watchReducedMotion}from"./web-CEXzR2DU.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/chat-elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.152.0",
|
|
4
4
|
"description": "The Webority Chat web elements: the <wui-chat> custom element and one custom element per message part kind, the chat styles on @webority/theme tokens, and the global bundle that Razor pages load.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"type": "module",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./src/renderers/*.ts"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@webority/chat-core": "0.
|
|
43
|
+
"@webority/chat-core": "0.152.0",
|
|
44
44
|
"@webority/markdown-core": "^0.174.0",
|
|
45
45
|
"@webority/theme": "^0.174.0",
|
|
46
46
|
"@webority/ui-elements": "^0.174.0",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@webority/chat-core": "0.
|
|
56
|
-
"@webority/theme": "0.174.
|
|
57
|
-
"@webority/ui-elements": "0.174.
|
|
55
|
+
"@webority/chat-core": "0.152.0",
|
|
56
|
+
"@webority/theme": "0.174.1",
|
|
57
|
+
"@webority/ui-elements": "0.174.1",
|
|
58
58
|
"@vitest/coverage-v8": "5.1.0",
|
|
59
59
|
"bootstrap": "5.3.9",
|
|
60
60
|
"jsdom": "30.1.1",
|
package/dist/web-CWwNklk-.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ChatSpeechError as e,ChatSpeechError as t,createExplain as n,mergeLabels as r}from"@webority/chat-core";import{glyphNode as i}from"@webority/ui-elements/helpers";var a=`(prefers-reduced-motion: reduce)`;function o(e,t){let n=e.style.animation;e.style.animation=`none`;let r=e.getBoundingClientRect();e.style.animation=n,e.style.transformOrigin=`${t.left+t.width/2-r.left}px ${t.top+t.height/2-r.top}px`}function s(e,t){let n=typeof window.matchMedia==`function`?window.matchMedia(a):null,r=/* @__PURE__ */ new Set,i=()=>e.motion===`Reduced`||t?.motion===!1||n?.matches===!0,o=i();function s(){let e=i();if(e!==o){o=e;for(let e of r)e(o)}}return n?.addEventListener(`change`,s),{get reduced(){return o},subscribe(e){return r.add(e),()=>{r.delete(e)}},destroy(){n?.removeEventListener(`change`,s),r.clear()}}}var c=`AppButton`,l={primary:`btn-primary`,secondary:`btn-soft-primary`,ghost:`btn-ghost-primary`,outline:`btn-outline-primary`,neutral:`btn-soft-neutral`,danger:`btn-danger`};function u(e,t,n){let r=document.createElement(e);if(t&&(r.className=t),n)for(let[e,t]of Object.entries(n))t!=null&&r.setAttribute(e,t);return r}function d(e,t=16){return i(e,{size:t})??u(`span`,`d-inline-flex`)}function f(e=`primary`,t=`md`){if(!Object.hasOwn(l,e))throw Error(`Unknown button variant "${e}". Use one of ${Object.keys(l).join(`, `)}.`);return`btn ${l[e]}${t===`sm`?` btn-sm`:``}`}function p(e,t,n,r){let i=u(`button`,`${f(e,`sm`)} wui-chat-action-btn`,{type:`button`});return i.dataset.wui=c,n&&i.append(d(n,14)),i.append(document.createTextNode(t)),i.addEventListener(`click`,r),i}function m(e,t,n){let r=u(`button`,`wui-chat-icon-btn`,{type:`button`,"aria-label":e,title:e});return r.append(d(t,20)),r.addEventListener(`click`,n),r}function h(e,t){let n=e.getAttribute(t);if(n!=null&&n!==``)try{return JSON.parse(n)}catch{throw Error(`<wui-chat ${t}> must be valid JSON.`)}}function g(e){let t;return n=>{let r=e.dataset.state;if((!n||r!==`open`&&r!==`opening`)&&(n||r!==`closed`&&r!==`closing`)){if(clearTimeout(t),n)e.dataset.state=`opening`,t=setTimeout(()=>{e.dataset.state=`open`},620);else{e.dataset.state=`closing`;let n=e.classList.contains(`wui-chat--panel-motion-none`)?0:300;t=setTimeout(()=>{e.dataset.state=`closed`},n)}}}}function _(e,t){t.position!==void 0&&(e.classList.toggle(`wui-chat--end`,t.position===`end`),e.classList.toggle(`wui-chat--start`,t.position===`start`)),t.reduced!==void 0&&e.classList.toggle(`wui-chat--reduced`,!!t.reduced),t.expressive!==void 0&&e.classList.toggle(`wui-chat--expressive`,t.expressive===!0),t.sendReveal!==void 0&&e.classList.toggle(`wui-chat--send-always`,t.sendReveal===`Always`),t.inputRing!==void 0&&e.classList.toggle(`wui-chat--input-ring-off`,t.inputRing===!1),t.panelMotion!==void 0&&(e.classList.toggle(`wui-chat--panel-motion-gentle`,t.panelMotion===`Gentle`),e.classList.toggle(`wui-chat--panel-motion-none`,t.panelMotion===`None`)),t.offsetX!==void 0&&e.style.setProperty(`--wui-chat-offset-x`,`${t.offsetX}px`),t.offsetY!==void 0&&e.style.setProperty(`--wui-chat-offset-y`,`${t.offsetY}px`),t.width!==void 0&&e.style.setProperty(`--wui-chat-width`,t.width),t.maxHeight!==void 0&&e.style.setProperty(`--wui-chat-panel-max-height`,`${t.maxHeight}px`),t.bottomGap!==void 0&&e.style.setProperty(`--wui-chat-bottom-gap`,`${t.bottomGap}px`),t.panelHeight!==void 0&&e.classList.toggle(`wui-chat--panel-height-content`,t.panelHeight===`Content`),t.avatar!==void 0&&(t.avatar?(e.style.setProperty(`--wui-chat-avatar`,`url(${JSON.stringify(t.avatar)})`),e.style.setProperty(`--wui-chat-typing-mark`,`url(${JSON.stringify(t.avatar)})`)):(e.style.removeProperty(`--wui-chat-avatar`),e.style.removeProperty(`--wui-chat-typing-mark`))),t.replyAvatars!==void 0&&e.classList.toggle(`wui-chat--reply-avatars-off`,t.replyAvatars===!1)}var v=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],y={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function b(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function x({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a}){let s=u(`div`,`wui-chat ${y[t]} wui-chat--${n}`),c=u(`section`,`wui-chat-panel`,{id:e,role:r}),l=i?g(s):null;s.dataset.state=i?`closed`:`open`;let f=null,p=null,m=null,h=null,v=null,x=null,S=null,C=`round`,w=!1,T=`bubble`,E=null,D=null,O=!1,k=`icon`,A=!1;function j(){if(!f)return;let e=f.dataset.launcher,t=[`wui-chat-launcher-wrap`];e===`entering`&&E&&t.push(`wui-chat-launcher--entrance-${E}`),e===`idle`&&D&&D!==`none`&&(D!==`ring`||C===`pill`)&&t.push(`wui-chat-launcher--idle-${D}`),f.className=t.join(` `)}function M(){if(!p)return;let e=[...p.classList].filter(e=>e.endsWith(`--opening`)||e.endsWith(`--closing`)),t=[`wui-chat-launcher`,`wui-chat-launcher--${C}`];C===`pill`&&w&&t.push(`wui-chat-launcher--compact`),k!==`icon`&&t.push(`wui-chat-launcher--mark-${k}`),t.push(`wui-chat-launcher--reveal-${T}`,...e),p.className=t.join(` `)}function N(){v&&x&&(v.textContent=S||x.launcher)}function P(){if(!p||!h||!x)return;let e=A?x.launcherClose:S||x.launcher;p.setAttribute(`aria-label`,e),h.textContent=e}if(i){let t=u(`div`,`wui-chat-launcher-wrap`);f=t,t.dataset.launcher=`idle`;let n=u(`button`,`wui-chat-launcher`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-controls":e});p=n;let r=u(`span`,`wui-chat-launcher-icon`,{"aria-hidden":`true`});m=r,r.append(d(`chat`,24));let i=u(`span`,`wui-chat-launcher-close`,{"aria-hidden":`true`});i.append(d(`x`,24));let o=u(`span`,`wui-chat-launcher-label`);h=o,n.append(r,i,o),n.addEventListener(`click`,()=>a()),n.addEventListener(`animationend`,e=>{e.target===n&&n.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`)});let l=u(`span`,`wui-chat-launcher-bubble`,{"aria-hidden":`true`});v=l,t.append(n,l),t.addEventListener(`animationend`,e=>{e.target===t&&t.dataset.launcher===`entering`&&(t.dataset.launcher=`idle`,j())}),M(),j(),s.append(t,c)}else s.append(c);function F(e){if(!l)return;let t=e&&!A&&p!==null&&p?p.getBoundingClientRect():null;e!==A&&p&&(p.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`),p.classList.add(e?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`)),A=e,l(e),t&&o(c,t),p&&(p.setAttribute(`aria-expanded`,String(e)),P())}function I(e){x=e,p&&(P(),N())}function L(e){if(_(s,e),e.theme!==void 0&&(e.theme===`light`||e.theme===`dark`?s.dataset.theme=e.theme:delete s.dataset.theme),!p||!f||!m)return;e.launcherStyle!==void 0&&(C=e.launcherStyle===`Pill`?`pill`:`round`),e.compact!==void 0&&(w=e.compact),e.labelReveal!==void 0&&(T=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(E=e.entrance===`None`?null:b(e.entrance)),e.idle!==void 0&&(D=e.idle===`None`?`none`:b(e.idle)),e.phone!==void 0&&(O=e.phone),e.hoverLabel!==void 0&&(S=e.hoverLabel||null),e.launcherMark!==void 0&&(k=b(e.launcherMark)),e.icon!==void 0&&e.icon!==m.dataset.icon&&(m.dataset.icon=e.icon,m.replaceChildren(d(e.icon,24)));let t=e.launcherState??f.dataset.launcher;O&&t===`entering`&&(t=`idle`),t===`entering`&&!E&&(t=`idle`),f.dataset.launcher=t,M(),j(),N(),P()}return{root:s,panel:c,setOpen:F,setLabels:I,setAppearance:L,nudgeHost:f,launcherButton:p,role:r}}var S=1e4,C=2e3,w=3e5,T=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),E=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function D(e){return T.has(k(e,`name`))?new t(`Blocked`,A(e)):E.has(k(e,`name`))?new t(`NoMicrophone`,A(e)):O(e)}function O(e){return e instanceof t?e:new t(`Failed`,A(e)??String(e))}function k(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function A(e){let t=k(e,`message`);return t==null?void 0:String(t)}function j(e){return typeof e==`object`&&!!e}function M(e){let t=k(e,`SpeechConfig`),n=k(e,`AudioConfig`),r=k(e,`NoMatchDetails`);return typeof k(t,`fromAuthorizationToken`)==`function`&&typeof k(n,`fromDefaultMicrophoneInput`)==`function`&&typeof k(n,`fromSpeakerOutput`)==`function`&&typeof k(r,`fromResult`)==`function`&&typeof k(e,`SpeechRecognizer`)==`function`&&typeof k(e,`SpeakerAudioDestination`)==`function`&&typeof k(e,`SpeechSynthesizer`)==`function`&&j(k(e,`PropertyId`))&&j(k(e,`ResultReason`))&&j(k(e,`NoMatchReason`))&&j(k(e,`CancellationReason`))}function N(e){if(!M(e))throw new t(`Unavailable`,`Speech is not available in this browser.`);return e}var P=null;function F(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(N(t)):(P===null&&(P=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>N(k(e,`SpeechConfig`)?e:k(e,`default`))).catch(e=>{throw P=null,e})),P)}function I(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function L(e){let n=e.getToken,r=e.loadSdk??F,i=e.getLanguage??I,a=typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,o=typeof window<`u`&&window.isSecureContext===!0,s=a&&o,c=typeof window<`u`,l=null,u=null,d=null;function f(){return l!==null&&Date.parse(l.expiresDateTimeUtc)-Date.now()>6e4?Promise.resolve(l):(u===null&&(u=Promise.resolve().then(()=>n()).then(e=>(l=e,u=null,e),e=>{throw u=null,O(e)})),u)}function p(){return d===null&&(d=Promise.resolve().then(()=>r()).then(e=>{if(!e?.SpeechConfig)throw new t(`Unavailable`,`Speech is not available in this browser.`);return e}).catch(e=>{throw d=null,O(e)})),d}function m(e={}){let{signal:n,onText:r,onEnd:a}=e;if(n?.aborted)return a?.(),Promise.resolve();let o=()=>{},c=()=>{},l=new Promise((e,t)=>{o=e,c=t}),u=!1,d=!1,m=null,h=!1,g=``,_=[],v,y,b,x=()=>{clearTimeout(v),clearTimeout(y),clearTimeout(b)},T=e=>{if(!u){u=!0,x(),n?.removeEventListener(`abort`,E);try{m?.close()}finally{try{a?.()}finally{e?c(e):o()}}}};async function E(){if(!(u||d)){d=!0,x();try{let e=m;e!==null&&await new Promise(t=>e.stopContinuousRecognitionAsync(()=>t(),()=>t()))}finally{T(null)}}}let k=()=>[..._,g].filter(e=>e!==``).join(` `).trim(),A=(e,t)=>{h||(h=!0,clearTimeout(v)),clearTimeout(y),y=setTimeout(E,C),r?.(k(),t)};async function j(){if(n?.addEventListener(`abort`,E),!s){T(new t(`Unavailable`,`Dictation is not available in this browser.`));return}let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){T(D(e));return}for(let e of r.getTracks())e.stop();if(!u)try{let n=await p(),r=await f();if(u)return;let a=n.SpeechConfig.fromAuthorizationToken(r.token,r.region);a.speechRecognitionLanguage=e.language||i(),a.setProperty(n.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,String(S));let o=new n.SpeechRecognizer(a,n.AudioConfig.fromDefaultMicrophoneInput());if(m=o,o.recognizing=(e,t)=>{if(u)return;let n=t.result?.text;n&&(g=n,A(n,!1))},o.recognized=(e,r)=>{if(u)return;let{reason:i,text:a}=r.result;i===n.ResultReason.RecognizedSpeech&&a?(_.push(a),g=``,A(a,!0)):i===n.ResultReason.NoMatch&&n.NoMatchDetails.fromResult(r.result).reason===n.NoMatchReason.InitialSilenceTimeout&&T(new t(`NoSpeech`,`No speech was heard.`))},o.canceled=(e,r)=>{u||(r.reason===n.CancellationReason.Error?T(new t(`Failed`,r.errorDetails)):T(null))},o.sessionStopped=()=>T(null),await new Promise((e,t)=>o.startContinuousRecognitionAsync(()=>e(),t)),u)return;e.onStarted?.(),v=setTimeout(()=>{h||T(new t(`NoSpeech`,`No speech was heard.`))},S),b=setTimeout(E,w)}catch(e){T(O(e))}}return j(),l}async function h(e,n={}){let{signal:r}=n;if(!r?.aborted)try{let a=await p(),o=await f();if(r?.aborted)return;let s=a.SpeechConfig.fromAuthorizationToken(o.token,o.region);s.speechSynthesisLanguage=n.language||i();let c=new a.SpeakerAudioDestination,l=new a.SpeechSynthesizer(s,a.AudioConfig.fromSpeakerOutput(c));await new Promise((n,i)=>{let o=!1,s=()=>{r?.removeEventListener(`abort`,f),l.close(),c.close()},u=()=>{o||(o=!0,s(),n())},d=e=>{o||(o=!0,s(),i(O(e)))};function f(){c.pause(),u()}r?.addEventListener(`abort`,f),c.onAudioEnd=u;try{l.speakTextAsync(e,e=>{e.reason!==a.ResultReason.SynthesizingAudioCompleted&&d(new t(`Failed`,`The reply could not be synthesised.`))},e=>d(e))}catch(e){d(e)}})}catch(e){throw O(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var R=6e4,z=60*R,B=48*z;function V(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function H(e,t=Date.now(),n){let r=V(e);if(r===null)return``;let i=t-r,a=Math.abs(i),o=i>=0,s=new Intl.RelativeTimeFormat(n,{numeric:`auto`});if(a<R)return s.format(0,`second`);if(a<z){let e=Math.floor(a/R);return s.format(o?-e:e,`minute`)}if(a<B){let e=Math.floor(a/z);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function ee(e,t){let n=V(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var U=`data-wchat-printing`,W=`data-wchat-print-hide`,G=`data-wchat-print-path`,K=`data-wchat-print-target`,te=/* @__PURE__ */ new Set([`script`,`style`,`link`,`template`]),q=null;function J(){if(q!==null){for(let e of q.marked)e.removeAttribute(W),e.removeAttribute(G),e.removeAttribute(K);q.heading.remove(),document.documentElement.removeAttribute(U),window.removeEventListener(`afterprint`,q.onAfterPrint),q=null}}function ne(e,t,n,r,i){J();let a=e.querySelector(`.wui-chat-panel`);if(a===null)throw Error(`print needs the wui-chat root`);let o=[],s=a;for(;s!==null&&s!==document.documentElement;){s.setAttribute(G,``),o.push(s);let e=s.parentElement;if(e===null)throw Error(`print walk left the chat root`);for(let t of e.children)t===s||te.has(t.localName)||(t.setAttribute(W,``),o.push(t));s=e}for(let e of n)e.setAttribute(W,``),o.push(e);r!==null&&(r.setAttribute(K,``),o.push(r));let c=document.createElement(`div`);c.className=`wui-chat-print-heading`;let l=document.createElement(`h1`);l.textContent=i.title;let u=document.createElement(`p`);u.textContent=i.printedOn,c.append(l,u),a.prepend(c),document.documentElement.setAttribute(U,t);let d=()=>J();window.addEventListener(`afterprint`,d,{once:!0}),q={marked:o,heading:c,onAfterPrint:d};try{window.print()}catch(e){throw J(),e}}function re(e,t){ne(e,`conversation`,[],null,t)}function ie(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);ne(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function ae(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function oe({title:e,text:t}){if(!ae())return`failed`;try{return await navigator.share({title:e,text:t}),`shared`}catch(e){return typeof e==`object`&&e&&`name`in e&&e.name===`AbortError`?`cancelled`:`failed`}}var se=`wchat:auto-opened`,ce=`wchat:dismissed`,le=`button, a[href], input, select, textarea`,ue=`input, textarea`;function Y(e){return!e.closest(`.wui-chat`)}function de(e){return e instanceof Element&&e.matches(ue)&&Y(e)}function fe(){return[...document.querySelectorAll(ue)].some(e=>Y(e)&&e.value!==e.defaultValue)}function pe(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function me(e){return e?[...document.querySelectorAll(le)].some(t=>{if(!Y(t))return!1;let n=t.getBoundingClientRect();return n.width===0||n.height===0?!1:n.left<e.right&&n.right>e.left&&n.top<e.bottom&&n.bottom>e.top}):!1}function he(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(se)||e.rememberDismissal&&sessionStorage.getItem(ce)||window.innerWidth<e.skipBelowWidthPx)return!0;let r=window.location.pathname;if(e.skipPathPrefixes.some(e=>r.startsWith(e)))return!0;let i=t.avoid.autoOpenOptOutSelector;return i&&document.querySelector(i)||e.skipWhenFormTouched&&fe()||n.isOpen()?!0:e.skipWhenCoversControl&&me(n.panelRect())}function ge(e){return de(document.activeElement)||pe(e.avoid.menuSelectors)||pe(e.avoid.autoOpenBusySelectors)}function _e(e,t,n){let r;function i(){r=void 0,he(e,t,n)||(ge(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(se,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var ve=.4,ye=20;function X(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function be(e){let t=e.match(/[\d.]+/g);if(!t||t.length<3)return null;let[n=0,r=0,i=0]=t.slice(0,3).map(Number);return{r:n,g:r,b:i,alpha:t.length>3?Number(t[3])/(e.includes(`%`)?100:1):1}}function xe({r:e,g:t,b:n}){return .2126*X(e)+.7152*X(t)+.0722*X(n)}function Se(e,t){let n=e.getBoundingClientRect(),r=document.elementsFromPoint?.(n.left+n.width/2,n.top+n.height/2)??[],i=t.length?t.join(`,`):null;for(let t of r){if(e.contains(t))continue;if(i&&t.closest(i))return!0;let n=be(getComputedStyle(t).backgroundColor);if(n&&n.alpha>0)return xe(n)<ve}return!1}function Ce(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function we(e){let t=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&(t=Math.max(t,window.innerHeight-e.top))}return t>0?t+ye:0}function Te(e){if(e.length===0)return!1;for(let t of document.querySelectorAll(e.join(`,`))){let e=t.getBoundingClientRect();if(e.width>0&&e.height>0)return!0}return!1}function Ee(e,t,n){let r=n.ownerDocument.documentElement,i=0,a=!1,o=null;function s(){i=0;let s=t.liftAboveFooter?Ce(e.liftSelectors):[];if(o)for(let e of s)o.observe(e);n.style.setProperty(`--wui-chat-lift`,`${we(s)}px`);let c=n.getBoundingClientRect(),l=c.height===0?0:Math.round(window.innerHeight-c.top);r.style.setProperty(`--wui-chat-launcher-block`,`${l}px`);let u=t.stepAsideForMenus&&Te(e.menuSelectors);u&&!a?(n.dataset.launcher=`hidden`,n.inert=!0,a=!0):!u&&a&&(n.dataset.launcher=`idle`,n.inert=!1,a=!1);let d=t.switchOnDark&&Se(n,e.darkSelectors);d&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!d&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function c(){i||=requestAnimationFrame(s)}typeof ResizeObserver==`function`&&(o=new ResizeObserver(c));let l=new MutationObserver(c);return l.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,c,{capture:!0,passive:!0}),window.addEventListener(`resize`,c),window.addEventListener(`load`,c),n.addEventListener(`animationend`,c),c(),{destroy(){i&&cancelAnimationFrame(i),i=0,o?.disconnect(),l.disconnect(),document.removeEventListener(`scroll`,c,{capture:!0}),window.removeEventListener(`resize`,c),window.removeEventListener(`load`,c),n.removeEventListener(`animationend`,c),a&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),r.style.removeProperty(`--wui-chat-launcher-block`)}}}var Z=`wchat:session-start`,De=`wchat:pages`,Oe=`wchat:services`;function ke(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function Ae(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function je(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function Me(e){sessionStorage.getItem(Z)||sessionStorage.setItem(Z,String(Date.now()));let t=0;function n(){let e=document.documentElement.scrollHeight;if(e<=0)return;let n=(window.scrollY+window.innerHeight)/e*100;n>t&&(t=n)}return window.addEventListener(`scroll`,n,{passive:!0}),function(){n();let r=window.location.pathname,i=ke(De);i.includes(r)||(i.push(r),Ae(De,i));let a=je(r,e),o=ke(Oe);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),Ae(Oe,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(Z)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var Q=8,Ne=`(min-width: 992px)`,Pe=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,Fe=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Ie=0;function Le(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function Re(e){let{trigger:t,request:i,isEmpty:a,renderAnswer:o,renderFooter:s,session:c,timings:l,onStateChange:d,returnFocusTo:f}=e??{};if(!(t instanceof HTMLElement))throw TypeError(`createExplainPopover needs a "trigger" element.`);if(typeof i!=`function`)throw TypeError(`createExplainPopover needs a "request" function.`);if(typeof o!=`function`)throw TypeError(`createExplainPopover needs a "renderAnswer" function.`);Ie+=1;let h=e.title??``,g=e.showNotCounted??!0,_=`wui-chat-explain-${Ie}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:U}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(Fe.map(e=>[e,t.getAttribute(e)])),S=t.hidden,C;t.setAttribute(`aria-haspopup`,`dialog`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,_);let w=null,T=null,E=null,D,O=null,k=[],A=[],j=()=>c?.getState().features.Explain===!1;function M(){b.getSnapshot().offline?(C===void 0&&(C=t.getAttribute(`title`)),t.setAttribute(`title`,v().explainOffline),t.setAttribute(`aria-disabled`,`true`),t.setAttribute(`data-offline`,``)):(C!==void 0&&Le(t,`title`,C),C=void 0,t.removeAttribute(`aria-disabled`),t.removeAttribute(`data-offline`)),c&&(t.hidden=j())}function N(e){if(T?.replaceChildren(),e.pillVisible){let t=u(`span`,`wui-chat-explain-pill`),n=u(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=u(`span`);r.textContent=e.state===`slow`?v().explainSlow:v().thinking,t.append(n,r);let i=u(`div`,`wui-chat-explain-thinking`,{role:`status`});i.append(t),T?.append(i)}else if(e.state===`answered`){e.answer!==D&&(E=o(e.answer,y())??null,D=e.answer);let t=u(`div`,`wui-chat-explain-answer`);E&&t.append(E),T?.append(t)}else if(e.state===`empty`){let e=u(`p`,`wui-chat-explain-text`);e.textContent=v().explainEmpty,T?.append(e)}else if(e.state===`capacity`){let t=u(`div`,`wui-chat-explain-alert wui-chat-explain-alert--warning`,{role:`status`}),n=u(`p`);n.textContent=e.resetsDateTimeUtc?v().explainCapacity(ee(e.resetsDateTimeUtc)):v().explainCapacityNoDate,t.append(n),T?.append(t)}else if(e.state===`error`){let e=u(`div`,`wui-chat-explain-alert wui-chat-explain-alert--error`,{role:`alert`}),t=u(`p`);t.textContent=v().explainError,e.append(t,p(`ghost`,v().retry,`rotate-ccw`,()=>b.ask())),T?.append(e)}}function P(){let e=w?.querySelector(`.wui-chat-explain-foot`);e?.replaceChildren();let t=s?.(y());if(t&&e?.append(t),g){let t=u(`p`,`wui-chat-explain-note`);t.textContent=v().explainNotCounted,e?.append(t)}}function F(){if(!w)return;let e=b.getSnapshot();w.dataset.state=e.state,N(e),P(),d?.(e)}function I(){if(!w)return;if(!t.isConnected){U({restoreFocus:!1});return}let e=document.documentElement.getAttribute(`data-wchat-docked`);if((e===`end`||e===`start`)&&globalThis.matchMedia?.(Ne)?.matches===!0){w.dataset.beside=e,w.style.left=``,w.style.top=``,w.style.maxHeight=``;return}delete w.dataset.beside,w.style.position=`fixed`;let n=t.getBoundingClientRect(),r=w.offsetWidth,i=w.offsetHeight,a=globalThis.innerHeight-n.bottom-Q,o=a<i&&n.top>a,s=o?n.top-Q:a,c=o?Math.max(Q,n.top-i-Q):n.bottom+Q,l=Math.max(Q,Math.min(n.left,globalThis.innerWidth-r-Q));w.style.top=`${c}px`,w.style.left=`${l}px`,w.style.maxHeight=s<i?`${Math.max(0,s)}px`:``}function L(e){e.key===`Escape`&&(document.documentElement.hasAttribute(`data-wchat-docked`)||(e.stopPropagation(),U()))}function R(e){let n=e.target;n instanceof Node&&(w?.contains(n)||t.contains(n))||n instanceof Element&&n.closest(`.wui-chat-panel`)||U({restoreFocus:!1})}function z(e){e.target instanceof Node&&w?.contains(e.target)||I()}function B(){b.getSnapshot().offline||W()}function V(){for(let[e,t,n,r]of k)e.removeEventListener(t,n,r);k=[];for(let e of A)e.disconnect();A=[]}function H(){if(w||j()||b.getSnapshot().offline)return;w=u(`div`,`wui-chat-explain`,{role:`dialog`,"aria-label":h,popover:`manual`,id:_});let e=u(`header`,`wui-chat-explain-head`),n=u(`strong`,`wui-chat-explain-title`);n.textContent=h,O=m(v().close,`x`,()=>U()),O.classList.add(`wui-chat-explain-close`),e.append(n,O),T=u(`div`,`wui-chat-explain-body`,{"aria-live":`polite`}),w.append(e,T,u(`div`,`wui-chat-explain-foot`)),w.dataset.state=b.getSnapshot().state,document.body.append(w),w.showPopover?.(),t.setAttribute(`aria-expanded`,`true`),b.ask(),I(),(w.querySelector(Pe)??O).focus({preventScroll:!0}),k=[[document,`keydown`,L,!0],[document,`pointerdown`,R,!0],[window,`resize`,I,!1],[document,`scroll`,z,!0]];for(let[e,t,n,r]of k)e.addEventListener(t,n,r);if(typeof ResizeObserver==`function`){let e=new ResizeObserver(()=>I());e.observe(w),A.push(e)}let r=new MutationObserver(()=>I());r.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-wchat-docked`]}),A.push(r)}function U(e={restoreFocus:!0}){w&&(b.reset(),V(),w.remove(),w=null,T=null,E=null,D=void 0,O=null,t.setAttribute(`aria-expanded`,`false`),M(),e?.restoreFocus!==!1&&(f?.()??t).focus({preventScroll:!0}))}function W(){w?U():H()}let G=b.subscribe(()=>{M(),b.getSnapshot().offline&&w?U():F()}),K=c?.subscribe(()=>{M(),j()&&w&&U({restoreFocus:!1})});return t.addEventListener(`click`,B),M(),{open:H,close:U,toggle:W,isOpen:()=>w!==null,destroy(){U({restoreFocus:!1}),G(),K?.(),b.dispose(),t.removeEventListener(`click`,B);for(let e of Fe)Le(t,e,x[e]);t.hidden=S}}}var ze=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function Be(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(ze)].filter(e=>e.tabIndex>=0&&!e.hidden),r=n[0],i=n[n.length-1];if(!r||!i){t.preventDefault();return}let a=e.ownerDocument.activeElement,o=e.contains(a);t.shiftKey?o&&a!==r||(t.preventDefault(),i.focus()):o&&a!==i||(t.preventDefault(),r.focus())}function Ve(e){e?.isConnected&&e.focus()}function He(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var Ue=`wui-chat-lock`,We=`wui-chat-scroll-lock`;function Ge(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(Ue);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(We,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(Ue);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(We,{detail:{locked:!1}}))}}}var Ke={open:{from:420,to:920,seconds:.16,peak:.16},reply:{from:680,to:540,seconds:.11,peak:.06},sent:{from:540,to:760,seconds:.09,peak:.05}},qe=[`pointerdown`,`keydown`,`touchstart`],Je=`wchat:muted`,Ye=1e-4;function Xe(e,t){let n=t.get(Je)===`1`,r=null;function i(){for(let e of qe)document.removeEventListener(e,a)}function a(){let e=globalThis.AudioContext||globalThis.webkitAudioContext;!r&&e&&(r=new e),r?.state===`suspended`&&r.resume().catch(e=>globalThis.reportError?.(e)),i()}for(let e of qe)document.addEventListener(e,a);return{play(t){let i=Ke[t];if(!i||n||!r||!e[t]||!(e.volume>0))return;let a=r.currentTime,o=r.createOscillator(),s=r.createGain();o.type=`sine`,o.frequency.setValueAtTime(i.from,a),o.frequency.linearRampToValueAtTime(i.to,a+i.seconds),s.gain.setValueAtTime(i.peak*e.volume,a),s.gain.exponentialRampToValueAtTime(Ye,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(Je,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function Ze(e,t={}){let n=t.language;return L({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var Qe=2e3,$e=500,et=32,$=16,tt=`data-wchat-switching`;function nt(e){return new Promise(t=>setTimeout(t,e))}function rt(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=$,setTimeout(i,$))};setTimeout(i,$)})}async function it(e,t={}){let n=t.reduced??globalThis.matchMedia?.(`(prefers-reduced-motion: reduce)`)?.matches===!0;if(typeof document.startViewTransition!=`function`||n){await e();return}let r=document.documentElement;r.setAttribute(tt,``);try{let n=()=>!t.target||document.querySelector(`.wui-chat--${t.target}`)!==null,r=()=>(typeof t.pageReady!=`function`||t.pageReady())&&n(),i=document.startViewTransition(async()=>{await e(),await rt(t.routeReady,Qe),await rt(r,$e),await nt(et)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(tt)}}var at=100,ot=12,st=220,ct=640;function lt(e,t){let n=t.phone.mode===`Sheet`,r=window.visualViewport,i;function a(){e.style.removeProperty(`bottom`),e.style.removeProperty(`max-height`)}function o(){if(i=void 0,window.innerWidth>t.phone.maxWidthPx){a();return}if(!r)return;let o=Math.max(0,window.innerHeight-r.height-r.offsetTop),s=r.height-ot;n&&(s=Math.min(ct,Math.max(st,s))),e.style.bottom=`${o}px`,e.style.maxHeight=`${s}px`}function s(){clearTimeout(i),i=setTimeout(o,at)}return r?.addEventListener(`resize`,s),r?.addEventListener(`scroll`,s),window.addEventListener(`resize`,s),window.addEventListener(`orientationchange`,s),o(),{destroy(){clearTimeout(i),r?.removeEventListener(`resize`,s),r?.removeEventListener(`scroll`,s),window.removeEventListener(`resize`,s),window.removeEventListener(`orientationchange`,s),a()}}}export{h as A,D as C,u as D,x as E,o as M,s as N,m as O,L as S,f as T,re as _,Xe as a,H as b,Ve as c,Me as d,Ee as f,J as g,oe as h,Ze as i,p as j,d as k,Be as l,ae as m,lt as n,Ge as o,_e as p,it as r,He as s,e as t,Re as u,ie as v,v as w,t as x,ee as y};
|