@webority/chat-elements 0.165.1 → 0.165.3
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.css +1 -1
- package/dist/chat.global.js +19 -19
- package/dist/types/WuiChat.d.ts +1 -1
- package/dist/types/dom.d.ts +1 -0
- package/dist/types/shell-docked.d.ts +1 -0
- package/dist/types/shell-embed.d.ts +1 -0
- package/dist/types/shell-launcher.d.ts +1 -0
- package/dist/types/shell-page.d.ts +1 -0
- package/dist/types/web/avoid.d.ts +1 -1
- package/dist/web-D_FBKpuC.js +1 -0
- package/dist/web.js +1 -1
- package/package.json +3 -3
- package/dist/web-BkMoHum8.js +0 -1
package/dist/types/WuiChat.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ type RendererApi = {
|
|
|
35
35
|
define: (kind: string, tagName: string) => void;
|
|
36
36
|
map: Record<ChatPartKind, string>;
|
|
37
37
|
};
|
|
38
|
-
type Shell = Pick<ReturnType<typeof createDockedShell>, "root" | "panel" | "setLabels" | "nudgeHost" | "launcherButton" | "role" | "setOpen" | "setAppearance"> & {
|
|
38
|
+
type Shell = Pick<ReturnType<typeof createDockedShell>, "root" | "panel" | "setLabels" | "nudgeHost" | "launcherButton" | "role" | "setOpen" | "setAppearance" | "setLauncherState"> & {
|
|
39
39
|
destroy?: () => void;
|
|
40
40
|
};
|
|
41
41
|
/** Every attribute `<wui-chat>` reads. Values are strings, as the DOM stores them; a closed set lists its words in lower case, which the element also takes in any case. */
|
package/dist/types/dom.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export declare function createShellBase({ id, layout, position, role, launcher,
|
|
|
89
89
|
sheetHeightDvh?: number | undefined;
|
|
90
90
|
sheetMaxHeightPx?: number | undefined;
|
|
91
91
|
}) => void;
|
|
92
|
+
setLauncherState: (state: string) => void;
|
|
92
93
|
nudgeHost: HTMLDivElement | null;
|
|
93
94
|
launcherButton: HTMLButtonElement | null;
|
|
94
95
|
role: string;
|
|
@@ -8,6 +8,7 @@ export declare function createDockedShell(options: {
|
|
|
8
8
|
root: HTMLDivElement;
|
|
9
9
|
panel: HTMLElement;
|
|
10
10
|
setLabels: (next: import("@webority/chat-core").ChatLabels) => void;
|
|
11
|
+
setLauncherState: (state: string) => void;
|
|
11
12
|
nudgeHost: HTMLDivElement | null;
|
|
12
13
|
launcherButton: HTMLButtonElement | null;
|
|
13
14
|
role: string;
|
|
@@ -28,6 +28,7 @@ export declare function createEmbedShell(options: {
|
|
|
28
28
|
sheetHeightDvh?: number | undefined;
|
|
29
29
|
sheetMaxHeightPx?: number | undefined;
|
|
30
30
|
}) => void;
|
|
31
|
+
setLauncherState: (state: string) => void;
|
|
31
32
|
nudgeHost: HTMLDivElement | null;
|
|
32
33
|
launcherButton: HTMLButtonElement | null;
|
|
33
34
|
role: string;
|
|
@@ -8,6 +8,7 @@ export declare function createLauncherShell(options: {
|
|
|
8
8
|
root: HTMLDivElement;
|
|
9
9
|
panel: HTMLElement;
|
|
10
10
|
setLabels: (next: import("@webority/chat-core").ChatLabels) => void;
|
|
11
|
+
setLauncherState: (state: string) => void;
|
|
11
12
|
role: string;
|
|
12
13
|
nudgeHost: HTMLDivElement;
|
|
13
14
|
launcherButton: HTMLButtonElement;
|
|
@@ -28,6 +28,7 @@ export declare function createPageShell(options: {
|
|
|
28
28
|
sheetHeightDvh?: number | undefined;
|
|
29
29
|
sheetMaxHeightPx?: number | undefined;
|
|
30
30
|
}) => void;
|
|
31
|
+
setLauncherState: (state: string) => void;
|
|
31
32
|
nudgeHost: HTMLDivElement | null;
|
|
32
33
|
launcherButton: HTMLButtonElement | null;
|
|
33
34
|
role: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ChatLauncherSettings, ChatLook } from "@webority/chat-core";
|
|
2
|
-
export declare function createAvoidance(avoid: ChatLook["avoid"], launcher: Pick<ChatLauncherSettings, "liftAboveBanner" | "liftAboveFooter" | "stepAsideForMenus" | "switchOnDark">, element: HTMLElement): {
|
|
2
|
+
export declare function createAvoidance(avoid: ChatLook["avoid"], launcher: Pick<ChatLauncherSettings, "liftAboveBanner" | "liftAboveFooter" | "stepAsideForMenus" | "switchOnDark">, element: HTMLElement, setLauncherState?: (state: string) => void): {
|
|
3
3
|
destroy(): void;
|
|
4
4
|
};
|
|
@@ -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=`--_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){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.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 T=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],E={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function D(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function O({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a,mark:s}){let l=p(`div`,`wui-chat ${E[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`,T=!1,O=`bubble`,k=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`&&k&&t.push(`wui-chat-launcher--entrance-${k}`),(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`&&T&&t.push(`wui-chat-launcher--compact`),M!==`icon`&&t.push(`wui-chat-launcher--mark-${M}`),t.push(`wui-chat-launcher--reveal-${O}`,...e),h.className=t.join(` `)}function L(){y&&b&&(y.textContent=x||b.launcher)}function R(){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 z(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)),R())}function B(e){b=e,h&&(R(),L())}function V(e){if(w(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=D(e.launcherStyle)),e.compact!==void 0&&(T=e.compact),e.labelReveal!==void 0&&(O=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(k=e.entrance===`None`?null:D(e.entrance)),e.idle!==void 0&&(A=e.idle===`None`?`none`:D(e.idle)),e.phone!==void 0&&(j=e.phone),e.hoverLabel!==void 0&&(x=e.hoverLabel||null),e.launcherMark!==void 0&&(M=D(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&&t===`entering`&&(t=`idle`),t===`entering`&&!k&&(t=`idle`),f.dataset.launcher=t,I(),P(),L(),R()}return{root:l,panel:u,setOpen:z,setLabels:B,setAppearance:V,setLauncherState:F,nudgeHost:f,launcherButton:h,role:r}}var k=1e4,A=2e3,j=3e5,M=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),N=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function P(e){return M.has(I(e,`name`))?new t(`Blocked`,{message:L(e)}):N.has(I(e,`name`))?new t(`NoMicrophone`,{message:L(e)}):F(e)}function F(e){return e instanceof t?e:new t(`Failed`,{message:L(e)??String(e)})}function I(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function L(e){let t=I(e,`message`);return t==null?void 0:String(t)}function R(e){return typeof e==`object`&&!!e}function z(e){let t=I(e,`SpeechConfig`),n=I(e,`AudioConfig`),r=I(e,`NoMatchDetails`);return typeof I(t,`fromAuthorizationToken`)==`function`&&typeof I(n,`fromDefaultMicrophoneInput`)==`function`&&typeof I(n,`fromSpeakerOutput`)==`function`&&typeof I(r,`fromResult`)==`function`&&typeof I(e,`SpeechRecognizer`)==`function`&&typeof I(e,`SpeakerAudioDestination`)==`function`&&typeof I(e,`SpeechSynthesizer`)==`function`&&R(I(e,`PropertyId`))&&R(I(e,`ResultReason`))&&R(I(e,`NoMatchReason`))&&R(I(e,`CancellationReason`))}function B(e){if(!z(e))throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}var V=null;function H(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(B(t)):(V===null&&(V=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>B(I(e,`SpeechConfig`)?e:I(e,`default`))).catch(e=>{throw V=null,e})),V)}function U(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function W(e){let n=e.getToken,r=e.loadSdk??H,i=e.getLanguage??U,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,F(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,F(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,A),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(P(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(k));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.`}))},k),b=setTimeout(C,j)}catch(e){S(F(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(F(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 F(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var G=`data-wchat-printing`,K=`data-wchat-print-hide`,ee=`data-wchat-print-path`,te=`data-wchat-print-target`,ne=/* @__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(ee),e.removeAttribute(te);q.heading.remove(),document.documentElement.removeAttribute(G),window.removeEventListener(`afterprint`,q.onAfterPrint),q=null}}function re(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(ee,``),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||ne.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(te,``),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(G,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 ie(e,t){re(e,`conversation`,[],null,t)}function ae(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);re(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function oe(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function se({title:e,text:t}){if(!oe())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,ce=48*X;function le(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function ue(e,t=Date.now(),n){let r=le(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<ce){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 de(e,t){let n=le(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var fe=`wchat:auto-opened`,pe=`wchat:dismissed`,me=`button, a[href], input, select, textarea`,he=`input, textarea`;function Z(e){return!e.closest(`.wui-chat`)}function ge(e){return e instanceof Element&&e.matches(he)&&Z(e)}function _e(){return[...document.querySelectorAll(he)].some(e=>Z(e)&&e.value!==e.defaultValue)}function ve(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function ye(e){return e?[...document.querySelectorAll(me)].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 be(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(fe)||e.rememberDismissal&&sessionStorage.getItem(pe)||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&&_e()||n.isOpen()?!0:e.skipWhenCoversControl&&ye(n.panelRect())}function xe(e){return ge(document.activeElement)||ve(e.avoid.menuSelectors)||ve(e.avoid.autoOpenBusySelectors)}function Se(e,t,n){let r;function i(){r=void 0,be(e,t,n)||(xe(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(fe,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var Ce=.4,we=.5,Te=`rgba(0, 0, 0, 0)`,Ee=20,De=`wui-consent-banner[open]`;function Q(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Oe(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=Te,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 ke({r:e,g:t,b:n}){return .2126*Q(e)+.7152*Q(t)+.0722*Q(n)}function Ae(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<we))return ke(r)<Ce}return!1}function je(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function Me(e,t){let n=0;for(let r of e){let e=r.getBoundingClientRect();e.height!==0&&e.left<t.right&&e.right>t.left&&(n=Math.max(n,window.innerHeight-e.top))}return n>0?n+Ee:0}function Ne(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 Pe(e,t,n,r=e=>{n.dataset.launcher=e}){let i=n.ownerDocument.documentElement,a=t.switchOnDark?Oe(n.ownerDocument):null,o=0,s=!1,c=null;function l(){o=0;let l=[...t.liftAboveFooter?je(e.liftSelectors):[],...t.liftAboveBanner?je([De]):[]];if(c)for(let e of l)c.observe(e);n.style.setProperty(`--wui-chat-lift`,`${Me(l,n.getBoundingClientRect())}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&&Ne(e.menuSelectors);f&&!s?(r(`hidden`),n.inert=!0,s=!0):!f&&s&&(r(`idle`),n.inert=!1,s=!1);let p=a!==null&&Ae(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 Fe=`wchat:session-start`,Ie=`wchat:pages`,Le=`wchat:services`;function Re(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function ze(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function Be(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function Ve(e){sessionStorage.getItem(Fe)||sessionStorage.setItem(Fe,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=Re(Ie);i.includes(r)||(i.push(r),ze(Ie,i));let a=Be(r,e),o=Re(Le);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),ze(Le,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(Fe)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var $=8,He=`(min-width: 992px)`,Ue=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,We=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Ge=0;function Ke(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function qe(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.`);Ge+=1;let f=e.title??``,m=e.showNotCounted??!0,h=`wui-chat-explain-${Ge}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:U}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(We.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&&Ke(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(de(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?.(He)?.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(Ue)??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 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 We)Ke(t,e,x[e]);t.hidden=S}}}var Je=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function Ye(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(Je)].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 Xe(e){e?.isConnected&&e.focus()}function Ze(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var Qe=`wui-chat-lock`,$e=`wui-chat-scroll-lock`;function et(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(Qe);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent($e,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(Qe);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent($e,{detail:{locked:!1}}))}}}var tt={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}},nt=[`pointerdown`,`keydown`,`touchstart`],rt=`wchat:muted`,it=1e-4;function at(e,t){let n=t.get(rt)===`1`,r=null;function i(){for(let e of nt)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 nt)document.addEventListener(e,a);return{play(t){let i=tt[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(it,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(rt,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function ot(e,t={}){let n=t.language;return W({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var st=2e3,ct=500,lt=32,ut=16,dt=`data-wchat-switching`;function ft(e){return new Promise(t=>setTimeout(t,e))}function pt(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=ut,setTimeout(i,ut))};setTimeout(i,ut)})}async function mt(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(dt,``);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 pt(t.routeReady,st),await pt(r,ct),await ft(lt)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(dt)}}var ht=100,gt=12,_t=220;function vt(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>gt,c=r.height-(n||s?gt:0);n&&(c=Math.min(t.phone.sheetMaxHeightPx,Math.max(_t,c))),e.style.bottom=`${o}px`,e.style.maxHeight=`${c}px`}function s(){clearTimeout(i),i=setTimeout(o,ht)}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,P as C,S as D,b as E,c as F,l as I,o as L,m as M,v as N,O,g as P,W as S,h as T,se as _,at as a,ae as b,Xe as c,Ve as d,Pe as f,oe as g,ue as h,ot as i,_ as j,p as k,Ye as l,de as m,vt as n,et as o,Se as p,mt as r,Ze as s,e as t,qe as u,J as v,T as w,t as x,ie 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,F 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,L as trackLauncherBlock,l as trapTab,s as vibrate,p as watchAutoOpen,I as watchReducedMotion}from"./web-
|
|
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,F 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,L as trackLauncherBlock,l as trapTab,s as vibrate,p as watchAutoOpen,I as watchReducedMotion}from"./web-D_FBKpuC.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/chat-elements",
|
|
3
|
-
"version": "0.165.
|
|
3
|
+
"version": "0.165.3",
|
|
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.165.
|
|
47
|
+
"@webority/chat-core": "0.165.3",
|
|
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.165.
|
|
59
|
+
"@webority/chat-core": "0.165.3",
|
|
60
60
|
"@webority/theme": "0.192.0",
|
|
61
61
|
"@webority/ui-elements": "0.192.0",
|
|
62
62
|
"@vitest/coverage-v8": "5.1.0",
|
package/dist/web-BkMoHum8.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=`--_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){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.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 T=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],E={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function D(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function O({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a,mark:s}){let l=p(`div`,`wui-chat ${E[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`,T=!1,O=`bubble`,k=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`&&k&&t.push(`wui-chat-launcher--entrance-${k}`),e===`idle`&&A&&A!==`none`&&t.push(`wui-chat-launcher--idle-${A}`),f.className=t.join(` `)}function F(){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`&&T&&t.push(`wui-chat-launcher--compact`),M!==`icon`&&t.push(`wui-chat-launcher--mark-${M}`),t.push(`wui-chat-launcher--reveal-${O}`,...e),h.className=t.join(` `)}function I(){y&&b&&(y.textContent=x||b.launcher)}function L(){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())}),F(),P(),l.append(t,u)}else l.append(u);function R(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)),L())}function z(e){b=e,h&&(L(),I())}function B(e){if(w(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=D(e.launcherStyle)),e.compact!==void 0&&(T=e.compact),e.labelReveal!==void 0&&(O=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(k=e.entrance===`None`?null:D(e.entrance)),e.idle!==void 0&&(A=e.idle===`None`?`none`:D(e.idle)),e.phone!==void 0&&(j=e.phone),e.hoverLabel!==void 0&&(x=e.hoverLabel||null),e.launcherMark!==void 0&&(M=D(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&&t===`entering`&&(t=`idle`),t===`entering`&&!k&&(t=`idle`),f.dataset.launcher=t,F(),P(),I(),L()}return{root:l,panel:u,setOpen:R,setLabels:z,setAppearance:B,nudgeHost:f,launcherButton:h,role:r}}var k=1e4,A=2e3,j=3e5,M=/* @__PURE__ */ new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),N=/* @__PURE__ */ new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function P(e){return M.has(I(e,`name`))?new t(`Blocked`,{message:L(e)}):N.has(I(e,`name`))?new t(`NoMicrophone`,{message:L(e)}):F(e)}function F(e){return e instanceof t?e:new t(`Failed`,{message:L(e)??String(e)})}function I(e,t){return typeof e==`object`&&e||typeof e==`function`?Reflect.get(e,t):void 0}function L(e){let t=I(e,`message`);return t==null?void 0:String(t)}function R(e){return typeof e==`object`&&!!e}function z(e){let t=I(e,`SpeechConfig`),n=I(e,`AudioConfig`),r=I(e,`NoMatchDetails`);return typeof I(t,`fromAuthorizationToken`)==`function`&&typeof I(n,`fromDefaultMicrophoneInput`)==`function`&&typeof I(n,`fromSpeakerOutput`)==`function`&&typeof I(r,`fromResult`)==`function`&&typeof I(e,`SpeechRecognizer`)==`function`&&typeof I(e,`SpeakerAudioDestination`)==`function`&&typeof I(e,`SpeechSynthesizer`)==`function`&&R(I(e,`PropertyId`))&&R(I(e,`ResultReason`))&&R(I(e,`NoMatchReason`))&&R(I(e,`CancellationReason`))}function B(e){if(!z(e))throw new t(`Unavailable`,{message:`Speech is not available in this browser.`});return e}var V=null;function H(){let e=globalThis,t=`SpeechSDK`in e?e.SpeechSDK:void 0;return t?Promise.resolve(B(t)):(V===null&&(V=import(`microsoft-cognitiveservices-speech-sdk`).then(e=>B(I(e,`SpeechConfig`)?e:I(e,`default`))).catch(e=>{throw V=null,e})),V)}function U(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function W(e){let n=e.getToken,r=e.loadSdk??H,i=e.getLanguage??U,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,F(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,F(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,A),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(P(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(k));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.`}))},k),b=setTimeout(C,j)}catch(e){S(F(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(F(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 F(e)}}return{dictation:s,readAloud:c,streamsText:!0,startDictation:m,speak:h}}var G=`data-wchat-printing`,K=`data-wchat-print-hide`,ee=`data-wchat-print-path`,te=`data-wchat-print-target`,ne=/* @__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(ee),e.removeAttribute(te);q.heading.remove(),document.documentElement.removeAttribute(G),window.removeEventListener(`afterprint`,q.onAfterPrint),q=null}}function re(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(ee,``),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||ne.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(te,``),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(G,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 ie(e,t){re(e,`conversation`,[],null,t)}function ae(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);re(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function oe(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function se({title:e,text:t}){if(!oe())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,ce=48*X;function le(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function ue(e,t=Date.now(),n){let r=le(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<ce){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 de(e,t){let n=le(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}var fe=`wchat:auto-opened`,pe=`wchat:dismissed`,me=`button, a[href], input, select, textarea`,he=`input, textarea`;function Z(e){return!e.closest(`.wui-chat`)}function ge(e){return e instanceof Element&&e.matches(he)&&Z(e)}function _e(){return[...document.querySelectorAll(he)].some(e=>Z(e)&&e.value!==e.defaultValue)}function ve(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function ye(e){return e?[...document.querySelectorAll(me)].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 be(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(fe)||e.rememberDismissal&&sessionStorage.getItem(pe)||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&&_e()||n.isOpen()?!0:e.skipWhenCoversControl&&ye(n.panelRect())}function xe(e){return ge(document.activeElement)||ve(e.avoid.menuSelectors)||ve(e.avoid.autoOpenBusySelectors)}function Se(e,t,n){let r;function i(){r=void 0,be(e,t,n)||(xe(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(fe,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=void 0}}}var Ce=.4,we=.5,Te=`rgba(0, 0, 0, 0)`,Ee=20,De=`wui-consent-banner[open]`;function Q(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Oe(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=Te,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 ke({r:e,g:t,b:n}){return .2126*Q(e)+.7152*Q(t)+.0722*Q(n)}function Ae(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<we))return ke(r)<Ce}return!1}function je(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function Me(e,t){let n=0;for(let r of e){let e=r.getBoundingClientRect();e.height!==0&&e.left<t.right&&e.right>t.left&&(n=Math.max(n,window.innerHeight-e.top))}return n>0?n+Ee:0}function Ne(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 Pe(e,t,n){let r=n.ownerDocument.documentElement,i=t.switchOnDark?Oe(n.ownerDocument):null,a=0,o=!1,s=null;function c(){a=0;let c=[...t.liftAboveFooter?je(e.liftSelectors):[],...t.liftAboveBanner?je([De]):[]];if(s)for(let e of c)s.observe(e);n.style.setProperty(`--wui-chat-lift`,`${Me(c,n.getBoundingClientRect())}px`);let l=n.getBoundingClientRect(),u=l.height===0?0:Math.round(window.innerHeight-l.top);r.style.setProperty(`--wui-chat-launcher-block`,`${u}px`);let d=t.stepAsideForMenus&&Ne(e.menuSelectors);d&&!o?(n.dataset.launcher=`hidden`,n.inert=!0,o=!0):!d&&o&&(n.dataset.launcher=`idle`,n.inert=!1,o=!1);let f=i!==null&&Ae(n,e.darkSelectors,i);f&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!f&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function l(){a||=requestAnimationFrame(c)}typeof ResizeObserver==`function`&&(s=new ResizeObserver(l));let u=new MutationObserver(l);return u.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,l,{capture:!0,passive:!0}),window.addEventListener(`resize`,l),window.addEventListener(`load`,l),n.addEventListener(`animationend`,l),l(),{destroy(){a&&cancelAnimationFrame(a),a=0,s?.disconnect(),u.disconnect(),document.removeEventListener(`scroll`,l,{capture:!0}),window.removeEventListener(`resize`,l),window.removeEventListener(`load`,l),n.removeEventListener(`animationend`,l),o&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),r.style.removeProperty(`--wui-chat-launcher-block`)}}}var Fe=`wchat:session-start`,Ie=`wchat:pages`,Le=`wchat:services`;function Re(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function ze(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function Be(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function Ve(e){sessionStorage.getItem(Fe)||sessionStorage.setItem(Fe,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=Re(Ie);i.includes(r)||(i.push(r),ze(Ie,i));let a=Be(r,e),o=Re(Le);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),ze(Le,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(Fe)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var $=8,He=`(min-width: 992px)`,Ue=`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`,We=[`aria-haspopup`,`aria-expanded`,`aria-controls`,`aria-disabled`,`data-offline`,`title`],Ge=0;function Ke(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function qe(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.`);Ge+=1;let f=e.title??``,m=e.showNotCounted??!0,h=`wui-chat-explain-${Ge}`,v=()=>r(e.labels??{}),y=()=>({labels:v(),close:U}),b=n({request:i,...a===void 0?{}:{isEmpty:a},...l}),x=Object.fromEntries(We.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&&Ke(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(de(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?.(He)?.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(Ue)??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 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 We)Ke(t,e,x[e]);t.hidden=S}}}var Je=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function Ye(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(Je)].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 Xe(e){e?.isConnected&&e.focus()}function Ze(e,t){if(t||typeof navigator>`u`)return;let n=navigator;typeof n.vibrate==`function`&&n.vibrate(e)}var Qe=`wui-chat-lock`,$e=`wui-chat-scroll-lock`;function et(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(Qe);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent($e,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(Qe);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent($e,{detail:{locked:!1}}))}}}var tt={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}},nt=[`pointerdown`,`keydown`,`touchstart`],rt=`wchat:muted`,it=1e-4;function at(e,t){let n=t.get(rt)===`1`,r=null;function i(){for(let e of nt)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 nt)document.addEventListener(e,a);return{play(t){let i=tt[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(it,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(rt,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close().catch(e=>globalThis.reportError?.(e)),r=null}}}function ot(e,t={}){let n=t.language;return W({getToken:()=>e.getSpeechToken(),getLanguage:n?()=>n:void 0})}var st=2e3,ct=500,lt=32,ut=16,dt=`data-wchat-switching`;function ft(e){return new Promise(t=>setTimeout(t,e))}function pt(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=ut,setTimeout(i,ut))};setTimeout(i,ut)})}async function mt(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(dt,``);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 pt(t.routeReady,st),await pt(r,ct),await ft(lt)});Promise.allSettled([i.ready]);try{await i.updateCallbackDone}finally{await Promise.allSettled([i.finished])}}finally{r.removeAttribute(dt)}}var ht=100,gt=12,_t=220;function vt(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>gt,c=r.height-(n||s?gt:0);n&&(c=Math.min(t.phone.sheetMaxHeightPx,Math.max(_t,c))),e.style.bottom=`${o}px`,e.style.maxHeight=`${c}px`}function s(){clearTimeout(i),i=setTimeout(o,ht)}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,P as C,S as D,b as E,c as F,l as I,o as L,m as M,v as N,O,g as P,W as S,h as T,se as _,at as a,ae as b,Xe as c,Ve as d,Pe as f,oe as g,ue as h,ot as i,_ as j,p as k,Ye as l,de as m,vt as n,et as o,Se as p,mt as r,Ze as s,e as t,qe as u,J as v,T as w,t as x,ie as y};
|