useyuva 0.0.9 → 0.0.11

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.
@@ -0,0 +1,11 @@
1
+ class c extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function m(e,t,n,{method:s="GET",json:i,body:r,headers:a={},token:l,blob:o}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=r;if(i!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(i);let u;try{u=await e(t+n,{method:s,headers:a,body:h,credentials:"omit"})}catch{throw new c(0,"network")}if(!u.ok){let p="error";try{p=(await u.json()).code??p}catch{}throw new c(u.status,p)}if(u.status===204)return;return o?await u.blob():await u.json()}function P(e,t,n){return m(e,t,`/client/v1/channels/${encodeURIComponent(n)}/lists`)}function b(e,t,n,s){return m(e,t,`/client/v1/channels/${encodeURIComponent(n)}/subscriptions`,{method:"POST",json:s})}class C{server;socketClass;handlers;#s=null;#o=0;#p=0;#t=null;#a=!0;constructor(e,t,n){this.server=e;this.socketClass=t;this.handlers=n}get connected(){return this.#s?.readyState===1}start(){if(this.#a=!1,!this.#s&&!this.#t)this.#r()}stop(){if(this.#a=!0,this.#t)clearTimeout(this.#t);this.#t=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#o=0}nudge(){if(this.#a||this.#s)return;if(this.#t)clearTimeout(this.#t);this.#t=null,this.#r()}#r(){let e=this.handlers.token();if(!e||this.#a)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#o>0)t.searchParams.set("last_event_id",String(this.#o));let n;try{n=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#n();return}this.#s=n,n.onmessage=(s)=>{let i;try{i=JSON.parse(String(s.data))}catch{return}if(i.type==="ready")this.#p=0,this.#o=Math.max(this.#o,i.last_event_id);else if("id"in i&&typeof i.id==="number")this.#o=Math.max(this.#o,i.id);this.handlers.event(i)},n.onclose=(s)=>{if(this.#s!==n)return;if(this.#s=null,this.#a)return;if(s.code===1008){this.#o=0,this.handlers.sessionEnded();return}this.#n()}}#n(){if(this.#a||this.#t)return;let e=this.#p++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#t=setTimeout(()=>{this.#t=null,this.#r()},t)}}function I(e,t,n){let s=new URL("/account/connect",e);return s.searchParams.set("channel",t),s.searchParams.set("origin",n),s.href}function T(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function R(e,t,{width:n=460,height:s=640}={}){let i=new URL(e).origin,r=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??n)-n)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??s)-s)/2),o=window.open(I(e,t,r),"yuva-reader",`popup=yes,width=${n},height=${s},left=${Math.round(a)},top=${Math.round(l)}`);if(!o)return Promise.reject(new c(0,"popup_blocked"));return new Promise((h,u)=>{let p=!1,f=()=>{p=!0,window.removeEventListener("message",S),clearInterval(v)},S=(d)=>{if(p||d.origin!==i||d.source&&d.source!==o)return;let g=d.data;if(!T(g)||g.channel_key!==t||g.origin!==r)return;f();try{o.close()}catch{}h({token:g.token,expires_at:g.expires_at,reader:g.reader})},v=setInterval(()=>{let d=!1;try{d=o.closed}catch{}if(!d)return;clearInterval(v),setTimeout(()=>{if(p)return;f(),u(new c(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",S)})}function x(e){return`yuva:${e}`}function w(e,t){return`yuva:reader:${e} ${t}`}function k(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function _(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(atob(t));return typeof n.sub==="string"?n.sub:null}catch{return null}}function M(){let e=globalThis.location;if(!e||!/^https?:$/.test(e.protocol))return{};let t=e.origin+e.pathname;if(t.length>2000)return{};let n=Array.from(globalThis.document?.title.trim()??"").slice(0,300).join("").trim();return n?{page_url:t,page_title:n}:{page_url:t}}function U(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,n)=>void e.set(t,n)}}function y(e){let t=new URLSearchParams;for(let[s,i]of Object.entries(e))if(i!==void 0)t.set(s,String(i));let n=t.toString();return n?`?${n}`:""}function E(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function O(e,t,n){let s=[];for(let[i,r]of e)s.push(`--${n}\r
2
+ Content-Disposition: form-data; name="${i}"\r
3
+ \r
4
+ ${r}\r
5
+ `);for(let i of t){let r=i.name||"file";s.push(`--${n}\r
6
+ Content-Disposition: form-data; name="files"; filename="${E(r)}"\r
7
+ Content-Type: ${i.type||"application/octet-stream"}\r
8
+ \r
9
+ `,i,`\r
10
+ `)}return s.push(`--${n}--\r
11
+ `),new Blob(s)}class D{server;channel;#s;#o;#p;#t;#a;#r=null;#n=null;#g=null;#m=null;#i=null;#c;#C=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,n)=>fetch(t,n)),this.#o=e.WebSocket??globalThis.WebSocket,this.#p=e.storage??U(),this.#t=e.identityToken??null,this.#a=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#n}get token(){return this.#r}get connected(){return this.#i?.connected??!1}on(e,t){let n=this.#C.get(e);if(!n)this.#C.set(e,n=new Set);return n.add(t),()=>void n.delete(t)}#l(e,t){for(let n of this.#C.get(e)??[])n(t)}stored(){try{let e=this.#p.getItem(x(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#y(e){try{this.#p.setItem(x(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#h(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#h(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return P(this.#s,this.server,this.channel)}subscribe(e){return b(this.#s,this.server,this.channel,e)}subscriptions(){return this.#e("/client/v1/subscriptions")}subscribeList(e,t){return this.#e(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#e(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#t=e,this.reset()}start(){if(this.#n)return Promise.resolve(this.#n);return this.#g??=this.#P(!1).then((e)=>(this.#l("session",{session:e,renewed:!1}),e)).finally(()=>{this.#g=null}),this.#g}async refresh(){let e=await this.#e("/client/v1/session");return this.#n={...this.#n,...e},this.#l("session",{session:this.#n,renewed:!1}),this.#n}reset(){this.#i?.stop(),this.#i?.reset(),this.#g=null,this.#m=null,this.#r=null,this.#n=null}async signOut(){let e=this.#r;this.reset();let t=this.stored();if(delete t.session,this.#y(t),e)await this.#h("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#o)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#i??=new C(this.server,this.#o,{token:()=>this.#r,event:(e)=>{if(e.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",e)},sessionEnded:()=>void this.#v().catch(()=>this.#i?.nudge()),reconnecting:(e)=>{if(this.#l("connection",{state:"reconnecting",attempt:e}),e===2)this.#e("/client/v1/session").catch(()=>{return})}}),!this.#i.connected)this.#l("connection",{state:"connecting",attempt:0});this.#i.start()}disconnect(){this.#i?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#i?.nudge()}listConversations(e={}){return this.#e(`/client/v1/conversations${y({...e})}`)}getConversation(e){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){let t=e.page_url===void 0?{...e,...M()}:e;return this.#e("/client/v1/conversations",this.#S(t))}listMessages(e,t={}){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/messages${y({...t})}`)}sendMessage(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#S(t))}markRead(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,n){let s={rating:t,comment:n?.trim()||void 0};return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:s})}setTyping(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#e("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#e(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??k();return this.#e("/client/v1/feedback",{method:"POST",headers:this.#f(t),json:{...e,client_id:t}})}get reader(){if(this.#c===void 0)try{let e=this.#p.getItem(w(this.server,this.channel));this.#c=e?JSON.parse(e):null}catch{this.#c=null}if(this.#c&&Date.parse(this.#c.expires_at)<=Date.now()+30000)this.#d(null);return this.#c}#d(e){let t=this.#c?.token!==e?.token;this.#c=e;try{this.#p.setItem(w(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#l("reader",e)}readerSignIn(e){return R(this.server,this.channel,e).then((t)=>(this.#d(t),t))}setReader(e){this.#d(e)}async readerSignOut(){let e=this.reader?.token;if(this.#d(null),e)await this.#h("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${y({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#u("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#u(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#u(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let n=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#u(n,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#n)return this.#n.contact.identified?"contact":null;return await this.#t?.()?"contact":null}async#u(e,t,n=!0){let s=this.reader;if(s)try{return await this.#h(e,{...t,token:s.token})}catch(r){if(!(r instanceof c)||r.status!==401||this.#c?.token!==s.token)throw r;if(this.#d(null),n)throw new c(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#e(e,t);if(n)throw new c(403,"sign_in_required");return this.#h(e,t)}#f(e){return this.#a&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#S({body:e,subject:t,files:n=[],client_id:s=k(),...i}){let r=this.#f(s),a=i.page_url??void 0,l=a?i.page_title:void 0;if(n.length===0)return{method:"POST",headers:r,json:{body:e,subject:t,client_id:s,page_url:a,page_title:l}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);if(o.push(["client_id",s]),a)o.push(["page_url",a]);if(l)o.push(["page_title",l]);let h=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return r["Content-Type"]=`multipart/form-data; boundary=${h}`,{method:"POST",headers:r,body:O(o,n,h)}}#h(e,t){return m(this.#s,this.server,e,t)}async#e(e,t={},n=!0){if(!this.#r)await this.start();try{return await this.#h(e,{...t,token:this.#r})}catch(s){if(!n||!(s instanceof c)||s.status!==401)throw s;return await this.#v(),this.#e(e,t,!1)}}#v(){return this.#m??=(async()=>{let e=await this.#P(!0);if(this.#i)this.#i.stop(),this.#i.reset(),this.#i.start();this.#l("session",{session:e,renewed:!0})})().finally(()=>{this.#m=null}),this.#m}async#P(e){let t=this.stored(),n=await this.#t?.()||null,s=n?_(n):null,i=t.session;if(!e&&i&&i.sub===s&&Date.parse(i.expires_at)>Date.now()+60000)try{let o=await this.#h("/client/v1/session",{token:i.token});return this.#b(o,i.token,s)}catch(o){if(!(o instanceof c)||o.status!==401&&o.status!==403)throw o}let r=await this.#h("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:n??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=r;return this.#b(l,a,s)}#b(e,t,n){this.#r=t,this.#n=e;let s=this.stored();if(s.session={token:t,expires_at:e.expires_at,sub:n},e.visitor_id)s.visitor_id=e.visitor_id;else if(e.contact.identified)delete s.visitor_id;return this.#y(s),e}}function L(e){return new D(e)}export{L as createYuvaClient};
@@ -0,0 +1 @@
1
+ (()=>{var i=()=>{},l=typeof YUVA_ANALYTICS_LITE<"u",_=()=>{try{let{id:e,createdAt:o}=JSON.parse(localStorage.getItem("yuva_pid"));if(Date.now()-o<34000000000)return e}catch{}},z=()=>{try{if(!_())localStorage.setItem("yuva_pid",JSON.stringify({id:crypto.randomUUID(),createdAt:Date.now()}))}catch{}return _()},F=(e)=>{let o=_();try{localStorage.removeItem("yuva_pid")}catch{}return o?[{n:"yuva_consent",u:e,c:{a:0,p:o}}]:[]};function J(e){if(typeof window>"u"||!e.key){let t={pageview:i,track:i,notFound:i,consent:i,optOut:i,optIn:i,destroy:i};return l?t:{...t,identify:i,persistentId:i}}let o=navigator,p=document,T=()=>{try{return localStorage}catch{}},I=`${e.server.replace(/\/$/,"")}/client/v1/analytics/${e.key}`,x=e.hash,k=o.globalPrivacyControl||o.doNotTrack=="1"||o.webdriver,d=k||T()?.getItem("yuva_optout")=="1",y=!e.consent,s=[],P="",a="",C=p.referrer,v=0,S=0,g=0,r,m=(t)=>{let n=JSON.stringify(s[1]?{e:s}:s[0]);if(s[0]&&(s=[],!(t&&o.sendBeacon?.(I,n))))fetch(I,{method:"POST",body:n,keepalive:!0,credentials:"omit"}).then((c)=>void(c.status==403&&(d=k=!0)),i)},A=(t)=>{if(d||!y)return;if(x)t.h=!0;if(l?e.consent:e.consent||r)t.c=l?{a:1}:{...t.c,a:1,p:r};if(s.push(t)<2)setTimeout(m)},E=()=>{let t=Date.now();if(S)v+=t-S;S=p.visibilityState=="visible"&&p.hasFocus()?t:0},N=()=>{g=Math.max(g,Math.min(100,Math.round((scrollY+innerHeight)/p.documentElement.scrollHeight*100))||0)},Y=()=>{if(E(),a&&v>0)A({n:"engagement",u:a,ms:Math.min(v,1800000),sd:g});v=0,g=0,N()},U=()=>location.pathname+(x?location.hash:""),K=(t={})=>{if(d||!y)return;Y(),P=U(),a=t.url||location.href,A({n:"pageview",u:a,r:t.referrer??C,w:innerWidth}),C=void 0},b=(t,{props:n,revenue:c}={})=>A({n:t,u:a||location.href,p:n,$:c&&{a:c.amount,c:c.currency}}),h=()=>!e.manual&&P!=U()&&K(),O=()=>{Y(),m(!0)},L=()=>{if(d=!0,s=l?[]:F(a||location.href),!l)r=void 0,m(!0);T()?.setItem("yuva_optout","1")},q=()=>{d=k,T()?.removeItem("yuva_optout")},M=history.pushState,R=function(...t){M.apply(this,t),h()};history.pushState=R;let f={popstate:h,hashchange:h,prerenderingchange:h,scroll:N,focus:E,blur:E,pagehide:O,visibilitychange:()=>p.visibilityState=="hidden"?O():E(),click:(t)=>{let n=t.target.closest?.("a");if(!n)return;let c=n.getAttribute("href"),D=c=="#yuva-optout"?L:c=="#yuva-optin"?q:0,H=e.files&&/\.(pdf|zip|dmg|exe|apk|csv|xlsx?|docx?|pptx?|mp[34])$/i.test(n.pathname)?"file_download":e.outbound&&n.host!=location.host&&"outbound_click";if(D)t.preventDefault(),D();else if(H&&/^https?:/.test(n.href))b(H,{props:{url:n.href}})}};if(e.chat)f["yuva-open"]=()=>b("chat_open");for(let t in f)addEventListener(t,f[t],!0);if(!p.prerendering)h();let B={pageview:K,track:b,notFound:()=>b("not_found"),consent:(t)=>{if(y=t===!0||!!t.analytics,!l){if(r=void 0,y&&t.persistent&&!d)r=z()}if(y)h();else s=[];if(!l&&!r){let[n]=F(a||location.href);if(n)s.push(n),m(!0)}},optOut:L,optIn:q,destroy:()=>{if(O(),d=!0,history.pushState==R)history.pushState=M;for(let t in f)removeEventListener(t,f[t],!0)}};return l?B:{...B,identify:(t)=>void(r&&A({n:"yuva_consent",u:a||location.href,c:{j:t}})),persistentId:()=>r}}var V=document.currentScript,u=V?.dataset??{},w=window,W=J({key:u.key??"",server:u.api??new URL(V?.src??"/",location.href).origin,hash:"hash"in u,consent:u.consent,manual:"manual"in u,outbound:"outbound"in u,files:"files"in u,chat:"chat"in u}),j=([e,...o])=>W[e]?.(...o),G=w.yuvaq;w.yuva=Object.assign(w.yuva??{},W);w.yuvaq={push:j};G?.forEach?.(j);})();
@@ -1 +1 @@
1
- (()=>{var s=()=>{};function K(e){if(typeof window>"u"||!e.key)return{pageview:s,track:s,notFound:s,consent:s,optOut:s,optIn:s,destroy:s};let r=navigator,c=document,b=()=>{try{return localStorage}catch{}},x=`${e.server.replace(/\/$/,"")}/client/v1/analytics/${e.key}`,E=e.hash,k=r.globalPrivacyControl||r.doNotTrack=="1"||r.webdriver,l=k||b()?.getItem("yuva_optout")=="1",h=!e.consent,o=[],T="",p="",_=c.referrer,y=0,w=0,f=0,P=(t)=>{let n=JSON.stringify(o[1]?{e:o}:o[0]);if(o[0]&&(o=[],!(t&&r.sendBeacon?.(x,n))))fetch(x,{method:"POST",body:n,keepalive:!0,credentials:"omit"}).then((a)=>void(a.status==403&&(l=k=!0)),s)},O=(t)=>{if(l||!h)return;if(E)t.h=!0;if(e.consent)t.c={a:1};if(o.push(t)<2)setTimeout(P)},v=()=>{let t=Date.now();if(w)y+=t-w;w=c.visibilityState=="visible"&&c.hasFocus()?t:0},S=()=>{f=Math.max(f,Math.min(100,Math.round((scrollY+innerHeight)/c.documentElement.scrollHeight*100))||0)},q=()=>{if(v(),p&&y>0)O({n:"engagement",u:p,ms:Math.min(y,1800000),sd:f});y=0,f=0,S()},C=()=>location.pathname+(E?location.hash:""),M=(t={})=>{if(l||!h)return;q(),T=C(),p=t.url||location.href,O({n:"pageview",u:p,r:t.referrer??_,w:innerWidth}),_=void 0},g=(t,{props:n,revenue:a}={})=>O({n:t,u:p||location.href,p:n,$:a&&{a:a.amount,c:a.currency}}),u=()=>!e.manual&&T!=C()&&M(),A=()=>{q(),P(!0)},H=()=>{l=!0,o=[],b()?.setItem("yuva_optout","1")},I=()=>{l=k,b()?.removeItem("yuva_optout")},N=history.pushState,U=function(...t){N.apply(this,t),u()};history.pushState=U;let d={popstate:u,hashchange:u,prerenderingchange:u,scroll:S,focus:v,blur:v,pagehide:A,visibilitychange:()=>c.visibilityState=="hidden"?A():v(),click:(t)=>{let n=t.target.closest?.("a");if(!n)return;let a=n.getAttribute("href"),Y=a=="#yuva-optout"?H:a=="#yuva-optin"?I:0,F=e.files&&/\.(pdf|zip|dmg|exe|apk|csv|xlsx?|docx?|pptx?|mp[34])$/i.test(n.pathname)?"file_download":e.outbound&&n.host!=location.host&&"outbound_click";if(Y)t.preventDefault(),Y();else if(F&&/^https?:/.test(n.href))g(F,{props:{url:n.href}})}};if(e.chat)d["yuva-open"]=()=>g("chat_open");for(let t in d)addEventListener(t,d[t],!0);if(!c.prerendering)u();return{pageview:M,track:g,notFound:()=>g("not_found"),consent:(t)=>{if(h=t===!0||!!t.analytics,h)u();else o=[]},optOut:H,optIn:I,destroy:()=>{if(A(),l=!0,history.pushState==U)history.pushState=N;for(let t in d)removeEventListener(t,d[t],!0)}}}var L=document.currentScript,i=L?.dataset??{},m=window,B=K({key:i.key??"",server:i.api??new URL(L?.src??"/",location.href).origin,hash:"hash"in i,consent:i.consent,manual:"manual"in i,outbound:"outbound"in i,files:"files"in i,chat:"chat"in i}),D=([e,...r])=>B[e]?.(...r),R=m.yuvaq;m.yuva=Object.assign(m.yuva??{},B);m.yuvaq={push:D};R?.forEach?.(D);})();
1
+ (()=>{var s=()=>{};function R(e){if(typeof window>"u"||!e.key)return{pageview:s,track:s,notFound:s,consent:s,optOut:s,optIn:s,destroy:s};let r=navigator,c=document,w=()=>{try{return localStorage}catch{}},T=`${e.server.replace(/\/$/,"")}/client/v1/analytics/${e.key}`,S=e.hash,A=r.globalPrivacyControl||r.doNotTrack=="1"||r.webdriver,l=A||w()?.getItem("yuva_optout")=="1",h=!e.consent,o=[],O="",u="",_=c.referrer,f=0,E=0,y=0,j,I=(t)=>{let n=JSON.stringify(o[1]?{e:o}:o[0]);if(o[0]&&(o=[],!(t&&r.sendBeacon?.(T,n))))fetch(T,{method:"POST",body:n,keepalive:!0,credentials:"omit"}).then((i)=>void(i.status==403&&(l=A=!0)),s)},b=(t)=>{if(l||!h)return;if(S)t.h=!0;if(e.consent)t.c={a:1};if(o.push(t)<2)setTimeout(I)},g=()=>{let t=Date.now();if(E)f+=t-E;E=c.visibilityState=="visible"&&c.hasFocus()?t:0},x=()=>{y=Math.max(y,Math.min(100,Math.round((scrollY+innerHeight)/c.documentElement.scrollHeight*100))||0)},P=()=>{if(g(),u&&f>0)b({n:"engagement",u,ms:Math.min(f,1800000),sd:y});f=0,y=0,x()},C=()=>location.pathname+(S?location.hash:""),N=(t={})=>{if(l||!h)return;P(),O=C(),u=t.url||location.href,b({n:"pageview",u,r:t.referrer??_,w:innerWidth}),_=void 0},v=(t,{props:n,revenue:i}={})=>b({n:t,u:u||location.href,p:n,$:i&&{a:i.amount,c:i.currency}}),d=()=>!e.manual&&O!=C()&&N(),k=()=>{P(),I(!0)},Y=()=>{l=!0,o=[],w()?.setItem("yuva_optout","1")},U=()=>{l=A,w()?.removeItem("yuva_optout")},q=history.pushState,K=function(...t){q.apply(this,t),d()};history.pushState=K;let p={popstate:d,hashchange:d,prerenderingchange:d,scroll:x,focus:g,blur:g,pagehide:k,visibilitychange:()=>c.visibilityState=="hidden"?k():g(),click:(t)=>{let n=t.target.closest?.("a");if(!n)return;let i=n.getAttribute("href"),L=i=="#yuva-optout"?Y:i=="#yuva-optin"?U:0,M=e.files&&/\.(pdf|zip|dmg|exe|apk|csv|xlsx?|docx?|pptx?|mp[34])$/i.test(n.pathname)?"file_download":e.outbound&&n.host!=location.host&&"outbound_click";if(L)t.preventDefault(),L();else if(M&&/^https?:/.test(n.href))v(M,{props:{url:n.href}})}};if(e.chat)p["yuva-open"]=()=>v("chat_open");for(let t in p)addEventListener(t,p[t],!0);if(!c.prerendering)d();return{pageview:N,track:v,notFound:()=>v("not_found"),consent:(t)=>{if(h=t===!0||!!t.analytics,h)d();else o=[]},optOut:Y,optIn:U,destroy:()=>{if(k(),l=!0,history.pushState==K)history.pushState=q;for(let t in p)removeEventListener(t,p[t],!0)}}}var B=document.currentScript,a=B?.dataset??{},m=window,D=R({key:a.key??"",server:a.api??new URL(B?.src??"/",location.href).origin,hash:"hash"in a,consent:a.consent,manual:"manual"in a,outbound:"outbound"in a,files:"files"in a,chat:"chat"in a}),H=([e,...r])=>D[e]?.(...r),F=m.yuvaq;m.yuva=Object.assign(m.yuva??{},D);m.yuvaq={push:H};F?.forEach?.(H);})();
package/dist/yuva-chat.js CHANGED
@@ -6,17 +6,17 @@ That means you use raw catalog or your catalog doesn't have a translation for th
6
6
  ICU features such as interpolation and plurals will not work properly for that message.
7
7
 
8
8
  Please compile your catalog first.
9
- `);if(S(c)&&ee.test(c))return te(c);if(S(c))return c;return Pe(c,this._locale,this._locales)(t,i?.formats)}t=this._.bind(this);date(e,t){return B(this._locales||this._locale,e,t)}number(e,t){return N(this._locales||this._locale,e,t)}}function K(e={}){return new se(e)}var je=K();var Y=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var re=JSON.parse('{"-HY5kX":["Neue Unterhaltung"],"-f5Tkb":["Schlecht"],"09Tv5j":["Verbindung wird wiederhergestellt…"],"0XGLbP":["Ihre Anmeldung ist abgelaufen. Laden Sie die Seite neu und versuchen Sie es erneut."],"1EICzz":["Wir sind gerade nicht da"],"4TqZiz":["Ihre Bewertung konnte nicht gesendet werden. Versuchen Sie es erneut."],"6Uau97":["Überspringen"],"6gRgw8":["Erneut versuchen"],"6lGaum":["Gesehen"],"ASr-r0":["Ältere Unterhaltungen anzeigen"],"Amai22":["Der Chat ist gerade nicht verfügbar."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"JkW3Ph":["Dieser Dateityp wird nicht akzeptiert."],"JlFcis":["Senden"],"KDw4GX":["Erneut versuchen"],"M62PBt":["Gerade ist niemand erreichbar. Hinterlassen Sie Ihre E-Mail-Adresse, dann senden wir die Antwort auch dorthin."],"N7m8E-":["Dateien anhängen"],"NBdIgR":["Kommentar"],"OEEQKT":["Gut"],"Pwqkdw":["Wird geladen…"],"PxYAul":["Schreibt…"],"RzWUUK":["Nachricht schreiben…"],"S63MQu":["Alle Unterhaltungen"],"SOk0EB":["Danke für Ihr Feedback"],"Sad2tK":["Wird gesendet…"],"SdV5Cn":["Schreiben Sie uns, wir antworten hier."],"UY1vmE":["Anhang"],"VggdQJ":["Übliche Antwortzeit: ",["duration"]],"XJURKP":["E-Mail-Adresse"],"YyNOE7":["Unterhaltung"],"ZxJcgC":["Ihre E-Mail-Adresse konnte nicht gespeichert werden. Versuchen Sie es erneut."],"axQ1h6":["Möchten Sie noch etwas ergänzen? (optional)"],"eOu9Px":["Die Datei ist zu groß."],"h69WC6":["Gesendet"],"iGNUZJ":["Danke! Falls Sie nicht mehr da sind, wenn wir antworten, schreiben wir Ihnen an ",["known"],"."],"meAa31":["Noch keine Unterhaltungen"],"nhTADq":["Wir antworten so schnell wie möglich"],"njBr8W":["sie@beispiel.de"],"oXOSPE":["Online"],"t7TeQU":["Nachrichten"],"tHaDPf":[["name"]," schreibt…"],"tfDRzk":["Speichern"],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"uA8iBc":["Wie zufrieden waren Sie?"],"upFvcp":["Nicht gesendet."],"w61W3L":[["0"]," entfernen"],"xDAtGP":["Nachricht"],"ydzYKJ":["Sie:"],"yz7wBu":["Schließen"],"zLzEI3":["Melden Sie sich an, um mit uns zu chatten."]}');var oe=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function ae(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function le(e){return`yuva:${e}`}function F(e){try{let t=localStorage.getItem(le(e));return t?JSON.parse(t):{}}catch{return{}}}function ce(e,t){try{localStorage.setItem(le(e),JSON.stringify(t))}catch{}}class f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function I(e,t,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await e(t+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new f(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}function de(e,t,i){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function he(e,t,i,n){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:n})}class W{server;socketClass;handlers;#s=null;#m=0;#n=0;#r=null;#y=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#y=!1,!this.#s)this.#a()}stop(){if(this.#y=!0,this.#r)clearTimeout(this.#r);this.#r=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#m=0}nudge(){if(this.#y||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let e=this.handlers.token();if(!e||this.#y)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#m>0)t.searchParams.set("last_event_id",String(this.#m));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#u();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#m=Math.max(this.#m,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#m=Math.max(this.#m,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#y)return;if(n.code===1008){this.#m=0,this.handlers.sessionEnded();return}this.#u()}}#u(){if(this.#y||this.#r)return;let e=this.#n++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},t)}}function Ee(e,t,i){let n=new URL("/account/connect",e);return n.searchParams.set("channel",t),n.searchParams.set("origin",i),n.href}function Te(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function ue(e,t,{width:i=460,height:n=640}={}){let s=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??n)-n)/2),c=window.open(Ee(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${n},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(_)},g=(b)=>{if(u||b.origin!==s||b.source&&b.source!==c)return;let d=b.data;if(!Te(d)||d.channel_key!==t||d.origin!==o)return;y();try{c.close()}catch{}h({token:d.token,expires_at:d.expires_at,reader:d.reader})},_=setInterval(()=>{let b=!1;try{b=c.closed}catch{}if(!b)return;clearInterval(_),setTimeout(()=>{if(u)return;y(),p(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function pe(e){return`yuva:${e}`}function fe(e,t){return`yuva:reader:${e} ${t}`}function M(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function ze(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(t));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Re(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,i)=>void e.set(t,i)}}function J(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))if(s!==void 0)t.set(n,String(s));let i=t.toString();return i?`?${i}`:""}function De(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Ie(e,t,i){let n=[];for(let[s,o]of e)n.push(`--${i}\r
9
+ `);if(S(c)&&ee.test(c))return te(c);if(S(c))return c;return Pe(c,this._locale,this._locales)(t,i?.formats)}t=this._.bind(this);date(e,t){return B(this._locales||this._locale,e,t)}number(e,t){return N(this._locales||this._locale,e,t)}}function K(e={}){return new se(e)}var Be=K();var Y=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var re=JSON.parse('{"-HY5kX":["Neue Unterhaltung"],"-f5Tkb":["Schlecht"],"09Tv5j":["Verbindung wird wiederhergestellt…"],"0XGLbP":["Ihre Anmeldung ist abgelaufen. Laden Sie die Seite neu und versuchen Sie es erneut."],"1EICzz":["Wir sind gerade nicht da"],"4TqZiz":["Ihre Bewertung konnte nicht gesendet werden. Versuchen Sie es erneut."],"6Uau97":["Überspringen"],"6gRgw8":["Erneut versuchen"],"6lGaum":["Gesehen"],"ASr-r0":["Ältere Unterhaltungen anzeigen"],"Amai22":["Der Chat ist gerade nicht verfügbar."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"JkW3Ph":["Dieser Dateityp wird nicht akzeptiert."],"JlFcis":["Senden"],"KDw4GX":["Erneut versuchen"],"M62PBt":["Gerade ist niemand erreichbar. Hinterlassen Sie Ihre E-Mail-Adresse, dann senden wir die Antwort auch dorthin."],"N7m8E-":["Dateien anhängen"],"NBdIgR":["Kommentar"],"OEEQKT":["Gut"],"Pwqkdw":["Wird geladen…"],"PxYAul":["Schreibt…"],"RzWUUK":["Nachricht schreiben…"],"S63MQu":["Alle Unterhaltungen"],"SOk0EB":["Danke für Ihr Feedback"],"Sad2tK":["Wird gesendet…"],"SdV5Cn":["Schreiben Sie uns, wir antworten hier."],"UY1vmE":["Anhang"],"VggdQJ":["Übliche Antwortzeit: ",["duration"]],"XJURKP":["E-Mail-Adresse"],"YyNOE7":["Unterhaltung"],"ZxJcgC":["Ihre E-Mail-Adresse konnte nicht gespeichert werden. Versuchen Sie es erneut."],"axQ1h6":["Möchten Sie noch etwas ergänzen? (optional)"],"eOu9Px":["Die Datei ist zu groß."],"h69WC6":["Gesendet"],"iGNUZJ":["Danke! Falls Sie nicht mehr da sind, wenn wir antworten, schreiben wir Ihnen an ",["known"],"."],"meAa31":["Noch keine Unterhaltungen"],"nhTADq":["Wir antworten so schnell wie möglich"],"njBr8W":["sie@beispiel.de"],"oXOSPE":["Online"],"t7TeQU":["Nachrichten"],"tHaDPf":[["name"]," schreibt…"],"tfDRzk":["Speichern"],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"uA8iBc":["Wie zufrieden waren Sie?"],"upFvcp":["Nicht gesendet."],"w61W3L":[["0"]," entfernen"],"xDAtGP":["Nachricht"],"ydzYKJ":["Sie:"],"yz7wBu":["Schließen"],"zLzEI3":["Melden Sie sich an, um mit uns zu chatten."]}');var oe=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function ae(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function le(e){return`yuva:${e}`}function F(e){try{let t=localStorage.getItem(le(e));return t?JSON.parse(t):{}}catch{return{}}}function ce(e,t){try{localStorage.setItem(le(e),JSON.stringify(t))}catch{}}class f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function I(e,t,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await e(t+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new f(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}function de(e,t,i){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function he(e,t,i,n){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:n})}class W{server;socketClass;handlers;#s=null;#m=0;#n=0;#r=null;#y=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#y=!1,!this.#s&&!this.#r)this.#a()}stop(){if(this.#y=!0,this.#r)clearTimeout(this.#r);this.#r=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#m=0}nudge(){if(this.#y||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let e=this.handlers.token();if(!e||this.#y)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#m>0)t.searchParams.set("last_event_id",String(this.#m));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#u();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#m=Math.max(this.#m,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#m=Math.max(this.#m,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#y)return;if(n.code===1008){this.#m=0,this.handlers.sessionEnded();return}this.#u()}}#u(){if(this.#y||this.#r)return;let e=this.#n++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},t)}}function Ee(e,t,i){let n=new URL("/account/connect",e);return n.searchParams.set("channel",t),n.searchParams.set("origin",i),n.href}function Te(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function ue(e,t,{width:i=460,height:n=640}={}){let s=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??n)-n)/2),c=window.open(Ee(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${n},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(_)},g=(b)=>{if(u||b.origin!==s||b.source&&b.source!==c)return;let d=b.data;if(!Te(d)||d.channel_key!==t||d.origin!==o)return;y();try{c.close()}catch{}h({token:d.token,expires_at:d.expires_at,reader:d.reader})},_=setInterval(()=>{let b=!1;try{b=c.closed}catch{}if(!b)return;clearInterval(_),setTimeout(()=>{if(u)return;y(),p(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function pe(e){return`yuva:${e}`}function fe(e,t){return`yuva:reader:${e} ${t}`}function M(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function ze(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(t));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Re(){let e=globalThis.location;if(!e||!/^https?:$/.test(e.protocol))return{};let t=e.origin+e.pathname;if(t.length>2000)return{};let i=Array.from(globalThis.document?.title.trim()??"").slice(0,300).join("").trim();return i?{page_url:t,page_title:i}:{page_url:t}}function De(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,i)=>void e.set(t,i)}}function J(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))if(s!==void 0)t.set(n,String(s));let i=t.toString();return i?`?${i}`:""}function Ie(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Me(e,t,i){let n=[];for(let[s,o]of e)n.push(`--${i}\r
10
10
  Content-Disposition: form-data; name="${s}"\r
11
11
  \r
12
12
  ${o}\r
13
13
  `);for(let s of t){let o=s.name||"file";n.push(`--${i}\r
14
- Content-Disposition: form-data; name="files"; filename="${De(o)}"\r
14
+ Content-Disposition: form-data; name="files"; filename="${Ie(o)}"\r
15
15
  Content-Type: ${s.type||"application/octet-stream"}\r
16
16
  \r
17
17
  `,s,`\r
18
18
  `)}return n.push(`--${i}--\r
19
- `),new Blob(n)}class ge{server;channel;#s;#m;#n;#r;#y;#a=null;#u=null;#w=null;#C=null;#t=null;#v;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,i)=>fetch(t,i)),this.#m=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??Re(),this.#r=e.identityToken??null,this.#y=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#u}get token(){return this.#a}get connected(){return this.#t?.connected??!1}on(e,t){let i=this.#p.get(e);if(!i)this.#p.set(e,i=new Set);return i.add(t),()=>void i.delete(t)}#c(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(pe(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#k(e){try{this.#n.setItem(pe(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return de(this.#s,this.server,this.channel)}subscribe(e){return he(this.#s,this.server,this.channel,e)}subscriptions(){return this.#l("/client/v1/subscriptions")}subscribeList(e,t){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#r=e,this.reset()}start(){if(this.#u)return Promise.resolve(this.#u);return this.#w??=this.#I(!1).then((e)=>(this.#c("session",{session:e,renewed:!1}),e)).finally(()=>{this.#w=null}),this.#w}async refresh(){let e=await this.#l("/client/v1/session");return this.#u={...this.#u,...e},this.#c("session",{session:this.#u,renewed:!1}),this.#u}reset(){this.#t?.stop(),this.#t?.reset(),this.#w=null,this.#C=null,this.#a=null,this.#u=null}async signOut(){let e=this.#a;this.reset();let t=this.stored();if(delete t.session,this.#k(t),e)await this.#f("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#m)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#t??=new W(this.server,this.#m,{token:()=>this.#a,event:(e)=>{if(e.type==="ready")this.#c("connection",{state:"open",attempt:0});this.#c("event",e)},sessionEnded:()=>void this.#D().catch(()=>this.#t?.nudge()),reconnecting:(e)=>{if(this.#c("connection",{state:"reconnecting",attempt:e}),e===2)this.#l("/client/v1/session").catch(()=>{return})}}),!this.#t.connected)this.#c("connection",{state:"connecting",attempt:0});this.#t.start()}disconnect(){this.#t?.stop(),this.#c("connection",{state:"closed",attempt:0})}reconnect(){this.#t?.nudge()}listConversations(e={}){return this.#l(`/client/v1/conversations${J({...e})}`)}getConversation(e){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#l("/client/v1/conversations",this.#z(e))}listMessages(e,t={}){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages${J({...t})}`)}sendMessage(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#z(t))}markRead(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let n={rating:t,comment:i?.trim()||void 0};return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:n})}setTyping(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#l("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#l(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??M();return this.#l("/client/v1/feedback",{method:"POST",headers:this.#x(t),json:{...e,client_id:t}})}get reader(){if(this.#v===void 0)try{let e=this.#n.getItem(fe(this.server,this.channel));this.#v=e?JSON.parse(e):null}catch{this.#v=null}if(this.#v&&Date.parse(this.#v.expires_at)<=Date.now()+30000)this.#i(null);return this.#v}#i(e){let t=this.#v?.token!==e?.token;this.#v=e;try{this.#n.setItem(fe(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#c("reader",e)}readerSignIn(e){return ue(this.server,this.channel,e).then((t)=>(this.#i(t),t))}setReader(e){this.#i(e)}async readerSignOut(){let e=this.reader?.token;if(this.#i(null),e)await this.#f("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${J({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#b("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#b(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#u)return this.#u.contact.identified?"contact":null;return await this.#r?.()?"contact":null}async#b(e,t,i=!0){let n=this.reader;if(n)try{return await this.#f(e,{...t,token:n.token})}catch(o){if(!(o instanceof f)||o.status!==401||this.#v?.token!==n.token)throw o;if(this.#i(null),i)throw new f(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#l(e,t);if(i)throw new f(403,"sign_in_required");return this.#f(e,t)}#x(e){return this.#y&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#z({body:e,subject:t,files:i=[],client_id:n=M()}){let s=this.#x(n);if(i.length===0)return{method:"POST",headers:s,json:{body:e,subject:t,client_id:n}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",n]);let a=`yuva-${n.replace(/[^\w-]/g,"").slice(0,60)}-${n.length}`;return s["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:s,body:Ie(o,i,a)}}#f(e,t){return I(this.#s,this.server,e,t)}async#l(e,t={},i=!0){if(!this.#a)await this.start();try{return await this.#f(e,{...t,token:this.#a})}catch(n){if(!i||!(n instanceof f)||n.status!==401)throw n;return await this.#D(),this.#l(e,t,!1)}}#D(){return this.#C??=(async()=>{let e=await this.#I(!0);if(this.#t)this.#t.stop(),this.#t.reset(),this.#t.start();this.#c("session",{session:e,renewed:!0})})().finally(()=>{this.#C=null}),this.#C}async#I(e){let t=this.stored(),i=await this.#r?.()||null,n=i?ze(i):null,s=t.session;if(!e&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#f("/client/v1/session",{token:s.token});return this.#M(c,s.token,n)}catch(c){if(!(c instanceof f)||c.status!==401&&c.status!==403)throw c}let o=await this.#f("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=o;return this.#M(l,a,n)}#M(e,t,i){this.#a=t,this.#u=e;let n=this.stored();if(n.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)n.visitor_id=e.visitor_id;else if(e.contact.identified)delete n.visitor_id;return this.#k(n),e}}function me(e){return new ge(e)}var ye=`
19
+ `),new Blob(n)}class ge{server;channel;#s;#m;#n;#r;#y;#a=null;#u=null;#w=null;#k=null;#t=null;#v;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,i)=>fetch(t,i)),this.#m=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??De(),this.#r=e.identityToken??null,this.#y=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#u}get token(){return this.#a}get connected(){return this.#t?.connected??!1}on(e,t){let i=this.#p.get(e);if(!i)this.#p.set(e,i=new Set);return i.add(t),()=>void i.delete(t)}#c(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(pe(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#C(e){try{this.#n.setItem(pe(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return de(this.#s,this.server,this.channel)}subscribe(e){return he(this.#s,this.server,this.channel,e)}subscriptions(){return this.#l("/client/v1/subscriptions")}subscribeList(e,t){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#r=e,this.reset()}start(){if(this.#u)return Promise.resolve(this.#u);return this.#w??=this.#I(!1).then((e)=>(this.#c("session",{session:e,renewed:!1}),e)).finally(()=>{this.#w=null}),this.#w}async refresh(){let e=await this.#l("/client/v1/session");return this.#u={...this.#u,...e},this.#c("session",{session:this.#u,renewed:!1}),this.#u}reset(){this.#t?.stop(),this.#t?.reset(),this.#w=null,this.#k=null,this.#a=null,this.#u=null}async signOut(){let e=this.#a;this.reset();let t=this.stored();if(delete t.session,this.#C(t),e)await this.#f("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#m)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#t??=new W(this.server,this.#m,{token:()=>this.#a,event:(e)=>{if(e.type==="ready")this.#c("connection",{state:"open",attempt:0});this.#c("event",e)},sessionEnded:()=>void this.#D().catch(()=>this.#t?.nudge()),reconnecting:(e)=>{if(this.#c("connection",{state:"reconnecting",attempt:e}),e===2)this.#l("/client/v1/session").catch(()=>{return})}}),!this.#t.connected)this.#c("connection",{state:"connecting",attempt:0});this.#t.start()}disconnect(){this.#t?.stop(),this.#c("connection",{state:"closed",attempt:0})}reconnect(){this.#t?.nudge()}listConversations(e={}){return this.#l(`/client/v1/conversations${J({...e})}`)}getConversation(e){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){let t=e.page_url===void 0?{...e,...Re()}:e;return this.#l("/client/v1/conversations",this.#z(t))}listMessages(e,t={}){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages${J({...t})}`)}sendMessage(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#z(t))}markRead(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let n={rating:t,comment:i?.trim()||void 0};return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:n})}setTyping(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#l("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#l(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??M();return this.#l("/client/v1/feedback",{method:"POST",headers:this.#x(t),json:{...e,client_id:t}})}get reader(){if(this.#v===void 0)try{let e=this.#n.getItem(fe(this.server,this.channel));this.#v=e?JSON.parse(e):null}catch{this.#v=null}if(this.#v&&Date.parse(this.#v.expires_at)<=Date.now()+30000)this.#i(null);return this.#v}#i(e){let t=this.#v?.token!==e?.token;this.#v=e;try{this.#n.setItem(fe(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#c("reader",e)}readerSignIn(e){return ue(this.server,this.channel,e).then((t)=>(this.#i(t),t))}setReader(e){this.#i(e)}async readerSignOut(){let e=this.reader?.token;if(this.#i(null),e)await this.#f("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${J({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#b("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#b(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#u)return this.#u.contact.identified?"contact":null;return await this.#r?.()?"contact":null}async#b(e,t,i=!0){let n=this.reader;if(n)try{return await this.#f(e,{...t,token:n.token})}catch(o){if(!(o instanceof f)||o.status!==401||this.#v?.token!==n.token)throw o;if(this.#i(null),i)throw new f(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#l(e,t);if(i)throw new f(403,"sign_in_required");return this.#f(e,t)}#x(e){return this.#y&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#z({body:e,subject:t,files:i=[],client_id:n=M(),...s}){let o=this.#x(n),a=s.page_url??void 0,l=a?s.page_title:void 0;if(i.length===0)return{method:"POST",headers:o,json:{body:e,subject:t,client_id:n,page_url:a,page_title:l}};let c=[];if(t)c.push(["subject",t]);if(e)c.push(["body",e]);if(c.push(["client_id",n]),a)c.push(["page_url",a]);if(l)c.push(["page_title",l]);let h=`yuva-${n.replace(/[^\w-]/g,"").slice(0,60)}-${n.length}`;return o["Content-Type"]=`multipart/form-data; boundary=${h}`,{method:"POST",headers:o,body:Me(c,i,h)}}#f(e,t){return I(this.#s,this.server,e,t)}async#l(e,t={},i=!0){if(!this.#a)await this.start();try{return await this.#f(e,{...t,token:this.#a})}catch(n){if(!i||!(n instanceof f)||n.status!==401)throw n;return await this.#D(),this.#l(e,t,!1)}}#D(){return this.#k??=(async()=>{let e=await this.#I(!0);if(this.#t)this.#t.stop(),this.#t.reset(),this.#t.start();this.#c("session",{session:e,renewed:!0})})().finally(()=>{this.#k=null}),this.#k}async#I(e){let t=this.stored(),i=await this.#r?.()||null,n=i?ze(i):null,s=t.session;if(!e&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#f("/client/v1/session",{token:s.token});return this.#M(c,s.token,n)}catch(c){if(!(c instanceof f)||c.status!==401&&c.status!==403)throw c}let o=await this.#f("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=o;return this.#M(l,a,n)}#M(e,t,i){this.#a=t,this.#u=e;let n=this.stored();if(n.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)n.visitor_id=e.visitor_id;else if(e.contact.identified)delete n.visitor_id;return this.#C(n),e}}function me(e){return new ge(e)}var ye=`
20
20
  [hidden] { display: none !important; }
21
21
  .header {
22
22
  display: flex;
@@ -208,6 +208,6 @@ Content-Type: ${s.type||"application/octet-stream"}\r
208
208
  .banner { padding: 6px 12px; background: var(--yuva-soft); color: var(--yuva-muted); font-size: 13px; text-align: center; }
209
209
  @media (max-width: 480px) { .composer textarea, .card input, .card textarea { font-size: 16px; } }
210
210
  .sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
211
- `;var Me=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Le(e,t){let i=document.createElement("a");return i.href=e,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function G(e,t){let i=document.createElement(e);return i.append(...t),i}function q(e){let t=[],i=0;for(let n of e.matchAll(Me)){let s=n.index??0;if(s>i)t.push(document.createTextNode(e.slice(i,s)));let[o,a,l,c,h]=n;if(a)t.push(G("code",[document.createTextNode(a.slice(1,-1))]));else if(l)t.push(G("strong",q(l.slice(2,-2))));else if(c)t.push(G("em",q(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);t.push(u.protocol==="http:"||u.protocol==="https:"?Le(u.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=s+o.length}if(i<e.length)t.push(document.createTextNode(e.slice(i)));return t}function L(e){let t=document.createDocumentFragment(),i=e.trim().replace(/\r\n?/g,`
211
+ `;var Le=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Ae(e,t){let i=document.createElement("a");return i.href=e,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function G(e,t){let i=document.createElement(e);return i.append(...t),i}function q(e){let t=[],i=0;for(let n of e.matchAll(Le)){let s=n.index??0;if(s>i)t.push(document.createTextNode(e.slice(i,s)));let[o,a,l,c,h]=n;if(a)t.push(G("code",[document.createTextNode(a.slice(1,-1))]));else if(l)t.push(G("strong",q(l.slice(2,-2))));else if(c)t.push(G("em",q(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);t.push(u.protocol==="http:"||u.protocol==="https:"?Ae(u.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=s+o.length}if(i<e.length)t.push(document.createTextNode(e.slice(i)));return t}function L(e){let t=document.createDocumentFragment(),i=e.trim().replace(/\r\n?/g,`
212
212
  `).split(/^```[^\n]*\n([\s\S]*?)^```[ \t]*$/m);return i.forEach((n,s)=>{if(s%2===1){let a=document.createElement("pre");a.textContent=n.replace(/\n$/,""),t.append(a);return}(i.length>1?n.replace(/^\n|\n$/g,""):n).split(`
213
- `).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...q(a))})}),t}var Ae={en:Y,tr:oe,de:re},Oe=10,ve=300000,P={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}function z(e,t,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=e,s.setAttribute("aria-label",t),s.title=t,s.addEventListener("click",i),s}var x=(e)=>Date.parse(e),be=(e,t)=>x(e.created_at)-x(t.created_at),Ue=(e,t)=>x(t.last_message_at??t.created_at)-x(e.last_message_at??e.created_at),A=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,$e=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class xe{#s;#m;#n;#r=null;#y=null;#a="loading";#u="";#w=null;#C=null;#t=new Map;#v;#p=new Map;#c=[];#k=new Map;#i=null;#b=!1;#x=[];#z=0;#f=null;#l=new Map;#D=new Map;#I=new Map;#M=!1;#S="";#H=!1;#_=new Map;#ke=r("div","card rate");#g=r("textarea");#Q="";#re=null;#V=r("header","header");#X=r("div","banner");#U=r("div","body");#d=r("div","scroll");#P=r("div","card");#E=r("input");#oe=r("div","composer");#Z=r("div","chips");#h=r("textarea");#T=r("input");#$;#K;#ee=r("div","sr");#Y;#L=!0;constructor(e){this.#s=e;let{server:t,channel:i}=e.config();this.#n=me({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#n.on("event",(s)=>this.#_e(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#b=o>0,this.#ne()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#W(s.inbox),this.#y=s.contact,o)this.#pe()}),this.#le(),this.#ee.setAttribute("aria-live","polite"),this.#d.addEventListener("scroll",()=>{if(this.#L=this.#d.scrollHeight-this.#d.scrollTop-this.#d.clientHeight<48,this.#d.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#G(this.#i.id,!0)}),this.#h.rows=1,this.#h.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#ie()}),this.#h.addEventListener("input",()=>{this.#ge(),this.#B(),this.#Te()}),this.#h.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#fe(o)}),this.#T.type="file",this.#T.multiple=!0,this.#T.hidden=!0,this.#T.addEventListener("change",()=>{this.#fe(Array.from(this.#T.files??[])),this.#T.value=""}),this.#K=z(P.attach,"",()=>this.#T.click()),this.#$=z(P.send,"",()=>void this.#ie(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#ie()}),n.append(this.#K,this.#h,this.#$,this.#T),this.#oe.append(this.#Z,n),this.#E.type="email",this.#E.required=!0,this.#E.autocomplete="email",this.#g.rows=2,this.#g.maxLength=2000,this.#g.dir="auto",document.addEventListener("visibilitychange",this.#F),window.addEventListener("online",this.#F),this.#we(),this.#N()}update(){this.#le(),this.#we()}opened(){if(this.#a==="error"){this.#w=null,this.#N();return}if(this.#a==="ready")this.#n.token?this.#Se():this.#ce().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#R(),this.#j(),this.#s.config().layout==="launcher")this.#h.focus({preventScroll:!0})}closed(){this.#O()}identityChanged(){this.#ae(),this.#N()}async signOut(){let e=this.#n.signOut();if(this.#ae(),await e,this.#s.isOpen())this.#N();else this.#o()}destroy(){this.#n.reset(),this.#O(),document.removeEventListener("visibilitychange",this.#F),window.removeEventListener("online",this.#F);for(let e of this.#l.values())URL.revokeObjectURL(e)}#ae(){this.#n.reset(),this.#w=null,this.#C=null,this.#r=null,this.#y=null,this.#a="loading",this.#t.clear(),this.#p.clear(),this.#c=[],this.#_.clear(),this.#Q="",this.#i=null,this.#H=!1,this.#s.setUnread(0)}#F=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#j(),this.#he()};#le(){let{locale:e}=this.#s.config();this.#m=K({locale:e,messages:{[e]:Ae[e]??Y}})}#e(e){return this.#m._(e)}#N(){return this.#w??=(async()=>{this.#a="loading",this.#o();let{channel:e}=this.#s.config();if(!e)throw new f(0,"not_configured");if(await this.#s.identityToken()||F(e).session)await this.#Ce();else if(await this.#ce(),!this.#r?.chat.allow_anonymous)throw new f(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let t=this.#xe();if(this.#i=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#G(this.#i.id)}this.#o(),this.#R(),this.#j()})().catch((e)=>{if(this.#w=null,this.#ue(e))return;this.#a="error",this.#u=e instanceof f?e.code:"error",this.#o()}),this.#w}async#ce(){let e=await this.#de();if(!this.#n.token)this.#W(e)}#de(){if(!this.#s.config().channel)throw new f(0,"not_configured");return this.#n.channelSettings()}#W(e){let{channel:t}=this.#s.config();this.#r=e;let i=ae(e);if(this.#s.setLauncher(i),t)ce(t,{...F(t),launcher:i})}async#he(){if(this.#a!=="ready")return;try{this.#W(await this.#de()),this.#o()}catch(e){this.#ue(e,!0)}}#ue(e,t=!this.#n.token){let i=e instanceof f&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#s.refused();return i}#Ce(){return this.#C??=(async()=>{await this.#n.start(),await this.#J(),await this.#n.connect()})().finally(()=>{this.#C=null}),this.#C}async#Se(){try{await this.#n.refresh(),this.#o()}catch{}}async#J(e=!1){let t=await this.#n.listConversations({limit:50,cursor:e?this.#v:void 0});if(!e)this.#t.clear();for(let i of t.items)this.#t.set(i.id,i);this.#v=t.next_cursor,this.#A()}async#pe(){await this.#J();let e=this.#i?.kind==="thread"?this.#i.id:null;for(let t of this.#p.keys())if(t!==e)this.#p.delete(t);if(e)this.#p.delete(e),await this.#G(e);this.#o()}async#G(e,t=!1){let i=this.#p.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#p.set(e,i);if(i.loading||t&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#d.scrollHeight-this.#d.scrollTop;try{let s=await this.#n.listMessages(e,{order:"desc",limit:30,cursor:t?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(be),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#o(),this.#d.scrollTop=this.#d.scrollHeight-n}#_e(e){switch(e.type){case"ready":if(this.#b=!1,this.#ne(),this.#H)this.#he();this.#H=!0;return;case"inbox.updated":{let t=this.#r?.ask_for_rating;if(this.#W(e.data),t!==void 0&&t!==e.data.ask_for_rating)this.#J().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pe();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#t.has(e.data.id))this.#t.set(e.data.id,e.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#t.size>1)this.#i=this.#c.some((t)=>t.conversation===null)?this.#i:{kind:"list"};this.#A();break;case"conversation.updated":{let t=this.#t.get(e.data.id),{status:i,can_rate:n,rating:s}=e.data;if(t)this.#t.set(t.id,{...t,status:i,can_rate:n,rating:s});if(!n)this.#_.delete(e.data.id);break}case"message.created":case"message.updated":this.#te(e.data,e.type==="message.created");break;case"read":{let t=this.#t.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||x(e.data.read_at)>x(i)))this.#t.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#k.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#k.set(t,{name:n,timer:setTimeout(()=>this.#k.delete(t)&&this.#o(),8000)})}else this.#k.delete(t);break}}this.#o()}#te(e,t){let i=e.conversation_id,n=this.#p.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===e.id);if(o>=0)n.messages[o]=e;else n.messages=[...n.messages,e].sort(be)}if(e.client_id)this.#c=this.#c.filter((o)=>o.client_id!==e.client_id);let s=this.#t.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#t.set(o.id,o),this.#A(),this.#o()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#t.set(i,{...s,last_message:{id:e.id,author_type:e.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:e.created_at},last_message_at:e.created_at,unread:s.unread||e.author.type!=="contact"}),e.author.type!=="contact"){let a=this.#k.get(i);if(a)clearTimeout(a.timer);this.#k.delete(i),this.#Pe(e)}}this.#A(),this.#j()}#Pe(e){this.#ee.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#A(){let e=0;for(let t of this.#t.values())if(t.unread)e++;this.#s.setUnread(e)}#Ee(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#j(){let e=this.#Ee(),t=e?this.#t.get(e):void 0;if(!e||!t?.unread)return;this.#t.set(e,{...t,unread:!1}),this.#A(),this.#n.markRead(e).catch(()=>{let i=this.#t.get(e);if(i)this.#t.set(e,{...i,unread:!0});this.#A()})}#fe(e){this.#x=[...this.#x,...e].slice(0,Oe),this.#q(),this.#B(),this.#h.focus()}#ge(){if(this.#h.style.blockSize="",this.#h.value==="")return;this.#h.style.blockSize="auto",this.#h.style.blockSize=`${Math.max(38,Math.min(this.#h.scrollHeight,140))}px`}#B(){this.#$.disabled=this.#h.value.trim()===""&&this.#x.length===0}#Te(){let e=this.#i?.kind==="thread"?this.#i.id:null;if(!e||this.#h.value.trim()===""){this.#O();return}if(Date.now()-this.#z>3000)this.#z=Date.now(),this.#n.setTyping(e,!0).catch(()=>{return});if(this.#f)clearTimeout(this.#f);this.#f=setTimeout(()=>this.#O(),4000)}#O(){if(this.#f)clearTimeout(this.#f);if(this.#f=null,this.#z===0)return;this.#z=0;let e=this.#i?.kind==="thread"?this.#i.id:null;if(e)this.#n.setTyping(e,!1).catch(()=>{return})}async#ie(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let e=this.#h.value.trim(),t=this.#x;if(!e&&t.length===0)return;if(this.#i.id===null&&this.#c.some((n)=>n.conversation===null))return;this.#O(),this.#h.value="",this.#x=[],this.#ge(),this.#q(),this.#B();let i={client_id:M(),conversation:this.#i.id,body:e,files:t,state:"sending"};this.#c.push(i),this.#o(),this.#R(),await this.#me(i)}async#me(e){e.state="sending",this.#o();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#n.startConversation(t),n=i.conversation.id;if(!this.#t.has(n))this.#t.set(n,i.conversation);if(!this.#p.has(n))this.#p.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#te(i.message,!1)}else{let i=await this.#n.sendMessage(e.conversation,t);this.#te(i,!0)}this.#c=this.#c.filter((i)=>i!==e)}catch(i){let n=i instanceof f?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#o(),this.#R()}async rate(e,t,i){try{let n=await this.#n.rate(e,t,i);return this.#t.set(n.id,n),this.#_.delete(e),this.#o(),n}catch(n){if(n instanceof f&&n.status===409){let s=await this.#n.getConversation(e).catch(()=>null);if(s)this.#t.set(s.id,s);this.#_.delete(e),this.#o()}throw n}}#ze(e,t){if(this.#_.get(e)?.state==="sending")return;if(this.#_.set(e,{choice:t,state:"choosing"}),this.#o(),this.#g.focus({preventScroll:!0}),this.#L)this.#R()}async#ye(e,t){let i=this.#_.get(e);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(e,i.choice,t?this.#g.value:void 0),this.#g.value=""}catch(n){if(n instanceof f&&n.status===409)return;i.state="failed",this.#o()}}async#Re(){let e=this.#E.value.trim();if(!e||!this.#E.checkValidity()){this.#S=this.#e({id:"E_qvzP"}),this.#se();return}try{this.#y=await this.#n.setEmail(e),this.#M=!0,this.#S=""}catch{this.#S=this.#e({id:"ZxJcgC"})}this.#se()}#ve(e){let t=this.#l.get(e.id);if(t)return Promise.resolve(t);let i=this.#D.get(e.id);if(!i)i=this.#n.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#l.set(e.id,s),s}),i.catch(()=>this.#D.delete(e.id)),this.#D.set(e.id,i);return i}async#be(e){let t=await this.#ve(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#xe(){return[...this.#t.values()].sort(Ue)}#De(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#R(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#we(){this.#h.placeholder=this.#e({id:"RzWUUK"}),this.#h.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#K.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#K.title=this.#e({id:"N7m8E-"}),this.#$.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#$.title=this.#e({id:"JlFcis"}),this.#E.placeholder=this.#e({id:"njBr8W"}),this.#E.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#B(),this.#q(),this.#o()}#o(){let e=this.#s.panel;if(e.childElementCount===0){let t=r("style");t.textContent=ye,e.append(t,this.#V,this.#X,this.#U,this.#ee),this.#V.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#Me(),this.#ne(),this.#a!=="ready"){this.#Y=void 0;let t=r("div","center");if(this.#a==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Ie()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#w=null,this.#N()}),t.append(i)}this.#U.replaceChildren(t);return}if(this.#i?.kind==="list")this.#Ae();else this.#$e()}#Ie(){switch(this.#u){case"anonymous_not_allowed":return this.#e({id:"zLzEI3"});case"invalid_identity_token":return this.#e({id:"0XGLbP"});case"rate_limited":return this.#e({id:"tzsBOP"});case"network":return this.#e({id:"GQVIIl"});default:return this.#e({id:"Amai22"})}}#Me(){let{layout:e}=this.#s.config(),t=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#t.size>1||n.id===null&&this.#t.size>0))i.push(z(P.back,this.#e({id:"S63MQu"}),()=>{this.#O(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",t?.name||this.#e({id:"t7TeQU"}))),t){let o=r("div","status");if(t.mode==="live"&&t.open_now&&t.presence?.available){let l=r("div","avatars");for(let c of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#e({id:"oXOSPE"})))}else if(!t.open_now||t.mode==="live")o.append(r("span","dot away"),r("span","",this.#e({id:"1EICzz"})));else o.append(r("span","",this.#Le(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(z(P.close,this.#e({id:"yz7wBu"}),()=>this.#s.close()));this.#V.replaceChildren(...i)}#Le(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#s.config(),[i,n]=e<60?[e,"minute"]:e<1440?[Math.round(e/60),"hour"]:[Math.round(e/1440),"day"],s=new Intl.NumberFormat(t,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#e({id:"VggdQJ",values:{duration:s}})}#ne(){this.#X.hidden=!this.#b,this.#X.textContent=this.#e({id:"09Tv5j"})}#Ae(){this.#Y=void 0;let{locale:e}=this.#s.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#xe()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#e({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Oe(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#v){let s=r("button","link",this.#e({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#J(!0).then(()=>this.#o())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#h.focus()}),this.#U.replaceChildren(t,n)}async#Oe(e){if(this.#i={kind:"thread",id:e},this.#o(),!this.#p.get(e)?.complete&&!this.#p.get(e)?.messages.length)await this.#G(e).catch(()=>{return});this.#o(),this.#R(),this.#j()}#Ue(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#I.get(i):!1;if(!i||n===!1)return t;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,t.replaceChildren(s),t;return s.addEventListener("load",()=>{if(this.#I.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#I.set(i,!1)),s.src=i,t}#$e(){let e=this.#i;if(e?.kind!=="thread")return;let t=e.id,i=this.#Y===t,n=this.#L,s=t?this.#p.get(t):void 0,o=s?.messages??[],a=this.#c.filter((d)=>d.conversation===t),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(L(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((d,v)=>{let k=o[v-1],w=o[v+1]??(a.length>0?null:void 0),m=d.author.type==="contact",C=!k||A(k)!==A(d)||x(d.created_at)-x(k.created_at)>ve,H=w===void 0||(w===null?!m:A(w)!==A(d)||x(w.created_at)-x(d.created_at)>ve);if(!m&&C&&d.author.name)l.push(r("div","author",d.author.name));let O=r("div",`row ${m?"mine":"theirs"}${C&&v>0?" group-gap":""}`);if(!m){let T=this.#Ue(d.author);if(!H)T.style.visibility="hidden";O.append(T)}let E=r("div","bubble");if(E.dir="auto",E.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())E.append(L(d.body));if(d.attachments.length>0)E.append(this.#je(d.attachments));if(O.append(E),l.push(O),H){let T=this.#Be(d.created_at);if(m&&v===o.length-1&&a.length===0){let Q=t?this.#t.get(t)?.last_read_by_member_at:void 0,we=Q&&x(Q)>=x(d.created_at);T+=` · ${we?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let U=r("div","meta",T);if(!m)U.style.alignSelf="flex-start";if(!m)U.style.marginInlineStart="36px";l.push(U)}});let h=t?this.#t.get(t):void 0,p=h?this.#Ne(h):null;if(p)l.push(p);a.forEach((d,v)=>{let k=r("div",`row mine${v===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),w=r("div","bubble");if(w.dir="auto",d.body)w.append(L(d.body));if(d.files.length>0){let m=r("div","files");for(let C of d.files)m.append(r("span","file",C.name||"image"));w.append(m)}if(k.append(w),l.push(k),d.state==="failed"){let m=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),C=r("button","link",this.#e({id:"6gRgw8"}));C.type="button",C.addEventListener("click",()=>void this.#me(d)),m.append(C),l.push(m)}else if(d.state==="refused"){let m=d.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${m}`))}else if(v===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let u=t?this.#k.get(t):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let v=u.name;d.append(r("span","",v?this.#e({id:"tHaDPf",values:{name:v}}):this.#e({id:"PxYAul"}))),l.push(d)}let g=this.#d.getRootNode().activeElement===this.#g,{selectionStart:_,selectionEnd:b}=this.#g;if(this.#d.replaceChildren(...l),g&&this.#g.isConnected)this.#g.focus({preventScroll:!0}),this.#g.setSelectionRange(_,b);if(this.#se(),this.#U.firstChild!==this.#d)this.#U.replaceChildren(this.#d,this.#P,this.#oe);if(this.#Y=t,!i||n)this.#R()}#Ne(e){let t=e.status==="closed"?e.rating:void 0,i=e.can_rate&&this.#r?.ask_for_rating?this.#_.get(e.id):void 0;if(!t&&!(e.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#ke,s=[e.id,t,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#re!==e.id)this.#re=e.id,this.#g.value="";let o=this.#e({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(t&&t!==u)continue;let y=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");y.type="button";let g=u==="good"?this.#e({id:"OEEQKT"}):this.#e({id:"-f5Tkb"});y.setAttribute("aria-label",g),y.title=g,y.setAttribute("aria-pressed",String((t??i?.choice)===u)),y.disabled=!!t||i?.state==="sending",y.addEventListener("click",()=>this.#ze(e.id,u)),a.append(y)}if(t)return n.replaceChildren(a,r("p","",this.#e({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#g.placeholder=this.#e({id:"axQ1h6"}),this.#g.setAttribute("aria-label",this.#e({id:"NBdIgR"})),this.#g.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#ye(e.id,!0)});let c=r("button","link",this.#e({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#ye(e.id,!1));let h=r("button","",i.state==="sending"?this.#e({id:"Sad2tK"}):this.#e({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#g,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#e({id:"4TqZiz"})));return n}#je(e){let t=r("div","files");for(let i of e)if($e(i)){let n=r("img");n.alt=i.filename;let s=this.#l.get(i.id);if(s)n.src=s;else this.#ve(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight}),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=P.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}return t}#Be(e){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(e))}#se(){let e=this.#y,t=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#c.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#De()&&n&&(!s||this.#M);if(this.#P.hidden=!o,!o)return;if(s&&this.#M){this.#P.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#P.querySelector("form")){let c=this.#P.querySelector(".error");if(c)c.textContent=this.#S;else if(this.#S)this.#P.append(r("p","error",this.#S));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#Re()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#E,l),this.#P.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#S)this.#P.append(r("p","error",this.#S))}#q(){this.#Z.hidden=this.#x.length===0,this.#Z.replaceChildren(...this.#x.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),z(P.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#x=this.#x.filter((n,s)=>s!==t),this.#q(),this.#B()})),i}))}}function Ne(e){return new xe(e)}export{Ne as mount};
213
+ `).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...q(a))})}),t}var Oe={en:Y,tr:oe,de:re},Ue=10,ve=300000,P={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}function z(e,t,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=e,s.setAttribute("aria-label",t),s.title=t,s.addEventListener("click",i),s}var x=(e)=>Date.parse(e),be=(e,t)=>x(e.created_at)-x(t.created_at),$e=(e,t)=>x(t.last_message_at??t.created_at)-x(e.last_message_at??e.created_at),A=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,Ne=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class xe{#s;#m;#n;#r=null;#y=null;#a="loading";#u="";#w=null;#k=null;#t=new Map;#v;#p=new Map;#c=[];#C=new Map;#i=null;#b=!1;#x=[];#z=0;#f=null;#l=new Map;#D=new Map;#I=new Map;#M=!1;#S="";#H=!1;#_=new Map;#ke=r("div","card rate");#g=r("textarea");#Q="";#re=null;#V=r("header","header");#X=r("div","banner");#U=r("div","body");#d=r("div","scroll");#P=r("div","card");#E=r("input");#oe=r("div","composer");#Z=r("div","chips");#h=r("textarea");#T=r("input");#$;#K;#ee=r("div","sr");#Y;#L=!0;constructor(e){this.#s=e;let{server:t,channel:i}=e.config();this.#n=me({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#n.on("event",(s)=>this.#_e(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#b=o>0,this.#ne()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#W(s.inbox),this.#y=s.contact,o)this.#pe();else if(!this.#k)this.#n.connect().catch(()=>{return})}),this.#le(),this.#ee.setAttribute("aria-live","polite"),this.#d.addEventListener("scroll",()=>{if(this.#L=this.#d.scrollHeight-this.#d.scrollTop-this.#d.clientHeight<48,this.#d.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#G(this.#i.id,!0)}),this.#h.rows=1,this.#h.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#ie()}),this.#h.addEventListener("input",()=>{this.#ge(),this.#B(),this.#Te()}),this.#h.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#fe(o)}),this.#T.type="file",this.#T.multiple=!0,this.#T.hidden=!0,this.#T.addEventListener("change",()=>{this.#fe(Array.from(this.#T.files??[])),this.#T.value=""}),this.#K=z(P.attach,"",()=>this.#T.click()),this.#$=z(P.send,"",()=>void this.#ie(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#ie()}),n.append(this.#K,this.#h,this.#$,this.#T),this.#oe.append(this.#Z,n),this.#E.type="email",this.#E.required=!0,this.#E.autocomplete="email",this.#g.rows=2,this.#g.maxLength=2000,this.#g.dir="auto",document.addEventListener("visibilitychange",this.#F),window.addEventListener("online",this.#F),this.#we(),this.#N()}update(){this.#le(),this.#we()}opened(){if(this.#a==="error"){this.#w=null,this.#N();return}if(this.#a==="ready")this.#n.token?this.#Se():this.#ce().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#R(),this.#j(),this.#s.config().layout==="launcher")this.#h.focus({preventScroll:!0})}closed(){this.#O()}identityChanged(){this.#ae(),this.#N()}async signOut(){let e=this.#n.signOut();if(this.#ae(),await e,this.#s.isOpen())this.#N();else this.#o()}destroy(){this.#n.reset(),this.#O(),document.removeEventListener("visibilitychange",this.#F),window.removeEventListener("online",this.#F);for(let e of this.#l.values())URL.revokeObjectURL(e)}#ae(){this.#n.reset(),this.#w=null,this.#k=null,this.#r=null,this.#y=null,this.#a="loading",this.#t.clear(),this.#p.clear(),this.#c=[],this.#_.clear(),this.#Q="",this.#i=null,this.#H=!1,this.#s.setUnread(0)}#F=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#j(),this.#he()};#le(){let{locale:e}=this.#s.config();this.#m=K({locale:e,messages:{[e]:Oe[e]??Y}})}#e(e){return this.#m._(e)}#N(){return this.#w??=(async()=>{this.#a="loading",this.#o();let{channel:e}=this.#s.config();if(!e)throw new f(0,"not_configured");if(await this.#s.identityToken()||F(e).session)await this.#Ce();else if(await this.#ce(),!this.#r?.chat.allow_anonymous)throw new f(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let t=this.#xe();if(this.#i=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#G(this.#i.id)}this.#o(),this.#R(),this.#j()})().catch((e)=>{if(this.#w=null,this.#ue(e))return;this.#a="error",this.#u=e instanceof f?e.code:"error",this.#o()}),this.#w}async#ce(){let e=await this.#de();if(!this.#n.token)this.#W(e)}#de(){if(!this.#s.config().channel)throw new f(0,"not_configured");return this.#n.channelSettings()}#W(e){let{channel:t}=this.#s.config();this.#r=e;let i=ae(e);if(this.#s.setLauncher(i),t)ce(t,{...F(t),launcher:i})}async#he(){if(this.#a!=="ready")return;try{this.#W(await this.#de()),this.#o()}catch(e){this.#ue(e,!0)}}#ue(e,t=!this.#n.token){let i=e instanceof f&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#s.refused();return i}#Ce(){return this.#k??=(async()=>{await this.#n.start(),await this.#J(),await this.#n.connect()})().finally(()=>{this.#k=null}),this.#k}async#Se(){try{await this.#n.refresh(),this.#o()}catch{}}async#J(e=!1){let t=await this.#n.listConversations({limit:50,cursor:e?this.#v:void 0});if(!e)this.#t.clear();for(let i of t.items)this.#t.set(i.id,i);this.#v=t.next_cursor,this.#A()}async#pe(){await this.#J();let e=this.#i?.kind==="thread"?this.#i.id:null;for(let t of this.#p.keys())if(t!==e)this.#p.delete(t);if(e)this.#p.delete(e),await this.#G(e);this.#o()}async#G(e,t=!1){let i=this.#p.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#p.set(e,i);if(i.loading||t&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#d.scrollHeight-this.#d.scrollTop;try{let s=await this.#n.listMessages(e,{order:"desc",limit:30,cursor:t?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(be),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#o(),this.#d.scrollTop=this.#d.scrollHeight-n}#_e(e){switch(e.type){case"ready":if(this.#b=!1,this.#ne(),this.#H)this.#he();this.#H=!0;return;case"inbox.updated":{let t=this.#r?.ask_for_rating;if(this.#W(e.data),t!==void 0&&t!==e.data.ask_for_rating)this.#J().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pe();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#t.has(e.data.id))this.#t.set(e.data.id,e.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#t.size>1)this.#i=this.#c.some((t)=>t.conversation===null)?this.#i:{kind:"list"};this.#A();break;case"conversation.updated":{let t=this.#t.get(e.data.id),{status:i,can_rate:n,rating:s}=e.data;if(t)this.#t.set(t.id,{...t,status:i,can_rate:n,rating:s});if(!n)this.#_.delete(e.data.id);break}case"message.created":case"message.updated":this.#te(e.data,e.type==="message.created");break;case"read":{let t=this.#t.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||x(e.data.read_at)>x(i)))this.#t.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#C.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#C.set(t,{name:n,timer:setTimeout(()=>this.#C.delete(t)&&this.#o(),8000)})}else this.#C.delete(t);break}}this.#o()}#te(e,t){let i=e.conversation_id,n=this.#p.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===e.id);if(o>=0)n.messages[o]=e;else n.messages=[...n.messages,e].sort(be)}if(e.client_id)this.#c=this.#c.filter((o)=>o.client_id!==e.client_id);let s=this.#t.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#t.set(o.id,o),this.#A(),this.#o()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#t.set(i,{...s,last_message:{id:e.id,author_type:e.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:e.created_at},last_message_at:e.created_at,unread:s.unread||e.author.type!=="contact"}),e.author.type!=="contact"){let a=this.#C.get(i);if(a)clearTimeout(a.timer);this.#C.delete(i),this.#Pe(e)}}this.#A(),this.#j()}#Pe(e){this.#ee.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#A(){let e=0;for(let t of this.#t.values())if(t.unread)e++;this.#s.setUnread(e)}#Ee(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#j(){let e=this.#Ee(),t=e?this.#t.get(e):void 0;if(!e||!t?.unread)return;this.#t.set(e,{...t,unread:!1}),this.#A(),this.#n.markRead(e).catch(()=>{let i=this.#t.get(e);if(i)this.#t.set(e,{...i,unread:!0});this.#A()})}#fe(e){this.#x=[...this.#x,...e].slice(0,Ue),this.#q(),this.#B(),this.#h.focus()}#ge(){if(this.#h.style.blockSize="",this.#h.value==="")return;this.#h.style.blockSize="auto",this.#h.style.blockSize=`${Math.max(38,Math.min(this.#h.scrollHeight,140))}px`}#B(){this.#$.disabled=this.#h.value.trim()===""&&this.#x.length===0}#Te(){let e=this.#i?.kind==="thread"?this.#i.id:null;if(!e||this.#h.value.trim()===""){this.#O();return}if(Date.now()-this.#z>3000)this.#z=Date.now(),this.#n.setTyping(e,!0).catch(()=>{return});if(this.#f)clearTimeout(this.#f);this.#f=setTimeout(()=>this.#O(),4000)}#O(){if(this.#f)clearTimeout(this.#f);if(this.#f=null,this.#z===0)return;this.#z=0;let e=this.#i?.kind==="thread"?this.#i.id:null;if(e)this.#n.setTyping(e,!1).catch(()=>{return})}async#ie(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let e=this.#h.value.trim(),t=this.#x;if(!e&&t.length===0)return;if(this.#i.id===null&&this.#c.some((n)=>n.conversation===null))return;this.#O(),this.#h.value="",this.#x=[],this.#ge(),this.#q(),this.#B();let i={client_id:M(),conversation:this.#i.id,body:e,files:t,state:"sending"};this.#c.push(i),this.#o(),this.#R(),await this.#me(i)}async#me(e){e.state="sending",this.#o();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#n.startConversation(t),n=i.conversation.id;if(!this.#t.has(n))this.#t.set(n,i.conversation);if(!this.#p.has(n))this.#p.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#te(i.message,!1)}else{let i=await this.#n.sendMessage(e.conversation,t);this.#te(i,!0)}this.#c=this.#c.filter((i)=>i!==e)}catch(i){let n=i instanceof f?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#o(),this.#R()}async rate(e,t,i){try{let n=await this.#n.rate(e,t,i);return this.#t.set(n.id,n),this.#_.delete(e),this.#o(),n}catch(n){if(n instanceof f&&n.status===409){let s=await this.#n.getConversation(e).catch(()=>null);if(s)this.#t.set(s.id,s);this.#_.delete(e),this.#o()}throw n}}#ze(e,t){if(this.#_.get(e)?.state==="sending")return;if(this.#_.set(e,{choice:t,state:"choosing"}),this.#o(),this.#g.focus({preventScroll:!0}),this.#L)this.#R()}async#ye(e,t){let i=this.#_.get(e);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(e,i.choice,t?this.#g.value:void 0),this.#g.value=""}catch(n){if(n instanceof f&&n.status===409)return;i.state="failed",this.#o()}}async#Re(){let e=this.#E.value.trim();if(!e||!this.#E.checkValidity()){this.#S=this.#e({id:"E_qvzP"}),this.#se();return}try{this.#y=await this.#n.setEmail(e),this.#M=!0,this.#S=""}catch{this.#S=this.#e({id:"ZxJcgC"})}this.#se()}#ve(e){let t=this.#l.get(e.id);if(t)return Promise.resolve(t);let i=this.#D.get(e.id);if(!i)i=this.#n.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#l.set(e.id,s),s}),i.catch(()=>this.#D.delete(e.id)),this.#D.set(e.id,i);return i}async#be(e){let t=await this.#ve(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#xe(){return[...this.#t.values()].sort($e)}#De(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#R(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#we(){this.#h.placeholder=this.#e({id:"RzWUUK"}),this.#h.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#K.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#K.title=this.#e({id:"N7m8E-"}),this.#$.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#$.title=this.#e({id:"JlFcis"}),this.#E.placeholder=this.#e({id:"njBr8W"}),this.#E.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#B(),this.#q(),this.#o()}#o(){let e=this.#s.panel;if(e.childElementCount===0){let t=r("style");t.textContent=ye,e.append(t,this.#V,this.#X,this.#U,this.#ee),this.#V.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#Me(),this.#ne(),this.#a!=="ready"){this.#Y=void 0;let t=r("div","center");if(this.#a==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Ie()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#w=null,this.#N()}),t.append(i)}this.#U.replaceChildren(t);return}if(this.#i?.kind==="list")this.#Ae();else this.#$e()}#Ie(){switch(this.#u){case"anonymous_not_allowed":return this.#e({id:"zLzEI3"});case"invalid_identity_token":return this.#e({id:"0XGLbP"});case"rate_limited":return this.#e({id:"tzsBOP"});case"network":return this.#e({id:"GQVIIl"});default:return this.#e({id:"Amai22"})}}#Me(){let{layout:e}=this.#s.config(),t=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#t.size>1||n.id===null&&this.#t.size>0))i.push(z(P.back,this.#e({id:"S63MQu"}),()=>{this.#O(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",t?.name||this.#e({id:"t7TeQU"}))),t){let o=r("div","status");if(t.mode==="live"&&t.open_now&&t.presence?.available){let l=r("div","avatars");for(let c of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#e({id:"oXOSPE"})))}else if(!t.open_now||t.mode==="live")o.append(r("span","dot away"),r("span","",this.#e({id:"1EICzz"})));else o.append(r("span","",this.#Le(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(z(P.close,this.#e({id:"yz7wBu"}),()=>this.#s.close()));this.#V.replaceChildren(...i)}#Le(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#s.config(),[i,n]=e<60?[e,"minute"]:e<1440?[Math.round(e/60),"hour"]:[Math.round(e/1440),"day"],s=new Intl.NumberFormat(t,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#e({id:"VggdQJ",values:{duration:s}})}#ne(){this.#X.hidden=!this.#b,this.#X.textContent=this.#e({id:"09Tv5j"})}#Ae(){this.#Y=void 0;let{locale:e}=this.#s.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#xe()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#e({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Oe(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#v){let s=r("button","link",this.#e({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#J(!0).then(()=>this.#o())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#h.focus()}),this.#U.replaceChildren(t,n)}async#Oe(e){if(this.#i={kind:"thread",id:e},this.#o(),!this.#p.get(e)?.complete&&!this.#p.get(e)?.messages.length)await this.#G(e).catch(()=>{return});this.#o(),this.#R(),this.#j()}#Ue(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#I.get(i):!1;if(!i||n===!1)return t;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,t.replaceChildren(s),t;return s.addEventListener("load",()=>{if(this.#I.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#I.set(i,!1)),s.src=i,t}#$e(){let e=this.#i;if(e?.kind!=="thread")return;let t=e.id,i=this.#Y===t,n=this.#L,s=t?this.#p.get(t):void 0,o=s?.messages??[],a=this.#c.filter((d)=>d.conversation===t),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(L(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((d,v)=>{let k=o[v-1],w=o[v+1]??(a.length>0?null:void 0),m=d.author.type==="contact",C=!k||A(k)!==A(d)||x(d.created_at)-x(k.created_at)>ve,H=w===void 0||(w===null?!m:A(w)!==A(d)||x(w.created_at)-x(d.created_at)>ve);if(!m&&C&&d.author.name)l.push(r("div","author",d.author.name));let O=r("div",`row ${m?"mine":"theirs"}${C&&v>0?" group-gap":""}`);if(!m){let T=this.#Ue(d.author);if(!H)T.style.visibility="hidden";O.append(T)}let E=r("div","bubble");if(E.dir="auto",E.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())E.append(L(d.body));if(d.attachments.length>0)E.append(this.#je(d.attachments));if(O.append(E),l.push(O),H){let T=this.#Be(d.created_at);if(m&&v===o.length-1&&a.length===0){let Q=t?this.#t.get(t)?.last_read_by_member_at:void 0,we=Q&&x(Q)>=x(d.created_at);T+=` · ${we?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let U=r("div","meta",T);if(!m)U.style.alignSelf="flex-start";if(!m)U.style.marginInlineStart="36px";l.push(U)}});let h=t?this.#t.get(t):void 0,p=h?this.#Ne(h):null;if(p)l.push(p);a.forEach((d,v)=>{let k=r("div",`row mine${v===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),w=r("div","bubble");if(w.dir="auto",d.body)w.append(L(d.body));if(d.files.length>0){let m=r("div","files");for(let C of d.files)m.append(r("span","file",C.name||"image"));w.append(m)}if(k.append(w),l.push(k),d.state==="failed"){let m=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),C=r("button","link",this.#e({id:"6gRgw8"}));C.type="button",C.addEventListener("click",()=>void this.#me(d)),m.append(C),l.push(m)}else if(d.state==="refused"){let m=d.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${m}`))}else if(v===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let u=t?this.#C.get(t):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let v=u.name;d.append(r("span","",v?this.#e({id:"tHaDPf",values:{name:v}}):this.#e({id:"PxYAul"}))),l.push(d)}let g=this.#d.getRootNode().activeElement===this.#g,{selectionStart:_,selectionEnd:b}=this.#g;if(this.#d.replaceChildren(...l),g&&this.#g.isConnected)this.#g.focus({preventScroll:!0}),this.#g.setSelectionRange(_,b);if(this.#se(),this.#U.firstChild!==this.#d)this.#U.replaceChildren(this.#d,this.#P,this.#oe);if(this.#Y=t,!i||n)this.#R()}#Ne(e){let t=e.status==="closed"?e.rating:void 0,i=e.can_rate&&this.#r?.ask_for_rating?this.#_.get(e.id):void 0;if(!t&&!(e.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#ke,s=[e.id,t,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#re!==e.id)this.#re=e.id,this.#g.value="";let o=this.#e({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(t&&t!==u)continue;let y=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");y.type="button";let g=u==="good"?this.#e({id:"OEEQKT"}):this.#e({id:"-f5Tkb"});y.setAttribute("aria-label",g),y.title=g,y.setAttribute("aria-pressed",String((t??i?.choice)===u)),y.disabled=!!t||i?.state==="sending",y.addEventListener("click",()=>this.#ze(e.id,u)),a.append(y)}if(t)return n.replaceChildren(a,r("p","",this.#e({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#g.placeholder=this.#e({id:"axQ1h6"}),this.#g.setAttribute("aria-label",this.#e({id:"NBdIgR"})),this.#g.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#ye(e.id,!0)});let c=r("button","link",this.#e({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#ye(e.id,!1));let h=r("button","",i.state==="sending"?this.#e({id:"Sad2tK"}):this.#e({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#g,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#e({id:"4TqZiz"})));return n}#je(e){let t=r("div","files");for(let i of e)if(Ne(i)){let n=r("img");n.alt=i.filename;let s=this.#l.get(i.id);if(s)n.src=s;else this.#ve(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight}),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=P.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}return t}#Be(e){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(e))}#se(){let e=this.#y,t=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#c.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#De()&&n&&(!s||this.#M);if(this.#P.hidden=!o,!o)return;if(s&&this.#M){this.#P.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#P.querySelector("form")){let c=this.#P.querySelector(".error");if(c)c.textContent=this.#S;else if(this.#S)this.#P.append(r("p","error",this.#S));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#Re()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#E,l),this.#P.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#S)this.#P.append(r("p","error",this.#S))}#q(){this.#Z.hidden=this.#x.length===0,this.#Z.replaceChildren(...this.#x.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),z(P.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#x=this.#x.filter((n,s)=>s!==t),this.#q(),this.#B()})),i}))}}function je(e){return new xe(e)}export{je as mount};