@pmeweb/plugin-chat 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.js CHANGED
@@ -1,2 +1,2 @@
1
- var it=`.pmw-chat__panel{position:fixed;z-index:81;inset:0;display:flex;flex-direction:column;background:var(--pmw-chat-panel-bg, #ffffff);color:var(--pmw-chat-fg, #1f2328);font-family:var(--pmw-chat-font, inherit);font-size:16px;line-height:1.45}.pmw-chat__panel[hidden]{display:flex!important;opacity:0;pointer-events:none}.pmw-chat__panel [hidden]{display:none!important}@media(min-width:640px){.pmw-chat__panel{inset:auto;right:calc(env(safe-area-inset-right,0px) + var(--pmw-chat-right, 16px));bottom:calc(env(safe-area-inset-bottom,0px) + var(--pmw-chat-bottom, 16px));width:380px;height:min(600px,calc(100dvh - 16px - env(safe-area-inset-bottom,0px) - var(--pmw-chat-bottom, 16px)));border:1px solid var(--pmw-chat-line, #e6e9f0);border-radius:20px;overflow:hidden;box-shadow:0 18px 48px #1018282e}}.pmw-chat__panel :where(button){font:inherit;cursor:pointer}.pmw-chat__panel :focus-visible{outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}.pmw-chat__head{display:flex;align-items:center;gap:12px;padding:14px 10px 14px 16px;border-bottom:1px solid var(--pmw-chat-line, #e6e9f0)}@media(max-width:639.98px){.pmw-chat__head{padding:12px 8px 12px 16px}}.pmw-chat__face{position:relative;flex:none;display:flex}.pmw-chat__head .pmw-chat__avatar{width:44px;height:44px;box-shadow:none}.pmw-chat__head .pmw-chat__avatar--icon{box-shadow:0 0 0 1.5px var(--pmw-chat-avatar-ring, transparent)}.pmw-chat__head .pmw-chat__avatar img{width:44px;height:44px}.pmw-chat__head .pmw-chat__avatar--logo img{width:32px;height:32px}.pmw-chat__head .pmw-chat__avatar svg{width:100%;height:100%}.pmw-chat__dot{position:absolute;right:-1px;bottom:-1px;width:12px;height:12px;border-radius:50%;background:var(--pmw-chat-live, #1a7f37);box-shadow:0 0 0 2px var(--pmw-chat-panel-bg, #ffffff)}.pmw-chat__who{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}.pmw-chat__name{margin:0;font-weight:600;font-size:16px}.pmw-chat__role,.pmw-chat__notice{margin:0;font-size:13px;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__panel[data-mode=human] .pmw-chat__role{color:var(--pmw-chat-live, #1a7f37);font-weight:500}.pmw-chat__notice a{color:var(--pmw-chat-link, #0a1b3d);text-decoration:underline;text-underline-offset:2px}.pmw-chat__close{flex:none;width:44px;height:44px;padding:0;border:0;border-radius:50%;display:flex;align-items:center;justify-content:center;background:transparent;color:var(--pmw-chat-fg, #1f2328)}.pmw-chat__close:hover{background:var(--pmw-chat-thread-bg, #f7f8fb)}.pmw-chat__close svg{width:18px;height:18px}.pmw-chat__body{flex:1;min-height:0;display:flex;flex-direction:column;overflow-y:auto;padding:18px 16px;background:var(--pmw-chat-thread-bg, #f7f8fb)}.pmw-chat__log{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}.pmw-chat__log>li{margin-top:4px}.pmw-chat__log>li:first-child,.pmw-chat__msg--bot+.pmw-chat__msg--bot,.pmw-chat__msg--bot+.pmw-chat__typing,.pmw-chat__msg--owner+.pmw-chat__msg--owner,.pmw-chat__msg--owner+.pmw-chat__typing,.pmw-chat__msg--visitor+.pmw-chat__msg--visitor{margin-top:0}.pmw-chat__msg{max-width:82%;padding:10px 14px;border-radius:18px;white-space:pre-wrap;overflow-wrap:anywhere}.pmw-chat__msg--bot,.pmw-chat__msg--owner{align-self:flex-start;border-bottom-left-radius:6px;color:var(--pmw-chat-fg, #1f2328)}.pmw-chat__msg--bot{background:var(--pmw-chat-other-bg, #ffffff);border:1px solid var(--pmw-chat-line, #e6e9f0)}.pmw-chat__msg--owner{background:var(--pmw-chat-owner-bg, #eef2fa);border:1px solid var(--pmw-chat-owner-border, #d5ddef)}.pmw-chat__msg--visitor{align-self:flex-end;background:var(--pmw-chat-accent, #0a1b3d);color:var(--pmw-chat-accent-fg, #ffffff);border-bottom-right-radius:6px}.pmw-chat__msg--bot+.pmw-chat__msg--bot,.pmw-chat__msg--owner+.pmw-chat__msg--owner{border-top-left-radius:6px}.pmw-chat__msg--visitor+.pmw-chat__msg--visitor{border-top-right-radius:6px}.pmw-chat__msg:has(>.pmw-chat__photo){padding:4px}.pmw-chat__msg:has(>.pmw-chat__photo) .pmw-chat__text:empty{display:none}.pmw-chat__msg.is-pending{opacity:.75}.pmw-chat__msg.is-failed{outline:2px solid var(--pmw-chat-error, #b42318);outline-offset:2px}.pmw-chat__retry{display:block;margin-top:4px;font-size:14px}.pmw-chat__retry button{padding:0;border:0;background:none;color:inherit;text-decoration:underline}.pmw-chat__typing{align-self:flex-start;display:flex;gap:5px;padding:14px 16px;border-radius:18px 18px 18px 6px;background:var(--pmw-chat-other-bg, #ffffff);border:1px solid var(--pmw-chat-line, #e6e9f0)}.pmw-chat__typing span{width:7px;height:7px;border-radius:50%;background:var(--pmw-chat-muted, #4b5563);animation:pmw-chat-dot 1.2s infinite ease-in-out}.pmw-chat__typing span:nth-child(2){animation-delay:.15s}.pmw-chat__typing span:nth-child(3){animation-delay:.3s}@keyframes pmw-chat-dot{0%,80%,to{opacity:.3}40%{opacity:1}}@media(prefers-reduced-motion:reduce){.pmw-chat__typing span{animation:none;opacity:.7}}.pmw-chat__log>.pmw-chat__relay,.pmw-chat__log>.pmw-chat__handback{align-self:stretch;margin:18px 0 8px;display:flex;align-items:center;gap:10px;font-size:13px;font-weight:500;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__relay:before,.pmw-chat__relay:after,.pmw-chat__handback:before,.pmw-chat__handback:after{content:"";flex:1;min-width:16px;height:1px;background:var(--pmw-chat-rule, #cfd5e1)}.pmw-chat__relay-label{display:flex;align-items:center;gap:6px;text-align:center}.pmw-chat__relay-dot{flex:none;width:8px;height:8px;border-radius:50%;background:var(--pmw-chat-live, #1a7f37)}.pmw-chat__relay-dot--back{background:var(--pmw-chat-muted, #4b5563)}.pmw-chat__log>.pmw-chat__relay+li,.pmw-chat__log>.pmw-chat__handback+li{margin-top:0}.pmw-chat__state{margin:8px 0 0;font-size:14px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__state:empty{display:none}.pmw-chat__ended{margin-top:22px;display:flex;flex-direction:column;align-items:center;gap:12px;text-align:center}.pmw-chat__ended:before{content:"";align-self:stretch;height:1px;background:var(--pmw-chat-line, #e6e9f0)}.pmw-chat__ended p{margin:0;font-size:15px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__restart{min-height:44px;padding:0 20px;border-radius:22px;border:1px solid var(--pmw-chat-link, #0a1b3d);background:var(--pmw-chat-panel-bg, #ffffff);color:var(--pmw-chat-link, #0a1b3d);font-weight:600}.pmw-chat__composer{--pmw-chat-gap: 8px;display:flex;flex-direction:column;gap:var(--pmw-chat-gap);padding:14px 16px 16px;border-top:1px solid var(--pmw-chat-line, #e6e9f0);background:var(--pmw-chat-panel-bg, #ffffff)}@media(max-width:639.98px){.pmw-chat__composer{padding:12px 16px calc(14px + env(safe-area-inset-bottom,0px))}}.pmw-chat__box{display:flex;align-items:flex-end;gap:6px;padding:4px;border-radius:24px;border:1px solid var(--pmw-chat-field-border, #7d8590);background:#fff;color:var(--pmw-chat-field-fg, #1f2328)}.pmw-chat__box textarea{flex:1;min-width:0;box-sizing:border-box;min-height:44px;max-height:132px;resize:none;margin:0;padding:10px 2px;border:0;border-radius:0;background:transparent;color:inherit;font:inherit;font-size:16px;line-height:1.5}.pmw-chat__box textarea::placeholder{color:#6b7280;opacity:1}@supports selector(:has(*)){.pmw-chat__box textarea:focus-visible{outline:none}.pmw-chat__box:has(textarea:focus-visible){outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}}.pmw-chat__send{flex:none;min-height:44px;padding:0 18px;border:0;border-radius:22px;font-weight:600;background:var(--pmw-chat-accent, #0a1b3d);color:var(--pmw-chat-accent-fg, #ffffff)}.pmw-chat__send:disabled,.pmw-chat__box textarea:disabled{cursor:not-allowed;opacity:.6}.pmw-chat__check{position:relative;display:grid;grid-template-rows:0fr;margin-bottom:calc(-1 * var(--pmw-chat-gap, 0px));transition:grid-template-rows .25s ease,margin-bottom .25s ease}.pmw-chat__check[data-ask]{grid-template-rows:1fr;margin-bottom:4px}.pmw-chat__check-in{min-height:0;overflow:hidden}.pmw-chat__check:not([data-ask]) .pmw-chat__check-in{position:absolute;top:0;left:0;right:0;overflow:visible;opacity:0;pointer-events:none}@media(prefers-reduced-motion:reduce){.pmw-chat__check{transition:none}}.pmw-chat__attach{flex:none;position:relative;width:44px;height:44px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;color:inherit}.pmw-chat__attach:hover{background:#eef0f4}.pmw-chat__attach svg{width:22px;height:22px}.pmw-chat__attach:focus-within{outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}.pmw-chat__hint{margin:0 8px;font-size:13px;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__composer .pmw-chat__photo-error{margin:0 8px}.pmw-chat__photo{display:block;max-width:100%;max-height:220px;border-radius:14px}.pmw-chat__fallback{--pmw-chat-gap: 14px;display:flex;flex-direction:column;gap:var(--pmw-chat-gap);margin-top:16px}.pmw-chat__fb-title{margin:0;font-size:20px;font-weight:600;line-height:1.3}.pmw-chat__fb-intro{margin:-8px 0 0;font-size:15px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__field{display:flex;flex-direction:column;gap:4px}.pmw-chat__field label{font-size:14px;font-weight:600}.pmw-chat__field input,.pmw-chat__field textarea{font:inherit;font-size:16px;padding:10px 14px;border-radius:12px;resize:none;border:1px solid var(--pmw-chat-field-border, #7d8590);background:#fff;color:var(--pmw-chat-field-fg, #1f2328)}.pmw-chat__fallback .pmw-chat__send{align-self:stretch;min-height:48px;border-radius:24px}.pmw-chat__error{margin:0;font-size:14px;color:var(--pmw-chat-error, #b42318)}.pmw-chat__error:empty{display:none}.pmw-chat__sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.pmw-chat[data-unread] .pmw-chat__bubble{position:relative}.pmw-chat[data-unread] .pmw-chat__bubble:after{content:"";position:absolute;top:2px;left:38px;width:12px;height:12px;border-radius:50%;background:var(--pmw-chat-error, #b42318);box-shadow:0 0 0 2px #fff}.pmw-chat__fb-done{margin:12px 0 0;padding:12px 14px;border-radius:12px;background:#e9f6ee;color:#14532d;border:1px solid #b7dfc4;font-weight:500}
2
- `;var Mt="400px 0px";var st=new Set,pe=null;function ct(r,{doc:p=document,attrs:o={}}={}){if(st.has(r)||(st.add(r),p.querySelector(`script[src="${r}"]`)))return;let t=p.createElement("script");t.src=r,t.async=!0;for(let[f,m]of Object.entries(o))t.setAttribute(f,m);p.head.append(t)}function lt({doc:r=document,hostname:p=globalThis.location?.hostname??""}={}){let o=r.getElementById("pmw-hosts");if(!o)return!1;let t;try{t=JSON.parse(o.textContent??"")}catch{return!1}if(!Array.isArray(t))return!1;let f=String(p).toLowerCase();return t.some(m=>typeof m=="string"&&m.toLowerCase()===f)}function Nt(r){return pe||(pe=new Promise(p=>{let o=null,t=null,f=0,m=r.PerformanceObserver?.supportedEntryTypes??[],w=typeof r.PerformanceObserver=="function"&&m.includes("paint"),l=()=>{o===null||w&&t===null||p(Math.max(o,t??0,f))};if(w)try{new r.PerformanceObserver(x=>{for(let v of x.getEntries())v.name==="first-contentful-paint"&&(t=v.startTime);l()}).observe({type:"paint",buffered:!0}),m.includes("largest-contentful-paint")&&new r.PerformanceObserver(x=>{for(let v of x.getEntries())f=Math.max(f,v.startTime)}).observe({type:"largest-contentful-paint",buffered:!0})}catch{t=0}let u=()=>{o=r.performance.now(),l()};r.document.readyState==="complete"?u():r.addEventListener("load",u,{once:!0})}),pe)}function Me(r,p,{win:o=window,rootMargin:t=Mt,settleMs:f=1500}={}){let m=null,w=!1,l=()=>{w||(w=!0,m?.disconnect(),r.removeEventListener("focusin",l),r.removeEventListener("pointerdown",l),p())};r.addEventListener("focusin",l),r.addEventListener("pointerdown",l);let u=Nt(o),x=async()=>{let v=await u;o.setTimeout(l,Math.max(0,v+f-o.performance.now()))};return typeof o.IntersectionObserver=="function"?(m=new o.IntersectionObserver(v=>{v.some(k=>k.isIntersecting)&&(m.disconnect(),x())},{rootMargin:t}),m.observe(r)):x(),{run:l}}var Pt="https://challenges.cloudflare.com/turnstile/v0/api.js";var pt=15e3;function dt(r=document){ct(Pt,{doc:r})}var ht={unauthorized:4401,expired:4410,rpc:4426,deleted:4404};var Rt={fr:{assistant:"Assistant virtuel",openLabel:"Assistant virtuel, ouvrir le clavardage",dismissTeaser:"Masquer ce message",close:"Fermer le clavardage",panelTitle:"Clavardage",automated:"R\xE9ponses automatiques, tir\xE9es du contenu de ce site.",privacy:"Confidentialit\xE9",you:"Vous",messageLabel:"Votre message",send:"Envoyer",live:"Vous r\xE9pond en direct",relay:"{name} a pris le relais",relayGeneric:"Une personne de l\u2019\xE9quipe a pris le relais",handback:"L\u2019assistant virtuel a repris la conversation",oneMoment:"Un instant\u2026",reconnecting:"Connexion perdue, reconnexion\u2026",notSent:"Non envoy\xE9.",retry:"R\xE9essayer",ended:"Cette conversation est termin\xE9e.",newConversation:"Nouvelle conversation",reload:"Rechargez la page pour continuer.",unavailable:"Un probl\xE8me est survenu. R\xE9essayez dans un moment.",turnstile:"L\u2019envoi n\u2019a pas abouti. R\xE9essayez.",tooMany:"Un instant, puis r\xE9essayez.",fallbackTitle:"Laissez-nous vos coordonn\xE9es",fallbackCap:"Laissez vos coordonn\xE9es et nous vous recontacterons.",fallbackDown:"Laissez vos coordonn\xE9es et nous vous recontacterons.",name:"Votre nom",contact:"T\xE9l\xE9phone ou courriel",need:"Votre demande",fallbackSend:"Envoyer la demande",fallbackSent:"Merci, votre demande a \xE9t\xE9 transmise.",fallbackMissing:"Remplissez les trois champs.",said:"{name}\xA0: {text}",attachPhoto:"Joindre une photo",photoHint:"\xC9vitez les photos de personnes ou de pi\xE8ces d\u2019identit\xE9.",photoAlt:"Votre photo",photoSent:"Photo envoy\xE9e",photoLimit:"Trois photos au plus par conversation.",photoTooLarge:"Cette photo est trop lourde.",photoUnreadable:"Ce fichier n\u2019est pas une photo lisible.",photoFailed:"La photo n\u2019a pas pu \xEAtre envoy\xE9e. R\xE9essayez.",demoAsk:"Pouvez-vous m\u2019en dire plus sur {topic}?",demoQuestion:"Quels sont vos d\xE9lais?",demoAnswer:"(D\xE9monstration) Ici, l\u2019assistant r\xE9pond \xE0 partir du contenu de votre site.",demoHint:"Aper\xE7u\xA0: la conversation est d\xE9sactiv\xE9e."},en:{assistant:"Virtual assistant",openLabel:"Virtual assistant, open the chat",dismissTeaser:"Hide this message",close:"Close the chat",panelTitle:"Chat",automated:"Automatic answers, drawn from this site\u2019s content.",privacy:"Privacy",you:"You",messageLabel:"Your message",send:"Send",live:"Replying live",relay:"{name} took over",relayGeneric:"A team member took over",handback:"The virtual assistant is back in the conversation",oneMoment:"One moment\u2026",reconnecting:"Connection lost, reconnecting\u2026",notSent:"Not sent.",retry:"Retry",ended:"This conversation has ended.",newConversation:"New conversation",reload:"Reload the page to continue.",unavailable:"Something went wrong. Try again in a moment.",turnstile:"Sending did not go through. Try again.",tooMany:"One moment, then try again.",fallbackTitle:"Leave us your details",fallbackCap:"Leave your details and we will get back to you.",fallbackDown:"Leave your details and we will get back to you.",name:"Your name",contact:"Phone or email",need:"Your request",fallbackSend:"Send the request",fallbackSent:"Thank you, your request was sent.",fallbackMissing:"Fill in all three fields.",said:"{name}: {text}",attachPhoto:"Attach a photo",photoHint:"Avoid photos of people or of identity documents.",photoAlt:"Your photo",photoSent:"Photo sent",photoLimit:"Three photos at most per conversation.",photoTooLarge:"This photo is too large.",photoUnreadable:"This file is not a readable photo.",photoFailed:"The photo could not be sent. Try again.",demoAsk:"Can you tell me more about {topic}?",demoQuestion:"What are your lead times?",demoAnswer:"(Demo) Here, the assistant answers from your site\u2019s content.",demoHint:"Preview: the conversation is turned off."}},de=r=>String(r??"").slice(0,2).toLowerCase()==="en"?"en":"fr";function Ne(r,p={}){let o=Rt[de(r)],t={...o};for(let[f,m]of Object.entries(p??{}))typeof m=="string"&&f in o&&(t[f]=m);return t}var Y=(r,p)=>r.replace(/\{(\w+)\}/g,(o,t)=>t in p?String(p[t]):o);var he="pmw-chat",ut=[1e3,2e3,4e3,8e3,16e3,3e4],ft=3,qt="chat-lead",It=3,zt=1600,Ht=.85,Dt=3e3,Ut=7200*1e3,Bt=8e3,Ft=40,$t=3e3,wt=8e3,Jt='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="3"/><circle cx="9" cy="10" r="1.6"/><path d="m21 16-5-5-8 8"/></svg>';async function jt(r,p){let o=await r.createImageBitmap(p,{imageOrientation:"from-image"}),t=Math.min(1,zt/Math.max(o.width,o.height)),f=Math.max(1,Math.round(o.width*t)),m=Math.max(1,Math.round(o.height*t)),w=r.document.createElement("canvas");return w.width=f,w.height=m,w.getContext("2d").drawImage(o,0,0,f,m),o.close?.(),new Promise((l,u)=>w.toBlob(x=>x?l(x):u(new Error("encode")),"image/jpeg",Ht))}var Kt={fr:{nos:"vos",notre:"votre",nous:"vous"},en:{our:"your",us:"you",we:"you"}},Gt={fr:/^une question sur (.+?)\s*\?$/i,en:/^(?:a |any )?questions? (?:about|on) (.+?)\s*\?$/i};function Vt(r,p){let o=de(p),t=Ne(o),f=String(r??"").trim().match(Gt[o]);if(!f)return t.demoQuestion;let m=f[1].replace(/[\p{L}’']+/gu,w=>Kt[o][w.toLowerCase()]??w);return Y(t.demoAsk,{topic:m})}var Yt='<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 3l10 10M13 3L3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>';function i(r,p,o={},t){let f=r.createElement(p);for(let[m,w]of Object.entries(o))w!=null&&w!==!1&&f.setAttribute(m,w===!0?"":w);return t!==void 0&&(f.textContent=t),f}var Xt=/^(?:300\d{3}|600\d{3}|110600|110620)$/,Wt=r=>Xt.test(String(r??"")),_t=200,Qt=(r,p)=>{let o=!1,t=l=>{let u=r.turnstile;if(!(l.el.hasAttribute("data-pmw-rendered")||!l.shown())){l.el.setAttribute("data-pmw-rendered","");try{l.id=u.render(l.el,l.params)}catch{}}},f=()=>{if(!r.turnstile?.render)return!1;for(let l of p)t(l);return!0},m=()=>{if(dt(r.document),o||f())return;o=!0;let l=0,u=()=>{!f()&&++l<600&&r.setTimeout(u,100)};r.setTimeout(u,100)},w=l=>p.find(u=>u.form===l);for(let l of p)l.params["error-callback"]=u=>(l.ask(!1),Wt(u)&&!l.retried&&l.id!==void 0?(l.retried=!0,r.setTimeout(()=>{try{r.turnstile?.reset(l.id)}catch{l.failed=!0}},0)):l.failed=!0,!0);return{load:m,async token(l){m();let u=w(l),x=0;for(;;){if(u?.failed)return null;let v=l.querySelector('input[name="cf-turnstile-response"]')?.value??"";if(v)return v;if(!u?.asking()){if(x>=pt)return"";x+=_t}await new Promise(k=>r.setTimeout(k,_t))}},reset(l){let u=w(l);!u||u.id===void 0||u.asking()||(u.failed=!1,u.retried=!1,r.turnstile?.reset(u.id))}}};function da(r,p={}){if(r.pmwChat)return r.pmwChat;let o=p.win??window,t=o.document,f=p.WebSocket??o.WebSocket,m=p.fetch??((...e)=>o.fetch(...e)),w=[],l=p.turnstile??null,u=p.uuid??(()=>o.crypto.randomUUID()),x=p.shrink??(e=>jt(o,e)),v=p.preview??(e=>new Promise((a,n)=>{let c=new o.FileReader;c.onload=()=>a(String(c.result)),c.onerror=()=>n(c.error),c.readAsDataURL(e)})),k={};try{k=JSON.parse(r.querySelector("[data-pmw-chat-config]")?.textContent??"{}")}catch{}let X=de(k.lang),s=Ne(X,k.strings),Pe=r.dataset.pmwChatOpener??"",Re=r.querySelector(".pmw-chat__bubble"),g=p.demo??(k.demo===!0||!lt({doc:t,hostname:o.location.hostname}));t.getElementById("pmw-chat-style")||t.head.append(i(t,"style",{id:"pmw-chat-style"},it));let S=i(t,"div",{class:"pmw-chat__panel",role:"dialog","aria-modal":"true","aria-labelledby":"pmw-chat-name",hidden:!0});S.inert=!0;let qe=i(t,"div",{class:"pmw-chat__head"}),me=r.querySelector(".pmw-chat__avatar")?.cloneNode(!0)??i(t,"span",{class:"pmw-chat__avatar","aria-hidden":"true"});for(let e of me.querySelectorAll("[id]")){let a=e.id;e.id=`${a}-head`;for(let n of me.querySelectorAll(`[mask="url(#${a})"]`))n.setAttribute("mask",`url(#${a}-head)`)}let Ie=i(t,"div",{class:"pmw-chat__who"}),ze=i(t,"p",{class:"pmw-chat__name",id:"pmw-chat-name"}),W=i(t,"p",{class:"pmw-chat__role"}),He=i(t,"span",{class:"pmw-chat__face"}),De=i(t,"span",{class:"pmw-chat__dot","aria-hidden":"true",hidden:!0}),Q=i(t,"button",{type:"button",class:"pmw-chat__close","aria-label":s.close});Q.innerHTML=Yt;let Z=i(t,"p",{class:"pmw-chat__notice"},s.automated);k.privacyHref&&(Z.append(" "),Z.append(i(t,"a",{href:k.privacyHref},s.privacy))),He.append(me,De),Ie.append(ze,W,Z),qe.append(He,Ie,Q);let T=i(t,"ol",{class:"pmw-chat__log"}),gt=i(t,"li",{class:"pmw-chat__msg pmw-chat__msg--bot pmw-chat__msg--greeting"},Pe),A=i(t,"li",{class:"pmw-chat__typing","aria-hidden":"true",hidden:!0});A.append(i(t,"span"),i(t,"span"),i(t,"span")),T.append(gt);let ue=i(t,"p",{class:"pmw-chat__state",role:"status"}),Ue=i(t,"p",{class:"pmw-chat__sr","aria-live":"polite"}),Be=(e,a)=>{let n=i(t,"div",{class:"pmw-chat__check"}),c=i(t,"div",{class:"pmw-chat__check-in"});c.inert=!0;let d=le=>{n.toggleAttribute("data-ask",le),c.inert=!le,E()},_=i(t,"div",{class:"pmw-chat__turnstile"}),O={el:_,form:e,shown:a,ask:d,asking:()=>n.hasAttribute("data-ask"),params:{sitekey:k.siteKey??"",action:"chat",theme:"light",language:X,appearance:"interaction-only",size:"flexible","refresh-expired":"auto",callback:()=>{O.retried=!1,O.failed=!1,d(!1)},"before-interactive-callback":()=>d(!0)}};return w.push(O),c.append(_),n.append(c),n},y=i(t,"form",{class:"pmw-chat__composer",novalidate:!0}),L=i(t,"textarea",{id:"pmw-chat-input",name:"message",rows:"1",maxlength:String(2e3),placeholder:s.messageLabel,autocomplete:"off",disabled:g,"aria-describedby":g?"pmw-chat-demo-hint":null}),bt=i(t,"button",{type:"submit",class:"pmw-chat__send",disabled:g},s.send),fe=i(t,"div",{class:"pmw-chat__box"});fe.append(i(t,"label",{class:"pmw-chat__sr",for:"pmw-chat-input"},s.messageLabel),L,bt),g||y.append(Be(y,()=>!0)),y.append(fe),g&&y.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-demo-hint"},s.demoHint));let F=null,z=i(t,"p",{class:"pmw-chat__error pmw-chat__photo-error",role:"alert"});if(k.photos===!0){let e=i(t,"label",{class:"pmw-chat__attach"});F=i(t,"input",{type:"file",class:"pmw-chat__sr",accept:"image/*",multiple:!0,"aria-describedby":"pmw-chat-photo-hint",disabled:g}),e.innerHTML=Jt,e.prepend(F),e.append(i(t,"span",{class:"pmw-chat__sr"},s.attachPhoto)),fe.insertBefore(e,L),y.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-photo-hint"},s.photoHint),z)}let ee=i(t,"div",{class:"pmw-chat__ended",hidden:!0}),Fe=i(t,"p",{},s.ended),te=i(t,"button",{type:"button",class:"pmw-chat__restart"},s.newConversation);ee.append(Fe,te);let b=i(t,"form",{class:"pmw-chat__fallback",novalidate:!0,hidden:!0,"aria-labelledby":"pmw-chat-fb-title"}),$e=i(t,"p",{class:"pmw-chat__fb-intro"}),we=(e,a,n)=>{let c=`pmw-chat-fb-${e}`,d=i(t,"div",{class:"pmw-chat__field"});return d.append(i(t,"label",{for:c},s[e]),i(t,a,{id:c,name:e,required:!0,...n})),d},$=i(t,"p",{class:"pmw-chat__error",role:"alert"});b.append(i(t,"p",{class:"pmw-chat__fb-title",id:"pmw-chat-fb-title"},s.fallbackTitle),$e,we("name","input",{autocomplete:"name",maxlength:"100"}),we("contact","input",{autocomplete:"on",maxlength:"200"}),we("need","textarea",{rows:"3",maxlength:"2000"}),$,i(t,"button",{type:"submit",class:"pmw-chat__send"},s.fallbackSend)),g||b.insertBefore(Be(b,()=>!b.hidden),$);let M=i(t,"div",{class:"pmw-chat__body"});M.append(T,ue,ee,b),S.append(qe,M,y,Ue),r.append(S),l??(l=Qt(o,w));let J=!0,Je=0,_e=0,xt=()=>M.scrollHeight-M.scrollTop-M.clientHeight;M.addEventListener("scroll",()=>{let e=M.scrollTop;xt()<=Ft?J=!0:e<Je&&(J=!1),Je=e},{passive:!0});let vt=e=>o.requestAnimationFrame?o.requestAnimationFrame(e):o.setTimeout(e,16);function E(e=!1,a=!1){e&&(J=!0),!(!J||_e)&&(_e=vt(()=>{if(_e=0,!J)return;let n=a||!!o.matchMedia?.("(prefers-reduced-motion: reduce)").matches;M.scrollTo({top:M.scrollHeight,behavior:n?"instant":"smooth"})}))}if(typeof o.ResizeObserver=="function"){let e=new o.ResizeObserver(()=>E());e.observe(T),e.observe(y)}let h=null;if(!g)try{h=JSON.parse(o.sessionStorage.getItem(he)??"null")}catch{h=null}if(h&&typeof h.at=="number"&&!(Date.now()-h.at<Ut)){h=null;try{o.sessionStorage.removeItem(he)}catch{}}let ge=()=>{try{o.sessionStorage.setItem(he,JSON.stringify(h))}catch{}},yt=()=>{h&&(h.at=Date.now(),ge())},C=null,be=0,xe=null,j=null,ae=0,K="bot",R=null,H=!1,je=0,ve=null,ye=new Set,q=new Map,ne=new Set,ke=0,Ke=()=>new URLSearchParams(o.location.hash.slice(1)).get("pmw-chat-botName")?.trim()||null,Ge=g?Ke():null,Se=()=>g?Ge:h?.botName||null;function G(){let e=K==="human";ze.textContent=e?R||s.assistant:Se()||s.assistant,W.textContent=e?s.live:Se()?s.assistant:"",W.hidden=W.textContent==="",Z.hidden=e,De.hidden=!e,S.dataset.mode=K}G();let N=e=>{ue.textContent=e??"",ue.hidden=!e};N("");let Ve=e=>e.role==="visitor"?s.you:e.role==="owner"?e.by||R||s.assistant:Se()||s.assistant;function D(e,a){let n=i(t,"li",{class:`pmw-chat__msg pmw-chat__msg--${a}`,"data-id":e}),c=i(t,"span",{class:"pmw-chat__sr"}),d=i(t,"span",{class:"pmw-chat__text"});return n.append(c,d),T.insertBefore(n,A.parentNode===T?A:null),n}let Ye=()=>A.parentNode===T?A.previousElementSibling:T.lastElementChild,P=(e,a)=>e.classList.contains(a);function Xe(e,a,n,c){let d=i(t,"li",{class:e,role:"separator","aria-label":n}),_=i(t,"span",{class:"pmw-chat__relay-label","aria-hidden":"true"});_.append(i(t,"span",{class:a}),n),d.append(_),T.insertBefore(d,c??(A.parentNode===T?A:null)),E()}function We(e,a){for(let n=e?e.previousElementSibling:Ye();n;n=n.previousElementSibling){if(P(n,"pmw-chat__relay")||P(n,"pmw-chat__msg--owner"))return;if(P(n,"pmw-chat__msg--bot")||P(n,"pmw-chat__handback"))break}Xe("pmw-chat__relay","pmw-chat__relay-dot",a?Y(s.relay,{name:a}):s.relayGeneric,e)}function Te(e){for(let a=e?e.previousElementSibling:Ye();;a=a.previousElementSibling){if(!a||P(a,"pmw-chat__handback")||P(a,"pmw-chat__msg--bot"))return;if(P(a,"pmw-chat__relay")||P(a,"pmw-chat__msg--owner"))break}Xe("pmw-chat__handback","pmw-chat__relay-dot pmw-chat__relay-dot--back",s.handback,e)}let Qe=e=>[...T.querySelectorAll("li[data-id]")].find(a=>a.dataset.id===e),I=(e,a,n)=>{e.firstChild.textContent=Y(s.said,{name:Ve(a),text:""}),e.lastChild.textContent=n===""&&a.photos?.length&&!e.querySelector("img")?s.photoSent:n};function U(){A.hidden=!0,o.clearTimeout(ve)}function Le(e){A.hidden=!1,T.append(A),o.clearTimeout(ve),e&&(ve=o.setTimeout(U,e)),E()}function Ze(e,{announce:a}){if(ye.has(e.seq))return;ye.add(e.seq),ae=Math.max(ae,e.seq);let n=Qe(e.id);n||(n=D(e.id,e.role),e.role==="owner"?We(n,e.by||R):e.role==="bot"&&Te(n)),n.classList.remove("is-streaming","is-pending","is-failed"),n.querySelector(".pmw-chat__retry")?.remove(),I(n,e,e.text),e.role==="visitor"?(q.delete(e.id),e.photos?.length&&ne.add(e.id)):(U(),a&&(Ue.textContent=Y(s.said,{name:Ve(e),text:e.text})),S.hidden&&r.setAttribute("data-unread","")),E()}function kt(e,a){U();let n=Qe(e);n||(n=D(e,"bot"),Te(n),n.classList.add("is-streaming"),I(n,{role:"bot"},"")),n.lastChild.textContent+=a,E()}if(g){I(D("demo-question","visitor"),{role:"visitor"},Vt(Pe,X));let e=D("demo-answer","bot");I(e,{role:"bot"},s.demoAnswer),o.addEventListener("hashchange",()=>{Ge=Ke(),G(),I(e,{role:"bot"},s.demoAnswer)})}function oe(e){if(e.failed=!0,e.li.classList.remove("is-pending"),e.li.classList.add("is-failed"),e.li.querySelector(".pmw-chat__retry"))return;let a=i(t,"span",{class:"pmw-chat__retry"},`${s.notSent} `),n=i(t,"button",{type:"button"},s.retry);n.addEventListener("click",()=>{e.failed=!1,e.tries=0,a.remove(),e.li.classList.replace("is-failed","is-pending"),h?re()?Ee(e):B():Ae()}),a.append(n),e.li.append(a)}let re=()=>!!C&&C.readyState===1;function Ee(e){if(!(e.failed||!re())){if(e.tries>=ft)return oe(e);e.tries++,C.send(JSON.stringify({type:"message",id:e.id,text:e.text}))}}function B(){if(!h||H||C)return;o.clearTimeout(xe);let e=o.location.protocol==="https:"?"wss:":"ws:",a=new URLSearchParams({c:h.c,k:h.k}),n=new f(`${e}//${o.location.host}/api/chat/ws?${a}`);C=n,n.onopen=()=>{be=0,ce&&(V(),Le(wt)),N(""),n.send(JSON.stringify({type:"hello",since:ae}));for(let c of q.values())Ee(c)},n.onmessage=c=>{let d;try{d=JSON.parse(c.data)}catch{return}Tt(d)},n.onclose=c=>{C===n&&(C=null);for(let _ of q.values())_.tries>=ft&&oe(_);if(c.code>=4e3&&c.code<5e3)return St(c.code);if(H)return;V(),N(s.reconnecting);let d=ut[Math.min(be,ut.length-1)];be++,xe=o.setTimeout(B,d)}}function St(e){if(e===ht.rpc)return ie(s.reload,!1);ie(s.ended,!0)}function ie(e,a){H=!0,o.clearTimeout(xe),N(""),Fe.textContent=e,te.hidden=!a,ee.hidden=!1,y.hidden=!0;for(let n of q.values())oe(n);E()}function et(e){K=e.mode==="human"?"human":"bot",R=typeof e.ownerName=="string"?e.ownerName:null,G(),K==="human"?We(null,R):Te(null),e.closed&&ie(s.ended,!0)}function Tt(e){switch(e?.type){case"history":typeof e.ownerName=="string"&&(R=e.ownerName);for(let a of e.messages??[])Ze(a,{announce:!1});return et(e);case"message":return yt(),Ze(e.msg,{announce:e.msg?.role!=="visitor"});case"delta":return kt(e.id,e.text);case"typing":return e.role==="visitor"?void 0:Le(wt);case"status":return et(e);case"fallback":return nt(e.reason==="cap"?s.fallbackCap:s.fallbackDown);case"lead":return at();case"error":(e.code==="closed"||e.code==="deleted")&&ie(s.ended,!0)}}let tt=!1;function at(){if(!(tt||h?.lead)){tt=!0,h&&(h.lead=!0,ge());try{o.pmw?.event(qt)}catch{}}}let se=new Set;async function Ce(e,a){let n="";if(se.has(e)){se.delete(e);try{l.reset(e)}catch{}}try{n=await l.token(e)}catch{n=""}if(n===null)return se.add(e),{ok:!1,error:s.turnstile,cap:!1,turnstile:!0};let c,d=null;try{c=await m("/api/chat/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:n,lang:X,page:o.location.pathname,...a})}),d=await c.json()}catch{c=null}return se.add(e),c?.ok&&d?{ok:!0,data:d}:{ok:!1,error:c?.status===403?s.turnstile:c?.status===429?s.tooMany:null,cap:c?.status===409&&d?.error==="cap",turnstile:c?.status===403}}let ce=null,V=()=>{o.clearTimeout(ce),ce=null};function Ae(){return j||h||(N(""),Le(),ce=o.setTimeout(()=>N(s.oneMoment),Bt),j=Ce(y,{}).then(e=>{if(j=null,e.ok&&e.data.conversationId&&e.data.visitorKey){h={c:e.data.conversationId,k:e.data.visitorKey,botName:typeof e.data.botName=="string"?e.data.botName:null,at:Date.now()},ge(),G(),B();return}V(),U();for(let a of q.values())oe(a);if(e.error)return N(e.error);N(""),nt(e.cap?s.fallbackCap:s.fallbackDown)})),j}function nt(e){U(),V(),N(""),$e.textContent=e,b.hidden=!1,y.hidden=!0,g||l.load(),b.querySelector("input")?.focus()}b.addEventListener("submit",async e=>{e.preventDefault();let a=O=>b.elements[O].value.trim(),n={name:a("name"),contact:a("contact"),need:a("need")};if(!n.name||!n.contact||!n.need){$.textContent=s.fallbackMissing;return}$.textContent="";let c=b.querySelector('button[type="submit"]');if(c.disabled)return;c.disabled=!0;let d={fallbackLead:n,...h?.c&&h?.k?{c:h.c,k:h.k}:{}},_=await Ce(b,d);if(!_.ok&&_.turnstile&&(_=await Ce(b,d)),c.disabled=!1,!_.ok){$.textContent=_.error??s.unavailable;return}b.replaceChildren(i(t,"p",{class:"pmw-chat__fb-done",role:"status"},s.fallbackSent)),at()});let Lt={413:"photoTooLarge",415:"photoUnreadable",409:"photoLimit",429:"tooMany"};async function Et(e){let a,n;try{a=await x(e),n=await v(a)}catch{z.textContent=s.photoUnreadable;return}let c=u(),d=D(c,"visitor");d.classList.add("is-pending");let _=i(t,"img",{class:"pmw-chat__photo",src:n,alt:s.photoAlt});_.addEventListener("load",()=>E(),{once:!0}),d.insertBefore(_,d.lastChild),I(d,{role:"visitor"},""),E(!0),h||await Ae();let O=null;if(h){let le=new URLSearchParams({c:h.c,k:h.k,id:c});try{O=await m(`/api/chat/photo?${le}`,{method:"POST",headers:{"content-type":"image/jpeg"},body:a})}catch{O=null}}if(O?.ok){d.classList.remove("is-pending"),ne.add(c),C||B();return}d.remove(),z.textContent=s[Lt[O?.status]]??s.photoFailed}F?.addEventListener("change",async()=>{let e=[...F.files??[]];if(F.value="",z.textContent="",H||g||e.length===0)return;let a=It-ne.size-ke;e.length>a&&(z.textContent=s.photoLimit);let n=e.slice(0,Math.max(0,a));ke+=n.length;for(let c of n)try{await Et(c)}finally{ke--}});function ot(){let e=L.value.trim();if(!e||H||g)return;L.value="",rt();let a={id:u(),text:e.slice(0,2e3),tries:0,failed:!1};a.li=D(a.id,"visitor"),a.li.classList.add("is-pending"),I(a.li,{role:"visitor"},a.text),q.set(a.id,a),E(!0),h?re()?Ee(a):B():Ae()}y.addEventListener("submit",e=>{e.preventDefault(),ot()}),L.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),ot())});let rt=()=>{L.style.height="auto",L.style.height=L.value?`${Math.min(L.scrollHeight,132)}px`:""};L.addEventListener("input",()=>{rt();let e=Date.now();re()&&e-je>$t&&(je=e,C.send(JSON.stringify({type:"typing"})))}),te.addEventListener("click",()=>{h=null;try{o.sessionStorage.removeItem(he)}catch{}try{C?.close(1e3)}catch{}C=null,H=!1,ae=0,ye.clear(),q.clear(),ne.clear(),z.textContent="",K="bot",R=null,G();for(let e of[...T.querySelectorAll("li[data-id], .pmw-chat__relay, .pmw-chat__handback")])e.remove();U(),V(),ee.hidden=!0,y.hidden=!1,L.focus()});let Ct=()=>[...S.querySelectorAll('a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])')].filter(e=>!e.disabled&&!e.closest("[hidden]"));S.addEventListener("keydown",e=>{if(e.key==="Escape"){e.preventDefault(),Oe();return}if(e.key!=="Tab")return;let a=Ct();if(a.length===0)return;let n=a[0],c=a[a.length-1];e.shiftKey&&t.activeElement===n?(e.preventDefault(),c.focus()):!e.shiftKey&&t.activeElement===c&&(e.preventDefault(),n.focus())}),Q.addEventListener("click",e=>Oe({keyboard:e.detail===0}));function At(){g||l.load(),S.hidden=!1,S.inert=!1,r.setAttribute("data-open",""),r.removeAttribute("data-unread"),h&&B(),(g?Q:y.hidden?b.hidden?te:b.querySelector("input"):L)?.focus(),E(!0,!0)}function Oe({keyboard:e=!0}={}){S.hidden=!0,S.inert=!0,r.removeAttribute("data-open"),e&&Re?.focus(),r.dispatchEvent(new o.FocusEvent("focusout",{relatedTarget:e?Re:null}))}return g||Me(r,()=>l.load(),{win:o,settleMs:Dt}),r.pmwChat={open:At,close:Oe,panel:S},r.pmwChat}export{ut as BACKOFF_MS,qt as GOAL,Ut as IDLE_MS,It as MAX_PHOTOS,ft as MAX_TRIES,zt as PHOTO_EDGE,Ht as PHOTO_QUALITY,Ft as PIN_SLACK,he as SESSION_KEY,Bt as SLOW_START_MS,Dt as WARM_MS,Vt as demoQuestion,da as mountChat,Wt as retryable};
1
+ var st=`.pmw-chat__panel{position:fixed;z-index:81;inset:0;display:flex;flex-direction:column;background:var(--pmw-chat-panel-bg, #ffffff);color:var(--pmw-chat-fg, #1f2328);font-family:var(--pmw-chat-font, inherit);font-size:16px;line-height:1.45}.pmw-chat__panel[hidden]{display:flex!important;opacity:0;pointer-events:none}.pmw-chat__panel [hidden]{display:none!important}@media(min-width:640px){.pmw-chat__panel{inset:auto;right:calc(env(safe-area-inset-right,0px) + var(--pmw-chat-right, 16px));bottom:calc(env(safe-area-inset-bottom,0px) + var(--pmw-chat-bottom, 16px));width:380px;height:min(600px,calc(100dvh - 16px - env(safe-area-inset-bottom,0px) - var(--pmw-chat-bottom, 16px)));border:1px solid var(--pmw-chat-line, #e6e9f0);border-radius:20px;overflow:hidden;box-shadow:0 18px 48px #1018282e}}.pmw-chat__panel :where(button){font:inherit;cursor:pointer}.pmw-chat__panel :focus-visible{outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}.pmw-chat__head{display:flex;align-items:center;gap:12px;padding:14px 10px 14px 16px;border-bottom:1px solid var(--pmw-chat-line, #e6e9f0)}@media(max-width:639.98px){.pmw-chat__head{padding:12px 8px 12px 16px}}.pmw-chat__face{position:relative;flex:none;display:flex}.pmw-chat__head .pmw-chat__avatar{width:44px;height:44px;box-shadow:none}.pmw-chat__head .pmw-chat__avatar--icon{box-shadow:0 0 0 1.5px var(--pmw-chat-avatar-ring, transparent)}.pmw-chat__head .pmw-chat__avatar img{width:44px;height:44px}.pmw-chat__head .pmw-chat__avatar--logo img{width:32px;height:32px}.pmw-chat__head .pmw-chat__avatar svg{width:100%;height:100%}.pmw-chat__dot{position:absolute;right:-1px;bottom:-1px;width:12px;height:12px;border-radius:50%;background:var(--pmw-chat-live, #1a7f37);box-shadow:0 0 0 2px var(--pmw-chat-panel-bg, #ffffff)}.pmw-chat__who{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}.pmw-chat__name{margin:0;font-weight:600;font-size:16px}.pmw-chat__role,.pmw-chat__notice{margin:0;font-size:13px;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__panel[data-mode=human] .pmw-chat__role{color:var(--pmw-chat-live, #1a7f37);font-weight:500}.pmw-chat__notice a{color:var(--pmw-chat-link, #0a1b3d);text-decoration:underline;text-underline-offset:2px}.pmw-chat__close{flex:none;width:44px;height:44px;padding:0;border:0;border-radius:50%;display:flex;align-items:center;justify-content:center;background:transparent;color:var(--pmw-chat-fg, #1f2328)}.pmw-chat__close:hover{background:var(--pmw-chat-thread-bg, #f7f8fb)}.pmw-chat__close svg{width:18px;height:18px}.pmw-chat__body{flex:1;min-height:0;display:flex;flex-direction:column;overflow-y:auto;padding:18px 16px;background:var(--pmw-chat-thread-bg, #f7f8fb)}.pmw-chat__log{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:6px}.pmw-chat__log>li{margin-top:4px}.pmw-chat__log>li:first-child,.pmw-chat__msg--bot+.pmw-chat__msg--bot,.pmw-chat__msg--bot+.pmw-chat__typing,.pmw-chat__msg--owner+.pmw-chat__msg--owner,.pmw-chat__msg--owner+.pmw-chat__typing,.pmw-chat__msg--visitor+.pmw-chat__msg--visitor{margin-top:0}.pmw-chat__msg{max-width:82%;padding:10px 14px;border-radius:18px;white-space:pre-wrap;overflow-wrap:anywhere}.pmw-chat__msg--bot,.pmw-chat__msg--owner{align-self:flex-start;border-bottom-left-radius:6px;color:var(--pmw-chat-fg, #1f2328)}.pmw-chat__msg--bot{background:var(--pmw-chat-other-bg, #ffffff);border:1px solid var(--pmw-chat-line, #e6e9f0)}.pmw-chat__msg--owner{background:var(--pmw-chat-owner-bg, #eef2fa);border:1px solid var(--pmw-chat-owner-border, #d5ddef)}.pmw-chat__msg--visitor{align-self:flex-end;background:var(--pmw-chat-accent, #0a1b3d);color:var(--pmw-chat-accent-fg, #ffffff);border-bottom-right-radius:6px}.pmw-chat__msg--bot+.pmw-chat__msg--bot,.pmw-chat__msg--owner+.pmw-chat__msg--owner{border-top-left-radius:6px}.pmw-chat__msg--visitor+.pmw-chat__msg--visitor{border-top-right-radius:6px}.pmw-chat__msg:has(>.pmw-chat__photo){padding:4px}.pmw-chat__msg:has(>.pmw-chat__photo) .pmw-chat__text:empty{display:none}.pmw-chat__msg.is-pending{opacity:.75}.pmw-chat__msg.is-failed{outline:2px solid var(--pmw-chat-error, #b42318);outline-offset:2px}.pmw-chat__retry{display:block;margin-top:4px;font-size:14px}.pmw-chat__retry button{padding:0;border:0;background:none;color:inherit;text-decoration:underline}.pmw-chat__typing{align-self:flex-start;display:flex;gap:5px;padding:14px 16px;border-radius:18px 18px 18px 6px;background:var(--pmw-chat-other-bg, #ffffff);border:1px solid var(--pmw-chat-line, #e6e9f0)}.pmw-chat__typing span{width:7px;height:7px;border-radius:50%;background:var(--pmw-chat-muted, #4b5563);animation:pmw-chat-dot 1.2s infinite ease-in-out}.pmw-chat__typing span:nth-child(2){animation-delay:.15s}.pmw-chat__typing span:nth-child(3){animation-delay:.3s}@keyframes pmw-chat-dot{0%,80%,to{opacity:.3}40%{opacity:1}}@media(prefers-reduced-motion:reduce){.pmw-chat__typing span{animation:none;opacity:.7}}.pmw-chat__log>.pmw-chat__relay,.pmw-chat__log>.pmw-chat__handback{align-self:stretch;margin:18px 0 8px;display:flex;align-items:center;gap:10px;font-size:13px;font-weight:500;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__relay:before,.pmw-chat__relay:after,.pmw-chat__handback:before,.pmw-chat__handback:after{content:"";flex:1;min-width:16px;height:1px;background:var(--pmw-chat-rule, #cfd5e1)}.pmw-chat__relay-label{display:flex;align-items:center;gap:6px;text-align:center}.pmw-chat__relay-dot{flex:none;width:8px;height:8px;border-radius:50%;background:var(--pmw-chat-live, #1a7f37)}.pmw-chat__relay-dot--back{background:var(--pmw-chat-muted, #4b5563)}.pmw-chat__log>.pmw-chat__relay+li,.pmw-chat__log>.pmw-chat__handback+li{margin-top:0}.pmw-chat__state{margin:8px 0 0;font-size:14px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__state:empty{display:none}.pmw-chat__ended{margin-top:22px;display:flex;flex-direction:column;align-items:center;gap:12px;text-align:center}.pmw-chat__ended:before{content:"";align-self:stretch;height:1px;background:var(--pmw-chat-line, #e6e9f0)}.pmw-chat__ended p{margin:0;font-size:15px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__restart{min-height:44px;padding:0 20px;border-radius:22px;border:1px solid var(--pmw-chat-link, #0a1b3d);background:var(--pmw-chat-panel-bg, #ffffff);color:var(--pmw-chat-link, #0a1b3d);font-weight:600}.pmw-chat__composer{--pmw-chat-gap: 8px;display:flex;flex-direction:column;gap:var(--pmw-chat-gap);padding:14px 16px 16px;border-top:1px solid var(--pmw-chat-line, #e6e9f0);background:var(--pmw-chat-panel-bg, #ffffff)}@media(max-width:639.98px){.pmw-chat__composer{padding:12px 16px calc(14px + env(safe-area-inset-bottom,0px))}}.pmw-chat__box{display:flex;align-items:flex-end;gap:6px;padding:4px;border-radius:24px;border:1px solid var(--pmw-chat-field-border, #7d8590);background:#fff;color:var(--pmw-chat-field-fg, #1f2328)}.pmw-chat__box textarea{flex:1;min-width:0;box-sizing:border-box;min-height:44px;max-height:132px;resize:none;margin:0;padding:10px 2px;border:0;border-radius:0;background:transparent;color:inherit;font:inherit;font-size:16px;line-height:1.5}.pmw-chat__box textarea::placeholder{color:#6b7280;opacity:1}@supports selector(:has(*)){.pmw-chat__box textarea:focus-visible{outline:none}.pmw-chat__box:has(textarea:focus-visible){outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}}.pmw-chat__send{flex:none;min-height:44px;padding:0 18px;border:0;border-radius:22px;font-weight:600;background:var(--pmw-chat-accent, #0a1b3d);color:var(--pmw-chat-accent-fg, #ffffff)}.pmw-chat__send:disabled,.pmw-chat__box textarea:disabled{cursor:not-allowed;opacity:.6}.pmw-chat__check{position:relative;display:grid;grid-template-rows:0fr;margin-bottom:calc(-1 * var(--pmw-chat-gap, 0px));transition:grid-template-rows .25s ease,margin-bottom .25s ease}.pmw-chat__check[data-ask]{grid-template-rows:1fr;margin-bottom:4px}.pmw-chat__check-in{min-height:0;overflow:hidden}.pmw-chat__check:not([data-ask]) .pmw-chat__check-in{position:absolute;top:0;left:0;right:0;overflow:visible;opacity:0;pointer-events:none}@media(prefers-reduced-motion:reduce){.pmw-chat__check{transition:none}}.pmw-chat__attach{flex:none;position:relative;width:44px;height:44px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;color:inherit}.pmw-chat__attach:hover{background:#eef0f4}.pmw-chat__attach svg{width:22px;height:22px}.pmw-chat__attach:focus-within{outline:3px solid var(--pmw-chat-focus, #0a1b3d);outline-offset:2px}.pmw-chat__hint{margin:0 8px;font-size:13px;line-height:1.4;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__composer .pmw-chat__photo-error{margin:0 8px}.pmw-chat__photo{display:block;max-width:100%;max-height:220px;border-radius:14px}.pmw-chat__fallback{--pmw-chat-gap: 14px;display:flex;flex-direction:column;gap:var(--pmw-chat-gap);margin-top:16px}.pmw-chat__fb-title{margin:0;font-size:20px;font-weight:600;line-height:1.3}.pmw-chat__fb-intro{margin:-8px 0 0;font-size:15px;color:var(--pmw-chat-muted, #4b5563)}.pmw-chat__field{display:flex;flex-direction:column;gap:4px}.pmw-chat__field label{font-size:14px;font-weight:600}.pmw-chat__field input,.pmw-chat__field textarea{font:inherit;font-size:16px;padding:10px 14px;border-radius:12px;resize:none;border:1px solid var(--pmw-chat-field-border, #7d8590);background:#fff;color:var(--pmw-chat-field-fg, #1f2328)}.pmw-chat__fallback .pmw-chat__send{align-self:stretch;min-height:48px;border-radius:24px}.pmw-chat__error{margin:0;font-size:14px;color:var(--pmw-chat-error, #b42318)}.pmw-chat__error:empty{display:none}.pmw-chat__sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}.pmw-chat[data-unread] .pmw-chat__bubble{position:relative}.pmw-chat[data-unread] .pmw-chat__bubble:after{content:"";position:absolute;top:2px;left:38px;width:12px;height:12px;border-radius:50%;background:var(--pmw-chat-error, #b42318);box-shadow:0 0 0 2px #fff}.pmw-chat__fb-done{margin:12px 0 0;padding:12px 14px;border-radius:12px;background:#e9f6ee;color:#14532d;border:1px solid #b7dfc4;font-weight:500}
2
+ `;var Mt="400px 0px";var ct=new Set,pe=null;function lt(r,{doc:p=document,attrs:o={}}={}){if(ct.has(r)||(ct.add(r),p.querySelector(`script[src="${r}"]`)))return;let t=p.createElement("script");t.src=r,t.async=!0;for(let[f,m]of Object.entries(o))t.setAttribute(f,m);p.head.append(t)}function pt({doc:r=document,hostname:p=globalThis.location?.hostname??""}={}){let o=r.getElementById("pmw-hosts");if(!o)return!1;let t;try{t=JSON.parse(o.textContent??"")}catch{return!1}if(!Array.isArray(t))return!1;let f=String(p).toLowerCase();return t.some(m=>typeof m=="string"&&m.toLowerCase()===f)}function Nt(r){return pe||(pe=new Promise(p=>{let o=null,t=null,f=0,m=r.PerformanceObserver?.supportedEntryTypes??[],w=typeof r.PerformanceObserver=="function"&&m.includes("paint"),l=()=>{o===null||w&&t===null||p(Math.max(o,t??0,f))};if(w)try{new r.PerformanceObserver(x=>{for(let v of x.getEntries())v.name==="first-contentful-paint"&&(t=v.startTime);l()}).observe({type:"paint",buffered:!0}),m.includes("largest-contentful-paint")&&new r.PerformanceObserver(x=>{for(let v of x.getEntries())f=Math.max(f,v.startTime)}).observe({type:"largest-contentful-paint",buffered:!0})}catch{t=0}let u=()=>{o=r.performance.now(),l()};r.document.readyState==="complete"?u():r.addEventListener("load",u,{once:!0})}),pe)}function Ne(r,p,{win:o=window,rootMargin:t=Mt,settleMs:f=1500}={}){let m=null,w=!1,l=()=>{w||(w=!0,m?.disconnect(),r.removeEventListener("focusin",l),r.removeEventListener("pointerdown",l),p())};r.addEventListener("focusin",l),r.addEventListener("pointerdown",l);let u=Nt(o),x=async()=>{let v=await u;o.setTimeout(l,Math.max(0,v+f-o.performance.now()))};return typeof o.IntersectionObserver=="function"?(m=new o.IntersectionObserver(v=>{v.some(S=>S.isIntersecting)&&(m.disconnect(),x())},{rootMargin:t}),m.observe(r)):x(),{run:l}}var Pt="https://challenges.cloudflare.com/turnstile/v0/api.js";var dt=15e3;function ht(r=document){lt(Pt,{doc:r})}var mt={unauthorized:4401,expired:4410,rpc:4426,deleted:4404};var Rt={fr:{assistant:"Assistant virtuel",openLabel:"Assistant virtuel, ouvrir le clavardage",dismissTeaser:"Masquer ce message",close:"Fermer le clavardage",panelTitle:"Clavardage",automated:"R\xE9ponses automatiques, tir\xE9es du contenu de ce site.",privacy:"Confidentialit\xE9",you:"Vous",messageLabel:"Votre message",send:"Envoyer",live:"Vous r\xE9pond en direct",relay:"{name} a pris le relais",relayGeneric:"Une personne de l\u2019\xE9quipe a pris le relais",handback:"L\u2019assistant virtuel a repris la conversation",oneMoment:"Un instant\u2026",reconnecting:"Connexion perdue, reconnexion\u2026",notSent:"Non envoy\xE9.",retry:"R\xE9essayer",ended:"Cette conversation est termin\xE9e.",newConversation:"Nouvelle conversation",reload:"Rechargez la page pour continuer.",unavailable:"Un probl\xE8me est survenu. R\xE9essayez dans un moment.",turnstile:"L\u2019envoi n\u2019a pas abouti. R\xE9essayez.",tooMany:"Un instant, puis r\xE9essayez.",fallbackTitle:"Laissez-nous vos coordonn\xE9es",fallbackCap:"Laissez vos coordonn\xE9es et nous vous recontacterons.",fallbackDown:"Laissez vos coordonn\xE9es et nous vous recontacterons.",name:"Votre nom",contact:"T\xE9l\xE9phone ou courriel",need:"Votre demande",fallbackSend:"Envoyer la demande",fallbackSent:"Merci, votre demande a \xE9t\xE9 transmise.",fallbackMissing:"Remplissez les trois champs.",said:"{name}\xA0: {text}",attachPhoto:"Joindre une photo",photoHint:"\xC9vitez les photos de personnes ou de pi\xE8ces d\u2019identit\xE9.",photoAlt:"Votre photo",photoSent:"Photo envoy\xE9e",photoLimit:"Trois photos au plus par conversation.",photoTooLarge:"Cette photo est trop lourde.",photoUnreadable:"Ce fichier n\u2019est pas une photo lisible.",photoFailed:"La photo n\u2019a pas pu \xEAtre envoy\xE9e. R\xE9essayez.",demoAsk:"Pouvez-vous m\u2019en dire plus sur {topic}?",demoQuestion:"Quels sont vos d\xE9lais?",demoAnswer:"(D\xE9monstration) Ici, l\u2019assistant r\xE9pond \xE0 partir du contenu de votre site.",demoHint:"Aper\xE7u\xA0: la conversation est d\xE9sactiv\xE9e."},en:{assistant:"Virtual assistant",openLabel:"Virtual assistant, open the chat",dismissTeaser:"Hide this message",close:"Close the chat",panelTitle:"Chat",automated:"Automatic answers, drawn from this site\u2019s content.",privacy:"Privacy",you:"You",messageLabel:"Your message",send:"Send",live:"Replying live",relay:"{name} took over",relayGeneric:"A team member took over",handback:"The virtual assistant is back in the conversation",oneMoment:"One moment\u2026",reconnecting:"Connection lost, reconnecting\u2026",notSent:"Not sent.",retry:"Retry",ended:"This conversation has ended.",newConversation:"New conversation",reload:"Reload the page to continue.",unavailable:"Something went wrong. Try again in a moment.",turnstile:"Sending did not go through. Try again.",tooMany:"One moment, then try again.",fallbackTitle:"Leave us your details",fallbackCap:"Leave your details and we will get back to you.",fallbackDown:"Leave your details and we will get back to you.",name:"Your name",contact:"Phone or email",need:"Your request",fallbackSend:"Send the request",fallbackSent:"Thank you, your request was sent.",fallbackMissing:"Fill in all three fields.",said:"{name}: {text}",attachPhoto:"Attach a photo",photoHint:"Avoid photos of people or of identity documents.",photoAlt:"Your photo",photoSent:"Photo sent",photoLimit:"Three photos at most per conversation.",photoTooLarge:"This photo is too large.",photoUnreadable:"This file is not a readable photo.",photoFailed:"The photo could not be sent. Try again.",demoAsk:"Can you tell me more about {topic}?",demoQuestion:"What are your lead times?",demoAnswer:"(Demo) Here, the assistant answers from your site\u2019s content.",demoHint:"Preview: the conversation is turned off."}},de=r=>String(r??"").slice(0,2).toLowerCase()==="en"?"en":"fr";function Pe(r,p={}){let o=Rt[de(r)],t={...o};for(let[f,m]of Object.entries(p??{}))typeof m=="string"&&f in o&&(t[f]=m);return t}var Y=(r,p)=>r.replace(/\{(\w+)\}/g,(o,t)=>t in p?String(p[t]):o);var he="pmw-chat",ft=[1e3,2e3,4e3,8e3,16e3,3e4],wt=3,qt="chat-lead",It=3,zt=1600,Ht=.85,Dt=3e3,Ut=7200*1e3,Bt=8e3,Ft=40,$t=3e3,_t=8e3,Jt='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="14" rx="3"/><circle cx="9" cy="10" r="1.6"/><path d="m21 16-5-5-8 8"/></svg>';async function jt(r,p){let o=await r.createImageBitmap(p,{imageOrientation:"from-image"}),t=Math.min(1,zt/Math.max(o.width,o.height)),f=Math.max(1,Math.round(o.width*t)),m=Math.max(1,Math.round(o.height*t)),w=r.document.createElement("canvas");return w.width=f,w.height=m,w.getContext("2d").drawImage(o,0,0,f,m),o.close?.(),new Promise((l,u)=>w.toBlob(x=>x?l(x):u(new Error("encode")),"image/jpeg",Ht))}var Kt={fr:{nos:"vos",notre:"votre",nous:"vous"},en:{our:"your",us:"you",we:"you"}},Gt={fr:/^une question sur (.+?)\s*\?$/i,en:/^(?:a |any )?questions? (?:about|on) (.+?)\s*\?$/i};function Vt(r,p){let o=de(p),t=Pe(o),f=String(r??"").trim().match(Gt[o]);if(!f)return t.demoQuestion;let m=f[1].replace(/[\p{L}’']+/gu,w=>Kt[o][w.toLowerCase()]??w);return Y(t.demoAsk,{topic:m})}var Yt='<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 3l10 10M13 3L3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>';function i(r,p,o={},t){let f=r.createElement(p);for(let[m,w]of Object.entries(o))w!=null&&w!==!1&&f.setAttribute(m,w===!0?"":w);return t!==void 0&&(f.textContent=t),f}var Xt=/^(?:300\d{3}|600\d{3}|110600|110620)$/,Wt=r=>Xt.test(String(r??"")),gt=200,Qt=(r,p)=>{let o=!1,t=l=>{let u=r.turnstile;if(!(l.el.hasAttribute("data-pmw-rendered")||!l.shown())){l.el.setAttribute("data-pmw-rendered","");try{l.id=u.render(l.el,l.params)}catch{}}},f=()=>{if(!r.turnstile?.render)return!1;for(let l of p)t(l);return!0},m=()=>{if(ht(r.document),o||f())return;o=!0;let l=0,u=()=>{!f()&&++l<600&&r.setTimeout(u,100)};r.setTimeout(u,100)},w=l=>p.find(u=>u.form===l);for(let l of p)l.params["error-callback"]=u=>(l.ask(!1),Wt(u)&&!l.retried&&l.id!==void 0?(l.retried=!0,r.setTimeout(()=>{try{r.turnstile?.reset(l.id)}catch{l.failed=!0}},0)):l.failed=!0,!0);return{load:m,async token(l){m();let u=w(l),x=0;for(;;){if(u?.failed)return null;let v=l.querySelector('input[name="cf-turnstile-response"]')?.value??"";if(v)return v;if(!u?.asking()){if(x>=dt)return"";x+=gt}await new Promise(S=>r.setTimeout(S,gt))}},reset(l){let u=w(l);!u||u.id===void 0||u.asking()||(u.failed=!1,u.retried=!1,r.turnstile?.reset(u.id))}}};function da(r,p={}){if(r.pmwChat)return r.pmwChat;let o=p.win??window,t=o.document,f=p.WebSocket??o.WebSocket,m=p.fetch??((...e)=>o.fetch(...e)),w=[],l=p.turnstile??null,u=p.uuid??(()=>o.crypto.randomUUID()),x=p.shrink??(e=>jt(o,e)),v=p.preview??(e=>new Promise((a,n)=>{let c=new o.FileReader;c.onload=()=>a(String(c.result)),c.onerror=()=>n(c.error),c.readAsDataURL(e)})),S={};try{S=JSON.parse(r.querySelector("[data-pmw-chat-config]")?.textContent??"{}")}catch{}let X=de(S.lang),s=Pe(X,S.strings),Re=r.dataset.pmwChatOpener??"",qe=r.querySelector(".pmw-chat__bubble"),g=p.demo??(S.demo===!0||!pt({doc:t,hostname:o.location.hostname}));t.getElementById("pmw-chat-style")||t.head.append(i(t,"style",{id:"pmw-chat-style"},st));let T=i(t,"div",{class:"pmw-chat__panel",role:"dialog","aria-modal":"true","aria-labelledby":"pmw-chat-name",hidden:!0});T.inert=!0;let Ie=i(t,"div",{class:"pmw-chat__head"}),me=r.querySelector(".pmw-chat__avatar")?.cloneNode(!0)??i(t,"span",{class:"pmw-chat__avatar","aria-hidden":"true"});for(let e of me.querySelectorAll("[id]")){let a=e.id;e.id=`${a}-head`;for(let n of me.querySelectorAll(`[mask="url(#${a})"]`))n.setAttribute("mask",`url(#${a}-head)`)}let ze=i(t,"div",{class:"pmw-chat__who"}),He=i(t,"p",{class:"pmw-chat__name",id:"pmw-chat-name"}),W=i(t,"p",{class:"pmw-chat__role"}),De=i(t,"span",{class:"pmw-chat__face"}),Ue=i(t,"span",{class:"pmw-chat__dot","aria-hidden":"true",hidden:!0}),Q=i(t,"button",{type:"button",class:"pmw-chat__close","aria-label":s.close});Q.innerHTML=Yt;let Z=i(t,"p",{class:"pmw-chat__notice"},s.automated);S.privacyHref&&(Z.append(" "),Z.append(i(t,"a",{href:S.privacyHref},s.privacy))),De.append(me,Ue),ze.append(He,W,Z),Ie.append(De,ze,Q);let y=i(t,"ol",{class:"pmw-chat__log"}),ue=i(t,"li",{class:"pmw-chat__msg pmw-chat__msg--bot pmw-chat__msg--greeting"},Re),A=i(t,"li",{class:"pmw-chat__typing","aria-hidden":"true",hidden:!0});A.append(i(t,"span"),i(t,"span"),i(t,"span")),y.append(ue);let fe=i(t,"p",{class:"pmw-chat__state",role:"status"}),Be=i(t,"p",{class:"pmw-chat__sr","aria-live":"polite"}),Fe=(e,a)=>{let n=i(t,"div",{class:"pmw-chat__check"}),c=i(t,"div",{class:"pmw-chat__check-in"});c.inert=!0;let d=le=>{n.toggleAttribute("data-ask",le),c.inert=!le,E()},_=i(t,"div",{class:"pmw-chat__turnstile"}),O={el:_,form:e,shown:a,ask:d,asking:()=>n.hasAttribute("data-ask"),params:{sitekey:S.siteKey??"",action:"chat",theme:"light",language:X,appearance:"interaction-only",size:"flexible","refresh-expired":"auto",callback:()=>{O.retried=!1,O.failed=!1,d(!1)},"before-interactive-callback":()=>d(!0)}};return w.push(O),c.append(_),n.append(c),n},k=i(t,"form",{class:"pmw-chat__composer",novalidate:!0}),L=i(t,"textarea",{id:"pmw-chat-input",name:"message",rows:"1",maxlength:String(2e3),placeholder:s.messageLabel,autocomplete:"off",disabled:g,"aria-describedby":g?"pmw-chat-demo-hint":null}),bt=i(t,"button",{type:"submit",class:"pmw-chat__send",disabled:g},s.send),we=i(t,"div",{class:"pmw-chat__box"});we.append(i(t,"label",{class:"pmw-chat__sr",for:"pmw-chat-input"},s.messageLabel),L,bt),g||k.append(Fe(k,()=>!0)),k.append(we),g&&k.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-demo-hint"},s.demoHint));let F=null,z=i(t,"p",{class:"pmw-chat__error pmw-chat__photo-error",role:"alert"});if(S.photos===!0){let e=i(t,"label",{class:"pmw-chat__attach"});F=i(t,"input",{type:"file",class:"pmw-chat__sr",accept:"image/*",multiple:!0,"aria-describedby":"pmw-chat-photo-hint",disabled:g}),e.innerHTML=Jt,e.prepend(F),e.append(i(t,"span",{class:"pmw-chat__sr"},s.attachPhoto)),we.insertBefore(e,L),k.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-photo-hint"},s.photoHint),z)}let ee=i(t,"div",{class:"pmw-chat__ended",hidden:!0}),$e=i(t,"p",{},s.ended),te=i(t,"button",{type:"button",class:"pmw-chat__restart"},s.newConversation);ee.append($e,te);let b=i(t,"form",{class:"pmw-chat__fallback",novalidate:!0,hidden:!0,"aria-labelledby":"pmw-chat-fb-title"}),Je=i(t,"p",{class:"pmw-chat__fb-intro"}),_e=(e,a,n)=>{let c=`pmw-chat-fb-${e}`,d=i(t,"div",{class:"pmw-chat__field"});return d.append(i(t,"label",{for:c},s[e]),i(t,a,{id:c,name:e,required:!0,...n})),d},$=i(t,"p",{class:"pmw-chat__error",role:"alert"});b.append(i(t,"p",{class:"pmw-chat__fb-title",id:"pmw-chat-fb-title"},s.fallbackTitle),Je,_e("name","input",{autocomplete:"name",maxlength:"100"}),_e("contact","input",{autocomplete:"on",maxlength:"200"}),_e("need","textarea",{rows:"3",maxlength:"2000"}),$,i(t,"button",{type:"submit",class:"pmw-chat__send"},s.fallbackSend)),g||b.insertBefore(Fe(b,()=>!b.hidden),$);let M=i(t,"div",{class:"pmw-chat__body"});M.append(y,fe,ee,b),T.append(Ie,M,k,Be),r.append(T),l??(l=Qt(o,w));let J=!0,je=0,ge=0,xt=()=>M.scrollHeight-M.scrollTop-M.clientHeight;M.addEventListener("scroll",()=>{let e=M.scrollTop;xt()<=Ft?J=!0:e<je&&(J=!1),je=e},{passive:!0});let vt=e=>o.requestAnimationFrame?o.requestAnimationFrame(e):o.setTimeout(e,16);function E(e=!1,a=!1){e&&(J=!0),!(!J||ge)&&(ge=vt(()=>{if(ge=0,!J)return;let n=a||!!o.matchMedia?.("(prefers-reduced-motion: reduce)").matches;M.scrollTo({top:M.scrollHeight,behavior:n?"instant":"smooth"})}))}if(typeof o.ResizeObserver=="function"){let e=new o.ResizeObserver(()=>E());e.observe(y),e.observe(k)}let h=null;if(!g)try{h=JSON.parse(o.sessionStorage.getItem(he)??"null")}catch{h=null}if(h&&typeof h.at=="number"&&!(Date.now()-h.at<Ut)){h=null;try{o.sessionStorage.removeItem(he)}catch{}}let be=()=>{try{o.sessionStorage.setItem(he,JSON.stringify(h))}catch{}},yt=()=>{h&&(h.at=Date.now(),be())},C=null,xe=0,ve=null,j=null,ae=0,K="bot",R=null,H=!1,Ke=0,ye=null,ke=new Set,q=new Map,ne=new Set,Se=0,Ge=()=>new URLSearchParams(o.location.hash.slice(1)).get("pmw-chat-botName")?.trim()||null,Ve=g?Ge():null,Te=()=>g?Ve:h?.botName||null;function G(){let e=K==="human";He.textContent=e?R||s.assistant:Te()||s.assistant,W.textContent=e?s.live:Te()?s.assistant:"",W.hidden=W.textContent==="",Z.hidden=e,Ue.hidden=!e,T.dataset.mode=K}G();let N=e=>{fe.textContent=e??"",fe.hidden=!e};N("");let Ye=e=>e.role==="visitor"?s.you:e.role==="owner"?e.by||R||s.assistant:Te()||s.assistant;function D(e,a){let n=i(t,"li",{class:`pmw-chat__msg pmw-chat__msg--${a}`,"data-id":e}),c=i(t,"span",{class:"pmw-chat__sr"}),d=i(t,"span",{class:"pmw-chat__text"});return n.append(c,d),y.insertBefore(n,A.parentNode===y?A:null),n}let Xe=()=>A.parentNode===y?A.previousElementSibling:y.lastElementChild,P=(e,a)=>e.classList.contains(a);function We(e,a,n,c){let d=i(t,"li",{class:e,role:"separator","aria-label":n}),_=i(t,"span",{class:"pmw-chat__relay-label","aria-hidden":"true"});_.append(i(t,"span",{class:a}),n),d.append(_),y.insertBefore(d,c??(A.parentNode===y?A:null)),E()}function Qe(e,a){for(let n=e?e.previousElementSibling:Xe();n;n=n.previousElementSibling){if(P(n,"pmw-chat__relay")||P(n,"pmw-chat__msg--owner"))return;if(P(n,"pmw-chat__msg--bot")||P(n,"pmw-chat__handback"))break}We("pmw-chat__relay","pmw-chat__relay-dot",a?Y(s.relay,{name:a}):s.relayGeneric,e)}function Le(e){for(let a=e?e.previousElementSibling:Xe();;a=a.previousElementSibling){if(!a||P(a,"pmw-chat__handback")||P(a,"pmw-chat__msg--bot"))return;if(P(a,"pmw-chat__relay")||P(a,"pmw-chat__msg--owner"))break}We("pmw-chat__handback","pmw-chat__relay-dot pmw-chat__relay-dot--back",s.handback,e)}let Ze=e=>[...y.querySelectorAll("li[data-id]")].find(a=>a.dataset.id===e),I=(e,a,n)=>{e.firstChild.textContent=Y(s.said,{name:Ye(a),text:""}),e.lastChild.textContent=n===""&&a.photos?.length&&!e.querySelector("img")?s.photoSent:n};function U(){A.hidden=!0,o.clearTimeout(ye)}function Ee(e){A.hidden=!1,y.append(A),o.clearTimeout(ye),e&&(ye=o.setTimeout(U,e)),E()}function et(e,{announce:a}){if(ke.has(e.seq))return;ke.add(e.seq),ae=Math.max(ae,e.seq);let n=Ze(e.id);n||(n=D(e.id,e.role),e.role==="owner"?Qe(n,e.by||R):e.role==="bot"&&Le(n)),n.classList.remove("is-streaming","is-pending","is-failed"),n.querySelector(".pmw-chat__retry")?.remove(),I(n,e,e.text),e.role==="visitor"?(q.delete(e.id),e.photos?.length&&ne.add(e.id)):(U(),a&&(Be.textContent=Y(s.said,{name:Ye(e),text:e.text})),T.hidden&&r.setAttribute("data-unread","")),E()}function kt(e,a){U();let n=Ze(e);n||(n=D(e,"bot"),Le(n),n.classList.add("is-streaming"),I(n,{role:"bot"},"")),n.lastChild.textContent+=a,E()}if(g){I(D("demo-question","visitor"),{role:"visitor"},Vt(Re,X));let e=D("demo-answer","bot");I(e,{role:"bot"},s.demoAnswer),o.addEventListener("hashchange",()=>{Ve=Ge(),G(),I(e,{role:"bot"},s.demoAnswer)})}function oe(e){if(e.failed=!0,e.li.classList.remove("is-pending"),e.li.classList.add("is-failed"),e.li.querySelector(".pmw-chat__retry"))return;let a=i(t,"span",{class:"pmw-chat__retry"},`${s.notSent} `),n=i(t,"button",{type:"button"},s.retry);n.addEventListener("click",()=>{e.failed=!1,e.tries=0,a.remove(),e.li.classList.replace("is-failed","is-pending"),h?re()?Ce(e):B():Oe()}),a.append(n),e.li.append(a)}let re=()=>!!C&&C.readyState===1;function Ce(e){if(!(e.failed||!re())){if(e.tries>=wt)return oe(e);e.tries++,C.send(JSON.stringify({type:"message",id:e.id,text:e.text}))}}function B(){if(!h||H||C)return;o.clearTimeout(ve);let e=o.location.protocol==="https:"?"wss:":"ws:",a=new URLSearchParams({c:h.c,k:h.k}),n=new f(`${e}//${o.location.host}/api/chat/ws?${a}`);C=n,n.onopen=()=>{xe=0,ce&&(V(),Ee(_t)),N(""),n.send(JSON.stringify({type:"hello",since:ae}));for(let c of q.values())Ce(c)},n.onmessage=c=>{let d;try{d=JSON.parse(c.data)}catch{return}Tt(d)},n.onclose=c=>{C===n&&(C=null);for(let _ of q.values())_.tries>=wt&&oe(_);if(c.code>=4e3&&c.code<5e3)return St(c.code);if(H)return;V(),N(s.reconnecting);let d=ft[Math.min(xe,ft.length-1)];xe++,ve=o.setTimeout(B,d)}}function St(e){if(e===mt.rpc)return ie(s.reload,!1);ie(s.ended,!0)}function ie(e,a){H=!0,o.clearTimeout(ve),N(""),$e.textContent=e,te.hidden=!a,ee.hidden=!1,k.hidden=!0;for(let n of q.values())oe(n);E()}function tt(e){K=e.mode==="human"?"human":"bot",R=typeof e.ownerName=="string"?e.ownerName:null,G(),K==="human"?Qe(null,R):Le(null),e.closed&&ie(s.ended,!0)}function Tt(e){switch(e?.type){case"history":typeof e.ownerName=="string"&&(R=e.ownerName);for(let a of e.messages??[])et(a,{announce:!1});return tt(e);case"message":return yt(),et(e.msg,{announce:e.msg?.role!=="visitor"});case"delta":return kt(e.id,e.text);case"typing":return e.role==="visitor"?void 0:Ee(_t);case"status":return tt(e);case"fallback":return ot(e.reason==="cap"?s.fallbackCap:s.fallbackDown);case"lead":return nt();case"error":(e.code==="closed"||e.code==="deleted")&&ie(s.ended,!0)}}let at=!1;function nt(){if(!(at||h?.lead)){at=!0,h&&(h.lead=!0,be());try{o.pmw?.event(qt)}catch{}}}let se=new Set;async function Ae(e,a){let n="";if(se.has(e)){se.delete(e);try{l.reset(e)}catch{}}try{n=await l.token(e)}catch{n=""}if(n===null)return se.add(e),{ok:!1,error:s.turnstile,cap:!1,turnstile:!0};let c,d=null;try{c=await m("/api/chat/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:n,lang:X,page:o.location.pathname,...a})}),d=await c.json()}catch{c=null}return se.add(e),c?.ok&&d?{ok:!0,data:d}:{ok:!1,error:c?.status===403?s.turnstile:c?.status===429?s.tooMany:null,cap:c?.status===409&&d?.error==="cap",turnstile:c?.status===403}}let ce=null,V=()=>{o.clearTimeout(ce),ce=null};function Oe(){if(j||h)return j;N(""),Ee(),ce=o.setTimeout(()=>N(s.oneMoment),Bt);let e=y.firstElementChild===ue?ue.textContent.trim():"";return j=Ae(k,e?{opener:e}:{}).then(a=>{if(j=null,a.ok&&a.data.conversationId&&a.data.visitorKey){h={c:a.data.conversationId,k:a.data.visitorKey,botName:typeof a.data.botName=="string"?a.data.botName:null,at:Date.now()},be(),G(),B();return}V(),U();for(let n of q.values())oe(n);if(a.error)return N(a.error);N(""),ot(a.cap?s.fallbackCap:s.fallbackDown)}),j}function ot(e){U(),V(),N(""),Je.textContent=e,b.hidden=!1,k.hidden=!0,g||l.load(),b.querySelector("input")?.focus()}b.addEventListener("submit",async e=>{e.preventDefault();let a=O=>b.elements[O].value.trim(),n={name:a("name"),contact:a("contact"),need:a("need")};if(!n.name||!n.contact||!n.need){$.textContent=s.fallbackMissing;return}$.textContent="";let c=b.querySelector('button[type="submit"]');if(c.disabled)return;c.disabled=!0;let d={fallbackLead:n,...h?.c&&h?.k?{c:h.c,k:h.k}:{}},_=await Ae(b,d);if(!_.ok&&_.turnstile&&(_=await Ae(b,d)),c.disabled=!1,!_.ok){$.textContent=_.error??s.unavailable;return}b.replaceChildren(i(t,"p",{class:"pmw-chat__fb-done",role:"status"},s.fallbackSent)),nt()});let Lt={413:"photoTooLarge",415:"photoUnreadable",409:"photoLimit",429:"tooMany"};async function Et(e){let a,n;try{a=await x(e),n=await v(a)}catch{z.textContent=s.photoUnreadable;return}let c=u(),d=D(c,"visitor");d.classList.add("is-pending");let _=i(t,"img",{class:"pmw-chat__photo",src:n,alt:s.photoAlt});_.addEventListener("load",()=>E(),{once:!0}),d.insertBefore(_,d.lastChild),I(d,{role:"visitor"},""),E(!0),h||await Oe();let O=null;if(h){let le=new URLSearchParams({c:h.c,k:h.k,id:c});try{O=await m(`/api/chat/photo?${le}`,{method:"POST",headers:{"content-type":"image/jpeg"},body:a})}catch{O=null}}if(O?.ok){d.classList.remove("is-pending"),ne.add(c),C||B();return}d.remove(),z.textContent=s[Lt[O?.status]]??s.photoFailed}F?.addEventListener("change",async()=>{let e=[...F.files??[]];if(F.value="",z.textContent="",H||g||e.length===0)return;let a=It-ne.size-Se;e.length>a&&(z.textContent=s.photoLimit);let n=e.slice(0,Math.max(0,a));Se+=n.length;for(let c of n)try{await Et(c)}finally{Se--}});function rt(){let e=L.value.trim();if(!e||H||g)return;L.value="",it();let a={id:u(),text:e.slice(0,2e3),tries:0,failed:!1};a.li=D(a.id,"visitor"),a.li.classList.add("is-pending"),I(a.li,{role:"visitor"},a.text),q.set(a.id,a),E(!0),h?re()?Ce(a):B():Oe()}k.addEventListener("submit",e=>{e.preventDefault(),rt()}),L.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),rt())});let it=()=>{L.style.height="auto",L.style.height=L.value?`${Math.min(L.scrollHeight,132)}px`:""};L.addEventListener("input",()=>{it();let e=Date.now();re()&&e-Ke>$t&&(Ke=e,C.send(JSON.stringify({type:"typing"})))}),te.addEventListener("click",()=>{h=null;try{o.sessionStorage.removeItem(he)}catch{}try{C?.close(1e3)}catch{}C=null,H=!1,ae=0,ke.clear(),q.clear(),ne.clear(),z.textContent="",K="bot",R=null,G();for(let e of[...y.querySelectorAll("li[data-id], .pmw-chat__relay, .pmw-chat__handback")])e.remove();U(),V(),ee.hidden=!0,k.hidden=!1,L.focus()});let Ct=()=>[...T.querySelectorAll('a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])')].filter(e=>!e.disabled&&!e.closest("[hidden]"));T.addEventListener("keydown",e=>{if(e.key==="Escape"){e.preventDefault(),Me();return}if(e.key!=="Tab")return;let a=Ct();if(a.length===0)return;let n=a[0],c=a[a.length-1];e.shiftKey&&t.activeElement===n?(e.preventDefault(),c.focus()):!e.shiftKey&&t.activeElement===c&&(e.preventDefault(),n.focus())}),Q.addEventListener("click",e=>Me({keyboard:e.detail===0}));function At(){g||l.load(),T.hidden=!1,T.inert=!1,r.setAttribute("data-open",""),r.removeAttribute("data-unread"),h&&B(),(g?Q:k.hidden?b.hidden?te:b.querySelector("input"):L)?.focus(),E(!0,!0)}function Me({keyboard:e=!0}={}){T.hidden=!0,T.inert=!0,r.removeAttribute("data-open"),e&&qe?.focus(),r.dispatchEvent(new o.FocusEvent("focusout",{relatedTarget:e?qe:null}))}return g||Ne(r,()=>l.load(),{win:o,settleMs:Dt}),r.pmwChat={open:At,close:Me,panel:T},r.pmwChat}export{ft as BACKOFF_MS,qt as GOAL,Ut as IDLE_MS,It as MAX_PHOTOS,wt as MAX_TRIES,zt as PHOTO_EDGE,Ht as PHOTO_QUALITY,Ft as PIN_SLACK,he as SESSION_KEY,Bt as SLOW_START_MS,Dt as WARM_MS,Vt as demoQuestion,da as mountChat,Wt as retryable};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmeweb/plugin-chat",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "PmeWeb chat plugin: the bubble, the lazy chat panel, the site Worker's /api/chat routes and the build-time context file. The conversations, the model and the alerts live in the pmeweb-chat service.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/widget.js CHANGED
@@ -702,7 +702,10 @@ export function mountChat(root, deps = {}) {
702
702
  showState('')
703
703
  showTyping()
704
704
  slowTimer = win.setTimeout(() => showState(s.oneMoment), SLOW_START_MS)
705
- starting = post(composer, {}).then((r) => {
705
+ // The opener shown as the first bubble goes with the start (1.3.3): pmeweb-chat makes it the
706
+ // thread's first bot message, so the model reads « Oui » as an answer to it.
707
+ const shown = log.firstElementChild === greeting ? greeting.textContent.trim() : ''
708
+ starting = post(composer, shown ? { opener: shown } : {}).then((r) => {
706
709
  starting = null
707
710
  if (r.ok && r.data.conversationId && r.data.visitorKey) {
708
711
  session = { c: r.data.conversationId, k: r.data.visitorKey, botName: typeof r.data.botName === 'string' ? r.data.botName : null, at: Date.now() }
package/src/worker.js CHANGED
@@ -32,7 +32,7 @@ import { verifyTurnstile } from '@pmeweb/turnstile/worker'
32
32
  import { RPC_HEADER, RPC_VERSION } from './protocol.js'
33
33
 
34
34
  /** This package's version, reported by the health route (a test holds it equal to package.json). */
35
- export const VERSION = '1.3.2'
35
+ export const VERSION = '1.3.3'
36
36
  export { RPC_VERSION }
37
37
 
38
38
  const SERVICE = 'https://pmeweb-chat.internal'
@@ -117,6 +117,10 @@ async function start(request, url, env, { config, lang }) {
117
117
  if (config?.sms === 'voipms') body.sms = 'voipms'
118
118
  if (config?.photos === true) body.photos = true
119
119
  if (lead) body.fallbackLead = lead
120
+ // The opener the panel showed as its first bubble (1.3.3): pmeweb-chat makes it the thread's first
121
+ // bot message. A malformed one is dropped, never a 400: the conversation still starts.
122
+ const opener = typeof b.opener === 'string' ? b.opener.trim() : ''
123
+ if (opener.length >= 1 && opener.length <= 80 && !/[\u0000-\u001f\u007f-\u009f]/.test(opener)) body.opener = opener
120
124
  // The conversation the visitor already had, so the form's request joins its thread (1.3.2); the
121
125
  // service checks the key, as it does for the socket.
122
126
  if (lead && typeof b.c === 'string' && /^[0-9a-f-]{36}$/i.test(b.c) && typeof b.k === 'string' && /^[A-Za-z0-9_-]{16,64}$/.test(b.k)) {