@webority/chat-elements 0.135.0 → 0.135.1
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 +2 -2
- package/dist/types/WuiChat.d.ts +2 -0
- package/dist/types/starters.d.ts +1 -0
- package/package.json +3 -3
package/dist/chat.global.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
`),language:i});continue}if(Ge(t,r)){let i=We(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&Ue(t[r]);)a.push(We(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(Re.test(e)){n.push({type:`rule`}),r+=1;continue}let i=Le.exec(e);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]}),r+=1;continue}if(Ve.test(e)){let e=[];for(;r<t.length;){let n=Ve.exec(t[r]);if(!n)break;e.push(n[1]),r+=1}n.push({type:`quote`,lines:e});continue}let a=Je(e);if(a){let e=[];for(;r<t.length&&t[r].trim();){let n=Je(t[r]);if(n){if(n.depth===0&&n.ordered!==a.ordered)break;e.push(n)}else if(Ke(t,r))break;else e[e.length-1].text+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!Ke(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var Xe=e=>e.map(e=>e.type===`text`||e.type===`code`||e.type===`citation`?e.text:Xe(e.children)).join(``),Ze=e=>Xe(Oe(e));function Qe(e){switch(e.type){case`paragraph`:case`quote`:return Ze(e.lines.join(` `));case`heading`:return Ze(e.text);case`list`:return e.items.map(e=>Ze(e.text)).join(`. `);case`table`:return[e.header,...e.rows].map(e=>e.map(Ze).join(`, `)).join(`. `);case`code`:return e.text;case`rule`:return``}}function $e(e){return Ye(e).map(Qe).filter(Boolean).join(`
|
|
13
13
|
`)}var et=[`KB`,`MB`,`GB`],tt=e=>{if(e<1024)return`${e} B`;let t=e/1024,n=0;for(;t>=1024&&n<et.length-1;)t/=1024,n+=1;return`${t.toFixed(1)} ${et[n]}`},nt=new Intl.DateTimeFormat(`en-GB`,{timeZone:`Asia/Kolkata`,day:`2-digit`,month:`short`,year:`numeric`}),rt=e=>nt.format(new Date(e)).replace(/ /g,`-`),it=e=>e.flatMap(e=>e.kind===`Text`?[$e(e.text)]:e.kind===`Notice`?[e.text]:[]).filter(e=>e!==``).join(`
|
|
14
14
|
|
|
15
|
-
`).trim(),at=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ot=`-`,st=new Intl.DateTimeFormat(`en-IN`,{timeZone:`Asia/Kolkata`,day:`2-digit`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0}),ct=e=>{let t=Date.parse(e);if(Number.isNaN(t))return ot;let n=st.formatToParts(t),r=e=>n.find(t=>t.type===e)?.value??``;return`${r(`day`)}-${at[Number(r(`month`))-1]}-${r(`year`)}, ${r(`hour`)}:${r(`minute`)} ${r(`dayPeriod`).toUpperCase()}`},lt=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:0}),ut=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:3}),dt=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:2}),ft=new Intl.NumberFormat(`en-IN`,{minimumFractionDigits:2,maximumFractionDigits:2}),pt=/^\d{4}-\d{2}-\d{2}$/,mt=e=>pt.test(e)?Date.parse(`${e}T00:00:00+05:30`):Date.parse(e),ht=e=>e.map(e=>e.kind===`sup`?`^${e.text}`:e.text).join(``),gt=(e,t)=>{if(t===null)return ft.format(e/100);try{let n=new Intl.NumberFormat(`en-IN`,{style:`currency`,currency:t}),r=n.resolvedOptions().maximumFractionDigits;if(r===void 0)throw Error(`No fraction digits resolved for currency ${t}.`);return n.format(e/10**r)}catch(n){if(!(n instanceof RangeError))throw n;return`${ft.format(e/100)} ${t.toUpperCase()}`}},_t=(e,t,n)=>{if(e==null||e===``)return ot;if(t===`Text`)return String(e);if(t===`Date`){let t=mt(String(e));return Number.isNaN(t)?ot:nt.format(t).replace(/ /g,`-`)}if(t===`DateTimeUtc`)return ct(String(e));let r=Number(e);return Number.isFinite(r)?t===`Integer`?lt.format(r):t===`Decimal`?r!==0&&Math.abs(r)<.001?ht(ye(r)):ut.format(r):t===`Percent`?`${dt.format(r)}%`:gt(r,n):String(e)},vt=/^https?:\/\/([^@/?#:]+)(?::\d+)?(?=[/?#]|$)/i;function yt(e,t){if(typeof e!=`string`||e===``||/[\t\n\r]/.test(e))return!1;if(e[0]===`/`)return e[1]!==`/`&&e[1]!==`\\`;if(t===void 0||t.length===0)return!1;let n=vt.exec(e);if(n===null)return!1;let r=n[1].toLowerCase();return t.some(e=>e.toLowerCase()===r)}var bt={launcher:{style:`Round`,entrance:`Rise`,idle:`None`,labelReveal:`Bubble`,compact:!1,mark:`Icon`},panel:{motion:`Spring`,widthPx:420,maxHeightPx:650,bottomGapPx:80,height:`Fixed`,replyAvatars:!0},phone:{maxWidthPx:768,mode:`FullScreen`,sheetHeightDvh:85,sheetMaxHeightPx:640},input:{ring:!0,sendReveal:`OnText`,sendIcon:`arrow-up`},avoid:{liftSelectors:[`footer`,`.form-actions-sticky`,`.wui-tabbar`],menuSelectors:[`.offcanvas.show`,`wui-drawer[open]`,`[data-menu-open]`],darkSelectors:[`[data-theme='dark']`,`[data-bs-theme='dark']`],autoOpenOptOutSelector:`[data-chat-no-autoopen]`,autoOpenBusySelectors:[`[data-chat-busy]`]},motion:`On`,avatar:null};function xt(e){let t=e??{};return{launcher:{...bt.launcher,...t.launcher},panel:{...bt.panel,...t.panel},phone:{...bt.phone,...t.phone},input:{...bt.input,...t.input},avoid:{...bt.avoid,...t.avoid},motion:t.motion??bt.motion,avatar:t.avatar??bt.avatar}}var St=(e,t,n)=>n||!t.typingPause?0:Math.min(t.pauseBaseMs+t.pausePerCharMs*e.length,t.pauseMaxMs),Ct=Object.freeze(`VisitorChat.Starters.Nudges.ResumeLast.OpenTickets.History.Rename.Delete.SuggestedReplies.Stop.Retry.Edit.Regenerate.Sources.Rating.Copy.Share.Print.Attachments.RichAnswers.InputRequests.LeadCapture.Booking.Scripts.AiAnswers.HumanHandoff.Dictation.ReadAloud.VoiceClips.Sounds.AutoOpen.BehaviourStarters.LeadShortcuts.LeadRecap.FigureText.LinkHandoff.Explain.PanelSwitch`.split(`.`)),wt=()=>{let e={};for(let t of Ct)e[t]=!1;return e},Tt=(e,t)=>{let n={};for(let r of Ct)n[r]=e.features[r]===!0&&t?.[r]!==!1;return Object.freeze(n)},Et=(e,t)=>e===`/`||t===e||t.startsWith(`${e}/`),Dt=(e,{pathname:t,returning:n})=>{let r=e.start,i=r.greeting,a=r.starters;n&&(i=r.returningGreeting??i,a=r.returningStarters??a);let o=null;for(let e of r.pageRules)Et(e.pathPrefix,t)&&(o===null||e.pathPrefix.length>o.pathPrefix.length)&&(o=e);return o&&(i=o.greeting??i,a=o.starters??a),{greeting:i,starters:a}},Ot=(e,t)=>t.Nudges&&e.start.nudge?e.start.nudge:null,kt=e=>e.captcha.mode!==`Off`&&typeof e.captcha.siteKey==`string`&&e.captcha.siteKey!==``,At=(e,t,n,r)=>{let i=n.length>0?n:[o.thinking],a=i[(r%i.length+i.length)%i.length],s=t.length>0?t[t.length-1]:void 0;return e===`Phrases`?{label:a,steps:[],activeIndex:-1}:e===`Steps`?{label:s??a,steps:t.length>0?[...t]:[a],activeIndex:t.length>0?t.length-1:0}:{label:s??a,steps:[],activeIndex:-1}},jt=globalThis,Mt=new Set([`stalled`,`network`,`invalid-response`,`stream_ended`]),Nt=e=>!(e instanceof f)||Mt.has(e.code)?!0:e.status===408||e.status===429||e.status!==void 0&&e.status>=500;function Pt(e){let t=e.baseDelayMs??1e3,n=e.maxDelayMs??3e4,r=e.maxFailedAttempts??10,i=!1,a=null,s=null,c=null,l=0,u=0,d=0,p=e=>new Promise(t=>{c=t,s=jt.setTimeout(()=>{s=null,c=null,t()},e)});return(async()=>{for(;!i;){if(d>0&&(await e.beforeReconnect().catch(()=>void 0),i))return;e.onStatus(`Connecting`);let s=new jt.AbortController;a=s;let c=!1,m=!1,h=()=>{i||(c=!0,l=0,u=0,m||(m=!0,e.onStatus(`Live`)))};try{await e.watch(e.getCursor(),s.signal,h)}catch(t){if(i)return;if(!Nt(t)){e.onError(t),e.onStatus(`Lost`);return}}if(i)return;a=null;let g=Math.min(n,t*2**u);if(c||(l+=1,u+=1),l>=r){e.onError(new f(`connection_lost`,o.errorGeneric)),e.onStatus(`Lost`);return}await p(g),d+=1}})().catch(t=>e.onError(t)),{stop(){i||(i=!0,a?.abort(),a=null,s!==null&&(jt.clearTimeout(s),s=null),c?.(),c=null)}}}var Ft=e=>e.replace(/[-_]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\s+/g,` `).trim(),It=(e,t)=>e===`/`||t===e||t.startsWith(`${e}/`),Lt=(e,t)=>{let n=e.starters,r=null;for(let n of e.pageRules)It(n.pathPrefix,t.pathname)&&(r===null||n.pathPrefix.length>r.pathPrefix.length)&&(r=n);r?.starters&&(n=r.starters),t.returning&&e.returningStarters&&(n=e.returningStarters);let i=t.behaviour;if(t.behaviourStarters&&i&&e.rules){let t=e.rules.find(e=>(e.minTimeOnSiteSeconds===null||i.timeOnSiteSeconds>=e.minTimeOnSiteSeconds)&&(e.minScrollPercent===null||i.scrollPercent>=e.minScrollPercent)&&(e.minPagesViewed===null||i.pagesViewed>=e.minPagesViewed)&&(e.minServicesViewed===null||i.viewedServices.length>=e.minServicesViewed));t&&(n=[...t.starters,...n.slice(0,t.keepPageStarters)])}let a=e.behaviour?.recentServiceStarter,o=i?.viewedServices[i.viewedServices.length-1];if(t.behaviourStarters&&i&&a&&o!==void 0){let e=Ft(o),t=e.toLowerCase(),r=n.some(e=>e.label.toLowerCase().includes(t));if(e!==``&&!r){let t=a.replace(/\{service\}/g,e);n=[{id:`recent-service`,label:t,message:t,icon:null,variant:null},...n]}}let s=e.behaviour?.maxStarters;return s===void 0?[...n]:n.slice(0,s)},Rt=globalThis,zt=5e3,Bt=3e3,Vt=300,Ht=1200,Ut=e=>{if(Rt.requestAnimationFrame&&Rt.cancelAnimationFrame){let t=Rt.requestAnimationFrame(()=>e());return()=>Rt.cancelAnimationFrame?.(t)}let t=Rt.setTimeout(e,16);return()=>Rt.clearTimeout(t)},Wt=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{},Gt=e=>{let t=Wt(e);return{code:typeof t.code==`string`&&t.code?t.code:`unknown`,message:typeof t.message==`string`&&t.message?t.message:o.errorGeneric,resetsDateTimeUtc:typeof t.resetsDateTimeUtc==`string`?t.resetsDateTimeUtc:null}},Kt=(e,t)=>({id:e.publicId,author:e.author,createdDateTimeUtc:e.createdDateTimeUtc,parts:e.parts,sequence:e.sequence,rating:e.rating,ratingNote:e.ratingNote,streaming:!1,stored:!0,restored:t}),qt=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n<0?[...e,t]:e.map((e,r)=>r===n?t:e)},Jt=(e,t)=>{for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1},Yt=e=>e.flatMap(e=>e.kind===`Text`?[e.text]:[]).join(`
|
|
15
|
+
`).trim(),at=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ot=`-`,st=new Intl.DateTimeFormat(`en-IN`,{timeZone:`Asia/Kolkata`,day:`2-digit`,month:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0}),ct=e=>{let t=Date.parse(e);if(Number.isNaN(t))return ot;let n=st.formatToParts(t),r=e=>n.find(t=>t.type===e)?.value??``;return`${r(`day`)}-${at[Number(r(`month`))-1]}-${r(`year`)}, ${r(`hour`)}:${r(`minute`)} ${r(`dayPeriod`).toUpperCase()}`},lt=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:0}),ut=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:3}),dt=new Intl.NumberFormat(`en-IN`,{maximumFractionDigits:2}),ft=new Intl.NumberFormat(`en-IN`,{minimumFractionDigits:2,maximumFractionDigits:2}),pt=/^\d{4}-\d{2}-\d{2}$/,mt=e=>pt.test(e)?Date.parse(`${e}T00:00:00+05:30`):Date.parse(e),ht=e=>e.map(e=>e.kind===`sup`?`^${e.text}`:e.text).join(``),gt=(e,t)=>{if(t===null)return ft.format(e/100);try{let n=new Intl.NumberFormat(`en-IN`,{style:`currency`,currency:t}),r=n.resolvedOptions().maximumFractionDigits;if(r===void 0)throw Error(`No fraction digits resolved for currency ${t}.`);return n.format(e/10**r)}catch(n){if(!(n instanceof RangeError))throw n;return`${ft.format(e/100)} ${t.toUpperCase()}`}},_t=(e,t,n)=>{if(e==null||e===``)return ot;if(t===`Text`)return String(e);if(t===`Date`){let t=mt(String(e));return Number.isNaN(t)?ot:nt.format(t).replace(/ /g,`-`)}if(t===`DateTimeUtc`)return ct(String(e));let r=Number(e);return Number.isFinite(r)?t===`Integer`?lt.format(r):t===`Decimal`?r!==0&&Math.abs(r)<.001?ht(ye(r)):ut.format(r):t===`Percent`?`${dt.format(r)}%`:gt(r,n):String(e)},vt=/^https?:\/\/([^@/?#:]+)(?::\d+)?(?=[/?#]|$)/i;function yt(e,t){if(typeof e!=`string`||e===``||/[\t\n\r]/.test(e))return!1;if(e[0]===`/`)return e[1]!==`/`&&e[1]!==`\\`;if(t===void 0||t.length===0)return!1;let n=vt.exec(e);if(n===null)return!1;let r=n[1].toLowerCase();return t.some(e=>e.toLowerCase()===r)}var bt={launcher:{style:`Round`,entrance:`Rise`,idle:`None`,labelReveal:`Bubble`,compact:!1,mark:`Icon`},panel:{motion:`Spring`,widthPx:420,maxHeightPx:650,bottomGapPx:80,height:`Fixed`,replyAvatars:!0,greetingLoaderMs:0},phone:{maxWidthPx:768,mode:`FullScreen`,sheetHeightDvh:85,sheetMaxHeightPx:640},input:{ring:!0,sendReveal:`OnText`,sendIcon:`arrow-up`},avoid:{liftSelectors:[`footer`,`.form-actions-sticky`,`.wui-tabbar`],menuSelectors:[`.offcanvas.show`,`wui-drawer[open]`,`[data-menu-open]`],darkSelectors:[`[data-theme='dark']`,`[data-bs-theme='dark']`],autoOpenOptOutSelector:`[data-chat-no-autoopen]`,autoOpenBusySelectors:[`[data-chat-busy]`]},motion:`On`,avatar:null};function xt(e){let t=e??{};return{launcher:{...bt.launcher,...t.launcher},panel:{...bt.panel,...t.panel},phone:{...bt.phone,...t.phone},input:{...bt.input,...t.input},avoid:{...bt.avoid,...t.avoid},motion:t.motion??bt.motion,avatar:t.avatar??bt.avatar}}var St=(e,t,n)=>n||!t.typingPause?0:Math.min(t.pauseBaseMs+t.pausePerCharMs*e.length,t.pauseMaxMs),Ct=Object.freeze(`VisitorChat.Starters.Nudges.ResumeLast.OpenTickets.History.Rename.Delete.SuggestedReplies.Stop.Retry.Edit.Regenerate.Sources.Rating.Copy.Share.Print.Attachments.RichAnswers.InputRequests.LeadCapture.Booking.Scripts.AiAnswers.HumanHandoff.Dictation.ReadAloud.VoiceClips.Sounds.AutoOpen.BehaviourStarters.LeadShortcuts.LeadRecap.FigureText.LinkHandoff.Explain.PanelSwitch`.split(`.`)),wt=()=>{let e={};for(let t of Ct)e[t]=!1;return e},Tt=(e,t)=>{let n={};for(let r of Ct)n[r]=e.features[r]===!0&&t?.[r]!==!1;return Object.freeze(n)},Et=(e,t)=>e===`/`||t===e||t.startsWith(`${e}/`),Dt=(e,{pathname:t,returning:n})=>{let r=e.start,i=r.greeting,a=r.starters;n&&(i=r.returningGreeting??i,a=r.returningStarters??a);let o=null;for(let e of r.pageRules)Et(e.pathPrefix,t)&&(o===null||e.pathPrefix.length>o.pathPrefix.length)&&(o=e);return o&&(i=o.greeting??i,a=o.starters??a),{greeting:i,starters:a}},Ot=(e,t)=>t.Nudges&&e.start.nudge?e.start.nudge:null,kt=e=>e.captcha.mode!==`Off`&&typeof e.captcha.siteKey==`string`&&e.captcha.siteKey!==``,At=(e,t,n,r)=>{let i=n.length>0?n:[o.thinking],a=i[(r%i.length+i.length)%i.length],s=t.length>0?t[t.length-1]:void 0;return e===`Phrases`?{label:a,steps:[],activeIndex:-1}:e===`Steps`?{label:s??a,steps:t.length>0?[...t]:[a],activeIndex:t.length>0?t.length-1:0}:{label:s??a,steps:[],activeIndex:-1}},jt=globalThis,Mt=new Set([`stalled`,`network`,`invalid-response`,`stream_ended`]),Nt=e=>!(e instanceof f)||Mt.has(e.code)?!0:e.status===408||e.status===429||e.status!==void 0&&e.status>=500;function Pt(e){let t=e.baseDelayMs??1e3,n=e.maxDelayMs??3e4,r=e.maxFailedAttempts??10,i=!1,a=null,s=null,c=null,l=0,u=0,d=0,p=e=>new Promise(t=>{c=t,s=jt.setTimeout(()=>{s=null,c=null,t()},e)});return(async()=>{for(;!i;){if(d>0&&(await e.beforeReconnect().catch(()=>void 0),i))return;e.onStatus(`Connecting`);let s=new jt.AbortController;a=s;let c=!1,m=!1,h=()=>{i||(c=!0,l=0,u=0,m||(m=!0,e.onStatus(`Live`)))};try{await e.watch(e.getCursor(),s.signal,h)}catch(t){if(i)return;if(!Nt(t)){e.onError(t),e.onStatus(`Lost`);return}}if(i)return;a=null;let g=Math.min(n,t*2**u);if(c||(l+=1,u+=1),l>=r){e.onError(new f(`connection_lost`,o.errorGeneric)),e.onStatus(`Lost`);return}await p(g),d+=1}})().catch(t=>e.onError(t)),{stop(){i||(i=!0,a?.abort(),a=null,s!==null&&(jt.clearTimeout(s),s=null),c?.(),c=null)}}}var Ft=e=>e.replace(/[-_]+/g,` `).replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/\s+/g,` `).trim(),It=(e,t)=>e===`/`||t===e||t.startsWith(`${e}/`),Lt=(e,t)=>{let n=e.starters,r=null;for(let n of e.pageRules)It(n.pathPrefix,t.pathname)&&(r===null||n.pathPrefix.length>r.pathPrefix.length)&&(r=n);r?.starters&&(n=r.starters),t.returning&&e.returningStarters&&(n=e.returningStarters);let i=t.behaviour;if(t.behaviourStarters&&i&&e.rules){let t=e.rules.find(e=>(e.minTimeOnSiteSeconds===null||i.timeOnSiteSeconds>=e.minTimeOnSiteSeconds)&&(e.minScrollPercent===null||i.scrollPercent>=e.minScrollPercent)&&(e.minPagesViewed===null||i.pagesViewed>=e.minPagesViewed)&&(e.minServicesViewed===null||i.viewedServices.length>=e.minServicesViewed));t&&(n=[...t.starters,...n.slice(0,t.keepPageStarters)])}let a=e.behaviour?.recentServiceStarter,o=i?.viewedServices[i.viewedServices.length-1];if(t.behaviourStarters&&i&&a&&o!==void 0){let e=Ft(o),t=e.toLowerCase(),r=n.some(e=>e.label.toLowerCase().includes(t));if(e!==``&&!r){let t=a.replace(/\{service\}/g,e);n=[{id:`recent-service`,label:t,message:t,icon:null,variant:null},...n]}}let s=e.behaviour?.maxStarters;return s===void 0?[...n]:n.slice(0,s)},Rt=globalThis,zt=5e3,Bt=3e3,Vt=300,Ht=1200,Ut=e=>{if(Rt.requestAnimationFrame&&Rt.cancelAnimationFrame){let t=Rt.requestAnimationFrame(()=>e());return()=>Rt.cancelAnimationFrame?.(t)}let t=Rt.setTimeout(e,16);return()=>Rt.clearTimeout(t)},Wt=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{},Gt=e=>{let t=Wt(e);return{code:typeof t.code==`string`&&t.code?t.code:`unknown`,message:typeof t.message==`string`&&t.message?t.message:o.errorGeneric,resetsDateTimeUtc:typeof t.resetsDateTimeUtc==`string`?t.resetsDateTimeUtc:null}},Kt=(e,t)=>({id:e.publicId,author:e.author,createdDateTimeUtc:e.createdDateTimeUtc,parts:e.parts,sequence:e.sequence,rating:e.rating,ratingNote:e.ratingNote,streaming:!1,stored:!0,restored:t}),qt=(e,t)=>{let n=e.findIndex(e=>e.id===t.id);return n<0?[...e,t]:e.map((e,r)=>r===n?t:e)},Jt=(e,t)=>{for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1},Yt=e=>e.flatMap(e=>e.kind===`Text`?[e.text]:[]).join(`
|
|
16
16
|
|
|
17
17
|
`),Xt=e=>e.flatMap(e=>e.kind===`File`?[{publicId:e.attachmentId,fileName:e.fileName,contentType:e.contentType,length:e.length}]:[]),Zt=e=>{let t=Wt(e);return{fileName:typeof t.name==`string`?t.name:``,contentType:typeof t.type==`string`?t.type:``,length:typeof t.size==`number`?t.size:null}},Qt=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n].id&&e.label===t[n].label&&e.message===t[n].message),$t=e=>{for(let t of e){if(!t.startsWith(`Enquiry type:`))continue;let e=t.slice(13).trim();return e===``?null:e}return null},en=(e,t)=>{if(t!==`WithAgent`)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];for(let e=n.parts.length-1;e>=0;--e){let t=n.parts[e];if(t.kind===`Handoff`){if(t.state===`Left`||t.state===`Ended`)return null;if(t.state===`Joined`&&t.agent)return t.agent}}if(n.author.kind===`Agent`)return{displayName:n.author.displayName??``,avatarUrl:n.author.avatarUrl}}return null},tn=(e,t)=>{(e.cursor===null||t>e.cursor)&&(e.cursor=t)},nn=(e,t)=>{let n=[];e!==``&&n.push({kind:`Text`,text:e});for(let e of t)n.push({kind:`File`,attachmentId:e.publicId,fileName:e.fileName,contentType:e.contentType,length:e.length});return n},rn=e=>{let t=Yt(e.parts);return{wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:null,attachments:Xt(e.parts)}},an=e=>({profile:null,profileError:null,features:wt(),conversationId:null,conversationState:`Open`,title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:e?.get(`wchat:muted`)===`1`,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),on=(e,t)=>{let n=s(t.labels),r=t.schedule??Ut,i=t.prefs,a=new Set,c=an(i),l=0,u=null,d=null,p=0,m=0,h=null,g=null,_=new Map,v=new Set,y=new Map,b=new Set,x=new Map,S={name:null,email:null,phone:null},C=new Set,w=null,T=null,E=null,D=null,O=null,k=!0,A=!1,j=new Set,ee=new Map,te=Promise.resolve(),ne=0,re=()=>t.pathname?.()??Rt.location?.pathname??`/`,ie=()=>t.reducedMotion?.()===!0||c.profile?.experience.motion===!1,ae=()=>c.streaming||c.thinking,oe=e=>{if(!e.profile)return{...e,greeting:null,starters:[]};let n=re(),r=e.lastConversation!==null,i=Dt(e.profile,{pathname:n,returning:r}).greeting,a=Lt(e.profile.start,{pathname:n,returning:r,behaviour:t.behaviour?.()??null,behaviourStarters:e.features.BehaviourStarters});return{...e,greeting:i,starters:Qt(e.starters,a)?e.starters:a}},se=()=>{w!==null&&(Rt.clearTimeout(w),w=null)},ce=()=>{E!==null&&(Rt.clearTimeout(E),E=null)},le=e=>e.flatMap(e=>e.parts.flatMap(e=>e.kind===`Action`&&e.actionKind===`ChatLeadCapture`&&e.state===`Done`?[{actionId:e.actionId,leadType:$t(e.lines)}]:[])),ue=()=>{S.name=null,S.email=null,S.phone=null,C.clear()},de=e=>{for(let t of le(e))C.add(t.actionId)},fe=()=>{for(let e of le(c.messages))C.has(e.actionId)||(C.add(e.actionId),t.onEvent?.(`leadSubmitted`,{conversationId:c.conversationId,fields:{name:S.name,email:S.email,phone:S.phone},leadType:e.leadType}))},pe=(e,t)=>{let n=c.messages.flatMap(e=>e.parts).find(t=>t.kind===`InputRequest`&&t.requestId===e);if(n)for(let e of n.fields){let n=t[e.key];typeof n==`string`&&n.trim()!==``&&(e.type===`Email`?S.email=n.trim():e.type===`Phone`?S.phone=n.trim():(e.type===`Name`||e.key.toLowerCase()===`name`)&&(S.name=n.trim()))}},me=e=>{let t=O;t!==null&&(O=null,t.handle?.stop(),e!==null&&M({live:e}))},he=()=>!A&&k&&c.features.HumanHandoff&&c.conversationId!==null&&(c.conversationState===`WaitingForAgent`||c.conversationState===`WithAgent`),ge=()=>{if(!he()){O!==null&&me(`Off`);return}let t=c.conversationId;if(t===null||O!==null&&O.conversationId===t)return;me(null);let n={conversationId:t,cursor:null,handle:null};O=n;let r=Pt({watch:(r,i,a)=>e.watchConversation(t,{afterSequence:r,signal:i,onCursor:e=>tn(n,e),onEvent:e=>{a(),O===n&&(e.name===`messageCompleted`&&tn(n,e.data.message.sequence),Ie(e,`live`,()=>O===n))}}),beforeReconnect:()=>Le(),getCursor:()=>{let e=n.cursor;for(let t of c.messages)t.sequence!==null&&(e===null||t.sequence>e)&&(e=t.sequence);return e},onStatus:e=>{O===n&&c.live!==e&&M({live:e})},onError:e=>Se(e)});n.handle=r,O!==n&&r.stop()},M=e=>{let t={...c,...e};c.conversationState===`WithAgent`&&t.conversationState!==`WithAgent`&&t.agentTyping!==null&&(se(),t.agentTyping=null),(e.messages!==void 0||e.conversationState!==void 0)&&(t.agent=en(t.messages,t.conversationState)),c=oe(t);for(let e of a)e();e.messages!==void 0&&fe(),ge()},_e=(e,t)=>M({attachments:c.attachments.map(n=>n.key===e?{...n,...t}:n)}),ve=()=>{if(_.size===0)return;let e=[..._.values()];_.clear(),M({messages:c.messages.map(t=>{let n=e.filter(e=>e.messageId===t.id);if(n.length===0)return t;let r=t.parts.map((e,t)=>{let r=n.filter(e=>e.index===t).map(e=>e.text).join(``);return e.kind===`Text`&&r!==``?{...e,text:e.text+r}:e});return{...t,parts:r}})})},ye=()=>{_.clear(),d?.(),d=null},be=(e,t,n)=>{let i=`${e}#${t}`,a=_.get(i);_.set(i,{messageId:e,index:t,text:(a?.text??``)+n}),d||=r(()=>{d=null,ve()})},xe=()=>{ve(),l+=1,u?.abort(),u=null},Se=e=>{if(t.onError)t.onError(e);else throw e},Ce=()=>{for(let e of x.values())e.abort();x.clear();for(let t of b){let n=y.get(t);n&&e.deleteAttachment(n.publicId).catch(Se)}b.clear(),y.clear()},we=e=>{let t=y.get(e);if(!t)throw Error(`No uploaded file for composer attachment ${e}.`);return t},Te=async(t,r)=>{let i=new Rt.AbortController;x.set(t,i);let a;try{a=await e.uploadAttachment(r,{signal:i.signal,onProgress:e=>{x.get(t)===i&&_e(t,{progress:e})}})}catch{x.get(t)===i&&(x.delete(t),_e(t,{status:`Failed`,progress:null,error:n.attachmentFailed}));return}x.get(t)===i?(x.delete(t),y.set(t,a),b.add(t),_e(t,{status:`Ready`,progress:null})):e.deleteAttachment(a.publicId).catch(Se)},Ee=e=>{let n={...Wt(t.pageContext?.()),path:re(),behaviour:t.behaviour?.()??null};return e&&(n.attribution=t.attribution?.()??null),n},De=async()=>{let e=c.profile?.captcha;if(!e||!t.getCaptchaToken||e.mode===`Off`&&!e.siteKey)return null;let r=null;try{r=await t.getCaptchaToken(e.action)}catch{}if(!r)throw new f(`captcha_unavailable`,n.captchaUnavailable);return r},Oe=(e,t,n)=>{let r=qt(c.messages,Kt(e,!1));M(n?{messages:r,messagesLeftToday:t??c.messagesLeftToday,steps:[],thinking:!1}:{messages:r})},ke=e=>{let t=c.profile?.experience.pacing;return!t||v.has(e.publicId)||e.author.kind!==`Assistant`&&e.author.kind!==`Script`?0:St(it(e.parts),t,ie())},Ae=(e,t,n,r,i)=>{ne+=1,M({pending:{typing:!0,authorKind:e.author.kind}}),te=te.then(()=>new Promise(e=>Rt.setTimeout(e,n))).then(()=>{--ne,r()&&Oe(e,t,i),ne===0&&M({pending:null})})},je=(e,t,n)=>{let r=[...e];return r[t]=n,r},Me=(e,t)=>c.messages.map(n=>n.id===e?t(n):n),Ne=e=>c.messages.some(t=>t.id===e),Pe=()=>{se(),c.agentTyping!==null&&M({agentTyping:null})},Fe=e=>{se(),w=Rt.setTimeout(()=>{w=null,M({agentTyping:null})},zt),M({agentTyping:{displayName:e}})},Ie=(e,t,n)=>{if(!n())return;let r=t===`turn`;if(e.name===`partDelta`)v.add(e.data.messageId),be(e.data.messageId,e.data.index,e.data.text);else switch(ve(),e.name){case`messageStarted`:{let t=e.data.message;if(t.author.kind===`Agent`&&Pe(),Ne(t.publicId))break;M({messages:[...c.messages,{id:t.publicId,author:t.author,createdDateTimeUtc:t.createdDateTimeUtc,parts:[...t.parts],sequence:t.sequence,rating:t.rating,ratingNote:t.ratingNote,streaming:!0,stored:!1,restored:!1}]});break}case`partStarted`:{let{messageId:t,index:n,part:i}=e.data;if(!Ne(t))break;M({messages:Me(t,e=>({...e,parts:je(e.parts,n,i)})),...r?{thinking:!1}:{}});break}case`partCompleted`:{let{messageId:t,index:n,part:r}=e.data;if(!Ne(t))break;M({messages:Me(t,e=>({...e,parts:je(e.parts,n,r)}))});break}case`messageReset`:{let{messageId:t}=e.data;if(!Ne(t))break;for(let e of[..._.keys()])_.get(e)?.messageId===t&&_.delete(e);M({messages:Me(t,e=>({...e,parts:[]})),...r?{thinking:!0,steps:[]}:{}});break}case`step`:{if(!r)break;let t=e.data.label;c.steps[c.steps.length-1]!==t&&M({steps:[...c.steps,t]});break}case`messageCompleted`:{let{message:t,messagesLeftToday:i}=e.data;t.author.kind===`Agent`&&Pe();let a=ke(t);a>0||ne>0?Ae(t,i,a,n,r):Oe(t,i,r);break}case`conversationUpdated`:{let t=e.data;M({conversationId:t.conversationId,conversationState:t.state,title:t.title,continuesConversationId:t.continuesConversationId});break}case`typing`:e.data.authorKind===`Agent`&&Fe(e.data.displayName)}},Le=async()=>{let t=c.conversationId;if(t===null)return;let n=l;try{let r=await e.getConversation(t);if(n!==l)return;let i=new Set(c.messages.filter(e=>e.restored).map(e=>e.id));M({messages:r.messages.map(e=>Kt(e,i.has(e.publicId))),title:r.title,conversationState:r.state,continuesConversationId:r.continuesConversationId})}catch(e){Se(e)}},Re=async(n,r,i)=>{let a=l,o=new Rt.AbortController,s=()=>a===l&&!o.signal.aborted;u=o;let d=c.conversationId===null;p+=1;let f={id:`local-${p}`,author:{kind:`Visitor`,displayName:null,avatarUrl:null},createdDateTimeUtc:new Date().toISOString(),parts:nn(n.displayText,n.attachments),sequence:null,rating:null,ratingNote:null,streaming:!1,stored:!1,restored:!1};i&&(b.clear(),y.clear()),M({messages:[...r,f],thinking:!0,streaming:!0,steps:[],turnError:null,stopped:!1,...i?{editing:null,attachments:[]}:{}});try{let t=await De();await e.send({conversationId:c.conversationId,text:n.wireText,quickReplyId:n.quickReplyId,attachmentIds:n.attachments.map(e=>e.publicId),replacesMessageId:n.replacesMessageId,pageContext:Ee(d),captchaToken:t},{signal:o.signal,onEvent:e=>Ie(e,`turn`,s)})}catch(e){if(ve(),!s())return;let t=Gt(e);M({messages:c.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,turnError:t,...t.code===`daily_limit`?{messagesLeftToday:0}:{},...t.code===`conversation_not_found`?{conversationId:null}:{}});return}finally{u===o&&(u=null)}if(await te,!s())return;ve(),M({thinking:!1,streaming:!1}),await Le();let m=c.conversationId;d&&m!==null&&m!==h&&(h=m,t.onEvent?.(`chatStarted`,{conversationId:m}))},ze=e=>M({messages:c.messages.map(t=>({...t,parts:t.parts.map(t=>t.kind===`Action`&&t.actionId===e.actionId?{...t,state:e.state,decidedDateTimeUtc:e.decidedDateTimeUtc,note:e.note}:t)}))}),Be=async()=>{try{M({openTickets:await e.listOpenTickets()})}catch{}},Ve=async()=>{let n;try{n=await e.getProfile(t.screen)}catch(e){M({profileError:Gt(e)});return}let r=Tt(n,t.narrow);if(M({profile:n,profileError:null,features:r,messagesLeftToday:n.messagesLeftToday}),r.OpenTickets&&Be(),r.ResumeLast&&r.History)try{let t=await e.listConversations({page:1,pageSize:1});M({lastConversation:t.items[0]??null})}catch{}t.conversationId&&await tt(t.conversationId)},He=()=>(g||=Ve(),g),Ue=async e=>{let t=typeof e==`string`?e.trim():``,n=c.attachments.filter(e=>e.status===`Ready`);if(t===``&&n.length===0||c.streaming||c.attachments.some(e=>e.status===`Uploading`))return;let r=c.messages,i=null;if(c.editing){let e=c.messages.findIndex(e=>e.id===c.editing?.messageId),t=c.messages[e];if(!t?.stored)return;i=t.id,r=c.messages.slice(0,e)}let a=n.map(e=>we(e.key));await Re({wireText:t===``?null:t,displayText:t,quickReplyId:null,replacesMessageId:i,attachments:a},r,!0)},We=async e=>{e.action!==`Send`||ae()||(e.id===`handoff.request`&&c.features.HumanHandoff&&c.conversationId!==null&&!c.handoffPending?await pt():await Re({wireText:null,displayText:e.label,quickReplyId:e.id,replacesMessageId:null,attachments:[]},c.messages,!1))},Ge=async(r,i,a=null)=>{if(c.streaming)return{ok:!1,errors:{},message:n.errorGeneric};let o=l,s=new Rt.AbortController,d=()=>o===l&&!s.signal.aborted;u=s,pe(r,i),M({streaming:!0,thinking:!0});try{let n=await De();await e.answerInput(r,{values:i,codes:a,captchaToken:n,attribution:t.attribution?.()??null},{signal:s.signal,onEvent:e=>Ie(e,`turn`,d)})}catch(e){return ve(),M({thinking:!1,streaming:!1}),s.signal.aborted?{ok:!1,errors:{},message:n.errorGeneric}:e instanceof f&&e.code===`validation_failed`?{ok:!1,errors:e.errors??{},message:e.message}:e instanceof f&&e.code===`input_request_closed`?(await Le(),{ok:!1,errors:{},message:e.message}):{ok:!1,errors:{},message:Gt(e).message}}finally{u===s&&(u=null)}return await te,d()&&(ve(),M({thinking:!1,streaming:!1}),t.onEvent?.(`inputSubmitted`,{requestId:r}),await Le()),{ok:!0}},Ke=async n=>{let r=await e.confirmAction(n);ze(r),t.onEvent?.(`chatActionConfirmed`,{actionId:r.actionId,kind:r.actionKind}),await Le()},qe=async(t,n)=>{ze(await e.rejectAction(t,n)),await Le()},Je=()=>{if(!c.streaming)return;ye();let e=u;u=null,e?.abort(),M({messages:c.messages.filter(e=>!e.streaming),thinking:!1,streaming:!1,stopped:!0,steps:[],pending:null})},Ye=async()=>{if(c.streaming||c.turnError===null&&!c.stopped)return;let e=Jt(c.messages,e=>e.author.kind===`Visitor`);e<0||await Re(rn(c.messages[e]),c.messages.slice(0,e),!1)},Xe=async()=>{if(ae())return;let e=Jt(c.messages,e=>e.author.kind===`Visitor`&&e.stored);if(e<0)return;let t=c.messages[e];await Re({...rn(t),replacesMessageId:t.id},c.messages.slice(0,e),!1)},Ze=e=>{let t=c.messages.find(t=>t.id===e);t?.stored&&t.author.kind===`Visitor`&&(Ce(),M({editing:{messageId:e,text:Yt(t.parts)},attachments:[]}))},Qe=()=>{c.editing&&(Ce(),M({editing:null,attachments:[]}))},$e=async e=>{let t=c.profile;if(!t||!c.features.Attachments)return;let r=t.limits,i=r.maxAttachments-c.attachments.filter(e=>e.status!==`Failed`).length,a=[],o=[];for(let t of e){let e=Zt(t);m+=1;let s=`file-${m}`,c={key:s,fileName:e.fileName,contentType:e.contentType,length:e.length??0};i<=0?a.push({...c,status:`Failed`,progress:null,error:n.attachmentLimit(r.maxAttachments)}):e.length!==null&&e.length>r.maxFileBytes||!r.contentTypes.includes(e.contentType)?a.push({...c,status:`Failed`,progress:null,error:n.attachmentFailed}):(--i,a.push({...c,status:`Uploading`,progress:0,error:null}),o.push({key:s,file:t}))}M({attachments:[...c.attachments,...a]}),await Promise.all(o.map(({key:e,file:t})=>Te(e,t)))},et=async t=>{let n=x.get(t);n&&(x.delete(t),n.abort());let r=b.has(t)?y.get(t):void 0;r&&await e.deleteAttachment(r.publicId),b.delete(t),y.delete(t),M({attachments:c.attachments.filter(e=>e.key!==t)})};async function tt(t){xe();let n=l;M({messages:[],conversationId:null,loadError:null,loading:!0,editing:null,thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1});try{let r=await e.getConversation(t);if(n!==l)return;let i=r.messages.map(e=>Kt(e,!0));ue(),de(i),M({messages:i,conversationId:r.publicId,title:r.title,conversationState:r.state,continuesConversationId:r.continuesConversationId})}catch(e){if(n!==l)return;M({loadError:Gt(e)})}finally{n===l&&M({loading:!1})}}let nt=async()=>{let e=c.lastConversation;e&&await tt(e.publicId)},rt=()=>{Ce(),xe(),ye(),ue(),M({messages:[],conversationId:null,title:null,conversationState:`Open`,continuesConversationId:null,loadError:null,loading:!1,editing:null,attachments:[],thinking:!1,streaming:!1,steps:[],turnError:null,stopped:!1,pending:null}),c.features.OpenTickets&&Be()},at=(e,t,n)=>{M({messages:Me(e,e=>({...e,rating:t,ratingNote:n}))})},ot=async(n,r,i)=>{let a=c.messages.find(e=>e.id===n);if(!a?.stored)throw Error(`Only a stored reply can be rated.`);let o={rating:a.rating,ratingNote:a.ratingNote},s=typeof i==`string`&&i.trim()?i.trim():null;at(n,r,s);try{await e.rateMessage(n,{rating:r,note:s})}catch(e){throw at(n,o.rating,o.ratingNote),e}t.onEvent?.(`rated`,{messageId:n,rating:r})},st=e=>{let n=c.open,r=e?.trigger??`manual`,a=e?.draft,o={open:!0};typeof a==`string`&&a.trim()!==``&&(o.draft=a),!n&&r===`auto`&&i?.set(`wchat:auto-opened`,`1`),M(o),n||t.onEvent?.(`chatOpened`,{layout:t.layout??null,trigger:r})},ct=e=>{c.open&&(i?.set(`wchat:dismissed`,`1`),M({open:!1}),t.onEvent?.(`chatClosed`,{layout:t.layout??null,reason:e}))},lt=e=>{i?.set(`wchat:muted`,e?`1`:`0`),M({muted:e}),t.onEvent?.(`chatSoundToggled`,{muted:e})},ut=async e=>{ae()||(t.onEvent?.(`chatLeadSkipped`,{requestId:e}),await Re({wireText:null,displayText:n.skip,quickReplyId:`lead.skip`,replacesMessageId:null,attachments:[]},c.messages,!1))},dt=async()=>{ae()||(t.onEvent?.(`chatLeadCancelled`,{}),await Re({wireText:null,displayText:n.cancel,quickReplyId:`lead.cancel`,replacesMessageId:null,attachments:[]},c.messages,!1))},ft=async(e,t)=>{ae()||c.messages.some(t=>t.parts.some(t=>t.kind===`Action`&&t.actionId===e))&&await Re({wireText:null,displayText:n.editSomething,quickReplyId:`lead.edit:${t}`,replacesMessageId:null,attachments:[]},c.messages,!1)},pt=async n=>{if(!c.features.HumanHandoff)throw new f(`chat_feature_off`,o.errorGeneric,403);let r=c.conversationId;if(r===null)throw new f(`conversation_required`,o.errorGeneric);if(c.streaming||c.handoffPending)throw new f(`busy`,o.errorGeneric);let i=new Rt.AbortController;D=i,M({handoffPending:!0}),t.onEvent?.(`chatHandoffRequested`,{conversationId:r});try{await e.requestHandoff({conversationId:r,reason:n??null},{signal:i.signal,onEvent:e=>Ie(e,`handoff`,()=>!i.signal.aborted)})}catch(e){throw M({messages:c.messages.filter(e=>!e.streaming),handoffPending:!1}),e}finally{D===i&&(D=null)}M({handoffPending:!1}),await Le(),t.onEvent?.(`chatHandoff`,{destination:`person`})},mt=()=>{let t=c.conversationId;if(!c.features.HumanHandoff||t===null||c.conversationState!==`WithAgent`)return;let n=Date.now();T!==null&&n-T<Bt||(T=n,e.sendTyping(t).catch(()=>void 0))},ht=e=>{k=e,ge()},gt=()=>{c.live===`Lost`&&he()&&(me(null),ge())},_t=e=>{if(t.reducedMotion?.()===!0)return Vt;let n=e.navigateAfterMs;if(typeof n==`number`&&Number.isFinite(n)&&n>=0)return n;let r=c.profile?.experience.pacing.handoffPauseMs;return typeof r==`number`&&Number.isFinite(r)?r:Ht},vt=()=>{ce(),c.handoffPause&&M({handoffPause:!1})};return{client:e,getState:()=>c,subscribe:e=>(a.add(e),g||He(),()=>{a.delete(e)}),load:He,submit:Ue,chooseQuickReply:We,answerInput:Ge,confirmAction:Ke,rejectAction:qe,stop:Je,retry:Ye,regenerate:Xe,startEdit:Ze,cancelEdit:Qe,attach:$e,removeAttachment:et,openConversation:tt,resumeLast:nt,newConversation:rt,rate:ot,open:st,close:ct,setMuted:lt,skipField:ut,cancelLead:dt,editLeadField:ft,requestHandoff:pt,notifyTyping:mt,setLiveActive:ht,resumeLive:gt,beginHandoff:(e,n)=>{c.handoffPause||(M({handoffPause:!0}),t.onEvent?.(`chatHandoff`,{destination:e.id}),E=Rt.setTimeout(()=>{E=null;try{n()}catch(e){vt(),Se(e)}},_t(e)))},endHandoffPause:vt,consumeDraft:()=>{c.draft!==null&&M({draft:null})},loadAttachmentUrl:t=>{let r=ee.get(t);if(r)return r;let i=(async()=>{let r=Rt.Blob,i=Rt.URL;if(!r||typeof i?.createObjectURL!=`function`)throw new f(`unsupported`,n.errorGeneric);let a=await e.getAttachment(t);if(A)throw new f(`aborted`,n.errorGeneric);let o=i.createObjectURL(new r([a]));return j.add(o),o})();return ee.set(t,i),i.catch(()=>{ee.get(t)===i&&ee.delete(t)}),i},reset:()=>{Ce(),ye(),xe(),g=null,te=Promise.resolve(),ne=0,v.clear(),h=null,ue(),se(),ce(),M(an(i))},dispose:()=>{a.clear(),A=!0,l+=1;let e=u;u=null,e?.abort(),D?.abort(),D=null,ce(),se(),me(null),Ce(),ye();for(let e of j)Rt.URL?.revokeObjectURL?.(e);j.clear(),ee.clear(),M({attachments:[],editing:null,agentTyping:null})}}},sn=e=>{let t=-1;for(let n=e.length-1;n>=0;--n)if(e[n].parts.some(e=>e.kind===`Handoff`)){t=n;break}let n=new Set;for(let r=0;r<t;r+=1)n.add(e[r].id);return n},cn=(e,t)=>({get features(){return e.getState().features},labels:t.labels,get isLast(){let n=e.getState().messages;return n[n.length-1]?.id===t.messageId},get busy(){let t=e.getState();return t.streaming||t.thinking},get handoffPause(){return e.getState().handoffPause},get handoffSettled(){return sn(e.getState().messages).has(t.messageId)},chooseQuickReply(t){e.chooseQuickReply(t)},skipInput(t){e.skipField(t)},cancelLead(){e.cancelLead()},answerInput:(t,n,r)=>e.answerInput(t,n,r),uploadInputFile:async(t,n)=>(await e.client.uploadAttachment(t,n?{onProgress:n}:{})).publicId,sendOtp:(t,n)=>e.client.sendOtp(t,n),confirmAction:t=>e.confirmAction(t),rejectAction:(t,n)=>e.rejectAction(t,n),requestHandoff:t=>e.requestHandoff(t),beginHandoff:(t,n)=>e.beginHandoff(t,n),readAttachment:t=>e.client.getAttachment(t),loadAttachmentUrl:t=>e.loadAttachmentUrl(t),...t.openAttachment?{openAttachment:t.openAttachment}:{},...t.openRecord?{openRecord:t.openRecord}:{},...t.openTicket?{openTicket:t.openTicket}:{},...t.attachmentUrl?{attachmentUrl:t.attachmentUrl}:{},...t.handoffHosts?{handoffHosts:t.handoffHosts}:{},...t.openCitation?{openCitation:t.openCitation}:{},...t.isCitation?{isCitation:t.isCitation}:{},...t.openTarget?{openTarget:t.openTarget}:{},...t.onNavigate?{onNavigate:t.onNavigate}:{}}),ln=e=>e;function un(e){return e!=null&&e.trim()!==``}function dn(e){return{kind:`paragraph`,text:e}}function fn(e){return e.split(/\n\s*\n/).map(e=>e.trim()).filter(e=>e!==``).map(dn)}function pn(e){return e.url!==null&&(e.url.startsWith(`http://`)||e.url.startsWith(`https://`))?`${e.title} (${e.url})`:e.title}function mn(e,t){return t===null?e:`${e??``} (${t})`.trim()}function hn(e){let t=[],n=new Set,r=e.map(e=>{let r=new Map;for(let i of e.points)r.set(i.label,i.value),n.has(i.label)||(n.add(i.label),t.push(i.label));return r});return t.map(e=>[e,...r.map(t=>{let n=t.get(e);return n===void 0?``:_t(n,`Decimal`,null)})])}function gn(e){return e.map(e=>e.kind===`sup`?`^${e.text}`:e.text).join(``)}function _n(e){return Math.abs(e)<.001&&e!==0?gn(ye(e)):_t(e,`Decimal`,null)}function vn(e,t){switch(e.kind){case`Text`:case`Notice`:return fn(it([e]));case`Sources`:return e.sources.length===0?[]:[dn(t.sources),{kind:`list`,ordered:!0,items:e.sources.map(pn)}];case`QuickReplies`:case`Handoff`:return[];case`InputRequest`:return e.state!==`Answered`||!un(e.answeredSummary)?[]:[dn(e.title===null?e.answeredSummary:`${e.title}: ${e.answeredSummary}`)];case`Action`:{let t=[dn(e.title)];return e.lines.length>0&&t.push({kind:`list`,ordered:!1,items:[...e.lines]}),t}case`Table`:return[{kind:`table`,title:e.title,head:e.columns.map(e=>e.label),rows:e.rows.map(t=>e.columns.map((n,r)=>_t(t[r],n.type,e.currency)))}];case`Chart`:return e.series.length===0?[]:[{kind:`table`,title:mn(e.title,e.unit),head:[``,...e.series.map(e=>e.name)],rows:hn(e.series)}];case`Figures`:return e.figures.length===0?[]:[{kind:`table`,title:null,head:[],rows:e.figures.map(e=>[e.label,_n(e.value)+(un(e.unit)?` ${e.unit}`:``)])}];case`RecordCard`:{let t=[dn(e.subtitle===null?e.title:`${e.title} ${e.subtitle}`)];return e.fields.length>0&&t.push({kind:`table`,title:null,head:[],rows:e.fields.map(e=>[e.label,_t(e.value,e.type,null)])}),t}case`Image`:return un(e.alt)?[dn(e.alt)]:[];case`File`:return[dn(`${e.fileName} (${tt(e.length)})`)];case`Ticket`:return[dn(`${e.number} ${e.subject}`)];case`VoiceClip`:return un(e.transcript)?[dn(e.transcript)]:[];default:return[]}}function yn(e,t){switch(e.kind){case`paragraph`:return{kind:`paragraph`,text:t(e.text)};case`list`:return{kind:`list`,ordered:e.ordered,items:e.items.map(e=>t(e))};case`table`:return{kind:`table`,title:e.title===null?null:t(e.title),head:e.head.map(e=>t(e)),rows:e.rows.map(e=>e.map(e=>t(e)))}}}function bn(e,t){switch(e.kind){case`Visitor`:case`Customer`:return t.you;case`Agent`:return un(e.displayName)?e.displayName:t.agent;case`Assistant`:case`Script`:return t.assistant;case`System`:throw Error(`A System message has no speaker: buildTranscript skips it.`)}}function xn(e,t){let n=t.figureText?ve:ln,r=[],i=null;for(let a of e){if(a.streaming||a.author.kind===`System`)continue;let e=a.parts.flatMap(e=>vn(e,t.labels)).map(e=>yn(e,n));e.length!==0&&(r.push({speaker:bn(a.author,t.labels),blocks:e}),i===null&&(i=rt(a.createdDateTimeUtc)))}return{title:un(t.title)?t.title:t.labels.untitled,dateText:i,entries:r}}function Sn(e){switch(e.kind){case`paragraph`:return[e.text];case`list`:return e.items.map((t,n)=>e.ordered?`${n+1}. ${t}`:`- ${t}`);case`table`:{let t=[];e.title!==null&&t.push(e.title),e.head.length>0&&t.push(e.head.join(` | `));for(let n of e.rows)t.push(n.join(` | `));return t}}}function Cn(e,t){let n=[];t.heading&&n.push([e.title,...e.dateText===null?[]:[e.dateText]].join(`
|
|
18
18
|
`));for(let r of e.entries){let e=t.speakers?[`${r.speaker}:`]:[];for(let t of r.blocks)e.push(...Sn(t));n.push(e.join(`
|
|
@@ -41,4 +41,4 @@
|
|
|
41
41
|
`)){var p=new tY;p.newline=!0,s.add(p)}else{var m=n.getSeriesByName(f)[0];if(!c.get(f)){if(m){var h=m.getData(),g=h.getVisual(`legendLineStyle`)||{},_=h.getVisual(`legendIcon`),v=h.getVisual(`style`),y=this._createItem(m,f,a,i,t,e,g,v,_,l,r);y.on(`click`,$J(PD,f,null,r,d)).on(`mouseover`,$J(FD,m.name,null,r,d)).on(`mouseout`,$J(ID,m.name,null,r,d)),n.ssr&&y.eachChild(function(e){var t=$F(e);t.seriesIndex=m.seriesIndex,t.dataIndex=a,t.ssrType=`legend`}),u&&y.eachChild(function(e){o.packEventData(e,t,m,a,f)}),c.set(f,!0)}else n.eachRawSeries(function(o){var s=this;if(!c.get(f)&&o.legendVisualProvider){var p=o.legendVisualProvider;if(!p.containName(f))return;var m=p.indexOfName(f),h=p.getItemVisual(m,`style`),g=p.getItemVisual(m,`legendIcon`),_=Da(h.fill);_&&_[3]===0&&(_[3]=.2,h=I(I({},h),{fill:Fa(_,`rgba`)}));var v=this._createItem(o,f,a,i,t,e,{},h,g,l,r);v.on(`click`,$J(PD,null,f,r,d)).on(`mouseover`,$J(FD,null,f,r,d)).on(`mouseout`,$J(ID,null,f,r,d)),n.ssr&&v.eachChild(function(e){var t=$F(e);t.seriesIndex=o.seriesIndex,t.dataIndex=a,t.ssrType=`legend`}),u&&v.eachChild(function(e){s.packEventData(e,t,o,a,f)}),c.set(f,!0)}},this)}}},this),i&&this._createSelector(i,t,r,a,o)},t.prototype.packEventData=function(e,t,n,r,i){var a={componentType:`legend`,componentIndex:t.componentIndex,dataIndex:r,value:i,seriesIndex:n.seriesIndex};$F(e).eventData=a},t.prototype._createSelector=function(e,t,n,r,i){var a=this.getSelectorGroup();eY(e,function(e){var r=e.type,i=new wF({style:{x:0,y:0,align:`center`,verticalAlign:`middle`},onclick:function(){n.dispatchAction({type:r===`all`?`legendAllSelect`:`legendInverseSelect`,legendId:t.id})}});a.add(i),Fu(i,{normal:t.getModel(`selectorLabel`),emphasis:t.getModel([`emphasis`,`selectorLabel`])},{defaultText:e.title}),dl(i)})},t.prototype._createItem=function(e,t,n,r,i,a,o,s,c,l,u){var d=e.visualDrawType,f=i.get(`itemWidth`),p=i.get(`itemHeight`),m=i.isSelected(t),h=r.get(`symbolRotate`),g=r.get(`symbolKeepAspect`),_=r.get(`icon`);c=_||c||`roundRect`;var v=MD(c,r,o,s,d,m,u),y=new tY,b=r.getModel(`textStyle`);if(B(e.getLegendIcon)&&(!_||_===`inherit`))y.add(e.getLegendIcon({itemWidth:f,itemHeight:p,icon:c,iconRotate:h,itemStyle:v.itemStyle,lineStyle:v.lineStyle,symbolKeepAspect:g}));else{var x=_===`inherit`&&e.getData().getVisual(`symbol`)?h===`inherit`?e.getData().getVisual(`symbolRotate`):h:0;y.add(ND({itemWidth:f,itemHeight:p,icon:c,iconRotate:x,itemStyle:v.itemStyle,lineStyle:v.lineStyle,symbolKeepAspect:g}))}var S=a===`left`?f+5:-5,C=a,w=i.get(`formatter`),T=t;V(w)&&w?T=w.replace(`{name}`,t??``):B(w)&&(T=w(t));var E=m?b.getTextColor():r.get(`inactiveColor`);y.add(new wF({style:Lu(b,{text:T,x:S,y:p/2,fill:E,align:C,verticalAlign:`middle`},{inheritColor:E})}));var D=new yF({shape:y.getBoundingRect(),style:{fill:`transparent`}}),O=r.getModel(`tooltip`);return O.get(`show`)&&bu({el:D,componentModel:i,itemName:t,itemTooltipOption:O.option}),y.add(D),y.eachChild(function(e){e.silent=!0}),D.silent=!l,this.getContentGroup().add(y),dl(y),y.__legendDataIndex=n,y},t.prototype.layoutInner=function(e,t,n,r,i,a){var o=this.getContentGroup(),s=this.getSelectorGroup();Rz(e.get(`orient`),o,e.get(`itemGap`),n.width,n.height);var c=o.getBoundingRect(),l=[-c.x,-c.y];if(s.markRedraw(),o.markRedraw(),i){Rz(`horizontal`,s,e.get(`selectorItemGap`,!0));var u=s.getBoundingRect(),d=[-u.x,-u.y],f=e.get(`selectorButtonGap`,!0),p=e.getOrient().index,m=p===0?`width`:`height`,h=p===0?`height`:`width`,g=p===0?`y`:`x`;a===`end`?d[p]+=c[m]+f:l[p]+=u[m]+f,d[1-p]+=c[h]/2-u[h]/2,s.x=d[0],s.y=d[1],o.x=l[0],o.y=l[1];var _={x:0,y:0};return _[m]=c[m]+f+u[m],_[h]=Math.max(c[h],u[h]),_[g]=Math.min(0,u[g]+d[1-p]),_}return o.x=l[0],o.y=l[1],this.group.getBoundingRect()},t.prototype.remove=function(){this.getContentGroup().removeAll(),this._isFirstRender=!0},t.type=`legend.plain`,t}(LU),rY=Dc(BD),iY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n}return t.prototype.setScrollDataIndex=function(e){this.option.scrollDataIndex=e},t.prototype.init=function(t,n,r){var i=ap(t);e.prototype.init.call(this,t,n,r),HD(this,t,i)},t.prototype.mergeOption=function(t,n){e.prototype.mergeOption.call(this,t,n),HD(this,this.option,t)},t.type=`legend.scroll`,t.defaultOption=Zd(QJ.defaultOption,{scrollDataIndex:0,pageButtonItemGap:5,pageButtonGap:null,pageButtonPosition:`end`,pageFormatter:`{current}/{total}`,pageIcons:{horizontal:[`M0,0L12,-10L12,10z`,`M0,0L-12,-10L-12,10z`],vertical:[`M0,0L20,0L10,-20z`,`M0,0L20,0L10,20z`]},pageIconColor:Z.color.accent50,pageIconInactiveColor:Z.color.accent10,pageIconSize:15,pageTextStyle:{color:Z.color.tertiary},animationDurationUpdate:800}),t}(QJ),aY=RI,oY=[`width`,`height`],sY=[`x`,`y`],cY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n.newlineDisabled=!0,n._currentIndex=0,n}return t.prototype.init=function(){e.prototype.init.call(this),this.group.add(this._containerGroup=new aY),this._containerGroup.add(this.getContentGroup()),this.group.add(this._controllerGroup=new aY)},t.prototype.resetInner=function(){e.prototype.resetInner.call(this),this._controllerGroup.removeAll(),this._containerGroup.removeClipPath(),this._containerGroup.__rectSize=null},t.prototype.renderInner=function(t,n,r,i,a,o,s){var c=this;e.prototype.renderInner.call(this,t,n,r,i,a,o,s);var l=this._controllerGroup,u=n.get(`pageIconSize`,!0),d=z(u)?u:[u,u];p(`pagePrev`,0);var f=n.getModel(`pageTextStyle`);l.add(new wF({name:`pageText`,style:{text:`xx/xx`,fill:f.getTextColor(),font:f.getFont(),verticalAlign:`middle`,align:`center`},silent:!0})),p(`pageNext`,1);function p(e,t){var r=e+`DataIndex`,a=pu(n.get(`pageIcons`,!0)[n.getOrient().name][t],{onclick:q(c._pageGo,c,r,n,i)},{x:-d[0]/2,y:-d[1]/2,width:d[0],height:d[1]});a.name=e,l.add(a)}},t.prototype.layoutInner=function(e,t,n,r,i,a){var o=this.getSelectorGroup(),s=e.getOrient().index,c=oY[s],l=sY[s],u=oY[1-s],d=sY[1-s];i&&Rz(`horizontal`,o,e.get(`selectorItemGap`,!0));var f=e.get(`selectorButtonGap`,!0),p=o.getBoundingRect(),m=[-p.x,-p.y],h=F(n);i&&(h[c]=n[c]-p[c]-f);var g=this._layoutContentAndController(e,r,h,s,c,u,d,l);if(i){if(a===`end`)m[s]+=g[c]+f;else{var _=p[c]+f;m[s]-=_,g[l]-=_}g[c]+=p[c]+f,m[1-s]+=g[d]+g[u]/2-p[u]/2,g[u]=Math.max(g[u],p[u]),g[d]=Math.min(g[d],p[d]+m[1-s]),o.x=m[0],o.y=m[1],o.markRedraw()}return g},t.prototype._layoutContentAndController=function(e,t,n,r,i,a,o,s){var c=this.getContentGroup(),l=this._containerGroup,u=this._controllerGroup;Rz(e.get(`orient`),c,e.get(`itemGap`),r?n.width:null,r?null:n.height),Rz(`horizontal`,u,e.get(`pageButtonItemGap`,!0));var d=c.getBoundingRect(),f=u.getBoundingRect(),p=this._showController=d[i]>n[i],m=[-d.x,-d.y];t||(m[r]=c[s]);var h=[0,0],g=[-f.x,-f.y],_=U(e.get(`pageButtonGap`,!0),e.get(`itemGap`,!0));p&&(e.get(`pageButtonPosition`,!0)===`end`?g[r]+=n[i]-f[i]:h[r]+=f[i]+_),g[1-r]+=d[a]/2-f[a]/2,c.setPosition(m),l.setPosition(h),u.setPosition(g);var v={x:0,y:0};if(v[i]=p?n[i]:d[i],v[a]=Math.max(d[a],f[a]),v[o]=Math.min(0,f[o]+g[1-r]),l.__rectSize=n[i],p){var y={x:0,y:0};y[i]=Math.max(n[i]-f[i]-_,0),y[a]=v[a],l.setClipPath(new yF({shape:y})),l.__rectSize=y[i]}else u.eachChild(function(e){e.attr({invisible:!0,silent:!0})});var b=this._getPageInfo(e);return b.pageIndex!=null&&Hl(c,{x:b.contentPosition[0],y:b.contentPosition[1]},p?e:null),this._updatePageInfoView(e,b),v},t.prototype._pageGo=function(e,t,n){var r=this._getPageInfo(t)[e];r!=null&&n.dispatchAction({type:`legendScroll`,scrollDataIndex:r,legendId:t.id})},t.prototype._updatePageInfoView=function(e,t){var n=this._controllerGroup;L([`pagePrev`,`pageNext`],function(r){var i=t[r+`DataIndex`]!=null,a=n.childOfName(r);a&&(a.setStyle(`fill`,i?e.get(`pageIconColor`,!0):e.get(`pageIconInactiveColor`,!0)),a.cursor=i?`pointer`:`default`)});var r=n.childOfName(`pageText`),i=e.get(`pageFormatter`),a=t.pageIndex,o=a==null?0:a+1,s=t.pageCount;r&&i&&r.setStyle(`text`,V(i)?i.replace(`{current}`,o==null?``:o+``).replace(`{total}`,s==null?``:s+``):i({current:o,total:s}))},t.prototype._getPageInfo=function(e){var t=e.get(`scrollDataIndex`,!0),n=this.getContentGroup(),r=this._containerGroup.__rectSize,i=e.getOrient().index,a=oY[i],o=sY[i],s=this._findTargetItemIndex(t),c=n.children(),l=c[s],u=c.length,d=+!!u,f={contentPosition:[n.x,n.y],pageCount:d,pageIndex:d-1,pagePrevDataIndex:null,pageNextDataIndex:null};if(!l)return f;var p=v(l);f.contentPosition[i]=-p.s;for(var m=s+1,h=p,g=p,_=null;m<=u;++m)_=v(c[m]),(!_&&g.e>h.s+r||_&&!y(_,h.s))&&(h=g.i>h.i?g:_,h&&(f.pageNextDataIndex??=h.i,++f.pageCount)),g=_;for(var m=s-1,h=p,g=p,_=null;m>=-1;--m)_=v(c[m]),(!_||!y(g,_.s))&&h.i<g.i&&(g=h,f.pagePrevDataIndex??=h.i,++f.pageCount,++f.pageIndex),h=_;return f;function v(e){if(e){var t=e.getBoundingRect(),n=t[o]+e[o];return{s:n,e:n+t[a],i:e.__legendDataIndex}}}function y(e,t){return e.e>=t&&e.s<=t+r}},t.prototype._findTargetItemIndex=function(e){if(!this._showController)return 0;var t,n=this.getContentGroup(),r;return n.eachChild(function(n,i){var a=n.__legendDataIndex;r==null&&a!=null&&(r=i),a===e&&(t=i)}),t??r},t.type=`legend.scroll`,t}(nY),lY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n}return t.type=`dataZoom.inside`,t.defaultOption=Zd(wJ.defaultOption,{disabled:!1,zoomLock:!1,zoomOnMouseWheel:!0,moveOnMouseMove:!0,moveOnMouseWheel:!1,preventDefaultMouseMove:!0}),t}(wJ),uY=tc(),dY=function(e){P(t,e);function t(){var t=e!==null&&e.apply(this,arguments)||this;return t.type=`dataZoom.inside`,t}return t.prototype.render=function(t,n,r){e.prototype.render.apply(this,arguments),t.noTarget()?this._clear():(this.range=t.getPercentRange(),KD(r,t,{pan:q(fY.pan,this),zoom:q(fY.zoom,this),scrollMove:q(fY.scrollMove,this)}))},t.prototype.dispose=function(){this._clear(),e.prototype.dispose.apply(this,arguments)},t.prototype._clear=function(){qD(this.api,this.dataZoomModel),this.range=null},t.type=`dataZoom.inside`,t}(TJ),fY={zoom:function(e,t,n,r){var i=this.range,a=i.slice(),o=e.axisModels[0];if(o){var s=pY[t](null,[r.originX,r.originY],o,n,e),c=(s.signal>0?s.pixelStart+s.pixelLength-s.pixel:s.pixel-s.pixelStart)/s.pixelLength*(a[1]-a[0])+a[0],l=Math.max(1/r.scale,0);a[0]=(a[0]-c)*l+c,a[1]=(a[1]-c)*l+c;var u=this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();if(Fw(0,a,[0,100],0,u.minSpan,u.maxSpan),this.range=a,i[0]!==a[0]||i[1]!==a[1])return a}},pan:eO(function(e,t,n,r,i,a){var o=pY[r]([a.oldX,a.oldY],[a.newX,a.newY],t,i,n);return o.signal*(e[1]-e[0])*o.pixel/o.pixelLength}),scrollMove:eO(function(e,t,n,r,i,a){return pY[r]([0,0],[a.scrollDelta,a.scrollDelta],t,i,n).signal*(e[1]-e[0])*a.scrollDelta})},pY={grid:function(e,t,n,r,i){var a=n.axis,o={},s=i.model.coordinateSystem.getRect();return e||=[0,0],a.dim===`x`?(o.pixel=t[0]-e[0],o.pixelLength=s.width,o.pixelStart=s.x,o.signal=a.inverse?1:-1):(o.pixel=t[1]-e[1],o.pixelLength=s.height,o.pixelStart=s.y,o.signal=a.inverse?-1:1),o},polar:function(e,t,n,r,i){var a=n.axis,o={},s=i.model.coordinateSystem,c=s.getRadiusAxis().getExtent(),l=s.getAngleAxis().getExtent();return e=e?s.pointToCoord(e):[0,0],t=s.pointToCoord(t),n.mainType===`radiusAxis`?(o.pixel=t[0]-e[0],o.pixelLength=c[1]-c[0],o.pixelStart=c[0],o.signal=a.inverse?1:-1):(o.pixel=t[1]-e[1],o.pixelLength=l[1]-l[0],o.pixelStart=l[0],o.signal=a.inverse?-1:1),o},singleAxis:function(e,t,n,r,i){var a=n.axis,o=i.model.coordinateSystem.getRect(),s={};return e||=[0,0],a.orient===`horizontal`?(s.pixel=t[0]-e[0],s.pixelLength=o.width,s.pixelStart=o.x,s.signal=a.inverse?1:-1):(s.pixel=t[1]-e[1],s.pixelLength=o.height,s.pixelStart=o.y,s.signal=a.inverse?-1:1),s}},mY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n}return t.type=`dataZoom.slider`,t.layoutMode=`box`,t.defaultOption=Zd(wJ.defaultOption,{show:!0,right:`ph`,top:`ph`,width:`ph`,height:`ph`,left:null,bottom:null,borderColor:Z.color.accent10,borderRadius:0,backgroundColor:Z.color.transparent,dataBackground:{lineStyle:{color:Z.color.accent30,width:.5},areaStyle:{color:Z.color.accent20,opacity:.2}},selectedDataBackground:{lineStyle:{color:Z.color.accent40,width:.5},areaStyle:{color:Z.color.accent20,opacity:.3}},fillerColor:`rgba(135,175,274,0.2)`,handleIcon:`path://M-9.35,34.56V42m0-40V9.5m-2,0h4a2,2,0,0,1,2,2v21a2,2,0,0,1-2,2h-4a2,2,0,0,1-2-2v-21A2,2,0,0,1-11.35,9.5Z`,handleSize:`100%`,handleStyle:{color:Z.color.neutral00,borderColor:Z.color.accent20},moveHandleSize:7,moveHandleIcon:`path://M-320.9-50L-320.9-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-348-41-339-50-320.9-50z M-212.3-50L-212.3-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-239.4-41-230.4-50-212.3-50z M-103.7-50L-103.7-50c18.1,0,27.1,9,27.1,27.1V85.7c0,18.1-9,27.1-27.1,27.1l0,0c-18.1,0-27.1-9-27.1-27.1V-22.9C-130.9-41-121.8-50-103.7-50z`,moveHandleStyle:{color:Z.color.accent40,opacity:.5},showDetail:!0,showDataShadow:`auto`,realtime:!0,zoomLock:!1,textStyle:{color:Z.color.tertiary},brushSelect:!0,brushStyle:{color:Z.color.accent30,opacity:.3},emphasis:{handleLabel:{show:!0},handleStyle:{borderColor:Z.color.accent40},moveHandleStyle:{opacity:.8}},defaultLocationEdgeGap:15}),t}(wJ),hY=yF,gY=1,_Y=30,vY=7,yY=`horizontal`,bY=`vertical`,xY=5,SY=[`line`,`bar`,`candlestick`,`scatter`],CY={easing:`cubicOut`,duration:100,delay:0},wY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n._displayables={},n}return t.prototype.init=function(e,t){this.api=t,this._onBrush=q(this._onBrush,this),this._onBrushEnd=q(this._onBrushEnd,this)},t.prototype.render=function(t,n,r,i){e.prototype.render.apply(this,arguments),Q_(this,`_dispatchZoomAction`,t.get(`throttle`),`fixRate`),this._orient=t.getOrient(),t.get(`show`)===!1?this.group.removeAll():t.noTarget()?(this._clear(),this.group.removeAll()):(i&&i.type===`dataZoom`&&i.from===this.uid||this._buildView(),this._updateView())},t.prototype.dispose=function(){this._clear(),e.prototype.dispose.apply(this,arguments)},t.prototype._clear=function(){$_(this,`_dispatchZoomAction`);var e=this.api.getZr();e.off(`mousemove`,this._onBrush),e.off(`mouseup`,this._onBrushEnd)},t.prototype._buildView=function(){var e=this.group;e.removeAll(),this._brushing=!1,this._displayables.brushRect=null,this._resetLocation(),this._resetInterval();var t=this._displayables.sliderGroup=new RI;this._renderBackground(),this._renderHandle(),this._renderDataShadow(),e.add(t),this._positionGroup()},t.prototype._resetLocation=function(){var e=this.dataZoomModel,t=this.api,n=e.get(`brushSelect`)?vY:0,r=ep(e,t).refContainer,i=this._findCoordRect(),a=e.get(`defaultLocationEdgeGap`,!0)||0,o=this._orient===yY?{right:r.width-i.x-i.width,top:r.height-_Y-a-n,width:i.width,height:_Y}:{right:a,top:i.y,width:_Y,height:i.height},s=ap(e.option);L([`right`,`top`,`width`,`height`],function(e){s[e]===`ph`&&(s[e]=o[e])});var c=$f(s,r);this._location={x:c.x,y:c.y},this._size=[c.width,c.height],this._orient===bY&&this._size.reverse()},t.prototype._positionGroup=function(){var e=this.group,t=this._location,n=this._orient,r=this.dataZoomModel.getFirstTargetAxisModel(),i=r&&r.get(`inverse`),a=this._displayables.sliderGroup,o=(this._dataShadowInfo||{}).otherAxisInverse;a.attr(n===yY&&!i?{scaleY:o?1:-1,scaleX:1}:n===yY&&i?{scaleY:o?1:-1,scaleX:-1}:n===bY&&!i?{scaleY:o?-1:1,scaleX:1,rotation:Math.PI/2}:{scaleY:o?-1:1,scaleX:-1,rotation:Math.PI/2});var s=e.getBoundingRect([a]),c=isNaN(s.x)?0:s.x,l=isNaN(s.y)?0:s.y;e.x=t.x-c,e.y=t.y-l,e.markRedraw()},t.prototype._getViewExtent=function(){return[0,this._size[0]]},t.prototype._renderBackground=function(){var e=this.dataZoomModel,t=this._size,n=this._displayables.sliderGroup,r=e.get(`brushSelect`);n.add(new hY({silent:!0,shape:{x:0,y:0,width:t[0],height:t[1]},style:{fill:e.get(`backgroundColor`)},z2:-40}));var i=new hY({shape:{x:0,y:0,width:t[0],height:t[1]},style:{fill:`transparent`},z2:0,onclick:q(this._onClickPanel,this)}),a=this.api.getZr();r?(i.on(`mousedown`,this._onBrushStart,this),i.cursor=`crosshair`,a.on(`mousemove`,this._onBrush),a.on(`mouseup`,this._onBrushEnd)):(a.off(`mousemove`,this._onBrush),a.off(`mouseup`,this._onBrushEnd)),n.add(i)},t.prototype._renderDataShadow=function(){var e=this._dataShadowInfo=this._prepareDataShadowInfo();if(this._displayables.dataShadowSegs=[],!e)return;var t=this._size,n=this._shadowSize||[],r=e.series,i=r.getRawData(),a=r.getShadowDim&&r.getShadowDim(),o=a&&i.getDimensionInfo(a)?r.getShadowDim():e.otherDim;if(o==null)return;var s=this._shadowPolygonPts,c=this._shadowPolylinePts;if(i!==this._shadowData||o!==this._shadowDim||t[0]!==n[0]||t[1]!==n[1]){var l=i.getDataExtent(e.thisDim),u=i.getDataExtent(o),d=(u[1]-u[0])*.3;u=[u[0]-d,u[1]+d];var f=[0,t[1]],p=[0,t[0]],m=[[t[0],0],[0,0]],h=[],g=p[1]/Math.max(1,i.count()-1),_=t[0]/(l[1]-l[0]),v=e.thisAxis.type===`time`,y=-g,b=Math.round(i.count()/t[0]),x;i.each([e.thisDim,o],function(e,t,n){if(b>0&&n%b)v||(y+=g);else{y=v?(+e-l[0])*_:y+g;var r=t==null||isNaN(t)||t===``,i=r?0:ss(t,u,f,!0);r&&!x&&n?(m.push([m[m.length-1][0],0]),h.push([h[h.length-1][0],0])):!r&&x&&(m.push([y,0]),h.push([y,0])),r||(m.push([y,i]),h.push([y,i])),x=r}}),s=this._shadowPolygonPts=m,c=this._shadowPolylinePts=h}this._shadowData=i,this._shadowDim=o,this._shadowSize=[t[0],t[1]];var S=this.dataZoomModel;function C(e){var t=S.getModel(e?`selectedDataBackground`:`dataBackground`),n=new RI,r=new aL({shape:{points:s},segmentIgnoreThreshold:1,style:t.getModel(`areaStyle`).getAreaStyle(),silent:!0,z2:-20}),i=new sL({shape:{points:c},segmentIgnoreThreshold:1,style:t.getModel(`lineStyle`).getLineStyle(),silent:!0,z2:-19});return n.add(r),n.add(i),n}for(var w=0;w<3;w++){var T=C(w===1);this._displayables.sliderGroup.add(T),this._displayables.dataShadowSegs.push(T)}},t.prototype._prepareDataShadowInfo=function(){var e=this.dataZoomModel,t=e.get(`showDataShadow`);if(t!==!1){var n,r=this.ecModel;return e.eachTargetAxis(function(i,a){L(e.getAxisProxy(i,a).getTargetSeriesModels(),function(e){if(!n&&!(t!==!0&&ar(SY,e.get(`type`))<0)){var o=r.getComponent(AE(i),a).axis,s=rO(i),c,l=e.coordinateSystem;s!=null&&l.getOtherAxis&&(c=l.getOtherAxis(o).inverse),s=e.getData().mapDimension(s),n={thisAxis:o,series:e,thisDim:e.getData().mapDimension(i),otherDim:s,otherAxisInverse:c}}},this)},this),n}},t.prototype._renderHandle=function(){var e=this.group,t=this._displayables,n=t.handles=[null,null],r=t.handleLabels=[null,null],i=this._displayables.sliderGroup,a=this._size,o=this.dataZoomModel,s=this.api,c=o.get(`borderRadius`)||0,l=o.get(`brushSelect`),u=t.filler=new hY({silent:l,style:{fill:o.get(`fillerColor`)},textConfig:{position:`inside`}});i.add(u),i.add(new hY({silent:!0,subPixelOptimize:!0,shape:{x:0,y:0,width:a[0],height:a[1],r:c},style:{stroke:o.get(`dataBackgroundColor`)||o.get(`borderColor`),lineWidth:gY,fill:Z.color.transparent}})),L([0,1],function(t){var a=o.get(`handleIcon`);!lB[a]&&a.indexOf(`path://`)<0&&a.indexOf(`image://`)<0&&(a=`path://`+a);var s=em(a,-1,0,2,2,null,!0);s.attr({cursor:iO(this._orient),draggable:!0,drift:q(this._onDragMove,this,t),ondragend:q(this._onDragEnd,this),onmouseover:q(this._onOverDataInfoTriggerArea,this,!0),onmouseout:q(this._onOverDataInfoTriggerArea,this,!1),z2:5});var c=s.getBoundingRect(),l=o.get(`handleSize`);this._handleHeight=X(l,this._size[1]),this._handleWidth=c.width/c.height*this._handleHeight,s.setStyle(o.getModel(`handleStyle`).getItemStyle()),s.style.strokeNoScale=!0,s.rectHover=!0,s.ensureState(`emphasis`).style=o.getModel([`emphasis`,`handleStyle`]).getItemStyle(),dl(s);var u=o.get(`handleColor`);u!=null&&(s.style.fill=u),i.add(n[t]=s);var d=o.getModel(`textStyle`),f=(o.get(`handleLabel`)||{}).show||!1;e.add(r[t]=new wF({silent:!0,invisible:!f,style:Lu(d,{x:0,y:0,text:``,verticalAlign:`middle`,align:`center`,fill:d.getTextColor(),font:d.getFont()}),z2:10}))},this);var d=u;if(l){var f=X(o.get(`moveHandleSize`),a[1]),p=t.moveHandle=new yF({style:o.getModel(`moveHandleStyle`).getItemStyle(),silent:!0,shape:{r:[0,0,2,2],y:a[1]-.5,height:f}}),m=f*.8,h=t.moveHandleIcon=em(o.get(`moveHandleIcon`),-m/2,-m/2,m,m,Z.color.neutral00,!0);h.silent=!0,h.y=a[1]+f/2-.5,p.ensureState(`emphasis`).style=o.getModel([`emphasis`,`moveHandleStyle`]).getItemStyle();var g=Math.min(a[1]/2,Math.max(f,10));d=t.moveZone=new yF({invisible:!0,shape:{y:a[1]-g,height:f+g}}),d.on(`mouseover`,function(){s.enterEmphasis(p)}).on(`mouseout`,function(){s.leaveEmphasis(p)}),i.add(p),i.add(h),i.add(d)}d.attr({draggable:!0,cursor:`grab`,drift:q(this._onActualMoveZoneDrift,this),ondragstart:q(this._onActualMoveZoneDragStart,this),ondragend:q(this._onActualMoveZoneDragEnd,this),onmouseover:q(this._onOverDataInfoTriggerArea,this,!0),onmouseout:q(this._onOverDataInfoTriggerArea,this,!1)})},t.prototype._resetInterval=function(){var e=this._range=this.dataZoomModel.getPercentRange(),t=this._getViewExtent();this._handleEnds=[ss(e[0],[0,100],t,!0),ss(e[1],[0,100],t,!0)]},t.prototype._updateInterval=function(e,t){var n=this.dataZoomModel,r=this._handleEnds,i=this._getViewExtent(),a=n.findRepresentativeAxisProxy().getMinMaxSpan(),o=[0,100];Fw(t,r,i,n.get(`zoomLock`)?`all`:e,a.minSpan==null?null:ss(a.minSpan,o,i,!0),a.maxSpan==null?null:ss(a.maxSpan,o,i,!0));var s=this._range,c=this._range=ps([ss(r[0],i,o,!0),ss(r[1],i,o,!0)]);return!s||s[0]!==c[0]||s[1]!==c[1]},t.prototype._updateView=function(e){var t=this._displayables,n=this._handleEnds,r=ps(n.slice()),i=this._size;L([0,1],function(e){var r=t.handles[e],a=this._handleHeight;r.attr({scaleX:a/2,scaleY:a/2,x:n[e]+(e?-1:1),y:i[1]/2-a/2})},this),t.filler.setShape({x:r[0],y:0,width:r[1]-r[0],height:i[1]});var a={x:r[0],width:r[1]-r[0]};t.moveHandle&&(t.moveHandle.setShape(a),t.moveZone.setShape(a),t.moveZone.getBoundingRect(),t.moveHandleIcon&&t.moveHandleIcon.attr(`x`,a.x+a.width/2));for(var o=t.dataShadowSegs,s=[0,r[0],r[1],i[0]],c=0;c<o.length;c++){var l=o[c],u=l.getClipPath();u||(u=new yF,l.setClipPath(u)),u.setShape({x:s[c],y:0,width:s[c+1]-s[c],height:i[1]})}this._updateDataInfo(e)},t.prototype._updateDataInfo=function(e){var t=this.dataZoomModel,n=this._displayables,r=n.handleLabels,i=this._orient,a=[``,``];if(t.get(`showDetail`)){var o=t.findRepresentativeAxisProxy(),s=o.getAxisModel().axis.scale;if(o){var c=this._range,l;if(e){var u={start:c[0],end:c[1]},d=IE(t,o);if(d){var f=d.calculateDataWindow(u).percentInverted;u={start:f[0],end:f[1]}}l=o.calculateDataWindow(u)}else l=o.getWindow();a=[nO(t,0,l,s),nO(t,1,l,s)]}}var p=ps(this._handleEnds.slice());m.call(this,0),m.call(this,1);function m(e){var t=au(n.handles[e].parent,this.group),o=su(e===0?`right`:`left`,t),s=this._handleWidth/2+xY,c=ou([p[e]+(e===0?-s:s),this._size[1]/2],t);r[e].setStyle({x:c[0],y:c[1],verticalAlign:i===yY?`middle`:o,align:i===yY?o:`center`,text:a[e]})}},t.prototype._onOverDataInfoTriggerArea=function(e){this._isOverDataInfoTriggerArea=e,this._showDataInfo(e)},t.prototype._showDataInfo=function(e){var t=(this.dataZoomModel.get(`handleLabel`)||{}).show||!1,n=this.dataZoomModel.getModel([`emphasis`,`handleLabel`]).get(`show`)||!1,r=e||this._dragging?n:t,i=this._displayables,a=i.handleLabels;a[0].attr(`invisible`,!r),a[1].attr(`invisible`,!r),i.moveHandle&&this.api[r?`enterEmphasis`:`leaveEmphasis`](i.moveHandle,1)},t.prototype._onActualMoveZoneDrift=function(e,t,n){this.api.getZr().setCursorStyle(`grabbing`),this._onDragMove(`all`,e,t,n)},t.prototype._onActualMoveZoneDragStart=function(e){e.target.attr(`cursor`,`grabbing`),this._showDataInfo(!0)},t.prototype._onActualMoveZoneDragEnd=function(e){e.target.attr(`cursor`,`grab`),this._onDragEnd()},t.prototype._onDragMove=function(e,t,n,r){this._dragging=!0,VH(r.event);var i=this._displayables.sliderGroup.getLocalTransform(),a=ou([t,n],i,!0),o=this._updateInterval(e,a[0]),s=this.dataZoomModel.get(`realtime`);this._updateView(!s),o&&s&&this._dispatchZoomAction(!0)},t.prototype._onDragEnd=function(){this._dragging=!1,this._isOverDataInfoTriggerArea||this._showDataInfo(!1),!this.dataZoomModel.get(`realtime`)&&this._dispatchZoomAction(!1)},t.prototype._onClickPanel=function(e){var t=this._size,n=this._displayables.sliderGroup.transformCoordToLocal(e.offsetX,e.offsetY);if(!(n[0]<0||n[0]>t[0]||n[1]<0||n[1]>t[1])){var r=this._handleEnds,i=(r[0]+r[1])/2,a=this._updateInterval(`all`,n[0]-i);this._updateView(),a&&this._dispatchZoomAction(!1)}},t.prototype._onBrushStart=function(e){var t=e.offsetX,n=e.offsetY;this._brushStart=new J(t,n),this._brushing=!0,this._brushStartTime=+new Date},t.prototype._onBrushEnd=function(e){if(this._brushing){var t=this._displayables.brushRect;if(this._brushing=!1,t){t.attr(`ignore`,!0);var n=t.shape;if(!(+new Date-this._brushStartTime<200&&Math.abs(n.width)<5)){var r=this._getViewExtent(),i=[0,100],a=this._handleEnds=[n.x,n.x+n.width],o=this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();Fw(0,a,r,0,o.minSpan==null?null:ss(o.minSpan,i,r,!0),o.maxSpan==null?null:ss(o.maxSpan,i,r,!0)),this._range=ps([ss(a[0],r,i,!0),ss(a[1],r,i,!0)]),this._updateView(),this._dispatchZoomAction(!1)}}}},t.prototype._onBrush=function(e){this._brushing&&(VH(e.event),this._updateBrushRect(e.offsetX,e.offsetY))},t.prototype._updateBrushRect=function(e,t){var n=this._displayables,r=this.dataZoomModel,i=n.brushRect;i||(i=n.brushRect=new hY({silent:!0,style:r.getModel(`brushStyle`).getItemStyle()}),n.sliderGroup.add(i)),i.attr(`ignore`,!1);var a=this._brushStart,o=this._displayables.sliderGroup,s=o.transformCoordToLocal(e,t),c=o.transformCoordToLocal(a.x,a.y),l=this._size;s[0]=Math.max(Math.min(l[0],s[0]),0),i.setShape({x:c[0],y:0,width:s[0]-c[0],height:l[1]})},t.prototype._dispatchZoomAction=function(e){var t=this._range;this.api.dispatchAction({type:`dataZoom`,from:this.uid,dataZoomId:this.dataZoomModel.id,animation:e?CY:null,start:t[0],end:t[1]})},t.prototype._findCoordRect=function(){var e,t=ME(this.dataZoomModel).infoList;if(!e&&t.length){var n=t[0].model.coordinateSystem;e=n.getRect&&n.getRect()}if(!e){var r=this.api.getWidth(),i=this.api.getHeight();e={x:r*.2,y:i*.2,width:r*.6,height:i*.6}}return e},t.type=`dataZoom.slider`,t}(TJ),TY={get:function(e,t,n){var r=F((EY[e]||{})[t]);return n&&z(r)?r[r.length-1]:r}},EY={color:{active:[`#006edd`,`#e0ffff`],inactive:[Z.color.transparent]},colorHue:{active:[0,360],inactive:[0,0]},colorSaturation:{active:[.3,1],inactive:[0,0]},colorLightness:{active:[.9,.5],inactive:[0,0]},colorAlpha:{active:[.3,1],inactive:[0,0]},opacity:{active:[.3,1],inactive:[0,0]},symbol:{active:[`circle`,`roundRect`,`diamond`],inactive:[`none`]},symbolSize:{active:[10,50],inactive:[0,0]}},DY=lq.mapVisual,OY=lq.eachVisual,kY=z,AY=L,jY=ps,MY=ss,NY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n.stateList=[`inRange`,`outOfRange`],n.replacableOptionKeys=[`inRange`,`outOfRange`,`target`,`controller`,`color`],n.layoutMode={type:`box`,ignoreSize:!0},n.dataBound=[-1/0,1/0],n.targetVisuals={},n.controllerVisuals={},n}return t.prototype.init=function(e,t,n){this.mergeDefaultAndTheme(e,n)},t.prototype.optionUpdated=function(e,t){var n=this.option;!t&&dD(n,e,this.replacableOptionKeys),this.textStyleModel=this.getModel(`textStyle`),this.resetItemSize(),this.completeVisualOption()},t.prototype.resetVisual=function(e){var t=this.stateList;e=q(e,this),this.controllerVisuals=uD(this.option.controller,t,e),this.targetVisuals=uD(this.option.target,t,e)},t.prototype.getItemSymbol=function(){return null},t.prototype.getTargetSeriesIndices=function(){var e=this,t=this.option.seriesTargets;if(t){var n=[];return AY(t,function(t){if(t.seriesIndex!=null)n.push(t.seriesIndex);else if(t.seriesId!=null){var r;e.ecModel.eachSeries(function(e){e.id===t.seriesId&&(r=e)}),r&&n.push(r.componentIndex)}}),n}var r=this.option.seriesId,i=this.option.seriesIndex;i==null&&r==null&&(i=`all`);var a=ic(this.ecModel,`series`,{index:i,id:r},{useDefault:!1,enableAll:!0,enableNone:!1}).models;return R(a,function(e){return e.componentIndex})},t.prototype.eachTargetSeries=function(e,t){L(this.getTargetSeriesIndices(),function(n){var r=this.ecModel.getSeriesByIndex(n);r&&e.call(t,r)},this)},t.prototype.isTargetSeries=function(e){var t=!1;return this.eachTargetSeries(function(n){n===e&&(t=!0)}),t},t.prototype.formatValueText=function(e,t,n){var r=this.option,i=r.precision,a=this.dataBound,o=r.formatter,s;n||=[`<`,`>`],z(e)&&(e=e.slice(),s=!0);var c=t?e:s?[l(e[0]),l(e[1])]:l(e);return V(o)?o.replace(`{value}`,s?c[0]:c).replace(`{value2}`,s?c[1]:c):B(o)?s?o(e[0],e[1]):o(e):s?e[0]===a[0]?n[0]+` `+c[1]:e[1]===a[1]?n[1]+` `+c[0]:c[0]+` - `+c[1]:c;function l(e){return e===a[0]?`min`:e===a[1]?`max`:(+e).toFixed(Math.min(i,20))}},t.prototype.resetExtent=function(){var e=this.option,t=jY([e.min,e.max]);this._dataExtent=t},t.prototype.getDimension=function(e){var t=this,n=this.option.seriesTargets;if(n){var r=dr(n,function(n){return n.seriesIndex!=null&&n.seriesIndex===e||n.seriesId!=null&&n.seriesId===t.ecModel.getSeriesByIndex(e).id});if(r)return r.dimension}return this.option.dimension},t.prototype.getDataDimensionIndex=function(e){var t=e.hostModel.seriesIndex,n=this.getDimension(t);if(n!=null)return e.getDimensionIndex(n);for(var r=e.dimensions,i=r.length-1;i>=0;i--){var a=r[i],o=e.getDimensionInfo(a);if(!o.isCalculationCoord)return o.storeDimIndex}},t.prototype.getExtent=function(){return this._dataExtent.slice()},t.prototype.completeVisualOption=function(){var e=this.ecModel,t=this.option,n={inRange:t.inRange,outOfRange:t.outOfRange},r=t.target||={},i=t.controller||={};nr(r,n),nr(i,n);var a=this.isCategory();o.call(this,r),o.call(this,i),s.call(this,r,`inRange`,`outOfRange`),c.call(this,i);function o(n){kY(t.color)&&!n.inRange&&(n.inRange={color:t.color.slice().reverse()}),n.inRange=n.inRange||{color:e.get(`gradientColor`)}}function s(e,t,n){var r=e[t],i=e[n];r&&!i&&(i=e[n]={},AY(r,function(e,t){if(lq.isValidType(t)){var n=TY.get(t,`inactive`,a);n!=null&&(i[t]=n,t===`color`&&!i.hasOwnProperty(`opacity`)&&!i.hasOwnProperty(`colorAlpha`)&&(i.opacity=[0,0]))}}))}function c(e){var t=(e.inRange||{}).symbol||(e.outOfRange||{}).symbol,n=(e.inRange||{}).symbolSize||(e.outOfRange||{}).symbolSize,r=this.get(`inactiveColor`),i=this.getItemSymbol()||`roundRect`;AY(this.stateList,function(o){var s=this.itemSize,c=e[o];c||=e[o]={color:a?r:[r]},c.symbol??(c.symbol=t&&F(t)||(a?i:[i])),c.symbolSize??(c.symbolSize=n&&F(n)||(a?s[0]:[s[0],s[0]])),c.symbol=DY(c.symbol,function(e){return e===`none`?i:e});var l=c.symbolSize;if(l!=null){var u=-1/0;OY(l,function(e){e>u&&(u=e)}),c.symbolSize=DY(l,function(e){return MY(e,[0,u],[0,s[0]],!0)})}},this)}},t.prototype.resetItemSize=function(){this.itemSize=[parseFloat(this.get(`itemWidth`)),parseFloat(this.get(`itemHeight`))]},t.prototype.isCategory=function(){return!!this.option.categories},t.prototype.setSelected=function(e){},t.prototype.getSelected=function(){return null},t.prototype.getValueState=function(e){return null},t.prototype.getVisualMeta=function(e){return null},t.type=`visualMap`,t.dependencies=[`series`],t.defaultOption={show:!0,z:4,min:0,max:200,left:0,right:null,top:null,bottom:0,itemWidth:null,itemHeight:null,inverse:!1,orient:`vertical`,backgroundColor:Z.color.transparent,borderColor:Z.color.borderTint,contentColor:Z.color.theme[0],inactiveColor:Z.color.disabled,borderWidth:0,padding:Z.size.m,textGap:10,precision:0,textStyle:{color:Z.color.secondary}},t}(Vz),PY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n.autoPositionValues={left:1,right:1,top:1,bottom:1},n}return t.prototype.init=function(e,t){this.ecModel=e,this.api=t},t.prototype.render=function(e,t,n,r){this.visualMapModel=e,e.get(`show`)===!1?this.group.removeAll():this.doRender(e,t,n,r)},t.prototype.renderBackground=function(e){var t=this.visualMapModel,n=Mz(t.get(`padding`)||0),r=e.getBoundingRect();e.add(new yF({z2:-1,silent:!0,shape:{x:r.x-n[3],y:r.y-n[0],width:r.width+n[3]+n[1],height:r.height+n[0]+n[2]},style:{fill:t.get(`backgroundColor`),stroke:t.get(`borderColor`),lineWidth:t.get(`borderWidth`)}}))},t.prototype.getControllerVisual=function(e,t,n){n||={};var r=n.forceState,i=this.visualMapModel,a={};t===`color`&&(a.color=i.get(`contentColor`));function o(e){return a[e]}function s(e,t){a[e]=t}var c=i.controllerVisuals[r||i.getValueState(e)];return L(lq.prepareVisualTypes(c),function(r){var i=c[r];n.convertOpacityToAlpha&&r===`opacity`&&(r=`colorAlpha`,i=c.__alphaForOpacity),lq.dependsOn(r,t)&&i&&i.applyVisual(e,o,s)}),a[t]},t.prototype.positionGroup=function(e){var t=this.visualMapModel,n=this.api,r=ep(t,n).refContainer;tp(e,t.getBoxLayoutParams(),r)},t.prototype.doRender=function(e,t,n,r){},t.type=`visualMap`,t}(LU),FY=[[`left`,`right`,`width`],[`top`,`bottom`,`height`]],IY={type:`selectDataRange`,event:`dataRangeSelected`,update:`update`},LY=function(e,t){t.eachComponent({mainType:`visualMap`,query:e},function(t){t.setSelected(e.selected)})},RY=[{createOnAllSeries:!0,reset:function(e,t){var n=[];return t.eachComponent(`visualMap`,function(t){var r=e.pipelineContext;!t.isTargetSeries(e)||r&&r.large||n.push(fD(t.stateList,t.targetVisuals,q(t.getValueState,t),t.getDataDimensionIndex(e.getData())))}),n}},{createOnAllSeries:!0,reset:function(e,t){var n=e.getData(),r=[];t.eachComponent(`visualMap`,function(t){if(t.isTargetSeries(e)){var i=t.getVisualMeta(q(lO,null,e,t))||{stops:[],outerColors:[]},a=t.getDataDimensionIndex(n);a>=0&&(i.dimension=a,r.push(i))}}),e.getData().setVisual(`visualMeta`,r)}}],zY=L,BY=!1,VY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n._pieceList=[],n}return t.prototype.optionUpdated=function(t,n){e.prototype.optionUpdated.apply(this,arguments),this.resetExtent();var r=this._mode=this._determineMode();this._pieceList=[],HY[this._mode].call(this,this._pieceList),this._resetSelected(t,n);var i=this.option.categories;this.resetVisual(function(e,t){r===`categories`?(e.mappingMethod=`category`,e.categories=F(i)):(e.dataExtent=this.getExtent(),e.mappingMethod=`piecewise`,e.pieceList=R(this._pieceList,function(e){return e=F(e),t!==`inRange`&&(e.visual=null),e}))})},t.prototype.completeVisualOption=function(){var t=this.option,n={},r=lq.listVisualTypes(),i=this.isCategory();L(t.pieces,function(e){L(r,function(t){e.hasOwnProperty(t)&&(n[t]=1)})}),L(n,function(e,n){var r=!1;L(this.stateList,function(e){r=r||a(t,e,n)||a(t.target,e,n)},this),!r&&L(this.stateList,function(e){(t[e]||(t[e]={}))[n]=TY.get(n,e===`inRange`?`active`:`inactive`,i)})},this);function a(e,t,n){return e&&e[t]&&e[t].hasOwnProperty(n)}e.prototype.completeVisualOption.apply(this,arguments)},t.prototype._resetSelected=function(e,t){var n=this.option,r=this._pieceList,i=(t?n:e).selected||{};if(n.selected=i,L(r,function(e,t){var n=this.getSelectedMapKey(e);i.hasOwnProperty(n)||(i[n]=!0)},this),n.selectedMode===`single`){var a=!1;L(r,function(e,t){var n=this.getSelectedMapKey(e);i[n]&&(a?i[n]=!1:a=!0)},this)}},t.prototype.getItemSymbol=function(){return this.get(`itemSymbol`)},t.prototype.getSelectedMapKey=function(e){return this._mode===`categories`?e.value+``:e.index+``},t.prototype.getPieceList=function(){return this._pieceList},t.prototype._determineMode=function(){var e=this.option;return e.pieces&&e.pieces.length>0?`pieces`:this.option.categories?`categories`:`splitNumber`},t.prototype.setSelected=function(e){this.option.selected=F(e)},t.prototype.getValueState=function(e){var t=lq.findPieceIndex(e,this._pieceList);return t==null?`outOfRange`:this.option.selected[this.getSelectedMapKey(this._pieceList[t])]?`inRange`:`outOfRange`},t.prototype.findTargetDataIndices=function(e){var t=[],n=this._pieceList;return this.eachTargetSeries(function(r){var i=[],a=r.getData();a.each(this.getDataDimensionIndex(a),function(t,r){lq.findPieceIndex(t,n)===e&&i.push(r)},this),t.push({seriesId:r.id,dataIndex:i})},this),t},t.prototype.getRepresentValue=function(e){var t;if(this.isCategory())t=e.value;else if(e.value!=null)t=e.value;else{var n=e.interval||[];t=n[0]===-1/0&&n[1]===1/0?0:(n[0]+n[1])/2}return t},t.prototype.getVisualMeta=function(e){if(this.isCategory())return;var t=[],n=[``,``],r=this;function i(i,a){var o=r.getRepresentValue({interval:i});a||=r.getValueState(o);var s=e(o,a);i[0]===-1/0?n[0]=s:i[1]===1/0?n[1]=s:t.push({value:i[0],color:s},{value:i[1],color:s})}var a=this._pieceList.slice();if(!a.length)a.push({interval:[-1/0,1/0]});else{var o=a[0].interval[0];o!==-1/0&&a.unshift({interval:[-1/0,o]}),o=a[a.length-1].interval[1],o!==1/0&&a.push({interval:[o,1/0]})}var s=-1/0;return L(a,function(e){var t=e.interval;t&&(t[0]>s&&i([s,t[0]],`outOfRange`),i(t.slice()),s=t[1])},this),{stops:t,outerColors:n}},t.type=`visualMap.piecewise`,t.defaultOption=Zd(NY.defaultOption,{selected:null,minOpen:!1,maxOpen:!1,align:`auto`,itemWidth:20,itemHeight:14,itemSymbol:`roundRect`,pieces:null,categories:null,splitNumber:5,selectedMode:`multiple`,itemGap:10,hoverLink:!0}),t}(NY),HY={splitNumber:function(e){var t=this.option,n=Math.min(t.precision,20),r=this.getExtent(),i=t.splitNumber;i=Math.max(parseInt(i,10),1),t.splitNumber=i;for(var a=(r[1]-r[0])/i;+a.toFixed(n)!==a&&n<5;)n++;t.precision=n,a=+a.toFixed(n),t.minOpen&&e.push({interval:[-1/0,r[0]],close:[0,0]});for(var o=0,s=r[0];o<i;s+=a,o++){var c=o===i-1?r[1]:s+a;e.push({interval:[s,c],close:[1,1]})}t.maxOpen&&e.push({interval:[r[1],1/0],close:[0,0]}),Ts(e),L(e,function(e,t){e.index=t,e.text=this.formatValueText(e.interval)},this)},categories:function(e){var t=this.option;L(t.categories,function(t){e.push({text:this.formatValueText(t,!0),value:t})},this),pO(t,e)},pieces:function(e){var t=this.option;L(t.pieces,function(t,n){H(t)||(t={value:t});var r={text:``,index:n};if(t.label!=null&&(r.text=t.label),t.hasOwnProperty(`value`)){var i=r.value=t.value;r.interval=[i,i],r.close=[1,1]}else{for(var a=r.interval=[],o=r.close=[0,0],s=[1,0,1],c=[-1/0,1/0],l=[],u=0;u<2;u++){for(var d=[[`gte`,`gt`,`min`],[`lte`,`lt`,`max`]][u],f=0;f<3&&a[u]==null;f++)a[u]=t[d[f]],o[u]=s[f],l[u]=f===2;a[u]??(a[u]=c[u])}l[0]&&a[1]===1/0&&(o[0]=0),l[1]&&a[0]===-1/0&&(o[1]=0),a[0]===a[1]&&o[0]&&o[1]&&(r.value=a[0])}r.visual=lq.retrieveVisuals(t),e.push(r)},this),pO(t,e),Ts(e),L(e,function(e){var t=e.close,n=[[`<`,`≤`][t[1]],[`>`,`≥`][t[0]]];e.text=e.text||this.formatValueText(e.value==null?e.interval:e.value,!1,n)},this)}},UY=function(e){P(t,e);function t(){var n=e!==null&&e.apply(this,arguments)||this;return n.type=t.type,n}return t.prototype.doRender=function(){var e=this.group;e.removeAll();var t=this.visualMapModel,n=t.get(`textGap`),r=t.textStyleModel,i=this._getItemAlign(),a=t.itemSize,o=this._getViewData(),s=o.endsText,c=Cr(t.get(`showLabel`,!0),!s),l=!t.get(`selectedMode`);s&&this._renderEndsText(e,s[0],a,c,i),L(o.viewPieceList,function(o){var s=o.piece,u=new RI;u.onclick=q(this._onItemClick,this,s),this._enableHoverLink(u,o.indexInModelPieceList);var d=t.getRepresentValue(s);if(this._createItemSymbol(u,d,[0,0,a[0],a[1]],l),c){var f=this.visualMapModel.getValueState(d),p=r.get(`align`)||i;u.add(new wF({style:Lu(r,{x:p===`right`?-n:a[0]+n,y:a[1]/2,text:s.text,verticalAlign:r.get(`verticalAlign`)||`middle`,align:p,opacity:U(r.get(`opacity`),f===`outOfRange`?.5:1)}),silent:l}))}e.add(u)},this),s&&this._renderEndsText(e,s[1],a,c,i),Rz(t.get(`orient`),e,t.get(`itemGap`)),this.renderBackground(e),this.positionGroup(e)},t.prototype._enableHoverLink=function(e,t){var n=this;e.on(`mouseover`,function(){return r(`highlight`)}).on(`mouseout`,function(){return r(`downplay`)});var r=function(e){var r=n.visualMapModel;r.option.hoverLink&&n.api.dispatchAction({type:e,batch:cO(r.findTargetDataIndices(t),r)})}},t.prototype._getItemAlign=function(){var e=this.visualMapModel,t=e.option;if(t.orient===`vertical`)return sO(e,this.api,e.itemSize);var n=t.align;return n&&n!==`auto`||(n=`left`),n},t.prototype._renderEndsText=function(e,t,n,r,i){if(t){var a=new RI,o=this.visualMapModel.textStyleModel;a.add(new wF({style:Lu(o,{x:r?i===`right`?n[0]:0:n[0]/2,y:n[1]/2,verticalAlign:`middle`,align:r?i:`center`,text:t})})),e.add(a)}},t.prototype._getViewData=function(){var e=this.visualMapModel,t=R(e.getPieceList(),function(e,t){return{piece:e,indexInModelPieceList:t}}),n=e.get(`text`),r=e.get(`orient`),i=e.get(`inverse`);return(r===`horizontal`?i:!i)?t.reverse():n&&=n.slice().reverse(),{viewPieceList:t,endsText:n}},t.prototype._createItemSymbol=function(e,t,n,r){var i=em(this.getControllerVisual(t,`symbol`),n[0],n[1],n[2],n[3],this.getControllerVisual(t,`color`));i.silent=r,e.add(i)},t.prototype._onItemClick=function(e){var t=this.visualMapModel,n=t.option,r=n.selectedMode;if(r){var i=F(n.selected),a=t.getSelectedMapKey(e);r===`single`||r===!0?(i[a]=!0,L(i,function(e,t){i[t]=t===a})):i[a]=!i[a],this.api.dispatchAction({type:`selectDataRange`,from:this.uid,visualMapId:this.visualMapModel.id,selected:i})}},t.type=`visualMap.piecewise`,t}(PY),WY=[`align`,`verticalAlign`,`width`,`height`,`fontSize`],GY=new TN,KY=tc(),qY=tc(),JY=[`x`,`y`,`rotation`],YY=function(){function e(){this._labelList=[],this._chartViewList=[]}return e.prototype.clearLabels=function(){this._labelList=[],this._chartViewList=[]},e.prototype._addLabel=function(e,t,n,r,i){var a=r.style,o=r.__hostTarget.textConfig||{},s=r.getComputedTransform(),c=r.getBoundingRect().plain();Y.applyTransform(c,c,s),s?GY.setLocalTransform(s):(GY.x=GY.y=GY.rotation=GY.originX=GY.originY=0,GY.scaleX=GY.scaleY=1),GY.rotation=Po(GY.rotation);var l=r.__hostTarget,u;if(l){u=l.getBoundingRect().plain();var d=l.getComputedTransform();Y.applyTransform(u,u,d)}var f=u&&l.getTextGuideLine();this._labelList.push({label:r,labelLine:f,seriesModel:n,dataIndex:e,dataType:t,layoutOptionOrCb:i,layoutOption:null,rect:c,hostRect:u,priority:u?u.width*u.height:0,defaultAttr:{ignore:r.ignore,labelGuideIgnore:f&&f.ignore,x:GY.x,y:GY.y,scaleX:GY.scaleX,scaleY:GY.scaleY,rotation:GY.rotation,style:{x:a.x,y:a.y,align:a.align,verticalAlign:a.verticalAlign,width:a.width,height:a.height,fontSize:a.fontSize},cursor:r.cursor,attachedPos:o.position,attachedRot:o.rotation}})},e.prototype.addLabelsOfSeries=function(e){var t=this;this._chartViewList.push(e);var n=e.__model,r=n.get(`labelLayout`);(B(r)||fr(r).length)&&e.group.traverse(function(e){if(e.ignore)return!0;var i=e.getTextContent(),a=$F(e);i&&!i.disableLabelLayout&&t._addLabel(a.dataIndex,a.dataType,n,i,r)})},e.prototype.updateLayoutConfig=function(e){var t=e.getWidth(),n=e.getHeight();function r(e,t){return function(){Av(e,t)}}for(var i=0;i<this._labelList.length;i++){var a=this._labelList[i],o=a.label,s=o.__hostTarget,c=a.defaultAttr,l=void 0;l=B(a.layoutOptionOrCb)?a.layoutOptionOrCb(gO(a,s)):a.layoutOptionOrCb,l||={},a.layoutOption=l;var u=Math.PI/180;s&&s.setTextConfig({local:!1,position:l.x!=null||l.y!=null?null:c.attachedPos,rotation:l.rotate==null?c.attachedRot:l.rotate*u,offset:[l.dx||0,l.dy||0]});var d=!1;if(l.x==null?(o.x=c.x,o.setStyle(`x`,c.style.x)):(o.x=X(l.x,t),o.setStyle(`x`,0),d=!0),l.y==null?(o.y=c.y,o.setStyle(`y`,c.style.y)):(o.y=X(l.y,n),o.setStyle(`y`,0),d=!0),l.labelLinePoints){var f=s.getTextGuideLine();f&&(f.setShape({points:l.labelLinePoints}),d=!1)}var p=KY(o);p.needsUpdateLabelLine=d,o.rotation=l.rotate==null?c.rotation:l.rotate*u,o.scaleX=c.scaleX,o.scaleY=c.scaleY;for(var m=0;m<WY.length;m++){var h=WY[m];o.setStyle(h,l[h]==null?c.style[h]:l[h])}if(l.draggable){if(o.draggable=!0,o.cursor=`move`,s){var g=a.seriesModel;a.dataIndex!=null&&(g=a.seriesModel.getData(a.dataType).getItemModel(a.dataIndex)),o.on(`drag`,r(s,g.getModel(`labelLine`)))}}else o.off(`drag`),o.cursor=c.cursor}},e.prototype.layout=function(e){var t=e.getWidth(),n=e.getHeight(),r=[];L(this._labelList,function(e){e.defaultAttr.ignore||r.push(Vg({},e))});var i=ur(r,function(e){return e.layoutOption.moveOverlap===`shiftX`}),a=ur(r,function(e){return e.layoutOption.moveOverlap===`shiftY`});Ug(i,0,0,t),Ug(a,1,0,n);var o=ur(r,function(e){return e.layoutOption.hideOverlap});Wg(o),Gg(o)},e.prototype.processLabelsOverall=function(){var e=this;L(this._chartViewList,function(t){var n=t.__model,r=t.ignoreLabelLineUpdate,i=n.isAnimationEnabled();t.group.traverse(function(t){if(t.ignore&&!t.forceLabelAnimation)return!0;var a=!r,o=t.getTextContent();!a&&o&&(a=KY(o).needsUpdateLabelLine),a&&e._updateLabelLine(t,n),i&&e._animateLabels(t,n)})})},e.prototype._updateLabelLine=function(e,t){var n=e.getTextContent(),r=$F(e),i=r.dataIndex;if(n&&i!=null){var a=t.getData(r.dataType),o=a.getItemModel(i),s={},c=a.getItemVisual(i,`style`);c&&(s.stroke=c[a.getVisual(`drawType`)]);var l=o.getModel(`labelLine`);Fv(e,Iv(o),s),Av(e,l)}},e.prototype._animateLabels=function(e,t){var n=e.getTextContent(),r=e.getTextGuideLine();if(n&&(e.forceLabelAnimation||!n.ignore&&!n.invisible&&!e.disableLabelAnimation&&!Wl(e))){var i=KY(n),a=i.oldLayout,o=$F(e),s=o.dataIndex,c={x:n.x,y:n.y,rotation:n.rotation},l=t.getData(o.dataType);if(a){n.attr(a);var u=e.prevStates;u&&(ar(u,`select`)>=0&&n.attr(i.oldLayoutSelect),ar(u,`emphasis`)>=0&&n.attr(i.oldLayoutEmphasis)),Hl(n,c,t,s)}else if(n.attr(c),!KL(n).valueAnimation){var d=U(n.style.opacity,1);n.style.opacity=0,Ul(n,{style:{opacity:d}},t,s)}if(i.oldLayout=c,n.states.select){var f=i.oldLayoutSelect={};_O(f,c,JY),_O(f,n.states.select,JY)}if(n.states.emphasis){var p=i.oldLayoutEmphasis={};_O(p,c,JY),_O(p,n.states.emphasis,JY)}Wu(n,s,l,t,t)}if(r&&!r.ignore&&!r.invisible){var i=qY(r),a=i.oldLayout,m={points:r.shape.points};a?(r.attr({shape:a}),Hl(r,{shape:m},t)):(r.setShape(m),r.style.strokePercent=0,Ul(r,{style:{strokePercent:1}},t)),i.oldLayout=m}},e}(),XY=tc(),ZY=function(){function e(t,n){Fm(this,e.decoratedMethods),this._outOfBrk=Vm(null,n);var r=this._linear=Vm(null,n);Im(this,r),this.breaks=t&&t.breaks||[]}return e.prototype.hasBreaks=function(){return!!this.breaks.length},e.prototype.calcNiceTickMultiple=function(e,t){for(var n=0;n<this.breaks.length;n++){var r=this.breaks[n];if(r.vmin<e&&e<r.vmax)return t(e,r.vmax)}return 0},e.decoratedMethods={needTransform:function(){return!this.breaks.length},getExtent:function(){return this._outOfBrk.getExtent()},getExtentUnsafe:function(e,t){return t==null||t===2?this._outOfBrk.getExtentUnsafe(e,null):this._linear.getExtentUnsafe(e,null)},setExtent:function(e,t){this.setExtent2(0,e,t)},setExtent2:function(e,t,n){_c(t,n)&&(e===0&&bO(this,[t,n]),this._outOfBrk.setExtent2(e,t,n),this._linear.setExtent2(e,this.transformIn(t,null),this.transformIn(n,null)))},normalize:function(e){return this._linear.normalize(this.transformIn(e,null))},scale:function(e){return this.transformOut(this._linear.scale(e),null)},contain:function(e){return this._outOfBrk.contain(e)},transformIn:function(e,t){if(t&&t.depth===2)return e;for(var n=QY,r=$Y,i=!0,a=0;a<this.breaks.length;a++){var o=this.breaks[a];if(e<=o.vmax){e>o.vmin?n+=o.vmin-r+(e-o.vmin)/(o.vmax-o.vmin)*o.gapReal:n+=e-r,r=o.vmax,i=!1;break}n+=o.vmin-r+o.gapReal,r=o.vmax}return i&&(n+=e-r),n},transformOut:function(e,t){if(t&&t.depth===2)return e;for(var n=QY,r=$Y,i=!0,a=0,o=0;o<this.breaks.length;o++){var s=this.breaks[o],c=n+s.vmin-r,l=c+s.gapReal;if(e<=l){a=e>c?s.vmin+(e-c)/(l-c)*(s.vmax-s.vmin):r+e-n,r=s.vmax,i=!1;break}n=l,r=s.vmax}return i&&(a=r+e-n),a}},e}(),QY=0,$Y=0,eX={vmin:`start`,vmax:`end`},tX=tc(),nX=Math.sin,rX=Math.cos,iX=Math.PI,aX=Math.PI*2,oX=180/iX,sX=function(){function e(){}return e.prototype.reset=function(e){this._start=!0,this._d=[],this._str=``,this._p=10**(e||4)},e.prototype.moveTo=function(e,t){this._add(`M`,e,t)},e.prototype.lineTo=function(e,t){this._add(`L`,e,t)},e.prototype.bezierCurveTo=function(e,t,n,r,i,a){this._add(`C`,e,t,n,r,i,a)},e.prototype.quadraticCurveTo=function(e,t,n,r){this._add(`Q`,e,t,n,r)},e.prototype.arc=function(e,t,n,r,i,a){this.ellipse(e,t,n,n,0,r,i,a)},e.prototype.ellipse=function(e,t,n,r,i,a,o,s){var c=o-a,l=!s,u=Math.abs(c),d=za(u-aX)||(l?c>=aX:-c>=aX),f=c>0?c%aX:c%aX+aX,p=!1;p=d?!0:!za(u)&&f>=iX==!!l;var m=e+n*rX(a),h=t+r*nX(a);this._start&&this._add(`M`,m,h);var g=Math.round(i*oX);if(d){var _=1/this._p,v=(l?1:-1)*(aX-_);this._add(`A`,n,r,g,1,+l,e+n*rX(a+v),t+r*nX(a+v)),_>.01&&this._add(`A`,n,r,g,0,+l,m,h)}else{var y=e+n*rX(o),b=t+r*nX(o);this._add(`A`,n,r,g,+p,+l,y,b)}},e.prototype.rect=function(e,t,n,r){this._add(`M`,e,t),this._add(`l`,n,0),this._add(`l`,0,r),this._add(`l`,-n,0),this._add(`Z`)},e.prototype.closePath=function(){this._d.length>0&&this._add(`Z`)},e.prototype._add=function(e,t,n,r,i,a,o,s,c){for(var l=[],u=this._p,d=1;d<arguments.length;d++){var f=arguments[d];if(isNaN(f)){this._invalid=!0;return}l.push(Math.round(f*u)/u)}this._d.push(e+l.join(` `)),this._start=e===`Z`},e.prototype.generateStr=function(){this._str=this._invalid?``:this._d.join(``),this._d=[]},e.prototype.getStr=function(){return this._str},e}(),cX=`none`,lX=Math.round,uX=[`lineCap`,`miterLimit`,`lineJoin`],dX=R(uX,function(e){return`stroke-`+e.toLowerCase()}),fX=`http://www.w3.org/2000/svg`,pX=`http://www.w3.org/1999/xlink`,mX=`http://www.w3.org/2000/xmlns/`,hX=`http://www.w3.org/XML/1998/namespace`,gX=`ecmeta_`,_X=0,vX={cubicIn:`0.32,0,0.67,0`,cubicOut:`0.33,1,0.68,1`,cubicInOut:`0.65,0,0.35,1`,quadraticIn:`0.11,0,0.5,0`,quadraticOut:`0.5,1,0.89,1`,quadraticInOut:`0.45,0,0.55,1`,quarticIn:`0.5,0,0.75,0`,quarticOut:`0.25,1,0.5,1`,quarticInOut:`0.76,0,0.24,1`,quinticIn:`0.64,0,0.78,0`,quinticOut:`0.22,1,0.36,1`,quinticInOut:`0.83,0,0.17,1`,sinusoidalIn:`0.12,0,0.39,0`,sinusoidalOut:`0.61,1,0.88,1`,sinusoidalInOut:`0.37,0,0.63,1`,exponentialIn:`0.7,0,0.84,0`,exponentialOut:`0.16,1,0.3,1`,exponentialInOut:`0.87,0,0.13,1`,circularIn:`0.55,0,1,0.45`,circularOut:`0,0.55,0.45,1`,circularInOut:`0.85,0,0.15,1`},yX=`transform-origin`,bX={fill:`fill`,opacity:`opacity`,lineWidth:`stroke-width`,lineDashOffset:`stroke-dashoffset`},xX=Math.round,SX={circle:[gk([`cx`,`cy`,`r`])],polyline:[mk,hk],polygon:[mk,hk]},CX=58,wX=120,TX=GO(``,``),EX=0,DX=function(){function e(e,t,n){if(this.type=`svg`,this.configLayer=Wk(`configLayer`),this.storage=t,this._opts=n=I({},n),this.root=e,this._id=`zr`+EX++,this._oldVNode=ZO(n.width,n.height),e&&!n.ssr){var r=this._viewport=document.createElement(`div`);r.style.cssText=`position:relative;overflow:hidden`;var i=this._svgDom=this._oldVNode.elm=WO(`svg`);Bk(null,this._oldVNode),r.appendChild(i),e.appendChild(r)}this.resize(n.width,n.height)}return e.prototype.getType=function(){return this.type},e.prototype.getViewportRoot=function(){return this._viewport},e.prototype.getViewportRootOffset=function(){var e=this.getViewportRoot();if(e)return{offsetLeft:e.offsetLeft||0,offsetTop:e.offsetTop||0}},e.prototype.getSvgDom=function(){return this._svgDom},e.prototype.refresh=function(){if(this.root){var e=this.renderToVNode({willUpdate:!0});e.attrs.style=`position:absolute;left:0;top:0;user-select:none`,Uk(this._oldVNode,e),this._oldVNode=e}},e.prototype.renderOneToVNode=function(e){return xk(e,XO(this._id))},e.prototype.renderToVNode=function(e){e||={};var t=this.storage.getDisplayList(!0),n=this._width,r=this._height,i=XO(this._id);i.animation=e.animation,i.willUpdate=e.willUpdate,i.compress=e.compress,i.emphasis=e.emphasis,i.ssr=this._opts.ssr;var a=[],o=this._bgVNode=Gk(n,r,this._backgroundColor,i);o&&a.push(o);var s=e.compress?null:this._mainVNode=GO(`g`,`main`,{},[]);this._paintList(t,i,s?s.children:a),s&&a.push(s);var c=R(fr(i.defs),function(e){return i.defs[e]});if(c.length&&a.push(GO(`defs`,`defs`,{},c)),e.animation){var l=YO(i.cssNodes,i.cssAnims,{newline:!0});if(l){var u=GO(`style`,`stl`,{},[],l);a.push(u)}}return ZO(n,r,a,e.useViewBox)},e.prototype.renderToString=function(e){return e||={},JO(this.renderToVNode({animation:U(e.cssAnimation,!0),emphasis:U(e.cssEmphasis,!0),willUpdate:!1,compress:!0,useViewBox:U(e.useViewBox,!0)}),{newline:!0})},e.prototype.setBackgroundColor=function(e){this._backgroundColor=e},e.prototype.getSvgRoot=function(){return this._mainVNode&&this._mainVNode.elm},e.prototype._paintList=function(e,t,n){for(var r=e.length,i=[],a=0,o,s,c=0,l=0;l<r;l++){var u=e[l];if(!u.invisible){var d=u.__clipPaths,f=d&&d.length||0,p=s&&s.length||0,m=void 0;for(m=Math.max(f-1,p-1);m>=0&&!(d&&s&&d[m]===s[m]);m--);for(var h=p-1;h>m;h--)a--,o=i[a-1];for(var g=m+1;g<f;g++){var _={};Tk(d[g],_,t);var v=GO(`g`,`clip-g-`+c++,_,[]);(o?o.children:n).push(v),i[a++]=v,o=v}s=d;var y=xk(u,t);y&&(o?o.children:n).push(y)}}},e.prototype.resize=function(e,t){var n=this._opts,r=this.root,i=this._viewport;if(e!=null&&(n.width=e),t!=null&&(n.height=t),r&&i&&(i.style.display=`none`,e=Fb(r,0,n),t=Fb(r,1,n),i.style.display=``),this._width!==e||this._height!==t){if(this._width=e,this._height=t,i){var a=i.style;a.width=e+`px`,a.height=t+`px`}if(Ja(this._backgroundColor))this.refresh();else{var o=this._svgDom;o&&(o.setAttribute(`width`,e),o.setAttribute(`height`,t));var s=this._bgVNode&&this._bgVNode.elm;s&&(s.setAttribute(`width`,e),s.setAttribute(`height`,t))}}},e.prototype.getWidth=function(){return this._width},e.prototype.getHeight=function(){return this._height},e.prototype.dispose=function(){this.root&&(this.root.innerHTML=``),this._svgDom=this._viewport=this.storage=this._oldVNode=this._bgVNode=this._mainVNode=null},e.prototype.clear=function(){this._svgDom&&(this._svgDom.innerHTML=null),this._oldVNode=null},e.prototype.toDataURL=function(e){var t=this.renderToString(),n=`data:image/svg+xml;`;return e?(t=qN(t),t&&n+`base64,`+t):n+`charset=UTF-8,`+encodeURIComponent(t)},e}(),OX=function(e){P(t,e);function t(t,n,r){var i=e.call(this)||this;i.motionBlur=!1,i.lastFrameAlpha=.7,i.dpr=1,i.virtual=!1,i.config={},i.zlevel=0,i.zlevel2=0,i.maxRepaintRectCount=5,i.__dirty=!0,i.__firstTimePaint=!0,i.__prevIdx={startIdx:0,endIdx:0};var a;r||=sP,typeof t==`string`?a=qk(t,n,r):H(t)&&(a=t,t=a.id),i.id=t,i.dom=a;var o=a.style;return o&&(Pr(a),a.onselectstart=function(){return!1},o.padding=`0`,o.margin=`0`,o.borderWidth=`0`),i.painter=n,i.dpr=r,i}return t.prototype.afterBrush=function(){this.__prevIdx=Yk(this)},t.prototype.initContext=function(){this.ctx=this.dom.getContext(`2d`),this.ctx.dpr=this.dpr},t.prototype.setUnpainted=function(){this.__firstTimePaint=!0},t.prototype.createBackBuffer=function(){var e=this.dpr;this.domBack=qk(`back-`+this.id,this.painter,e),this.ctxBack=this.domBack.getContext(`2d`),e!==1&&this.ctxBack.scale(e,e)},t.prototype.createRepaintRects=function(e,t,n,r){if(this.__firstTimePaint)return this.__firstTimePaint=!1,null;var i=[],a=this.maxRepaintRectCount,o=!1,s=new Y(0,0,0,0);function c(e){if(e.isFinite()&&!e.isZero()){if(i.length===0){var t=new Y(0,0,0,0);t.copy(e),i.push(t)}else{for(var n=!1,r=1/0,c=0,l=0;l<i.length;++l){var u=i[l];if(u.intersect(e)){var d=new Y(0,0,0,0);d.copy(u),d.union(e),i[l]=d,n=!0;break}if(o){s.copy(e),s.union(u);var f=e.width*e.height,p=u.width*u.height,m=s.width*s.height-f-p;m<r&&(r=m,c=l)}}if(o&&(i[c].union(e),n=!0),!n){var t=new Y(0,0,0,0);t.copy(e),i.push(t)}o||=i.length>=a}}}for(var l=Yk(this),u=l.startIdx;u<l.endIdx;++u){var d=e[u];if(d){var f=d.shouldBePainted(n,r,!0,!0),p=d.__isRendered&&(d.__dirty&1||!f)?d.getPrevPaintRect():null;p&&c(p);var m=f&&(d.__dirty&1||!d.__isRendered)?d.getPaintRect():null;m&&c(m)}}for(var h=this.__prevIdx,u=h.startIdx;u<h.endIdx;++u){var d=t[u],f=d&&d.shouldBePainted(n,r,!0,!0);if(d&&(!f||!d.__zr)&&d.__isRendered){var p=d.getPrevPaintRect();p&&c(p)}}var g;do{g=!1;for(var u=0;u<i.length;)if(i[u].isZero())i.splice(u,1);else{for(var _=u+1;_<i.length;)i[u].intersect(i[_])?(g=!0,i[u].union(i[_]),i.splice(_,1)):_++;u++}}while(g);return this._paintRects=i,i},t.prototype.debugGetPaintRects=function(){return(this._paintRects||[]).slice()},t.prototype.resize=function(e,t){var n=this.dpr,r=this.dom,i=r.style,a=this.domBack;i&&(i.width=e+`px`,i.height=t+`px`),r.width=e*n,r.height=t*n,a&&(a.width=e*n,a.height=t*n,n!==1&&this.ctxBack.scale(n,n))},t.prototype.clear=function(e,t,n){var r=this.dom,i=this.ctx,a=r.width,o=r.height;t||=this.clearColor;var s=this.motionBlur&&!e,c=this.lastFrameAlpha,l=this.dpr,u=this;s&&(this.domBack||this.createBackBuffer(),this.ctxBack.globalCompositeOperation=`copy`,this.ctxBack.drawImage(r,0,0,a/l,o/l));var d=this.domBack;function f(e,n,r,a){if(i.clearRect(e,n,r,a),t&&t!==`transparent`){var o=void 0;br(t)?(o=(t.global||t.__width===r&&t.__height===a)&&t.__canvasGradient||Mb(i,t,{x:0,y:0,width:r,height:a}),t.__canvasGradient=o,t.__width=r,t.__height=a):xr(t)&&(t.scaleX=t.scaleX||l,t.scaleY=t.scaleY||l,o=Ub(i,t,{dirty:function(){u.setUnpainted(),u.painter.refresh()}})),i.save(),i.fillStyle=o||t,i.fillRect(e,n,r,a),i.restore()}s&&(i.save(),i.globalAlpha=c,i.drawImage(d,e,n,r,a),i.restore())}!n||s?f(0,0,a,o):n.length&&L(n,function(e){f(e.x*l,e.y*l,e.width*l,e.height*l)})},t}(aP),kX=1e5,AX=314159,jX=void 0,MX=1,NX=2,PX=1,FX=2,IX=4,LX=PX|IX,RX=function(){function e(e,t,n,r){this.type=`canvas`,this._prevDisplayList=[],this._layerConfig={},this._needsManuallyCompositing=!1,this.type=`canvas`,this._i={layerStack:[],layers:[]};var i=!e.nodeName||e.nodeName.toUpperCase()===`CANVAS`;if(this._opts=n=I({},n||{}),this.dpr=n.devicePixelRatio||sP,this._singleCanvas=i,this.root=e,e.style&&(Pr(e),e.innerHTML=``),this.storage=t,this._prevDisplayList=[],i){var a=e,o=a.width,s=a.height;n.width!=null&&(o=n.width),n.height!=null&&(s=n.height),this.dpr=n.devicePixelRatio||1,a.width=o*this.dpr,a.height=s*this.dpr,this._width=o,this._height=s;var c=Qk(a,this,AX,0);c.initContext(),this._insertLayer(c,AX,0,!0),this._domRoot=e}else{this._width=Fb(e,0,n),this._height=Fb(e,1,n);var l=this._domRoot=Zk(this._width,this._height);e.appendChild(l)}}return e.prototype.getType=function(){return`canvas`},e.prototype.isSingleCanvas=function(){return this._singleCanvas},e.prototype.getViewportRoot=function(){return this._domRoot},e.prototype.getViewportRootOffset=function(){var e=this.getViewportRoot();if(e)return{offsetLeft:e.offsetLeft||0,offsetTop:e.offsetTop||0}},e.prototype.refresh=function(e){var t=e&&!H(e)?{paintAll:!!e}:e||{},n=U(t.refresh,!0),r=U(t.refreshHover,!1);if(r&&(this._hoverLayerDirty=NX),!n)return r&&this._paintHoverList(this.storage.getDisplayList(!1)),this;var i=this.storage.getDisplayList(!0);this._updateLayerStatus(i,t.paintAll),this._redrawId=Math.random();var a=this._prevDisplayList;this._paintList(i,a,this._redrawId);var o=this._backgroundColor;return iA(this._i,function(e,t,n,r){e.refresh&&e.refresh(r===0?o:null)},FX),this._opts.useDirtyRect&&(this._prevDisplayList=i.slice()),this},e.prototype._paintHoverList=function(e){var t=this._i.hoverlayer,n=this._hoverLayerDirty;if(this._hoverLayerDirty=jX,n!==jX&&(!t&&n===NX&&(t=this._i.hoverlayer=this._ensureLayer(kX)),t)){t.clear();for(var r={inHover:!0,viewWidth:this._width,viewHeight:this._height,beforeBrushParam:{}},i,a=0,o=e.length;a<o;a++){var s=e[a];if(s.__inHover){i||(i=t.ctx,i.save());var c=s.__hoverStyle,l=void 0;c&&(l=s.style,s.style=c),nx(i,s,r),c&&(s.style=l)}}i&&(rx(i,r),i.restore())}},e.prototype.getHoverLayer=function(){return this._ensureLayer(kX)},e.prototype.paintOne=function(e,t){tx(e,t)},e.prototype._paintList=function(e,t,n){if(this._redrawId===n){var r=this._doPaintList(e,t);if(this._needsManuallyCompositing&&this._compositeManually(),r)iA(this._i,function(e){e.afterBrush&&e.afterBrush()},LX),this._paintHoverList(e);else{var i=this;eU(function(){i._paintList(e,t,n)})}}},e.prototype._compositeManually=function(){var e=this._ensureLayer(AX).ctx,t=this._domRoot.width,n=this._domRoot.height;e.clearRect(0,0,t,n),iA(this._i,function(r){r.virtual&&e.drawImage(r.dom,0,0,t,n)},PX)},e.prototype._doPaintList=function(e,t){var n=this,r=!0;return iA(this._i,function(i){var a=!1;if(nA(i,function(e){(e.drawIdx<e.endIdx||e.notClearIdx>=0)&&(a=!0)}),a||i.__dirty){var o=n._opts.useDirtyRect&&!Jk(i)?i.createRepaintRects(e,t,n._width,n._height):null,s=n._i.layerStack[0],c=!0;if(i.__dirty){c=!1,i.__dirty=!1;var l=i.zlevel===s.zl&&i.zlevel2===s.zl2?n._backgroundColor:null;i.clear(!1,l,o)}nA(i,function(t){var a=n._paintPerCursor(i,t,e,o,c);r&&=a})}},LX),OM.wxa&&iA(this._i,function(e){e&&e.ctx&&e.ctx.draw&&e.ctx.draw()}),r},e.prototype._paintPerCursor=function(e,t,n,r,i){var a=e.ctx;if(r){if(!r.length)t.drawIdx=t.endIdx;else for(var o=this.dpr,s=0;s<r.length;++s){var c=r[s];a.save(),a.beginPath(),a.rect(c.x*o,c.y*o,c.width*o,c.height*o),a.clip(),this._paintPerCursorInRect(e,t,n,c,i),a.restore()}}else a.save(),this._paintPerCursorInRect(e,t,n,null,i),a.restore();return t.drawIdx>=t.endIdx},e.prototype._paintPerCursorInRect=function(e,t,n,r,i){for(var a={inHover:!1,allClipped:!1,prevEl:null,viewWidth:this._width,viewHeight:this._height,beforeBrushParam:{contentRetained:i}},o=e.ctx,s=Jk(e),c=s&&cM.getTime(),l=t.drawIdx,u=t.notClearIdx,d=u>=0?Math.min(u,l):l;d<t.endIdx;d++){var f=n[d];if(!(d<l&&!f.notClear)){if(f.__inHover&&(this._hoverLayerDirty=NX),r!=null){var p=f.getPaintRect();p&&p.intersect(r)&&(nx(o,f,a),f.setPrevPaintRect(p))}else nx(o,f,a);if(s&&cM.getTime()-c>15){d++;break}}}rx(o,a),t.drawIdx=Math.max(d,l)},e.prototype.getLayer=function(e,t){return this._ensureLayer(e,0,t)},e.prototype._ensureLayer=function(e,t,n){t||=0;var r=this._singleCanvas;r&&!this._needsManuallyCompositing&&(e=AX,t=0);var i=rA(this._i,e)[t];return i||(i=Qk(`zr_`+e+`.`+t,this,e,t),this._layerConfig[e]&&nr(i,this._layerConfig[e],!0),(n||r&&e!==AX)&&(i.virtual=!0),this._insertLayer(i,e,t,!1),i.initContext()),i},e.prototype.insertLayer=function(e,t){this._insertLayer(t,e,0,!1)},e.prototype._insertLayer=function(e,t,n,r){var i=this._i,a=i.layers,o=i.layerStack,s=this._domRoot,c=null;if(!(a[t]&&a[t][n])&&Xk(e)){for(var l=o.length,u=0;u<l&&(o[u].zl<t||o[u].zl===t&&o[u].zl2<n);)u++;if(u>0&&(c=rA(i,o[u-1].zl)[o[u-1].zl2]),o.splice(u,0,{zl:t,zl2:n}),rA(i,t)[n]=e,!r&&!e.virtual){if(c){var d=c.dom;d.nextSibling?s.insertBefore(e.dom,d.nextSibling):s.appendChild(e.dom)}else s.firstChild?s.insertBefore(e.dom,s.firstChild):s.appendChild(e.dom)}e.painter||=this}},e.prototype.eachLayer=function(e,t){return iA(this._i,function(n,r){e.call(t,n,r)})},e.prototype.eachBuiltinLayer=function(e,t){return iA(this._i,function(n,r){e.call(t,n,r)},PX)},e.prototype.eachOtherLayer=function(e,t){return iA(this._i,function(n,r){e.call(t,n,r)},FX)},e.prototype.getLayers=function(){var e={};return iA(this._i,function(t,n,r){e[t.id]=t}),e},e.prototype._updateLayerStatus=function(e,t){var n=this;if(n._singleCanvas)for(var r=1;r<e.length;r++){var i=e[r];if(i.zlevel!==e[r-1].zlevel||i.incremental){n._needsManuallyCompositing=!0;break}}iA(n._i,function(e){e.__dirty=!1,nA(e,function(e){e.used=!1,e.endIdxNew=0,e.notClearIdx=-1})},LX);for(var a,o=null,s=null,c=!1,l=0,u=e.length;l<u;l++){var i=e[l],d=i.zlevel,f=i.incremental,p=void 0;if(a!==d&&(a=d,c=!1),f?(c=!0,p=1):p=c?2:0,(!o||d!==o.zlevel||p!==o.zlevel2)&&(o=n._ensureLayer(d,p),s=null,!o.__builtin__))tr(`ZLevel `+d+` has been used by unknown layer `+o.id);else{if((!s||f!==s.key)&&(s=tA(o,f),!s.used)){if(s.used=!0,!t&&s.first===i.id){var m=l-s.startIdx;s.startIdx=l,s.drawIdx+=m,s.endIdx+=m}else o.__dirty=!0,s.first=i.id,s.startIdx=s.drawIdx=l,s.endIdx=l+1}s.endIdxNew=l+1,i.__dirty&1&&!i.__inHover&&((!f||!i.notClear&&l<s.drawIdx)&&(o.__dirty=!0),f&&i.notClear&&s.notClearIdx<0&&(s.notClearIdx=l))}}iA(n._i,function(t){for(var r=t.__cursorStack,i=t.__cursors,a=r.length-1;a>=0;a--){var o=i.get(r[a]);if(!o.used)t.__dirty=!0,i.removeKey(r[a]),r.splice(a,1);else{var s=o.endIdxNew;(Jk(t)?s<o.drawIdx:s!==o.endIdx||!s||e[s-1].id!==o.last)&&(t.__dirty=!0),o.endIdx=o.endIdxNew,o.last=s?e[s-1].id:NaN}}t.__dirty&&(nA(t,function(e){e.drawIdx=e.startIdx}),n._hoverLayerDirty===jX&&(n._hoverLayerDirty=MX))},LX)},e.prototype.clear=function(){return iA(this._i,function(e){e.clear(),$k(e)},PX),this},e.prototype.setBackgroundColor=function(e){this._backgroundColor=e,iA(this._i,function(e){e.setUnpainted()})},e.prototype.configLayer=function(e,t){if(t){var n=this._layerConfig;n[e]?nr(n[e],t,!0):n[e]=t,iA(this._i,function(e,t){nr(e,n[t],!0)})}},e.prototype.delLayer=function(e){for(var t=this._i.layerStack,n=this._i.layers,r=t.length-1;r>=0;r--){var i=t[r];if(i.zl===e){var a=n[e][i.zl2];if(a.__builtin__)continue;if(t.splice(r,1),n[e][i.zl2]=void 0,!a.virtual){var o=a.dom.parentNode;o&&o.removeChild(a.dom)}}}},e.prototype.resize=function(e,t){if(this._domRoot.style){var n=this._domRoot;n.style.display=`none`;var r=this._opts,i=this.root;e!=null&&(r.width=e),t!=null&&(r.height=t),e=Fb(i,0,r),t=Fb(i,1,r),n.style.display=``,(this._width!==e||t!==this._height)&&(n.style.width=e+`px`,n.style.height=t+`px`,iA(this._i,function(n){n.resize(e,t)}),this.refresh({paintAll:!0})),this._width=e,this._height=t}else{if(e==null||t==null)return;this._width=e,this._height=t,this._ensureLayer(AX).resize(e,t)}return this},e.prototype.clearLayer=function(e){L(this._i.layers[e],function(e){e&&!e.__builtin__&&e.clear()})},e.prototype.dispose=function(){this.root.innerHTML=``,this.root=this.storage=this._domRoot=this._i=null},e.prototype.getRenderedCanvas=function(e){if(e||={},this._singleCanvas&&!this._compositeManually)return this._i.layers[AX][0].dom;var t=new OX(`image`,this,e.pixelRatio||this.dpr);t.initContext(),t.clear(!1,e.backgroundColor||this._backgroundColor);var n=t.ctx;if(e.pixelRatio<=this.dpr){this.refresh();var r=t.dom.width,i=t.dom.height;iA(this._i,function(e){e.__builtin__?n.drawImage(e.dom,0,0,r,i):e.renderToCanvas&&(n.save(),e.renderToCanvas(n),n.restore())})}else{for(var a={inHover:!1,viewWidth:this._width,viewHeight:this._height,beforeBrushParam:{}},o=this.storage.getDisplayList(!0),s=0,c=o.length;s<c;s++){var l=o[s];nx(n,l,a)}rx(n,a)}return t.dom},e.prototype.getWidth=function(){return this._width},e.prototype.getHeight=function(){return this._height},e}(),zX=Object.freeze({INR:`₹`,USD:`$`,EUR:`€`,GBP:`£`}),BX=e=>typeof e==`string`&&/^[A-Z]{3}$/.test(e),VX=(e=`INR`)=>zX[e]??`${e} `,HX=`Asia/Kolkata`,UX=198e5,WX=new Map,GX=[`number`,`currency`,`percent`,`compact`,`duration`,`date`],KX=[`rupees`,`paise`],qX=[`ms`,`s`,`min`,`h`],JX=[`day`,`month`,`year`,`datetime`,`time`],YX=`−`,XX=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ZX=[[1e7,`Cr`],[1e5,`L`],[1e3,`K`]],QX=(e,t)=>Number.isInteger(e)&&e>=0&&e<=20?e:t,$X=new Map,eZ=e=>($X.has(e)||$X.set(e,new Intl.NumberFormat(`en-IN`,{minimumFractionDigits:0,maximumFractionDigits:e})),$X.get(e)),tZ=new Map,nZ=e=>(tZ.has(e)||tZ.set(e,new Intl.NumberFormat(`en-IN`,{minimumFractionDigits:e,maximumFractionDigits:e})),tZ.get(e)),rZ=e=>typeof e==`number`&&Number.isFinite(e),iZ=e=>e<0&&!Object.is(Math.abs(e),0)?YX:``,aZ=(e,t)=>t===`paise`?e/100:e,oZ=e=>e>0&&e<.1?Math.min(20,1-Math.floor(Math.log10(e))):2,sZ=[`line`,`area`,`column`,`bar`,`donut`,`heatmap`,`calendar`,`funnel`,`gauge`,`waterfall`,`treemap`,`sankey`,`scatter`,`bubble`,`multiples`],cZ=[`none`,`stacked`,`percent`],lZ=[`category`,`time`,`value`],uZ=[`auto`,`svg`,`canvas`],dZ=[`ready`,`loading`,`empty`,`error`],fZ=[`chart`,`table`],pZ=`Other`,mZ=`No data to show for this chart.`,hZ=`This chart couldn't load. Try again in a moment.`,gZ=`Loading chart`,_Z=`This chart has more series than it can show clearly.`,vZ=`This chart has more groups than it can show clearly.`,yZ={line:`Line chart`,area:`Area chart`,column:`Column chart`,bar:`Bar chart`,donut:`Donut chart`,heatmap:`Heatmap`,calendar:`Calendar heatmap`,funnel:`Funnel chart`,gauge:`Gauge`,waterfall:`Waterfall chart`,treemap:`Treemap`,sankey:`Sankey diagram`,scatter:`Scatter plot`,bubble:`Bubble chart`,multiples:`Small multiples`},bZ=[`donut`,`heatmap`,`calendar`,`funnel`,`gauge`,`waterfall`,`treemap`,`sankey`,`scatter`,`bubble`],xZ=e=>bZ.includes(e),SZ=[`area`,`column`,`bar`],CZ=[`line`,`area`,`column`,`bar`,`multiples`],wZ={line:[`category`,`time`],area:[`category`,`time`],column:[`category`,`time`],bar:[`category`,`time`],multiples:[`category`,`time`],calendar:[`time`],scatter:[`value`],bubble:[`value`]},TZ={group:[`heatmap`,`treemap`,`scatter`,`bubble`],to:[`sankey`],size:[`bubble`],trend:[`scatter`,`bubble`],zoom:[`line`,`area`],bands:[`gauge`],centerLabel:[`donut`],valueLabels:[`column`,`bar`]},EZ={gauge:240,calendar:200,treemap:340,sankey:340},DZ=100,OZ=72,kZ=32,AZ=[`type`,`title`,`description`,`data`,`x`,`series`,`group`,`to`,`size`,`trend`,`zoom`,`bands`,`stack`,`y`,`target`,`centerLabel`,`valueLabels`,`height`,`state`,`emptyText`,`errorText`,`loadingText`,`renderer`,`timeZone`],jZ=[`key`,`kind`,`format`,`label`,`labelFit`],MZ=[`auto`,`all`,`rotate`,`ellipsis`],NZ=[`key`,`label`,`format`],PZ=[`key`,`label`],FZ=[`key`,`label`,`format`],IZ=[`upTo`,`label`],LZ=[`label`,`format`,`min`,`max`,`wholeNumbers`],RZ=[`value`,`label`],zZ=[`style`,`currency`,`unit`,`decimals`,`pattern`],BZ=new Set,VZ=e=>e.map(e=>`"${e}"`).join(` | `),HZ=e=>typeof e==`number`&&Number.isFinite(e),UZ=e=>typeof e==`object`&&!!e&&!Array.isArray(e),WZ=e=>e?.currency==null||BX(e.currency)?e:{...e,currency:void 0},GZ=e=>[...new Set(e)],KZ=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],qZ=e=>e.reduce((e,t)=>t<e?t:e,1/0),JZ=e=>e.reduce((e,t)=>t>e?t:e,-1/0),YZ=(e,t)=>e.data.map((n,r)=>K(e,t,r)).filter(e=>e!=null),XZ=(e,t)=>t?G(e/t,{style:`percent`}):`-`,ZZ=(e,t)=>t==null?`-`:qA(e,t).label,QZ=(e,t,n)=>{if(!t.length)return null;let r=qZ(t),i=JZ(t);return r===i?`${e} is ${G(r,n)}.`:`${e} runs from ${G(r,n)} to ${G(i,n)}.`},$Z=(e,t)=>G(K(e,e.series[0].key,t),e.series[0].format),eQ=864e5,tQ={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1},nQ=[`donut`,`funnel`,`waterfall`,`treemap`,`sankey`,`scatter`,`bubble`],Mx([qh,vv,Gv,fT,Pw,kw,pw,lT,gS,pE,cD,GD,jD,OE,gE,mO,oO,pD,BO,vO,Kk,aA]),rQ=[`series`,`graphic`,`grid`,`xAxis`,`yAxis`,`title`,`visualMap`,`calendar`,`dataZoom`],iQ=e=>String(e).replace(/[{}]/g,e=>e===`{`?`{`:`}`),aQ=(e,t)=>{let n=e.filter(e=>e!=null&&Number.isFinite(e));return[Math.min(...t?[0,...n]:n),Math.max(...t?[0,...n]:n)]},oQ=24,sQ=4,cQ=.6,lQ=(e,t)=>String(e).length*t*cQ,uQ=e=>e.map(e=>e/255).map(e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4).reduce((e,t,n)=>e+t*[.2126,.7152,.0722][n],0),dQ=(e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05),fQ=(e,t)=>({type:`linear`,x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:vj(e,t)},{offset:1,color:vj(e,0)}]}),pQ=(e,t)=>e+dA(e,t),mQ=e=>[...new Set(e)],hQ=(e,t)=>e.data.map((n,r)=>K(e,t,r)),gQ=(e,t,n={})=>({type:`category`,data:t,axisLine:{lineStyle:{color:e.axis}},axisTick:{show:!1},axisLabel:{color:e.label,fontSize:12,margin:12,hideOverlap:!0},...n}),_Q=(e,t,n={})=>({type:`value`,splitNumber:4,axisLine:{show:!1},axisTick:{show:!1},splitLine:{lineStyle:{color:e.grid,type:`solid`,width:1}},axisLabel:{color:e.label,fontSize:12,formatter:t},...n}),vQ=6048e5,yQ=(e,t)=>{let n=uA(e,t);return`${n.year}-${String(n.month+1).padStart(2,`0`)}-${String(n.day).padStart(2,`0`)}`},bQ=e=>e.reduce((e,t)=>t<e?t:e,1/0),xQ=e=>e.reduce((e,t)=>t>e?t:e,-1/0),SQ=9,CQ=24,wQ=4,TQ=72,EQ=12,DQ=(e,t)=>Math.floor(t/Math.max(1,e)-wQ),OQ=44,kQ=28,AQ=8,jQ=32,MQ=8,NQ=26,PQ={donut:Tj,heatmap:Oj,calendar:Aj,funnel:jj,gauge:Mj,waterfall:Lj,treemap:zj,sankey:Vj,scatter:Uj,bubble:Uj,multiples:Wj},FQ=typeof HTMLElement>`u`?class{}:HTMLElement,IQ=`wui-chart:select`,LQ=`wui-chart:legend-change`,RQ=`wui-chart:ready`,zQ=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`Escape`],BQ=`(prefers-color-scheme: dark)`,VQ=`(prefers-reduced-motion: reduce)`,HQ=e=>typeof window.matchMedia==`function`?window.matchMedia(e):null,UQ=!1,WQ=new Set,GQ=null,KQ=(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r},qQ=0,JQ=class extends FQ{static get observedAttributes(){return[`view`]}constructor(){super(),qQ+=1,this.uid=`wui-chart-${qQ}`,this._spec=null,this._normal=null,this._hidden=new Set,this._focus=null}get spec(){return this._spec}set spec(e){this._spec=e??null,this._normal=null,this._clearFocus(),this._parts&&this._update()}get view(){return this.getAttribute(`view`)===`table`?`table`:`chart`}set view(e){this.setAttribute(`view`,String(e??`chart`))}connectedCallback(){if(Object.hasOwn(this,`spec`)){let e=this.spec;delete this.spec,this._spec=e??null}this._spec??=this._readScript(),this._spec==null&&!this.querySelector(`:scope > script[type='application/json']`)&&(this._awaitingSpec=!0,queueMicrotask(()=>{this._awaitingSpec=!1,this._parts&&this._update()})),this._build(),Zj(this),this._theme=Xj(this),this._width=this.clientWidth,this._resizeObserver=new ResizeObserver(()=>this._resized()),this._resizeObserver.observe(this),typeof IntersectionObserver==`function`?(this._visible=!1,this._intersection=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(this._intersection.disconnect(),this._visible=!0,this._update())},{threshold:.05}),this._intersection.observe(this)):this._visible=!0,this._update()}disconnectedCallback(){Qj(this),this._resizeObserver?.disconnect(),this._intersection?.disconnect(),this._engine?.dispose(),this._engine=null,this._drawn=!1,this._parts=null,this.removeAttribute(`data-ready`)}attributeChangedCallback(e,t,n){t!==n&&this._parts&&(wA(`view`,n,fZ),this._update())}toCsv(){let{spec:e}=this._normalized();return e?cj(e):``}toPng(){let{spec:e}=this._normalized();return e?Jj(e,this._theme??Xj(this),this._size(e),{hidden:this._hidden,renderer:RA(e)}):``}exportCsv(e){let t=URL.createObjectURL(new Blob([this.toCsv()],{type:`text/csv;charset=utf-8`}));$j(t,e??`${lj(this._normalized().spec)}.csv`),setTimeout(()=>URL.revokeObjectURL(t),2e3)}exportPng(e){let t=this.toPng();t&&$j(t,e??`${lj(this._normalized().spec)}.png`)}_readScript(){let e=this.querySelector(`:scope > script[type="application/json"]`);if(!e)return null;try{return JSON.parse(e.textContent)}catch(e){return sA(`[@webority/ui-elements] <wui-chart> could not read its JSON spec:`,e?.message),null}}_normalized(){return this._normal??=DA(this._spec),this._normal}_build(){let e=KQ(`div`,`wui-chart-legend`);e.setAttribute(`role`,`group`),e.setAttribute(`aria-label`,`Legend`),e.hidden=!0,e.addEventListener(`click`,e=>{let t=e.target.closest?.(`.wui-chart-legend-item`);t&&this._toggle(t.dataset.key)});let t=KQ(`div`,`wui-chart-surface`);t.tabIndex=0,t.setAttribute(`role`,`group`),t.setAttribute(`aria-roledescription`,`chart`),t.addEventListener(`keydown`,e=>this._onKey(e)),t.addEventListener(`blur`,()=>this._clearFocus());let n=KQ(`div`,`wui-chart-canvas`);n.setAttribute(`aria-hidden`,`true`),t.append(n);let r=KQ(`div`,`wui-chart-state`);r.setAttribute(`role`,`status`),r.hidden=!0;let i=KQ(`div`,`wui-chart-table-wrap visually-hidden`),a=KQ(`p`,`visually-hidden`);a.id=`${this.uid}-summary`;let o=KQ(`div`,`visually-hidden`);o.setAttribute(`aria-live`,`polite`),this.replaceChildren(e,t,r,i,a,o),this.setAttribute(`role`,`figure`),this.setAttribute(`aria-describedby`,a.id),this._parts={legend:e,surface:t,canvas:n,state:r,tableWrap:i,summary:a,live:o},this._legendSignature=null,this._tableSpec=null}_size(e){return{width:this._parts?.surface.clientWidth||this.clientWidth||800,height:e.height}}_update(){if(!this._parts||this._awaitingSpec&&this._spec==null)return;let{spec:e,problem:t}=this._normalized(),n=this._parts,r=t?`error`:e.state===`ready`&&(!e.data.length||!jA(e))?`empty`:e.state,i=`${e?.height??320}px`,a=this.view===`table`,o=e&&(r===`ready`||r===`loading`&&this._drawn),s=r===`loading`&&o;if(this.setAttribute(`aria-label`,e?.title||`Chart`),r===`loading`?this.setAttribute(`aria-busy`,`true`):this.removeAttribute(`aria-busy`),this.setAttribute(`data-state`,r),n.surface.setAttribute(`aria-label`,`${e?.title||`Chart`}: use the arrow keys to read the values`),n.summary.textContent=e?uj(e,this._hidden):``,e){if(!s){let t=new Set(zA(e));for(let e of this._hidden)t.has(e)||this._hidden.delete(e)}this._renderTable(e)}else n.tableWrap.replaceChildren();s||this._renderLegend(e,o&&!a),this._renderState(r,t??(r===`error`?e.errorText:r===`loading`?e?.loadingText??`Loading chart`:e?.emptyText),i,o);let c=r===`ready`&&!a;s||this.toggleAttribute(`data-ready`,!c);let l=n.surface.hidden&&o&&!a;n.surface.hidden=!o||a,n.surface.style.height=i,n.tableWrap.className=a&&e?`wui-chart-table-wrap`:`wui-chart-table-wrap visually-hidden`,n.tableWrap.style.height=a&&e?i:``,a&&e?(n.tableWrap.tabIndex=0,n.tableWrap.setAttribute(`role`,`region`),n.tableWrap.setAttribute(`aria-label`,`${e.title||`Chart`} data`)):(n.tableWrap.removeAttribute(`tabindex`),n.tableWrap.removeAttribute(`role`),n.tableWrap.removeAttribute(`aria-label`)),l&&this._engine?.resize(),r===`ready`&&!a&&this._visible&&this._draw()}_renderState(e,t,n,r){let i=this._parts.state,a=!r&&e!==`ready`;i.hidden=!a,a?(i.style.height=n,e===`loading`?i.replaceChildren(KQ(`div`,`skeleton wui-chart-skeleton`),KQ(`span`,`visually-hidden`,t)):i.replaceChildren(KQ(`p`,`wui-chart-state-text`,t))):i.replaceChildren()}_colour(e,t){return e.type===`donut`?QA(e,t,this._theme):this._theme.palette[t]}_renderLegend(e,t){let n=this._parts.legend,r=e?zA(e):[],i=!!e&&t&&r.length>=2;if(n.hidden=!i,!i)return;let a=BA(e),o=r.map((t,n)=>this._colour(e,n)),s=JSON.stringify([e.type,r,a,o]);s!==this._legendSignature&&(this._legendSignature=s,n.replaceChildren(...r.map((t,n)=>{let r=KQ(`button`,`wui-chart-legend-item`);r.type=`button`,r.dataset.key=t;let i=KQ(`span`,e.type===`line`?`wui-chart-legend-swatch wui-chart-legend-swatch-line`:`wui-chart-legend-swatch`);return i.style.background=o[n],r.append(i,KQ(`span`,`wui-chart-legend-label`,a[n])),r})));for(let e of n.children)e.setAttribute(`aria-pressed`,String(!this._hidden.has(e.dataset.key)))}_renderTable(e){if(this._tableSpec===e)return;this._tableSpec=e;let t=aj(e),n=KQ(`table`,`wui-chart-table`);n.append(KQ(`caption`,`visually-hidden`,t.caption));let r=KQ(`tr`);t.head.forEach((e,t)=>{let n=KQ(`th`,t?`wui-chart-num`:null,e);n.scope=`col`,r.append(n)});let i=KQ(`thead`);i.append(r),n.append(i);let a=KQ(`tbody`);for(let e of t.rows){let t=KQ(`tr`),n=KQ(`th`,null,e.head);n.scope=`row`,t.append(n,...e.cells.map(e=>KQ(`td`,`wui-chart-num`,e))),a.append(t)}n.append(a);let o=[n];t.truncated&&o.push(KQ(`p`,`wui-chart-table-note`,`Showing the first ${t.rows.length} of ${t.total} rows. Download the CSV for all of them.`)),this._parts.tableWrap.replaceChildren(...o)}_draw(){let{spec:e}=this._normalized(),t=RA(e),n=e.type!==this._drawnType;this._engine&&this._engine.renderer!==t&&(this._engine.dispose(),this._engine=null);let r=`${e.height}px`,i=this._parts.canvas.style.height!==r;this._parts.canvas.style.height=r,i&&this._engine?.resize(),this._engine||(this._engine=Yj(this._parts.canvas,{renderer:t}),this._engine.onSelect(({seriesIndex:e,dataIndex:t})=>this._select(e,t)),this._engine.onFinished(()=>{this.setAttribute(`data-ready`,``),this._announcedReady||(this._announcedReady=!0,this.dispatchEvent(new CustomEvent(RQ,{bubbles:!0,detail:{renderer:t}})))}),n=!0),this._engine.render(e,this._theme,this._size(e),{hidden:this._hidden,renderer:t},{replace:n}),this._drawnType=e.type,this._drawn=!0}_themeChanged(){if(!this._parts)return;let e=Xj(this);JSON.stringify(e)!==JSON.stringify(this._theme)&&(this._theme=e,this._update())}_resized(){let e=this.clientWidth;e!==this._width&&(this._width=e,this._engine&&this._drawn&&(this._parts.surface.hidden||this._engine.resize(),this._update()))}_toggle(e){let{spec:t}=this._normalized();if(!t||e==null)return;this._hidden.has(e)?this._hidden.delete(e):this._hidden.add(e),this._clearFocus(),this._update();let n=Object.fromEntries(zA(t).map(e=>[e,!this._hidden.has(e)]));this.dispatchEvent(new CustomEvent(LQ,{bubbles:!0,detail:{visible:n}}))}_onKey(e){let{spec:t}=this._normalized();if(!t||!this._engine||this.view===`table`||e.altKey||e.ctrlKey||e.metaKey)return;if(e.key===`Enter`){if(!this._focus)return;e.preventDefault(),this._select(this._focus.series,this._focus.index);return}if(!zQ.includes(e.key)||e.key===`Escape`&&!this._focus)return;e.preventDefault();let n=mj(t,this._focus,e.key,this._hidden);n?(this._focus=n,this._engine.focusPoint(n.series,n.index),this._announce(rj($A(t,n.index,this._hidden,this._theme)))):this._clearFocus()}_announce(e){let t=this._parts.live;t.textContent=e===t.textContent?`${e}\u00a0`:e}_clearFocus(){this._focus&&(this._focus=null,this._engine?.clearFocus(),this._parts&&(this._parts.live.textContent=``))}_select(e,t){let{spec:n}=this._normalized(),r=n?.series[xZ(n.type)?0:e];if(!r)return;let i=n.data[t]??null;this.dispatchEvent(new CustomEvent(IQ,{bubbles:!0,detail:{series:r.key,label:r.label,x:i?.[n.x.key]??null,value:K(n,r.key,t),row:i,index:t}}))}},typeof customElements<`u`&&!customElements.get(`wui-chart`)&&customElements.define(`wui-chart`,JQ)})),XQ=null;async function ZQ(){await Promise.resolve().then(()=>(YQ(),Qn)),await customElements.whenDefined(`wui-chart`)}async function QQ(){return XQ??=ZQ().catch(e=>{throw XQ=null,e}),XQ}var $Q={sub:`wui-chat-sub`,sup:`wui-chat-sup`};function e$(e,t){let n=e.ownerDocument;for(let r of t){if($Q[r.kind]===void 0){e.append(n.createTextNode(r.text));continue}let t=n.createElement(r.kind);t.className=$Q[r.kind],t.textContent=r.text,e.append(t)}}function t$(e,t){e.replaceChildren(),e$(e,_e(String(t??``)))}function n$(e){return ve(String(e??``))}function r$(e){return ye(e)}var i$=8,a$={Bar:`column`,Line:`line`,Donut:`donut`};function o$(e,t){return e===`Bar`&&t>4?300:240}function s$(e,t){let n=e.chartType===`Donut`,r=n?e.series.slice(0,1):e.series.slice(0,i$),i=r.map((e,n)=>({key:`s${n}`,label:n$(e.name)||t.chart})),a=Object.fromEntries(i.map(e=>[e.key,null])),o=new Map;r.forEach((e,t)=>{for(let n of e.points){let e=String(n.label);o.has(e)||o.set(e,{label:n$(e),...a}),o.get(e)[`s${t}`]=n.value}});let s=[...o.values()],c={type:a$[e.chartType],title:n$(e.title)||t.chart,x:{key:`label`,kind:`category`},series:i,data:s,height:o$(e.chartType,s.length)};return!n&&e.unit&&(c.y={label:n$(e.unit)}),s.length===0&&(c.state=`empty`,c.emptyText=t.chartEmpty),c}Vn(`wui-chat-part-chart`,class extends Bn{#e=null;#t=0;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;this.#e=r,this.#t+=1;let i=this.#t,a=this.ownerDocument;if(this.#r||(this.#r=N(a,`figure`,`wui-chat-chart`),this.#a=N(a,`div`,`wui-chat-chart-body`),this.#r.append(this.#a),this.replaceChildren(this.#r)),this.#i?.remove(),this.#i=null,e.title&&(this.#i=N(a,`figcaption`,`wui-chat-chart-title`),t$(this.#i,e.title),this.#r.prepend(this.#i)),this.#n){let t=s$(e,n.labels);this.#o.spec=t,this.#c(t.state!==`empty`,n.labels)}else QQ().then(()=>{if(i!==this.#t||!this.isConnected)return;let t=s$(e,n.labels);this.#o=a.createElement(`wui-chart`),this.#o.spec=t,this.#n=!0,this.#a.replaceChildren(this.#o),this.#c(t.state!==`empty`,n.labels)},()=>{i===this.#t&&this.isConnected&&this.#u(n.labels)})}disposePart(){this.#t+=1,this.#e=null}#c(e,t){if(!e){this.#s?.remove(),this.#s=null;return}this.#s||(this.#s=N(this.ownerDocument,`button`,`btn btn-link btn-sm wui-chat-chart-toggle`),this.#s.type=`button`,this.#s.addEventListener(`click`,()=>this.#l()),this.#r.append(this.#s));let n=this.#o.getAttribute(`view`)===`table`;this.#s.setAttribute(`aria-pressed`,String(n)),this.#s.textContent=n?t.chartShowChart:t.chartShowTable}#l(){let e=this.#o.getAttribute(`view`)!==`table`;this.#o.setAttribute(`view`,e?`table`:`chart`),this.#c(!0,this.turn.labels)}#u(e){let t=N(this.ownerDocument,`p`,`wui-chat-chart-error`,e.chartLoadFailed);t.setAttribute(`role`,`status`),this.#a.replaceChildren(t),this.#s?.remove(),this.#s=null}});var c$={Positive:`wui-metric-tone-success`,Caution:`wui-metric-tone-warning`,Negative:`wui-metric-tone-danger`},l$=new Set([`Positive`,`Caution`,`Negative`]),u$=.001;function d$(e,t,n){let r=c$[t.status],i=N(e,`div`,r?`wui-metric ${r}`:`wui-metric`);i.dataset.status=t.status;let a=N(e,`div`,`wui-metric-label`);t$(a,t.label);let o=N(e,`div`,`wui-metric-value`);if(e$(o,t.value!==0&&Math.abs(t.value)<u$?r$(t.value):[{kind:`text`,text:In(t.value)}]),t.unit){let n=N(e,`span`,`wui-chat-figure-unit`);t$(n,t.unit),n.prepend(` `),o.append(n)}return l$.has(t.status)&&o.append(N(e,`span`,`visually-hidden`,n.figureStatus(t.status))),i.append(a,o),i}Vn(`wui-chat-part-figures`,class extends Bn{#e=null;renderPart(e,t,n){let r=JSON.stringify(e);if(r===this.#e)return;if(this.#e=r,!e.figures||e.figures.length===0){this.replaceChildren();return}let i=this.ownerDocument,a=N(i,`div`,`wui-chat-figures`),o=N(i,`div`,`wui-metric-strip wui-metric-strip-sm wui-chat-figures-strip`);o.setAttribute(`role`,`group`),o.setAttribute(`aria-label`,n.labels.figures);for(let t of e.figures)o.append(d$(i,t,n.labels));a.append(o),this.replaceChildren(a)}}),Vn(`wui-chat-part-file`,class extends Bn{renderPart(e,t,n){let r=typeof n.openAttachment==`function`,i=document.createElement(r?`button`:`span`);i.className=`wui-chat-file-chip`,r&&(i.type=`button`,i.setAttribute(`aria-label`,n.labels.fileOpen(e.fileName)),i.addEventListener(`click`,()=>n.openAttachment(e)));let a=Hn(document,`document-text`,16),o=document.createElement(`span`);o.className=`wui-chat-file-name`,o.textContent=e.fileName;let s=document.createElement(`span`);s.className=`wui-chat-file-size`,s.textContent=tt(e.length),i.append(...[a,o,s].filter(Boolean));let c=document.createElement(`div`);c.className=`wui-chat-file`,c.append(i),this.replaceChildren(c)}});var f$=`(prefers-reduced-motion: reduce)`;function p$(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 m$(e,t){let n=typeof window.matchMedia==`function`?window.matchMedia(f$):null,r=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 h$=`AppButton`,g$={primary:`btn-primary`,secondary:`btn-soft-primary`,ghost:`btn-ghost-primary`,outline:`btn-outline-primary`,neutral:`btn-soft-neutral`,danger:`btn-danger`};function $(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 _$(e,t=16){let n=Rn(e,{size:t});if(!n)return $(`span`,`d-inline-flex`);let r=document.createElement(`template`);return r.innerHTML=n,r.content.firstElementChild??$(`span`,`d-inline-flex`)}function v$(e=`primary`,t=`md`){if(!Object.hasOwn(g$,e))throw Error(`Unknown button variant "${e}". Use one of ${Object.keys(g$).join(`, `)}.`);return`btn ${g$[e]}${t===`sm`?` btn-sm`:``}`}function y$(e,t,n,r){let i=$(`button`,`${v$(e,`sm`)} wui-chat-action-btn`,{type:`button`});return i.dataset.wui=h$,n&&i.append(_$(n,14)),i.append(document.createTextNode(t)),i.addEventListener(`click`,r),i}function b$(e,t,n){let r=$(`button`,`wui-chat-icon-btn`,{type:`button`,"aria-label":e,title:e});return r.append(_$(t,20)),r.addEventListener(`click`,n),r}function x$(e,t){let n=e.getAttribute(t);if(n!=null&&n!==``)try{return JSON.parse(n)}catch{throw Error(`<wui-chat ${t}> must be valid JSON.`)}}function S$(e){let t=null;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 C$(e,t){t.position!==void 0&&(e.classList.toggle(`wui-chat--end`,t.position===`end`),e.classList.toggle(`wui-chat--start`,t.position===`start`)),t.reduced!==void 0&&e.classList.toggle(`wui-chat--reduced`,!!t.reduced),t.sendReveal!==void 0&&e.classList.toggle(`wui-chat--send-always`,t.sendReveal===`Always`),t.inputRing!==void 0&&e.classList.toggle(`wui-chat--input-ring-off`,t.inputRing===!1),t.panelMotion!==void 0&&(e.classList.toggle(`wui-chat--panel-motion-gentle`,t.panelMotion===`Gentle`),e.classList.toggle(`wui-chat--panel-motion-none`,t.panelMotion===`None`)),t.offsetX!==void 0&&e.style.setProperty(`--wui-chat-offset-x`,`${t.offsetX}px`),t.offsetY!==void 0&&e.style.setProperty(`--wui-chat-offset-y`,`${t.offsetY}px`),t.width!==void 0&&e.style.setProperty(`--wui-chat-width`,t.width),t.maxHeight!==void 0&&e.style.setProperty(`--wui-chat-panel-max-height`,`${t.maxHeight}px`),t.bottomGap!==void 0&&e.style.setProperty(`--wui-chat-bottom-gap`,`${t.bottomGap}px`),t.panelHeight!==void 0&&e.classList.toggle(`wui-chat--panel-height-content`,t.panelHeight===`Content`),t.avatar!==void 0&&(t.avatar?e.style.setProperty(`--wui-chat-avatar`,`url(${JSON.stringify(t.avatar)})`):e.style.removeProperty(`--wui-chat-avatar`)),t.replyAvatars!==void 0&&e.classList.toggle(`wui-chat--reply-avatars-off`,t.replyAvatars===!1)}var w$=[`Text`,`Sources`,`QuickReplies`,`InputRequest`,`Action`,`Notice`,`Table`,`Chart`,`Figures`,`RecordCard`,`Image`,`File`,`Ticket`,`Handoff`,`VoiceClip`],T$={launcher:`wui-chat--launcher`,docked:`wui-chat--docked`,"full-page":`wui-chat--full-page`,embedded:`wui-chat--embedded`};function E$(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function D$({id:e,layout:t,position:n,role:r,launcher:i,onToggle:a}){let o=$(`div`,`wui-chat ${T$[t]} wui-chat--${n}`),s=$(`section`,`wui-chat-panel`,{id:e,role:r}),c=i?S$(o):null;o.dataset.state=i?`closed`:`open`;let l=null,u=null,d=null,f=null,p=null,m=null,h=null,g=`round`,_=!1,v=`bubble`,y=null,b=null,x=!1,S=`icon`,C=!1;function w(){let e=l.dataset.launcher,t=[`wui-chat-launcher-wrap`];e===`entering`&&y&&t.push(`wui-chat-launcher--entrance-${y}`),e===`idle`&&b&&b!==`none`&&(b!==`ring`||g===`pill`)&&t.push(`wui-chat-launcher--idle-${b}`),l.className=t.join(` `)}function T(){let e=[...u.classList].filter(e=>e.endsWith(`--opening`)||e.endsWith(`--closing`)),t=[`wui-chat-launcher`,`wui-chat-launcher--${g}`];g===`pill`&&_&&t.push(`wui-chat-launcher--compact`),S===`avatar`&&t.push(`wui-chat-launcher--mark-avatar`),t.push(`wui-chat-launcher--reveal-${v}`,...e),u.className=t.join(` `)}function E(){p&&m&&(p.textContent=h||m.launcher)}function D(){if(!u||!m)return;let e=C?m.launcherClose:h||m.launcher;u.setAttribute(`aria-label`,e),f.textContent=e}if(i){l=$(`div`,`wui-chat-launcher-wrap`),l.dataset.launcher=`idle`,u=$(`button`,`wui-chat-launcher`,{type:`button`,"aria-haspopup":`dialog`,"aria-expanded":`false`,"aria-controls":e}),d=$(`span`,`wui-chat-launcher-icon`,{"aria-hidden":`true`}),d.append(_$(`chat`,24));let t=$(`span`,`wui-chat-launcher-close`,{"aria-hidden":`true`});t.append(_$(`x`,24)),f=$(`span`,`wui-chat-launcher-label`),u.append(d,t,f),u.addEventListener(`click`,()=>a()),u.addEventListener(`animationend`,e=>{e.target===u&&u.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`)}),p=$(`span`,`wui-chat-launcher-bubble`,{"aria-hidden":`true`}),l.append(u,p),l.addEventListener(`animationend`,e=>{e.target===l&&l.dataset.launcher===`entering`&&(l.dataset.launcher=`idle`,w())}),T(),w(),o.append(l,s)}else o.append(s);function O(e){if(!c)return;let t=e&&!C&&u!==null,n=t?u.getBoundingClientRect():null;e!==C&&u&&(u.classList.remove(`wui-chat-launcher--opening`,`wui-chat-launcher--closing`),u.classList.add(e?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`)),C=e,c(e),t&&p$(s,n),u&&(u.setAttribute(`aria-expanded`,String(e)),D())}function k(e){m=e,u&&(D(),E())}function A(e){if(C$(o,e),e.theme!==void 0&&(e.theme===`light`||e.theme===`dark`?o.dataset.theme=e.theme:delete o.dataset.theme),!u)return;e.launcherStyle!==void 0&&(g=e.launcherStyle===`Pill`?`pill`:`round`),e.compact!==void 0&&(_=e.compact),e.labelReveal!==void 0&&(v=e.labelReveal===`Expand`?`expand`:`bubble`),e.entrance!==void 0&&(y=e.entrance===`None`?null:E$(e.entrance)),e.idle!==void 0&&(b=e.idle===`None`?`none`:E$(e.idle)),e.phone!==void 0&&(x=e.phone),e.hoverLabel!==void 0&&(h=e.hoverLabel||null),e.launcherMark!==void 0&&(S=e.launcherMark===`Avatar`?`avatar`:`icon`),e.icon!==void 0&&e.icon!==d.dataset.icon&&(d.dataset.icon=e.icon,d.replaceChildren(_$(e.icon,24)));let t=e.launcherState??l.dataset.launcher;x&&t===`entering`&&(t=`idle`),t===`entering`&&!y&&(t=`idle`),l.dataset.launcher=t,T(),w(),E(),D()}return{root:o,panel:s,setOpen:O,setLabels:k,setAppearance:A,nudgeHost:l,launcherButton:u,role:r}}var O$={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`},k$=/^\/[/\\]/,A$=/^https?:\/\//i,j$=/[\t\r\n]/g;function M$(e){return typeof e==`string`&&e.trim()!==``}function N$(e){return e.replace(j$,``)}function P$(e){if(typeof e!=`string`)return!1;let t=N$(e);return t.startsWith(`/`)?!k$.test(t):A$.test(t)}function F$(e){if(typeof e!=`string`)return`?`;let t=e.split(/\s+/).filter(Boolean).slice(0,2).map(e=>[...e][0].toUpperCase()).join(``);return t===``?`?`:t}function I$(e,t){let n=F$(M$(e?.displayName)?e.displayName:t),r=$(`span`,`wui-chat-avatar`,{"aria-hidden":`true`}),i=typeof e?.avatarUrl==`string`?N$(e.avatarUrl):null;if(P$(i)){let e=$(`img`,null,{alt:``,src:i,loading:`lazy`});e.addEventListener(`error`,()=>{r.textContent=n}),r.append(e)}else r.textContent=n;return r}function L$(e,t){let n=$(`div`,`wui-chat-agent-head`),r=$(`span`,`wui-chat-agent-name`);r.textContent=M$(e?.displayName)?e.displayName:t.agent;let i=$(`span`,`wui-chat-agent-role wui-chat-agent-tag`);return i.textContent=t.agent,n.append(I$(e,t.agent),r,i),n}function R$(e,t){let n=e.displayName,r=$(`li`,`wui-chat-message wui-chat-message--agent wui-chat-message--typing`),i=$(`span`,`wui-chat-typing`);for(let e=0;e<3;e+=1)i.append($(`span`,`wui-chat-typing-dot`,{"aria-hidden":`true`}));let a=$(`span`,`visually-hidden`);return a.textContent=t.agentTyping(M$(n)?n:t.agent),r.append(L$({kind:`Agent`,displayName:n,avatarUrl:null},t),i,a),r}function z$(e){return Object.hasOwn(O$,e)?O$[e]:null}function B$(e,t){return z$(e)===null?``:t.ticketStatus(e)}var V$=new Set([`Requested`,`Waiting`]),H$=new Set([`Requested`,`Waiting`,`Joined`]),U$=H$;function W$(e,t){let n=e?.displayName;return typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback}function G$(){let e=$(`div`,`wui-chat-handoff-pulses`);for(let t=0;t<3;t+=1)e.append($(`span`,`wui-chat-handoff-pulse`,{"aria-hidden":`true`}));return e}function K$(e,t,n){let r=$(e,t);return r.textContent=n,r}function q$(e,t){let n=$(`div`,`wui-chat-handoff-body`);return n.append(K$(`strong`,`wui-chat-handoff-title`,e),K$(`p`,`wui-chat-handoff-text`,t)),n}function J$(e,t){if(typeof e.queuePosition!=`number`){let e=$(`span`,`wui-chat-system-line-stack`);return e.append(K$(`p`,`wui-chat-handoff-text`,t.handoffWaiting),K$(`p`,`wui-chat-handoff-text`,t.handoffQueuedText)),[G$(),e]}let n=$(`span`,`wui-chat-handoff-position`,{"aria-hidden":`true`});return n.textContent=String(e.queuePosition),[n,q$(t.handoffQueued(e.queuePosition),t.handoffQueuedText)]}function Y$(e,t){let n=W$(e.agent,t),r=$(`span`,`wui-chat-handoff-agent`);return r.append(I$(e.agent,t.handoffAgentFallback),$(`span`,`wui-chat-handoff-online`,{"aria-hidden":`true`})),[r,q$(t.handoffJoined(n),t.handoffJoinedText(n))]}function X$(e,t){switch(e.state){case`Requested`:return[G$(),K$(`p`,`wui-chat-handoff-text`,t.handoffRequested)];case`Waiting`:return J$(e,t);case`Joined`:return Y$(e,t);case`Left`:return[q$(t.handoffLeft(W$(e.agent,t)),t.handoffLeftText)];case`Ended`:return[q$(t.handoffEnded,t.handoffEndedText)];default:return null}}Vn(`wui-chat-part-handoff`,class extends Bn{constructor(){super(),this._signature=null}renderPart(e,t,n){let r=n.isLast,i=n.handoffSettled===!0&&V$.has(e.state),a=JSON.stringify([e.state,e.queuePosition,e.agent,r,n.features.HumanHandoff,n.busy,i]);if(a===this._signature)return;if(this._signature=a,i){this.replaceChildren();return}let o=X$(e,n.labels);if(o===null){this.replaceChildren();return}let s=$(`div`,`wui-chat-handoff wui-chat-handoff--${e.state.toLowerCase()}`);if(r&&V$.has(e.state)&&s.classList.add(`wui-chat-handoff--live`),r&&H$.has(e.state)&&s.setAttribute(`role`,`status`),U$.has(e.state)){s.classList.add(`wui-chat-system-line`);let e=$(`span`,`wui-chat-system-line-content`);e.append(...o),s.append(e)}else s.append(...o);this.replaceChildren(s)}});function Z$(e,t){if(typeof customElements>`u`||customElements.get(e))return;let n=[];if(typeof document<`u`)for(let r of document.querySelectorAll(e))for(let e of Object.keys(r)){let i=Object.getOwnPropertyDescriptor(t.prototype,e);i&&(i.set||i.get)&&(n.push([r,e,r[e]]),delete r[e])}customElements.define(e,t);for(let[e,t,r]of n)e[t]=r}var Q$=typeof HTMLElement>`u`?class{}:HTMLElement,$$=`a.wui-lightbox-item`,e1=1,t1=4,n1=.5,r1=2,i1=50,a1=6,o1=300,s1=300;function c1(e){return Number.isFinite(e)?Math.min(t1,Math.max(e1,e)):e1}function l1(e,t,n,r){let i=(e,n)=>Math.max(0,(e*t-n)/2),a=i(r.width,n.width),o=i(r.height,n.height);return{x:Math.min(a,Math.max(-a,e.x)),y:Math.min(o,Math.max(-o,e.y))}}function u1(e,t){return Math.abs(e)<i1||Math.abs(e)<Math.abs(t)*1.5?0:e<0?1:-1}function d1(e){let t=String(e??``).split(/[?#]/)[0].split(`/`).filter(Boolean).pop()??``;try{return decodeURIComponent(t)}catch{return t}}function f1(e,t,n={}){let r=document.createElement(e);r.className=t;for(let[e,t]of Object.entries(n))r.setAttribute(e,t);return r}function p1(e,t,n){let r=f1(`button`,`u-action wui-lightbox-btn ${n}`,{type:`button`,"aria-label":t,title:t});return r.style.setProperty(`--wui-action-size`,`40px`),r.innerHTML=Rn(e,{size:20}),r}Z$(`wui-lightbox`,class extends Q${static get observedAttributes(){return[`open-index`]}constructor(){super(),this._ui=null,this._index=0,this._zoom=e1,this._pan={x:0,y:0},this._pointers=new Map,this._gesture=null,this._lastTap=-1/0,this._returnTo=null,this._lockedOverflow=null,this._onClick=e=>{if(e.defaultPrevented||e.button!==0||e.ctrlKey||e.metaKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.($$);if(!t||!this.contains(t))return;let n=this._links().indexOf(t);n<0||(e.preventDefault(),this.open(n))}}get download(){return this.hasAttribute(`download`)}set download(e){this.toggleAttribute(`download`,e===!0||e===``||e===`true`)}get label(){return this.getAttribute(`label`)||`Image viewer`}set label(e){this.setAttribute(`label`,String(e??``))}get isOpen(){return this._ui!==null}connectedCallback(){this.addEventListener(`click`,this._onClick),this._syncOpenIndex()}disconnectedCallback(){this.removeEventListener(`click`,this._onClick),this._teardown()}attributeChangedCallback(){this.isConnected&&this._syncOpenIndex()}_syncOpenIndex(){let e=this.getAttribute(`open-index`);e===null?this.close():this.open(Number(e))}_links(){return[...this.querySelectorAll($$)]}_items(){return this._links().map(e=>{let t=e.getAttribute(`href`)??``;return{link:e,src:t,alt:e.querySelector(`img`)?.getAttribute(`alt`)??``,caption:e.dataset.caption??``,name:e.dataset.name||d1(t)}})}open(e=0){let t=this._items();return t.length?(this._ui||(this._returnTo=document.activeElement,this._build(),this.dispatchEvent(new CustomEvent(`wui-lightbox:open`,{bubbles:!0,detail:{index:e}}))),this._show(e,t),this._ui.close.focus(),!0):!1}close(){if(!this._ui)return;let e=this._index,t=this._links()[e]??this._returnTo;this._teardown(),t?.isConnected&&t.focus(),this._returnTo=null,this.dispatchEvent(new CustomEvent(`wui-lightbox:close`,{bubbles:!0,detail:{index:e}}))}_teardown(){this._ui&&(this._ui.root.remove(),this._ui=null,this._pointers.clear(),this._gesture=null,this._lockedOverflow!==null&&(document.documentElement.style.overflow=this._lockedOverflow,this._lockedOverflow=null))}_build(){let e=f1(`div`,`wui-lightbox-overlay`,{role:`dialog`,"aria-modal":`true`,"aria-label":this.label,tabindex:`-1`}),t=f1(`div`,`wui-lightbox-bar`),n=f1(`span`,`wui-lightbox-count`,{"aria-live":`polite`}),r=f1(`div`,`wui-lightbox-tools`),i=p1(`zoom-out`,`Zoom out`,`wui-lightbox-zoom-out`),a=p1(`zoom-in`,`Zoom in`,`wui-lightbox-zoom-in`),o=f1(`a`,`u-action wui-lightbox-btn wui-lightbox-download`,{"aria-label":`Download`,title:`Download`});o.style.setProperty(`--wui-action-size`,`40px`),o.innerHTML=Rn(`download`,{size:20}),o.hidden=!this.download;let s=p1(`x`,`Close`,`wui-lightbox-close`);r.append(i,a,o,s),t.append(n,r);let c=f1(`div`,`wui-lightbox-stage`),l=p1(`chevron-left`,`Previous image`,`wui-lightbox-nav wui-lightbox-prev`),u=p1(`chevron-right`,`Next image`,`wui-lightbox-nav wui-lightbox-next`),d=f1(`img`,`wui-lightbox-image`,{decoding:`async`,draggable:`false`,alt:``}),f=f1(`p`,`wui-lightbox-status`,{role:`status`});c.append(d,f,l,u);let p=f1(`p`,`wui-lightbox-caption`);e.append(t,c,p);let m={root:e,count:n,zoomOut:i,zoomIn:a,download:o,close:s,stage:c,prev:l,next:u,image:d,status:f,caption:p};this._ui=m,s.addEventListener(`click`,()=>this.close()),l.addEventListener(`click`,()=>this.step(-1)),u.addEventListener(`click`,()=>this.step(1)),i.addEventListener(`click`,()=>this._setZoom(this._zoom-n1)),a.addEventListener(`click`,()=>this._setZoom(this._zoom+n1)),e.addEventListener(`keydown`,e=>this._onKeyDown(e)),c.addEventListener(`pointerdown`,e=>this._onPointerDown(e)),c.addEventListener(`pointermove`,e=>this._onPointerMove(e)),c.addEventListener(`pointerup`,e=>this._onPointerEnd(e,!0)),c.addEventListener(`pointercancel`,e=>this._onPointerEnd(e,!1)),c.addEventListener(`wheel`,e=>this._onWheel(e),{passive:!1}),d.addEventListener(`load`,()=>{this._ui===m&&(f.textContent=``,c.removeAttribute(`aria-busy`),d.hidden=!1,this._applyTransform())}),d.addEventListener(`error`,()=>{this._ui===m&&(c.removeAttribute(`aria-busy`),d.hidden=!0,f.textContent=`This image can't be shown.`)}),this.append(e),this._lockedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}step(e){if(!this._ui||!e)return;let t=this._items();t.length<2||this._show((this._index+e+t.length)%t.length,t)}_show(e,t){let n=this._ui,r=Math.min(t.length-1,Math.max(0,Math.trunc(Number(e))||0)),i=t[r],a=r!==this._index||!n.image.getAttribute(`src`);if(this._index=r,this._zoom=e1,this._pan={x:0,y:0},n.count.textContent=`${In(r+1,{decimals:0})} of ${In(t.length,{decimals:0})}`,n.caption.textContent=i.caption,n.caption.hidden=!i.caption,n.download.href=i.src,n.download.setAttribute(`download`,i.name),n.prev.hidden=n.next.hidden=t.length<2,n.stage.setAttribute(`aria-busy`,`true`),n.status.textContent=``,n.image.hidden=!1,n.image.alt=i.alt||i.caption,n.image.src=i.src,this._applyTransform(),this._syncZoomButtons(),t.length>1)for(let e of[t[(r+1)%t.length],t[(r-1+t.length)%t.length]])new Image().src=e.src;a&&this.dispatchEvent(new CustomEvent(`wui-lightbox:change`,{bubbles:!0,detail:{index:r}}))}_syncZoomButtons(){this._ui.zoomOut.disabled=this._zoom<=e1,this._ui.zoomIn.disabled=this._zoom>=t1;let e=document.activeElement;(e===this._ui.zoomOut||e===this._ui.zoomIn)&&e.disabled&&this._ui.close.focus()}_setZoom(e){this._ui&&(this._zoom=c1(e),this._pan=this._clampedPan(this._pan),this._applyTransform(),this._syncZoomButtons())}_clampedPan(e){let{stage:t,image:n}=this._ui;return l1(e,this._zoom,{width:t.clientWidth,height:t.clientHeight},{width:n.offsetWidth,height:n.offsetHeight})}_applyTransform(){let{image:e,stage:t}=this._ui;e.style.transform=`translate(${this._pan.x}px, ${this._pan.y}px) scale(${this._zoom})`,t.classList.toggle(`wui-lightbox-zoomed`,this._zoom>e1)}_onKeyDown(e){if(e.key===`Escape`)e.preventDefault(),e.stopPropagation(),this.close();else if(e.key===`Tab`)this._trapTab(e);else if(e.key===`ArrowLeft`||e.key===`ArrowRight`)e.preventDefault(),this.step(e.key===`ArrowRight`?1:-1);else if(e.key===`Home`||e.key===`End`){e.preventDefault();let t=this._items();this._show(e.key===`Home`?0:t.length-1,t)}else e.key===`+`||e.key===`=`?(e.preventDefault(),this._setZoom(this._zoom+n1)):e.key===`-`?(e.preventDefault(),this._setZoom(this._zoom-n1)):e.key===`0`&&(e.preventDefault(),this._setZoom(e1))}_trapTab(e){let t=[...this._ui.root.querySelectorAll(`button, a[href]`)].filter(e=>!e.hidden&&!e.disabled);if(!t.length){e.preventDefault();return}let n=t[0],r=t[t.length-1],i=document.activeElement;e.shiftKey&&(i===n||!this._ui.root.contains(i))?(e.preventDefault(),r.focus()):e.shiftKey||i!==r&&this._ui.root.contains(i)||(e.preventDefault(),n.focus())}_onWheel(e){e.preventDefault(),this._setZoom(this._zoom*(e.deltaY<0?1.15:1/1.15))}_onPointerDown(e){if(!e.target.closest(`.wui-lightbox-nav`)){if(this._ui.stage.setPointerCapture?.(e.pointerId),this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this._pointers.size===2){let[e,t]=[...this._pointers.values()];this._gesture={kind:`pinch`,distance:Math.hypot(e.x-t.x,e.y-t.y)||1,zoom:this._zoom}}else this._pointers.size===1&&(this._gesture={kind:`drag`,startX:e.clientX,startY:e.clientY,startTime:e.timeStamp,pan:{...this._pan},onImage:e.target===this._ui.image,moved:!1})}}_onPointerMove(e){let t=this._gesture;if(t&&this._pointers.has(e.pointerId)){if(this._pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.kind===`pinch`&&this._pointers.size===2){let[e,n]=[...this._pointers.values()];this._setZoom(t.zoom*Math.hypot(e.x-n.x,e.y-n.y)/t.distance)}else if(t.kind===`drag`){let n=e.clientX-t.startX,r=e.clientY-t.startY;Math.hypot(n,r)>a1&&(t.moved=!0),this._zoom>e1&&(this._pan=this._clampedPan({x:t.pan.x+n,y:t.pan.y+r}),this._ui.stage.classList.add(`is-dragging`),this._applyTransform())}}}_onPointerEnd(e,t){let n=this._gesture;if(this._pointers.delete(e.pointerId),this._ui?.stage.classList.remove(`is-dragging`),!n)return;if(n.kind===`pinch`){this._pointers.size<2&&(this._gesture=null);return}if(this._gesture=null,!t)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;n.moved?this._zoom===e1&&this.step(u1(r,i)):e.timeStamp-n.startTime>o1||(n.onImage?e.timeStamp-this._lastTap<s1?(this._lastTap=-1/0,this._setZoom(this._zoom>e1?e1:r1)):this._lastTap=e.timeStamp:this.close())}}),Vn(`wui-chat-part-image`,class extends Bn{#e=null;#t=0;#n=null;renderPart(e,t,n){if(e.attachmentId===this.#e)return;this.#e=e.attachmentId;let r=this.ownerDocument,i=N(r,`figure`,`wui-chat-image`);this.#n=N(r,`div`,`wui-chat-image-frame`),Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0&&(this.#n.style.aspectRatio=`${e.width} / ${e.height}`),i.append(this.#n),this.replaceChildren(i),this.#r(e,n)}disposePart(){this.#t+=1,this.#e=null}#r(e,t){this.#t+=1;let n=this.#t,r=this.ownerDocument,i=N(r,`div`,`wui-chat-image-skeleton`);i.setAttribute(`aria-hidden`,`true`);let a=N(r,`span`,`visually-hidden`,t.labels.imageLoading);a.setAttribute(`role`,`status`),this.#n.replaceChildren(i,a),typeof t.loadAttachmentUrl==`function`?t.loadAttachmentUrl(e.attachmentId).then(r=>{n===this.#t&&this.isConnected&&this.#i(r,e,t)},()=>{n===this.#t&&this.isConnected&&this.#a(e,t)}):this.#a(e,t)}#i(e,t,n){let r=this.ownerDocument,i=n$(t.alt),a=r.createElement(`wui-lightbox`);a.setAttribute(`label`,n.labels.imageViewer);let o=N(r,`a`,`wui-lightbox-item`);o.setAttribute(`href`,e),o.dataset.caption=i,o.dataset.name=i;let s=r.createElement(`img`);s.src=e,s.alt=i,s.decoding=`async`,o.append(s),a.append(o),this.#n.replaceChildren(a)}#a(e,t){let n=this.ownerDocument,r=N(n,`p`,`wui-chat-image-error`,t.labels.imageFailed);r.setAttribute(`role`,`status`);let i=N(n,`button`,`btn btn-soft-primary btn-sm`,t.labels.retry);i.type=`button`,i.addEventListener(`click`,()=>this.#r(e,t)),this.#n.replaceChildren(r,i)}});var m1={ActionLimitReached:`warning`,ConversationTooLong:`warning`,AssistantUnavailable:`danger`},h1={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};Vn(`wui-chat-part-notice`,class extends Bn{renderPart(e){let t=this.ownerDocument,n=m1[e.code]??`info`,r=N(t,`div`,`wui-chat-notice wui-chat-notice--${n}`);r.setAttribute(`role`,n===`danger`?`alert`:`status`);let i=N(t,`span`,`wui-chat-notice-icon`);i.setAttribute(`aria-hidden`,`true`);let a=Hn(t,h1[n],16);a&&i.append(a);let o=N(t,`div`,`wui-chat-notice-body`);if(o.append(N(t,`span`,`wui-chat-notice-text`,e.text)),e.action){let n=N(t,`button`,`wui-chat-notice-action`,e.action.label);n.type=`button`,n.addEventListener(`click`,()=>e.action.run()),o.append(n)}r.append(i,o),this.replaceChildren(r)}});var g1=new Set([`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`]),_1={Email:{type:`email`,autocomplete:`email`},Phone:{type:`tel`,autocomplete:`tel`},Name:{type:`text`,autocomplete:`name`},Company:{type:`text`,autocomplete:`organization`},Text:{type:`text`,autocomplete:null},LongText:{type:`text`,autocomplete:null}},v1=[`Open`,`Answered`,`Skipped`,`Expired`],y1=0;function b1(e){return y1+=1,`${e}-${y1}`}function x1(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!=null&&(r.textContent=n),r}function S1(){let e=x1(`p`,`wui-chat-field-error`);return e.id=b1(`wui-chat-field-error`),e.setAttribute(`role`,`alert`),e.hidden=!0,e}function C1(e,t){return e.required?[]:[x1(`span`,`wui-chat-field-hint`,t.inputOptional)]}function w1(e,t){let n=b1(`wui-chat-field`),r=_1[e.type],i=e.type===`LongText`&&!e.secret,a=x1(i?`textarea`:`input`,`form-control wui-chat-input-control`);i?a.rows=3:(a.type=e.secret?`password`:r.type,e.secret?a.autocomplete=`off`:r.autocomplete&&(a.autocomplete=r.autocomplete)),a.id=n,a.name=e.key,e.placeholder!=null&&(a.placeholder=e.placeholder),e.maxLength!=null&&(a.maxLength=e.maxLength),e.required&&a.setAttribute(`aria-required`,`true`);let o=x1(`label`,`form-label`,e.label);o.htmlFor=n;let s=S1();a.setAttribute(`aria-describedby`,s.id);let c=x1(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(o,...C1(e,t),a,s),{field:e,element:c,controls:[a],focus:a,invalid:a,error:s,read:()=>e.secret?a.value:a.value.trim()}}function T1(e,t,n,r,i){let a=e.controls[0],o=x1(`button`,`btn btn-soft-primary`,n.inputSendCode);o.type=`button`,o.dataset.wui=`AppButton`;let s=x1(`p`,`wui-chat-field-hint`);s.setAttribute(`aria-live`,`polite`);let c=b1(`wui-chat-field`),l=x1(`label`,`form-label`,n.inputEnterCode);l.htmlFor=c,l.hidden=!0;let u=x1(`input`,`form-control wui-chat-input-control`);return u.type=`text`,u.id=c,u.inputMode=`numeric`,u.autocomplete=`one-time-code`,u.hidden=!0,o.addEventListener(`click`,async()=>{o.disabled=!0;try{await r.sendOtp(i,{fieldKey:t.key,value:a.value.trim()}),s.textContent=n.inputCodeSent,l.hidden=!1,u.hidden=!1}catch{s.textContent=n.inputCodeFailed}finally{o.disabled=!1}}),e.element.insertBefore(o,e.error),e.element.insertBefore(s,e.error),e.element.insertBefore(l,e.error),e.element.insertBefore(u,e.error),{...e,controls:[...e.controls,o,u],codeRead:()=>u.value.trim()}}function E1(e,t){let n=b1(`wui-chat-field-label`),r=x1(`span`,`form-label`,e.label);r.id=n;let i=x1(`div`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=S1();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=x1(`div`,`form-check`),r=x1(`input`,`form-check-input`);r.type=`radio`,r.name=e.key,r.value=t.id,r.id=b1(`wui-chat-option`);let a=x1(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=x1(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...C1(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>o.find(e=>e.checked)?.value??``}}function D1(e,t){let n=b1(`wui-chat-field-label`),r=x1(`span`,`form-label`,e.label);r.id=n;let i=x1(`div`,`wui-chat-input-choices`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-labelledby`,n);let a=S1();i.setAttribute(`aria-describedby`,a.id);let o=[];for(let t of e.options??[]){let n=x1(`div`,`form-check`),r=x1(`input`,`form-check-input`);r.type=`checkbox`,r.name=e.key,r.value=t.id,r.id=b1(`wui-chat-option`);let a=x1(`label`,`form-check-label`,t.label);a.htmlFor=r.id,n.append(r,a),i.append(n),o.push(r)}o.length===0&&(i.tabIndex=-1);let s=x1(`div`,`wui-chat-field`);return s.dataset.key=e.key,s.append(r,...C1(e,t),i,a),{field:e,element:s,controls:o,focus:o[0]??i,invalid:i,error:a,read:()=>JSON.stringify(o.filter(e=>e.checked).map(e=>e.value))}}function O1(e,t){let n=b1(`wui-chat-field-label`),r=x1(`span`,`form-label`,e.label);r.id=n;let i=x1(`div`,`wui-chat-input-slots`);i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-labelledby`,n);let a=S1();i.setAttribute(`aria-describedby`,a.id);let o=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),s=[];for(let t of e.slots??[]){let n=x1(`input`,`wui-chat-input-slot-radio`);n.type=`radio`,n.name=e.key,n.value=t.id,n.id=b1(`wui-chat-slot`);let r=x1(`label`,`btn btn-soft-primary wui-chat-input-slot`,o.format(new Date(t.startDateTimeUtc)));r.htmlFor=n.id,i.append(n,r),s.push(n)}s.length===0&&(i.tabIndex=-1);let c=x1(`div`,`wui-chat-field`);return c.dataset.key=e.key,c.append(r,...C1(e,t),i,a),{field:e,element:c,controls:s,focus:s[0]??i,invalid:i,error:a,read:()=>s.find(e=>e.checked)?.value??``}}function k1(e,t,n){let r=b1(`wui-chat-field-label`),i=x1(`span`,`form-label`,e.label);i.id=r;let a=S1(),o=x1(`input`);o.type=`file`,o.name=e.key,o.id=b1(`wui-chat-field`),o.hidden=!0,e.accept?.length&&(o.accept=e.accept.join(`,`));let s=x1(`button`,`btn btn-soft-primary`,t.inputChooseFile);s.type=`button`,s.dataset.wui=`AppButton`,s.setAttribute(`aria-describedby`,a.id),s.addEventListener(`click`,()=>o.click());let c=x1(`span`,`wui-chat-input-file-status`);c.setAttribute(`aria-live`,`polite`);let l=x1(`button`,`btn btn-link`);l.type=`button`,l.hidden=!0;let u=x1(`div`,`wui-chat-input-file`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-labelledby`,r),u.append(s,c,l,o);let d=`empty`,f=``,p=``,m=0,h=()=>{c.textContent=d===`uploading`?`${t.attachmentUploading} ${f}`:f,l.hidden=f===``,l.textContent=f===``?``:t.inputRemoveFile(f);let e=d===`failed`;a.textContent=e?t.attachmentFailed:``,a.hidden=!e,e?u.setAttribute(`aria-invalid`,`true`):u.removeAttribute(`aria-invalid`)},g=async e=>{m+=1;let t=m;d=`uploading`,f=e.name,p=``,h();try{let r=await n.uploadInputFile(e);if(t!==m)return;p=r,d=`ready`}catch{if(t!==m)return;d=`failed`}h()};o.addEventListener(`change`,()=>{let e=o.files?.[0];e&&g(e)}),l.addEventListener(`click`,()=>{m+=1,d=`empty`,f=``,p=``,o.value=``,h()}),h();let _=x1(`div`,`wui-chat-field`);return _.dataset.key=e.key,_.append(i,...C1(e,t),u,a),{field:e,element:_,controls:[s,l,o],focus:s,invalid:u,error:a,read:()=>d===`ready`?p:``,uploadProblem:()=>d===`uploading`?t.attachmentUploading:d===`failed`?t.attachmentFailed:null}}function A1(e){let t=x1(`input`,`form-check-input`);t.type=`checkbox`,t.name=e.key,t.id=b1(`wui-chat-field`);let n=x1(`label`,`form-check-label`,e.consentText||e.label);n.htmlFor=t.id;let r=S1();t.setAttribute(`aria-describedby`,r.id);let i=x1(`div`,`form-check`);i.append(t,n);let a=x1(`div`,`wui-chat-field`);return a.dataset.key=e.key,a.append(i,r),{field:e,element:a,controls:[t],focus:t,invalid:t,error:r,read:()=>t.checked?`true`:`false`}}function j1(e,t,n,r){if(e.type===`Choice`)return E1(e,t);if(e.type===`MultiChoice`)return D1(e,t);if(e.type===`TimeSlot`)return O1(e,t);if(e.type===`File`)return k1(e,t,n);if(e.type===`Consent`)return A1(e);let i=w1(e,t);return e.verify===`Otp`?T1(i,e,t,n,r):i}function M1(e,t,n){let r=e.uploadProblem?.();if(r)return r;let{field:i}=e;return i.required?i.type===`Consent`?t===`true`?null:n.inputConsentRequired:i.type===`MultiChoice`?t===`[]`?n.inputRequired:null:t===``?n.inputRequired:null:null}function N1(e,t){return e.state===`Answered`?x1(`p`,`wui-chat-input-summary`,e.answeredSummary||t.inputAnswered):x1(`p`,`wui-chat-input-summary`,e.state===`Skipped`?t.inputSkipped:t.inputExpired)}function P1(e){return{kind:`Notice`,code:`NeedsNewerApp`,text:e.needsNewerApp}}Vn(`wui-chat-part-input-request`,class extends Bn{constructor(){super(),this._signature=null,this._turn=null,this._notice=null,this._generation=0}renderPart(e,t,n){this._turn=n;for(let t of v1)this.classList.toggle(`wui-chat-input-request--${t.toLowerCase()}`,e.state===t);let r=JSON.stringify([e.requestId,e.state,e.answeredSummary,e.fields]);r===this._signature?this._notice&&(this._notice.message=t,this._notice.turn=n,this._notice.part=P1(n.labels)):(this._signature=r,this._generation+=1,this._notice=null,this.replaceChildren(this._content(e,t,n)))}_content(e,t,n){if(e.state!==`Open`)return N1(e,n.labels);if(e.fields.some(e=>!g1.has(e.type))){let e=document.createElement(`wui-chat-part-notice`);return e.message=t,e.turn=n,e.part=P1(n.labels),this._notice=e,e}return this._form(e,this._generation)}_form(e,t){let n=this._turn.labels,r=this._turn.features,i=x1(`form`,`wui-chat-input-form`);i.noValidate=!0,i.setAttribute(`aria-label`,e.title||e.submitLabel),e.title&&i.append(x1(`h3`,`wui-chat-input-title`,e.title));let a=e.fields.map(t=>j1(t,n,this._turn,e.requestId));for(let e of a)i.append(e.element);let o=x1(`p`,`wui-chat-input-error`);o.setAttribute(`role`,`status`),o.hidden=!0,i.append(o);let s=x1(`button`,`btn btn-primary`,e.submitLabel);s.type=`submit`,s.dataset.wui=`AppButton`;let c=x1(`div`,`d-flex flex-wrap gap-2`);c.append(s);let l=[s];if(r.LeadShortcuts&&e.fields.length===1&&!e.fields[0].required){let t=x1(`button`,`btn btn-soft-primary`,n.skip);t.type=`button`,t.dataset.wui=`AppButton`,t.addEventListener(`click`,()=>this._turn.skipInput(e.requestId)),c.append(t),l.push(t)}if(r.LeadShortcuts&&e.cancellable){let e=x1(`button`,`btn btn-link`,n.cancel);e.type=`button`,e.addEventListener(`click`,()=>this._turn.cancelLead()),c.append(e),l.push(e)}i.append(c),e.allowTyped&&i.append(x1(`p`,`wui-chat-input-typed`,n.typeAnswer));let u=!1,d=t=>{for(let e of a)for(let n of e.controls)n.disabled=t;for(let e of l)e.disabled=t;s.textContent=t?n.inputSubmitting:e.submitLabel},f=()=>{for(let e of a)e.error.hidden=!0,e.error.textContent=``,e.invalid.removeAttribute(`aria-invalid`);o.hidden=!0,o.textContent=``},p=(e,t)=>{e.error.textContent=t,e.error.hidden=!1,e.invalid.setAttribute(`aria-invalid`,`true`)};return i.addEventListener(`submit`,async r=>{if(r.preventDefault(),u)return;f();let i={},c={},l=[];for(let e of a){let t=e.read();i[e.field.key]=t,e.codeRead&&(c[e.field.key]=e.codeRead());let r=M1(e,t,n);r&&l.push([e,r])}if(l.length>0){for(let[e,t]of l)p(e,t);l[0][0].focus.focus();return}u=!0,d(!0);let m;try{m=await this._turn.answerInput(e.requestId,i,Object.keys(c).length>0?c:null)}catch{m={ok:!1,errors:{},message:n.errorGeneric}}if(t!==this._generation||m.ok)return;u=!1;let h=null;for(let e of a){let t=m.errors?.[e.field.key];t&&(p(e,t),h??=e)}m.message!=null&&(o.textContent=m.message,o.hidden=!1),d(!1),h?h.focus.focus():a[0]?a[0].focus.focus():s.focus()}),i}});var F1={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};Vn(`wui-chat-part-quick-replies`,class extends Bn{#e=null;renderPart(e,t,n){let r=n.features.SuggestedReplies===!0&&n.isLast===!0&&n.busy===!1&&e.replies.length>0,i=typeof n.openTarget==`function`,a=typeof n.beginHandoff==`function`,o=n.handoffPause===!0,s=JSON.stringify([r,e.replies,e.placement,n.labels.quickReplies,n.labels.handoffMoment,i,a,o,n.handoffHosts??null,n.features.LinkHandoff===!0]);if(s===this.#e||(this.#e=s,this.replaceChildren(),!r))return;let c=this.ownerDocument,l=e.placement===`Composer`,u=N(c,`div`,l?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`);u.setAttribute(`role`,`group`),u.setAttribute(`aria-label`,n.labels.quickReplies);let d=l?null:e.replies.find(e=>e.id===`handoff.request`&&e.action===`Send`),f=0;d&&(u.classList.add(`wui-chat-quick-replies--offer`),u.append(this.#t(c,d,n)),f+=1);for(let t of e.replies){if(t===d||t.action===`Open`&&(!t.target||!i))continue;let e=null;if(t.action===`Navigate`){if(n.features.LinkHandoff!==!0)continue;if(yt(t.target,n.handoffHosts))e=t.target;else{let r=n.resolveLink?.(t.target);e=typeof r==`string`&&r!==``?r:null}if(e===null){u.append(N(c,`span`,null,t.label));continue}if(!a)continue}u.append(this.#n(c,t,f,n,d?`wui-chat-quick-reply--quiet`:``,e)),f+=1}if(o){let e=N(c,`span`,`visually-hidden`,n.labels.handoffMoment);e.setAttribute(`role`,`status`),u.append(e)}u.childElementCount>0&&this.append(u)}#t(e,t,n){let r=N(e,`div`,`wui-chat-offer`);return r.style.setProperty(`--wui-chat-i`,`0`),r.append(N(e,`div`,`wui-chat-offer-title`,t.label)),r.append(this.#n(e,{...t,variant:`Primary`},0,n,`wui-chat-offer-action`)),r}#n(e,t,n,r,i=``,a=null){let o=e.createElement(`button`);o.type=`button`,o.className=[`wui-chat-quick-reply`,F1[t.variant]??``,i].filter(Boolean).join(` `),o.style.setProperty(`--wui-chat-i`,String(n));let s=t.action===`Navigate`,c=s&&r.handoffPause===!0;if(o.disabled=c,t.icon){let n=Hn(e,t.icon,16);if(n){let t=N(e,`span`,`wui-chat-quick-reply-icon`);t.setAttribute(`aria-hidden`,`true`),t.append(n),o.append(t)}}return o.append(N(e,`span`,`wui-chat-quick-reply-label`,c?r.labels.handoffMoment:t.label)),o.addEventListener(`click`,()=>{t.action===`Open`?this.turn.openTarget(t.target):s?this.turn.beginHandoff(t,()=>this.#r(a)):(this.turn.chooseQuickReply(t),this.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus())}),o}#r(e){typeof this.turn.openTarget==`function`?this.turn.openTarget(e):globalThis.location.assign(e)}});var I1=new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function L1(e){return I1.has(e)}function R1(e,t,n,r=!0){let i=e=>r?_e(e):[{kind:`text`,text:e}];if(t==null||t===``)return[{kind:`text`,text:`-`}];if(e===`Date`||e===`DateTimeUtc`)return[{kind:`text`,text:_t(t,e,n)}];if(L1(e)){let r=Number(t);return i(Number.isFinite(r)?_t(r,e,n):String(t))}return i(String(t))}var z1=0;function B1(e){return z1+=1,`${e}-${z1}`}Vn(`wui-chat-part-record-card`,class extends Bn{#e=null;renderPart(e,t,n){let r=!!e.target&&typeof n.openRecord==`function`,i=n.features?.FigureText===!0,a=JSON.stringify([e,r,i]);if(a===this.#e)return;this.#e=a;let o=this.ownerDocument,s=N(o,`article`,`wui-chat-record`),c=B1(`wui-chat-record-title`);s.setAttribute(`aria-labelledby`,c);let l=N(o,`div`,`wui-chat-record-head`),u=N(o,`strong`,`wui-chat-record-title`);if(u.id=c,u.setAttribute(`role`,`heading`),u.setAttribute(`aria-level`,`3`),i?t$(u,e.title):u.textContent=String(e.title??``),l.append(u),e.subtitle){let t=N(o,`span`,`wui-chat-record-subtitle`);i?t$(t,e.subtitle):t.textContent=String(e.subtitle??``),l.append(t)}if(s.append(l),e.fields?.length>0){let t=N(o,`dl`,`wui-chat-record-fields`);for(let n of e.fields){let e=N(o,`div`),r=N(o,`dt`);i?t$(r,n.label):r.textContent=String(n.label??``);let a=N(o,`dd`);L1(n.type)&&(a.className=`wui-chat-num`),e$(a,R1(n.type,n.value,null,i)),e.append(r,a),t.append(e)}s.append(t)}if(r){let t=N(o,`button`,`btn btn-soft-primary btn-sm wui-chat-record-open`,n.labels.recordOpen);t.type=`button`,t.setAttribute(`aria-label`,n.labels.recordOpenFor(n$(e.title))),t.addEventListener(`click`,()=>this.turn.openRecord(e)),s.append(t)}this.replaceChildren(s)}});var V1=/^https?:\/\//i;Vn(`wui-chat-part-sources`,class extends Bn{renderPart(e,t,n){if(this.replaceChildren(),!n.features.Sources||e.sources.length===0)return;let r=this.ownerDocument,i=N(r,`div`,`wui-chat-sources`);i.append(N(r,`p`,`wui-chat-sources-label`,n.labels.sources));let a=N(r,`ul`,`wui-chat-sources-list`);a.setAttribute(`aria-label`,n.labels.sources);for(let t of e.sources){let e=r.createElement(`li`);e.append(this.#e(r,t,n)),a.append(e)}i.append(a),this.append(i)}#e(e,t,n){let r;return typeof t.url==`string`&&V1.test(t.url)?(r=N(e,`a`,`wui-chat-source`),r.setAttribute(`href`,t.url),r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`),r.setAttribute(`aria-label`,n.labels.openSource(t.title))):(r=N(e,`span`,`wui-chat-source`),r.tabIndex=-1),r.dataset.marker=String(t.marker),r.append(N(e,`span`,`wui-chat-source-marker`,String(t.marker)),N(e,`span`,`wui-chat-source-title`,t.title)),r}});var H1=25,U1=0;function W1(e,t,n){let r=e.createElement(`tr`);for(let i of t.columns){let t=e.createElement(`th`);t.setAttribute(`scope`,`col`),L1(i.type)&&(t.className=`wui-chat-num`),n?t$(t,i.label):t.textContent=String(i.label??``),r.append(t)}return r}function G1(e,t,n,r){let i=e.createElement(`tr`);return t.columns.forEach((a,o)=>{let s=o===0&&a.type===`Text`,c=e.createElement(s?`th`:`td`);s&&c.setAttribute(`scope`,`row`),L1(a.type)&&(c.className=`wui-chat-num`);let l=n[o];l==null||l===``?c.append(N(c.ownerDocument,`span`,`wui-chat-null`,`-`)):e$(c,R1(a.type,l,t.currency,r)),i.append(c)}),i}function K1(e,t){let n=()=>{let n=t.scrollWidth-t.clientWidth;e.dataset.scroll=n<=1?`none`:t.scrollLeft>=n-1?`end`:t.scrollLeft>0?`middle`:`start`};t.addEventListener(`scroll`,n,{passive:!0}),typeof ResizeObserver<`u`&&new ResizeObserver(n).observe(t),n()}function q1(e,t,n,r,i){let a=e.ownerDocument;for(let o=n;o<r;o+=1)e.append(G1(a,t,t.rows[o],i))}Vn(`wui-chat-part-table`,class extends Bn{#e=null;renderPart(e,t,n){let r=n.features?.FigureText===!0,i=JSON.stringify([e,r]);if(i===this.#e)return;if(this.#e=i,!e.columns||e.columns.length===0){this.replaceChildren();return}let a=this.ownerDocument,o=N(a,`figure`,`wui-chat-table`),s=null;if(e.title){U1+=1,s=`wui-chat-table-${U1}`;let t=N(a,`figcaption`,`wui-chat-table-title`);t.id=s,r?t$(t,e.title):t.textContent=String(e.title??``),o.append(t)}let c=N(a,`div`,`table-wrap wui-chat-table-wrap`);c.tabIndex=0,c.setAttribute(`role`,`region`),s?c.setAttribute(`aria-labelledby`,s):c.setAttribute(`aria-label`,n.labels.table);let l=N(a,`table`,`table table-sm wui-chat-table-grid`),u=a.createElement(`thead`);u.append(W1(a,e,r));let d=a.createElement(`tbody`);q1(d,e,0,Math.min(e.rows.length,H1),r),l.append(u,d),c.append(l);let f=N(a,`div`,`wui-chat-table-frame`),p=N(a,`span`,`wui-chat-table-cue`);if(p.setAttribute(`aria-hidden`,`true`),f.append(c,p),o.append(f),K1(f,c),e.rows.length>H1){let t=N(a,`button`,`btn btn-soft-primary btn-sm wui-chat-table-more`,n.labels.tableShowAll(e.rows.length));t.type=`button`,t.addEventListener(`click`,()=>{q1(d,e,H1,e.rows.length,r),t.remove()}),o.append(t)}this.replaceChildren(o)}});var J1=/\[([^[\]\n]+)\](?!\()/g,Y1=new Set(`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`),X1=/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,Z1=/!\[([^\]\n]*)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/y,Q1=new RegExp(J1.source,`y`),$1=e=>/[\p{L}\p{N}]/u.test(e);function e0(e,t){let n=0;for(let r=t-1;r>=0&&e.charAt(r)===`\\`;--r)n+=1;return n%2==1}function t0(e,t,n){let r=n.length===1;for(let i=e.indexOf(n,t);i!==-1;i=e.indexOf(n,i+1)){let a=i>t&&!/\s/.test(e.charAt(t))&&!/\s/.test(e.charAt(i-1)),o=r&&(e.charAt(i+1)===n||e.charAt(i-1)===n),s=n===`_`&&$1(e.charAt(i+n.length));if(a&&!o&&!s&&!e0(e,i))return i}return-1}function n0(e,t){let n=t?.isCitation,r=[],i=``,a=()=>{i&&=(r.push({type:`text`,text:i}),``)},o=0;for(;o<e.length;){let s=e.charAt(o),c=e.charAt(o+1);if(s===`\\`&&Y1.has(c)){i+=c,o+=2;continue}if(s==="`"){let t=e.indexOf("`",o+1);if(t>o+1){a(),r.push({type:`code`,text:e.slice(o+1,t)}),o=t+1;continue}}let l=s+c;if(l===`**`||l===`__`||l===`~~`){let n=t0(e,o+2,l);if(n!==-1&&!(l===`__`&&$1(e.charAt(o-1)))){a();let i=n0(e.slice(o+2,n),t);l===`~~`?r.push({type:`strike`,children:i}):r.push({type:`strong`,children:i}),o=n+2;continue}i+=l,o+=2}else{if(s===`*`||s===`_`){let n=t0(e,o+1,s);if(n!==-1&&!(s===`_`&&$1(e.charAt(o-1)))){a(),r.push({type:`em`,children:n0(e.slice(o+1,n),t)}),o=n+1;continue}}if(s===`[`){X1.lastIndex=o;let t=X1.exec(e);if(t){a(),r.push({type:`link`,href:t[2],children:n0(t[1])}),o+=t[0].length;continue}if(n){Q1.lastIndex=o;let t=Q1.exec(e);if(t&&n(t[1])){a(),r.push({type:`citation`,text:t[1]}),o+=t[0].length;continue}}}if(s===`!`){Z1.lastIndex=o;let t=Z1.exec(e);if(t){a(),r.push({type:`image`,children:n0(t[1])}),o+=t[0].length;continue}}i+=s,o+=1}}return a(),r.map((e,t)=>({...e,key:t}))}var r0=/^[a-z][a-z0-9+.-]*:[a-z0-9_-]+\/[a-z0-9_.~-]+$/i,i0=/^https?:/i,a0=/^(mailto|tel):/i,o0=/^(?:\/(?![/\\])|#|\?|\.{1,2}\/)/;function s0(e,t,n,r){if(n&&(t===`page`||r0.test(e))){let t=n(e);if(t!=null)return{kind:`app`,target:t}}return t===`app`?null:o0.test(e)?{kind:`page`,href:e}:t===`page`&&!(i0.test(e)&&r&&c0(e,r))?null:i0.test(e)?{kind:r&&c0(e,r)?`page`:`web`,href:e}:a0.test(e)?{kind:`contact`,href:e}:null}function c0(e,t){if(e.slice(0,t.length).toLowerCase()!==t.toLowerCase())return!1;let n=e[t.length];return n===void 0||n===`/`||n===`?`||n===`#`}function l0(e){return typeof e!=`string`||!e.startsWith(`/`)||e[1]===`/`||e[1]===`\\`?null:e}var u0=/^\s*```/,d0=/^\s*```\s*(\S*)/,f0=/^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/,p0=/^\s*([-*_])(\s*\1){2,}\s*$/,m0=/^(\s*)[-*+]\s+(.*)$/,h0=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,g0=/^\s*>\s?(.*)$/,_0=/^\s*\|?\s*:?-{3,}:?\s*(\|\s*:?-{3,}:?\s*)*\|?\s*$/,v0=e=>e.includes(`|`);function y0(e){let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&(t=t.slice(0,-1)),t.split(`|`).map(e=>e.trim())}function b0(e,t){return v0(e[t])&&t+1<e.length&&e[t+1].includes(`|`)&&_0.test(e[t+1])}function x0(e,t){let n=e[t];return u0.test(n)||g0.test(n)||m0.test(n)||h0.test(n)||f0.test(n)||p0.test(n)||b0(e,t)}function S0(e){let t=e.replace(/\t/g,` `).length;return Math.min(Math.floor(t/2),4)}function C0(e){let t=h0.exec(e);if(t)return{text:t[3],depth:S0(t[1]),ordered:!0,number:Number(t[2])};let n=m0.exec(e);return n?{text:n[2],depth:S0(n[1]),ordered:!1,number:0}:null}function w0(e){let t=(e??``).replace(/\r\n?/g,`
|
|
42
42
|
`).split(`
|
|
43
43
|
`),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r+=1;continue}if(u0.test(e)){let i=d0.exec(e)?.[1]||null,a=[];for(r+=1;r<t.length&&!u0.test(t[r]);)a.push(t[r]),r+=1;r+=1,n.push({type:`code`,text:a.join(`
|
|
44
|
-
`),language:i});continue}if(b0(t,r)){let i=y0(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&v0(t[r]);)a.push(y0(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(p0.test(e)){n.push({type:`rule`}),r+=1;continue}let i=f0.exec(e);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]}),r+=1;continue}if(g0.test(e)){let e=[];for(;r<t.length;){let n=g0.exec(t[r]);if(!n)break;e.push(n[1]),r+=1}n.push({type:`quote`,lines:e});continue}let a=C0(e);if(a){let e=[];for(;r<t.length&&t[r].trim();){let n=C0(t[r]);if(n){if(n.depth===0&&n.ordered!==a.ordered)break;e.push(n)}else if(x0(t,r))break;else e[e.length-1].text+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!x0(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var T0=[`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`],E0=[`app`,`web`,`page`];function D0(e,t,n,r,i=null){let a=O0(e.ownerDocument,n,r).map((e,n)=>{let r=t[n]?.sig===e.sig?t[n].nodes:null;return{sig:e.sig,nodes:r??e.build()}}),o=new Set(a.flatMap(e=>e.nodes));for(let e of t)for(let t of e.nodes)o.has(t)||t.remove();let s=i;for(let t of a.flatMap(e=>e.nodes))(t.parentNode!==e||t.previousSibling!==s)&&e.insertBefore(t,s?s.nextSibling:e.firstChild),s=t;return a}function O0(e,t,n){let r={doc:e,links:E0.includes(n.links)?n.links:`web`,headings:n.headings===`text`?`text`:`outline`,resolveLink:n.resolveLink,isCitation:n.isCitation},i=n.resolverGeneration??0;return w0(t).map(e=>({sig:`${JSON.stringify(e)}|${r.links}|${r.headings}|${i}`,build:()=>j0(r,e)}))}var k0=class extends Q${static get observedAttributes(){return[`links`,`headings`]}constructor(){super(),this._drawn=[],this._blocks=[],this._observer=null,this._connected=!1,this._resolveLink=void 0,this._isCitation=void 0,this._resolverGeneration=0}connectedCallback(){this._connected=!0,this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._drawn.some(t=>t.contains(e.target)))&&this._render()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._connected=!1,this._observer?.disconnect(),this._observer=null}get resolveLink(){return this._resolveLink}set resolveLink(e){this._resolveLink=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get isCitation(){return this._isCitation}set isCitation(e){this._isCitation=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}attributeChangedCallback(e,t,n){t!==n&&this._connected&&this._render()}_source(){return Array.from(this.children).find(e=>e.tagName===`PRE`&&e.classList.contains(`wui-markdown-source`))}_render(){let e=this._source();e&&(this._blocks=D0(this,this._blocks,e.textContent??``,{links:this.getAttribute(`links`)??void 0,headings:this.getAttribute(`headings`)??void 0,resolveLink:this._resolveLink,isCitation:this._isCitation,resolverGeneration:this._resolverGeneration},e),this._drawn=this._blocks.flatMap(e=>e.nodes),e.hidden=!0,this._observer?.takeRecords())}};function A0(e,t,n=[]){let r=e.createElement(t);return r.append(...n),r}function j0(e,t){switch(t.type){case`paragraph`:return[A0(e.doc,`p`,M0(e,t.lines))];case`heading`:return[N0(e,t)];case`list`:return P0(e,t.items);case`table`:return[I0(e,t)];case`code`:return[L0(e.doc,t)];case`quote`:return[A0(e.doc,`blockquote`,M0(e,t.lines))];case`rule`:return[e.doc.createElement(`hr`)];default:return[]}}function M0(e,t){let n=[];return t.forEach((t,r)=>{r>0&&n.push(e.doc.createElement(`br`)),n.push(...R0(e,t))}),n}function N0(e,t){let n=R0(e,t.text);if(e.headings===`text`){let t=A0(e.doc,`p`,n);return t.className=`fw-semibold`,t}return A0(e.doc,`h2`,n)}function P0(e,t){let n=[];for(let r=0;r<t.length;){let i=F0(e,t,r);n.push(i.list),r=i.next}return n}function F0(e,t,n){let{depth:r,ordered:i,number:a}=t[n],o=e.doc.createElement(i?`ol`:`ul`);i&&a!==1&&o.setAttribute(`start`,String(a));let s=null,c=n;for(;c<t.length&&t[c].depth>=r;)if(t[c].depth===r)s=A0(e.doc,`li`,R0(e,t[c].text)),o.append(s),c+=1;else{let n=F0(e,t,c);s.append(n.list),c=n.next}return{list:o,next:c}}function I0(e,t){let n=t.header.map(t=>{let n=A0(e.doc,`th`,R0(e,t));return n.setAttribute(`scope`,`col`),n}),r=t.rows.map(n=>A0(e.doc,`tr`,t.header.map((t,r)=>A0(e.doc,`td`,R0(e,n[r]??``))))),i=A0(e.doc,`table`,[A0(e.doc,`thead`,[A0(e.doc,`tr`,n)]),A0(e.doc,`tbody`,r)]);i.className=`table`;let a=A0(e.doc,`div`,[i]);return a.className=`table-responsive`,a}function L0(e,t){let n=A0(e,`pre`,[A0(e,`code`,[e.createTextNode(t.text)])]);n.className=`wui-code-source`;let r=A0(e,`wui-code-block`,[n]);return r.className=`wui-code-block`,r.setAttribute(`language`,T0.includes(t.language)?t.language:`text`),r}function R0(e,t){return z0(e,n0(t,{isCitation:e.isCitation}))}function z0(e,t){return t.flatMap(t=>B0(e,t))}function B0(e,t){let{doc:n}=e;switch(t.type){case`code`:return[A0(n,`code`,[n.createTextNode(t.text)])];case`strong`:return[A0(n,`strong`,z0(e,t.children))];case`em`:return[A0(n,`em`,z0(e,t.children))];case`strike`:return[A0(n,`del`,z0(e,t.children))];case`image`:return[n.createTextNode(`[`),...z0(e,t.children),n.createTextNode(`]`)];case`link`:return V0(e,t);case`citation`:return[H0(n,t.text)];default:return[n.createTextNode(t.text)]}}function V0(e,t){let n=z0(e,t.children),r=s0(t.href,e.links,e.resolveLink,globalThis.location?.origin);if(!r)return n;if(r.kind===`app`){let t=l0(r.target);return t?[U0(e.doc,t,n,!1)]:n}return[U0(e.doc,r.href,n,r.kind===`web`)]}function H0(e,t){let n=e.createElement(`span`);n.className=`chip primary chip-outline chip-sm chip-clickable wui-markdown-citation`,n.setAttribute(`data-wui`,`AppChip`);let r=e.createElement(`button`);r.type=`button`,r.className=`chip-body`,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>{r.dispatchEvent(new CustomEvent(`wui-markdown-citation`,{bubbles:!0,detail:{citation:t}}))});let i=e.createElement(`span`);return i.className=`chip-label`,i.textContent=t,r.append(i),n.append(r),n}function U0(e,t,n,r){let i=A0(e,`span`,n);i.className=`wui-link__label`;let a=A0(e,`a`,[i]);return a.className=`wui-link wui-link--static`,a.setAttribute(`data-wui`,`AppLink`),a.setAttribute(`href`,t),r&&(a.setAttribute(`target`,`_blank`),a.setAttribute(`rel`,`noopener noreferrer`)),a}Z$(`wui-markdown`,k0);var W0=`AppButton`,G0={primary:`btn-primary`,soft:`btn-soft-primary`,outline:`btn-outline-primary`,ghost:`btn-ghost-primary`,text:`btn-link-primary`,danger:`btn-danger`,success:`btn-success`,"outline-danger":`btn-outline-danger`,light:`btn-neutral`,warning:`btn-warning`,neutral:`btn-soft-neutral`,"outline-light":`btn-glass`,"outline-secondary":`btn-outline-neutral`};function K0(e=`primary`,t=`md`){let n=G0[e];if(!n)throw Error(`buttonClass: unknown variant "${e}"`);return t===`md`?`btn ${n}`:`btn ${n} btn-${t}`}var q0=Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`]),J0=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,css:`CSS`}),Y0=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),X0=`(?![\\s\\S])`,Z0=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${X0})`).source,Q0=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,Y0([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],$0=[[`comment`,RegExp(`//[^\\n]*|${Z0}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,Y0(`async.await.break.case.catch.class.const.continue.default.delete.do.else.export.extends.finally.for.from.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.yield`.split(`.`))],[`literal`,Y0([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],e2=[[`comment`,RegExp(`//[^\\n]*|${Z0}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,Y0(`abstract.as.async.await.base.bool.break.byte.case.catch.char.checked.class.const.continue.decimal.default.delegate.do.double.else.enum.event.explicit.extern.finally.fixed.float.for.foreach.get.goto.if.implicit.in.init.int.interface.internal.is.lock.long.namespace.new.object.operator.out.override.params.private.protected.public.readonly.record.ref.required.return.sbyte.sealed.set.short.sizeof.static.string.struct.switch.this.throw.try.typeof.uint.ulong.unchecked.unsafe.ushort.using.var.virtual.void.volatile.when.while.with`.split(`.`))],[`literal`,Y0([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],t2=[[`comment`,RegExp(`--[^\\n]*|${Z0}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,Y0(`add.all.alter.and.as.asc.begin.between.by.case.check.column.commit.constraint.create.cross.database.declare.default.delete.desc.distinct.drop.else.end.exec.execute.exists.foreign.from.full.function.group.having.if.in.index.inner.insert.into.is.join.key.left.like.limit.not.null.offset.on.or.order.outer.over.partition.primary.procedure.references.return.returns.right.rollback.select.set.table.then.top.transaction.union.unique.update.values.view.when.where.while.with`.split(`.`))],[`literal`,Y0([`true`,`false`])],[`type`,Y0([`bigint`,`bit`,`char`,`date`,`datetime`,`datetime2`,`decimal`,`float`,`int`,`money`,`nchar`,`numeric`,`nvarchar`,`real`,`smallint`,`text`,`time`,`tinyint`,`uniqueidentifier`,`varchar`])],[`function`,/\b[A-Za-z_]\w*(?=\s*\()/],[`punct`,/[(),;]/]],n2=[[`comment`,/(?<![^\s;|&(])#[^\n]*/],[`string`,/"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/],[`variable`,/\$(?:\{[^}\n]*\}?|[A-Za-z_]\w*|[0-9@#?$!*-])/],[`attr`,/(?<![\w-])--?[A-Za-z][\w-]*/],[`number`,/(?<![\w.-])\d+(?:\.\d+)?\b/],[`keyword`,Y0([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,Y0(`awk.az.cat.cd.chmod.chown.cp.curl.docker.dotnet.echo.gcloud.git.grep.kubectl.ls.mkdir.mv.npm.npx.pnpm.rm.sed.source.sudo.wget`.split(`.`))],[`punct`,/[|&;<>(){}[\]]+/]],r2=[[`comment`,/^#[^\n]*/m],[`keyword`,/^(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(?= )/m],[`literal`,/HTTP\/\d(?:\.\d)?/],[`number`,/(?<=^HTTP\/\d(?:\.\d)? )\d{3}\b/m],[`function`,/(?<=^[A-Z]+ )\S+/m],[`attr`,/^[A-Za-z][\w-]*(?=:)/m],[`string`,/(?<=^[A-Za-z][\w-]*:[ \t]*)[^\n]+/m]],i2=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${X0})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],a2={json:Q0,js:$0,cs:e2,sql:t2,bash:n2,http:r2,css:[[`comment`,new RegExp(Z0)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`keyword`,/@[\w-]+|!important/],[`attr`,/[\w-]+(?=\s*:[^{};]*[;}])/],[`number`,/#[0-9a-fA-F]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:%|[A-Za-z]{1,4})?/],[`function`,/[\w-]+(?=\()/],[`type`,/[.#](?!\d)[A-Za-z_][\w-]*/],[`punct`,/[{}();:,]/]],html:i2,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},o2=new Map;function s2(e){let t=o2.get(e);if(!t){let n=a2[e],r=e===`sql`?`gi`:`g`,i=n.map(([,e])=>`(${e.source})`).join(`|`);t={re:new RegExp(i,`${r}m`),types:n.map(([e])=>e)},o2.set(e,t)}return t}function c2(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function l2(e,t,n=[]){let{re:r,types:i}=s2(e),a=0;for(let o of t.matchAll(r)){if(!o[0])continue;c2(n,`plain`,t.slice(a,o.index));let r=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[r]===`tag`?l2(`htmlTag`,o[0],n):c2(n,i[r],o[0]),a=o.index+o[0].length}return c2(n,`plain`,t.slice(a)),n}function u2(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return l2(`http`,e);let n=l2(`http`,e.slice(0,t.index+t[0].length)),r=e.slice(t.index+t[0].length),i=r.trimStart()[0];return i===`{`||i===`[`?l2(`json`,r,n):i===`<`?l2(`html`,r,n):(c2(n,`plain`,r),n)}function d2(e,t){let n=String(e??``);return!n||n.length>1e5?n?[[`plain`,n]]:[]:t===`http`?u2(n):!Object.hasOwn(a2,t)||t===`htmlTag`?[[`plain`,n]]:l2(t,n)}function f2(e,t){let n=[[]];for(let[r,i]of d2(e,t))i.split(/\r\n|\r|\n/).forEach((e,t)=>{t>0&&n.push([]),e&&n[n.length-1].push([r,e])});return n.length>1&&n[n.length-1].length===0&&n.pop(),n}var p2=class extends Q${static get observedAttributes(){return[`language`,`line-numbers`,`wrap`,`label`,`copy-label`,`copied-label`]}constructor(){super(),this._chrome=null,this._title=null,this._view=null,this._codeEl=null,this._copyIcon=null,this._copyText=null,this._copied=!1,this._observer=null,this._timer=0,this._cancelFrame=null}connectedCallback(){this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._chrome?.contains(e.target))&&this._schedule()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._cancelPending()}attributeChangedCallback(){this.isConnected&&this._render()}_source(){return Array.from(this.children).find(e=>e.classList.contains(`wui-code-source`))}_code(){return(this._source()?.textContent??``).replace(/\r?\n$/,``)}_schedule(){if(this._cancelFrame)return;let e=()=>{this._cancelFrame=null,this._render()};if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);this._cancelFrame=()=>cancelAnimationFrame(t)}else{let t=!0;queueMicrotask(()=>{t&&e()}),this._cancelFrame=()=>{t=!1}}}_cancelPending(){this._cancelFrame?.(),this._cancelFrame=null}_render(){if(!this._source())return;this._cancelPending();let e=this.ownerDocument;this._chrome||this._build(e);let t=this.getAttribute(`language`),n=q0.includes(t)?t:`text`,r=this.getAttribute(`label`)||``,i=f2(this._code(),n);this._title.textContent=r||J0[n],this._view.setAttribute(`aria-label`,r||`Code`),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>m2(e,t))),this._copied||(this._copyText.textContent=this._copyLabel()),this.setAttribute(`data-wui-ready`,``),this._observer?.takeRecords()}_build(e){let t=e.createElement(`div`);t.className=`wui-code-chrome`,t.append(this._bar(e));let n=e.createElement(`div`);n.className=`wui-code-view`,n.setAttribute(`role`,`region`),n.tabIndex=0;let r=e.createElement(`pre`);r.className=`wui-code-pre`,this._codeEl=e.createElement(`code`),r.append(this._codeEl),n.append(r),t.append(n),this._chrome=t,this._view=n,this.append(t)}_bar(e){let t=e.createElement(`div`);t.className=`wui-code-bar`,this._title=e.createElement(`span`),this._title.className=`wui-code-title`;let n=e.createElement(`button`);return n.type=`button`,n.className=`${K0(`ghost`,`sm`)} wui-code-copy`,n.dataset.wui=W0,n.setAttribute(`aria-live`,`polite`),this._copyIcon=e.createElement(`span`),this._copyIcon.className=`wui-code-copy-icon`,this._copyText=e.createElement(`span`),this._setCopied(!1),n.append(this._copyIcon,this._copyText),n.addEventListener(`click`,async()=>{await kn(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=setTimeout(()=>this._setCopied(!1),2e3))}),t.append(this._title,n),t}_setCopied(e){this._copied=e,this._copyIcon.innerHTML=Rn(e?`check`:`files`,{size:14}),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||`Copied`:this.getAttribute(`copy-label`)||`Copy`}};function m2(e,t){let n=e.createElement(`span`);n.className=`wui-code-line`;for(let[r,i]of t){if(r===`plain`){n.append(i);continue}let t=e.createElement(`span`);t.className=`wui-code-t-${r}`,t.textContent=i,n.append(t)}return n}Z$(`wui-code-block`,p2);var h2=new Set([`Visitor`,`Customer`]),g2=/^\d+$/,_2=`pre, code, .wui-markdown-source`;function v2(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):g2.test(t):!1}function y2(e,t){if(yt(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function b2(e,t){let n=globalThis.location?.origin;for(let r of e.querySelectorAll(`a[href]`)){let e=r.dataset.linkSource??r.getAttribute(`href`);r.dataset.linkSource=e;let i=y2(e,t);i===null?r.replaceWith(r.ownerDocument.createTextNode(r.textContent)):(i!==r.getAttribute(`href`)&&r.setAttribute(`href`,i),Ne(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function x2(e){let t=e.ownerDocument,n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[];for(let e=n.nextNode();e;e=n.nextNode())e.parentElement?.closest(_2)||r.push(e);for(let e of r){let n=_e(e.nodeValue);if(n.length===1&&n[0].kind===`text`)continue;let r=t.createDocumentFragment();e$(r,n),e.replaceWith(r)}}function S2(e){let t=e.turn;b2(e,t),t?.features?.FigureText===!0&&x2(e)}Vn(`wui-chat-part-text`,class extends Bn{#e=null;#t=null;#n=null;#r=null;#i=!1;#a=null;constructor(){super(),this.addEventListener(`wui-markdown-citation`,e=>{let t=this.turn;typeof t?.openCitation==`function`&&t.openCitation(Number(e.detail.citation))}),this.addEventListener(`click`,e=>this.#s(e))}renderPart(e,t){let n=h2.has(t.author.kind)?`plain`:`markdown`;if(n!==this.#e&&(this.#e=n,this.#r=null,this.#t=n===`plain`?this.#c():this.#l(e.text),this.#n=n===`plain`?null:this.#t.firstElementChild,this.replaceChildren(this.#t)),n===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#r&&(this.#r=n,this.#t.replaceChildren(),t?e$(this.#t,_e(e.text)):this.#t.append(this.ownerDocument.createTextNode(e.text)))}else this.#n.textContent!==e.text&&(this.#n.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#i||(this.#i=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#o()}disposePart(){this.#a?.disconnect(),this.#a=null}#o(){this.#a||(this.#a=new MutationObserver(()=>S2(this)),this.#a.observe(this,{childList:!0,subtree:!0,characterData:!0}),S2(this))}#s(e){let t=e.target instanceof Element?e.target.closest(`a[href]`):null,n=this.turn;if(!t||!this.contains(t))return;let r=t.getAttribute(`href`);r.startsWith(`#`)||(r.startsWith(`/`)&&typeof n?.onNavigate==`function`?(e.preventDefault(),n.onNavigate(r)):typeof n?.openTarget==`function`&&(e.preventDefault(),n.openTarget(r)))}#c(){return N(this.ownerDocument,`div`,`wui-chat-bubble`)}#l(e){let t=this.ownerDocument,n=N(t,`wui-markdown`,`wui-markdown wui-chat-text`);n.setAttribute(`links`,`web`),n.setAttribute(`headings`,`text`),n.isCitation=e=>v2(this.turn,e);let r=N(t,`pre`,`wui-markdown-source`,e);return n.append(r),n}}),Vn(`wui-chat-part-ticket`,class extends Bn{renderPart(e,t,n){let{labels:r}=n,i=$(`article`,`wui-chat-ticket`,{"aria-label":r.ticketAria(e.number)}),a=$(`div`,`wui-chat-ticket-head`),o=$(`span`,`wui-chat-ticket-number`);o.textContent=r.ticketAria(e.number),a.append(o);let s=z$(e.status);if(s!==null){let t=$(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${s}`);t.textContent=B$(e.status,r),a.append(t)}let c=$(`strong`,`wui-chat-ticket-title`);if(c.textContent=e.subject,i.append(a,c),typeof n.openTicket==`function`){let t=$(`div`,`wui-chat-ticket-foot`),a=$(`button`,`wui-chat-ticket-link`,{type:`button`});a.textContent=r.ticketView,a.addEventListener(`click`,()=>n.openTicket({ticketId:e.ticketId,number:e.number})),t.append(a),i.append(t)}this.replaceChildren(i)}});var C2=`http://www.w3.org/2000/svg`,w2={mic:`M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12z`,stop:`M6 6h12v12H6z`,play:`M8 5v14l11-7z`,pause:`M6 5h4v14H6zm8 0h4v14h-4z`,speaker:`M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z`};function T2(e,t=18){if(!Object.hasOwn(w2,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(C2,`svg`);n.setAttribute(`viewBox`,`0 0 24 24`),n.setAttribute(`width`,String(t)),n.setAttribute(`height`,String(t)),n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`focusable`,`false`),n.setAttribute(`fill`,`currentColor`);let r=document.createElementNS(C2,`path`);return r.setAttribute(`d`,w2[e]),n.append(r),n}var E2=40,D2=null,O2=class extends Bn{#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;#u=0;#d=0;#f=!1;#p=null;#m=null;#h=null;#g=0;#_=!1;renderPart(e,t,n){this.#e=n,n.features.VoiceClips?(this.#t===null&&this.#y(),e.attachmentId!==this.#l&&(this.disposePart(),this.#l=e.attachmentId,this.#d=0,this.#n.replaceChildren(...En(e.attachmentId,E2).map(k2))),this.#u=e.durationMs,this.#b(e)):this.#v(e.transcript)}disposePart(){this.#g+=1,this.#p?.pause(),this.#h!==null&&URL.revokeObjectURL(this.#h),D2===this&&(D2=null),this.#p=null,this.#m=null,this.#h=null,this.#f=!1}#v(e){if(this.disposePart(),this.#t=null,this.#l=null,this.#o=null,this.#s=null,typeof e==`string`&&e!==``){let t=N(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#y(){this.#t=N(document,`div`,`wui-chat-clip`),this.#t.setAttribute(`role`,`group`);let e=N(document,`div`,`wui-chat-clip-row`);this.#r=N(document,`button`,`wui-chat-clip-play`),this.#r.type=`button`,this.#r.addEventListener(`click`,()=>this.#A()),this.#n=N(document,`div`,`wui-chat-clip-wave`),this.#n.setAttribute(`aria-hidden`,`true`),this.#i=N(document,`span`,`wui-chat-clip-time`),e.append(this.#r,this.#n,this.#i),this.#a=N(document,`p`,`wui-chat-clip-error`),this.#a.setAttribute(`role`,`status`),this.#a.hidden=!0,this.#t.append(e,this.#a),this.replaceChildren(this.#t)}#b(e){let t=this.#e.labels;this.#t.setAttribute(`aria-label`,t.voiceClip),this.#r.disabled=this.#_||typeof this.#e.readAttachment!=`function`,this.#x(),this.#S(),this.#C(e.transcript)}#x(){let e=this.#e.labels,t=this.#f?e.voiceClipPause:e.voiceClipPlay;this.#r.setAttribute(`aria-label`,t),this.#r.title=t,this.#r.replaceChildren(T2(this.#f?`pause`:`play`,18))}#S(){let e=this.#u/1e3,t=e>0?Math.min(1,this.#d/e):0,n=Math.floor(t*E2);[...this.#n.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<n)});let r=Dn(Math.max(1,Math.round(e)));this.#i.textContent=this.#e.labels.voiceClipTime(Dn(this.#d),r)}#C(e){typeof e!=`string`||e===``?(this.#o?.remove(),this.#s?.remove(),this.#o=null,this.#s=null):(this.#o===null&&(this.#o=N(document,`button`,`wui-chat-clip-toggle`),this.#o.type=`button`,this.#o.addEventListener(`click`,()=>{this.#c=!this.#c,this.#s.hidden=!this.#c,this.#w()}),this.#s=N(document,`p`,`wui-chat-clip-transcript`),this.#s.hidden=!this.#c,this.#t.append(this.#o,this.#s)),this.#s.textContent=e,this.#w())}#w(){let e=this.#e.labels;this.#o.setAttribute(`aria-expanded`,String(this.#c)),this.#o.textContent=this.#c?e.voiceClipHideTranscript:e.voiceClipShowTranscript}#T(){return this.#m??=this.#E().catch(e=>{throw this.#m=null,e}),this.#m}async#E(){let e=this.#g,t=await this.#e.readAttachment(this.#l),n=URL.createObjectURL(new Blob([t],{type:r(t)}));if(e!==this.#g)return URL.revokeObjectURL(n),null;this.#h!==null&&URL.revokeObjectURL(this.#h),this.#h=n;let i=new Audio(this.#h);return i.addEventListener(`timeupdate`,()=>{this.#d=i.currentTime,this.#S()}),i.addEventListener(`ended`,()=>{this.#d=0,this.#D(),this.#S()}),i.addEventListener(`error`,()=>{this.#D(),this.#m=null,this.#k()}),this.#p=i,i}#D(){this.#p?.pause(),this.#O(!1)}#O(e){this.#f=e,e?(D2&&D2!==this&&D2.#D(),D2=this):D2===this&&(D2=null),this.#t!==null&&this.#x()}#k(){this.#a.textContent=this.#e.labels.voiceClipFailed,this.#a.hidden=!1}async#A(){if(this.#f)this.#D();else{this.#a.hidden=!0,this.#_=!0,this.#r.disabled=!0,this.#r.setAttribute(`aria-busy`,`true`);try{let e=await this.#T();if(e===null)return;this.#O(!0),await e.play()}catch{this.#D(),this.#m=null,this.#k()}finally{this.#_=!1,this.#r.removeAttribute(`aria-busy`),this.#r.disabled=typeof this.#e.readAttachment!=`function`}}}};function k2(e){let t=N(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}Vn(`wui-chat-part-voice-clip`,O2);var A2={Text:`wui-chat-part-text`,Sources:`wui-chat-part-sources`,QuickReplies:`wui-chat-part-quick-replies`,InputRequest:`wui-chat-part-input-request`,Action:`wui-chat-part-action`,Notice:`wui-chat-part-notice`,Table:`wui-chat-part-table`,Chart:`wui-chat-part-chart`,Figures:`wui-chat-part-figures`,RecordCard:`wui-chat-part-record-card`,Image:`wui-chat-part-image`,File:`wui-chat-part-file`,Ticket:`wui-chat-part-ticket`,Handoff:`wui-chat-part-handoff`,VoiceClip:`wui-chat-part-voice-clip`},j2=n({SpeechConfig:()=>void 0}),M2=t((()=>{})),N2=1e4,P2=2e3,F2=3e5,I2=new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),L2=new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function R2(e){return I2.has(e?.name)?new A(`Blocked`,e.message):L2.has(e?.name)?new A(`NoMicrophone`,e.message):z2(e)}function z2(e){return e instanceof A?e:new A(`Failed`,e?.message??String(e))}var B2=null;function V2(){return globalThis.SpeechSDK?globalThis.SpeechSDK:(B2===null&&(B2=Promise.resolve().then(()=>(M2(),j2)).then(e=>e.SpeechConfig?e:e.default).catch(e=>{throw B2=null,e})),B2)}function H2(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function U2(e){let t=e.getToken,n=e.loadSdk??V2,r=e.getLanguage??H2,i=typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,a=typeof window<`u`&&window.isSecureContext===!0,o=i&&a,s=typeof window<`u`,c=null,l=null,u=null;function d(){return c!==null&&Date.parse(c.expiresDateTimeUtc)-Date.now()>6e4?Promise.resolve(c):(l===null&&(l=Promise.resolve().then(()=>t()).then(e=>(c=e,l=null,e),e=>{throw l=null,z2(e)})),l)}function f(){return u===null&&(u=Promise.resolve().then(()=>n()).then(e=>{if(!e?.SpeechConfig)throw new A(`Unavailable`,`Speech is not available in this browser.`);return e}).catch(e=>{throw u=null,z2(e)})),u}function p(e={}){let{signal:t,onText:n,onEnd:i}=e;if(t?.aborted)return i?.(),Promise.resolve();let a,s,c=new Promise((e,t)=>{a=e,s=t}),l=!1,u=!1,p=null,m=!1,h=``,g=[],_=null,v=null,y=null,b=()=>{clearTimeout(_),clearTimeout(v),clearTimeout(y)},x=e=>{if(!l){l=!0,b(),t?.removeEventListener(`abort`,S);try{p?.close()}finally{try{i?.()}finally{e?s(e):a()}}}};async function S(){if(!(l||u)){if(u=!0,b(),p!==null)try{await new Promise(e=>p.stopContinuousRecognitionAsync(e,e))}catch{}x(null)}}let C=()=>[...g,h].filter(e=>e!==``).join(` `).trim(),w=(e,t)=>{m||(m=!0,clearTimeout(_)),clearTimeout(v),v=setTimeout(S,P2),n?.(C(),t)};async function T(){if(t?.addEventListener(`abort`,S),!o){x(new A(`Unavailable`,`Dictation is not available in this browser.`));return}let n;try{n=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){x(R2(e));return}for(let e of n.getTracks())e.stop();if(!l)try{let t=await f(),n=await d();if(l)return;let i=t.SpeechConfig.fromAuthorizationToken(n.token,n.region);if(i.speechRecognitionLanguage=e.language||r(),i.setProperty(t.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,String(N2)),p=new t.SpeechRecognizer(i,t.AudioConfig.fromDefaultMicrophoneInput()),p.recognizing=(e,t)=>{if(l)return;let n=t.result?.text;n&&(h=n,w(n,!1))},p.recognized=(e,n)=>{if(l)return;let{reason:r,text:i}=n.result;r===t.ResultReason.RecognizedSpeech&&i?(g.push(i),h=``,w(i,!0)):r===t.ResultReason.NoMatch&&t.NoMatchDetails.fromResult(n.result).reason===t.NoMatchReason.InitialSilenceTimeout&&x(new A(`NoSpeech`,`No speech was heard.`))},p.canceled=(e,n)=>{l||(n.reason===t.CancellationReason.Error?x(new A(`Failed`,n.errorDetails)):x(null))},p.sessionStopped=()=>x(null),await new Promise((e,t)=>p.startContinuousRecognitionAsync(e,t)),l)return;e.onStarted?.(),_=setTimeout(()=>{m||x(new A(`NoSpeech`,`No speech was heard.`))},N2),y=setTimeout(S,F2)}catch(e){x(z2(e))}}return T(),c}async function m(e,t={}){let{signal:n}=t;if(!n?.aborted)try{let i=await f(),a=await d();if(n?.aborted)return;let o=i.SpeechConfig.fromAuthorizationToken(a.token,a.region);o.speechSynthesisLanguage=t.language||r();let s=new i.SpeakerAudioDestination,c=new i.SpeechSynthesizer(o,i.AudioConfig.fromSpeakerOutput(s));await new Promise((t,r)=>{let a=!1,o=()=>{n?.removeEventListener(`abort`,d),c.close(),s.close()},l=()=>{a||(a=!0,o(),t())},u=e=>{a||(a=!0,o(),r(z2(e)))};function d(){s.pause(),l()}n?.addEventListener(`abort`,d),s.onAudioEnd=l;try{c.speakTextAsync(e,e=>{e.reason!==i.ResultReason.SynthesizingAudioCompleted&&u(new A(`Failed`,`The reply could not be synthesised.`))},e=>u(e))}catch(e){u(e)}})}catch(e){throw z2(e)}}return{dictation:o,readAloud:s,streamsText:!0,startDictation:p,speak:m}}var W2=8e3,G2=6e3,K2=new Set([`Blocked`,`NoMicrophone`]);function q2(e){let t=e instanceof A?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:K2.has(t)}}function J2(e){let t=it(e.filter(e=>e.kind===`Text`)).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=6e3)return t;let n=t.slice(0,G2),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function Y2(e,t){switch(e.code){case`Blocked`:return t.dictationBlocked;case`NoMicrophone`:return t.dictationNoMicrophone;case`NoSpeech`:return t.dictationNotHeard;case`Unavailable`:return t.dictationUnavailable;case`Failed`:return t.dictationFailed;case`SpeakFailed`:return t.readAloudFailed;default:throw Error(`Unknown voice note code "${e.code}".`)}}function X2(e){let t=e.getState,n=e.speech??U2({getToken:e.getToken}),r=`Idle`,i=null,a=null,o=null,s=null,c=0,l=null,u=new Set,d=()=>({mode:r,messageId:i,startedAtMs:a,note:o});function f(){let e=d();for(let t of[...u])t(e)}function p(e){r=e.mode,i=e.messageId??null,a=e.startedAtMs??null,f()}function m(){clearTimeout(l),l=null}function h(e){m(),o=e,e&&!e.sticky&&(l=setTimeout(()=>{l=null,o=null,f()},W2)),f()}function g(){o!==null&&(m(),o=null,f())}function _(){return c+=1,s={id:c,controller:new AbortController,stopped:!1},s}function v(e){s===e&&(s=null,p({mode:`Idle`}))}function y(){let e=s;s=null,e&&(e.stopped=!0,e.controller.abort()),r!==`Idle`&&p({mode:`Idle`})}function b(){let e=t();return!!(e.features.Dictation&&e.profile?.speechAvailable&&n.dictation)}function x(){let e=t();return!!(e.features.ReadAloud&&e.profile?.speechAvailable&&n.readAloud)}async function S(e){if(r===`Dictating`){y();return}if(y(),h(null),!b())return;let t=e.getText(),i=t!==``&&!/\s$/.test(t)?`${t} `:t,a=_();p({mode:`Dictating`});try{await n.startDictation({signal:a.controller.signal,onText:t=>{s===a&&e.setText(i+t)},onEnd:()=>v(a)})}catch(e){if(a.stopped)return;v(a),h(q2(e))}}async function C(e,t){if(r===`Speaking`&&i===e){y();return}y(),h(null);let a=J2(t);if(a===``)return;let o=_();p({mode:`Speaking`,messageId:e});try{await n.speak(a,{signal:o.controller.signal}),v(o)}catch{if(o.stopped)return;v(o),h({code:`SpeakFailed`,source:`ReadAloud`,sticky:!1,messageId:e})}}function w(e){return u.add(e),()=>{u.delete(e)}}function T(){y(),m(),o=null,u.clear()}return{canDictate:b,canSpeak:x,getStatus:d,subscribe:w,toggleDictation:S,toggleSpeak:C,stop:y,dismissNote:g,destroy:T}}var Z2=new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function Q2(e,t){e.isTrusted&&!Z2.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function $2({voice:e,getLabels:t,textarea:n,onTextChanged:r}){let i=null,a=$(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});a.append(T2(`mic`,20)),a.hidden=!0,a.addEventListener(`click`,()=>{e.toggleDictation({getText:()=>n.value,setText:e=>{n.value=n.maxLength>0?e.slice(0,n.maxLength):e,r(),n.setSelectionRange(n.value.length,n.value.length)}})});let o=$(`p`,`wui-chat-voice-note`,{role:`status`});o.hidden=!0;let s=$(`span`,`visually-hidden`,{"aria-live":`polite`});function c(e){let n=t(),r=e.note?.source===`ReadAloud`?null:e.note,i=e.mode===`Dictating`,c=i?n.dictateStop:n.dictate;a.setAttribute(`aria-pressed`,String(i)),a.setAttribute(`aria-label`,c),a.title=c;let l=r?.code===`Blocked`||r?.code===`NoMicrophone`;r===null?(o.hidden=!0,o.textContent=``):(o.hidden=!1,o.textContent=Y2(r,n),o.setAttribute(`role`,r.sticky?`alert`:`status`)),o.classList.toggle(`wui-chat-voice-note--blocked`,l),s.textContent=i?n.dictateListening:``}function l(t){let{state:n}=t;a.hidden=!e.canDictate();let r=e.getStatus().mode===`Speaking`,i=n.messagesLeftToday===0;a.disabled=i||r||n.handoffPause===!0}function u(e){c(e),i!==null&&l(i)}let d=e.subscribe(u);function f(t){i=t,l(t),c(e.getStatus())}function p(){d()}return{buttons:[a],note:o,announcer:s,paint:f,destroy:p}}var e4=10,t4=.9,n4=0;function r4(e){for(let t of e.toReversed())for(let e of t.parts.toReversed())if(e.kind===`InputRequest`&&e.state===`Open`)return e.fields[0]?.label??e.title??null;return null}function i4(e){n4+=1;let t=`wui-chat-composer-hint-${n4}`,n=$(`p`,`wui-chat-allowance`,{role:`status`});n.hidden=!0;let r=$(`span`),i=$(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});i.addEventListener(`click`,()=>e.onCancelEdit());let a=$(`div`,`wui-chat-editing`);a.hidden=!0,a.append(r,i);let o=$(`div`,`wui-chat-attachments`);o.hidden=!0;let s=$(`button`,`wui-chat-tool`,{type:`button`});s.append(_$(`paperclip`,20)),s.hidden=!0;let c=$(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});c.hidden=!0,c.addEventListener(`change`,()=>{let t=[...c.files];c.value=``,t.length>0&&e.onAttach(t)}),s.addEventListener(`click`,()=>c.click());let l=$(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":t}),u=$(`span`,`visually-hidden`,{id:t}),d=$(`span`,`wui-chat-counter`);d.hidden=!0;let f=$(`button`,`wui-chat-send`,{type:`submit`});f.append(_$(`arrow-up`,18));let p=$(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});p.append(_$(`stop`,16)),p.hidden=!0,p.addEventListener(`click`,()=>e.onStop());let m=$(`form`,`wui-chat-composer`);m.append(s,c,l,d,u,p,f);let h=null,g=null,_=null,v=0,y=null;function b(){l.style.height=`auto`,l.style.height=`${l.scrollHeight}px`;let e=getComputedStyle(l),t=l.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom);m.classList.toggle(`wui-chat-composer--multiline`,t>(parseFloat(e.lineHeight)||22)*1.5)}function x(){return y?.attachments.some(e=>e.status===`Uploading`)??!1}function S(){return y?.attachments.some(e=>e.status===`Ready`)??!1}function C(){let e=l.value.length,t=v>0&&e>v*t4;d.hidden=!t,t&&_&&(d.textContent=_.counter(e,v))}function w(){let e=y?.messagesLeftToday??null,t=l.value.trim()===``&&!S();f.disabled=!!y?.streaming||e===0||x()||t||y?.handoffPause===!0,m.classList.toggle(`wui-chat-composer--has-text`,!t)}function T(){if(f.disabled)return;let t=l.value.trim();l.value=``,b(),C(),w(),e.voice?.stop(),e.voice?.dismissNote(),e.onSubmit(t)}l.addEventListener(`input`,()=>{b(),C(),w(),l.value!==``&&e.onTyping?.()}),l.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),T())}),m.addEventListener(`submit`,e=>{e.preventDefault(),T()});let E=e.voice?$2({voice:e.voice,getLabels:()=>_,textarea:l,onTextChanged:()=>{b(),C(),w()}}):null;E&&(m.insertBefore(E.buttons[0],f),l.addEventListener(`keydown`,t=>Q2(t,e.voice)));function D(t){let n=t.map(t=>{let n=$(`span`,`wui-chat-chip`),r=$(`span`,null,t.status===`Failed`?{title:t.error??``}:null);r.textContent=t.fileName;let i=$(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":_.removeAttachment(t.fileName)});i.append(_$(`x`,14)),i.addEventListener(`click`,()=>e.onRemove(t.key));let a=[];if(t.status===`Uploading`){let e=$(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof t.progress==`number`&&(e.value=t.progress);let n=$(`span`,`wui-chat-chip-status`);n.textContent=_.attachmentUploading,a.push(e,n)}if(t.status===`Failed`){let e=$(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=t.error||_.attachmentFailed,a.push(e)}return n.append(r,...a,i),n});o.replaceChildren(...n),o.hidden=n.length===0}function O(t){y=t.state,_=t.labels,v=t.maxLength,t.sendIcon&&f.dataset.icon!==t.sendIcon&&(f.dataset.icon=t.sendIcon,f.replaceChildren(_$(t.sendIcon,18)));let o=y.messagesLeftToday;m.setAttribute(`aria-label`,_.composer),u.textContent=_.composerHint,l.setAttribute(`aria-label`,_.composer),l.maxLength=v,l.placeholder=y.handoffPause?_.handoffMoment:r4(y.messages)??_.placeholder,l.disabled=o===0||y.handoffPause===!0,n.hidden=!(o!==null&&o<=e4),n.hidden||(n.textContent=_.allowance(o));let d=y.editing?.messageId??null;if(d!==h){let t=h!==null;h=d,y.editing?(e.voice?.stop(),l.value=y.editing.text,b()):t&&(l.value=``,b())}a.hidden=!y.editing,r.textContent=_.editing,i.textContent=_.cancel;let x=t.draft??null;typeof x==`string`&&x!==``&&x!==g&&(g=x,l.value=x,l.dispatchEvent(new Event(`input`)),l.focus(),e.onDraftApplied?.()),D(y.attachments);let S=y.features.Attachments&&(y.profile?.limits.maxAttachments??0)>0&&y.handoffPause!==!0;s.hidden=!S,s.setAttribute(`aria-label`,_.attach),s.title=_.attachHint,c.accept=t.accept??``;let T=y.streaming&&y.features.Stop;p.hidden=!T,p.setAttribute(`aria-label`,_.stop),f.hidden=T,f.setAttribute(`aria-label`,_.send),C(),w(),E?.paint({state:y})}function k(){l.focus()}function A(){E?.destroy();for(let e of j)e.remove()}let j=[n,a,o,...E?[E.note,E.announcer]:[],m];return{nodes:j,paint:O,focus:k,destroy:A,getDraft:()=>l.value}}var a4=`https://policies.google.com/privacy`,o4=`https://policies.google.com/terms`;function s4(e,t){let n=$(`a`,`wui-chat-footer-link`,{href:t,target:`_blank`,rel:`noopener noreferrer`});return n.textContent=e,n}function c4(){let e=$(`span`,`wui-chat-footer-sep`,{"aria-hidden":`true`});return e.textContent=`·`,e}function l4(){let e=$(`p`,`wui-chat-footer`);e.hidden=!0;function t(t){let{labels:n,profile:r}=t,i=[];if(r){let e=$(`span`,`wui-chat-footer-text`);e.textContent=r.footer.disclaimer||n.disclaimer,i.push(e);let t=$(`span`,`wui-chat-footer-privacy`);if(r.footer.privacyText&&t.append(document.createTextNode(r.footer.privacyText)),r.footer.privacyUrl){t.hasChildNodes()&&t.append(document.createTextNode(` `));let e=$(`a`,`wui-chat-footer-link`,{href:r.footer.privacyUrl});e.textContent=n.footerPrivacy,t.append(e)}if(t.hasChildNodes()&&i.push(t),r.footer.assuranceText){let e=$(`span`);e.textContent=r.footer.assuranceText,i.push(e)}if(kt(r)){let e=$(`span`,`wui-chat-footer-captcha`);e.append(document.createTextNode(`${n.captchaNote} `),s4(n.captchaPrivacy,a4),document.createTextNode(` `),s4(n.captchaTerms,o4)),i.push(e)}}e.replaceChildren(...i.flatMap((e,t)=>t?[c4(),e]:[e])),e.hidden=i.length===0}return{el:e,paint:t}}function u4(e,t,n){e.setAttribute(`aria-label`,t),e.title=t,e.dataset.icon!==n&&(e.dataset.icon=n,e.replaceChildren(_$(n,20)))}function d4(e){let t=$(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),n=$(`strong`,`wui-chat-title`);e.titleId&&(n.id=e.titleId);let r=$(`span`,`wui-chat-tagline`),i=$(`span`,`wui-chat-status`),a=$(`div`,`wui-chat-header-text`);a.append(n,r,i);let o=b$(``,`history`,()=>e.onHistory()),s=b$(``,`volume-high`,()=>e.onMute()),c=b$(``,`plus`,()=>e.onNew()),l=b$(``,`maximize-4`,()=>e.onSwitch());l.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let u=b$(``,`panel-left-open`,()=>e.onSwitch());u.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let d=b$(``,`x`,()=>e.onClose());d.classList.add(`wui-chat-close-btn`);let f=$(`div`,`wui-chat-header-actions`);f.append(o,s,c,l,u,d);let p=$(`header`,`wui-chat-header`);p.append(t,a,f);function m(e){let{labels:t}=e;p.hidden=!1,n.textContent=e.title??``,r.textContent=e.tagline??``,r.hidden=!e.tagline,i.textContent=e.status??``,o.hidden=!e.showHistory,e.viewingHistory?u4(o,t.backToChat,`arrow-left`):u4(o,t.history,`history`),s.hidden=!e.showMute,u4(s,e.muted?t.unmuteSounds:t.muteSounds,e.muted?`volume-mute`:`volume-high`),c.hidden=!!e.viewingHistory||e.showNew===!1,c.disabled=!e.canNew,u4(c,t.newChat,`plus`),l.hidden=e.switchTo!==`full-page`,l.disabled=!e.canSwitch,u4(l,t.openFullScreen,`maximize-4`),u.hidden=e.switchTo!==`docked`,u.disabled=!e.canSwitch,u4(u,t.openSidePanel,`panel-left-open`),d.hidden=!e.showClose,u4(d,t.close,`x`)}return{el:p,paint:m}}var f4=120;function p4(e,t,n=`outline`){let r=$(`button`,`${v$(n,`sm`)} wui-chat-action-btn`,{type:`button`});return r.textContent=e,r.addEventListener(`click`,t),r}function m4(e){let t=$(`div`,`wui-chat-history`);t.hidden=!0;let n=null,r=null,i=null,a=null,o=null,s=!1;function c(){return n||(n=k({client:e.getClient()}),r=n.subscribe(()=>_()),n)}function l(e){i={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},a=null,o=null,s=!0,_()}function u(e){i={id:e.publicId,kind:`delete`,saving:!1},a=null,o=null,_()}function d(){i=null,a=null,o=null,_()}async function f(){let t=i,n=t?.draft.trim()??``;if(t?.kind===`rename`&&!t.saving&&n){t.saving=!0,_();try{await c().rename(t.id,n),i===t&&(i=null),a=null,o=null}catch{if(i!==t)return;t.saving=!1,o=e.getLabels().renameFailed}_()}}async function p(){let t=i;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,_();try{await c().remove(t.id),i===t&&(i=null),a=null,e.onDeleted(t.id)}catch{if(i!==t)return;t.saving=!1,a=e.getLabels().deleteFailed}_()}}function m(e){let t=$(`li`,`wui-chat-history-row wui-chat-history-row--editing`),n=$(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(f4)});n.value=i.draft,n.addEventListener(`input`,()=>{i.draft=n.value,r.disabled=i.saving||!i.draft.trim()}),n.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),f()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),d())});let r=p4(e.renameSave,()=>f(),`primary`);if(r.disabled=i.saving||!i.draft.trim(),t.append(n,r,p4(e.cancel,()=>d(),`ghost`)),o!==null){let e=$(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=o,t.append(e)}return s&&(s=!1,queueMicrotask(()=>n.focus())),t}function h(e){let t=$(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),n=$(`p`);n.textContent=e.deleteConfirmTitle;let r=$(`p`);r.textContent=e.deleteConfirmMessage;let a=p4(e.deleteConfirm,()=>p(),`danger`);return a.disabled=i.saving,t.append(n,r,a,p4(e.cancel,()=>d(),`ghost`)),t}function g(t,n,r){if(i?.id===t.publicId&&i.kind===`rename`)return m(n);if(i?.id===t.publicId&&i.kind===`delete`)return h(n);let a=$(`li`,`wui-chat-history-row`),o=$(`button`,`wui-chat-history-open`,{type:`button`}),s=$(`span`,`wui-chat-history-title`);s.textContent=t.title||n.untitled;let c=$(`span`,`wui-chat-history-time`);return c.textContent=rt(t.lastActivityDateTimeUtc),o.append(s,c),o.addEventListener(`click`,()=>e.onOpen(t.publicId)),a.append(o),r.Rename&&a.append(b$(n.rename,`pencil`,()=>l(t))),r.Delete&&a.append(b$(n.deleteChat,`trash`,()=>u(t))),a}function _(){let r=e.getLabels(),i=e.getFeatures(),o=n?n.getState():{items:[],loading:!1,error:null,hasMore:!1},s=[];if(o.error||a){let e=$(`p`,`wui-chat-history-error`,{role:`alert`});o.error?(e.append(document.createTextNode(r.loadFailed),document.createTextNode(` `)),e.append(p4(r.retry,()=>c().load(),`outline`))):e.textContent=a,s.push(e)}if(o.loading&&o.items.length===0){let e=$(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=r.loadingConversation,s.push(e)}if(o.items.length===0&&!o.loading&&!o.error){let e=$(`p`,`wui-chat-history-empty`),t=$(`span`);t.textContent=r.historyEmptyTitle;let n=$(`span`);n.textContent=r.historyEmptyText,e.append(t,n),s.push(e)}if(o.items.length>0){let e=$(`ul`,`wui-chat-history-list`,{"aria-label":r.history});e.append(...o.items.map(e=>g(e,r,i))),s.push(e)}o.hasMore&&!o.loading&&s.push(p4(r.loadMore,()=>c().loadMore(),`outline`)),t.replaceChildren(...s)}function v(){t.hidden=!1,c().load().catch(()=>{}),_()}function y(){t.hidden=!0}function b(){r?.(),r=null,n?.dispose(),n=null}return{el:t,show:v,hide:y,paint:_,dispose:b}}var h4=new Set([`GET`,`HEAD`]);function g4(){let e=document.querySelector(`meta[name="wui-csrf"]`),t=e?.getAttribute(`content`);return t?{token:t,header:e.getAttribute(`data-header`)||`RequestVerificationToken`}:null}async function _4(e){let t=await e.text();if(t){if((e.headers.get(`content-type`)||``).includes(`json`))try{return JSON.parse(t)}catch{return t}return t}}async function v4(e,t){let n=new TextDecoder,r=e.body.getReader(),i=``;for(;;){let{done:a,value:o}=await r.read();if(a)break;i+=n.decode(o,{stream:!0}),t({event:{target:{responseText:i,status:e.status}}})}return i+=n.decode(),i}function y4({fetch:e=(...e)=>globalThis.fetch(...e)}={}){async function t(t,n,r,i={}){let a={...i.headers},o;if(typeof FormData<`u`&&r instanceof FormData){for(let e of Object.keys(a))e.toLowerCase()===`content-type`&&delete a[e];o=r}else r!==void 0&&(a[`Content-Type`]=`application/json`,o=JSON.stringify(r));if(!h4.has(t)){let e=g4();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l.abort(s.reason);i.timeout>0&&(l=new AbortController,c=l.signal,s?.aborted?l.abort(s.reason):s?.addEventListener(`abort`,d,{once:!0}),u=setTimeout(()=>l.abort(new DOMException(`The request timed out.`,`TimeoutError`)),i.timeout));try{let r=await e(n,{method:t,headers:a,body:o,signal:c,credentials:`same-origin`});if(!r.ok){let e=Error(`Request failed with status ${r.status}`);throw e.response={status:r.status,data:await _4(r)},e}let s=i.responseType===`arraybuffer`,l=!s&&typeof i.onDownloadProgress==`function`&&r.body,u;return u=s?await r.arrayBuffer():l?await v4(r,i.onDownloadProgress):await _4(r),{data:u,status:r.status}}finally{clearTimeout(u),s?.removeEventListener(`abort`,d)}}return{get:(e,n)=>t(`GET`,e,void 0,n),post:(e,n,r)=>t(`POST`,e,n,r),put:(e,n,r)=>t(`PUT`,e,n,r),delete:(e,n)=>t(`DELETE`,e,void 0,n)}}function b4(e){let t=null,n=!1,r=!1,i=$(`div`,`wui-chat-nudge`,{role:`status`});i.hidden=!0;let a=$(`button`,`wui-chat-nudge-text`,{type:`button`}),o=$(`button`,`wui-chat-nudge-close`,{type:`button`});o.append(_$(`x`,14)),i.append(a,o);function s(){clearTimeout(t),t=null}function c(){s(),r=!0,i.hidden=!0}a.addEventListener(`click`,()=>{i.hidden=!0,e.onActivate()}),o.addEventListener(`click`,()=>{c(),e.onDismiss()});function l(e){s(),r||n||(t=setTimeout(()=>{t=null,a.textContent=e.text,o.setAttribute(`aria-label`,e.label),i.hidden=!1,n=!0},e.delaySeconds*1e3))}function u(){s(),i.remove()}return{el:i,schedule:l,cancel:s,dismiss:c,isShown:()=>n,destroy:u}}var x4=6e4,S4=60*x4,C4=48*S4;function w4(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function T4(e,t=Date.now(),n=void 0){let r=w4(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<x4)return s.format(0,`second`);if(a<S4){let e=Math.floor(a/x4);return s.format(o?-e:e,`minute`)}if(a<C4){let e=Math.floor(a/S4);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function E4(e,t=void 0){let n=w4(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}function D4(e){let{list:t,getLabels:n,getFeatures:r,onOpen:i}=e,a=e.now??(()=>Date.now()),o=$(`div`,`wui-chat-empty-rows wui-chat-empty-rows--past`);o.hidden=!0;let s=!1;function c(e,t){let n=$(`button`,`wui-chat-empty-row`,{type:`button`}),r=$(`span`,`wui-chat-empty-row-title`);r.textContent=e.title||t.earlierChat;let o=$(`span`,`wui-chat-empty-row-time`,{title:E4(e.lastActivityDateTimeUtc)});return o.textContent=T4(e.lastActivityDateTimeUtc,a()),n.append(r,o),n.addEventListener(`click`,()=>i(e.publicId)),n}function l(){if(s)return;let e=t.getState().items;if(r().History!==!0||e.length===0){o.replaceChildren(),o.hidden=!0;return}let i=n();o.replaceChildren(...e.slice(0,20).map(e=>c(e,i))),o.hidden=!1}let u=t.subscribe(l);return{el:o,refresh(){r().History===!0&&t.load().catch(()=>{})},paint:l,dispose(){s=!0,u()}}}var O4=`https://www.google.com/recaptcha/api.js?render=`,k4=new Map;function A4(e){let t=k4.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=O4+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{k4.delete(e),n(Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return k4.set(e,n),n}async function j4(e,t){let n=await A4(e);await new Promise(e=>n.ready(e));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var M4=`data-wui-chat-docked`,N4=`--wui-chat-docked-width`,P4=420,F4=new Set;function I4(e,t){let n=document.documentElement;n.setAttribute(M4,e),n.style.setProperty(N4,t)}function L4(){let e=document.documentElement;e.removeAttribute(M4),e.style.removeProperty(N4)}function R4(e){let t=D$({...e,layout:`docked`,role:`dialog`,launcher:!0}),n={},r=e.position,i=!1,a=null,o=()=>`${Math.round(t.panel.getBoundingClientRect().width)||P4}px`;function s(){F4.add(n),I4(r,o()),typeof ResizeObserver==`function`&&(a=new ResizeObserver(()=>document.documentElement.style.setProperty(N4,o())),a.observe(t.panel))}function c(){a?.disconnect(),a=null,F4.delete(n),F4.size===0&&L4()}function l(e){t.setOpen(e),e&&!i?(i=!0,s()):!e&&i&&(i=!1,c())}function u(e){t.setAppearance(e),e.position!==void 0&&(r=e.position,i&&document.documentElement.setAttribute(M4,r))}function d(){l(!1)}return{...t,setOpen:l,setAppearance:u,destroy:d}}function z4(e){return D$({...e,layout:`embedded`,role:`region`,launcher:!1})}var B4=`wchat:peeked`,V4=576,H4=200;function U4(e){let t=D$({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:n,panel:r,nudgeHost:i,launcherButton:a}=t,o={peek:!1,peekSeconds:3,hideWhileOpen:!1};a.dataset.state=`closed`;let s=!1,c=!1,l=null,u=null;function d(){!o.peek||s||c||i.dataset.launcher!==`idle`||globalThis.innerWidth<V4||globalThis.sessionStorage.getItem(B4)!==null||(globalThis.sessionStorage.setItem(B4,`1`),i.dataset.launcher=`peeking`,l=setTimeout(()=>{l=null,i.dataset.launcher===`peeking`&&(i.dataset.launcher=`idle`)},o.peekSeconds*1e3))}i.addEventListener(`animationend`,e=>{e.target===i&&i.dataset.launcher===`idle`&&d()});function f(e){if(e!==c){if(c=e,clearTimeout(l),l=null,e)clearTimeout(u),u=null,o.hideWhileOpen?(i.dataset.launcher=`hidden`,i.toggleAttribute(`inert`,!0)):i.dataset.launcher===`peeking`&&(i.dataset.launcher=`idle`);else if(o.hideWhileOpen){let e=r.contains(document.activeElement);u=setTimeout(()=>{u=null,i.toggleAttribute(`inert`,!1),i.dataset.launcher=`idle`,e&&a.focus()},H4)}}a.dataset.state=e?`open`:`closed`,t.setOpen(e)}function p(e){e.reduced!==void 0&&(s=!!e.reduced),e.peek!==void 0&&(o.peek=e.peek),e.peekSeconds!==void 0&&(o.peekSeconds=e.peekSeconds),e.hideWhileOpen!==void 0&&(o.hideWhileOpen=e.hideWhileOpen),e.phoneMode!==void 0&&n.classList.toggle(`wui-chat--sheet`,e.phoneMode===`Sheet`),e.sheetHeightDvh!==void 0&&n.style.setProperty(`--wui-chat-sheet-height`,`${e.sheetHeightDvh}dvh`),e.sheetMaxHeightPx!==void 0&&n.style.setProperty(`--wui-chat-sheet-max-height`,`${e.sheetMaxHeightPx}px`),t.setAppearance(e),!o.hideWhileOpen&&i.dataset.launcher===`hidden`&&!c&&(i.dataset.launcher=`idle`),i.dataset.launcher===`idle`&&d()}return{...t,setOpen:f,setAppearance:p}}function W4(e){return D$({...e,layout:`full-page`,role:`region`,launcher:!1})}var G4=3,K4={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function q4(e){let t=$(`h2`,`wui-chat-greeting`),n=$(`div`,`wui-chat-empty-hero`);n.append($(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),t);let r=$(`div`,`wui-chat-empty-extra`);r.hidden=!0;let i=$(`div`,`wui-chat-starters`,{role:`group`}),a=$(`div`,`wui-chat-empty-rows`),o=$(`div`,`wui-chat-empty-past`),s=$(`div`,`wui-chat-empty`,{role:`group`});s.append(n,r,i,a,o);function c(t,n){let r=$(`button`,[`wui-chat-starter`,K4[t.variant]??``].filter(Boolean).join(` `),{type:`button`});return r.style.setProperty(`--wui-chat-i`,String(n)),t.icon&&r.append(_$(t.icon,16)),r.append(document.createTextNode(t.label)),r.addEventListener(`click`,()=>e.onStarter(t)),r}function l(t,n){let r=$(`button`,`wui-chat-empty-row`,{type:`button`}),i=$(`span`,`wui-chat-empty-row-label`);i.textContent=n.resumeLast;let a=$(`span`,`wui-chat-empty-row-title`,{title:t.title||n.untitled});a.textContent=t.title||n.untitled;let o=$(`span`,`wui-chat-empty-row-time`);return o.textContent=rt(t.lastActivityDateTimeUtc),r.append(i,a,o),r.addEventListener(`click`,()=>e.onResume()),r}function u(t,n,r){let i=r?$(`button`,`wui-chat-empty-row`,{type:`button`}):$(`span`,`wui-chat-empty-row`),a=$(`span`,`wui-chat-empty-row-label`);a.textContent=n.ticketAria(t.number);let o=$(`span`,`wui-chat-empty-row-title`);o.textContent=t.subject;let s=$(`span`,`wui-chat-empty-row-status`);return s.textContent=B$(t.status,n),i.append(a,o,s),r&&i.addEventListener(`click`,()=>e.onTicket(t)),i}function d(e,t){if(e.features?.OpenTickets!==!0||!e.openTickets?.length)return null;let n=$(`div`,`wui-chat-open-tickets`,{role:`group`,"aria-label":t.openTickets});return n.append(...e.openTickets.slice(0,G4).map(n=>u(n,t,e.ticketsClickable===!0))),n}function f(e){let{labels:n}=e;t.textContent=e.greeting??``,s.setAttribute(`aria-label`,n.emptyTitle);let r=e.starters??[];i.setAttribute(`aria-label`,n.starters),i.hidden=!e.showStarters||r.length===0,i.replaceChildren(...r.map(c));let o=e.resume??null,u=d(e,n);a.hidden=o===null&&u===null,a.replaceChildren(...[o===null?null:l(o,n),u].filter(Boolean))}return{el:s,paint:f,extraHost:r,pastHost:o}}function J4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-orb`;let t=document.createElement(`span`);t.className=`wui-chat-loader-orb-mark`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-orb-glow`,n.setAttribute(`aria-hidden`,`true`);let r=document.createElement(`span`);r.className=`wui-chat-loader-orb-disc`,r.setAttribute(`aria-hidden`,`true`),t.append(n,r);let i=document.createElement(`span`);return i.className=`wui-chat-loader-orb-label`,e.append(t,i),{el:e,render(e){i.textContent!==e.label&&(i.textContent=e.label)}}}var Y4=150,X4=1800;function Z4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-phrases`;let t=document.createElement(`span`);t.className=`wui-chat-loader-phrases-orb`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-phrases-stage`,e.append(t,n);let r=null,i=null;function a(){return e.closest(`.wui-chat-loader`)?.classList.contains(`wui-chat-loader--reduced`)===!0}function o(e){if(e.label===r)return;r=e.label;let t=i,o=document.createElement(`span`);o.className=`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,o.textContent=e.label,o.style.animationDelay=`-${Math.round(performance.now()%X4)}ms, 0s`,n.append(o),i=o,t&&(t.classList.remove(`wui-chat-loader-phrases-text--in`),t.classList.add(`wui-chat-loader-phrases-text--out`),t.style.animationDelay=`-${Math.round(performance.now()%X4)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),Y4))}return{el:e,render:o}}var Q4=[`95%`,`80%`,`60%`];function $4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-skeleton`;let t=document.createElement(`div`);t.className=`wui-chat-loader-skeleton-label`;let n=document.createElement(`div`);n.className=`wui-chat-loader-skeleton-body`;let r=document.createElement(`span`);r.className=`wui-chat-loader-skeleton-avatar`,r.setAttribute(`aria-hidden`,`true`),n.append(r);for(let e of Q4){let t=document.createElement(`span`);t.className=`wui-chat-loader-skeleton-line`,t.setAttribute(`aria-hidden`,`true`),t.style.width=e,n.append(t)}return e.append(t,n),{el:e,render(e){t.textContent!==e.label&&(t.textContent=e.label)}}}var e3=`http://www.w3.org/2000/svg`;function t3(e){if(e===`done`){let e=document.createElementNS(e3,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(e3,`path`);return t.setAttribute(`d`,`M3 8.5 6.5 12 13 4.5`),t.setAttribute(`pathLength`,`1`),e.append(t),e}let t=document.createElement(`span`);return t.className=e===`active`?`wui-chat-loader-steps-ring`:`wui-chat-loader-steps-dot`,t}function n3(){let e=document.createElement(`div`);e.className=`wui-chat-loader-steps`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-pill`;let n=document.createElement(`ol`);n.className=`wui-chat-loader-steps-list`,e.append(t,n);let r=[];function i(){let e=document.createElement(`li`);e.className=`wui-chat-loader-steps-item`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-icon`,t.setAttribute(`aria-hidden`,`true`);let i=document.createElement(`span`);i.className=`wui-chat-loader-steps-text`,e.append(t,i);let a={li:e,icon:t,text:i,state:null};return r.push(a),n.append(e),a}function a(e){let a=e.steps.length===0;for(t.hidden=!a,n.hidden=a,a&&t.textContent!==e.label&&(t.textContent=e.label),e.steps.forEach((t,n)=>{let a=r[n]??i();a.text.textContent!==t&&(a.text.textContent=t);let o=n<e.activeIndex?`done`:n===e.activeIndex?`active`:`pending`;a.state!==o&&(a.state=o,a.li.dataset.state=o,a.icon.replaceChildren(t3(o)))});r.length>e.steps.length;)r.pop().li.remove()}return{el:e,render:a}}var r3={Steps:n3,Phrases:Z4,Orb:J4,Skeleton:$4},i3=500;function a3(){let e=document.createElement(`div`);e.className=`wui-chat-loader`,e.setAttribute(`role`,`status`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-avatar`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`div`);n.className=`wui-chat-loader-body`;let r=document.createElement(`span`);r.className=`visually-hidden`,e.append(t,n,r);let i=null,a=null,o=0,s=null,c=0,l=null,u=!1;function d(){s!==null&&clearInterval(s),s=null}function f(){e.isConnected?(o+=1,p()):d()}function p(){if(!a||!i)return;let t=At(i.style,i.steps,i.phrases,o);a.render(t),e.setAttribute(`aria-label`,t.label)}function m(){l!==null&&clearTimeout(l),l=null,u=!1,r.textContent=``}function h(e){!u&&l===null&&e&&(l=setTimeout(()=>{l=null,u=!0,r.textContent=e},i3))}function g(t){if(!t.active)i=null,e.hidden=!0,e.removeAttribute(`data-loading`),d(),m();else{if(!Object.hasOwn(r3,t.style))throw Error(`Unknown loader style. Use Steps, Phrases, Orb or Skeleton.`);if(!(t.intervalMs>0))throw Error(`Loader intervalMs must be a positive number.`);if(i={...t,steps:t.steps??[],phrases:t.phrases??[]},e.hidden=!1,e.setAttribute(`data-loading`,`true`),e.classList.toggle(`wui-chat-loader--reduced`,t.reduced===!0),!a||a.style!==t.style){let r=r3[t.style]();n.replaceChildren(r.el),a={style:t.style,render:r.render},e.dataset.style=t.style,o=0}h(t.announce),t.reduced===!0?(d(),o=0):(s===null||c!==t.intervalMs)&&(d(),c=t.intervalMs,s=setInterval(f,c)),p()}}function _(){d(),m(),a=null,i=null,e.remove()}return{el:e,update:g,destroy:_}}var o3=`data-wui-printing`,s3=`data-wui-print-hide`,c3=`data-wui-print-path`,l3=`data-wui-print-target`,u3=new Set([`script`,`style`,`link`,`template`]),d3=null;function f3(){if(d3!==null){for(let e of d3.marked)e.removeAttribute(s3),e.removeAttribute(c3),e.removeAttribute(l3);d3.heading.remove(),document.documentElement.removeAttribute(o3),window.removeEventListener(`afterprint`,d3.onAfterPrint),d3=null}}function p3(e,t,n,r,i){f3();let a=e.querySelector(`.wui-chat-panel`);if(a===null)throw Error(`print needs the wui-chat root`);let o=[];for(let e=a;e!==document.documentElement;e=e.parentElement){e.setAttribute(c3,``),o.push(e);for(let t of e.parentElement.children)t===e||u3.has(t.localName)||(t.setAttribute(s3,``),o.push(t))}for(let e of n)e.setAttribute(s3,``),o.push(e);r!==null&&(r.setAttribute(l3,``),o.push(r));let s=document.createElement(`div`);s.className=`wui-chat-print-heading`;let c=document.createElement(`h1`);c.textContent=i.title;let l=document.createElement(`p`);l.textContent=i.printedOn,s.append(c,l),a.prepend(s),document.documentElement.setAttribute(o3,t);let u=()=>f3();window.addEventListener(`afterprint`,u,{once:!0}),d3={marked:o,heading:s,onAfterPrint:u};try{window.print()}catch(e){throw f3(),e}}function m3(e,t){p3(e,`conversation`,[],null,t)}function h3(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);p3(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function g3(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function _3({title:e,text:t}){if(!g3())return`failed`;try{return await navigator.share({title:e,text:t}),`shared`}catch(e){return e?.name===`AbortError`?`cancelled`:`failed`}}var v3=new Set([`Assistant`,`Agent`,`Script`]),y3=new WeakMap;function b3(e,t,n){let{labels:r,features:i,title:a,busy:o}=n;if(it(t.parts)!==``){if(i.Share&&g3()){let n=y$(`ghost`,r.share,`share`,async()=>{let e=w3([t],i,r,a,!1);e!==``&&await _3({title:a,text:e})===`failed`&&O3(n.parentElement,r.shareFailed)});n.disabled=o===!0,e.append(n)}if(i.Print){let t=y$(`ghost`,r.print,`printer`,()=>{try{h3(t.closest(`.wui-chat`),t.closest(`li.wui-chat-message`),{title:a,printedOn:E3(r)})}catch{D3(t,r.printFailed)}});e.append(t)}}}function x3(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&v3.has(e.author.kind)&&it(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&g3(),o=!!i.Print;if(!a&&!o){e.hidden=!0;return}let s=[a,o,t.messages.length,r.shareConversation,r.printConversation].join(`|`);e.dataset.sig!==s&&(e.dataset.sig=s,e.replaceChildren(),a&&e.append(S3(e,r,i,n)),o&&e.append(C3(e,r,n))),e.hidden=!1}function S3(e,t,n,r){return y$(`ghost`,t.shareConversation,`share`,async()=>{let i=r.getState(),a=T3(i,r);await _3({title:a,text:w3(i.messages.filter(e=>e.stored),n,t,a,!0)})===`failed`&&O3(e,t.shareFailed)})}function C3(e,t,n){let r=y$(`ghost`,t.printConversation,`printer`,()=>{try{m3(e.closest(`.wui-chat`),{title:T3(n.getState(),n),printedOn:E3(t)})}catch{D3(r,t.printFailed)}});return r}function w3(e,t,n,r,i){return Cn(xn(e,{labels:n,title:r,figureText:t.FigureText}),{heading:i,speakers:i})}function T3(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function E3(e){return e.printedOn(rt(new Date().toISOString()))}function D3(e,t){let n=e.lastChild,r=y3.get(n);r?clearTimeout(r.timer):r={original:n.data},n.data=t,r.timer=setTimeout(()=>{n.data=r.original,y3.delete(n)},On),y3.set(n,r)}function O3(e,t){if(!e)return;let n=document.createElement(`span`);n.className=`wui-chat-action-notice`,n.setAttribute(`role`,`status`),n.textContent=t,e.append(n),setTimeout(()=>n.remove(),On)}function k3({voice:e,getLabels:t,message:n}){if(n.streaming||!e.canSpeak()||J2(n.parts)===``)return null;let r=e.getStatus(),i=r.mode===`Speaking`&&r.messageId===n.id,a=t(),o=i?a.readAloudStop:a.readAloud,s=$(`button`,`wui-chat-action-btn wui-chat-speak`,{type:`button`,"aria-pressed":String(i),"aria-label":o,title:o});return s.append(T2(i?`stop`:`speaker`,16)),s.addEventListener(`click`,()=>{e.toggleSpeak(n.id,n.parts)}),s}function A3({voice:e,getLabels:t,message:n}){let r=e.getStatus().note;if(r?.code!==`SpeakFailed`||r.messageId!==n.id)return null;let i=$(`span`,`wui-chat-action-notice`,{role:`status`});return i.textContent=Y2(r,t()),i}var j3=new Set([`Assistant`,`Agent`]),M3=new Set([`Assistant`,`Agent`,`Script`]),N3=new Set([`Visitor`,`Customer`]),P3=48,F3=120,I3={author:{kind:`Assistant`}},L3={warning:`alert-triangle`,danger:`alert-circle`};function R3(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=P3}function z3(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function B3(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function V3(e){let t=e.textContent.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.title=t)}function H3(e){return e.reduced===!0}function U3(e,t,n){let r=$(`button`,`${v$(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":e,title:e}),i=$(`span`);return i.textContent=e,r.append(_$(t,14),i),r.addEventListener(`click`,n),{node:r,text:i}}function W3(e,t){return e.profile?.assistant.name??t.panelTitle}function G3(e,t){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?t.you:e.author.kind===`Agent`?t.agent:t.assistant:e.author.displayName}function K3(e){let t=$(`ol`,`wui-chat-thread`),n=$(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});n.append(t);let r=a3(),i=$(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),a=$(`div`,`wui-chat-loader-slot`);a.append(r.el),i.append(a);let o=!1,s=null,c=$(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),l=$(`div`,`wui-chat-message-body`),u=$(`p`,`wui-chat-text`);l.append(u),c.append(l);let d=$(`li`,`wui-chat-conversation-actions`);d.hidden=!0;let f=$(`button`,`wui-chat-jump`,{type:`button`}),p=$(`div`,`wui-chat-jump-slot`);p.hidden=!0,p.append(f);let m=null,h=!0,g=null,_=null,v=new Map,y=``,b=null;function x(e,t,n){return n[e.kind]?{kind:e.kind,part:e,tag:n[e.kind]}:{kind:`Notice`,part:{kind:`Notice`,code:`NeedsNewerApp`,text:t.needsNewerApp},tag:n.Notice}}function S(t,n,r){let i=document.createElement(t);return i.message=r,i.turn=e.makeTurnApi(r.id),i.part=n,i}function C(e){return $(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function w(e,t,n,r,i){e.parts=[];let a=[],o=e=>{let i=x(e,n,r),a=C(i.kind);return a.append(S(i.tag,i.part,t)),a};for(let e of i(t))if(Array.isArray(e)){let t=$(`div`,`wui-chat-part-group`);t.append(...e.map(o)),a.push(t)}else a.push(o(e));e.body.replaceChildren(...a)}function T(t,n,r,i){let a=[];n.parts.forEach((o,s)=>{let c=x(o,r,i),l=t.parts[s];if(l&&l.kind===c.kind&&l.tag===c.tag){l.part!==c.part&&(l.element.message=n,l.element.turn=e.makeTurnApi(n.id),l.element.part=c.part,l.part=c.part),a.push(l);return}let u=C(c.kind),d=S(c.tag,c.part,n);u.append(d),a.push({kind:c.kind,tag:c.tag,part:c.part,element:d,wrapper:u})}),t.parts=a,E(t.body,a.map(e=>e.wrapper))}function E(e,t){let n=new Set(t);for(let t of[...e.children])n.has(t)||t.remove();t.forEach((t,n)=>{e.children[n]!==t&&e.insertBefore(t,e.children[n]??null)})}function D(e,t,n){let r=$(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${n.rateUp}/${n.rateDown}`});for(let[i,a,o]of[[`Up`,n.rateUp,`thumbs-up`],[`Down`,n.rateDown,`thumbs-down`]]){let s=t.rating===i,c=$(`button`,`${v$(s?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(s),"data-rating":i,"aria-label":a,title:a}),l=$(`span`);l.textContent=a,c.append(_$(o,14),l),c.addEventListener(`click`,()=>O(e,t,i,n)),r.append(c)}if(e.ratingNote){let t=$(`span`,null,{role:`status`});t.textContent=e.ratingNote,r.append(t)}return r}async function O(t,n,r,i){try{await e.onRate(n.id,r),t.ratingNote=i.rated}catch{t.ratingNote=i.ratingFailed}b&&ue(b.state,b.context)}function k(t,n,r,i,a){let{labels:o}=i,s=r.features,c=n.author.kind,l=it(n.parts),u=[];if(s.Copy&&M3.has(c)&&l){let e=U3(o.copy,`copy`,async()=>{await kn(l)&&(e.text.textContent=o.copied,e.node.dataset.done=``,e.node.setAttribute(`aria-label`,o.copied),e.node.title=o.copied,clearTimeout(t.copyTimer),t.copyTimer=setTimeout(()=>{e.text.textContent=o.copy,delete e.node.dataset.done,e.node.setAttribute(`aria-label`,o.copy),e.node.title=o.copy},On))});u.push(e.node)}let d=e.getVoice?.();if(d&&M3.has(c)){let e=k3({voice:d,getLabels:()=>o,message:n});e&&u.push(e);let t=A3({voice:d,getLabels:()=>o,message:n});t&&u.push(t)}if(M3.has(c)){let e=$(`div`);b3(e,n,{labels:o,features:s,title:W3(r,o),busy:r.streaming||r.thinking});for(let t of e.childNodes)V3(t);u.push(...e.childNodes)}let f=r.messages.some(e=>e.author.kind===`Visitor`&&e.stored);a&&c===`Assistant`&&!r.streaming&&!r.thinking&&s.Regenerate&&f&&u.push(U3(o.regenerate,`refresh`,()=>e.onRegenerate()).node);let p=r.messages.findLast(e=>e.author.kind===`Visitor`&&e.stored);s.Edit&&p?.id===n.id&&!r.streaming&&!r.thinking&&u.push(U3(o.edit,`pencil`,()=>e.getSession().startEdit(n.id)).node),s.Rating&&n.stored&&j3.has(c)&&u.push(D(t,n,o)),t.actions.hidden=u.length===0,t.actions.replaceChildren(...u)}function A(e){let t=v.get(e.id);if(t)return t;let n=$(`li`,`wui-chat-message`),r=$(`span`,`wui-chat-author visually-hidden`),i=$(`div`,`wui-chat-message-body`),a=$(`div`,`wui-chat-message-actions`);n.append(r,i,a);let o={li:n,author:r,body:i,actions:a,head:null,parts:[],copyTimer:null,ratingNote:null};return v.set(e.id,o),o}function j(e,t,n,r){let i=n?.author.kind===`Agent`&&t.author.kind===`Agent`&&(n.author.displayName??``)===(t.author.displayName??``);e.head?.remove(),e.head=t.author.kind===`Agent`&&!i?L$(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ee(t,n,r,i,a,o){let{labels:s}=i;t.li.className=`wui-chat-message wui-chat-message--${n.author.kind.toLowerCase()}`,t.li.toggleAttribute(`data-restored`,n.restored===!0),t.li.toggleAttribute(`data-run-start`,!o||z3(o)!==z3(n)),n.streaming?t.li.setAttribute(`aria-busy`,`true`):t.li.removeAttribute(`aria-busy`),t.author.textContent=`${G3(n,s)}: `,j(t,n,o,s);let c=e.getRenderers(),l=e.getLayoutParts();typeof l==`function`?w(t,n,s,c,l):T(t,n,s,c),n.streaming?(t.actions.hidden=!0,t.actions.replaceChildren()):k(t,n,r,i,a)}function te(e,t){let n=$(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),r=$(`div`,`wui-chat-notice wui-chat-notice--${e}`,{role:e===`danger`?`alert`:`status`}),i=$(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});i.append(_$(L3[e],16));let a=$(`div`,`wui-chat-notice-body`),o=$(`span`,`wui-chat-notice-text`);return o.textContent=t,a.append(o),r.append(i,a),n.append(r),n}function ne(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(E4(e.resetsDateTimeUtc))}`:``;return te(`warning`,`${e.message}${n}`)}function re(t,n){let{labels:r}=n,i=t.turnError?.code??``;if(i===`daily_limit`)return ne(t.turnError,r);if(i.endsWith(`feature_off`))return te(`danger`,t.turnError.message||r.stopped);let a=$(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),o=$(`p`,`wui-chat-error`,{role:`alert`});o.textContent=t.turnError?.message||r.stopped;let s=_$(`alert-circle`,16);if(s.setAttribute(`aria-hidden`,`true`),a.append(s,o),t.features.Retry){let t=$(`div`,`wui-chat-message-actions`);t.append(U3(r.retry,`rotate-ccw`,()=>e.onRetry()).node),a.append(t)}return a}function ie(){return t.closest(`.wui-chat`)}function ae(){return t.closest(`.wui-chat-body`)??B3(t)}function oe(e){ie()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),R3(e)&&(p.hidden=!0)}function se(){h=R3(m),oe(m)}function ce(e){n.nextElementSibling!==p&&n.parentNode&&n.after(p),e!==m&&(m?.removeEventListener(`scroll`,se),m=e,e.addEventListener(`scroll`,se,{passive:!0}),!g&&typeof ResizeObserver==`function`&&(g=new ResizeObserver(()=>{h&&m&&(m.scrollTop=m.scrollHeight)}),g.observe(t)))}f.addEventListener(`click`,()=>{let e=ae(),t=b?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),p.hidden=!0,f.blur()});function le(e,t){let n=e.messages.at(-1),r=n?`${n.id}|${it(n.parts).length}`:``;if(r===y)return;let i=y===``||e.conversationId!==_;y=r,_=e.conversationId;let a=ae();a&&(ce(a),i||t||N3.has(n?.author.kind)?(a.scrollTop=a.scrollHeight,p.hidden=!0,h=!0):(p.hidden=!1,h=!1),oe(a))}function ue(a,l){b={state:a,context:l};let{labels:p}=l;n.setAttribute(`aria-label`,p.thread),f.textContent=p.newMessages??`New messages`;let m=ae();m&&ce(m);let h=m===null||m.clientHeight===0||R3(m),g=[],_=new Set,y=a.messages.filter(e=>!(e.streaming&&e.parts.length===0)),x=y.length>0&&N3.has(y[0].author.kind)&&a.greeting?a.greeting:null;x&&(u.textContent=x,g.push(c)),y.forEach((e,t)=>{let n=A(e);_.add(e.id);let r=y[t-1]??(x?I3:null);ee(n,e,a,l,t===y.length-1,r),g.push(n.li)});for(let e of[...v.keys()])_.has(e)||v.delete(e);a.agentTyping&&g.push(R$(a.agentTyping,p)),a.thinking?(clearTimeout(s),s=null,i.classList.remove(`wui-chat-message--leaving`),o=!0,r.update({active:!0,style:l.loaderStyle,steps:a.steps,phrases:l.phrases,intervalMs:l.intervalMs,reduced:l.reduced,announce:l.assistantName?.trim()?p.preparingAnswer(l.assistantName):void 0}),g.push(i)):o&&s===null&&!H3(l)?(i.classList.add(`wui-chat-message--leaving`),s=setTimeout(()=>{s=null,o=!1,i.classList.remove(`wui-chat-message--leaving`),r.update({active:!1}),b&&ue(b.state,b.context)},F3),g.push(i)):s===null?(o=!1,r.update({active:!1})):g.push(i),!a.streaming&&(a.turnError||a.stopped)&&g.push(re(a,l)),x3(d,a,{labels:p,features:a.features,title:W3(a,p),getState:()=>e.getSession().getState()}),g.push(d),E(t,g),le(a,h)}function de(e){return v.get(e)?.li??null}function fe(){clearTimeout(s),r.destroy(),m?.removeEventListener(`scroll`,se),g?.disconnect(),v.clear(),b=null,n.remove()}return{el:n,paint:ue,find:de,destroy:fe}}var q3=`wchat:auto-opened`,J3=`wchat:dismissed`,Y3=`button, a[href], input, select, textarea`,X3=`input, textarea`;function Z3(e){return!e.closest(`.wui-chat`)}function Q3(e){return e instanceof Element&&e.matches(X3)&&Z3(e)}function $3(){return[...document.querySelectorAll(X3)].some(e=>Z3(e)&&e.value!==e.defaultValue)}function e6(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function t6(e){return e?[...document.querySelectorAll(Y3)].some(t=>{if(!Z3(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 n6(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(q3)||e.rememberDismissal&&sessionStorage.getItem(J3)||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&&$3()||n.isOpen()?!0:e.skipWhenCoversControl&&t6(n.panelRect())}function r6(e){return Q3(document.activeElement)||e6(e.avoid.menuSelectors)||e6(e.avoid.autoOpenBusySelectors)}function i6(e,t,n){let r=0;function i(){r=0,n6(e,t,n)||(r6(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(q3,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=0}}}var a6=.4,o6=20;function s6(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function c6(e){let t=e.match(/[\d.]+/g);if(!t||t.length<3)return null;let[n,r,i]=t.slice(0,3).map(Number);return{r:n,g:r,b:i,alpha:t.length>3?Number(t[3])/(e.includes(`%`)?100:1):1}}function l6({r:e,g:t,b:n}){return .2126*s6(e)+.7152*s6(t)+.0722*s6(n)}function u6(e,t){let n=e.getBoundingClientRect(),r=document.elementsFromPoint?.(n.left+n.width/2,n.top+n.height/2)??[],i=t.length?t.join(`,`):null;for(let t of r){if(e.contains(t))continue;if(i&&t.closest(i))return!0;let n=c6(getComputedStyle(t).backgroundColor);if(n&&n.alpha>0)return l6(n)<a6}return!1}function d6(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function f6(e){let t=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&(t=Math.max(t,window.innerHeight-e.top))}return t>0?t+o6:0}function p6(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 m6(e,t,n){let r=n.ownerDocument.documentElement,i=0,a=!1,o=null;function s(){i=0;let s=t.liftAboveFooter?d6(e.liftSelectors):[];if(o)for(let e of s)o.observe(e);n.style.setProperty(`--wui-chat-lift`,`${f6(s)}px`);let c=n.getBoundingClientRect(),l=c.height===0?0:Math.round(window.innerHeight-c.top);r.style.setProperty(`--wui-chat-launcher-block`,`${l}px`);let u=t.stepAsideForMenus&&p6(e.menuSelectors);u&&!a?(n.dataset.launcher=`hidden`,n.inert=!0,a=!0):!u&&a&&(n.dataset.launcher=`idle`,n.inert=!1,a=!1);let d=t.switchOnDark&&u6(n,e.darkSelectors);d&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!d&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function c(){i||=requestAnimationFrame(s)}typeof ResizeObserver==`function`&&(o=new ResizeObserver(c));let l=new MutationObserver(c);return l.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,c,{capture:!0,passive:!0}),window.addEventListener(`resize`,c),window.addEventListener(`load`,c),n.addEventListener(`animationend`,c),c(),{destroy(){i&&cancelAnimationFrame(i),i=0,o?.disconnect(),l.disconnect(),document.removeEventListener(`scroll`,c,{capture:!0}),window.removeEventListener(`resize`,c),window.removeEventListener(`load`,c),n.removeEventListener(`animationend`,c),a&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),r.style.removeProperty(`--wui-chat-launcher-block`)}}}var h6=`wchat:session-start`,g6=`wchat:pages`,_6=`wchat:services`;function v6(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function y6(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function b6(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function x6(e){sessionStorage.getItem(h6)||sessionStorage.setItem(h6,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=v6(g6);i.includes(r)||(i.push(r),y6(g6,i));let a=b6(r,e),o=v6(_6);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),y6(_6,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(h6)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var S6=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function C6(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(S6)].filter(e=>e.tabIndex>=0&&!e.hidden);if(n.length===0){t.preventDefault();return}let r=n[0],i=n[n.length-1],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 w6(e){e?.isConnected&&e.focus()}function T6(e,t){t||typeof navigator>`u`||typeof navigator.vibrate!=`function`||navigator.vibrate(e)}var E6=`wui-chat-lock`,D6=`wui-chat-scroll-lock`;function O6(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(E6);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(D6,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(E6);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(D6,{detail:{locked:!1}}))}}}var k6={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}},A6=[`pointerdown`,`keydown`,`touchstart`],j6=`wchat:muted`,M6=1e-4;function N6(e,t){let n=t.get(j6)===`1`,r=null;function i(){for(let e of A6)document.removeEventListener(e,a)}function a(){let e=globalThis.AudioContext||globalThis.webkitAudioContext;!r&&e&&(r=new e),r?.state===`suspended`&&r.resume(),i()}for(let e of A6)document.addEventListener(e,a);return{play(t){let i=k6[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(M6,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(j6,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close(),r=null}}}var P6=2e3,F6=500,I6=32,L6=16,R6=`data-wui-chat-switching`;function z6(e){return new Promise(t=>setTimeout(t,e))}function B6(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=L6,setTimeout(i,L6))};setTimeout(i,L6)})}async function V6(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(R6,``);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 B6(t.routeReady,P6),await B6(r,F6),await z6(I6)});i.ready.catch(()=>{});try{await i.updateCallbackDone}finally{await i.finished.catch(()=>{})}}finally{r.removeAttribute(R6)}}var H6=100,U6=12,W6=220,G6=640;function K6(e,t){let n=t.phone.mode===`Sheet`,r=window.visualViewport,i=0;function a(){e.style.removeProperty(`bottom`),e.style.removeProperty(`max-height`)}function o(){if(i=0,window.innerWidth>t.phone.maxWidthPx){a();return}if(!r)return;let o=Math.max(0,window.innerHeight-r.height-r.offsetTop),s=r.height-U6;n&&(s=Math.min(G6,Math.max(W6,s))),e.style.bottom=`${o}px`,e.style.maxHeight=`${s}px`}function s(){clearTimeout(i),i=setTimeout(o,H6)}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()}}}var q6=typeof HTMLElement>`u`?class{}:HTMLElement;function J6(e,t){if(e.conversationState===`WaitingForAgent`)return t.statusWaitingForAgent;if(e.conversationState===`WithAgent`){let n=e.agent?.displayName;return t.statusWithAgent(typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback)}return t.headerStatus}function Y6(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function X6(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}var Z6=[`launcher`,`docked`,`full-page`,`embedded`],Q6=[`end`,`start`],$6={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},e8={on:`On`,reduced:`Reduced`},t8=[`auto`,`light`,`dark`],n8=`wchat:muted`,r8=6e4,i8=400,a8=[`labels`,`pageContext`,`compact`,`open`,`layoutParts`,`getCaptchaToken`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],o8={...A2};function s8(e,t){if(!w$.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${w$.join(`, `)}.`);if(typeof t!=`string`||!t.includes(`-`))throw Error(`Renderer tag "${t}" must be a custom element name containing a hyphen.`)}function c8(e,t){s8(e,t),o8[e]=t}function l8(e,t){return n=>{let r=n.toLowerCase();if(!Object.hasOwn(t,r))throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return t[r]}}function u8(e){return t=>{let n=Number(t);if(!Number.isInteger(n)||n<0)throw Error(`<wui-chat ${e}> must be a whole number of pixels, got "${t}".`);return n}}function d8(e){return t=>{if(t===``||t===`true`)return!0;if(t===`false`)return!1;throw Error(`<wui-chat ${e}> must be true or false, got "${t}".`)}}var f8=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),p8=[[`launcher-style`,`launcher`,`style`,l8(`launcher-style`,{round:`Round`,pill:`Pill`})],[`entrance`,`launcher`,`entrance`,l8(`entrance`,{"slide-up":`SlideUp`,"bounce-in":`BounceIn`,"fade-in-pulse":`FadeInPulse`,"spin-scale":`SpinScale`,"wiggle-in":`WiggleIn`,"elastic-in":`ElasticIn`,rise:`Rise`,none:`None`})],[`idle`,`launcher`,`idle`,l8(`idle`,{"float-and-pulse":`FloatAndPulse`,ring:`Ring`,none:`None`})],[`label-reveal`,`launcher`,`labelReveal`,l8(`label-reveal`,{bubble:`Bubble`,expand:`Expand`})],[`compact`,`launcher`,`compact`,d8(`compact`)],[`launcher-mark`,`launcher`,`mark`,l8(`launcher-mark`,{icon:`Icon`,avatar:`Avatar`})],[`panel-height`,`panel`,`height`,l8(`panel-height`,{fixed:`Fixed`,content:`Content`})],[`reply-avatars`,`panel`,`replyAvatars`,d8(`reply-avatars`)],[`panel-motion`,`panel`,`motion`,l8(`panel-motion`,{spring:`Spring`,gentle:`Gentle`,none:`None`})],[`panel-width`,`panel`,`widthPx`,u8(`panel-width`)],[`panel-max-height`,`panel`,`maxHeightPx`,u8(`panel-max-height`)],[`panel-bottom-gap`,`panel`,`bottomGapPx`,u8(`panel-bottom-gap`)],[`phone-max-width`,`phone`,`maxWidthPx`,u8(`phone-max-width`)],[`phone-mode`,`phone`,`mode`,l8(`phone-mode`,{"full-screen":`FullScreen`,sheet:`Sheet`})],[`sheet-height-dvh`,`phone`,`sheetHeightDvh`,u8(`sheet-height-dvh`)],[`sheet-max-height`,`phone`,`sheetMaxHeightPx`,u8(`sheet-max-height`)],[`input-ring`,`input`,`ring`,d8(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,l8(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`send-icon`,`input`,`sendIcon`,e=>e],[`lift-selectors`,`avoid`,`liftSelectors`,f8],[`menu-selectors`,`avoid`,`menuSelectors`,f8],[`dark-selectors`,`avoid`,`darkSelectors`,f8],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,f8],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],m8={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},h8=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`avatar`,`narrow`,...p8.map(([e])=>e).filter(e=>e!==`compact`)],g8=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function _8(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of p8){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`),r=e.getAttribute(`avatar`);return xt({...t,motion:n==null?void 0:l8(`motion`,e8)(n),avatar:r||void 0})}function v8(e){let t=e.getAttribute(`loader`)??`steps`;if(!Object.hasOwn($6,t))throw Error(`<wui-chat loader> must be one of ${Object.keys($6).join(`, `)}, got "${t}".`);return $6[t]}function y8(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries(f8(t).map(e=>[e,!1]))}function b8(e){return e===n8?globalThis.localStorage:globalThis.sessionStorage}var x8={get:e=>b8(e).getItem(e),set:(e,t)=>b8(e).setItem(e,t)};function S8(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function C8(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}var w8=0,T8=class extends q6{static get observedAttributes(){return[...h8,`compact`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),w8+=1,this._uid=`wui-chat-${w8}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._shell=null,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...o8},this._rendererApi={define:(e,t)=>{s8(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=null,this._openAttachmentProp=null,this._openCitationProp=null,this._openTargetProp=null,this._resolveLinkProp=null,this._openTicketProp=void 0,this._emptyContentProp=null,this._onPanelSwitchProp=null,this._preloadPanelSwitchProp=null,this._preloaded=!1,this._pastList=null,this._past=null,this._pastRefreshed=!1,this._historyShown=!1,this._openedConversation=null,this._lastOpen=!1,this._openTrigger=`manual`,this._focusTimer=null,this._nudgeArmed=!1,this._seeded=!1,this._wasLoading=!1,this._seen=new Set,this._sound=null,this._behaviour=null,this._autoOpen=null,this._avoid=null,this._motion=null,this._phone=null,this._requesting=!1,this._onKeyDown=e=>{e.key===`Escape`&&this._session?.getState().open&&(e.stopPropagation(),this._session.close(`escape`))}}get session(){return this._session??null}get conversationId(){return this._session?.getState().conversationId??null}get labels(){return s({...x$(this,`labels`),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?x$(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){return this.hasAttribute(`compact`)}set compact(e){this.toggleAttribute(`compact`,e===!0||e===``||e===`true`)}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,e===!0||e===``||e===`true`)}get renderers(){return this._rendererApi}get layoutParts(){return this._layoutParts}set layoutParts(e){this._layoutParts=typeof e==`function`?e:null,this._render()}get getCaptchaToken(){return this._captchaToken}set getCaptchaToken(e){this._captchaToken=typeof e==`function`?e:null}get openAttachment(){return this._openAttachmentProp??(e=>this._defaultOpenAttachment(e))}set openAttachment(e){this._openAttachmentProp=typeof e==`function`?e:null}get openCitation(){return this._openCitationProp??((e,t)=>this._defaultOpenCitation(e,t))}set openCitation(e){this._openCitationProp=typeof e==`function`?e:null}get openTarget(){return this._openTargetProp??(e=>this._defaultOpenTarget(e))}set openTarget(e){this._openTargetProp=typeof e==`function`?e:null}get openTicket(){return this._openTicketProp}set openTicket(e){this._openTicketProp=typeof e==`function`?e:void 0}get onNavigate(){return this._onNavigateProp}set onNavigate(e){this._onNavigateProp=typeof e==`function`?e:void 0}get resolveLink(){return this._resolveLinkProp}set resolveLink(e){this._resolveLinkProp=typeof e==`function`?e:null}get emptyContent(){return this._emptyContentProp}set emptyContent(e){if(e!==null&&!(e instanceof Node))throw TypeError(`emptyContent must be a Node or null`);this._emptyContentProp=e,this._applyEmptyContent()}get onPanelSwitch(){return this._onPanelSwitchProp}set onPanelSwitch(e){this._onPanelSwitchProp=typeof e==`function`?e:null}get preloadPanelSwitch(){return this._preloadPanelSwitchProp}set preloadPanelSwitch(e){this._preloadPanelSwitchProp=typeof e==`function`?e:null}connectedCallback(){if(this._adoptEarlyProperties(),this._assertLayout(),this._assertPosition(),this.base.trim()===``)throw TypeError(`<wui-chat> needs a base path, e.g. base="/api/assistant".`);this._built||this._build(),this._shell||this._buildShell(),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this._session.subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of a8){if(!Object.hasOwn(this,e))continue;let t=this[e];delete this[e],this[e]=t}}disconnectedCallback(){this._voice?.stop(),this._session?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._disposePast(),this._shell?.destroy?.(),document.removeEventListener(`keydown`,this._onKeyDown),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._motion?.destroy(),this._motion=null}attributeChangedCallback(e,t,n){if(this._built&&t!==n){if(e===`layout`)this._assertLayout(),this._buildShell();else if(e===`position`)this._assertPosition();else if(e===`base`||e===`screen`||e===`narrow`)this._resetSession();else if(e===`motion`)this._motion?.destroy(),this._motion=null;else if(e===`open`&&this._session){let e=this._session.getState().open;this.open!==e&&this._setOpen(this.open,`manual`)}this._render()}}toggle(){this._session&&(this._session.getState().open?this._session.close(`button`):this._setOpen(!0,`manual`))}close(){this._voice?.stop(),this._session?.close(`button`)}newConversation(){this._voice?.stop(),this._session?.newConversation(),this._past?.refresh()}reset(){this._voice?.stop(),this._session?.reset()}_setOpen(e,t){this._session&&(e?(this._openTrigger=t,this._session.open({trigger:t})):this._session.close(`button`))}_assertLayout(){let e=this.layout;if(!Z6.includes(e))throw Error(`<wui-chat layout> must be one of ${Z6.join(`, `)}, got "${e}".`)}_assertPosition(){let e=this.position;if(!Q6.includes(e))throw Error(`<wui-chat position> must be one of ${Q6.join(`, `)}, got "${e}".`)}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}_build(){this._built=!0,this._header=d4({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>this._session?.setMuted(!this._session.getState().muted),onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=q4({onStarter:e=>this._session.submit(e.message),onResume:()=>this._session.resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=X2({getState:()=>this._session.getState(),getLabels:()=>this.labels,getToken:()=>this._session.client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=K3({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this._session.retry(),onRegenerate:()=>this._session.regenerate(),onRate:(e,t)=>this._session.rate(e,t),getSession:()=>this._session,getVoice:()=>this._voice}),this._composer=i4({voice:this._voice,onSubmit:e=>this._session.submit(e),onStop:()=>this._session.stop(),onAttach:e=>this._session.attach(e),onRemove:e=>this._session.removeAttachment(e),onCancelEdit:()=>this._session.cancelEdit(),onTyping:()=>this._session.notifyTyping(),onDraftApplied:()=>this._session.consumeDraft()}),this._footer=l4(),this._history=m4({getClient:()=>this._session.client,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{}),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this._session.newConversation()}}),this._nudge=b4({onActivate:()=>this._setOpen(!0,`manual`),onDismiss:()=>{}}),this._status=$(`p`,null,{role:`status`}),this._status.hidden=!0,this._errorEl=$(`p`,`wui-chat-profile-error`,{role:`alert`}),this._errorEl.hidden=!0,this._liveStatus=$(`p`,`wui-chat-live-status`,{role:`status`}),this._liveStatus.hidden=!0,this._talk=$(`button`,`${v$(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=$(`button`,v$(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this._session.resumeLive()),this._liveError=$(`p`,`wui-chat-live-error`,{role:`alert`}),this._liveError.hidden=!0,this._live=$(`div`,`wui-chat-live`),this._live.append(this._liveStatus,this._talk,this._liveRetry,this._liveError),this._live.hidden=!0,this._body=$(`div`,`wui-chat-body`),this._body.append(this._starters.el,this._thread.el,this._live,this._history.el,this._status,this._errorEl),this._foot=$(`div`,`wui-chat-foot`),this._foot.append(...this._composer.nodes,this._footer.el)}_buildShell(){let e={launcher:U4,docked:R4,"full-page":W4,embedded:z4};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let t=e[this.layout]({id:`${this._uid}-panel`,position:this.position,onToggle:()=>this.toggle()});t.panel.append(this._header.el,this._body,this._foot),t.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),t.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&C6(t.panel,e)}),t.nudgeHost&&t.nudgeHost.prepend(this._nudge.el),this._shell=t,this.replaceChildren(t.root)}_createSession(){let e=E(y4(),{base:this.base}),t=y8(this);this._session=on(e,{screen:this.screen||void 0,narrow:t,pageContext:()=>this.pageContext,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:x8,reducedMotion:()=>this._motion?.reduced??!1,schedule:C8,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?j4(t,e):Promise.resolve(null)},onEvent:(e,t)=>{this.dispatchEvent(new CustomEvent(`wui-chat-event`,{bubbles:!0,detail:{name:e,data:t}}))},onError:()=>{},labels:this.labels}),this._unsubscribe=null,this._lastOpen=!1,this._openApplied=!1,this._seeded=!1,this._wasLoading=!1,this._seen=new Set,this._pastRefreshed=!1}_createPast(){this._pastList=k({client:this._session.client,pageSize:20}),this._past=D4({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{})}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this._pastList.dispose(),this._past=null,this._pastList=null)}_applyEmptyContent(){if(!this._starters)return;let e=this._starters.extraHost;e.replaceChildren(...this._emptyContentProp?[this._emptyContentProp]:[]),e.hidden=!this._emptyContentProp}_switchPanel(){let e=this._session.getState(),t=X6(this.layout,e.features,this._onPanelSwitchProp);if(t===null)return;t===`full-page`&&this.close();let n={from:this.layout,to:t,conversationId:e.conversationId,draft:this._composer.getDraft()};V6(()=>this._onPanelSwitchProp(n),{target:t,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${t} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this._session.requestHandoff()}catch(e){this._liveError.textContent=e?.message||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Y6(e);this._liveStatus.hidden=!r,this._liveStatus.textContent=r?t.liveLost:``,this._liveRetry.hidden=!r,this._liveRetry.textContent=t.retry,this._talk.hidden=!i,this._talk.textContent=t.talkToPerson,this._talk.disabled=this._requesting,this._live.hidden=n||!r&&!i}_resetSession(){this._voice?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._session?.dispose(),this._session=null,this._disposePast(),this._history.dispose(),this.isConnected&&(this._createSession(),this._createPast(),this._unsubscribe=this._session.subscribe(()=>this._render()))}_toggleHistory(e=!this._historyShown){this._historyShown=e,e?this._history.show():this._history.hide(),this._render()}_makeTurnApi(e){let t=cn(this._session,{messageId:e,labels:this.labels,openAttachment:e=>this.openAttachment(e),openCitation:t=>this.openCitation(e,t),openTarget:e=>this.openTarget(e),openTicket:this.openTicket,onNavigate:this.onNavigate});return t.resolveLink=this.resolveLink,t}_defaultOpenAttachment(e){this._session.client.getAttachment(e.attachmentId).then(t=>{let n=URL.createObjectURL(new Blob([t],{type:e.contentType}));window.open(n,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(n),r8)}).catch(e=>globalThis.reportError?.(e))}_defaultOpenCitation(e,t){let n=this._thread.find(e);if(n){for(let e of n.querySelectorAll(`[data-marker]`))if(e.dataset.marker===String(t)){e.focus();return}}}_defaultOpenTarget(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}_render(){this._built&&this._session&&this._paint(this._session.getState())}_paint(e){e.conversationId!==this._voiceConversationId&&(this._voiceConversationId=e.conversationId,this._voice.stop());let t=this.labels,n=e.profile,r=this._isLauncherLike();if(!n){this.hidden=r,this._header.el.hidden=!0,this._starters.el.hidden=!0,this._thread.el.hidden=!0,this._history.el.hidden=!0,this._foot.hidden=!0,this._errorEl.hidden=e.profileError==null,e.profileError&&(this._errorEl.textContent=e.profileError.message),this._status.hidden=e.profileError!=null,this._status.textContent=t.loadingConversation,this._shell.panel.setAttribute(`aria-busy`,String(e.profileError==null));return}if(this._shell.panel.removeAttribute(`aria-busy`),!e.features.VisitorChat){this.hidden=!0,this._status.hidden=!0;return}this.hidden=!1;let i=e.features,a=_8(this);this._ensureRuntime(e,n,a,t);let o=e.loading,s=e.loadError,c=e.messages.length===0&&!o,l=this._historyShown&&i.History===!0,u=e.messages.some(e=>e.author.kind===`Visitor`),d=X6(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:J6(e,t),canNew:!f,showNew:this.layout===`full-page`||u,showHistory:i.History,showClose:r||this.layout===`full-page`&&d!==null,switchTo:d,canSwitch:!f,viewingHistory:l,showMute:i.Sounds&&n.experience.sound.muteControl,muted:e.muted}),this._starters.el.hidden=!c||l,c&&this._starters.paint({labels:t,greeting:e.greeting,starters:e.starters,showStarters:i.Starters&&!e.streaming,resume:!i.History&&i.ResumeLast?e.lastConversation:null,openTickets:e.openTickets,features:e.features,ticketsClickable:typeof this.openTicket==`function`}),i.History&&!this._pastRefreshed&&(this._pastRefreshed=!0,this._past?.refresh()),this._past?.paint();let p=!c&&!o&&!s&&!l;this._thread.el.hidden=!p,p&&this._thread.paint(e,{labels:t,loaderStyle:v8(this),reduced:this._motion?.reduced??!1,phrases:n.experience.pacing.thinkingPhrases,intervalMs:n.experience.pacing.phraseIntervalMs,assistantName:n.assistant.name}),this._paintLive(e,t,l),this._status.hidden=!o||l,this._status.textContent=t.loadingConversation,this._errorEl.hidden=!s||l,s&&(this._errorEl.textContent=s.message),this._foot.hidden=l,this._composer.paint({state:e,labels:t,maxLength:n.limits.maxMessageLength,accept:n.limits.contentTypes.join(`,`),draft:e.draft??null,sendIcon:a.input.sendIcon}),this._footer.paint({labels:t,profile:n}),this._history.el.hidden=!l,this._syncOpen(e,n,i,t,r),this._syncConversation(e),this._playSounds(e)}_ensureRuntime(e,t,n,r){let i=e.features;this._motion||(this._motion=m$(n,t.experience),this._motion.subscribe(()=>this._render())),i.Sounds&&!this._sound&&(this._sound=N6(t.experience.sound,x8)),!i.Sounds&&this._sound&&(this._sound=null),i.BehaviourStarters&&!this._behaviour&&(this._behaviour=x6(t.start.behaviour?.servicePathPrefixes??[]));let a=this._isLauncherLike();a&&!this._avoid&&this.layout===`launcher`&&(this._avoid=m6(n.avoid,t.experience.launcher,this._shell.nudgeHost)),this.layout===`launcher`&&i.AutoOpen&&!this._autoOpen&&(this._autoOpen=i6(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this._session.getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let o=S8(n);this._shell.setLabels(r),this._shell.setAppearance({position:this.position,offsetX:this.hasAttribute(`offset-x`)?u8(`offset-x`)(this.getAttribute(`offset-x`)):void 0,offsetY:this.hasAttribute(`offset-y`)?u8(`offset-y`)(this.getAttribute(`offset-y`)):void 0,width:`${n.panel.widthPx}px`,maxHeight:n.panel.maxHeightPx,bottomGap:n.panel.bottomGapPx,reduced:this._motion.reduced,sendReveal:n.input.sendReveal,inputRing:n.input.ring,panelMotion:n.panel.motion,theme:t8.includes(this.getAttribute(`theme`))?this.getAttribute(`theme`):`auto`,icon:this.icon,launcherStyle:n.launcher.style,compact:n.launcher.compact,labelReveal:n.launcher.labelReveal,entrance:n.launcher.entrance,idle:n.launcher.idle,launcherMark:n.launcher.mark,panelHeight:n.panel.height,replyAvatars:n.panel.replyAvatars,avatar:n.avatar,phone:o,hoverLabel:t.experience.launcher.hoverLabel,peek:t.experience.launcher.peek,peekSeconds:t.experience.launcher.peekSeconds,hideWhileOpen:t.experience.launcher.hideWhileOpen,phoneMode:n.phone.mode,sheetHeightDvh:n.phone.sheetHeightDvh,sheetMaxHeightPx:n.phone.sheetMaxHeightPx,launcherState:this._launcherPlayed?void 0:`entering`}),this._launcherPlayed=!0,this._shell.root.classList.toggle(`wui-chat--phone`,a&&S8(n))}_syncOpen(e,t,n,r,i){if(i){if(!this._openApplied&&(this._openApplied=!0,this.hasAttribute(`open`)&&!e.open))this._setOpen(!0,`manual`);else if(this._shell.setOpen(e.open),this.toggleAttribute(`open`,e.open),e.open!==this._lastOpen&&(this._lastOpen=e.open,this._onOpenChange(e.open)),e.open)this._nudge.cancel(),this._nudgeArmed=!1,this._autoOpen?.cancel();else if(n.Nudges&&this.layout===`launcher`&&!this._nudgeArmed){let e=Ot(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=S8(_8(this));if(e){if(document.addEventListener(`keydown`,this._onKeyDown),this._sound?.play(`open`),this._past?.refresh(),this.layout===`docked`&&!this._preloaded&&typeof this._preloadPanelSwitchProp==`function`){this._preloaded=!0;try{this._preloadPanelSwitchProp()?.catch?.(()=>{})}catch{}}if(t){let e=_8(this);this._phone={fit:K6(this._shell.panel,e),unlock:O6(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},i8))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),w6(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&this._session.openConversation(t).catch(()=>{}))}_playSounds(e){if(e.loading){this._wasLoading=!0;for(let t of e.messages)this._seen.add(t.id)}else if(this._wasLoading||!this._seeded){this._wasLoading=!1,this._seeded=!0;for(let t of e.messages)this._seen.add(t.id)}else for(let t of e.messages)this._seen.has(t.id)||(this._seen.add(t.id),this._announce(t))}_announce(e){if(!this._sound||e.restored||e.parts.some(e=>e.kind===`Notice`))return;let t=e.author.kind;if(t===`Visitor`)e.stored||this._sound.play(`sent`);else if(t===`Assistant`||t===`Script`||t===`Agent`){this._sound.play(`reply`);let e=this._session.getState().profile;e?.experience.sound.vibrate&&T6(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty(T8.prototype,"layout",{get(){return this.getAttribute(`layout`)??m8.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of h8)e!==`layout`&&Object.defineProperty(T8.prototype,g8(e),{configurable:!0,get(){return this.getAttribute(e)??m8[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function E8(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,T8)}E8(),E8(),globalThis.WeborityChat=Object.assign(globalThis.WeborityChat||{},{session:e=>e.session,renderers:{define:c8}})})();
|
|
44
|
+
`),language:i});continue}if(b0(t,r)){let i=y0(e),a=[];for(r+=2;r<t.length&&t[r].trim()&&v0(t[r]);)a.push(y0(t[r])),r+=1;n.push({type:`table`,header:i,rows:a});continue}if(p0.test(e)){n.push({type:`rule`}),r+=1;continue}let i=f0.exec(e);if(i){n.push({type:`heading`,level:i[1].length,text:i[2]}),r+=1;continue}if(g0.test(e)){let e=[];for(;r<t.length;){let n=g0.exec(t[r]);if(!n)break;e.push(n[1]),r+=1}n.push({type:`quote`,lines:e});continue}let a=C0(e);if(a){let e=[];for(;r<t.length&&t[r].trim();){let n=C0(t[r]);if(n){if(n.depth===0&&n.ordered!==a.ordered)break;e.push(n)}else if(x0(t,r))break;else e[e.length-1].text+=` ${t[r].trim()}`;r+=1}n.push({type:`list`,ordered:a.ordered,start:a.ordered?a.number:1,items:e});continue}let o=[e];for(r+=1;r<t.length&&t[r].trim()&&!x0(t,r);)o.push(t[r]),r+=1;n.push({type:`paragraph`,lines:o})}return n.map((e,t)=>({...e,key:t}))}var T0=[`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`],E0=[`app`,`web`,`page`];function D0(e,t,n,r,i=null){let a=O0(e.ownerDocument,n,r).map((e,n)=>{let r=t[n]?.sig===e.sig?t[n].nodes:null;return{sig:e.sig,nodes:r??e.build()}}),o=new Set(a.flatMap(e=>e.nodes));for(let e of t)for(let t of e.nodes)o.has(t)||t.remove();let s=i;for(let t of a.flatMap(e=>e.nodes))(t.parentNode!==e||t.previousSibling!==s)&&e.insertBefore(t,s?s.nextSibling:e.firstChild),s=t;return a}function O0(e,t,n){let r={doc:e,links:E0.includes(n.links)?n.links:`web`,headings:n.headings===`text`?`text`:`outline`,resolveLink:n.resolveLink,isCitation:n.isCitation},i=n.resolverGeneration??0;return w0(t).map(e=>({sig:`${JSON.stringify(e)}|${r.links}|${r.headings}|${i}`,build:()=>j0(r,e)}))}var k0=class extends Q${static get observedAttributes(){return[`links`,`headings`]}constructor(){super(),this._drawn=[],this._blocks=[],this._observer=null,this._connected=!1,this._resolveLink=void 0,this._isCitation=void 0,this._resolverGeneration=0}connectedCallback(){this._connected=!0,this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._drawn.some(t=>t.contains(e.target)))&&this._render()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._connected=!1,this._observer?.disconnect(),this._observer=null}get resolveLink(){return this._resolveLink}set resolveLink(e){this._resolveLink=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}get isCitation(){return this._isCitation}set isCitation(e){this._isCitation=typeof e==`function`?e:void 0,this._resolverGeneration+=1,this._connected&&this._render()}attributeChangedCallback(e,t,n){t!==n&&this._connected&&this._render()}_source(){return Array.from(this.children).find(e=>e.tagName===`PRE`&&e.classList.contains(`wui-markdown-source`))}_render(){let e=this._source();e&&(this._blocks=D0(this,this._blocks,e.textContent??``,{links:this.getAttribute(`links`)??void 0,headings:this.getAttribute(`headings`)??void 0,resolveLink:this._resolveLink,isCitation:this._isCitation,resolverGeneration:this._resolverGeneration},e),this._drawn=this._blocks.flatMap(e=>e.nodes),e.hidden=!0,this._observer?.takeRecords())}};function A0(e,t,n=[]){let r=e.createElement(t);return r.append(...n),r}function j0(e,t){switch(t.type){case`paragraph`:return[A0(e.doc,`p`,M0(e,t.lines))];case`heading`:return[N0(e,t)];case`list`:return P0(e,t.items);case`table`:return[I0(e,t)];case`code`:return[L0(e.doc,t)];case`quote`:return[A0(e.doc,`blockquote`,M0(e,t.lines))];case`rule`:return[e.doc.createElement(`hr`)];default:return[]}}function M0(e,t){let n=[];return t.forEach((t,r)=>{r>0&&n.push(e.doc.createElement(`br`)),n.push(...R0(e,t))}),n}function N0(e,t){let n=R0(e,t.text);if(e.headings===`text`){let t=A0(e.doc,`p`,n);return t.className=`fw-semibold`,t}return A0(e.doc,`h2`,n)}function P0(e,t){let n=[];for(let r=0;r<t.length;){let i=F0(e,t,r);n.push(i.list),r=i.next}return n}function F0(e,t,n){let{depth:r,ordered:i,number:a}=t[n],o=e.doc.createElement(i?`ol`:`ul`);i&&a!==1&&o.setAttribute(`start`,String(a));let s=null,c=n;for(;c<t.length&&t[c].depth>=r;)if(t[c].depth===r)s=A0(e.doc,`li`,R0(e,t[c].text)),o.append(s),c+=1;else{let n=F0(e,t,c);s.append(n.list),c=n.next}return{list:o,next:c}}function I0(e,t){let n=t.header.map(t=>{let n=A0(e.doc,`th`,R0(e,t));return n.setAttribute(`scope`,`col`),n}),r=t.rows.map(n=>A0(e.doc,`tr`,t.header.map((t,r)=>A0(e.doc,`td`,R0(e,n[r]??``))))),i=A0(e.doc,`table`,[A0(e.doc,`thead`,[A0(e.doc,`tr`,n)]),A0(e.doc,`tbody`,r)]);i.className=`table`;let a=A0(e.doc,`div`,[i]);return a.className=`table-responsive`,a}function L0(e,t){let n=A0(e,`pre`,[A0(e,`code`,[e.createTextNode(t.text)])]);n.className=`wui-code-source`;let r=A0(e,`wui-code-block`,[n]);return r.className=`wui-code-block`,r.setAttribute(`language`,T0.includes(t.language)?t.language:`text`),r}function R0(e,t){return z0(e,n0(t,{isCitation:e.isCitation}))}function z0(e,t){return t.flatMap(t=>B0(e,t))}function B0(e,t){let{doc:n}=e;switch(t.type){case`code`:return[A0(n,`code`,[n.createTextNode(t.text)])];case`strong`:return[A0(n,`strong`,z0(e,t.children))];case`em`:return[A0(n,`em`,z0(e,t.children))];case`strike`:return[A0(n,`del`,z0(e,t.children))];case`image`:return[n.createTextNode(`[`),...z0(e,t.children),n.createTextNode(`]`)];case`link`:return V0(e,t);case`citation`:return[H0(n,t.text)];default:return[n.createTextNode(t.text)]}}function V0(e,t){let n=z0(e,t.children),r=s0(t.href,e.links,e.resolveLink,globalThis.location?.origin);if(!r)return n;if(r.kind===`app`){let t=l0(r.target);return t?[U0(e.doc,t,n,!1)]:n}return[U0(e.doc,r.href,n,r.kind===`web`)]}function H0(e,t){let n=e.createElement(`span`);n.className=`chip primary chip-outline chip-sm chip-clickable wui-markdown-citation`,n.setAttribute(`data-wui`,`AppChip`);let r=e.createElement(`button`);r.type=`button`,r.className=`chip-body`,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>{r.dispatchEvent(new CustomEvent(`wui-markdown-citation`,{bubbles:!0,detail:{citation:t}}))});let i=e.createElement(`span`);return i.className=`chip-label`,i.textContent=t,r.append(i),n.append(r),n}function U0(e,t,n,r){let i=A0(e,`span`,n);i.className=`wui-link__label`;let a=A0(e,`a`,[i]);return a.className=`wui-link wui-link--static`,a.setAttribute(`data-wui`,`AppLink`),a.setAttribute(`href`,t),r&&(a.setAttribute(`target`,`_blank`),a.setAttribute(`rel`,`noopener noreferrer`)),a}Z$(`wui-markdown`,k0);var W0=`AppButton`,G0={primary:`btn-primary`,soft:`btn-soft-primary`,outline:`btn-outline-primary`,ghost:`btn-ghost-primary`,text:`btn-link-primary`,danger:`btn-danger`,success:`btn-success`,"outline-danger":`btn-outline-danger`,light:`btn-neutral`,warning:`btn-warning`,neutral:`btn-soft-neutral`,"outline-light":`btn-glass`,"outline-secondary":`btn-outline-neutral`};function K0(e=`primary`,t=`md`){let n=G0[e];if(!n)throw Error(`buttonClass: unknown variant "${e}"`);return t===`md`?`btn ${n}`:`btn ${n} btn-${t}`}var q0=Object.freeze([`text`,`json`,`js`,`cs`,`sql`,`bash`,`http`,`html`,`css`]),J0=Object.freeze({text:``,json:`JSON`,js:`JavaScript`,cs:`C#`,sql:`SQL`,bash:`Bash`,http:`HTTP`,html:`HTML`,css:`CSS`}),Y0=e=>RegExp(`\\b(?:${e.join(`|`)})\\b`),X0=`(?![\\s\\S])`,Z0=RegExp(`/\\*[\\s\\S]*?(?:\\*/|${X0})`).source,Q0=[[`attr`,/"(?:[^"\\\n]|\\.)*"(?=\s*:)/],[`string`,/"(?:[^"\\\n]|\\.)*"?/],[`number`,/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/],[`literal`,Y0([`true`,`false`,`null`])],[`punct`,/[{}[\],:]/]],$0=[[`comment`,RegExp(`//[^\\n]*|${Z0}`)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?/],[`number`,/\b(?:0[xX][\da-fA-F_]+|\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?n?)\b/],[`keyword`,Y0(`async.await.break.case.catch.class.const.continue.default.delete.do.else.export.extends.finally.for.from.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.yield`.split(`.`))],[`literal`,Y0([`true`,`false`,`null`,`undefined`,`NaN`,`Infinity`])],[`function`,/(?<![\w$])[A-Za-z_$][\w$]*(?=\s*\()/],[`type`,/(?<![\w$])[A-Z][\w$]*/],[`punct`,/[{}()[\];,]/]],e2=[[`comment`,RegExp(`//[^\\n]*|${Z0}`)],[`string`,/@"(?:[^"]|"")*"?|\$@?"(?:[^"\\\n]|\\.)*"?|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`number`,/\b\d[\d_]*\.?\d*(?:[eE][+-]?\d+)?[fFdDmMlLuU]{0,2}\b/],[`keyword`,Y0(`abstract.as.async.await.base.bool.break.byte.case.catch.char.checked.class.const.continue.decimal.default.delegate.do.double.else.enum.event.explicit.extern.finally.fixed.float.for.foreach.get.goto.if.implicit.in.init.int.interface.internal.is.lock.long.namespace.new.object.operator.out.override.params.private.protected.public.readonly.record.ref.required.return.sbyte.sealed.set.short.sizeof.static.string.struct.switch.this.throw.try.typeof.uint.ulong.unchecked.unsafe.ushort.using.var.virtual.void.volatile.when.while.with`.split(`.`))],[`literal`,Y0([`true`,`false`,`null`])],[`function`,/(?<!\w)[A-Za-z_]\w*(?=\s*\()/],[`type`,/(?<!\w)[A-Z]\w*/],[`punct`,/[{}()[\];,]/]],t2=[[`comment`,RegExp(`--[^\\n]*|${Z0}`)],[`string`,/'(?:[^']|'')*'?/],[`variable`,/@@?\w+/],[`number`,/\b\d+(?:\.\d+)?\b/],[`keyword`,Y0(`add.all.alter.and.as.asc.begin.between.by.case.check.column.commit.constraint.create.cross.database.declare.default.delete.desc.distinct.drop.else.end.exec.execute.exists.foreign.from.full.function.group.having.if.in.index.inner.insert.into.is.join.key.left.like.limit.not.null.offset.on.or.order.outer.over.partition.primary.procedure.references.return.returns.right.rollback.select.set.table.then.top.transaction.union.unique.update.values.view.when.where.while.with`.split(`.`))],[`literal`,Y0([`true`,`false`])],[`type`,Y0([`bigint`,`bit`,`char`,`date`,`datetime`,`datetime2`,`decimal`,`float`,`int`,`money`,`nchar`,`numeric`,`nvarchar`,`real`,`smallint`,`text`,`time`,`tinyint`,`uniqueidentifier`,`varchar`])],[`function`,/\b[A-Za-z_]\w*(?=\s*\()/],[`punct`,/[(),;]/]],n2=[[`comment`,/(?<![^\s;|&(])#[^\n]*/],[`string`,/"(?:[^"\\]|\\[\s\S])*"?|'[^']*'?/],[`variable`,/\$(?:\{[^}\n]*\}?|[A-Za-z_]\w*|[0-9@#?$!*-])/],[`attr`,/(?<![\w-])--?[A-Za-z][\w-]*/],[`number`,/(?<![\w.-])\d+(?:\.\d+)?\b/],[`keyword`,Y0([`case`,`do`,`done`,`elif`,`else`,`esac`,`exit`,`export`,`fi`,`for`,`function`,`if`,`in`,`local`,`return`,`select`,`then`,`until`,`while`])],[`function`,Y0(`awk.az.cat.cd.chmod.chown.cp.curl.docker.dotnet.echo.gcloud.git.grep.kubectl.ls.mkdir.mv.npm.npx.pnpm.rm.sed.source.sudo.wget`.split(`.`))],[`punct`,/[|&;<>(){}[\]]+/]],r2=[[`comment`,/^#[^\n]*/m],[`keyword`,/^(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|TRACE|CONNECT)(?= )/m],[`literal`,/HTTP\/\d(?:\.\d)?/],[`number`,/(?<=^HTTP\/\d(?:\.\d)? )\d{3}\b/m],[`function`,/(?<=^[A-Z]+ )\S+/m],[`attr`,/^[A-Za-z][\w-]*(?=:)/m],[`string`,/(?<=^[A-Za-z][\w-]*:[ \t]*)[^\n]+/m]],i2=[[`comment`,RegExp(`<!--[\\s\\S]*?(?:-->|${X0})`)],[`keyword`,/<![A-Za-z][^>]*>?/],[`tag`,/<\/?[A-Za-z][^<>]*>?/],[`literal`,/&#?\w+;/]],a2={json:Q0,js:$0,cs:e2,sql:t2,bash:n2,http:r2,css:[[`comment`,new RegExp(Z0)],[`string`,/"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/],[`keyword`,/@[\w-]+|!important/],[`attr`,/[\w-]+(?=\s*:[^{};]*[;}])/],[`number`,/#[0-9a-fA-F]{3,8}\b|(?<![\w-])-?(?:\d+\.?\d*|\.\d+)(?:%|[A-Za-z]{1,4})?/],[`function`,/[\w-]+(?=\()/],[`type`,/[.#](?!\d)[A-Za-z_][\w-]*/],[`punct`,/[{}();:,]/]],html:i2,htmlTag:[[`tag`,/^<\/?[\w:.-]+/],[`string`,/"[^"]*"?|'[^']*'?/],[`attr`,/(?<=\s)[^\s=<>/"']+/],[`punct`,/\/?>|=/]]},o2=new Map;function s2(e){let t=o2.get(e);if(!t){let n=a2[e],r=e===`sql`?`gi`:`g`,i=n.map(([,e])=>`(${e.source})`).join(`|`);t={re:new RegExp(i,`${r}m`),types:n.map(([e])=>e)},o2.set(e,t)}return t}function c2(e,t,n){if(!n)return;let r=e[e.length-1];r&&r[0]===t?r[1]+=n:e.push([t,n])}function l2(e,t,n=[]){let{re:r,types:i}=s2(e),a=0;for(let o of t.matchAll(r)){if(!o[0])continue;c2(n,`plain`,t.slice(a,o.index));let r=i.findIndex((e,t)=>o[t+1]!==void 0);e===`html`&&i[r]===`tag`?l2(`htmlTag`,o[0],n):c2(n,i[r],o[0]),a=o.index+o[0].length}return c2(n,`plain`,t.slice(a)),n}function u2(e){let t=/\r?\n\r?\n/.exec(e);if(!t)return l2(`http`,e);let n=l2(`http`,e.slice(0,t.index+t[0].length)),r=e.slice(t.index+t[0].length),i=r.trimStart()[0];return i===`{`||i===`[`?l2(`json`,r,n):i===`<`?l2(`html`,r,n):(c2(n,`plain`,r),n)}function d2(e,t){let n=String(e??``);return!n||n.length>1e5?n?[[`plain`,n]]:[]:t===`http`?u2(n):!Object.hasOwn(a2,t)||t===`htmlTag`?[[`plain`,n]]:l2(t,n)}function f2(e,t){let n=[[]];for(let[r,i]of d2(e,t))i.split(/\r\n|\r|\n/).forEach((e,t)=>{t>0&&n.push([]),e&&n[n.length-1].push([r,e])});return n.length>1&&n[n.length-1].length===0&&n.pop(),n}var p2=class extends Q${static get observedAttributes(){return[`language`,`line-numbers`,`wrap`,`label`,`copy-label`,`copied-label`]}constructor(){super(),this._chrome=null,this._title=null,this._view=null,this._codeEl=null,this._copyIcon=null,this._copyText=null,this._copied=!1,this._observer=null,this._timer=0,this._cancelFrame=null}connectedCallback(){this._render(),typeof MutationObserver<`u`&&(this._observer=new MutationObserver(e=>{e.some(e=>!this._chrome?.contains(e.target))&&this._schedule()}),this._observer.observe(this,{childList:!0,subtree:!0,characterData:!0}))}disconnectedCallback(){this._observer?.disconnect(),this._observer=null,this._cancelPending()}attributeChangedCallback(){this.isConnected&&this._render()}_source(){return Array.from(this.children).find(e=>e.classList.contains(`wui-code-source`))}_code(){return(this._source()?.textContent??``).replace(/\r?\n$/,``)}_schedule(){if(this._cancelFrame)return;let e=()=>{this._cancelFrame=null,this._render()};if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);this._cancelFrame=()=>cancelAnimationFrame(t)}else{let t=!0;queueMicrotask(()=>{t&&e()}),this._cancelFrame=()=>{t=!1}}}_cancelPending(){this._cancelFrame?.(),this._cancelFrame=null}_render(){if(!this._source())return;this._cancelPending();let e=this.ownerDocument;this._chrome||this._build(e);let t=this.getAttribute(`language`),n=q0.includes(t)?t:`text`,r=this.getAttribute(`label`)||``,i=f2(this._code(),n);this._title.textContent=r||J0[n],this._view.setAttribute(`aria-label`,r||`Code`),this._view.style.setProperty(`--wui-code-digits`,String(String(i.length).length)),this._codeEl.replaceChildren(...i.map(t=>m2(e,t))),this._copied||(this._copyText.textContent=this._copyLabel()),this.setAttribute(`data-wui-ready`,``),this._observer?.takeRecords()}_build(e){let t=e.createElement(`div`);t.className=`wui-code-chrome`,t.append(this._bar(e));let n=e.createElement(`div`);n.className=`wui-code-view`,n.setAttribute(`role`,`region`),n.tabIndex=0;let r=e.createElement(`pre`);r.className=`wui-code-pre`,this._codeEl=e.createElement(`code`),r.append(this._codeEl),n.append(r),t.append(n),this._chrome=t,this._view=n,this.append(t)}_bar(e){let t=e.createElement(`div`);t.className=`wui-code-bar`,this._title=e.createElement(`span`),this._title.className=`wui-code-title`;let n=e.createElement(`button`);return n.type=`button`,n.className=`${K0(`ghost`,`sm`)} wui-code-copy`,n.dataset.wui=W0,n.setAttribute(`aria-live`,`polite`),this._copyIcon=e.createElement(`span`),this._copyIcon.className=`wui-code-copy-icon`,this._copyText=e.createElement(`span`),this._setCopied(!1),n.append(this._copyIcon,this._copyText),n.addEventListener(`click`,async()=>{await kn(this._code())&&(this._setCopied(!0),clearTimeout(this._timer),this._timer=setTimeout(()=>this._setCopied(!1),2e3))}),t.append(this._title,n),t}_setCopied(e){this._copied=e,this._copyIcon.innerHTML=Rn(e?`check`:`files`,{size:14}),this._copyText.textContent=this._copyLabel()}_copyLabel(){return this._copied?this.getAttribute(`copied-label`)||`Copied`:this.getAttribute(`copy-label`)||`Copy`}};function m2(e,t){let n=e.createElement(`span`);n.className=`wui-code-line`;for(let[r,i]of t){if(r===`plain`){n.append(i);continue}let t=e.createElement(`span`);t.className=`wui-code-t-${r}`,t.textContent=i,n.append(t)}return n}Z$(`wui-code-block`,p2);var h2=new Set([`Visitor`,`Customer`]),g2=/^\d+$/,_2=`pre, code, .wui-markdown-source`;function v2(e,t){return e?.features?.Sources===!0?typeof e?.isCitation==`function`?e.isCitation(t):g2.test(t):!1}function y2(e,t){if(yt(e,t?.handoffHosts))return e;let n=t?.resolveLink?.(e);return typeof n==`string`&&n!==``?n:null}function b2(e,t){let n=globalThis.location?.origin;for(let r of e.querySelectorAll(`a[href]`)){let e=r.dataset.linkSource??r.getAttribute(`href`);r.dataset.linkSource=e;let i=y2(e,t);i===null?r.replaceWith(r.ownerDocument.createTextNode(r.textContent)):(i!==r.getAttribute(`href`)&&r.setAttribute(`href`,i),Ne(i,`web`,void 0,n)?.kind===`web`?(r.setAttribute(`target`,`_blank`),r.setAttribute(`rel`,`noopener noreferrer`)):(r.removeAttribute(`target`),r.removeAttribute(`rel`)))}}function x2(e){let t=e.ownerDocument,n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[];for(let e=n.nextNode();e;e=n.nextNode())e.parentElement?.closest(_2)||r.push(e);for(let e of r){let n=_e(e.nodeValue);if(n.length===1&&n[0].kind===`text`)continue;let r=t.createDocumentFragment();e$(r,n),e.replaceWith(r)}}function S2(e){let t=e.turn;b2(e,t),t?.features?.FigureText===!0&&x2(e)}Vn(`wui-chat-part-text`,class extends Bn{#e=null;#t=null;#n=null;#r=null;#i=!1;#a=null;constructor(){super(),this.addEventListener(`wui-markdown-citation`,e=>{let t=this.turn;typeof t?.openCitation==`function`&&t.openCitation(Number(e.detail.citation))}),this.addEventListener(`click`,e=>this.#s(e))}renderPart(e,t){let n=h2.has(t.author.kind)?`plain`:`markdown`;if(n!==this.#e&&(this.#e=n,this.#r=null,this.#t=n===`plain`?this.#c():this.#l(e.text),this.#n=n===`plain`?null:this.#t.firstElementChild,this.replaceChildren(this.#t)),n===`plain`){let t=this.turn?.features?.FigureText===!0,n=JSON.stringify([e.text,t]);n!==this.#r&&(this.#r=n,this.#t.replaceChildren(),t?e$(this.#t,_e(e.text)):this.#t.append(this.ownerDocument.createTextNode(e.text)))}else this.#n.textContent!==e.text&&(this.#n.textContent=e.text);this.toggleAttribute(`data-streaming`,t.streaming===!0),this.#i||(this.#i=!0,this.closest(`[data-restored]`)||this.classList.add(`wui-chat-part-enter`)),this.#o()}disposePart(){this.#a?.disconnect(),this.#a=null}#o(){this.#a||(this.#a=new MutationObserver(()=>S2(this)),this.#a.observe(this,{childList:!0,subtree:!0,characterData:!0}),S2(this))}#s(e){let t=e.target instanceof Element?e.target.closest(`a[href]`):null,n=this.turn;if(!t||!this.contains(t))return;let r=t.getAttribute(`href`);r.startsWith(`#`)||(r.startsWith(`/`)&&typeof n?.onNavigate==`function`?(e.preventDefault(),n.onNavigate(r)):typeof n?.openTarget==`function`&&(e.preventDefault(),n.openTarget(r)))}#c(){return N(this.ownerDocument,`div`,`wui-chat-bubble`)}#l(e){let t=this.ownerDocument,n=N(t,`wui-markdown`,`wui-markdown wui-chat-text`);n.setAttribute(`links`,`web`),n.setAttribute(`headings`,`text`),n.isCitation=e=>v2(this.turn,e);let r=N(t,`pre`,`wui-markdown-source`,e);return n.append(r),n}}),Vn(`wui-chat-part-ticket`,class extends Bn{renderPart(e,t,n){let{labels:r}=n,i=$(`article`,`wui-chat-ticket`,{"aria-label":r.ticketAria(e.number)}),a=$(`div`,`wui-chat-ticket-head`),o=$(`span`,`wui-chat-ticket-number`);o.textContent=r.ticketAria(e.number),a.append(o);let s=z$(e.status);if(s!==null){let t=$(`span`,`wui-chat-ticket-badge wui-chat-ticket-badge--${s}`);t.textContent=B$(e.status,r),a.append(t)}let c=$(`strong`,`wui-chat-ticket-title`);if(c.textContent=e.subject,i.append(a,c),typeof n.openTicket==`function`){let t=$(`div`,`wui-chat-ticket-foot`),a=$(`button`,`wui-chat-ticket-link`,{type:`button`});a.textContent=r.ticketView,a.addEventListener(`click`,()=>n.openTicket({ticketId:e.ticketId,number:e.number})),t.append(a),i.append(t)}this.replaceChildren(i)}});var C2=`http://www.w3.org/2000/svg`,w2={mic:`M12 15a3 3 0 0 0 3-3V6a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-2.08A7 7 0 0 0 19 12z`,stop:`M6 6h12v12H6z`,play:`M8 5v14l11-7z`,pause:`M6 5h4v14H6zm8 0h4v14h-4z`,speaker:`M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z`};function T2(e,t=18){if(!Object.hasOwn(w2,e))throw Error(`Unknown voice icon "${e}".`);let n=document.createElementNS(C2,`svg`);n.setAttribute(`viewBox`,`0 0 24 24`),n.setAttribute(`width`,String(t)),n.setAttribute(`height`,String(t)),n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`focusable`,`false`),n.setAttribute(`fill`,`currentColor`);let r=document.createElementNS(C2,`path`);return r.setAttribute(`d`,w2[e]),n.append(r),n}var E2=40,D2=null,O2=class extends Bn{#e=null;#t=null;#n=null;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;#u=0;#d=0;#f=!1;#p=null;#m=null;#h=null;#g=0;#_=!1;renderPart(e,t,n){this.#e=n,n.features.VoiceClips?(this.#t===null&&this.#y(),e.attachmentId!==this.#l&&(this.disposePart(),this.#l=e.attachmentId,this.#d=0,this.#n.replaceChildren(...En(e.attachmentId,E2).map(k2))),this.#u=e.durationMs,this.#b(e)):this.#v(e.transcript)}disposePart(){this.#g+=1,this.#p?.pause(),this.#h!==null&&URL.revokeObjectURL(this.#h),D2===this&&(D2=null),this.#p=null,this.#m=null,this.#h=null,this.#f=!1}#v(e){if(this.disposePart(),this.#t=null,this.#l=null,this.#o=null,this.#s=null,typeof e==`string`&&e!==``){let t=N(document,`p`,`wui-chat-clip-transcript`);t.textContent=e,this.replaceChildren(t)}else this.replaceChildren()}#y(){this.#t=N(document,`div`,`wui-chat-clip`),this.#t.setAttribute(`role`,`group`);let e=N(document,`div`,`wui-chat-clip-row`);this.#r=N(document,`button`,`wui-chat-clip-play`),this.#r.type=`button`,this.#r.addEventListener(`click`,()=>this.#A()),this.#n=N(document,`div`,`wui-chat-clip-wave`),this.#n.setAttribute(`aria-hidden`,`true`),this.#i=N(document,`span`,`wui-chat-clip-time`),e.append(this.#r,this.#n,this.#i),this.#a=N(document,`p`,`wui-chat-clip-error`),this.#a.setAttribute(`role`,`status`),this.#a.hidden=!0,this.#t.append(e,this.#a),this.replaceChildren(this.#t)}#b(e){let t=this.#e.labels;this.#t.setAttribute(`aria-label`,t.voiceClip),this.#r.disabled=this.#_||typeof this.#e.readAttachment!=`function`,this.#x(),this.#S(),this.#C(e.transcript)}#x(){let e=this.#e.labels,t=this.#f?e.voiceClipPause:e.voiceClipPlay;this.#r.setAttribute(`aria-label`,t),this.#r.title=t,this.#r.replaceChildren(T2(this.#f?`pause`:`play`,18))}#S(){let e=this.#u/1e3,t=e>0?Math.min(1,this.#d/e):0,n=Math.floor(t*E2);[...this.#n.children].forEach((e,t)=>{e.classList.toggle(`wui-chat-clip-bar--played`,t<n)});let r=Dn(Math.max(1,Math.round(e)));this.#i.textContent=this.#e.labels.voiceClipTime(Dn(this.#d),r)}#C(e){typeof e!=`string`||e===``?(this.#o?.remove(),this.#s?.remove(),this.#o=null,this.#s=null):(this.#o===null&&(this.#o=N(document,`button`,`wui-chat-clip-toggle`),this.#o.type=`button`,this.#o.addEventListener(`click`,()=>{this.#c=!this.#c,this.#s.hidden=!this.#c,this.#w()}),this.#s=N(document,`p`,`wui-chat-clip-transcript`),this.#s.hidden=!this.#c,this.#t.append(this.#o,this.#s)),this.#s.textContent=e,this.#w())}#w(){let e=this.#e.labels;this.#o.setAttribute(`aria-expanded`,String(this.#c)),this.#o.textContent=this.#c?e.voiceClipHideTranscript:e.voiceClipShowTranscript}#T(){return this.#m??=this.#E().catch(e=>{throw this.#m=null,e}),this.#m}async#E(){let e=this.#g,t=await this.#e.readAttachment(this.#l),n=URL.createObjectURL(new Blob([t],{type:r(t)}));if(e!==this.#g)return URL.revokeObjectURL(n),null;this.#h!==null&&URL.revokeObjectURL(this.#h),this.#h=n;let i=new Audio(this.#h);return i.addEventListener(`timeupdate`,()=>{this.#d=i.currentTime,this.#S()}),i.addEventListener(`ended`,()=>{this.#d=0,this.#D(),this.#S()}),i.addEventListener(`error`,()=>{this.#D(),this.#m=null,this.#k()}),this.#p=i,i}#D(){this.#p?.pause(),this.#O(!1)}#O(e){this.#f=e,e?(D2&&D2!==this&&D2.#D(),D2=this):D2===this&&(D2=null),this.#t!==null&&this.#x()}#k(){this.#a.textContent=this.#e.labels.voiceClipFailed,this.#a.hidden=!1}async#A(){if(this.#f)this.#D();else{this.#a.hidden=!0,this.#_=!0,this.#r.disabled=!0,this.#r.setAttribute(`aria-busy`,`true`);try{let e=await this.#T();if(e===null)return;this.#O(!0),await e.play()}catch{this.#D(),this.#m=null,this.#k()}finally{this.#_=!1,this.#r.removeAttribute(`aria-busy`),this.#r.disabled=typeof this.#e.readAttachment!=`function`}}}};function k2(e){let t=N(document,`span`,`wui-chat-clip-bar`);return t.style.setProperty(`--wui-chat-bar-height`,`${Math.round(e*100)}%`),t}Vn(`wui-chat-part-voice-clip`,O2);var A2={Text:`wui-chat-part-text`,Sources:`wui-chat-part-sources`,QuickReplies:`wui-chat-part-quick-replies`,InputRequest:`wui-chat-part-input-request`,Action:`wui-chat-part-action`,Notice:`wui-chat-part-notice`,Table:`wui-chat-part-table`,Chart:`wui-chat-part-chart`,Figures:`wui-chat-part-figures`,RecordCard:`wui-chat-part-record-card`,Image:`wui-chat-part-image`,File:`wui-chat-part-file`,Ticket:`wui-chat-part-ticket`,Handoff:`wui-chat-part-handoff`,VoiceClip:`wui-chat-part-voice-clip`},j2=n({SpeechConfig:()=>void 0}),M2=t((()=>{})),N2=1e4,P2=2e3,F2=3e5,I2=new Set([`NotAllowedError`,`SecurityError`,`PermissionDeniedError`]),L2=new Set([`NotFoundError`,`OverconstrainedError`,`NotReadableError`]);function R2(e){return I2.has(e?.name)?new A(`Blocked`,e.message):L2.has(e?.name)?new A(`NoMicrophone`,e.message):z2(e)}function z2(e){return e instanceof A?e:new A(`Failed`,e?.message??String(e))}var B2=null;function V2(){return globalThis.SpeechSDK?globalThis.SpeechSDK:(B2===null&&(B2=Promise.resolve().then(()=>(M2(),j2)).then(e=>e.SpeechConfig?e:e.default).catch(e=>{throw B2=null,e})),B2)}function H2(){return globalThis.document?.documentElement?.lang||globalThis.navigator?.language||`en-US`}function U2(e){let t=e.getToken,n=e.loadSdk??V2,r=e.getLanguage??H2,i=typeof navigator<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,a=typeof window<`u`&&window.isSecureContext===!0,o=i&&a,s=typeof window<`u`,c=null,l=null,u=null;function d(){return c!==null&&Date.parse(c.expiresDateTimeUtc)-Date.now()>6e4?Promise.resolve(c):(l===null&&(l=Promise.resolve().then(()=>t()).then(e=>(c=e,l=null,e),e=>{throw l=null,z2(e)})),l)}function f(){return u===null&&(u=Promise.resolve().then(()=>n()).then(e=>{if(!e?.SpeechConfig)throw new A(`Unavailable`,`Speech is not available in this browser.`);return e}).catch(e=>{throw u=null,z2(e)})),u}function p(e={}){let{signal:t,onText:n,onEnd:i}=e;if(t?.aborted)return i?.(),Promise.resolve();let a,s,c=new Promise((e,t)=>{a=e,s=t}),l=!1,u=!1,p=null,m=!1,h=``,g=[],_=null,v=null,y=null,b=()=>{clearTimeout(_),clearTimeout(v),clearTimeout(y)},x=e=>{if(!l){l=!0,b(),t?.removeEventListener(`abort`,S);try{p?.close()}finally{try{i?.()}finally{e?s(e):a()}}}};async function S(){if(!(l||u)){if(u=!0,b(),p!==null)try{await new Promise(e=>p.stopContinuousRecognitionAsync(e,e))}catch{}x(null)}}let C=()=>[...g,h].filter(e=>e!==``).join(` `).trim(),w=(e,t)=>{m||(m=!0,clearTimeout(_)),clearTimeout(v),v=setTimeout(S,P2),n?.(C(),t)};async function T(){if(t?.addEventListener(`abort`,S),!o){x(new A(`Unavailable`,`Dictation is not available in this browser.`));return}let n;try{n=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){x(R2(e));return}for(let e of n.getTracks())e.stop();if(!l)try{let t=await f(),n=await d();if(l)return;let i=t.SpeechConfig.fromAuthorizationToken(n.token,n.region);if(i.speechRecognitionLanguage=e.language||r(),i.setProperty(t.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs,String(N2)),p=new t.SpeechRecognizer(i,t.AudioConfig.fromDefaultMicrophoneInput()),p.recognizing=(e,t)=>{if(l)return;let n=t.result?.text;n&&(h=n,w(n,!1))},p.recognized=(e,n)=>{if(l)return;let{reason:r,text:i}=n.result;r===t.ResultReason.RecognizedSpeech&&i?(g.push(i),h=``,w(i,!0)):r===t.ResultReason.NoMatch&&t.NoMatchDetails.fromResult(n.result).reason===t.NoMatchReason.InitialSilenceTimeout&&x(new A(`NoSpeech`,`No speech was heard.`))},p.canceled=(e,n)=>{l||(n.reason===t.CancellationReason.Error?x(new A(`Failed`,n.errorDetails)):x(null))},p.sessionStopped=()=>x(null),await new Promise((e,t)=>p.startContinuousRecognitionAsync(e,t)),l)return;e.onStarted?.(),_=setTimeout(()=>{m||x(new A(`NoSpeech`,`No speech was heard.`))},N2),y=setTimeout(S,F2)}catch(e){x(z2(e))}}return T(),c}async function m(e,t={}){let{signal:n}=t;if(!n?.aborted)try{let i=await f(),a=await d();if(n?.aborted)return;let o=i.SpeechConfig.fromAuthorizationToken(a.token,a.region);o.speechSynthesisLanguage=t.language||r();let s=new i.SpeakerAudioDestination,c=new i.SpeechSynthesizer(o,i.AudioConfig.fromSpeakerOutput(s));await new Promise((t,r)=>{let a=!1,o=()=>{n?.removeEventListener(`abort`,d),c.close(),s.close()},l=()=>{a||(a=!0,o(),t())},u=e=>{a||(a=!0,o(),r(z2(e)))};function d(){s.pause(),l()}n?.addEventListener(`abort`,d),s.onAudioEnd=l;try{c.speakTextAsync(e,e=>{e.reason!==i.ResultReason.SynthesizingAudioCompleted&&u(new A(`Failed`,`The reply could not be synthesised.`))},e=>u(e))}catch(e){u(e)}})}catch(e){throw z2(e)}}return{dictation:o,readAloud:s,streamsText:!0,startDictation:p,speak:m}}var W2=8e3,G2=6e3,K2=new Set([`Blocked`,`NoMicrophone`]);function q2(e){let t=e instanceof A?e.code:`Failed`;return{code:t,source:`Dictation`,sticky:K2.has(t)}}function J2(e){let t=it(e.filter(e=>e.kind===`Text`)).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=6e3)return t;let n=t.slice(0,G2),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function Y2(e,t){switch(e.code){case`Blocked`:return t.dictationBlocked;case`NoMicrophone`:return t.dictationNoMicrophone;case`NoSpeech`:return t.dictationNotHeard;case`Unavailable`:return t.dictationUnavailable;case`Failed`:return t.dictationFailed;case`SpeakFailed`:return t.readAloudFailed;default:throw Error(`Unknown voice note code "${e.code}".`)}}function X2(e){let t=e.getState,n=e.speech??U2({getToken:e.getToken}),r=`Idle`,i=null,a=null,o=null,s=null,c=0,l=null,u=new Set,d=()=>({mode:r,messageId:i,startedAtMs:a,note:o});function f(){let e=d();for(let t of[...u])t(e)}function p(e){r=e.mode,i=e.messageId??null,a=e.startedAtMs??null,f()}function m(){clearTimeout(l),l=null}function h(e){m(),o=e,e&&!e.sticky&&(l=setTimeout(()=>{l=null,o=null,f()},W2)),f()}function g(){o!==null&&(m(),o=null,f())}function _(){return c+=1,s={id:c,controller:new AbortController,stopped:!1},s}function v(e){s===e&&(s=null,p({mode:`Idle`}))}function y(){let e=s;s=null,e&&(e.stopped=!0,e.controller.abort()),r!==`Idle`&&p({mode:`Idle`})}function b(){let e=t();return!!(e.features.Dictation&&e.profile?.speechAvailable&&n.dictation)}function x(){let e=t();return!!(e.features.ReadAloud&&e.profile?.speechAvailable&&n.readAloud)}async function S(e){if(r===`Dictating`){y();return}if(y(),h(null),!b())return;let t=e.getText(),i=t!==``&&!/\s$/.test(t)?`${t} `:t,a=_();p({mode:`Dictating`});try{await n.startDictation({signal:a.controller.signal,onText:t=>{s===a&&e.setText(i+t)},onEnd:()=>v(a)})}catch(e){if(a.stopped)return;v(a),h(q2(e))}}async function C(e,t){if(r===`Speaking`&&i===e){y();return}y(),h(null);let a=J2(t);if(a===``)return;let o=_();p({mode:`Speaking`,messageId:e});try{await n.speak(a,{signal:o.controller.signal}),v(o)}catch{if(o.stopped)return;v(o),h({code:`SpeakFailed`,source:`ReadAloud`,sticky:!1,messageId:e})}}function w(e){return u.add(e),()=>{u.delete(e)}}function T(){y(),m(),o=null,u.clear()}return{canDictate:b,canSpeak:x,getStatus:d,subscribe:w,toggleDictation:S,toggleSpeak:C,stop:y,dismissNote:g,destroy:T}}var Z2=new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function Q2(e,t){e.isTrusted&&!Z2.has(e.key)&&t.getStatus().mode===`Dictating`&&t.stop()}function $2({voice:e,getLabels:t,textarea:n,onTextChanged:r}){let i=null,a=$(`button`,`wui-chat-tool wui-chat-mic`,{type:`button`});a.append(T2(`mic`,20)),a.hidden=!0,a.addEventListener(`click`,()=>{e.toggleDictation({getText:()=>n.value,setText:e=>{n.value=n.maxLength>0?e.slice(0,n.maxLength):e,r(),n.setSelectionRange(n.value.length,n.value.length)}})});let o=$(`p`,`wui-chat-voice-note`,{role:`status`});o.hidden=!0;let s=$(`span`,`visually-hidden`,{"aria-live":`polite`});function c(e){let n=t(),r=e.note?.source===`ReadAloud`?null:e.note,i=e.mode===`Dictating`,c=i?n.dictateStop:n.dictate;a.setAttribute(`aria-pressed`,String(i)),a.setAttribute(`aria-label`,c),a.title=c;let l=r?.code===`Blocked`||r?.code===`NoMicrophone`;r===null?(o.hidden=!0,o.textContent=``):(o.hidden=!1,o.textContent=Y2(r,n),o.setAttribute(`role`,r.sticky?`alert`:`status`)),o.classList.toggle(`wui-chat-voice-note--blocked`,l),s.textContent=i?n.dictateListening:``}function l(t){let{state:n}=t;a.hidden=!e.canDictate();let r=e.getStatus().mode===`Speaking`,i=n.messagesLeftToday===0;a.disabled=i||r||n.handoffPause===!0}function u(e){c(e),i!==null&&l(i)}let d=e.subscribe(u);function f(t){i=t,l(t),c(e.getStatus())}function p(){d()}return{buttons:[a],note:o,announcer:s,paint:f,destroy:p}}var e4=10,t4=.9,n4=0;function r4(e){for(let t of e.toReversed())for(let e of t.parts.toReversed())if(e.kind===`InputRequest`&&e.state===`Open`)return e.fields[0]?.label??e.title??null;return null}function i4(e){n4+=1;let t=`wui-chat-composer-hint-${n4}`,n=$(`p`,`wui-chat-allowance`,{role:`status`});n.hidden=!0;let r=$(`span`),i=$(`button`,`btn btn-ghost-primary btn-sm wui-chat-action-btn`,{type:`button`});i.addEventListener(`click`,()=>e.onCancelEdit());let a=$(`div`,`wui-chat-editing`);a.hidden=!0,a.append(r,i);let o=$(`div`,`wui-chat-attachments`);o.hidden=!0;let s=$(`button`,`wui-chat-tool`,{type:`button`});s.append(_$(`paperclip`,20)),s.hidden=!0;let c=$(`input`,null,{type:`file`,multiple:``,tabindex:`-1`});c.hidden=!0,c.addEventListener(`change`,()=>{let t=[...c.files];c.value=``,t.length>0&&e.onAttach(t)}),s.addEventListener(`click`,()=>c.click());let l=$(`textarea`,`wui-chat-input`,{rows:`1`,"aria-describedby":t}),u=$(`span`,`visually-hidden`,{id:t}),d=$(`span`,`wui-chat-counter`);d.hidden=!0;let f=$(`button`,`wui-chat-send`,{type:`submit`});f.append(_$(`arrow-up`,18));let p=$(`button`,`wui-chat-send wui-chat-send--stop`,{type:`button`});p.append(_$(`stop`,16)),p.hidden=!0,p.addEventListener(`click`,()=>e.onStop());let m=$(`form`,`wui-chat-composer`);m.append(s,c,l,d,u,p,f);let h=null,g=null,_=null,v=0,y=null;function b(){l.style.height=`auto`,l.style.height=`${l.scrollHeight}px`;let e=getComputedStyle(l),t=l.scrollHeight-parseFloat(e.paddingTop)-parseFloat(e.paddingBottom);m.classList.toggle(`wui-chat-composer--multiline`,t>(parseFloat(e.lineHeight)||22)*1.5)}function x(){return y?.attachments.some(e=>e.status===`Uploading`)??!1}function S(){return y?.attachments.some(e=>e.status===`Ready`)??!1}function C(){let e=l.value.length,t=v>0&&e>v*t4;d.hidden=!t,t&&_&&(d.textContent=_.counter(e,v))}function w(){let e=y?.messagesLeftToday??null,t=l.value.trim()===``&&!S();f.disabled=!!y?.streaming||e===0||x()||t||y?.handoffPause===!0,m.classList.toggle(`wui-chat-composer--has-text`,!t)}function T(){if(f.disabled)return;let t=l.value.trim();l.value=``,b(),C(),w(),e.voice?.stop(),e.voice?.dismissNote(),e.onSubmit(t)}l.addEventListener(`input`,()=>{b(),C(),w(),l.value!==``&&e.onTyping?.()}),l.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),T())}),m.addEventListener(`submit`,e=>{e.preventDefault(),T()});let E=e.voice?$2({voice:e.voice,getLabels:()=>_,textarea:l,onTextChanged:()=>{b(),C(),w()}}):null;E&&(m.insertBefore(E.buttons[0],f),l.addEventListener(`keydown`,t=>Q2(t,e.voice)));function D(t){let n=t.map(t=>{let n=$(`span`,`wui-chat-chip`),r=$(`span`,null,t.status===`Failed`?{title:t.error??``}:null);r.textContent=t.fileName;let i=$(`button`,`wui-chat-chip-remove`,{type:`button`,"aria-label":_.removeAttachment(t.fileName)});i.append(_$(`x`,14)),i.addEventListener(`click`,()=>e.onRemove(t.key));let a=[];if(t.status===`Uploading`){let e=$(`progress`,`wui-chat-chip-progress`,{max:`1`});typeof t.progress==`number`&&(e.value=t.progress);let n=$(`span`,`wui-chat-chip-status`);n.textContent=_.attachmentUploading,a.push(e,n)}if(t.status===`Failed`){let e=$(`span`,`wui-chat-chip-error`,{"aria-live":`polite`});e.textContent=t.error||_.attachmentFailed,a.push(e)}return n.append(r,...a,i),n});o.replaceChildren(...n),o.hidden=n.length===0}function O(t){y=t.state,_=t.labels,v=t.maxLength,t.sendIcon&&f.dataset.icon!==t.sendIcon&&(f.dataset.icon=t.sendIcon,f.replaceChildren(_$(t.sendIcon,18)));let o=y.messagesLeftToday;m.setAttribute(`aria-label`,_.composer),u.textContent=_.composerHint,l.setAttribute(`aria-label`,_.composer),l.maxLength=v,l.placeholder=y.handoffPause?_.handoffMoment:r4(y.messages)??_.placeholder,l.disabled=o===0||y.handoffPause===!0,n.hidden=!(o!==null&&o<=e4),n.hidden||(n.textContent=_.allowance(o));let d=y.editing?.messageId??null;if(d!==h){let t=h!==null;h=d,y.editing?(e.voice?.stop(),l.value=y.editing.text,b()):t&&(l.value=``,b())}a.hidden=!y.editing,r.textContent=_.editing,i.textContent=_.cancel;let x=t.draft??null;typeof x==`string`&&x!==``&&x!==g&&(g=x,l.value=x,l.dispatchEvent(new Event(`input`)),l.focus(),e.onDraftApplied?.()),D(y.attachments);let S=y.features.Attachments&&(y.profile?.limits.maxAttachments??0)>0&&y.handoffPause!==!0;s.hidden=!S,s.setAttribute(`aria-label`,_.attach),s.title=_.attachHint,c.accept=t.accept??``;let T=y.streaming&&y.features.Stop;p.hidden=!T,p.setAttribute(`aria-label`,_.stop),f.hidden=T,f.setAttribute(`aria-label`,_.send),C(),w(),E?.paint({state:y})}function k(){l.focus()}function A(){E?.destroy();for(let e of j)e.remove()}let j=[n,a,o,...E?[E.note,E.announcer]:[],m];return{nodes:j,paint:O,focus:k,destroy:A,getDraft:()=>l.value}}var a4=`https://policies.google.com/privacy`,o4=`https://policies.google.com/terms`;function s4(e,t){let n=$(`a`,`wui-chat-footer-link`,{href:t,target:`_blank`,rel:`noopener noreferrer`});return n.textContent=e,n}function c4(){let e=$(`span`,`wui-chat-footer-sep`,{"aria-hidden":`true`});return e.textContent=`·`,e}function l4(){let e=$(`p`,`wui-chat-footer`);e.hidden=!0;function t(t){let{labels:n,profile:r}=t,i=[];if(r){let e=$(`span`,`wui-chat-footer-text`);e.textContent=r.footer.disclaimer||n.disclaimer,i.push(e);let t=$(`span`,`wui-chat-footer-privacy`);if(r.footer.privacyText&&t.append(document.createTextNode(r.footer.privacyText)),r.footer.privacyUrl){t.hasChildNodes()&&t.append(document.createTextNode(` `));let e=$(`a`,`wui-chat-footer-link`,{href:r.footer.privacyUrl});e.textContent=n.footerPrivacy,t.append(e)}if(t.hasChildNodes()&&i.push(t),r.footer.assuranceText){let e=$(`span`);e.textContent=r.footer.assuranceText,i.push(e)}if(kt(r)){let e=$(`span`,`wui-chat-footer-captcha`);e.append(document.createTextNode(`${n.captchaNote} `),s4(n.captchaPrivacy,a4),document.createTextNode(` `),s4(n.captchaTerms,o4)),i.push(e)}}e.replaceChildren(...i.flatMap((e,t)=>t?[c4(),e]:[e])),e.hidden=i.length===0}return{el:e,paint:t}}function u4(e,t,n){e.setAttribute(`aria-label`,t),e.title=t,e.dataset.icon!==n&&(e.dataset.icon=n,e.replaceChildren(_$(n,20)))}function d4(e){let t=$(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),n=$(`strong`,`wui-chat-title`);e.titleId&&(n.id=e.titleId);let r=$(`span`,`wui-chat-tagline`),i=$(`span`,`wui-chat-status`),a=$(`div`,`wui-chat-header-text`);a.append(n,r,i);let o=b$(``,`history`,()=>e.onHistory()),s=b$(``,`volume-high`,()=>e.onMute()),c=b$(``,`plus`,()=>e.onNew()),l=b$(``,`maximize-4`,()=>e.onSwitch());l.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--full`);let u=b$(``,`panel-left-open`,()=>e.onSwitch());u.classList.add(`wui-chat-switch-btn`,`wui-chat-switch-btn--side`);let d=b$(``,`x`,()=>e.onClose());d.classList.add(`wui-chat-close-btn`);let f=$(`div`,`wui-chat-header-actions`);f.append(o,s,c,l,u,d);let p=$(`header`,`wui-chat-header`);p.append(t,a,f);function m(e){let{labels:t}=e;p.hidden=!1,n.textContent=e.title??``,r.textContent=e.tagline??``,r.hidden=!e.tagline,i.textContent=e.status??``,o.hidden=!e.showHistory,e.viewingHistory?u4(o,t.backToChat,`arrow-left`):u4(o,t.history,`history`),s.hidden=!e.showMute,u4(s,e.muted?t.unmuteSounds:t.muteSounds,e.muted?`volume-mute`:`volume-high`),c.hidden=!!e.viewingHistory||e.showNew===!1,c.disabled=!e.canNew,u4(c,t.newChat,`plus`),l.hidden=e.switchTo!==`full-page`,l.disabled=!e.canSwitch,u4(l,t.openFullScreen,`maximize-4`),u.hidden=e.switchTo!==`docked`,u.disabled=!e.canSwitch,u4(u,t.openSidePanel,`panel-left-open`),d.hidden=!e.showClose,u4(d,t.close,`x`)}return{el:p,paint:m}}var f4=120;function p4(e,t,n=`outline`){let r=$(`button`,`${v$(n,`sm`)} wui-chat-action-btn`,{type:`button`});return r.textContent=e,r.addEventListener(`click`,t),r}function m4(e){let t=$(`div`,`wui-chat-history`);t.hidden=!0;let n=null,r=null,i=null,a=null,o=null,s=!1;function c(){return n||(n=k({client:e.getClient()}),r=n.subscribe(()=>_()),n)}function l(e){i={id:e.publicId,kind:`rename`,draft:e.title??``,saving:!1},a=null,o=null,s=!0,_()}function u(e){i={id:e.publicId,kind:`delete`,saving:!1},a=null,o=null,_()}function d(){i=null,a=null,o=null,_()}async function f(){let t=i,n=t?.draft.trim()??``;if(t?.kind===`rename`&&!t.saving&&n){t.saving=!0,_();try{await c().rename(t.id,n),i===t&&(i=null),a=null,o=null}catch{if(i!==t)return;t.saving=!1,o=e.getLabels().renameFailed}_()}}async function p(){let t=i;if(!(t?.kind!==`delete`||t.saving)){t.saving=!0,_();try{await c().remove(t.id),i===t&&(i=null),a=null,e.onDeleted(t.id)}catch{if(i!==t)return;t.saving=!1,a=e.getLabels().deleteFailed}_()}}function m(e){let t=$(`li`,`wui-chat-history-row wui-chat-history-row--editing`),n=$(`input`,`wui-chat-history-input`,{type:`text`,"aria-label":e.conversationTitle,maxlength:String(f4)});n.value=i.draft,n.addEventListener(`input`,()=>{i.draft=n.value,r.disabled=i.saving||!i.draft.trim()}),n.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),f()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),d())});let r=p4(e.renameSave,()=>f(),`primary`);if(r.disabled=i.saving||!i.draft.trim(),t.append(n,r,p4(e.cancel,()=>d(),`ghost`)),o!==null){let e=$(`p`,`wui-chat-history-error`,{role:`alert`});e.textContent=o,t.append(e)}return s&&(s=!1,queueMicrotask(()=>n.focus())),t}function h(e){let t=$(`li`,`wui-chat-history-row wui-chat-history-row--confirm`),n=$(`p`);n.textContent=e.deleteConfirmTitle;let r=$(`p`);r.textContent=e.deleteConfirmMessage;let a=p4(e.deleteConfirm,()=>p(),`danger`);return a.disabled=i.saving,t.append(n,r,a,p4(e.cancel,()=>d(),`ghost`)),t}function g(t,n,r){if(i?.id===t.publicId&&i.kind===`rename`)return m(n);if(i?.id===t.publicId&&i.kind===`delete`)return h(n);let a=$(`li`,`wui-chat-history-row`),o=$(`button`,`wui-chat-history-open`,{type:`button`}),s=$(`span`,`wui-chat-history-title`);s.textContent=t.title||n.untitled;let c=$(`span`,`wui-chat-history-time`);return c.textContent=rt(t.lastActivityDateTimeUtc),o.append(s,c),o.addEventListener(`click`,()=>e.onOpen(t.publicId)),a.append(o),r.Rename&&a.append(b$(n.rename,`pencil`,()=>l(t))),r.Delete&&a.append(b$(n.deleteChat,`trash`,()=>u(t))),a}function _(){let r=e.getLabels(),i=e.getFeatures(),o=n?n.getState():{items:[],loading:!1,error:null,hasMore:!1},s=[];if(o.error||a){let e=$(`p`,`wui-chat-history-error`,{role:`alert`});o.error?(e.append(document.createTextNode(r.loadFailed),document.createTextNode(` `)),e.append(p4(r.retry,()=>c().load(),`outline`))):e.textContent=a,s.push(e)}if(o.loading&&o.items.length===0){let e=$(`p`,`wui-chat-history-empty`,{role:`status`});e.textContent=r.loadingConversation,s.push(e)}if(o.items.length===0&&!o.loading&&!o.error){let e=$(`p`,`wui-chat-history-empty`),t=$(`span`);t.textContent=r.historyEmptyTitle;let n=$(`span`);n.textContent=r.historyEmptyText,e.append(t,n),s.push(e)}if(o.items.length>0){let e=$(`ul`,`wui-chat-history-list`,{"aria-label":r.history});e.append(...o.items.map(e=>g(e,r,i))),s.push(e)}o.hasMore&&!o.loading&&s.push(p4(r.loadMore,()=>c().loadMore(),`outline`)),t.replaceChildren(...s)}function v(){t.hidden=!1,c().load().catch(()=>{}),_()}function y(){t.hidden=!0}function b(){r?.(),r=null,n?.dispose(),n=null}return{el:t,show:v,hide:y,paint:_,dispose:b}}var h4=new Set([`GET`,`HEAD`]);function g4(){let e=document.querySelector(`meta[name="wui-csrf"]`),t=e?.getAttribute(`content`);return t?{token:t,header:e.getAttribute(`data-header`)||`RequestVerificationToken`}:null}async function _4(e){let t=await e.text();if(t){if((e.headers.get(`content-type`)||``).includes(`json`))try{return JSON.parse(t)}catch{return t}return t}}async function v4(e,t){let n=new TextDecoder,r=e.body.getReader(),i=``;for(;;){let{done:a,value:o}=await r.read();if(a)break;i+=n.decode(o,{stream:!0}),t({event:{target:{responseText:i,status:e.status}}})}return i+=n.decode(),i}function y4({fetch:e=(...e)=>globalThis.fetch(...e)}={}){async function t(t,n,r,i={}){let a={...i.headers},o;if(typeof FormData<`u`&&r instanceof FormData){for(let e of Object.keys(a))e.toLowerCase()===`content-type`&&delete a[e];o=r}else r!==void 0&&(a[`Content-Type`]=`application/json`,o=JSON.stringify(r));if(!h4.has(t)){let e=g4();e&&(a[e.header]=e.token)}let s=i.signal,c=s,l,u,d=()=>l.abort(s.reason);i.timeout>0&&(l=new AbortController,c=l.signal,s?.aborted?l.abort(s.reason):s?.addEventListener(`abort`,d,{once:!0}),u=setTimeout(()=>l.abort(new DOMException(`The request timed out.`,`TimeoutError`)),i.timeout));try{let r=await e(n,{method:t,headers:a,body:o,signal:c,credentials:`same-origin`});if(!r.ok){let e=Error(`Request failed with status ${r.status}`);throw e.response={status:r.status,data:await _4(r)},e}let s=i.responseType===`arraybuffer`,l=!s&&typeof i.onDownloadProgress==`function`&&r.body,u;return u=s?await r.arrayBuffer():l?await v4(r,i.onDownloadProgress):await _4(r),{data:u,status:r.status}}finally{clearTimeout(u),s?.removeEventListener(`abort`,d)}}return{get:(e,n)=>t(`GET`,e,void 0,n),post:(e,n,r)=>t(`POST`,e,n,r),put:(e,n,r)=>t(`PUT`,e,n,r),delete:(e,n)=>t(`DELETE`,e,void 0,n)}}function b4(e){let t=null,n=!1,r=!1,i=$(`div`,`wui-chat-nudge`,{role:`status`});i.hidden=!0;let a=$(`button`,`wui-chat-nudge-text`,{type:`button`}),o=$(`button`,`wui-chat-nudge-close`,{type:`button`});o.append(_$(`x`,14)),i.append(a,o);function s(){clearTimeout(t),t=null}function c(){s(),r=!0,i.hidden=!0}a.addEventListener(`click`,()=>{i.hidden=!0,e.onActivate()}),o.addEventListener(`click`,()=>{c(),e.onDismiss()});function l(e){s(),r||n||(t=setTimeout(()=>{t=null,a.textContent=e.text,o.setAttribute(`aria-label`,e.label),i.hidden=!1,n=!0},e.delaySeconds*1e3))}function u(){s(),i.remove()}return{el:i,schedule:l,cancel:s,dismiss:c,isShown:()=>n,destroy:u}}var x4=6e4,S4=60*x4,C4=48*S4;function w4(e){if(typeof e!=`string`||e===``)return null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function T4(e,t=Date.now(),n=void 0){let r=w4(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<x4)return s.format(0,`second`);if(a<S4){let e=Math.floor(a/x4);return s.format(o?-e:e,`minute`)}if(a<C4){let e=Math.floor(a/S4);return s.format(o?-e:e,`hour`)}return new Intl.DateTimeFormat(n,{day:`numeric`,month:`short`,year:`numeric`}).format(new Date(r))}function E4(e,t=void 0){let n=w4(e);return n===null?``:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(n))}function D4(e){let{list:t,getLabels:n,getFeatures:r,onOpen:i}=e,a=e.now??(()=>Date.now()),o=$(`div`,`wui-chat-empty-rows wui-chat-empty-rows--past`);o.hidden=!0;let s=!1;function c(e,t){let n=$(`button`,`wui-chat-empty-row`,{type:`button`}),r=$(`span`,`wui-chat-empty-row-title`);r.textContent=e.title||t.earlierChat;let o=$(`span`,`wui-chat-empty-row-time`,{title:E4(e.lastActivityDateTimeUtc)});return o.textContent=T4(e.lastActivityDateTimeUtc,a()),n.append(r,o),n.addEventListener(`click`,()=>i(e.publicId)),n}function l(){if(s)return;let e=t.getState().items;if(r().History!==!0||e.length===0){o.replaceChildren(),o.hidden=!0;return}let i=n();o.replaceChildren(...e.slice(0,20).map(e=>c(e,i))),o.hidden=!1}let u=t.subscribe(l);return{el:o,refresh(){r().History===!0&&t.load().catch(()=>{})},paint:l,dispose(){s=!0,u()}}}var O4=`https://www.google.com/recaptcha/api.js?render=`,k4=new Map;function A4(e){let t=k4.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=O4+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{k4.delete(e),n(Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return k4.set(e,n),n}async function j4(e,t){let n=await A4(e);await new Promise(e=>n.ready(e));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var M4=`data-wui-chat-docked`,N4=`--wui-chat-docked-width`,P4=420,F4=new Set;function I4(e,t){let n=document.documentElement;n.setAttribute(M4,e),n.style.setProperty(N4,t)}function L4(){let e=document.documentElement;e.removeAttribute(M4),e.style.removeProperty(N4)}function R4(e){let t=D$({...e,layout:`docked`,role:`dialog`,launcher:!0}),n={},r=e.position,i=!1,a=null,o=()=>`${Math.round(t.panel.getBoundingClientRect().width)||P4}px`;function s(){F4.add(n),I4(r,o()),typeof ResizeObserver==`function`&&(a=new ResizeObserver(()=>document.documentElement.style.setProperty(N4,o())),a.observe(t.panel))}function c(){a?.disconnect(),a=null,F4.delete(n),F4.size===0&&L4()}function l(e){t.setOpen(e),e&&!i?(i=!0,s()):!e&&i&&(i=!1,c())}function u(e){t.setAppearance(e),e.position!==void 0&&(r=e.position,i&&document.documentElement.setAttribute(M4,r))}function d(){l(!1)}return{...t,setOpen:l,setAppearance:u,destroy:d}}function z4(e){return D$({...e,layout:`embedded`,role:`region`,launcher:!1})}var B4=`wchat:peeked`,V4=576,H4=200;function U4(e){let t=D$({...e,layout:`launcher`,role:`dialog`,launcher:!0}),{root:n,panel:r,nudgeHost:i,launcherButton:a}=t,o={peek:!1,peekSeconds:3,hideWhileOpen:!1};a.dataset.state=`closed`;let s=!1,c=!1,l=null,u=null;function d(){!o.peek||s||c||i.dataset.launcher!==`idle`||globalThis.innerWidth<V4||globalThis.sessionStorage.getItem(B4)!==null||(globalThis.sessionStorage.setItem(B4,`1`),i.dataset.launcher=`peeking`,l=setTimeout(()=>{l=null,i.dataset.launcher===`peeking`&&(i.dataset.launcher=`idle`)},o.peekSeconds*1e3))}i.addEventListener(`animationend`,e=>{e.target===i&&i.dataset.launcher===`idle`&&d()});function f(e){if(e!==c){if(c=e,clearTimeout(l),l=null,e)clearTimeout(u),u=null,o.hideWhileOpen?(i.dataset.launcher=`hidden`,i.toggleAttribute(`inert`,!0)):i.dataset.launcher===`peeking`&&(i.dataset.launcher=`idle`);else if(o.hideWhileOpen){let e=r.contains(document.activeElement);u=setTimeout(()=>{u=null,i.toggleAttribute(`inert`,!1),i.dataset.launcher=`idle`,e&&a.focus()},H4)}}a.dataset.state=e?`open`:`closed`,t.setOpen(e)}function p(e){e.reduced!==void 0&&(s=!!e.reduced),e.peek!==void 0&&(o.peek=e.peek),e.peekSeconds!==void 0&&(o.peekSeconds=e.peekSeconds),e.hideWhileOpen!==void 0&&(o.hideWhileOpen=e.hideWhileOpen),e.phoneMode!==void 0&&n.classList.toggle(`wui-chat--sheet`,e.phoneMode===`Sheet`),e.sheetHeightDvh!==void 0&&n.style.setProperty(`--wui-chat-sheet-height`,`${e.sheetHeightDvh}dvh`),e.sheetMaxHeightPx!==void 0&&n.style.setProperty(`--wui-chat-sheet-max-height`,`${e.sheetMaxHeightPx}px`),t.setAppearance(e),!o.hideWhileOpen&&i.dataset.launcher===`hidden`&&!c&&(i.dataset.launcher=`idle`),i.dataset.launcher===`idle`&&d()}return{...t,setOpen:f,setAppearance:p}}function W4(e){return D$({...e,layout:`full-page`,role:`region`,launcher:!1})}var G4=new Set([`Agent`,`Customer`]);function K4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-typing`,e.setAttribute(`aria-hidden`,`true`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-typing-orb`;let n=document.createElement(`span`);n.className=`wui-chat-loader-typing-dots`;for(let e=0;e<3;e++){let e=document.createElement(`span`);e.className=`wui-chat-loader-typing-dot`,n.append(e)}e.append(t,n);function r({active:n,reduced:r,authorKind:i}){e.hidden=!n,e.classList.toggle(`wui-chat-loader--reduced`,r===!0),t.hidden=G4.has(i)}function i(){e.remove()}return{el:e,update:r,destroy:i}}var q4=3,J4={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function Y4(e){let t=$(`h2`,`wui-chat-greeting`),n=$(`div`,`wui-chat-empty-hero`);n.append($(`span`,`wui-chat-orb`,{"aria-hidden":`true`}),t);let r=$(`div`,`wui-chat-empty-extra`);r.hidden=!0;let i=$(`div`,`wui-chat-starters`,{role:`group`}),a=$(`div`,`wui-chat-empty-rows`),o=$(`div`,`wui-chat-empty-past`),s=$(`div`,`wui-chat-empty`,{role:`group`}),c=K4();s.append(c.el,n,r,i,a,o);let l=null;function u(t,n){let r=$(`button`,[`wui-chat-starter`,J4[t.variant]??``].filter(Boolean).join(` `),{type:`button`});return r.style.setProperty(`--wui-chat-i`,String(n)),t.icon&&r.append(_$(t.icon,16)),r.append(document.createTextNode(t.label)),r.addEventListener(`click`,()=>e.onStarter(t)),r}function d(t,n){let r=$(`button`,`wui-chat-empty-row`,{type:`button`}),i=$(`span`,`wui-chat-empty-row-label`);i.textContent=n.resumeLast;let a=$(`span`,`wui-chat-empty-row-title`,{title:t.title||n.untitled});a.textContent=t.title||n.untitled;let o=$(`span`,`wui-chat-empty-row-time`);return o.textContent=rt(t.lastActivityDateTimeUtc),r.append(i,a,o),r.addEventListener(`click`,()=>e.onResume()),r}function f(t,n,r){let i=r?$(`button`,`wui-chat-empty-row`,{type:`button`}):$(`span`,`wui-chat-empty-row`),a=$(`span`,`wui-chat-empty-row-label`);a.textContent=n.ticketAria(t.number);let o=$(`span`,`wui-chat-empty-row-title`);o.textContent=t.subject;let s=$(`span`,`wui-chat-empty-row-status`);return s.textContent=B$(t.status,n),i.append(a,o,s),r&&i.addEventListener(`click`,()=>e.onTicket(t)),i}function p(e,t){if(e.features?.OpenTickets!==!0||!e.openTickets?.length)return null;let n=$(`div`,`wui-chat-open-tickets`,{role:`group`,"aria-label":t.openTickets});return n.append(...e.openTickets.slice(0,q4).map(n=>f(n,t,e.ticketsClickable===!0))),n}function m(e){let{labels:n}=e;t.textContent=e.greeting??``,s.setAttribute(`aria-label`,n.emptyTitle);let r=e.starters??[];i.setAttribute(`aria-label`,n.starters),i.hidden=!e.showStarters||r.length===0,i.replaceChildren(...r.map(u));let o=e.resume??null,c=p(e,n);a.hidden=o===null&&c===null,a.replaceChildren(...[o===null?null:d(o,n),c].filter(Boolean))}function h(e){clearTimeout(l),s.classList.remove(`wui-chat-empty--revealed`),s.classList.add(`wui-chat-empty--intro`),c.update({active:!0,reduced:!1,authorKind:`Assistant`}),l=setTimeout(()=>{l=null,c.update({active:!1,reduced:!1,authorKind:`Assistant`}),s.classList.replace(`wui-chat-empty--intro`,`wui-chat-empty--revealed`)},e)}return{el:s,paint:m,intro:h,extraHost:r,pastHost:o}}function X4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-orb`;let t=document.createElement(`span`);t.className=`wui-chat-loader-orb-mark`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-orb-glow`,n.setAttribute(`aria-hidden`,`true`);let r=document.createElement(`span`);r.className=`wui-chat-loader-orb-disc`,r.setAttribute(`aria-hidden`,`true`),t.append(n,r);let i=document.createElement(`span`);return i.className=`wui-chat-loader-orb-label`,e.append(t,i),{el:e,render(e){i.textContent!==e.label&&(i.textContent=e.label)}}}var Z4=150,Q4=1800;function $4(){let e=document.createElement(`div`);e.className=`wui-chat-loader-phrases`;let t=document.createElement(`span`);t.className=`wui-chat-loader-phrases-orb`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`span`);n.className=`wui-chat-loader-phrases-stage`,e.append(t,n);let r=null,i=null;function a(){return e.closest(`.wui-chat-loader`)?.classList.contains(`wui-chat-loader--reduced`)===!0}function o(e){if(e.label===r)return;r=e.label;let t=i,o=document.createElement(`span`);o.className=`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,o.textContent=e.label,o.style.animationDelay=`-${Math.round(performance.now()%Q4)}ms, 0s`,n.append(o),i=o,t&&(t.classList.remove(`wui-chat-loader-phrases-text--in`),t.classList.add(`wui-chat-loader-phrases-text--out`),t.style.animationDelay=`-${Math.round(performance.now()%Q4)}ms, 0s`,a()?t.remove():setTimeout(()=>t.remove(),Z4))}return{el:e,render:o}}var e3=[`95%`,`80%`,`60%`];function t3(){let e=document.createElement(`div`);e.className=`wui-chat-loader-skeleton`;let t=document.createElement(`div`);t.className=`wui-chat-loader-skeleton-label`;let n=document.createElement(`div`);n.className=`wui-chat-loader-skeleton-body`;let r=document.createElement(`span`);r.className=`wui-chat-loader-skeleton-avatar`,r.setAttribute(`aria-hidden`,`true`),n.append(r);for(let e of e3){let t=document.createElement(`span`);t.className=`wui-chat-loader-skeleton-line`,t.setAttribute(`aria-hidden`,`true`),t.style.width=e,n.append(t)}return e.append(t,n),{el:e,render(e){t.textContent!==e.label&&(t.textContent=e.label)}}}var n3=`http://www.w3.org/2000/svg`;function r3(e){if(e===`done`){let e=document.createElementNS(n3,`svg`);e.setAttribute(`viewBox`,`0 0 16 16`),e.setAttribute(`class`,`wui-chat-loader-steps-check`);let t=document.createElementNS(n3,`path`);return t.setAttribute(`d`,`M3 8.5 6.5 12 13 4.5`),t.setAttribute(`pathLength`,`1`),e.append(t),e}let t=document.createElement(`span`);return t.className=e===`active`?`wui-chat-loader-steps-ring`:`wui-chat-loader-steps-dot`,t}function i3(){let e=document.createElement(`div`);e.className=`wui-chat-loader-steps`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-pill`;let n=document.createElement(`ol`);n.className=`wui-chat-loader-steps-list`,e.append(t,n);let r=[];function i(){let e=document.createElement(`li`);e.className=`wui-chat-loader-steps-item`;let t=document.createElement(`span`);t.className=`wui-chat-loader-steps-icon`,t.setAttribute(`aria-hidden`,`true`);let i=document.createElement(`span`);i.className=`wui-chat-loader-steps-text`,e.append(t,i);let a={li:e,icon:t,text:i,state:null};return r.push(a),n.append(e),a}function a(e){let a=e.steps.length===0;for(t.hidden=!a,n.hidden=a,a&&t.textContent!==e.label&&(t.textContent=e.label),e.steps.forEach((t,n)=>{let a=r[n]??i();a.text.textContent!==t&&(a.text.textContent=t);let o=n<e.activeIndex?`done`:n===e.activeIndex?`active`:`pending`;a.state!==o&&(a.state=o,a.li.dataset.state=o,a.icon.replaceChildren(r3(o)))});r.length>e.steps.length;)r.pop().li.remove()}return{el:e,render:a}}var a3={Steps:i3,Phrases:$4,Orb:X4,Skeleton:t3},o3=500;function s3(){let e=document.createElement(`div`);e.className=`wui-chat-loader`,e.setAttribute(`role`,`status`),e.hidden=!0;let t=document.createElement(`span`);t.className=`wui-chat-loader-avatar`,t.setAttribute(`aria-hidden`,`true`);let n=document.createElement(`div`);n.className=`wui-chat-loader-body`;let r=document.createElement(`span`);r.className=`visually-hidden`,e.append(t,n,r);let i=null,a=null,o=0,s=null,c=0,l=null,u=!1;function d(){s!==null&&clearInterval(s),s=null}function f(){e.isConnected?(o+=1,p()):d()}function p(){if(!a||!i)return;let t=At(i.style,i.steps,i.phrases,o);a.render(t),e.setAttribute(`aria-label`,t.label)}function m(){l!==null&&clearTimeout(l),l=null,u=!1,r.textContent=``}function h(e){!u&&l===null&&e&&(l=setTimeout(()=>{l=null,u=!0,r.textContent=e},o3))}function g(t){if(!t.active)i=null,e.hidden=!0,e.removeAttribute(`data-loading`),d(),m();else{if(!Object.hasOwn(a3,t.style))throw Error(`Unknown loader style. Use Steps, Phrases, Orb or Skeleton.`);if(!(t.intervalMs>0))throw Error(`Loader intervalMs must be a positive number.`);if(i={...t,steps:t.steps??[],phrases:t.phrases??[]},e.hidden=!1,e.setAttribute(`data-loading`,`true`),e.classList.toggle(`wui-chat-loader--reduced`,t.reduced===!0),!a||a.style!==t.style){let r=a3[t.style]();n.replaceChildren(r.el),a={style:t.style,render:r.render},e.dataset.style=t.style,o=0}h(t.announce),t.reduced===!0?(d(),o=0):(s===null||c!==t.intervalMs)&&(d(),c=t.intervalMs,s=setInterval(f,c)),p()}}function _(){d(),m(),a=null,i=null,e.remove()}return{el:e,update:g,destroy:_}}var c3=`data-wui-printing`,l3=`data-wui-print-hide`,u3=`data-wui-print-path`,d3=`data-wui-print-target`,f3=new Set([`script`,`style`,`link`,`template`]),p3=null;function m3(){if(p3!==null){for(let e of p3.marked)e.removeAttribute(l3),e.removeAttribute(u3),e.removeAttribute(d3);p3.heading.remove(),document.documentElement.removeAttribute(c3),window.removeEventListener(`afterprint`,p3.onAfterPrint),p3=null}}function h3(e,t,n,r,i){m3();let a=e.querySelector(`.wui-chat-panel`);if(a===null)throw Error(`print needs the wui-chat root`);let o=[];for(let e=a;e!==document.documentElement;e=e.parentElement){e.setAttribute(u3,``),o.push(e);for(let t of e.parentElement.children)t===e||f3.has(t.localName)||(t.setAttribute(l3,``),o.push(t))}for(let e of n)e.setAttribute(l3,``),o.push(e);r!==null&&(r.setAttribute(d3,``),o.push(r));let s=document.createElement(`div`);s.className=`wui-chat-print-heading`;let c=document.createElement(`h1`);c.textContent=i.title;let l=document.createElement(`p`);l.textContent=i.printedOn,s.append(c,l),a.prepend(s),document.documentElement.setAttribute(c3,t);let u=()=>m3();window.addEventListener(`afterprint`,u,{once:!0}),p3={marked:o,heading:s,onAfterPrint:u};try{window.print()}catch(e){throw m3(),e}}function g3(e,t){h3(e,`conversation`,[],null,t)}function _3(e,t,n){if(!e.contains(t))throw Error(`printReply needs a message inside the wui-chat root`);h3(e,`reply`,Array.from(e.querySelectorAll(`li.wui-chat-message`)).filter(e=>e!==t),t,n)}function v3(){return typeof navigator<`u`&&typeof navigator.share==`function`}async function y3({title:e,text:t}){if(!v3())return`failed`;try{return await navigator.share({title:e,text:t}),`shared`}catch(e){return e?.name===`AbortError`?`cancelled`:`failed`}}var b3=new Set([`Assistant`,`Agent`,`Script`]),x3=new WeakMap;function S3(e,t,n){let{labels:r,features:i,title:a,busy:o}=n;if(it(t.parts)!==``){if(i.Share&&v3()){let n=y$(`ghost`,r.share,`share`,async()=>{let e=E3([t],i,r,a,!1);e!==``&&await y3({title:a,text:e})===`failed`&&A3(n.parentElement,r.shareFailed)});n.disabled=o===!0,e.append(n)}if(i.Print){let t=y$(`ghost`,r.print,`printer`,()=>{try{_3(t.closest(`.wui-chat`),t.closest(`li.wui-chat-message`),{title:a,printedOn:O3(r)})}catch{k3(t,r.printFailed)}});e.append(t)}}}function C3(e,t,n){if(t.streaming||t.thinking||t.loading||t.conversationId===null||t.messages.filter(e=>e.stored&&b3.has(e.author.kind)&&it(e.parts)!==``).length===0){e.hidden=!0;return}let{labels:r,features:i}=n,a=!!i.Share&&v3(),o=!!i.Print;if(!a&&!o){e.hidden=!0;return}let s=[a,o,t.messages.length,r.shareConversation,r.printConversation].join(`|`);e.dataset.sig!==s&&(e.dataset.sig=s,e.replaceChildren(),a&&e.append(w3(e,r,i,n)),o&&e.append(T3(e,r,n))),e.hidden=!1}function w3(e,t,n,r){return y$(`ghost`,t.shareConversation,`share`,async()=>{let i=r.getState(),a=D3(i,r);await y3({title:a,text:E3(i.messages.filter(e=>e.stored),n,t,a,!0)})===`failed`&&A3(e,t.shareFailed)})}function T3(e,t,n){let r=y$(`ghost`,t.printConversation,`printer`,()=>{try{g3(e.closest(`.wui-chat`),{title:D3(n.getState(),n),printedOn:O3(t)})}catch{k3(r,t.printFailed)}});return r}function E3(e,t,n,r,i){return Cn(xn(e,{labels:n,title:r,figureText:t.FigureText}),{heading:i,speakers:i})}function D3(e,t){return typeof e.title==`string`&&e.title!==``?e.title:t.title}function O3(e){return e.printedOn(rt(new Date().toISOString()))}function k3(e,t){let n=e.lastChild,r=x3.get(n);r?clearTimeout(r.timer):r={original:n.data},n.data=t,r.timer=setTimeout(()=>{n.data=r.original,x3.delete(n)},On),x3.set(n,r)}function A3(e,t){if(!e)return;let n=document.createElement(`span`);n.className=`wui-chat-action-notice`,n.setAttribute(`role`,`status`),n.textContent=t,e.append(n),setTimeout(()=>n.remove(),On)}function j3({voice:e,getLabels:t,message:n}){if(n.streaming||!e.canSpeak()||J2(n.parts)===``)return null;let r=e.getStatus(),i=r.mode===`Speaking`&&r.messageId===n.id,a=t(),o=i?a.readAloudStop:a.readAloud,s=$(`button`,`wui-chat-action-btn wui-chat-speak`,{type:`button`,"aria-pressed":String(i),"aria-label":o,title:o});return s.append(T2(i?`stop`:`speaker`,16)),s.addEventListener(`click`,()=>{e.toggleSpeak(n.id,n.parts)}),s}function M3({voice:e,getLabels:t,message:n}){let r=e.getStatus().note;if(r?.code!==`SpeakFailed`||r.messageId!==n.id)return null;let i=$(`span`,`wui-chat-action-notice`,{role:`status`});return i.textContent=Y2(r,t()),i}var N3=new Set([`Assistant`,`Agent`]),P3=new Set([`Assistant`,`Agent`,`Script`]),F3=new Set([`Visitor`,`Customer`]),I3=48,L3=120,R3={author:{kind:`Assistant`}},z3={warning:`alert-triangle`,danger:`alert-circle`};function B3(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=I3}function V3(e){let{kind:t,displayName:n}=e.author;return t===`Agent`?`Agent:${n??``}`:t===`Script`?`Assistant`:t}function H3(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function U3(e){let t=e.textContent.trim();t&&!e.hasAttribute(`aria-label`)&&(e.setAttribute(`aria-label`,t),e.title=t)}function W3(e){return e.reduced===!0}function G3(e,t,n){let r=$(`button`,`${v$(`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-label":e,title:e}),i=$(`span`);return i.textContent=e,r.append(_$(t,14),i),r.addEventListener(`click`,n),{node:r,text:i}}function K3(e,t){return e.profile?.assistant.name??t.panelTitle}function q3(e,t){return e.author.displayName==null?e.author.kind===`Visitor`||e.author.kind===`Customer`?t.you:e.author.kind===`Agent`?t.agent:t.assistant:e.author.displayName}function J3(e){let t=$(`ol`,`wui-chat-thread`),n=$(`div`,`wui-chat-log`,{role:`log`,"aria-live":`polite`});n.append(t);let r=s3(),i=$(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`),a=$(`div`,`wui-chat-loader-slot`);a.append(r.el),i.append(a);let o=!1,s=null,c=$(`li`,`wui-chat-message wui-chat-message--assistant wui-chat-message--greeting`,{"data-run-start":``,"data-restored":``}),l=$(`div`,`wui-chat-message-body`),u=$(`p`,`wui-chat-text`);l.append(u),c.append(l);let d=$(`li`,`wui-chat-conversation-actions`);d.hidden=!0;let f=$(`button`,`wui-chat-jump`,{type:`button`}),p=$(`div`,`wui-chat-jump-slot`);p.hidden=!0,p.append(f);let m=null,h=!0,g=null,_=null,v=new Map,y=``,b=null;function x(e,t,n){return n[e.kind]?{kind:e.kind,part:e,tag:n[e.kind]}:{kind:`Notice`,part:{kind:`Notice`,code:`NeedsNewerApp`,text:t.needsNewerApp},tag:n.Notice}}function S(t,n,r){let i=document.createElement(t);return i.message=r,i.turn=e.makeTurnApi(r.id),i.part=n,i}function C(e){return $(`div`,`wui-chat-part wui-chat-part--${e.toLowerCase()}`)}function w(e,t,n,r,i){e.parts=[];let a=[],o=e=>{let i=x(e,n,r),a=C(i.kind);return a.append(S(i.tag,i.part,t)),a};for(let e of i(t))if(Array.isArray(e)){let t=$(`div`,`wui-chat-part-group`);t.append(...e.map(o)),a.push(t)}else a.push(o(e));e.body.replaceChildren(...a)}function T(t,n,r,i){let a=[];n.parts.forEach((o,s)=>{let c=x(o,r,i),l=t.parts[s];if(l&&l.kind===c.kind&&l.tag===c.tag){l.part!==c.part&&(l.element.message=n,l.element.turn=e.makeTurnApi(n.id),l.element.part=c.part,l.part=c.part),a.push(l);return}let u=C(c.kind),d=S(c.tag,c.part,n);u.append(d),a.push({kind:c.kind,tag:c.tag,part:c.part,element:d,wrapper:u})}),t.parts=a,E(t.body,a.map(e=>e.wrapper))}function E(e,t){let n=new Set(t);for(let t of[...e.children])n.has(t)||t.remove();t.forEach((t,n)=>{e.children[n]!==t&&e.insertBefore(t,e.children[n]??null)})}function D(e,t,n){let r=$(`div`,`wui-chat-rating`,{role:`group`,"aria-label":`${n.rateUp}/${n.rateDown}`});for(let[i,a,o]of[[`Up`,n.rateUp,`thumbs-up`],[`Down`,n.rateDown,`thumbs-down`]]){let s=t.rating===i,c=$(`button`,`${v$(s?`neutral`:`ghost`,`sm`)} wui-chat-action-btn`,{type:`button`,"aria-pressed":String(s),"data-rating":i,"aria-label":a,title:a}),l=$(`span`);l.textContent=a,c.append(_$(o,14),l),c.addEventListener(`click`,()=>O(e,t,i,n)),r.append(c)}if(e.ratingNote){let t=$(`span`,null,{role:`status`});t.textContent=e.ratingNote,r.append(t)}return r}async function O(t,n,r,i){try{await e.onRate(n.id,r),t.ratingNote=i.rated}catch{t.ratingNote=i.ratingFailed}b&&ue(b.state,b.context)}function k(t,n,r,i,a){let{labels:o}=i,s=r.features,c=n.author.kind,l=it(n.parts),u=[];if(s.Copy&&P3.has(c)&&l){let e=G3(o.copy,`copy`,async()=>{await kn(l)&&(e.text.textContent=o.copied,e.node.dataset.done=``,e.node.setAttribute(`aria-label`,o.copied),e.node.title=o.copied,clearTimeout(t.copyTimer),t.copyTimer=setTimeout(()=>{e.text.textContent=o.copy,delete e.node.dataset.done,e.node.setAttribute(`aria-label`,o.copy),e.node.title=o.copy},On))});u.push(e.node)}let d=e.getVoice?.();if(d&&P3.has(c)){let e=j3({voice:d,getLabels:()=>o,message:n});e&&u.push(e);let t=M3({voice:d,getLabels:()=>o,message:n});t&&u.push(t)}if(P3.has(c)){let e=$(`div`);S3(e,n,{labels:o,features:s,title:K3(r,o),busy:r.streaming||r.thinking});for(let t of e.childNodes)U3(t);u.push(...e.childNodes)}let f=r.messages.some(e=>e.author.kind===`Visitor`&&e.stored);a&&c===`Assistant`&&!r.streaming&&!r.thinking&&s.Regenerate&&f&&u.push(G3(o.regenerate,`refresh`,()=>e.onRegenerate()).node);let p=r.messages.findLast(e=>e.author.kind===`Visitor`&&e.stored);s.Edit&&p?.id===n.id&&!r.streaming&&!r.thinking&&u.push(G3(o.edit,`pencil`,()=>e.getSession().startEdit(n.id)).node),s.Rating&&n.stored&&N3.has(c)&&u.push(D(t,n,o)),t.actions.hidden=u.length===0,t.actions.replaceChildren(...u)}function A(e){let t=v.get(e.id);if(t)return t;let n=$(`li`,`wui-chat-message`),r=$(`span`,`wui-chat-author visually-hidden`),i=$(`div`,`wui-chat-message-body`),a=$(`div`,`wui-chat-message-actions`);n.append(r,i,a);let o={li:n,author:r,body:i,actions:a,head:null,parts:[],copyTimer:null,ratingNote:null};return v.set(e.id,o),o}function j(e,t,n,r){let i=n?.author.kind===`Agent`&&t.author.kind===`Agent`&&(n.author.displayName??``)===(t.author.displayName??``);e.head?.remove(),e.head=t.author.kind===`Agent`&&!i?L$(t.author,r):null,e.head&&e.li.insertBefore(e.head,e.body)}function ee(t,n,r,i,a,o){let{labels:s}=i;t.li.className=`wui-chat-message wui-chat-message--${n.author.kind.toLowerCase()}`,t.li.toggleAttribute(`data-restored`,n.restored===!0),t.li.toggleAttribute(`data-run-start`,!o||V3(o)!==V3(n)),n.streaming?t.li.setAttribute(`aria-busy`,`true`):t.li.removeAttribute(`aria-busy`),t.author.textContent=`${q3(n,s)}: `,j(t,n,o,s);let c=e.getRenderers(),l=e.getLayoutParts();typeof l==`function`?w(t,n,s,c,l):T(t,n,s,c),n.streaming?(t.actions.hidden=!0,t.actions.replaceChildren()):k(t,n,r,i,a)}function te(e,t){let n=$(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--notice`),r=$(`div`,`wui-chat-notice wui-chat-notice--${e}`,{role:e===`danger`?`alert`:`status`}),i=$(`span`,`wui-chat-notice-icon`,{"aria-hidden":`true`});i.append(_$(z3[e],16));let a=$(`div`,`wui-chat-notice-body`),o=$(`span`,`wui-chat-notice-text`);return o.textContent=t,a.append(o),r.append(i,a),n.append(r),n}function ne(e,t){let n=e.resetsDateTimeUtc?` ${t.dailyLimitRefresh(E4(e.resetsDateTimeUtc))}`:``;return te(`warning`,`${e.message}${n}`)}function re(t,n){let{labels:r}=n,i=t.turnError?.code??``;if(i===`daily_limit`)return ne(t.turnError,r);if(i.endsWith(`feature_off`))return te(`danger`,t.turnError.message||r.stopped);let a=$(`li`,`wui-chat-message wui-chat-message--system wui-chat-message--error`),o=$(`p`,`wui-chat-error`,{role:`alert`});o.textContent=t.turnError?.message||r.stopped;let s=_$(`alert-circle`,16);if(s.setAttribute(`aria-hidden`,`true`),a.append(s,o),t.features.Retry){let t=$(`div`,`wui-chat-message-actions`);t.append(G3(r.retry,`rotate-ccw`,()=>e.onRetry()).node),a.append(t)}return a}function ie(){return t.closest(`.wui-chat`)}function ae(){return t.closest(`.wui-chat-body`)??H3(t)}function oe(e){ie()?.classList.toggle(`wui-chat--scrolled`,e.scrollTop>0),B3(e)&&(p.hidden=!0)}function se(){h=B3(m),oe(m)}function ce(e){n.nextElementSibling!==p&&n.parentNode&&n.after(p),e!==m&&(m?.removeEventListener(`scroll`,se),m=e,e.addEventListener(`scroll`,se,{passive:!0}),!g&&typeof ResizeObserver==`function`&&(g=new ResizeObserver(()=>{h&&m&&(m.scrollTop=m.scrollHeight)}),g.observe(t)))}f.addEventListener(`click`,()=>{let e=ae(),t=b?.context.reduced===!0;e?.scrollTo({top:e.scrollHeight,behavior:t?`auto`:`smooth`}),p.hidden=!0,f.blur()});function le(e,t){let n=e.messages.at(-1),r=n?`${n.id}|${it(n.parts).length}`:``;if(r===y)return;let i=y===``||e.conversationId!==_;y=r,_=e.conversationId;let a=ae();a&&(ce(a),i||t||F3.has(n?.author.kind)?(a.scrollTop=a.scrollHeight,p.hidden=!0,h=!0):(p.hidden=!1,h=!1),oe(a))}function ue(a,l){b={state:a,context:l};let{labels:p}=l;n.setAttribute(`aria-label`,p.thread),f.textContent=p.newMessages??`New messages`;let m=ae();m&&ce(m);let h=m===null||m.clientHeight===0||B3(m),g=[],_=new Set,y=a.messages.filter(e=>!(e.streaming&&e.parts.length===0)),x=y.length>0&&F3.has(y[0].author.kind)&&a.greeting?a.greeting:null;x&&(u.textContent=x,g.push(c)),y.forEach((e,t)=>{let n=A(e);_.add(e.id);let r=y[t-1]??(x?R3:null);ee(n,e,a,l,t===y.length-1,r),g.push(n.li)});for(let e of[...v.keys()])_.has(e)||v.delete(e);a.agentTyping&&g.push(R$(a.agentTyping,p)),a.thinking?(clearTimeout(s),s=null,i.classList.remove(`wui-chat-message--leaving`),o=!0,r.update({active:!0,style:l.loaderStyle,steps:a.steps,phrases:l.phrases,intervalMs:l.intervalMs,reduced:l.reduced,announce:l.assistantName?.trim()?p.preparingAnswer(l.assistantName):void 0}),g.push(i)):o&&s===null&&!W3(l)?(i.classList.add(`wui-chat-message--leaving`),s=setTimeout(()=>{s=null,o=!1,i.classList.remove(`wui-chat-message--leaving`),r.update({active:!1}),b&&ue(b.state,b.context)},L3),g.push(i)):s===null?(o=!1,r.update({active:!1})):g.push(i),!a.streaming&&(a.turnError||a.stopped)&&g.push(re(a,l)),C3(d,a,{labels:p,features:a.features,title:K3(a,p),getState:()=>e.getSession().getState()}),g.push(d),E(t,g),le(a,h)}function de(e){return v.get(e)?.li??null}function fe(){clearTimeout(s),r.destroy(),m?.removeEventListener(`scroll`,se),g?.disconnect(),v.clear(),b=null,n.remove()}return{el:n,paint:ue,find:de,destroy:fe}}var Y3=`wchat:auto-opened`,X3=`wchat:dismissed`,Z3=`button, a[href], input, select, textarea`,Q3=`input, textarea`;function $3(e){return!e.closest(`.wui-chat`)}function e6(e){return e instanceof Element&&e.matches(Q3)&&$3(e)}function t6(){return[...document.querySelectorAll(Q3)].some(e=>$3(e)&&e.value!==e.defaultValue)}function n6(e){return e.length!==0&&[...document.querySelectorAll(e.join(`,`))].some(e=>{let t=e.getBoundingClientRect();return t.width>0&&t.height>0})}function r6(e){return e?[...document.querySelectorAll(Z3)].some(t=>{if(!$3(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 i6(e,t,n){if(e.oncePerSession&&sessionStorage.getItem(Y3)||e.rememberDismissal&&sessionStorage.getItem(X3)||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&&t6()||n.isOpen()?!0:e.skipWhenCoversControl&&r6(n.panelRect())}function a6(e){return e6(document.activeElement)||n6(e.avoid.menuSelectors)||n6(e.avoid.autoOpenBusySelectors)}function o6(e,t,n){let r=0;function i(){r=0,i6(e,t,n)||(a6(t)?r=setTimeout(i,e.busyRetrySeconds*1e3):(sessionStorage.setItem(Y3,`1`),n.open()))}return r=setTimeout(i,e.delaySeconds*1e3),{cancel(){clearTimeout(r),r=0}}}var s6=.4,c6=20;function l6(e){let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function u6(e){let t=e.match(/[\d.]+/g);if(!t||t.length<3)return null;let[n,r,i]=t.slice(0,3).map(Number);return{r:n,g:r,b:i,alpha:t.length>3?Number(t[3])/(e.includes(`%`)?100:1):1}}function d6({r:e,g:t,b:n}){return .2126*l6(e)+.7152*l6(t)+.0722*l6(n)}function f6(e,t){let n=e.getBoundingClientRect(),r=document.elementsFromPoint?.(n.left+n.width/2,n.top+n.height/2)??[],i=t.length?t.join(`,`):null;for(let t of r){if(e.contains(t))continue;if(i&&t.closest(i))return!0;let n=u6(getComputedStyle(t).backgroundColor);if(n&&n.alpha>0)return d6(n)<s6}return!1}function p6(e){return e.length===0?[]:[...document.querySelectorAll(e.join(`,`))]}function m6(e){let t=0;for(let n of e){let e=n.getBoundingClientRect();e.height!==0&&(t=Math.max(t,window.innerHeight-e.top))}return t>0?t+c6:0}function h6(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 g6(e,t,n){let r=n.ownerDocument.documentElement,i=0,a=!1,o=null;function s(){i=0;let s=t.liftAboveFooter?p6(e.liftSelectors):[];if(o)for(let e of s)o.observe(e);n.style.setProperty(`--wui-chat-lift`,`${m6(s)}px`);let c=n.getBoundingClientRect(),l=c.height===0?0:Math.round(window.innerHeight-c.top);r.style.setProperty(`--wui-chat-launcher-block`,`${l}px`);let u=t.stepAsideForMenus&&h6(e.menuSelectors);u&&!a?(n.dataset.launcher=`hidden`,n.inert=!0,a=!0):!u&&a&&(n.dataset.launcher=`idle`,n.inert=!1,a=!1);let d=t.switchOnDark&&f6(n,e.darkSelectors);d&&n.dataset.onDark===void 0&&(n.dataset.onDark=``),!d&&n.dataset.onDark!==void 0&&delete n.dataset.onDark}function c(){i||=requestAnimationFrame(s)}typeof ResizeObserver==`function`&&(o=new ResizeObserver(c));let l=new MutationObserver(c);return l.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`class`,`open`,`data-menu-open`]}),document.addEventListener(`scroll`,c,{capture:!0,passive:!0}),window.addEventListener(`resize`,c),window.addEventListener(`load`,c),n.addEventListener(`animationend`,c),c(),{destroy(){i&&cancelAnimationFrame(i),i=0,o?.disconnect(),l.disconnect(),document.removeEventListener(`scroll`,c,{capture:!0}),window.removeEventListener(`resize`,c),window.removeEventListener(`load`,c),n.removeEventListener(`animationend`,c),a&&=(n.inert=!1,!1),delete n.dataset.onDark,n.style.removeProperty(`--wui-chat-lift`),r.style.removeProperty(`--wui-chat-launcher-block`)}}}var _6=`wchat:session-start`,v6=`wchat:pages`,y6=`wchat:services`;function b6(e){let t=sessionStorage.getItem(e);return t?JSON.parse(t):[]}function x6(e,t){sessionStorage.setItem(e,JSON.stringify(t))}function S6(e,t){let n=t.find(t=>e.startsWith(t));return n===void 0?null:e.slice(n.length).replace(/^\/+|\/+$/g,``)||null}function C6(e){sessionStorage.getItem(_6)||sessionStorage.setItem(_6,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=b6(v6);i.includes(r)||(i.push(r),x6(v6,i));let a=S6(r,e),o=b6(y6);return a!==null&&(o=o.filter(e=>e!==a),o.push(a),o=o.slice(-10),x6(y6,o)),{timeOnSiteSeconds:Math.floor((Date.now()-Number(sessionStorage.getItem(_6)))/1e3),scrollPercent:Math.min(100,Math.floor(t)),pagesViewed:i.length,viewedServices:o}}}var w6=`a[href],button:not([disabled]),input:not([disabled]):not([type='hidden']),select:not([disabled]),textarea:not([disabled]),[tabindex]`;function T6(e,t){if(t.key!==`Tab`)return;let n=[...e.querySelectorAll(w6)].filter(e=>e.tabIndex>=0&&!e.hidden);if(n.length===0){t.preventDefault();return}let r=n[0],i=n[n.length-1],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 E6(e){e?.isConnected&&e.focus()}function D6(e,t){t||typeof navigator>`u`||typeof navigator.vibrate!=`function`||navigator.vibrate(e)}var O6=`wui-chat-lock`,k6=`wui-chat-scroll-lock`;function A6(e){let t=e.ownerDocument,n=[t.documentElement,t.body],r=e.style.overscrollBehavior;for(let e of n)e.classList.add(O6);e.setAttribute(`data-lenis-prevent`,``),e.style.overscrollBehavior=`contain`,window.dispatchEvent(new CustomEvent(k6,{detail:{locked:!0}}));let i=!0;return function(){if(i){i=!1;for(let e of n)e.classList.remove(O6);e.removeAttribute(`data-lenis-prevent`),e.style.overscrollBehavior=r,window.dispatchEvent(new CustomEvent(k6,{detail:{locked:!1}}))}}}var j6={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}},M6=[`pointerdown`,`keydown`,`touchstart`],N6=`wchat:muted`,P6=1e-4;function F6(e,t){let n=t.get(N6)===`1`,r=null;function i(){for(let e of M6)document.removeEventListener(e,a)}function a(){let e=globalThis.AudioContext||globalThis.webkitAudioContext;!r&&e&&(r=new e),r?.state===`suspended`&&r.resume(),i()}for(let e of M6)document.addEventListener(e,a);return{play(t){let i=j6[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(P6,a+i.seconds),o.connect(s),s.connect(r.destination),o.start(a),o.stop(a+i.seconds)},setMuted(e){n=!!e,t.set(N6,n?`1`:`0`)},isMuted(){return n},destroy(){i(),r?.close(),r=null}}}var I6=2e3,L6=500,R6=32,z6=16,B6=`data-wui-chat-switching`;function V6(e){return new Promise(t=>setTimeout(t,e))}function H6(e,t){return typeof e!=`function`||e()?Promise.resolve():new Promise(n=>{let r=0,i=()=>{e()||r>=t?n():(r+=z6,setTimeout(i,z6))};setTimeout(i,z6)})}async function U6(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(B6,``);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 H6(t.routeReady,I6),await H6(r,L6),await V6(R6)});i.ready.catch(()=>{});try{await i.updateCallbackDone}finally{await i.finished.catch(()=>{})}}finally{r.removeAttribute(B6)}}var W6=100,G6=12,K6=220,q6=640;function J6(e,t){let n=t.phone.mode===`Sheet`,r=window.visualViewport,i=0;function a(){e.style.removeProperty(`bottom`),e.style.removeProperty(`max-height`)}function o(){if(i=0,window.innerWidth>t.phone.maxWidthPx){a();return}if(!r)return;let o=Math.max(0,window.innerHeight-r.height-r.offsetTop),s=r.height-G6;n&&(s=Math.min(q6,Math.max(K6,s))),e.style.bottom=`${o}px`,e.style.maxHeight=`${s}px`}function s(){clearTimeout(i),i=setTimeout(o,W6)}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()}}}var Y6=typeof HTMLElement>`u`?class{}:HTMLElement;function X6(e,t){if(e.conversationState===`WaitingForAgent`)return t.statusWaitingForAgent;if(e.conversationState===`WithAgent`){let n=e.agent?.displayName;return t.statusWithAgent(typeof n==`string`&&n.trim()!==``?n:t.handoffAgentFallback)}return t.headerStatus}function Z6(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function Q6(e,t,n){return t.PanelSwitch!==!0||typeof n!=`function`?null:e===`docked`?`full-page`:e===`full-page`?`docked`:null}var $6=[`launcher`,`docked`,`full-page`,`embedded`],e8=[`end`,`start`],t8={steps:`Steps`,phrases:`Phrases`,orb:`Orb`,skeleton:`Skeleton`},n8={on:`On`,reduced:`Reduced`},r8=[`auto`,`light`,`dark`],i8=`wchat:muted`,a8=6e4,o8=400,s8=[`labels`,`pageContext`,`compact`,`open`,`layoutParts`,`getCaptchaToken`,`openAttachment`,`openCitation`,`openTarget`,`openTicket`,`onNavigate`,`resolveLink`,`emptyContent`,`onPanelSwitch`,`preloadPanelSwitch`],c8={...A2};function l8(e,t){if(!w$.includes(e))throw Error(`Unknown part kind "${e}". Use one of ${w$.join(`, `)}.`);if(typeof t!=`string`||!t.includes(`-`))throw Error(`Renderer tag "${t}" must be a custom element name containing a hyphen.`)}function u8(e,t){l8(e,t),c8[e]=t}function d8(e,t){return n=>{let r=n.toLowerCase();if(!Object.hasOwn(t,r))throw Error(`<wui-chat ${e}> must be one of ${Object.keys(t).join(`, `)}, got "${n}".`);return t[r]}}function f8(e){return t=>{let n=Number(t);if(!Number.isInteger(n)||n<0)throw Error(`<wui-chat ${e}> must be a whole number of pixels, got "${t}".`);return n}}function p8(e){return t=>{if(t===``||t===`true`)return!0;if(t===`false`)return!1;throw Error(`<wui-chat ${e}> must be true or false, got "${t}".`)}}var m8=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean),h8=[[`launcher-style`,`launcher`,`style`,d8(`launcher-style`,{round:`Round`,pill:`Pill`})],[`entrance`,`launcher`,`entrance`,d8(`entrance`,{"slide-up":`SlideUp`,"bounce-in":`BounceIn`,"fade-in-pulse":`FadeInPulse`,"spin-scale":`SpinScale`,"wiggle-in":`WiggleIn`,"elastic-in":`ElasticIn`,rise:`Rise`,none:`None`})],[`idle`,`launcher`,`idle`,d8(`idle`,{"float-and-pulse":`FloatAndPulse`,ring:`Ring`,none:`None`})],[`label-reveal`,`launcher`,`labelReveal`,d8(`label-reveal`,{bubble:`Bubble`,expand:`Expand`})],[`compact`,`launcher`,`compact`,p8(`compact`)],[`launcher-mark`,`launcher`,`mark`,d8(`launcher-mark`,{icon:`Icon`,avatar:`Avatar`})],[`panel-height`,`panel`,`height`,d8(`panel-height`,{fixed:`Fixed`,content:`Content`})],[`reply-avatars`,`panel`,`replyAvatars`,p8(`reply-avatars`)],[`greeting-loader-ms`,`panel`,`greetingLoaderMs`,f8(`greeting-loader-ms`)],[`panel-motion`,`panel`,`motion`,d8(`panel-motion`,{spring:`Spring`,gentle:`Gentle`,none:`None`})],[`panel-width`,`panel`,`widthPx`,f8(`panel-width`)],[`panel-max-height`,`panel`,`maxHeightPx`,f8(`panel-max-height`)],[`panel-bottom-gap`,`panel`,`bottomGapPx`,f8(`panel-bottom-gap`)],[`phone-max-width`,`phone`,`maxWidthPx`,f8(`phone-max-width`)],[`phone-mode`,`phone`,`mode`,d8(`phone-mode`,{"full-screen":`FullScreen`,sheet:`Sheet`})],[`sheet-height-dvh`,`phone`,`sheetHeightDvh`,f8(`sheet-height-dvh`)],[`sheet-max-height`,`phone`,`sheetMaxHeightPx`,f8(`sheet-max-height`)],[`input-ring`,`input`,`ring`,p8(`input-ring`)],[`send-reveal`,`input`,`sendReveal`,d8(`send-reveal`,{"on-text":`OnText`,always:`Always`})],[`send-icon`,`input`,`sendIcon`,e=>e],[`lift-selectors`,`avoid`,`liftSelectors`,m8],[`menu-selectors`,`avoid`,`menuSelectors`,m8],[`dark-selectors`,`avoid`,`darkSelectors`,m8],[`autoopen-busy-selectors`,`avoid`,`autoOpenBusySelectors`,m8],[`autoopen-optout-selector`,`avoid`,`autoOpenOptOutSelector`,e=>e]],g8={layout:`launcher`,position:`end`,"offset-x":`24`,"offset-y":`24`,loader:`steps`,motion:`on`,icon:`chat`},_8=[`base`,`layout`,`position`,`offset-x`,`offset-y`,`loader`,`screen`,`motion`,`theme`,`icon`,`avatar`,`narrow`,...h8.map(([e])=>e).filter(e=>e!==`compact`)],v8=e=>e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase());function y8(e){let t={launcher:{},panel:{},phone:{},input:{},avoid:{}};for(let[n,r,i,a]of h8){let o=e.getAttribute(n);o!=null&&(t[r][i]=a(o))}let n=e.getAttribute(`motion`),r=e.getAttribute(`avatar`);return xt({...t,motion:n==null?void 0:d8(`motion`,n8)(n),avatar:r||void 0})}function b8(e){let t=e.getAttribute(`loader`)??`steps`;if(!Object.hasOwn(t8,t))throw Error(`<wui-chat loader> must be one of ${Object.keys(t8).join(`, `)}, got "${t}".`);return t8[t]}function x8(e){let t=e.getAttribute(`narrow`);if(t!=null&&t!==``)return Object.fromEntries(m8(t).map(e=>[e,!1]))}function S8(e){return e===i8?globalThis.localStorage:globalThis.sessionStorage}var C8={get:e=>S8(e).getItem(e),set:(e,t)=>S8(e).setItem(e,t)};function w8(e){return globalThis.innerWidth<=e.phone.maxWidthPx}function T8(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}var E8=0,D8=class extends Y6{static get observedAttributes(){return[..._8,`compact`,`open`,`labels`,`page-context`,`narrow`].filter((e,t,n)=>n.indexOf(e)===t)}constructor(){super(),E8+=1,this._uid=`wui-chat-${E8}`,this._built=!1,this._session=null,this._unsubscribe=null,this._voice=null,this._voiceConversationId=void 0,this._shell=null,this._labelsProp=void 0,this._pageContextProp=void 0,this._layoutParts=null,this._renderers={...c8},this._rendererApi={define:(e,t)=>{l8(e,t),this._renderers[e]=t,this._render()},map:this._renderers},this._captchaToken=null,this._openAttachmentProp=null,this._openCitationProp=null,this._openTargetProp=null,this._resolveLinkProp=null,this._openTicketProp=void 0,this._emptyContentProp=null,this._onPanelSwitchProp=null,this._preloadPanelSwitchProp=null,this._preloaded=!1,this._pastList=null,this._past=null,this._pastRefreshed=!1,this._historyShown=!1,this._openedConversation=null,this._lastOpen=!1,this._openTrigger=`manual`,this._focusTimer=null,this._nudgeArmed=!1,this._seeded=!1,this._wasLoading=!1,this._seen=new Set,this._sound=null,this._behaviour=null,this._autoOpen=null,this._avoid=null,this._motion=null,this._phone=null,this._requesting=!1,this._onKeyDown=e=>{e.key===`Escape`&&this._session?.getState().open&&(e.stopPropagation(),this._session.close(`escape`))}}get session(){return this._session??null}get conversationId(){return this._session?.getState().conversationId??null}get labels(){return s({...x$(this,`labels`),...this._labelsProp})}set labels(e){this._labelsProp=e??void 0,this._render()}get pageContext(){return this._pageContextProp===void 0?x$(this,`page-context`):this._pageContextProp}set pageContext(e){this._pageContextProp=e===null?void 0:e}get compact(){return this.hasAttribute(`compact`)}set compact(e){this.toggleAttribute(`compact`,e===!0||e===``||e===`true`)}get open(){return this.hasAttribute(`open`)}set open(e){this.toggleAttribute(`open`,e===!0||e===``||e===`true`)}get renderers(){return this._rendererApi}get layoutParts(){return this._layoutParts}set layoutParts(e){this._layoutParts=typeof e==`function`?e:null,this._render()}get getCaptchaToken(){return this._captchaToken}set getCaptchaToken(e){this._captchaToken=typeof e==`function`?e:null}get openAttachment(){return this._openAttachmentProp??(e=>this._defaultOpenAttachment(e))}set openAttachment(e){this._openAttachmentProp=typeof e==`function`?e:null}get openCitation(){return this._openCitationProp??((e,t)=>this._defaultOpenCitation(e,t))}set openCitation(e){this._openCitationProp=typeof e==`function`?e:null}get openTarget(){return this._openTargetProp??(e=>this._defaultOpenTarget(e))}set openTarget(e){this._openTargetProp=typeof e==`function`?e:null}get openTicket(){return this._openTicketProp}set openTicket(e){this._openTicketProp=typeof e==`function`?e:void 0}get onNavigate(){return this._onNavigateProp}set onNavigate(e){this._onNavigateProp=typeof e==`function`?e:void 0}get resolveLink(){return this._resolveLinkProp}set resolveLink(e){this._resolveLinkProp=typeof e==`function`?e:null}get emptyContent(){return this._emptyContentProp}set emptyContent(e){if(e!==null&&!(e instanceof Node))throw TypeError(`emptyContent must be a Node or null`);this._emptyContentProp=e,this._applyEmptyContent()}get onPanelSwitch(){return this._onPanelSwitchProp}set onPanelSwitch(e){this._onPanelSwitchProp=typeof e==`function`?e:null}get preloadPanelSwitch(){return this._preloadPanelSwitchProp}set preloadPanelSwitch(e){this._preloadPanelSwitchProp=typeof e==`function`?e:null}connectedCallback(){if(this._adoptEarlyProperties(),this._assertLayout(),this._assertPosition(),this.base.trim()===``)throw TypeError(`<wui-chat> needs a base path, e.g. base="/api/assistant".`);this._built||this._build(),this._shell||this._buildShell(),this._session||this._createSession(),this._past||this._createPast(),this._unsubscribe||=this._session.subscribe(()=>this._render()),this._render()}_adoptEarlyProperties(){for(let e of s8){if(!Object.hasOwn(this,e))continue;let t=this[e];delete this[e],this[e]=t}}disconnectedCallback(){this._voice?.stop(),this._session?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._disposePast(),this._shell?.destroy?.(),document.removeEventListener(`keydown`,this._onKeyDown),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._motion?.destroy(),this._motion=null}attributeChangedCallback(e,t,n){if(this._built&&t!==n){if(e===`layout`)this._assertLayout(),this._buildShell();else if(e===`position`)this._assertPosition();else if(e===`base`||e===`screen`||e===`narrow`)this._resetSession();else if(e===`motion`)this._motion?.destroy(),this._motion=null;else if(e===`open`&&this._session){let e=this._session.getState().open;this.open!==e&&this._setOpen(this.open,`manual`)}this._render()}}toggle(){this._session&&(this._session.getState().open?this._session.close(`button`):this._setOpen(!0,`manual`))}close(){this._voice?.stop(),this._session?.close(`button`)}newConversation(){this._voice?.stop(),this._session?.newConversation(),this._past?.refresh()}reset(){this._voice?.stop(),this._session?.reset()}_setOpen(e,t){this._session&&(e?(this._openTrigger=t,this._session.open({trigger:t})):this._session.close(`button`))}_assertLayout(){let e=this.layout;if(!$6.includes(e))throw Error(`<wui-chat layout> must be one of ${$6.join(`, `)}, got "${e}".`)}_assertPosition(){let e=this.position;if(!e8.includes(e))throw Error(`<wui-chat position> must be one of ${e8.join(`, `)}, got "${e}".`)}_isLauncherLike(){return this.layout===`launcher`||this.layout===`docked`}_build(){this._built=!0,this._header=d4({onNew:()=>this.newConversation(),onHistory:()=>this._toggleHistory(),onClose:()=>this.close(),onMute:()=>this._session?.setMuted(!this._session.getState().muted),onSwitch:()=>this._switchPanel(),titleId:`${this._uid}-title`}),this._starters=Y4({onStarter:e=>this._session.submit(e.message),onResume:()=>this._session.resumeLast(),onTicket:e=>{typeof this.openTicket==`function`&&this.openTicket({ticketId:e.ticketId,number:e.number})}}),this._applyEmptyContent(),this._voice=X2({getState:()=>this._session.getState(),getLabels:()=>this.labels,getToken:()=>this._session.client.getSpeechToken()}),this._voice.subscribe(()=>this._render()),this._thread=J3({getRenderers:()=>this._renderers,getLayoutParts:()=>this._layoutParts,makeTurnApi:e=>this._makeTurnApi(e),onRetry:()=>this._session.retry(),onRegenerate:()=>this._session.regenerate(),onRate:(e,t)=>this._session.rate(e,t),getSession:()=>this._session,getVoice:()=>this._voice}),this._composer=i4({voice:this._voice,onSubmit:e=>this._session.submit(e),onStop:()=>this._session.stop(),onAttach:e=>this._session.attach(e),onRemove:e=>this._session.removeAttachment(e),onCancelEdit:()=>this._session.cancelEdit(),onTyping:()=>this._session.notifyTyping(),onDraftApplied:()=>this._session.consumeDraft()}),this._footer=l4(),this._history=m4({getClient:()=>this._session.client,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{}),this._toggleHistory(!1)},onDeleted:e=>{e===this.conversationId&&this._session.newConversation()}}),this._nudge=b4({onActivate:()=>this._setOpen(!0,`manual`),onDismiss:()=>{}}),this._status=$(`p`,null,{role:`status`}),this._status.hidden=!0,this._errorEl=$(`p`,`wui-chat-profile-error`,{role:`alert`}),this._errorEl.hidden=!0,this._liveStatus=$(`p`,`wui-chat-live-status`,{role:`status`}),this._liveStatus.hidden=!0,this._talk=$(`button`,`${v$(`outline`,`sm`)} wui-chat-handoff-request`,{type:`button`}),this._talk.addEventListener(`click`,()=>this._requestHandoff()),this._liveRetry=$(`button`,v$(`ghost`,`sm`),{type:`button`}),this._liveRetry.addEventListener(`click`,()=>this._session.resumeLive()),this._liveError=$(`p`,`wui-chat-live-error`,{role:`alert`}),this._liveError.hidden=!0,this._live=$(`div`,`wui-chat-live`),this._live.append(this._liveStatus,this._talk,this._liveRetry,this._liveError),this._live.hidden=!0,this._body=$(`div`,`wui-chat-body`),this._body.append(this._starters.el,this._thread.el,this._live,this._history.el,this._status,this._errorEl),this._foot=$(`div`,`wui-chat-foot`),this._foot.append(...this._composer.nodes,this._footer.el)}_buildShell(){let e={launcher:U4,docked:R4,"full-page":W4,embedded:z4};this._shell?.destroy?.(),this._avoid?.destroy(),this._avoid=null,this._autoOpen?.cancel(),this._autoOpen=null,this._lastOpen=!1,this._launcherPlayed=!1;let t=e[this.layout]({id:`${this._uid}-panel`,position:this.position,onToggle:()=>this.toggle()});t.panel.append(this._header.el,this._body,this._foot),t.panel.setAttribute(`aria-labelledby`,`${this._uid}-title`),t.panel.addEventListener(`keydown`,e=>{e.key===`Tab`&&T6(t.panel,e)}),t.nudgeHost&&t.nudgeHost.prepend(this._nudge.el),this._shell=t,this.replaceChildren(t.root)}_createSession(){let e=E(y4(),{base:this.base}),t=x8(this);this._session=on(e,{screen:this.screen||void 0,narrow:t,pageContext:()=>this.pageContext,behaviour:()=>this._session?.getState().features.BehaviourStarters?this._behaviour?.()??null:null,prefs:C8,reducedMotion:()=>this._motion?.reduced??!1,schedule:T8,getCaptchaToken:e=>{if(this._captchaToken)return this._captchaToken(e);let t=this._session?.getState().profile?.captcha?.siteKey;return t?j4(t,e):Promise.resolve(null)},onEvent:(e,t)=>{this.dispatchEvent(new CustomEvent(`wui-chat-event`,{bubbles:!0,detail:{name:e,data:t}}))},onError:()=>{},labels:this.labels}),this._unsubscribe=null,this._lastOpen=!1,this._openApplied=!1,this._seeded=!1,this._wasLoading=!1,this._seen=new Set,this._pastRefreshed=!1}_createPast(){this._pastList=k({client:this._session.client,pageSize:20}),this._past=D4({list:this._pastList,getLabels:()=>this.labels,getFeatures:()=>this._session.getState().features,onOpen:e=>{this._session.openConversation(e).catch(()=>{})}}),this._starters.pastHost.append(this._past.el)}_disposePast(){this._past&&(this._past.el.remove(),this._past.dispose(),this._pastList.dispose(),this._past=null,this._pastList=null)}_applyEmptyContent(){if(!this._starters)return;let e=this._starters.extraHost;e.replaceChildren(...this._emptyContentProp?[this._emptyContentProp]:[]),e.hidden=!this._emptyContentProp}_switchPanel(){let e=this._session.getState(),t=Q6(this.layout,e.features,this._onPanelSwitchProp);if(t===null)return;t===`full-page`&&this.close();let n={from:this.layout,to:t,conversationId:e.conversationId,draft:this._composer.getDraft()};U6(()=>this._onPanelSwitchProp(n),{target:t,reduced:this._motion?.reduced===!0}).then(()=>document.querySelector(`.wui-chat--${t} .wui-chat-input`)?.focus()).catch(e=>globalThis.reportError?.(e))}async _requestHandoff(){this._requesting=!0,this._liveError.hidden=!0,this._render();try{await this._session.requestHandoff()}catch(e){this._liveError.textContent=e?.message||this.labels.errorGeneric,this._liveError.hidden=!1}finally{this._requesting=!1,this._render()}}_paintLive(e,t,n){let r=e.live===`Lost`,i=Z6(e);this._liveStatus.hidden=!r,this._liveStatus.textContent=r?t.liveLost:``,this._liveRetry.hidden=!r,this._liveRetry.textContent=t.retry,this._talk.hidden=!i,this._talk.textContent=t.talkToPerson,this._talk.disabled=this._requesting,this._live.hidden=n||!r&&!i}_resetSession(){this._voice?.stop(),this._unsubscribe?.(),this._unsubscribe=null,this._session?.dispose(),this._session=null,this._disposePast(),this._history.dispose(),this.isConnected&&(this._createSession(),this._createPast(),this._unsubscribe=this._session.subscribe(()=>this._render()))}_toggleHistory(e=!this._historyShown){this._historyShown=e,e?this._history.show():this._history.hide(),this._render()}_makeTurnApi(e){let t=cn(this._session,{messageId:e,labels:this.labels,openAttachment:e=>this.openAttachment(e),openCitation:t=>this.openCitation(e,t),openTarget:e=>this.openTarget(e),openTicket:this.openTicket,onNavigate:this.onNavigate});return t.resolveLink=this.resolveLink,t}_defaultOpenAttachment(e){this._session.client.getAttachment(e.attachmentId).then(t=>{let n=URL.createObjectURL(new Blob([t],{type:e.contentType}));window.open(n,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(n),a8)}).catch(e=>globalThis.reportError?.(e))}_defaultOpenCitation(e,t){let n=this._thread.find(e);if(n){for(let e of n.querySelectorAll(`[data-marker]`))if(e.dataset.marker===String(t)){e.focus();return}}}_defaultOpenTarget(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}_render(){this._built&&this._session&&this._paint(this._session.getState())}_paint(e){e.conversationId!==this._voiceConversationId&&(this._voiceConversationId=e.conversationId,this._voice.stop());let t=this.labels,n=e.profile,r=this._isLauncherLike();if(!n){this.hidden=r,this._header.el.hidden=!0,this._starters.el.hidden=!0,this._thread.el.hidden=!0,this._history.el.hidden=!0,this._foot.hidden=!0,this._errorEl.hidden=e.profileError==null,e.profileError&&(this._errorEl.textContent=e.profileError.message),this._status.hidden=e.profileError!=null,this._status.textContent=t.loadingConversation,this._shell.panel.setAttribute(`aria-busy`,String(e.profileError==null));return}if(this._shell.panel.removeAttribute(`aria-busy`),!e.features.VisitorChat){this.hidden=!0,this._status.hidden=!0;return}this.hidden=!1;let i=e.features,a=y8(this);this._ensureRuntime(e,n,a,t);let o=e.loading,s=e.loadError,c=e.messages.length===0&&!o,l=this._historyShown&&i.History===!0,u=e.messages.some(e=>e.author.kind===`Visitor`),d=Q6(this.layout,i,this._onPanelSwitchProp),f=e.streaming||e.thinking;this._header.paint({labels:t,title:n.assistant.name,tagline:n.assistant.tagline,status:X6(e,t),canNew:!f,showNew:this.layout===`full-page`||u,showHistory:i.History,showClose:r||this.layout===`full-page`&&d!==null,switchTo:d,canSwitch:!f,viewingHistory:l,showMute:i.Sounds&&n.experience.sound.muteControl,muted:e.muted}),this._starters.el.hidden=!c||l,c&&e.open&&!this._introPlayed&&a.panel.greetingLoaderMs>0&&!this._motion.reduced&&(this._introPlayed=!0,this._starters.intro(a.panel.greetingLoaderMs)),c&&this._starters.paint({labels:t,greeting:e.greeting,starters:e.starters,showStarters:i.Starters&&!e.streaming,resume:!i.History&&i.ResumeLast?e.lastConversation:null,openTickets:e.openTickets,features:e.features,ticketsClickable:typeof this.openTicket==`function`}),i.History&&!this._pastRefreshed&&(this._pastRefreshed=!0,this._past?.refresh()),this._past?.paint();let p=!c&&!o&&!s&&!l;this._thread.el.hidden=!p,p&&this._thread.paint(e,{labels:t,loaderStyle:b8(this),reduced:this._motion?.reduced??!1,phrases:n.experience.pacing.thinkingPhrases,intervalMs:n.experience.pacing.phraseIntervalMs,assistantName:n.assistant.name}),this._paintLive(e,t,l),this._status.hidden=!o||l,this._status.textContent=t.loadingConversation,this._errorEl.hidden=!s||l,s&&(this._errorEl.textContent=s.message),this._foot.hidden=l,this._composer.paint({state:e,labels:t,maxLength:n.limits.maxMessageLength,accept:n.limits.contentTypes.join(`,`),draft:e.draft??null,sendIcon:a.input.sendIcon}),this._footer.paint({labels:t,profile:n}),this._history.el.hidden=!l,this._syncOpen(e,n,i,t,r),this._syncConversation(e),this._playSounds(e)}_ensureRuntime(e,t,n,r){let i=e.features;this._motion||(this._motion=m$(n,t.experience),this._motion.subscribe(()=>this._render())),i.Sounds&&!this._sound&&(this._sound=F6(t.experience.sound,C8)),!i.Sounds&&this._sound&&(this._sound=null),i.BehaviourStarters&&!this._behaviour&&(this._behaviour=C6(t.start.behaviour?.servicePathPrefixes??[]));let a=this._isLauncherLike();a&&!this._avoid&&this.layout===`launcher`&&(this._avoid=g6(n.avoid,t.experience.launcher,this._shell.nudgeHost)),this.layout===`launcher`&&i.AutoOpen&&!this._autoOpen&&(this._autoOpen=o6(t.experience.autoOpen,n,{open:()=>this._setOpen(!0,`auto`),isOpen:()=>this._session.getState().open,panelRect:()=>this._shell.panel.getBoundingClientRect()}));let o=w8(n);this._shell.setLabels(r),this._shell.setAppearance({position:this.position,offsetX:this.hasAttribute(`offset-x`)?f8(`offset-x`)(this.getAttribute(`offset-x`)):void 0,offsetY:this.hasAttribute(`offset-y`)?f8(`offset-y`)(this.getAttribute(`offset-y`)):void 0,width:`${n.panel.widthPx}px`,maxHeight:n.panel.maxHeightPx,bottomGap:n.panel.bottomGapPx,reduced:this._motion.reduced,sendReveal:n.input.sendReveal,inputRing:n.input.ring,panelMotion:n.panel.motion,theme:r8.includes(this.getAttribute(`theme`))?this.getAttribute(`theme`):`auto`,icon:this.icon,launcherStyle:n.launcher.style,compact:n.launcher.compact,labelReveal:n.launcher.labelReveal,entrance:n.launcher.entrance,idle:n.launcher.idle,launcherMark:n.launcher.mark,panelHeight:n.panel.height,replyAvatars:n.panel.replyAvatars,avatar:n.avatar,phone:o,hoverLabel:t.experience.launcher.hoverLabel,peek:t.experience.launcher.peek,peekSeconds:t.experience.launcher.peekSeconds,hideWhileOpen:t.experience.launcher.hideWhileOpen,phoneMode:n.phone.mode,sheetHeightDvh:n.phone.sheetHeightDvh,sheetMaxHeightPx:n.phone.sheetMaxHeightPx,launcherState:this._launcherPlayed?void 0:`entering`}),this._launcherPlayed=!0,this._shell.root.classList.toggle(`wui-chat--phone`,a&&w8(n))}_syncOpen(e,t,n,r,i){if(i){if(!this._openApplied&&(this._openApplied=!0,this.hasAttribute(`open`)&&!e.open))this._setOpen(!0,`manual`);else if(this._shell.setOpen(e.open),this.toggleAttribute(`open`,e.open),e.open!==this._lastOpen&&(this._lastOpen=e.open,this._onOpenChange(e.open)),e.open)this._nudge.cancel(),this._nudgeArmed=!1,this._autoOpen?.cancel();else if(n.Nudges&&this.layout===`launcher`&&!this._nudgeArmed){let e=Ot(t,n);e&&(this._nudge.schedule({text:e.text,delaySeconds:e.delaySeconds,label:r.nudgeDismiss}),this._nudgeArmed=!0)}}}_onOpenChange(e){let t=w8(y8(this));if(e){if(document.addEventListener(`keydown`,this._onKeyDown),this._sound?.play(`open`),this._past?.refresh(),this.layout===`docked`&&!this._preloaded&&typeof this._preloadPanelSwitchProp==`function`){this._preloaded=!0;try{this._preloadPanelSwitchProp()?.catch?.(()=>{})}catch{}}if(t){let e=y8(this);this._phone={fit:J6(this._shell.panel,e),unlock:A6(this._thread.el)}}else this._openTrigger===`manual`&&(this._focusTimer=setTimeout(()=>{this._focusTimer=null,this._composer.focus()},o8))}else document.removeEventListener(`keydown`,this._onKeyDown),clearTimeout(this._focusTimer),this._focusTimer=null,this._phone?.fit.destroy(),this._phone?.unlock(),this._phone=null,this._historyShown&&(this._historyShown=!1,this._history.hide(),this._render()),E6(this._shell.launcherButton)}_syncConversation(e){let t=this.getAttribute(`conversation-id`);t&&t!==this._openedConversation&&!e.loading&&(this._openedConversation=t,e.conversationId!==t&&this._session.openConversation(t).catch(()=>{}))}_playSounds(e){if(e.loading){this._wasLoading=!0;for(let t of e.messages)this._seen.add(t.id)}else if(this._wasLoading||!this._seeded){this._wasLoading=!1,this._seeded=!0;for(let t of e.messages)this._seen.add(t.id)}else for(let t of e.messages)this._seen.has(t.id)||(this._seen.add(t.id),this._announce(t))}_announce(e){if(!this._sound||e.restored||e.parts.some(e=>e.kind===`Notice`))return;let t=e.author.kind;if(t===`Visitor`)e.stored||this._sound.play(`sent`);else if(t===`Assistant`||t===`Script`||t===`Agent`){this._sound.play(`reply`);let e=this._session.getState().profile;e?.experience.sound.vibrate&&D6(e.experience.sound.vibrateMs,this._sound.isMuted())}}};Object.defineProperty(D8.prototype,"layout",{get(){return this.getAttribute(`layout`)??g8.layout},set(e){this.setAttribute(`layout`,String(e))}});for(let e of _8)e!==`layout`&&Object.defineProperty(D8.prototype,v8(e),{configurable:!0,get(){return this.getAttribute(e)??g8[e]??``},set(t){t==null?this.removeAttribute(e):this.setAttribute(e,String(t))}});function O8(){typeof customElements<`u`&&!customElements.get(`wui-chat`)&&customElements.define(`wui-chat`,D8)}O8(),O8(),globalThis.WeborityChat=Object.assign(globalThis.WeborityChat||{},{session:e=>e.session,renderers:{define:u8}})})();
|