useyuva 0.0.10 → 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.
package/dist/yuva-docs.js CHANGED
@@ -1,14 +1,14 @@
1
- (()=>{class d extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function P(e,t,i,{method:s="GET",json:n,body:o,headers:r={},token:l,blob:c}={}){if(r={...r},l)r.Authorization=`Bearer ${l}`;let h=o;if(n!==void 0)r["Content-Type"]="application/json",h=JSON.stringify(n);let p;try{p=await e(t+i,{method:s,headers:r,body:h,credentials:"omit"})}catch{throw new d(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new d(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}function z(e,t,i){return P(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function O(e,t,i,s){return P(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:s})}class R{server;socketClass;handlers;#e=null;#i=0;#n=0;#t=null;#r=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#e?.readyState===1}start(){if(this.#r=!1,!this.#e&&!this.#t)this.#o()}stop(){if(this.#r=!0,this.#t)clearTimeout(this.#t);this.#t=null;let e=this.#e;this.#e=null,e?.close(1000)}reset(){this.#i=0}nudge(){if(this.#r||this.#e)return;if(this.#t)clearTimeout(this.#t);this.#t=null,this.#o()}#o(){let e=this.handlers.token();if(!e||this.#r)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#i>0)t.searchParams.set("last_event_id",String(this.#i));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#s();return}this.#e=i,i.onmessage=(s)=>{let n;try{n=JSON.parse(String(s.data))}catch{return}if(n.type==="ready")this.#n=0,this.#i=Math.max(this.#i,n.last_event_id);else if("id"in n&&typeof n.id==="number")this.#i=Math.max(this.#i,n.id);this.handlers.event(n)},i.onclose=(s)=>{if(this.#e!==i)return;if(this.#e=null,this.#r)return;if(s.code===1008){this.#i=0,this.handlers.sessionEnded();return}this.#s()}}#s(){if(this.#r||this.#t)return;let e=this.#n++;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.#o()},t)}}function ce(e,t,i){let s=new URL("/account/connect",e);return s.searchParams.set("channel",t),s.searchParams.set("origin",i),s.href}function de(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 W(e,t,{width:i=460,height:s=640}={}){let n=new URL(e).origin,o=location.origin,r=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??s)-s)/2),c=window.open(ce(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${s},left=${Math.round(r)},top=${Math.round(l)}`);if(!c)return Promise.reject(new d(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",f),clearInterval(m)},f=(g)=>{if(u||g.origin!==n||g.source&&g.source!==c)return;let b=g.data;if(!de(b)||b.channel_key!==t||b.origin!==o)return;y();try{c.close()}catch{}h({token:b.token,expires_at:b.expires_at,reader:b.reader})},m=setInterval(()=>{let g=!1;try{g=c.closed}catch{}if(!g)return;clearInterval(m),setTimeout(()=>{if(u)return;y(),p(new d(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",f)})}function q(e){return`yuva:${e}`}function K(e,t){return`yuva:reader:${e} ${t}`}function j(){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 he(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 ue(){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 M(e){let t=new URLSearchParams;for(let[s,n]of Object.entries(e))if(n!==void 0)t.set(s,String(n));let i=t.toString();return i?`?${i}`:""}function pe(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function fe(e,t,i){let s=[];for(let[n,o]of e)s.push(`--${i}\r
1
+ (()=>{class h extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function P(e,t,i,{method:s="GET",json:n,body:o,headers:r={},token:a,blob:c}={}){if(r={...r},a)r.Authorization=`Bearer ${a}`;let d=o;if(n!==void 0)r["Content-Type"]="application/json",d=JSON.stringify(n);let p;try{p=await e(t+i,{method:s,headers:r,body:d,credentials:"omit"})}catch{throw new h(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new h(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}function z(e,t,i){return P(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function O(e,t,i,s){return P(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:s})}class R{server;socketClass;handlers;#e=null;#i=0;#n=0;#t=null;#r=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#e?.readyState===1}start(){if(this.#r=!1,!this.#e&&!this.#t)this.#o()}stop(){if(this.#r=!0,this.#t)clearTimeout(this.#t);this.#t=null;let e=this.#e;this.#e=null,e?.close(1000)}reset(){this.#i=0}nudge(){if(this.#r||this.#e)return;if(this.#t)clearTimeout(this.#t);this.#t=null,this.#o()}#o(){let e=this.handlers.token();if(!e||this.#r)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#i>0)t.searchParams.set("last_event_id",String(this.#i));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#s();return}this.#e=i,i.onmessage=(s)=>{let n;try{n=JSON.parse(String(s.data))}catch{return}if(n.type==="ready")this.#n=0,this.#i=Math.max(this.#i,n.last_event_id);else if("id"in n&&typeof n.id==="number")this.#i=Math.max(this.#i,n.id);this.handlers.event(n)},i.onclose=(s)=>{if(this.#e!==i)return;if(this.#e=null,this.#r)return;if(s.code===1008){this.#i=0,this.handlers.sessionEnded();return}this.#s()}}#s(){if(this.#r||this.#t)return;let e=this.#n++;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.#o()},t)}}function ce(e,t,i){let s=new URL("/account/connect",e);return s.searchParams.set("channel",t),s.searchParams.set("origin",i),s.href}function de(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 W(e,t,{width:i=460,height:s=640}={}){let n=new URL(e).origin,o=location.origin,r=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),a=Math.max(0,(window.screenY??0)+((window.outerHeight??s)-s)/2),c=window.open(ce(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${s},left=${Math.round(r)},top=${Math.round(a)}`);if(!c)return Promise.reject(new h(0,"popup_blocked"));return new Promise((d,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(m)},g=(f)=>{if(u||f.origin!==n||f.source&&f.source!==c)return;let b=f.data;if(!de(b)||b.channel_key!==t||b.origin!==o)return;y();try{c.close()}catch{}d({token:b.token,expires_at:b.expires_at,reader:b.reader})},m=setInterval(()=>{let f=!1;try{f=c.closed}catch{}if(!f)return;clearInterval(m),setTimeout(()=>{if(u)return;y(),p(new h(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function q(e){return`yuva:${e}`}function j(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 he(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 ue(){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 pe(){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 M(e){let t=new URLSearchParams;for(let[s,n]of Object.entries(e))if(n!==void 0)t.set(s,String(n));let i=t.toString();return i?`?${i}`:""}function ge(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function fe(e,t,i){let s=[];for(let[n,o]of e)s.push(`--${i}\r
2
2
  Content-Disposition: form-data; name="${n}"\r
3
3
  \r
4
4
  ${o}\r
5
5
  `);for(let n of t){let o=n.name||"file";s.push(`--${i}\r
6
- Content-Disposition: form-data; name="files"; filename="${pe(o)}"\r
6
+ Content-Disposition: form-data; name="files"; filename="${ge(o)}"\r
7
7
  Content-Type: ${n.type||"application/octet-stream"}\r
8
8
  \r
9
9
  `,n,`\r
10
10
  `)}return s.push(`--${i}--\r
11
- `),new Blob(s)}class B{server;channel;#e;#i;#n;#t;#r;#o=null;#s=null;#h=null;#g=null;#l=null;#c;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#e=e.fetch??((t,i)=>fetch(t,i)),this.#i=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??ue(),this.#t=e.identityToken??null,this.#r=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#s}get token(){return this.#o}get connected(){return this.#l?.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)}#d(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(q(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#x(e){try{this.#n.setItem(q(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 z(this.#e,this.server,this.channel)}subscribe(e){return O(this.#e,this.server,this.channel,e)}subscriptions(){return this.#a("/client/v1/subscriptions")}subscribeList(e,t){return this.#a(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#a(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#t=e,this.reset()}start(){if(this.#s)return Promise.resolve(this.#s);return this.#h??=this.#C(!1).then((e)=>(this.#d("session",{session:e,renewed:!1}),e)).finally(()=>{this.#h=null}),this.#h}async refresh(){let e=await this.#a("/client/v1/session");return this.#s={...this.#s,...e},this.#d("session",{session:this.#s,renewed:!1}),this.#s}reset(){this.#l?.stop(),this.#l?.reset(),this.#h=null,this.#g=null,this.#o=null,this.#s=null}async signOut(){let e=this.#o;this.reset();let t=this.stored();if(delete t.session,this.#x(t),e)await this.#f("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#i)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#l??=new R(this.server,this.#i,{token:()=>this.#o,event:(e)=>{if(e.type==="ready")this.#d("connection",{state:"open",attempt:0});this.#d("event",e)},sessionEnded:()=>void this.#y().catch(()=>this.#l?.nudge()),reconnecting:(e)=>{if(this.#d("connection",{state:"reconnecting",attempt:e}),e===2)this.#a("/client/v1/session").catch(()=>{return})}}),!this.#l.connected)this.#d("connection",{state:"connecting",attempt:0});this.#l.start()}disconnect(){this.#l?.stop(),this.#d("connection",{state:"closed",attempt:0})}reconnect(){this.#l?.nudge()}listConversations(e={}){return this.#a(`/client/v1/conversations${M({...e})}`)}getConversation(e){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#a("/client/v1/conversations",this.#S(e))}listMessages(e,t={}){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages${M({...t})}`)}sendMessage(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#S(t))}markRead(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let s={rating:t,comment:i?.trim()||void 0};return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:s})}setTyping(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#a("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#a(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??j();return this.#a("/client/v1/feedback",{method:"POST",headers:this.#w(t),json:{...e,client_id:t}})}get reader(){if(this.#c===void 0)try{let e=this.#n.getItem(K(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.#m(null);return this.#c}#m(e){let t=this.#c?.token!==e?.token;this.#c=e;try{this.#n.setItem(K(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#d("reader",e)}readerSignIn(e){return W(this.server,this.channel,e).then((t)=>(this.#m(t),t))}setReader(e){this.#m(e)}async readerSignOut(){let e=this.reader?.token;if(this.#m(null),e)await this.#f("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${M({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 i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#u(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#s)return this.#s.contact.identified?"contact":null;return await this.#t?.()?"contact":null}async#u(e,t,i=!0){let s=this.reader;if(s)try{return await this.#f(e,{...t,token:s.token})}catch(o){if(!(o instanceof d)||o.status!==401||this.#c?.token!==s.token)throw o;if(this.#m(null),i)throw new d(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#a(e,t);if(i)throw new d(403,"sign_in_required");return this.#f(e,t)}#w(e){return this.#r&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#S({body:e,subject:t,files:i=[],client_id:s=j()}){let n=this.#w(s);if(i.length===0)return{method:"POST",headers:n,json:{body:e,subject:t,client_id:s}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",s]);let r=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return n["Content-Type"]=`multipart/form-data; boundary=${r}`,{method:"POST",headers:n,body:fe(o,i,r)}}#f(e,t){return P(this.#e,this.server,e,t)}async#a(e,t={},i=!0){if(!this.#o)await this.start();try{return await this.#f(e,{...t,token:this.#o})}catch(s){if(!i||!(s instanceof d)||s.status!==401)throw s;return await this.#y(),this.#a(e,t,!1)}}#y(){return this.#g??=(async()=>{let e=await this.#C(!0);if(this.#l)this.#l.stop(),this.#l.reset(),this.#l.start();this.#d("session",{session:e,renewed:!0})})().finally(()=>{this.#g=null}),this.#g}async#C(e){let t=this.stored(),i=await this.#t?.()||null,s=i?he(i):null,n=t.session;if(!e&&n&&n.sub===s&&Date.parse(n.expires_at)>Date.now()+60000)try{let c=await this.#f("/client/v1/session",{token:n.token});return this.#b(c,n.token,s)}catch(c){if(!(c instanceof d)||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:r,...l}=o;return this.#b(l,r,s)}#b(e,t,i){this.#o=t,this.#s=e;let s=this.stored();if(s.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)s.visitor_id=e.visitor_id;else if(e.contact.identified)delete s.visitor_id;return this.#x(s),e}}function F(e){return new B(e)}var I=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var H=JSON.parse('{"6I7cJR":["Chat öffnen"],"OkHvGB":["Chat öffnen, ",["count"]," ungelesen"],"pqZJT2":["Chat schließen"]}');var N=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function G(e,t,i){let s=e[t.id]??i[t.id],n=t.values??{};if(typeof s==="string")return s;if(Array.isArray(s))return s.map((o)=>typeof o==="string"?o:Array.isArray(o)?String(n[o[0]]??""):"").join("");return t.message??t.id}var ge=new Set(["ar","fa","he","ur"]),Y="en";function J(e,t){for(let i of t){if(!i)continue;let s=i.toLowerCase();if(e[s])return s;let n=s.split(/[-_]/)[0]??"";if(e[n])return n}return Y}function A(e){return ge.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var me={en:I,tr:N,de:H};function V(...e){return J(me,e)}function Q(e,t,i=I){return G(e,t,i)}var w=JSON.parse(`{"-UxBoG":["Deleted member"],"1UzENP":["No"],"2lF8Zj":["Unanswered"],"5lWFkC":["Sign in"],"78dEKp":["Sort discussions"],"7oGBMv":["Discussions"],"8Ekoev":["You can't do that."],"8ntmc1":["Votes: ",["0"]],"D16wQE":["Could not open the discussion. Try again."],"D9CFV5":["Anonymous"],"E_qvzP":["Enter a valid e-mail address."],"EmiQvf":["Thanks! Anything we could add? (optional)"],"FMWGhb":["Deleted reader"],"G2fuEb":["Locked"],"GQVIIl":["You seem to be offline."],"GqCA_t":["Answered"],"Hw3P48":["Replies: ",["0"]],"JlFcis":["Send"],"KDw4GX":["Try again"],"KEjhwb":["This discussion is locked."],"KM6m8p":["Team"],"LwDe8g":["Sign in to take part in the discussion."],"MDmQKn":["Could not load the discussions."],"Pwqkdw":["Loading…"],"SOvBw9":["Was this page helpful?"],"Sad2tK":["Sending…"],"Su3Vyp":["Check the title and the text and try again."],"U7H5Fm":["Sorry about that. What was missing or unclear?"],"UbRKMZ":["Pending"],"WWy8TN":["Top"],"XJURKP":["E-mail address"],"a_qtPP":["E-mail for a reply (optional)"],"b6Orhy":["Have a question or an idea? Start the first one."],"b_f4xj":["Posts can be edited for 30 minutes after they are written."],"d6N994":["Thanks for your feedback."],"fMPkxb":["Show more"],"fcWrnU":["Sign out"],"isRobC":["New"],"j-3eim":["Discussions about this page"],"l75CjT":["Yes"],"lWv8id":["Awaiting approval"],"nLqMRA":["Team member"],"nW3go1":["Your browser blocked the sign-in window. Allow pop-ups for this site and try again."],"pzatAP":["Loading discussions…"],"rpfOwz":["No discussions about this page yet."],"tA4dAO":["No thanks"],"tAL5wg":["Could not send. Try again."],"tayT8P":["Discussions are turned off for this site."],"twEQ41":["Every discussion on this page has an answer."],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uuIskV":["Sign in to write to us."],"xOTzt5":["just now"],"z1qf6l":["Start a discussion"],"zmA6sS":["Reader"]}`);var Z=JSON.parse('{"-UxBoG":["Gelöschtes Mitglied"],"1UzENP":["Nein"],"2lF8Zj":["Unbeantwortet"],"5lWFkC":["Anmelden"],"78dEKp":["Diskussionen sortieren"],"7oGBMv":["Diskussionen"],"8Ekoev":["Das können Sie nicht tun."],"8ntmc1":["Stimmen: ",["0"]],"D16wQE":["Die Diskussion konnte nicht eröffnet werden. Versuchen Sie es erneut."],"D9CFV5":["Anonym"],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"EmiQvf":["Danke! Können wir noch etwas ergänzen? (optional)"],"FMWGhb":["Gelöschter Leser"],"G2fuEb":["Gesperrt"],"GQVIIl":["Sie scheinen offline zu sein."],"GqCA_t":["Beantwortet"],"Hw3P48":["Antworten: ",["0"]],"JlFcis":["Senden"],"KDw4GX":["Erneut versuchen"],"KEjhwb":["Diese Diskussion ist gesperrt."],"KM6m8p":["Team"],"LwDe8g":["Melden Sie sich an, um an der Diskussion teilzunehmen."],"MDmQKn":["Die Diskussionen konnten nicht geladen werden."],"Pwqkdw":["Wird geladen…"],"SOvBw9":["War diese Seite hilfreich?"],"Sad2tK":["Wird gesendet…"],"Su3Vyp":["Prüfen Sie Titel und Text und versuchen Sie es erneut."],"U7H5Fm":["Das tut uns leid. Was hat gefehlt oder war unklar?"],"UbRKMZ":["Ausstehend"],"WWy8TN":["Beliebteste"],"XJURKP":["E-Mail-Adresse"],"a_qtPP":["E-Mail für eine Antwort (optional)"],"b6Orhy":["Haben Sie eine Frage oder eine Idee? Starten Sie die erste Diskussion."],"b_f4xj":["Beiträge können bis 30 Minuten nach dem Schreiben bearbeitet werden."],"d6N994":["Danke für Ihr Feedback."],"fMPkxb":["Mehr anzeigen"],"fcWrnU":["Abmelden"],"isRobC":["Neu"],"j-3eim":["Diskussionen zu dieser Seite"],"l75CjT":["Ja"],"lWv8id":["Wartet auf Freigabe"],"nLqMRA":["Teammitglied"],"nW3go1":["Ihr Browser hat das Anmeldefenster blockiert. Erlauben Sie Pop-ups für diese Website und versuchen Sie es erneut."],"pzatAP":["Diskussionen werden geladen…"],"rpfOwz":["Zu dieser Seite gibt es noch keine Diskussionen."],"tA4dAO":["Nein, danke"],"tAL5wg":["Senden fehlgeschlagen. Versuchen Sie es erneut."],"tayT8P":["Diskussionen sind für diese Website deaktiviert."],"twEQ41":["Jede Diskussion auf dieser Seite hat eine Antwort."],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"uuIskV":["Melden Sie sich an, um uns zu schreiben."],"xOTzt5":["gerade eben"],"z1qf6l":["Diskussion starten"],"zmA6sS":["Leser"]}');var X=JSON.parse('{"-UxBoG":["Silinmiş üye"],"1UzENP":["Hayır"],"2lF8Zj":["Yanıtsız"],"5lWFkC":["Giriş yap"],"78dEKp":["Tartışmaları sırala"],"7oGBMv":["Tartışmalar"],"8Ekoev":["Bunu yapamazsınız."],"8ntmc1":["Oylar: ",["0"]],"D16wQE":["Tartışma açılamadı. Yeniden deneyin."],"D9CFV5":["Anonim"],"E_qvzP":["Geçerli bir e-posta adresi girin."],"EmiQvf":["Teşekkürler! Ekleyebileceğimiz bir şey var mı? (isteğe bağlı)"],"FMWGhb":["Silinmiş okuyucu"],"G2fuEb":["Kilitli"],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"GqCA_t":["Yanıtlandı"],"Hw3P48":["Yanıtlar: ",["0"]],"JlFcis":["Gönder"],"KDw4GX":["Yeniden dene"],"KEjhwb":["Bu tartışma kilitli."],"KM6m8p":["Ekip"],"LwDe8g":["Tartışmaya katılmak için giriş yapın."],"MDmQKn":["Tartışmalar yüklenemedi."],"Pwqkdw":["Yükleniyor…"],"SOvBw9":["Bu sayfa işinize yaradı mı?"],"Sad2tK":["Gönderiliyor…"],"Su3Vyp":["Başlığı ve metni kontrol edip yeniden deneyin."],"U7H5Fm":["Üzgünüz. Eksik ya da anlaşılmayan ne vardı?"],"UbRKMZ":["Bekliyor"],"WWy8TN":["En çok oy alan"],"XJURKP":["E-posta adresi"],"a_qtPP":["Yanıt için e-posta (isteğe bağlı)"],"b6Orhy":["Bir sorunuz ya da fikriniz mi var? İlk tartışmayı siz başlatın."],"b_f4xj":["Gönderiler yazıldıktan sonra 30 dakika içinde düzenlenebilir."],"d6N994":["Geri bildiriminiz için teşekkürler."],"fMPkxb":["Daha fazla göster"],"fcWrnU":["Çıkış yap"],"isRobC":["Yeni"],"j-3eim":["Bu sayfayla ilgili tartışmalar"],"l75CjT":["Evet"],"lWv8id":["Onay bekliyor"],"nLqMRA":["Ekip üyesi"],"nW3go1":["Tarayıcınız giriş penceresini engelledi. Bu site için açılır pencerelere izin verip yeniden deneyin."],"pzatAP":["Tartışmalar yükleniyor…"],"rpfOwz":["Bu sayfayla ilgili henüz bir tartışma yok."],"tA4dAO":["Hayır, teşekkürler"],"tAL5wg":["Gönderilemedi. Yeniden deneyin."],"tayT8P":["Bu sitede tartışmalar kapalı."],"twEQ41":["Bu sayfadaki her tartışmanın bir yanıtı var."],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uuIskV":["Bize yazmak için oturum açın."],"xOTzt5":["az önce"],"z1qf6l":["Tartışma başlat"],"zmA6sS":["Okur"]}');function ee(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function te(e){let t=Number.parseInt(e.slice(1),16),[i,s,n]=[t>>16&255,t>>8&255,t&255].map((o)=>{let r=o/255;return r<=0.03928?r/12.92:((r+0.055)/1.055)**2.4});return 0.2126*i+0.7152*s+0.0722*n>0.4?"#111827":"#ffffff"}function ie(e){return`yuva:${e}`}function L(e){try{let t=localStorage.getItem(ie(e));return t?JSON.parse(t):{}}catch{return{}}}function se(e,t){try{localStorage.setItem(ie(e),JSON.stringify(t))}catch{}}function a(e,t,i){let s=document.createElement(e);if(t)s.className=t;if(i!==void 0)s.textContent=i;return s}var ne=Symbol.for("yuva.navigation");function ye(){let e=window,t=e[ne];if(t)return t;let i=new EventTarget;t=e[ne]=i;let s=()=>i.dispatchEvent(new Event("change"));for(let n of["pushState","replaceState"]){let o=history[n];history[n]=function(...r){let l=o.apply(this,r);return s(),l}}return window.addEventListener("popstate",s),window.addEventListener("hashchange",s),t}function T(e){try{let t=new URL(e||location.href,location.href);return t.search="",t.hash="",t.href}catch{return e||location.href}}function re(e){let t=ye(),i=!1,s=()=>{if(i)return;i=!0,queueMicrotask(()=>{i=!1,e()})};return t.addEventListener("change",s),()=>t.removeEventListener("change",s)}var ve={en:w,tr:X,de:Z},_=new Map,be=typeof HTMLElement>"u"?class{}:HTMLElement,D=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",xe=`
11
+ `),new Blob(s)}class B{server;channel;#e;#i;#n;#t;#r;#o=null;#s=null;#h=null;#f=null;#l=null;#c;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#e=e.fetch??((t,i)=>fetch(t,i)),this.#i=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??pe(),this.#t=e.identityToken??null,this.#r=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#s}get token(){return this.#o}get connected(){return this.#l?.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)}#d(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(q(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#x(e){try{this.#n.setItem(q(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#g(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#g(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return z(this.#e,this.server,this.channel)}subscribe(e){return O(this.#e,this.server,this.channel,e)}subscriptions(){return this.#a("/client/v1/subscriptions")}subscribeList(e,t){return this.#a(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#a(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#t=e,this.reset()}start(){if(this.#s)return Promise.resolve(this.#s);return this.#h??=this.#C(!1).then((e)=>(this.#d("session",{session:e,renewed:!1}),e)).finally(()=>{this.#h=null}),this.#h}async refresh(){let e=await this.#a("/client/v1/session");return this.#s={...this.#s,...e},this.#d("session",{session:this.#s,renewed:!1}),this.#s}reset(){this.#l?.stop(),this.#l?.reset(),this.#h=null,this.#f=null,this.#o=null,this.#s=null}async signOut(){let e=this.#o;this.reset();let t=this.stored();if(delete t.session,this.#x(t),e)await this.#g("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#i)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#l??=new R(this.server,this.#i,{token:()=>this.#o,event:(e)=>{if(e.type==="ready")this.#d("connection",{state:"open",attempt:0});this.#d("event",e)},sessionEnded:()=>void this.#y().catch(()=>this.#l?.nudge()),reconnecting:(e)=>{if(this.#d("connection",{state:"reconnecting",attempt:e}),e===2)this.#a("/client/v1/session").catch(()=>{return})}}),!this.#l.connected)this.#d("connection",{state:"connecting",attempt:0});this.#l.start()}disconnect(){this.#l?.stop(),this.#d("connection",{state:"closed",attempt:0})}reconnect(){this.#l?.nudge()}listConversations(e={}){return this.#a(`/client/v1/conversations${M({...e})}`)}getConversation(e){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){let t=e.page_url===void 0?{...e,...ue()}:e;return this.#a("/client/v1/conversations",this.#S(t))}listMessages(e,t={}){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages${M({...t})}`)}sendMessage(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#S(t))}markRead(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let s={rating:t,comment:i?.trim()||void 0};return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:s})}setTyping(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#a("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#a(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??K();return this.#a("/client/v1/feedback",{method:"POST",headers:this.#w(t),json:{...e,client_id:t}})}get reader(){if(this.#c===void 0)try{let e=this.#n.getItem(j(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.#m(null);return this.#c}#m(e){let t=this.#c?.token!==e?.token;this.#c=e;try{this.#n.setItem(j(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#d("reader",e)}readerSignIn(e){return W(this.server,this.channel,e).then((t)=>(this.#m(t),t))}setReader(e){this.#m(e)}async readerSignOut(){let e=this.reader?.token;if(this.#m(null),e)await this.#g("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${M({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 i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#u(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#s)return this.#s.contact.identified?"contact":null;return await this.#t?.()?"contact":null}async#u(e,t,i=!0){let s=this.reader;if(s)try{return await this.#g(e,{...t,token:s.token})}catch(o){if(!(o instanceof h)||o.status!==401||this.#c?.token!==s.token)throw o;if(this.#m(null),i)throw new h(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#a(e,t);if(i)throw new h(403,"sign_in_required");return this.#g(e,t)}#w(e){return this.#r&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#S({body:e,subject:t,files:i=[],client_id:s=K(),...n}){let o=this.#w(s),r=n.page_url??void 0,a=r?n.page_title:void 0;if(i.length===0)return{method:"POST",headers:o,json:{body:e,subject:t,client_id:s,page_url:r,page_title:a}};let c=[];if(t)c.push(["subject",t]);if(e)c.push(["body",e]);if(c.push(["client_id",s]),r)c.push(["page_url",r]);if(a)c.push(["page_title",a]);let d=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return o["Content-Type"]=`multipart/form-data; boundary=${d}`,{method:"POST",headers:o,body:fe(c,i,d)}}#g(e,t){return P(this.#e,this.server,e,t)}async#a(e,t={},i=!0){if(!this.#o)await this.start();try{return await this.#g(e,{...t,token:this.#o})}catch(s){if(!i||!(s instanceof h)||s.status!==401)throw s;return await this.#y(),this.#a(e,t,!1)}}#y(){return this.#f??=(async()=>{let e=await this.#C(!0);if(this.#l)this.#l.stop(),this.#l.reset(),this.#l.start();this.#d("session",{session:e,renewed:!0})})().finally(()=>{this.#f=null}),this.#f}async#C(e){let t=this.stored(),i=await this.#t?.()||null,s=i?he(i):null,n=t.session;if(!e&&n&&n.sub===s&&Date.parse(n.expires_at)>Date.now()+60000)try{let c=await this.#g("/client/v1/session",{token:n.token});return this.#b(c,n.token,s)}catch(c){if(!(c instanceof h)||c.status!==401&&c.status!==403)throw c}let o=await this.#g("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:r,...a}=o;return this.#b(a,r,s)}#b(e,t,i){this.#o=t,this.#s=e;let s=this.stored();if(s.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)s.visitor_id=e.visitor_id;else if(e.contact.identified)delete s.visitor_id;return this.#x(s),e}}function F(e){return new B(e)}var A=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var H=JSON.parse('{"6I7cJR":["Chat öffnen"],"OkHvGB":["Chat öffnen, ",["count"]," ungelesen"],"pqZJT2":["Chat schließen"]}');var N=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function G(e,t,i){let s=e[t.id]??i[t.id],n=t.values??{};if(typeof s==="string")return s;if(Array.isArray(s))return s.map((o)=>typeof o==="string"?o:Array.isArray(o)?String(n[o[0]]??""):"").join("");return t.message??t.id}var me=new Set(["ar","fa","he","ur"]),Y="en";function J(e,t){for(let i of t){if(!i)continue;let s=i.toLowerCase();if(e[s])return s;let n=s.split(/[-_]/)[0]??"";if(e[n])return n}return Y}function I(e){return me.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var ye={en:A,tr:N,de:H};function V(...e){return J(ye,e)}function Q(e,t,i=A){return G(e,t,i)}var w=JSON.parse(`{"-UxBoG":["Deleted member"],"1UzENP":["No"],"2lF8Zj":["Unanswered"],"5lWFkC":["Sign in"],"78dEKp":["Sort discussions"],"7oGBMv":["Discussions"],"8Ekoev":["You can't do that."],"8ntmc1":["Votes: ",["0"]],"D16wQE":["Could not open the discussion. Try again."],"D9CFV5":["Anonymous"],"E_qvzP":["Enter a valid e-mail address."],"EmiQvf":["Thanks! Anything we could add? (optional)"],"FMWGhb":["Deleted reader"],"G2fuEb":["Locked"],"GQVIIl":["You seem to be offline."],"GqCA_t":["Answered"],"Hw3P48":["Replies: ",["0"]],"JlFcis":["Send"],"KDw4GX":["Try again"],"KEjhwb":["This discussion is locked."],"KM6m8p":["Team"],"LwDe8g":["Sign in to take part in the discussion."],"MDmQKn":["Could not load the discussions."],"Pwqkdw":["Loading…"],"SOvBw9":["Was this page helpful?"],"Sad2tK":["Sending…"],"Su3Vyp":["Check the title and the text and try again."],"U7H5Fm":["Sorry about that. What was missing or unclear?"],"UbRKMZ":["Pending"],"WWy8TN":["Top"],"XJURKP":["E-mail address"],"a_qtPP":["E-mail for a reply (optional)"],"b6Orhy":["Have a question or an idea? Start the first one."],"b_f4xj":["Posts can be edited for 30 minutes after they are written."],"d6N994":["Thanks for your feedback."],"fMPkxb":["Show more"],"fcWrnU":["Sign out"],"isRobC":["New"],"j-3eim":["Discussions about this page"],"l75CjT":["Yes"],"lWv8id":["Awaiting approval"],"nLqMRA":["Team member"],"nW3go1":["Your browser blocked the sign-in window. Allow pop-ups for this site and try again."],"pzatAP":["Loading discussions…"],"rpfOwz":["No discussions about this page yet."],"tA4dAO":["No thanks"],"tAL5wg":["Could not send. Try again."],"tayT8P":["Discussions are turned off for this site."],"twEQ41":["Every discussion on this page has an answer."],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uuIskV":["Sign in to write to us."],"xOTzt5":["just now"],"z1qf6l":["Start a discussion"],"zmA6sS":["Reader"]}`);var Z=JSON.parse('{"-UxBoG":["Gelöschtes Mitglied"],"1UzENP":["Nein"],"2lF8Zj":["Unbeantwortet"],"5lWFkC":["Anmelden"],"78dEKp":["Diskussionen sortieren"],"7oGBMv":["Diskussionen"],"8Ekoev":["Das können Sie nicht tun."],"8ntmc1":["Stimmen: ",["0"]],"D16wQE":["Die Diskussion konnte nicht eröffnet werden. Versuchen Sie es erneut."],"D9CFV5":["Anonym"],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"EmiQvf":["Danke! Können wir noch etwas ergänzen? (optional)"],"FMWGhb":["Gelöschter Leser"],"G2fuEb":["Gesperrt"],"GQVIIl":["Sie scheinen offline zu sein."],"GqCA_t":["Beantwortet"],"Hw3P48":["Antworten: ",["0"]],"JlFcis":["Senden"],"KDw4GX":["Erneut versuchen"],"KEjhwb":["Diese Diskussion ist gesperrt."],"KM6m8p":["Team"],"LwDe8g":["Melden Sie sich an, um an der Diskussion teilzunehmen."],"MDmQKn":["Die Diskussionen konnten nicht geladen werden."],"Pwqkdw":["Wird geladen…"],"SOvBw9":["War diese Seite hilfreich?"],"Sad2tK":["Wird gesendet…"],"Su3Vyp":["Prüfen Sie Titel und Text und versuchen Sie es erneut."],"U7H5Fm":["Das tut uns leid. Was hat gefehlt oder war unklar?"],"UbRKMZ":["Ausstehend"],"WWy8TN":["Beliebteste"],"XJURKP":["E-Mail-Adresse"],"a_qtPP":["E-Mail für eine Antwort (optional)"],"b6Orhy":["Haben Sie eine Frage oder eine Idee? Starten Sie die erste Diskussion."],"b_f4xj":["Beiträge können bis 30 Minuten nach dem Schreiben bearbeitet werden."],"d6N994":["Danke für Ihr Feedback."],"fMPkxb":["Mehr anzeigen"],"fcWrnU":["Abmelden"],"isRobC":["Neu"],"j-3eim":["Diskussionen zu dieser Seite"],"l75CjT":["Ja"],"lWv8id":["Wartet auf Freigabe"],"nLqMRA":["Teammitglied"],"nW3go1":["Ihr Browser hat das Anmeldefenster blockiert. Erlauben Sie Pop-ups für diese Website und versuchen Sie es erneut."],"pzatAP":["Diskussionen werden geladen…"],"rpfOwz":["Zu dieser Seite gibt es noch keine Diskussionen."],"tA4dAO":["Nein, danke"],"tAL5wg":["Senden fehlgeschlagen. Versuchen Sie es erneut."],"tayT8P":["Diskussionen sind für diese Website deaktiviert."],"twEQ41":["Jede Diskussion auf dieser Seite hat eine Antwort."],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"uuIskV":["Melden Sie sich an, um uns zu schreiben."],"xOTzt5":["gerade eben"],"z1qf6l":["Diskussion starten"],"zmA6sS":["Leser"]}');var X=JSON.parse('{"-UxBoG":["Silinmiş üye"],"1UzENP":["Hayır"],"2lF8Zj":["Yanıtsız"],"5lWFkC":["Giriş yap"],"78dEKp":["Tartışmaları sırala"],"7oGBMv":["Tartışmalar"],"8Ekoev":["Bunu yapamazsınız."],"8ntmc1":["Oylar: ",["0"]],"D16wQE":["Tartışma açılamadı. Yeniden deneyin."],"D9CFV5":["Anonim"],"E_qvzP":["Geçerli bir e-posta adresi girin."],"EmiQvf":["Teşekkürler! Ekleyebileceğimiz bir şey var mı? (isteğe bağlı)"],"FMWGhb":["Silinmiş okuyucu"],"G2fuEb":["Kilitli"],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"GqCA_t":["Yanıtlandı"],"Hw3P48":["Yanıtlar: ",["0"]],"JlFcis":["Gönder"],"KDw4GX":["Yeniden dene"],"KEjhwb":["Bu tartışma kilitli."],"KM6m8p":["Ekip"],"LwDe8g":["Tartışmaya katılmak için giriş yapın."],"MDmQKn":["Tartışmalar yüklenemedi."],"Pwqkdw":["Yükleniyor…"],"SOvBw9":["Bu sayfa işinize yaradı mı?"],"Sad2tK":["Gönderiliyor…"],"Su3Vyp":["Başlığı ve metni kontrol edip yeniden deneyin."],"U7H5Fm":["Üzgünüz. Eksik ya da anlaşılmayan ne vardı?"],"UbRKMZ":["Bekliyor"],"WWy8TN":["En çok oy alan"],"XJURKP":["E-posta adresi"],"a_qtPP":["Yanıt için e-posta (isteğe bağlı)"],"b6Orhy":["Bir sorunuz ya da fikriniz mi var? İlk tartışmayı siz başlatın."],"b_f4xj":["Gönderiler yazıldıktan sonra 30 dakika içinde düzenlenebilir."],"d6N994":["Geri bildiriminiz için teşekkürler."],"fMPkxb":["Daha fazla göster"],"fcWrnU":["Çıkış yap"],"isRobC":["Yeni"],"j-3eim":["Bu sayfayla ilgili tartışmalar"],"l75CjT":["Evet"],"lWv8id":["Onay bekliyor"],"nLqMRA":["Ekip üyesi"],"nW3go1":["Tarayıcınız giriş penceresini engelledi. Bu site için açılır pencerelere izin verip yeniden deneyin."],"pzatAP":["Tartışmalar yükleniyor…"],"rpfOwz":["Bu sayfayla ilgili henüz bir tartışma yok."],"tA4dAO":["Hayır, teşekkürler"],"tAL5wg":["Gönderilemedi. Yeniden deneyin."],"tayT8P":["Bu sitede tartışmalar kapalı."],"twEQ41":["Bu sayfadaki her tartışmanın bir yanıtı var."],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uuIskV":["Bize yazmak için oturum açın."],"xOTzt5":["az önce"],"z1qf6l":["Tartışma başlat"],"zmA6sS":["Okur"]}');function ee(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function te(e){let t=Number.parseInt(e.slice(1),16),[i,s,n]=[t>>16&255,t>>8&255,t&255].map((o)=>{let r=o/255;return r<=0.03928?r/12.92:((r+0.055)/1.055)**2.4});return 0.2126*i+0.7152*s+0.0722*n>0.4?"#111827":"#ffffff"}function ie(e){return`yuva:${e}`}function _(e){try{let t=localStorage.getItem(ie(e));return t?JSON.parse(t):{}}catch{return{}}}function se(e,t){try{localStorage.setItem(ie(e),JSON.stringify(t))}catch{}}function l(e,t,i){let s=document.createElement(e);if(t)s.className=t;if(i!==void 0)s.textContent=i;return s}var ne=Symbol.for("yuva.navigation");function ve(){let e=window,t=e[ne];if(t)return t;let i=new EventTarget;t=e[ne]=i;let s=()=>i.dispatchEvent(new Event("change"));for(let n of["pushState","replaceState"]){let o=history[n];history[n]=function(...r){let a=o.apply(this,r);return s(),a}}return window.addEventListener("popstate",s),window.addEventListener("hashchange",s),t}function T(e){try{let t=new URL(e||location.href,location.href);return t.search="",t.hash="",t.href}catch{return e||location.href}}function re(e){let t=ve(),i=!1,s=()=>{if(i)return;i=!0,queueMicrotask(()=>{i=!1,e()})};return t.addEventListener("change",s),()=>t.removeEventListener("change",s)}var be={en:w,tr:X,de:Z},L=new Map,xe=typeof HTMLElement>"u"?class{}:HTMLElement,D=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",ke=`
12
12
  :host {
13
13
  --yuva-accent: #2563eb;
14
14
  --yuva-on-accent: #ffffff;
@@ -56,7 +56,7 @@ textarea:focus-visible, input:focus-visible { outline: 2px solid var(--yuva-acce
56
56
  .send:focus-visible, .link:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: 2px; }
57
57
  .link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; opacity: 0.8; }
58
58
  @media (max-width: 480px) { textarea, input { font-size: 16px; } }
59
- `;class S extends be{static observedAttributes=["channel","server","locale","dir","page","page-title","identity-token"];root;inbox=null;pageUrl="";refused=!1;direction="ltr";#e=w;#i=null;#n=null;#t=null;#r="";#o=!1;#s="";constructor(){super();this.root=this.attachShadow({mode:"open"})}get channel(){return this.getAttribute("channel")}set channel(e){this.#h("channel",e)}get server(){return(this.getAttribute("server")||(D?new URL(D).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#h("server",e)}get locale(){return V(this.getAttribute("locale"),navigator.language)}set locale(e){this.#h("locale",e)}get page(){return this.pageUrl||T(this.getAttribute("page"))}set page(e){this.#h("page",e)}get pageTitle(){return this.getAttribute("page-title")||document.title}set pageTitle(e){this.#h("page-title",e)}#h(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}setIdentityToken(e){if(this.#n=e,this.#i?.setIdentityToken(()=>this.#g()),this.#o&&!this.refused)this.render()}connectedCallback(){this.#o=!0,this.#t??=re(()=>this.#l()),this.pageUrl=T(this.getAttribute("page")),this.#c(),this.#p(),this.render(),this.pageChanged()}disconnectedCallback(){this.#o=!1,this.#t?.(),this.#t=null}attributeChangedCallback(e,t,i){if(!this.#o||t===i)return;if(e==="channel"||e==="server"){this.#i?.reset(),this.#i=null,this.refused=!1,this.inbox=null,this.#r="",this.#p(),this.reset(),this.render(),this.pageChanged();return}if(e==="page")return this.#l();if(e==="identity-token")this.#i?.setIdentityToken(()=>this.#g());if(e==="locale"||e==="dir")this.#c();this.render()}t(e){return Q(this.#e,e,w)}client(){return this.#i??=F({server:this.server,channel:this.channel??"",identityToken:()=>this.#g()}),this.#i}get identified(){return!!this.#n||this.hasAttribute("identity-token")}get canWrite(){return this.identified||this.inbox?.chat.allow_anonymous!==!1}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}refusal(e,t=!0){let i=e instanceof d&&(e.code==="origin_not_allowed"||e.code==="page_origin"||t&&e.status===404);if(i&&!this.refused)this.refused=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${this.pageUrl}`),this.root.replaceChildren();return i}errorText(e){let t=e instanceof d?e.code:"";if(t==="rate_limited")return this.t({id:"tzsBOP"});if(t==="network")return this.t({id:"GQVIIl"});if(t==="anonymous_not_allowed"||t==="invalid_identity_token")return this.t({id:"uuIskV"});return this.t({id:"tAL5wg"})}frame(e,...t){let i=a("style");i.textContent=xe+e;let s=a("div","frame");if(s.dir=this.direction,s.lang=this.locale,this.#s)s.style.setProperty("--yuva-accent",this.#s),s.style.setProperty("--yuva-on-accent",te(this.#s));s.append(...t);let n=null;try{n=this.root.activeElement}catch{}if(this.root.replaceChildren(i,s),n instanceof HTMLElement&&n.isConnected)n.focus({preventScroll:!0})}async#g(){return this.#n?await this.#n()??null:this.getAttribute("identity-token")}#l(){if(!this.#o)return;let e=T(this.getAttribute("page"));if(e===this.pageUrl)return;this.pageUrl=e,this.reset(),this.render(),this.pageChanged()}#c(){let e=this.locale;this.#e=ve[e]??w,this.direction=this.getAttribute("dir")==="rtl"?"rtl":this.getAttribute("dir")==="ltr"?"ltr":A(e)}#p(){let e=this.channel,t=`${this.server} ${e}`;if(!e||this.#r===t)return;this.#r=t;let i=L(e).launcher;if(i?.color)this.#d(i.color);let s=_.get(t);if(!s)s=this.client().channelSettings(),_.set(t,s),s.catch(()=>_.delete(t));s.then((n)=>{if(this.channel!==e)return;this.inbox=n;let o=ee(n);if(o.color)this.#d(o.color);if(se(e,{...L(e),launcher:o}),!this.refused)this.render()}).catch((n)=>{if(this.channel===e)this.refusal(n)})}#d(e){if(!/^#[0-9a-f]{6}$/i.test(e))return;this.#s=e}}var oe="#yuva-discussion-",ke=60000,x=new Map;function we(e){for(let t of x.keys())if(t.startsWith(e))x.delete(t)}var C=(e)=>`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,v={up:C('<path d="M12 19V5M5 12l7-7 7 7"/>'),comment:C('<path d="M21 12a8 8 0 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/>'),check:C('<path d="M20 6L9 17l-5-5"/>'),lock:C('<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/>'),clock:C('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')},Se=`
59
+ `;class S extends xe{static observedAttributes=["channel","server","locale","dir","page","page-title","identity-token"];root;inbox=null;pageUrl="";refused=!1;direction="ltr";#e=w;#i=null;#n=null;#t=null;#r="";#o=!1;#s="";constructor(){super();this.root=this.attachShadow({mode:"open"})}get channel(){return this.getAttribute("channel")}set channel(e){this.#h("channel",e)}get server(){return(this.getAttribute("server")||(D?new URL(D).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#h("server",e)}get locale(){return V(this.getAttribute("locale"),navigator.language)}set locale(e){this.#h("locale",e)}get page(){return this.pageUrl||T(this.getAttribute("page"))}set page(e){this.#h("page",e)}get pageTitle(){return this.getAttribute("page-title")||document.title}set pageTitle(e){this.#h("page-title",e)}#h(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}setIdentityToken(e){if(this.#n=e,this.#i?.setIdentityToken(()=>this.#f()),this.#o&&!this.refused)this.render()}connectedCallback(){this.#o=!0,this.#t??=re(()=>this.#l()),this.pageUrl=T(this.getAttribute("page")),this.#c(),this.#p(),this.render(),this.pageChanged()}disconnectedCallback(){this.#o=!1,this.#t?.(),this.#t=null}attributeChangedCallback(e,t,i){if(!this.#o||t===i)return;if(e==="channel"||e==="server"){this.#i?.reset(),this.#i=null,this.refused=!1,this.inbox=null,this.#r="",this.#p(),this.reset(),this.render(),this.pageChanged();return}if(e==="page")return this.#l();if(e==="identity-token")this.#i?.setIdentityToken(()=>this.#f());if(e==="locale"||e==="dir")this.#c();this.render()}t(e){return Q(this.#e,e,w)}client(){return this.#i??=F({server:this.server,channel:this.channel??"",identityToken:()=>this.#f()}),this.#i}get identified(){return!!this.#n||this.hasAttribute("identity-token")}get canWrite(){return this.identified||this.inbox?.chat.allow_anonymous!==!1}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}refusal(e,t=!0){let i=e instanceof h&&(e.code==="origin_not_allowed"||e.code==="page_origin"||t&&e.status===404);if(i&&!this.refused)this.refused=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${this.pageUrl}`),this.root.replaceChildren();return i}errorText(e){let t=e instanceof h?e.code:"";if(t==="rate_limited")return this.t({id:"tzsBOP"});if(t==="network")return this.t({id:"GQVIIl"});if(t==="anonymous_not_allowed"||t==="invalid_identity_token")return this.t({id:"uuIskV"});return this.t({id:"tAL5wg"})}frame(e,...t){let i=l("style");i.textContent=ke+e;let s=l("div","frame");if(s.dir=this.direction,s.lang=this.locale,this.#s)s.style.setProperty("--yuva-accent",this.#s),s.style.setProperty("--yuva-on-accent",te(this.#s));s.append(...t);let n=null;try{n=this.root.activeElement}catch{}if(this.root.replaceChildren(i,s),n instanceof HTMLElement&&n.isConnected)n.focus({preventScroll:!0})}async#f(){return this.#n?await this.#n()??null:this.getAttribute("identity-token")}#l(){if(!this.#o)return;let e=T(this.getAttribute("page"));if(e===this.pageUrl)return;this.pageUrl=e,this.reset(),this.render(),this.pageChanged()}#c(){let e=this.locale;this.#e=be[e]??w,this.direction=this.getAttribute("dir")==="rtl"?"rtl":this.getAttribute("dir")==="ltr"?"ltr":I(e)}#p(){let e=this.channel,t=`${this.server} ${e}`;if(!e||this.#r===t)return;this.#r=t;let i=_(e).launcher;if(i?.color)this.#d(i.color);let s=L.get(t);if(!s)s=this.client().channelSettings(),L.set(t,s),s.catch(()=>L.delete(t));s.then((n)=>{if(this.channel!==e)return;this.inbox=n;let o=ee(n);if(o.color)this.#d(o.color);if(se(e,{..._(e),launcher:o}),!this.refused)this.render()}).catch((n)=>{if(this.channel===e)this.refusal(n)})}#d(e){if(!/^#[0-9a-f]{6}$/i.test(e))return;this.#s=e}}var oe="#yuva-discussion-",we=60000,x=new Map;function Se(e){for(let t of x.keys())if(t.startsWith(e))x.delete(t)}var C=(e)=>`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,v={up:C('<path d="M12 19V5M5 12l7-7 7 7"/>'),comment:C('<path d="M21 12a8 8 0 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/>'),check:C('<path d="M20 6L9 17l-5-5"/>'),lock:C('<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/>'),clock:C('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')},Ce=`
60
60
  .frame { display: flex; flex-direction: column; gap: 16px; }
61
61
  :host { --yuva-success: #1a7f37; --yuva-warn: #9a6700; }
62
62
  @media (prefers-color-scheme: dark) { :host { --yuva-success: #3fb950; --yuva-warn: #d29922; } }
@@ -120,7 +120,7 @@ button { font: inherit; color: inherit; }
120
120
  .item .avatar { display: none; }
121
121
  .bar .send { inline-size: 100%; }
122
122
  }
123
- `;function Ce(e){let t=0;for(let i of e)t=t*31+i.charCodeAt(0)|0;return Math.abs(t)%360}function Pe(e){let t=document.createElement("template");return t.innerHTML=e,(t.content.textContent??"").replace(/\s+/g," ").trim().slice(0,240)}class k extends S{static loadThread;#e={view:{kind:"list"},items:[],thread:null,threadState:"loading",writer:null,reader:null,busy:new Set,notice:"",error:"",confirm:"",focus:""};#i="new";#n;#t="loading";#r="";#o=null;#s=null;#h=null;#g="";get discussions(){return this.#e.items}get reader(){return this.#e.reader}#l=()=>this.#x();connectedCallback(){super.connectedCallback(),window.addEventListener("hashchange",this.#l),this.#c()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hashchange",this.#l),this.#o?.(),this.#o=null}attributeChangedCallback(e,t,i){if(super.attributeChangedCallback(e,t,i),t===i||!this.isConnected)return;if(e==="channel"||e==="server")this.#o?.(),this.#o=null,this.#c();else if(e==="identity-token")this.#p(!0)}setIdentityToken(e){super.setIdentityToken(e),this.#p(!0)}#c(){if(!this.channel||this.#o)return;let e=this.client();this.#e.reader=e.reader,this.#o=e.on("reader",(t)=>{this.#e.reader=t,this.emit("yuva-reader",t?t.reader:null),this.#p(!0)}),this.#p(!1)}async#p(e){if(!this.channel)return;let t=await this.client().discussionWriter().catch(()=>null),i=t!==this.#e.writer;if(this.#e.writer=t,e&&i){if(this.#r="",this.#a(!1),this.#e.view.kind==="thread")this.#y(this.#e.view.id,!1)}this.render()}reset(){let e=this.#e;e.view={kind:"list"},e.items=[],this.#n=void 0,this.#t="loading",this.#r="",e.thread=null,e.notice="",e.error="",e.confirm="",this.#s?.reset()}pageChanged(){this.#a(!1),this.#x()}#d(){let e=location.hash;return e.startsWith(oe)?decodeURIComponent(e.slice(oe.length)):""}#x(){let e=this.#d();if(!e||!this.channel||this.refused)return;if(this.#e.view.kind==="thread"&&this.#e.view.id===e)return;this.#s?.close(),this.#e.confirm="",this.#y(e,!0),this.scrollIntoView({block:"start"})}#m(e){let t=()=>void this.#u();e.addEventListener("pointerenter",t,{once:!0}),e.addEventListener("focus",t,{once:!0})}#u(){return this.#h??=k.loadThread().then((e)=>{if(this.#g=e.styles,this.#s=e.createThread(this.#w),this.#e.view.kind!=="list")this.render();return this.#s},()=>{if(this.#h=null,this.#e.view.kind!=="list")this.#e.view={kind:"list"},this.#e.error=this.t({id:"D16wQE"}),this.render();return null}),this.#h}#w=this.#S();#S(){return{s:this.#e,icons:v,root:this.root,locale:()=>this.locale,direction:()=>this.direction,page:()=>this.pageUrl,pageTitle:()=>this.pageTitle,mode:()=>this.#P,client:()=>this.client(),render:()=>this.render(),emit:(e,t)=>this.emit(e,t),act:(e,t)=>this.#I(e,t),signIn:()=>this.signIn(),open:(e,t)=>this.#y(e,t),toList:()=>this.#C(),forget:()=>we(this.#f),button:(e,t,i,s,n)=>this.#v(e,t,i,s,n),avatar:(e,t)=>this.#T(e,t),badge:(e,t)=>this.#k(e,t),time:(e)=>this.#E(e),authorName:(e)=>this.#D(e),noticeBox:(e,t)=>this.#M(e,t)}}reload(){return this.#a(!0)}open(e){return this.#y(e,!0)}signIn(){return this.#e.error="",this.client().readerSignIn().then(()=>{return}).catch((e)=>{let t=e instanceof d?e.code:"";if(t==="sign_in_cancelled")return;this.#e.error=t==="popup_blocked"?this.t({id:"nW3go1"}):this.#b(e),this.render()})}signOut(){return this.client().readerSignOut()}get#f(){return`${this.server} ${this.channel} ${this.pageUrl} `}async#a(e,t=!1){let i=this.pageUrl;if(!this.channel||!i||this.refused)return;let s=this.client().reader,n=s?s.token.slice(-12):this.#e.writer??"-",o=`${this.#f}${this.#i} ${n}`;if(!e&&!t&&this.#r===o)return;this.#r=o;let r;if(t)r=this.client().listDiscussions(i,{sort:this.#i,cursor:this.#n});else{let l=x.get(o);if(e||!l||Date.now()-l.at>ke){l={at:Date.now(),request:this.client().listDiscussions(i,{sort:this.#i})},x.set(o,l);let c=l;l.request.catch(()=>x.get(o)===c&&x.delete(o))}if(r=l.request,!this.#e.items.length)this.#t="loading"}if(t)this.#e.busy.add("more");this.render();try{let l=await r;if(this.#r!==o)return;this.#e.items=t?[...this.#e.items,...l.items.filter((c)=>!this.#e.items.some((h)=>h.id===c.id))]:l.items,this.#n=l.next_cursor,this.#t="ready"}catch(l){if(this.#r!==o||this.refusal(l))return;if(!t)this.#r="";if(this.#t=l instanceof d&&l.code==="discussions_off"?"off":t?"ready":"error",t)this.#e.error=this.#b(l)}finally{this.#e.busy.delete("more")}this.render()}async#y(e,t){let i=this.#e,s=this.pageUrl,n=i.thread?.discussion.id===e?i.thread:null;this.#u(),i.view={kind:"thread",id:e};let o=i.items.find((r)=>r.id===e);if(i.thread=n??(o?{discussion:o,posts:[]}:null),i.threadState=n?"ready":"loading",t)i.notice=n?i.notice:"",i.error="",i.focus="thread-title";this.render();try{let r=await this.client().getDiscussion(e);if(this.pageUrl!==s||i.view.kind!=="thread"||i.view.id!==e)return;let l=!!i.thread;if(i.thread=r,i.threadState="ready",t&&!l)i.focus="thread-title";i.items=i.items.map((c)=>c.id===e?r.discussion:c)}catch(r){if(this.pageUrl!==s||i.view.kind!=="thread"||i.view.id!==e)return;if(this.refusal(r,!1))return;i.threadState=r instanceof d&&r.status===404?"missing":"error"}this.render()}#C(){let e=this.#e;if(this.#d()){let t=new URL(location.href);t.hash="",history.replaceState(history.state,"",t.href)}e.view={kind:"list"},this.#s?.close(),e.confirm="",e.error="",e.focus=e.thread?`open-${e.thread.discussion.id}`:"start",this.render(),this.#a(!1)}#b(e){let t=e instanceof d?e.code:"";if(t==="sign_in_required")return this.t({id:"LwDe8g"});if(t==="discussion_locked")return this.t({id:"KEjhwb"});if(t==="edit_window_closed")return this.t({id:"b_f4xj"});if(t==="discussions_off")return this.t({id:"tayT8P"});if(t==="forbidden")return this.t({id:"8Ekoev"});if(t==="validation_failed")return this.t({id:"Su3Vyp"});return this.errorText(e)}async#I(e,t){let i=this.#e;if(i.busy.has(e))return;i.busy.add(e),i.error="",this.render();try{return await t()}catch(s){if(!this.refusal(s,!1))i.error=this.#b(s);if(s instanceof d&&s.code==="sign_in_required")this.#p(!1);return}finally{i.busy.delete(e),this.render()}}get#P(){return this.inbox?.chat.discussions??"moderated"}#v(e,t,i,s,n=""){let o=a("button",e);if(o.type="button",n)o.innerHTML=n;return o.append(t),o.dataset.key=i,o.addEventListener("click",s),o}#D(e){if(e.deleted)return e.kind==="member"?this.t({id:"-UxBoG"}):this.t({id:"FMWGhb"});if(e.kind==="anonymous")return this.t({id:"D9CFV5"});return e.name||(e.kind==="member"?this.t({id:"nLqMRA"}):this.t({id:"zmA6sS"}))}#T(e,t=!1){let i=a("span",`avatar${t?" small":""}`,e.deleted?"":e.initials||"?");if(i.setAttribute("aria-hidden","true"),e.deleted||e.kind==="anonymous")i.classList.add("gone");else if(e.kind==="member")i.classList.add("team");else i.style.setProperty("--avatar",`hsl(${Ce(e.name||e.initials)} 45% 42%)`);return i}#k(e,t=!1){let i=e==="answered"?this.t({id:"GqCA_t"}):e==="pending"?t?this.t({id:"UbRKMZ"}):this.t({id:"lWv8id"}):e==="team"?this.t({id:"KM6m8p"}):this.t({id:"G2fuEb"}),s=a("span",`badge ${e}`);if(e!=="team")s.innerHTML=e==="answered"?v.check:e==="pending"?v.clock:v.lock;return s.append(i),s}#E(e){let t=a("time");t.dateTime=e;let i=new Date(e);t.title=i.toLocaleString(this.locale);let s=(i.getTime()-Date.now())/1000,n=[["second",60],["minute",60],["hour",24],["day",30],["month",12],["year",1/0]],o=s;for(let[r,l]of n){if(Math.abs(o)<l){t.textContent=r==="second"?this.t({id:"xOTzt5"}):new Intl.RelativeTimeFormat(this.locale,{numeric:"auto"}).format(Math.round(o),r);break}o/=l}return t}#A(){let e=a("div","head");e.append(a("h2","",this.t({id:"7oGBMv"})));let t=a("div","who"),i=this.#e.reader;if(i){let s=i.reader.name||this.t({id:"zmA6sS"});t.append(this.#T({kind:"reader",name:s,initials:i.reader.initials,deleted:!1},!0)),t.append(a("span","",s)),t.append(this.#v("plain",this.t({id:"fcWrnU"}),"sign-out",()=>void this.signOut()))}else if(!this.#e.writer&&this.#P!=="off")t.append(this.#v("ghost",this.t({id:"5lWFkC"}),"sign-in",()=>void this.signIn()));return e.append(t),e}#L(){let e=[],t=a("div","bar"),i=a("div","tabs");i.setAttribute("role","tablist"),i.setAttribute("aria-label",this.t({id:"78dEKp"}));let s=[["new",this.t({id:"isRobC"})],["top",this.t({id:"WWy8TN"})],["unanswered",this.t({id:"2lF8Zj"})]];s.forEach(([r,l],c)=>{let h=this.#v("tab",l,`sort-${r}`,()=>this.#R(r));h.setAttribute("role","tab"),h.setAttribute("aria-selected",String(this.#i===r)),h.setAttribute("aria-controls","yuva-discussion-list"),h.tabIndex=this.#i===r?0:-1,h.addEventListener("keydown",(p)=>{let u=p.key==="ArrowRight"?1:p.key==="ArrowLeft"?-1:0;if(!u)return;p.preventDefault();let y=this.direction==="rtl"?-u:u,f=s[(c+y+s.length)%s.length];if(f)this.#R(f[0])}),i.append(h)});let n=this.#v("send",this.t({id:"z1qf6l"}),"start",()=>{this.#u(),this.#e.view={kind:"new"},this.#e.error="",this.#e.notice="",this.#e.focus="new-title",this.render()});if(this.#m(n),t.append(i,n),e.push(t),this.#t==="loading"&&!this.#e.items.length){let r=a("div","skeleton");return r.setAttribute("aria-busy","true"),r.setAttribute("aria-label",this.t({id:"pzatAP"})),e.push(r),e}if(this.#t==="error"&&!this.#e.items.length){let r=a("div","empty");r.append(a("p","",this.t({id:"MDmQKn"})));let l=this.#v("ghost",this.t({id:"KDw4GX"}),"retry",()=>void this.#a(!0));return l.style.marginBlockStart="8px",r.append(l),e.push(r),e}if(!this.#e.items.length){let r=a("div","empty");if(r.append(a("p","",this.#i==="unanswered"?this.t({id:"twEQ41"}):this.t({id:"rpfOwz"}))),this.#i!=="unanswered")r.append(a("p","muted",this.t({id:"b6Orhy"})));return e.push(r),e}let o=a("ul","list");o.id="yuva-discussion-list",o.setAttribute("aria-label",this.t({id:"j-3eim"})),o.setAttribute("aria-busy",String(this.#t==="loading"));for(let r of this.#e.items){let l=a("li","item");l.append(this.#T(r.author));let c=a("div","main"),h=this.#v("title",r.title,`open-${r.id}`,()=>void this.#y(r.id,!0));h.dir="auto",this.#m(h),c.append(h);let p=r.deleted?"":Pe(r.body_html);if(p){let g=a("p","excerpt",p);g.dir="auto",c.append(g)}let u=a("div","meta");if(u.append(a("span","",this.#D(r.author)),this.#E(r.created_at)),r.author.kind==="member"&&!r.author.deleted)u.append(this.#k("team"));if(r.answer_post_id)u.append(this.#k("answered"));if(r.state==="pending")u.append(this.#k("pending"));if(r.locked)u.append(this.#k("locked"));c.append(u);let y=a("div","counts"),f=a("span","count");f.innerHTML=v.up,f.append(String(r.votes)),f.setAttribute("aria-label",this.t({id:"8ntmc1",values:{0:r.votes}})),f.title=f.getAttribute("aria-label")??"";let m=a("span","count");m.innerHTML=v.comment,m.append(String(r.reply_count)),m.setAttribute("aria-label",this.t({id:"Hw3P48",values:{0:r.reply_count}})),m.title=m.getAttribute("aria-label")??"",y.append(f,m),l.append(c,y),o.append(l)}if(e.push(o),this.#n){let r=this.#v("ghost more",this.#e.busy.has("more")?this.t({id:"Pwqkdw"}):this.t({id:"fMPkxb"}),"more",()=>void this.#a(!1,!0));r.disabled=this.#e.busy.has("more"),e.push(r)}return e}#R(e){if(this.#i===e)return;this.#i=e,this.#e.items=[],this.#n=void 0,this.#t="loading",this.#e.focus=`sort-${e}`,this.#a(!1)}#M(e,t=v.clock){let i=a("div","notice");return i.setAttribute("role","status"),i.innerHTML=t,i.append(a("p","",e)),i}render(){if(this.refused||!this.channel){this.root.replaceChildren();return}let e="";try{e=this.root.activeElement?.dataset?.key??""}catch{}let t=[this.#A()];if(this.#P==="off"||this.#t==="off")t.push(a("p","muted",this.t({id:"tayT8P"})));else if(this.#e.view.kind!=="list"){let r=this.#s;if(r)t.push(...this.#e.view.kind==="thread"?r.threadView():r.newView());else{let l=a("div","skeleton");l.setAttribute("aria-busy","true"),l.setAttribute("aria-label",this.t({id:"Pwqkdw"})),t.push(l)}}else{if(this.#e.notice)t.push(this.#M(this.#e.notice));t.push(...this.#L())}if(this.#e.error){let r=a("p","error",this.#e.error);r.setAttribute("role","alert"),t.push(r)}if(this.frame(Se+this.#g,...t),this.#e.view.kind!=="list"&&!this.#s)return;this.#s?.syncSend();let i=this.#e.focus;this.#e.focus="";let s=i||e;if(!s)return;let n=null;try{n=this.root.activeElement}catch{}if(n instanceof HTMLElement&&n.dataset.key===s)return;[...this.root.querySelectorAll("[data-key]")].find((r)=>r.dataset.key===s)?.focus({preventScroll:!i})}}var Te=500,De=(e)=>`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"${e?' style="transform:scaleY(-1)"':""}><path d="M7 10v11H3V10zM7 10l4-8a3 3 0 013 3v4h6a2 2 0 012 2.3l-1.4 8A2 2 0 0118.6 21H7"/></svg>`,Ee=`
123
+ `;function Pe(e){let t=0;for(let i of e)t=t*31+i.charCodeAt(0)|0;return Math.abs(t)%360}function Te(e){let t=document.createElement("template");return t.innerHTML=e,(t.content.textContent??"").replace(/\s+/g," ").trim().slice(0,240)}class k extends S{static loadThread;#e={view:{kind:"list"},items:[],thread:null,threadState:"loading",writer:null,reader:null,busy:new Set,notice:"",error:"",confirm:"",focus:""};#i="new";#n;#t="loading";#r="";#o=null;#s=null;#h=null;#f="";get discussions(){return this.#e.items}get reader(){return this.#e.reader}#l=()=>this.#x();connectedCallback(){super.connectedCallback(),window.addEventListener("hashchange",this.#l),this.#c()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hashchange",this.#l),this.#o?.(),this.#o=null}attributeChangedCallback(e,t,i){if(super.attributeChangedCallback(e,t,i),t===i||!this.isConnected)return;if(e==="channel"||e==="server")this.#o?.(),this.#o=null,this.#c();else if(e==="identity-token")this.#p(!0)}setIdentityToken(e){super.setIdentityToken(e),this.#p(!0)}#c(){if(!this.channel||this.#o)return;let e=this.client();this.#e.reader=e.reader,this.#o=e.on("reader",(t)=>{this.#e.reader=t,this.emit("yuva-reader",t?t.reader:null),this.#p(!0)}),this.#p(!1)}async#p(e){if(!this.channel)return;let t=await this.client().discussionWriter().catch(()=>null),i=t!==this.#e.writer;if(this.#e.writer=t,e&&i){if(this.#r="",this.#a(!1),this.#e.view.kind==="thread")this.#y(this.#e.view.id,!1)}this.render()}reset(){let e=this.#e;e.view={kind:"list"},e.items=[],this.#n=void 0,this.#t="loading",this.#r="",e.thread=null,e.notice="",e.error="",e.confirm="",this.#s?.reset()}pageChanged(){this.#a(!1),this.#x()}#d(){let e=location.hash;return e.startsWith(oe)?decodeURIComponent(e.slice(oe.length)):""}#x(){let e=this.#d();if(!e||!this.channel||this.refused)return;if(this.#e.view.kind==="thread"&&this.#e.view.id===e)return;this.#s?.close(),this.#e.confirm="",this.#y(e,!0),this.scrollIntoView({block:"start"})}#m(e){let t=()=>void this.#u();e.addEventListener("pointerenter",t,{once:!0}),e.addEventListener("focus",t,{once:!0})}#u(){return this.#h??=k.loadThread().then((e)=>{if(this.#f=e.styles,this.#s=e.createThread(this.#w),this.#e.view.kind!=="list")this.render();return this.#s},()=>{if(this.#h=null,this.#e.view.kind!=="list")this.#e.view={kind:"list"},this.#e.error=this.t({id:"D16wQE"}),this.render();return null}),this.#h}#w=this.#S();#S(){return{s:this.#e,icons:v,root:this.root,locale:()=>this.locale,direction:()=>this.direction,page:()=>this.pageUrl,pageTitle:()=>this.pageTitle,mode:()=>this.#P,client:()=>this.client(),render:()=>this.render(),emit:(e,t)=>this.emit(e,t),act:(e,t)=>this.#A(e,t),signIn:()=>this.signIn(),open:(e,t)=>this.#y(e,t),toList:()=>this.#C(),forget:()=>Se(this.#g),button:(e,t,i,s,n)=>this.#v(e,t,i,s,n),avatar:(e,t)=>this.#T(e,t),badge:(e,t)=>this.#k(e,t),time:(e)=>this.#E(e),authorName:(e)=>this.#D(e),noticeBox:(e,t)=>this.#M(e,t)}}reload(){return this.#a(!0)}open(e){return this.#y(e,!0)}signIn(){return this.#e.error="",this.client().readerSignIn().then(()=>{return}).catch((e)=>{let t=e instanceof h?e.code:"";if(t==="sign_in_cancelled")return;this.#e.error=t==="popup_blocked"?this.t({id:"nW3go1"}):this.#b(e),this.render()})}signOut(){return this.client().readerSignOut()}get#g(){return`${this.server} ${this.channel} ${this.pageUrl} `}async#a(e,t=!1){let i=this.pageUrl;if(!this.channel||!i||this.refused)return;let s=this.client().reader,n=s?s.token.slice(-12):this.#e.writer??"-",o=`${this.#g}${this.#i} ${n}`;if(!e&&!t&&this.#r===o)return;this.#r=o;let r;if(t)r=this.client().listDiscussions(i,{sort:this.#i,cursor:this.#n});else{let a=x.get(o);if(e||!a||Date.now()-a.at>we){a={at:Date.now(),request:this.client().listDiscussions(i,{sort:this.#i})},x.set(o,a);let c=a;a.request.catch(()=>x.get(o)===c&&x.delete(o))}if(r=a.request,!this.#e.items.length)this.#t="loading"}if(t)this.#e.busy.add("more");this.render();try{let a=await r;if(this.#r!==o)return;this.#e.items=t?[...this.#e.items,...a.items.filter((c)=>!this.#e.items.some((d)=>d.id===c.id))]:a.items,this.#n=a.next_cursor,this.#t="ready"}catch(a){if(this.#r!==o||this.refusal(a))return;if(!t)this.#r="";if(this.#t=a instanceof h&&a.code==="discussions_off"?"off":t?"ready":"error",t)this.#e.error=this.#b(a)}finally{this.#e.busy.delete("more")}this.render()}async#y(e,t){let i=this.#e,s=this.pageUrl,n=i.thread?.discussion.id===e?i.thread:null;this.#u(),i.view={kind:"thread",id:e};let o=i.items.find((r)=>r.id===e);if(i.thread=n??(o?{discussion:o,posts:[]}:null),i.threadState=n?"ready":"loading",t)i.notice=n?i.notice:"",i.error="",i.focus="thread-title";this.render();try{let r=await this.client().getDiscussion(e);if(this.pageUrl!==s||i.view.kind!=="thread"||i.view.id!==e)return;let a=!!i.thread;if(i.thread=r,i.threadState="ready",t&&!a)i.focus="thread-title";i.items=i.items.map((c)=>c.id===e?r.discussion:c)}catch(r){if(this.pageUrl!==s||i.view.kind!=="thread"||i.view.id!==e)return;if(this.refusal(r,!1))return;i.threadState=r instanceof h&&r.status===404?"missing":"error"}this.render()}#C(){let e=this.#e;if(this.#d()){let t=new URL(location.href);t.hash="",history.replaceState(history.state,"",t.href)}e.view={kind:"list"},this.#s?.close(),e.confirm="",e.error="",e.focus=e.thread?`open-${e.thread.discussion.id}`:"start",this.render(),this.#a(!1)}#b(e){let t=e instanceof h?e.code:"";if(t==="sign_in_required")return this.t({id:"LwDe8g"});if(t==="discussion_locked")return this.t({id:"KEjhwb"});if(t==="edit_window_closed")return this.t({id:"b_f4xj"});if(t==="discussions_off")return this.t({id:"tayT8P"});if(t==="forbidden")return this.t({id:"8Ekoev"});if(t==="validation_failed")return this.t({id:"Su3Vyp"});return this.errorText(e)}async#A(e,t){let i=this.#e;if(i.busy.has(e))return;i.busy.add(e),i.error="",this.render();try{return await t()}catch(s){if(!this.refusal(s,!1))i.error=this.#b(s);if(s instanceof h&&s.code==="sign_in_required")this.#p(!1);return}finally{i.busy.delete(e),this.render()}}get#P(){return this.inbox?.chat.discussions??"moderated"}#v(e,t,i,s,n=""){let o=l("button",e);if(o.type="button",n)o.innerHTML=n;return o.append(t),o.dataset.key=i,o.addEventListener("click",s),o}#D(e){if(e.deleted)return e.kind==="member"?this.t({id:"-UxBoG"}):this.t({id:"FMWGhb"});if(e.kind==="anonymous")return this.t({id:"D9CFV5"});return e.name||(e.kind==="member"?this.t({id:"nLqMRA"}):this.t({id:"zmA6sS"}))}#T(e,t=!1){let i=l("span",`avatar${t?" small":""}`,e.deleted?"":e.initials||"?");if(i.setAttribute("aria-hidden","true"),e.deleted||e.kind==="anonymous")i.classList.add("gone");else if(e.kind==="member")i.classList.add("team");else i.style.setProperty("--avatar",`hsl(${Pe(e.name||e.initials)} 45% 42%)`);return i}#k(e,t=!1){let i=e==="answered"?this.t({id:"GqCA_t"}):e==="pending"?t?this.t({id:"UbRKMZ"}):this.t({id:"lWv8id"}):e==="team"?this.t({id:"KM6m8p"}):this.t({id:"G2fuEb"}),s=l("span",`badge ${e}`);if(e!=="team")s.innerHTML=e==="answered"?v.check:e==="pending"?v.clock:v.lock;return s.append(i),s}#E(e){let t=l("time");t.dateTime=e;let i=new Date(e);t.title=i.toLocaleString(this.locale);let s=(i.getTime()-Date.now())/1000,n=[["second",60],["minute",60],["hour",24],["day",30],["month",12],["year",1/0]],o=s;for(let[r,a]of n){if(Math.abs(o)<a){t.textContent=r==="second"?this.t({id:"xOTzt5"}):new Intl.RelativeTimeFormat(this.locale,{numeric:"auto"}).format(Math.round(o),r);break}o/=a}return t}#I(){let e=l("div","head");e.append(l("h2","",this.t({id:"7oGBMv"})));let t=l("div","who"),i=this.#e.reader;if(i){let s=i.reader.name||this.t({id:"zmA6sS"});t.append(this.#T({kind:"reader",name:s,initials:i.reader.initials,deleted:!1},!0)),t.append(l("span","",s)),t.append(this.#v("plain",this.t({id:"fcWrnU"}),"sign-out",()=>void this.signOut()))}else if(!this.#e.writer&&this.#P!=="off")t.append(this.#v("ghost",this.t({id:"5lWFkC"}),"sign-in",()=>void this.signIn()));return e.append(t),e}#_(){let e=[],t=l("div","bar"),i=l("div","tabs");i.setAttribute("role","tablist"),i.setAttribute("aria-label",this.t({id:"78dEKp"}));let s=[["new",this.t({id:"isRobC"})],["top",this.t({id:"WWy8TN"})],["unanswered",this.t({id:"2lF8Zj"})]];s.forEach(([r,a],c)=>{let d=this.#v("tab",a,`sort-${r}`,()=>this.#R(r));d.setAttribute("role","tab"),d.setAttribute("aria-selected",String(this.#i===r)),d.setAttribute("aria-controls","yuva-discussion-list"),d.tabIndex=this.#i===r?0:-1,d.addEventListener("keydown",(p)=>{let u=p.key==="ArrowRight"?1:p.key==="ArrowLeft"?-1:0;if(!u)return;p.preventDefault();let y=this.direction==="rtl"?-u:u,g=s[(c+y+s.length)%s.length];if(g)this.#R(g[0])}),i.append(d)});let n=this.#v("send",this.t({id:"z1qf6l"}),"start",()=>{this.#u(),this.#e.view={kind:"new"},this.#e.error="",this.#e.notice="",this.#e.focus="new-title",this.render()});if(this.#m(n),t.append(i,n),e.push(t),this.#t==="loading"&&!this.#e.items.length){let r=l("div","skeleton");return r.setAttribute("aria-busy","true"),r.setAttribute("aria-label",this.t({id:"pzatAP"})),e.push(r),e}if(this.#t==="error"&&!this.#e.items.length){let r=l("div","empty");r.append(l("p","",this.t({id:"MDmQKn"})));let a=this.#v("ghost",this.t({id:"KDw4GX"}),"retry",()=>void this.#a(!0));return a.style.marginBlockStart="8px",r.append(a),e.push(r),e}if(!this.#e.items.length){let r=l("div","empty");if(r.append(l("p","",this.#i==="unanswered"?this.t({id:"twEQ41"}):this.t({id:"rpfOwz"}))),this.#i!=="unanswered")r.append(l("p","muted",this.t({id:"b6Orhy"})));return e.push(r),e}let o=l("ul","list");o.id="yuva-discussion-list",o.setAttribute("aria-label",this.t({id:"j-3eim"})),o.setAttribute("aria-busy",String(this.#t==="loading"));for(let r of this.#e.items){let a=l("li","item");a.append(this.#T(r.author));let c=l("div","main"),d=this.#v("title",r.title,`open-${r.id}`,()=>void this.#y(r.id,!0));d.dir="auto",this.#m(d),c.append(d);let p=r.deleted?"":Te(r.body_html);if(p){let f=l("p","excerpt",p);f.dir="auto",c.append(f)}let u=l("div","meta");if(u.append(l("span","",this.#D(r.author)),this.#E(r.created_at)),r.author.kind==="member"&&!r.author.deleted)u.append(this.#k("team"));if(r.answer_post_id)u.append(this.#k("answered"));if(r.state==="pending")u.append(this.#k("pending"));if(r.locked)u.append(this.#k("locked"));c.append(u);let y=l("div","counts"),g=l("span","count");g.innerHTML=v.up,g.append(String(r.votes)),g.setAttribute("aria-label",this.t({id:"8ntmc1",values:{0:r.votes}})),g.title=g.getAttribute("aria-label")??"";let m=l("span","count");m.innerHTML=v.comment,m.append(String(r.reply_count)),m.setAttribute("aria-label",this.t({id:"Hw3P48",values:{0:r.reply_count}})),m.title=m.getAttribute("aria-label")??"",y.append(g,m),a.append(c,y),o.append(a)}if(e.push(o),this.#n){let r=this.#v("ghost more",this.#e.busy.has("more")?this.t({id:"Pwqkdw"}):this.t({id:"fMPkxb"}),"more",()=>void this.#a(!1,!0));r.disabled=this.#e.busy.has("more"),e.push(r)}return e}#R(e){if(this.#i===e)return;this.#i=e,this.#e.items=[],this.#n=void 0,this.#t="loading",this.#e.focus=`sort-${e}`,this.#a(!1)}#M(e,t=v.clock){let i=l("div","notice");return i.setAttribute("role","status"),i.innerHTML=t,i.append(l("p","",e)),i}render(){if(this.refused||!this.channel){this.root.replaceChildren();return}let e="";try{e=this.root.activeElement?.dataset?.key??""}catch{}let t=[this.#I()];if(this.#P==="off"||this.#t==="off")t.push(l("p","muted",this.t({id:"tayT8P"})));else if(this.#e.view.kind!=="list"){let r=this.#s;if(r)t.push(...this.#e.view.kind==="thread"?r.threadView():r.newView());else{let a=l("div","skeleton");a.setAttribute("aria-busy","true"),a.setAttribute("aria-label",this.t({id:"Pwqkdw"})),t.push(a)}}else{if(this.#e.notice)t.push(this.#M(this.#e.notice));t.push(...this.#_())}if(this.#e.error){let r=l("p","error",this.#e.error);r.setAttribute("role","alert"),t.push(r)}if(this.frame(Ce+this.#f,...t),this.#e.view.kind!=="list"&&!this.#s)return;this.#s?.syncSend();let i=this.#e.focus;this.#e.focus="";let s=i||e;if(!s)return;let n=null;try{n=this.root.activeElement}catch{}if(n instanceof HTMLElement&&n.dataset.key===s)return;[...this.root.querySelectorAll("[data-key]")].find((r)=>r.dataset.key===s)?.focus({preventScroll:!i})}}var De=500,Ee=(e)=>`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"${e?' style="transform:scaleY(-1)"':""}><path d="M7 10v11H3V10zM7 10l4-8a3 3 0 013 3v4h6a2 2 0 012 2.3l-1.4 8A2 2 0 0118.6 21H7"/></svg>`,Re=`
124
124
  .frame { display: flex; flex-direction: column; gap: 12px; }
125
125
  .ask { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
126
126
  .question { font-weight: 600; }
@@ -141,4 +141,4 @@ button { font: inherit; color: inherit; }
141
141
  .choice[aria-pressed="true"] { background: var(--yuva-soft); }
142
142
  .choice:disabled { cursor: default; }
143
143
  .choice:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: 2px; }
144
- `;function ae(e){return`yuva:${e}:page-ratings`}function E(e){try{let t=localStorage.getItem(ae(e));return t?JSON.parse(t):{}}catch{return{}}}function Re(e,t,i){try{let s=E(e);delete s[t],s[t]=i;let n=Object.keys(s);for(let o of n.slice(0,Math.max(0,n.length-Te)))delete s[o];localStorage.setItem(ae(e),JSON.stringify(s))}catch{}}class U extends S{#e="ask";#i;#n="";#t=a("textarea");#r=a("input");constructor(){super();this.#t.rows=3,this.#t.maxLength=5000,this.#t.dir="auto",this.#t.addEventListener("input",()=>this.#s()),this.#r.type="email",this.#r.autocomplete="email"}get rating(){return this.#i??null}reset(){this.#e="ask",this.#n="",this.#t.value="",this.#i=this.channel?E(this.channel)[this.pageUrl]:void 0}pageChanged(){if(this.#e==="ask"&&!this.#n)this.#i=this.channel?E(this.channel)[this.pageUrl]:void 0;this.render()}async rate(e){let t=this.channel;if(!t||this.refused||this.#e==="rating"||this.#e==="sending")return;let i=this.pageUrl,s=E(t)[i];if(this.#n="",s===e){this.#i=e,this.#e=this.canWrite?"form":"thanks",this.render(),this.#t.focus({preventScroll:!0});return}this.#e="rating",this.#i=e,this.render();try{await this.client().ratePage({page:i,title:this.pageTitle||void 0,rating:e,previous:s})}catch(n){if(this.pageUrl!==i||this.refusal(n))return;this.#i=s,this.#e="ask",this.#n=this.errorText(n),this.render();return}if(Re(t,i,e),this.emit("yuva-rating",{page:i,rating:e,previous:s??null}),this.pageUrl!==i)return;this.#e=this.canWrite?"form":"thanks",this.render(),this.#t.focus({preventScroll:!0})}async#o(){let e=this.#t.value.trim(),t=this.#r.value.trim(),i=this.#i;if(!e||this.#e!=="form")return;if(t&&!this.#r.checkValidity()){this.#n=this.t({id:"E_qvzP"}),this.render();return}let s=this.pageUrl;this.#e="sending",this.#n="",this.render();try{let{conversation:n}=await this.client().sendFeedback({page_url:s,page_title:this.pageTitle||void 0,rating:i,body:e,locale:this.locale,allow_email:this.identified||!!t,email:!this.identified&&t?t:void 0});if(this.emit("yuva-feedback",{page:s,rating:i??null,conversation_id:n.id}),this.pageUrl!==s)return;this.#t.value="",this.#e="thanks"}catch(n){if(this.pageUrl!==s||this.refusal(n,!1))return;this.#e="form",this.#n=this.errorText(n)}this.render()}#s(){let e=this.root.querySelector(".send");if(e)e.disabled=this.#e!=="form"||this.#t.value.trim()===""}render(){if(this.refused||!this.channel){this.root.replaceChildren();return}let e=this.t({id:"SOvBw9"}),t=a("div","ask");t.setAttribute("role","group"),t.setAttribute("aria-label",e);let i=a("div","choices");for(let n of["up","down"]){let o=a("button","choice");o.type="button",o.innerHTML=De(n==="down"),o.append(a("span","",n==="up"?this.t({id:"l75CjT"}):this.t({id:"1UzENP"}))),o.setAttribute("aria-pressed",String(this.#i===n)),o.disabled=this.#e==="rating"||this.#e==="sending",o.addEventListener("click",()=>void this.rate(n)),i.append(o)}t.append(a("p","question",e),i);let s=[t];if(this.#e==="form"||this.#e==="sending"){let n=a("form");n.noValidate=!0,n.addEventListener("submit",(h)=>{h.preventDefault(),this.#o()});let o=this.#i==="down"?this.t({id:"U7H5Fm"}):this.t({id:"EmiQvf"});if(this.#t.placeholder=o,this.#t.setAttribute("aria-label",o),this.#t.disabled=this.#e==="sending",n.append(this.#t),!this.identified)this.#r.placeholder=this.t({id:"a_qtPP"}),this.#r.setAttribute("aria-label",this.t({id:"XJURKP"})),this.#r.disabled=this.#e==="sending",n.append(this.#r);let r=a("button","link",this.t({id:"tA4dAO"}));r.type="button",r.disabled=this.#e==="sending",r.addEventListener("click",()=>{this.#e="thanks",this.#n="",this.render()});let l=a("button","send",this.#e==="sending"?this.t({id:"Sad2tK"}):this.t({id:"JlFcis"}));l.type="submit";let c=a("div","actions");c.append(r,l),n.append(c),s.push(n)}else if(this.#e==="thanks"){let n=a("p","muted",this.t({id:"d6N994"}));n.setAttribute("role","status"),s.push(n)}if(this.#n){let n=a("p","error",this.#n);n.setAttribute("role","alert"),s.push(n)}this.frame(Ee,...s),this.#s()}}function le(){if(typeof customElements>"u")return;if(!customElements.get("yuva-discussions"))customElements.define("yuva-discussions",k);if(!customElements.get("yuva-page-feedback"))customElements.define("yuva-page-feedback",U)}k.loadThread=()=>import(new URL("widget/yuva-docs-thread-8st0egsq.js",D||location.href).href);le();})();
144
+ `;function ae(e){return`yuva:${e}:page-ratings`}function E(e){try{let t=localStorage.getItem(ae(e));return t?JSON.parse(t):{}}catch{return{}}}function Me(e,t,i){try{let s=E(e);delete s[t],s[t]=i;let n=Object.keys(s);for(let o of n.slice(0,Math.max(0,n.length-De)))delete s[o];localStorage.setItem(ae(e),JSON.stringify(s))}catch{}}class U extends S{#e="ask";#i;#n="";#t=l("textarea");#r=l("input");constructor(){super();this.#t.rows=3,this.#t.maxLength=5000,this.#t.dir="auto",this.#t.addEventListener("input",()=>this.#s()),this.#r.type="email",this.#r.autocomplete="email"}get rating(){return this.#i??null}reset(){this.#e="ask",this.#n="",this.#t.value="",this.#i=this.channel?E(this.channel)[this.pageUrl]:void 0}pageChanged(){if(this.#e==="ask"&&!this.#n)this.#i=this.channel?E(this.channel)[this.pageUrl]:void 0;this.render()}async rate(e){let t=this.channel;if(!t||this.refused||this.#e==="rating"||this.#e==="sending")return;let i=this.pageUrl,s=E(t)[i];if(this.#n="",s===e){this.#i=e,this.#e=this.canWrite?"form":"thanks",this.render(),this.#t.focus({preventScroll:!0});return}this.#e="rating",this.#i=e,this.render();try{await this.client().ratePage({page:i,title:this.pageTitle||void 0,rating:e,previous:s})}catch(n){if(this.pageUrl!==i||this.refusal(n))return;this.#i=s,this.#e="ask",this.#n=this.errorText(n),this.render();return}if(Me(t,i,e),this.emit("yuva-rating",{page:i,rating:e,previous:s??null}),this.pageUrl!==i)return;this.#e=this.canWrite?"form":"thanks",this.render(),this.#t.focus({preventScroll:!0})}async#o(){let e=this.#t.value.trim(),t=this.#r.value.trim(),i=this.#i;if(!e||this.#e!=="form")return;if(t&&!this.#r.checkValidity()){this.#n=this.t({id:"E_qvzP"}),this.render();return}let s=this.pageUrl;this.#e="sending",this.#n="",this.render();try{let{conversation:n}=await this.client().sendFeedback({page_url:s,page_title:this.pageTitle||void 0,rating:i,body:e,locale:this.locale,allow_email:this.identified||!!t,email:!this.identified&&t?t:void 0});if(this.emit("yuva-feedback",{page:s,rating:i??null,conversation_id:n.id}),this.pageUrl!==s)return;this.#t.value="",this.#e="thanks"}catch(n){if(this.pageUrl!==s||this.refusal(n,!1))return;this.#e="form",this.#n=this.errorText(n)}this.render()}#s(){let e=this.root.querySelector(".send");if(e)e.disabled=this.#e!=="form"||this.#t.value.trim()===""}render(){if(this.refused||!this.channel){this.root.replaceChildren();return}let e=this.t({id:"SOvBw9"}),t=l("div","ask");t.setAttribute("role","group"),t.setAttribute("aria-label",e);let i=l("div","choices");for(let n of["up","down"]){let o=l("button","choice");o.type="button",o.innerHTML=Ee(n==="down"),o.append(l("span","",n==="up"?this.t({id:"l75CjT"}):this.t({id:"1UzENP"}))),o.setAttribute("aria-pressed",String(this.#i===n)),o.disabled=this.#e==="rating"||this.#e==="sending",o.addEventListener("click",()=>void this.rate(n)),i.append(o)}t.append(l("p","question",e),i);let s=[t];if(this.#e==="form"||this.#e==="sending"){let n=l("form");n.noValidate=!0,n.addEventListener("submit",(d)=>{d.preventDefault(),this.#o()});let o=this.#i==="down"?this.t({id:"U7H5Fm"}):this.t({id:"EmiQvf"});if(this.#t.placeholder=o,this.#t.setAttribute("aria-label",o),this.#t.disabled=this.#e==="sending",n.append(this.#t),!this.identified)this.#r.placeholder=this.t({id:"a_qtPP"}),this.#r.setAttribute("aria-label",this.t({id:"XJURKP"})),this.#r.disabled=this.#e==="sending",n.append(this.#r);let r=l("button","link",this.t({id:"tA4dAO"}));r.type="button",r.disabled=this.#e==="sending",r.addEventListener("click",()=>{this.#e="thanks",this.#n="",this.render()});let a=l("button","send",this.#e==="sending"?this.t({id:"Sad2tK"}):this.t({id:"JlFcis"}));a.type="submit";let c=l("div","actions");c.append(r,a),n.append(c),s.push(n)}else if(this.#e==="thanks"){let n=l("p","muted",this.t({id:"d6N994"}));n.setAttribute("role","status"),s.push(n)}if(this.#n){let n=l("p","error",this.#n);n.setAttribute("role","alert"),s.push(n)}this.frame(Re,...s),this.#s()}}function le(){if(typeof customElements>"u")return;if(!customElements.get("yuva-discussions"))customElements.define("yuva-discussions",k);if(!customElements.get("yuva-page-feedback"))customElements.define("yuva-page-feedback",U)}k.loadThread=()=>import(new URL("widget/yuva-docs-thread-8st0egsq.js",D||location.href).href);le();})();
@@ -30,4 +30,4 @@ legend{padding:0;margin-block-end:4px;font-weight:600}
30
30
  .error{color:var(--d)}
31
31
  .trap{position:absolute;inset-inline-start:-1e4px;inline-size:1px;overflow:hidden}
32
32
  @media (max-width:480px){input{font-size:16px}}
33
- `;class f extends _{static observedAttributes=["channel","server","locale","dir","lists","layout","name","button-text","consent","privacy-url","identity-token"];static loadClient=null;#l;#L=g;#g=!1;#a=0;#i="loading";#C=!1;#b=null;#c=[];#h=new Set;#v="";#k=0;#w=!1;#r="";#u="";#y="";#d="";#x=null;#p=null;#S=new Set;#t=c("input");#n=c("input");#m=c("input");#o=c("input");#f=c("p");constructor(){super();this.#l=this.attachShadow({mode:"open"}),this.#t.type="email",this.#t.autocomplete="email",this.#t.required=!0,this.#t.maxLength=320,this.#t.id="email",this.#n.autocomplete="name",this.#n.maxLength=200,this.#n.id="name",this.#m.name="website",this.#m.tabIndex=-1,this.#m.autocomplete="off",this.#o.type="checkbox",this.#o.id="consent",this.#o.addEventListener("change",()=>{this.#d="",this.#s()});for(let e of[this.#t,this.#n])e.setAttribute("part","field"),e.dir="auto";this.#f.setAttribute("part","status"),this.#f.setAttribute("role","status"),this.#f.setAttribute("aria-live","polite")}get channel(){return this.getAttribute("channel")}set channel(e){this.#A("channel",e)}get server(){return(this.getAttribute("server")||(x?new URL(x).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#A("server",e)}get locale(){return E(L,[this.getAttribute("locale"),navigator.language])}set locale(e){this.#A("locale",e)}get lists(){return this.#c.map((e)=>e.list)}setIdentityToken(e){if(this.#x=e,this.#g)this.#P()}connectedCallback(){this.#g=!0,this.#P()}disconnectedCallback(){this.#g=!1}attributeChangedCallback(e,t,i){if(!this.#g||t===i)return;if(["channel","server","lists","identity-token"].includes(e))return void this.#P();this.#s()}#A(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}#e(e){return P(this.#L,e,g)}get#q(){return!!this.#x||this.hasAttribute("identity-token")}async#T(){return this.#x?await this.#x()??null:this.getAttribute("identity-token")}#I(e){let t=(this.getAttribute("lists")??"").split(",").map((n)=>n.trim()).filter((n)=>n&&n!=="all");if(t.length===0)return e;let i=t.map((n)=>e.find((s)=>s.id===n)).filter((n)=>!!n);if(i.length<t.length)console.warn(`Yuva: some lists in "${t.join(",")}" are not public lists`);return i}async#P(){let e=++this.#a,t=this.channel;if(this.#C=!1,this.#i="loading",this.#c=[],this.#r="",this.#p=null,this.#s(),!t)return;let i=this.server;try{let n=b(y,i,`/client/v1/channels/${encodeURIComponent(t)}`),s=null;if(this.#q&&f.loadClient&&await this.#T()){let{createYuvaClient:r}=await f.loadClient(),o=r({server:i,channel:t,identityToken:()=>this.#T()});try{let{items:a}=await o.subscriptions(),l=new Set(this.#I(a.map((h)=>h.list)));s=a.filter((h)=>l.has(h.list)),this.#p=o}catch(a){if(!(a instanceof p)||a.code!=="identity_required")throw a}}if(!s){let{lists:r,form_token:o}=await C(y,i,t);s=this.#I(r).map((a)=>({list:a})),this.#v=o,this.#k=Date.now()}if(this.#b=await n,e!==this.#a)return;if(this.#c=s,this.#h=new Set(s.length===1?[s[0].list.id]:[]),this.#i="idle",s.length===0)console.warn(`Yuva: channel ${t} has no public mailing lists to offer`)}catch(n){if(e!==this.#a)return;if(this.#R(n))return;this.#i="idle",this.#r=this.#E(n)}this.#s()}#R(e){let t=e instanceof p&&(e.status===404||e.code==="origin_not_allowed"||e.code==="page_origin");if(t)this.#C=!0,console.warn(`Yuva: channel ${this.channel} is unknown, offers no such list or does not allow ${location.origin}`),this.#s();return t}#E(e){let t=e instanceof p?e.code:"";if(t==="rate_limited")return this.#e({id:"tzsBOP"});if(t==="network")return this.#e({id:"GQVIIl"});if(t==="no_email")return this.#e({id:"eku1-t"});return this.#e({id:"jWgNnM"})}#M(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#D(e){this.#M("yuva-subscribe-error",{code:e instanceof p?e.code:"error"})}consentText(e=this.#_()){let t=this.getAttribute("consent")?.trim();if(t)return t;let i=(e.length?e:this.lists).map((r)=>r.name),n=new Intl.ListFormat(this.locale,{type:"conjunction"}).format(i),s=this.#b?.name??"";return this.#e({id:"dMJfG5",values:{list:n,inbox:s}})}#_(){return this.lists.filter((e)=>this.#h.has(e.id))}async#N(){if(this.#i!=="idle"||!this.channel)return;let e=this.#_(),t=this.#t.value.trim(),i=this.#n.value.trim(),n=this.getAttribute("name");if(this.#r=e.length===0?this.#e({id:"-g5O6h"}):"",this.#u=this.#t.checkValidity()&&t?"":this.#e({id:"E_qvzP"}),this.#y=n==="required"&&!i?this.#e({id:"E_LjOR"}):"",this.#d=this.#o.checked?"":this.#e({id:"lDEbTy"}),this.#r||this.#u||this.#y||this.#d){this.#s();let l=[this.#u&&this.#t,this.#y&&this.#n,this.#d&&this.#o];for(let h of l)if(h)return h.focus();return}let s=this.channel,r=this.#a,o=this.consentText(e);this.#i="submitting",this.#s();let a=async(l)=>{let h=this.#k+D-Date.now();if(h>0)await new Promise((u)=>setTimeout(u,h));try{let{confirmation:u}=await k(y,this.server,s,{email:t,name:n==="optional"||n==="required"?i||void 0:void 0,list_ids:e.map((d)=>d.id),locale:this.locale,page_url:location.href.split("#")[0].slice(0,2000),consent_text:o,form_token:this.#v,website:this.#m.value||void 0});return this.#w=u,!0}catch(u){if(l&&u instanceof p&&u.code==="form_token"){let d=await C(y,this.server,s);return this.#v=d.form_token,this.#k=Date.now(),a(!1)}throw u}};try{await a(!0)}catch(l){if(r!==this.#a)return;if(this.#D(l),this.#i="idle",this.#R(l))return;if(l instanceof p&&l.code==="invalid_email")return this.#u=this.#e({id:"E_qvzP"}),this.#s(),this.#t.focus();return this.#r=this.#E(l),this.#s()}if(r!==this.#a)return;this.#i="done",this.#M("yuva-subscribe",{lists:e.map((l)=>l.id),confirmation:this.#w}),this.#s()}async#j(e,t){let i=this.#p;if(!i||this.#S.has(e.list.id))return;this.#S.add(e.list.id),this.#r="",this.#s();try{if(t){let{state:n}=await i.subscribeList(e.list.id,{consent_text:this.consentText([e.list]),page_url:location.href.split("#")[0].slice(0,2000)});e.state=n,this.#M("yuva-subscribe",{lists:[e.list.id],confirmation:n==="pending"})}else await i.unsubscribeList(e.list.id),e.state="unsubscribed"}catch(n){this.#D(n),this.#r=this.#E(n)}if(this.#S.delete(e.list.id),i===this.#p)this.#s()}#z(e,t){if(e.setAttribute("aria-invalid",String(!!t)),!t)return e.removeAttribute("aria-describedby"),null;let i=`${e.id}-error`;e.setAttribute("aria-describedby",i);let n=c("p","error",t);return n.id=i,n}#U(e,t,i,n){let s=c("label","check"),r=c("input");r.type="checkbox",r.checked=t,r.dataset.key=n,r.addEventListener("change",()=>i(r.checked));let o=c("span","text");return o.append(...e),s.append(r,o),s}#O(e){if(!e&&this.#c.length<2)return null;let t=c("fieldset");t.append(c("legend","",this.#e({id:"h16FyT"})));for(let i of this.#c){let n=[c("span","",i.list.name)];if(i.list.description)n.push(c("span","muted",i.list.description));if(e){if(n.push(c("span","muted consent",this.consentText([i.list]))),i.state==="pending")n.push(c("span","muted",this.#e({id:"x6dU53"})))}let s=e?i.state==="subscribed"||i.state==="pending":this.#h.has(i.list.id),r=this.#U(n,s,(a)=>{if(e)return void this.#j(i,a);if(a)this.#h.add(i.list.id);else this.#h.delete(i.list.id);this.#r="",this.#s()},i.list.id),o=r.querySelector("input");if(e)o.setAttribute("role","switch"),o.setAttribute("aria-checked",String(o.checked)),o.addEventListener("keydown",(a)=>{if(a.key!=="Enter")return;a.preventDefault(),o.click()}),o.disabled=this.#S.has(i.list.id);else o.disabled=this.#i==="submitting";t.append(r)}return t}#J(){let e=c("form",this.getAttribute("layout")==="inline"?"inline":"");e.noValidate=!0,e.addEventListener("submit",(m)=>{m.preventDefault(),this.#N()});let t=this.#i==="submitting",i=this.#O(!1);if(i)e.append(i);let n=c("div","row"),s=[],r=this.getAttribute("name");if(r==="optional"||r==="required"){this.#n.placeholder=r==="required"?this.#e({id:"q8yluz"}):this.#e({id:"YnOaHp"}),this.#n.setAttribute("aria-label",this.#n.placeholder),this.#n.required=r==="required",this.#n.disabled=t,n.append(this.#n);let m=this.#z(this.#n,this.#y);if(m)s.push(m)}this.#t.placeholder=this.#e({id:"XJURKP"}),this.#t.setAttribute("aria-label",this.#t.placeholder),this.#t.disabled=t,n.append(this.#t);let o=this.#z(this.#t,this.#u);if(o)s.push(o);let a=c("button","",t?this.#e({id:"1w51t9"}):this.getAttribute("button-text")||this.#e({id:"EDl9kS"}));a.type="submit",a.disabled=t,a.setAttribute("part","button"),n.append(a);let l=c("div","trap");l.setAttribute("aria-hidden","true"),l.append(this.#m);let h=c("span","",this.consentText()),u=c("label","check consent");u.setAttribute("part","consent"),this.#o.disabled=t;let d=c("span");d.append(h);let S=this.getAttribute("privacy-url");if(S&&/^https?:\/\//i.test(S)){let m=c("a","",this.#e({id:"ScJ9fj"}));m.href=S,m.target="_blank",m.rel="noopener noreferrer",d.append(" ",m)}u.append(this.#o,d);let v=this.#z(this.#o,this.#d);if(e.append(n,...s,u),v)e.append(v);return e.append(l),e}#s(){if(this.#C||!this.channel||this.#i!=="loading"&&this.#c.length===0&&!this.#r){this.#l.replaceChildren();return}let e=this.locale;this.#L=L[e]??g;let t=this.getAttribute("dir"),i=c("div","frame");i.dir=t==="rtl"||t==="ltr"?t:M(e),i.lang=e;let n=this.#b?.chat.launcher_color??this.#b?.branding.color;if(n&&/^#[0-9a-f]{6}$/i.test(n))i.style.setProperty("--brand",n),i.style.setProperty("--brand-on",z(n));let s="";if(this.#i==="done")s=this.#w?this.#e({id:"y3k2zM"}):this.#e({id:"rgySXy"});if(this.#f.textContent=s,this.#i==="idle"||this.#i==="submitting"){let h=this.#p?this.#O(!0):this.#J();if(h)i.append(h)}if(i.append(this.#f),this.#r){let h=c("p","error",this.#r);h.setAttribute("role","alert"),i.append(h)}let r,o=null;try{o=this.#l.activeElement}catch{}if(o instanceof HTMLInputElement)r=o.dataset.key;let a=c("style");a.textContent=O,this.#l.replaceChildren(a,i);let l=r?this.#l.querySelector(`[data-key="${r}"]`):o;if(l instanceof HTMLElement&&l.isConnected)l.focus({preventScroll:!0})}}function T(){if(typeof customElements>"u")return;if(!customElements.get("yuva-subscribe"))customElements.define("yuva-subscribe",f)}f.loadClient=()=>import(new URL("widget/yuva-subscribe-client-jya732vb.js",x||location.href).href);T();})();
33
+ `;class f extends _{static observedAttributes=["channel","server","locale","dir","lists","layout","name","button-text","consent","privacy-url","identity-token"];static loadClient=null;#l;#L=g;#g=!1;#a=0;#i="loading";#C=!1;#b=null;#c=[];#h=new Set;#v="";#k=0;#w=!1;#r="";#u="";#y="";#d="";#x=null;#p=null;#S=new Set;#t=c("input");#n=c("input");#m=c("input");#o=c("input");#f=c("p");constructor(){super();this.#l=this.attachShadow({mode:"open"}),this.#t.type="email",this.#t.autocomplete="email",this.#t.required=!0,this.#t.maxLength=320,this.#t.id="email",this.#n.autocomplete="name",this.#n.maxLength=200,this.#n.id="name",this.#m.name="website",this.#m.tabIndex=-1,this.#m.autocomplete="off",this.#o.type="checkbox",this.#o.id="consent",this.#o.addEventListener("change",()=>{this.#d="",this.#s()});for(let e of[this.#t,this.#n])e.setAttribute("part","field"),e.dir="auto";this.#f.setAttribute("part","status"),this.#f.setAttribute("role","status"),this.#f.setAttribute("aria-live","polite")}get channel(){return this.getAttribute("channel")}set channel(e){this.#A("channel",e)}get server(){return(this.getAttribute("server")||(x?new URL(x).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#A("server",e)}get locale(){return E(L,[this.getAttribute("locale"),navigator.language])}set locale(e){this.#A("locale",e)}get lists(){return this.#c.map((e)=>e.list)}setIdentityToken(e){if(this.#x=e,this.#g)this.#P()}connectedCallback(){this.#g=!0,this.#P()}disconnectedCallback(){this.#g=!1}attributeChangedCallback(e,t,i){if(!this.#g||t===i)return;if(["channel","server","lists","identity-token"].includes(e))return void this.#P();this.#s()}#A(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}#e(e){return P(this.#L,e,g)}get#q(){return!!this.#x||this.hasAttribute("identity-token")}async#T(){return this.#x?await this.#x()??null:this.getAttribute("identity-token")}#I(e){let t=(this.getAttribute("lists")??"").split(",").map((n)=>n.trim()).filter((n)=>n&&n!=="all");if(t.length===0)return e;let i=t.map((n)=>e.find((s)=>s.id===n)).filter((n)=>!!n);if(i.length<t.length)console.warn(`Yuva: some lists in "${t.join(",")}" are not public lists`);return i}async#P(){let e=++this.#a,t=this.channel;if(this.#C=!1,this.#i="loading",this.#c=[],this.#r="",this.#p=null,this.#s(),!t)return;let i=this.server;try{let n=b(y,i,`/client/v1/channels/${encodeURIComponent(t)}`),s=null;if(this.#q&&f.loadClient&&await this.#T()){let{createYuvaClient:r}=await f.loadClient(),o=r({server:i,channel:t,identityToken:()=>this.#T()});try{let{items:a}=await o.subscriptions(),l=new Set(this.#I(a.map((h)=>h.list)));s=a.filter((h)=>l.has(h.list)),this.#p=o}catch(a){if(!(a instanceof p)||a.code!=="identity_required")throw a}}if(!s){let{lists:r,form_token:o}=await C(y,i,t);s=this.#I(r).map((a)=>({list:a})),this.#v=o,this.#k=Date.now()}if(this.#b=await n,e!==this.#a)return;if(this.#c=s,this.#h=new Set(s.length===1?[s[0].list.id]:[]),this.#i="idle",s.length===0)console.warn(`Yuva: channel ${t} has no public mailing lists to offer`)}catch(n){if(e!==this.#a)return;if(this.#R(n))return;this.#i="idle",this.#r=this.#E(n)}this.#s()}#R(e){let t=e instanceof p&&(e.status===404||e.code==="origin_not_allowed"||e.code==="page_origin");if(t)this.#C=!0,console.warn(`Yuva: channel ${this.channel} is unknown, offers no such list or does not allow ${location.origin}`),this.#s();return t}#E(e){let t=e instanceof p?e.code:"";if(t==="rate_limited")return this.#e({id:"tzsBOP"});if(t==="network")return this.#e({id:"GQVIIl"});if(t==="no_email")return this.#e({id:"eku1-t"});return this.#e({id:"jWgNnM"})}#M(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#D(e){this.#M("yuva-subscribe-error",{code:e instanceof p?e.code:"error"})}consentText(e=this.#_()){let t=this.getAttribute("consent")?.trim();if(t)return t;let i=(e.length?e:this.lists).map((r)=>r.name),n=new Intl.ListFormat(this.locale,{type:"conjunction"}).format(i),s=this.#b?.name??"";return this.#e({id:"dMJfG5",values:{list:n,inbox:s}})}#_(){return this.lists.filter((e)=>this.#h.has(e.id))}async#N(){if(this.#i!=="idle"||!this.channel)return;let e=this.#_(),t=this.#t.value.trim(),i=this.#n.value.trim(),n=this.getAttribute("name");if(this.#r=e.length===0?this.#e({id:"-g5O6h"}):"",this.#u=this.#t.checkValidity()&&t?"":this.#e({id:"E_qvzP"}),this.#y=n==="required"&&!i?this.#e({id:"E_LjOR"}):"",this.#d=this.#o.checked?"":this.#e({id:"lDEbTy"}),this.#r||this.#u||this.#y||this.#d){this.#s();let l=[this.#u&&this.#t,this.#y&&this.#n,this.#d&&this.#o];for(let h of l)if(h)return h.focus();return}let s=this.channel,r=this.#a,o=this.consentText(e);this.#i="submitting",this.#s();let a=async(l)=>{let h=this.#k+D-Date.now();if(h>0)await new Promise((u)=>setTimeout(u,h));try{let{confirmation:u}=await k(y,this.server,s,{email:t,name:n==="optional"||n==="required"?i||void 0:void 0,list_ids:e.map((d)=>d.id),locale:this.locale,page_url:location.href.split("#")[0].slice(0,2000),consent_text:o,form_token:this.#v,website:this.#m.value||void 0});return this.#w=u,!0}catch(u){if(l&&u instanceof p&&u.code==="form_token"){let d=await C(y,this.server,s);return this.#v=d.form_token,this.#k=Date.now(),a(!1)}throw u}};try{await a(!0)}catch(l){if(r!==this.#a)return;if(this.#D(l),this.#i="idle",this.#R(l))return;if(l instanceof p&&l.code==="invalid_email")return this.#u=this.#e({id:"E_qvzP"}),this.#s(),this.#t.focus();return this.#r=this.#E(l),this.#s()}if(r!==this.#a)return;this.#i="done",this.#M("yuva-subscribe",{lists:e.map((l)=>l.id),confirmation:this.#w}),this.#s()}async#j(e,t){let i=this.#p;if(!i||this.#S.has(e.list.id))return;this.#S.add(e.list.id),this.#r="",this.#s();try{if(t){let{state:n}=await i.subscribeList(e.list.id,{consent_text:this.consentText([e.list]),page_url:location.href.split("#")[0].slice(0,2000)});e.state=n,this.#M("yuva-subscribe",{lists:[e.list.id],confirmation:n==="pending"})}else await i.unsubscribeList(e.list.id),e.state="unsubscribed"}catch(n){this.#D(n),this.#r=this.#E(n)}if(this.#S.delete(e.list.id),i===this.#p)this.#s()}#z(e,t){if(e.setAttribute("aria-invalid",String(!!t)),!t)return e.removeAttribute("aria-describedby"),null;let i=`${e.id}-error`;e.setAttribute("aria-describedby",i);let n=c("p","error",t);return n.id=i,n}#U(e,t,i,n){let s=c("label","check"),r=c("input");r.type="checkbox",r.checked=t,r.dataset.key=n,r.addEventListener("change",()=>i(r.checked));let o=c("span","text");return o.append(...e),s.append(r,o),s}#O(e){if(!e&&this.#c.length<2)return null;let t=c("fieldset");t.append(c("legend","",this.#e({id:"h16FyT"})));for(let i of this.#c){let n=[c("span","",i.list.name)];if(i.list.description)n.push(c("span","muted",i.list.description));if(e){if(n.push(c("span","muted consent",this.consentText([i.list]))),i.state==="pending")n.push(c("span","muted",this.#e({id:"x6dU53"})))}let s=e?i.state==="subscribed"||i.state==="pending":this.#h.has(i.list.id),r=this.#U(n,s,(a)=>{if(e)return void this.#j(i,a);if(a)this.#h.add(i.list.id);else this.#h.delete(i.list.id);this.#r="",this.#s()},i.list.id),o=r.querySelector("input");if(e)o.setAttribute("role","switch"),o.setAttribute("aria-checked",String(o.checked)),o.addEventListener("keydown",(a)=>{if(a.key!=="Enter")return;a.preventDefault(),o.click()}),o.disabled=this.#S.has(i.list.id);else o.disabled=this.#i==="submitting";t.append(r)}return t}#J(){let e=c("form",this.getAttribute("layout")==="inline"?"inline":"");e.noValidate=!0,e.addEventListener("submit",(m)=>{m.preventDefault(),this.#N()});let t=this.#i==="submitting",i=this.#O(!1);if(i)e.append(i);let n=c("div","row"),s=[],r=this.getAttribute("name");if(r==="optional"||r==="required"){this.#n.placeholder=r==="required"?this.#e({id:"q8yluz"}):this.#e({id:"YnOaHp"}),this.#n.setAttribute("aria-label",this.#n.placeholder),this.#n.required=r==="required",this.#n.disabled=t,n.append(this.#n);let m=this.#z(this.#n,this.#y);if(m)s.push(m)}this.#t.placeholder=this.#e({id:"XJURKP"}),this.#t.setAttribute("aria-label",this.#t.placeholder),this.#t.disabled=t,n.append(this.#t);let o=this.#z(this.#t,this.#u);if(o)s.push(o);let a=c("button","",t?this.#e({id:"1w51t9"}):this.getAttribute("button-text")||this.#e({id:"EDl9kS"}));a.type="submit",a.disabled=t,a.setAttribute("part","button"),n.append(a);let l=c("div","trap");l.setAttribute("aria-hidden","true"),l.append(this.#m);let h=c("span","",this.consentText()),u=c("label","check consent");u.setAttribute("part","consent"),this.#o.disabled=t;let d=c("span");d.append(h);let S=this.getAttribute("privacy-url");if(S&&/^https?:\/\//i.test(S)){let m=c("a","",this.#e({id:"ScJ9fj"}));m.href=S,m.target="_blank",m.rel="noopener noreferrer",d.append(" ",m)}u.append(this.#o,d);let v=this.#z(this.#o,this.#d);if(e.append(n,...s,u),v)e.append(v);return e.append(l),e}#s(){if(this.#C||!this.channel||this.#i!=="loading"&&this.#c.length===0&&!this.#r){this.#l.replaceChildren();return}let e=this.locale;this.#L=L[e]??g;let t=this.getAttribute("dir"),i=c("div","frame");i.dir=t==="rtl"||t==="ltr"?t:M(e),i.lang=e;let n=this.#b?.chat.launcher_color??this.#b?.branding.color;if(n&&/^#[0-9a-f]{6}$/i.test(n))i.style.setProperty("--brand",n),i.style.setProperty("--brand-on",z(n));let s="";if(this.#i==="done")s=this.#w?this.#e({id:"y3k2zM"}):this.#e({id:"rgySXy"});if(this.#f.textContent=s,this.#i==="idle"||this.#i==="submitting"){let h=this.#p?this.#O(!0):this.#J();if(h)i.append(h)}if(i.append(this.#f),this.#r){let h=c("p","error",this.#r);h.setAttribute("role","alert"),i.append(h)}let r,o=null;try{o=this.#l.activeElement}catch{}if(o instanceof HTMLInputElement)r=o.dataset.key;let a=c("style");a.textContent=O,this.#l.replaceChildren(a,i);let l=r?this.#l.querySelector(`[data-key="${r}"]`):o;if(l instanceof HTMLElement&&l.isConnected)l.focus({preventScroll:!0})}}function T(){if(typeof customElements>"u")return;if(!customElements.get("yuva-subscribe"))customElements.define("yuva-subscribe",f)}f.loadClient=()=>import(new URL("widget/yuva-subscribe-client-kba66fz1.js",x||location.href).href);T();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "useyuva",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Yuva for the web: a headless client for contacts, the <yuva-chat> element, documentation page feedback and discussions, the <yuva-subscribe> mailing list form, cookieless web analytics, React hooks, a Nuxt module and a typed /v1 client.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,7 @@
29
29
  "./dist/yuva-chat.js",
30
30
  "./dist/yuva-docs.js",
31
31
  "./dist/yuva-analytics.js",
32
+ "./dist/yuva-analytics-consent.js",
32
33
  "./dist/yuva-subscribe.js"
33
34
  ],
34
35
  "exports": {
@@ -1,11 +0,0 @@
1
- class c extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function g(e,t,n,{method:s="GET",json:i,body:o,headers:a={},token:p,blob:r}={}){if(a={...a},p)a.Authorization=`Bearer ${p}`;let m=o;if(i!==void 0)a["Content-Type"]="application/json",m=JSON.stringify(i);let l;try{l=await e(t+n,{method:s,headers:a,body:m,credentials:"omit"})}catch{throw new c(0,"network")}if(!l.ok){let u="error";try{u=(await l.json()).code??u}catch{}throw new c(l.status,u)}if(l.status===204)return;return r?await l.blob():await l.json()}function P(e,t,n){return g(e,t,`/client/v1/channels/${encodeURIComponent(n)}/lists`)}function b(e,t,n,s){return g(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,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??n)-n)/2),p=Math.max(0,(window.screenY??0)+((window.outerHeight??s)-s)/2),r=window.open(I(e,t,o),"yuva-reader",`popup=yes,width=${n},height=${s},left=${Math.round(a)},top=${Math.round(p)}`);if(!r)return Promise.reject(new c(0,"popup_blocked"));return new Promise((m,l)=>{let u=!1,f=()=>{u=!0,window.removeEventListener("message",S),clearInterval(v)},S=(h)=>{if(u||h.origin!==i||h.source&&h.source!==r)return;let d=h.data;if(!T(d)||d.channel_key!==t||d.origin!==o)return;f();try{r.close()}catch{}m({token:d.token,expires_at:d.expires_at,reader:d.reader})},v=setInterval(()=>{let h=!1;try{h=r.closed}catch{}if(!h)return;clearInterval(v),setTimeout(()=>{if(u)return;f(),l(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 M(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 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 _(e,t,n){let s=[];for(let[i,o]of e)s.push(`--${n}\r
2
- Content-Disposition: form-data; name="${i}"\r
3
- \r
4
- ${o}\r
5
- `);for(let i of t){let o=i.name||"file";s.push(`--${n}\r
6
- Content-Disposition: form-data; name="files"; filename="${E(o)}"\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;#m=null;#g=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.#m??=this.#P(!1).then((e)=>(this.#l("session",{session:e,renewed:!1}),e)).finally(()=>{this.#m=null}),this.#m}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.#m=null,this.#g=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){return this.#e("/client/v1/conversations",this.#S(e))}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(o){if(!(o instanceof c)||o.status!==401||this.#c?.token!==s.token)throw o;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()}){let i=this.#f(s);if(n.length===0)return{method:"POST",headers:i,json:{body:e,subject:t,client_id:s}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",s]);let a=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return i["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:i,body:_(o,n,a)}}#h(e,t){return g(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.#g??=(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.#g=null}),this.#g}async#P(e){let t=this.stored(),n=await this.#t?.()||null,s=n?M(n):null,i=t.session;if(!e&&i&&i.sub===s&&Date.parse(i.expires_at)>Date.now()+60000)try{let r=await this.#h("/client/v1/session",{token:i.token});return this.#b(r,i.token,s)}catch(r){if(!(r instanceof c)||r.status!==401&&r.status!==403)throw r}let o=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,...p}=o;return this.#b(p,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 O(e){return new D(e)}export{O as createYuvaClient};