@pmeweb/plugin-chat 1.3.2 → 1.3.4

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 dt=`.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}.pmw-chat__panel{transform-origin:bottom right;transition:opacity .22s cubic-bezier(.2,.8,.2,1),transform .22s cubic-bezier(.2,.8,.2,1)}.pmw-chat__panel[hidden]{transform:translateY(24px);transition:opacity .16s ease-in,transform .16s ease-in}@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[hidden]{transform:translateY(12px) scale(.96)}}@media(prefers-reduced-motion:reduce){.pmw-chat__panel,.pmw-chat__panel[hidden]{transform:none}}.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__badge{position:absolute;top:-4px;left:30px;min-width:20px;height:20px;padding:0 6px;box-sizing:border-box;border-radius:10px;background:var(--pmw-chat-error, #b42318);color:#fff;box-shadow:0 0 0 2px #fff;font-size:12px;font-weight:700;line-height:20px;text-align:center}.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 Ht="400px 0px";var ht=new Set,me=null;function mt(r,{doc:c=document,attrs:n={}}={}){if(ht.has(r)||(ht.add(r),c.querySelector(`script[src="${r}"]`)))return;let t=c.createElement("script");t.src=r,t.async=!0;for(let[h,d]of Object.entries(n))t.setAttribute(h,d);c.head.append(t)}function ut({doc:r=document,hostname:c=globalThis.location?.hostname??""}={}){let n=r.getElementById("pmw-hosts");if(!n)return!1;let t;try{t=JSON.parse(n.textContent??"")}catch{return!1}if(!Array.isArray(t))return!1;let h=String(c).toLowerCase();return t.some(d=>typeof d=="string"&&d.toLowerCase()===h)}function Dt(r){return me||(me=new Promise(c=>{let n=null,t=null,h=0,d=r.PerformanceObserver?.supportedEntryTypes??[],u=typeof r.PerformanceObserver=="function"&&d.includes("paint"),p=()=>{n===null||u&&t===null||c(Math.max(n,t??0,h))};if(u)try{new r.PerformanceObserver(x=>{for(let v of x.getEntries())v.name==="first-contentful-paint"&&(t=v.startTime);p()}).observe({type:"paint",buffered:!0}),d.includes("largest-contentful-paint")&&new r.PerformanceObserver(x=>{for(let v of x.getEntries())h=Math.max(h,v.startTime)}).observe({type:"largest-contentful-paint",buffered:!0})}catch{t=0}let w=()=>{n=r.performance.now(),p()};r.document.readyState==="complete"?w():r.addEventListener("load",w,{once:!0})}),me)}function Ie(r,c,{win:n=window,rootMargin:t=Ht,settleMs:h=1500}={}){let d=null,u=!1,p=()=>{u||(u=!0,d?.disconnect(),r.removeEventListener("focusin",p),r.removeEventListener("pointerdown",p),c())};r.addEventListener("focusin",p),r.addEventListener("pointerdown",p);let w=Dt(n),x=async()=>{let v=await w;n.setTimeout(p,Math.max(0,v+h-n.performance.now()))};return typeof n.IntersectionObserver=="function"?(d=new n.IntersectionObserver(v=>{v.some(T=>T.isIntersecting)&&(d.disconnect(),x())},{rootMargin:t}),d.observe(r)):x(),{run:p}}var Ut="https://challenges.cloudflare.com/turnstile/v0/api.js";var ft=15e3;function wt(r=document){mt(Ut,{doc:r})}var _t={unauthorized:4401,expired:4410,rpc:4426,deleted:4404};var Bt={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}",unreadOne:"{n} nouveau message",unreadMany:"{n} nouveaux messages",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}",unreadOne:"{n} new message",unreadMany:"{n} new messages",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."}},ue=r=>String(r??"").slice(0,2).toLowerCase()==="en"?"en":"fr";function ze(r,c={}){let n=Bt[ue(r)],t={...n};for(let[h,d]of Object.entries(c??{}))typeof d=="string"&&h in n&&(t[h]=d);return t}var J=(r,c)=>r.replace(/\{(\w+)\}/g,(n,t)=>t in c?String(c[t]):n);var fe="pmw-chat",bt=[1e3,2e3,4e3,8e3,16e3,3e4],xt=3,Ft="chat-lead",$t=3,Jt=1600,Vt=.85,jt=3e3,Gt=7200*1e3,Yt=8e3,Kt=40,Xt=2e3,Wt=3e3,vt=8e3,Qt='<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 Zt(r,c){let n=await r.createImageBitmap(c,{imageOrientation:"from-image"}),t=Math.min(1,Jt/Math.max(n.width,n.height)),h=Math.max(1,Math.round(n.width*t)),d=Math.max(1,Math.round(n.height*t)),u=r.document.createElement("canvas");return u.width=h,u.height=d,u.getContext("2d").drawImage(n,0,0,h,d),n.close?.(),new Promise((p,w)=>u.toBlob(x=>x?p(x):w(new Error("encode")),"image/jpeg",Vt))}var ea={fr:{nos:"vos",notre:"votre",nous:"vous"},en:{our:"your",us:"you",we:"you"}},ta={fr:/^une question sur (.+?)\s*\?$/i,en:/^(?:a |any )?questions? (?:about|on) (.+?)\s*\?$/i};function aa(r,c){let n=ue(c),t=ze(n),h=String(r??"").trim().match(ta[n]);if(!h)return t.demoQuestion;let d=h[1].replace(/[\p{L}’']+/gu,u=>ea[n][u.toLowerCase()]??u);return J(t.demoAsk,{topic:d})}var na='<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 oa(r){let c=null;return{unlock(){try{let n=r.AudioContext||r.webkitAudioContext;if(!n)return;c??(c=new n),c.state==="suspended"&&c.resume()}catch{c=null}},play(){if(c)try{c.state==="suspended"&&c.resume();let n=c.currentTime;for(let[t,h]of[[880,0],[1320,.12]]){let d=c.createOscillator(),u=c.createGain();d.type="sine",d.frequency.value=t,u.gain.setValueAtTime(1e-4,n+h),u.gain.exponentialRampToValueAtTime(.15,n+h+.02),u.gain.exponentialRampToValueAtTime(1e-4,n+h+.35),d.connect(u).connect(c.destination),d.start(n+h),d.stop(n+h+.4)}}catch{}}}}function i(r,c,n={},t){let h=r.createElement(c);for(let[d,u]of Object.entries(n))u!=null&&u!==!1&&h.setAttribute(d,u===!0?"":u);return t!==void 0&&(h.textContent=t),h}var ra=/^(?:300\d{3}|600\d{3}|110600|110620)$/,ia=r=>ra.test(String(r??"")),yt=200,sa=(r,c)=>{let n=!1,t=p=>{let w=r.turnstile;if(!(p.el.hasAttribute("data-pmw-rendered")||!p.shown())){p.el.setAttribute("data-pmw-rendered","");try{p.id=w.render(p.el,p.params)}catch{}}},h=()=>{if(!r.turnstile?.render)return!1;for(let p of c)t(p);return!0},d=()=>{if(wt(r.document),n||h())return;n=!0;let p=0,w=()=>{!h()&&++p<600&&r.setTimeout(w,100)};r.setTimeout(w,100)},u=p=>c.find(w=>w.form===p);for(let p of c)p.params["error-callback"]=w=>(p.ask(!1),ia(w)&&!p.retried&&p.id!==void 0?(p.retried=!0,r.setTimeout(()=>{try{r.turnstile?.reset(p.id)}catch{p.failed=!0}},0)):p.failed=!0,!0);return{load:d,async token(p){d();let w=u(p),x=0;for(;;){if(w?.failed)return null;let v=p.querySelector('input[name="cf-turnstile-response"]')?.value??"";if(v)return v;if(!w?.asking()){if(x>=ft)return"";x+=yt}await new Promise(T=>r.setTimeout(T,yt))}},reset(p){let w=u(p);!w||w.id===void 0||w.asking()||(w.failed=!1,w.retried=!1,r.turnstile?.reset(w.id))}}};function xa(r,c={}){if(r.pmwChat)return r.pmwChat;let n=c.win??window,t=n.document,h=c.WebSocket??n.WebSocket,d=c.fetch??((...e)=>n.fetch(...e)),u=[],p=c.turnstile??null,w=c.uuid??(()=>n.crypto.randomUUID()),x=c.shrink??(e=>Zt(n,e)),v=c.preview??(e=>new Promise((a,o)=>{let l=new n.FileReader;l.onload=()=>a(String(l.result)),l.onerror=()=>o(l.error),l.readAsDataURL(e)})),T={};try{T=JSON.parse(r.querySelector("[data-pmw-chat-config]")?.textContent??"{}")}catch{}let Q=ue(T.lang),s=ze(Q,T.strings),He=r.dataset.pmwChatOpener??"",Z=r.querySelector(".pmw-chat__bubble"),we=c.chime??oa(n),kt=c.now??(()=>Date.now()),g=c.demo??(T.demo===!0||!ut({doc:t,hostname:n.location.hostname}));t.getElementById("pmw-chat-style")||t.head.append(i(t,"style",{id:"pmw-chat-style"},dt));let y=i(t,"div",{class:"pmw-chat__panel",role:"dialog","aria-modal":"true","aria-labelledby":"pmw-chat-name",hidden:!0});y.inert=!0;let De=i(t,"div",{class:"pmw-chat__head"}),_e=r.querySelector(".pmw-chat__avatar")?.cloneNode(!0)??i(t,"span",{class:"pmw-chat__avatar","aria-hidden":"true"});for(let e of _e.querySelectorAll("[id]")){let a=e.id;e.id=`${a}-head`;for(let o of _e.querySelectorAll(`[mask="url(#${a})"]`))o.setAttribute("mask",`url(#${a}-head)`)}let Ue=i(t,"div",{class:"pmw-chat__who"}),Be=i(t,"p",{class:"pmw-chat__name",id:"pmw-chat-name"}),ee=i(t,"p",{class:"pmw-chat__role"}),Fe=i(t,"span",{class:"pmw-chat__face"}),$e=i(t,"span",{class:"pmw-chat__dot","aria-hidden":"true",hidden:!0}),te=i(t,"button",{type:"button",class:"pmw-chat__close","aria-label":s.close});te.innerHTML=na;let ae=i(t,"p",{class:"pmw-chat__notice"},s.automated);T.privacyHref&&(ae.append(" "),ae.append(i(t,"a",{href:T.privacyHref},s.privacy))),Fe.append(_e,$e),Ue.append(Be,ee,ae),De.append(Fe,Ue,te);let k=i(t,"ol",{class:"pmw-chat__log"}),ge=i(t,"li",{class:"pmw-chat__msg pmw-chat__msg--bot pmw-chat__msg--greeting"},He),A=i(t,"li",{class:"pmw-chat__typing","aria-hidden":"true",hidden:!0});A.append(i(t,"span"),i(t,"span"),i(t,"span")),k.append(ge);let be=i(t,"p",{class:"pmw-chat__state",role:"status"}),Je=i(t,"p",{class:"pmw-chat__sr","aria-live":"polite"}),Ve=(e,a)=>{let o=i(t,"div",{class:"pmw-chat__check"}),l=i(t,"div",{class:"pmw-chat__check-in"});l.inert=!0;let m=he=>{o.toggleAttribute("data-ask",he),l.inert=!he,C()},_=i(t,"div",{class:"pmw-chat__turnstile"}),O={el:_,form:e,shown:a,ask:m,asking:()=>o.hasAttribute("data-ask"),params:{sitekey:T.siteKey??"",action:"chat",theme:"light",language:Q,appearance:"interaction-only",size:"flexible","refresh-expired":"auto",callback:()=>{O.retried=!1,O.failed=!1,m(!1)},"before-interactive-callback":()=>m(!0)}};return u.push(O),l.append(_),o.append(l),o},S=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}),St=i(t,"button",{type:"submit",class:"pmw-chat__send",disabled:g},s.send),xe=i(t,"div",{class:"pmw-chat__box"});xe.append(i(t,"label",{class:"pmw-chat__sr",for:"pmw-chat-input"},s.messageLabel),L,St),g||S.append(Ve(S,()=>!0)),S.append(xe),g&&S.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-demo-hint"},s.demoHint));let V=null,H=i(t,"p",{class:"pmw-chat__error pmw-chat__photo-error",role:"alert"});if(T.photos===!0){let e=i(t,"label",{class:"pmw-chat__attach"});V=i(t,"input",{type:"file",class:"pmw-chat__sr",accept:"image/*",multiple:!0,"aria-describedby":"pmw-chat-photo-hint",disabled:g}),e.innerHTML=Qt,e.prepend(V),e.append(i(t,"span",{class:"pmw-chat__sr"},s.attachPhoto)),xe.insertBefore(e,L),S.append(i(t,"p",{class:"pmw-chat__hint",id:"pmw-chat-photo-hint"},s.photoHint),H)}let ne=i(t,"div",{class:"pmw-chat__ended",hidden:!0}),je=i(t,"p",{},s.ended),oe=i(t,"button",{type:"button",class:"pmw-chat__restart"},s.newConversation);ne.append(je,oe);let b=i(t,"form",{class:"pmw-chat__fallback",novalidate:!0,hidden:!0,"aria-labelledby":"pmw-chat-fb-title"}),Ge=i(t,"p",{class:"pmw-chat__fb-intro"}),ve=(e,a,o)=>{let l=`pmw-chat-fb-${e}`,m=i(t,"div",{class:"pmw-chat__field"});return m.append(i(t,"label",{for:l},s[e]),i(t,a,{id:l,name:e,required:!0,...o})),m},j=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),Ge,ve("name","input",{autocomplete:"name",maxlength:"100"}),ve("contact","input",{autocomplete:"on",maxlength:"200"}),ve("need","textarea",{rows:"3",maxlength:"2000"}),j,i(t,"button",{type:"submit",class:"pmw-chat__send"},s.fallbackSend)),g||b.insertBefore(Ve(b,()=>!b.hidden),j);let M=i(t,"div",{class:"pmw-chat__body"});M.append(k,be,ne,b),y.append(De,M,S,Je),r.append(y),p??(p=sa(n,u));let G=!0,Ye=0,ye=0,Tt=()=>M.scrollHeight-M.scrollTop-M.clientHeight;M.addEventListener("scroll",()=>{let e=M.scrollTop;Tt()<=Kt?G=!0:e<Ye&&(G=!1),Ye=e},{passive:!0});let Lt=e=>n.requestAnimationFrame?n.requestAnimationFrame(e):n.setTimeout(e,16);function C(e=!1,a=!1){e&&(G=!0),!(!G||ye)&&(ye=Lt(()=>{if(ye=0,!G)return;let o=a||!!n.matchMedia?.("(prefers-reduced-motion: reduce)").matches;M.scrollTo({top:M.scrollHeight,behavior:o?"instant":"smooth"})}))}if(typeof n.ResizeObserver=="function"){let e=new n.ResizeObserver(()=>C());e.observe(k),e.observe(S)}let f=null;if(!g)try{f=JSON.parse(n.sessionStorage.getItem(fe)??"null")}catch{f=null}if(f&&typeof f.at=="number"&&!(Date.now()-f.at<Gt)){f=null;try{n.sessionStorage.removeItem(fe)}catch{}}let ke=()=>{try{n.sessionStorage.setItem(fe,JSON.stringify(f))}catch{}},Ct=()=>{f&&(f.at=Date.now(),ke())},E=null,Se=0,Te=null,Y=null,re=0,K="bot",R=null,D=!1,Ke=0,Le=null,Ce=new Set,q=new Map,ie=new Set,Ee=0,Xe=()=>new URLSearchParams(n.location.hash.slice(1)).get("pmw-chat-botName")?.trim()||null,We=g?Xe():null,Ae=()=>g?We:f?.botName||null;function X(){let e=K==="human";Be.textContent=e?R||s.assistant:Ae()||s.assistant,ee.textContent=e?s.live:Ae()?s.assistant:"",ee.hidden=ee.textContent==="",ae.hidden=e,$e.hidden=!e,y.dataset.mode=K}X();let N=e=>{be.textContent=e??"",be.hidden=!e};N("");let Qe=e=>e.role==="visitor"?s.you:e.role==="owner"?e.by||R||s.assistant:Ae()||s.assistant;function U(e,a){let o=i(t,"li",{class:`pmw-chat__msg pmw-chat__msg--${a}`,"data-id":e}),l=i(t,"span",{class:"pmw-chat__sr"}),m=i(t,"span",{class:"pmw-chat__text"});return o.append(l,m),k.insertBefore(o,A.parentNode===k?A:null),o}let Ze=()=>A.parentNode===k?A.previousElementSibling:k.lastElementChild,P=(e,a)=>e.classList.contains(a);function et(e,a,o,l){let m=i(t,"li",{class:e,role:"separator","aria-label":o}),_=i(t,"span",{class:"pmw-chat__relay-label","aria-hidden":"true"});_.append(i(t,"span",{class:a}),o),m.append(_),k.insertBefore(m,l??(A.parentNode===k?A:null)),C()}function tt(e,a){for(let o=e?e.previousElementSibling:Ze();o;o=o.previousElementSibling){if(P(o,"pmw-chat__relay")||P(o,"pmw-chat__msg--owner"))return;if(P(o,"pmw-chat__msg--bot")||P(o,"pmw-chat__handback"))break}et("pmw-chat__relay","pmw-chat__relay-dot",a?J(s.relay,{name:a}):s.relayGeneric,e)}function Oe(e){for(let a=e?e.previousElementSibling:Ze();;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}et("pmw-chat__handback","pmw-chat__relay-dot pmw-chat__relay-dot--back",s.handback,e)}let at=e=>[...k.querySelectorAll("li[data-id]")].find(a=>a.dataset.id===e),I=(e,a,o)=>{e.firstChild.textContent=J(s.said,{name:Qe(a),text:""}),e.lastChild.textContent=o===""&&a.photos?.length&&!e.querySelector("img")?s.photoSent:o};function B(){A.hidden=!0,n.clearTimeout(Le)}function Me(e){A.hidden=!1,k.append(A),n.clearTimeout(Le),e&&(Le=n.setTimeout(B,e)),C()}function nt(e,{announce:a}){if(Ce.has(e.seq))return;Ce.add(e.seq),re=Math.max(re,e.seq);let o=at(e.id);o||(o=U(e.id,e.role),e.role==="owner"?tt(o,e.by||R):e.role==="bot"&&Oe(o)),o.classList.remove("is-streaming","is-pending","is-failed"),o.querySelector(".pmw-chat__retry")?.remove(),I(o,e,e.text),e.role==="visitor"?(q.delete(e.id),e.photos?.length&&ie.add(e.id)):(B(),a&&(Je.textContent=J(s.said,{name:Qe(e),text:e.text}),(y.hidden||t.visibilityState==="hidden")&&Et(),y.hidden&&(z++,At()))),C()}let z=0,F=null,ot=-1/0;function Et(){let e=kt();e-ot<Xt||(ot=e,we.play())}function At(){if(!Z)return;F||(F=i(t,"span",{class:"pmw-chat__badge"}),Z.append(F));let e=z>9?"9+":String(z);F.replaceChildren(i(t,"span",{"aria-hidden":"true"},e),i(t,"span",{class:"pmw-chat__sr"},J(z===1?s.unreadOne:s.unreadMany,{n:String(z)}))),r.setAttribute("data-unread",String(z))}function Ot(e,a){B();let o=at(e);o||(o=U(e,"bot"),Oe(o),o.classList.add("is-streaming"),I(o,{role:"bot"},"")),o.lastChild.textContent+=a,C()}if(g){I(U("demo-question","visitor"),{role:"visitor"},aa(He,Q));let e=U("demo-answer","bot");I(e,{role:"bot"},s.demoAnswer),n.addEventListener("hashchange",()=>{We=Xe(),X(),I(e,{role:"bot"},s.demoAnswer)})}function se(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} `),o=i(t,"button",{type:"button"},s.retry);o.addEventListener("click",()=>{e.failed=!1,e.tries=0,a.remove(),e.li.classList.replace("is-failed","is-pending"),f?ce()?Ne(e):$():Re()}),a.append(o),e.li.append(a)}let ce=()=>!!E&&E.readyState===1;function Ne(e){if(!(e.failed||!ce())){if(e.tries>=xt)return se(e);e.tries++,E.send(JSON.stringify({type:"message",id:e.id,text:e.text}))}}function $(){if(!f||D||E)return;n.clearTimeout(Te);let e=n.location.protocol==="https:"?"wss:":"ws:",a=new URLSearchParams({c:f.c,k:f.k}),o=new h(`${e}//${n.location.host}/api/chat/ws?${a}`);E=o,o.onopen=()=>{Se=0,de&&(W(),Me(vt)),N(""),o.send(JSON.stringify({type:"hello",since:re}));for(let l of q.values())Ne(l)},o.onmessage=l=>{let m;try{m=JSON.parse(l.data)}catch{return}Nt(m)},o.onclose=l=>{E===o&&(E=null);for(let _ of q.values())_.tries>=xt&&se(_);if(l.code>=4e3&&l.code<5e3)return Mt(l.code);if(D)return;W(),N(s.reconnecting);let m=bt[Math.min(Se,bt.length-1)];Se++,Te=n.setTimeout($,m)}}function Mt(e){if(e===_t.rpc)return le(s.reload,!1);le(s.ended,!0)}function le(e,a){D=!0,n.clearTimeout(Te),N(""),je.textContent=e,oe.hidden=!a,ne.hidden=!1,S.hidden=!0;for(let o of q.values())se(o);C()}function rt(e){K=e.mode==="human"?"human":"bot",R=typeof e.ownerName=="string"?e.ownerName:null,X(),K==="human"?tt(null,R):Oe(null),e.closed&&le(s.ended,!0)}function Nt(e){switch(e?.type){case"history":typeof e.ownerName=="string"&&(R=e.ownerName);for(let a of e.messages??[])nt(a,{announce:!1});return rt(e);case"message":return Ct(),nt(e.msg,{announce:e.msg?.role!=="visitor"});case"delta":return Ot(e.id,e.text);case"typing":return e.role==="visitor"?void 0:Me(vt);case"status":return rt(e);case"fallback":return ct(e.reason==="cap"?s.fallbackCap:s.fallbackDown);case"lead":return st();case"error":(e.code==="closed"||e.code==="deleted")&&le(s.ended,!0)}}let it=!1;function st(){if(!(it||f?.lead)){it=!0,f&&(f.lead=!0,ke());try{n.pmw?.event(Ft)}catch{}}}let pe=new Set;async function Pe(e,a){let o="";if(pe.has(e)){pe.delete(e);try{p.reset(e)}catch{}}try{o=await p.token(e)}catch{o=""}if(o===null)return pe.add(e),{ok:!1,error:s.turnstile,cap:!1,turnstile:!0};let l,m=null;try{l=await d("/api/chat/start",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:o,lang:Q,page:n.location.pathname,...a})}),m=await l.json()}catch{l=null}return pe.add(e),l?.ok&&m?{ok:!0,data:m}:{ok:!1,error:l?.status===403?s.turnstile:l?.status===429?s.tooMany:null,cap:l?.status===409&&m?.error==="cap",turnstile:l?.status===403}}let de=null,W=()=>{n.clearTimeout(de),de=null};function Re(){if(Y||f)return Y;N(""),Me(),de=n.setTimeout(()=>N(s.oneMoment),Yt);let e=k.firstElementChild===ge?ge.textContent.trim():"";return Y=Pe(S,e?{opener:e}:{}).then(a=>{if(Y=null,a.ok&&a.data.conversationId&&a.data.visitorKey){f={c:a.data.conversationId,k:a.data.visitorKey,botName:typeof a.data.botName=="string"?a.data.botName:null,at:Date.now()},ke(),X(),$();return}W(),B();for(let o of q.values())se(o);if(a.error)return N(a.error);N(""),ct(a.cap?s.fallbackCap:s.fallbackDown)}),Y}function ct(e){B(),W(),N(""),Ge.textContent=e,b.hidden=!1,S.hidden=!0,g||p.load(),b.querySelector("input")?.focus()}b.addEventListener("submit",async e=>{e.preventDefault();let a=O=>b.elements[O].value.trim(),o={name:a("name"),contact:a("contact"),need:a("need")};if(!o.name||!o.contact||!o.need){j.textContent=s.fallbackMissing;return}j.textContent="";let l=b.querySelector('button[type="submit"]');if(l.disabled)return;l.disabled=!0;let m={fallbackLead:o,...f?.c&&f?.k?{c:f.c,k:f.k}:{}},_=await Pe(b,m);if(!_.ok&&_.turnstile&&(_=await Pe(b,m)),l.disabled=!1,!_.ok){j.textContent=_.error??s.unavailable;return}b.replaceChildren(i(t,"p",{class:"pmw-chat__fb-done",role:"status"},s.fallbackSent)),st()});let Pt={413:"photoTooLarge",415:"photoUnreadable",409:"photoLimit",429:"tooMany"};async function Rt(e){let a,o;try{a=await x(e),o=await v(a)}catch{H.textContent=s.photoUnreadable;return}let l=w(),m=U(l,"visitor");m.classList.add("is-pending");let _=i(t,"img",{class:"pmw-chat__photo",src:o,alt:s.photoAlt});_.addEventListener("load",()=>C(),{once:!0}),m.insertBefore(_,m.lastChild),I(m,{role:"visitor"},""),C(!0),f||await Re();let O=null;if(f){let he=new URLSearchParams({c:f.c,k:f.k,id:l});try{O=await d(`/api/chat/photo?${he}`,{method:"POST",headers:{"content-type":"image/jpeg"},body:a})}catch{O=null}}if(O?.ok){m.classList.remove("is-pending"),ie.add(l),E||$();return}m.remove(),H.textContent=s[Pt[O?.status]]??s.photoFailed}V?.addEventListener("change",async()=>{let e=[...V.files??[]];if(V.value="",H.textContent="",D||g||e.length===0)return;let a=$t-ie.size-Ee;e.length>a&&(H.textContent=s.photoLimit);let o=e.slice(0,Math.max(0,a));Ee+=o.length;for(let l of o)try{await Rt(l)}finally{Ee--}});function lt(){let e=L.value.trim();if(!e||D||g)return;we.unlock(),L.value="",pt();let a={id:w(),text:e.slice(0,2e3),tries:0,failed:!1};a.li=U(a.id,"visitor"),a.li.classList.add("is-pending"),I(a.li,{role:"visitor"},a.text),q.set(a.id,a),C(!0),f?ce()?Ne(a):$():Re()}S.addEventListener("submit",e=>{e.preventDefault(),lt()}),L.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),lt())});let pt=()=>{L.style.height="auto",L.style.height=L.value?`${Math.min(L.scrollHeight,132)}px`:""};L.addEventListener("input",()=>{pt();let e=Date.now();ce()&&e-Ke>Wt&&(Ke=e,E.send(JSON.stringify({type:"typing"})))}),oe.addEventListener("click",()=>{f=null;try{n.sessionStorage.removeItem(fe)}catch{}try{E?.close(1e3)}catch{}E=null,D=!1,re=0,Ce.clear(),q.clear(),ie.clear(),H.textContent="",K="bot",R=null,X();for(let e of[...k.querySelectorAll("li[data-id], .pmw-chat__relay, .pmw-chat__handback")])e.remove();B(),W(),ne.hidden=!0,S.hidden=!1,L.focus()});let qt=()=>[...y.querySelectorAll('a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])')].filter(e=>!e.disabled&&!e.closest("[hidden]"));y.addEventListener("keydown",e=>{if(e.key==="Escape"){e.preventDefault(),qe();return}if(e.key!=="Tab")return;let a=qt();if(a.length===0)return;let o=a[0],l=a[a.length-1];e.shiftKey&&t.activeElement===o?(e.preventDefault(),l.focus()):!e.shiftKey&&t.activeElement===l&&(e.preventDefault(),o.focus())}),te.addEventListener("click",e=>qe({keyboard:e.detail===0}));function It(){g||p.load(),y.hidden=!1,y.inert=!1,r.setAttribute("data-open",""),r.removeAttribute("data-unread"),z=0,F?.remove(),F=null,we.unlock(),f&&$(),(g?te:S.hidden?b.hidden?oe:b.querySelector("input"):L)?.focus(),C(!0,!0)}function qe({keyboard:e=!0}={}){y.hidden=!0,y.inert=!0,r.removeAttribute("data-open"),e&&Z?.focus(),r.dispatchEvent(new n.FocusEvent("focusout",{relatedTarget:e?Z:null}))}return g||Ie(r,()=>p.load(),{win:n,settleMs:jt}),r.pmwChat={open:It,close:qe,panel:y},r.pmwChat}export{bt as BACKOFF_MS,Xt as CHIME_GAP_MS,Ft as GOAL,Gt as IDLE_MS,$t as MAX_PHOTOS,xt as MAX_TRIES,Jt as PHOTO_EDGE,Vt as PHOTO_QUALITY,Kt as PIN_SLACK,fe as SESSION_KEY,Yt as SLOW_START_MS,jt as WARM_MS,aa as demoQuestion,xa as mountChat,ia as retryable,oa as webChime};
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.4",
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/strings.js CHANGED
@@ -44,6 +44,8 @@ export const STRINGS = {
44
44
  fallbackSent: 'Merci, votre demande a été transmise.',
45
45
  fallbackMissing: 'Remplissez les trois champs.',
46
46
  said: `{name}${NBSP}: {text}`,
47
+ unreadOne: '{n} nouveau message',
48
+ unreadMany: '{n} nouveaux messages',
47
49
  attachPhoto: 'Joindre une photo',
48
50
  photoHint: 'Évitez les photos de personnes ou de pièces d’identité.',
49
51
  photoAlt: 'Votre photo',
@@ -92,6 +94,8 @@ export const STRINGS = {
92
94
  fallbackSent: 'Thank you, your request was sent.',
93
95
  fallbackMissing: 'Fill in all three fields.',
94
96
  said: '{name}: {text}',
97
+ unreadOne: '{n} new message',
98
+ unreadMany: '{n} new messages',
95
99
  attachPhoto: 'Attach a photo',
96
100
  photoHint: 'Avoid photos of people or of identity documents.',
97
101
  photoAlt: 'Your photo',
package/src/widget.css CHANGED
@@ -18,6 +18,17 @@
18
18
  is rendered into a box with a real size, never a display:none one). */
19
19
  .pmw-chat__panel[hidden] { display: flex !important; opacity: 0; pointer-events: none; }
20
20
  .pmw-chat__panel [hidden] { display: none !important; }
21
+ /* Opening and closing (operator, 2026-11-14): the panel rises out of the bubble's corner and fades in,
22
+ then sinks back, a bit faster, when it closes. Closed it stays laid out (above), so both ways are
23
+ plain transitions; transform never changes the Turnstile box's layout size. Reduced motion: a fade. */
24
+ .pmw-chat__panel {
25
+ transform-origin: bottom right;
26
+ transition: opacity 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
27
+ }
28
+ .pmw-chat__panel[hidden] {
29
+ transform: translateY(24px);
30
+ transition: opacity 0.16s ease-in, transform 0.16s ease-in;
31
+ }
21
32
  @media (min-width: 640px) {
22
33
  .pmw-chat__panel {
23
34
  inset: auto;
@@ -27,6 +38,11 @@
27
38
  border: 1px solid var(--pmw-chat-line, #e6e9f0); border-radius: 20px; overflow: hidden;
28
39
  box-shadow: 0 18px 48px rgb(16 24 40 / 0.18);
29
40
  }
41
+ .pmw-chat__panel[hidden] { transform: translateY(12px) scale(0.96); }
42
+ }
43
+ /* After the desktop rule, so it wins there too. */
44
+ @media (prefers-reduced-motion: reduce) {
45
+ .pmw-chat__panel, .pmw-chat__panel[hidden] { transform: none; }
30
46
  }
31
47
  /* :where() keeps this reset at one class, so .pmw-chat__send's weight (and every later button rule) wins. */
32
48
  .pmw-chat__panel :where(button) { font: inherit; cursor: pointer; }
@@ -197,11 +213,13 @@
197
213
  .pmw-chat__error { margin: 0; font-size: 14px; color: var(--pmw-chat-error, #b42318); }
198
214
  .pmw-chat__error:empty { display: none; }
199
215
  .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; }
200
- /* A reply arrived while the panel was closed. */
216
+ /* Replies that arrived while the panel was closed: their count on the bubble. #ffffff on #b42318 is
217
+ 6.5:1 (a11y-tools/contrast.mjs). */
201
218
  .pmw-chat[data-unread] .pmw-chat__bubble { position: relative; }
202
- .pmw-chat[data-unread] .pmw-chat__bubble::after {
203
- content: ''; position: absolute; top: 2px; left: 38px; width: 12px; height: 12px; border-radius: 50%;
204
- background: var(--pmw-chat-error, #b42318); box-shadow: 0 0 0 2px #ffffff;
219
+ .pmw-chat__badge {
220
+ position: absolute; top: -4px; left: 30px; min-width: 20px; height: 20px; padding: 0 6px; box-sizing: border-box;
221
+ border-radius: 10px; background: var(--pmw-chat-error, #b42318); color: #ffffff; box-shadow: 0 0 0 2px #ffffff;
222
+ font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
205
223
  }
206
224
  /* The contact form's confirmation: a box of its own, never plain text under the thread
207
225
  (operator, 2026-11-13). #14532d on #e9f6ee is 8.19:1 (a11y-tools/contrast.mjs), whatever the site's palette. */
package/src/widget.js CHANGED
@@ -57,6 +57,8 @@ export const IDLE_MS = 2 * 60 * 60 * 1000
57
57
  export const SLOW_START_MS = 8000
58
58
  /** How close to the bottom of the thread (px) still counts as « at the bottom ». */
59
59
  export const PIN_SLACK = 40
60
+ /** Two chimes closer than this play once (a burst of owner messages rings once). */
61
+ export const CHIME_GAP_MS = 2000
60
62
  const TYPING_SEND_MS = 3000
61
63
  const TYPING_SHOW_MS = 8000
62
64
 
@@ -91,6 +93,44 @@ export function demoQuestion(opener, lang) {
91
93
 
92
94
  const X_ICON = '<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>'
93
95
 
96
+ // THE CHIME (operator, 2026-11-14): a reply that arrives while the visitor is not looking (panel
97
+ // closed, or another tab) plays a short sound, mostly for an owner answering live. Two soft notes made
98
+ // with Web Audio: no audio file, no request. Browsers start audio only after a gesture, so the context
99
+ // is created on the visitor's own click (open, send) and reused; until then, and wherever Web Audio
100
+ // is missing or refused, the chime is silent and nothing else changes.
101
+ export function webChime(win) {
102
+ let ctx = null
103
+ return {
104
+ unlock() {
105
+ try {
106
+ const AC = win.AudioContext || win.webkitAudioContext
107
+ if (!AC) return
108
+ ctx ??= new AC()
109
+ if (ctx.state === 'suspended') ctx.resume()
110
+ } catch { ctx = null }
111
+ },
112
+ play() {
113
+ if (!ctx) return
114
+ try {
115
+ if (ctx.state === 'suspended') ctx.resume()
116
+ const t = ctx.currentTime
117
+ for (const [freq, at] of [[880, 0], [1320, 0.12]]) {
118
+ const osc = ctx.createOscillator()
119
+ const gain = ctx.createGain()
120
+ osc.type = 'sine'
121
+ osc.frequency.value = freq
122
+ gain.gain.setValueAtTime(0.0001, t + at)
123
+ gain.gain.exponentialRampToValueAtTime(0.15, t + at + 0.02)
124
+ gain.gain.exponentialRampToValueAtTime(0.0001, t + at + 0.35)
125
+ osc.connect(gain).connect(ctx.destination)
126
+ osc.start(t + at)
127
+ osc.stop(t + at + 0.4)
128
+ }
129
+ } catch { /* a chime never breaks the chat */ }
130
+ },
131
+ }
132
+ }
133
+
94
134
  function el(doc, tag, attrs = {}, text) {
95
135
  const e = doc.createElement(tag)
96
136
  for (const [k, v] of Object.entries(attrs)) if (v !== null && v !== undefined && v !== false) e.setAttribute(k, v === true ? '' : v)
@@ -226,6 +266,8 @@ export function mountChat(root, deps = {}) {
226
266
  const s = stringsFor(lang, cfg.strings)
227
267
  const opener = root.dataset.pmwChatOpener ?? ''
228
268
  const bubble = root.querySelector('.pmw-chat__bubble')
269
+ const chime = deps.chime ?? webChime(win)
270
+ const now = deps.now ?? (() => Date.now())
229
271
  // cfg.demo: Chat.astro switched off, rendered only for a « Contenu » preview build.
230
272
  const demo = deps.demo ?? (cfg.demo === true || !isCanonical({ doc, hostname: win.location.hostname }))
231
273
 
@@ -510,11 +552,34 @@ export function mountChat(root, deps = {}) {
510
552
  }
511
553
  else {
512
554
  hideTyping()
513
- if (announce) announcer.textContent = fill(s.said, { name: speaker(m), text: m.text })
514
- if (panel.hidden) root.setAttribute('data-unread', '')
555
+ if (announce) {
556
+ announcer.textContent = fill(s.said, { name: speaker(m), text: m.text })
557
+ if (panel.hidden || doc.visibilityState === 'hidden') ring()
558
+ if (panel.hidden) { unread++; badge() }
559
+ }
515
560
  }
516
561
  follow()
517
562
  }
563
+ // Unread replies while the panel is closed: a count on the bubble, cleared when it opens.
564
+ let unread = 0
565
+ let badgeEl = null
566
+ let lastChime = -Infinity
567
+ function ring() {
568
+ const t = now()
569
+ if (t - lastChime < CHIME_GAP_MS) return
570
+ lastChime = t
571
+ chime.play()
572
+ }
573
+ function badge() {
574
+ if (!bubble) return
575
+ if (!badgeEl) {
576
+ badgeEl = el(doc, 'span', { class: 'pmw-chat__badge' })
577
+ bubble.append(badgeEl)
578
+ }
579
+ const n = unread > 9 ? '9+' : String(unread)
580
+ badgeEl.replaceChildren(el(doc, 'span', { 'aria-hidden': 'true' }, n), el(doc, 'span', { class: 'pmw-chat__sr' }, fill(unread === 1 ? s.unreadOne : s.unreadMany, { n: String(unread) })))
581
+ root.setAttribute('data-unread', String(unread))
582
+ }
518
583
  function delta(id, text) {
519
584
  hideTyping()
520
585
  let li = find(id)
@@ -702,7 +767,10 @@ export function mountChat(root, deps = {}) {
702
767
  showState('')
703
768
  showTyping()
704
769
  slowTimer = win.setTimeout(() => showState(s.oneMoment), SLOW_START_MS)
705
- starting = post(composer, {}).then((r) => {
770
+ // The opener shown as the first bubble goes with the start (1.3.3): pmeweb-chat makes it the
771
+ // thread's first bot message, so the model reads « Oui » as an answer to it.
772
+ const shown = log.firstElementChild === greeting ? greeting.textContent.trim() : ''
773
+ starting = post(composer, shown ? { opener: shown } : {}).then((r) => {
706
774
  starting = null
707
775
  if (r.ok && r.data.conversationId && r.data.visitorKey) {
708
776
  session = { c: r.data.conversationId, k: r.data.visitorKey, botName: typeof r.data.botName === 'string' ? r.data.botName : null, at: Date.now() }
@@ -818,6 +886,7 @@ export function mountChat(root, deps = {}) {
818
886
  function submit() {
819
887
  const text = input.value.trim()
820
888
  if (!text || over || demo) return
889
+ chime.unlock()
821
890
  input.value = ''
822
891
  grow()
823
892
  const entry = { id: uuid(), text: text.slice(0, MAX_TEXT), tries: 0, failed: false }
@@ -892,6 +961,10 @@ export function mountChat(root, deps = {}) {
892
961
  panel.inert = false
893
962
  root.setAttribute('data-open', '')
894
963
  root.removeAttribute('data-unread')
964
+ unread = 0
965
+ badgeEl?.remove()
966
+ badgeEl = null
967
+ chime.unlock()
895
968
  if (session) connect()
896
969
  ;(demo ? closeBtn : composer.hidden ? (fallback.hidden ? restart : fallback.querySelector('input')) : input)?.focus()
897
970
  follow(true, true)
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.4'
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)) {