@zabbu/chat-widget 0.9.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-ui.js +1 -1
- package/dist/loader.js +27 -12
- package/package.json +1 -1
package/dist/chat-ui.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var Z=["\u{1F600}","\u{1F602}","\u{1F609}","\u{1F60A}","\u{1F60D}","\u{1F914}","\u{1F605}","\u{1F622}","\u{1F62E}","\u{1F60E}","\u{1F64F}","\u{1F44D}","\u{1F44E}","\u{1F44F}","\u{1F64C}","\u{1F389}","\u2764\uFE0F","\u{1F525}","\u2705","\u274C","\u26A0\uFE0F","\u{1F4A1}","\u{1F4CE}","\u23F3"];function J(n){return!!n&&n.startsWith("image/")}function P(n,o,t){let e=document.createElement("div");if(e.className=`chat-bubble chat-bubble--${o}`,o==="admin"){let a=document.createElement("div");a.className="chat-bubble-label",a.textContent="Agente",e.appendChild(a)}if(n){let a=document.createElement("div");a.textContent=n,e.appendChild(a)}return t?.attachmentUrl&&e.appendChild(X(t)),e}function X(n){let{attachmentUrl:o,attachmentName:t,attachmentMime:e}=n;if(J(e)){let r=document.createElement("a");r.href=o,r.target="_blank",r.rel="noopener noreferrer",r.className="chat-attachment-image-link";let u=document.createElement("img");return u.src=o,u.alt=t??"",u.className="chat-attachment-image",r.appendChild(u),r}let a=document.createElement("a");return a.href=o,a.target="_blank",a.rel="noopener noreferrer",a.className="chat-attachment-file",a.textContent=`\u{1F4CE} ${t??"Archivo adjunto"}`,a}function L(){let n=document.createElement("div");n.className="chat-bubble chat-bubble--admin chat-typing-indicator",n.setAttribute("aria-live","polite"),n.setAttribute("aria-label","El agente est\xE1 escribiendo");for(let o=0;o<3;o++){let t=document.createElement("span");t.className="chat-typing-dot",n.appendChild(t)}return n}function R(n){let o=document.createElement("div");o.className="chat-emoji-wrapper";let t=document.createElement("button");t.type="button",t.className="chat-emoji-toggle",t.setAttribute("aria-label","Insertar emoji"),t.textContent="\u{1F642}";let e=document.createElement("div");return e.className="chat-emoji-panel",e.hidden=!0,Z.forEach(a=>{let r=document.createElement("button");r.type="button",r.className="chat-emoji-option",r.textContent=a,r.addEventListener("click",()=>{n(a),e.hidden=!0}),e.appendChild(r)}),t.addEventListener("click",()=>{e.hidden=!e.hidden}),document.addEventListener("click",a=>{o.contains(a.target)||(e.hidden=!0)}),o.appendChild(t),o.appendChild(e),{wrapper:o,toggleButton:t}}var ee={SOFT_TINT:"linear-gradient(180deg, color-mix(in srgb, var(--chat-primary-color) 8%, white) 0%, white 100%)",DIAGONAL_WASH:"linear-gradient(135deg, color-mix(in srgb, var(--chat-primary-color) 14%, white) 0%, white 55%, color-mix(in srgb, var(--chat-primary-color) 6%, white) 100%)",RADIAL_GLOW:"radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--chat-primary-color) 18%, white) 0%, white 65%)",DUOTONE_SOFT:"linear-gradient(160deg, color-mix(in srgb, var(--chat-primary-color) 20%, white) 0%, color-mix(in srgb, var(--chat-primary-color) 5%, white) 100%)",MESH_SOFT:"radial-gradient(60% 50% at 15% 10%, color-mix(in srgb, var(--chat-primary-color) 20%, white) 0%, transparent 60%), radial-gradient(50% 45% at 90% 20%, color-mix(in srgb, var(--chat-primary-color) 14%, white) 0%, transparent 60%), radial-gradient(70% 60% at 50% 100%, color-mix(in srgb, var(--chat-primary-color) 10%, white) 0%, transparent 60%), white"},te={SOFT_TINT:"linear-gradient(180deg, color-mix(in srgb, var(--chat-primary-color) 14%, #17181f) 0%, #17181f 100%)",DIAGONAL_WASH:"linear-gradient(135deg, color-mix(in srgb, var(--chat-primary-color) 22%, #17181f) 0%, #17181f 55%, color-mix(in srgb, var(--chat-primary-color) 10%, #17181f) 100%)",RADIAL_GLOW:"radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--chat-primary-color) 26%, #17181f) 0%, #17181f 65%)",DUOTONE_SOFT:"linear-gradient(160deg, color-mix(in srgb, var(--chat-primary-color) 28%, #17181f) 0%, color-mix(in srgb, var(--chat-primary-color) 8%, #17181f) 100%)",MESH_SOFT:"radial-gradient(60% 50% at 15% 10%, color-mix(in srgb, var(--chat-primary-color) 28%, #17181f) 0%, transparent 60%), radial-gradient(50% 45% at 90% 20%, color-mix(in srgb, var(--chat-primary-color) 20%, #17181f) 0%, transparent 60%), radial-gradient(70% 60% at 50% 100%, color-mix(in srgb, var(--chat-primary-color) 16%, #17181f) 0%, transparent 60%), #17181f"};function I(n){n.primaryColor&&document.documentElement.style.setProperty("--chat-primary-color",n.primaryColor);let o=n.colorScheme==="DARK";document.body.dataset.theme=o?"dark":"light";let t=o?te:ee,e=n.backgroundStyle&&t[n.backgroundStyle];e&&document.documentElement.style.setProperty("--chat-bg",e)}function M(n,o){let t=document.createElement("div");t.className="chat-welcome-card";let e=document.createElement("div");e.className="chat-welcome-card-icon",e.textContent="\u{1F4AC}",t.appendChild(e);let a=document.createElement("h4");a.className="chat-welcome-card-heading",a.textContent=`\xA1Hola! Bienvenido a ${n}`,t.appendChild(a);let r=document.createElement("p");return r.className="chat-welcome-card-body",r.textContent=o,t.appendChild(r),t}function O(n){return n==="SLASH"?"/":"@"}function w(n,o,t){let e=document.createElement("div");e.className="chat-autocomplete-panel",e.hidden=!0;let a=0,r=[];function u(){e.replaceChildren(),r.forEach((i,p)=>{let d=document.createElement("button");d.type="button",d.className=p===a?"chat-autocomplete-option chat-autocomplete-option--active":"chat-autocomplete-option";let m=document.createElement("span");m.className="chat-autocomplete-trigger",m.textContent=`${O(i.symbol)}${i.trigger}`;let y=document.createElement("span");y.className="chat-autocomplete-label",y.textContent=i.label,d.appendChild(m),d.appendChild(y),d.addEventListener("mousedown",h=>{h.preventDefault(),f(i)}),e.appendChild(d)})}function f(i){t(`${O(i.symbol)}${i.trigger} `),g()}function g(){e.hidden=!0,r=[]}function E(){let i=/^([/@])(\S*)$/.exec(n.value);if(!i){g();return}let[,p,d]=i,m=p==="/"?"SLASH":"AT";if(r=o.filter(y=>y.symbol===m&&y.trigger.toLowerCase().startsWith(d.toLowerCase())),r.length===0){g();return}a=0,e.hidden=!1,u()}return n.addEventListener("input",E),n.addEventListener("keydown",i=>{e.hidden||r.length===0||(i.key==="ArrowDown"?(i.preventDefault(),a=(a+1)%r.length,u()):i.key==="ArrowUp"?(i.preventDefault(),a=(a-1+r.length)%r.length,u()):i.key==="Enter"||i.key==="Tab"?(i.preventDefault(),f(r[a])):i.key==="Escape"&&g())}),document.addEventListener("click",i=>{!e.contains(i.target)&&i.target!==n&&g()}),e}var ne={TICKET_CREATE:"\u{1F3AB}",TICKET_LOOKUP:"\u{1F50D}",SHOW_MENU:"\u{1F4CB}",CANNED_REPLY:"\u{1F4AC}",RUN_WORKFLOW:"\u26A1"};function D(n){return n&&ne[n]||"\u{1F4AC}"}function U(n,o){let t=document.createElement("div");return t.className="chat-quick-replies",n.forEach(e=>{let a=document.createElement("button");a.type="button",a.className="chat-quick-reply-chip";let r=e.symbol==="SLASH"?"/":"@";a.textContent=`${D(e.action)} ${e.label}`,a.addEventListener("click",()=>o(`${r}${e.trigger}`)),t.appendChild(a)}),t}function k(n,o,t,e){let a=document.createElement("button");a.type="button",a.className="chat-cta-button";let r=o?D(o.action):"\u{1F4AC}";return a.textContent=`${r} ${n}`,a.addEventListener("click",()=>{if(o){let u=o.symbol==="SLASH"?"/":"@";t(`${u}${o.trigger}`)}else e()}),a}var B="chat:ready";var G="chat:close",$="chat:toggle";var N="chat:send",Y="chat:bot-reply",j="chat:connect-error",W="chat:history",F="chat:admin-message",K="chat:admin-typing",q="chat:agent-presence",_="chat:typing",V="chat:upload-attachment",Q="chat:attachment-uploaded",z="chat:attachment-upload-error";function ae(){let n=new URLSearchParams(location.hash.replace(/^#/,""));return{prefix:n.get("prefix"),apiBase:n.get("api")}}function b(n){window.parent.postMessage(n,"*")}async function oe(n,o){let t=await fetch(`${n}/public/sites/${o}`);if(!t.ok)throw new Error("site config unavailable");return t.json()}function re(n){let o=document.getElementById("app");for(;o.firstChild;)o.removeChild(o.firstChild);let t=document.createElement("div");t.className="chat-shell";let e=document.createElement("div");e.className="chat-header";let a=document.createElement("div");a.className="chat-header-title";let r=document.createElement("span");if(r.className="chat-header-avatar-wrap",n.logoUrl){let h=document.createElement("img");h.src=n.logoUrl,h.alt="",r.appendChild(h)}else{let h=document.createElement("span");h.className="chat-header-avatar",h.textContent=n.name.slice(0,1).toUpperCase(),r.appendChild(h)}a.appendChild(r);let u=document.createElement("div");u.className="chat-header-text";let f=document.createElement("span");f.className="chat-header-name",f.textContent=n.name,u.appendChild(f),a.appendChild(u),e.appendChild(a);let g=document.createElement("button");g.className="chat-close-button",g.type="button",g.setAttribute("aria-label","Cerrar"),g.textContent="\u2715",g.addEventListener("click",()=>b({type:G})),e.appendChild(g);let E=document.createElement("div");E.className="chat-messages";let i=document.createElement("form");i.className="chat-input-row";let p=document.createElement("input");p.type="text",p.placeholder="Escribe un mensaje o /menu",p.autocomplete="off";let d,m;if(n.attachmentsEnabled){d=document.createElement("button"),d.type="button",d.className="chat-attach-button",d.setAttribute("aria-label","Adjuntar archivo"),d.textContent="\u{1F4CE}",m=document.createElement("input"),m.type="file",m.accept="image/png,image/jpeg,image/gif,image/webp,application/pdf",m.style.display="none";let h=m;d.addEventListener("click",()=>h.click()),i.appendChild(d),i.appendChild(m)}if(n.emojiPickerEnabled!==!1){let{wrapper:h}=R(v=>{let A=p.selectionStart??p.value.length,C=p.selectionEnd??p.value.length;p.value=p.value.slice(0,A)+v+p.value.slice(C),p.focus(),p.selectionStart=p.selectionEnd=A+v.length});i.appendChild(h)}let y=document.createElement("button");if(y.type="submit",y.textContent=n.sendButtonText||"Enviar",n.commands?.length){let h=w(p,n.commands,v=>{p.value=v,p.focus()});i.appendChild(h)}return i.appendChild(p),i.appendChild(y),t.appendChild(e),t.appendChild(E),t.appendChild(i),o.appendChild(t),{messages:E,inputRow:i,input:p,attachButton:d,attachInput:m,avatarWrap:r,textCol:u}}function ie(n){let o=Date.now()-new Date(n).getTime(),t=Math.round(o/6e4);if(t<1)return"justo ahora";if(t<60)return`hace ${t} min`;let e=Math.round(t/60);return e<24?`hace ${e} h`:`hace ${Math.round(e/24)} d`}function le(n,o,t){if(n.querySelector(".chat-header-presence")?.remove(),o.querySelector(".chat-header-subtitle")?.remove(),!!t){if(t.viewing){let e=document.createElement("span");e.className="chat-header-presence",e.setAttribute("aria-hidden","true"),n.appendChild(e);let a=document.createElement("span");a.className="chat-header-subtitle",a.textContent=t.agentName?`${t.agentName} est\xE1 en l\xEDnea`:"En l\xEDnea",o.appendChild(a)}else if(t.lastActiveAt){let e=document.createElement("span");e.className="chat-header-subtitle",e.textContent=`\xDAltima vez activo ${ie(t.lastActiveAt)}`,o.appendChild(e)}}}async function ce(){let{prefix:n,apiBase:o}=ae();if(!n||!o){document.body.textContent="Configuraci\xF3n inv\xE1lida.";return}let t;try{t=await oe(o,n)}catch{document.body.textContent="No se pudo cargar el chat.";return}I(t);let{messages:e,inputRow:a,input:r,attachInput:u,avatarWrap:f,textCol:g}=re(t),E=new Map;function i(c){let s=crypto.randomUUID();return new Promise((l,T)=>{E.set(s,{resolve:l,reject:T}),b({type:V,payload:{requestId:s,file:c}})})}function p(c){return c?.attachmentUrl?.startsWith("/")?{...c,attachmentUrl:`${o}${c.attachmentUrl}`}:c}function d(c,s,l){e.appendChild(P(c,s,p(l))),e.scrollTop=e.scrollHeight}let m=null;function y(c){c&&!m?(m=L(),e.appendChild(m),e.scrollTop=e.scrollHeight):!c&&m&&(m.remove(),m=null)}function h(c){return c==="VISITOR"?"visitor":c==="ADMIN"?"admin":"bot"}function v(){let c=t.openingStyle??"SIMPLE";if(c!=="RULE_DRIVEN"&&t.welcomeText){if(c==="CARD"){e.appendChild(M(t.name,t.welcomeText)),e.scrollTop=e.scrollHeight;return}if(d(t.welcomeText,"bot"),c==="QUICK_REPLIES"&&t.commands?.length&&(e.appendChild(U(t.commands,x)),e.scrollTop=e.scrollHeight),c==="CTA_BUTTON"){let s=t.commands?.[0]??null,l=s?.label||"Iniciar conversaci\xF3n";e.appendChild(k(l,s,x,()=>r.focus())),e.scrollTop=e.scrollHeight}}}window.addEventListener("message",c=>{let s=c.data;if(!(!s||typeof s.type!="string")){if(s.type===Y){let l=s.payload?.text;l&&d(l,"bot")}else if(s.type===F){let l=s.payload;l&&(y(!1),d(l.text,"admin",l))}else if(s.type===K){let l=s.payload;y(!!l?.isTyping)}else if(s.type===Q){let l=s.payload;l&&(E.get(l.requestId)?.resolve(l),E.delete(l.requestId))}else if(s.type===z){let l=s.payload;l&&(E.get(l.requestId)?.reject(new Error(l.message)),E.delete(l.requestId))}else if(s.type===j)d(t.fallbackMessage,"bot");else if(s.type===W){let l=s.payload?.messages??[];l.length===0?v():l.forEach(T=>d(T.text,h(T.sender),T))}else if(s.type===$&&s.payload?.open)r.focus();else if(s.type===q){let l=s.payload?.presence??null;le(f,g,l)}}});let A=!1,C;function S(){C&&(clearTimeout(C),C=void 0),A&&(A=!1,b({type:_,payload:{isTyping:!1}}))}r.addEventListener("input",()=>{A||(A=!0,b({type:_,payload:{isTyping:!0}})),C&&clearTimeout(C),C=setTimeout(S,2e3)});function x(c){c&&(S(),d(c,"visitor"),b({type:N,payload:{text:c}}),r.value="")}a.addEventListener("submit",c=>{c.preventDefault(),x(r.value.trim())}),u?.addEventListener("change",async()=>{let c=u.files?.[0];if(!c)return;u.value="";let s=r.value.trim();try{let{url:l,name:T,mime:H}=await i(c);d(s,"visitor",{attachmentUrl:l,attachmentName:T,attachmentMime:H}),b({type:N,payload:{text:s,attachmentUrl:l,attachmentName:T,attachmentMime:H}}),r.value=""}catch{d("No se pudo subir el archivo. Intenta de nuevo.","bot")}}),b({type:B,payload:{triggerIcon:t.triggerIcon,soundEnabled:t.soundEnabled,soundTriggers:t.soundTriggers,autoOpenAfterSeconds:t.autoOpenAfterSeconds}})}ce();})();
|
|
1
|
+
"use strict";(()=>{var ee=["\u{1F600}","\u{1F602}","\u{1F609}","\u{1F60A}","\u{1F60D}","\u{1F914}","\u{1F605}","\u{1F622}","\u{1F62E}","\u{1F60E}","\u{1F64F}","\u{1F44D}","\u{1F44E}","\u{1F44F}","\u{1F64C}","\u{1F389}","\u2764\uFE0F","\u{1F525}","\u2705","\u274C","\u26A0\uFE0F","\u{1F4A1}","\u{1F4CE}","\u23F3"];function te(e){return!!e&&e.startsWith("image/")}function R(e,r,n){let t=document.createElement("div");if(t.className=`chat-bubble chat-bubble--${r}`,r==="admin"){let a=document.createElement("div");a.className="chat-bubble-label",a.textContent="Agente",t.appendChild(a)}if(e){let a=document.createElement("div");a.textContent=e,t.appendChild(a)}return n?.attachmentUrl&&t.appendChild(ne(n)),t}function ne(e){let{attachmentUrl:r,attachmentName:n,attachmentMime:t}=e;if(te(t)){let o=document.createElement("a");o.href=r,o.target="_blank",o.rel="noopener noreferrer",o.className="chat-attachment-image-link";let c=document.createElement("img");return c.src=r,c.alt=n??"",c.className="chat-attachment-image",o.appendChild(c),o}let a=document.createElement("a");return a.href=r,a.target="_blank",a.rel="noopener noreferrer",a.className="chat-attachment-file",a.textContent=`\u{1F4CE} ${n??"Archivo adjunto"}`,a}function I(){let e=document.createElement("div");e.className="chat-bubble chat-bubble--admin chat-typing-indicator",e.setAttribute("aria-live","polite"),e.setAttribute("aria-label","El agente est\xE1 escribiendo");for(let r=0;r<3;r++){let n=document.createElement("span");n.className="chat-typing-dot",e.appendChild(n)}return e}function M(e){let r=document.createElement("div");r.className="chat-emoji-wrapper";let n=document.createElement("button");n.type="button",n.className="chat-emoji-toggle",n.setAttribute("aria-label","Insertar emoji"),n.textContent="\u{1F642}";let t=document.createElement("div");return t.className="chat-emoji-panel",t.hidden=!0,ee.forEach(a=>{let o=document.createElement("button");o.type="button",o.className="chat-emoji-option",o.textContent=a,o.addEventListener("click",()=>{e(a),t.hidden=!0}),t.appendChild(o)}),n.addEventListener("click",()=>{t.hidden=!t.hidden}),document.addEventListener("click",a=>{r.contains(a.target)||(t.hidden=!0)}),r.appendChild(n),r.appendChild(t),{wrapper:r,toggleButton:n}}var ae={SOFT_TINT:"linear-gradient(180deg, color-mix(in srgb, var(--chat-primary-color) 8%, white) 0%, white 100%)",DIAGONAL_WASH:"linear-gradient(135deg, color-mix(in srgb, var(--chat-primary-color) 14%, white) 0%, white 55%, color-mix(in srgb, var(--chat-primary-color) 6%, white) 100%)",RADIAL_GLOW:"radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--chat-primary-color) 18%, white) 0%, white 65%)",DUOTONE_SOFT:"linear-gradient(160deg, color-mix(in srgb, var(--chat-primary-color) 20%, white) 0%, color-mix(in srgb, var(--chat-primary-color) 5%, white) 100%)",MESH_SOFT:"radial-gradient(60% 50% at 15% 10%, color-mix(in srgb, var(--chat-primary-color) 20%, white) 0%, transparent 60%), radial-gradient(50% 45% at 90% 20%, color-mix(in srgb, var(--chat-primary-color) 14%, white) 0%, transparent 60%), radial-gradient(70% 60% at 50% 100%, color-mix(in srgb, var(--chat-primary-color) 10%, white) 0%, transparent 60%), white"},oe={SOFT_TINT:"linear-gradient(180deg, color-mix(in srgb, var(--chat-primary-color) 14%, #17181f) 0%, #17181f 100%)",DIAGONAL_WASH:"linear-gradient(135deg, color-mix(in srgb, var(--chat-primary-color) 22%, #17181f) 0%, #17181f 55%, color-mix(in srgb, var(--chat-primary-color) 10%, #17181f) 100%)",RADIAL_GLOW:"radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--chat-primary-color) 26%, #17181f) 0%, #17181f 65%)",DUOTONE_SOFT:"linear-gradient(160deg, color-mix(in srgb, var(--chat-primary-color) 28%, #17181f) 0%, color-mix(in srgb, var(--chat-primary-color) 8%, #17181f) 100%)",MESH_SOFT:"radial-gradient(60% 50% at 15% 10%, color-mix(in srgb, var(--chat-primary-color) 28%, #17181f) 0%, transparent 60%), radial-gradient(50% 45% at 90% 20%, color-mix(in srgb, var(--chat-primary-color) 20%, #17181f) 0%, transparent 60%), radial-gradient(70% 60% at 50% 100%, color-mix(in srgb, var(--chat-primary-color) 16%, #17181f) 0%, transparent 60%), #17181f"};function w(e){e.primaryColor&&document.documentElement.style.setProperty("--chat-primary-color",e.primaryColor);let r=e.colorScheme==="DARK";document.body.dataset.theme=r?"dark":"light";let n=r?oe:ae,t=e.backgroundStyle&&n[e.backgroundStyle];t&&document.documentElement.style.setProperty("--chat-bg",t)}function D(e,r){let n=document.createElement("div");n.className="chat-welcome-card";let t=document.createElement("div");t.className="chat-welcome-card-icon",t.textContent="\u{1F4AC}",n.appendChild(t);let a=document.createElement("h4");a.className="chat-welcome-card-heading",a.textContent=`\xA1Hola! Bienvenido a ${e}`,n.appendChild(a);let o=document.createElement("p");return o.className="chat-welcome-card-body",o.textContent=r,n.appendChild(o),n}function L(e){return e==="SLASH"?"/":"@"}function U(e,r,n){let t=document.createElement("div");t.className="chat-autocomplete-panel",t.hidden=!0;let a=0,o=[];function c(){t.replaceChildren(),o.forEach((i,p)=>{let u=document.createElement("button");u.type="button",u.className=p===a?"chat-autocomplete-option chat-autocomplete-option--active":"chat-autocomplete-option";let g=document.createElement("span");g.className="chat-autocomplete-trigger",g.textContent=`${L(i.symbol)}${i.trigger}`;let y=document.createElement("span");y.className="chat-autocomplete-label",y.textContent=i.label,u.appendChild(g),u.appendChild(y),u.addEventListener("mousedown",m=>{m.preventDefault(),C(i)}),t.appendChild(u)})}function C(i){n(`${L(i.symbol)}${i.trigger} `),h()}function h(){t.hidden=!0,o=[]}function T(){let i=/^([/@])(\S*)$/.exec(e.value);if(!i){h();return}let[,p,u]=i,g=p==="/"?"SLASH":"AT";if(o=r.filter(y=>y.symbol===g&&y.trigger.toLowerCase().startsWith(u.toLowerCase())),o.length===0){h();return}a=0,t.hidden=!1,c()}return e.addEventListener("input",T),e.addEventListener("keydown",i=>{t.hidden||o.length===0||(i.key==="ArrowDown"?(i.preventDefault(),a=(a+1)%o.length,c()):i.key==="ArrowUp"?(i.preventDefault(),a=(a-1+o.length)%o.length,c()):i.key==="Enter"||i.key==="Tab"?(i.preventDefault(),C(o[a])):i.key==="Escape"&&h())}),document.addEventListener("click",i=>{!t.contains(i.target)&&i.target!==e&&h()}),t}var re={TICKET_CREATE:"\u{1F3AB}",TICKET_LOOKUP:"\u{1F50D}",SHOW_MENU:"\u{1F4CB}",CANNED_REPLY:"\u{1F4AC}",RUN_WORKFLOW:"\u26A1"};function k(e){return e&&re[e]||"\u{1F4AC}"}function B(e,r){let n=document.createElement("div");return n.className="chat-quick-replies",e.forEach(t=>{let a=document.createElement("button");a.type="button",a.className="chat-quick-reply-chip";let o=t.symbol==="SLASH"?"/":"@";a.textContent=`${k(t.action)} ${t.label}`,a.addEventListener("click",()=>r(`${o}${t.trigger}`)),n.appendChild(a)}),n}function G(e,r,n,t){let a=document.createElement("button");a.type="button",a.className="chat-cta-button";let o=r?k(r.action):"\u{1F4AC}";return a.textContent=`${o} ${e}`,a.addEventListener("click",()=>{if(r){let c=r.symbol==="SLASH"?"/":"@";n(`${c}${r.trigger}`)}else t()}),a}var $="chat:ready";var Y="chat:close",j="chat:toggle";var _="chat:send",W="chat:bot-reply",F="chat:connect-error",K="chat:history",q="chat:admin-message",V="chat:admin-typing",Q="chat:agent-presence",H="chat:typing",z="chat:upload-attachment",Z="chat:attachment-uploaded",J="chat:attachment-upload-error";function ie(){let e=new URLSearchParams(location.hash.replace(/^#/,""));return{prefix:e.get("prefix"),apiBase:e.get("api"),welcomeText:e.get("welcome"),primaryColor:e.get("color"),colorScheme:e.get("scheme")}}function A(e){window.parent.postMessage(e,"*")}async function le(e,r){let n=await fetch(`${e}/public/sites/${r}`);if(!n.ok)throw new Error("site config unavailable");return n.json()}function ce(e){let r=document.getElementById("app");for(;r.firstChild;)r.removeChild(r.firstChild);let n=document.createElement("div");n.className="chat-shell";let t=document.createElement("div");t.className="chat-header";let a=document.createElement("div");a.className="chat-header-title";let o=document.createElement("span");if(o.className="chat-header-avatar-wrap",e.logoUrl){let m=document.createElement("img");m.src=e.logoUrl,m.alt="",o.appendChild(m)}else{let m=document.createElement("span");m.className="chat-header-avatar",m.textContent=e.name.slice(0,1).toUpperCase(),o.appendChild(m)}a.appendChild(o);let c=document.createElement("div");c.className="chat-header-text";let C=document.createElement("span");C.className="chat-header-name",C.textContent=e.name,c.appendChild(C),a.appendChild(c),t.appendChild(a);let h=document.createElement("button");h.className="chat-close-button",h.type="button",h.setAttribute("aria-label","Cerrar"),h.textContent="\u2715",h.addEventListener("click",()=>A({type:Y})),t.appendChild(h);let T=document.createElement("div");T.className="chat-messages";let i=document.createElement("form");i.className="chat-input-row";let p=document.createElement("input");p.type="text",p.placeholder="Escribe un mensaje o /menu",p.autocomplete="off";let u,g;if(e.attachmentsEnabled){u=document.createElement("button"),u.type="button",u.className="chat-attach-button",u.setAttribute("aria-label","Adjuntar archivo"),u.textContent="\u{1F4CE}",g=document.createElement("input"),g.type="file",g.accept="image/png,image/jpeg,image/gif,image/webp,application/pdf",g.style.display="none";let m=g;u.addEventListener("click",()=>m.click()),i.appendChild(u),i.appendChild(g)}if(e.emojiPickerEnabled!==!1){let{wrapper:m}=M(E=>{let x=p.selectionStart??p.value.length,N=p.selectionEnd??p.value.length;p.value=p.value.slice(0,x)+E+p.value.slice(N),p.focus(),p.selectionStart=p.selectionEnd=x+E.length});i.appendChild(m)}let y=document.createElement("button");if(y.type="submit",y.textContent=e.sendButtonText||"Enviar",e.commands?.length){let m=U(p,e.commands,E=>{p.value=E,p.focus()});i.appendChild(m)}return i.appendChild(p),i.appendChild(y),n.appendChild(t),n.appendChild(T),n.appendChild(i),r.appendChild(n),{messages:T,inputRow:i,input:p,attachButton:u,attachInput:g,avatarWrap:o,textCol:c}}function se(e){let r=Date.now()-new Date(e).getTime(),n=Math.round(r/6e4);if(n<1)return"justo ahora";if(n<60)return`hace ${n} min`;let t=Math.round(n/60);return t<24?`hace ${t} h`:`hace ${Math.round(t/24)} d`}function de(e,r,n){if(e.querySelector(".chat-header-presence")?.remove(),r.querySelector(".chat-header-subtitle")?.remove(),!!n){if(n.viewing){let t=document.createElement("span");t.className="chat-header-presence",t.setAttribute("aria-hidden","true"),e.appendChild(t);let a=document.createElement("span");a.className="chat-header-subtitle",a.textContent=n.agentName?`${n.agentName} est\xE1 en l\xEDnea`:"En l\xEDnea",r.appendChild(a)}else if(n.lastActiveAt){let t=document.createElement("span");t.className="chat-header-subtitle",t.textContent=`\xDAltima vez activo ${se(n.lastActiveAt)}`,r.appendChild(t)}}}async function pe(){let{prefix:e,apiBase:r,welcomeText:n,primaryColor:t,colorScheme:a}=ie();if(!e||!r){document.body.textContent="Configuraci\xF3n inv\xE1lida.";return}let o;try{o=await le(r,e)}catch{document.body.textContent="No se pudo cargar el chat.";return}n&&(o.welcomeText=n),t&&(o.primaryColor=t),(a==="LIGHT"||a==="DARK")&&(o.colorScheme=a),w(o);let{messages:c,inputRow:C,input:h,attachInput:T,avatarWrap:i,textCol:p}=ce(o),u=new Map;function g(s){let d=crypto.randomUUID();return new Promise((l,f)=>{u.set(d,{resolve:l,reject:f}),A({type:z,payload:{requestId:d,file:s}})})}function y(s){return s?.attachmentUrl?.startsWith("/")?{...s,attachmentUrl:`${r}${s.attachmentUrl}`}:s}function m(s,d,l){c.appendChild(R(s,d,y(l))),c.scrollTop=c.scrollHeight}let E=null;function x(s){s&&!E?(E=I(),c.appendChild(E),c.scrollTop=c.scrollHeight):!s&&E&&(E.remove(),E=null)}function N(s){return s==="VISITOR"?"visitor":s==="ADMIN"?"admin":"bot"}function X(){let s=o.openingStyle??"SIMPLE";if(s!=="RULE_DRIVEN"&&o.welcomeText){if(s==="CARD"){c.appendChild(D(o.name,o.welcomeText)),c.scrollTop=c.scrollHeight;return}if(m(o.welcomeText,"bot"),s==="QUICK_REPLIES"&&o.commands?.length&&(c.appendChild(B(o.commands,S)),c.scrollTop=c.scrollHeight),s==="CTA_BUTTON"){let d=o.commands?.[0]??null,l=d?.label||"Iniciar conversaci\xF3n";c.appendChild(G(l,d,S,()=>h.focus())),c.scrollTop=c.scrollHeight}}}window.addEventListener("message",s=>{let d=s.data;if(!(!d||typeof d.type!="string")){if(d.type===W){let l=d.payload?.text;l&&m(l,"bot")}else if(d.type===q){let l=d.payload;l&&(x(!1),m(l.text,"admin",l))}else if(d.type===V){let l=d.payload;x(!!l?.isTyping)}else if(d.type===Z){let l=d.payload;l&&(u.get(l.requestId)?.resolve(l),u.delete(l.requestId))}else if(d.type===J){let l=d.payload;l&&(u.get(l.requestId)?.reject(new Error(l.message)),u.delete(l.requestId))}else if(d.type===F)m(o.fallbackMessage,"bot");else if(d.type===K){let l=d.payload?.messages??[];l.length===0?X():l.forEach(f=>m(f.text,N(f.sender),f))}else if(d.type===j&&d.payload?.open)h.focus();else if(d.type===Q){let l=d.payload?.presence??null;de(i,p,l)}}});let v=!1,b;function O(){b&&(clearTimeout(b),b=void 0),v&&(v=!1,A({type:H,payload:{isTyping:!1}}))}h.addEventListener("input",()=>{v||(v=!0,A({type:H,payload:{isTyping:!0}})),b&&clearTimeout(b),b=setTimeout(O,2e3)});function S(s){s&&(O(),m(s,"visitor"),A({type:_,payload:{text:s}}),h.value="")}C.addEventListener("submit",s=>{s.preventDefault(),S(h.value.trim())}),T?.addEventListener("change",async()=>{let s=T.files?.[0];if(!s)return;T.value="";let d=h.value.trim();try{let{url:l,name:f,mime:P}=await g(s);m(d,"visitor",{attachmentUrl:l,attachmentName:f,attachmentMime:P}),A({type:_,payload:{text:d,attachmentUrl:l,attachmentName:f,attachmentMime:P}}),h.value=""}catch{m("No se pudo subir el archivo. Intenta de nuevo.","bot")}}),A({type:$,payload:{triggerIcon:o.triggerIcon,soundEnabled:o.soundEnabled,soundTriggers:o.soundTriggers,autoOpenAfterSeconds:o.autoOpenAfterSeconds}})}pe();})();
|
package/dist/loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";(()=>{var Lt=Object.defineProperty;var Pt=(r,e)=>{for(var t in e)Lt(r,t,{get:e[t],enumerable:!0})};var x=Object.create(null);x.open="0";x.close="1";x.ping="2";x.pong="3";x.message="4";x.upgrade="5";x.noop="6";var U=Object.create(null);Object.keys(x).forEach(r=>{U[x[r]]=r});var V={type:"error",data:"parser error"};var Ie=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",De=typeof ArrayBuffer=="function",qe=r=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r&&r.buffer instanceof ArrayBuffer,F=({type:r,data:e},t,n)=>Ie&&e instanceof Blob?t?n(e):Be(e,n):De&&(e instanceof ArrayBuffer||qe(e))?t?n(e):Be(new Blob([e]),n):n(x[r]+(e||"")),Be=(r,e)=>{let t=new FileReader;return t.onload=function(){let n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(r)};function He(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}var le;function Ue(r,e){if(Ie&&r.data instanceof Blob)return r.data.arrayBuffer().then(He).then(e);if(De&&(r.data instanceof ArrayBuffer||qe(r.data)))return e(He(r.data));F(r,!1,t=>{le||(le=new TextEncoder),e(le.encode(t))})}var Ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let r=0;r<Ve.length;r++)G[Ve.charCodeAt(r)]=r;var Fe=r=>{let e=r.length*.75,t=r.length,n,s=0,i,o,a,c;r[r.length-1]==="="&&(e--,r[r.length-2]==="="&&e--);let f=new ArrayBuffer(e),u=new Uint8Array(f);for(n=0;n<t;n+=4)i=G[r.charCodeAt(n)],o=G[r.charCodeAt(n+1)],a=G[r.charCodeAt(n+2)],c=G[r.charCodeAt(n+3)],u[s++]=i<<2|o>>4,u[s++]=(o&15)<<4|a>>2,u[s++]=(a&3)<<6|c&63;return f};var Mt=typeof ArrayBuffer=="function",z=(r,e)=>{if(typeof r!="string")return{type:"message",data:Ge(r,e)};let t=r.charAt(0);return t==="b"?{type:"message",data:Bt(r.substring(1),e)}:U[t]?r.length>1?{type:U[t],data:r.substring(1)}:{type:U[t]}:V},Bt=(r,e)=>{if(Mt){let t=Fe(r);return Ge(t,e)}else return{base64:!0,data:r}},Ge=(r,e)=>{switch(e){case"blob":return r instanceof Blob?r:new Blob([r]);case"arraybuffer":default:return r instanceof ArrayBuffer?r:r.buffer}};var ze="",Ye=(r,e)=>{let t=r.length,n=new Array(t),s=0;r.forEach((i,o)=>{F(i,!1,a=>{n[o]=a,++s===t&&e(n.join(ze))})})},$e=(r,e)=>{let t=r.split(ze),n=[];for(let s=0;s<t.length;s++){let i=z(t[s],e);if(n.push(i),i.type==="error")break}return n};function Ke(){return new TransformStream({transform(r,e){Ue(r,t=>{let n=t.length,s;if(n<126)s=new Uint8Array(1),new DataView(s.buffer).setUint8(0,n);else if(n<65536){s=new Uint8Array(3);let i=new DataView(s.buffer);i.setUint8(0,126),i.setUint16(1,n)}else{s=new Uint8Array(9);let i=new DataView(s.buffer);i.setUint8(0,127),i.setBigUint64(1,BigInt(n))}r.data&&typeof r.data!="string"&&(s[0]|=128),e.enqueue(s),e.enqueue(t)})}})}var pe;function J(r){return r.reduce((e,t)=>e+t.length,0)}function Q(r,e){if(r[0].length===e)return r.shift();let t=new Uint8Array(e),n=0;for(let s=0;s<e;s++)t[s]=r[0][n++],n===r[0].length&&(r.shift(),n=0);return r.length&&n<r[0].length&&(r[0]=r[0].slice(n)),t}function Ze(r,e){pe||(pe=new TextDecoder);let t=[],n=0,s=-1,i=!1;return new TransformStream({transform(o,a){for(t.push(o);;){if(n===0){if(J(t)<1)break;let c=Q(t,1);i=(c[0]&128)===128,s=c[0]&127,s<126?n=3:s===126?n=1:n=2}else if(n===1){if(J(t)<2)break;let c=Q(t,2);s=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),n=3}else if(n===2){if(J(t)<8)break;let c=Q(t,8),f=new DataView(c.buffer,c.byteOffset,c.length),u=f.getUint32(0);if(u>Math.pow(2,21)-1){a.enqueue(V);break}s=u*Math.pow(2,32)+f.getUint32(4),n=3}else{if(J(t)<s)break;let c=Q(t,s);a.enqueue(z(i?c:pe.decode(c),e)),n=0}if(s===0||s>r){a.enqueue(V);break}}}})}var ue=4;function p(r){if(r)return Ht(r)}function Ht(r){for(var e in p.prototype)r[e]=p.prototype[e];return r}p.prototype.on=p.prototype.addEventListener=function(r,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+r]=this._callbacks["$"+r]||[]).push(e),this};p.prototype.once=function(r,e){function t(){this.off(r,t),e.apply(this,arguments)}return t.fn=e,this.on(r,t),this};p.prototype.off=p.prototype.removeListener=p.prototype.removeAllListeners=p.prototype.removeEventListener=function(r,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+r];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+r],this;for(var n,s=0;s<t.length;s++)if(n=t[s],n===e||n.fn===e){t.splice(s,1);break}return t.length===0&&delete this._callbacks["$"+r],this};p.prototype.emit=function(r){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+r],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t){t=t.slice(0);for(var n=0,s=t.length;n<s;++n)t[n].apply(this,e)}return this};p.prototype.emitReserved=p.prototype.emit;p.prototype.listeners=function(r){return this._callbacks=this._callbacks||{},this._callbacks["$"+r]||[]};p.prototype.hasListeners=function(r){return!!this.listeners(r).length};var T=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),g=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),We="arraybuffer";function j(r,...e){return e.reduce((t,n)=>(r.hasOwnProperty(n)&&(t[n]=r[n]),t),{})}var It=g.setTimeout,Dt=g.clearTimeout;function A(r,e){e.useNativeTimers?(r.setTimeoutFn=It.bind(g),r.clearTimeoutFn=Dt.bind(g)):(r.setTimeoutFn=g.setTimeout.bind(g),r.clearTimeoutFn=g.clearTimeout.bind(g))}var qt=1.33;function Xe(r){return typeof r=="string"?Ut(r):Math.ceil((r.byteLength||r.size)*qt)}function Ut(r){let e=0,t=0;for(let n=0,s=r.length;n<s;n++)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(n++,t+=4);return t}function ee(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Je(r){let e="";for(let t in r)r.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(r[t]));return e}function Qe(r){let e={},t=r.split("&");for(let n=0,s=t.length;n<s;n++){let i=t[n].split("=");e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e}var te=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}},w=class extends p{constructor(e){super(),this.writable=!1,A(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved("error",new te(e,t,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){let t=z(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){let t=Je(e);return t.length?"?"+t:""}};var Y=class extends w{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";let t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let n=0;this._polling&&(n++,this.once("pollComplete",function(){--n||t()})),this.writable||(n++,this.once("drain",function(){--n||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){let t=n=>{if(this.readyState==="opening"&&n.type==="open"&&this.onOpen(),n.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(n)};$e(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,Ye(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=ee()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}};var je=!1;try{je=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var et=je;function Vt(){}var fe=class extends Y{constructor(e){if(super(e),typeof location<"u"){let t=location.protocol==="https:",n=location.port;n||(n=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(s,i)=>{this.onError("xhr post error",s,i)})}doPoll(){let e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,n)=>{this.onError("xhr poll error",t,n)}),this.pollXhr=e}},v=class r extends p{constructor(e,t,n){super(),this.createRequest=e,A(this,n),this._opts=n,this._method=n.method||"GET",this._uri=t,this._data=n.data!==void 0?n.data:null,this._create()}_create(){var e;let t=j(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;let n=this._xhr=this.createRequest(t);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let s in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(s)&&n.setRequestHeader(s,this._opts.extraHeaders[s])}}catch{}if(this._method==="POST")try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{n.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var s;n.readyState===3&&((s=this._opts.cookieJar)===null||s===void 0||s.parseCookies(n.getResponseHeader("set-cookie"))),n.readyState===4&&(n.status===200||n.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof n.status=="number"?n.status:0)},0))},n.send(this._data)}catch(s){this.setTimeoutFn(()=>{this._onError(s)},0);return}typeof document<"u"&&(this._index=r.requestsCount++,r.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=Vt,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete r.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};v.requestsCount=0;v.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",tt);else if(typeof addEventListener=="function"){let r="onpagehide"in g?"pagehide":"unload";addEventListener(r,tt,!1)}}function tt(){for(let r in v.requests)v.requests.hasOwnProperty(r)&&v.requests[r].abort()}var Ft=function(){let r=rt({xdomain:!1});return r&&r.responseType!==null}(),S=class extends fe{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Ft&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new v(rt,this.uri(),e)}};function rt(r){let e=r.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||et))return new XMLHttpRequest}catch{}if(!e)try{return new g[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var nt=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",me=class extends w{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,n=nt?{}:j(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(s){return this.emitReserved("error",s)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1;F(n,this.supportsBinary,i=>{try{this.doWrite(n,i)}catch{}s&&T(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=ee()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},de=g.WebSocket||g.MozWebSocket,k=class extends me{createSocket(e,t,n){return nt?new de(e,t,n):t?new de(e,t):new de(e)}doWrite(e,t){this.ws.send(t)}};var P=class extends w{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{let t=Ze(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),s=Ke();s.readable.pipeTo(e.writable),this._writer=s.writable.getWriter();let i=()=>{n.read().then(({done:a,value:c})=>{a||(this.onPacket(c),i())}).catch(a=>{})};i();let o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1;this._writer.write(n).then(()=>{s&&T(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}};var ye={websocket:k,webtransport:P,polling:S};var Gt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,zt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function M(r){if(r.length>8e3)throw"URI too long";let e=r,t=r.indexOf("["),n=r.indexOf("]");t!=-1&&n!=-1&&(r=r.substring(0,t)+r.substring(t,n).replace(/:/g,";")+r.substring(n,r.length));let s=Gt.exec(r||""),i={},o=14;for(;o--;)i[zt[o]]=s[o]||"";return t!=-1&&n!=-1&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=Yt(i,i.path),i.queryKey=$t(i,i.query),i}function Yt(r,e){let t=/\/{2,9}/g,n=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&n.splice(0,1),e.slice(-1)=="/"&&n.splice(n.length-1,1),n}function $t(r,e){let t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,s,i){s&&(t[s]=i)}),t}var ge=typeof addEventListener=="function"&&typeof removeEventListener=="function",re=[];ge&&addEventListener("offline",()=>{re.forEach(r=>r())},!1);var N=class r extends p{constructor(e,t){if(super(),this.binaryType=We,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){let n=M(e);t.hostname=n.host,t.secure=n.protocol==="https"||n.protocol==="wss",t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=M(t.host).host);A(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach(n=>{let s=n.prototype.name;this.transports.push(s),this._transportsByName[s]=n}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Qe(this.opts.query)),ge&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},re.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=ue,t.transport=e,this.id&&(t.sid=this.id);let n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let e=this.opts.rememberUpgrade&&r.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",r.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let n=0;n<this.writeBuffer.length;n++){let s=this.writeBuffer[n].data;if(s&&(t+=Xe(s)),n>0&&t>this._maxPayload)return this.writeBuffer.slice(0,n);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,T(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket("message",e,t,n),this}send(e,t,n){return this._sendPacket("message",e,t,n),this}_sendPacket(e,t,n,s){if(typeof t=="function"&&(s=t,t=void 0),typeof n=="function"&&(s=n,n=null),this.readyState==="closing"||this.readyState==="closed")return;n=n||{},n.compress=n.compress!==!1;let i={type:e,data:t,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),s&&this.once("flush",s),this.flush()}close(){let e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():e()}):this.upgrading?n():e()),this}_onError(e){if(r.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ge&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let n=re.indexOf(this._offlineEventListener);n!==-1&&re.splice(n,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}};N.protocol=ue;var ne=class extends N{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;N.priorWebsocketSuccess=!1;let s=()=>{n||(t.send([{type:"ping",data:"probe"}]),t.once("packet",d=>{if(!n)if(d.type==="pong"&&d.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;N.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{n||this.readyState!=="closed"&&(u(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{let b=new Error("probe error");b.transport=t.name,this.emitReserved("upgradeError",b)}}))};function i(){n||(n=!0,u(),t.close(),t=null)}let o=d=>{let b=new Error("probe error: "+d);b.transport=t.name,i(),this.emitReserved("upgradeError",b)};function a(){o("transport closed")}function c(){o("socket closed")}function f(d){t&&d.name!==t.name&&i()}let u=()=>{t.removeListener("open",s),t.removeListener("error",o),t.removeListener("close",a),this.off("close",c),this.off("upgrading",f)};t.once("open",s),t.once("error",o),t.once("close",a),this.once("close",c),this.once("upgrading",f),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},B=class extends ne{constructor(e,t={}){let n=typeof e=="object",s=n?{...e}:{...t};(!s.transports||s.transports&&typeof s.transports[0]=="string")&&(s.transports=(s.transports||["polling","websocket","webtransport"]).map(i=>ye[i]).filter(i=>!!i)),super(n?s:e,s)}};var xn=B.protocol;function st(r,e="",t){let n=r;t=t||typeof location<"u"&&location,r==null&&(r=t.protocol+"//"+t.host),typeof r=="string"&&(r.charAt(0)==="/"&&(r.charAt(1)==="/"?r=t.protocol+r:r=t.host+r),/^(https?|wss?):\/\//.test(r)||(typeof t<"u"?r=t.protocol+"//"+r:r="https://"+r),n=M(r)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";let i=n.host.indexOf(":")!==-1?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+i+":"+n.port+e,n.href=n.protocol+"://"+i+(t&&t.port===n.port?"":":"+n.port),n}var Te={};Pt(Te,{Decoder:()=>xe,Encoder:()=>be,PacketType:()=>h,isPacketValid:()=>tr,protocol:()=>ht});var Zt=typeof ArrayBuffer=="function",Wt=r=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r.buffer instanceof ArrayBuffer,it=Object.prototype.toString,Xt=typeof Blob=="function"||typeof Blob<"u"&&it.call(Blob)==="[object BlobConstructor]",Jt=typeof File=="function"||typeof File<"u"&&it.call(File)==="[object FileConstructor]";function K(r){return Zt&&(r instanceof ArrayBuffer||Wt(r))||Xt&&r instanceof Blob||Jt&&r instanceof File}function $(r,e){if(!r||typeof r!="object")return!1;if(Array.isArray(r)){for(let t=0,n=r.length;t<n;t++)if($(r[t]))return!0;return!1}if(K(r))return!0;if(r.toJSON&&typeof r.toJSON=="function"&&arguments.length===1)return $(r.toJSON(),!0);for(let t in r)if(Object.prototype.hasOwnProperty.call(r,t)&&$(r[t]))return!0;return!1}function ot(r){let e=[],t=r.data,n=r;return n.data=se(t,e),n.attachments=e.length,{packet:n,buffers:e}}function se(r,e,t){if(!r)return r;if(K(r)){let n={_placeholder:!0,num:e.length};return e.push(r),n}else if(Array.isArray(r)){let n=new Array(r.length);for(let s=0;s<r.length;s++)n[s]=se(r[s],e);return n}else if(typeof r=="object"&&!(r instanceof Date)){if(r.toJSON&&typeof r.toJSON=="function"&&!t)return se(r.toJSON(),e,!0);let n={};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=se(r[s],e));return n}return r}function at(r,e){return r.data=_e(r.data,e),delete r.attachments,r}function _e(r,e){if(!r)return r;if(r&&r._placeholder===!0){if(typeof r.num=="number"&&r.num>=0&&r.num<e.length)return e[r.num];throw new Error("illegal attachments")}else if(Array.isArray(r))for(let t=0;t<r.length;t++)r[t]=_e(r[t],e);else if(typeof r=="object")for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&(r[t]=_e(r[t],e));return r}var ct=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ht=5,h;(function(r){r[r.CONNECT=0]="CONNECT",r[r.DISCONNECT=1]="DISCONNECT",r[r.EVENT=2]="EVENT",r[r.ACK=3]="ACK",r[r.CONNECT_ERROR=4]="CONNECT_ERROR",r[r.BINARY_EVENT=5]="BINARY_EVENT",r[r.BINARY_ACK=6]="BINARY_ACK"})(h||(h={}));var be=class{constructor(e){this.replacer=e}encode(e){return(e.type===h.EVENT||e.type===h.ACK)&&$(e)?this.encodeAsBinary({type:e.type===h.EVENT?h.BINARY_EVENT:h.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===h.BINARY_EVENT||e.type===h.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=ot(e),n=this.encodeAsString(t.packet),s=t.buffers;return s.unshift(n),s}},xe=class r extends p{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e=="function"?{reviver:e}:e)}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);let n=t.type===h.BINARY_EVENT;n||t.type===h.BINARY_ACK?(t.type=n?h.EVENT:h.ACK,this.reconstructor=new Ee(t)):super.emitReserved("decoded",t)}else if(K(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0,n={type:Number(e.charAt(0))};if(h[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===h.BINARY_EVENT||n.type===h.BINARY_ACK){let i=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);let o=e.substring(i,t);if(o!=Number(o)||e.charAt(t)!=="-")throw new Error("Illegal attachments");let a=Number(o);if(!lt(a)||a<1)throw new Error("Illegal attachments");if(a>this.opts.maxAttachments)throw new Error("too many attachments");n.attachments=a}if(e.charAt(t+1)==="/"){let i=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););n.nsp=e.substring(i,t)}else n.nsp="/";let s=e.charAt(t+1);if(s!==""&&Number(s)==s){let i=t+1;for(;++t;){let o=e.charAt(t);if(o==null||Number(o)!=o){--t;break}if(t===e.length)break}n.id=Number(e.substring(i,t+1))}if(e.charAt(++t)){let i=this.tryParse(e.substr(t));if(r.isPayloadValid(n.type,i))n.data=i;else throw new Error("invalid payload")}return n}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case h.CONNECT:return ie(t);case h.DISCONNECT:return t===void 0;case h.CONNECT_ERROR:return typeof t=="string"||ie(t);case h.EVENT:case h.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&ct.indexOf(t[0])===-1);case h.ACK:case h.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},Ee=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let t=at(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function Qt(r){return typeof r=="string"}var lt=Number.isInteger||function(r){return typeof r=="number"&&isFinite(r)&&Math.floor(r)===r};function jt(r){return r===void 0||lt(r)}function ie(r){return Object.prototype.toString.call(r)==="[object Object]"}function er(r,e){switch(r){case h.CONNECT:return e===void 0||ie(e);case h.DISCONNECT:return e===void 0;case h.EVENT:return Array.isArray(e)&&(typeof e[0]=="number"||typeof e[0]=="string"&&ct.indexOf(e[0])===-1);case h.ACK:return Array.isArray(e);case h.CONNECT_ERROR:return typeof e=="string"||ie(e);default:return!1}}function tr(r){return Qt(r.nsp)&&jt(r.id)&&er(r.type,r.data)}function _(r,e,t){return r.on(e,t),function(){r.off(e,t)}}var rr=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),H=class extends p{constructor(e,t,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[_(e,"open",this.onopen.bind(this)),_(e,"packet",this.onpacket.bind(this)),_(e,"error",this.onerror.bind(this)),_(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var n,s,i;if(rr.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;let o={type:h.EVENT,data:t};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){let u=this.ids++,d=t.pop();this._registerAckCallback(u,d),o.id=u}let a=(s=(n=this.io.engine)===null||n===void 0?void 0:n.transport)===null||s===void 0?void 0:s.writable,c=this.connected&&!(!((i=this.io.engine)===null||i===void 0)&&i._hasPingExpired());return this.flags.volatile&&!a||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(e,t){var n;let s=(n=this.flags.timeout)!==null&&n!==void 0?n:this._opts.ackTimeout;if(s===void 0){this.acks[e]=t;return}let i=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let a=0;a<this.sendBuffer.length;a++)this.sendBuffer[a].id===e&&this.sendBuffer.splice(a,1);t.call(this,new Error("operation has timed out"))},s),o=(...a)=>{this.io.clearTimeoutFn(i),t.apply(this,a)};o.withError=!0,this.acks[e]=o}emitWithAck(e,...t){return new Promise((n,s)=>{let i=(o,a)=>o?s(o):n(a);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((s,...i)=>(this._queue[0],s!==null?n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(s)):(this._queue.shift(),t&&t(null,...i)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:h.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(n=>String(n.id)===e)){let n=this.acks[e];delete this.acks[e],n.withError&&n.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case h.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case h.EVENT:case h.BINARY_EVENT:this.onevent(e);break;case h.ACK:case h.BINARY_ACK:this.onack(e);break;case h.DISCONNECT:this.ondisconnect();break;case h.CONNECT_ERROR:this.destroy();let n=new Error(e.data.message);n.data=e.data.data,this.emitReserved("connect_error",n);break}}onevent(e){let t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){let t=this._anyListeners.slice();for(let n of t)n.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){let t=this,n=!1;return function(...s){n||(n=!0,t.packet({type:h.ACK,id:e,data:s}))}}onack(e){let t=this.acks[e.id];typeof t=="function"&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:h.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function L(r){r=r||{},this.ms=r.min||100,this.max=r.max||1e4,this.factor=r.factor||2,this.jitter=r.jitter>0&&r.jitter<=1?r.jitter:0,this.attempts=0}L.prototype.duration=function(){var r=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*r);r=Math.floor(e*10)&1?r+t:r-t}return Math.min(r,this.max)|0};L.prototype.reset=function(){this.attempts=0};L.prototype.setMin=function(r){this.ms=r};L.prototype.setMax=function(r){this.max=r};L.prototype.setJitter=function(r){this.jitter=r};var I=class extends p{constructor(e,t){var n;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,A(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((n=t.randomizationFactor)!==null&&n!==void 0?n:.5),this.backoff=new L({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;let s=t.parser||Te;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new B(this.uri,this.opts);let t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;let s=_(t,"open",function(){n.onopen(),e&&e()}),i=a=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",a),e?e(a):this.maybeReconnectOnOpen()},o=_(t,"error",i);if(this._timeout!==!1){let a=this._timeout,c=this.setTimeoutFn(()=>{s(),i(new Error("timeout")),t.close()},a);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(s),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let e=this.engine;this.subs.push(_(e,"ping",this.onping.bind(this)),_(e,"data",this.ondata.bind(this)),_(e,"error",this.onerror.bind(this)),_(e,"close",this.onclose.bind(this)),_(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){T(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new H(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let n of t)if(this.nsps[n].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var n;this.cleanup(),(n=this.engine)===null||n===void 0||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(s=>{s?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",s)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}};var Z={};function W(r,e){typeof r=="object"&&(e=r,r=void 0),e=e||{};let t=st(r,e.path||"/socket.io"),n=t.source,s=t.id,i=t.path,o=Z[s]&&i in Z[s].nsps,a=e.forceNew||e["force new connection"]||e.multiplex===!1||o,c;return a?c=new I(n,e):(Z[s]||(Z[s]=new I(n,e)),c=Z[s]),t.query&&!e.query&&(e.query=t.queryKey),c.socket(t.path,e)}Object.assign(W,{Manager:I,Socket:H,io:W,connect:W});function pt(r,e,t){return W(`${r}/chat`,{auth:{apiKey:e,visitorId:t??void 0},transports:["websocket"]})}var nr="chat",ut={chat:'<path d="M4 5h16v11H9l-4 3.5V16H4V5Z"/><path d="M8 9h8M8 12h5"/>',"chat-round":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/>',"chat-dots":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/><circle cx="9" cy="11.5" r=".9" fill="currentColor" stroke="none"/><circle cx="12" cy="11.5" r=".9" fill="currentColor" stroke="none"/><circle cx="15" cy="11.5" r=".9" fill="currentColor" stroke="none"/>',"chat-two":'<path d="M4 5.5h10v7h-4l-2.5 2V12.5H4V5.5Z"/><path d="M10 10.5h10v7h-3.5L14 20v-2.5h-4v-7Z"/>',thought:'<path d="M8 5.5a5 5 0 0 1 9 3 4 4 0 0 1-1 7.9H8.5A4.5 4.5 0 0 1 8 5.5Z"/><circle cx="7" cy="18" r="1" fill="currentColor" stroke="none"/><circle cx="5" cy="20.5" r=".6" fill="currentColor" stroke="none"/>',mail:'<rect x="3.5" y="6" width="17" height="12" rx="1.5"/><path d="M4 7l8 6 8-6"/>',"mail-open":'<rect x="3.5" y="8" width="17" height="10" rx="1.5"/><path d="M3.5 8 12 3l8.5 5"/><path d="M3.5 8 10 13M20.5 8 14 13"/>',send:'<path d="M4 12 20 4l-4 16-5-6-6-2Z"/><path d="M20 4 9.5 14"/>',robot:'<rect x="5" y="8" width="14" height="10" rx="2.5"/><path d="M12 8V5"/><circle cx="12" cy="4" r="1.1" fill="currentColor" stroke="none"/><circle cx="9" cy="13" r="1.1" fill="currentColor" stroke="none"/><circle cx="15" cy="13" r="1.1" fill="currentColor" stroke="none"/><path d="M9 16.5h6"/>',brain:'<path d="M9 4.5a3 3 0 0 0-3 3 3 3 0 0 0-1 5.6 3 3 0 0 0 3.6 4A3 3 0 0 0 12 19V6a2.5 2.5 0 0 0-3-1.5Z"/><path d="M15 4.5a3 3 0 0 1 3 3 3 3 0 0 1 1 5.6 3 3 0 0 1-3.6 4A3 3 0 0 1 12 19V6a2.5 2.5 0 0 1 3-1.5Z"/>',bulb:'<path d="M9 16.5h6M10 19.5h4"/><path d="M12 3.5a6 6 0 0 0-3.2 11.1c.6.4 1 1.1 1 1.9h4.4c0-.8.4-1.5 1-1.9A6 6 0 0 0 12 3.5Z"/>',bolt:'<path d="M12.5 3 5 13.5h5.5L11 21l7.5-10.5H13l-.5-7.5Z"/>',sparkles:'<path d="M12 3.5c.5 3 1.7 4.2 4.7 4.7-3 .5-4.2 1.7-4.7 4.7-.5-3-1.7-4.2-4.7-4.7 3-.5 4.2-1.7 4.7-4.7Z"/><path d="M18.5 14c.3 1.7 1 2.4 2.7 2.7-1.7.3-2.4 1-2.7 2.7-.3-1.7-1-2.4-2.7-2.7 1.7-.3 2.4-1 2.7-2.7Z"/>',orbit:'<circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none"/><ellipse cx="12" cy="12" rx="9" ry="3.6"/><ellipse cx="12" cy="12" rx="9" ry="3.6" transform="rotate(60 12 12)"/><ellipse cx="12" cy="12" rx="9" ry="3.6" transform="rotate(120 12 12)"/>',rocket:'<path d="M12 3c2.5 1.5 4 4.5 4 8.5 0 2-1 4-1 4H9s-1-2-1-4c0-4 1.5-7 4-8.5Z"/><circle cx="12" cy="9" r="1.4"/><path d="M9 15l-2.5 2.5M15 15l2.5 2.5M10 19l2 2 2-2"/>',wand:'<path d="M4 20 15 9"/><path d="M17 4l.8 1.9L19.7 6.7 17.8 7.5 17 9.4 16.2 7.5 14.3 6.7 16.2 5.9 17 4Z"/><path d="M6 13.5l.5 1.2 1.2.5-1.2.5-.5 1.2-.5-1.2L4.3 15l1.2-.5.5-1.2Z"/>',wave:'<path d="M9 13V6a1.5 1.5 0 0 1 3 0v5"/><path d="M12 11V4.5a1.5 1.5 0 0 1 3 0V11"/><path d="M15 11V6a1.5 1.5 0 0 1 3 0v8c0 3-2 6-6 6s-6-2.5-6.5-5L4 12.5a1.4 1.4 0 0 1 2.3-1.6L9 14"/>',"raised-hand":'<path d="M7 20V10a1.2 1.2 0 0 1 2.4 0v3"/><path d="M9.4 12.5V6a1.2 1.2 0 0 1 2.4 0v6.5"/><path d="M11.8 12.5V5a1.2 1.2 0 0 1 2.4 0v7.5"/><path d="M14.2 12.5V7a1.2 1.2 0 0 1 2.4 0v7c0 3.3-2.3 6-6 6-2.5 0-4-1.2-5-3l-2-3.6a1.3 1.3 0 0 1 2.2-1.3l1.6 2.4"/>',smile:'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 14c1 1.3 2.2 2 3.5 2s2.5-.7 3.5-2"/><circle cx="9" cy="10" r=".9" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r=".9" fill="currentColor" stroke="none"/>',"smile-chat":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/><circle cx="9.5" cy="11" r=".8" fill="currentColor" stroke="none"/><circle cx="14.5" cy="11" r=".8" fill="currentColor" stroke="none"/><path d="M9.5 13.5c.7.8 1.5 1.2 2.5 1.2s1.8-.4 2.5-1.2"/>',handshake:'<path d="M3 12l4-3 3.5 2-1.5 2"/><path d="M21 12l-4-3-3.5 2 1.5 2"/><path d="M9 13l2.5 2.2a1.4 1.4 0 0 0 2-2l-3-2.7"/><path d="M15 13l-2.5 2.2"/>',"heart-chat":'<path d="M12 20s-7-4.4-9.3-8.8C1.3 8 3 5 6.2 5c2 0 3.4 1.2 4.3 2.4C11.4 6.2 12.8 5 14.8 5 18 5 19.7 8 17.3 11.2 15 15.6 12 20 12 20Z"/>',"thumbs-up":'<path d="M7 11v9H4v-9h3Z"/><path d="M7 11l3.5-6.5a1.6 1.6 0 0 1 3 1l-1 4.5H17a2 2 0 0 1 2 2.4l-1.3 6A2 2 0 0 1 15.7 20H10a3 3 0 0 1-3-3v-6Z"/>',wink:'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 14c1 1.3 2.2 2 3.5 2s2.5-.7 3.5-2"/><path d="M7.5 10h3"/><circle cx="15" cy="10" r=".9" fill="currentColor" stroke="none"/>',headset:'<path d="M4 13a8 8 0 0 1 16 0"/><rect x="3" y="13" width="4" height="6" rx="1.5"/><rect x="17" y="13" width="4" height="6" rx="1.5"/><path d="M19 19v1a3 3 0 0 1-3 3h-3"/>',bell:'<path d="M6 17V11a6 6 0 0 1 12 0v6l1.5 2h-15L6 17Z"/><path d="M10 20.5a2 2 0 0 0 4 0"/>',megaphone:'<path d="M3 10v4h3l6 4V6L6 10H3Z"/><path d="M14 9a4 4 0 0 1 0 6"/><path d="M17 6.5a8 8 0 0 1 0 11"/>',broadcast:'<circle cx="12" cy="12" r="2"/><path d="M8.5 8.5a5 5 0 0 0 0 7M15.5 8.5a5 5 0 0 1 0 7"/><path d="M5.5 5.5a9.5 9.5 0 0 0 0 13M18.5 5.5a9.5 9.5 0 0 1 0 13"/>',"life-ring":'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="3.5"/><path d="M6 6l3.5 3.5M18 6l-3.5 3.5M6 18l3.5-3.5M18 18l-3.5-3.5"/>',question:'<circle cx="12" cy="12" r="8.5"/><path d="M9.5 9.3a2.5 2.5 0 1 1 3.6 2.3c-.8.5-1.1.9-1.1 1.9"/><circle cx="12" cy="16.5" r=".9" fill="currentColor" stroke="none"/>',info:'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="8" r=".9" fill="currentColor" stroke="none"/><path d="M12 11v6"/>',"phone-support":'<path d="M6.5 4.5h3L11 8l-2 1.5a11 11 0 0 0 5.5 5.5L16 13l3.5 1.5v3a2 2 0 0 1-2.2 2A15.5 15.5 0 0 1 4.5 6.7a2 2 0 0 1 2-2.2Z"/>',star:'<path d="M12 3.5l2.4 5.1 5.6.6-4.2 3.8 1.2 5.5L12 15.7l-5 2.8 1.2-5.5-4.2-3.8 5.6-.6L12 3.5Z"/>',"star-fill":'<path d="M12 3.5l2.4 5.1 5.6.6-4.2 3.8 1.2 5.5L12 15.7l-5 2.8 1.2-5.5-4.2-3.8 5.6-.6L12 3.5Z" fill="currentColor"/>',"check-circle":'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 12.3 11 15l4.5-5.5"/>',target:'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"/>',flame:'<path d="M12 3.5c1 2.5-.5 3.5-1.5 5C9 10 8 11.5 8 13.5A4 4 0 0 0 12 17.5a4 4 0 0 0 4-4c0-1.5-.7-2.3-1.3-3 .3 1.2-.2 2-1 2.3.3-2-1-2.7-1.7-4.3Z"/>',"shield-check":'<path d="M12 3.5 19 6.5V11c0 5-3 8.2-7 9.5-4-1.3-7-4.5-7-9.5V6.5L12 3.5Z"/><path d="M9 12l2 2 4-4.5"/>',crown:'<path d="M4 17l-1.5-8L7 12l5-6 5 6 4.5-3L20 17H4Z"/><path d="M4 19.5h16"/>',gift:'<rect x="4" y="9.5" width="16" height="10" rx="1"/><path d="M4 13h16"/><path d="M12 9.5v10"/><path d="M12 9.5c-1-2.5-2.8-4-4.3-4A2 2 0 0 0 6 7.5c0 1.3 1.2 2 2.5 2H12Z"/><path d="M12 9.5c1-2.5 2.8-4 4.3-4A2 2 0 0 1 18 7.5c0 1.3-1.2 2-2.5 2H12Z"/>'};function Ae(r){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">${r&&ut[r]||ut[nr]}</svg>`}var oe={SOFT:{waveform:"sine",gain:.12,tones:{CHAT_OPENED:[{freq:523,start:0,duration:.14}],BOT_REPLY:[{freq:659,start:0,duration:.16}],AGENT_MESSAGE:[{freq:494,start:0,duration:.14},{freq:587,start:.12,duration:.2}],RULE_TRIGGERED:[{freq:587,start:0,duration:.13}],COMMAND_EXECUTED:[{freq:440,start:0,duration:.18}]}},CLASSIC:{waveform:"sine",gain:.2,tones:{CHAT_OPENED:[{freq:660,start:0,duration:.09}],BOT_REPLY:[{freq:880,start:0,duration:.12}],AGENT_MESSAGE:[{freq:587,start:0,duration:.1},{freq:784,start:.1,duration:.14}],RULE_TRIGGERED:[{freq:740,start:0,duration:.08},{freq:740,start:.12,duration:.08}],COMMAND_EXECUTED:[{freq:784,start:0,duration:.1},{freq:660,start:.1,duration:.14}]}},BELL:{waveform:"triangle",gain:.15,tones:{CHAT_OPENED:[{freq:784,start:0,duration:.1},{freq:988,start:.05,duration:.12}],BOT_REPLY:[{freq:1046,start:0,duration:.18}],AGENT_MESSAGE:[{freq:659,start:0,duration:.12},{freq:784,start:.1,duration:.12},{freq:988,start:.2,duration:.22}],RULE_TRIGGERED:[{freq:1174,start:0,duration:.14}],COMMAND_EXECUTED:[{freq:880,start:0,duration:.1},{freq:1046,start:.1,duration:.16}]}}},sr={enabled:!0,soundStyle:"CLASSIC"},ae=class{constructor(){this.triggers={}}setTriggers(e){this.triggers=e}prime(){if(this.context){this.context.state==="suspended"&&this.context.resume();return}let e=window.AudioContext??window.webkitAudioContext;if(e)try{this.context=new e}catch{}}play(e){let t=this.context;if(!t)return;let n=this.triggers[e]??sr;if(!n.enabled)return;let{waveform:s,gain:i}=oe[n.soundStyle]??oe.CLASSIC,o=(oe[n.soundStyle]??oe.CLASSIC).tones[e],a=t.currentTime;for(let c of o){let f=t.createOscillator(),u=t.createGain();f.type=s,f.frequency.value=c.freq;let d=a+c.start,b=d+c.duration;u.gain.setValueAtTime(0,d),u.gain.linearRampToValueAtTime(i,d+.01),u.gain.linearRampToValueAtTime(0,b),f.connect(u),u.connect(t.destination),f.start(d),f.stop(b+.02)}}};var ft="chat:ready";var dt="chat:close",mt="chat:toggle",yt="chat:resize",gt="chat:send",_t="chat:bot-reply",bt="chat:connect-error",xt="chat:history",Et="chat:admin-message",Tt="chat:admin-typing",we="chat:agent-presence",At="chat:typing",wt="chat:upload-attachment",Ct="chat:attachment-uploaded",vt="chat:attachment-upload-error";var Ce="zabbu-chat-widget-launcher",ve="zabbu-chat-widget-panel",kt="zabbu-chat-widget-iframe",X="zabbu-chat-widget-teaser",Se="zabbu-chat-widget-badge",Rt="#2563eb";function ir(r,e){switch(r){case"NONE":return{launcher:"none",panel:"none",teaser:"none"};case"ELEVATED":return{launcher:"0 16px 40px -8px rgba(0, 0, 0, 0.45), 0 6px 16px rgba(0, 0, 0, 0.25)",panel:"0 30px 80px -16px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.3)",teaser:"0 20px 50px -12px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.2)"};case"BRAND_GLOW":{let t=ke(e,.5),n=ke(e,.3);return{launcher:`0 10px 26px -4px ${t}, 0 3px 10px ${n}`,panel:`0 26px 64px -12px ${t}, 0 10px 28px ${n}`,teaser:`0 18px 42px -8px ${t}, 0 6px 16px ${n}`}}case"SOFT":default:return{launcher:"0 4px 12px rgba(0, 0, 0, 0.2)",panel:"0 8px 30px rgba(0, 0, 0, 0.25)",teaser:"0 6px 20px rgba(0, 0, 0, 0.15)"}}}function ke(r,e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);if(!t)return ke(Rt,e);let[n,s,i]=t.slice(1).map(o=>parseInt(o,16));return`rgba(${n}, ${s}, ${i}, ${e})`}function or(r,e,t){let n=r||Rt,s=ir(e,n),i=document.documentElement.style;i.setProperty("--zabbu-chat-primary",n),i.setProperty("--zabbu-chat-shadow-launcher",s.launcher),i.setProperty("--zabbu-chat-shadow-panel",s.panel),i.setProperty("--zabbu-chat-shadow-teaser",s.teaser),document.getElementById(X)?.classList.toggle("zabbu-chat-teaser-dark",t==="DARK")}async function ar(r,e){try{let t=await fetch(`${r}/public/sites/${e}`);if(!t.ok)return;let n=await t.json();or(n.primaryColor??null,n.shadowStyle??"SOFT",n.colorScheme??"LIGHT")}catch{}}function cr(){let r=document.currentScript;if(!r)throw new Error("zabbu-chat-widget: loader.js must run as a plain <script> tag");return r}function hr(r){let e=r.dataset.apiBase;return e?e.replace(/\/$/,""):"https://api-production-e565.up.railway.app"}function lr(r){return new URL(r.src).href.replace(/\/[^/]*$/,"")}function St(r){return`zabbu-chat-visitor:${r}`}function pr(){let r=document.createElement("style");r.textContent=`
|
|
2
|
-
#${
|
|
1
|
+
"use strict";(()=>{var Kt=Object.defineProperty;var zt=(r,e)=>{for(var t in e)Kt(r,t,{get:e[t],enumerable:!0})};var T=Object.create(null);T.open="0";T.close="1";T.ping="2";T.pong="3";T.message="4";T.upgrade="5";T.noop="6";var z=Object.create(null);Object.keys(T).forEach(r=>{z[T[r]]=r});var W={type:"error",data:"parser error"};var Ke=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",ze=typeof ArrayBuffer=="function",We=r=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r&&r.buffer instanceof ArrayBuffer,Z=({type:r,data:e},t,n)=>Ke&&e instanceof Blob?t?n(e):Ve(e,n):ze&&(e instanceof ArrayBuffer||We(e))?t?n(e):Ve(new Blob([e]),n):n(T[r]+(e||"")),Ve=(r,e)=>{let t=new FileReader;return t.onload=function(){let n=t.result.split(",")[1];e("b"+(n||""))},t.readAsDataURL(r)};function Ge(r){return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}var Ee;function Ze(r,e){if(Ke&&r.data instanceof Blob)return r.data.arrayBuffer().then(Ge).then(e);if(ze&&(r.data instanceof ArrayBuffer||We(r.data)))return e(Ge(r.data));Z(r,!1,t=>{Ee||(Ee=new TextEncoder),e(Ee.encode(t))})}var $e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",$=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let r=0;r<$e.length;r++)$[$e.charCodeAt(r)]=r;var Ye=r=>{let e=r.length*.75,t=r.length,n,s=0,i,o,a,c;r[r.length-1]==="="&&(e--,r[r.length-2]==="="&&e--);let d=new ArrayBuffer(e),f=new Uint8Array(d);for(n=0;n<t;n+=4)i=$[r.charCodeAt(n)],o=$[r.charCodeAt(n+1)],a=$[r.charCodeAt(n+2)],c=$[r.charCodeAt(n+3)],f[s++]=i<<2|o>>4,f[s++]=(o&15)<<4|a>>2,f[s++]=(a&3)<<6|c&63;return d};var Wt=typeof ArrayBuffer=="function",Y=(r,e)=>{if(typeof r!="string")return{type:"message",data:Xe(r,e)};let t=r.charAt(0);return t==="b"?{type:"message",data:Zt(r.substring(1),e)}:z[t]?r.length>1?{type:z[t],data:r.substring(1)}:{type:z[t]}:W},Zt=(r,e)=>{if(Wt){let t=Ye(r);return Xe(t,e)}else return{base64:!0,data:r}},Xe=(r,e)=>{switch(e){case"blob":return r instanceof Blob?r:new Blob([r]);case"arraybuffer":default:return r instanceof ArrayBuffer?r:r.buffer}};var Je="",je=(r,e)=>{let t=r.length,n=new Array(t),s=0;r.forEach((i,o)=>{Z(i,!1,a=>{n[o]=a,++s===t&&e(n.join(Je))})})},Qe=(r,e)=>{let t=r.split(Je),n=[];for(let s=0;s<t.length;s++){let i=Y(t[s],e);if(n.push(i),i.type==="error")break}return n};function et(){return new TransformStream({transform(r,e){Ze(r,t=>{let n=t.length,s;if(n<126)s=new Uint8Array(1),new DataView(s.buffer).setUint8(0,n);else if(n<65536){s=new Uint8Array(3);let i=new DataView(s.buffer);i.setUint8(0,126),i.setUint16(1,n)}else{s=new Uint8Array(9);let i=new DataView(s.buffer);i.setUint8(0,127),i.setBigUint64(1,BigInt(n))}r.data&&typeof r.data!="string"&&(s[0]|=128),e.enqueue(s),e.enqueue(t)})}})}var xe;function oe(r){return r.reduce((e,t)=>e+t.length,0)}function ae(r,e){if(r[0].length===e)return r.shift();let t=new Uint8Array(e),n=0;for(let s=0;s<e;s++)t[s]=r[0][n++],n===r[0].length&&(r.shift(),n=0);return r.length&&n<r[0].length&&(r[0]=r[0].slice(n)),t}function tt(r,e){xe||(xe=new TextDecoder);let t=[],n=0,s=-1,i=!1;return new TransformStream({transform(o,a){for(t.push(o);;){if(n===0){if(oe(t)<1)break;let c=ae(t,1);i=(c[0]&128)===128,s=c[0]&127,s<126?n=3:s===126?n=1:n=2}else if(n===1){if(oe(t)<2)break;let c=ae(t,2);s=new DataView(c.buffer,c.byteOffset,c.length).getUint16(0),n=3}else if(n===2){if(oe(t)<8)break;let c=ae(t,8),d=new DataView(c.buffer,c.byteOffset,c.length),f=d.getUint32(0);if(f>Math.pow(2,21)-1){a.enqueue(W);break}s=f*Math.pow(2,32)+d.getUint32(4),n=3}else{if(oe(t)<s)break;let c=ae(t,s);a.enqueue(Y(i?c:xe.decode(c),e)),n=0}if(s===0||s>r){a.enqueue(W);break}}}})}var Te=4;function p(r){if(r)return $t(r)}function $t(r){for(var e in p.prototype)r[e]=p.prototype[e];return r}p.prototype.on=p.prototype.addEventListener=function(r,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+r]=this._callbacks["$"+r]||[]).push(e),this};p.prototype.once=function(r,e){function t(){this.off(r,t),e.apply(this,arguments)}return t.fn=e,this.on(r,t),this};p.prototype.off=p.prototype.removeListener=p.prototype.removeAllListeners=p.prototype.removeEventListener=function(r,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+r];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+r],this;for(var n,s=0;s<t.length;s++)if(n=t[s],n===e||n.fn===e){t.splice(s,1);break}return t.length===0&&delete this._callbacks["$"+r],this};p.prototype.emit=function(r){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+r],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t){t=t.slice(0);for(var n=0,s=t.length;n<s;++n)t[n].apply(this,e)}return this};p.prototype.emitReserved=p.prototype.emit;p.prototype.listeners=function(r){return this._callbacks=this._callbacks||{},this._callbacks["$"+r]||[]};p.prototype.hasListeners=function(r){return!!this.listeners(r).length};var w=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),b=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),rt="arraybuffer";function ce(r,...e){return e.reduce((t,n)=>(r.hasOwnProperty(n)&&(t[n]=r[n]),t),{})}var Yt=b.setTimeout,Xt=b.clearTimeout;function C(r,e){e.useNativeTimers?(r.setTimeoutFn=Yt.bind(b),r.clearTimeoutFn=Xt.bind(b)):(r.setTimeoutFn=b.setTimeout.bind(b),r.clearTimeoutFn=b.clearTimeout.bind(b))}var Jt=1.33;function nt(r){return typeof r=="string"?jt(r):Math.ceil((r.byteLength||r.size)*Jt)}function jt(r){let e=0,t=0;for(let n=0,s=r.length;n<s;n++)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(n++,t+=4);return t}function he(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function st(r){let e="";for(let t in r)r.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(r[t]));return e}function it(r){let e={},t=r.split("&");for(let n=0,s=t.length;n<s;n++){let i=t[n].split("=");e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e}var le=class extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}},v=class extends p{constructor(e){super(),this.writable=!1,C(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved("error",new le(e,t,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){let t=Y(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){let t=st(e);return t.length?"?"+t:""}};var X=class extends v{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";let t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let n=0;this._polling&&(n++,this.once("pollComplete",function(){--n||t()})),this.writable||(n++,this.once("drain",function(){--n||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){let t=n=>{if(this.readyState==="opening"&&n.type==="open"&&this.onOpen(),n.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(n)};Qe(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,je(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=he()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}};var ot=!1;try{ot=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var at=ot;function Qt(){}var Ae=class extends X{constructor(e){if(super(e),typeof location<"u"){let t=location.protocol==="https:",n=location.port;n||(n=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){let n=this.request({method:"POST",data:e});n.on("success",t),n.on("error",(s,i)=>{this.onError("xhr post error",s,i)})}doPoll(){let e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,n)=>{this.onError("xhr poll error",t,n)}),this.pollXhr=e}},S=class r extends p{constructor(e,t,n){super(),this.createRequest=e,C(this,n),this._opts=n,this._method=n.method||"GET",this._uri=t,this._data=n.data!==void 0?n.data:null,this._create()}_create(){var e;let t=ce(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;let n=this._xhr=this.createRequest(t);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let s in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(s)&&n.setRequestHeader(s,this._opts.extraHeaders[s])}}catch{}if(this._method==="POST")try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{n.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var s;n.readyState===3&&((s=this._opts.cookieJar)===null||s===void 0||s.parseCookies(n.getResponseHeader("set-cookie"))),n.readyState===4&&(n.status===200||n.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof n.status=="number"?n.status:0)},0))},n.send(this._data)}catch(s){this.setTimeoutFn(()=>{this._onError(s)},0);return}typeof document<"u"&&(this._index=r.requestsCount++,r.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=Qt,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete r.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};S.requestsCount=0;S.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",ct);else if(typeof addEventListener=="function"){let r="onpagehide"in b?"pagehide":"unload";addEventListener(r,ct,!1)}}function ct(){for(let r in S.requests)S.requests.hasOwnProperty(r)&&S.requests[r].abort()}var er=function(){let r=ht({xdomain:!1});return r&&r.responseType!==null}(),k=class extends Ae{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=er&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new S(ht,this.uri(),e)}};function ht(r){let e=r.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||at))return new XMLHttpRequest}catch{}if(!e)try{return new b[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var lt=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Ce=class extends v{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,n=lt?{}:ce(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}catch(s){return this.emitReserved("error",s)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1;Z(n,this.supportsBinary,i=>{try{this.doWrite(n,i)}catch{}s&&w(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=he()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},we=b.WebSocket||b.MozWebSocket,R=class extends Ce{createSocket(e,t,n){return lt?new we(e,t,n):t?new we(e,t):new we(e)}doWrite(e,t){this.ws.send(t)}};var B=class extends v{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{let t=tt(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),s=et();s.readable.pipeTo(e.writable),this._writer=s.writable.getWriter();let i=()=>{n.read().then(({done:a,value:c})=>{a||(this.onPacket(c),i())}).catch(a=>{})};i();let o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1;this._writer.write(n).then(()=>{s&&w(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}};var ve={websocket:R,webtransport:B,polling:k};var tr=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,rr=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function I(r){if(r.length>8e3)throw"URI too long";let e=r,t=r.indexOf("["),n=r.indexOf("]");t!=-1&&n!=-1&&(r=r.substring(0,t)+r.substring(t,n).replace(/:/g,";")+r.substring(n,r.length));let s=tr.exec(r||""),i={},o=14;for(;o--;)i[rr[o]]=s[o]||"";return t!=-1&&n!=-1&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=nr(i,i.path),i.queryKey=sr(i,i.query),i}function nr(r,e){let t=/\/{2,9}/g,n=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&n.splice(0,1),e.slice(-1)=="/"&&n.splice(n.length-1,1),n}function sr(r,e){let t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,s,i){s&&(t[s]=i)}),t}var Se=typeof addEventListener=="function"&&typeof removeEventListener=="function",pe=[];Se&&addEventListener("offline",()=>{pe.forEach(r=>r())},!1);var M=class r extends p{constructor(e,t){if(super(),this.binaryType=rt,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){let n=I(e);t.hostname=n.host,t.secure=n.protocol==="https"||n.protocol==="wss",t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=I(t.host).host);C(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach(n=>{let s=n.prototype.name;this.transports.push(s),this._transportsByName[s]=n}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=it(this.opts.query)),Se&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},pe.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=Te,t.transport=e,this.id&&(t.sid=this.id);let n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](n)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let e=this.opts.rememberUpgrade&&r.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",r.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let n=0;n<this.writeBuffer.length;n++){let s=this.writeBuffer[n].data;if(s&&(t+=nt(s)),n>0&&t>this._maxPayload)return this.writeBuffer.slice(0,n);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,w(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket("message",e,t,n),this}send(e,t,n){return this._sendPacket("message",e,t,n),this}_sendPacket(e,t,n,s){if(typeof t=="function"&&(s=t,t=void 0),typeof n=="function"&&(s=n,n=null),this.readyState==="closing"||this.readyState==="closed")return;n=n||{},n.compress=n.compress!==!1;let i={type:e,data:t,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),s&&this.once("flush",s),this.flush()}close(){let e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():e()}):this.upgrading?n():e()),this}_onError(e){if(r.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),Se&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let n=pe.indexOf(this._offlineEventListener);n!==-1&&pe.splice(n,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}};M.protocol=Te;var de=class extends M{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;M.priorWebsocketSuccess=!1;let s=()=>{n||(t.send([{type:"ping",data:"probe"}]),t.once("packet",u=>{if(!n)if(u.type==="pong"&&u.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;M.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{n||this.readyState!=="closed"&&(f(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{let g=new Error("probe error");g.transport=t.name,this.emitReserved("upgradeError",g)}}))};function i(){n||(n=!0,f(),t.close(),t=null)}let o=u=>{let g=new Error("probe error: "+u);g.transport=t.name,i(),this.emitReserved("upgradeError",g)};function a(){o("transport closed")}function c(){o("socket closed")}function d(u){t&&u.name!==t.name&&i()}let f=()=>{t.removeListener("open",s),t.removeListener("error",o),t.removeListener("close",a),this.off("close",c),this.off("upgrading",d)};t.once("open",s),t.once("error",o),t.once("close",a),this.once("close",c),this.once("upgrading",d),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{n||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){let t=[];for(let n=0;n<e.length;n++)~this.transports.indexOf(e[n])&&t.push(e[n]);return t}},H=class extends de{constructor(e,t={}){let n=typeof e=="object",s=n?{...e}:{...t};(!s.transports||s.transports&&typeof s.transports[0]=="string")&&(s.transports=(s.transports||["polling","websocket","webtransport"]).map(i=>ve[i]).filter(i=>!!i)),super(n?s:e,s)}};var Pn=H.protocol;function pt(r,e="",t){let n=r;t=t||typeof location<"u"&&location,r==null&&(r=t.protocol+"//"+t.host),typeof r=="string"&&(r.charAt(0)==="/"&&(r.charAt(1)==="/"?r=t.protocol+r:r=t.host+r),/^(https?|wss?):\/\//.test(r)||(typeof t<"u"?r=t.protocol+"//"+r:r="https://"+r),n=I(r)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";let i=n.host.indexOf(":")!==-1?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+i+":"+n.port+e,n.href=n.protocol+"://"+i+(t&&t.port===n.port?"":":"+n.port),n}var Me={};zt(Me,{Decoder:()=>Oe,Encoder:()=>Re,PacketType:()=>l,isPacketValid:()=>fr,protocol:()=>yt});var or=typeof ArrayBuffer=="function",ar=r=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(r):r.buffer instanceof ArrayBuffer,dt=Object.prototype.toString,cr=typeof Blob=="function"||typeof Blob<"u"&&dt.call(Blob)==="[object BlobConstructor]",hr=typeof File=="function"||typeof File<"u"&&dt.call(File)==="[object FileConstructor]";function j(r){return or&&(r instanceof ArrayBuffer||ar(r))||cr&&r instanceof Blob||hr&&r instanceof File}function J(r,e){if(!r||typeof r!="object")return!1;if(Array.isArray(r)){for(let t=0,n=r.length;t<n;t++)if(J(r[t]))return!0;return!1}if(j(r))return!0;if(r.toJSON&&typeof r.toJSON=="function"&&arguments.length===1)return J(r.toJSON(),!0);for(let t in r)if(Object.prototype.hasOwnProperty.call(r,t)&&J(r[t]))return!0;return!1}function ft(r){let e=[],t=r.data,n=r;return n.data=fe(t,e),n.attachments=e.length,{packet:n,buffers:e}}function fe(r,e,t){if(!r)return r;if(j(r)){let n={_placeholder:!0,num:e.length};return e.push(r),n}else if(Array.isArray(r)){let n=new Array(r.length);for(let s=0;s<r.length;s++)n[s]=fe(r[s],e);return n}else if(typeof r=="object"&&!(r instanceof Date)){if(r.toJSON&&typeof r.toJSON=="function"&&!t)return fe(r.toJSON(),e,!0);let n={};for(let s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=fe(r[s],e));return n}return r}function ut(r,e){return r.data=ke(r.data,e),delete r.attachments,r}function ke(r,e){if(!r)return r;if(r&&r._placeholder===!0){if(typeof r.num=="number"&&r.num>=0&&r.num<e.length)return e[r.num];throw new Error("illegal attachments")}else if(Array.isArray(r))for(let t=0;t<r.length;t++)r[t]=ke(r[t],e);else if(typeof r=="object")for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&(r[t]=ke(r[t],e));return r}var mt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],yt=5,l;(function(r){r[r.CONNECT=0]="CONNECT",r[r.DISCONNECT=1]="DISCONNECT",r[r.EVENT=2]="EVENT",r[r.ACK=3]="ACK",r[r.CONNECT_ERROR=4]="CONNECT_ERROR",r[r.BINARY_EVENT=5]="BINARY_EVENT",r[r.BINARY_ACK=6]="BINARY_ACK"})(l||(l={}));var Re=class{constructor(e){this.replacer=e}encode(e){return(e.type===l.EVENT||e.type===l.ACK)&&J(e)?this.encodeAsBinary({type:e.type===l.EVENT?l.BINARY_EVENT:l.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return(e.type===l.BINARY_EVENT||e.type===l.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=ft(e),n=this.encodeAsString(t.packet),s=t.buffers;return s.unshift(n),s}},Oe=class r extends p{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e=="function"?{reviver:e}:e)}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);let n=t.type===l.BINARY_EVENT;n||t.type===l.BINARY_ACK?(t.type=n?l.EVENT:l.ACK,this.reconstructor=new Le(t)):super.emitReserved("decoded",t)}else if(j(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0,n={type:Number(e.charAt(0))};if(l[n.type]===void 0)throw new Error("unknown packet type "+n.type);if(n.type===l.BINARY_EVENT||n.type===l.BINARY_ACK){let i=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);let o=e.substring(i,t);if(o!=Number(o)||e.charAt(t)!=="-")throw new Error("Illegal attachments");let a=Number(o);if(!gt(a)||a<1)throw new Error("Illegal attachments");if(a>this.opts.maxAttachments)throw new Error("too many attachments");n.attachments=a}if(e.charAt(t+1)==="/"){let i=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););n.nsp=e.substring(i,t)}else n.nsp="/";let s=e.charAt(t+1);if(s!==""&&Number(s)==s){let i=t+1;for(;++t;){let o=e.charAt(t);if(o==null||Number(o)!=o){--t;break}if(t===e.length)break}n.id=Number(e.substring(i,t+1))}if(e.charAt(++t)){let i=this.tryParse(e.substr(t));if(r.isPayloadValid(n.type,i))n.data=i;else throw new Error("invalid payload")}return n}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch{return!1}}static isPayloadValid(e,t){switch(e){case l.CONNECT:return ue(t);case l.DISCONNECT:return t===void 0;case l.CONNECT_ERROR:return typeof t=="string"||ue(t);case l.EVENT:case l.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&mt.indexOf(t[0])===-1);case l.ACK:case l.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},Le=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let t=ut(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function lr(r){return typeof r=="string"}var gt=Number.isInteger||function(r){return typeof r=="number"&&isFinite(r)&&Math.floor(r)===r};function pr(r){return r===void 0||gt(r)}function ue(r){return Object.prototype.toString.call(r)==="[object Object]"}function dr(r,e){switch(r){case l.CONNECT:return e===void 0||ue(e);case l.DISCONNECT:return e===void 0;case l.EVENT:return Array.isArray(e)&&(typeof e[0]=="number"||typeof e[0]=="string"&&mt.indexOf(e[0])===-1);case l.ACK:return Array.isArray(e);case l.CONNECT_ERROR:return typeof e=="string"||ue(e);default:return!1}}function fr(r){return lr(r.nsp)&&pr(r.id)&&dr(r.type,r.data)}function _(r,e,t){return r.on(e,t),function(){r.off(e,t)}}var ur=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),D=class extends p{constructor(e,t,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[_(e,"open",this.onopen.bind(this)),_(e,"packet",this.onpacket.bind(this)),_(e,"error",this.onerror.bind(this)),_(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var n,s,i;if(ur.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;let o={type:l.EVENT,data:t};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof t[t.length-1]=="function"){let f=this.ids++,u=t.pop();this._registerAckCallback(f,u),o.id=f}let a=(s=(n=this.io.engine)===null||n===void 0?void 0:n.transport)===null||s===void 0?void 0:s.writable,c=this.connected&&!(!((i=this.io.engine)===null||i===void 0)&&i._hasPingExpired());return this.flags.volatile&&!a||(c?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(e,t){var n;let s=(n=this.flags.timeout)!==null&&n!==void 0?n:this._opts.ackTimeout;if(s===void 0){this.acks[e]=t;return}let i=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let a=0;a<this.sendBuffer.length;a++)this.sendBuffer[a].id===e&&this.sendBuffer.splice(a,1);t.call(this,new Error("operation has timed out"))},s),o=(...a)=>{this.io.clearTimeoutFn(i),t.apply(this,a)};o.withError=!0,this.acks[e]=o}emitWithAck(e,...t){return new Promise((n,s)=>{let i=(o,a)=>o?s(o):n(a);i.withError=!0,t.push(i),this.emit(e,...t)})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());let n={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((s,...i)=>(this._queue[0],s!==null?n.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(s)):(this._queue.shift(),t&&t(null,...i)),n.pending=!1,this._drainQueue())),this._queue.push(n),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||this._queue.length===0)return;let t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:l.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(n=>String(n.id)===e)){let n=this.acks[e];delete this.acks[e],n.withError&&n.call(this,new Error("socket has been disconnected"))}})}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case l.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case l.EVENT:case l.BINARY_EVENT:this.onevent(e);break;case l.ACK:case l.BINARY_ACK:this.onack(e);break;case l.DISCONNECT:this.ondisconnect();break;case l.CONNECT_ERROR:this.destroy();let n=new Error(e.data.message);n.data=e.data.data,this.emitReserved("connect_error",n);break}}onevent(e){let t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){let t=this._anyListeners.slice();for(let n of t)n.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1])}ack(e){let t=this,n=!1;return function(...s){n||(n=!0,t.packet({type:l.ACK,id:e,data:s}))}}onack(e){let t=this.acks[e.id];typeof t=="function"&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data))}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:l.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){let t=this._anyListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let n=0;n<t.length;n++)if(e===t[n])return t.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let n of t)n.apply(this,e.data)}}};function N(r){r=r||{},this.ms=r.min||100,this.max=r.max||1e4,this.factor=r.factor||2,this.jitter=r.jitter>0&&r.jitter<=1?r.jitter:0,this.attempts=0}N.prototype.duration=function(){var r=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*r);r=Math.floor(e*10)&1?r+t:r-t}return Math.min(r,this.max)|0};N.prototype.reset=function(){this.attempts=0};N.prototype.setMin=function(r){this.ms=r};N.prototype.setMax=function(r){this.max=r};N.prototype.setJitter=function(r){this.jitter=r};var q=class extends p{constructor(e,t){var n;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,C(this,t),this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((n=t.randomizationFactor)!==null&&n!==void 0?n:.5),this.backoff=new N({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;let s=t.parser||Me;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=t.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new H(this.uri,this.opts);let t=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;let s=_(t,"open",function(){n.onopen(),e&&e()}),i=a=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",a),e?e(a):this.maybeReconnectOnOpen()},o=_(t,"error",i);if(this._timeout!==!1){let a=this._timeout,c=this.setTimeoutFn(()=>{s(),i(new Error("timeout")),t.close()},a);this.opts.autoUnref&&c.unref(),this.subs.push(()=>{this.clearTimeoutFn(c)})}return this.subs.push(s),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let e=this.engine;this.subs.push(_(e,"ping",this.onping.bind(this)),_(e,"data",this.ondata.bind(this)),_(e,"error",this.onerror.bind(this)),_(e,"close",this.onclose.bind(this)),_(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(t){this.onclose("parse error",t)}}ondecoded(e){w(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let n=this.nsps[e];return n?this._autoConnect&&!n.active&&n.connect():(n=new D(this,e,t),this.nsps[e]=n),n}_destroy(e){let t=Object.keys(this.nsps);for(let n of t)if(this.nsps[n].active)return;this._close()}_packet(e){let t=this.encoder.encode(e);for(let n=0;n<t.length;n++)this.engine.write(t[n],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(e,t){var n;this.cleanup(),(n=this.engine)===null||n===void 0||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let t=this.backoff.duration();this._reconnecting=!0;let n=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(s=>{s?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",s)):e.onreconnect()}))},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}};var Q={};function ee(r,e){typeof r=="object"&&(e=r,r=void 0),e=e||{};let t=pt(r,e.path||"/socket.io"),n=t.source,s=t.id,i=t.path,o=Q[s]&&i in Q[s].nsps,a=e.forceNew||e["force new connection"]||e.multiplex===!1||o,c;return a?c=new q(n,e):(Q[s]||(Q[s]=new q(n,e)),c=Q[s]),t.query&&!e.query&&(e.query=t.queryKey),c.socket(t.path,e)}Object.assign(ee,{Manager:q,Socket:D,io:ee,connect:ee});function bt(r,e,t){return ee(`${r}/chat`,{auth:{apiKey:e,visitorId:t??void 0},transports:["websocket"]})}var mr="chat",_t={chat:'<path d="M4 5h16v11H9l-4 3.5V16H4V5Z"/><path d="M8 9h8M8 12h5"/>',"chat-round":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/>',"chat-dots":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/><circle cx="9" cy="11.5" r=".9" fill="currentColor" stroke="none"/><circle cx="12" cy="11.5" r=".9" fill="currentColor" stroke="none"/><circle cx="15" cy="11.5" r=".9" fill="currentColor" stroke="none"/>',"chat-two":'<path d="M4 5.5h10v7h-4l-2.5 2V12.5H4V5.5Z"/><path d="M10 10.5h10v7h-3.5L14 20v-2.5h-4v-7Z"/>',thought:'<path d="M8 5.5a5 5 0 0 1 9 3 4 4 0 0 1-1 7.9H8.5A4.5 4.5 0 0 1 8 5.5Z"/><circle cx="7" cy="18" r="1" fill="currentColor" stroke="none"/><circle cx="5" cy="20.5" r=".6" fill="currentColor" stroke="none"/>',mail:'<rect x="3.5" y="6" width="17" height="12" rx="1.5"/><path d="M4 7l8 6 8-6"/>',"mail-open":'<rect x="3.5" y="8" width="17" height="10" rx="1.5"/><path d="M3.5 8 12 3l8.5 5"/><path d="M3.5 8 10 13M20.5 8 14 13"/>',send:'<path d="M4 12 20 4l-4 16-5-6-6-2Z"/><path d="M20 4 9.5 14"/>',robot:'<rect x="5" y="8" width="14" height="10" rx="2.5"/><path d="M12 8V5"/><circle cx="12" cy="4" r="1.1" fill="currentColor" stroke="none"/><circle cx="9" cy="13" r="1.1" fill="currentColor" stroke="none"/><circle cx="15" cy="13" r="1.1" fill="currentColor" stroke="none"/><path d="M9 16.5h6"/>',brain:'<path d="M9 4.5a3 3 0 0 0-3 3 3 3 0 0 0-1 5.6 3 3 0 0 0 3.6 4A3 3 0 0 0 12 19V6a2.5 2.5 0 0 0-3-1.5Z"/><path d="M15 4.5a3 3 0 0 1 3 3 3 3 0 0 1 1 5.6 3 3 0 0 1-3.6 4A3 3 0 0 1 12 19V6a2.5 2.5 0 0 1 3-1.5Z"/>',bulb:'<path d="M9 16.5h6M10 19.5h4"/><path d="M12 3.5a6 6 0 0 0-3.2 11.1c.6.4 1 1.1 1 1.9h4.4c0-.8.4-1.5 1-1.9A6 6 0 0 0 12 3.5Z"/>',bolt:'<path d="M12.5 3 5 13.5h5.5L11 21l7.5-10.5H13l-.5-7.5Z"/>',sparkles:'<path d="M12 3.5c.5 3 1.7 4.2 4.7 4.7-3 .5-4.2 1.7-4.7 4.7-.5-3-1.7-4.2-4.7-4.7 3-.5 4.2-1.7 4.7-4.7Z"/><path d="M18.5 14c.3 1.7 1 2.4 2.7 2.7-1.7.3-2.4 1-2.7 2.7-.3-1.7-1-2.4-2.7-2.7 1.7-.3 2.4-1 2.7-2.7Z"/>',orbit:'<circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none"/><ellipse cx="12" cy="12" rx="9" ry="3.6"/><ellipse cx="12" cy="12" rx="9" ry="3.6" transform="rotate(60 12 12)"/><ellipse cx="12" cy="12" rx="9" ry="3.6" transform="rotate(120 12 12)"/>',rocket:'<path d="M12 3c2.5 1.5 4 4.5 4 8.5 0 2-1 4-1 4H9s-1-2-1-4c0-4 1.5-7 4-8.5Z"/><circle cx="12" cy="9" r="1.4"/><path d="M9 15l-2.5 2.5M15 15l2.5 2.5M10 19l2 2 2-2"/>',wand:'<path d="M4 20 15 9"/><path d="M17 4l.8 1.9L19.7 6.7 17.8 7.5 17 9.4 16.2 7.5 14.3 6.7 16.2 5.9 17 4Z"/><path d="M6 13.5l.5 1.2 1.2.5-1.2.5-.5 1.2-.5-1.2L4.3 15l1.2-.5.5-1.2Z"/>',wave:'<path d="M9 13V6a1.5 1.5 0 0 1 3 0v5"/><path d="M12 11V4.5a1.5 1.5 0 0 1 3 0V11"/><path d="M15 11V6a1.5 1.5 0 0 1 3 0v8c0 3-2 6-6 6s-6-2.5-6.5-5L4 12.5a1.4 1.4 0 0 1 2.3-1.6L9 14"/>',"raised-hand":'<path d="M7 20V10a1.2 1.2 0 0 1 2.4 0v3"/><path d="M9.4 12.5V6a1.2 1.2 0 0 1 2.4 0v6.5"/><path d="M11.8 12.5V5a1.2 1.2 0 0 1 2.4 0v7.5"/><path d="M14.2 12.5V7a1.2 1.2 0 0 1 2.4 0v7c0 3.3-2.3 6-6 6-2.5 0-4-1.2-5-3l-2-3.6a1.3 1.3 0 0 1 2.2-1.3l1.6 2.4"/>',smile:'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 14c1 1.3 2.2 2 3.5 2s2.5-.7 3.5-2"/><circle cx="9" cy="10" r=".9" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r=".9" fill="currentColor" stroke="none"/>',"smile-chat":'<path d="M12 4c4.97 0 9 3.36 9 7.5S16.97 19 12 19c-1 0-1.96-.14-2.85-.4L5 20l1.2-3.6C4.8 15 4 13.3 4 11.5 4 7.36 7.03 4 12 4Z"/><circle cx="9.5" cy="11" r=".8" fill="currentColor" stroke="none"/><circle cx="14.5" cy="11" r=".8" fill="currentColor" stroke="none"/><path d="M9.5 13.5c.7.8 1.5 1.2 2.5 1.2s1.8-.4 2.5-1.2"/>',handshake:'<path d="M3 12l4-3 3.5 2-1.5 2"/><path d="M21 12l-4-3-3.5 2 1.5 2"/><path d="M9 13l2.5 2.2a1.4 1.4 0 0 0 2-2l-3-2.7"/><path d="M15 13l-2.5 2.2"/>',"heart-chat":'<path d="M12 20s-7-4.4-9.3-8.8C1.3 8 3 5 6.2 5c2 0 3.4 1.2 4.3 2.4C11.4 6.2 12.8 5 14.8 5 18 5 19.7 8 17.3 11.2 15 15.6 12 20 12 20Z"/>',"thumbs-up":'<path d="M7 11v9H4v-9h3Z"/><path d="M7 11l3.5-6.5a1.6 1.6 0 0 1 3 1l-1 4.5H17a2 2 0 0 1 2 2.4l-1.3 6A2 2 0 0 1 15.7 20H10a3 3 0 0 1-3-3v-6Z"/>',wink:'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 14c1 1.3 2.2 2 3.5 2s2.5-.7 3.5-2"/><path d="M7.5 10h3"/><circle cx="15" cy="10" r=".9" fill="currentColor" stroke="none"/>',headset:'<path d="M4 13a8 8 0 0 1 16 0"/><rect x="3" y="13" width="4" height="6" rx="1.5"/><rect x="17" y="13" width="4" height="6" rx="1.5"/><path d="M19 19v1a3 3 0 0 1-3 3h-3"/>',bell:'<path d="M6 17V11a6 6 0 0 1 12 0v6l1.5 2h-15L6 17Z"/><path d="M10 20.5a2 2 0 0 0 4 0"/>',megaphone:'<path d="M3 10v4h3l6 4V6L6 10H3Z"/><path d="M14 9a4 4 0 0 1 0 6"/><path d="M17 6.5a8 8 0 0 1 0 11"/>',broadcast:'<circle cx="12" cy="12" r="2"/><path d="M8.5 8.5a5 5 0 0 0 0 7M15.5 8.5a5 5 0 0 1 0 7"/><path d="M5.5 5.5a9.5 9.5 0 0 0 0 13M18.5 5.5a9.5 9.5 0 0 1 0 13"/>',"life-ring":'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="3.5"/><path d="M6 6l3.5 3.5M18 6l-3.5 3.5M6 18l3.5-3.5M18 18l-3.5-3.5"/>',question:'<circle cx="12" cy="12" r="8.5"/><path d="M9.5 9.3a2.5 2.5 0 1 1 3.6 2.3c-.8.5-1.1.9-1.1 1.9"/><circle cx="12" cy="16.5" r=".9" fill="currentColor" stroke="none"/>',info:'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="8" r=".9" fill="currentColor" stroke="none"/><path d="M12 11v6"/>',"phone-support":'<path d="M6.5 4.5h3L11 8l-2 1.5a11 11 0 0 0 5.5 5.5L16 13l3.5 1.5v3a2 2 0 0 1-2.2 2A15.5 15.5 0 0 1 4.5 6.7a2 2 0 0 1 2-2.2Z"/>',star:'<path d="M12 3.5l2.4 5.1 5.6.6-4.2 3.8 1.2 5.5L12 15.7l-5 2.8 1.2-5.5-4.2-3.8 5.6-.6L12 3.5Z"/>',"star-fill":'<path d="M12 3.5l2.4 5.1 5.6.6-4.2 3.8 1.2 5.5L12 15.7l-5 2.8 1.2-5.5-4.2-3.8 5.6-.6L12 3.5Z" fill="currentColor"/>',"check-circle":'<circle cx="12" cy="12" r="8.5"/><path d="M8.5 12.3 11 15l4.5-5.5"/>',target:'<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.4" fill="currentColor" stroke="none"/>',flame:'<path d="M12 3.5c1 2.5-.5 3.5-1.5 5C9 10 8 11.5 8 13.5A4 4 0 0 0 12 17.5a4 4 0 0 0 4-4c0-1.5-.7-2.3-1.3-3 .3 1.2-.2 2-1 2.3.3-2-1-2.7-1.7-4.3Z"/>',"shield-check":'<path d="M12 3.5 19 6.5V11c0 5-3 8.2-7 9.5-4-1.3-7-4.5-7-9.5V6.5L12 3.5Z"/><path d="M9 12l2 2 4-4.5"/>',crown:'<path d="M4 17l-1.5-8L7 12l5-6 5 6 4.5-3L20 17H4Z"/><path d="M4 19.5h16"/>',gift:'<rect x="4" y="9.5" width="16" height="10" rx="1"/><path d="M4 13h16"/><path d="M12 9.5v10"/><path d="M12 9.5c-1-2.5-2.8-4-4.3-4A2 2 0 0 0 6 7.5c0 1.3 1.2 2 2.5 2H12Z"/><path d="M12 9.5c1-2.5 2.8-4 4.3-4A2 2 0 0 1 18 7.5c0 1.3-1.2 2-2.5 2H12Z"/>'};function Ne(r){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">${r&&_t[r]||_t[mr]}</svg>`}var me={SOFT:{waveform:"sine",gain:.12,tones:{CHAT_OPENED:[{freq:523,start:0,duration:.14}],BOT_REPLY:[{freq:659,start:0,duration:.16}],AGENT_MESSAGE:[{freq:494,start:0,duration:.14},{freq:587,start:.12,duration:.2}],RULE_TRIGGERED:[{freq:587,start:0,duration:.13}],COMMAND_EXECUTED:[{freq:440,start:0,duration:.18}]}},CLASSIC:{waveform:"sine",gain:.2,tones:{CHAT_OPENED:[{freq:660,start:0,duration:.09}],BOT_REPLY:[{freq:880,start:0,duration:.12}],AGENT_MESSAGE:[{freq:587,start:0,duration:.1},{freq:784,start:.1,duration:.14}],RULE_TRIGGERED:[{freq:740,start:0,duration:.08},{freq:740,start:.12,duration:.08}],COMMAND_EXECUTED:[{freq:784,start:0,duration:.1},{freq:660,start:.1,duration:.14}]}},BELL:{waveform:"triangle",gain:.15,tones:{CHAT_OPENED:[{freq:784,start:0,duration:.1},{freq:988,start:.05,duration:.12}],BOT_REPLY:[{freq:1046,start:0,duration:.18}],AGENT_MESSAGE:[{freq:659,start:0,duration:.12},{freq:784,start:.1,duration:.12},{freq:988,start:.2,duration:.22}],RULE_TRIGGERED:[{freq:1174,start:0,duration:.14}],COMMAND_EXECUTED:[{freq:880,start:0,duration:.1},{freq:1046,start:.1,duration:.16}]}}},yr={enabled:!0,soundStyle:"CLASSIC"},ye=class{constructor(){this.triggers={}}setTriggers(e){this.triggers=e}prime(){if(this.context){this.context.state==="suspended"&&this.context.resume();return}let e=window.AudioContext??window.webkitAudioContext;if(e)try{this.context=new e}catch{}}play(e){let t=this.context;if(!t)return;let n=this.triggers[e]??yr;if(!n.enabled)return;let{waveform:s,gain:i}=me[n.soundStyle]??me.CLASSIC,o=(me[n.soundStyle]??me.CLASSIC).tones[e],a=t.currentTime;for(let c of o){let d=t.createOscillator(),f=t.createGain();d.type=s,d.frequency.value=c.freq;let u=a+c.start,g=u+c.duration;f.gain.setValueAtTime(0,u),f.gain.linearRampToValueAtTime(i,u+.01),f.gain.linearRampToValueAtTime(0,g),d.connect(f),f.connect(t.destination),d.start(u),d.stop(g+.02)}}};var Et="chat:ready";var xt="chat:close",Tt="chat:toggle",At="chat:resize",wt="chat:send",Ct="chat:bot-reply",vt="chat:connect-error",St="chat:history",kt="chat:admin-message",Rt="chat:admin-typing",Pe="chat:agent-presence",Ot="chat:typing",Lt="chat:upload-attachment",Mt="chat:attachment-uploaded",Nt="chat:attachment-upload-error";var re="zabbu-chat-widget-launcher",ne="zabbu-chat-widget-panel",It="zabbu-chat-widget-iframe",P="zabbu-chat-widget-teaser",se="zabbu-chat-widget-badge",Ht="#2563eb";function gr(r,e){switch(r){case"NONE":return{launcher:"none",panel:"none",teaser:"none"};case"ELEVATED":return{launcher:"0 16px 40px -8px rgba(0, 0, 0, 0.45), 0 6px 16px rgba(0, 0, 0, 0.25)",panel:"0 30px 80px -16px rgba(0, 0, 0, 0.5), 0 12px 32px rgba(0, 0, 0, 0.3)",teaser:"0 20px 50px -12px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.2)"};case"BRAND_GLOW":{let t=Be(e,.5),n=Be(e,.3);return{launcher:`0 10px 26px -4px ${t}, 0 3px 10px ${n}`,panel:`0 26px 64px -12px ${t}, 0 10px 28px ${n}`,teaser:`0 18px 42px -8px ${t}, 0 6px 16px ${n}`}}case"SOFT":default:return{launcher:"0 4px 12px rgba(0, 0, 0, 0.2)",panel:"0 8px 30px rgba(0, 0, 0, 0.25)",teaser:"0 6px 20px rgba(0, 0, 0, 0.15)"}}}function Be(r,e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);if(!t)return Be(Ht,e);let[n,s,i]=t.slice(1).map(o=>parseInt(o,16));return`rgba(${n}, ${s}, ${i}, ${e})`}function Dt(r){if(r==="bottom-left"||r==="BOTTOM_LEFT")return"BOTTOM_LEFT";if(r==="bottom-right"||r==="BOTTOM_RIGHT")return"BOTTOM_RIGHT"}function qt(r){if(r==="dark"||r==="DARK")return"DARK";if(r==="light"||r==="LIGHT")return"LIGHT"}function br(){let r=new Map;return{on(e,t){let n=r.get(e);n||(n=new Set,r.set(e,n)),n.add(t)},off(e,t){r.get(e)?.delete(t)},emit(e,t){r.get(e)?.forEach(n=>n(t))}}}function _r(r,e,t,n){let s=r||Ht,i=gr(e,s),o=document.documentElement.style;o.setProperty("--zabbu-chat-primary",s),o.setProperty("--zabbu-chat-shadow-launcher",i.launcher),o.setProperty("--zabbu-chat-shadow-panel",i.panel),o.setProperty("--zabbu-chat-shadow-teaser",i.teaser),document.getElementById(P)?.classList.toggle("zabbu-chat-teaser-dark",t==="DARK");let a=n==="BOTTOM_LEFT";for(let c of[re,ne,P,se])document.getElementById(c)?.classList.toggle("zabbu-chat-position-left",a)}async function Er(r,e,t){let n=null,s="SOFT",i="LIGHT",o="BOTTOM_RIGHT";try{let a=await fetch(`${r}/public/sites/${e}`);if(a.ok){let c=await a.json();n=c.primaryColor??null,s=c.shadowStyle??"SOFT",i=c.colorScheme??"LIGHT",o=c.widgetPosition??"BOTTOM_RIGHT"}}catch{}_r(t.primaryColor??n,s,t.colorScheme??i,t.position??o)}function xr(){let r=document.currentScript;if(!r)throw new Error("zabbu-chat-widget: loader.js must run as a plain <script> tag");return r}function Tr(r){let e=r.dataset.apiBase;return e?e.replace(/\/$/,""):"https://api-production-e565.up.railway.app"}function Ar(r){return new URL(r.src).href.replace(/\/[^/]*$/,"")}function Pt(r){return`zabbu-chat-visitor:${r}`}function wr(){let r=document.createElement("style");r.textContent=`
|
|
2
|
+
#${re} {
|
|
3
3
|
position: fixed;
|
|
4
4
|
bottom: 20px;
|
|
5
5
|
right: 20px;
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
transition: box-shadow 0.3s ease;
|
|
18
18
|
z-index: 2147483000;
|
|
19
19
|
}
|
|
20
|
-
#${
|
|
20
|
+
#${re} svg {
|
|
21
21
|
width: 26px;
|
|
22
22
|
height: 26px;
|
|
23
23
|
}
|
|
24
|
-
#${
|
|
24
|
+
#${ne} {
|
|
25
25
|
position: fixed;
|
|
26
26
|
bottom: 88px;
|
|
27
27
|
right: 20px;
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
z-index: 2147483000;
|
|
37
37
|
display: none;
|
|
38
38
|
}
|
|
39
|
-
#${
|
|
39
|
+
#${ne}.zabbu-chat-open {
|
|
40
40
|
display: block;
|
|
41
41
|
}
|
|
42
|
-
#${
|
|
42
|
+
#${It} {
|
|
43
43
|
width: 100%;
|
|
44
44
|
height: 100%;
|
|
45
45
|
border: 0;
|
|
46
46
|
}
|
|
47
|
-
#${
|
|
47
|
+
#${P} {
|
|
48
48
|
position: fixed;
|
|
49
49
|
bottom: 32px;
|
|
50
50
|
right: 88px;
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
|
|
65
65
|
pointer-events: none;
|
|
66
66
|
}
|
|
67
|
-
#${
|
|
67
|
+
#${P}.zabbu-chat-teaser-visible {
|
|
68
68
|
opacity: 1;
|
|
69
69
|
transform: translateY(0) scale(1);
|
|
70
70
|
pointer-events: auto;
|
|
71
71
|
}
|
|
72
|
-
#${
|
|
72
|
+
#${P}.zabbu-chat-teaser-dark {
|
|
73
73
|
background: #1f2028;
|
|
74
74
|
color: #f1eff8;
|
|
75
75
|
border-color: rgba(255, 255, 255, 0.1);
|
|
76
76
|
}
|
|
77
|
-
#${
|
|
77
|
+
#${se} {
|
|
78
78
|
/* Sibling of the launcher, not a child \u2014 launcher.innerHTML gets fully replaced
|
|
79
79
|
when the trigger icon updates (see the CHAT_READY handler below), which would
|
|
80
80
|
silently delete a badge nested inside it. Positioned to overlap the launcher's
|
|
@@ -95,7 +95,22 @@
|
|
|
95
95
|
pointer-events: none;
|
|
96
96
|
display: none;
|
|
97
97
|
}
|
|
98
|
-
#${
|
|
98
|
+
#${se}.zabbu-chat-badge-visible {
|
|
99
99
|
display: block;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
/* Mirror image of the default (bottom-right) placement above, toggled by
|
|
102
|
+
ZabbuConfig.position / data-position \u2014 same offsets, opposite side. */
|
|
103
|
+
#${re}.zabbu-chat-position-left,
|
|
104
|
+
#${ne}.zabbu-chat-position-left {
|
|
105
|
+
right: auto;
|
|
106
|
+
left: 20px;
|
|
107
|
+
}
|
|
108
|
+
#${P}.zabbu-chat-position-left {
|
|
109
|
+
right: auto;
|
|
110
|
+
left: 88px;
|
|
111
|
+
}
|
|
112
|
+
#${se}.zabbu-chat-position-left {
|
|
113
|
+
right: auto;
|
|
114
|
+
left: 11px;
|
|
115
|
+
}
|
|
116
|
+
`,document.head.appendChild(r)}function Cr(r,e,t,n){let s=new URL(`${r}/index.html`),i=new URLSearchParams({prefix:t,api:e});return n.welcomeText&&i.set("welcome",n.welcomeText),n.primaryColor&&i.set("color",n.primaryColor),n.colorScheme&&i.set("scheme",n.colorScheme),s.hash=i.toString(),s.toString()}function vr(r,e){let t=e.siteKey,n=t.split(".")[0],s=e.apiBase?.replace(/\/$/,"")??Tr(r),i=Ar(r),o=Dt(e.position),a=qt(e.colorScheme),c=br();wr();let d=document.createElement("button");d.id=re,d.type="button",d.setAttribute("aria-label","Abrir chat"),d.innerHTML=Ne(null);let f=document.createElement("div");f.id=ne;let u=document.createElement("iframe");u.id=It,u.sandbox.add("allow-scripts","allow-forms","allow-same-origin"),u.src=Cr(i,s,n,{welcomeText:e.welcomeText,primaryColor:e.primaryColor,colorScheme:a}),f.appendChild(u);let g=document.createElement("button");g.id=P,g.type="button",g.textContent="\xBFNecesit\xE1s ayuda? \u{1F44B}";let U=document.createElement("span");U.id=se,U.setAttribute("aria-hidden","true"),document.body.appendChild(f),document.body.appendChild(d),document.body.appendChild(g),document.body.appendChild(U),Er(s,n,{primaryColor:e.primaryColor,position:o,colorScheme:a});let ie=!0,F=new ye,ge=0;function be(h){ge=h,U.textContent=h>9?"9+":String(h),U.classList.toggle("zabbu-chat-badge-visible",h>0)}let x=!1;function V(h){h!==x&&(x=h,f.classList.toggle("zabbu-chat-open",x),G({type:Tt,payload:{open:x}}),x&&be(0),c.emit(x?"open":"close",void 0))}function G(h){u.contentWindow?.postMessage(h,new URL(u.src).origin)}function Ie(){g.classList.remove("zabbu-chat-teaser-visible")}g.addEventListener("click",()=>{Ie(),d.click()});let He=!1;d.addEventListener("click",()=>{F.prime(),Ie();let h=!x;V(h),h&&ie&&F.play("CHAT_OPENED"),h&&!He&&(He=!0,A.emit("chat-opened"))});let Vt=localStorage.getItem(Pt(n)),A=bt(s,t,Vt),De=!1,qe=[];function O(h){De?G(h):qe.push(h)}let Ue=!1;A.on("session",h=>{localStorage.setItem(Pt(n),h.visitorId),Ue||(Ue=!0,O({type:St,payload:{messages:h.history}})),h.agentPresence!==void 0&&O({type:Pe,payload:{presence:h.agentPresence}})}),A.on("agent-presence",h=>{O({type:Pe,payload:{presence:h}})}),A.on("bot-reply",h=>{O({type:Ct,payload:{text:h.text}}),ie&&F.play(h.event??"BOT_REPLY"),x||be(ge+1),c.emit("message",{text:h.text})}),A.on("admin-message",h=>{O({type:kt,payload:{...h}}),ie&&F.play("AGENT_MESSAGE"),x||be(ge+1),c.emit("message",{text:h.text})}),A.on("admin-typing",h=>{O({type:Rt,payload:{...h}})}),A.on("connect_error",()=>{O({type:vt})}),window.addEventListener("message",h=>{if(h.source!==u.contentWindow)return;let m=h.data;if(!(!m||typeof m.type!="string")){if(m.type===xt)V(!1);else if(m.type===At){let y=!!m.payload?.fullscreen;f.classList.toggle("zabbu-chat-fullscreen",y)}else if(m.type===wt){let y=m.payload;(y?.text||y?.attachmentUrl)&&A.emit("message",y)}else if(m.type===Ot){let y=m.payload;A.emit("typing",{isTyping:!!y?.isTyping})}else if(m.type===Lt){let y=m.payload;y&&Gt(y,t)}else if(m.type===Et){d.disabled=!1;let y=m.payload,L=y?.triggerIcon;typeof L=="string"&&L&&(d.innerHTML=Ne(L)),ie=y?.soundEnabled!==!1,F.setTriggers(Object.fromEntries((y?.soundTriggers??[]).map(_e=>[_e.event,{enabled:_e.enabled,soundStyle:_e.soundStyle}]))),De=!0,qe.splice(0).forEach(G);let K=y?.autoOpenAfterSeconds;typeof K=="number"&&K>0&&setTimeout(()=>{x||g.classList.add("zabbu-chat-teaser-visible")},K*1e3)}}});async function Gt(h,m){let y=new FormData;y.append("file",h.file);try{let L=await fetch(`${s}/public/sites/${n}/attachments`,{method:"POST",headers:{"X-Api-Key":m},body:y});if(!L.ok)throw new Error(`upload failed with status ${L.status}`);let K=await L.json();G({type:Mt,payload:{requestId:h.requestId,...K}})}catch{G({type:Nt,payload:{requestId:h.requestId,message:"upload failed"}})}}let Fe=!1;return queueMicrotask(()=>{Fe=!0,c.emit("ready",void 0)}),{open:()=>V(!0),close:()=>V(!1),toggle:()=>V(!x),on(h,m){if(h==="ready"&&Fe){m(void 0);return}c.on(h,m)},off:(h,m)=>c.off(h,m)}}function Sr(r){let e=r.dataset.siteKey;if(!e)return null;let t=Dt(r.dataset.position),n=qt(r.dataset.colorScheme);return{siteKey:e,apiBase:r.dataset.apiBase,primaryColor:r.dataset.primaryColor,welcomeText:r.dataset.welcomeText,position:t==="BOTTOM_LEFT"?"bottom-left":t==="BOTTOM_RIGHT"?"bottom-right":void 0,colorScheme:n==="DARK"?"dark":n==="LIGHT"?"light":void 0}}var Ut=xr(),E=null;function te(r){console.warn(`zabbu-chat-widget: Zabbu.${r}() called before Zabbu.init()`)}var Ft={init(r){if(!E){if(!r?.siteKey)throw new Error("zabbu-chat-widget: Zabbu.init() requires a siteKey");E=vr(Ut,r)}return E},open(){E?E.open():te("open")},close(){E?E.close():te("close")},toggle(){E?E.toggle():te("toggle")},on(r,e){E?E.on(r,e):te("on")},off(r,e){E?E.off(r,e):te("off")}};window.Zabbu=Ft;var Bt=Sr(Ut);Bt&&Ft.init(Bt);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zabbu/chat-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Embeddable chat widget (loader.js + chat UI) for the chat portal backend (zabbu-chat-portal). Served standalone — see server.mjs and Dockerfile.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|