useyuva 0.0.7 → 0.0.8

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 f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function N(e,t,i,{method:s="GET",json:n,body:r,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=r;if(n!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(n);let d;try{d=await e(t+i,{method:s,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!d.ok){let u="error";try{u=(await d.json()).code??u}catch{}throw new f(d.status,u)}if(d.status===204)return;return c?await d.blob():await d.json()}class E{server;socketClass;handlers;#t=null;#s=0;#i=0;#n=null;#r=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#t?.readyState===1}start(){if(this.#r=!1,!this.#t)this.#o()}stop(){if(this.#r=!0,this.#n)clearTimeout(this.#n);this.#n=null;let e=this.#t;this.#t=null,e?.close(1000)}reset(){this.#s=0}nudge(){if(this.#r||this.#t)return;if(this.#n)clearTimeout(this.#n);this.#n=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.#s>0)t.searchParams.set("last_event_id",String(this.#s));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#e();return}this.#t=i,i.onmessage=(s)=>{let n;try{n=JSON.parse(String(s.data))}catch{return}if(n.type==="ready")this.#i=0,this.#s=Math.max(this.#s,n.last_event_id);else if("id"in n&&typeof n.id==="number")this.#s=Math.max(this.#s,n.id);this.handlers.event(n)},i.onclose=(s)=>{if(this.#t!==i)return;if(this.#t=null,this.#r)return;if(s.code===1008){this.#s=0,this.handlers.sessionEnded();return}this.#e()}}#e(){if(this.#r||this.#n)return;let e=this.#i++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#n=setTimeout(()=>{this.#n=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 he(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 j(e,t,{width:i=460,height:s=640}={}){let n=new URL(e).origin,r=location.origin,a=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,r),"yuva-reader",`popup=yes,width=${i},height=${s},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,d)=>{let u=!1,g=()=>{u=!0,window.removeEventListener("message",p),clearInterval(m)},p=(y)=>{if(u||y.origin!==n||y.source&&y.source!==c)return;let x=y.data;if(!he(x)||x.channel_key!==t||x.origin!==r)return;g();try{c.close()}catch{}h({token:x.token,expires_at:x.expires_at,reader:x.reader})},m=setInterval(()=>{let y=!1;try{y=c.closed}catch{}if(!y)return;clearInterval(m),setTimeout(()=>{if(u)return;g(),d(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",p)})}function Y(e){return`yuva:${e}`}function W(e,t){return`yuva:reader:${e} ${t}`}function H(){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 ue(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 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 D(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 fe(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function ge(e,t,i){let s=[];for(let[n,r]of e)s.push(`--${i}\r
1
+ (()=>{class d extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function U(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()}class E{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.#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 ne(e,t,i){let s=new URL("/account/connect",e);return s.searchParams.set("channel",t),s.searchParams.set("origin",i),s.href}function re(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 L(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(ne(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(!re(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 O(e){return`yuva:${e}`}function z(e,t){return`yuva:reader:${e} ${t}`}function W(){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 oe(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 ae(){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 D(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 le(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function ce(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
- ${r}\r
5
- `);for(let n of t){let r=n.name||"file";s.push(`--${i}\r
6
- Content-Disposition: form-data; name="files"; filename="${fe(r)}"\r
4
+ ${o}\r
5
+ `);for(let n of t){let o=n.name||"file";s.push(`--${i}\r
6
+ Content-Disposition: form-data; name="files"; filename="${le(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;#t;#s;#i;#n;#r;#o=null;#e=null;#g=null;#f=null;#c=null;#p;#d=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#t=e.fetch??((t,i)=>fetch(t,i)),this.#s=e.WebSocket??globalThis.WebSocket,this.#i=e.storage??pe(),this.#n=e.identityToken??null,this.#r=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#e}get token(){return this.#o}get connected(){return this.#c?.connected??!1}on(e,t){let i=this.#d.get(e);if(!i)this.#d.set(e,i=new Set);return i.add(t),()=>void i.delete(t)}#l(e,t){for(let i of this.#d.get(e)??[])i(t)}stored(){try{let e=this.#i.getItem(Y(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#x(e){try{this.#i.setItem(Y(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}setIdentityToken(e){this.#n=e,this.reset()}start(){if(this.#e)return Promise.resolve(this.#e);return this.#g??=this.#R(!1).then((e)=>(this.#l("session",{session:e,renewed:!1}),e)).finally(()=>{this.#g=null}),this.#g}async refresh(){let e=await this.#a("/client/v1/session");return this.#e={...this.#e,...e},this.#l("session",{session:this.#e,renewed:!1}),this.#e}reset(){this.#c?.stop(),this.#c?.reset(),this.#g=null,this.#f=null,this.#o=null,this.#e=null}async signOut(){let e=this.#o;this.reset();let t=this.stored();if(delete t.session,this.#x(t),e)await this.#b("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#s)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#c??=new E(this.server,this.#s,{token:()=>this.#o,event:(e)=>{if(e.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",e)},sessionEnded:()=>void this.#h().catch(()=>this.#c?.nudge()),reconnecting:(e)=>{if(this.#l("connection",{state:"reconnecting",attempt:e}),e===2)this.#a("/client/v1/session").catch(()=>{return})}}),!this.#c.connected)this.#l("connection",{state:"connecting",attempt:0});this.#c.start()}disconnect(){this.#c?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#c?.nudge()}listConversations(e={}){return this.#a(`/client/v1/conversations${D({...e})}`)}getConversation(e){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#a("/client/v1/conversations",this.#m(e))}listMessages(e,t={}){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages${D({...t})}`)}sendMessage(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#m(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??H();return this.#a("/client/v1/feedback",{method:"POST",headers:this.#y(t),json:{...e,client_id:t}})}get reader(){if(this.#p===void 0)try{let e=this.#i.getItem(W(this.server,this.channel));this.#p=e?JSON.parse(e):null}catch{this.#p=null}if(this.#p&&Date.parse(this.#p.expires_at)<=Date.now()+30000)this.#w(null);return this.#p}#w(e){let t=this.#p?.token!==e?.token;this.#p=e;try{this.#i.setItem(W(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#l("reader",e)}readerSignIn(e){return j(this.server,this.channel,e).then((t)=>(this.#w(t),t))}setReader(e){this.#w(e)}async readerSignOut(){let e=this.reader?.token;if(this.#w(null),e)await this.#b("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#v(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${D({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#v(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#v("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#v(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#v(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#v(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#v(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#v(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#v(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#e)return this.#e.contact.identified?"contact":null;return await this.#n?.()?"contact":null}async#v(e,t,i=!0){let s=this.reader;if(s)try{return await this.#b(e,{...t,token:s.token})}catch(r){if(!(r instanceof f)||r.status!==401||this.#p?.token!==s.token)throw r;if(this.#w(null),i)throw new f(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#a(e,t);if(i)throw new f(403,"sign_in_required");return this.#b(e,t)}#y(e){return this.#r&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#m({body:e,subject:t,files:i=[],client_id:s=H()}){let n=this.#y(s);if(i.length===0)return{method:"POST",headers:n,json:{body:e,subject:t,client_id:s}};let r=[];if(t)r.push(["subject",t]);if(e)r.push(["body",e]);r.push(["client_id",s]);let a=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return n["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:n,body:ge(r,i,a)}}#b(e,t){return N(this.#t,this.server,e,t)}async#a(e,t={},i=!0){if(!this.#o)await this.start();try{return await this.#b(e,{...t,token:this.#o})}catch(s){if(!i||!(s instanceof f)||s.status!==401)throw s;return await this.#h(),this.#a(e,t,!1)}}#h(){return this.#f??=(async()=>{let e=await this.#R(!0);if(this.#c)this.#c.stop(),this.#c.reset(),this.#c.start();this.#l("session",{session:e,renewed:!0})})().finally(()=>{this.#f=null}),this.#f}async#R(e){let t=this.stored(),i=await this.#n?.()||null,s=i?ue(i):null,n=t.session;if(!e&&n&&n.sub===s&&Date.parse(n.expires_at)>Date.now()+60000)try{let c=await this.#b("/client/v1/session",{token:n.token});return this.#E(c,n.token,s)}catch(c){if(!(c instanceof f)||c.status!==401&&c.status!==403)throw c}let r=await this.#b("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=r;return this.#E(l,a,s)}#E(e,t,i){this.#o=t,this.#e=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 G(e){return new B(e)}var M=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var F=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var V={en:M,tr:F},me=new Set(["ar","fa","he","ur"]),ye="en";function J(...e){for(let t of e){if(!t)continue;let i=t.toLowerCase();if(V[i])return i;let s=i.split(/[-_]/)[0]??"";if(V[s])return s}return ye}function Q(e){return me.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}function Z(e,t,i=M){let s=e[t.id]??i[t.id],n=t.values??{};if(typeof s==="string")return s;if(Array.isArray(s))return s.map((r)=>typeof r==="string"?r:Array.isArray(r)?String(n[r[0]]??""):"").join("");return t.message??t.id}var S=JSON.parse(`{"-UxBoG":["Deleted member"],"1UzENP":["No"],"2Hlmdt":["Write a reply…"],"2lF8Zj":["Unanswered"],"3CApMv":["All discussions"],"3PqJQG":["Nothing to preview."],"4-S4QM":["Unmark as answer"],"5lWFkC":["Sign in"],"78dEKp":["Sort discussions"],"7oGBMv":["Discussions"],"8Ekoev":["You can't do that."],"8ntmc1":["Votes: ",["0"]],"8wRl7c":["The opening post was deleted."],"99w-GZ":["Sign in to start a discussion. Your name is shown with your post."],"D9CFV5":["Anonymous"],"E_qvzP":["Enter a valid e-mail address."],"EmiQvf":["Thanks! Anything we could add? (optional)"],"FMWGhb":["Deleted reader"],"F_vGso":["Your reply"],"G2fuEb":["Locked"],"GQVIIl":["You seem to be offline."],"GqCA_t":["Answered"],"HkXOWm":["This reply was deleted."],"Hw3P48":["Replies: ",["0"]],"ImOQa9":["Reply"],"JfAIiv":["This discussion is locked. New replies are closed."],"JlFcis":["Send"],"KDw4GX":["Try again"],"KEjhwb":["This discussion is locked."],"KM6m8p":["Team"],"Kl3TuI":["Get an e-mail when someone replies or an answer is accepted."],"Klsidc":["Delete this reply?"],"LwDe8g":["Sign in to take part in the discussion."],"MDmQKn":["Could not load the discussions."],"MHrjPM":["Title"],"MKEPCY":["Follow"],"NjUiZ4":["Ask a question, share an idea or describe a problem with this page."],"NrGspR":["Thanks! Your discussion will appear for everyone once the team approves it."],"OVijcR":["Remove your vote (",["0"]," votes)"],"PL0621":["Sign in to reply, vote and follow this discussion."],"PN38hZ":["Your question or idea"],"PZ_kxo":["Keep"],"Pwqkdw":["Loading…"],"RqsQKK":["Your first posts are checked by the team before they appear for everyone."],"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"],"VGqKyv":["This discussion is no longer available."],"Vwy_nT":["Markdown is supported."],"WWy8TN":["Top"],"XJURKP":["E-mail address"],"YZayoP":["Thanks! Your reply will appear for everyone once the team approves it."],"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."],"cnGeoo":["Delete"],"d6N994":["Thanks for your feedback."],"dEgA5A":["Cancel"],"dNOvhg":["Upvote (",["0"]," votes)"],"ePK91l":["Edit"],"fMPkxb":["Show more"],"fcWrnU":["Sign out"],"i4_LY_":["Write"],"isRobC":["New"],"j-3eim":["Discussions about this page"],"jhu92n":["Mark as answer"],"k4b5_X":["edited"],"l75CjT":["Yes"],"lWv8id":["Awaiting approval"],"n5vqdp":["Start discussion"],"nLqMRA":["Team member"],"nW3go1":["Your browser blocked the sign-in window. Allow pop-ups for this site and try again."],"pzatAP":["Loading discussions…"],"qzVesX":["Edit your post"],"rAl91-":["Delete this discussion?"],"rdUucN":["Preview"],"rpfOwz":["No discussions about this page yet."],"tA4dAO":["No thanks"],"tAL5wg":["Could not send. Try again."],"tayT8P":["Discussions are turned off for this site."],"tfDRzk":["Save"],"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"],"y-KXxN":["Accepted answer"],"y6sq5j":["Following"],"z1qf6l":["Start a discussion"],"zmA6sS":["Reader"]}`);var X=JSON.parse('{"-UxBoG":["Silinmiş üye"],"1UzENP":["Hayır"],"2Hlmdt":["Bir yanıt yazın…"],"2lF8Zj":["Yanıtsız"],"3CApMv":["Tüm tartışmalar"],"3PqJQG":["Önizlenecek bir şey yok."],"4-S4QM":["Yanıt işaretini kaldır"],"5lWFkC":["Giriş yap"],"78dEKp":["Tartışmaları sırala"],"7oGBMv":["Tartışmalar"],"8Ekoev":["Bunu yapamazsınız."],"8ntmc1":["Oylar: ",["0"]],"8wRl7c":["Açılış gönderisi silindi."],"99w-GZ":["Tartışma başlatmak için giriş yapın. Adınız gönderinizle birlikte gösterilir."],"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"],"F_vGso":["Yanıtınız"],"G2fuEb":["Kilitli"],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"GqCA_t":["Yanıtlandı"],"HkXOWm":["Bu yanıt silindi."],"Hw3P48":["Yanıtlar: ",["0"]],"ImOQa9":["Yanıtla"],"JfAIiv":["Bu tartışma kilitli. Yeni yanıt yazılamaz."],"JlFcis":["Gönder"],"KDw4GX":["Yeniden dene"],"KEjhwb":["Bu tartışma kilitli."],"KM6m8p":["Ekip"],"Kl3TuI":["Biri yanıt yazdığında ya da bir yanıt kabul edildiğinde e-posta alın."],"Klsidc":["Bu yanıt silinsin mi?"],"LwDe8g":["Tartışmaya katılmak için giriş yapın."],"MDmQKn":["Tartışmalar yüklenemedi."],"MHrjPM":["Başlık"],"MKEPCY":["Takip et"],"NjUiZ4":["Bir soru sorun, bir fikir paylaşın ya da bu sayfadaki bir sorunu anlatın."],"NrGspR":["Teşekkürler! Tartışmanız ekip onayladığında herkese görünecek."],"OVijcR":["Oyunuzu geri alın (",["0"]," oy)"],"PL0621":["Bu tartışmada yanıt yazmak, oy vermek ve takip etmek için giriş yapın."],"PN38hZ":["Sorunuz ya da fikriniz"],"PZ_kxo":["Kalsın"],"Pwqkdw":["Yükleniyor…"],"RqsQKK":["İlk gönderileriniz herkese görünmeden önce ekip tarafından kontrol edilir."],"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"],"VGqKyv":["Bu tartışma artık mevcut değil."],"Vwy_nT":["Markdown desteklenir."],"WWy8TN":["En çok oy alan"],"XJURKP":["E-posta adresi"],"YZayoP":["Teşekkürler! Yanıtınız ekip onayladığında herkese görünecek."],"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."],"cnGeoo":["Sil"],"d6N994":["Geri bildiriminiz için teşekkürler."],"dEgA5A":["Vazgeç"],"dNOvhg":["Oy ver (",["0"]," oy)"],"ePK91l":["Düzenle"],"fMPkxb":["Daha fazla göster"],"fcWrnU":["Çıkış yap"],"i4_LY_":["Yaz"],"isRobC":["Yeni"],"j-3eim":["Bu sayfayla ilgili tartışmalar"],"jhu92n":["Yanıt olarak işaretle"],"k4b5_X":["düzenlendi"],"l75CjT":["Evet"],"lWv8id":["Onay bekliyor"],"n5vqdp":["Tartışmayı başlat"],"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…"],"qzVesX":["Gönderinizi düzenleyin"],"rAl91-":["Bu tartışma silinsin mi?"],"rdUucN":["Önizleme"],"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ı."],"tfDRzk":["Kaydet"],"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"],"y-KXxN":["Kabul edilen yanıt"],"y6sq5j":["Takip ediliyor"],"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((r)=>{let a=r/255;return a<=0.03928?a/12.92:((a+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 A(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{}}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 r=history[n];history[n]=function(...a){let l=r.apply(this,a);return s(),l}}return window.addEventListener("popstate",s),window.addEventListener("hashchange",s),t}function _(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:S,tr:X},I=new Map,xe=typeof HTMLElement>"u"?class{}:HTMLElement,ae=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",we=`
11
+ `),new Blob(s)}class q{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??ae(),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(O(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#x(e){try{this.#n.setItem(O(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})}setIdentityToken(e){this.#t=e,this.reset()}start(){if(this.#s)return Promise.resolve(this.#s);return this.#h??=this.#S(!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 E(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${D({...e})}`)}getConversation(e){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#a("/client/v1/conversations",this.#C(e))}listMessages(e,t={}){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages${D({...t})}`)}sendMessage(e,t){return this.#a(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#C(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??W();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(z(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(z(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#d("reader",e)}readerSignIn(e){return L(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${D({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}:{}}#C({body:e,subject:t,files:i=[],client_id:s=W()}){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:ce(o,i,r)}}#f(e,t){return U(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.#S(!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#S(e){let t=this.stored(),i=await this.#t?.()||null,s=i?oe(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 j(e){return new q(e)}var M=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var K=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function Y(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 B={en:M,tr:K},de=new Set(["ar","fa","he","ur"]),he="en";function H(...e){for(let t of e){if(!t)continue;let i=t.toLowerCase();if(B[i])return i;let s=i.split(/[-_]/)[0]??"";if(B[s])return s}return he}function F(e){return de.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}function N(e,t,i=M){return Y(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 G=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 J(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function V(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 Q(e){return`yuva:${e}`}function I(e){try{let t=localStorage.getItem(Q(e));return t?JSON.parse(t):{}}catch{return{}}}function Z(e,t){try{localStorage.setItem(Q(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 X=Symbol.for("yuva.navigation");function ue(){let e=window,t=e[X];if(t)return t;let i=new EventTarget;t=e[X]=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 P(e){try{let t=new URL(e||location.href,location.href);return t.search="",t.hash="",t.href}catch{return e||location.href}}function ee(e){let t=ue(),i=!1,s=()=>{if(i)return;i=!0,queueMicrotask(()=>{i=!1,e()})};return t.addEventListener("change",s),()=>t.removeEventListener("change",s)}var pe={en:w,tr:G},_=new Map,fe=typeof HTMLElement>"u"?class{}:HTMLElement,T=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",ge=`
12
12
  :host {
13
13
  --yuva-accent: #2563eb;
14
14
  --yuva-on-accent: #ffffff;
@@ -56,11 +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
- `;function o(e,t,i){let s=document.createElement(e);if(t)s.className=t;if(i!==void 0)s.textContent=i;return s}class P extends xe{static observedAttributes=["channel","server","locale","dir","page","page-title","identity-token"];root;inbox=null;pageUrl="";refused=!1;direction="ltr";#t=S;#s=null;#i=null;#n=null;#r="";#o=!1;#e="";constructor(){super();this.root=this.attachShadow({mode:"open"})}get channel(){return this.getAttribute("channel")}set channel(e){this.#g("channel",e)}get server(){return(this.getAttribute("server")||(ae?new URL(ae).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#g("server",e)}get locale(){return J(this.getAttribute("locale"),navigator.language)}set locale(e){this.#g("locale",e)}get page(){return this.pageUrl||_(this.getAttribute("page"))}set page(e){this.#g("page",e)}get pageTitle(){return this.getAttribute("page-title")||document.title}set pageTitle(e){this.#g("page-title",e)}#g(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}setIdentityToken(e){if(this.#i=e,this.#s?.setIdentityToken(()=>this.#f()),this.#o&&!this.refused)this.render()}connectedCallback(){this.#o=!0,this.#n??=re(()=>this.#c()),this.pageUrl=_(this.getAttribute("page")),this.#p(),this.#d(),this.render(),this.pageChanged()}disconnectedCallback(){this.#o=!1,this.#n?.(),this.#n=null}attributeChangedCallback(e,t,i){if(!this.#o||t===i)return;if(e==="channel"||e==="server"){this.#s?.reset(),this.#s=null,this.refused=!1,this.inbox=null,this.#r="",this.#d(),this.reset(),this.render(),this.pageChanged();return}if(e==="page")return this.#c();if(e==="identity-token")this.#s?.setIdentityToken(()=>this.#f());if(e==="locale"||e==="dir")this.#p();this.render()}t(e){return Z(this.#t,e,S)}client(){return this.#s??=G({server:this.server,channel:this.channel??"",identityToken:()=>this.#f()}),this.#s}get identified(){return!!this.#i||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 f&&(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 f?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=o("style");i.textContent=we+e;let s=o("div","frame");if(s.dir=this.direction,s.lang=this.locale,this.#e)s.style.setProperty("--yuva-accent",this.#e),s.style.setProperty("--yuva-on-accent",te(this.#e));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.#i?await this.#i()??null:this.getAttribute("identity-token")}#c(){if(!this.#o)return;let e=_(this.getAttribute("page"));if(e===this.pageUrl)return;this.pageUrl=e,this.reset(),this.render(),this.pageChanged()}#p(){let e=this.locale;this.#t=be[e]??S,this.direction=this.getAttribute("dir")==="rtl"?"rtl":this.getAttribute("dir")==="ltr"?"ltr":Q(e)}#d(){let e=this.channel,t=`${this.server} ${e}`;if(!e||this.#r===t)return;this.#r=t;let i=A(e).launcher;if(i?.color)this.#l(i.color);let s=I.get(t);if(!s)s=this.client().channelSettings(),I.set(t,s),s.catch(()=>I.delete(t));s.then((n)=>{if(this.channel!==e)return;this.inbox=n;let r=ee(n);if(r.color)this.#l(r.color);if(se(e,{...A(e),launcher:r}),!this.refused)this.render()}).catch((n)=>{if(this.channel===e)this.refusal(n)})}#l(e){if(!/^#[0-9a-f]{6}$/i.test(e))return;this.#e=e}}var ke=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Ce(e,t){let i=document.createElement("a");return i.href=e,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function z(e,t){let i=document.createElement(e);return i.append(...t),i}function w(e){let t=[],i=0;for(let s of e.matchAll(ke)){let n=s.index??0;if(n>i)t.push(document.createTextNode(e.slice(i,n)));let[r,a,l,c,h]=s;if(a)t.push(z("code",[document.createTextNode(a.slice(1,-1))]));else if(l)t.push(z("strong",w(l.slice(2,-2))));else if(c)t.push(z("em",w(c.slice(1,-1))));else if(h){let d=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(d);t.push(u.protocol==="http:"||u.protocol==="https:"?Ce(u.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=n+r.length}if(i<e.length)t.push(document.createTextNode(e.slice(i)));return t}var Se=/\[([^\]\n]+)\]\(([^)\s]+)\)/g;function oe(e){let t=[],i=0;for(let s of e.matchAll(Se)){let n=s.index??0;if(n>i)t.push(...w(e.slice(i,n)));let[r,a="",l=""]=s,c=null;try{c=new URL(l)}catch{}if(c&&(c.protocol==="http:"||c.protocol==="https:")){let h=document.createElement("a");h.href=c.href,h.target="_blank",h.rel="nofollow ugc noopener",h.append(...w(a)),t.push(h)}else t.push(document.createTextNode(r));i=n+r.length}if(i<e.length)t.push(...w(e.slice(i)));return t}function L(e,t){let i=document.createElement(e);return i.append(...oe(t.join(" "))),i}function O(e){let t=document.createDocumentFragment(),i=e.replace(/\r\n?/g,`
60
- `).split(`
61
- `),s=[],n=null,r=[],a=()=>{if(s.length)t.append(L("p",s));if(r.length){let l=document.createElement("blockquote");l.append(O(r.join(`
62
- `))),t.append(l)}s=[],r=[],n=null};for(let l=0;l<i.length;l++){let c=i[l]??"",h=/^\s*(```|~~~)/.exec(c);if(h){a();let p=[];while(++l<i.length&&!(i[l]??"").trimStart().startsWith(h[1]??"```"))p.push(i[l]??"");let m=document.createElement("pre");m.append(Object.assign(document.createElement("code"),{textContent:p.join(`
63
- `)})),t.append(m);continue}if(/^\s*$/.test(c)){a();continue}let d=/^\s*>\s?(.*)$/.exec(c);if(d){if(s.length||n)a();r.push(d[1]??"");continue}let u=/^\s*(#{1,6})\s+(.*)$/.exec(c);if(u){a(),t.append(L(`h${Math.min(6,(u[1]?.length??1)+2)}`,[u[2]??""]));continue}let g=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(c);if(g){let p=g[1]?"ul":"ol";if(s.length||r.length||n&&n.tagName.toLowerCase()!==p)a();if(!n)n=document.createElement(p),t.append(n);n.append(L("li",[g[3]??""]));continue}if(r.length)a();if(n&&/^\s{2,}/.test(c)){n.lastElementChild?.append(" ",...oe(c.trim()));continue}n=null,s.push(c.trim())}return a(),t}var de="#yuva-discussion-",Pe=60000,Te=1800000,C=new Map;function k(e){for(let t of C.keys())if(t.startsWith(e))C.delete(t)}var b=(e,t=16)=>`<svg width="${t}" height="${t}" 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:b('<path d="M12 19V5M5 12l7-7 7 7"/>'),comment:b('<path d="M21 12a8 8 0 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/>'),check:b('<path d="M20 6L9 17l-5-5"/>'),checkCircle:b('<circle cx="12" cy="12" r="9"/><path d="M8 12l3 3 5-6"/>'),lock:b('<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/>'),clock:b('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>'),back:b('<path d="M19 12H5M12 19l-7-7 7-7"/>'),bell:b('<path d="M18 8a6 6 0 10-12 0c0 7-3 9-3 9h18s-3-2-3-9M13.7 21a2 2 0 01-3.4 0"/>')},_e=`
59
+ `;class C extends fe{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")||(T?new URL(T).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#h("server",e)}get locale(){return H(this.getAttribute("locale"),navigator.language)}set locale(e){this.#h("locale",e)}get page(){return this.pageUrl||P(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??=ee(()=>this.#l()),this.pageUrl=P(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 N(this.#e,e,w)}client(){return this.#i??=j({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=ge+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",V(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=P(this.getAttribute("page"));if(e===this.pageUrl)return;this.pageUrl=e,this.reset(),this.render(),this.pageChanged()}#c(){let e=this.locale;this.#e=pe[e]??w,this.direction=this.getAttribute("dir")==="rtl"?"rtl":this.getAttribute("dir")==="ltr"?"ltr":F(e)}#p(){let e=this.channel,t=`${this.server} ${e}`;if(!e||this.#r===t)return;this.#r=t;let i=I(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=J(n);if(o.color)this.#d(o.color);if(Z(e,{...I(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 te="#yuva-discussion-",me=60000,x=new Map;function ye(e){for(let t of x.keys())if(t.startsWith(e))x.delete(t)}var S=(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:S('<path d="M12 19V5M5 12l7-7 7 7"/>'),comment:S('<path d="M21 12a8 8 0 01-11.6 7.1L4 20l1-4.6A8 8 0 1121 12z"/>'),check:S('<path d="M20 6L9 17l-5-5"/>'),lock:S('<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 018 0v4"/>'),clock:S('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')},ve=`
64
60
  .frame { display: flex; flex-direction: column; gap: 16px; }
65
61
  :host { --yuva-success: #1a7f37; --yuva-warn: #9a6700; }
66
62
  @media (prefers-color-scheme: dark) { :host { --yuva-success: #3fb950; --yuva-warn: #d29922; } }
@@ -115,69 +111,16 @@ button { font: inherit; color: inherit; }
115
111
  .badge.locked { opacity: 0.75; }
116
112
  .empty { padding: 28px 16px; text-align: center; border: 1px dashed var(--yuva-border); border-radius: 12px; }
117
113
  .empty p + p { margin-block-start: 4px; }
118
- .thread { display: flex; flex-direction: column; gap: 12px; }
119
- .thread-head { display: flex; flex-direction: column; gap: 8px; }
120
- .post { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--yuva-border); border-radius: 12px; }
121
- .post.accepted { border-color: var(--yuva-success); box-shadow: inset 0 0 0 1px var(--yuva-success); }
122
- .post.pending { border-style: dashed; }
123
- .side { display: flex; flex-direction: column; align-items: center; gap: 6px; }
124
- .vote {
125
- display: inline-flex; flex-direction: column; align-items: center; gap: 0; min-inline-size: 40px; padding: 4px 6px;
126
- border: 1px solid var(--yuva-border); border-radius: 8px; background: none; cursor: pointer; font-size: 0.85em; font-weight: 600;
127
- }
128
- .vote:hover:not(:disabled) { border-color: var(--yuva-accent); }
129
- .vote[aria-pressed="true"] { border-color: var(--yuva-accent); color: var(--yuva-accent); background: var(--yuva-soft); }
130
- .post-body { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 8px; }
131
- .post-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.88em; }
132
- .name { font-weight: 600; }
133
- .answer-label { display: flex; align-items: center; gap: 6px; color: var(--yuva-success); font-weight: 600; font-size: 0.85em; }
134
- .tools { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
135
- .children { display: flex; flex-direction: column; gap: 10px; margin-block-start: 4px; padding-inline-start: 14px; border-inline-start: 2px solid var(--yuva-border); }
136
- .children .post { padding: 10px 0; border: 0; box-shadow: none; }
137
- .children .post + .post { border-block-start: 1px solid var(--yuva-border); border-radius: 0; }
138
- .deleted { font-style: italic; opacity: 0.65; }
139
114
  .notice { padding: 10px 12px; border-radius: 10px; background: var(--yuva-soft); font-size: 0.9em; display: flex; gap: 8px; align-items: flex-start; }
140
115
  .notice svg { flex-shrink: 0; margin-block-start: 3px; }
141
- .signin { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 14px; border: 1px solid var(--yuva-border); border-radius: 12px; }
142
- .composer { display: flex; flex-direction: column; border: 1px solid var(--yuva-border); border-radius: 12px; overflow: hidden; }
143
- .composer:focus-within { border-color: var(--yuva-accent); }
144
- .composer .ctabs { display: flex; gap: 4px; padding: 0 8px; border-block-end: 1px solid var(--yuva-border); }
145
- .composer .ctab { padding: 7px 10px; border: 0; border-block-end: 2px solid transparent; background: none; cursor: pointer; font-size: 0.88em; opacity: 0.75; margin-block-end: -1px; }
146
- .composer .ctab[aria-selected="true"] { border-block-end-color: var(--yuva-accent); font-weight: 600; opacity: 1; }
147
- .composer .ctab:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: -2px; }
148
- .composer textarea, .composer .preview { border: 0; border-radius: 0; min-block-size: 110px; padding: 10px 12px; }
149
- .composer textarea:focus-visible { outline: none; }
150
- .composer .preview { overflow-wrap: anywhere; }
151
- .composer .foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border-block-start: 1px solid var(--yuva-border); }
152
- .composer .hint { font-size: 0.8em; opacity: 0.7; }
153
- .composer .buttons { display: flex; gap: 8px; margin-inline-start: auto; }
154
- .field-title { font-size: 1.05em; font-weight: 600; }
155
- .form { display: flex; flex-direction: column; gap: 10px; }
156
116
  .more { align-self: center; }
157
- .md { overflow-wrap: anywhere; }
158
- .md > :first-child { margin-block-start: 0; }
159
- .md > :last-child { margin-block-end: 0; }
160
- .md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 0.75em; }
161
- .md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 0.9em 0 0.4em; font-size: 1em; font-weight: 600; }
162
- .md h1, .md h3 { font-size: 1.1em; }
163
- .md ul, .md ol { padding-inline-start: 1.5em; }
164
- .md a { color: var(--yuva-accent); }
165
- .md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; padding: 1px 5px; border-radius: 5px; background: var(--yuva-soft); }
166
- .md pre { padding: 10px 12px; border-radius: 8px; background: var(--yuva-soft); overflow-x: auto; }
167
- .md pre code { padding: 0; background: none; }
168
- .md blockquote { padding-inline-start: 12px; border-inline-start: 3px solid var(--yuva-border); opacity: 0.85; }
169
- .md table { border-collapse: collapse; display: block; overflow-x: auto; }
170
- .md th, .md td { border: 1px solid var(--yuva-border); padding: 4px 8px; }
171
- .md img { max-inline-size: 100%; }
172
- .md hr { border: 0; border-block-start: 1px solid var(--yuva-border); }
173
117
  .skeleton { block-size: 64px; border-radius: 12px; background: var(--yuva-soft); }
174
118
  @media (max-width: 560px) {
175
119
  .item { gap: 10px; padding: 12px; }
176
120
  .item .avatar { display: none; }
177
- .post { padding: 12px; gap: 10px; }
178
121
  .bar .send { inline-size: 100%; }
179
122
  }
180
- `;function Re(e){let t=0;for(let i of e)t=t*31+i.charCodeAt(0)|0;return Math.abs(t)%360}function Ee(e){let t=document.createElement("template");return t.innerHTML=e,(t.content.textContent??"").replace(/\s+/g," ").trim().slice(0,240)}class T{area=o("textarea");previewing=!1;constructor(e){this.area.rows=e,this.area.maxLength=20000,this.area.dir="auto"}get value(){return this.area.value.trim()}clear(){this.area.value="",this.previewing=!1}}class U extends P{#t={kind:"list"};#s="new";#i=[];#n;#r="loading";#o="";#e=null;#g="loading";#f=null;#c=null;#p=null;#d=new Set;#l="";#x="";#w="";#v=new T(4);#y=null;#m=null;#b=new T(6);#a=o("input");#h="";constructor(){super();this.#a.maxLength=200,this.#a.dir="auto",this.#a.className="field-title";for(let e of[this.#v.area,this.#b.area])e.addEventListener("input",()=>this.#_());this.#a.addEventListener("input",()=>this.#_())}get discussions(){return this.#i}get reader(){return this.#c}#R=()=>this.#N();connectedCallback(){super.connectedCallback(),window.addEventListener("hashchange",this.#R),this.#E()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("hashchange",this.#R),this.#p?.(),this.#p=null}attributeChangedCallback(e,t,i){if(super.attributeChangedCallback(e,t,i),t===i||!this.isConnected)return;if(e==="channel"||e==="server")this.#p?.(),this.#p=null,this.#E();else if(e==="identity-token")this.#D(!0)}setIdentityToken(e){super.setIdentityToken(e),this.#D(!0)}#E(){if(!this.channel||this.#p)return;let e=this.client();this.#c=e.reader,this.#p=e.on("reader",(t)=>{this.#c=t,this.emit("yuva-reader",t?t.reader:null),this.#D(!0)}),this.#D(!1)}async#D(e){if(!this.channel)return;let t=await this.client().discussionWriter().catch(()=>null),i=t!==this.#f;if(this.#f=t,e&&i){if(this.#o="",this.#P(!1),this.#t.kind==="thread")this.#k(this.#t.id,!1)}this.render()}reset(){this.#t={kind:"list"},this.#i=[],this.#n=void 0,this.#r="loading",this.#o="",this.#e=null,this.#l="",this.#x="",this.#w="",this.#y=null,this.#m=null,this.#v.clear()}pageChanged(){this.#P(!1),this.#N()}#K(){let e=location.hash;return e.startsWith(de)?decodeURIComponent(e.slice(de.length)):""}#N(){let e=this.#K();if(!e||!this.channel||this.refused)return;if(this.#t.kind==="thread"&&this.#t.id===e)return;this.#y=null,this.#m=null,this.#w="",this.#k(e,!0),this.scrollIntoView({block:"start"})}reload(){return this.#P(!0)}open(e){return this.#k(e,!0)}signIn(){return this.#x="",this.client().readerSignIn().then(()=>{return}).catch((e)=>{let t=e instanceof f?e.code:"";if(t==="sign_in_cancelled")return;this.#x=t==="popup_blocked"?this.t({id:"nW3go1"}):this.#I(e),this.render()})}signOut(){return this.client().readerSignOut()}get#S(){return`${this.server} ${this.channel} ${this.pageUrl} `}async#P(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.#f??"-",r=`${this.#S}${this.#s} ${n}`;if(!e&&!t&&this.#o===r)return;this.#o=r;let a;if(t)a=this.client().listDiscussions(i,{sort:this.#s,cursor:this.#n});else{let l=C.get(r);if(e||!l||Date.now()-l.at>Pe){l={at:Date.now(),request:this.client().listDiscussions(i,{sort:this.#s})},C.set(r,l);let c=l;l.request.catch(()=>C.get(r)===c&&C.delete(r))}if(a=l.request,!this.#i.length)this.#r="loading"}if(t)this.#d.add("more");this.render();try{let l=await a;if(this.#o!==r)return;this.#i=t?[...this.#i,...l.items.filter((c)=>!this.#i.some((h)=>h.id===c.id))]:l.items,this.#n=l.next_cursor,this.#r="ready"}catch(l){if(this.#o!==r||this.refusal(l))return;if(!t)this.#o="";if(this.#r=l instanceof f&&l.code==="discussions_off"?"off":t?"ready":"error",t)this.#x=this.#I(l)}finally{this.#d.delete("more")}this.render()}async#k(e,t){let i=this.pageUrl,s=this.#e?.discussion.id===e?this.#e:null;this.#t={kind:"thread",id:e};let n=this.#i.find((r)=>r.id===e);if(this.#e=s??(n?{discussion:n,posts:[]}:null),this.#g=s?"ready":"loading",t)this.#l=s?this.#l:"",this.#x="",this.#h="thread-title";this.render();try{let r=await this.client().getDiscussion(e);if(this.pageUrl!==i||this.#t.kind!=="thread"||this.#t.id!==e)return;let a=!!this.#e;if(this.#e=r,this.#g="ready",t&&!a)this.#h="thread-title";this.#i=this.#i.map((l)=>l.id===e?r.discussion:l)}catch(r){if(this.pageUrl!==i||this.#t.kind!=="thread"||this.#t.id!==e)return;if(this.refusal(r,!1))return;this.#g=r instanceof f&&r.status===404?"missing":"error"}this.render()}#A(){if(this.#K()){let e=new URL(location.href);e.hash="",history.replaceState(history.state,"",e.href)}this.#t={kind:"list"},this.#y=null,this.#m=null,this.#w="",this.#x="",this.#h=this.#e?`open-${this.#e.discussion.id}`:"start",this.render(),this.#P(!1)}#I(e){let t=e instanceof f?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#T(e,t){if(this.#d.has(e))return;this.#d.add(e),this.#x="",this.render();try{return await t()}catch(i){if(!this.refusal(i,!1))this.#x=this.#I(i);if(i instanceof f&&i.code==="sign_in_required")this.#D(!1);return}finally{this.#d.delete(e),this.render()}}async#Q(){let e=this.#a.value.trim(),t=this.#b.value;if(e.length<3||!t)return;let i=this.pageUrl,s=await this.#T("start",()=>this.client().startDiscussion({page_url:i,page_title:this.pageTitle||void 0,title:e,body:t}));if(!s)return;if(k(this.#S),this.emit("yuva-discussion",{page:i,discussion_id:s.id,state:s.state}),this.pageUrl!==i)return;this.#a.value="",this.#b.clear(),this.#i=[s,...this.#i.filter((n)=>n.id!==s.id)],this.#l=s.state==="pending"?this.t({id:"NrGspR"}):"",this.#e={discussion:s,posts:[]},await this.#k(s.id,!0)}async#j(e,t){let i=this.#e,s=e.value;if(!i||!s)return;let n=this.pageUrl,r=i.discussion.id,a=await this.#T(t?`reply-${t}`:"reply",()=>this.client().replyToDiscussion(r,{body:s,parent_post_id:t}));if(!a)return;if(k(this.#S),this.emit("yuva-post",{page:n,discussion_id:r,post_id:a.id,state:a.state}),e.clear(),t)this.#y=null;if(this.#l=a.state==="pending"?this.t({id:"YZayoP"}):"",this.#e?.discussion.id===r)this.#e={...this.#e,posts:[...this.#e.posts,a]},this.#h=`post-${a.id}`,this.render(),this.#k(r,!1)}async#Z(e,t){if(!this.#f)return void this.signIn();let i=await this.#T(`vote-${e.id}`,()=>this.client().voteDiscussionPost(e.id,!e.voted));if(!i||!this.#e)return;if(k(this.#S),t){let s={...this.#e.discussion,votes:i.votes,voted:i.voted};this.#e={...this.#e,discussion:s},this.#i=this.#i.map((n)=>n.id===s.id?s:n)}else this.#e={...this.#e,posts:this.#e.posts.map((s)=>s.id===i.id?{...s,...i}:s)}}async#X(){let e=this.#e;if(!e)return;if(!this.#f)return void this.signIn();let t=!e.discussion.following;if(await this.#T("follow",()=>this.client().followDiscussion(e.discussion.id,t).then(()=>!0))&&this.#e?.discussion.id===e.discussion.id)this.#e={...this.#e,discussion:{...this.#e.discussion,following:t}}}async#ee(e){let t=this.#e;if(!t)return;let i=await this.#T(`accept-${e?.id??"clear"}`,()=>this.client().acceptDiscussionAnswer(t.discussion.id,e?.id??null));if(!i)return;k(this.#S),this.#h=e?`post-${e.id}`:"thread-title",await this.#k(i.id,!1)}async#te(){let e=this.#m,t=this.#e;if(!e||!t)return;let i=e.composer.value,s=!e.post,n=e.title.value.trim();if(!i||s&&n.length<3)return;let r=e.post?.id??t.discussion.opening_post_id;if(!await this.#T(`edit-${r}`,()=>this.client().editDiscussionPost(r,s?{body:i,title:n}:{body:i})))return;k(this.#S),this.#m=null,this.#h=s?"thread-title":`post-${r}`,await this.#k(t.discussion.id,!1)}async#ie(e,t){let i=this.#e;if(!i)return;let s=await this.#T(`delete-${e}`,()=>this.client().deleteDiscussionPost(e).then(()=>!0));if(this.#w="",!s)return;if(k(this.#S),t)try{await this.client().getDiscussion(i.discussion.id)}catch{return this.#i=this.#i.filter((n)=>n.id!==i.discussion.id),this.#e=null,this.#A()}await this.#k(i.discussion.id,!1)}#_(){for(let e of this.root.querySelectorAll("[data-requires]")){let t=e.dataset.requires,i=this.#d.has(e.dataset.busy??""),s=t==="start"?this.#a.value.trim().length>=3&&this.#b.value!=="":t==="reply"?this.#v.value!=="":t==="inline"?!!this.#y?.composer.value:t==="edit"?!!this.#m?.composer.value&&(!!this.#m.post||this.#m.title.value.trim().length>=3):!0;e.disabled=i||!s}}get#z(){return this.inbox?.chat.discussions??"moderated"}#u(e,t,i,s,n=""){let r=o("button",e);if(r.type="button",n)r.innerHTML=n;return r.append(t),r.dataset.key=i,r.addEventListener("click",s),r}#$(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"}))}#L(e,t=!1){let i=o("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(${Re(e.name||e.initials)} 45% 42%)`);return i}#C(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=o("span",`badge ${e}`);if(e!=="team")s.innerHTML=e==="answered"?v.check:e==="pending"?v.clock:v.lock;return s.append(i),s}#Y(e){let t=o("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]],r=s;for(let[a,l]of n){if(Math.abs(r)<l){t.textContent=a==="second"?this.t({id:"xOTzt5"}):new Intl.RelativeTimeFormat(this.locale,{numeric:"auto"}).format(Math.round(r),a);break}r/=l}return t}#W(e){let t=o("div","md");t.dir="auto",t.innerHTML=e;for(let i of t.querySelectorAll("a[href]"))i.setAttribute("target","_blank");return t}#M(e,t){let i=o("div","composer"),s=o("div","ctabs");s.setAttribute("role","tablist"),s.setAttribute("aria-label",t.label);let n=`p-${t.focusKey}`,r=this.#u("ctab",this.t({id:"i4_LY_"}),`${t.focusKey}-write`,()=>{e.previewing=!1,this.#h=t.focusKey,this.render()}),a=this.#u("ctab",this.t({id:"rdUucN"}),`${t.focusKey}-preview`,()=>{e.previewing=!0,this.render()});for(let[d,u]of[[r,!e.previewing],[a,e.previewing]])d.setAttribute("role","tab"),d.setAttribute("aria-selected",String(u)),d.setAttribute("aria-controls",n),d.tabIndex=u?0:-1,d.addEventListener("keydown",(g)=>{if(g.key!=="ArrowLeft"&&g.key!=="ArrowRight")return;g.preventDefault(),e.previewing=!e.previewing,this.#h=`${t.focusKey}-${e.previewing?"preview":"write"}`,this.render()});if(s.append(r,a),i.append(s),e.previewing){let d=o("div","preview md");if(d.dir="auto",d.id=n,d.setAttribute("role","tabpanel"),d.setAttribute("aria-label",this.t({id:"rdUucN"})),e.value)d.append(O(e.area.value));else d.append(o("p","muted",this.t({id:"3PqJQG"})));i.append(d)}else e.area.id=n,e.area.placeholder=t.placeholder,e.area.setAttribute("aria-label",t.label),e.area.dataset.key=t.focusKey,e.area.disabled=this.#d.has(t.busy),e.area.onkeydown=(d)=>{if(d.key==="Enter"&&(d.metaKey||d.ctrlKey))d.preventDefault(),t.onSubmit();else if(d.key==="Escape"&&t.onCancel)t.onCancel()},i.append(e.area);let l=o("div","foot");l.append(o("span","hint",this.t({id:"Vwy_nT"})));let c=o("div","buttons");if(t.onCancel)c.append(this.#u("ghost",this.t({id:"dEgA5A"}),`${t.focusKey}-cancel`,t.onCancel));let h=this.#u("send",this.#d.has(t.busy)?this.t({id:"Sad2tK"}):t.submit,`${t.focusKey}-submit`,t.onSubmit);return h.dataset.requires=t.requires,h.dataset.busy=t.busy,c.append(h),l.append(c),i.append(l),i}#H(e){let t=o("div","signin");return t.append(o("p","",e)),t.append(this.#u("send",this.t({id:"5lWFkC"}),"sign-in-box",()=>void this.signIn())),t}#se(){let e=o("div","head");e.append(o("h2","",this.t({id:"7oGBMv"})));let t=o("div","who"),i=this.#c;if(i){let s=i.reader.name||this.t({id:"zmA6sS"});t.append(this.#L({kind:"reader",name:s,initials:i.reader.initials,deleted:!1},!0)),t.append(o("span","",s)),t.append(this.#u("plain",this.t({id:"fcWrnU"}),"sign-out",()=>void this.signOut()))}else if(!this.#f&&this.#z!=="off")t.append(this.#u("ghost",this.t({id:"5lWFkC"}),"sign-in",()=>void this.signIn()));return e.append(t),e}#ne(){let e=[],t=o("div","bar"),i=o("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(([a,l],c)=>{let h=this.#u("tab",l,`sort-${a}`,()=>this.#B(a));h.setAttribute("role","tab"),h.setAttribute("aria-selected",String(this.#s===a)),h.setAttribute("aria-controls","yuva-discussion-list"),h.tabIndex=this.#s===a?0:-1,h.addEventListener("keydown",(d)=>{let u=d.key==="ArrowRight"?1:d.key==="ArrowLeft"?-1:0;if(!u)return;d.preventDefault();let g=this.direction==="rtl"?-u:u,p=s[(c+g+s.length)%s.length];if(p)this.#B(p[0])}),i.append(h)});let n=this.#u("send",this.t({id:"z1qf6l"}),"start",()=>{this.#t={kind:"new"},this.#x="",this.#l="",this.#h="new-title",this.render()});if(t.append(i,n),e.push(t),this.#r==="loading"&&!this.#i.length){let a=o("div","skeleton");return a.setAttribute("aria-busy","true"),a.setAttribute("aria-label",this.t({id:"pzatAP"})),e.push(a),e}if(this.#r==="error"&&!this.#i.length){let a=o("div","empty");a.append(o("p","",this.t({id:"MDmQKn"})));let l=this.#u("ghost",this.t({id:"KDw4GX"}),"retry",()=>void this.#P(!0));return l.style.marginBlockStart="8px",a.append(l),e.push(a),e}if(!this.#i.length){let a=o("div","empty");if(a.append(o("p","",this.#s==="unanswered"?this.t({id:"twEQ41"}):this.t({id:"rpfOwz"}))),this.#s!=="unanswered")a.append(o("p","muted",this.t({id:"b6Orhy"})));return e.push(a),e}let r=o("ul","list");r.id="yuva-discussion-list",r.setAttribute("aria-label",this.t({id:"j-3eim"})),r.setAttribute("aria-busy",String(this.#r==="loading"));for(let a of this.#i){let l=o("li","item");l.append(this.#L(a.author));let c=o("div","main"),h=this.#u("title",a.title,`open-${a.id}`,()=>void this.#k(a.id,!0));h.dir="auto",c.append(h);let d=a.deleted?"":Ee(a.body_html);if(d){let y=o("p","excerpt",d);y.dir="auto",c.append(y)}let u=o("div","meta");if(u.append(o("span","",this.#$(a.author)),this.#Y(a.created_at)),a.author.kind==="member"&&!a.author.deleted)u.append(this.#C("team"));if(a.answer_post_id)u.append(this.#C("answered"));if(a.state==="pending")u.append(this.#C("pending"));if(a.locked)u.append(this.#C("locked"));c.append(u);let g=o("div","counts"),p=o("span","count");p.innerHTML=v.up,p.append(String(a.votes)),p.setAttribute("aria-label",this.t({id:"8ntmc1",values:{0:a.votes}})),p.title=p.getAttribute("aria-label")??"";let m=o("span","count");m.innerHTML=v.comment,m.append(String(a.reply_count)),m.setAttribute("aria-label",this.t({id:"Hw3P48",values:{0:a.reply_count}})),m.title=m.getAttribute("aria-label")??"",g.append(p,m),l.append(c,g),r.append(l)}if(e.push(r),this.#n){let a=this.#u("ghost more",this.#d.has("more")?this.t({id:"Pwqkdw"}):this.t({id:"fMPkxb"}),"more",()=>void this.#P(!1,!0));a.disabled=this.#d.has("more"),e.push(a)}return e}#B(e){if(this.#s===e)return;this.#s=e,this.#i=[],this.#n=void 0,this.#r="loading",this.#h=`sort-${e}`,this.#P(!1)}#O(){let e=this.#u("plain",this.t({id:"3CApMv"}),"back",()=>this.#A(),v.back);e.style.alignSelf="flex-start",e.style.display="inline-flex",e.style.gap="6px",e.style.alignItems="center";let t=e.querySelector("svg");if(t&&this.direction==="rtl")t.style.transform="scaleX(-1)";return e}#re(){let e=o("div","form");if(e.append(o("h3","",this.t({id:"z1qf6l"}))),!this.#f)return e.append(this.#H(this.t({id:"99w-GZ"}))),[this.#O(),e];if(this.#a.placeholder=this.t({id:"MHrjPM"}),this.#a.setAttribute("aria-label",this.t({id:"MHrjPM"})),this.#a.dataset.key="new-title",this.#a.disabled=this.#d.has("start"),e.append(this.#a),e.append(this.#M(this.#b,{label:this.t({id:"PN38hZ"}),placeholder:this.t({id:"NjUiZ4"}),submit:this.t({id:"n5vqdp"}),busy:"start",requires:"start",focusKey:"new-body",onSubmit:()=>void this.#Q(),onCancel:()=>this.#A()})),this.#z==="moderated"&&this.#c)e.append(o("p","muted",this.t({id:"RqsQKK"})));return[this.#O(),e]}#ae(e){return!!e.mine&&!this.#e?.discussion.locked&&Date.now()-Date.parse(e.created_at)<Te}#G(e,t){let i=this.#e;if(!i)return null;let s=i.discussion,n=!e,r=e?.id??s.opening_post_id,a=n?!!s.mine:!!e.mine,l=n?!!s.deleted:e.deleted,c=o("div","tools");if(l)return null;if(!n&&t&&!s.locked&&this.#f&&e.state==="published")c.append(this.#u("plain",this.t({id:"ImOQa9"}),`reply-to-${e.id}`,()=>{this.#y=this.#y?.target===t.id?this.#y:{target:t.id,composer:new T(3)},this.#y.composer.area.oninput=()=>this.#_(),this.#h=`inline-${t.id}`,this.render()}));if(!n&&s.mine&&!e.parent_post_id&&e.state==="published"&&!s.locked){let h=s.answer_post_id===e.id,d=this.#u("plain",h?this.t({id:"4-S4QM"}):this.t({id:"jhu92n"}),`accept-${e.id}`,()=>void this.#ee(h?null:e),h?"":v.checkCircle);d.style.display="inline-flex",d.style.gap="4px",d.style.alignItems="center",d.disabled=this.#d.has(`accept-${e.id}`)||this.#d.has("accept-clear"),c.append(d)}if(a&&this.#ae(n?s:e))c.append(this.#u("plain",this.t({id:"ePK91l"}),`edit-${r}`,()=>{let h=new T(n?6:4);h.area.value=n?s.body:e.body,h.area.oninput=()=>this.#_();let d=o("input");d.className="field-title",d.maxLength=200,d.dir="auto",d.value=s.title,d.oninput=()=>this.#_(),this.#m={post:e,composer:h,title:d},this.#h=n?"edit-title":`edit-body-${r}`,this.render()}));if(a)if(this.#w===r){let h=this.#u("plain danger",this.t({id:"cnGeoo"}),`delete-yes-${r}`,()=>void this.#ie(r,n));h.disabled=this.#d.has(`delete-${r}`),c.append(o("span","muted",n?this.t({id:"rAl91-"}):this.t({id:"Klsidc"})),h,this.#u("plain",this.t({id:"PZ_kxo"}),`delete-no-${r}`,()=>{this.#w="",this.#h=`delete-${r}`,this.render()}))}else c.append(this.#u("plain",this.t({id:"cnGeoo"}),`delete-${r}`,()=>{this.#w=r,this.#h=`delete-no-${r}`,this.render()}));return c.childElementCount?c:null}#F(e,t){let i=this.#u("vote",String(e.votes),`vote-${e.id}`,()=>void this.#Z(e,t),v.up);return i.setAttribute("aria-pressed",String(!!e.voted)),i.setAttribute("aria-label",e.voted?this.t({id:"OVijcR",values:{0:e.votes}}):this.t({id:"dNOvhg",values:{0:e.votes}})),i.disabled=!!e.mine||!!this.#e?.discussion.locked||this.#d.has(`vote-${e.id}`),i}#V(e,t,i=[]){let n=this.#e.discussion.answer_post_id===e.id,r=o("article",`post${n?" accepted":""}${e.state==="pending"?" pending":""}`);r.dataset.key=`post-${e.id}`,r.tabIndex=-1,r.setAttribute("aria-label",this.#$(e.author));let a=o("div","side");if(!e.deleted)a.append(this.#F(e,!1));if(!t||t.id===e.id)r.append(a);let l=o("div","post-body");if(n){let h=o("div","answer-label");h.innerHTML=v.checkCircle,h.append(this.t({id:"y-KXxN"})),l.append(h)}if(l.append(this.#U(e.author,e.created_at,e.edited_at,e.state,e.deleted)),this.#m?.post?.id===e.id)l.append(this.#J());else if(e.deleted)l.append(o("p","deleted",this.t({id:"HkXOWm"})));else l.append(this.#W(e.body_html));let c=this.#G(e,t);if(c)l.append(c);if(i.length||this.#y?.target===e.id){let h=o("div","children");for(let d of i)h.append(this.#V(d,e));if(this.#y?.target===e.id){let d=this.#y;h.append(this.#M(d.composer,{label:this.t({id:"F_vGso"}),placeholder:this.t({id:"2Hlmdt"}),submit:this.t({id:"ImOQa9"}),busy:`reply-${e.id}`,requires:"inline",focusKey:`inline-${e.id}`,onSubmit:()=>void this.#j(d.composer,e.id),onCancel:()=>{this.#y=null,this.#h=`reply-to-${e.id}`,this.render()}}))}l.append(h)}return r.append(l),r}#U(e,t,i,s,n){let r=o("div","post-head");if(!n){if(r.append(this.#L(e,!0),o("span","name",this.#$(e))),e.kind==="member"&&!e.deleted)r.append(this.#C("team"))}if(r.append(this.#Y(t)),i&&!n)r.append(o("span","muted",this.t({id:"k4b5_X"})));if(s==="pending")r.append(this.#C("pending"));return r}#J(){let e=this.#m,t=o("div","form");if(!e.post)e.title.setAttribute("aria-label",this.t({id:"MHrjPM"})),e.title.dataset.key="edit-title",t.append(e.title);let i=e.post?.id??this.#e.discussion.opening_post_id;return t.append(this.#M(e.composer,{label:this.t({id:"qzVesX"}),placeholder:"",submit:this.t({id:"tfDRzk"}),busy:`edit-${i}`,requires:"edit",focusKey:`edit-body-${i}`,onSubmit:()=>void this.#te(),onCancel:()=>{this.#m=null,this.#h=`edit-${i}`,this.render()}})),t}#oe(){let e=[this.#O()],t=this.#e;if(!t||this.#g==="missing"){let d=o("div","empty");return d.append(o("p","",this.#g==="loading"?this.t({id:"Pwqkdw"}):this.t({id:"VGqKyv"}))),e.push(d),e}let i=t.discussion,s=o("div","thread"),n=o("div","thread-head");if(this.#m&&!this.#m.post)n.append(this.#U(i.author,i.created_at,i.edited_at,i.state,!1)),n.append(this.#J()),s.append(n);else{let d=o("h3","",i.title);d.dir="auto",d.tabIndex=-1,d.dataset.key="thread-title",n.append(d);let u=o("div","meta");if(i.answer_post_id)u.append(this.#C("answered"));if(i.state==="pending")u.append(this.#C("pending"));if(i.locked)u.append(this.#C("locked"));if(u.childElementCount)n.append(u);s.append(n);let g=o("article",`post${i.state==="pending"?" pending":""}`),p=o("div","side");if(!i.deleted)p.append(this.#F({id:i.opening_post_id,votes:i.votes,voted:i.voted,mine:i.mine},!0));let m=o("div","post-body");m.append(this.#U(i.author,i.created_at,i.edited_at,i.state,!!i.deleted)),m.append(i.deleted?o("p","deleted",this.t({id:"8wRl7c"})):this.#W(i.body_html));let y=this.#G(null,null);if(y)m.append(y);g.append(p,m),s.append(g)}let r=o("div","bar"),a=this.#u("ghost",i.following?this.t({id:"y6sq5j"}):this.t({id:"MKEPCY"}),"follow",()=>void this.#X(),v.bell);a.setAttribute("aria-pressed",String(!!i.following)),a.title=this.t({id:"Kl3TuI"}),a.disabled=this.#d.has("follow");let l=o("span","muted",this.t({id:"Hw3P48",values:{0:i.reply_count}}));if(r.append(l,a),s.append(r),this.#g==="loading"&&!t.posts.length&&i.reply_count>0){let d=o("div","skeleton");d.setAttribute("aria-busy","true"),d.setAttribute("aria-label",this.t({id:"Pwqkdw"})),s.append(d)}let c=t.posts.filter((d)=>!d.parent_post_id),h=o("div","thread");for(let d of c)h.append(this.#V(d,d,t.posts.filter((u)=>u.parent_post_id===d.id)));if(c.length)s.append(h);if(this.#l)s.append(this.#q(this.#l));if(i.locked)s.append(this.#q(this.t({id:"JfAIiv"}),v.lock));else if(!this.#f)s.append(this.#H(this.t({id:"PL0621"})));else s.append(this.#M(this.#v,{label:this.t({id:"F_vGso"}),placeholder:this.t({id:"2Hlmdt"}),submit:this.t({id:"ImOQa9"}),busy:"reply",requires:"reply",focusKey:"reply",onSubmit:()=>void this.#j(this.#v)}));return e.push(s),e}#q(e,t=v.clock){let i=o("div","notice");return i.setAttribute("role","status"),i.innerHTML=t,i.append(o("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.#se()];if(this.#z==="off"||this.#r==="off")t.push(o("p","muted",this.t({id:"tayT8P"})));else if(this.#t.kind==="thread")t.push(...this.#oe());else if(this.#t.kind==="new")t.push(...this.#re());else{if(this.#l)t.push(this.#q(this.#l));t.push(...this.#ne())}if(this.#x){let a=o("p","error",this.#x);a.setAttribute("role","alert"),t.push(a)}this.frame(_e,...t),this.#_();let i=this.#h;this.#h="";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((a)=>a.dataset.key===s)?.focus({preventScroll:!i})}}var De=500,Me=(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>`,Ae=`
123
+ `;function be(e){let t=0;for(let i of e)t=t*31+i.charCodeAt(0)|0;return Math.abs(t)%360}function xe(e){let t=document.createElement("template");return t.innerHTML=e,(t.content.textContent??"").replace(/\s+/g," ").trim().slice(0,240)}class k extends C{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(te)?decodeURIComponent(e.slice(te.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.#C();#C(){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.#S(),forget:()=>ye(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.#R(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>me){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()}#S(){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}#R(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(${be(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}#_(){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}#A(){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.#D(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.#D(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?"":xe(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.#R(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}#D(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.#_()];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.#A())}if(this.#e.error){let r=a("p","error",this.#e.error);r.setAttribute("role","alert"),t.push(r)}if(this.frame(ve+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 ke=500,we=(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>`,Ce=`
181
124
  .frame { display: flex; flex-direction: column; gap: 12px; }
182
125
  .ask { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
183
126
  .question { font-weight: 600; }
@@ -198,4 +141,4 @@ button { font: inherit; color: inherit; }
198
141
  .choice[aria-pressed="true"] { background: var(--yuva-soft); }
199
142
  .choice:disabled { cursor: default; }
200
143
  .choice:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: 2px; }
201
- `;function le(e){return`yuva:${e}:page-ratings`}function R(e){try{let t=localStorage.getItem(le(e));return t?JSON.parse(t):{}}catch{return{}}}function Ie(e,t,i){try{let s=R(e);delete s[t],s[t]=i;let n=Object.keys(s);for(let r of n.slice(0,Math.max(0,n.length-De)))delete s[r];localStorage.setItem(le(e),JSON.stringify(s))}catch{}}class q extends P{#t="ask";#s;#i="";#n=o("textarea");#r=o("input");constructor(){super();this.#n.rows=3,this.#n.maxLength=5000,this.#n.dir="auto",this.#n.addEventListener("input",()=>this.#e()),this.#r.type="email",this.#r.autocomplete="email"}get rating(){return this.#s??null}reset(){this.#t="ask",this.#i="",this.#n.value="",this.#s=this.channel?R(this.channel)[this.pageUrl]:void 0}pageChanged(){if(this.#t==="ask"&&!this.#i)this.#s=this.channel?R(this.channel)[this.pageUrl]:void 0;this.render()}async rate(e){let t=this.channel;if(!t||this.refused||this.#t==="rating"||this.#t==="sending")return;let i=this.pageUrl,s=R(t)[i];if(this.#i="",s===e){this.#s=e,this.#t=this.canWrite?"form":"thanks",this.render(),this.#n.focus({preventScroll:!0});return}this.#t="rating",this.#s=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.#s=s,this.#t="ask",this.#i=this.errorText(n),this.render();return}if(Ie(t,i,e),this.emit("yuva-rating",{page:i,rating:e,previous:s??null}),this.pageUrl!==i)return;this.#t=this.canWrite?"form":"thanks",this.render(),this.#n.focus({preventScroll:!0})}async#o(){let e=this.#n.value.trim(),t=this.#r.value.trim(),i=this.#s;if(!e||this.#t!=="form")return;if(t&&!this.#r.checkValidity()){this.#i=this.t({id:"E_qvzP"}),this.render();return}let s=this.pageUrl;this.#t="sending",this.#i="",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.#n.value="",this.#t="thanks"}catch(n){if(this.pageUrl!==s||this.refusal(n,!1))return;this.#t="form",this.#i=this.errorText(n)}this.render()}#e(){let e=this.root.querySelector(".send");if(e)e.disabled=this.#t!=="form"||this.#n.value.trim()===""}render(){if(this.refused||!this.channel){this.root.replaceChildren();return}let e=this.t({id:"SOvBw9"}),t=o("div","ask");t.setAttribute("role","group"),t.setAttribute("aria-label",e);let i=o("div","choices");for(let n of["up","down"]){let r=o("button","choice");r.type="button",r.innerHTML=Me(n==="down"),r.append(o("span","",n==="up"?this.t({id:"l75CjT"}):this.t({id:"1UzENP"}))),r.setAttribute("aria-pressed",String(this.#s===n)),r.disabled=this.#t==="rating"||this.#t==="sending",r.addEventListener("click",()=>void this.rate(n)),i.append(r)}t.append(o("p","question",e),i);let s=[t];if(this.#t==="form"||this.#t==="sending"){let n=o("form");n.noValidate=!0,n.addEventListener("submit",(h)=>{h.preventDefault(),this.#o()});let r=this.#s==="down"?this.t({id:"U7H5Fm"}):this.t({id:"EmiQvf"});if(this.#n.placeholder=r,this.#n.setAttribute("aria-label",r),this.#n.disabled=this.#t==="sending",n.append(this.#n),!this.identified)this.#r.placeholder=this.t({id:"a_qtPP"}),this.#r.setAttribute("aria-label",this.t({id:"XJURKP"})),this.#r.disabled=this.#t==="sending",n.append(this.#r);let a=o("button","link",this.t({id:"tA4dAO"}));a.type="button",a.disabled=this.#t==="sending",a.addEventListener("click",()=>{this.#t="thanks",this.#i="",this.render()});let l=o("button","send",this.#t==="sending"?this.t({id:"Sad2tK"}):this.t({id:"JlFcis"}));l.type="submit";let c=o("div","actions");c.append(a,l),n.append(c),s.push(n)}else if(this.#t==="thanks"){let n=o("p","muted",this.t({id:"d6N994"}));n.setAttribute("role","status"),s.push(n)}if(this.#i){let n=o("p","error",this.#i);n.setAttribute("role","alert"),s.push(n)}this.frame(Ae,...s),this.#e()}}function K(){if(typeof customElements>"u")return;if(!customElements.get("yuva-discussions"))customElements.define("yuva-discussions",U);if(!customElements.get("yuva-page-feedback"))customElements.define("yuva-page-feedback",q)}K();K();})();
144
+ `;function ie(e){return`yuva:${e}:page-ratings`}function R(e){try{let t=localStorage.getItem(ie(e));return t?JSON.parse(t):{}}catch{return{}}}function Se(e,t,i){try{let s=R(e);delete s[t],s[t]=i;let n=Object.keys(s);for(let o of n.slice(0,Math.max(0,n.length-ke)))delete s[o];localStorage.setItem(ie(e),JSON.stringify(s))}catch{}}class A extends C{#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?R(this.channel)[this.pageUrl]:void 0}pageChanged(){if(this.#e==="ask"&&!this.#n)this.#i=this.channel?R(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=R(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(Se(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=we(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(Ce,...s),this.#s()}}function se(){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",A)}k.loadThread=()=>import(new URL("widget/yuva-docs-thread-4580g2ny.js",T||location.href).href);se();})();
package/dist/yuva.js CHANGED
@@ -1,4 +1,4 @@
1
- (()=>{var o=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var p=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var c={en:o,tr:p},w=new Set(["ar","fa","he","ur"]),C="en";function f(...e){for(let t of e){if(!t)continue;let i=t.toLowerCase();if(c[i])return i;let n=i.split(/[-_]/)[0]??"";if(c[n])return n}return C}function g(e){return w.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}function y(e){return c[e]??o}function r(e,t,i=o){let n=e[t.id]??i[t.id],a=t.values??{};if(typeof n==="string")return n;if(Array.isArray(n))return n.map((s)=>typeof s==="string"?s:Array.isArray(s)?String(a[s[0]]??""):"").join("");return t.message??t.id}function m(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function b(e){let t=Number.parseInt(e.slice(1),16),[i,n,a]=[t>>16&255,t>>8&255,t&255].map((s)=>{let l=s/255;return l<=0.03928?l/12.92:((l+0.055)/1.055)**2.4});return 0.2126*i+0.7152*n+0.0722*a>0.4?"#111827":"#ffffff"}function v(e){return`yuva:${e}`}function h(e){try{let t=localStorage.getItem(v(e));return t?JSON.parse(t):{}}catch{return{}}}function x(e,t){try{localStorage.setItem(v(e),JSON.stringify(t))}catch{}}var S=`
1
+ (()=>{var o=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var p=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function g(e,t,i){let n=e[t.id]??i[t.id],a=t.values??{};if(typeof n==="string")return n;if(Array.isArray(n))return n.map((s)=>typeof s==="string"?s:Array.isArray(s)?String(a[s[0]]??""):"").join("");return t.message??t.id}var c={en:o,tr:p},C=new Set(["ar","fa","he","ur"]),S="en";function f(...e){for(let t of e){if(!t)continue;let i=t.toLowerCase();if(c[i])return i;let n=i.split(/[-_]/)[0]??"";if(c[n])return n}return S}function y(e){return C.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}function m(e){return c[e]??o}function r(e,t,i=o){return g(e,t,i)}function b(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function v(e){let t=Number.parseInt(e.slice(1),16),[i,n,a]=[t>>16&255,t>>8&255,t&255].map((s)=>{let l=s/255;return l<=0.03928?l/12.92:((l+0.055)/1.055)**2.4});return 0.2126*i+0.7152*n+0.0722*a>0.4?"#111827":"#ffffff"}function x(e){return`yuva:${e}`}function h(e){try{let t=localStorage.getItem(x(e));return t?JSON.parse(t):{}}catch{return{}}}function k(e,t){try{localStorage.setItem(x(e),JSON.stringify(t))}catch{}}var L=`
2
2
  :host {
3
3
  --yuva-accent: #2563eb;
4
4
  --yuva-on-accent: #ffffff;
@@ -106,4 +106,4 @@
106
106
  block-size: 100%;
107
107
  min-block-size: 320px;
108
108
  }
109
- `,L='<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H9l-5 4z"/></svg>',A='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',u=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class d extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",u||location.href).href);#r;#s=null;#n=null;#i;#e=null;#a={};#t=!1;#u=0;#l=null;#o=!1;constructor(){super();this.#r=this.attachShadow({mode:"open"}),this.#i=document.createElement("section"),this.#i.className="panel",this.#i.setAttribute("role","dialog"),this.#i.hidden=!0,this.#i.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&this.layout==="launcher")this.close()})}get layout(){return this.getAttribute("layout")==="embedded"?"embedded":"launcher"}get channel(){return this.getAttribute("channel")}get server(){return(this.getAttribute("server")||(u?new URL(u).origin:location.origin)).replace(/\/+$/,"")}get locale(){return f(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#t}get unread(){return this.#u}setIdentityToken(e){if(this.#l=e,this.#e)this.#e.then((t)=>t.identityChanged())}async signOut(){if(this.#l=null,this.removeAttribute("identity-token"),this.#e)await(await this.#e).signOut()}async rate(e,t,i){return(await this.#d()).rate(e,t,i)}connectedCallback(){this.#c();let e=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!e)return;let t=h(e);if(t.launcher)this.#p(t.launcher);let i=()=>{if(!this.isConnected||this.#e||this.channel!==e)return;if(t.session)this.#d();else this.#g(e)};if("requestIdleCallback"in window)requestIdleCallback(i,{timeout:3000});else setTimeout(i,1000)}#g(e){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(e)}`,{credentials:"omit"}).then((t)=>{if(t.status===403||t.status===404)this.#f();return t.ok?t.json():null}).then((t)=>{if(!t||this.channel!==e||this.#e)return;let i=m(t);this.#p(i),x(e,{...h(e),launcher:i})}).catch(()=>{return})}disconnectedCallback(){let e=this.#e;if(this.#e=null,e)e.then((t)=>t.destroy())}attributeChangedCallback(e,t,i){if(!this.isConnected||t===i)return;if(e==="open"){i===null?this.close():this.open();return}if(e==="identity-token"){if(this.#e)this.#e.then((n)=>n.identityChanged());return}if(e==="channel"||e==="server"){this.disconnectedCallback(),this.#o=!1,this.#c();return}if(this.#c(),this.#e)this.#e.then((n)=>n.update())}async open(){if(this.#t||this.#o)return;this.#t=!0,this.toggleAttribute("open-panel",!0),this.#h();let e=await this.#d();if(!this.#t)return;this.#i.hidden=!1,e.opened()}close(){if(!this.#t||this.layout==="embedded")return;if(this.#t=!1,this.toggleAttribute("open-panel",!1),this.#i.hidden=!0,this.#h(),this.#s?.focus(),this.#e)this.#e.then((e)=>e.closed())}toggle(){return this.#t?this.close():this.open()}#y(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#d(){return this.#e??=d.loadPanel().then(({mount:e})=>e({panel:this.#i,config:()=>this.#y(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#t,close:()=>this.close(),setUnread:(t)=>{this.#u=t,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:t}}))},setLauncher:(t)=>this.#p(t),refused:()=>this.#f()})),this.#e}#f(){if(this.#o)return;this.#o=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#t=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(e){if(this.setAttribute("position",e.position==="left"?"left":"right"),e.color&&/^#[0-9a-f]{6}$/i.test(e.color))this.style.setProperty("--yuva-accent",e.color),this.style.setProperty("--yuva-on-accent",b(e.color))}#c(){let e=this.locale;this.#a=y(e),this.setAttribute("lang",e);let t=document.createElement("style");if(t.textContent=S,this.#i.dir=this.getAttribute("dir")??g(e),this.#i.setAttribute("aria-modal","false"),this.#o){this.#s=null,this.#n=null,this.#r.replaceChildren();return}if(this.layout==="embedded"){this.#s=null,this.#n=null,this.#r.replaceChildren(t,this.#i),this.#t=!1,this.open();return}let i=document.createElement("button");if(i.type="button",i.className="launcher",i.addEventListener("click",()=>void this.toggle()),this.#s=i,this.#n=document.createElement("span"),this.#n.className="badge",this.#n.setAttribute("aria-hidden","true"),this.#r.replaceChildren(t,this.#i,i),this.#h(),this.hasAttribute("open")&&!this.#t)this.open()}#h(){let e=this.#s,t=this.#n;if(!e||!t)return;let i=this.#u;e.setAttribute("aria-expanded",String(this.#t)),e.setAttribute("aria-label",this.#t?r(this.#a,{id:"pqZJT2"}):i>0?r(this.#a,{id:"OkHvGB",values:{count:i}}):r(this.#a,{id:"6I7cJR"})),e.innerHTML=this.#t?A:L,t.textContent=i>9?"9+":String(i),t.hidden=this.#t||i===0,e.append(t)}}function k(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",d)}k();})();
109
+ `,A='<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H9l-5 4z"/></svg>',M='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',u=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class d extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",u||location.href).href);#r;#s=null;#n=null;#i;#e=null;#a={};#t=!1;#u=0;#l=null;#o=!1;constructor(){super();this.#r=this.attachShadow({mode:"open"}),this.#i=document.createElement("section"),this.#i.className="panel",this.#i.setAttribute("role","dialog"),this.#i.hidden=!0,this.#i.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&this.layout==="launcher")this.close()})}get layout(){return this.getAttribute("layout")==="embedded"?"embedded":"launcher"}get channel(){return this.getAttribute("channel")}get server(){return(this.getAttribute("server")||(u?new URL(u).origin:location.origin)).replace(/\/+$/,"")}get locale(){return f(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#t}get unread(){return this.#u}setIdentityToken(e){if(this.#l=e,this.#e)this.#e.then((t)=>t.identityChanged())}async signOut(){if(this.#l=null,this.removeAttribute("identity-token"),this.#e)await(await this.#e).signOut()}async rate(e,t,i){return(await this.#d()).rate(e,t,i)}connectedCallback(){this.#c();let e=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!e)return;let t=h(e);if(t.launcher)this.#p(t.launcher);let i=()=>{if(!this.isConnected||this.#e||this.channel!==e)return;if(t.session)this.#d();else this.#f(e)};if("requestIdleCallback"in window)requestIdleCallback(i,{timeout:3000});else setTimeout(i,1000)}#f(e){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(e)}`,{credentials:"omit"}).then((t)=>{if(t.status===403||t.status===404)this.#g();return t.ok?t.json():null}).then((t)=>{if(!t||this.channel!==e||this.#e)return;let i=b(t);this.#p(i),k(e,{...h(e),launcher:i})}).catch(()=>{return})}disconnectedCallback(){let e=this.#e;if(this.#e=null,e)e.then((t)=>t.destroy())}attributeChangedCallback(e,t,i){if(!this.isConnected||t===i)return;if(e==="open"){i===null?this.close():this.open();return}if(e==="identity-token"){if(this.#e)this.#e.then((n)=>n.identityChanged());return}if(e==="channel"||e==="server"){this.disconnectedCallback(),this.#o=!1,this.#c();return}if(this.#c(),this.#e)this.#e.then((n)=>n.update())}async open(){if(this.#t||this.#o)return;this.#t=!0,this.toggleAttribute("open-panel",!0),this.#h();let e=await this.#d();if(!this.#t)return;this.#i.hidden=!1,e.opened()}close(){if(!this.#t||this.layout==="embedded")return;if(this.#t=!1,this.toggleAttribute("open-panel",!1),this.#i.hidden=!0,this.#h(),this.#s?.focus(),this.#e)this.#e.then((e)=>e.closed())}toggle(){return this.#t?this.close():this.open()}#y(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#d(){return this.#e??=d.loadPanel().then(({mount:e})=>e({panel:this.#i,config:()=>this.#y(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#t,close:()=>this.close(),setUnread:(t)=>{this.#u=t,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:t}}))},setLauncher:(t)=>this.#p(t),refused:()=>this.#g()})),this.#e}#g(){if(this.#o)return;this.#o=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#t=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(e){if(this.setAttribute("position",e.position==="left"?"left":"right"),e.color&&/^#[0-9a-f]{6}$/i.test(e.color))this.style.setProperty("--yuva-accent",e.color),this.style.setProperty("--yuva-on-accent",v(e.color))}#c(){let e=this.locale;this.#a=m(e),this.setAttribute("lang",e);let t=document.createElement("style");if(t.textContent=L,this.#i.dir=this.getAttribute("dir")??y(e),this.#i.setAttribute("aria-modal","false"),this.#o){this.#s=null,this.#n=null,this.#r.replaceChildren();return}if(this.layout==="embedded"){this.#s=null,this.#n=null,this.#r.replaceChildren(t,this.#i),this.#t=!1,this.open();return}let i=document.createElement("button");if(i.type="button",i.className="launcher",i.addEventListener("click",()=>void this.toggle()),this.#s=i,this.#n=document.createElement("span"),this.#n.className="badge",this.#n.setAttribute("aria-hidden","true"),this.#r.replaceChildren(t,this.#i,i),this.#h(),this.hasAttribute("open")&&!this.#t)this.open()}#h(){let e=this.#s,t=this.#n;if(!e||!t)return;let i=this.#u;e.setAttribute("aria-expanded",String(this.#t)),e.setAttribute("aria-label",this.#t?r(this.#a,{id:"pqZJT2"}):i>0?r(this.#a,{id:"OkHvGB",values:{count:i}}):r(this.#a,{id:"6I7cJR"})),e.innerHTML=this.#t?M:A,t.textContent=i>9?"9+":String(i),t.hidden=this.#t||i===0,e.append(t)}}function w(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",d)}w();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "useyuva",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Yuva for the web: a headless client for contacts, the <yuva-chat> element, documentation page feedback and discussions, React hooks, a Nuxt module and a typed /v1 client.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,2 +0,0 @@
1
- var messages=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var messages2=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var catalogs={en:messages,tr:messages2},rtlLanguages=new Set(["ar","fa","he","ur"]),sourceLocale="en";function resolveLocale(...candidates){for(let candidate of candidates){if(!candidate)continue;let tag=candidate.toLowerCase();if(catalogs[tag])return tag;let language=tag.split(/[-_]/)[0]??"";if(catalogs[language])return language}return sourceLocale}function directionOf(locale){return rtlLanguages.has(locale.split(/[-_]/)[0]??"")?"rtl":"ltr"}function catalogFor(locale){return catalogs[locale]??messages}function translatePlain(messages2,descriptor,fallback=messages){let entry=messages2[descriptor.id]??fallback[descriptor.id],values=descriptor.values??{};if(typeof entry==="string")return entry;if(Array.isArray(entry))return entry.map((part)=>typeof part==="string"?part:Array.isArray(part)?String(values[part[0]]??""):"").join("");return descriptor.message??descriptor.id}function launcherOf(inbox){return{position:inbox.chat.launcher_position,color:inbox.chat.launcher_color??inbox.branding.color}}function contrastOn(color){let n=Number.parseInt(color.slice(1),16),[r,g,b]=[n>>16&255,n>>8&255,n&255].map((c)=>{let s=c/255;return s<=0.03928?s/12.92:((s+0.055)/1.055)**2.4});return 0.2126*r+0.7152*g+0.0722*b>0.4?"#111827":"#ffffff"}function storageKey(channel){return`yuva:${channel}`}function readStored(channel){try{let raw=localStorage.getItem(storageKey(channel));return raw?JSON.parse(raw):{}}catch{return{}}}function writeStored(channel,state){try{localStorage.setItem(storageKey(channel),JSON.stringify(state))}catch{}}
2
- export{resolveLocale,directionOf,catalogFor,translatePlain,launcherOf,contrastOn,readStored,writeStored};