@webority/chat-elements 0.166.0 → 0.166.2

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.
@@ -1 +1 @@
1
- (function(){var e=document.currentScript;if(!(e instanceof HTMLScriptElement)||!e.dataset.chatSrc)throw Error(`chat.loader.js needs a data-chat-src attribute naming chat.global.js; add it through <app-chat>.`);var t=e.dataset.chatSrc,n=e.nonce,r=!1;function i(){if(r)return;r=!0;let e=document.createElement(`script`);e.src=t,n&&(e.nonce=n),document.head.append(e)}function a(){try{return globalThis.sessionStorage.getItem(`wchat:open`)===`1`}catch{return!1}}function o(e,t){let n=e.querySelector(`:scope > [slot="mark"]`),r=t.querySelector(`.wui-chat-launcher-icon`);if(n===null||r===null)return;let i=n.cloneNode(!0);i instanceof Element&&(i.removeAttribute(`slot`),i.removeAttribute(`id`),r.replaceChildren(i))}function s(){typeof globalThis.requestIdleCallback==`function`?globalThis.requestIdleCallback(i,{timeout:4e3}):setTimeout(i,1e3)}var c=[...document.querySelectorAll(`wui-chat`)];if(!c.every(e=>e.querySelector(`:scope > [data-wui-chat-placeholder]`)!==null&&!e.hasAttribute(`open`))||a())i();else{for(let e of c){let t=e.querySelector(`:scope > [data-wui-chat-placeholder] .wui-chat-launcher`);t!==null&&(o(e,t),t.addEventListener(`pointerenter`,i,{once:!0}),t.addEventListener(`focus`,i,{once:!0}),t.addEventListener(`click`,()=>{e.setAttribute(`open`,``),i()},{once:!0}))}document.readyState===`complete`?s():globalThis.addEventListener(`load`,s,{once:!0})}})();
1
+ (function(){function e(e,t,n){let r=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&e.left<t.right&&e.right>t.left&&(r=Math.max(r,window.innerHeight-e.top))}return r>0?r+n:0}function t(t){let n=t.querySelector(`:scope > [data-wui-chat-placeholder] .wui-chat-launcher-wrap`);if(!(n instanceof HTMLElement))return;let r=n,i=Number.parseInt(t.getAttribute(`lift-gap`)??``,10),a=Number.isNaN(i)?20:i,o=new MutationObserver(s);function s(){if(!r.isConnected){o.disconnect(),window.removeEventListener(`resize`,s);return}let t=[...document.querySelectorAll(`wui-consent-banner[open]`)];r.style.setProperty(`--wui-chat-lift`,`${e(t,r.getBoundingClientRect(),a)}px`)}o.observe(document.documentElement,{attributes:!0,attributeFilter:[`style`]}),window.addEventListener(`resize`,s),s()}var n=document.currentScript;if(!(n instanceof HTMLScriptElement)||!n.dataset.chatSrc)throw Error(`chat.loader.js needs a data-chat-src attribute naming chat.global.js; add it through <app-chat>.`);var r=n.dataset.chatSrc,i=n.nonce,a=!1;function o(){if(a)return;a=!0;let e=document.createElement(`script`);e.src=r,i&&(e.nonce=i),document.head.append(e)}function s(){try{return globalThis.sessionStorage.getItem(`wchat:open`)===`1`}catch{return!1}}function c(e,t){let n=e.querySelector(`:scope > [slot="mark"]`),r=t.querySelector(`.wui-chat-launcher-icon`);if(n===null||r===null)return;let i=n.cloneNode(!0);i instanceof Element&&(i.removeAttribute(`slot`),i.removeAttribute(`id`),r.replaceChildren(i))}function l(){typeof globalThis.requestIdleCallback==`function`?globalThis.requestIdleCallback(o,{timeout:4e3}):setTimeout(o,1e3)}var u=[...document.querySelectorAll(`wui-chat`)];if(!u.every(e=>e.querySelector(`:scope > [data-wui-chat-placeholder]`)!==null&&!e.hasAttribute(`open`))||s())o();else{for(let e of u){let n=e.querySelector(`:scope > [data-wui-chat-placeholder] .wui-chat-launcher`);n!==null&&(c(e,n),t(e),n.addEventListener(`pointerenter`,o,{once:!0}),n.addEventListener(`focus`,o,{once:!0}),n.addEventListener(`click`,()=>{e.setAttribute(`open`,``),o()},{once:!0}))}document.readyState===`complete`?l():globalThis.addEventListener(`load`,l,{once:!0})}})();
@@ -1,13 +1 @@
1
- declare const OPEN_KEY = "wchat:open";
2
- declare const IDLE_TIMEOUT_MS = 4000;
3
- declare const NO_IDLE_DELAY_MS = 1000;
4
- declare const script: HTMLOrSVGScriptElement | null;
5
- declare const engineSrc: string;
6
- declare const nonce: string;
7
- declare let started: boolean;
8
- declare function load(): void;
9
- declare function leftOpen(): boolean;
10
- declare function copyMark(host: Element, button: Element): void;
11
- declare function whenIdle(): void;
12
- declare const hosts: import("./WuiChat").WuiChat[];
13
- declare const waits: boolean;
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const BANNER_SELECTOR = "wui-consent-banner[open]";
2
+ export declare function liftFor(targets: Element[], launcher: DOMRect, gapPx: number): number;
3
+ export declare function trackDrawnLauncherLift(host: Element): void;
@@ -1 +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=`--_wui-chat-launcher-block`;function o(e,t){let n=()=>{let n=t.offsetHeight;n>0&&e.style.setProperty(a,`${n}px`)};if(n(),typeof ResizeObserver>`u`)return()=>void 0;let r=new ResizeObserver(n);return r.observe(t),()=>r.disconnect()}var s=`(prefers-reduced-motion: reduce)`;function c(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 l(e,t){let n=typeof window.matchMedia==`function`?window.matchMedia(s):null,r=/* @__PURE__ */ new Set,i=()=>e.motion===`Reduced`||t?.motion===!1||n?.matches===!0,a=i();function o(){let e=i();if(e!==a){a=e;for(let e of r)e(a)}}return n?.addEventListener(`change`,o),{get reduced(){return a},subscribe(e){return r.add(e),()=>{r.delete(e)}},destroy(){n?.removeEventListener(`change`,o),r.clear()}}}var u=`AppButton`,d={primary:`btn-primary`,secondary:`btn-soft-primary`,ghost:`btn-ghost-primary`,outline:`btn-outline-primary`,neutral:`btn-soft-neutral`,danger:`btn-danger`};function f(e,t){return Object.getOwnPropertyDescriptor(e,t)!==void 0}function p(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 m(e,t=16){return i(e,{size:t})??p(`span`,`d-inline-flex`)}function h(e=`primary`,t=`md`){if(!f(d,e))throw Error(`Unknown button variant "${e}". Use one of ${Object.keys(d).join(`, `)}.`);return`btn ${d[e]}${t===`sm`?` btn-sm`:``}`}function g(e,t,n,r){let i=p(`button`,`${h(e,`sm`)} wui-chat-action-btn`,{type:`button`});return i.dataset.wui=u,n&&i.append(m(n,14)),i.append(document.createTextNode(t)),i.addEventListener(`click`,r),i}function _(e,t,n){let r=p(`button`,`wui-chat-icon-btn`,{type:`button`,"aria-label":e,title:e});return r.append(m(t,20)),r.addEventListener(`click`,n),r}function v(e,t){let n=e.getAttribute(t);if(n!=null&&n!==``)try{return JSON.parse(n)}catch(e){throw Error(`<wui-chat ${t}> must be valid JSON.`,{cause:e})}}var y=0;function b(e){return e.querySelector(`:scope > [slot="mark"]`)}function x(e,t){for(let t of e.querySelectorAll(`script`))t.remove();let n=[e,...e.querySelectorAll(`*`)],r=[];for(let e of n){for(let t of e.getAttributeNames())t.startsWith(`on`)&&e.removeAttribute(t);let n=e.getAttribute(`id`);if(n){let i=`${n}-${t}`;r.push([n,i]),e.setAttribute(`id`,i)}}let i=e=>r.reduce((e,[t,n])=>e.split(`url(#${t})`).join(`url(#${n})`),e);for(let e of n){for(let t of e.getAttributeNames()){let n=e.getAttribute(t);n?.includes(`url(#`)&&e.setAttribute(t,i(n))}let t=e.localName===`style`?e.textContent:null;t?.includes(`url(#`)&&(e.textContent=i(t))}}function S(e){return(t,n)=>{if(e===null)return null;let r=e.cloneNode(!0);if(!(r instanceof Element))return null;r.removeAttribute(`slot`),y+=1,x(r,`mark${y}`);let i=p(`span`,`wui-chat-mark`,{"aria-hidden":`true`,"data-place":t,"data-state":n});return i.append(r),i}}function C(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 w(e,t,n){n!==void 0&&(n===null?e.style.removeProperty(t):e.style.setProperty(t,`${n}px`))}function T(e,t){if(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.panelPlacement!==void 0&&e.classList.toggle(`wui-chat--placement-side`,t.panelPlacement===`Side`),t.inputMark!==void 0&&e.classList.toggle(`wui-chat--input-mark-avatar`,t.inputMark===`Avatar`),t.phoneHideLauncher!==void 0&&e.classList.toggle(`wui-chat--phone-hide-launcher`,t.phoneHideLauncher),t.phoneLauncherLabel!==void 0&&e.classList.toggle(`wui-chat--phone-label`,t.phoneLauncherLabel),t.inputMarkAlign!==void 0&&e.classList.toggle(`wui-chat--input-mark-bottom`,t.inputMarkAlign===`Bottom`),t.startersHeading!==void 0&&e.classList.toggle(`wui-chat--starters-heading`,t.startersHeading),t.startersGap!==void 0&&e.classList.toggle(`wui-chat--starters-gap`,t.startersGap!==null),w(e,`--_wui-chat-phone-offset-x`,t.phoneOffsetX),w(e,`--_wui-chat-phone-offset-y`,t.phoneOffsetY),w(e,`--_wui-chat-input-mark-inset`,t.inputMarkInset),w(e,`--_wui-chat-send-inset`,t.inputSendInset),w(e,`--_wui-chat-input-row-height`,t.inputRowHeight),w(e,`--_wui-chat-starters-gap`,t.startersGap),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.avatarMotion!==void 0){let n=e.style.getPropertyValue(`--_wui-chat-avatar`)!==``;e.classList.toggle(`wui-chat--avatar-drift`,t.avatarMotion===`Drift`&&!n)}t.replyAvatars!==void 0&&(e.classList.toggle(`wui-chat--reply-avatars-off`,t.replyAvatars===`None`),e.classList.toggle(`wui-chat--reply-avatars-every`,t.replyAvatars===`Every`)),t.footerLayout!==void 0&&e.classList.toggle(`wui-chat--footer-inline`,t.footerLayout===`Inline`),t.inputEdge!==void 0&&e.classList.toggle(`wui-chat--input-edge-gradient`,t.inputEdge===`Gradient`),t.inputBusyEdge!==void 0&&e.classList.toggle(`wui-chat--input-busy-edge-sweep`,t.inputBusyEdge===`Sweep`),t.inputPlaceholder!==void 0&&e.classList.toggle(`wui-chat--placeholder-gradient`,t.inputPlaceholder===`Gradient`),t.startersStyle!==void 0&&e.classList.toggle(`wui-chat--starters-rows`,t.startersStyle===`Rows`)}var E=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],D={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function O(e){for(let t of e.getAnimations())if(t instanceof CSSAnimation&&t.playState===`running`&&typeof t.currentTime==`number`)return t.currentTime;return null}function k(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function A({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a,mark:s}){let l=p(`div`,`wui-chat ${D[t]} wui-chat--${n}`),u=p(`section`,`wui-chat-panel`,{id:e,role:r}),d=i?C(l):null;l.dataset.state=i?`closed`:`open`;let f=null,h=null,g=null,_=null,v=null,y=null,b=null,x=null,S=`round`,w=!1,E=`bubble`,O=null,A=null,j=!1,M=`icon`,N=!1;function P(){if(!f)return;let e=f.dataset.launcher,t=[`wui-chat-launcher-wrap`];e===`entering`&&O&&t.push(`wui-chat-launcher--entrance-${O}`),(e===`idle`||A===`ring`&&(e===`hidden`||e===`peeking`))&&A&&A!==`none`&&t.push(`wui-chat-launcher--idle-${A}`),f.className=t.join(` `)}function F(e){f&&(f.dataset.launcher=e,P())}function I(){if(!h)return;let e=[...h.classList].filter(e=>e.endsWith(`--opening`)||e.endsWith(`--closing`)),t=[`wui-chat-launcher`,`wui-chat-launcher--${S}`];S===`expanding`&&t.push(`wui-chat-launcher--pill`),S===`pill`&&w&&t.push(`wui-chat-launcher--compact`),M!==`icon`&&t.push(`wui-chat-launcher--mark-${M}`),t.push(`wui-chat-launcher--reveal-${E}`,...e),h.className=t.join(` `)}function L(e){if(f&&O){F(`entering`);for(let t of f.getAnimations())t.currentTime=e}}function R(){y&&b&&(y.textContent=x||b.launcher)}function z(){if(!h||!v||!b)return;let e=x||b.launcher;h.setAttribute(`aria-label`,N?b.launcherClose:e),v.textContent=e}if(i){let t=p(`div`,`wui-chat-launcher-wrap`);f=t,t.dataset.launcher=`idle`;let n=p(`button`,`wui-chat-launcher`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-controls":e});h=n;let r=p(`span`,`wui-chat-launcher-icon`,{"aria-hidden":`true`});g=r,_=s?.(`launcher`,`rest`)??null,r.append(_??m(`chat`,24));let i=p(`span`,`wui-chat-launcher-close`,{"aria-hidden":`true`});i.append(m(`x`,24));let c=p(`span`,`wui-chat-launcher-label`);v=c,n.append(r,i,c),n.addEventListener(`click`,()=>a()),n.addEventListener(`animationend`,e=>{e.target===n&&n.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`)});let d=p(`span`,`wui-chat-launcher-bubble`,{"aria-hidden":`true`});y=d,t.append(n,d),o(l,n),t.addEventListener(`animationend`,e=>{e.target===t&&t.dataset.launcher===`entering`&&(t.dataset.launcher=`idle`,P())}),I(),P(),l.append(t,u)}else l.append(u);function B(e){if(!d)return;let t=e&&!N&&h!==null&&h?h.getBoundingClientRect():null;e!==N&&h&&(h.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`),h.classList.add(e?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`)),N=e,d(e),t&&c(u,t),h&&(h.setAttribute(`aria-expanded`,String(e)),z())}function V(e){b=e,h&&(z(),R())}function H(e){if(T(l,e),e.theme!==void 0&&(e.theme===`light`||e.theme===`dark`?l.dataset.theme=e.theme:delete l.dataset.theme),!h||!f||!g)return;e.launcherStyle!==void 0&&(S=k(e.launcherStyle)),e.compact!==void 0&&(w=e.compact),e.labelReveal!==void 0&&(E=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(O=e.entrance===`None`?null:k(e.entrance)),e.idle!==void 0&&(A=e.idle===`None`?`none`:k(e.idle)),e.phone!==void 0&&(j=e.phone),e.hoverLabel!==void 0&&(x=e.hoverLabel||null),e.launcherMark!==void 0&&(M=k(e.launcherMark)),_===null&&e.icon!==void 0&&e.icon!==g.dataset.icon&&(g.dataset.icon=e.icon,g.replaceChildren(m(e.icon,24)));let t=e.launcherState??f.dataset.launcher;j&&e.launcherState===`entering`&&e.phoneEntrance!==`Match`&&(t=`idle`),t===`entering`&&!O&&(t=`idle`),f.dataset.launcher=t,I(),P(),R(),z()}return{root:l,panel:u,setOpen:B,setLabels:V,setAppearance:H,setLauncherState:F,resumeEntrance:L,nudgeHost:f,launcherButton:h,role:r}}var j=1e4,M=2e3,N=3e5,P=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),F=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function I(e){return P.has(R(e,`name`))?new t(`Blocked`,{message:z(e)}):F.has(R(e,`name`))?new t(`NoMicrophone`,{message:z(e)}):L(e)}function L(e){return e instanceof t?e:new t(`Failed`,{message:z(e)??String(e)})}function R(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function z(e){let t=R(e,`message`);return t==null?void 0:String(t)}function B(e){return typeof e==`object`&&!!e}function V(e){let t=R(e,`SpeechConfig`),n=R(e,`AudioConfig`),r=R(e,`NoMatchDetails`);return typeof R(t,`fromAuthorizationToken`)==`function`&&typeof R(n,`fromDefaultMicrophoneInput`)==`function`&&typeof R(n,`fromSpeakerOutput`)==`function`&&typeof R(r,`fromResult`)==`function`&&typeof R(e,`SpeechRecognizer`)==`function`&&typeof R(e,`SpeakerAudioDestination`)==`function`&&typeof R(e,`SpeechSynthesizer`)==`function`&&B(R(e,`PropertyId`))&&B(R(e,`ResultReason`))&&B(R(e,`NoMatchReason`))&&B(R(e,`CancellationReason`))}function H(e){if(!V(e))throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}var U=null;function W(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(H(t)):(U===null&&(U=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>H(R(e,`SpeechConfig`)?e:R(e,`default`))).catch(e=>{throw U=null,e})),U)}function ee(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function G(e){let n=e.getToken,r=e.loadSdk??W,i=e.getLanguage??ee,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,L(e)})),u)}function p(){return d===null&&(d=Promise.resolve().then(()=>r()).then(e=>{if(!e?.SpeechConfig)throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}).catch(e=>{throw d=null,L(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`,C);try{m?.close()}finally{try{a?.()}finally{e?c(e):o()}}}};async function C(){if(!(u||d)){d=!0,x();try{let e=m;e!==null&&await new Promise(t=>e.stopContinuousRecognitionAsync(()=>t(),()=>t()))}finally{S(null)}}}let w=()=>[..._,g].filter(e=>e!==``).join(` `).trim(),T=(e,t)=>{h||(h=!0,clearTimeout(v)),clearTimeout(y),y=setTimeout(C,M),r?.(w(),t)};async function E(){if(n?.addEventListener(`abort`,C),!s){S(new t(`Unavailable`,{message:`Dictation is not available in this browser.`}));return}let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){S(I(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(j));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,T(n,!1))},o.recognized=(e,r)=>{if(u)return;let{reason:i,text:a}=r.result;i===n.ResultReason.RecognizedSpeech&&a?(_.push(a),g=``,T(a,!0)):i===n.ResultReason.NoMatch&&n.NoMatchDetails.fromResult(r.result).reason===n.NoMatchReason.InitialSilenceTimeout&&S(new t(`NoSpeech`,{message:`No speech was heard.`}))},o.canceled=(e,r)=>{u||(r.reason===n.CancellationReason.Error?S(new t(`Failed`,{message: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`,{message:`No speech was heard.`}))},j),b=setTimeout(C,N)}catch(e){S(L(e))}}return E(),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(L(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`,{message:`The reply could not be synthesised.`}))},e=>d(e))}catch(e){d(e)}})}catch(e){throw L(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var te=`data-wchat-printing`,K=`data-wchat-print-hide`,ne=`data-wchat-print-path`,re=`data-wchat-print-target`,ie=/* @__PURE__ */ new Set([`script`,`style`,`link`,`template`]),q=null;function J(){if(q!==null){for(let e of q.marked)e.removeAttribute(K),e.removeAttribute(ne),e.removeAttribute(re);q.heading.remove(),document.documentElement.removeAttribute(te),window.removeEventListener(`afterprint`,q.onAfterPrint),q=null}}function ae(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(ne,``),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||ie.has(t.localName)||(t.setAttribute(K,``),o.push(t));s=e}for(let e of n)e.setAttribute(K,``),o.push(e);r!==null&&(r.setAttribute(re,``),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(te,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 oe(e,t){ae(e,`conversation`,[],null,t)}function se(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);ae(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function ce(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function le({title:e,text:t}){if(!ce())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 Y=6e4,X=60*Y,ue=48*X;function de(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function fe(e,t=Date.now(),n){let r=de(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<Y)return s.format(0,`second`);if(a<X){let e=Math.floor(a/Y);return s.format(o?-e:e,`minute`)}if(a<ue){let e=Math.floor(a/X);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function pe(e,t){let n=de(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var me=`wchat:auto-opened`,he=`wchat:dismissed`,ge=`button, a[href], input, select, textarea`,_e=`input, textarea`;function Z(e){return!e.closest(`.wui-chat`)}function ve(e){return e instanceof Element&&e.matches(_e)&&Z(e)}function ye(){return[...document.querySelectorAll(_e)].some(e=>Z(e)&&e.value!==e.defaultValue)}function be(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function xe(e){return e?[...document.querySelectorAll(ge)].some(t=>{if(!Z(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 Se(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(me)||e.rememberDismissal&&sessionStorage.getItem(he)||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&&ye()||n.isOpen()?!0:e.skipWhenCoversControl&&xe(n.panelRect())}function Ce(e){return ve(document.activeElement)||be(e.avoid.menuSelectors)||be(e.avoid.autoOpenBusySelectors)}function we(e,t,n){let r;function i(){r=void 0,Se(e,t,n)||(Ce(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(me,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var Te=.4,Ee=.5,De=`rgba(0, 0, 0, 0)`,Oe=`wui-consent-banner[open]`;function Q(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function ke(e){let t=e.createElement(`canvas`);t.width=1,t.height=1;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)throw Error(`A 2D canvas context is needed to read the colour under the launcher.`);return e=>{n.clearRect(0,0,1,1),n.fillStyle=De,n.fillStyle=e,n.fillRect(0,0,1,1);let[t=0,r=0,i=0,a=0]=n.getImageData(0,0,1,1).data;return{r:t,g:r,b:i,alpha:a/255}}}function Ae({r:e,g:t,b:n}){return .2126*Q(e)+.7152*Q(t)+.0722*Q(n)}function je(e,t,n){let r=e.getBoundingClientRect(),i=document.elementsFromPoint?.(r.left+r.width/2,r.top+r.height/2)??[],a=t.length?t.join(`,`):null;for(let t of i){if(e.contains(t))continue;if(a&&t.closest(a))return!0;let r=n(getComputedStyle(t).backgroundColor);if(!(r.alpha<Ee))return Ae(r)<Te}return!1}function Me(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function Ne(e,t,n){let r=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&e.left<t.right&&e.right>t.left&&(r=Math.max(r,window.innerHeight-e.top))}return r>0?r+n:0}function Pe(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 Fe(e,t,n,r=e=>{n.dataset.launcher=e}){let i=n.ownerDocument.documentElement,a=t.switchOnDark?ke(n.ownerDocument):null,o=0,s=!1,c=null;function l(){o=0;let l=[...t.liftAboveFooter?Me(e.liftSelectors):[],...t.liftAboveBanner?Me([Oe]):[]];if(c)for(let e of l)c.observe(e);n.style.setProperty(`--wui-chat-lift`,`${Ne(l,n.getBoundingClientRect(),e.liftGapPx)}px`);let u=n.getBoundingClientRect(),d=u.height===0?0:Math.round(window.innerHeight-u.top);i.style.setProperty(`--wui-chat-launcher-block`,`${d}px`);let f=t.stepAsideForMenus&&Pe(e.menuSelectors);f&&!s?(r(`hidden`),n.inert=!0,s=!0):!f&&s&&(r(`idle`),n.inert=!1,s=!1);let p=a!==null&&je(n,e.darkSelectors,a);p&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!p&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function u(){o||=requestAnimationFrame(l)}typeof ResizeObserver==`function`&&(c=new ResizeObserver(u));let d=new MutationObserver(u);return d.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,u,{capture:!0,passive:!0}),window.addEventListener(`resize`,u),window.addEventListener(`load`,u),n.addEventListener(`animationend`,u),u(),{destroy(){o&&cancelAnimationFrame(o),o=0,c?.disconnect(),d.disconnect(),document.removeEventListener(`scroll`,u,{capture:!0}),window.removeEventListener(`resize`,u),window.removeEventListener(`load`,u),n.removeEventListener(`animationend`,u),s&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),i.style.removeProperty(`--wui-chat-launcher-block`)}}}var Ie=`wchat:session-start`,Le=`wchat:pages`,Re=`wchat:services`;function ze(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function Be(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function Ve(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function He(e){sessionStorage.getItem(Ie)||sessionStorage.setItem(Ie,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=ze(Le);i.includes(r)||(i.push(r),Be(Le,i));let a=Ve(r,e),o=ze(Re);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),Be(Re,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(Ie)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var $=8,Ue=`(min-width: 992px)`,We=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,Ge=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Ke=0;function qe(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function Je(e){let{trigger:t,request:i,isEmpty:a,renderAnswer:o,renderFooter:s,session:c,timings:l,onStateChange:u,returnFocusTo:d}=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.`);Ke+=1;let f=e.title??``,m=e.showNotCounted??!0,h=`wui-chat-explain-${Ke}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:U}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(Ge.map(e=>[e,t.getAttribute(e)])),S=t.hidden,C;t.setAttribute(`aria-haspopup`,`dialog`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,h);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&&qe(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=p(`span`,`wui-chat-explain-pill`),n=p(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=p(`span`);r.textContent=e.state===`slow`?v().explainSlow:v().thinking,t.append(n,r);let i=p(`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=p(`div`,`wui-chat-explain-answer`);E&&t.append(E),T?.append(t)}else if(e.state===`empty`){let e=p(`p`,`wui-chat-explain-text`);e.textContent=v().explainEmpty,T?.append(e)}else if(e.state===`capacity`){let t=p(`div`,`wui-chat-explain-alert wui-chat-explain-alert--warning`,{role:`status`}),n=p(`p`);n.textContent=e.resetsDateTimeUtc?v().explainCapacity(pe(e.resetsDateTimeUtc)):v().explainCapacityNoDate,t.append(n),T?.append(t)}else if(e.state===`error`){let e=p(`div`,`wui-chat-explain-alert wui-chat-explain-alert--error`,{role:`alert`}),t=p(`p`);t.textContent=v().explainError,e.append(t,g(`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),m){let t=p(`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){U({restoreFocus:!1});return}let e=document.documentElement.getAttribute(`data-wchat-docked`);if((e===`end`||e===`start`)&&globalThis.matchMedia?.(Ue)?.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-$,o=a<i&&n.top>a,s=o?n.top-$:a,c=o?Math.max($,n.top-i-$):n.bottom+$,l=Math.max($,Math.min(n.left,globalThis.innerWidth-r-$));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=p(`div`,`wui-chat-explain`,{role:`dialog`,"aria-label":f,popover:`manual`,id:h});let e=p(`header`,`wui-chat-explain-head`),n=p(`strong`,`wui-chat-explain-title`);n.textContent=f,O=_(v().close,`x`,()=>U()),O.classList.add(`wui-chat-explain-close`),e.append(n,O),T=p(`div`,`wui-chat-explain-body`,{"aria-live":`polite`}),w.append(e,T,p(`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(We)??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&&(d?.()??t).focus({preventScroll:!0}))}function W(){w?U():H()}let ee=b.subscribe(()=>{M(),b.getSnapshot().offline&&w?U():F()}),G=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}),ee(),G?.(),b.dispose(),t.removeEventListener(`click`,B);for(let e of Ge)qe(t,e,x[e]);t.hidden=S}}}var Ye=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function Xe(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(Ye)].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 Ze(e){e?.isConnected&&e.focus()}function Qe(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var $e=`wui-chat-lock`,et=`wui-chat-scroll-lock`;function tt(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add($e);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(et,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove($e);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(et,{detail:{locked:!1}}))}}}var nt={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}},rt=[`pointerdown`,`keydown`,`touchstart`],it=`wchat:muted`,at=1e-4;function ot(e,t){let n=t.get(it)===`1`,r=null;function i(){for(let e of rt)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 rt)document.addEventListener(e,a);return{play(t){let i=nt[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(at,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(it,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function st(e,t={}){let n=t.language;return G({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var ct=2e3,lt=500,ut=32,dt=16,ft=`data-wchat-switching`;function pt(e){return new Promise(t=>setTimeout(t,e))}function mt(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=dt,setTimeout(i,dt))};setTimeout(i,dt)})}async function ht(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(ft,``);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 mt(t.routeReady,ct),await mt(r,lt),await pt(ut)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(ft)}}var gt=100,_t=12,vt=220;function yt(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=window.innerHeight-r.height>_t,c=r.height-(n||s?_t:0);n&&(c=Math.min(t.phone.sheetMaxHeightPx,Math.max(vt,c))),e.style.bottom=`${o}px`,e.style.maxHeight=`${c}px`}function s(){clearTimeout(i),i=setTimeout(o,gt)}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{O as A,I as C,S as D,b as E,g as F,c as I,l as L,_ as M,m as N,A as O,v as P,o as R,G as S,h as T,le as _,ot as a,se as b,Ze as c,He as d,Fe as f,ce as g,fe as h,st as i,f as j,p as k,Xe as l,pe as m,yt as n,tt as o,we as p,ht as r,Qe as s,e as t,Je as u,J as v,E as w,t as x,oe as y};
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=`--_wui-chat-launcher-block`;function o(e,t){let n=()=>{let n=t.offsetHeight;n>0&&e.style.setProperty(a,`${n}px`)};if(n(),typeof ResizeObserver>`u`)return()=>void 0;let r=new ResizeObserver(n);return r.observe(t),()=>r.disconnect()}var s=`(prefers-reduced-motion: reduce)`;function c(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 l(e,t){let n=typeof window.matchMedia==`function`?window.matchMedia(s):null,r=/* @__PURE__ */ new Set,i=()=>e.motion===`Reduced`||t?.motion===!1||n?.matches===!0,a=i();function o(){let e=i();if(e!==a){a=e;for(let e of r)e(a)}}return n?.addEventListener(`change`,o),{get reduced(){return a},subscribe(e){return r.add(e),()=>{r.delete(e)}},destroy(){n?.removeEventListener(`change`,o),r.clear()}}}var u=`AppButton`,d={primary:`btn-primary`,secondary:`btn-soft-primary`,ghost:`btn-ghost-primary`,outline:`btn-outline-primary`,neutral:`btn-soft-neutral`,danger:`btn-danger`};function f(e,t){return Object.getOwnPropertyDescriptor(e,t)!==void 0}function p(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 m(e,t=16){return i(e,{size:t})??p(`span`,`d-inline-flex`)}function h(e=`primary`,t=`md`){if(!f(d,e))throw Error(`Unknown button variant "${e}". Use one of ${Object.keys(d).join(`, `)}.`);return`btn ${d[e]}${t===`sm`?` btn-sm`:``}`}function g(e,t,n,r){let i=p(`button`,`${h(e,`sm`)} wui-chat-action-btn`,{type:`button`});return i.dataset.wui=u,n&&i.append(m(n,14)),i.append(document.createTextNode(t)),i.addEventListener(`click`,r),i}function _(e,t,n){let r=p(`button`,`wui-chat-icon-btn`,{type:`button`,"aria-label":e,title:e});return r.append(m(t,20)),r.addEventListener(`click`,n),r}function v(e,t){let n=e.getAttribute(t);if(n!=null&&n!==``)try{return JSON.parse(n)}catch(e){throw Error(`<wui-chat ${t}> must be valid JSON.`,{cause:e})}}var y=0;function b(e){return e.querySelector(`:scope > [slot="mark"]`)}function x(e,t){for(let t of e.querySelectorAll(`script`))t.remove();let n=[e,...e.querySelectorAll(`*`)],r=[];for(let e of n){for(let t of e.getAttributeNames())t.startsWith(`on`)&&e.removeAttribute(t);let n=e.getAttribute(`id`);if(n){let i=`${n}-${t}`;r.push([n,i]),e.setAttribute(`id`,i)}}let i=e=>r.reduce((e,[t,n])=>e.split(`url(#${t})`).join(`url(#${n})`),e);for(let e of n){for(let t of e.getAttributeNames()){let n=e.getAttribute(t);n?.includes(`url(#`)&&e.setAttribute(t,i(n))}let t=e.localName===`style`?e.textContent:null;t?.includes(`url(#`)&&(e.textContent=i(t))}}function S(e){return(t,n)=>{if(e===null)return null;let r=e.cloneNode(!0);if(!(r instanceof Element))return null;r.removeAttribute(`slot`),y+=1,x(r,`mark${y}`);let i=p(`span`,`wui-chat-mark`,{"aria-hidden":`true`,"data-place":t,"data-state":n});return i.append(r),i}}function C(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 w(e,t,n){n!==void 0&&(n===null?e.style.removeProperty(t):e.style.setProperty(t,`${n}px`))}function T(e,t){if(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.panelPlacement!==void 0&&e.classList.toggle(`wui-chat--placement-side`,t.panelPlacement===`Side`),t.inputMark!==void 0&&e.classList.toggle(`wui-chat--input-mark-avatar`,t.inputMark===`Avatar`),t.phoneHideLauncher!==void 0&&e.classList.toggle(`wui-chat--phone-hide-launcher`,t.phoneHideLauncher),t.phoneLauncherLabel!==void 0&&e.classList.toggle(`wui-chat--phone-label`,t.phoneLauncherLabel),t.inputMarkAlign!==void 0&&e.classList.toggle(`wui-chat--input-mark-bottom`,t.inputMarkAlign===`Bottom`),t.startersHeading!==void 0&&e.classList.toggle(`wui-chat--starters-heading`,t.startersHeading),t.startersGap!==void 0&&e.classList.toggle(`wui-chat--starters-gap`,t.startersGap!==null),w(e,`--_wui-chat-phone-offset-x`,t.phoneOffsetX),w(e,`--_wui-chat-phone-offset-y`,t.phoneOffsetY),w(e,`--_wui-chat-input-mark-inset`,t.inputMarkInset),w(e,`--_wui-chat-send-inset`,t.inputSendInset),w(e,`--_wui-chat-input-row-height`,t.inputRowHeight),w(e,`--_wui-chat-starters-gap`,t.startersGap),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.avatarMotion!==void 0){let n=e.style.getPropertyValue(`--_wui-chat-avatar`)!==``;e.classList.toggle(`wui-chat--avatar-drift`,t.avatarMotion===`Drift`&&!n)}t.replyAvatars!==void 0&&(e.classList.toggle(`wui-chat--reply-avatars-off`,t.replyAvatars===`None`),e.classList.toggle(`wui-chat--reply-avatars-every`,t.replyAvatars===`Every`)),t.footerLayout!==void 0&&e.classList.toggle(`wui-chat--footer-inline`,t.footerLayout===`Inline`),t.inputEdge!==void 0&&e.classList.toggle(`wui-chat--input-edge-gradient`,t.inputEdge===`Gradient`),t.inputBusyEdge!==void 0&&e.classList.toggle(`wui-chat--input-busy-edge-sweep`,t.inputBusyEdge===`Sweep`),t.inputPlaceholder!==void 0&&e.classList.toggle(`wui-chat--placeholder-gradient`,t.inputPlaceholder===`Gradient`),t.startersStyle!==void 0&&e.classList.toggle(`wui-chat--starters-rows`,t.startersStyle===`Rows`)}var E=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],D={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function O(e){for(let t of e.getAnimations())if(t instanceof CSSAnimation&&t.playState===`running`&&typeof t.currentTime==`number`)return t.currentTime;return null}function k(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function A({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a,mark:s}){let l=p(`div`,`wui-chat ${D[t]} wui-chat--${n}`),u=p(`section`,`wui-chat-panel`,{id:e,role:r}),d=i?C(l):null;l.dataset.state=i?`closed`:`open`;let f=null,h=null,g=null,_=null,v=null,y=null,b=null,x=null,S=`round`,w=!1,E=`bubble`,O=null,A=null,j=!1,M=`icon`,N=!1;function P(){if(!f)return;let e=f.dataset.launcher,t=[`wui-chat-launcher-wrap`];e===`entering`&&O&&t.push(`wui-chat-launcher--entrance-${O}`),(e===`idle`||A===`ring`&&(e===`hidden`||e===`peeking`))&&A&&A!==`none`&&t.push(`wui-chat-launcher--idle-${A}`),f.className=t.join(` `)}function F(e){f&&(f.dataset.launcher=e,P())}function I(){if(!h)return;let e=[...h.classList].filter(e=>e.endsWith(`--opening`)||e.endsWith(`--closing`)),t=[`wui-chat-launcher`,`wui-chat-launcher--${S}`];S===`expanding`&&t.push(`wui-chat-launcher--pill`),S===`pill`&&w&&t.push(`wui-chat-launcher--compact`),M!==`icon`&&t.push(`wui-chat-launcher--mark-${M}`),t.push(`wui-chat-launcher--reveal-${E}`,...e),h.className=t.join(` `)}function L(e){if(f&&O){F(`entering`);for(let t of f.getAnimations())t.currentTime=e}}function R(){y&&b&&(y.textContent=x||b.launcher)}function z(){if(!h||!v||!b)return;let e=x||b.launcher;h.setAttribute(`aria-label`,N?b.launcherClose:e),v.textContent=e}if(i){let t=p(`div`,`wui-chat-launcher-wrap`);f=t,t.dataset.launcher=`idle`;let n=p(`button`,`wui-chat-launcher`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-controls":e});h=n;let r=p(`span`,`wui-chat-launcher-icon`,{"aria-hidden":`true`});g=r,_=s?.(`launcher`,`rest`)??null,r.append(_??m(`chat`,24));let i=p(`span`,`wui-chat-launcher-close`,{"aria-hidden":`true`});i.append(m(`x`,24));let c=p(`span`,`wui-chat-launcher-label`);v=c,n.append(r,i,c),n.addEventListener(`click`,()=>a()),n.addEventListener(`animationend`,e=>{e.target===n&&n.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`)});let d=p(`span`,`wui-chat-launcher-bubble`,{"aria-hidden":`true`});y=d,t.append(n,d),o(l,n),t.addEventListener(`animationend`,e=>{e.target===t&&t.dataset.launcher===`entering`&&(t.dataset.launcher=`idle`,P())}),I(),P(),l.append(t,u)}else l.append(u);function B(e){if(!d)return;let t=e&&!N&&h!==null&&h?h.getBoundingClientRect():null;e!==N&&h&&(h.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`),h.classList.add(e?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`)),N=e,d(e),t&&c(u,t),h&&(h.setAttribute(`aria-expanded`,String(e)),z())}function V(e){b=e,h&&(z(),R())}function H(e){if(T(l,e),e.theme!==void 0&&(e.theme===`light`||e.theme===`dark`?l.dataset.theme=e.theme:delete l.dataset.theme),!h||!f||!g)return;e.launcherStyle!==void 0&&(S=k(e.launcherStyle)),e.compact!==void 0&&(w=e.compact),e.labelReveal!==void 0&&(E=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(O=e.entrance===`None`?null:k(e.entrance)),e.idle!==void 0&&(A=e.idle===`None`?`none`:k(e.idle)),e.phone!==void 0&&(j=e.phone),e.hoverLabel!==void 0&&(x=e.hoverLabel||null),e.launcherMark!==void 0&&(M=k(e.launcherMark)),_===null&&e.icon!==void 0&&e.icon!==g.dataset.icon&&(g.dataset.icon=e.icon,g.replaceChildren(m(e.icon,24)));let t=e.launcherState??f.dataset.launcher;j&&e.launcherState===`entering`&&e.phoneEntrance!==`Match`&&(t=`idle`),t===`entering`&&!O&&(t=`idle`),f.dataset.launcher=t,I(),P(),R(),z()}return{root:l,panel:u,setOpen:B,setLabels:V,setAppearance:H,setLauncherState:F,resumeEntrance:L,nudgeHost:f,launcherButton:h,role:r}}var j=1e4,M=2e3,N=3e5,P=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),F=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function I(e){return P.has(R(e,`name`))?new t(`Blocked`,{message:z(e)}):F.has(R(e,`name`))?new t(`NoMicrophone`,{message:z(e)}):L(e)}function L(e){return e instanceof t?e:new t(`Failed`,{message:z(e)??String(e)})}function R(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function z(e){let t=R(e,`message`);return t==null?void 0:String(t)}function B(e){return typeof e==`object`&&!!e}function V(e){let t=R(e,`SpeechConfig`),n=R(e,`AudioConfig`),r=R(e,`NoMatchDetails`);return typeof R(t,`fromAuthorizationToken`)==`function`&&typeof R(n,`fromDefaultMicrophoneInput`)==`function`&&typeof R(n,`fromSpeakerOutput`)==`function`&&typeof R(r,`fromResult`)==`function`&&typeof R(e,`SpeechRecognizer`)==`function`&&typeof R(e,`SpeakerAudioDestination`)==`function`&&typeof R(e,`SpeechSynthesizer`)==`function`&&B(R(e,`PropertyId`))&&B(R(e,`ResultReason`))&&B(R(e,`NoMatchReason`))&&B(R(e,`CancellationReason`))}function H(e){if(!V(e))throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}var U=null;function W(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(H(t)):(U===null&&(U=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>H(R(e,`SpeechConfig`)?e:R(e,`default`))).catch(e=>{throw U=null,e})),U)}function ee(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function G(e){let n=e.getToken,r=e.loadSdk??W,i=e.getLanguage??ee,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,L(e)})),u)}function p(){return d===null&&(d=Promise.resolve().then(()=>r()).then(e=>{if(!e?.SpeechConfig)throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}).catch(e=>{throw d=null,L(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`,C);try{m?.close()}finally{try{a?.()}finally{e?c(e):o()}}}};async function C(){if(!(u||d)){d=!0,x();try{let e=m;e!==null&&await new Promise(t=>e.stopContinuousRecognitionAsync(()=>t(),()=>t()))}finally{S(null)}}}let w=()=>[..._,g].filter(e=>e!==``).join(` `).trim(),T=(e,t)=>{h||(h=!0,clearTimeout(v)),clearTimeout(y),y=setTimeout(C,M),r?.(w(),t)};async function E(){if(n?.addEventListener(`abort`,C),!s){S(new t(`Unavailable`,{message:`Dictation is not available in this browser.`}));return}let r;try{r=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){S(I(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(j));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,T(n,!1))},o.recognized=(e,r)=>{if(u)return;let{reason:i,text:a}=r.result;i===n.ResultReason.RecognizedSpeech&&a?(_.push(a),g=``,T(a,!0)):i===n.ResultReason.NoMatch&&n.NoMatchDetails.fromResult(r.result).reason===n.NoMatchReason.InitialSilenceTimeout&&S(new t(`NoSpeech`,{message:`No speech was heard.`}))},o.canceled=(e,r)=>{u||(r.reason===n.CancellationReason.Error?S(new t(`Failed`,{message: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`,{message:`No speech was heard.`}))},j),b=setTimeout(C,N)}catch(e){S(L(e))}}return E(),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(L(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`,{message:`The reply could not be synthesised.`}))},e=>d(e))}catch(e){d(e)}})}catch(e){throw L(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var te=`data-wchat-printing`,K=`data-wchat-print-hide`,ne=`data-wchat-print-path`,re=`data-wchat-print-target`,ie=/* @__PURE__ */ new Set([`script`,`style`,`link`,`template`]),q=null;function J(){if(q!==null){for(let e of q.marked)e.removeAttribute(K),e.removeAttribute(ne),e.removeAttribute(re);q.heading.remove(),document.documentElement.removeAttribute(te),window.removeEventListener(`afterprint`,q.onAfterPrint),q=null}}function ae(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(ne,``),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||ie.has(t.localName)||(t.setAttribute(K,``),o.push(t));s=e}for(let e of n)e.setAttribute(K,``),o.push(e);r!==null&&(r.setAttribute(re,``),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(te,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 oe(e,t){ae(e,`conversation`,[],null,t)}function se(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);ae(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function ce(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function le({title:e,text:t}){if(!ce())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 Y=6e4,X=60*Y,ue=48*X;function de(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function fe(e,t=Date.now(),n){let r=de(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<Y)return s.format(0,`second`);if(a<X){let e=Math.floor(a/Y);return s.format(o?-e:e,`minute`)}if(a<ue){let e=Math.floor(a/X);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function pe(e,t){let n=de(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var me=`wchat:auto-opened`,he=`wchat:dismissed`,ge=`button, a[href], input, select, textarea`,_e=`input, textarea`;function Z(e){return!e.closest(`.wui-chat`)}function ve(e){return e instanceof Element&&e.matches(_e)&&Z(e)}function ye(){return[...document.querySelectorAll(_e)].some(e=>Z(e)&&e.value!==e.defaultValue)}function be(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function xe(e){return e?[...document.querySelectorAll(ge)].some(t=>{if(!Z(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 Se(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(me)||e.rememberDismissal&&sessionStorage.getItem(he)||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&&ye()||n.isOpen()?!0:e.skipWhenCoversControl&&xe(n.panelRect())}function Ce(e){return ve(document.activeElement)||be(e.avoid.menuSelectors)||be(e.avoid.autoOpenBusySelectors)}function we(e,t,n){let r;function i(){r=void 0,Se(e,t,n)||(Ce(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(me,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var Te=`wui-consent-banner[open]`;function Ee(e,t,n){let r=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&e.left<t.right&&e.right>t.left&&(r=Math.max(r,window.innerHeight-e.top))}return r>0?r+n:0}var De=.4,Oe=.5,ke=`rgba(0, 0, 0, 0)`;function Q(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Ae(e){let t=e.createElement(`canvas`);t.width=1,t.height=1;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)throw Error(`A 2D canvas context is needed to read the colour under the launcher.`);return e=>{n.clearRect(0,0,1,1),n.fillStyle=ke,n.fillStyle=e,n.fillRect(0,0,1,1);let[t=0,r=0,i=0,a=0]=n.getImageData(0,0,1,1).data;return{r:t,g:r,b:i,alpha:a/255}}}function je({r:e,g:t,b:n}){return .2126*Q(e)+.7152*Q(t)+.0722*Q(n)}function Me(e,t,n){let r=e.getBoundingClientRect(),i=document.elementsFromPoint?.(r.left+r.width/2,r.top+r.height/2)??[],a=t.length?t.join(`,`):null;for(let t of i){if(e.contains(t))continue;if(a&&t.closest(a))return!0;let r=n(getComputedStyle(t).backgroundColor);if(!(r.alpha<Oe))return je(r)<De}return!1}function Ne(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function Pe(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 Fe(e,t,n,r=e=>{n.dataset.launcher=e}){let i=n.ownerDocument.documentElement,a=t.switchOnDark?Ae(n.ownerDocument):null,o=0,s=!1,c=null;function l(){o=0;let l=[...t.liftAboveFooter?Ne(e.liftSelectors):[],...t.liftAboveBanner?Ne([Te]):[]];if(c)for(let e of l)c.observe(e);n.style.setProperty(`--wui-chat-lift`,`${Ee(l,n.getBoundingClientRect(),e.liftGapPx)}px`);let u=n.getBoundingClientRect(),d=u.height===0?0:Math.round(window.innerHeight-u.top);i.style.setProperty(`--wui-chat-launcher-block`,`${d}px`);let f=t.stepAsideForMenus&&Pe(e.menuSelectors);f&&!s?(r(`hidden`),n.inert=!0,s=!0):!f&&s&&(r(`idle`),n.inert=!1,s=!1);let p=a!==null&&Me(n,e.darkSelectors,a);p&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!p&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function u(){o||=requestAnimationFrame(l)}typeof ResizeObserver==`function`&&(c=new ResizeObserver(u));let d=new MutationObserver(u);return d.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,u,{capture:!0,passive:!0}),window.addEventListener(`resize`,u),window.addEventListener(`load`,u),n.addEventListener(`animationend`,u),u(),{destroy(){o&&cancelAnimationFrame(o),o=0,c?.disconnect(),d.disconnect(),document.removeEventListener(`scroll`,u,{capture:!0}),window.removeEventListener(`resize`,u),window.removeEventListener(`load`,u),n.removeEventListener(`animationend`,u),s&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),i.style.removeProperty(`--wui-chat-launcher-block`)}}}var Ie=`wchat:session-start`,Le=`wchat:pages`,Re=`wchat:services`;function ze(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function Be(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function Ve(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function He(e){sessionStorage.getItem(Ie)||sessionStorage.setItem(Ie,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=ze(Le);i.includes(r)||(i.push(r),Be(Le,i));let a=Ve(r,e),o=ze(Re);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),Be(Re,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(Ie)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var $=8,Ue=`(min-width: 992px)`,We=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,Ge=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Ke=0;function qe(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function Je(e){let{trigger:t,request:i,isEmpty:a,renderAnswer:o,renderFooter:s,session:c,timings:l,onStateChange:u,returnFocusTo:d}=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.`);Ke+=1;let f=e.title??``,m=e.showNotCounted??!0,h=`wui-chat-explain-${Ke}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:U}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(Ge.map(e=>[e,t.getAttribute(e)])),S=t.hidden,C;t.setAttribute(`aria-haspopup`,`dialog`),t.setAttribute(`aria-expanded`,`false`),t.setAttribute(`aria-controls`,h);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&&qe(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=p(`span`,`wui-chat-explain-pill`),n=p(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),r=p(`span`);r.textContent=e.state===`slow`?v().explainSlow:v().thinking,t.append(n,r);let i=p(`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=p(`div`,`wui-chat-explain-answer`);E&&t.append(E),T?.append(t)}else if(e.state===`empty`){let e=p(`p`,`wui-chat-explain-text`);e.textContent=v().explainEmpty,T?.append(e)}else if(e.state===`capacity`){let t=p(`div`,`wui-chat-explain-alert wui-chat-explain-alert--warning`,{role:`status`}),n=p(`p`);n.textContent=e.resetsDateTimeUtc?v().explainCapacity(pe(e.resetsDateTimeUtc)):v().explainCapacityNoDate,t.append(n),T?.append(t)}else if(e.state===`error`){let e=p(`div`,`wui-chat-explain-alert wui-chat-explain-alert--error`,{role:`alert`}),t=p(`p`);t.textContent=v().explainError,e.append(t,g(`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),m){let t=p(`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){U({restoreFocus:!1});return}let e=document.documentElement.getAttribute(`data-wchat-docked`);if((e===`end`||e===`start`)&&globalThis.matchMedia?.(Ue)?.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-$,o=a<i&&n.top>a,s=o?n.top-$:a,c=o?Math.max($,n.top-i-$):n.bottom+$,l=Math.max($,Math.min(n.left,globalThis.innerWidth-r-$));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=p(`div`,`wui-chat-explain`,{role:`dialog`,"aria-label":f,popover:`manual`,id:h});let e=p(`header`,`wui-chat-explain-head`),n=p(`strong`,`wui-chat-explain-title`);n.textContent=f,O=_(v().close,`x`,()=>U()),O.classList.add(`wui-chat-explain-close`),e.append(n,O),T=p(`div`,`wui-chat-explain-body`,{"aria-live":`polite`}),w.append(e,T,p(`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(We)??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&&(d?.()??t).focus({preventScroll:!0}))}function W(){w?U():H()}let ee=b.subscribe(()=>{M(),b.getSnapshot().offline&&w?U():F()}),G=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}),ee(),G?.(),b.dispose(),t.removeEventListener(`click`,B);for(let e of Ge)qe(t,e,x[e]);t.hidden=S}}}var Ye=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function Xe(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(Ye)].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 Ze(e){e?.isConnected&&e.focus()}function Qe(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var $e=`wui-chat-lock`,et=`wui-chat-scroll-lock`;function tt(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add($e);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(et,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove($e);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(et,{detail:{locked:!1}}))}}}var nt={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}},rt=[`pointerdown`,`keydown`,`touchstart`],it=`wchat:muted`,at=1e-4;function ot(e,t){let n=t.get(it)===`1`,r=null;function i(){for(let e of rt)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 rt)document.addEventListener(e,a);return{play(t){let i=nt[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(at,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(it,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function st(e,t={}){let n=t.language;return G({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var ct=2e3,lt=500,ut=32,dt=16,ft=`data-wchat-switching`;function pt(e){return new Promise(t=>setTimeout(t,e))}function mt(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=dt,setTimeout(i,dt))};setTimeout(i,dt)})}async function ht(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(ft,``);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 mt(t.routeReady,ct),await mt(r,lt),await pt(ut)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(ft)}}var gt=100,_t=12,vt=220;function yt(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=window.innerHeight-r.height>_t,c=r.height-(n||s?_t:0);n&&(c=Math.min(t.phone.sheetMaxHeightPx,Math.max(vt,c))),e.style.bottom=`${o}px`,e.style.maxHeight=`${c}px`}function s(){clearTimeout(i),i=setTimeout(o,gt)}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{O as A,I as C,S as D,b as E,g as F,c as I,l as L,_ as M,m as N,A as O,v as P,o as R,G as S,h as T,le as _,ot as a,se as b,Ze as c,He as d,Fe as f,ce as g,fe as h,st as i,f as j,p as k,Xe as l,pe as m,yt as n,tt as o,we as p,ht as r,Qe as s,e as t,Je as u,J as v,E as w,t as x,oe as y};
package/dist/web.js CHANGED
@@ -1 +1 @@
1
- export{t as ChatSpeechError,g as canShareText,f as createAvoidance,S as createAzureSpeech,d as createBehaviourCollector,u as createExplainPopover,a as createSound,i as createWebSpeech,v as endPrint,n as fitToViewport,m as fullMoment,I as growFromButton,o as lockPageScroll,C as microphoneError,y as printConversation,b as printReply,h as relativeMoment,c as returnFocus,_ as shareText,r as switchPanel,R as trackLauncherBlock,l as trapTab,s as vibrate,p as watchAutoOpen,L as watchReducedMotion}from"./web-B_Wi4f8p.js";
1
+ export{t as ChatSpeechError,g as canShareText,f as createAvoidance,S as createAzureSpeech,d as createBehaviourCollector,u as createExplainPopover,a as createSound,i as createWebSpeech,v as endPrint,n as fitToViewport,m as fullMoment,I as growFromButton,o as lockPageScroll,C as microphoneError,y as printConversation,b as printReply,h as relativeMoment,c as returnFocus,_ as shareText,r as switchPanel,R as trackLauncherBlock,l as trapTab,s as vibrate,p as watchAutoOpen,L as watchReducedMotion}from"./web-B028Hkf4.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/chat-elements",
3
- "version": "0.166.0",
3
+ "version": "0.166.2",
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",
@@ -44,7 +44,7 @@
44
44
  "./src/renderers/*.ts"
45
45
  ],
46
46
  "peerDependencies": {
47
- "@webority/chat-core": "0.166.0",
47
+ "@webority/chat-core": "0.166.2",
48
48
  "@webority/markdown-core": "^0.192.0",
49
49
  "@webority/theme": "^0.192.0",
50
50
  "@webority/ui-elements": "^0.192.0",
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "devDependencies": {
59
- "@webority/chat-core": "0.166.0",
59
+ "@webority/chat-core": "0.166.2",
60
60
  "@webority/theme": "0.192.0",
61
61
  "@webority/ui-elements": "0.192.0",
62
62
  "@vitest/coverage-v8": "5.1.0",