@prodantix/sdk 0.8.0 → 0.9.0-beta.783

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.
Files changed (40) hide show
  1. package/README.md +2 -2
  2. package/dist/chat.cjs +3 -5
  3. package/dist/chat.d.cts +10 -7
  4. package/dist/chat.d.ts +10 -7
  5. package/dist/chat.js +3 -5
  6. package/dist/chunk-3S3BR7QH.js +2 -0
  7. package/dist/{chunk-ODN4ZELX.js → chunk-5WTMO52O.js} +2 -2
  8. package/dist/{client-vogZuHfD.d.cts → client-C8r0UAth.d.cts} +1 -1
  9. package/dist/{client-Cz7M6XJC.d.ts → client-DnfOdWQo.d.ts} +1 -1
  10. package/dist/{config-C8WD1Pge.d.cts → config-CUWitmwr.d.cts} +10 -1
  11. package/dist/{config-Bhwwo-uC.d.ts → config-DsYOO9JC.d.ts} +10 -1
  12. package/dist/consent.iife.js +45 -14
  13. package/dist/ctas.iife.js +3 -3
  14. package/dist/forms.iife.js +2 -2
  15. package/dist/{http-BCh716Vs.d.cts → http-CAOViYSh.d.cts} +1 -0
  16. package/dist/{http-BCh716Vs.d.ts → http-CAOViYSh.d.ts} +1 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +4 -4
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +1 -1
  21. package/dist/messenger-help.iife.js +1 -1
  22. package/dist/messenger-tickets.iife.js +1 -1
  23. package/dist/messenger.d.cts +2 -2
  24. package/dist/messenger.d.ts +2 -2
  25. package/dist/messenger.iife.js +2 -4
  26. package/dist/messenger.js +1 -1
  27. package/dist/node.cjs +1 -1
  28. package/dist/node.d.cts +2 -2
  29. package/dist/node.d.ts +2 -2
  30. package/dist/node.js +1 -1
  31. package/dist/pages.iife.js +1 -1
  32. package/dist/prodantix-push-sw.js +1 -1
  33. package/dist/{transport-C9C4hqlF.d.cts → transport-BBYpAuVK.d.cts} +4 -2
  34. package/dist/{transport-C4mkCaix.d.ts → transport-BZDcmleq.d.ts} +4 -2
  35. package/dist/web.cjs +4 -4
  36. package/dist/web.d.cts +3 -3
  37. package/dist/web.d.ts +3 -3
  38. package/dist/web.js +4 -4
  39. package/package.json +1 -1
  40. package/dist/chunk-YHIIKYUP.js +0 -2
package/dist/chat.js CHANGED
@@ -1,9 +1,7 @@
1
- import {c,a as a$1,b as b$1}from'./chunk-V77KYPOF.js';import {e,h,d,b}from'./chunk-ODN4ZELX.js';import {a}from'./chunk-5XGN7UAV.js';var z="X-Prodantix-Conversation-Token",_="prodantix.chat.handle";function W(){let i=globalThis.localStorage;if(i)return {get:e=>i.getItem(e),remove:e=>i.removeItem(e),set:(e,t)=>i.setItem(e,t)}}var L=class{constructor(e$1){this.options=e$1;a(this,"fetchImpl");a(this,"fileFetchImpl");a(this,"host");a(this,"storage");a(this,"handle");a(this,"identity",null);a(this,"fromArticle",null);this.fetchImpl=e(e$1.fetchImpl),this.fileFetchImpl=e$1.fileFetchImpl??((t,n)=>fetch(t,n)),this.host=h(e$1.host),this.storage=e$1.storage??W(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}avatarUrl(e){return e.startsWith("/")?`${this.host}${e}?api_key=${encodeURIComponent(this.options.apiKey)}`:e}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,fromArticle:this.fromArticle,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.fromArticle=null,this.storage?.set(_,JSON.stringify(this.handle)),true)}cameFrom(e){this.fromArticle={language:e.language,pageId:e.pageId};}async send(e,t,n){if(!await this.ensureThread())return null;let r=this.handle;return r?(await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{attachmentIds:n,body:e,pageContext:t},token:r.token}))?.turn??null:null}async upload(e,t){if(!await this.ensureThread())return null;let n=this.handle;return n?this.fileRequest("POST",`/v1/conversations/${encodeURIComponent(n.conversationId)}/attachments?name=${encodeURIComponent(e.name)}`,n.token,async r=>JSON.parse(await r.text()),e,t):null}async file(e){let t=this.handle;return t?this.fileRequest("GET",e,t.token,n=>n.blob()):null}async helpCentre(e,t,n){let r=new URLSearchParams({...t,...this.options.locale&&{lang:this.options.locale},...this.identity&&{user_hash:this.identity.userHash,user_id:this.identity.userId}}).toString();return this.request(n?"POST":"GET",`/v1/messenger/articles${e}${r?`?${r}`:""}`,n?{body:{...n,distinctId:this.options.distinctId}}:{})}get visitor(){return this.identity&&{...this.identity,distinctId:this.options.distinctId}}edge(e,t,n){return this.request(t?"POST":"GET",e,{body:t,token:n})}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(_);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch(t){this.options.onError?.(t);}return this.storage?.remove(_),null}async fileRequest(e,t,n,r,a,s){let l={authorization:`Bearer ${this.options.apiKey}`,[z]:n};a&&(l["content-type"]=a.type||"application/octet-stream");try{let h=await this.fileFetchImpl(`${this.host}${t}`,{body:a,headers:l,method:e});if(h.ok)return await r(h);let u=s?.(await h.text());if(u)return u;this.options.onError?.(new d(`prodantix chat ${t}: ${h.status}`,h.status));}catch(h){this.options.onError?.(h);}return null}async request(e,t,n={}){let r=this.fetchImpl;if(!r)return this.options.onError?.(new d("no fetch available for prodantix chat")),null;let a={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};n.token&&(a[z]=n.token);try{let s=await r(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:a,method:e}),l=await s.text();return s.ok?l?JSON.parse(l):{}:(this.options.onError?.(new d(`prodantix chat ${t}: ${s.status}`,s.status)),null)}catch(s){return this.options.onError?.(s),null}}};var J={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function P(i,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:i.timezone,weekday:"short"}).formatToParts(e),n=J[t.find(l=>l.type==="weekday")?.value??""];if(!n)return false;let r=t.find(l=>l.type==="hour")?.value??"",a=t.find(l=>l.type==="minute")?.value??"",s=`${r}:${a}`;return i.windows.some(l=>l.days.includes(n)&&l.open<=s&&s<l.close)}var f={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},X=["quiet","standard"],V=["round","square"],Z=["rounded","tailed"],Q=["filled","outlined"],ee=["circle","pill","squircle"],te=["filled","outlined"],ne=["avatar","glyph","team_faces"],ie=["large","medium","small"],re=["above","hidden","inline"],ae=["beside_name","none","under_turn"],se=["time","time_and_latency"],y=(i,e,t)=>typeof i=="string"&&e.includes(i)?i:t,B=(i,e)=>typeof i=="boolean"?i:e,oe={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},le={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ce={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},de={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},pe={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function E(i){let e=typeof i=="object"&&i!==null?i:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:oe[t],r=typeof e.namePlacement=="string"?e.namePlacement:void 0,a=r===void 0?void 0:le[r],s=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,l=s===void 0?void 0:ce[s],h=typeof e.skin=="string"?e.skin:void 0,u=h===void 0?void 0:de[h],d=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,c=d===void 0?void 0:pe[d],p={bubbleFill:y(e.bubbleFill,Q,c?.[1]??f.bubbleFill),bubbleShape:y(e.bubbleShape,Z,c?.[0]??f.bubbleShape),composerShape:y(e.composerShape,V,u?.[1]??f.composerShape),dayDividers:B(e.dayDividers,l?.[0]??f.dayDividers),launcherContent:y(e.launcherContent,ne,n?.[2]??f.launcherContent),launcherFill:y(e.launcherFill,te,n?.[1]??f.launcherFill),launcherShape:y(e.launcherShape,ee,n?.[0]??f.launcherShape),launcherSize:y(e.launcherSize,ie,n?.[3]??f.launcherSize),nameAvatar:B(e.nameAvatar,a?.[1]??f.nameAvatar),namePlacement:y(e.namePlacement,re,a?.[0]??f.namePlacement),skin:y(e.skin,X,u?.[0]??f.skin),stampContent:y(e.stampContent,se,l?.[2]??f.stampContent),stampPlacement:y(e.stampPlacement,ae,l?.[1]??f.stampPlacement)};return p.stampPlacement==="beside_name"&&p.namePlacement==="hidden"&&(p.stampPlacement="under_turn"),p}function O(i){let e=i.split(/\s+/).filter(n=>n.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var he="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",ue={large:66,medium:56,small:46},me={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},ge={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},fe={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},be=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",ye={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},xe={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},ve={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},Se={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function D(i,e,t,n){return `.launcher{--fab-size:${ue[n]}px;${me[i]}${ge[e]}}${fe[t]}${be}${ye[i]}${xe[e]}${ve[i]}${Se[i]}`}function q(i,e,t,n=r=>r){let r=document.createDocumentFragment();if(i==="glyph"||t.length===0){let a=document.createElement("span");return a.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${he}"/></svg>`,r.append(...a.childNodes,R()),r}return i==="avatar"?(r.append(j(t[0],e,n),R()),r):(r.append(H(t,e,n),R()),r)}function H(i,e,t=n=>n){let n=document.createElement("span");n.className="faces";for(let r of i.slice(0,2))n.append(j(r,e,t));return n}function j(i,e,t){let n=document.createElement("span");if(n.className="av",n.setAttribute("aria-hidden","true"),i&&(n.style.background=i.tone),i?.avatarUrl){let r=document.createElement("img");return r.alt="",r.src=t(i.avatarUrl),n.append(r),n}return n.textContent=i?i.initials:e.agentLabel.slice(0,2).toUpperCase(),n}function R(){let i=document.createElement("span");return i.className="live",i.setAttribute("aria-hidden","true"),i}var ke={agentLabel:"Agent",aiLabel:"AI",attachLabel:"Attach a file",awayBody:"We are away right now, but we will reply as soon as we are back.",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",fileRefusal:(i,e)=>`That file is ${i}. Send a PNG, JPEG, WebP, GIF or PDF up to ${e}.`,inputPlaceholder:"Type a message",launcherLabel:"Chat with us",removeFileLabel:"Remove file",replyTime:"Usually replying in a few minutes",retryLabel:"Not delivered. Retry",sendLabel:"Send",timeLabel:i=>{let e=new Date(i);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:i=>`${i} unread`},w={accentColor:"#5958fc",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...f};function Ce(i,e){let t=document.createElement("a");t.className="powered",t.href="https://prodantix.com",t.target="_blank",t.rel="noopener";let n=document.createElement("img");return n.src=e,n.alt="",n.width=12,n.height=12,t.append(n,i),t}var Te={quiet:".composer{position:relative;padding:8px 10px 10px}.composer input{padding-right:36px}.composer button{position:absolute;top:50%;right:14px;width:28px;min-width:28px;height:28px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:16px;height:16px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.header .faces,.header .status{display:none}.header .close{top:6px}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},we={round:".composer{padding:10px 10px 12px;gap:6px}.composer input{height:36px;border-radius:18px;padding:0 14px}.composer button{width:36px;min-width:36px;height:36px;padding:0;border-radius:18px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:36px;border-radius:8px;padding:0 12px}"},Le={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},Ee={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Ae={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Pe=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn.agent .body,.turn.ai .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Fe='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',_e={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Re=".lat{font-size:11px;opacity:.7;margin-left:6px}",G=`--paper: oklch(24.6% 0.015 257); --ink: #fff; --ink-3: rgba(255,255,255,.55);
2
- --fill: rgba(255,255,255,.06); --hairline: rgba(255,255,255,.13); --ink-2: rgba(255,255,255,.70);
3
- --online: oklch(72% 0.13 163.23);`;function He(i){return i==="light"?"":i==="dark"?`:host { ${G} }`:`@media (prefers-color-scheme: dark) {
1
+ import {c,a as a$1,b as b$1}from'./chunk-V77KYPOF.js';import {e,h,d,b}from'./chunk-5WTMO52O.js';import {a}from'./chunk-5XGN7UAV.js';var z="X-Prodantix-Conversation-Token",_="prodantix.chat.handle";function W(){let i=globalThis.localStorage;if(i)return {get:e=>i.getItem(e),remove:e=>i.removeItem(e),set:(e,t)=>i.setItem(e,t)}}var L=class{constructor(e$1){this.options=e$1;a(this,"fetchImpl");a(this,"fileFetchImpl");a(this,"host");a(this,"storage");a(this,"handle");a(this,"identity",null);a(this,"fromArticle",null);this.fetchImpl=e(e$1.fetchImpl),this.fileFetchImpl=e$1.fileFetchImpl??((t,n)=>fetch(t,n)),this.host=h(e$1.host),this.storage=e$1.storage??W(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}avatarUrl(e){return e.startsWith("/")?`${this.host}${e}?api_key=${encodeURIComponent(this.options.apiKey)}`:e}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,fromArticle:this.fromArticle,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.fromArticle=null,this.storage?.set(_,JSON.stringify(this.handle)),true)}cameFrom(e){this.fromArticle={language:e.language,pageId:e.pageId};}async send(e,t,n){if(!await this.ensureThread())return null;let r=this.handle;return r?(await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{attachmentIds:n,body:e,pageContext:t},token:r.token}))?.turn??null:null}async upload(e,t){if(!await this.ensureThread())return null;let n=this.handle;return n?this.fileRequest("POST",`/v1/conversations/${encodeURIComponent(n.conversationId)}/attachments?name=${encodeURIComponent(e.name)}`,n.token,async r=>JSON.parse(await r.text()),e,t):null}async file(e){let t=this.handle;return t?this.fileRequest("GET",e,t.token,n=>n.blob()):null}async helpCentre(e,t,n){let r=new URLSearchParams({...t,...this.options.locale&&{lang:this.options.locale},...this.identity&&{user_hash:this.identity.userHash,user_id:this.identity.userId}}).toString();return this.request(n?"POST":"GET",`/v1/messenger/articles${e}${r?`?${r}`:""}`,n?{body:{...n,distinctId:this.options.distinctId}}:{})}get visitor(){return this.identity&&{...this.identity,distinctId:this.options.distinctId}}edge(e,t,n){return this.request(t?"POST":"GET",e,{body:t,token:n})}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(_);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch(t){this.options.onError?.(t);}return this.storage?.remove(_),null}async fileRequest(e,t,n,r,a,s){let l={authorization:`Bearer ${this.options.apiKey}`,[z]:n};a&&(l["content-type"]=a.type||"application/octet-stream");try{let h=await this.fileFetchImpl(`${this.host}${t}`,{body:a,headers:l,method:e});if(h.ok)return await r(h);let u=s?.(await h.text());if(u)return u;this.options.onError?.(new d(`prodantix chat ${t}: ${h.status}`,h.status));}catch(h){this.options.onError?.(h);}return null}async request(e,t,n={}){let r=this.fetchImpl;if(!r)return this.options.onError?.(new d("no fetch available for prodantix chat")),null;let a={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};n.token&&(a[z]=n.token);try{let s=await r(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:a,method:e}),l=await s.text();return s.ok?l?JSON.parse(l):{}:(this.options.onError?.(new d(`prodantix chat ${t}: ${s.status}`,s.status)),null)}catch(s){return this.options.onError?.(s),null}}};var J={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function P(i,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:i.timezone,weekday:"short"}).formatToParts(e),n=J[t.find(l=>l.type==="weekday")?.value??""];if(!n)return false;let r=t.find(l=>l.type==="hour")?.value??"",a=t.find(l=>l.type==="minute")?.value??"",s=`${r}:${a}`;return i.windows.some(l=>l.days.includes(n)&&l.open<=s&&s<l.close)}var f={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},X=["quiet","standard"],V=["round","square"],Z=["rounded","tailed"],Q=["filled","outlined"],ee=["circle","pill","squircle"],te=["filled","outlined"],ne=["avatar","glyph","team_faces"],ie=["large","medium","small"],re=["above","hidden","inline"],ae=["beside_name","none","under_turn"],se=["time","time_and_latency"],y=(i,e,t)=>typeof i=="string"&&e.includes(i)?i:t,B=(i,e)=>typeof i=="boolean"?i:e,oe={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},le={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ce={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},de={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},pe={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function A(i){let e=typeof i=="object"&&i!==null?i:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:oe[t],r=typeof e.namePlacement=="string"?e.namePlacement:void 0,a=r===void 0?void 0:le[r],s=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,l=s===void 0?void 0:ce[s],h=typeof e.skin=="string"?e.skin:void 0,u=h===void 0?void 0:de[h],d=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,c=d===void 0?void 0:pe[d],p={bubbleFill:y(e.bubbleFill,Q,c?.[1]??f.bubbleFill),bubbleShape:y(e.bubbleShape,Z,c?.[0]??f.bubbleShape),composerShape:y(e.composerShape,V,u?.[1]??f.composerShape),dayDividers:B(e.dayDividers,l?.[0]??f.dayDividers),launcherContent:y(e.launcherContent,ne,n?.[2]??f.launcherContent),launcherFill:y(e.launcherFill,te,n?.[1]??f.launcherFill),launcherShape:y(e.launcherShape,ee,n?.[0]??f.launcherShape),launcherSize:y(e.launcherSize,ie,n?.[3]??f.launcherSize),nameAvatar:B(e.nameAvatar,a?.[1]??f.nameAvatar),namePlacement:y(e.namePlacement,re,a?.[0]??f.namePlacement),skin:y(e.skin,X,u?.[0]??f.skin),stampContent:y(e.stampContent,se,l?.[2]??f.stampContent),stampPlacement:y(e.stampPlacement,ae,l?.[1]??f.stampPlacement)};return p.stampPlacement==="beside_name"&&p.namePlacement==="hidden"&&(p.stampPlacement="under_turn"),p}function O(i){let e=i.split(/\s+/).filter(n=>n.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var he="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",ue={large:66,medium:56,small:46},me={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},ge={filled:"background:var(--a);color:var(--oa);",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},fe={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},be=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",ye={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},xe={filled:"",outlined:".badge{background:var(--a);color:var(--oa);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},ve={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},ke={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function D(i,e,t,n){return `.launcher{--fab-size:${ue[n]}px;${me[i]}${ge[e]}}${fe[t]}${be}${ye[i]}${xe[e]}${ve[i]}${ke[i]}`}function q(i,e,t,n=r=>r){let r=document.createDocumentFragment();if(i==="glyph"||t.length===0){let a=document.createElement("span");return a.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${he}"/></svg>`,r.append(...a.childNodes,R()),r}return i==="avatar"?(r.append(j(t[0],e,n),R()),r):(r.append(H(t,e,n),R()),r)}function H(i,e,t=n=>n){let n=document.createElement("span");n.className="faces";for(let r of i.slice(0,2))n.append(j(r,e,t));return n}function j(i,e,t){let n=document.createElement("span");if(n.className="av",n.setAttribute("aria-hidden","true"),i&&(n.style.background=i.tone),i?.avatarUrl){let r=document.createElement("img");return r.alt="",r.src=t(i.avatarUrl),n.append(r),n}return n.textContent=i?i.initials:e.agentLabel.slice(0,2).toUpperCase(),n}function R(){let i=document.createElement("span");return i.className="live",i.setAttribute("aria-hidden","true"),i}var Se={agentLabel:"Agent",aiLabel:"AI",attachLabel:"Attach a file",awayBody:"We are away right now, but we will reply as soon as we are back.",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",fileRefusal:(i,e)=>`That file is ${i}. Send a PNG, JPEG, WebP, GIF or PDF up to ${e}.`,inputPlaceholder:"Type a message",launcherLabel:"Chat with us",removeFileLabel:"Remove file",replyTime:"Usually replying in a few minutes",retryLabel:"Not delivered. Retry",sendLabel:"Send",timeLabel:i=>{let e=new Date(i);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:i=>`${i} unread`},w={accentColor:"#5958fc",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...f};function Ce(i,e){let t=document.createElement("a");t.className="powered",t.href="https://prodantix.com",t.target="_blank",t.rel="noopener";let n=document.createElement("img");return n.src=e,n.alt="",n.width=12,n.height=12,t.append(n,i),t}var Te={quiet:".composer{position:relative;padding:8px 10px 10px}.composer input{padding-right:36px}.composer button{position:absolute;top:50%;right:14px;width:28px;min-width:28px;height:28px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:16px;height:16px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.header .faces,.header .status{display:none}.header .close{top:6px}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:var(--oa);flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},we={round:".composer{padding:10px 10px 12px;gap:6px}.composer input{height:36px;border-radius:18px;padding:0 14px}.composer button{width:36px;min-width:36px;height:36px;padding:0;border-radius:18px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:36px;border-radius:8px;padding:0 12px}"},Le={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},Ae={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Ee={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Pe=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn.agent .body,.turn.ai .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Fe='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',_e={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Re=".lat{font-size:11px;opacity:.7;margin-left:6px}",G="--paper:oklch(24.6% 0.015 257);--ink:#fff;--ink-3:rgba(255,255,255,.55);--fill:rgba(255,255,255,.06);--hairline:rgba(255,255,255,.13);--ink-2:rgba(255,255,255,.70);--online:oklch(72% 0.13 163.23);--at:var(--atd)";function He(i){return i==="light"?"":i==="dark"?`:host { ${G} }`:`@media (prefers-color-scheme: dark) {
4
2
  :host {
5
3
  ${G}
6
4
  }
7
- }`}var Ne=/https?:\/\/[^\s<>"]+/g,Ie=/[.,;:!?)]$/,Me=i=>{let e=i;for(;Ie.test(e);){let t=e.split("(").length-1,n=e.split(")").length-1;if(e.endsWith(")")&&t>=n)break;e=e.slice(0,-1);}return e};function $e(i,e){let t=0;for(let n of e.matchAll(Ne)){let r=n.index??0,a=Me(n[0]);r>t&&i.append(e.slice(t,r));let s=document.createElement("a");s.href=a,s.target="_blank",s.rel="noopener noreferrer",s.textContent=a,i.append(s),t=r+a.length;}t<e.length&&i.append(e.slice(t));}var Ue=["P","BR","STRONG","EM","A","UL","OL","LI"],Ke=i=>typeof i=="object"&&i!==null&&"html"in i&&typeof i.html=="string"&&"text"in i&&typeof i.text=="string",ze=(i,e)=>e.name==="class"||e.name==="data-block-type"?true:i!=="A"?false:e.name==="target"||e.name==="rel"?true:e.name==="href"&&/^https?:\/\//i.test(e.value.trim()),Be=i=>[...i.querySelectorAll("*")].every(e=>Ue.includes(e.tagName)&&[...e.attributes].every(t=>ze(e.tagName,t)));function Y(i,e="system"){let t=E(i),n=i.launcherPosition==="bottom_left"?"left":"right",r=i.accentColor;return `${`:host{all:initial;z-index:2147483000;--a:${r};--paper:#fff;--ink:#0f172a;--ink-3:rgba(0,0,0,.55);--fill:#f1f5f9;--hairline:#e2e8f0;--ink-2:rgba(0,0,0,.72);--online:oklch(53.8% 0.1274 163.23);color-scheme:${e==="system"?"light dark":e}}${He(e)}*{box-sizing:border-box;font-family:system-ui,sans-serif}.launcher{z-index:2147483000;position:fixed;${n}:${i.launcherOffsetX}px;bottom:${i.launcherOffsetY}px;width:56px;height:56px;border-radius:28px;border:none;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;background:${r};color:#fff;font-size:24px;box-shadow:0 4px 12px rgba(0,0,0,.2)}.launcher:focus-visible{outline:3px solid #0b0e14;outline-offset:2px}.launcher{transition:background-color 120ms ease}.launcher:hover{background:color-mix(in srgb,#000 12%,${r})}.launcher:active{background:color-mix(in srgb,#000 20%,${r})}@media (prefers-reduced-motion:reduce){.launcher{transition:none}}.badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;border-radius:10px;background:#dc2626;color:#fff;font-size:12px;display:flex;align-items:center;justify-content:center;padding:0 4px}.badge[hidden]{display:none}.panel{z-index:2147483001;position:fixed;${n}:${i.launcherOffsetX}px;bottom:${i.launcherOffsetY+68}px;width:360px;max-width:calc(100vw - 40px);height:520px;max-height:calc(100vh - 120px);background:var(--paper);color:var(--ink);border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,.24);display:flex;flex-direction:column;overflow:hidden}.header{position:relative;padding:14px 16px;background:#0b0e14;color:#fff;display:flex;align-items:center;justify-content:space-between}.header h2{margin:0;font-size:15px}.header .faces{display:flex}.header .av{width:36px;height:36px;box-shadow:0 0 0 2px var(--a)}.header .av + .av{margin-left:-12px}.headmain{display:flex;flex-direction:column}.header .status{display:flex;align-items:center;gap:6px;margin:5px 0 0;font-size:12.5px;color:rgb(255 255 255 / 80%)}.header .status .live{flex:none;width:10px;height:10px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper)}.panel.closed .status{display:none}.header .close{position:absolute;top:8px;right:8px}.close{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;padding:0;background:none;border:none;border-radius:8px;color:inherit;cursor:pointer;transition:background-color 120ms ease}.close svg{display:block;width:22px;height:22px}.close:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.close:focus-visible{outline:2px solid currentColor;outline-offset:1px}.log{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:8px}.turn{max-width:80%;padding:8px 12px;border-radius:12px;font-size:14px}.turn.end_user{align-self:flex-end;background:${r};color:#fff}.turn.agent,.turn.ai{align-self:flex-start;background:var(--fill);color:var(--ink)}.turn.system{align-self:center;font-size:12px;color:var(--ink-3)}.turn.ai a{color:${r};text-decoration:underline;overflow-wrap:anywhere}.author{font-size:11px;opacity:.7;margin-bottom:2px}.turn[data-pending]{opacity:.6}.turn[data-failed]{opacity:1;box-shadow:inset 0 0 0 1px #dc2626}.retry{display:block;margin:5px 0 0;padding:0;background:none;border:0;color:inherit;font:inherit;font-size:11.5px;text-decoration:underline;cursor:pointer;opacity:.85}.away{display:flex;gap:10px;align-items:flex-start;margin:12px 12px 0;padding:10px 14px;font-size:13px;line-height:1.43;color:${r};background:color-mix(in srgb,${r}12%,transparent);border-radius:4px}.awayglyph{flex:none;width:16px;height:16px;margin-top:1px;border:1.5px solid currentColor;border-radius:50%}.empty{display:flex;flex-direction:column;gap:8px;padding:20px 16px}.empty h3{margin:0;font-size:18px;font-weight:640;letter-spacing:-.015em}.empty > p{margin:0 0 8px;font-size:13.5px;color:var(--ink-2)}.prompt{position:relative;display:flex;align-items:center;min-height:44px;padding:10px 14px;text-align:left;font-family:inherit;font-size:13.5px;font-weight:500;color:var(--ink);background:none;border:1px solid var(--hairline);border-radius:8px;cursor:pointer}.promptwords{min-width:0;overflow-wrap:anywhere}.promptwords > :last-child{margin-bottom:0}.prompt p{margin:0 0 16px;line-height:1.6}.prompt ul,.prompt ol{margin:0 0 16px;padding-left:32px}.prompt li{margin:8px 0;line-height:1.6}.prompt a{position:relative;z-index:1;color:${r};text-decoration:underline;overflow-wrap:anywhere}.promptpress{position:absolute;inset:0;padding:0;background:none;border:0;border-radius:inherit;cursor:pointer}.promptpress:focus-visible{outline:2px solid ${r};outline-offset:2px}.av{width:30px;height:30px;border-radius:50%;flex:none;display:inline-flex;align-items:center;justify-content:center;font-size:11.5px;font-weight:650;color:#fff;background:oklch(52% 0.17 22)}.av.bot{border-radius:9px;background:var(--fill);color:var(--ink)}.av img{width:100%;height:100%;display:block;object-fit:cover;border-radius:inherit}.composer{display:flex;gap:6px;padding:10px;border-top:1px solid var(--hairline)}.composer input{flex:1;min-width:0;height:36px;padding:0 12px;border:0;border-radius:8px;font-size:14px;background:var(--fill);color:var(--ink)}.composer input:focus-visible{outline:2px solid ${r}}.composer button{display:inline-flex;align-items:center;justify-content:center;gap:0;min-width:56px;height:36px;padding:0 14px;background:${r};color:#fff;border:none;border-radius:8px;cursor:pointer;font-family:inherit;font-size:13.5px;font-weight:550}.composer button:hover{background:color-mix(in srgb,#000 12%,${r})}.composer button:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.composer button .sendglyph{display:none;width:17px;height:17px}.composer button:focus-visible{outline:2px solid #0b0e14}.powered{display:flex;align-items:center;justify-content:center;gap:4px;height:24px;font-size:11px;font-weight:500;color:var(--ink-3);text-decoration:none}.powered:hover{color:var(--ink-2)}.powered:focus-visible{outline:2px solid var(--ink);outline-offset:-2px}.powered img{width:12px;height:12px}@media (prefers-reduced-motion:no-preference){.panel{animation:rise 180ms ease-out}@keyframes rise{from{transform:translateY(8px);opacity:0}to{transform:none;opacity:1}}}.scrim,.grip{display:none}@media (max-width:770px){.panel{inset:auto 0 0;width:100%;max-width:none;height:86dvh;max-height:86dvh}:host .panel{border-bottom-left-radius:0;border-bottom-right-radius:0}.scrim{display:block;position:fixed;inset:0;z-index:2147483000;background:rgb(15 23 42/.24)}.grip{display:block;position:absolute;top:7px;left:calc(50% - 17px);width:34px;height:4px;border-radius:2px;background:currentColor;opacity:.45}.panel:not([data-dragging]){transition:translate .2s}.composer{padding-bottom:max(12px,env(safe-area-inset-bottom))}}`}${we[t.composerShape]}${Te[t.skin]}${D(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Le[t.bubbleShape]}${Ee[t.bubbleFill]}${Ae[t.namePlacement]}${t.nameAvatar?Pe:""}${t.dayDividers?Fe:""}${_e[t.stampPlacement]}${t.stampContent==="time_and_latency"?Re:""}`}var Oe=["end_user","agent","ai"];function De(){let i=globalThis.location;if(i)return {host:i.host,path:i.pathname,title:document.title}}var qe='<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M15.88 9.29 12 13.17 8.12 9.29a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0"/></svg>',A=class{constructor(e,t,n={},r={},a$1={}){this.host=e;this.client=t;a(this,"root");a(this,"strings");a(this,"settings");a(this,"appearance");a(this,"launcher");a(this,"badge");a(this,"panel",null);a(this,"scrim",null);a(this,"lastFocused",null);a(this,"unread",0);a(this,"pendingTurns",0);a(this,"openNow");a(this,"styles");a(this,"scheme");a(this,"picked",null);a(this,"objectUrls",[]);a(this,"helpLoader");a(this,"kit",null);a(this,"kitLoad",null);a(this,"filesLoader");a(this,"filesKit",null);a(this,"filesLoad",null);a(this,"ticketsLoader");a(this,"ticketsLoad");this.strings={...ke,...n},this.appearance={...w,...r},this.settings=E({...w,...r}),this.root=e.attachShadow({mode:a$1.shadowMode??"closed"}),this.openNow=P(this.appearance.availability,new Date),this.scheme=a$1.scheme,this.helpLoader=a$1.help,this.filesLoader=a$1.files,this.ticketsLoader=a$1.tickets,this.styles=Ye(this.root),this.paint(),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.drawLauncher(),this.root.append(this.launcher);}drawLauncher(){if(this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.replaceChildren(),this.launcher.append(q(this.settings.launcherContent,this.strings,this.appearance.team,e=>this.client.avatarUrl(e))),this.settings.launcherShape==="pill"){let e=document.createElement("span");e.className="label",e.textContent=this.strings.launcherLabel,this.launcher.append(e);}this.launcher.append(this.badge),this.launcher.classList.toggle("closed",!this.openNow);}update(e,t){this.appearance={...w,...e},this.settings=E(this.appearance),t!==void 0&&(this.scheme=t),this.paint(),this.drawLauncher(),this.panel&&(this.close(),this.open());}paint(){this.styles(`${Y(this.appearance,this.scheme)}${this.kit&&this.appearance.help?this.kit.HELP_CSS:""}${this.filesKit?this.filesKit.filesCss(this.appearance.attachments?.enabled===true,this.settings.composerShape):""}`);}loadKit(){return !this.appearance.help||!this.helpLoader?Promise.resolve(null):(this.kitLoad??(this.kitLoad=this.helpLoader().then(e=>(this.kit=e,this.paint(),e))),this.kitLoad)}loadFiles(){return this.filesLoader?(this.filesLoad??(this.filesLoad=this.filesLoader().then(e=>(this.filesKit=e,this.paint(),e))),this.filesLoad):Promise.resolve(null)}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.openNow=e,this.launcher.classList.toggle("closed",!e),this.panel?.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className=this.openNow?"panel":"panel closed",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let n=document.createElement("span");n.className="grip",n.setAttribute("aria-hidden","true"),t.append(n);let r=this.appearance.team??[];r.length>0&&t.append(H(r,this.strings,b=>this.client.avatarUrl(b)));let a=document.createElement("div");a.className="headmain";let s=document.createElement("h2");s.textContent=this.strings.title;let l=document.createElement("p");l.className="status";let h=document.createElement("span");h.className="live",h.setAttribute("aria-hidden","true"),l.append(h,this.strings.replyTime),a.append(s,l);let u=document.createElement("button");u.className="close",u.type="button",u.setAttribute("aria-label",this.strings.closeLabel),u.innerHTML=qe,u.addEventListener("click",()=>this.close()),t.append(a,u);let d=document.createElement("div");d.className="log",d.setAttribute("role","log"),d.setAttribute("aria-live","polite"),d.setAttribute("aria-label",this.strings.title);let c=document.createElement("form");c.className="composer";let p=document.createElement("input");p.type="text",p.setAttribute("aria-label",this.strings.inputPlaceholder),p.placeholder=this.strings.inputPlaceholder;let m=document.createElement("button");m.type="submit",m.setAttribute("aria-label",this.strings.sendLabel),m.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let C=document.createElement("span");C.className="sendtext",C.textContent=this.strings.sendLabel,m.append(C),c.append(p,m),c.addEventListener("submit",b=>{b.preventDefault(),this.submit(p,d);}),e.append(t,d,c),this.appearance.poweredBy&&e.append(Ce(this.appearance.poweredBy,this.client.avatarUrl("/messenger-mark.png"))),e.addEventListener("keydown",b=>this.onKeydown(b,e,u));let S=document.createElement("div");S.className="scrim",S.addEventListener("click",()=>this.close()),this.root.append(S,e),this.panel=e,this.scrim=S,Ge(e,()=>this.close()),p.focus();let k=this.appearance.attachments,[g,,,x]=await Promise.all([this.client.load(),this.loadKit(),k?.enabled&&this.client.upload?this.loadFiles():null,this.ticketsLoad??(this.ticketsLoad=this.ticketsLoader?.())]);if(g?.turns.some(b=>b.attachments?.length)&&await this.loadFiles(),this.panel!==e)return;this.filesKit&&k?.enabled&&this.client.upload&&this.filesKit.attachField({attachLabel:this.strings.attachLabel,fileRefusal:this.strings.fileRefusal,hold:b=>{this.picked=b;},objectUrl:b=>this.objectUrl(b),removeFileLabel:this.strings.removeFileLabel,root:this.root},c,p,d,k);let v=this.helpHost();v?.placement==="tab"&&v.host.source.collections&&v.host.source.collectionArticles&&v.kit.helpTab(v.host),v?.placement==="while_typing"&&v.kit.whileTyping(v.host,p,c),x&&this.appearance.tickets&&x.ticketsTab(e,this.client,this.appearance.tickets.words),g&&g.turns.length>0?this.renderThread(d,g):this.renderFirstRun(d,p),this.openNow||this.renderAway(t);}renderFirstRun(e,t){let n=document.createElement("div");n.className="empty";let r=document.createElement("h3");r.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle,n.append(r);let a=this.helpHost();if(a?.placement==="first_view")a.kit.firstView(a.host,n);else {let l=document.createElement("p");l.textContent=this.strings.emptyBody,n.append(l);}this.appearance.starterPrompts.filter(Ke).forEach((l,h)=>{let u=document.createElement("div");u.className="prompt";let d=document.createElement("div");d.className="promptwords",d.id=`prompt-${h}`;let c=document.createElement("template");c.innerHTML=l.html,Be(c.content)?d.append(c.content):d.textContent=l.text;for(let m of d.querySelectorAll("a"))m.target="_blank",m.rel="noopener noreferrer";let p=document.createElement("button");p.className="promptpress",p.type="button",p.setAttribute("aria-labelledby",d.id),p.addEventListener("click",()=>{t.value=l.text,this.submit(t,e);}),u.append(d,p),n.append(u);}),e.replaceChildren(n);}helpHost(){let e=this.appearance.help,{kit:t,panel:n}=this,r=e&&t&&n?t.hostOf(this.client,{close:()=>this.close(),closeLabel:this.strings.closeLabel,panel:n,scheme:this.scheme,words:e.words}):null;return r&&t&&e?{host:r,kit:t,placement:e.placement}:null}renderAway(e){let t=document.createElement("div");t.className="away";let n=document.createElement("span");n.className="awayglyph",n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.textContent=this.appearance.awayMessage.trim()||this.strings.awayBody,t.append(n,r),e.after(t);}objectUrl(e){let t=URL.createObjectURL(e);return this.objectUrls.push(t),t}close(){if(this.panel){this.panel.remove(),this.scrim?.remove(),this.panel=null,this.scrim=null,this.picked=null;for(let e of this.objectUrls)URL.revokeObjectURL(e);this.objectUrls=[],this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus();}}onIncomingTurn(e){if(this.panel&&e.attachments?.length&&!this.filesKit&&this.filesLoader){this.loadFiles().then(()=>this.takeTurn(e));return}this.takeTurn(e);}takeTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&!this.hasTurn(t,e.id)&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let n=e.value.trim(),r=this.picked;if(!(!n&&!r)){e.value="",this.picked=null;for(let a of this.root.querySelectorAll(".file,.ferr,.hsugg"))a.remove();await this.sendBody(t,n,r);}}async sendBody(e,t,n=null){e.querySelector(".empty")?.remove(),this.pendingTurns+=1;let r=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`},n);r.setAttribute("data-pending","");let a=n?await this.client.upload?.(n,this.filesKit?.uploadRefusalOf):void 0;if(a&&"refusal"in a){this.filesKit?.markRefused(r,a.refusal,this.appearance.attachments,()=>this.sendBody(e,t,n));return}let s=a===null?null:await this.client.send(t,De(),a?[a.id]:void 0);if(r.removeAttribute("data-pending"),s){r.dataset.turnId=s.id;return}this.markFailed(e,r,t,n);}markFailed(e,t,n,r){t.setAttribute("data-failed","");let a=document.createElement("button");a.type="button",a.className="retry",a.textContent=this.strings.retryLabel,a.addEventListener("click",()=>{t.remove(),this.sendBody(e,n,r);}),(t.querySelector(".body")??t).append(a);}hasTurn(e,t){for(let n of e.children)if(n instanceof HTMLElement&&n.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let n of t.turns)this.appendTurn(e,n);}appendTurn(e,t,n=null){if(e.querySelector(".empty")?.remove(),t.authorKind==="system"){let c=document.createElement("div");return c.className="turn system",c.dataset.turnId=t.id,c.textContent=t.body,e.append(c),c}let r=Oe.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,s=document.createElement("div");if(s.className=`turn ${r}`,s.dataset.turnId=t.id,r!=="end_user"&&a.nameAvatar){let c=document.createElement("span");if(c.className=r==="ai"?"av bot":"av",c.setAttribute("aria-hidden","true"),r==="agent"&&t.authorAvatarUrl){let p=document.createElement("img");p.alt="",p.src=this.client.avatarUrl(t.authorAvatarUrl),c.append(p);}else {c.textContent=r==="ai"?this.strings.aiLabel:O(this.agentName(t));let p=r==="agent"?this.appearance.team?.find(m=>m.name===t.authorName)?.tone:void 0;p&&(c.style.background=p);}s.append(c);}let h=document.createElement("div");if(h.className="body",r==="end_user"){let c=this.filesKit,p=m=>this.objectUrl(m);n&&c?.drawFile(h,n.name,n.type,n.size,Promise.resolve(n),p);for(let m of t.attachments??[])c?.drawFile(h,m.name,m.contentType,m.bytes,this.client.file?.(m.url)??Promise.resolve(null),p);}let u=r!=="end_user"&&a.namePlacement!=="hidden",d=document.createElement("div");if(r==="ai"?$e(d,t.body):d.textContent=t.body,u||r==="ai"&&a.namePlacement==="hidden"){let c=document.createElement("div");c.className=r==="ai"?"author ai":"author",c.textContent=r==="ai"?this.strings.aiLabel:this.agentName(t),a.stampPlacement==="beside_name"&&c.append(this.stamp(t)),a.namePlacement==="inline"?(c.classList.add("below"),h.append(d,c)):h.append(c,d);}else t.body&&h.append(d);return a.stampPlacement==="under_turn"&&h.append(this.stamp(t)),s.append(h),e.append(s),e.scrollTop=e.scrollHeight,s}agentName(e){return e.authorName||this.strings.agentLabel}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,n){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let r=[...t.querySelectorAll('button, input, a[href], [tabindex]:not([tabindex="-1"])')].filter(h=>!h.closest("[hidden]")&&!h.hidden);if(r.length===0)return;let a=r[0],s=r[r.length-1],l=this.root.activeElement;e.shiftKey&&l===a?(e.preventDefault(),s.focus()):!e.shiftKey&&l===s?(e.preventDefault(),a.focus()):l===null&&(e.preventDefault(),n.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}},je="(max-width: 770px)";function Ge(i,e){let t=null;i.addEventListener("pointerdown",r=>{if(t||r.button!==0||!globalThis.matchMedia?.(je).matches)return;let a=r.target;if(!a?.closest("a, button, input, textarea, iframe")){for(;a&&a!==i;a=a.parentElement)if(a.scrollTop>0)return;t={at:r.timeStamp,id:r.pointerId,offset:0,startY:r.clientY},i.setPointerCapture?.(r.pointerId),i.dataset.dragging="";}}),i.addEventListener("pointermove",r=>{if(t?.id!==r.pointerId)return;let a=r.clientY-t.startY;t.offset=a>=0?a:-16*(1-Math.exp(a/48)),i.style.translate=`0 ${t.offset}px`;});let n=r=>{let a=t;if(a?.id!==r.pointerId)return;t=null,delete i.dataset.dragging;let s=a.offset>Math.min(72,i.getBoundingClientRect().height*.4),l=a.offset/Math.max(1,r.timeStamp-a.at)>.5&&a.offset>16;s||l?e():i.style.translate="";};i.addEventListener("pointerup",n),i.addEventListener("pointercancel",n);}var Ye=i=>{if(typeof CSSStyleSheet=="function"&&"adoptedStyleSheets"in i&&"replaceSync"in CSSStyleSheet.prototype){let t=new CSSStyleSheet;return i.adoptedStyleSheets=[t],n=>t.replaceSync(n)}let e=document.createElement("style");return i.append(e),t=>{e.textContent=t;}};var We="/socket.io/?EIO=4&transport=websocket",F=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??Je,this.setTimer=e.setTimer??((t,n)=>setTimeout(t,n)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${We}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=n=>this.receive(String(n.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=c(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(a$1(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(b$1());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let n=t.payload?.turn;n&&this.options.onTurn(n);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Je(i){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(i)}var Xe=6e4;function yt(i){let e=globalThis.document;if(!e)throw new b("prodantix chat requires a document; mount it in the browser");let t=i.mountPoint??e.createElement("div");i.mountPoint||e.body.append(t);let n=new L(i),r=new A(t,n,i.strings,i.appearance,{files:i.files,help:i.help,tickets:i.tickets}),a=i.appearance?.availability??w.availability,s,l=()=>{r.setOpenNow(P(a,new Date)),s=setTimeout(l,Xe);};l();let h=new Set,u,d=null,c=i.pollIntervalMs??15e3,p=g=>{h.has(g.id)||g.authorKind==="end_user"||(h.add(g.id),r.onIncomingTurn(g));},m=async()=>{if(!n.hasThread)return;let g=await n.load();if(g){for(let x of g.turns)p(x);h=new Set(g.turns.map(x=>x.id));}},C=()=>{u||c<=0||(u=setInterval(()=>void m(),c));},S=()=>{u&&clearInterval(u),u=void 0;},k=()=>{if(d||!i.socketHost)return;let g=n.socketAuth;g&&(d=new F({auth:g,host:i.socketHost,onClosed:x=>{d=null,C(),x&&k();},onReady:S,onTurn:p,socketFactory:i.socketFactory}),d.open());};return C(),k(),{close:()=>r.close(),destroy:()=>{S(),clearTimeout(s),d?.close(),d=null,r.close(),t.remove();},identify:g=>n.identify(g),open:()=>{r.open().then(k);}}}
8
- export{L as ChatClient,A as ChatPanel,w as DEFAULT_APPEARANCE,f as DEFAULT_APPEARANCE_SETTINGS,yt as mountChat,Y as panelStyles,E as resolveAppearance};//# sourceMappingURL=chat.js.map
5
+ }`}var Ne=/https?:\/\/[^\s<>"]+/g,Ie=/[.,;:!?)]$/,Me=i=>{let e=i;for(;Ie.test(e);){let t=e.split("(").length-1,n=e.split(")").length-1;if(e.endsWith(")")&&t>=n)break;e=e.slice(0,-1);}return e};function Ue(i,e){let t=0;for(let n of e.matchAll(Ne)){let r=n.index??0,a=Me(n[0]);r>t&&i.append(e.slice(t,r));let s=document.createElement("a");s.href=a,s.target="_blank",s.rel="noopener noreferrer",s.textContent=a,i.append(s),t=r+a.length;}t<e.length&&i.append(e.slice(t));}var $e=["P","BR","STRONG","EM","A","UL","OL","LI"],Ke=i=>typeof i=="object"&&i!==null&&"html"in i&&typeof i.html=="string"&&"text"in i&&typeof i.text=="string",ze=(i,e)=>e.name==="class"||e.name==="data-block-type"?true:i!=="A"?false:e.name==="target"||e.name==="rel"?true:e.name==="href"&&/^https?:\/\//i.test(e.value.trim()),Be=i=>[...i.querySelectorAll("*")].every(e=>$e.includes(e.tagName)&&[...e.attributes].every(t=>ze(e.tagName,t)));function Y(i,e="system"){let t=A(i),n=i.launcherPosition==="bottom_left"?"left":"right",r=i.accentColor;return `${`:host{all:initial;z-index:2147483000;--a:${r};--oa:${i.onAccent||"#fff"};--at:${i.accentInk||r};--atd:${i.accentInkDark||r};--paper:#fff;--ink:#0f172a;--ink-3:rgba(0,0,0,.55);--fill:#f1f5f9;--hairline:#e2e8f0;--ink-2:rgba(0,0,0,.72);--online:oklch(53.8% 0.1274 163.23);color-scheme:${e==="system"?"light dark":e}}${He(e)}*{box-sizing:border-box;font-family:system-ui,sans-serif}.launcher{z-index:2147483000;position:fixed;${n}:${i.launcherOffsetX}px;bottom:${i.launcherOffsetY}px;width:56px;height:56px;border-radius:28px;border:none;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;font-size:24px;box-shadow:0 4px 12px rgba(0,0,0,.2)}.launcher:focus-visible{outline:3px solid #0b0e14;outline-offset:2px}.launcher{transition:background-color 120ms ease}.launcher:hover{background:color-mix(in srgb,#000 12%,${r})}.launcher:active{background:color-mix(in srgb,#000 20%,${r})}@media (prefers-reduced-motion:reduce){.launcher{transition:none}}.badge{position:absolute;top:-4px;right:-4px;min-width:20px;height:20px;border-radius:10px;background:#dc2626;color:#fff;font-size:12px;display:flex;align-items:center;justify-content:center;padding:0 4px}.badge[hidden]{display:none}.panel{z-index:2147483001;position:fixed;${n}:${i.launcherOffsetX}px;bottom:${i.launcherOffsetY+68}px;width:360px;max-width:calc(100vw - 40px);height:520px;max-height:calc(100vh - 120px);background:var(--paper);color:var(--ink);border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,.24);display:flex;flex-direction:column;overflow:hidden}.header{position:relative;padding:14px 16px;background:#0b0e14;color:#fff;display:flex;align-items:center;justify-content:space-between}.header h2{margin:0;font-size:15px}.header .faces{display:flex}.header .av{width:36px;height:36px;box-shadow:0 0 0 2px var(--a)}.header .av + .av{margin-left:-12px}.headmain{display:flex;flex-direction:column}.header .status{display:flex;align-items:center;gap:6px;margin:5px 0 0;font-size:12.5px;color:color-mix(in srgb,currentColor 80%,transparent)}.header .status .live{flex:none;width:10px;height:10px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper)}.panel.closed .status{display:none}.header .close{position:absolute;top:8px;right:8px}.close{display:inline-flex;align-items:center;justify-content:center;width:32px;height:32px;padding:0;background:none;border:none;border-radius:8px;color:inherit;cursor:pointer;transition:background-color 120ms ease}.close svg{display:block;width:22px;height:22px}.close:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.close:focus-visible{outline:2px solid currentColor;outline-offset:1px}.log{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:8px}.turn{max-width:80%;padding:8px 12px;border-radius:12px;font-size:14px}.turn.end_user{align-self:flex-end;background:${r};color:var(--oa)}.turn.agent,.turn.ai{align-self:flex-start;background:var(--fill);color:var(--ink)}.turn.system{align-self:center;font-size:12px;color:var(--ink-3)}.turn.ai a{color:var(--at);text-decoration:underline;overflow-wrap:anywhere}.author{font-size:11px;opacity:.7;margin-bottom:2px}.turn[data-pending]{opacity:.6}.turn[data-failed]{opacity:1;box-shadow:inset 0 0 0 1px #dc2626}.retry{display:block;margin:5px 0 0;padding:0;background:none;border:0;color:inherit;font:inherit;font-size:11.5px;text-decoration:underline;cursor:pointer;opacity:.85}.away{display:flex;gap:10px;align-items:flex-start;margin:12px 12px 0;padding:10px 14px;font-size:13px;line-height:1.43;color:var(--at);background:color-mix(in srgb,${r}12%,transparent);border-radius:4px}.awayglyph{flex:none;width:16px;height:16px;margin-top:1px;border:1.5px solid currentColor;border-radius:50%}.empty{display:flex;flex-direction:column;gap:8px;padding:20px 16px}.empty h3{margin:0;font-size:18px;font-weight:640;letter-spacing:-.015em}.empty > p{margin:0 0 8px;font-size:13.5px;color:var(--ink-2)}.prompt{position:relative;display:flex;align-items:center;min-height:44px;padding:10px 14px;text-align:left;font-family:inherit;font-size:13.5px;font-weight:500;color:var(--ink);background:none;border:1px solid var(--hairline);border-radius:8px;cursor:pointer}.promptwords{min-width:0;overflow-wrap:anywhere}.promptwords > :last-child{margin-bottom:0}.prompt p{margin:0 0 16px;line-height:1.6}.prompt ul,.prompt ol{margin:0 0 16px;padding-left:32px}.prompt li{margin:8px 0;line-height:1.6}.prompt a{position:relative;z-index:1;color:var(--at);text-decoration:underline;overflow-wrap:anywhere}.promptpress{position:absolute;inset:0;padding:0;background:none;border:0;border-radius:inherit;cursor:pointer}.promptpress:focus-visible{outline:2px solid var(--at);outline-offset:2px}.av{width:30px;height:30px;border-radius:50%;flex:none;display:inline-flex;align-items:center;justify-content:center;font-size:11.5px;font-weight:650;color:#fff;background:oklch(52% 0.17 22)}.av.bot{border-radius:9px;background:var(--fill);color:var(--ink)}.av img{width:100%;height:100%;display:block;object-fit:cover;border-radius:inherit}.composer{display:flex;gap:6px;padding:10px;border-top:1px solid var(--hairline)}.composer input{flex:1;min-width:0;height:36px;padding:0 12px;border:0;border-radius:8px;font-size:14px;background:var(--fill);color:var(--ink)}.composer input:focus-visible{outline:2px solid var(--at)}.composer button{display:inline-flex;align-items:center;justify-content:center;gap:0;min-width:56px;height:36px;padding:0 14px;background:${r};color:var(--oa);border:none;border-radius:8px;cursor:pointer;font-family:inherit;font-size:13.5px;font-weight:550}.composer button:hover{background:color-mix(in srgb,#000 12%,${r})}.composer button:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.composer button .sendglyph{display:none;width:17px;height:17px}.powered{display:flex;align-items:center;justify-content:center;gap:4px;height:24px;font-size:11px;font-weight:500;color:var(--ink-3);text-decoration:none}.powered:hover{color:var(--ink-2)}.powered:focus-visible{outline:2px solid var(--ink);outline-offset:-2px}.powered img{width:12px;height:12px}@media (prefers-reduced-motion:no-preference){.panel{animation:rise 180ms ease-out}@keyframes rise{from{transform:translateY(8px);opacity:0}to{transform:none;opacity:1}}}.scrim,.grip{display:none}@media (max-width:770px){.panel{inset:auto 0 0;width:100%;max-width:none;height:86dvh;max-height:86dvh}:host .panel{border-bottom-left-radius:0;border-bottom-right-radius:0}.scrim{display:block;position:fixed;inset:0;z-index:2147483000;background:rgb(15 23 42/.24)}.grip{display:block;position:absolute;top:7px;left:calc(50% - 17px);width:34px;height:4px;border-radius:2px;background:currentColor;opacity:.45}.panel:not([data-dragging]){transition:translate .2s}.composer{padding-bottom:max(12px,env(safe-area-inset-bottom))}}`}${we[t.composerShape]}${Te[t.skin]}${D(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Le[t.bubbleShape]}${Ae[t.bubbleFill]}${Ee[t.namePlacement]}${t.nameAvatar?Pe:""}${t.dayDividers?Fe:""}${_e[t.stampPlacement]}${t.stampContent==="time_and_latency"?Re:""}`}var Oe=["end_user","agent","ai"];function De(){let i=globalThis.location;if(i)return {host:i.host,path:i.pathname,title:document.title}}var qe='<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M15.88 9.29 12 13.17 8.12 9.29a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0"/></svg>',E=class{constructor(e,t,n={},r={},a$1={}){this.host=e;this.client=t;a(this,"root");a(this,"strings");a(this,"settings");a(this,"appearance");a(this,"launcher");a(this,"badge");a(this,"panel",null);a(this,"scrim",null);a(this,"lastFocused",null);a(this,"unread",0);a(this,"pendingTurns",0);a(this,"openNow");a(this,"styles");a(this,"scheme");a(this,"picked",null);a(this,"objectUrls",[]);a(this,"helpLoader");a(this,"kit",null);a(this,"kitLoad",null);a(this,"filesLoader");a(this,"filesKit",null);a(this,"filesLoad",null);a(this,"ticketsLoader");a(this,"ticketsLoad");this.strings={...Se,...n},this.appearance={...w,...r},this.settings=A({...w,...r}),this.root=e.attachShadow({mode:a$1.shadowMode??"closed"}),this.openNow=P(this.appearance.availability,new Date),this.scheme=a$1.scheme,this.helpLoader=a$1.help,this.filesLoader=a$1.files,this.ticketsLoader=a$1.tickets,this.styles=Ye(this.root),this.paint(),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.drawLauncher(),this.root.append(this.launcher);}drawLauncher(){if(this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.replaceChildren(),this.launcher.append(q(this.settings.launcherContent,this.strings,this.appearance.team,e=>this.client.avatarUrl(e))),this.settings.launcherShape==="pill"){let e=document.createElement("span");e.className="label",e.textContent=this.strings.launcherLabel,this.launcher.append(e);}this.launcher.append(this.badge),this.launcher.classList.toggle("closed",!this.openNow);}update(e,t){this.appearance={...w,...e},this.settings=A(this.appearance),t!==void 0&&(this.scheme=t),this.paint(),this.drawLauncher(),this.panel&&(this.close(),this.open());}paint(){this.styles(`${Y(this.appearance,this.scheme)}${this.kit&&this.appearance.help?this.kit.HELP_CSS:""}${this.filesKit?this.filesKit.filesCss(this.appearance.attachments?.enabled===true,this.settings.composerShape):""}`);}loadKit(){return !this.appearance.help||!this.helpLoader?Promise.resolve(null):(this.kitLoad??(this.kitLoad=this.helpLoader().then(e=>(this.kit=e,this.paint(),e))),this.kitLoad)}loadFiles(){return this.filesLoader?(this.filesLoad??(this.filesLoad=this.filesLoader().then(e=>(this.filesKit=e,this.paint(),e))),this.filesLoad):Promise.resolve(null)}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.openNow=e,this.launcher.classList.toggle("closed",!e),this.panel?.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className=this.openNow?"panel":"panel closed",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let n=document.createElement("span");n.className="grip",n.setAttribute("aria-hidden","true"),t.append(n);let r=this.appearance.team??[];r.length>0&&t.append(H(r,this.strings,b=>this.client.avatarUrl(b)));let a=document.createElement("div");a.className="headmain";let s=document.createElement("h2");s.textContent=this.strings.title;let l=document.createElement("p");l.className="status";let h=document.createElement("span");h.className="live",h.setAttribute("aria-hidden","true"),l.append(h,this.strings.replyTime),a.append(s,l);let u=document.createElement("button");u.className="close",u.type="button",u.setAttribute("aria-label",this.strings.closeLabel),u.innerHTML=qe,u.addEventListener("click",()=>this.close()),t.append(a,u);let d=document.createElement("div");d.className="log",d.setAttribute("role","log"),d.setAttribute("aria-live","polite"),d.setAttribute("aria-label",this.strings.title);let c=document.createElement("form");c.className="composer";let p=document.createElement("input");p.type="text",p.setAttribute("aria-label",this.strings.inputPlaceholder),p.placeholder=this.strings.inputPlaceholder;let m=document.createElement("button");m.type="submit",m.setAttribute("aria-label",this.strings.sendLabel),m.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let C=document.createElement("span");C.className="sendtext",C.textContent=this.strings.sendLabel,m.append(C),c.append(p,m),c.addEventListener("submit",b=>{b.preventDefault(),this.submit(p,d);}),e.append(t,d,c),this.appearance.poweredBy&&e.append(Ce(this.appearance.poweredBy,this.client.avatarUrl("/messenger-mark.png"))),e.addEventListener("keydown",b=>this.onKeydown(b,e,u));let k=document.createElement("div");k.className="scrim",k.addEventListener("click",()=>this.close()),this.root.append(k,e),this.panel=e,this.scrim=k,Ge(e,()=>this.close()),p.focus();let S=this.appearance.attachments,[g,,,x]=await Promise.all([this.client.load(),this.loadKit(),S?.enabled&&this.client.upload?this.loadFiles():null,this.ticketsLoad??(this.ticketsLoad=this.ticketsLoader?.())]);if(g?.turns.some(b=>b.attachments?.length)&&await this.loadFiles(),this.panel!==e)return;this.filesKit&&S?.enabled&&this.client.upload&&this.filesKit.attachField({attachLabel:this.strings.attachLabel,fileRefusal:this.strings.fileRefusal,hold:b=>{this.picked=b;},objectUrl:b=>this.objectUrl(b),removeFileLabel:this.strings.removeFileLabel,root:this.root},c,p,d,S);let v=this.helpHost();v?.placement==="tab"&&v.host.source.collections&&v.host.source.collectionArticles&&v.kit.helpTab(v.host),v?.placement==="while_typing"&&v.kit.whileTyping(v.host,p,c),x&&this.appearance.tickets&&x.ticketsTab(e,this.client,this.appearance.tickets.words),g&&g.turns.length>0?this.renderThread(d,g):this.renderFirstRun(d,p),this.openNow||this.renderAway(t);}renderFirstRun(e,t){let n=document.createElement("div");n.className="empty";let r=document.createElement("h3");r.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle,n.append(r);let a=this.helpHost();if(a?.placement==="first_view")a.kit.firstView(a.host,n);else {let l=document.createElement("p");l.textContent=this.strings.emptyBody,n.append(l);}this.appearance.starterPrompts.filter(Ke).forEach((l,h)=>{let u=document.createElement("div");u.className="prompt";let d=document.createElement("div");d.className="promptwords",d.id=`prompt-${h}`;let c=document.createElement("template");c.innerHTML=l.html,Be(c.content)?d.append(c.content):d.textContent=l.text;for(let m of d.querySelectorAll("a"))m.target="_blank",m.rel="noopener noreferrer";let p=document.createElement("button");p.className="promptpress",p.type="button",p.setAttribute("aria-labelledby",d.id),p.addEventListener("click",()=>{t.value=l.text,this.submit(t,e);}),u.append(d,p),n.append(u);}),e.replaceChildren(n);}helpHost(){let e=this.appearance.help,{kit:t,panel:n}=this,r=e&&t&&n?t.hostOf(this.client,{close:()=>this.close(),closeLabel:this.strings.closeLabel,panel:n,scheme:this.scheme,words:e.words}):null;return r&&t&&e?{host:r,kit:t,placement:e.placement}:null}renderAway(e){let t=document.createElement("div");t.className="away";let n=document.createElement("span");n.className="awayglyph",n.setAttribute("aria-hidden","true");let r=document.createElement("span");r.textContent=this.appearance.awayMessage.trim()||this.strings.awayBody,t.append(n,r),e.after(t);}objectUrl(e){let t=URL.createObjectURL(e);return this.objectUrls.push(t),t}close(){if(this.panel){this.panel.remove(),this.scrim?.remove(),this.panel=null,this.scrim=null,this.picked=null;for(let e of this.objectUrls)URL.revokeObjectURL(e);this.objectUrls=[],this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus();}}onIncomingTurn(e){if(this.panel&&e.attachments?.length&&!this.filesKit&&this.filesLoader){this.loadFiles().then(()=>this.takeTurn(e));return}this.takeTurn(e);}takeTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&!this.hasTurn(t,e.id)&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let n=e.value.trim(),r=this.picked;if(!(!n&&!r)){e.value="",this.picked=null;for(let a of this.root.querySelectorAll(".file,.ferr,.hsugg"))a.remove();await this.sendBody(t,n,r);}}async sendBody(e,t,n=null){e.querySelector(".empty")?.remove(),this.pendingTurns+=1;let r=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`},n);r.setAttribute("data-pending","");let a=n?await this.client.upload?.(n,this.filesKit?.uploadRefusalOf):void 0;if(a&&"refusal"in a){this.filesKit?.markRefused(r,a.refusal,this.appearance.attachments,()=>this.sendBody(e,t,n));return}let s=a===null?null:await this.client.send(t,De(),a?[a.id]:void 0);if(r.removeAttribute("data-pending"),s){r.dataset.turnId=s.id;return}this.markFailed(e,r,t,n);}markFailed(e,t,n,r){t.setAttribute("data-failed","");let a=document.createElement("button");a.type="button",a.className="retry",a.textContent=this.strings.retryLabel,a.addEventListener("click",()=>{t.remove(),this.sendBody(e,n,r);}),(t.querySelector(".body")??t).append(a);}hasTurn(e,t){for(let n of e.children)if(n instanceof HTMLElement&&n.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let n of t.turns)this.appendTurn(e,n);}appendTurn(e,t,n=null){if(e.querySelector(".empty")?.remove(),t.authorKind==="system"){let c=document.createElement("div");return c.className="turn system",c.dataset.turnId=t.id,c.textContent=t.body,e.append(c),c}let r=Oe.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,s=document.createElement("div");if(s.className=`turn ${r}`,s.dataset.turnId=t.id,r!=="end_user"&&a.nameAvatar){let c=document.createElement("span");if(c.className=r==="ai"?"av bot":"av",c.setAttribute("aria-hidden","true"),r==="agent"&&t.authorAvatarUrl){let p=document.createElement("img");p.alt="",p.src=this.client.avatarUrl(t.authorAvatarUrl),c.append(p);}else {c.textContent=r==="ai"?this.strings.aiLabel:O(this.agentName(t));let p=r==="agent"?this.appearance.team?.find(m=>m.name===t.authorName)?.tone:void 0;p&&(c.style.background=p);}s.append(c);}let h=document.createElement("div");if(h.className="body",r==="end_user"){let c=this.filesKit,p=m=>this.objectUrl(m);n&&c?.drawFile(h,n.name,n.type,n.size,Promise.resolve(n),p);for(let m of t.attachments??[])c?.drawFile(h,m.name,m.contentType,m.bytes,this.client.file?.(m.url)??Promise.resolve(null),p);}let u=r!=="end_user"&&a.namePlacement!=="hidden",d=document.createElement("div");if(r==="ai"?Ue(d,t.body):d.textContent=t.body,u||r==="ai"&&a.namePlacement==="hidden"){let c=document.createElement("div");c.className=r==="ai"?"author ai":"author",c.textContent=r==="ai"?this.strings.aiLabel:this.agentName(t),a.stampPlacement==="beside_name"&&c.append(this.stamp(t)),a.namePlacement==="inline"?(c.classList.add("below"),h.append(d,c)):h.append(c,d);}else t.body&&h.append(d);return a.stampPlacement==="under_turn"&&h.append(this.stamp(t)),s.append(h),e.append(s),e.scrollTop=e.scrollHeight,s}agentName(e){return e.authorName||this.strings.agentLabel}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,n){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let r=[...t.querySelectorAll('button, input, a[href], [tabindex]:not([tabindex="-1"])')].filter(h=>!h.closest("[hidden]")&&!h.hidden);if(r.length===0)return;let a=r[0],s=r[r.length-1],l=this.root.activeElement;e.shiftKey&&l===a?(e.preventDefault(),s.focus()):!e.shiftKey&&l===s?(e.preventDefault(),a.focus()):l===null&&(e.preventDefault(),n.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}},je="(max-width: 770px)";function Ge(i,e){let t=null;i.addEventListener("pointerdown",r=>{if(t||r.button!==0||!globalThis.matchMedia?.(je).matches)return;let a=r.target;if(!a?.closest("a, button, input, textarea, iframe")){for(;a&&a!==i;a=a.parentElement)if(a.scrollTop>0)return;t={at:r.timeStamp,id:r.pointerId,offset:0,startY:r.clientY},i.setPointerCapture?.(r.pointerId),i.dataset.dragging="";}}),i.addEventListener("pointermove",r=>{if(t?.id!==r.pointerId)return;let a=r.clientY-t.startY;t.offset=a>=0?a:-16*(1-Math.exp(a/48)),i.style.translate=`0 ${t.offset}px`;});let n=r=>{let a=t;if(a?.id!==r.pointerId)return;t=null,delete i.dataset.dragging;let s=a.offset>Math.min(72,i.getBoundingClientRect().height*.4),l=a.offset/Math.max(1,r.timeStamp-a.at)>.5&&a.offset>16;s||l?e():i.style.translate="";};i.addEventListener("pointerup",n),i.addEventListener("pointercancel",n);}var Ye=i=>{if(typeof CSSStyleSheet=="function"&&"adoptedStyleSheets"in i&&"replaceSync"in CSSStyleSheet.prototype){let t=new CSSStyleSheet;return i.adoptedStyleSheets=[t],n=>t.replaceSync(n)}let e=document.createElement("style");return i.append(e),t=>{e.textContent=t;}};var We="/socket.io/?EIO=4&transport=websocket",F=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??Je,this.setTimer=e.setTimer??((t,n)=>setTimeout(t,n)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${We}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=n=>this.receive(String(n.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=c(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(a$1(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(b$1());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let n=t.payload?.turn;n&&this.options.onTurn(n);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Je(i){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(i)}var Xe=6e4;function yt(i){let e=globalThis.document;if(!e)throw new b("prodantix chat requires a document; mount it in the browser");let t=i.mountPoint??e.createElement("div");i.mountPoint||e.body.append(t);let n=new L(i),r=new E(t,n,i.strings,i.appearance,{files:i.files,help:i.help,tickets:i.tickets}),a=i.appearance?.availability??w.availability,s,l=()=>{r.setOpenNow(P(a,new Date)),s=setTimeout(l,Xe);};l();let h=new Set,u,d=null,c=i.pollIntervalMs??15e3,p=g=>{h.has(g.id)||g.authorKind==="end_user"||(h.add(g.id),r.onIncomingTurn(g));},m=async()=>{if(!n.hasThread)return;let g=await n.load();if(g){for(let x of g.turns)p(x);h=new Set(g.turns.map(x=>x.id));}},C=()=>{u||c<=0||(u=setInterval(()=>void m(),c));},k=()=>{u&&clearInterval(u),u=void 0;},S=()=>{if(d||!i.socketHost)return;let g=n.socketAuth;g&&(d=new F({auth:g,host:i.socketHost,onClosed:x=>{d=null,C(),x&&S();},onReady:k,onTurn:p,socketFactory:i.socketFactory}),d.open());};return C(),S(),{close:()=>r.close(),destroy:()=>{k(),clearTimeout(s),d?.close(),d=null,r.close(),t.remove();},identify:g=>n.identify(g),open:()=>{r.open().then(S);}}}
6
+ export{L as ChatClient,E as ChatPanel,w as DEFAULT_APPEARANCE,f as DEFAULT_APPEARANCE_SETTINGS,yt as mountChat,Y as panelStyles,A as resolveAppearance};//# sourceMappingURL=chat.js.map
9
7
  //# sourceMappingURL=chat.js.map
@@ -0,0 +1,2 @@
1
+ import {c,a as a$2,b as b$2}from'./chunk-V77KYPOF.js';import {e,h,d,f as f$1,g as g$1,a as a$1,b as b$1,c as c$1}from'./chunk-5WTMO52O.js';import {a}from'./chunk-5XGN7UAV.js';var g=class{constructor(){a(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,t){this.store.set(e,t);}},v=class{constructor(e,t=()=>false){this.real=e;this.passes=t;a(this,"held",new g);a(this,"opened",false);}get isOpen(){return this.opened}open(){this.opened=true;}close(){this.opened=false;}target(e){return this.opened||this.passes(e)?this.real:this.held}getItem(e){return this.target(e).getItem(e)}removeItem(e){this.target(e).removeItem(e);}setItem(e,t){this.target(e).setItem(e,t);}};function Ze(){try{let s=globalThis.localStorage;if(s){let e="__pdx_probe__";return s.setItem(e,"1"),s.removeItem(e),s}}catch{return new g}return new g}var Z={now:()=>new Date};function w(s){return s.toISOString()}function ee(){if(typeof window>"u"||typeof Intl>"u")return null;let s=Intl.DateTimeFormat().resolvedOptions().timeZone;return typeof s=="string"&&s!==""?s:null}var Te=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var $e=/^(?:\$|[a-z])[a-z0-9_.]*$/;function te(s){let e=0;for(let t of s)e+=1;return e}function se(s){return Te.test(s)}function Ae(s){return $e.test(s)}function ne(s){let e=te(s);if(e<1||e>200)throw new c$1("distinct_id","distinct_id must be between 1 and 200 characters")}function ie(s){let e=te(s);if(e<1||e>200)throw new c$1("event_name","event_name must be between 1 and 200 characters");if(!Ae(s))throw new c$1("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var re="prodantix-js",oe="0.9.0";function Pe(){return globalThis.crypto}function Re(s){s[6]=s[6]&15|64,s[8]=s[8]&63|128;let e=[];for(let t=0;t<16;t+=1)e.push(s[t].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function Me(){let s=Pe();if(s?.randomUUID)return s.randomUUID();let e=new Uint8Array(16);if(s?.getRandomValues)s.getRandomValues(e);else for(let t=0;t<16;t+=1)e[t]=Math.floor(Math.random()*256);return Re(e)}var ae={uuid:Me};var qe=s=>{};function le(s){if(!s.apiKey||!se(s.apiKey))throw new b$1("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!s.host)throw new b$1("host is required (the ingest base URL)");let e=h(s.host),t=s.defaultProperties,n=s.storage??new g;return {apiKey:s.apiKey,autocapture:s.autocapture??false,clock:s.clock??Z,consent:s.consent,consentMode:s.consentMode,defaultProperties:typeof t=="function"?t:()=>t??{},describeElement:s.describeElement,flagsHost:s.flagsHost?h(s.flagsHost):e,flushAt:s.flushAt??20,flushIntervalMs:s.flushIntervalMs??1e4,host:e,ids:s.ids??ae,locale:s.locale,maxQueueSize:s.maxQueueSize??1e3,maxRetries:s.maxRetries??3,namespace:Ke(s.apiKey),onError:s.onError??qe,os:s.os,requestTimeoutMs:s.requestTimeoutMs??1e4,sdkName:s.sdkName??re,sdkVersion:s.sdkVersion??oe,sessionTracking:s.sessionTracking??false,sharedStorage:s.sharedStorage??n,socketFactory:s.socketFactory,storage:n,streamFlags:s.streamFlags??false,transport:s.transport}}function Ke(s){return s.slice(0,16)}var y=Symbol("absent");function Oe(s,e){if(s==="distinct_id")return e.distinctId;let t=e.properties??{};if(Object.prototype.hasOwnProperty.call(t,s))return t[s];let n=e.attributes??{};return Object.prototype.hasOwnProperty.call(n,s)?n[s]:y}function f(s){return s===y?"undefined":String(s)}function ce(s){return s===y?Number.NaN:Number(s)}function ue(s){return s!==y&&s!==null&&s!==""}function de(s,e){if(!Array.isArray(e))return false;let t=f(s);return e.map(n=>String(n)).includes(t)}function pe(s,e){let t=Oe(s.attribute,e),n=s.value;switch(s.op){case "is_set":return ue(t);case "is_not_set":return !ue(t);case "eq":return f(t)===f(n===void 0?y:n);case "neq":return f(t)!==f(n===void 0?y:n);case "contains":return f(t).includes(f(n===void 0?y:n));case "in":return de(t,n);case "not_in":return Array.isArray(n)?!de(t,n):false;case "gt":return _(t,n,(i,r)=>i>r);case "gte":return _(t,n,(i,r)=>i>=r);case "lt":return _(t,n,(i,r)=>i<r);case "lte":return _(t,n,(i,r)=>i<=r);case "in_cohort":return typeof n=="string"&&n!==""&&(e.cohorts??[]).includes(n);case "not_in_cohort":return typeof n=="string"&&n!==""&&!(e.cohorts??[]).includes(n);default:return false}}function _(s,e,t){let n=ce(s),i=e===void 0?Number.NaN:ce(e);return Number.isNaN(n)||Number.isNaN(i)?false:t(n,i)}function he(s,e){let t=`${s}:${e}`,n=2166136261;for(let i=0;i<t.length;i++)n^=t.charCodeAt(i),n=Math.imul(n,16777619);return (n>>>0)%100}function N(s,e){return s.targeting.length===0||s.targeting.every(t=>pe(t,e))}function me(s,e){let t=he(s.key,e.distinctId),n=s.variations??[];if(n.length===0)return s.rolloutPercentage>=100||t<s.rolloutPercentage?"true":"false";let i=0;for(let r=n.length-1;r>=0;r--)if(i+=n[r].weight,t<i)return n[r].key;return n[0].key}function j(s,e,t,n){for(let i of s.prerequisites??[]){if(n.includes(i.flagKey))return false;let r=e.find(c=>c.key===i.flagKey);if(!r||!r.enabled)return false;n.push(r.key);let a=j(r,e,t,n)&&N(r,t)&&me(r,t)===i.variationKey;if(n.pop(),!a)return false}return true}function b(s,e,t){return s.enabled?j(s,e,t,[s.key])?N(s,t)?s.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:he(s.key,t.distinctId)<s.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function yt(s,e){return b(s,[],e)}function ge(s,e){let t={};for(let n of s)t[n.key]=b(n,s,e).enabled;return t}function S(s,e,t){let n=s.variations??[],i=n[0];if(!i)return null;if(!s.enabled||!j(s,e,t,[s.key])||!N(s,t))return i;let r=me(s,t);return n.find(a=>a.key===r)??i}function vt(s,e){return S(s,[],e)}function bt(s,e,t){let n=s.find(i=>i.key===e);return n?S(n,s,t)?.value??null:null}function fe(s){return s.some(e=>e.targeting.some(t=>t.op==="in_cohort"||t.op==="not_in_cohort"))}var F=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`flags request failed with status ${a.status}`,a.status);let c=JSON.parse(await a.text());return {flags:c.flags??{},variants:c.variants??{}}}finally{r!==void 0&&clearTimeout(r);}}async snapshot(){let e=this.fetch;if(!e)throw new d("no fetch implementation available in this runtime");let t=`${this.host}/v1/flags/snapshot`,n=f$1(),i=n?setTimeout(()=>n.abort(),this.requestTimeoutMs):void 0;try{let r=await e(t,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:n?.signal});if(!r.ok)throw new d(`flag snapshot request failed with status ${r.status}`,r.status);let a=JSON.parse(await r.text()),c={flags:a.flags??[],generatedAt:a.generatedAt};return typeof a.socketUrl=="string"&&a.socketUrl!==""&&(c.socketUrl=a.socketUrl),c}finally{i!==void 0&&clearTimeout(i);}}async memberships(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(n,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`memberships request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).cohorts??[]}finally{r!==void 0&&clearTimeout(r);}}};var ye="$survey_shown",ve="$survey_dismissed",be="$survey_sent",C=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async surveys(e,t){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await n(`${this.host}/v1/surveys?distinct_id=${encodeURIComponent(e)}${t?`&lang=${encodeURIComponent(t)}`:""}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(!a.ok)throw new d(`surveys request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).surveys??[]}finally{r!==void 0&&clearTimeout(r);}}},De=864e5,Le=s=>`${s.id}:${s.iteration}`;function V(s,e){return s.length===0?true:s.some(t=>{switch(t.matches){case "exact":return e===t.value;case "starts_with":return e.startsWith(t.value);default:return e.includes(t.value)}})}function It(s,e,t,n,i){return s.kind!=="popover"||e.settled.includes(Le(s))||s.showOnce&&e.settled.some(r=>r.startsWith(`${s.id}:`))||s.waitDays>0&&e.lastShownAt!==void 0&&n-e.lastShownAt<s.waitDays*De||s.event&&s.event!==i?false:V(s.urls,t)}function Ne(s,e,t){return s>=(e.minScore??0)&&s<=(e.maxScore??t)}function Et(s,e,t){let n=e.kind==="nps"?10:e.scale??5,i=e.branches.find(a=>a.choice!=null?t===a.choice:typeof t=="number"&&Ne(t,a,n));if(i)return i.next??null;let r=s.questions.findIndex(a=>a.id===e.id);return s.questions[r+1]?.id??null}function I(s,e){let t={$survey_id:s.id,$survey_iteration:s.iteration,$survey_name:s.name};for(let[n,i]of Object.entries(e))t[`$survey_response_${n}`]=i;return t}var Mt="$guide_shown",qt="$guide_step_viewed",Kt="$guide_step_missed",Ot="$guide_completed",Dt="$guide_dismissed",Lt="$checklist_task_done",E=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async guides(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=f$1(),i=n?setTimeout(()=>n.abort(),this.requestTimeoutMs):void 0;try{let r=await t(`${this.host}/v1/guides?distinct_id=${encodeURIComponent(e)}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:n?.signal});if(!r.ok)throw new d(`guides request failed with status ${r.status}`,r.status);return JSON.parse(await r.text()).guides??[]}finally{i!==void 0&&clearTimeout(i);}}},je=864e5,Se=s=>`${s.id}:${s.iteration}`,Ve=(s,e)=>`${Se(s)}:${e}`;function Nt(s,e,t,n,i){return e.settled.includes(Se(s))||s.showOnce&&e.settled.some(r=>r.startsWith(`${s.id}:`))||s.kind!=="checklist"&&s.waitDays>0&&e.lastShownAt!==void 0&&n-e.lastShownAt<s.waitDays*je||s.event&&s.event!==i?false:V(s.urls,t)}var jt=(s,e)=>s.steps.filter(t=>e.done.includes(Ve(s,t.id))).map(t=>t.id),Vt=(s,e)=>s.kind==="checklist"?s.steps.find(t=>t.event===e):void 0;function ke(s,e){let t={$guide_id:s.id,$guide_iteration:s.iteration,$guide_name:s.name};return e!==void 0&&(t.$guide_step_id=e),t}function k(s){if(typeof s!="string")return;let e=Array.from(s).length;return e>=1&&e<=200?s:void 0}function $(s,e){return `pdx.${s}.${e}`}var U="consent",Ge=["identityLink","analytics","marketing","functional"];function G(s){if(typeof s!="string")return null;try{let e=JSON.parse(s);if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=e,n={};for(let i of Ge){let r=t[i];typeof r=="boolean"&&(n[i]=r);}return typeof t.version=="number"&&Number.isInteger(t.version)&&(n.version=t.version),Array.isArray(t.categories)&&t.categories.every(i=>typeof i=="string")&&(n.categories=t.categories),Object.keys(n).length===0?null:n}catch{return null}}var xe=s=>s.endsWith(`.${U}`);function A(s,e){return G(s.getItem($(e,U)))}function Ue(s,e,t){let n=$(e,U),i=G(JSON.stringify(t)),r=i===null?null:G(JSON.stringify({...A(s,e)??{},...i}));if(r===null){s.removeItem(n);return}s.setItem(n,JSON.stringify(r));}function Bt(s,e,t,n){let i=$(t,"anonymous_id"),r=k(e.getItem(i))??k(s.getItem(i));return e.setItem(i,n),s.setItem(i,n),r!==void 0&&r!==n?r:void 0}var T=class{constructor(e,t,n,i){this.storage=e;this.shared=t;this.ids=n;this.namespace=i;a(this,"anonymousId");a(this,"distinctId");a(this,"identified");this.refresh();}refresh(){let e=k(this.shared.getItem(this.key("anonymous_id"))),t=k(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,t!==e&&this.storage.setItem(this.key("anonymous_id"),e)):t?(this.anonymousId=t,this.shared.setItem(this.key("anonymous_id"),t)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let n=k(this.storage.getItem(this.key("distinct_id")));n?(this.distinctId=n,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return A(this.shared,this.namespace)}setConsent(e){Ue(this.shared,this.namespace,e);}assumeAnonymousId(e){this.anonymousId=e,this.shared.setItem(this.key("anonymous_id"),e),this.storage.setItem(this.key("anonymous_id"),e),this.identified||(this.distinctId=e);}identify(e){let t=!this.identified||this.distinctId!==e,n=this.storage.getItem(this.key("linked_anonymous_id")),i=t||n!==this.anonymousId;return this.distinctId=e,this.identified=true,t&&this.storage.setItem(this.key("distinct_id"),e),!i||this.consent()?.identityLink===false?{changed:t}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:t})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return $(this.namespace,e)}};var P=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async inbox(e){let t=this.requireFetch(),n=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,i=await this.request(t,n,{headers:this.authHeaders(),method:"GET"});if(!i.ok)throw new d(`inbox request failed with status ${i.status}`,i.status);return JSON.parse(await i.text()).messages??[]}async markRead(e,t){let n=this.requireFetch(),i=`${this.host}/v1/messages/read`,r=await this.request(n,i,{body:JSON.stringify({distinct_id:t,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!r.ok)throw new d(`mark-read request failed with status ${r.status}`,r.status)}requireFetch(){if(!this.fetch)throw new d("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,t,n){let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{return await e(t,{...n,signal:i?.signal})}finally{r!==void 0&&clearTimeout(r);}}};var u={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageleave:"$pageleave",pageview:"$pageview",screen:"$screen",set:"$set",webVitals:"$web_vitals"},Be=[{emittedBy:"web_and_flutter",meaning:"A click anywhere on the page, with the element that was clicked. The web SDK sends it by default; autocapture: false or autocaptureOptions.clicks: false turns it off. A Flutter app sends each tap as this event too, under TelemetryTapCapture.",name:u.autocapture,properties:["$event_type","$el_description","$el_description_source","$el_action","$el_tag","$el_text","$el_id","$el_classes","$el_href","$current_url","$pathname","$host","$title","$referrer","$screen_name"]},{emittedBy:"web",meaning:"A page shown, including every client-side navigation the History API makes: one per distinct path and query.",name:u.pageview,properties:["$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"web",meaning:"A landing page left the visitor's sight, by a tab switch, a closed tab or a navigation away, with the seconds it was in front of them so far. A page returned to and left again sends it again with the larger total.",name:u.pageleave,properties:["$engaged_seconds","$page_id","$page_view_id","$page_variant"]},{emittedBy:"web",meaning:"A page's Core Web Vitals, sent once per page load the first time the page leaves the visitor's sight: largest contentful paint, first contentful paint, cumulative layout shift, interaction to next paint and time to first byte, each only when the browser measured it. autocaptureOptions.webVitals: false turns it off.",name:u.webVitals,properties:["$lcp_ms","$fcp_ms","$cls","$inp_ms","$ttfb_ms","$pathname"]},{emittedBy:"flutter",meaning:"A named route pushed or replaced in a Flutter app, the mobile counterpart of $pageview.",name:u.screen,properties:["screen"]},{emittedBy:"every",meaning:"A person becomes known by a distinct id. The anonymous trail before it is joined to them, and any traits ride along under $set.",name:u.identify,properties:["$anon_distinct_id","$set"]},{emittedBy:"every",meaning:"A second id for the same person, so events sent under either resolve to one profile.",name:u.createAlias,properties:["alias"]},{emittedBy:"every",meaning:"The person is placed in a group such as a company or a team; group properties ride along under $set.",name:u.group,properties:["$group_type","$group_key","$set"]},{emittedBy:"every",meaning:"Person properties written without an identify: $set overwrites, $set_once fills only what is still empty.",name:u.set,properties:["$set","$set_once"]},{emittedBy:"every",meaning:"A flag was evaluated for this person, sent once per distinct answer. Experiments attribute exposure from it.",name:u.featureFlagCalled,properties:["$feature_flag","$feature_flag_response"]}],Xt=s=>s.startsWith("$"),Zt=s=>Be.find(e=>e.name===s);var we=6e4;function He(s){return s.length*3<=we||new TextEncoder().encode(s).length<=we}function _e(s){return s>=400&&s<500&&s!==429}var R=class{constructor(e$1={}){a(this,"fetch");a(this,"maxRetries");a(this,"requestTimeoutMs");a(this,"baseDelayMs");a(this,"maxDelayMs");a(this,"sleep");a(this,"random");this.fetch=e(e$1.fetch),this.maxRetries=e$1.maxRetries??3,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4,this.baseDelayMs=e$1.baseDelayMs??500,this.maxDelayMs=e$1.maxDelayMs??3e4,this.sleep=e$1.sleep??g$1,this.random=e$1.random??Math.random;}async send(e,t={}){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let i=JSON.stringify(e.body),r=t.keepalive===true&&He(i),a;for(let c=0;c<=this.maxRetries;c+=1){try{let h=await this.attempt(n,e,i,r);if(h.ok)return;if(_e(h.status))throw new d(`ingest rejected batch with status ${h.status}`,h.status);a=new d(`ingest transient status ${h.status}`,h.status);}catch(h){if(h instanceof d&&h.status!==void 0&&_e(h.status))throw h;a=h;}c<this.maxRetries&&await this.sleep(this.backoff(c));}throw new d("ingest delivery failed after retries",void 0,{cause:a})}async attempt(e,t,n,i){let r=f$1(),a=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{return await e(t.url,{body:n,headers:{authorization:`Bearer ${t.projectKey}`,"content-type":"application/json"},...i?{keepalive:!0}:{},method:"POST",signal:r?.signal})}finally{a!==void 0&&clearTimeout(a);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};var as="$cta_viewed",ls="$cta_clicked",cs="$cta_dismissed",Fe=(s,e)=>{let t={$cta_id:s.id,$cta_kind:s.kind,$cta_variant:s.variant.key,$cta_version:s.version},n=e===void 0?void 0:s.variant.content.buttons[e];return n&&e!==void 0&&(t.$cta_button=e,t.$cta_button_label=n.label,n.action.kind==="form"&&(t.$cta_form_id=n.action.value)),t},M=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async ctas(e){let t=this.fetch;if(!t)throw new d("no fetch implementation available in this runtime");let n=new URLSearchParams({anonymous:String(e.anonymous),device:e.device,distinct_id:e.distinctId,language:e.language,url:e.url}),i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a=await t(`${this.host}/v1/ctas?${n.toString()}`,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:i?.signal});if(a.status<200||a.status>=300)throw new d(`ctas request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).ctas}finally{r!==void 0&&clearTimeout(r);}}};function Ce(s,e,t){ie(s.eventName),ne(s.distinctId);let n={distinct_id:s.distinctId,event_id:s.eventId??t.uuid(),event_name:s.eventName,properties:s.properties??{},schema_version:1,timestamp:w(s.timestamp??e.now())};return s.context&&(n.context=s.context),s.sessionId&&(n.session_id=s.sessionId),n}var Je="/socket.io/?EIO=4&transport=websocket",ze=250,q=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"pending",null);a(this,"lastKey","");a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??Qe,this.setTimer=e.setTimer??((t,n)=>setTimeout(t,n)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Je}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=n=>this.receive(String(n.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let t=c(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(a$2({projectKey:this.options.projectKey}));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(b$2());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true;return}if(t.name==="flagChange"){let n=t.payload?.key;this.lastKey=typeof n=="string"?n:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},ze));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Qe(s){let e=globalThis.WebSocket;if(!e)throw new d("no WebSocket");return new e(s)}var ks="$form_viewed",xs="$form_started",B=class extends Error{constructor(t,n,i){super(i);a(this,"fields");a(this,"status");this.name="FormRefusedError",this.status=t,this.fields=n;}},K=class{constructor(e$1){a(this,"fetch");a(this,"host");a(this,"projectKey");a(this,"requestTimeoutMs");this.fetch=e(e$1.fetch),this.host=h(e$1.host),this.projectKey=e$1.projectKey,this.requestTimeoutMs=e$1.requestTimeoutMs??1e4;}async request(e,t){let n=this.fetch;if(!n)throw new d("no fetch implementation available in this runtime");let i=f$1(),r=i?setTimeout(()=>i.abort(),this.requestTimeoutMs):void 0;try{let a={authorization:`Bearer ${this.projectKey}`};t.body!==void 0&&(a["content-type"]="application/json");let c=await n(`${this.host}${e}`,{body:t.body,headers:a,method:t.method,signal:i?.signal});return {status:c.status,text:await c.text()}}finally{r!==void 0&&clearTimeout(r);}}async form(e,t){let{status:n,text:i}=await this.request(`/v1/forms/${encodeURIComponent(e)}?distinct_id=${encodeURIComponent(t)}`,{method:"GET"});if(n<200||n>=300)throw new d(`form request failed with status ${n}`,n);return JSON.parse(i)}async submit(e,t){let{status:n,text:i}=await this.request(`/v1/forms/${encodeURIComponent(e)}/submissions`,{body:JSON.stringify(t),method:"POST"});if(n>=200&&n<300)return JSON.parse(i).afterSubmit;let r=[],a=`form submission failed with status ${n}`;try{let c=JSON.parse(i);r=c.error?.fields??[],a=c.error?.message??a;}catch{r=[];}throw new B(n,r,a)}};var O=class{constructor(e,t){this.maxSize=e;this.onOverflow=t;a(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let t=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,t)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var We={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function Ie(s){return `pdx.${s}.session`}function Is(s,e,t,n){let i={id:t.id,lastActivityAt:n,startedAt:t.startedAt};s.setItem(Ie(e),JSON.stringify(i));}var D=class{constructor(e,t,n,i,r=We){this.storage=e;this.ids=t;this.clock=n;this.namespace=i;this.options=r;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),t=this.live(this.read(),e);if(t===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-t.lastActivityAt<=this.options.throttleMs)return t;let n=this.live(this.read(),e),i=n!==void 0&&n.id!==t.id?n:t;return this.write({...i,lastActivityAt:e})}live(e,t){if(e!==void 0&&!(t-e.lastActivityAt>this.options.idleMs||t-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let t=JSON.parse(e);return typeof t.id=="string"&&typeof t.startedAt=="number"&&typeof t.lastActivityAt=="number"?{id:t.id,lastActivityAt:t.lastActivityAt,startedAt:t.startedAt}:void 0}catch{return}}key(){return Ie(this.namespace)}};var Ye="queue",Xe=1e3,Ee=3e4,H=s=>{let e={};return s.avatar!==void 0&&(e.$avatar=s.avatar),s.email!==void 0&&(e.$email=s.email),s.name!==void 0&&(e.$name=s.name),s.phone!==void 0&&(e.$phone=s.phone),e},J=class{constructor(e){a(this,"config");a(this,"identity");a(this,"session");a(this,"queue");a(this,"transport");a(this,"flagsClient");a(this,"messagesClient");a(this,"surveysClient");a(this,"guidesClient");a(this,"captureListeners",new Set);a(this,"formsClient");a(this,"ctasClient");a(this,"context");a(this,"flushTimer");a(this,"flushing",false);a(this,"cachedFlags");a(this,"cachedSnapshot");a(this,"membershipCache");a(this,"stream");a(this,"shutDown",false);a(this,"exposures",new Set);a(this,"gates");a(this,"cookielessId");a(this,"storageListeners",new Set);let t=le(e),n=A(t.sharedStorage,t.namespace)??t.consent??null;if(this.gates=[new v(t.storage),new v(t.sharedStorage,xe)],t.consentMode!=="banner"||n?.analytics===true)for(let a of this.gates)a.open();let[i,r]=this.gates;this.config={...t,sharedStorage:r,storage:i},this.identity=new T(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new D(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new O(this.config.maxQueueSize,({dropped:a})=>{this.config.onError(new a$1("queue_overflow",`event queue overflow: dropped ${a.length} oldest event(s)`));}),this.transport=this.config.transport??new R({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new F({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new P({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.surveysClient=new C({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.guidesClient=new E({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.formsClient=new K({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.ctasClient=new M({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,t={}){try{this.identity.refresh();let n={...this.config.defaultProperties(),...t.element===void 0?{}:this.config.describeElement?.(t.element)??{},...t.properties??{}},i=Ce({context:this.context,distinctId:t.distinctId??this.identity.getDistinctId(),eventName:e,properties:n,sessionId:t.sessionId??this.session?.current(),timestamp:t.timestamp},this.config.clock,this.config.ids);this.enqueue(i);}catch(n){this.config.onError(n);}for(let n of this.captureListeners)try{n(e);}catch(i){this.config.onError(i);}}onCapture(e){return this.captureListeners.add(e),()=>{this.captureListeners.delete(e);}}identify(e,t={}){if(this.isCookieless())return;this.identity.refresh();let n=this.identity.identify(e),i={};n.anonymousToLink!==void 0&&(i.$anon_distinct_id=n.anonymousToLink);let r=ee(),a={...r===null?{}:{$timezone:r},...H(t.traits??{}),...t.set??{}};Object.keys(a).length>0&&(i.$set=a),this.capture(u.identify,{properties:i});}link(e,t,n){if(this.isCookieless())return;let i={$anon_distinct_id:t},r=H(n??{});Object.keys(r).length>0&&(i.$set=r),this.capture(u.identify,{distinctId:e,properties:i});}setConsent(e){this.identity.setConsent(e),e.analytics===true&&this.allowStorage(),e.analytics===false&&this.config.consentMode==="banner"&&this.forbidStorage();}isCookieless(){return !this.gates[0].isOpen}takeCookielessId(e){this.cookielessId=e,this.isCookieless()&&this.identity.assumeAnonymousId(e);}allowStorage(){if(this.isCookieless()){for(let e of this.gates)e.open();this.identity.refresh();for(let e of [...this.storageListeners])e();}}onStorageAllowed(e){return this.storageListeners.add(e),()=>{this.storageListeners.delete(e);}}forbidStorage(){if(!this.isCookieless()){for(let e of ["anonymous_id","distinct_id","linked_anonymous_id","session"])this.config.storage.removeItem(`pdx.${this.config.namespace}.${e}`),this.config.sharedStorage.removeItem(`pdx.${this.config.namespace}.${e}`);for(let e of this.gates)e.close();this.identity.refresh(),this.cookielessId!==void 0&&this.identity.assumeAnonymousId(this.cookielessId);}}consent(){return this.identity.consent()}alias(e){this.capture(u.createAlias,{properties:{alias:e}});}group(e,t,n){let i={$group_key:t,$group_type:e};n&&(i.$set=n),this.capture(u.group,{properties:i});}setPersonProperties(e,t){if(this.isCookieless())return;let n={};e&&(n.$set=e),t&&(n.$set_once=t),this.capture(u.set,{properties:n});}setPersonTraits(e){if(this.isCookieless())return;let t=H(e);Object.keys(t).length!==0&&this.capture(u.set,{properties:{$set:t}});}async getAllFlags(){let e=this.identity.getDistinctId(),t=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:t.flags,variants:t.variants??{}},t.flags}async isFeatureEnabled(e){let n=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(n)),n}async getVariant(e){let t=await this.getAllFlags(),n=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,n?.key??String(t[e]??false)),n}async getVariantLocal(e,t={}){let n=await this.flagSnapshot(),i=n.flags.find(h=>h.key===e),r=await this.localContext(t,n.flags),a=i?S(i,n.flags,r):null,c=i?b(i,n.flags,r).enabled:false;return this.recordExposure(e,a?.key??String(c)),a?{key:a.key,value:a.value}:null}recordExposure(e,t){let n=`${this.identity.getDistinctId()} ${e} ${t}`;this.exposures.has(n)||(this.exposures.add(n),this.capture(u.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:t}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let t=await this.flagSnapshot();return ge(t.flags,await this.localContext(e,t.flags))}async isFeatureEnabledLocal(e,t={}){let n=await this.flagSnapshot(),i=n.flags.find(c=>c.key===e),r=await this.localContext(t,n.flags),a=i?b(i,n.flags,r).enabled:false;return this.recordExposure(e,(i?S(i,n.flags,r)?.key:void 0)??String(a)),a}async localContext(e,t){let n=this.identity.getDistinctId(),i=e.cohorts;if(i===void 0&&fe(t)){let r=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===n&&r-this.membershipCache.fetchedAt<Ee?i=this.membershipCache.cohorts:(i=await this.flagsClient.memberships(n),this.membershipCache={cohorts:i,distinctId:n,fetchedAt:r});}return {attributes:e.attributes,cohorts:i,distinctId:n,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<Ee)return this.cachedSnapshot.snapshot;let t=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:t},this.maybeStream(t),t}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let t=new q({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(n=>this.config.onError(n));},onClosed:n=>{this.stream=void 0,n&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=t,t.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async getSurveys(e){return this.surveysClient.surveys(this.identity.getDistinctId(),e??this.config.locale)}captureSurveyShown(e){this.capture(ye,{properties:I(e,{})});}captureSurveyDismissed(e){this.capture(ve,{properties:I(e,{})});}captureSurveySent(e,t){this.capture(be,{properties:I(e,t)});}async getGuides(){return this.guidesClient.guides(this.identity.getDistinctId())}captureGuide(e,t,n){this.capture(e,{properties:ke(t,n)});}async getForm(e){return this.formsClient.form(e,this.identity.getDistinctId())}async submitForm(e,t,n,i){let{$page_id:r,$page_variant:a}=this.config.defaultProperties();return this.formsClient.submit(e,{answers:t,challenge:n,distinctId:this.identity.getDistinctId(),isAnonymous:!this.identity.isIdentified(),pageUrl:typeof window>"u"?"":window.location.href,solution:i,...typeof r=="string"&&typeof a=="string"?{pageId:r,pageVariant:a}:{}})}async getCtas(e){return this.ctasClient.ctas({...e,anonymous:!this.identity.isIdentified(),distinctId:this.identity.getDistinctId()})}captureCta(e,t,n){this.capture(e,{properties:Fe(t,n)});}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(Xe);try{await this.transport.send({body:{events:e,sent_at:w(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(t){this.queue.requeue(e),this.persistQueue(),this.config.onError(t);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let t=JSON.parse(e);Array.isArray(t)&&this.queue.restore(t);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),t=e;typeof t.unref=="function"&&t.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Ye}`}};function Js(s){return new J(s)}export{Js as $,V as A,It as B,Et as C,I as D,Mt as E,qt as F,Kt as G,Ot as H,Dt as I,Lt as J,E as K,Se as L,Ve as M,Nt as N,jt as O,Vt as P,ke as Q,G as R,Bt as S,P as T,Is as U,u as V,Be as W,Xt as X,Zt as Y,R as Z,J as _,g as a,Ze as b,Z as c,Me as d,te as e,re as f,oe as g,Ke as h,as as i,ls as j,cs as k,pe as l,he as m,yt as n,ge as o,vt as p,bt as q,F as r,ks as s,xs as t,B as u,ye as v,ve as w,be as x,C as y,Le as z};//# sourceMappingURL=chunk-3S3BR7QH.js.map
2
+ //# sourceMappingURL=chunk-3S3BR7QH.js.map
@@ -1,2 +1,2 @@
1
- import {a as a$1}from'./chunk-5XGN7UAV.js';var n=class extends Error{constructor(r,o,i){super(o,i);a$1(this,"code");this.code=r,this.name="ProdantixError";}},a=class extends n{constructor(t){super("config",t),this.name="ConfigError";}},l=class extends n{constructor(r,o){super("validation",o);a$1(this,"field");this.field=r,this.name="ValidationError";}},c=class extends n{constructor(r,o,i){super("transport",r,i);a$1(this,"status");this.status=o,this.name="TransportError";}};function p(e){if(e)return e;let t=globalThis.fetch;if(typeof t=="function")return t.bind(globalThis)}function h(){let e=globalThis.AbortController;return e?new e:void 0}var g=e=>new Promise(t=>{setTimeout(t,e);});function f(e){return e.replace(/\/+$/,"")}export{n as a,a as b,l as c,c as d,p as e,h as f,g,f as h};//# sourceMappingURL=chunk-ODN4ZELX.js.map
2
- //# sourceMappingURL=chunk-ODN4ZELX.js.map
1
+ import {a as a$1}from'./chunk-5XGN7UAV.js';var n=class extends Error{constructor(r,o,i){super(o,i);a$1(this,"code");this.code=r,this.name="ProdantixError";}},a=class extends n{constructor(t){super("config",t),this.name="ConfigError";}},l=class extends n{constructor(r,o){super("validation",o);a$1(this,"field");this.field=r,this.name="ValidationError";}},c=class extends n{constructor(r,o,i){super("transport",r,i);a$1(this,"status");this.status=o,this.name="TransportError";}};function p(e){if(e)return e;let t=globalThis.fetch;if(typeof t=="function")return t.bind(globalThis)}function h(){let e=globalThis.AbortController;return e?new e:void 0}var g=e=>new Promise(t=>{setTimeout(t,e);});function f(e){return e.replace(/\/+$/,"")}export{n as a,a as b,l as c,c as d,p as e,h as f,g,f as h};//# sourceMappingURL=chunk-5WTMO52O.js.map
2
+ //# sourceMappingURL=chunk-5WTMO52O.js.map
@@ -1,4 +1,4 @@
1
- import { F as FetchLike } from './http-BCh716Vs.cjs';
1
+ import { F as FetchLike } from './http-CAOViYSh.cjs';
2
2
  import { e as EventProperties, P as ProdantixConfig, b as Consent, f as FlagVariant, I as InboxMessage } from './types-BUXFV_aE.cjs';
3
3
 
4
4
  type CtaKind = 'banner' | 'embedded' | 'popup' | 'slide_in';
@@ -1,4 +1,4 @@
1
- import { F as FetchLike } from './http-BCh716Vs.js';
1
+ import { F as FetchLike } from './http-CAOViYSh.js';
2
2
  import { e as EventProperties, P as ProdantixConfig, b as Consent, f as FlagVariant, I as InboxMessage } from './types-BUXFV_aE.js';
3
3
 
4
4
  type CtaKind = 'banner' | 'embedded' | 'popup' | 'slide_in';
@@ -1,4 +1,4 @@
1
- import { F as FetchLike } from './http-BCh716Vs.cjs';
1
+ import { F as FetchLike } from './http-CAOViYSh.cjs';
2
2
 
3
3
  interface ChatTurn {
4
4
  id: string;
@@ -171,6 +171,9 @@ interface MessengerConfig extends AppearanceSettings {
171
171
  launcherOffsetX: number;
172
172
  launcherOffsetY: number;
173
173
  accentColor: string;
174
+ onAccent?: string;
175
+ accentInk?: string;
176
+ accentInkDark?: string;
174
177
  greeting: string;
175
178
  awayMessage: string;
176
179
  availability: Availability;
@@ -221,6 +224,12 @@ interface TicketWords {
221
224
  reply: string;
222
225
  back: string;
223
226
  failed: string;
227
+ /** "Updated {when}", the time line of an open ticket. */
228
+ updated: string;
229
+ /** "We asked a question {when}", the time line of a ticket waiting on the visitor. */
230
+ asked: string;
231
+ /** "Closed on {date}", the time line of a resolved ticket. */
232
+ closed: string;
224
233
  }
225
234
  interface MessengerTickets {
226
235
  words: TicketWords;
@@ -1,4 +1,4 @@
1
- import { F as FetchLike } from './http-BCh716Vs.js';
1
+ import { F as FetchLike } from './http-CAOViYSh.js';
2
2
 
3
3
  interface ChatTurn {
4
4
  id: string;
@@ -171,6 +171,9 @@ interface MessengerConfig extends AppearanceSettings {
171
171
  launcherOffsetX: number;
172
172
  launcherOffsetY: number;
173
173
  accentColor: string;
174
+ onAccent?: string;
175
+ accentInk?: string;
176
+ accentInkDark?: string;
174
177
  greeting: string;
175
178
  awayMessage: string;
176
179
  availability: Availability;
@@ -221,6 +224,12 @@ interface TicketWords {
221
224
  reply: string;
222
225
  back: string;
223
226
  failed: string;
227
+ /** "Updated {when}", the time line of an open ticket. */
228
+ updated: string;
229
+ /** "We asked a question {when}", the time line of a ticket waiting on the visitor. */
230
+ asked: string;
231
+ /** "Closed on {date}", the time line of a resolved ticket. */
232
+ closed: string;
224
233
  }
225
234
  interface MessengerTickets {
226
235
  words: TicketWords;
@@ -1,20 +1,51 @@
1
- (function(){'use strict';var gt=Object.defineProperty;var mt=(t,e,n)=>e in t?gt(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var b=(t,e,n)=>mt(t,typeof e!="symbol"?e+"":e,n);var L=class extends Error{constructor(n,r,o){super(r,o);b(this,"code");this.code=n,this.name="ProdantixError";}};var C=class extends L{constructor(n,r,o){super("transport",n,o);b(this,"status");this.status=r,this.name="TransportError";}};function U(t){let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}var E=class{constructor(){b(this,"store",new Map);}getItem(e){var n;return (n=this.store.get(e))!=null?n:null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function M(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch(t){return new E}return new E}function yt(){return globalThis.crypto}function ht(t){t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=[];for(let n=0;n<16;n+=1)e.push(t[n].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function ft(){let t=yt();if(t!=null&&t.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t!=null&&t.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return ht(e)}var J={uuid:ft};function V(t){return t.slice(0,16)}function F(t,e){return `pdx.${t}.${e}`}var z="consent",xt=["identityLink","analytics","marketing","functional"];function N(t){if(typeof t!="string")return null;try{let e=JSON.parse(t);if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e,r={};for(let o of xt){let i=n[o];typeof i=="boolean"&&(r[o]=i);}return typeof n.version=="number"&&Number.isInteger(n.version)&&(r.version=n.version),Array.isArray(n.categories)&&n.categories.every(o=>typeof o=="string")&&(r.categories=n.categories),Object.keys(r).length===0?null:r}catch(e){return null}}var P=t=>F(t,"anonymous_id");function R(t,e){return N(t.getItem(F(e,z)))}function W(t,e,n){var s;let r=F(e,z),o=N(JSON.stringify(n)),i=o===null?null:N(JSON.stringify({...(s=R(t,e))!=null?s:{},...o}));if(i===null){t.removeItem(r);return}t.setItem(r,JSON.stringify(i));}var k=["analytics","marketing","functional"],G="prodantix:consent-ready",q="prodantix:consent",Y="__prodantixConsent",X=(t,e)=>{var r;if(t===null||t.version===void 0)return true;let n=(r=t.categories)!=null?r:[];return e.categories.some(o=>!n.includes(o))},Q=(t,e)=>({analytics:t.categories.includes("analytics")&&e.has("analytics"),categories:[...t.categories],functional:t.categories.includes("functional")&&e.has("functional"),marketing:t.categories.includes("marketing")&&e.has("marketing"),version:t.version}),B=t=>new Set(k.filter(e=>(t==null?void 0:t[e])===true));var Z="prodantix-consent-style",bt=`
2
- .pdx-consent{position:fixed;z-index:2147483000;left:0;right:0;box-sizing:border-box;padding:16px;font:14px/1.5 system-ui,sans-serif;color:var(--pdx-consent-text);background:var(--pdx-consent-background);box-shadow:0 -2px 12px rgba(0,0,0,.15)}
1
+ (function(){'use strict';var ft=Object.defineProperty;var yt=(t,e,n)=>e in t?ft(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var A=(t,e,n)=>yt(t,typeof e!="symbol"?e+"":e,n);var O=class extends Error{constructor(n,r,o){super(r,o);A(this,"code");this.code=n,this.name="ProdantixError";}};var M=class extends O{constructor(n,r,o){super("transport",n,o);A(this,"status");this.status=r,this.name="TransportError";}};function G(t){let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}var B=class{constructor(){A(this,"store",new Map);}getItem(e){var n;return (n=this.store.get(e))!=null?n:null}removeItem(e){this.store.delete(e);}setItem(e,n){this.store.set(e,n);}};function H(){try{let t=globalThis.localStorage;if(t){let e="__pdx_probe__";return t.setItem(e,"1"),t.removeItem(e),t}}catch(t){return new B}return new B}function bt(){return globalThis.crypto}function vt(t){t[6]=t[6]&15|64,t[8]=t[8]&63|128;let e=[];for(let n=0;n<16;n+=1)e.push(t[n].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function kt(){let t=bt();if(t!=null&&t.randomUUID)return t.randomUUID();let e=new Uint8Array(16);if(t!=null&&t.getRandomValues)t.getRandomValues(e);else for(let n=0;n<16;n+=1)e[n]=Math.floor(Math.random()*256);return vt(e)}var q={uuid:kt};function Y(t){return t.slice(0,16)}function j(t,e){return `pdx.${t}.${e}`}var X="consent",St=["identityLink","analytics","marketing","functional"];function K(t){if(typeof t!="string")return null;try{let e=JSON.parse(t);if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e,r={};for(let o of St){let i=n[o];typeof i=="boolean"&&(r[o]=i);}return typeof n.version=="number"&&Number.isInteger(n.version)&&(r.version=n.version),Array.isArray(n.categories)&&n.categories.every(o=>typeof o=="string")&&(r.categories=n.categories),Object.keys(r).length===0?null:r}catch(e){return null}}var U=t=>j(t,"anonymous_id");function z(t,e){return K(t.getItem(j(e,X)))}function Q(t,e,n){var s;let r=j(e,X),o=K(JSON.stringify(n)),i=o===null?null:K(JSON.stringify({...(s=z(t,e))!=null?s:{},...o}));if(i===null){t.removeItem(r);return}t.setItem(r,JSON.stringify(i));}var E=["analytics","marketing","functional"],Z="prodantix:consent-ready",tt="prodantix:consent",et="__prodantixConsent",nt=(t,e)=>{var r;if(t===null||t.version===void 0)return true;let n=(r=t.categories)!=null?r:[];return e.categories.some(o=>!n.includes(o))},ot=(t,e)=>({analytics:t.categories.includes("analytics")&&e.has("analytics"),categories:[...t.categories],functional:t.categories.includes("functional")&&e.has("functional"),marketing:t.categories.includes("marketing")&&e.has("marketing"),version:t.version}),J=t=>new Set(E.filter(e=>(t==null?void 0:t[e])===true));var rt="prodantix-consent-style",wt=`
2
+ .pdx-consent,.pdx-consent-dialog{color-scheme:light dark;--pdx-text:light-dark(oklch(0% 0 0/.93),oklch(100% 0 0));--pdx-text-2:light-dark(color-mix(in oklab,var(--pdx-text) 85%,transparent),color-mix(in oklab,var(--pdx-text) 70%,transparent));--pdx-surface:light-dark(oklch(97% .0029 264.54),oklch(26.5% .0157 256.82));--pdx-divider:light-dark(color-mix(in oklab,var(--pdx-text) 17.2%,transparent),color-mix(in oklab,var(--pdx-text) 12%,transparent));--pdx-hover:light-dark(color-mix(in oklab,var(--pdx-text) 4.6%,transparent),color-mix(in oklab,var(--pdx-text) 8%,transparent));--pdx-success:light-dark(oklch(52.4% .1274 163.23),oklch(69.51% .1809 145.62));box-sizing:border-box;font:14px/1.5 Geist,-apple-system,BlinkMacSystemFont,'Segoe UI',Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif;color:var(--pdx-text)}
3
+ .pdx-consent *,.pdx-consent-dialog *{box-sizing:border-box}
4
+ .pdx-consent{position:fixed;z-index:2147483000;background:var(--pdx-surface);border:1px solid var(--pdx-divider)}
5
+ .pdx-consent[data-layout="box"]{bottom:24px;left:24px;width:min(420px,calc(100vw - 32px));padding:20px;border-radius:12px;box-shadow:0 16px 40px rgba(0,0,0,.2)}
6
+ .pdx-consent[data-layout^="bar"]{left:0;right:0;display:flex;flex-wrap:wrap;gap:12px 24px;align-items:center;justify-content:space-between;padding:20px 24px;border-width:1px 0;box-shadow:0 8px 24px rgba(0,0,0,.16)}
3
7
  .pdx-consent[data-layout="bar_bottom"]{bottom:0}
4
8
  .pdx-consent[data-layout="bar_top"]{top:0}
5
- .pdx-consent[data-layout="box"]{left:16px;right:auto;bottom:16px;max-width:360px;border-radius:var(--pdx-consent-radius)}
6
- .pdx-consent h2{margin:0 0 4px;font-size:16px}
7
- .pdx-consent p{margin:0 0 12px}
9
+ .pdx-consent-title{margin:0 0 4px;font-size:16px;font-weight:600}
10
+ .pdx-consent-body,.pdx-consent-intro{margin:0;max-width:62ch;color:var(--pdx-text-2)}
11
+ .pdx-consent[data-layout="box"] .pdx-consent-body{margin-bottom:16px}
12
+ .pdx-consent a{color:var(--pdx-text);text-decoration:underline;text-underline-offset:2px}
8
13
  .pdx-consent-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
9
- .pdx-consent-choice{min-width:120px;min-height:44px;padding:0 16px;font:inherit;font-weight:600;color:var(--pdx-consent-button-text);background:var(--pdx-consent-button);border:0;border-radius:var(--pdx-consent-radius);cursor:pointer}
10
- .pdx-consent-link{min-height:44px;padding:0 8px;font:inherit;color:inherit;text-decoration:underline;background:none;border:0;cursor:pointer}
11
- .pdx-consent-choice:focus-visible,.pdx-consent-link:focus-visible,.pdx-consent input:focus-visible{outline:2px solid currentColor;outline-offset:2px}
14
+ .pdx-consent-button{min-height:44px;padding:0 16px;font:inherit;font-weight:600;border:1px solid transparent;border-radius:8px;cursor:pointer}
15
+ .pdx-consent-button[data-variant="contained"]{color:#fff;background:var(--pdx-accent);border-color:var(--pdx-accent)}
16
+ .pdx-consent-button[data-variant="outlined"]{color:var(--pdx-text);background:transparent;border-color:var(--pdx-divider)}
17
+ .pdx-consent-button[data-variant="outlined"]:hover{background:var(--pdx-hover)}
18
+ .pdx-consent :focus-visible,.pdx-consent-dialog :focus-visible{outline:2px solid var(--pdx-text);outline-offset:2px}
19
+ .pdx-consent-meta{width:100%;margin:12px 0 0;font-size:12px;color:var(--pdx-text-2)}
12
20
  .pdx-consent-dialog{position:fixed;inset:0;z-index:2147483001;display:flex;align-items:center;justify-content:center;padding:16px;background:rgba(0,0,0,.4)}
13
- .pdx-consent-panel{box-sizing:border-box;width:100%;max-width:480px;max-height:100%;overflow:auto;padding:20px;font:14px/1.5 system-ui,sans-serif;color:var(--pdx-consent-text);background:var(--pdx-consent-background);border-radius:var(--pdx-consent-radius)}
14
- .pdx-consent-panel h2{margin:0 0 12px;font-size:16px}
15
- .pdx-consent-category{display:flex;gap:12px;align-items:flex-start;padding:8px 0;border-top:1px solid currentColor}
16
- .pdx-consent-category input{width:20px;height:20px;margin:2px 0 0}
17
- .pdx-consent-meta{margin:12px 0 0;font-size:12px;opacity:.8}
18
- `,kt=t=>{if(t.getElementById(Z))return;let e=t.createElement("style");e.id=Z,e.textContent=bt,t.head.append(e);},tt=(t,e)=>{t.style.setProperty("--pdx-consent-background",e.style.background),t.style.setProperty("--pdx-consent-text",e.style.text),t.style.setProperty("--pdx-consent-button",e.style.button),t.style.setProperty("--pdx-consent-button-text",e.style.buttonText),t.style.setProperty("--pdx-consent-radius",`${e.style.radius}px`);},v=(t,e,n,r,o)=>{let i=t.createElement("button");return i.type="button",i.className=n==="choice"?"pdx-consent-choice":"pdx-consent-link",i.textContent=e,i.dataset.testid=r,i.addEventListener("click",o),i},et=(t,e,n,r)=>{kt(t);let o=e.texts,i=k.filter(d=>e.categories.includes(d)),s=null,g=null,y=null,h=()=>{g==null||g.remove(),g=null,y==null||y.focus();},p=d=>{h(),s==null||s.remove(),s=null,n.onAnswer(d);},l=d=>{var j;if(g)return;y=t.activeElement instanceof HTMLElement?t.activeElement:null;let u=t.createElement("div");u.className="pdx-consent-dialog";let a=t.createElement("div");a.className="pdx-consent-panel",a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true"),a.setAttribute("aria-labelledby","pdx-consent-settings-title"),a.dataset.testid="prodantix-consent-settings",tt(a,e);let c=t.createElement("h2");c.id="pdx-consent-settings-title",c.textContent=o.settings,a.append(c);let S=new Map,H=(m,w,pt,ut)=>{let $=t.createElement("label");$.className="pdx-consent-category";let x=t.createElement("input");x.type="checkbox",x.checked=pt,x.disabled=ut,x.dataset.testid=`prodantix-consent-category-${m}`;let K=t.createElement("span");return K.textContent=w,$.append(x,K),a.append($),x};H("necessary",o.necessary,true,true);for(let m of i)S.set(m,H(m,o[m],d.has(m),false));let T=t.createElement("div");T.className="pdx-consent-actions",T.append(v(t,o.save,"choice","prodantix-consent-save",()=>p(new Set(i.filter(m=>{var w;return ((w=S.get(m))==null?void 0:w.checked)===true})))),v(t,o.acceptAll,"choice","prodantix-consent-settings-accept",()=>p(new Set(i))),v(t,o.rejectAll,"choice","prodantix-consent-settings-reject",()=>p(new Set))),a.append(T),u.append(a),u.addEventListener("keydown",m=>{m.key==="Escape"&&h();}),t.body.append(u),g=u,(j=a.querySelector("input:not([disabled])"))==null||j.focus();};if(r){s=t.createElement("section"),s.className="pdx-consent",s.dataset.layout=e.layout,s.dataset.testid="prodantix-consent-banner",s.setAttribute("aria-label",o.title),tt(s,e);let d=t.createElement("h2");d.textContent=o.title;let u=t.createElement("p");u.textContent=o.body,s.append(d,u);let a=t.createElement("div");if(a.className="pdx-consent-actions",a.append(v(t,o.acceptAll,"choice","prodantix-consent-accept",()=>p(new Set(i))),v(t,o.rejectAll,"choice","prodantix-consent-reject",()=>p(new Set)),v(t,o.settings,"link","prodantix-consent-open-settings",()=>l(new Set))),e.policyUrl.startsWith("https://")){let c=t.createElement("a");c.className="pdx-consent-link",c.href=e.policyUrl,c.rel="noopener",c.target="_blank",c.textContent=o.policyLabel||e.policyUrl,a.append(c);}if(s.append(a),e.poweredBy){let c=t.createElement("p");c.className="pdx-consent-meta",c.textContent=e.poweredByText,s.append(c);}t.body.append(s);}return {openSettings:l,remove:()=>{h(),s==null||s.remove(),s=null;}}};var vt='script[type="text/plain"][data-prodantix-consent]',A=(t,e)=>{let n=0;for(let r of Array.from(t.querySelectorAll(vt))){let o=r.dataset.prodantixConsent;if(o===void 0||!e.has(o))continue;let i=t.createElement("script");for(let s of Array.from(r.attributes))s.name!=="type"&&s.name!=="data-prodantix-consent"&&i.setAttribute(s.name,s.value);i.text=r.text,r.replaceWith(i),n+=1;}return n};var nt=(t,e,n)=>{t.win.dispatchEvent(new CustomEvent(e,{detail:n}));},ot=async t=>{let e=await t.fetch(`${t.edge}/v1/consent?language=${encodeURIComponent(t.language)}`,{headers:{authorization:`Bearer ${t.apiKey}`},method:"GET"});if(!e.ok)throw new C("the consent banner could not be read",e.status);let n=JSON.parse(await e.text()),r=R(t.shared,t.namespace),o=n.banner,i=o!==null&&r!==null&&!X(r,o)?r:null,s={anonymousId:n.anonymousId,consent:i,rule:n.rule};if(t.win[Y]=s,nt(t,G,s),o===null)return A(t.doc,new Set(k)),{openSettings:()=>{}};A(t.doc,i!==null?B(i):n.rule==="notice"?new Set(k):new Set);let g=p=>{var u,a,c;let l=Q(o,p),d=n.anonymousId;l.analytics===true&&(d=(u=t.shared.getItem(P(t.namespace)))!=null?u:t.ids.uuid(),t.shared.setItem(P(t.namespace),d)),W(t.shared,t.namespace,l),s.consent=l,nt(t,q,l),A(t.doc,p),t.fetch(`${t.edge}/v1/consent`,{body:JSON.stringify({analytics:l.analytics===true,distinctId:d,functional:l.functional===true,marketing:l.marketing===true,pageUrl:(c=(a=t.doc.location)==null?void 0:a.href)!=null?c:"",version:o.version}),headers:{authorization:`Bearer ${t.apiKey}`,"content-type":"application/json"},method:"POST"}).then(S=>{S.ok||t.onError(new C("the consent answer could not be kept",S.status));}).catch(t.onError);},y=et(t.doc,o,{onAnswer:g},i===null),h=()=>y.openSettings(B(s.consent));return t.doc.addEventListener("click",p=>{var d,u;(u=(d=p.target)==null?void 0:d.closest)!=null&&u.call(d,"[data-prodantix-consent-settings]")&&(p.preventDefault(),h());}),{openSettings:h}};var St=/^\d{1,3}(\.\d{1,3}){3}$/,Ct=/^[a-z0-9.-]+$/i;function rt(){return Math.random().toString(36).slice(2,12)}function _(t,e){let n=`${e}=`,r=[];for(let o of t.cookie.split(";")){let i=o.trim();i.startsWith(n)&&r.push(i.slice(n.length));}return r}function I(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function st(t,e,n,r){try{let o=`pdx_probe_${r()}`,i=r();t.cookie=`${o}=${i}; ${I(e,60,n)}`;let s=_(t,o).includes(i);t.cookie=`${o}=; ${I(e,0,n)}`;let g=_(t,o).includes(i);return s&&!g}catch(o){return false}}function It(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||St.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let o=n.length-2;o>=0;o-=1)r.push(n.slice(o).join("."));return r}function wt(t,e,n,r=rt){for(let o of It(t))if(st(e,o,n,r))return o}function Et(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,o]of Object.entries(n))typeof o=="string"&&e.set(r,o);return e}var D=class{constructor(e,n,r,o){this.jar=e;this.name=n;this.domain=r;this.secure=o;}getItem(e){var n;return (n=this.read().get(e))!=null?n:null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=_(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${I(void 0,0,this.secure)}`,e=_(this.jar,this.name));let n=e[0];return n?Et(n):new Map}catch(e){return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${I(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${I(this.domain,31536e3,this.secure)}`;}catch(n){return}}};function At(){return globalThis.document}function _t(){var t,e;return (e=(t=globalThis.location)==null?void 0:t.hostname)!=null?e:""}function Tt(){var t;return ((t=globalThis.location)==null?void 0:t.protocol)==="https:"}function $t(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Ct.test(e)?e.toLowerCase():void 0}function it(t){var s,g,y,h,p;let e="jar"in t?t.jar:At();if(!e||((s=globalThis.navigator)==null?void 0:s.cookieEnabled)===false)return null;let r=(g=t.random)!=null?g:rt,o=(y=t.secure)!=null?y:Tt(),i=(h=t.hostname)!=null?h:_t();try{let l=(p=$t(t.domain))!=null?p:wt(i,e,o,r);return st(e,l,o,r)?new D(e,t.name,l,o):null}catch(l){return null}}var f=document.currentScript,O=f==null?void 0:f.dataset.key,at=U(),dt,ct,lt;if(f&&O&&at){let t=V(O),e=M();try{e=(dt=it({name:`pdx_${t}`}))!=null?dt:e;}catch(n){e=M();}ot({apiKey:O,doc:document,edge:(ct=f.dataset.edge)!=null?ct:new URL(f.src,window.location.href).origin,fetch:at,ids:J,language:(lt=f.dataset.language)!=null?lt:document.documentElement.lang,namespace:t,onError:n=>console.error("[prodantix] the consent answer could not be kept",n),shared:e,win:window}).then(n=>{window.prodantixConsent=n;}).catch(n=>console.error("[prodantix] the consent banner could not be read",n));}
21
+ .pdx-consent-panel{display:flex;flex-direction:column;width:100%;max-width:640px;max-height:min(720px,100%);background:var(--pdx-surface);border:1px solid var(--pdx-divider);border-radius:12px;box-shadow:0 16px 40px rgba(0,0,0,.2)}
22
+ .pdx-consent-panel h2{margin:0;padding:20px 24px 12px;font-size:16px;font-weight:600}
23
+ .pdx-consent-content{overflow:auto;padding:0 24px}
24
+ .pdx-consent-intro{margin-bottom:16px}
25
+ .pdx-consent-cats{display:flex;flex-direction:column;gap:8px}
26
+ .pdx-consent-cat{position:relative;border:1px solid var(--pdx-divider);border-radius:8px}
27
+ .pdx-consent-head{display:flex;gap:8px;align-items:center;width:100%;min-height:52px;padding:0 140px 0 16px;font:inherit;font-weight:600;color:inherit;text-align:start;background:none;border:0;cursor:pointer}
28
+ .pdx-consent-head::before{content:"";width:6px;height:6px;border:solid currentColor;border-width:0 2px 2px 0;transform:rotate(-45deg)}
29
+ .pdx-consent-head[aria-expanded="true"]::before{transform:rotate(45deg)}
30
+ .pdx-consent-count{font-weight:400;font-size:12px;color:var(--pdx-text-2)}
31
+ .pdx-consent-control{position:absolute;top:0;right:16px;display:flex;align-items:center;height:52px}
32
+ .pdx-consent-chip{padding:2px 8px;font-size:12px;font-weight:600;color:var(--pdx-success);background:color-mix(in oklab,var(--pdx-success) 12%,transparent);border-radius:9999px}
33
+ .pdx-consent-switch{appearance:none;position:relative;width:40px;height:24px;margin:0;background:var(--pdx-divider);border-radius:9999px;cursor:pointer}
34
+ .pdx-consent-switch::after{content:"";position:absolute;top:3px;left:3px;width:18px;height:18px;background:#fff;border-radius:50%;box-shadow:0 1px 2px rgba(16,24,40,.2)}
35
+ .pdx-consent-switch:checked{background:var(--pdx-accent)}
36
+ .pdx-consent-switch:checked::after{transform:translateX(16px)}
37
+ .pdx-consent-detail{padding:0 16px 16px}
38
+ .pdx-consent-detail p{margin:0 0 12px;font-size:12px;color:var(--pdx-text-2)}
39
+ .pdx-consent-table{width:100%;font-size:12px;border-collapse:collapse}
40
+ .pdx-consent-table th{padding:8px 12px;font-size:11px;color:var(--pdx-text-2);text-align:start}
41
+ .pdx-consent-table th,.pdx-consent-table td{border-bottom:1px solid var(--pdx-divider)}
42
+ .pdx-consent-table td{padding:8px 12px;vertical-align:top}
43
+ .pdx-consent-table tr:last-child td{border-bottom:0}
44
+ .pdx-consent-name{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px}
45
+ .pdx-consent-foot{justify-content:flex-end;padding:16px 24px 20px}
46
+ @media (max-width:639px){.pdx-consent-dialog{align-items:flex-end;padding:0}.pdx-consent-panel{max-height:85vh;border-radius:12px 12px 0 0}.pdx-consent-foot .pdx-consent-button{flex:1 1 auto}}
47
+ @media (prefers-reduced-motion:no-preference){.pdx-consent,.pdx-consent-panel{animation:pdx-consent-in .2s ease-out}.pdx-consent-switch::after{transition:transform .15s ease-out}}
48
+ @keyframes pdx-consent-in{from{opacity:0;transform:translateY(8px)}}
49
+ `,Ct={alwaysActive:"Always active",analyticsName:"Analytics",cookieColumn:"Cookie",durationColumn:"Duration",functionalName:"Functional",marketingName:"Marketing",necessaryName:"Necessary",preferencesTitle:"Privacy preferences",providerColumn:"Provider",purposeColumn:"Purpose",visitDuration:"Session"},It={days:"day",hours:"hour",minutes:"minute",months:"month",years:"year"},At=t=>{if(t.getElementById(rt))return;let e=t.createElement("style");e.id=rt,e.textContent=wt,t.head.append(e);},Et=(t,e,n)=>{var r;return t.unit==="visit"?n:new Intl.NumberFormat(e,{style:"unit",unit:It[t.unit],unitDisplay:"long"}).format((r=t.amount)!=null?r:0)},a=(t,e,n="",r="")=>{let o=t.createElement(e);return n&&(o.className=n),r&&(o.textContent=r),o},T=(t,e,n,r,o)=>{let i=a(t,"button","pdx-consent-button",e);return i.type="button",i.dataset.variant=n,i.dataset.testid=r,i.addEventListener("click",o),i},st=(t,e,n,r,o)=>{let i=a(t,"p",e,n);if(r.policyUrl.startsWith("https://")){let s=a(t,"a","",o||r.policyUrl);s.href=r.policyUrl,s.rel="noopener",s.target="_blank",s.dataset.testid="prodantix-consent-policy",i.append(" ",s);}return i},it="button,a[href],input:not([disabled])",at=(t,e,n,r)=>{At(t);let o={...e.texts};for(let[l,p]of Object.entries(Ct))o[l]||(o[l]=p);let i=E.filter(l=>e.categories.includes(l)),s=null,m=null,v=null,S=l=>{l.style.setProperty("--pdx-accent",e.style.accent);},x=()=>{m&&(m.remove(),m=null,v==null||v.focus());},u=l=>{x(),s==null||s.remove(),s=null,n.onAnswer(l);},f=(l,p,g,D)=>{var L,$;let C=a(t,"div","pdx-consent-cat");C.dataset.testid=`prodantix-consent-category-${p}`;let h=a(t,"button","pdx-consent-head",o[`${p}Name`]);h.type="button",h.setAttribute("aria-expanded","false"),h.dataset.testid=`prodantix-consent-category-${p}-head`,h.append(" ",a(t,"span","pdx-consent-count",String(g.length)));let k=a(t,"div","pdx-consent-detail");if(k.hidden=true,k.dataset.testid=`prodantix-consent-category-${p}-detail`,o[p]&&k.append(a(t,"p","",o[p])),g.length>0){let y=a(t,"table","pdx-consent-table"),c=a(t,"tr");for(let d of [o.cookieColumn,o.providerColumn,o.purposeColumn,o.durationColumn]){let b=a(t,"th","",d);b.scope="col",c.append(b);}y.append(a(t,"thead"),a(t,"tbody")),(L=y.tHead)==null||L.append(c);for(let d of g){let b=a(t,"tr");b.append(a(t,"td","pdx-consent-name",d.name),a(t,"td","",d.provider),a(t,"td","",d.purpose),a(t,"td","",Et(d.duration,e.language,o.visitDuration))),($=y.tBodies[0])==null||$.append(b);}k.append(y);}h.addEventListener("click",()=>{let y=h.getAttribute("aria-expanded")!=="true";h.setAttribute("aria-expanded",String(y)),k.hidden=!y;});let _=a(t,"span","pdx-consent-control");_.append(D),C.append(h,_,k),l.append(C);},w=l=>{var y;if(m)return;v=t.activeElement instanceof HTMLElement?t.activeElement:null;let p=a(t,"div","pdx-consent-dialog");S(p);let g=a(t,"div","pdx-consent-panel");g.setAttribute("role","dialog"),g.setAttribute("aria-modal","true"),g.setAttribute("aria-labelledby","pdx-consent-preferences-title"),g.dataset.testid="prodantix-consent-settings";let D=a(t,"h2","",o.preferencesTitle);D.id="pdx-consent-preferences-title";let C=a(t,"div","pdx-consent-content");o.preferencesIntro&&C.append(st(t,"pdx-consent-intro",o.preferencesIntro,e,o.policyLabel));let h=a(t,"div","pdx-consent-cats"),k=c=>e.items.filter(d=>d.category===c),_=a(t,"span","pdx-consent-chip",o.alwaysActive);_.dataset.testid="prodantix-consent-always-active",f(h,"necessary",k("necessary"),_);let L=new Map;for(let c of i){let d=a(t,"input","pdx-consent-switch");d.type="checkbox",d.setAttribute("role","switch"),d.checked=l.has(c),d.setAttribute("aria-checked",String(d.checked)),d.setAttribute("aria-label",o[`${c}Name`]),d.dataset.testid=`prodantix-consent-switch-${c}`,d.addEventListener("change",()=>d.setAttribute("aria-checked",String(d.checked))),L.set(c,d),f(h,c,k(c),d);}C.append(h);let $=a(t,"div","pdx-consent-actions pdx-consent-foot");$.append(T(t,o.rejectAll,"outlined","prodantix-consent-settings-reject",()=>u(new Set)),T(t,o.acceptAll,"outlined","prodantix-consent-settings-accept",()=>u(new Set(i))),T(t,o.save,"contained","prodantix-consent-save",()=>u(new Set(i.filter(c=>{var d;return ((d=L.get(c))==null?void 0:d.checked)===true}))))),g.append(D,C,$),p.append(g),p.addEventListener("keydown",c=>{if(c.key==="Escape"){c.preventDefault(),x();return}if(c.key!=="Tab")return;let d=[...g.querySelectorAll(it)],b=d[0],F=d[d.length-1];c.shiftKey&&t.activeElement===b?(c.preventDefault(),F==null||F.focus()):!c.shiftKey&&t.activeElement===F&&(c.preventDefault(),b==null||b.focus());}),t.body.append(p),m=p,(y=g.querySelector(it))==null||y.focus();};if(r){s=a(t,"section","pdx-consent"),s.dataset.layout=e.layout,s.dataset.testid="prodantix-consent-banner",s.setAttribute("aria-label",o.title),S(s);let l=a(t,"div");l.append(a(t,"p","pdx-consent-title",o.title),st(t,"pdx-consent-body",o.body,e,o.policyLabel));let p=a(t,"div","pdx-consent-actions");p.append(T(t,o.acceptAll,"contained","prodantix-consent-accept",()=>u(new Set(i))),T(t,o.rejectAll,"contained","prodantix-consent-reject",()=>u(new Set)),T(t,o.preferences,"outlined","prodantix-consent-open-settings",()=>w(new Set))),s.append(l,p),e.poweredBy&&s.append(a(t,"p","pdx-consent-meta",e.poweredByText)),t.body.append(s);}return {openSettings:w,remove:()=>{x(),s==null||s.remove(),s=null;}}};var Tt='script[type="text/plain"][data-prodantix-consent]',P=(t,e)=>{let n=0;for(let r of Array.from(t.querySelectorAll(Tt))){let o=r.dataset.prodantixConsent;if(o===void 0||!e.has(o))continue;let i=t.createElement("script");for(let s of Array.from(r.attributes))s.name!=="type"&&s.name!=="data-prodantix-consent"&&i.setAttribute(s.name,s.value);i.text=r.text,r.replaceWith(i),n+=1;}return n};var dt=(t,e,n)=>{t.win.dispatchEvent(new CustomEvent(e,{detail:n}));},ct=async t=>{let e=await t.fetch(`${t.edge}/v1/consent?language=${encodeURIComponent(t.language)}`,{headers:{authorization:`Bearer ${t.apiKey}`},method:"GET"});if(!e.ok)throw new M("the consent banner could not be read",e.status);let n=JSON.parse(await e.text()),r=z(t.shared,t.namespace),o=n.banner,i=o!==null&&r!==null&&!nt(r,o)?r:null,s={anonymousId:n.anonymousId,consent:i,rule:n.rule};if(t.win[et]=s,dt(t,Z,s),o===null)return P(t.doc,new Set(E)),{openSettings:()=>{}};P(t.doc,i!==null?J(i):n.rule==="notice"?new Set(E):new Set);let m=x=>{var w,l,p;let u=ot(o,x),f=n.anonymousId;u.analytics===true&&(f=(w=t.shared.getItem(U(t.namespace)))!=null?w:t.ids.uuid(),t.shared.setItem(U(t.namespace),f)),Q(t.shared,t.namespace,u),s.consent=u,dt(t,tt,u),P(t.doc,x),t.fetch(`${t.edge}/v1/consent`,{body:JSON.stringify({analytics:u.analytics===true,distinctId:f,functional:u.functional===true,marketing:u.marketing===true,pageUrl:(p=(l=t.doc.location)==null?void 0:l.href)!=null?p:"",version:o.version}),headers:{authorization:`Bearer ${t.apiKey}`,"content-type":"application/json"},method:"POST"}).then(g=>{g.ok||t.onError(new M("the consent answer could not be kept",g.status));}).catch(t.onError);},v=at(t.doc,o,{onAnswer:m},i===null),S=()=>v.openSettings(J(s.consent));return t.doc.addEventListener("click",x=>{var f,w;(w=(f=x.target)==null?void 0:f.closest)!=null&&w.call(f,"[data-prodantix-consent-settings]")&&(x.preventDefault(),S());}),{openSettings:S}};var _t=/^\d{1,3}(\.\d{1,3}){3}$/,Lt=/^[a-z0-9.-]+$/i;function pt(){return Math.random().toString(36).slice(2,12)}function R(t,e){let n=`${e}=`,r=[];for(let o of t.cookie.split(";")){let i=o.trim();i.startsWith(n)&&r.push(i.slice(n.length));}return r}function N(t,e,n){let r=["Path=/",`Max-Age=${e}`,"SameSite=Lax"];return t&&r.push(`Domain=${t}`),n&&r.push("Secure"),r.join("; ")}function lt(t,e,n,r){try{let o=`pdx_probe_${r()}`,i=r();t.cookie=`${o}=${i}; ${N(e,60,n)}`;let s=R(t,o).includes(i);t.cookie=`${o}=; ${N(e,0,n)}`;let m=R(t,o).includes(i);return s&&!m}catch(o){return false}}function $t(t){let e=t.replace(/^\[|\]$/g,"").toLowerCase();if(e.includes(":")||_t.test(e)||!e.includes("."))return [];let n=e.split("."),r=[];for(let o=n.length-2;o>=0;o-=1)r.push(n.slice(o).join("."));return r}function Mt(t,e,n,r=pt){for(let o of $t(t))if(lt(e,o,n,r))return o}function Nt(t){let e=new Map,n=JSON.parse(decodeURIComponent(t));if(n===null||typeof n!="object"||Array.isArray(n))return e;for(let[r,o]of Object.entries(n))typeof o=="string"&&e.set(r,o);return e}var V=class{constructor(e,n,r,o){this.jar=e;this.name=n;this.domain=r;this.secure=o;}getItem(e){var n;return (n=this.read().get(e))!=null?n:null}setItem(e,n){let r=this.read();r.set(e,n),this.write(r);}removeItem(e){let n=this.read();n.delete(e)&&this.write(n);}read(){try{let e=R(this.jar,this.name);e.length>1&&this.domain&&(this.jar.cookie=`${this.name}=; ${N(void 0,0,this.secure)}`,e=R(this.jar,this.name));let n=e[0];return n?Nt(n):new Map}catch(e){return new Map}}write(e){try{if(e.size===0){this.jar.cookie=`${this.name}=; ${N(this.domain,0,this.secure)}`;return}let n=encodeURIComponent(JSON.stringify(Object.fromEntries(e)));this.jar.cookie=`${this.name}=${n}; ${N(this.domain,31536e3,this.secure)}`;}catch(n){return}}};function Dt(){return globalThis.document}function Ft(){var t,e;return (e=(t=globalThis.location)==null?void 0:t.hostname)!=null?e:""}function Bt(){var t;return ((t=globalThis.location)==null?void 0:t.protocol)==="https:"}function Pt(t){if(t===void 0)return;let e=t.startsWith(".")?t.slice(1):t;return Lt.test(e)?e.toLowerCase():void 0}function ut(t){var s,m,v,S,x;let e="jar"in t?t.jar:Dt();if(!e||((s=globalThis.navigator)==null?void 0:s.cookieEnabled)===false)return null;let r=(m=t.random)!=null?m:pt,o=(v=t.secure)!=null?v:Bt(),i=(S=t.hostname)!=null?S:Ft();try{let u=(x=Pt(t.domain))!=null?x:Mt(i,e,o,r);return lt(e,u,o,r)?new V(e,t.name,u,o):null}catch(u){return null}}var I=document.currentScript,W=I==null?void 0:I.dataset.key,gt=G(),mt,xt,ht;if(I&&W&&gt){let t=Y(W),e=H();try{e=(mt=ut({name:`pdx_${t}`}))!=null?mt:e;}catch(n){e=H();}ct({apiKey:W,doc:document,edge:(xt=I.dataset.edge)!=null?xt:new URL(I.src,window.location.href).origin,fetch:gt,ids:q,language:(ht=I.dataset.language)!=null?ht:document.documentElement.lang,namespace:t,onError:n=>console.error("[prodantix] the consent answer could not be kept",n),shared:e,win:window}).then(n=>{window.prodantixConsent=n;}).catch(n=>console.error("[prodantix] the consent banner could not be read",n));}
19
50
  })();//# sourceMappingURL=consent.iife.js.map
20
51
  //# sourceMappingURL=consent.iife.js.map