useyuva 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/chat.js +1 -1
- package/dist/esm/{index-feftwnsj.js → index-d1vxbqpr.js} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/yuva-chat-tebg111a.js +195 -0
- package/dist/types/client/api.d.ts +2 -0
- package/dist/types/client/client.d.ts +2 -1
- package/dist/types/element.d.ts +2 -1
- package/dist/types/panel/chat.d.ts +2 -0
- package/dist/types/panel/styles.d.ts +1 -1
- package/dist/types/schema.gen.d.ts +1145 -68
- package/dist/types/types.d.ts +3 -0
- package/dist/yuva-chat.js +22 -10
- package/dist/yuva.js +2 -2
- package/package.json +1 -1
- package/dist/esm/yuva-chat-2482m97r.js +0 -183
package/dist/types/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IdentityTokenSource } from "./client/client.js";
|
|
2
2
|
import type { components } from "./schema.gen.js";
|
|
3
3
|
export type { IdentityTokenSource };
|
|
4
|
+
export type Rating = components["schemas"]["Rating"];
|
|
5
|
+
export type ClientConversation = components["schemas"]["ClientConversation"];
|
|
4
6
|
export type Layout = "launcher" | "embedded";
|
|
5
7
|
export interface LauncherStyle {
|
|
6
8
|
position: "right" | "left";
|
|
@@ -29,6 +31,7 @@ export interface PanelController {
|
|
|
29
31
|
closed(): void;
|
|
30
32
|
identityChanged(): void;
|
|
31
33
|
signOut(): Promise<void>;
|
|
34
|
+
rate(conversationId: string, rating: Rating, comment?: string): Promise<ClientConversation>;
|
|
32
35
|
destroy(): void;
|
|
33
36
|
}
|
|
34
37
|
export interface PanelModule {
|
package/dist/yuva-chat.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
1
|
+
var C=(t)=>typeof t==="string",yt=(t)=>typeof t==="function",H=new Map,X="en";function U(t){return[...Array.isArray(t)?t:[t],X]}function j(t,e,i){let n=U(t);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 I(()=>R("date",n,i),()=>new Intl.DateTimeFormat(n,s)).format(C(e)?new Date(e):e)}function vt(t,e,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 j(t,e,n)}function D(t,e,i){let n=U(t);return I(()=>R("number",n,i),()=>new Intl.NumberFormat(n,i)).format(e)}function Q(t,e,i,{offset:n=0,...s}){let o=U(t),a=e?I(()=>R("plural-ordinal",o),()=>new Intl.PluralRules(o,{type:"ordinal"})):I(()=>R("plural-cardinal",o),()=>new Intl.PluralRules(o,{type:"cardinal"}));return s[i]??s[a.select(i-n)]??s.other}function I(t,e){let i=t(),n=H.get(i);if(!n)n=e(),H.set(i,n);return n}function R(t,e,i){let n=e.join("-");return`${t}-${n}-${JSON.stringify(i)}`}var V=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,Z=(t)=>t.replace(/\\u([a-fA-F0-9]{4})|\\x([a-fA-F0-9]{2})/g,(e,i,n)=>{if(i){let s=parseInt(i,16);return String.fromCharCode(s)}else{let s=parseInt(n,16);return String.fromCharCode(s)}}),tt="%__lingui_octothorpe__%",bt=(t,e,i={})=>{let n=e||t,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=D(n,a,c);return l.replace(new RegExp(tt,"g"),h)};return{plural:(a,l)=>{let{offset:c=0}=l,h=Q(n,!1,a,l);return o(a-c,h)},selectordinal:(a,l)=>{let{offset:c=0}=l,h=Q(n,!0,a,l);return o(a-c,h)},select:xt,number:(a,l)=>D(n,a,s(l)||{style:l}),date:(a,l)=>j(n,a,s(l)||l),time:(a,l)=>vt(n,a,s(l)||l)}},xt=(t,e)=>(Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0)??e.other;function kt(t,e,i){return(n={},s)=>{let o=bt(e,i,s),a=(c,h=!1)=>{if(!Array.isArray(c))return c;return c.reduce((p,u)=>{if(u==="#"&&h)return p+tt;if(C(u))return p+u;let[b,y,P]=u,_={};if(y==="plural"||y==="selectordinal"||y==="select")Object.entries(P).forEach(([m,k])=>{_[m]=a(k,y==="plural"||y==="selectordinal")});else _=P;let d;if(y){let m=o[y];d=m(n[b],_)}else d=n[b];if(d==null)return p;return p+d},"")},l=a(t);if(C(l)&&V.test(l))return Z(l);if(C(l))return l;return l?String(l):""}}class et{_events={};on(t,e){return this._events[t]??=new Set,this._events[t].add(e),()=>this.removeListener(t,e)}removeListener(t,e){let i=this._events[t];if(i?.delete(e),i?.size===0)delete this._events[t]}emit(t,...e){let i=this._events[t];if(!i)return;for(let n of[...i])n.apply(this,e)}}class it extends et{_locale="";_locales;_messages={};_missing;_messageCompiler;constructor(t){super();if(t.missing!=null)this._missing=t.missing;if(t.messages!=null)this.load(t.messages);if(typeof t.locale==="string"||t.locales)this.activate(t.locale??X,t.locales)}get locale(){return this._locale}get locales(){return this._locales}get messages(){return this._messages[this._locale]??{}}setMessagesCompiler(t){return this._messageCompiler=t,this}_load(t,e){let i=Object.prototype.hasOwnProperty.call(this._messages,t)?this._messages[t]:void 0;if(!i)this._messages[t]=e;else Object.assign(i,e)}load(t,e){if(typeof t=="string"&&typeof e==="object")this._load(t,e);else Object.entries(t).forEach(([i,n])=>this._load(i,n));this.emit("change")}loadAndActivate({locale:t,locales:e,messages:i}){this._locale=t,this._locales=e||void 0,this._messages[this._locale]=i,this.emit("change")}activate(t,e){this._locale=t,this._locales=e,this.emit("change")}_(t,e,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(!t)t="";if(!C(t))e=t.values||e,n=t.message,t=t.id;let s=this.messages,o=Object.prototype.hasOwnProperty.call(s,t)?s[t]:void 0,a=o===void 0,l=this._missing;if(l&&a)return yt(l)?l(this._locale,t):l;if(a)this.emit("missing",{id:t,locale:this._locale});let c=o||n||t;if(C(c))if(this._messageCompiler)c=this._messageCompiler(c);else console.warn(`Uncompiled message detected! Message:
|
|
2
2
|
|
|
3
|
-
> ${
|
|
3
|
+
> ${c}
|
|
4
4
|
|
|
5
5
|
That means you use raw catalog or your catalog doesn't have a translation for the message and fallback was used.
|
|
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(
|
|
9
|
+
`);if(C(c)&&V.test(c))return Z(c);if(C(c))return c;return kt(c,this._locale,this._locales)(e,i?.formats)}t=this._.bind(this);date(t,e){return j(this._locales||this._locale,t,e)}number(t,e){return D(this._locales||this._locale,t,e)}}function B(t={}){return new it(t)}var Lt=B();var N=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 nt=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 st(t){return{position:t.chat.launcher_position,color:t.chat.launcher_color??t.branding.color}}function rt(t){return`yuva:${t}`}function Y(t){try{let e=localStorage.getItem(rt(t));return e?JSON.parse(e):{}}catch{return{}}}function ot(t,e){try{localStorage.setItem(rt(t),JSON.stringify(e))}catch{}}class g extends Error{status;code;constructor(t,e){super(`${t} ${e}`);this.status=t;this.code=e}}async function at(t,e,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 t(e+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new g(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new g(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}class K{server;socketClass;handlers;#s=null;#p=0;#n=0;#r=null;#g=!0;constructor(t,e,i){this.server=t;this.socketClass=e;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#g=!1,!this.#s)this.#a()}stop(){if(this.#g=!0,this.#r)clearTimeout(this.#r);this.#r=null;let t=this.#s;this.#s=null,t?.close(1000)}reset(){this.#p=0}nudge(){if(this.#g||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let t=this.handlers.token();if(!t||this.#g)return;let e=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(e.protocol=e.protocol==="https:"?"wss:":"ws:",this.#p>0)e.searchParams.set("last_event_id",String(this.#p));let i;try{i=new this.socketClass(e,["yuva",`yuva.token.${t}`])}catch{this.#f();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.#p=Math.max(this.#p,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#p=Math.max(this.#p,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#g)return;if(n.code===1008){this.#p=0,this.handlers.sessionEnded();return}this.#f()}}#f(){if(this.#g||this.#r)return;let t=this.#n++;this.handlers.reconnecting(t);let e=Math.min(30000,1000*2**t)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},e)}}function lt(t){return`yuva:${t}`}function F(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(t)=>t.toString(16).padStart(2,"0")).join("")}function wt(t){try{let e=(t.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(e));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Ct(){try{let e=globalThis.localStorage;if(e)return e}catch{}let t=new Map;return{getItem:(e)=>t.get(e)??null,setItem:(e,i)=>void t.set(e,i)}}function ct(t){let e=new URLSearchParams;for(let[n,s]of Object.entries(t))if(s!==void 0)e.set(n,String(s));let i=e.toString();return i?`?${i}`:""}function St(t){return t.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function _t(t,e,i){let n=[];for(let[s,o]of t)n.push(`--${i}\r
|
|
10
10
|
Content-Disposition: form-data; name="${s}"\r
|
|
11
11
|
\r
|
|
12
12
|
${o}\r
|
|
13
|
-
`);for(let s of
|
|
14
|
-
Content-Disposition: form-data; name="files"; filename="${
|
|
13
|
+
`);for(let s of e){let o=s.name||"file";n.push(`--${i}\r
|
|
14
|
+
Content-Disposition: form-data; name="files"; filename="${St(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 dt{server;channel;#s;#p;#n;#r;#g;#a=null;#f=null;#v=null;#x=null;#e=null;#E=new Map;constructor(t){this.server=t.server.replace(/\/+$/,""),this.channel=t.channel,this.#s=t.fetch??((e,i)=>fetch(e,i)),this.#p=t.WebSocket??globalThis.WebSocket,this.#n=t.storage??Ct(),this.#r=t.identityToken??null,this.#g=t.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#f}get token(){return this.#a}get connected(){return this.#e?.connected??!1}on(t,e){let i=this.#E.get(t);if(!i)this.#E.set(t,i=new Set);return i.add(e),()=>void i.delete(e)}#l(t,e){for(let i of this.#E.get(t)??[])i(e)}stored(){try{let t=this.#n.getItem(lt(this.channel));return t?JSON.parse(t):{}}catch{return{}}}#m(t){try{this.#n.setItem(lt(this.channel),JSON.stringify(t))}catch{}}channelSettings(){return this.#i(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}setIdentityToken(t){this.#r=t,this.reset()}start(){if(this.#f)return Promise.resolve(this.#f);return this.#v??=this.#T(!1).then((t)=>(this.#l("session",{session:t,renewed:!1}),t)).finally(()=>{this.#v=null}),this.#v}async refresh(){let t=await this.#h("/client/v1/session");return this.#f={...this.#f,...t},this.#l("session",{session:this.#f,renewed:!1}),this.#f}reset(){this.#e?.stop(),this.#e?.reset(),this.#v=null,this.#x=null,this.#a=null,this.#f=null}async signOut(){let t=this.#a;this.reset();let e=this.stored();if(delete e.session,this.#m(e),t)await this.#i("/client/v1/session",{method:"DELETE",token:t}).catch(()=>{return})}async connect(){if(!this.#p)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#e??=new K(this.server,this.#p,{token:()=>this.#a,event:(t)=>{if(t.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",t)},sessionEnded:()=>void this.#y().catch(()=>this.#e?.nudge()),reconnecting:(t)=>{if(this.#l("connection",{state:"reconnecting",attempt:t}),t===2)this.#h("/client/v1/session").catch(()=>{return})}}),!this.#e.connected)this.#l("connection",{state:"connecting",attempt:0});this.#e.start()}disconnect(){this.#e?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#e?.nudge()}listConversations(t={}){return this.#h(`/client/v1/conversations${ct({...t})}`)}getConversation(t){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}`)}startConversation(t){return this.#h("/client/v1/conversations",this.#b(t))}listMessages(t,e={}){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/messages${ct({...e})}`)}sendMessage(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/messages`,this.#b(e))}markRead(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/read`,{method:"POST",json:e?{message_id:e}:{}})}rate(t,e,i){let n={rating:e,comment:i?.trim()||void 0};return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/rating`,{method:"POST",json:n})}setTyping(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/typing`,{method:"POST",json:{typing:e}})}setEmail(t){return this.#h("/client/v1/contact/email",{method:"PUT",json:{email:t}})}attachment(t){return this.#h(`/client/v1/attachments/${encodeURIComponent(t)}`,{blob:!0})}#b({body:t,subject:e,files:i=[],client_id:n=F()}){let s=this.#g&&/^[\x20-\x7e]{1,255}$/.test(n)?{"Idempotency-Key":n}:{};if(i.length===0)return{method:"POST",headers:s,json:{body:t,subject:e,client_id:n}};let o=[];if(e)o.push(["subject",e]);if(t)o.push(["body",t]);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:_t(o,i,a)}}#i(t,e){return at(this.#s,this.server,t,e)}async#h(t,e={},i=!0){if(!this.#a)await this.start();try{return await this.#i(t,{...e,token:this.#a})}catch(n){if(!i||!(n instanceof g)||n.status!==401)throw n;return await this.#y(),this.#h(t,e,!1)}}#y(){return this.#x??=(async()=>{let t=await this.#T(!0);if(this.#e)this.#e.stop(),this.#e.reset(),this.#e.start();this.#l("session",{session:t,renewed:!0})})().finally(()=>{this.#x=null}),this.#x}async#T(t){let e=this.stored(),i=await this.#r?.()||null,n=i?wt(i):null,s=e.session;if(!t&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#i("/client/v1/session",{token:s.token});return this.#k(c,s.token,n)}catch(c){if(!(c instanceof g)||c.status!==401&&c.status!==403)throw c}let o=await this.#i("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:e.visitor_id}}),{token:a,...l}=o;return this.#k(l,a,n)}#k(t,e,i){this.#a=e,this.#f=t;let n=this.stored();if(n.session={token:e,expires_at:t.expires_at,sub:i},t.visitor_id)n.visitor_id=t.visitor_id;else if(t.contact.identified)delete n.visitor_id;return this.#m(n),t}}function ht(t){return new dt(t)}var ut=`
|
|
20
20
|
[hidden] { display: none !important; }
|
|
21
21
|
.header {
|
|
22
22
|
display: flex;
|
|
@@ -169,6 +169,18 @@ Content-Type: ${s.type||"application/octet-stream"}\r
|
|
|
169
169
|
}
|
|
170
170
|
.card button { padding: 8px 12px; border: 0; border-radius: 8px; background: var(--yuva-accent); color: var(--yuva-on-accent); font: inherit; font-weight: 600; cursor: pointer; }
|
|
171
171
|
.card .error { margin: 6px 0 0; color: var(--yuva-danger); }
|
|
172
|
+
.card button:disabled { opacity: 0.6; cursor: default; }
|
|
173
|
+
.rate { text-align: center; }
|
|
174
|
+
.choices { display: flex; justify-content: center; gap: 10px; }
|
|
175
|
+
.card .choice { inline-size: 44px; block-size: 44px; padding: 0; border: 1px solid var(--yuva-border); border-radius: 50%; background: var(--yuva-bg); font-size: 20px; line-height: 1; }
|
|
176
|
+
.card .choice:hover:not(:disabled), .card .choice[aria-pressed="true"] { border-color: var(--yuva-accent); box-shadow: 0 0 0 1px var(--yuva-accent); }
|
|
177
|
+
.card .choice:disabled { opacity: 1; }
|
|
178
|
+
.card .choice:focus-visible { outline: 2px solid var(--yuva-accent); outline-offset: 2px; }
|
|
179
|
+
.rate .choices + p { margin: 8px 0 0; }
|
|
180
|
+
.rate form { flex-direction: column; margin-block-start: 10px; }
|
|
181
|
+
.rate textarea { box-sizing: border-box; inline-size: 100%; padding: 8px 10px; border: 1px solid var(--yuva-border); border-radius: 8px; background: var(--yuva-bg); color: inherit; font: inherit; resize: vertical; }
|
|
182
|
+
.rate .actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; }
|
|
183
|
+
.card .link { padding: 0; background: none; color: var(--yuva-muted); font-weight: 400; }
|
|
172
184
|
.composer { border-block-start: 1px solid var(--yuva-border); padding: 8px; }
|
|
173
185
|
.composer form { display: flex; gap: 4px; align-items: flex-end; }
|
|
174
186
|
.composer textarea {
|
|
@@ -194,8 +206,8 @@ Content-Type: ${s.type||"application/octet-stream"}\r
|
|
|
194
206
|
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-inline-size: 180px; }
|
|
195
207
|
.chip .icon { inline-size: 22px; block-size: 22px; }
|
|
196
208
|
.banner { padding: 6px 12px; background: var(--yuva-soft); color: var(--yuva-muted); font-size: 13px; text-align: center; }
|
|
197
|
-
@media (max-width: 480px) { .composer textarea, .card input { font-size: 16px; } }
|
|
209
|
+
@media (max-width: 480px) { .composer textarea, .card input, .card textarea { font-size: 16px; } }
|
|
198
210
|
.sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
199
|
-
`;var
|
|
200
|
-
`).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$/,""),
|
|
201
|
-
`).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...Y(a))})}),t}var ke={en:A,tr:V},Ce=10,ae=300000,C={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 S(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 y=(e)=>Date.parse(e),le=(e,t)=>y(e.created_at)-y(t.created_at),_e=(e,t)=>y(t.last_message_at??t.created_at)-y(e.last_message_at??e.created_at),P=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,Se=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class ce{#n;#u;#s;#r=null;#f=null;#o="loading";#p="";#y=null;#b=null;#i=new Map;#S;#l=new Map;#m=[];#v=new Map;#t=null;#h=!1;#g=[];#z=0;#x=null;#$=new Map;#K=new Map;#F=new Map;#J=!1;#w="";#W=!1;#G=r("header","header");#H=r("div","banner");#I=r("div","body");#d=r("div","scroll");#k=r("div","card");#C=r("input");#ie=r("div","composer");#q=r("div","chips");#c=r("textarea");#_=r("input");#M;#D;#X=r("div","sr");#U;#L=!0;constructor(e){this.#n=e;let{server:t,channel:i}=e.config();this.#s=re({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#s.on("event",(s)=>this.#be(s)),this.#s.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#h=o>0,this.#ee()}),this.#s.on("session",({session:s,renewed:o})=>{if(this.#N(s.inbox),this.#f=s.contact,o)this.#ce()}),this.#se(),this.#X.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.#t?.kind==="thread"&&this.#t.id)this.#Y(this.#t.id,!0)}),this.#c.rows=1,this.#c.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#Z()}),this.#c.addEventListener("input",()=>{this.#he(),this.#A(),this.#ke()}),this.#c.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#de(o)}),this.#_.type="file",this.#_.multiple=!0,this.#_.hidden=!0,this.#_.addEventListener("change",()=>{this.#de(Array.from(this.#_.files??[])),this.#_.value=""}),this.#D=S(C.attach,"",()=>this.#_.click()),this.#M=S(C.send,"",()=>void this.#Z(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#Z()}),n.append(this.#D,this.#c,this.#M,this.#_),this.#ie.append(this.#q,n),this.#C.type="email",this.#C.required=!0,this.#C.autocomplete="email",document.addEventListener("visibilitychange",this.#j),window.addEventListener("online",this.#j),this.#ge(),this.#R()}update(){this.#se(),this.#ge()}opened(){if(this.#o==="error"){this.#y=null,this.#R();return}if(this.#o==="ready")this.#s.token?this.#ve():this.#re().then(()=>this.#a()).catch(()=>{return});if(this.#a(),this.#P(),this.#O(),this.#n.config().layout==="launcher")this.#c.focus({preventScroll:!0})}closed(){this.#E()}identityChanged(){this.#ne(),this.#R()}async signOut(){let e=this.#s.signOut();if(this.#ne(),await e,this.#n.isOpen())this.#R();else this.#a()}destroy(){this.#s.reset(),this.#E(),document.removeEventListener("visibilitychange",this.#j),window.removeEventListener("online",this.#j);for(let e of this.#$.values())URL.revokeObjectURL(e)}#ne(){this.#s.reset(),this.#y=null,this.#b=null,this.#r=null,this.#f=null,this.#o="loading",this.#i.clear(),this.#l.clear(),this.#m=[],this.#t=null,this.#W=!1,this.#n.setUnread(0)}#j=()=>{if(document.visibilityState!=="visible")return;this.#s.reconnect(),this.#O(),this.#ae()};#se(){let{locale:e}=this.#n.config();this.#u=O({locale:e,messages:{[e]:ke[e]??A}})}#e(e){return this.#u._(e)}#R(){return this.#y??=(async()=>{this.#o="loading",this.#a();let{channel:e}=this.#n.config();if(!e)throw new m(0,"not_configured");if(await this.#n.identityToken()||D(e).session)await this.#ye();else if(await this.#re(),!this.#r?.chat.allow_anonymous)throw new m(403,"anonymous_not_allowed");if(this.#o="ready",!this.#t){let t=this.#me();if(this.#t=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#t.kind==="thread"&&this.#t.id)await this.#Y(this.#t.id)}this.#a(),this.#P(),this.#O()})().catch((e)=>{if(this.#y=null,this.#le(e))return;this.#o="error",this.#p=e instanceof m?e.code:"error",this.#a()}),this.#y}async#re(){let e=await this.#oe();if(!this.#s.token)this.#N(e)}#oe(){if(!this.#n.config().channel)throw new m(0,"not_configured");return this.#s.channelSettings()}#N(e){let{channel:t}=this.#n.config();this.#r=e;let i=Q(e);if(this.#n.setLauncher(i),t)ee(t,{...D(t),launcher:i})}async#ae(){if(this.#o!=="ready")return;try{this.#N(await this.#oe()),this.#a()}catch(e){this.#le(e,!0)}}#le(e,t=!this.#s.token){let i=e instanceof m&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#n.refused();return i}#ye(){return this.#b??=(async()=>{await this.#s.start(),await this.#V(),await this.#s.connect()})().finally(()=>{this.#b=null}),this.#b}async#ve(){try{await this.#s.refresh(),this.#a()}catch{}}async#V(e=!1){let t=await this.#s.listConversations({limit:50,cursor:e?this.#S:void 0});if(!e)this.#i.clear();for(let i of t.items)this.#i.set(i.id,i);this.#S=t.next_cursor,this.#T()}async#ce(){await this.#V();let e=this.#t?.kind==="thread"?this.#t.id:null;for(let t of[...this.#l.keys()])if(t!==e)this.#l.delete(t);if(e)this.#l.delete(e),await this.#Y(e);this.#a()}async#Y(e,t=!1){let i=this.#l.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#l.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.#s.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(le),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#a(),this.#d.scrollTop=this.#d.scrollHeight-n}#be(e){switch(e.type){case"ready":if(this.#h=!1,this.#ee(),this.#W)this.#ae();this.#W=!0;return;case"inbox.updated":this.#N(e.data);break;case"resync_required":this.#ce();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#i.has(e.data.id))this.#i.set(e.data.id,e.data);if(this.#t?.kind==="thread"&&this.#t.id===null&&this.#i.size>1)this.#t=this.#m.some((t)=>t.conversation===null)?this.#t:{kind:"list"};this.#T();break;case"conversation.updated":{let t=this.#i.get(e.data.id);if(t)this.#i.set(t.id,{...t,status:e.data.status});break}case"message.created":case"message.updated":this.#Q(e.data,e.type==="message.created");break;case"read":{let t=this.#i.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||y(e.data.read_at)>y(i)))this.#i.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#v.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#v.set(t,{name:n,timer:setTimeout(()=>this.#v.delete(t)&&this.#a(),8000)})}else this.#v.delete(t);break}}this.#a()}#Q(e,t){let i=e.conversation_id,n=this.#l.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(le)}if(e.client_id)this.#m=this.#m.filter((o)=>o.client_id!==e.client_id);let s=this.#i.get(i);if(!s){this.#s.getConversation(i).then((o)=>{this.#i.set(o.id,o),this.#T(),this.#a()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#i.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.#v.get(i);if(a)clearTimeout(a.timer);this.#v.delete(i),this.#xe(e)}}this.#T(),this.#O()}#xe(e){this.#X.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#T(){let e=0;for(let t of this.#i.values())if(t.unread)e++;this.#n.setUnread(e)}#we(){if(!this.#n.isOpen()||document.visibilityState!=="visible")return null;return this.#t?.kind==="thread"?this.#t.id:null}#O(){let e=this.#we(),t=e?this.#i.get(e):void 0;if(!e||!t?.unread)return;this.#i.set(e,{...t,unread:!1}),this.#T(),this.#s.markRead(e).catch(()=>{let i=this.#i.get(e);if(i)this.#i.set(e,{...i,unread:!0});this.#T()})}#de(e){this.#g=[...this.#g,...e].slice(0,Ce),this.#B(),this.#A(),this.#c.focus()}#he(){if(this.#c.style.blockSize="",this.#c.value==="")return;this.#c.style.blockSize="auto",this.#c.style.blockSize=`${Math.max(38,Math.min(this.#c.scrollHeight,140))}px`}#A(){this.#M.disabled=this.#c.value.trim()===""&&this.#g.length===0}#ke(){let e=this.#t?.kind==="thread"?this.#t.id:null;if(!e||this.#c.value.trim()===""){this.#E();return}if(Date.now()-this.#z>3000)this.#z=Date.now(),this.#s.setTyping(e,!0).catch(()=>{return});if(this.#x)clearTimeout(this.#x);this.#x=setTimeout(()=>this.#E(),4000)}#E(){if(this.#x)clearTimeout(this.#x);if(this.#x=null,this.#z===0)return;this.#z=0;let e=this.#t?.kind==="thread"?this.#t.id:null;if(e)this.#s.setTyping(e,!1).catch(()=>{return})}async#Z(){if(this.#o!=="ready"||this.#t?.kind!=="thread")return;let e=this.#c.value.trim(),t=this.#g;if(!e&&t.length===0)return;if(this.#t.id===null&&this.#m.some((n)=>n.conversation===null))return;this.#E(),this.#c.value="",this.#g=[],this.#he(),this.#B(),this.#A();let i={client_id:j(),conversation:this.#t.id,body:e,files:t,state:"sending"};this.#m.push(i),this.#a(),this.#P(),await this.#ue(i)}async#ue(e){e.state="sending",this.#a();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#s.startConversation(t),n=i.conversation.id;if(!this.#i.has(n))this.#i.set(n,i.conversation);if(!this.#l.has(n))this.#l.set(n,{messages:[],complete:!0,loading:!1});if(this.#t?.kind==="thread"&&this.#t.id===null)this.#t={kind:"thread",id:n};this.#Q(i.message,!1)}else{let i=await this.#s.sendMessage(e.conversation,t);this.#Q(i,!0)}this.#m=this.#m.filter((i)=>i!==e)}catch(i){let n=i instanceof m?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#a(),this.#P()}async#Ce(){let e=this.#C.value.trim();if(!e||!this.#C.checkValidity()){this.#w=this.#e({id:"E_qvzP"}),this.#te();return}try{this.#f=await this.#s.setEmail(e),this.#J=!0,this.#w=""}catch{this.#w=this.#e({id:"ZxJcgC"})}this.#te()}#pe(e){let t=this.#$.get(e.id);if(t)return Promise.resolve(t);let i=this.#K.get(e.id);if(!i)i=this.#s.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#$.set(e.id,s),s}),i.catch(()=>this.#K.delete(e.id)),this.#K.set(e.id,i);return i}async#fe(e){let t=await this.#pe(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#me(){return[...this.#i.values()].sort(_e)}#_e(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#P(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#ge(){this.#c.placeholder=this.#e({id:"RzWUUK"}),this.#c.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#D.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#D.title=this.#e({id:"N7m8E-"}),this.#M.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#M.title=this.#e({id:"JlFcis"}),this.#C.placeholder=this.#e({id:"njBr8W"}),this.#C.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#A(),this.#B(),this.#a()}#a(){let e=this.#n.panel;if(e.childElementCount===0){let t=r("style");t.textContent=oe,e.append(t,this.#G,this.#H,this.#I,this.#X),this.#G.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#ze(),this.#ee(),this.#o!=="ready"){this.#U=void 0;let t=r("div","center");if(this.#o==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Se()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#y=null,this.#R()}),t.append(i)}this.#I.replaceChildren(t);return}if(this.#t?.kind==="list")this.#Ee();else this.#Me()}#Se(){switch(this.#p){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"})}}#ze(){let{layout:e}=this.#n.config(),t=this.#r,i=[],n=this.#t;if(this.#o==="ready"&&n?.kind==="thread"&&(this.#i.size>1||n.id===null&&this.#i.size>0))i.push(S(C.back,this.#e({id:"S63MQu"}),()=>{this.#E(),this.#t={kind:"list"},this.#a()}));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 d of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",d.initials||"•");h.title=d.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.#Te(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(S(C.close,this.#e({id:"yz7wBu"}),()=>this.#n.close()));this.#G.replaceChildren(...i)}#Te(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#n.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}})}#ee(){this.#H.hidden=!this.#h,this.#H.textContent=this.#e({id:"09Tv5j"})}#Ee(){this.#U=void 0;let{locale:e}=this.#n.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#me()){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 d=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,d.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(d)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",c=r("div","item-preview",h.replace(/\*\*|`/g,""));if(c.dir="auto",a.append(l,c),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Pe(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#S){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.#V(!0).then(()=>this.#a())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#t={kind:"thread",id:null},this.#a(),this.#c.focus()}),this.#I.replaceChildren(t,n)}async#Pe(e){if(this.#t={kind:"thread",id:e},this.#a(),!this.#l.get(e)?.complete&&!this.#l.get(e)?.messages.length)await this.#Y(e).catch(()=>{return});this.#a(),this.#P(),this.#O()}#Ie(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#F.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.#F.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#F.set(i,!1)),s.src=i,t}#Me(){let e=this.#t;if(e?.kind!=="thread")return;let t=e.id,i=this.#U===t,n=this.#L,s=t?this.#l.get(t):void 0,o=s?.messages??[],a=this.#m.filter((c)=>c.conversation===t),l=[],d=this.#r?.chat.greeting;if(!s||s.complete){if(d){let c=r("div","bubble greeting");c.append(E(d)),l.push(c)}else if(o.length===0&&a.length===0){let c=r("div","center");c.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(c)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((c,u)=>{let v=o[u-1],f=o[u+1]??(a.length>0?null:void 0),p=c.author.type==="contact",g=!v||P(v)!==P(c)||y(c.created_at)-y(v.created_at)>ae,x=f===void 0||(f===null?!p:P(f)!==P(c)||y(f.created_at)-y(c.created_at)>ae);if(!p&&g&&c.author.name)l.push(r("div","author",c.author.name));let w=r("div",`row ${p?"mine":"theirs"}${g&&u>0?" group-gap":""}`);if(!p){let _=this.#Ie(c.author);if(!x)_.style.visibility="hidden";w.append(_)}let k=r("div","bubble");if(k.dir="auto",k.title=new Date(c.created_at).toLocaleString(this.#n.config().locale),c.body.trim())k.append(E(c.body));if(c.attachments.length>0)k.append(this.#Le(c.attachments));if(w.append(k),l.push(w),x){let _=this.#Re(c.created_at);if(p&&u===o.length-1&&a.length===0){let B=t?this.#i.get(t)?.last_read_by_member_at:void 0,de=B&&y(B)>=y(c.created_at);_+=` · ${de?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let I=r("div","meta",_);if(!p)I.style.alignSelf="flex-start";if(!p)I.style.marginInlineStart="36px";l.push(I)}}),a.forEach((c,u)=>{let v=r("div",`row mine${u===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),f=r("div","bubble");if(f.dir="auto",c.body)f.append(E(c.body));if(c.files.length>0){let p=r("div","files");for(let g of c.files)p.append(r("span","file",g.name||"image"));f.append(p)}if(v.append(f),l.push(v),c.state==="failed"){let p=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),g=r("button","link",this.#e({id:"6gRgw8"}));g.type="button",g.addEventListener("click",()=>void this.#ue(c)),p.append(g),l.push(p)}else if(c.state==="refused"){let p=c.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${p}`))}else if(u===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let h=t?this.#v.get(t):void 0;if(h){let c=r("div","typing");c.append(r("i"),r("i"),r("i"));let u=h.name;c.append(r("span","",u?this.#e({id:"tHaDPf",values:{name:u}}):this.#e({id:"PxYAul"}))),l.push(c)}if(this.#d.replaceChildren(...l),this.#te(),this.#I.firstChild!==this.#d)this.#I.replaceChildren(this.#d,this.#k,this.#ie);if(this.#U=t,!i||n)this.#P()}#Le(e){let t=r("div","files");for(let i of e)if(Se(i)){let n=r("img");n.alt=i.filename;let s=this.#$.get(i.id);if(s)n.src=s;else this.#pe(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.#fe(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=C.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#fe(i)),t.append(n)}return t}#Re(e){return new Intl.DateTimeFormat(this.#n.config().locale,{timeStyle:"short"}).format(new Date(e))}#te(){let e=this.#f,t=this.#r?.chat,n=(this.#t?.kind==="thread"?this.#t.id:null)!==null||this.#m.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#_e()&&n&&(!s||this.#J);if(this.#k.hidden=!o,!o)return;if(s&&this.#J){this.#k.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#k.querySelector("form")){let d=this.#k.querySelector(".error");if(d)d.textContent=this.#w;else if(this.#w)this.#k.append(r("p","error",this.#w));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(d)=>{d.preventDefault(),this.#Ce()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#C,l),this.#k.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#w)this.#k.append(r("p","error",this.#w))}#B(){this.#q.hidden=this.#g.length===0,this.#q.replaceChildren(...this.#g.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),S(C.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#g=this.#g.filter((n,s)=>s!==t),this.#B(),this.#A()})),i}))}}function ze(e){return new ce(e)}export{ze as mount};
|
|
211
|
+
`;var zt=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Et(t,e){let i=document.createElement("a");return i.href=t,i.textContent=e,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function J(t,e){let i=document.createElement(t);return i.append(...e),i}function G(t){let e=[],i=0;for(let n of t.matchAll(zt)){let s=n.index??0;if(s>i)e.push(document.createTextNode(t.slice(i,s)));let[o,a,l,c,h]=n;if(a)e.push(J("code",[document.createTextNode(a.slice(1,-1))]));else if(l)e.push(J("strong",G(l.slice(2,-2))));else if(c)e.push(J("em",G(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);e.push(u.protocol==="http:"||u.protocol==="https:"?Et(u.href,h):document.createTextNode(h))}catch{e.push(document.createTextNode(h))}}i=s+o.length}if(i<t.length)e.push(document.createTextNode(t.slice(i)));return e}function M(t){let e=document.createDocumentFragment(),i=t.trim().replace(/\r\n?/g,`
|
|
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$/,""),e.append(a);return}(i.length>1?n.replace(/^\n|\n$/g,""):n).split(`
|
|
213
|
+
`).forEach((a,l)=>{if(l>0)e.append(document.createElement("br"));e.append(...G(a))})}),e}var Tt={en:N,tr:nt},Pt=10,pt=300000,S={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(t,e,i){let n=document.createElement(t);if(e)n.className=e;if(i!==void 0)n.textContent=i;return n}function T(t,e,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=t,s.setAttribute("aria-label",e),s.title=e,s.addEventListener("click",i),s}var v=(t)=>Date.parse(t),ft=(t,e)=>v(t.created_at)-v(e.created_at),It=(t,e)=>v(e.last_message_at??e.created_at)-v(t.last_message_at??t.created_at),L=(t)=>t.author.type==="contact"?"contact":`${t.author.type}:${t.author.name??""}`,Rt=(t)=>/^image\/(png|jpeg|gif|webp)$/.test(t.content_type);class gt{#s;#p;#n;#r=null;#g=null;#a="loading";#f="";#v=null;#x=null;#e=new Map;#E;#l=new Map;#m=[];#b=new Map;#i=null;#h=!1;#y=[];#T=0;#k=null;#U=new Map;#G=new Map;#W=new Map;#q=!1;#w="";#H=!1;#C=new Map;#wt=r("div","card rate");#u=r("textarea");#Q="";#rt=null;#X=r("header","header");#V=r("div","banner");#L=r("div","body");#c=r("div","scroll");#S=r("div","card");#_=r("input");#ot=r("div","composer");#Z=r("div","chips");#d=r("textarea");#z=r("input");#A;#j;#tt=r("div","sr");#B;#I=!0;constructor(t){this.#s=t;let{server:e,channel:i}=t.config();this.#n=ht({server:e,channel:i??"",identityToken:()=>t.identityToken()}),this.#n.on("event",(s)=>this.#_t(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#h=o>0,this.#nt()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#Y(s.inbox),this.#g=s.contact,o)this.#pt()}),this.#lt(),this.#tt.setAttribute("aria-live","polite"),this.#c.addEventListener("scroll",()=>{if(this.#I=this.#c.scrollHeight-this.#c.scrollTop-this.#c.clientHeight<48,this.#c.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#F(this.#i.id,!0)}),this.#d.rows=1,this.#d.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#it()}),this.#d.addEventListener("input",()=>{this.#gt(),this.#D(),this.#Tt()}),this.#d.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#ft(o)}),this.#z.type="file",this.#z.multiple=!0,this.#z.hidden=!0,this.#z.addEventListener("change",()=>{this.#ft(Array.from(this.#z.files??[])),this.#z.value=""}),this.#j=T(S.attach,"",()=>this.#z.click()),this.#A=T(S.send,"",()=>void this.#it(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#it()}),n.append(this.#j,this.#d,this.#A,this.#z),this.#ot.append(this.#Z,n),this.#_.type="email",this.#_.required=!0,this.#_.autocomplete="email",this.#u.rows=2,this.#u.maxLength=2000,this.#u.dir="auto",document.addEventListener("visibilitychange",this.#N),window.addEventListener("online",this.#N),this.#kt(),this.#O()}update(){this.#lt(),this.#kt()}opened(){if(this.#a==="error"){this.#v=null,this.#O();return}if(this.#a==="ready")this.#n.token?this.#St():this.#ct().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#P(),this.#$(),this.#s.config().layout==="launcher")this.#d.focus({preventScroll:!0})}closed(){this.#M()}identityChanged(){this.#at(),this.#O()}async signOut(){let t=this.#n.signOut();if(this.#at(),await t,this.#s.isOpen())this.#O();else this.#o()}destroy(){this.#n.reset(),this.#M(),document.removeEventListener("visibilitychange",this.#N),window.removeEventListener("online",this.#N);for(let t of this.#U.values())URL.revokeObjectURL(t)}#at(){this.#n.reset(),this.#v=null,this.#x=null,this.#r=null,this.#g=null,this.#a="loading",this.#e.clear(),this.#l.clear(),this.#m=[],this.#C.clear(),this.#Q="",this.#i=null,this.#H=!1,this.#s.setUnread(0)}#N=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#$(),this.#ht()};#lt(){let{locale:t}=this.#s.config();this.#p=B({locale:t,messages:{[t]:Tt[t]??N}})}#t(t){return this.#p._(t)}#O(){return this.#v??=(async()=>{this.#a="loading",this.#o();let{channel:t}=this.#s.config();if(!t)throw new g(0,"not_configured");if(await this.#s.identityToken()||Y(t).session)await this.#Ct();else if(await this.#ct(),!this.#r?.chat.allow_anonymous)throw new g(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let e=this.#xt();if(this.#i=e.length>1?{kind:"list"}:{kind:"thread",id:e[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#F(this.#i.id)}this.#o(),this.#P(),this.#$()})().catch((t)=>{if(this.#v=null,this.#ut(t))return;this.#a="error",this.#f=t instanceof g?t.code:"error",this.#o()}),this.#v}async#ct(){let t=await this.#dt();if(!this.#n.token)this.#Y(t)}#dt(){if(!this.#s.config().channel)throw new g(0,"not_configured");return this.#n.channelSettings()}#Y(t){let{channel:e}=this.#s.config();this.#r=t;let i=st(t);if(this.#s.setLauncher(i),e)ot(e,{...Y(e),launcher:i})}async#ht(){if(this.#a!=="ready")return;try{this.#Y(await this.#dt()),this.#o()}catch(t){this.#ut(t,!0)}}#ut(t,e=!this.#n.token){let i=t instanceof g&&(t.code==="origin_not_allowed"||t.status===404&&e);if(i)this.#s.refused();return i}#Ct(){return this.#x??=(async()=>{await this.#n.start(),await this.#K(),await this.#n.connect()})().finally(()=>{this.#x=null}),this.#x}async#St(){try{await this.#n.refresh(),this.#o()}catch{}}async#K(t=!1){let e=await this.#n.listConversations({limit:50,cursor:t?this.#E:void 0});if(!t)this.#e.clear();for(let i of e.items)this.#e.set(i.id,i);this.#E=e.next_cursor,this.#R()}async#pt(){await this.#K();let t=this.#i?.kind==="thread"?this.#i.id:null;for(let e of[...this.#l.keys()])if(e!==t)this.#l.delete(e);if(t)this.#l.delete(t),await this.#F(t);this.#o()}async#F(t,e=!1){let i=this.#l.get(t);if(!i)i={messages:[],complete:!1,loading:!1},this.#l.set(t,i);if(i.loading||e&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#c.scrollHeight-this.#c.scrollTop;try{let s=await this.#n.listMessages(t,{order:"desc",limit:30,cursor:e?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(ft),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(e)this.#o(),this.#c.scrollTop=this.#c.scrollHeight-n}#_t(t){switch(t.type){case"ready":if(this.#h=!1,this.#nt(),this.#H)this.#ht();this.#H=!0;return;case"inbox.updated":{let e=this.#r?.ask_for_rating;if(this.#Y(t.data),e!==void 0&&e!==t.data.ask_for_rating)this.#K().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pt();return;case"presence":if(this.#r)this.#r={...this.#r,presence:t.data};break;case"conversation.created":if(!this.#e.has(t.data.id))this.#e.set(t.data.id,t.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#e.size>1)this.#i=this.#m.some((e)=>e.conversation===null)?this.#i:{kind:"list"};this.#R();break;case"conversation.updated":{let e=this.#e.get(t.data.id),{status:i,can_rate:n,rating:s}=t.data;if(e)this.#e.set(e.id,{...e,status:i,can_rate:n,rating:s});if(!n)this.#C.delete(t.data.id);break}case"message.created":case"message.updated":this.#et(t.data,t.type==="message.created");break;case"read":{let e=this.#e.get(t.data.conversation_id),i=e?.last_read_by_member_at;if(e&&(!i||v(t.data.read_at)>v(i)))this.#e.set(e.id,{...e,last_read_by_member_at:t.data.read_at});break}case"typing":{let e=t.data.conversation_id,i=this.#b.get(e);if(i)clearTimeout(i.timer);if(t.data.typing){let n=t.data.author.name??"";this.#b.set(e,{name:n,timer:setTimeout(()=>this.#b.delete(e)&&this.#o(),8000)})}else this.#b.delete(e);break}}this.#o()}#et(t,e){let i=t.conversation_id,n=this.#l.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===t.id);if(o>=0)n.messages[o]=t;else n.messages=[...n.messages,t].sort(ft)}if(t.client_id)this.#m=this.#m.filter((o)=>o.client_id!==t.client_id);let s=this.#e.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#e.set(o.id,o),this.#R(),this.#o()}).catch(()=>{return});return}if(e){let o=t.body.replace(/\s+/g," ").trim();if(this.#e.set(i,{...s,last_message:{id:t.id,author_type:t.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:t.created_at},last_message_at:t.created_at,unread:s.unread||t.author.type!=="contact"}),t.author.type!=="contact"){let a=this.#b.get(i);if(a)clearTimeout(a.timer);this.#b.delete(i),this.#zt(t)}}this.#R(),this.#$()}#zt(t){this.#tt.textContent=`${t.author.name||this.#r?.name||""}: ${t.body.slice(0,200)}`}#R(){let t=0;for(let e of this.#e.values())if(e.unread)t++;this.#s.setUnread(t)}#Et(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#$(){let t=this.#Et(),e=t?this.#e.get(t):void 0;if(!t||!e?.unread)return;this.#e.set(t,{...e,unread:!1}),this.#R(),this.#n.markRead(t).catch(()=>{let i=this.#e.get(t);if(i)this.#e.set(t,{...i,unread:!0});this.#R()})}#ft(t){this.#y=[...this.#y,...t].slice(0,Pt),this.#J(),this.#D(),this.#d.focus()}#gt(){if(this.#d.style.blockSize="",this.#d.value==="")return;this.#d.style.blockSize="auto",this.#d.style.blockSize=`${Math.max(38,Math.min(this.#d.scrollHeight,140))}px`}#D(){this.#A.disabled=this.#d.value.trim()===""&&this.#y.length===0}#Tt(){let t=this.#i?.kind==="thread"?this.#i.id:null;if(!t||this.#d.value.trim()===""){this.#M();return}if(Date.now()-this.#T>3000)this.#T=Date.now(),this.#n.setTyping(t,!0).catch(()=>{return});if(this.#k)clearTimeout(this.#k);this.#k=setTimeout(()=>this.#M(),4000)}#M(){if(this.#k)clearTimeout(this.#k);if(this.#k=null,this.#T===0)return;this.#T=0;let t=this.#i?.kind==="thread"?this.#i.id:null;if(t)this.#n.setTyping(t,!1).catch(()=>{return})}async#it(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let t=this.#d.value.trim(),e=this.#y;if(!t&&e.length===0)return;if(this.#i.id===null&&this.#m.some((n)=>n.conversation===null))return;this.#M(),this.#d.value="",this.#y=[],this.#gt(),this.#J(),this.#D();let i={client_id:F(),conversation:this.#i.id,body:t,files:e,state:"sending"};this.#m.push(i),this.#o(),this.#P(),await this.#mt(i)}async#mt(t){t.state="sending",this.#o();let e={body:t.body,files:t.files,client_id:t.client_id};try{if(t.conversation===null){let i=await this.#n.startConversation(e),n=i.conversation.id;if(!this.#e.has(n))this.#e.set(n,i.conversation);if(!this.#l.has(n))this.#l.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#et(i.message,!1)}else{let i=await this.#n.sendMessage(t.conversation,e);this.#et(i,!0)}this.#m=this.#m.filter((i)=>i!==t)}catch(i){let n=i instanceof g?i.status:0;t.state=n===413||n===415?"refused":"failed",t.status=n}this.#o(),this.#P()}async rate(t,e,i){try{let n=await this.#n.rate(t,e,i);return this.#e.set(n.id,n),this.#C.delete(t),this.#o(),n}catch(n){if(n instanceof g&&n.status===409){let s=await this.#n.getConversation(t).catch(()=>null);if(s)this.#e.set(s.id,s);this.#C.delete(t),this.#o()}throw n}}#Pt(t,e){if(this.#C.get(t)?.state==="sending")return;if(this.#C.set(t,{choice:e,state:"choosing"}),this.#o(),this.#u.focus({preventScroll:!0}),this.#I)this.#P()}async#yt(t,e){let i=this.#C.get(t);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(t,i.choice,e?this.#u.value:void 0),this.#u.value=""}catch(n){if(n instanceof g&&n.status===409)return;i.state="failed",this.#o()}}async#It(){let t=this.#_.value.trim();if(!t||!this.#_.checkValidity()){this.#w=this.#t({id:"E_qvzP"}),this.#st();return}try{this.#g=await this.#n.setEmail(t),this.#q=!0,this.#w=""}catch{this.#w=this.#t({id:"ZxJcgC"})}this.#st()}#vt(t){let e=this.#U.get(t.id);if(e)return Promise.resolve(e);let i=this.#G.get(t.id);if(!i)i=this.#n.attachment(t.id).then((n)=>{let s=URL.createObjectURL(n);return this.#U.set(t.id,s),s}),i.catch(()=>this.#G.delete(t.id)),this.#G.set(t.id,i);return i}async#bt(t){let e=await this.#vt(t),i=r("a");i.href=e,i.download=t.filename,i.rel="noopener",i.click()}#xt(){return[...this.#e.values()].sort(It)}#Rt(){let t=this.#r;if(!t)return!1;return!t.open_now||t.mode==="async"||!t.presence?.available}#P(){this.#I=!0,this.#c.scrollTop=this.#c.scrollHeight,requestAnimationFrame(()=>{if(this.#I)this.#c.scrollTop=this.#c.scrollHeight})}#kt(){this.#d.placeholder=this.#t({id:"RzWUUK"}),this.#d.setAttribute("aria-label",this.#t({id:"xDAtGP"})),this.#j.setAttribute("aria-label",this.#t({id:"N7m8E-"})),this.#j.title=this.#t({id:"N7m8E-"}),this.#A.setAttribute("aria-label",this.#t({id:"JlFcis"})),this.#A.title=this.#t({id:"JlFcis"}),this.#_.placeholder=this.#t({id:"njBr8W"}),this.#_.setAttribute("aria-label",this.#t({id:"XJURKP"})),this.#D(),this.#J(),this.#o()}#o(){let t=this.#s.panel;if(t.childElementCount===0){let e=r("style");e.textContent=ut,t.append(e,this.#X,this.#V,this.#L,this.#tt),this.#X.id="yuva-title",t.setAttribute("aria-labelledby","yuva-title")}if(this.#Lt(),this.#nt(),this.#a!=="ready"){this.#B=void 0;let e=r("div","center");if(this.#a==="loading")e.append(r("p","hint",this.#t({id:"Pwqkdw"})));else{e.append(r("p","empty",this.#Mt()));let i=r("button","primary",this.#t({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#v=null,this.#O()}),e.append(i)}this.#L.replaceChildren(e);return}if(this.#i?.kind==="list")this.#Ot();else this.#Ut()}#Mt(){switch(this.#f){case"anonymous_not_allowed":return this.#t({id:"zLzEI3"});case"invalid_identity_token":return this.#t({id:"0XGLbP"});case"rate_limited":return this.#t({id:"tzsBOP"});case"network":return this.#t({id:"GQVIIl"});default:return this.#t({id:"Amai22"})}}#Lt(){let{layout:t}=this.#s.config(),e=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#e.size>1||n.id===null&&this.#e.size>0))i.push(T(S.back,this.#t({id:"S63MQu"}),()=>{this.#M(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",e?.name||this.#t({id:"t7TeQU"}))),e){let o=r("div","status");if(e.mode==="live"&&e.open_now&&e.presence?.available){let l=r("div","avatars");for(let c of e.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.#t({id:"oXOSPE"})))}else if(!e.open_now||e.mode==="live")o.append(r("span","dot away"),r("span","",this.#t({id:"1EICzz"})));else o.append(r("span","",this.#At(e.expected_reply_minutes)));s.append(o)}if(i.push(s),t==="launcher")i.push(T(S.close,this.#t({id:"yz7wBu"}),()=>this.#s.close()));this.#X.replaceChildren(...i)}#At(t){if(!t)return this.#t({id:"nhTADq"});let{locale:e}=this.#s.config(),[i,n]=t<60?[t,"minute"]:t<1440?[Math.round(t/60),"hour"]:[Math.round(t/1440),"day"],s=new Intl.NumberFormat(e,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#t({id:"VggdQJ",values:{duration:s}})}#nt(){this.#V.hidden=!this.#h,this.#V.textContent=this.#t({id:"09Tv5j"})}#Ot(){this.#B=void 0;let{locale:t}=this.#s.config(),e=r("ul","list"),i=new Date().toDateString();for(let s of this.#xt()){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.#t({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(t,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#t({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#t({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.#$t(s.id));let u=r("li");u.append(o),e.append(u)}if(this.#E){let s=r("button","link",this.#t({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#K(!0).then(()=>this.#o())),e.append(s)}let n=r("button","primary",this.#t({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#d.focus()}),this.#L.replaceChildren(e,n)}async#$t(t){if(this.#i={kind:"thread",id:t},this.#o(),!this.#l.get(t)?.complete&&!this.#l.get(t)?.messages.length)await this.#F(t).catch(()=>{return});this.#o(),this.#P(),this.#$()}#Dt(t){let e=r("span","avatar",t.initials||""),i=t.avatar_url,n=i?this.#W.get(i):!1;if(!i||n===!1)return e;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,e.replaceChildren(s),e;return s.addEventListener("load",()=>{if(this.#W.set(i,!0),e.isConnected)e.replaceChildren(s)}),s.addEventListener("error",()=>this.#W.set(i,!1)),s.src=i,e}#Ut(){let t=this.#i;if(t?.kind!=="thread")return;let e=t.id,i=this.#B===e,n=this.#I,s=e?this.#l.get(e):void 0,o=s?.messages??[],a=this.#m.filter((d)=>d.conversation===e),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.#t({id:"meAa31"})),r("p","hint",this.#t({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#t({id:"Pwqkdw"})));o.forEach((d,m)=>{let k=o[m-1],x=o[m+1]??(a.length>0?null:void 0),f=d.author.type==="contact",w=!k||L(k)!==L(d)||v(d.created_at)-v(k.created_at)>pt,W=x===void 0||(x===null?!f:L(x)!==L(d)||v(x.created_at)-v(d.created_at)>pt);if(!f&&w&&d.author.name)l.push(r("div","author",d.author.name));let A=r("div",`row ${f?"mine":"theirs"}${w&&m>0?" group-gap":""}`);if(!f){let E=this.#Dt(d.author);if(!W)E.style.visibility="hidden";A.append(E)}let z=r("div","bubble");if(z.dir="auto",z.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())z.append(M(d.body));if(d.attachments.length>0)z.append(this.#Bt(d.attachments));if(A.append(z),l.push(A),W){let E=this.#Nt(d.created_at);if(f&&m===o.length-1&&a.length===0){let q=e?this.#e.get(e)?.last_read_by_member_at:void 0,mt=q&&v(q)>=v(d.created_at);E+=` · ${mt?this.#t({id:"6lGaum"}):this.#t({id:"h69WC6"})}`}let O=r("div","meta",E);if(!f)O.style.alignSelf="flex-start";if(!f)O.style.marginInlineStart="36px";l.push(O)}});let h=e?this.#e.get(e):void 0,p=h?this.#jt(h):null;if(p)l.push(p);a.forEach((d,m)=>{let k=r("div",`row mine${m===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),x=r("div","bubble");if(x.dir="auto",d.body)x.append(M(d.body));if(d.files.length>0){let f=r("div","files");for(let w of d.files)f.append(r("span","file",w.name||"image"));x.append(f)}if(k.append(x),l.push(k),d.state==="failed"){let f=r("div","meta failed",`${this.#t({id:"upFvcp"})} `),w=r("button","link",this.#t({id:"6gRgw8"}));w.type="button",w.addEventListener("click",()=>void this.#mt(d)),f.append(w),l.push(f)}else if(d.state==="refused"){let f=d.status===413?this.#t({id:"eOu9Px"}):this.#t({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#t({id:"upFvcp"})} ${f}`))}else if(m===a.length-1)l.push(r("div","meta",this.#t({id:"Sad2tK"})))});let u=e?this.#b.get(e):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let m=u.name;d.append(r("span","",m?this.#t({id:"tHaDPf",values:{name:m}}):this.#t({id:"PxYAul"}))),l.push(d)}let y=this.#c.getRootNode().activeElement===this.#u,{selectionStart:P,selectionEnd:_}=this.#u;if(this.#c.replaceChildren(...l),y&&this.#u.isConnected)this.#u.focus({preventScroll:!0}),this.#u.setSelectionRange(P,_);if(this.#st(),this.#L.firstChild!==this.#c)this.#L.replaceChildren(this.#c,this.#S,this.#ot);if(this.#B=e,!i||n)this.#P()}#jt(t){let e=t.status==="closed"?t.rating:void 0,i=t.can_rate&&this.#r?.ask_for_rating?this.#C.get(t.id):void 0;if(!e&&!(t.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#wt,s=[t.id,e,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#rt!==t.id)this.#rt=t.id,this.#u.value="";let o=this.#t({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(e&&e!==u)continue;let b=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");b.type="button";let y=u==="good"?this.#t({id:"OEEQKT"}):this.#t({id:"-f5Tkb"});b.setAttribute("aria-label",y),b.title=y,b.setAttribute("aria-pressed",String((e??i?.choice)===u)),b.disabled=!!e||i?.state==="sending",b.addEventListener("click",()=>this.#Pt(t.id,u)),a.append(b)}if(e)return n.replaceChildren(a,r("p","",this.#t({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#u.placeholder=this.#t({id:"axQ1h6"}),this.#u.setAttribute("aria-label",this.#t({id:"NBdIgR"})),this.#u.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#yt(t.id,!0)});let c=r("button","link",this.#t({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#yt(t.id,!1));let h=r("button","",i.state==="sending"?this.#t({id:"Sad2tK"}):this.#t({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#u,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#t({id:"4TqZiz"})));return n}#Bt(t){let e=r("div","files");for(let i of t)if(Rt(i)){let n=r("img");n.alt=i.filename;let s=this.#U.get(i.id);if(s)n.src=s;else this.#vt(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#I)this.#c.scrollTop=this.#c.scrollHeight}),n.addEventListener("click",()=>void this.#bt(i)),e.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=S.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#bt(i)),e.append(n)}return e}#Nt(t){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(t))}#st(){let t=this.#g,e=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#m.length>0,s=t?.email||t?.typed_email,o=!!e?.ask_email_offline&&this.#Rt()&&n&&(!s||this.#q);if(this.#S.hidden=!o,!o)return;if(s&&this.#q){this.#S.replaceChildren(r("p","",this.#t({id:"iGNUZJ",values:{known:s}})));return}if(this.#S.querySelector("form")){let c=this.#S.querySelector(".error");if(c)c.textContent=this.#w;else if(this.#w)this.#S.append(r("p","error",this.#w));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#It()});let l=r("button","",this.#t({id:"tfDRzk"}));if(l.type="submit",a.append(this.#_,l),this.#S.replaceChildren(r("p","",this.#t({id:"M62PBt"})),a),this.#w)this.#S.append(r("p","error",this.#w))}#J(){this.#Z.hidden=this.#y.length===0,this.#Z.replaceChildren(...this.#y.map((t,e)=>{let i=r("span","chip");return i.append(r("span","",t.name||"image"),T(S.close,this.#t({id:"w61W3L",values:{0:t.name}}),()=>{this.#y=this.#y.filter((n,s)=>s!==e),this.#J(),this.#D()})),i}))}}function Mt(t){return new gt(t)}export{Mt as mount};
|
package/dist/yuva.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var o=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var d=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var l={en:o,tr:d},k=new Set(["ar","fa","he","ur"]),
|
|
1
|
+
(()=>{var o=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var d=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');var l={en:o,tr:d},k=new Set(["ar","fa","he","ur"]),w="en";function p(...t){for(let e of t){if(!e)continue;let i=e.toLowerCase();if(l[i])return i;let n=i.split(/[-_]/)[0]??"";if(l[n])return n}return w}function f(t){return k.has(t.split(/[-_]/)[0]??"")?"rtl":"ltr"}function g(t){return l[t]??o}function r(t,e){let i=t[e.id]??o[e.id],n=e.values??{};if(typeof i==="string")return i;if(Array.isArray(i))return i.map((s)=>typeof s==="string"?s:Array.isArray(s)?String(n[s[0]]??""):"").join("");return e.message??e.id}function y(t){return{position:t.chat.launcher_position,color:t.chat.launcher_color??t.branding.color}}function m(t){return`yuva:${t}`}function c(t){try{let e=localStorage.getItem(m(t));return e?JSON.parse(e):{}}catch{return{}}}function v(t,e){try{localStorage.setItem(m(t),JSON.stringify(e))}catch{}}var C=`
|
|
2
2
|
:host {
|
|
3
3
|
--yuva-accent: #2563eb;
|
|
4
4
|
--yuva-on-accent: #ffffff;
|
|
@@ -106,4 +106,4 @@
|
|
|
106
106
|
block-size: 100%;
|
|
107
107
|
min-block-size: 320px;
|
|
108
108
|
}
|
|
109
|
-
`,
|
|
109
|
+
`,S='<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H9l-5 4z"/></svg>',L='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',h=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";function A(t){let e=Number.parseInt(t.slice(1),16),[i,n,s]=[e>>16&255,e>>8&255,e&255].map((x)=>{let a=x/255;return a<=0.03928?a/12.92:((a+0.055)/1.055)**2.4});return 0.2126*i+0.7152*n+0.0722*s>0.4?"#111827":"#ffffff"}class u extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",h||location.href).href);#r;#s=null;#n=null;#i;#t=null;#a={};#e=!1;#u=0;#l=null;#o=!1;constructor(){super();this.#r=this.attachShadow({mode:"open"}),this.#i=document.createElement("section"),this.#i.className="panel",this.#i.setAttribute("role","dialog"),this.#i.hidden=!0,this.#i.addEventListener("keydown",(t)=>{if(t.key==="Escape"&&this.layout==="launcher")this.close()})}get layout(){return this.getAttribute("layout")==="embedded"?"embedded":"launcher"}get channel(){return this.getAttribute("channel")}get server(){return(this.getAttribute("server")||(h?new URL(h).origin:location.origin)).replace(/\/+$/,"")}get locale(){return p(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#e}get unread(){return this.#u}setIdentityToken(t){if(this.#l=t,this.#t)this.#t.then((e)=>e.identityChanged())}async signOut(){if(this.#l=null,this.removeAttribute("identity-token"),this.#t)await(await this.#t).signOut()}async rate(t,e,i){return(await this.#d()).rate(t,e,i)}connectedCallback(){this.#c();let t=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!t)return;let e=c(t);if(e.launcher)this.#p(e.launcher);let i=()=>{if(!this.isConnected||this.#t||this.channel!==t)return;if(e.session)this.#d();else this.#g(t)};if("requestIdleCallback"in window)requestIdleCallback(i,{timeout:3000});else setTimeout(i,1000)}#g(t){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(t)}`,{credentials:"omit"}).then((e)=>{if(e.status===403||e.status===404)this.#f();return e.ok?e.json():null}).then((e)=>{if(!e||this.channel!==t||this.#t)return;let i=y(e);this.#p(i),v(t,{...c(t),launcher:i})}).catch(()=>{return})}disconnectedCallback(){let t=this.#t;if(this.#t=null,t)t.then((e)=>e.destroy())}attributeChangedCallback(t,e,i){if(!this.isConnected||e===i)return;if(t==="open"){i===null?this.close():this.open();return}if(t==="identity-token"){if(this.#t)this.#t.then((n)=>n.identityChanged());return}if(t==="channel"||t==="server"){this.disconnectedCallback(),this.#o=!1,this.#c();return}if(this.#c(),this.#t)this.#t.then((n)=>n.update())}async open(){if(this.#e||this.#o)return;this.#e=!0,this.toggleAttribute("open-panel",!0),this.#h();let t=await this.#d();if(!this.#e)return;this.#i.hidden=!1,t.opened()}close(){if(!this.#e||this.layout==="embedded")return;if(this.#e=!1,this.toggleAttribute("open-panel",!1),this.#i.hidden=!0,this.#h(),this.#s?.focus(),this.#t)this.#t.then((t)=>t.closed())}toggle(){return this.#e?this.close():this.open()}#y(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#d(){return this.#t??=u.loadPanel().then(({mount:t})=>t({panel:this.#i,config:()=>this.#y(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#e,close:()=>this.close(),setUnread:(e)=>{this.#u=e,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:e}}))},setLauncher:(e)=>this.#p(e),refused:()=>this.#f()})),this.#t}#f(){if(this.#o)return;this.#o=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#e=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(t){if(this.setAttribute("position",t.position==="left"?"left":"right"),t.color&&/^#[0-9a-f]{6}$/i.test(t.color))this.style.setProperty("--yuva-accent",t.color),this.style.setProperty("--yuva-on-accent",A(t.color))}#c(){let t=this.locale;this.#a=g(t),this.setAttribute("lang",t);let e=document.createElement("style");if(e.textContent=C,this.#i.dir=this.getAttribute("dir")??f(t),this.#i.setAttribute("aria-modal","false"),this.#o){this.#s=null,this.#n=null,this.#r.replaceChildren();return}if(this.layout==="embedded"){this.#s=null,this.#n=null,this.#r.replaceChildren(e,this.#i),this.#e=!1,this.open();return}let i=document.createElement("button");if(i.type="button",i.className="launcher",i.addEventListener("click",()=>void this.toggle()),this.#s=i,this.#n=document.createElement("span"),this.#n.className="badge",this.#n.setAttribute("aria-hidden","true"),this.#r.replaceChildren(e,this.#i,i),this.#h(),this.hasAttribute("open")&&!this.#e)this.open()}#h(){let t=this.#s,e=this.#n;if(!t||!e)return;let i=this.#u;t.setAttribute("aria-expanded",String(this.#e)),t.setAttribute("aria-label",this.#e?r(this.#a,{id:"pqZJT2"}):i>0?r(this.#a,{id:"OkHvGB",values:{count:i}}):r(this.#a,{id:"6I7cJR"})),t.innerHTML=this.#e?L:S,e.textContent=i>9?"9+":String(i),e.hidden=this.#e||i===0,t.append(e)}}function b(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",u)}b();})();
|