useyuva 0.0.8 → 0.0.10
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/README.md +98 -6
- package/dist/esm/analytics.js +1 -0
- package/dist/esm/chat.js +2 -2
- package/dist/esm/client-9wy8zy77.js +1 -0
- package/dist/esm/docs.js +2 -2
- package/dist/esm/index-98r96a7e.js +2 -0
- package/dist/esm/index-c6q8br7d.js +2 -0
- package/dist/esm/index-geeh5h34.js +12 -0
- package/dist/esm/index-gk84nm8f.js +2 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/nuxt/module.js +7 -3
- package/dist/esm/nuxt/runtime/analytics.js +6 -0
- package/dist/esm/nuxt/runtime/components.js +32 -0
- package/dist/esm/nuxt/runtime/plugin.js +11 -0
- package/dist/esm/react.js +2 -1
- package/dist/esm/subscribe.js +33 -0
- package/dist/esm/{thread-3ydc3xfc.js → thread-btm71nxt.js} +2 -2
- package/dist/esm/yuva-chat-nkt3xjhb.js +193 -0
- package/dist/types/analytics/core.d.ts +47 -0
- package/dist/types/analytics/handle.d.ts +3 -0
- package/dist/types/analytics.d.ts +1 -0
- package/dist/types/client/api.d.ts +11 -0
- package/dist/types/client/client.d.ts +6 -1
- package/dist/types/i18n.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/locales/de/docs.d.ts +2 -0
- package/dist/types/locales/de/loader.d.ts +2 -0
- package/dist/types/locales/de/panel.d.ts +2 -0
- package/dist/types/locales/de/subscribe.d.ts +2 -0
- package/dist/types/locales/de/thread.d.ts +2 -0
- package/dist/types/locales/en/subscribe.d.ts +2 -0
- package/dist/types/locales/tr/subscribe.d.ts +2 -0
- package/dist/types/nuxt/module.d.ts +8 -1
- package/dist/types/nuxt/runtime/analytics.d.ts +2 -0
- package/dist/types/nuxt/runtime/components.d.ts +34 -0
- package/dist/types/nuxt/runtime/plugin.d.ts +6 -0
- package/dist/types/react.d.ts +18 -0
- package/dist/types/schema.gen.d.ts +15384 -5025
- package/dist/types/subscribe/element.d.ts +34 -0
- package/dist/types/subscribe.d.ts +4 -0
- package/dist/types/translate.d.ts +3 -0
- package/dist/widget/yuva-docs-thread-8st0egsq.js +61 -0
- package/dist/widget/yuva-subscribe-client-jya732vb.js +11 -0
- package/dist/yuva-analytics.js +1 -0
- package/dist/yuva-chat.js +6 -6
- package/dist/yuva-docs.js +6 -6
- package/dist/yuva-subscribe.js +33 -0
- package/dist/yuva.js +2 -2
- package/package.json +27 -4
- package/dist/esm/index-dj5dhqc1.js +0 -12
- package/dist/esm/index-e2tek7yk.js +0 -2
- package/dist/esm/yuva-chat-86e4mz63.js +0 -193
- package/dist/widget/yuva-docs-thread-4580g2ny.js +0 -61
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ClientMailingList } from "../client/api.js";
|
|
2
|
+
import type { IdentityTokenSource, YuvaClient, YuvaClientOptions } from "../client/client.js";
|
|
3
|
+
export interface SubscribeDetail {
|
|
4
|
+
lists: string[];
|
|
5
|
+
confirmation: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SubscribeErrorDetail {
|
|
8
|
+
code: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SubscribeClientModule {
|
|
11
|
+
createYuvaClient(options: YuvaClientOptions): YuvaClient;
|
|
12
|
+
}
|
|
13
|
+
declare const Base: typeof HTMLElement;
|
|
14
|
+
export declare const scriptSrc: string;
|
|
15
|
+
export declare class YuvaSubscribeElement extends Base {
|
|
16
|
+
#private;
|
|
17
|
+
static observedAttributes: string[];
|
|
18
|
+
static loadClient: (() => Promise<SubscribeClientModule>) | null;
|
|
19
|
+
constructor();
|
|
20
|
+
get channel(): string | null;
|
|
21
|
+
set channel(value: string | null);
|
|
22
|
+
get server(): string;
|
|
23
|
+
set server(value: string | null);
|
|
24
|
+
get locale(): string;
|
|
25
|
+
set locale(value: string | null);
|
|
26
|
+
get lists(): ClientMailingList[];
|
|
27
|
+
setIdentityToken(source: IdentityTokenSource | null): void;
|
|
28
|
+
connectedCallback(): void;
|
|
29
|
+
disconnectedCallback(): void;
|
|
30
|
+
attributeChangedCallback(name: string, previous: string | null, value: string | null): void;
|
|
31
|
+
consentText(lists?: ClientMailingList[]): string;
|
|
32
|
+
}
|
|
33
|
+
export declare function defineSubscribe(): void;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { defineSubscribe, YuvaSubscribeElement, type SubscribeDetail, type SubscribeErrorDetail } from "./subscribe/element.js";
|
|
2
|
+
export { defineSubscribe, YuvaSubscribeElement, type SubscribeDetail, type SubscribeErrorDetail };
|
|
3
|
+
export type { IdentityTokenSource } from "./client/client.js";
|
|
4
|
+
export type { ClientMailingList, SubscriptionState } from "./client/api.js";
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { MessageDescriptor, Messages } from "@lingui/core";
|
|
2
2
|
export declare function translate(messages: Messages, descriptor: MessageDescriptor, fallback: Messages): string;
|
|
3
|
+
export declare const sourceLocale = "en";
|
|
4
|
+
export declare function localeIn(catalogs: Record<string, Messages>, candidates: (string | null | undefined)[]): string;
|
|
5
|
+
export declare function directionOf(locale: string): "ltr" | "rtl";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var D=JSON.parse('{"2Hlmdt":["Write a reply…"],"3CApMv":["All discussions"],"3PqJQG":["Nothing to preview."],"4-S4QM":["Unmark as answer"],"5lWFkC":["Sign in"],"8wRl7c":["The opening post was deleted."],"99w-GZ":["Sign in to start a discussion. Your name is shown with your post."],"F_vGso":["Your reply"],"HkXOWm":["This reply was deleted."],"Hw3P48":["Replies: ",["0"]],"ImOQa9":["Reply"],"JfAIiv":["This discussion is locked. New replies are closed."],"Kl3TuI":["Get an e-mail when someone replies or an answer is accepted."],"Klsidc":["Delete this reply?"],"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."],"Sad2tK":["Sending…"],"VGqKyv":["This discussion is no longer available."],"Vwy_nT":["Markdown is supported."],"YZayoP":["Thanks! Your reply will appear for everyone once the team approves it."],"cnGeoo":["Delete"],"dEgA5A":["Cancel"],"dNOvhg":["Upvote (",["0"]," votes)"],"ePK91l":["Edit"],"i4_LY_":["Write"],"jhu92n":["Mark as answer"],"k4b5_X":["edited"],"n5vqdp":["Start discussion"],"qzVesX":["Edit your post"],"rAl91-":["Delete this discussion?"],"rdUucN":["Preview"],"tfDRzk":["Save"],"y-KXxN":["Accepted answer"],"y6sq5j":["Following"],"z1qf6l":["Start a discussion"]}');var Q=JSON.parse('{"2Hlmdt":["Antwort schreiben…"],"3CApMv":["Alle Diskussionen"],"3PqJQG":["Noch nichts für die Vorschau."],"4-S4QM":["Antwortmarkierung entfernen"],"5lWFkC":["Anmelden"],"8wRl7c":["Der erste Beitrag wurde gelöscht."],"99w-GZ":["Melden Sie sich an, um eine Diskussion zu starten. Ihr Name wird mit Ihrem Beitrag angezeigt."],"F_vGso":["Ihre Antwort"],"HkXOWm":["Diese Antwort wurde gelöscht."],"Hw3P48":["Antworten: ",["0"]],"ImOQa9":["Antworten"],"JfAIiv":["Diese Diskussion ist gesperrt. Neue Antworten sind nicht möglich."],"Kl3TuI":["Erhalten Sie eine E-Mail, wenn jemand antwortet oder eine Antwort akzeptiert wird."],"Klsidc":["Diese Antwort löschen?"],"MHrjPM":["Titel"],"MKEPCY":["Folgen"],"NjUiZ4":["Stellen Sie eine Frage, teilen Sie eine Idee oder beschreiben Sie ein Problem mit dieser Seite."],"NrGspR":["Danke! Ihre Diskussion ist für alle sichtbar, sobald das Team sie freigibt."],"OVijcR":["Stimme zurückziehen (",["0"]," Stimmen)"],"PL0621":["Melden Sie sich an, um zu antworten, abzustimmen und dieser Diskussion zu folgen."],"PN38hZ":["Ihre Frage oder Idee"],"PZ_kxo":["Behalten"],"Pwqkdw":["Wird geladen…"],"RqsQKK":["Ihre ersten Beiträge prüft das Team, bevor sie für alle sichtbar sind."],"Sad2tK":["Wird gesendet…"],"VGqKyv":["Diese Diskussion ist nicht mehr verfügbar."],"Vwy_nT":["Markdown wird unterstützt."],"YZayoP":["Danke! Ihre Antwort ist für alle sichtbar, sobald das Team sie freigibt."],"cnGeoo":["Löschen"],"dEgA5A":["Abbrechen"],"dNOvhg":["Zustimmen (",["0"]," Stimmen)"],"ePK91l":["Bearbeiten"],"i4_LY_":["Schreiben"],"jhu92n":["Als Antwort markieren"],"k4b5_X":["bearbeitet"],"n5vqdp":["Diskussion starten"],"qzVesX":["Beitrag bearbeiten"],"rAl91-":["Diese Diskussion löschen?"],"rdUucN":["Vorschau"],"tfDRzk":["Speichern"],"y-KXxN":["Akzeptierte Antwort"],"y6sq5j":["Gefolgt"],"z1qf6l":["Diskussion starten"]}');var X=JSON.parse('{"2Hlmdt":["Bir yanıt yazın…"],"3CApMv":["Tüm tartışmalar"],"3PqJQG":["Önizlenecek bir şey yok."],"4-S4QM":["Yanıt işaretini kaldır"],"5lWFkC":["Giriş yap"],"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."],"F_vGso":["Yanıtınız"],"HkXOWm":["Bu yanıt silindi."],"Hw3P48":["Yanıtlar: ",["0"]],"ImOQa9":["Yanıtla"],"JfAIiv":["Bu tartışma kilitli. Yeni yanıt yazılamaz."],"Kl3TuI":["Biri yanıt yazdığında ya da bir yanıt kabul edildiğinde e-posta alın."],"Klsidc":["Bu yanıt silinsin mi?"],"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."],"Sad2tK":["Gönderiliyor…"],"VGqKyv":["Bu tartışma artık mevcut değil."],"Vwy_nT":["Markdown desteklenir."],"YZayoP":["Teşekkürler! Yanıtınız ekip onayladığında herkese görünecek."],"cnGeoo":["Sil"],"dEgA5A":["Vazgeç"],"dNOvhg":["Oy ver (",["0"]," oy)"],"ePK91l":["Düzenle"],"i4_LY_":["Yaz"],"jhu92n":["Yanıt olarak işaretle"],"k4b5_X":["düzenlendi"],"n5vqdp":["Tartışmayı başlat"],"qzVesX":["Gönderinizi düzenleyin"],"rAl91-":["Bu tartışma silinsin mi?"],"rdUucN":["Önizleme"],"tfDRzk":["Kaydet"],"y-KXxN":["Kabul edilen yanıt"],"y6sq5j":["Takip ediliyor"],"z1qf6l":["Tartışma başlat"]}');function W(n,t,i){let f=n[t.id]??i[t.id],m=t.values??{};if(typeof f==="string")return f;if(Array.isArray(f))return f.map((p)=>typeof p==="string"?p:Array.isArray(p)?String(m[p[0]]??""):"").join("");return t.message??t.id}function o(n,t,i){let f=document.createElement(n);if(t)f.className=t;if(i!==void 0)f.textContent=i;return f}var ae=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function re(n,t){let i=document.createElement("a");return i.href=n,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function L(n,t){let i=document.createElement(n);return i.append(...t),i}function K(n){let t=[],i=0;for(let f of n.matchAll(ae)){let m=f.index??0;if(m>i)t.push(document.createTextNode(n.slice(i,m)));let[p,g,u,y,h]=f;if(g)t.push(L("code",[document.createTextNode(g.slice(1,-1))]));else if(u)t.push(L("strong",K(u.slice(2,-2))));else if(y)t.push(L("em",K(y.slice(1,-1))));else if(h){let A=h.startsWith("www.")?`https://${h}`:h;try{let _=new URL(A);t.push(_.protocol==="http:"||_.protocol==="https:"?re(_.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=m+p.length}if(i<n.length)t.push(document.createTextNode(n.slice(i)));return t}var se=/\[([^\]\n]+)\]\(([^)\s]+)\)/g;function U(n){let t=[],i=0;for(let f of n.matchAll(se)){let m=f.index??0;if(m>i)t.push(...K(n.slice(i,m)));let[p,g="",u=""]=f,y=null;try{y=new URL(u)}catch{}if(y&&(y.protocol==="http:"||y.protocol==="https:")){let h=document.createElement("a");h.href=y.href,h.target="_blank",h.rel="nofollow ugc noopener",h.append(...K(g)),t.push(h)}else t.push(document.createTextNode(p));i=m+p.length}if(i<n.length)t.push(...K(n.slice(i)));return t}function j(n,t){let i=document.createElement(n);return i.append(...U(t.join(" "))),i}function G(n){let t=document.createDocumentFragment(),i=n.replace(/\r\n?/g,`
|
|
2
|
+
`).split(`
|
|
3
|
+
`),f=[],m=null,p=[],g=()=>{if(f.length)t.append(j("p",f));if(p.length){let u=document.createElement("blockquote");u.append(G(p.join(`
|
|
4
|
+
`))),t.append(u)}f=[],p=[],m=null};for(let u=0;u<i.length;u++){let y=i[u]??"",h=/^\s*(```|~~~)/.exec(y);if(h){g();let M=[];while(++u<i.length&&!(i[u]??"").trimStart().startsWith(h[1]??"```"))M.push(i[u]??"");let q=document.createElement("pre");q.append(Object.assign(document.createElement("code"),{textContent:M.join(`
|
|
5
|
+
`)})),t.append(q);continue}if(/^\s*$/.test(y)){g();continue}let A=/^\s*>\s?(.*)$/.exec(y);if(A){if(f.length||m)g();p.push(A[1]??"");continue}let _=/^\s*(#{1,6})\s+(.*)$/.exec(y);if(_){g(),t.append(j(`h${Math.min(6,(_[1]?.length??1)+2)}`,[_[2]??""]));continue}let S=/^\s*(?:([-*+])|(\d+)[.)])\s+(.*)$/.exec(y);if(S){let M=S[1]?"ul":"ol";if(f.length||p.length||m&&m.tagName.toLowerCase()!==M)g();if(!m)m=document.createElement(M),t.append(m);m.append(j("li",[S[3]??""]));continue}if(p.length)g();if(m&&/^\s{2,}/.test(y)){m.lastElementChild?.append(" ",...U(y.trim()));continue}m=null,f.push(y.trim())}return g(),t}var de=1800000,oe={en:D,tr:X,de:Q},R=(n)=>`<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">${n}</svg>`,J=R('<circle cx="12" cy="12" r="9"/><path d="M8 12l3 3 5-6"/>'),le=R('<path d="M19 12H5M12 19l-7-7 7-7"/>'),ce=R('<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"/>'),Me=`
|
|
6
|
+
.thread { display: flex; flex-direction: column; gap: 12px; }
|
|
7
|
+
.thread-head { display: flex; flex-direction: column; gap: 8px; }
|
|
8
|
+
.post { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--yuva-border); border-radius: 12px; }
|
|
9
|
+
.post.accepted { border-color: var(--yuva-success); box-shadow: inset 0 0 0 1px var(--yuva-success); }
|
|
10
|
+
.post.pending { border-style: dashed; }
|
|
11
|
+
.side { display: flex; flex-direction: column; align-items: center; gap: 6px; }
|
|
12
|
+
.vote {
|
|
13
|
+
display: inline-flex; flex-direction: column; align-items: center; gap: 0; min-inline-size: 40px; padding: 4px 6px;
|
|
14
|
+
border: 1px solid var(--yuva-border); border-radius: 8px; background: none; cursor: pointer; font-size: 0.85em; font-weight: 600;
|
|
15
|
+
}
|
|
16
|
+
.vote:hover:not(:disabled) { border-color: var(--yuva-accent); }
|
|
17
|
+
.vote[aria-pressed="true"] { border-color: var(--yuva-accent); color: var(--yuva-accent); background: var(--yuva-soft); }
|
|
18
|
+
.post-body { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
19
|
+
.post-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.88em; }
|
|
20
|
+
.name { font-weight: 600; }
|
|
21
|
+
.answer-label { display: flex; align-items: center; gap: 6px; color: var(--yuva-success); font-weight: 600; font-size: 0.85em; }
|
|
22
|
+
.tools { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
|
|
23
|
+
.children { display: flex; flex-direction: column; gap: 10px; margin-block-start: 4px; padding-inline-start: 14px; border-inline-start: 2px solid var(--yuva-border); }
|
|
24
|
+
.children .post { padding: 10px 0; border: 0; box-shadow: none; }
|
|
25
|
+
.children .post + .post { border-block-start: 1px solid var(--yuva-border); border-radius: 0; }
|
|
26
|
+
.deleted { font-style: italic; opacity: 0.65; }
|
|
27
|
+
.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; }
|
|
28
|
+
.composer { display: flex; flex-direction: column; border: 1px solid var(--yuva-border); border-radius: 12px; overflow: hidden; }
|
|
29
|
+
.composer:focus-within { border-color: var(--yuva-accent); }
|
|
30
|
+
.composer .ctabs { display: flex; gap: 4px; padding: 0 8px; border-block-end: 1px solid var(--yuva-border); }
|
|
31
|
+
.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; }
|
|
32
|
+
.composer .ctab[aria-selected="true"] { border-block-end-color: var(--yuva-accent); font-weight: 600; opacity: 1; }
|
|
33
|
+
.composer .ctab:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: -2px; }
|
|
34
|
+
.composer textarea, .composer .preview { border: 0; border-radius: 0; min-block-size: 110px; padding: 10px 12px; }
|
|
35
|
+
.composer textarea:focus-visible { outline: none; }
|
|
36
|
+
.composer .preview { overflow-wrap: anywhere; }
|
|
37
|
+
.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); }
|
|
38
|
+
.composer .hint { font-size: 0.8em; opacity: 0.7; }
|
|
39
|
+
.composer .buttons { display: flex; gap: 8px; margin-inline-start: auto; }
|
|
40
|
+
.field-title { font-size: 1.05em; font-weight: 600; }
|
|
41
|
+
.form { display: flex; flex-direction: column; gap: 10px; }
|
|
42
|
+
.md { overflow-wrap: anywhere; }
|
|
43
|
+
.md > :first-child { margin-block-start: 0; }
|
|
44
|
+
.md > :last-child { margin-block-end: 0; }
|
|
45
|
+
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 0.75em; }
|
|
46
|
+
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 0.9em 0 0.4em; font-size: 1em; font-weight: 600; }
|
|
47
|
+
.md h1, .md h3 { font-size: 1.1em; }
|
|
48
|
+
.md ul, .md ol { padding-inline-start: 1.5em; }
|
|
49
|
+
.md a { color: var(--yuva-accent); }
|
|
50
|
+
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; padding: 1px 5px; border-radius: 5px; background: var(--yuva-soft); }
|
|
51
|
+
.md pre { padding: 10px 12px; border-radius: 8px; background: var(--yuva-soft); overflow-x: auto; }
|
|
52
|
+
.md pre code { padding: 0; background: none; }
|
|
53
|
+
.md blockquote { padding-inline-start: 12px; border-inline-start: 3px solid var(--yuva-border); opacity: 0.85; }
|
|
54
|
+
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
|
|
55
|
+
.md th, .md td { border: 1px solid var(--yuva-border); padding: 4px 8px; }
|
|
56
|
+
.md img { max-inline-size: 100%; }
|
|
57
|
+
.md hr { border: 0; border-block-start: 1px solid var(--yuva-border); }
|
|
58
|
+
@media (max-width: 560px) {
|
|
59
|
+
.post { padding: 12px; gap: 10px; }
|
|
60
|
+
}
|
|
61
|
+
`;class N{area=o("textarea");previewing=!1;constructor(n){this.area.rows=n,this.area.maxLength=20000,this.area.dir="auto"}get value(){return this.area.value.trim()}clear(){this.area.value="",this.previewing=!1}}function ze(n){let t=n.s,i=(e)=>W(oe[n.locale()]??D,e,D),f=new N(4),m=new N(6),p=o("input"),g=null,u=null;p.maxLength=200,p.dir="auto",p.className="field-title";for(let e of[f.area,m.area])e.addEventListener("input",()=>y());p.addEventListener("input",()=>y());function y(){for(let e of n.root.querySelectorAll("[data-requires]")){let a=e.dataset.requires,r=t.busy.has(e.dataset.busy??""),s=a==="start"?p.value.trim().length>=3&&m.value!=="":a==="reply"?f.value!=="":a==="inline"?!!g?.composer.value:a==="edit"?!!u?.composer.value&&(!!u.post||u.title.value.trim().length>=3):!0;e.disabled=r||!s}}async function h(){let e=p.value.trim(),a=m.value;if(e.length<3||!a)return;let r=n.page(),s=await n.act("start",()=>n.client().startDiscussion({page_url:r,page_title:n.pageTitle()||void 0,title:e,body:a}));if(!s)return;if(n.forget(),n.emit("yuva-discussion",{page:r,discussion_id:s.id,state:s.state}),n.page()!==r)return;p.value="",m.clear(),t.items=[s,...t.items.filter((c)=>c.id!==s.id)],t.notice=s.state==="pending"?i({id:"NrGspR"}):"",t.thread={discussion:s,posts:[]},await n.open(s.id,!0)}async function A(e,a){let r=t.thread,s=e.value;if(!r||!s)return;let c=n.page(),l=r.discussion.id,v=await n.act(a?`reply-${a}`:"reply",()=>n.client().replyToDiscussion(l,{body:s,parent_post_id:a}));if(!v)return;if(n.forget(),n.emit("yuva-post",{page:c,discussion_id:l,post_id:v.id,state:v.state}),e.clear(),a)g=null;if(t.notice=v.state==="pending"?i({id:"YZayoP"}):"",t.thread?.discussion.id===l)t.thread={...t.thread,posts:[...t.thread.posts,v]},t.focus=`post-${v.id}`,n.render(),n.open(l,!1)}async function _(e,a){if(!t.writer)return void n.signIn();let r=await n.act(`vote-${e.id}`,()=>n.client().voteDiscussionPost(e.id,!e.voted));if(!r||!t.thread)return;if(n.forget(),a){let s={...t.thread.discussion,votes:r.votes,voted:r.voted};t.thread={...t.thread,discussion:s},t.items=t.items.map((c)=>c.id===s.id?s:c)}else t.thread={...t.thread,posts:t.thread.posts.map((s)=>s.id===r.id?{...s,...r}:s)}}async function S(){let e=t.thread;if(!e)return;if(!t.writer)return void n.signIn();let a=!e.discussion.following;if(await n.act("follow",()=>n.client().followDiscussion(e.discussion.id,a).then(()=>!0))&&t.thread?.discussion.id===e.discussion.id)t.thread={...t.thread,discussion:{...t.thread.discussion,following:a}}}async function M(e){let a=t.thread;if(!a)return;let r=await n.act(`accept-${e?.id??"clear"}`,()=>n.client().acceptDiscussionAnswer(a.discussion.id,e?.id??null));if(!r)return;n.forget(),t.focus=e?`post-${e.id}`:"thread-title",await n.open(r.id,!1)}async function q(){let e=u,a=t.thread;if(!e||!a)return;let r=e.composer.value,s=!e.post,c=e.title.value.trim();if(!r||s&&c.length<3)return;let l=e.post?.id??a.discussion.opening_post_id;if(!await n.act(`edit-${l}`,()=>n.client().editDiscussionPost(l,s?{body:r,title:c}:{body:r})))return;n.forget(),u=null,t.focus=s?"thread-title":`post-${l}`,await n.open(a.discussion.id,!1)}async function ee(e,a){let r=t.thread;if(!r)return;let s=await n.act(`delete-${e}`,()=>n.client().deleteDiscussionPost(e).then(()=>!0));if(t.confirm="",!s)return;if(n.forget(),a)try{await n.client().getDiscussion(r.discussion.id)}catch{return t.items=t.items.filter((c)=>c.id!==r.discussion.id),t.thread=null,n.toList()}await n.open(r.discussion.id,!1)}function C(e){let a=o("div","md");a.dir="auto",a.innerHTML=e;for(let r of a.querySelectorAll("a[href]"))r.setAttribute("target","_blank");return a}function P(e,a){let r=o("div","composer"),s=o("div","ctabs");s.setAttribute("role","tablist"),s.setAttribute("aria-label",a.label);let c=`p-${a.focusKey}`,l=n.button("ctab",i({id:"i4_LY_"}),`${a.focusKey}-write`,()=>{e.previewing=!1,t.focus=a.focusKey,n.render()}),v=n.button("ctab",i({id:"rdUucN"}),`${a.focusKey}-preview`,()=>{e.previewing=!0,n.render()});for(let[d,k]of[[l,!e.previewing],[v,e.previewing]])d.setAttribute("role","tab"),d.setAttribute("aria-selected",String(k)),d.setAttribute("aria-controls",c),d.tabIndex=k?0:-1,d.addEventListener("keydown",(z)=>{if(z.key!=="ArrowLeft"&&z.key!=="ArrowRight")return;z.preventDefault(),e.previewing=!e.previewing,t.focus=`${a.focusKey}-${e.previewing?"preview":"write"}`,n.render()});if(s.append(l,v),r.append(s),e.previewing){let d=o("div","preview md");if(d.dir="auto",d.id=c,d.setAttribute("role","tabpanel"),d.setAttribute("aria-label",i({id:"rdUucN"})),e.value)d.append(G(e.area.value));else d.append(o("p","muted",i({id:"3PqJQG"})));r.append(d)}else e.area.id=c,e.area.placeholder=a.placeholder,e.area.setAttribute("aria-label",a.label),e.area.dataset.key=a.focusKey,e.area.disabled=t.busy.has(a.busy),e.area.onkeydown=(d)=>{if(d.key==="Enter"&&(d.metaKey||d.ctrlKey))d.preventDefault(),a.onSubmit();else if(d.key==="Escape"&&a.onCancel)a.onCancel()},r.append(e.area);let x=o("div","foot");x.append(o("span","hint",i({id:"Vwy_nT"})));let w=o("div","buttons");if(a.onCancel)w.append(n.button("ghost",i({id:"dEgA5A"}),`${a.focusKey}-cancel`,a.onCancel));let b=n.button("send",t.busy.has(a.busy)?i({id:"Sad2tK"}):a.submit,`${a.focusKey}-submit`,a.onSubmit);return b.dataset.requires=a.requires,b.dataset.busy=a.busy,w.append(b),x.append(w),r.append(x),r}function H(e){let a=o("div","signin");return a.append(o("p","",e)),a.append(n.button("send",i({id:"5lWFkC"}),"sign-in-box",()=>void n.signIn())),a}function E(){let e=n.button("plain",i({id:"3CApMv"}),"back",()=>n.toList(),le);e.style.alignSelf="flex-start",e.style.display="inline-flex",e.style.gap="6px",e.style.alignItems="center";let a=e.querySelector("svg");if(a&&n.direction()==="rtl")a.style.transform="scaleX(-1)";return e}function te(){let e=o("div","form");if(e.append(o("h3","",i({id:"z1qf6l"}))),!t.writer)return e.append(H(i({id:"99w-GZ"}))),[E(),e];if(p.placeholder=i({id:"MHrjPM"}),p.setAttribute("aria-label",i({id:"MHrjPM"})),p.dataset.key="new-title",p.disabled=t.busy.has("start"),e.append(p),e.append(P(m,{label:i({id:"PN38hZ"}),placeholder:i({id:"NjUiZ4"}),submit:i({id:"n5vqdp"}),busy:"start",requires:"start",focusKey:"new-body",onSubmit:()=>void h(),onCancel:()=>n.toList()})),n.mode()==="moderated"&&t.reader)e.append(o("p","muted",i({id:"RqsQKK"})));return[E(),e]}function ne(e){return!!e.mine&&!t.thread?.discussion.locked&&Date.now()-Date.parse(e.created_at)<de}function Y(e,a){let r=t.thread;if(!r)return null;let s=r.discussion,c=!e,l=e?.id??s.opening_post_id,v=c?!!s.mine:!!e.mine,x=c?!!s.deleted:e.deleted,w=o("div","tools");if(x)return null;if(!c&&a&&!s.locked&&t.writer&&e.state==="published")w.append(n.button("plain",i({id:"ImOQa9"}),`reply-to-${e.id}`,()=>{g=g?.target===a.id?g:{target:a.id,composer:new N(3)},g.composer.area.oninput=()=>y(),t.focus=`inline-${a.id}`,n.render()}));if(!c&&s.mine&&!e.parent_post_id&&e.state==="published"&&!s.locked){let b=s.answer_post_id===e.id,d=n.button("plain",b?i({id:"4-S4QM"}):i({id:"jhu92n"}),`accept-${e.id}`,()=>void M(b?null:e),b?"":J);d.style.display="inline-flex",d.style.gap="4px",d.style.alignItems="center",d.disabled=t.busy.has(`accept-${e.id}`)||t.busy.has("accept-clear"),w.append(d)}if(v&&ne(c?s:e))w.append(n.button("plain",i({id:"ePK91l"}),`edit-${l}`,()=>{let b=new N(c?6:4);b.area.value=c?s.body:e.body,b.area.oninput=()=>y();let d=o("input");d.className="field-title",d.maxLength=200,d.dir="auto",d.value=s.title,d.oninput=()=>y(),u={post:e,composer:b,title:d},t.focus=c?"edit-title":`edit-body-${l}`,n.render()}));if(v)if(t.confirm===l){let b=n.button("plain danger",i({id:"cnGeoo"}),`delete-yes-${l}`,()=>void ee(l,c));b.disabled=t.busy.has(`delete-${l}`),w.append(o("span","muted",c?i({id:"rAl91-"}):i({id:"Klsidc"})),b,n.button("plain",i({id:"PZ_kxo"}),`delete-no-${l}`,()=>{t.confirm="",t.focus=`delete-${l}`,n.render()}))}else w.append(n.button("plain",i({id:"cnGeoo"}),`delete-${l}`,()=>{t.confirm=l,t.focus=`delete-no-${l}`,n.render()}));return w.childElementCount?w:null}function O(e,a){let r=n.button("vote",String(e.votes),`vote-${e.id}`,()=>void _(e,a),n.icons.up);return r.setAttribute("aria-pressed",String(!!e.voted)),r.setAttribute("aria-label",e.voted?i({id:"OVijcR",values:{0:e.votes}}):i({id:"dNOvhg",values:{0:e.votes}})),r.disabled=!!e.mine||!!t.thread?.discussion.locked||t.busy.has(`vote-${e.id}`),r}function B(e,a,r=[]){let c=t.thread.discussion.answer_post_id===e.id,l=o("article",`post${c?" accepted":""}${e.state==="pending"?" pending":""}`);l.dataset.key=`post-${e.id}`,l.tabIndex=-1,l.setAttribute("aria-label",n.authorName(e.author));let v=o("div","side");if(!e.deleted)v.append(O(e,!1));if(!a||a.id===e.id)l.append(v);let x=o("div","post-body");if(c){let b=o("div","answer-label");b.innerHTML=J,b.append(i({id:"y-KXxN"})),x.append(b)}if(x.append(I(e.author,e.created_at,e.edited_at,e.state,e.deleted)),u?.post?.id===e.id)x.append(V());else if(e.deleted)x.append(o("p","deleted",i({id:"HkXOWm"})));else x.append(C(e.body_html));let w=Y(e,a);if(w)x.append(w);if(r.length||g?.target===e.id){let b=o("div","children");for(let d of r)b.append(B(d,e));if(g?.target===e.id){let d=g;b.append(P(d.composer,{label:i({id:"F_vGso"}),placeholder:i({id:"2Hlmdt"}),submit:i({id:"ImOQa9"}),busy:`reply-${e.id}`,requires:"inline",focusKey:`inline-${e.id}`,onSubmit:()=>void A(d.composer,e.id),onCancel:()=>{g=null,t.focus=`reply-to-${e.id}`,n.render()}}))}x.append(b)}return l.append(x),l}function I(e,a,r,s,c){let l=o("div","post-head");if(!c){if(l.append(n.avatar(e,!0),o("span","name",n.authorName(e))),e.kind==="member"&&!e.deleted)l.append(n.badge("team"))}if(l.append(n.time(a)),r&&!c)l.append(o("span","muted",i({id:"k4b5_X"})));if(s==="pending")l.append(n.badge("pending"));return l}function V(){let e=u,a=o("div","form");if(!e.post)e.title.setAttribute("aria-label",i({id:"MHrjPM"})),e.title.dataset.key="edit-title",a.append(e.title);let r=e.post?.id??t.thread.discussion.opening_post_id;return a.append(P(e.composer,{label:i({id:"qzVesX"}),placeholder:"",submit:i({id:"tfDRzk"}),busy:`edit-${r}`,requires:"edit",focusKey:`edit-body-${r}`,onSubmit:()=>void q(),onCancel:()=>{u=null,t.focus=`edit-${r}`,n.render()}})),a}function ie(){let e=[E()],a=t.thread;if(!a||t.threadState==="missing"){let d=o("div","empty");return d.append(o("p","",t.threadState==="loading"?i({id:"Pwqkdw"}):i({id:"VGqKyv"}))),e.push(d),e}let r=a.discussion,s=o("div","thread"),c=o("div","thread-head");if(u&&!u.post)c.append(I(r.author,r.created_at,r.edited_at,r.state,!1)),c.append(V()),s.append(c);else{let d=o("h3","",r.title);d.dir="auto",d.tabIndex=-1,d.dataset.key="thread-title",c.append(d);let k=o("div","meta");if(r.answer_post_id)k.append(n.badge("answered"));if(r.state==="pending")k.append(n.badge("pending"));if(r.locked)k.append(n.badge("locked"));if(k.childElementCount)c.append(k);s.append(c);let z=o("article",`post${r.state==="pending"?" pending":""}`),Z=o("div","side");if(!r.deleted)Z.append(O({id:r.opening_post_id,votes:r.votes,voted:r.voted,mine:r.mine},!0));let T=o("div","post-body");T.append(I(r.author,r.created_at,r.edited_at,r.state,!!r.deleted)),T.append(r.deleted?o("p","deleted",i({id:"8wRl7c"})):C(r.body_html));let F=Y(null,null);if(F)T.append(F);z.append(Z,T),s.append(z)}let l=o("div","bar"),v=n.button("ghost",r.following?i({id:"y6sq5j"}):i({id:"MKEPCY"}),"follow",()=>void S(),ce);v.setAttribute("aria-pressed",String(!!r.following)),v.title=i({id:"Kl3TuI"}),v.disabled=t.busy.has("follow");let x=o("span","muted",i({id:"Hw3P48",values:{0:r.reply_count}}));if(l.append(x,v),s.append(l),t.threadState==="loading"&&!a.posts.length&&r.reply_count>0){let d=o("div","skeleton");d.setAttribute("aria-busy","true"),d.setAttribute("aria-label",i({id:"Pwqkdw"})),s.append(d)}let w=a.posts.filter((d)=>!d.parent_post_id),b=o("div","thread");for(let d of w)b.append(B(d,d,a.posts.filter((k)=>k.parent_post_id===d.id)));if(w.length)s.append(b);if(t.notice)s.append(n.noticeBox(t.notice));if(r.locked)s.append(n.noticeBox(i({id:"JfAIiv"}),n.icons.lock));else if(!t.writer)s.append(H(i({id:"PL0621"})));else s.append(P(f,{label:i({id:"F_vGso"}),placeholder:i({id:"2Hlmdt"}),submit:i({id:"ImOQa9"}),busy:"reply",requires:"reply",focusKey:"reply",onSubmit:()=>void A(f)}));return e.push(s),e}return{threadView:ie,newView:te,syncSend:y,close(){g=null,u=null},reset(){g=null,u=null,f.clear()}}}export{ze as createThread,Me as styles};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class c extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function g(e,t,n,{method:s="GET",json:i,body:o,headers:a={},token:p,blob:r}={}){if(a={...a},p)a.Authorization=`Bearer ${p}`;let m=o;if(i!==void 0)a["Content-Type"]="application/json",m=JSON.stringify(i);let l;try{l=await e(t+n,{method:s,headers:a,body:m,credentials:"omit"})}catch{throw new c(0,"network")}if(!l.ok){let u="error";try{u=(await l.json()).code??u}catch{}throw new c(l.status,u)}if(l.status===204)return;return r?await l.blob():await l.json()}function P(e,t,n){return g(e,t,`/client/v1/channels/${encodeURIComponent(n)}/lists`)}function b(e,t,n,s){return g(e,t,`/client/v1/channels/${encodeURIComponent(n)}/subscriptions`,{method:"POST",json:s})}class C{server;socketClass;handlers;#s=null;#o=0;#p=0;#t=null;#a=!0;constructor(e,t,n){this.server=e;this.socketClass=t;this.handlers=n}get connected(){return this.#s?.readyState===1}start(){if(this.#a=!1,!this.#s&&!this.#t)this.#r()}stop(){if(this.#a=!0,this.#t)clearTimeout(this.#t);this.#t=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#o=0}nudge(){if(this.#a||this.#s)return;if(this.#t)clearTimeout(this.#t);this.#t=null,this.#r()}#r(){let e=this.handlers.token();if(!e||this.#a)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#o>0)t.searchParams.set("last_event_id",String(this.#o));let n;try{n=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#n();return}this.#s=n,n.onmessage=(s)=>{let i;try{i=JSON.parse(String(s.data))}catch{return}if(i.type==="ready")this.#p=0,this.#o=Math.max(this.#o,i.last_event_id);else if("id"in i&&typeof i.id==="number")this.#o=Math.max(this.#o,i.id);this.handlers.event(i)},n.onclose=(s)=>{if(this.#s!==n)return;if(this.#s=null,this.#a)return;if(s.code===1008){this.#o=0,this.handlers.sessionEnded();return}this.#n()}}#n(){if(this.#a||this.#t)return;let e=this.#p++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#t=setTimeout(()=>{this.#t=null,this.#r()},t)}}function I(e,t,n){let s=new URL("/account/connect",e);return s.searchParams.set("channel",t),s.searchParams.set("origin",n),s.href}function T(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function R(e,t,{width:n=460,height:s=640}={}){let i=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??n)-n)/2),p=Math.max(0,(window.screenY??0)+((window.outerHeight??s)-s)/2),r=window.open(I(e,t,o),"yuva-reader",`popup=yes,width=${n},height=${s},left=${Math.round(a)},top=${Math.round(p)}`);if(!r)return Promise.reject(new c(0,"popup_blocked"));return new Promise((m,l)=>{let u=!1,f=()=>{u=!0,window.removeEventListener("message",S),clearInterval(v)},S=(h)=>{if(u||h.origin!==i||h.source&&h.source!==r)return;let d=h.data;if(!T(d)||d.channel_key!==t||d.origin!==o)return;f();try{r.close()}catch{}m({token:d.token,expires_at:d.expires_at,reader:d.reader})},v=setInterval(()=>{let h=!1;try{h=r.closed}catch{}if(!h)return;clearInterval(v),setTimeout(()=>{if(u)return;f(),l(new c(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",S)})}function x(e){return`yuva:${e}`}function w(e,t){return`yuva:reader:${e} ${t}`}function k(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function M(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),n=JSON.parse(atob(t));return typeof n.sub==="string"?n.sub:null}catch{return null}}function U(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,n)=>void e.set(t,n)}}function y(e){let t=new URLSearchParams;for(let[s,i]of Object.entries(e))if(i!==void 0)t.set(s,String(i));let n=t.toString();return n?`?${n}`:""}function E(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function _(e,t,n){let s=[];for(let[i,o]of e)s.push(`--${n}\r
|
|
2
|
+
Content-Disposition: form-data; name="${i}"\r
|
|
3
|
+
\r
|
|
4
|
+
${o}\r
|
|
5
|
+
`);for(let i of t){let o=i.name||"file";s.push(`--${n}\r
|
|
6
|
+
Content-Disposition: form-data; name="files"; filename="${E(o)}"\r
|
|
7
|
+
Content-Type: ${i.type||"application/octet-stream"}\r
|
|
8
|
+
\r
|
|
9
|
+
`,i,`\r
|
|
10
|
+
`)}return s.push(`--${n}--\r
|
|
11
|
+
`),new Blob(s)}class D{server;channel;#s;#o;#p;#t;#a;#r=null;#n=null;#m=null;#g=null;#i=null;#c;#C=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,n)=>fetch(t,n)),this.#o=e.WebSocket??globalThis.WebSocket,this.#p=e.storage??U(),this.#t=e.identityToken??null,this.#a=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#n}get token(){return this.#r}get connected(){return this.#i?.connected??!1}on(e,t){let n=this.#C.get(e);if(!n)this.#C.set(e,n=new Set);return n.add(t),()=>void n.delete(t)}#l(e,t){for(let n of this.#C.get(e)??[])n(t)}stored(){try{let e=this.#p.getItem(x(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#y(e){try{this.#p.setItem(x(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#h(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#h(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return P(this.#s,this.server,this.channel)}subscribe(e){return b(this.#s,this.server,this.channel,e)}subscriptions(){return this.#e("/client/v1/subscriptions")}subscribeList(e,t){return this.#e(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#e(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#t=e,this.reset()}start(){if(this.#n)return Promise.resolve(this.#n);return this.#m??=this.#P(!1).then((e)=>(this.#l("session",{session:e,renewed:!1}),e)).finally(()=>{this.#m=null}),this.#m}async refresh(){let e=await this.#e("/client/v1/session");return this.#n={...this.#n,...e},this.#l("session",{session:this.#n,renewed:!1}),this.#n}reset(){this.#i?.stop(),this.#i?.reset(),this.#m=null,this.#g=null,this.#r=null,this.#n=null}async signOut(){let e=this.#r;this.reset();let t=this.stored();if(delete t.session,this.#y(t),e)await this.#h("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#o)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#i??=new C(this.server,this.#o,{token:()=>this.#r,event:(e)=>{if(e.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",e)},sessionEnded:()=>void this.#v().catch(()=>this.#i?.nudge()),reconnecting:(e)=>{if(this.#l("connection",{state:"reconnecting",attempt:e}),e===2)this.#e("/client/v1/session").catch(()=>{return})}}),!this.#i.connected)this.#l("connection",{state:"connecting",attempt:0});this.#i.start()}disconnect(){this.#i?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#i?.nudge()}listConversations(e={}){return this.#e(`/client/v1/conversations${y({...e})}`)}getConversation(e){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#e("/client/v1/conversations",this.#S(e))}listMessages(e,t={}){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/messages${y({...t})}`)}sendMessage(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#S(t))}markRead(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,n){let s={rating:t,comment:n?.trim()||void 0};return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:s})}setTyping(e,t){return this.#e(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#e("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#e(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??k();return this.#e("/client/v1/feedback",{method:"POST",headers:this.#f(t),json:{...e,client_id:t}})}get reader(){if(this.#c===void 0)try{let e=this.#p.getItem(w(this.server,this.channel));this.#c=e?JSON.parse(e):null}catch{this.#c=null}if(this.#c&&Date.parse(this.#c.expires_at)<=Date.now()+30000)this.#d(null);return this.#c}#d(e){let t=this.#c?.token!==e?.token;this.#c=e;try{this.#p.setItem(w(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#l("reader",e)}readerSignIn(e){return R(this.server,this.channel,e).then((t)=>(this.#d(t),t))}setReader(e){this.#d(e)}async readerSignOut(){let e=this.reader?.token;if(this.#d(null),e)await this.#h("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${y({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#u(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#u("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#u(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#u(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#u(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let n=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#u(n,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#n)return this.#n.contact.identified?"contact":null;return await this.#t?.()?"contact":null}async#u(e,t,n=!0){let s=this.reader;if(s)try{return await this.#h(e,{...t,token:s.token})}catch(o){if(!(o instanceof c)||o.status!==401||this.#c?.token!==s.token)throw o;if(this.#d(null),n)throw new c(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#e(e,t);if(n)throw new c(403,"sign_in_required");return this.#h(e,t)}#f(e){return this.#a&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#S({body:e,subject:t,files:n=[],client_id:s=k()}){let i=this.#f(s);if(n.length===0)return{method:"POST",headers:i,json:{body:e,subject:t,client_id:s}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",s]);let a=`yuva-${s.replace(/[^\w-]/g,"").slice(0,60)}-${s.length}`;return i["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:i,body:_(o,n,a)}}#h(e,t){return g(this.#s,this.server,e,t)}async#e(e,t={},n=!0){if(!this.#r)await this.start();try{return await this.#h(e,{...t,token:this.#r})}catch(s){if(!n||!(s instanceof c)||s.status!==401)throw s;return await this.#v(),this.#e(e,t,!1)}}#v(){return this.#g??=(async()=>{let e=await this.#P(!0);if(this.#i)this.#i.stop(),this.#i.reset(),this.#i.start();this.#l("session",{session:e,renewed:!0})})().finally(()=>{this.#g=null}),this.#g}async#P(e){let t=this.stored(),n=await this.#t?.()||null,s=n?M(n):null,i=t.session;if(!e&&i&&i.sub===s&&Date.parse(i.expires_at)>Date.now()+60000)try{let r=await this.#h("/client/v1/session",{token:i.token});return this.#b(r,i.token,s)}catch(r){if(!(r instanceof c)||r.status!==401&&r.status!==403)throw r}let o=await this.#h("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:n??void 0,visitor_id:t.visitor_id}}),{token:a,...p}=o;return this.#b(p,a,s)}#b(e,t,n){this.#r=t,this.#n=e;let s=this.stored();if(s.session={token:t,expires_at:e.expires_at,sub:n},e.visitor_id)s.visitor_id=e.visitor_id;else if(e.contact.identified)delete s.visitor_id;return this.#y(s),e}}function O(e){return new D(e)}export{O as createYuvaClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var s=()=>{};function K(e){if(typeof window>"u"||!e.key)return{pageview:s,track:s,notFound:s,consent:s,optOut:s,optIn:s,destroy:s};let r=navigator,c=document,b=()=>{try{return localStorage}catch{}},x=`${e.server.replace(/\/$/,"")}/client/v1/analytics/${e.key}`,E=e.hash,k=r.globalPrivacyControl||r.doNotTrack=="1"||r.webdriver,l=k||b()?.getItem("yuva_optout")=="1",h=!e.consent,o=[],T="",p="",_=c.referrer,y=0,w=0,f=0,P=(t)=>{let n=JSON.stringify(o[1]?{e:o}:o[0]);if(o[0]&&(o=[],!(t&&r.sendBeacon?.(x,n))))fetch(x,{method:"POST",body:n,keepalive:!0,credentials:"omit"}).then((a)=>void(a.status==403&&(l=k=!0)),s)},O=(t)=>{if(l||!h)return;if(E)t.h=!0;if(e.consent)t.c={a:1};if(o.push(t)<2)setTimeout(P)},v=()=>{let t=Date.now();if(w)y+=t-w;w=c.visibilityState=="visible"&&c.hasFocus()?t:0},S=()=>{f=Math.max(f,Math.min(100,Math.round((scrollY+innerHeight)/c.documentElement.scrollHeight*100))||0)},q=()=>{if(v(),p&&y>0)O({n:"engagement",u:p,ms:Math.min(y,1800000),sd:f});y=0,f=0,S()},C=()=>location.pathname+(E?location.hash:""),M=(t={})=>{if(l||!h)return;q(),T=C(),p=t.url||location.href,O({n:"pageview",u:p,r:t.referrer??_,w:innerWidth}),_=void 0},g=(t,{props:n,revenue:a}={})=>O({n:t,u:p||location.href,p:n,$:a&&{a:a.amount,c:a.currency}}),u=()=>!e.manual&&T!=C()&&M(),A=()=>{q(),P(!0)},H=()=>{l=!0,o=[],b()?.setItem("yuva_optout","1")},I=()=>{l=k,b()?.removeItem("yuva_optout")},N=history.pushState,U=function(...t){N.apply(this,t),u()};history.pushState=U;let d={popstate:u,hashchange:u,prerenderingchange:u,scroll:S,focus:v,blur:v,pagehide:A,visibilitychange:()=>c.visibilityState=="hidden"?A():v(),click:(t)=>{let n=t.target.closest?.("a");if(!n)return;let a=n.getAttribute("href"),Y=a=="#yuva-optout"?H:a=="#yuva-optin"?I:0,F=e.files&&/\.(pdf|zip|dmg|exe|apk|csv|xlsx?|docx?|pptx?|mp[34])$/i.test(n.pathname)?"file_download":e.outbound&&n.host!=location.host&&"outbound_click";if(Y)t.preventDefault(),Y();else if(F&&/^https?:/.test(n.href))g(F,{props:{url:n.href}})}};if(e.chat)d["yuva-open"]=()=>g("chat_open");for(let t in d)addEventListener(t,d[t],!0);if(!c.prerendering)u();return{pageview:M,track:g,notFound:()=>g("not_found"),consent:(t)=>{if(h=t===!0||!!t.analytics,h)u();else o=[]},optOut:H,optIn:I,destroy:()=>{if(A(),l=!0,history.pushState==U)history.pushState=N;for(let t in d)removeEventListener(t,d[t],!0)}}}var L=document.currentScript,i=L?.dataset??{},m=window,B=K({key:i.key??"",server:i.api??new URL(L?.src??"/",location.href).origin,hash:"hash"in i,consent:i.consent,manual:"manual"in i,outbound:"outbound"in i,files:"files"in i,chat:"chat"in i}),D=([e,...r])=>B[e]?.(...r),R=m.yuvaq;m.yuva=Object.assign(m.yuva??{},B);m.yuvaq={push:D};R?.forEach?.(D);})();
|
package/dist/yuva-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var S=(e)=>typeof e==="string",
|
|
1
|
+
var S=(e)=>typeof e==="string",ke=(e)=>typeof e==="function",V=new Map,Z="en";function j(e){return[...Array.isArray(e)?e:[e],Z]}function B(e,t,i){let n=j(e);if(!i)i="default";let s;if(typeof i==="string")switch(s={day:"numeric",month:"short",year:"numeric"},i){case"full":s.weekday="long";case"long":s.month="long";break;case"short":s.month="numeric";break}else s=i;return R(()=>D("date",n,i),()=>new Intl.DateTimeFormat(n,s)).format(S(t)?new Date(t):t)}function Ce(e,t,i){let n;if(!i)i="default";if(typeof i==="string")switch(n={second:"numeric",minute:"numeric",hour:"numeric"},i){case"full":case"long":n.timeZoneName="short";break;case"short":delete n.second}else n=i;return B(e,t,n)}function N(e,t,i){let n=j(e);return R(()=>D("number",n,i),()=>new Intl.NumberFormat(n,i)).format(t)}function X(e,t,i,{offset:n=0,...s}){let o=j(e),a=t?R(()=>D("plural-ordinal",o),()=>new Intl.PluralRules(o,{type:"ordinal"})):R(()=>D("plural-cardinal",o),()=>new Intl.PluralRules(o,{type:"cardinal"}));return s[i]??s[a.select(i-n)]??s.other}function R(e,t){let i=e(),n=V.get(i);if(!n)n=t(),V.set(i,n);return n}function D(e,t,i){let n=t.join("-");return`${e}-${n}-${JSON.stringify(i)}`}var ee=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,te=(e)=>e.replace(/\\u([a-fA-F0-9]{4})|\\x([a-fA-F0-9]{2})/g,(t,i,n)=>{if(i){let s=parseInt(i,16);return String.fromCharCode(s)}else{let s=parseInt(n,16);return String.fromCharCode(s)}}),ie="%__lingui_octothorpe__%",Se=(e,t,i={})=>{let n=t||e,s=(a)=>{if(typeof a==="object")return a;return i[a]},o=(a,l)=>{let c=Object.keys(i).length?s("number"):void 0,h=N(n,a,c);return l.replace(new RegExp(ie,"g"),h)};return{plural:(a,l)=>{let{offset:c=0}=l,h=X(n,!1,a,l);return o(a-c,h)},selectordinal:(a,l)=>{let{offset:c=0}=l,h=X(n,!0,a,l);return o(a-c,h)},select:_e,number:(a,l)=>N(n,a,s(l)||{style:l}),date:(a,l)=>B(n,a,s(l)||l),time:(a,l)=>Ce(n,a,s(l)||l)}},_e=(e,t)=>(Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0)??t.other;function Pe(e,t,i){return(n={},s)=>{let o=Se(t,i,s),a=(c,h=!1)=>{if(!Array.isArray(c))return c;return c.reduce((p,u)=>{if(u==="#"&&h)return p+ie;if(S(u))return p+u;let[y,g,_]=u,b={};if(g==="plural"||g==="selectordinal"||g==="select")Object.entries(_).forEach(([v,k])=>{b[v]=a(k,g==="plural"||g==="selectordinal")});else b=_;let d;if(g){let v=o[g];d=v(n[y],b)}else d=n[y];if(d==null)return p;return p+d},"")},l=a(e);if(S(l)&&ee.test(l))return te(l);if(S(l))return l;return l?String(l):""}}class ne{_events={};on(e,t){return this._events[e]??=new Set,this._events[e].add(t),()=>this.removeListener(e,t)}removeListener(e,t){let i=this._events[e];if(i?.delete(t),i?.size===0)delete this._events[e]}emit(e,...t){let i=this._events[e];if(!i)return;for(let n of[...i])n.apply(this,t)}}class se extends ne{_locale="";_locales;_messages={};_missing;_messageCompiler;constructor(e){super();if(e.missing!=null)this._missing=e.missing;if(e.messages!=null)this.load(e.messages);if(typeof e.locale==="string"||e.locales)this.activate(e.locale??Z,e.locales)}get locale(){return this._locale}get locales(){return this._locales}get messages(){return this._messages[this._locale]??{}}setMessagesCompiler(e){return this._messageCompiler=e,this}_load(e,t){let i=Object.prototype.hasOwnProperty.call(this._messages,e)?this._messages[e]:void 0;if(!i)this._messages[e]=t;else Object.assign(i,t)}load(e,t){if(typeof e=="string"&&typeof t==="object")this._load(e,t);else Object.entries(e).forEach(([i,n])=>this._load(i,n));this.emit("change")}loadAndActivate({locale:e,locales:t,messages:i}){this._locale=e,this._locales=t||void 0,this._messages[this._locale]=i,this.emit("change")}activate(e,t){this._locale=e,this._locales=t,this.emit("change")}_(e,t,i){if(!this.locale)throw Error("Lingui: Attempted to call a translation function without setting a locale.\nMake sure to call `i18n.activate(locale)` before using Lingui functions.\nThis issue may also occur due to a race condition in your initialization logic.");let n=i?.message;if(!e)e="";if(!S(e))t=e.values||t,n=e.message,e=e.id;let s=this.messages,o=Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0,a=o===void 0,l=this._missing;if(l&&a)return ke(l)?l(this._locale,e):l;if(a)this.emit("missing",{id:e,locale:this._locale});let c=o||n||e;if(S(c))if(this._messageCompiler)c=this._messageCompiler(c);else console.warn(`Uncompiled message detected! Message:
|
|
2
2
|
|
|
3
3
|
> ${c}
|
|
4
4
|
|
|
@@ -6,17 +6,17 @@ That means you use raw catalog or your catalog doesn't have a translation for th
|
|
|
6
6
|
ICU features such as interpolation and plurals will not work properly for that message.
|
|
7
7
|
|
|
8
8
|
Please compile your catalog first.
|
|
9
|
-
`);if(S(c)&&Z.test(c))return ee(c);if(S(c))return c;return Ce(c,this._locale,this._locales)(t,i?.formats)}t=this._.bind(this);date(e,t){return N(this._locales||this._locale,e,t)}number(e,t){return U(this._locales||this._locale,e,t)}}function B(e={}){return new ne(e)}var $e=B();var Y=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var se=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function re(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function oe(e){return`yuva:${e}`}function K(e){try{let t=localStorage.getItem(oe(e));return t?JSON.parse(t):{}}catch{return{}}}function ae(e,t){try{localStorage.setItem(oe(e),JSON.stringify(t))}catch{}}class f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function le(e,t,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await e(t+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new f(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}class F{server;socketClass;handlers;#s=null;#m=0;#n=0;#r=null;#y=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#y=!1,!this.#s)this.#a()}stop(){if(this.#y=!0,this.#r)clearTimeout(this.#r);this.#r=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#m=0}nudge(){if(this.#y||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let e=this.handlers.token();if(!e||this.#y)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#m>0)t.searchParams.set("last_event_id",String(this.#m));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#u();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#m=Math.max(this.#m,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#m=Math.max(this.#m,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#y)return;if(n.code===1008){this.#m=0,this.handlers.sessionEnded();return}this.#u()}}#u(){if(this.#y||this.#r)return;let e=this.#n++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},t)}}function Se(e,t,i){let n=new URL("/account/connect",e);return n.searchParams.set("channel",t),n.searchParams.set("origin",i),n.href}function _e(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 ce(e,t,{width:i=460,height:n=640}={}){let s=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??n)-n)/2),c=window.open(Se(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${n},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(_)},g=(b)=>{if(u||b.origin!==s||b.source&&b.source!==c)return;let d=b.data;if(!_e(d)||d.channel_key!==t||d.origin!==o)return;y();try{c.close()}catch{}h({token:d.token,expires_at:d.expires_at,reader:d.reader})},_=setInterval(()=>{let b=!1;try{b=c.closed}catch{}if(!b)return;clearInterval(_),setTimeout(()=>{if(u)return;y(),p(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function de(e){return`yuva:${e}`}function he(e,t){return`yuva:reader:${e} ${t}`}function I(){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 Pe(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 Te(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,i)=>void e.set(t,i)}}function J(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))if(s!==void 0)t.set(n,String(s));let i=t.toString();return i?`?${i}`:""}function Ee(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Re(e,t,i){let n=[];for(let[s,o]of e)n.push(`--${i}\r
|
|
9
|
+
`);if(S(c)&&ee.test(c))return te(c);if(S(c))return c;return Pe(c,this._locale,this._locales)(t,i?.formats)}t=this._.bind(this);date(e,t){return B(this._locales||this._locale,e,t)}number(e,t){return N(this._locales||this._locale,e,t)}}function K(e={}){return new se(e)}var je=K();var Y=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var re=JSON.parse('{"-HY5kX":["Neue Unterhaltung"],"-f5Tkb":["Schlecht"],"09Tv5j":["Verbindung wird wiederhergestellt…"],"0XGLbP":["Ihre Anmeldung ist abgelaufen. Laden Sie die Seite neu und versuchen Sie es erneut."],"1EICzz":["Wir sind gerade nicht da"],"4TqZiz":["Ihre Bewertung konnte nicht gesendet werden. Versuchen Sie es erneut."],"6Uau97":["Überspringen"],"6gRgw8":["Erneut versuchen"],"6lGaum":["Gesehen"],"ASr-r0":["Ältere Unterhaltungen anzeigen"],"Amai22":["Der Chat ist gerade nicht verfügbar."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"JkW3Ph":["Dieser Dateityp wird nicht akzeptiert."],"JlFcis":["Senden"],"KDw4GX":["Erneut versuchen"],"M62PBt":["Gerade ist niemand erreichbar. Hinterlassen Sie Ihre E-Mail-Adresse, dann senden wir die Antwort auch dorthin."],"N7m8E-":["Dateien anhängen"],"NBdIgR":["Kommentar"],"OEEQKT":["Gut"],"Pwqkdw":["Wird geladen…"],"PxYAul":["Schreibt…"],"RzWUUK":["Nachricht schreiben…"],"S63MQu":["Alle Unterhaltungen"],"SOk0EB":["Danke für Ihr Feedback"],"Sad2tK":["Wird gesendet…"],"SdV5Cn":["Schreiben Sie uns, wir antworten hier."],"UY1vmE":["Anhang"],"VggdQJ":["Übliche Antwortzeit: ",["duration"]],"XJURKP":["E-Mail-Adresse"],"YyNOE7":["Unterhaltung"],"ZxJcgC":["Ihre E-Mail-Adresse konnte nicht gespeichert werden. Versuchen Sie es erneut."],"axQ1h6":["Möchten Sie noch etwas ergänzen? (optional)"],"eOu9Px":["Die Datei ist zu groß."],"h69WC6":["Gesendet"],"iGNUZJ":["Danke! Falls Sie nicht mehr da sind, wenn wir antworten, schreiben wir Ihnen an ",["known"],"."],"meAa31":["Noch keine Unterhaltungen"],"nhTADq":["Wir antworten so schnell wie möglich"],"njBr8W":["sie@beispiel.de"],"oXOSPE":["Online"],"t7TeQU":["Nachrichten"],"tHaDPf":[["name"]," schreibt…"],"tfDRzk":["Speichern"],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"uA8iBc":["Wie zufrieden waren Sie?"],"upFvcp":["Nicht gesendet."],"w61W3L":[["0"]," entfernen"],"xDAtGP":["Nachricht"],"ydzYKJ":["Sie:"],"yz7wBu":["Schließen"],"zLzEI3":["Melden Sie sich an, um mit uns zu chatten."]}');var oe=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function ae(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function le(e){return`yuva:${e}`}function F(e){try{let t=localStorage.getItem(le(e));return t?JSON.parse(t):{}}catch{return{}}}function ce(e,t){try{localStorage.setItem(le(e),JSON.stringify(t))}catch{}}class f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function I(e,t,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await e(t+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new f(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}function de(e,t,i){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function he(e,t,i,n){return I(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:n})}class W{server;socketClass;handlers;#s=null;#m=0;#n=0;#r=null;#y=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#y=!1,!this.#s&&!this.#r)this.#a()}stop(){if(this.#y=!0,this.#r)clearTimeout(this.#r);this.#r=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#m=0}nudge(){if(this.#y||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let e=this.handlers.token();if(!e||this.#y)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#m>0)t.searchParams.set("last_event_id",String(this.#m));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#u();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#m=Math.max(this.#m,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#m=Math.max(this.#m,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#y)return;if(n.code===1008){this.#m=0,this.handlers.sessionEnded();return}this.#u()}}#u(){if(this.#y||this.#r)return;let e=this.#n++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},t)}}function Ee(e,t,i){let n=new URL("/account/connect",e);return n.searchParams.set("channel",t),n.searchParams.set("origin",i),n.href}function Te(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function ue(e,t,{width:i=460,height:n=640}={}){let s=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??n)-n)/2),c=window.open(Ee(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${n},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(_)},g=(b)=>{if(u||b.origin!==s||b.source&&b.source!==c)return;let d=b.data;if(!Te(d)||d.channel_key!==t||d.origin!==o)return;y();try{c.close()}catch{}h({token:d.token,expires_at:d.expires_at,reader:d.reader})},_=setInterval(()=>{let b=!1;try{b=c.closed}catch{}if(!b)return;clearInterval(_),setTimeout(()=>{if(u)return;y(),p(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function pe(e){return`yuva:${e}`}function fe(e,t){return`yuva:reader:${e} ${t}`}function M(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function ze(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(t));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Re(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,i)=>void e.set(t,i)}}function J(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))if(s!==void 0)t.set(n,String(s));let i=t.toString();return i?`?${i}`:""}function De(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Ie(e,t,i){let n=[];for(let[s,o]of e)n.push(`--${i}\r
|
|
10
10
|
Content-Disposition: form-data; name="${s}"\r
|
|
11
11
|
\r
|
|
12
12
|
${o}\r
|
|
13
13
|
`);for(let s of t){let o=s.name||"file";n.push(`--${i}\r
|
|
14
|
-
Content-Disposition: form-data; name="files"; filename="${
|
|
14
|
+
Content-Disposition: form-data; name="files"; filename="${De(o)}"\r
|
|
15
15
|
Content-Type: ${s.type||"application/octet-stream"}\r
|
|
16
16
|
\r
|
|
17
17
|
`,s,`\r
|
|
18
18
|
`)}return n.push(`--${i}--\r
|
|
19
|
-
`),new Blob(n)}class
|
|
19
|
+
`),new Blob(n)}class ge{server;channel;#s;#m;#n;#r;#y;#a=null;#u=null;#w=null;#k=null;#t=null;#v;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,i)=>fetch(t,i)),this.#m=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??Re(),this.#r=e.identityToken??null,this.#y=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#u}get token(){return this.#a}get connected(){return this.#t?.connected??!1}on(e,t){let i=this.#p.get(e);if(!i)this.#p.set(e,i=new Set);return i.add(t),()=>void i.delete(t)}#c(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(pe(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#C(e){try{this.#n.setItem(pe(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}lists(){return de(this.#s,this.server,this.channel)}subscribe(e){return he(this.#s,this.server,this.channel,e)}subscriptions(){return this.#l("/client/v1/subscriptions")}subscribeList(e,t){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"PUT",json:t})}unsubscribeList(e){return this.#l(`/client/v1/subscriptions/${encodeURIComponent(e)}`,{method:"DELETE"})}setIdentityToken(e){this.#r=e,this.reset()}start(){if(this.#u)return Promise.resolve(this.#u);return this.#w??=this.#I(!1).then((e)=>(this.#c("session",{session:e,renewed:!1}),e)).finally(()=>{this.#w=null}),this.#w}async refresh(){let e=await this.#l("/client/v1/session");return this.#u={...this.#u,...e},this.#c("session",{session:this.#u,renewed:!1}),this.#u}reset(){this.#t?.stop(),this.#t?.reset(),this.#w=null,this.#k=null,this.#a=null,this.#u=null}async signOut(){let e=this.#a;this.reset();let t=this.stored();if(delete t.session,this.#C(t),e)await this.#f("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#m)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#t??=new W(this.server,this.#m,{token:()=>this.#a,event:(e)=>{if(e.type==="ready")this.#c("connection",{state:"open",attempt:0});this.#c("event",e)},sessionEnded:()=>void this.#D().catch(()=>this.#t?.nudge()),reconnecting:(e)=>{if(this.#c("connection",{state:"reconnecting",attempt:e}),e===2)this.#l("/client/v1/session").catch(()=>{return})}}),!this.#t.connected)this.#c("connection",{state:"connecting",attempt:0});this.#t.start()}disconnect(){this.#t?.stop(),this.#c("connection",{state:"closed",attempt:0})}reconnect(){this.#t?.nudge()}listConversations(e={}){return this.#l(`/client/v1/conversations${J({...e})}`)}getConversation(e){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#l("/client/v1/conversations",this.#z(e))}listMessages(e,t={}){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages${J({...t})}`)}sendMessage(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#z(t))}markRead(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let n={rating:t,comment:i?.trim()||void 0};return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:n})}setTyping(e,t){return this.#l(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#l("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#l(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??M();return this.#l("/client/v1/feedback",{method:"POST",headers:this.#x(t),json:{...e,client_id:t}})}get reader(){if(this.#v===void 0)try{let e=this.#n.getItem(fe(this.server,this.channel));this.#v=e?JSON.parse(e):null}catch{this.#v=null}if(this.#v&&Date.parse(this.#v.expires_at)<=Date.now()+30000)this.#i(null);return this.#v}#i(e){let t=this.#v?.token!==e?.token;this.#v=e;try{this.#n.setItem(fe(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#c("reader",e)}readerSignIn(e){return ue(this.server,this.channel,e).then((t)=>(this.#i(t),t))}setReader(e){this.#i(e)}async readerSignOut(){let e=this.reader?.token;if(this.#i(null),e)await this.#f("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${J({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#b("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#b(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#u)return this.#u.contact.identified?"contact":null;return await this.#r?.()?"contact":null}async#b(e,t,i=!0){let n=this.reader;if(n)try{return await this.#f(e,{...t,token:n.token})}catch(o){if(!(o instanceof f)||o.status!==401||this.#v?.token!==n.token)throw o;if(this.#i(null),i)throw new f(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#l(e,t);if(i)throw new f(403,"sign_in_required");return this.#f(e,t)}#x(e){return this.#y&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#z({body:e,subject:t,files:i=[],client_id:n=M()}){let s=this.#x(n);if(i.length===0)return{method:"POST",headers:s,json:{body:e,subject:t,client_id:n}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",n]);let a=`yuva-${n.replace(/[^\w-]/g,"").slice(0,60)}-${n.length}`;return s["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:s,body:Ie(o,i,a)}}#f(e,t){return I(this.#s,this.server,e,t)}async#l(e,t={},i=!0){if(!this.#a)await this.start();try{return await this.#f(e,{...t,token:this.#a})}catch(n){if(!i||!(n instanceof f)||n.status!==401)throw n;return await this.#D(),this.#l(e,t,!1)}}#D(){return this.#k??=(async()=>{let e=await this.#I(!0);if(this.#t)this.#t.stop(),this.#t.reset(),this.#t.start();this.#c("session",{session:e,renewed:!0})})().finally(()=>{this.#k=null}),this.#k}async#I(e){let t=this.stored(),i=await this.#r?.()||null,n=i?ze(i):null,s=t.session;if(!e&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#f("/client/v1/session",{token:s.token});return this.#M(c,s.token,n)}catch(c){if(!(c instanceof f)||c.status!==401&&c.status!==403)throw c}let o=await this.#f("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=o;return this.#M(l,a,n)}#M(e,t,i){this.#a=t,this.#u=e;let n=this.stored();if(n.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)n.visitor_id=e.visitor_id;else if(e.contact.identified)delete n.visitor_id;return this.#C(n),e}}function me(e){return new ge(e)}var ye=`
|
|
20
20
|
[hidden] { display: none !important; }
|
|
21
21
|
.header {
|
|
22
22
|
display: flex;
|
|
@@ -208,6 +208,6 @@ Content-Type: ${s.type||"application/octet-stream"}\r
|
|
|
208
208
|
.banner { padding: 6px 12px; background: var(--yuva-soft); color: var(--yuva-muted); font-size: 13px; text-align: center; }
|
|
209
209
|
@media (max-width: 480px) { .composer textarea, .card input, .card textarea { font-size: 16px; } }
|
|
210
210
|
.sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
211
|
-
`;var
|
|
211
|
+
`;var Me=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Le(e,t){let i=document.createElement("a");return i.href=e,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function G(e,t){let i=document.createElement(e);return i.append(...t),i}function q(e){let t=[],i=0;for(let n of e.matchAll(Me)){let s=n.index??0;if(s>i)t.push(document.createTextNode(e.slice(i,s)));let[o,a,l,c,h]=n;if(a)t.push(G("code",[document.createTextNode(a.slice(1,-1))]));else if(l)t.push(G("strong",q(l.slice(2,-2))));else if(c)t.push(G("em",q(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);t.push(u.protocol==="http:"||u.protocol==="https:"?Le(u.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=s+o.length}if(i<e.length)t.push(document.createTextNode(e.slice(i)));return t}function L(e){let t=document.createDocumentFragment(),i=e.trim().replace(/\r\n?/g,`
|
|
212
212
|
`).split(/^```[^\n]*\n([\s\S]*?)^```[ \t]*$/m);return i.forEach((n,s)=>{if(s%2===1){let a=document.createElement("pre");a.textContent=n.replace(/\n$/,""),t.append(a);return}(i.length>1?n.replace(/^\n|\n$/g,""):n).split(`
|
|
213
|
-
`).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...G(a))})}),t}var Ie={en:Y,tr:se},Me=10,ge=300000,P={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}function R(e,t,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=e,s.setAttribute("aria-label",t),s.title=t,s.addEventListener("click",i),s}var x=(e)=>Date.parse(e),me=(e,t)=>x(e.created_at)-x(t.created_at),Le=(e,t)=>x(t.last_message_at??t.created_at)-x(e.last_message_at??e.created_at),L=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,Oe=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class ye{#s;#m;#n;#r=null;#y=null;#a="loading";#u="";#w=null;#C=null;#t=new Map;#v;#p=new Map;#l=[];#k=new Map;#i=null;#b=!1;#x=[];#R=0;#f=null;#c=new Map;#D=new Map;#I=new Map;#M=!1;#S="";#q=!1;#_=new Map;#ke=r("div","card rate");#g=r("textarea");#Q="";#re=null;#X=r("header","header");#V=r("div","banner");#$=r("div","body");#d=r("div","scroll");#P=r("div","card");#T=r("input");#oe=r("div","composer");#Z=r("div","chips");#h=r("textarea");#E=r("input");#U;#Y;#ee=r("div","sr");#K;#L=!0;constructor(e){this.#s=e;let{server:t,channel:i}=e.config();this.#n=pe({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#n.on("event",(s)=>this.#_e(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#b=o>0,this.#ne()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#J(s.inbox),this.#y=s.contact,o)this.#pe()}),this.#le(),this.#ee.setAttribute("aria-live","polite"),this.#d.addEventListener("scroll",()=>{if(this.#L=this.#d.scrollHeight-this.#d.scrollTop-this.#d.clientHeight<48,this.#d.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#G(this.#i.id,!0)}),this.#h.rows=1,this.#h.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#ie()}),this.#h.addEventListener("input",()=>{this.#ge(),this.#B(),this.#Ee()}),this.#h.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#fe(o)}),this.#E.type="file",this.#E.multiple=!0,this.#E.hidden=!0,this.#E.addEventListener("change",()=>{this.#fe(Array.from(this.#E.files??[])),this.#E.value=""}),this.#Y=R(P.attach,"",()=>this.#E.click()),this.#U=R(P.send,"",()=>void this.#ie(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#ie()}),n.append(this.#Y,this.#h,this.#U,this.#E),this.#oe.append(this.#Z,n),this.#T.type="email",this.#T.required=!0,this.#T.autocomplete="email",this.#g.rows=2,this.#g.maxLength=2000,this.#g.dir="auto",document.addEventListener("visibilitychange",this.#F),window.addEventListener("online",this.#F),this.#we(),this.#j()}update(){this.#le(),this.#we()}opened(){if(this.#a==="error"){this.#w=null,this.#j();return}if(this.#a==="ready")this.#n.token?this.#Se():this.#ce().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#z(),this.#N(),this.#s.config().layout==="launcher")this.#h.focus({preventScroll:!0})}closed(){this.#A()}identityChanged(){this.#ae(),this.#j()}async signOut(){let e=this.#n.signOut();if(this.#ae(),await e,this.#s.isOpen())this.#j();else this.#o()}destroy(){this.#n.reset(),this.#A(),document.removeEventListener("visibilitychange",this.#F),window.removeEventListener("online",this.#F);for(let e of this.#c.values())URL.revokeObjectURL(e)}#ae(){this.#n.reset(),this.#w=null,this.#C=null,this.#r=null,this.#y=null,this.#a="loading",this.#t.clear(),this.#p.clear(),this.#l=[],this.#_.clear(),this.#Q="",this.#i=null,this.#q=!1,this.#s.setUnread(0)}#F=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#N(),this.#he()};#le(){let{locale:e}=this.#s.config();this.#m=B({locale:e,messages:{[e]:Ie[e]??Y}})}#e(e){return this.#m._(e)}#j(){return this.#w??=(async()=>{this.#a="loading",this.#o();let{channel:e}=this.#s.config();if(!e)throw new f(0,"not_configured");if(await this.#s.identityToken()||K(e).session)await this.#Ce();else if(await this.#ce(),!this.#r?.chat.allow_anonymous)throw new f(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let t=this.#xe();if(this.#i=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#G(this.#i.id)}this.#o(),this.#z(),this.#N()})().catch((e)=>{if(this.#w=null,this.#ue(e))return;this.#a="error",this.#u=e instanceof f?e.code:"error",this.#o()}),this.#w}async#ce(){let e=await this.#de();if(!this.#n.token)this.#J(e)}#de(){if(!this.#s.config().channel)throw new f(0,"not_configured");return this.#n.channelSettings()}#J(e){let{channel:t}=this.#s.config();this.#r=e;let i=re(e);if(this.#s.setLauncher(i),t)ae(t,{...K(t),launcher:i})}async#he(){if(this.#a!=="ready")return;try{this.#J(await this.#de()),this.#o()}catch(e){this.#ue(e,!0)}}#ue(e,t=!this.#n.token){let i=e instanceof f&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#s.refused();return i}#Ce(){return this.#C??=(async()=>{await this.#n.start(),await this.#W(),await this.#n.connect()})().finally(()=>{this.#C=null}),this.#C}async#Se(){try{await this.#n.refresh(),this.#o()}catch{}}async#W(e=!1){let t=await this.#n.listConversations({limit:50,cursor:e?this.#v:void 0});if(!e)this.#t.clear();for(let i of t.items)this.#t.set(i.id,i);this.#v=t.next_cursor,this.#O()}async#pe(){await this.#W();let e=this.#i?.kind==="thread"?this.#i.id:null;for(let t of this.#p.keys())if(t!==e)this.#p.delete(t);if(e)this.#p.delete(e),await this.#G(e);this.#o()}async#G(e,t=!1){let i=this.#p.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#p.set(e,i);if(i.loading||t&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#d.scrollHeight-this.#d.scrollTop;try{let s=await this.#n.listMessages(e,{order:"desc",limit:30,cursor:t?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(me),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#o(),this.#d.scrollTop=this.#d.scrollHeight-n}#_e(e){switch(e.type){case"ready":if(this.#b=!1,this.#ne(),this.#q)this.#he();this.#q=!0;return;case"inbox.updated":{let t=this.#r?.ask_for_rating;if(this.#J(e.data),t!==void 0&&t!==e.data.ask_for_rating)this.#W().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pe();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#t.has(e.data.id))this.#t.set(e.data.id,e.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#t.size>1)this.#i=this.#l.some((t)=>t.conversation===null)?this.#i:{kind:"list"};this.#O();break;case"conversation.updated":{let t=this.#t.get(e.data.id),{status:i,can_rate:n,rating:s}=e.data;if(t)this.#t.set(t.id,{...t,status:i,can_rate:n,rating:s});if(!n)this.#_.delete(e.data.id);break}case"message.created":case"message.updated":this.#te(e.data,e.type==="message.created");break;case"read":{let t=this.#t.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||x(e.data.read_at)>x(i)))this.#t.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#k.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#k.set(t,{name:n,timer:setTimeout(()=>this.#k.delete(t)&&this.#o(),8000)})}else this.#k.delete(t);break}}this.#o()}#te(e,t){let i=e.conversation_id,n=this.#p.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===e.id);if(o>=0)n.messages[o]=e;else n.messages=[...n.messages,e].sort(me)}if(e.client_id)this.#l=this.#l.filter((o)=>o.client_id!==e.client_id);let s=this.#t.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#t.set(o.id,o),this.#O(),this.#o()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#t.set(i,{...s,last_message:{id:e.id,author_type:e.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:e.created_at},last_message_at:e.created_at,unread:s.unread||e.author.type!=="contact"}),e.author.type!=="contact"){let a=this.#k.get(i);if(a)clearTimeout(a.timer);this.#k.delete(i),this.#Pe(e)}}this.#O(),this.#N()}#Pe(e){this.#ee.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#O(){let e=0;for(let t of this.#t.values())if(t.unread)e++;this.#s.setUnread(e)}#Te(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#N(){let e=this.#Te(),t=e?this.#t.get(e):void 0;if(!e||!t?.unread)return;this.#t.set(e,{...t,unread:!1}),this.#O(),this.#n.markRead(e).catch(()=>{let i=this.#t.get(e);if(i)this.#t.set(e,{...i,unread:!0});this.#O()})}#fe(e){this.#x=[...this.#x,...e].slice(0,Me),this.#H(),this.#B(),this.#h.focus()}#ge(){if(this.#h.style.blockSize="",this.#h.value==="")return;this.#h.style.blockSize="auto",this.#h.style.blockSize=`${Math.max(38,Math.min(this.#h.scrollHeight,140))}px`}#B(){this.#U.disabled=this.#h.value.trim()===""&&this.#x.length===0}#Ee(){let e=this.#i?.kind==="thread"?this.#i.id:null;if(!e||this.#h.value.trim()===""){this.#A();return}if(Date.now()-this.#R>3000)this.#R=Date.now(),this.#n.setTyping(e,!0).catch(()=>{return});if(this.#f)clearTimeout(this.#f);this.#f=setTimeout(()=>this.#A(),4000)}#A(){if(this.#f)clearTimeout(this.#f);if(this.#f=null,this.#R===0)return;this.#R=0;let e=this.#i?.kind==="thread"?this.#i.id:null;if(e)this.#n.setTyping(e,!1).catch(()=>{return})}async#ie(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let e=this.#h.value.trim(),t=this.#x;if(!e&&t.length===0)return;if(this.#i.id===null&&this.#l.some((n)=>n.conversation===null))return;this.#A(),this.#h.value="",this.#x=[],this.#ge(),this.#H(),this.#B();let i={client_id:I(),conversation:this.#i.id,body:e,files:t,state:"sending"};this.#l.push(i),this.#o(),this.#z(),await this.#me(i)}async#me(e){e.state="sending",this.#o();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#n.startConversation(t),n=i.conversation.id;if(!this.#t.has(n))this.#t.set(n,i.conversation);if(!this.#p.has(n))this.#p.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#te(i.message,!1)}else{let i=await this.#n.sendMessage(e.conversation,t);this.#te(i,!0)}this.#l=this.#l.filter((i)=>i!==e)}catch(i){let n=i instanceof f?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#o(),this.#z()}async rate(e,t,i){try{let n=await this.#n.rate(e,t,i);return this.#t.set(n.id,n),this.#_.delete(e),this.#o(),n}catch(n){if(n instanceof f&&n.status===409){let s=await this.#n.getConversation(e).catch(()=>null);if(s)this.#t.set(s.id,s);this.#_.delete(e),this.#o()}throw n}}#Re(e,t){if(this.#_.get(e)?.state==="sending")return;if(this.#_.set(e,{choice:t,state:"choosing"}),this.#o(),this.#g.focus({preventScroll:!0}),this.#L)this.#z()}async#ye(e,t){let i=this.#_.get(e);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(e,i.choice,t?this.#g.value:void 0),this.#g.value=""}catch(n){if(n instanceof f&&n.status===409)return;i.state="failed",this.#o()}}async#ze(){let e=this.#T.value.trim();if(!e||!this.#T.checkValidity()){this.#S=this.#e({id:"E_qvzP"}),this.#se();return}try{this.#y=await this.#n.setEmail(e),this.#M=!0,this.#S=""}catch{this.#S=this.#e({id:"ZxJcgC"})}this.#se()}#ve(e){let t=this.#c.get(e.id);if(t)return Promise.resolve(t);let i=this.#D.get(e.id);if(!i)i=this.#n.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#c.set(e.id,s),s}),i.catch(()=>this.#D.delete(e.id)),this.#D.set(e.id,i);return i}async#be(e){let t=await this.#ve(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#xe(){return[...this.#t.values()].sort(Le)}#De(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#z(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#we(){this.#h.placeholder=this.#e({id:"RzWUUK"}),this.#h.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#Y.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#Y.title=this.#e({id:"N7m8E-"}),this.#U.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#U.title=this.#e({id:"JlFcis"}),this.#T.placeholder=this.#e({id:"njBr8W"}),this.#T.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#B(),this.#H(),this.#o()}#o(){let e=this.#s.panel;if(e.childElementCount===0){let t=r("style");t.textContent=fe,e.append(t,this.#X,this.#V,this.#$,this.#ee),this.#X.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#Me(),this.#ne(),this.#a!=="ready"){this.#K=void 0;let t=r("div","center");if(this.#a==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Ie()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#w=null,this.#j()}),t.append(i)}this.#$.replaceChildren(t);return}if(this.#i?.kind==="list")this.#Oe();else this.#Ue()}#Ie(){switch(this.#u){case"anonymous_not_allowed":return this.#e({id:"zLzEI3"});case"invalid_identity_token":return this.#e({id:"0XGLbP"});case"rate_limited":return this.#e({id:"tzsBOP"});case"network":return this.#e({id:"GQVIIl"});default:return this.#e({id:"Amai22"})}}#Me(){let{layout:e}=this.#s.config(),t=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#t.size>1||n.id===null&&this.#t.size>0))i.push(R(P.back,this.#e({id:"S63MQu"}),()=>{this.#A(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",t?.name||this.#e({id:"t7TeQU"}))),t){let o=r("div","status");if(t.mode==="live"&&t.open_now&&t.presence?.available){let l=r("div","avatars");for(let c of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#e({id:"oXOSPE"})))}else if(!t.open_now||t.mode==="live")o.append(r("span","dot away"),r("span","",this.#e({id:"1EICzz"})));else o.append(r("span","",this.#Le(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(R(P.close,this.#e({id:"yz7wBu"}),()=>this.#s.close()));this.#X.replaceChildren(...i)}#Le(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#s.config(),[i,n]=e<60?[e,"minute"]:e<1440?[Math.round(e/60),"hour"]:[Math.round(e/1440),"day"],s=new Intl.NumberFormat(t,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#e({id:"VggdQJ",values:{duration:s}})}#ne(){this.#V.hidden=!this.#b,this.#V.textContent=this.#e({id:"09Tv5j"})}#Oe(){this.#K=void 0;let{locale:e}=this.#s.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#xe()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#e({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Ae(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#v){let s=r("button","link",this.#e({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#W(!0).then(()=>this.#o())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#h.focus()}),this.#$.replaceChildren(t,n)}async#Ae(e){if(this.#i={kind:"thread",id:e},this.#o(),!this.#p.get(e)?.complete&&!this.#p.get(e)?.messages.length)await this.#G(e).catch(()=>{return});this.#o(),this.#z(),this.#N()}#$e(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#I.get(i):!1;if(!i||n===!1)return t;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,t.replaceChildren(s),t;return s.addEventListener("load",()=>{if(this.#I.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#I.set(i,!1)),s.src=i,t}#Ue(){let e=this.#i;if(e?.kind!=="thread")return;let t=e.id,i=this.#K===t,n=this.#L,s=t?this.#p.get(t):void 0,o=s?.messages??[],a=this.#l.filter((d)=>d.conversation===t),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(M(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((d,v)=>{let k=o[v-1],w=o[v+1]??(a.length>0?null:void 0),m=d.author.type==="contact",C=!k||L(k)!==L(d)||x(d.created_at)-x(k.created_at)>ge,H=w===void 0||(w===null?!m:L(w)!==L(d)||x(w.created_at)-x(d.created_at)>ge);if(!m&&C&&d.author.name)l.push(r("div","author",d.author.name));let O=r("div",`row ${m?"mine":"theirs"}${C&&v>0?" group-gap":""}`);if(!m){let E=this.#$e(d.author);if(!H)E.style.visibility="hidden";O.append(E)}let T=r("div","bubble");if(T.dir="auto",T.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())T.append(M(d.body));if(d.attachments.length>0)T.append(this.#Ne(d.attachments));if(O.append(T),l.push(O),H){let E=this.#Be(d.created_at);if(m&&v===o.length-1&&a.length===0){let q=t?this.#t.get(t)?.last_read_by_member_at:void 0,ve=q&&x(q)>=x(d.created_at);E+=` · ${ve?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let A=r("div","meta",E);if(!m)A.style.alignSelf="flex-start";if(!m)A.style.marginInlineStart="36px";l.push(A)}});let h=t?this.#t.get(t):void 0,p=h?this.#je(h):null;if(p)l.push(p);a.forEach((d,v)=>{let k=r("div",`row mine${v===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),w=r("div","bubble");if(w.dir="auto",d.body)w.append(M(d.body));if(d.files.length>0){let m=r("div","files");for(let C of d.files)m.append(r("span","file",C.name||"image"));w.append(m)}if(k.append(w),l.push(k),d.state==="failed"){let m=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),C=r("button","link",this.#e({id:"6gRgw8"}));C.type="button",C.addEventListener("click",()=>void this.#me(d)),m.append(C),l.push(m)}else if(d.state==="refused"){let m=d.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${m}`))}else if(v===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let u=t?this.#k.get(t):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let v=u.name;d.append(r("span","",v?this.#e({id:"tHaDPf",values:{name:v}}):this.#e({id:"PxYAul"}))),l.push(d)}let g=this.#d.getRootNode().activeElement===this.#g,{selectionStart:_,selectionEnd:b}=this.#g;if(this.#d.replaceChildren(...l),g&&this.#g.isConnected)this.#g.focus({preventScroll:!0}),this.#g.setSelectionRange(_,b);if(this.#se(),this.#$.firstChild!==this.#d)this.#$.replaceChildren(this.#d,this.#P,this.#oe);if(this.#K=t,!i||n)this.#z()}#je(e){let t=e.status==="closed"?e.rating:void 0,i=e.can_rate&&this.#r?.ask_for_rating?this.#_.get(e.id):void 0;if(!t&&!(e.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#ke,s=[e.id,t,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#re!==e.id)this.#re=e.id,this.#g.value="";let o=this.#e({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(t&&t!==u)continue;let y=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");y.type="button";let g=u==="good"?this.#e({id:"OEEQKT"}):this.#e({id:"-f5Tkb"});y.setAttribute("aria-label",g),y.title=g,y.setAttribute("aria-pressed",String((t??i?.choice)===u)),y.disabled=!!t||i?.state==="sending",y.addEventListener("click",()=>this.#Re(e.id,u)),a.append(y)}if(t)return n.replaceChildren(a,r("p","",this.#e({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#g.placeholder=this.#e({id:"axQ1h6"}),this.#g.setAttribute("aria-label",this.#e({id:"NBdIgR"})),this.#g.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#ye(e.id,!0)});let c=r("button","link",this.#e({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#ye(e.id,!1));let h=r("button","",i.state==="sending"?this.#e({id:"Sad2tK"}):this.#e({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#g,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#e({id:"4TqZiz"})));return n}#Ne(e){let t=r("div","files");for(let i of e)if(Oe(i)){let n=r("img");n.alt=i.filename;let s=this.#c.get(i.id);if(s)n.src=s;else this.#ve(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight}),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=P.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}return t}#Be(e){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(e))}#se(){let e=this.#y,t=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#l.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#De()&&n&&(!s||this.#M);if(this.#P.hidden=!o,!o)return;if(s&&this.#M){this.#P.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#P.querySelector("form")){let c=this.#P.querySelector(".error");if(c)c.textContent=this.#S;else if(this.#S)this.#P.append(r("p","error",this.#S));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#ze()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#T,l),this.#P.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#S)this.#P.append(r("p","error",this.#S))}#H(){this.#Z.hidden=this.#x.length===0,this.#Z.replaceChildren(...this.#x.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),R(P.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#x=this.#x.filter((n,s)=>s!==t),this.#H(),this.#B()})),i}))}}function Ae(e){return new ye(e)}export{Ae as mount};
|
|
213
|
+
`).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...q(a))})}),t}var Ae={en:Y,tr:oe,de:re},Oe=10,ve=300000,P={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}function z(e,t,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=e,s.setAttribute("aria-label",t),s.title=t,s.addEventListener("click",i),s}var x=(e)=>Date.parse(e),be=(e,t)=>x(e.created_at)-x(t.created_at),Ue=(e,t)=>x(t.last_message_at??t.created_at)-x(e.last_message_at??e.created_at),A=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,$e=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class xe{#s;#m;#n;#r=null;#y=null;#a="loading";#u="";#w=null;#k=null;#t=new Map;#v;#p=new Map;#c=[];#C=new Map;#i=null;#b=!1;#x=[];#z=0;#f=null;#l=new Map;#D=new Map;#I=new Map;#M=!1;#S="";#H=!1;#_=new Map;#ke=r("div","card rate");#g=r("textarea");#Q="";#re=null;#V=r("header","header");#X=r("div","banner");#U=r("div","body");#d=r("div","scroll");#P=r("div","card");#E=r("input");#oe=r("div","composer");#Z=r("div","chips");#h=r("textarea");#T=r("input");#$;#K;#ee=r("div","sr");#Y;#L=!0;constructor(e){this.#s=e;let{server:t,channel:i}=e.config();this.#n=me({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#n.on("event",(s)=>this.#_e(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#b=o>0,this.#ne()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#W(s.inbox),this.#y=s.contact,o)this.#pe();else if(!this.#k)this.#n.connect().catch(()=>{return})}),this.#le(),this.#ee.setAttribute("aria-live","polite"),this.#d.addEventListener("scroll",()=>{if(this.#L=this.#d.scrollHeight-this.#d.scrollTop-this.#d.clientHeight<48,this.#d.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#G(this.#i.id,!0)}),this.#h.rows=1,this.#h.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#ie()}),this.#h.addEventListener("input",()=>{this.#ge(),this.#B(),this.#Te()}),this.#h.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#fe(o)}),this.#T.type="file",this.#T.multiple=!0,this.#T.hidden=!0,this.#T.addEventListener("change",()=>{this.#fe(Array.from(this.#T.files??[])),this.#T.value=""}),this.#K=z(P.attach,"",()=>this.#T.click()),this.#$=z(P.send,"",()=>void this.#ie(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#ie()}),n.append(this.#K,this.#h,this.#$,this.#T),this.#oe.append(this.#Z,n),this.#E.type="email",this.#E.required=!0,this.#E.autocomplete="email",this.#g.rows=2,this.#g.maxLength=2000,this.#g.dir="auto",document.addEventListener("visibilitychange",this.#F),window.addEventListener("online",this.#F),this.#we(),this.#N()}update(){this.#le(),this.#we()}opened(){if(this.#a==="error"){this.#w=null,this.#N();return}if(this.#a==="ready")this.#n.token?this.#Se():this.#ce().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#R(),this.#j(),this.#s.config().layout==="launcher")this.#h.focus({preventScroll:!0})}closed(){this.#O()}identityChanged(){this.#ae(),this.#N()}async signOut(){let e=this.#n.signOut();if(this.#ae(),await e,this.#s.isOpen())this.#N();else this.#o()}destroy(){this.#n.reset(),this.#O(),document.removeEventListener("visibilitychange",this.#F),window.removeEventListener("online",this.#F);for(let e of this.#l.values())URL.revokeObjectURL(e)}#ae(){this.#n.reset(),this.#w=null,this.#k=null,this.#r=null,this.#y=null,this.#a="loading",this.#t.clear(),this.#p.clear(),this.#c=[],this.#_.clear(),this.#Q="",this.#i=null,this.#H=!1,this.#s.setUnread(0)}#F=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#j(),this.#he()};#le(){let{locale:e}=this.#s.config();this.#m=K({locale:e,messages:{[e]:Ae[e]??Y}})}#e(e){return this.#m._(e)}#N(){return this.#w??=(async()=>{this.#a="loading",this.#o();let{channel:e}=this.#s.config();if(!e)throw new f(0,"not_configured");if(await this.#s.identityToken()||F(e).session)await this.#Ce();else if(await this.#ce(),!this.#r?.chat.allow_anonymous)throw new f(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let t=this.#xe();if(this.#i=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#G(this.#i.id)}this.#o(),this.#R(),this.#j()})().catch((e)=>{if(this.#w=null,this.#ue(e))return;this.#a="error",this.#u=e instanceof f?e.code:"error",this.#o()}),this.#w}async#ce(){let e=await this.#de();if(!this.#n.token)this.#W(e)}#de(){if(!this.#s.config().channel)throw new f(0,"not_configured");return this.#n.channelSettings()}#W(e){let{channel:t}=this.#s.config();this.#r=e;let i=ae(e);if(this.#s.setLauncher(i),t)ce(t,{...F(t),launcher:i})}async#he(){if(this.#a!=="ready")return;try{this.#W(await this.#de()),this.#o()}catch(e){this.#ue(e,!0)}}#ue(e,t=!this.#n.token){let i=e instanceof f&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#s.refused();return i}#Ce(){return this.#k??=(async()=>{await this.#n.start(),await this.#J(),await this.#n.connect()})().finally(()=>{this.#k=null}),this.#k}async#Se(){try{await this.#n.refresh(),this.#o()}catch{}}async#J(e=!1){let t=await this.#n.listConversations({limit:50,cursor:e?this.#v:void 0});if(!e)this.#t.clear();for(let i of t.items)this.#t.set(i.id,i);this.#v=t.next_cursor,this.#A()}async#pe(){await this.#J();let e=this.#i?.kind==="thread"?this.#i.id:null;for(let t of this.#p.keys())if(t!==e)this.#p.delete(t);if(e)this.#p.delete(e),await this.#G(e);this.#o()}async#G(e,t=!1){let i=this.#p.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#p.set(e,i);if(i.loading||t&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#d.scrollHeight-this.#d.scrollTop;try{let s=await this.#n.listMessages(e,{order:"desc",limit:30,cursor:t?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(be),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#o(),this.#d.scrollTop=this.#d.scrollHeight-n}#_e(e){switch(e.type){case"ready":if(this.#b=!1,this.#ne(),this.#H)this.#he();this.#H=!0;return;case"inbox.updated":{let t=this.#r?.ask_for_rating;if(this.#W(e.data),t!==void 0&&t!==e.data.ask_for_rating)this.#J().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pe();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#t.has(e.data.id))this.#t.set(e.data.id,e.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#t.size>1)this.#i=this.#c.some((t)=>t.conversation===null)?this.#i:{kind:"list"};this.#A();break;case"conversation.updated":{let t=this.#t.get(e.data.id),{status:i,can_rate:n,rating:s}=e.data;if(t)this.#t.set(t.id,{...t,status:i,can_rate:n,rating:s});if(!n)this.#_.delete(e.data.id);break}case"message.created":case"message.updated":this.#te(e.data,e.type==="message.created");break;case"read":{let t=this.#t.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||x(e.data.read_at)>x(i)))this.#t.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#C.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#C.set(t,{name:n,timer:setTimeout(()=>this.#C.delete(t)&&this.#o(),8000)})}else this.#C.delete(t);break}}this.#o()}#te(e,t){let i=e.conversation_id,n=this.#p.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===e.id);if(o>=0)n.messages[o]=e;else n.messages=[...n.messages,e].sort(be)}if(e.client_id)this.#c=this.#c.filter((o)=>o.client_id!==e.client_id);let s=this.#t.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#t.set(o.id,o),this.#A(),this.#o()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#t.set(i,{...s,last_message:{id:e.id,author_type:e.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:e.created_at},last_message_at:e.created_at,unread:s.unread||e.author.type!=="contact"}),e.author.type!=="contact"){let a=this.#C.get(i);if(a)clearTimeout(a.timer);this.#C.delete(i),this.#Pe(e)}}this.#A(),this.#j()}#Pe(e){this.#ee.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#A(){let e=0;for(let t of this.#t.values())if(t.unread)e++;this.#s.setUnread(e)}#Ee(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#j(){let e=this.#Ee(),t=e?this.#t.get(e):void 0;if(!e||!t?.unread)return;this.#t.set(e,{...t,unread:!1}),this.#A(),this.#n.markRead(e).catch(()=>{let i=this.#t.get(e);if(i)this.#t.set(e,{...i,unread:!0});this.#A()})}#fe(e){this.#x=[...this.#x,...e].slice(0,Oe),this.#q(),this.#B(),this.#h.focus()}#ge(){if(this.#h.style.blockSize="",this.#h.value==="")return;this.#h.style.blockSize="auto",this.#h.style.blockSize=`${Math.max(38,Math.min(this.#h.scrollHeight,140))}px`}#B(){this.#$.disabled=this.#h.value.trim()===""&&this.#x.length===0}#Te(){let e=this.#i?.kind==="thread"?this.#i.id:null;if(!e||this.#h.value.trim()===""){this.#O();return}if(Date.now()-this.#z>3000)this.#z=Date.now(),this.#n.setTyping(e,!0).catch(()=>{return});if(this.#f)clearTimeout(this.#f);this.#f=setTimeout(()=>this.#O(),4000)}#O(){if(this.#f)clearTimeout(this.#f);if(this.#f=null,this.#z===0)return;this.#z=0;let e=this.#i?.kind==="thread"?this.#i.id:null;if(e)this.#n.setTyping(e,!1).catch(()=>{return})}async#ie(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let e=this.#h.value.trim(),t=this.#x;if(!e&&t.length===0)return;if(this.#i.id===null&&this.#c.some((n)=>n.conversation===null))return;this.#O(),this.#h.value="",this.#x=[],this.#ge(),this.#q(),this.#B();let i={client_id:M(),conversation:this.#i.id,body:e,files:t,state:"sending"};this.#c.push(i),this.#o(),this.#R(),await this.#me(i)}async#me(e){e.state="sending",this.#o();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#n.startConversation(t),n=i.conversation.id;if(!this.#t.has(n))this.#t.set(n,i.conversation);if(!this.#p.has(n))this.#p.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#te(i.message,!1)}else{let i=await this.#n.sendMessage(e.conversation,t);this.#te(i,!0)}this.#c=this.#c.filter((i)=>i!==e)}catch(i){let n=i instanceof f?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#o(),this.#R()}async rate(e,t,i){try{let n=await this.#n.rate(e,t,i);return this.#t.set(n.id,n),this.#_.delete(e),this.#o(),n}catch(n){if(n instanceof f&&n.status===409){let s=await this.#n.getConversation(e).catch(()=>null);if(s)this.#t.set(s.id,s);this.#_.delete(e),this.#o()}throw n}}#ze(e,t){if(this.#_.get(e)?.state==="sending")return;if(this.#_.set(e,{choice:t,state:"choosing"}),this.#o(),this.#g.focus({preventScroll:!0}),this.#L)this.#R()}async#ye(e,t){let i=this.#_.get(e);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(e,i.choice,t?this.#g.value:void 0),this.#g.value=""}catch(n){if(n instanceof f&&n.status===409)return;i.state="failed",this.#o()}}async#Re(){let e=this.#E.value.trim();if(!e||!this.#E.checkValidity()){this.#S=this.#e({id:"E_qvzP"}),this.#se();return}try{this.#y=await this.#n.setEmail(e),this.#M=!0,this.#S=""}catch{this.#S=this.#e({id:"ZxJcgC"})}this.#se()}#ve(e){let t=this.#l.get(e.id);if(t)return Promise.resolve(t);let i=this.#D.get(e.id);if(!i)i=this.#n.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#l.set(e.id,s),s}),i.catch(()=>this.#D.delete(e.id)),this.#D.set(e.id,i);return i}async#be(e){let t=await this.#ve(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#xe(){return[...this.#t.values()].sort(Ue)}#De(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#R(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#we(){this.#h.placeholder=this.#e({id:"RzWUUK"}),this.#h.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#K.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#K.title=this.#e({id:"N7m8E-"}),this.#$.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#$.title=this.#e({id:"JlFcis"}),this.#E.placeholder=this.#e({id:"njBr8W"}),this.#E.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#B(),this.#q(),this.#o()}#o(){let e=this.#s.panel;if(e.childElementCount===0){let t=r("style");t.textContent=ye,e.append(t,this.#V,this.#X,this.#U,this.#ee),this.#V.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#Me(),this.#ne(),this.#a!=="ready"){this.#Y=void 0;let t=r("div","center");if(this.#a==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Ie()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#w=null,this.#N()}),t.append(i)}this.#U.replaceChildren(t);return}if(this.#i?.kind==="list")this.#Ae();else this.#$e()}#Ie(){switch(this.#u){case"anonymous_not_allowed":return this.#e({id:"zLzEI3"});case"invalid_identity_token":return this.#e({id:"0XGLbP"});case"rate_limited":return this.#e({id:"tzsBOP"});case"network":return this.#e({id:"GQVIIl"});default:return this.#e({id:"Amai22"})}}#Me(){let{layout:e}=this.#s.config(),t=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#t.size>1||n.id===null&&this.#t.size>0))i.push(z(P.back,this.#e({id:"S63MQu"}),()=>{this.#O(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",t?.name||this.#e({id:"t7TeQU"}))),t){let o=r("div","status");if(t.mode==="live"&&t.open_now&&t.presence?.available){let l=r("div","avatars");for(let c of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#e({id:"oXOSPE"})))}else if(!t.open_now||t.mode==="live")o.append(r("span","dot away"),r("span","",this.#e({id:"1EICzz"})));else o.append(r("span","",this.#Le(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(z(P.close,this.#e({id:"yz7wBu"}),()=>this.#s.close()));this.#V.replaceChildren(...i)}#Le(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#s.config(),[i,n]=e<60?[e,"minute"]:e<1440?[Math.round(e/60),"hour"]:[Math.round(e/1440),"day"],s=new Intl.NumberFormat(t,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#e({id:"VggdQJ",values:{duration:s}})}#ne(){this.#X.hidden=!this.#b,this.#X.textContent=this.#e({id:"09Tv5j"})}#Ae(){this.#Y=void 0;let{locale:e}=this.#s.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#xe()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#e({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Oe(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#v){let s=r("button","link",this.#e({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#J(!0).then(()=>this.#o())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#h.focus()}),this.#U.replaceChildren(t,n)}async#Oe(e){if(this.#i={kind:"thread",id:e},this.#o(),!this.#p.get(e)?.complete&&!this.#p.get(e)?.messages.length)await this.#G(e).catch(()=>{return});this.#o(),this.#R(),this.#j()}#Ue(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#I.get(i):!1;if(!i||n===!1)return t;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,t.replaceChildren(s),t;return s.addEventListener("load",()=>{if(this.#I.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#I.set(i,!1)),s.src=i,t}#$e(){let e=this.#i;if(e?.kind!=="thread")return;let t=e.id,i=this.#Y===t,n=this.#L,s=t?this.#p.get(t):void 0,o=s?.messages??[],a=this.#c.filter((d)=>d.conversation===t),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(L(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((d,v)=>{let k=o[v-1],w=o[v+1]??(a.length>0?null:void 0),m=d.author.type==="contact",C=!k||A(k)!==A(d)||x(d.created_at)-x(k.created_at)>ve,H=w===void 0||(w===null?!m:A(w)!==A(d)||x(w.created_at)-x(d.created_at)>ve);if(!m&&C&&d.author.name)l.push(r("div","author",d.author.name));let O=r("div",`row ${m?"mine":"theirs"}${C&&v>0?" group-gap":""}`);if(!m){let T=this.#Ue(d.author);if(!H)T.style.visibility="hidden";O.append(T)}let E=r("div","bubble");if(E.dir="auto",E.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())E.append(L(d.body));if(d.attachments.length>0)E.append(this.#je(d.attachments));if(O.append(E),l.push(O),H){let T=this.#Be(d.created_at);if(m&&v===o.length-1&&a.length===0){let Q=t?this.#t.get(t)?.last_read_by_member_at:void 0,we=Q&&x(Q)>=x(d.created_at);T+=` · ${we?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let U=r("div","meta",T);if(!m)U.style.alignSelf="flex-start";if(!m)U.style.marginInlineStart="36px";l.push(U)}});let h=t?this.#t.get(t):void 0,p=h?this.#Ne(h):null;if(p)l.push(p);a.forEach((d,v)=>{let k=r("div",`row mine${v===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),w=r("div","bubble");if(w.dir="auto",d.body)w.append(L(d.body));if(d.files.length>0){let m=r("div","files");for(let C of d.files)m.append(r("span","file",C.name||"image"));w.append(m)}if(k.append(w),l.push(k),d.state==="failed"){let m=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),C=r("button","link",this.#e({id:"6gRgw8"}));C.type="button",C.addEventListener("click",()=>void this.#me(d)),m.append(C),l.push(m)}else if(d.state==="refused"){let m=d.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${m}`))}else if(v===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let u=t?this.#C.get(t):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let v=u.name;d.append(r("span","",v?this.#e({id:"tHaDPf",values:{name:v}}):this.#e({id:"PxYAul"}))),l.push(d)}let g=this.#d.getRootNode().activeElement===this.#g,{selectionStart:_,selectionEnd:b}=this.#g;if(this.#d.replaceChildren(...l),g&&this.#g.isConnected)this.#g.focus({preventScroll:!0}),this.#g.setSelectionRange(_,b);if(this.#se(),this.#U.firstChild!==this.#d)this.#U.replaceChildren(this.#d,this.#P,this.#oe);if(this.#Y=t,!i||n)this.#R()}#Ne(e){let t=e.status==="closed"?e.rating:void 0,i=e.can_rate&&this.#r?.ask_for_rating?this.#_.get(e.id):void 0;if(!t&&!(e.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#ke,s=[e.id,t,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#re!==e.id)this.#re=e.id,this.#g.value="";let o=this.#e({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(t&&t!==u)continue;let y=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");y.type="button";let g=u==="good"?this.#e({id:"OEEQKT"}):this.#e({id:"-f5Tkb"});y.setAttribute("aria-label",g),y.title=g,y.setAttribute("aria-pressed",String((t??i?.choice)===u)),y.disabled=!!t||i?.state==="sending",y.addEventListener("click",()=>this.#ze(e.id,u)),a.append(y)}if(t)return n.replaceChildren(a,r("p","",this.#e({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#g.placeholder=this.#e({id:"axQ1h6"}),this.#g.setAttribute("aria-label",this.#e({id:"NBdIgR"})),this.#g.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#ye(e.id,!0)});let c=r("button","link",this.#e({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#ye(e.id,!1));let h=r("button","",i.state==="sending"?this.#e({id:"Sad2tK"}):this.#e({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#g,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#e({id:"4TqZiz"})));return n}#je(e){let t=r("div","files");for(let i of e)if($e(i)){let n=r("img");n.alt=i.filename;let s=this.#l.get(i.id);if(s)n.src=s;else this.#ve(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight}),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=P.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}return t}#Be(e){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(e))}#se(){let e=this.#y,t=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#c.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#De()&&n&&(!s||this.#M);if(this.#P.hidden=!o,!o)return;if(s&&this.#M){this.#P.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#P.querySelector("form")){let c=this.#P.querySelector(".error");if(c)c.textContent=this.#S;else if(this.#S)this.#P.append(r("p","error",this.#S));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#Re()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#E,l),this.#P.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#S)this.#P.append(r("p","error",this.#S))}#q(){this.#Z.hidden=this.#x.length===0,this.#Z.replaceChildren(...this.#x.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),z(P.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#x=this.#x.filter((n,s)=>s!==t),this.#q(),this.#B()})),i}))}}function Ne(e){return new xe(e)}export{Ne as mount};
|