useyuva 0.0.12 → 0.0.14

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.
Files changed (38) hide show
  1. package/README.md +244 -2
  2. package/dist/esm/chat.js +2 -2
  3. package/dist/esm/docs.js +4 -4
  4. package/dist/esm/h3.js +1 -0
  5. package/dist/esm/{index-c6q8br7d.js → index-9vqd1b2a.js} +1 -1
  6. package/dist/esm/index-qcd538se.js +2 -0
  7. package/dist/esm/index-r9f9ttb2.js +2 -0
  8. package/dist/esm/nitro/module.js +39 -0
  9. package/dist/esm/nitro/runtime/core.js +64 -0
  10. package/dist/esm/nitro/runtime/define.js +3 -0
  11. package/dist/esm/nitro/runtime/identity.js +3 -0
  12. package/dist/esm/nitro/runtime/plugin.js +3 -0
  13. package/dist/esm/nitro/runtime/webhook.js +3 -0
  14. package/dist/esm/nitro/setup.js +65 -0
  15. package/dist/esm/nuxt/module.js +64 -2
  16. package/dist/esm/nuxt/runtime/components.js +8 -1
  17. package/dist/esm/server.js +1 -0
  18. package/dist/esm/subscribe.js +2 -2
  19. package/dist/esm/{thread-btm71nxt.js → thread-gx5pssds.js} +1 -1
  20. package/dist/esm/{yuva-chat-kf9vz8r3.js → yuva-chat-025wzr6w.js} +2 -2
  21. package/dist/types/h3.d.ts +36 -0
  22. package/dist/types/nitro/module.d.ts +8 -0
  23. package/dist/types/nitro/runtime/core.d.ts +41 -0
  24. package/dist/types/nitro/runtime/define.d.ts +21 -0
  25. package/dist/types/nitro/setup.d.ts +36 -0
  26. package/dist/types/nuxt/module.d.ts +17 -3
  27. package/dist/types/server/analytics.d.ts +52 -0
  28. package/dist/types/server/encoding.d.ts +6 -0
  29. package/dist/types/server/identity.d.ts +14 -0
  30. package/dist/types/server/webhook.d.ts +28 -0
  31. package/dist/types/server.d.ts +3 -0
  32. package/dist/types/styles.d.ts +2 -0
  33. package/dist/yuva-chat.js +6 -6
  34. package/dist/yuva-docs.js +6 -6
  35. package/dist/yuva-subscribe.js +2 -2
  36. package/dist/yuva.js +2 -2
  37. package/package.json +26 -2
  38. package/dist/esm/index-98r96a7e.js +0 -2
@@ -1,4 +1,4 @@
1
- (()=>{class p extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function b(e,t,i,{method:n="GET",json:s,body:r,headers:o={},token:a,blob:l}={}){if(o={...o},a)o.Authorization=`Bearer ${a}`;let h=r;if(s!==void 0)o["Content-Type"]="application/json",h=JSON.stringify(s);let u;try{u=await e(t+i,{method:n,headers:o,body:h,credentials:"omit"})}catch{throw new p(0,"network")}if(!u.ok){let d="error";try{d=(await u.json()).code??d}catch{}throw new p(u.status,d)}if(u.status===204)return;return l?await u.blob():await u.json()}function C(e,t,i){return b(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function k(e,t,i,n){return b(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:n})}function c(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}var g=JSON.parse('{"-g5O6h":["Choose at least one list."],"1w51t9":["Subscribing…"],"EDl9kS":["Subscribe"],"E_LjOR":["Enter your name."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"ScJ9fj":["Privacy policy"],"XJURKP":["E-mail address"],"YnOaHp":["Your name (optional)"],"dMJfG5":["I want to receive e-mails about ",["list"]," from ",["inbox"],". I can unsubscribe at any time."],"eku1-t":["Your account has no e-mail address yet."],"h16FyT":["Lists"],"jWgNnM":["Could not subscribe. Try again."],"lDEbTy":["Tick the box to agree."],"q8yluz":["Your name"],"rgySXy":["Thanks! You are subscribed."],"tzsBOP":["Too many attempts. Wait a moment and try again."],"x6dU53":["Check your inbox to confirm."],"y3k2zM":["Almost done. Check your inbox and confirm your subscription."]}');var w=JSON.parse('{"-g5O6h":["Wählen Sie mindestens eine Liste."],"1w51t9":["Wird angemeldet…"],"EDl9kS":["Abonnieren"],"E_LjOR":["Geben Sie Ihren Namen ein."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"ScJ9fj":["Datenschutzerklärung"],"XJURKP":["E-Mail-Adresse"],"YnOaHp":["Ihr Name (optional)"],"dMJfG5":["Ich möchte E-Mails von ",["inbox"]," zu ",["list"]," erhalten. Ich kann mich jederzeit abmelden."],"eku1-t":["Ihr Konto hat noch keine E-Mail-Adresse."],"h16FyT":["Listen"],"jWgNnM":["Anmeldung fehlgeschlagen. Versuchen Sie es erneut."],"lDEbTy":["Setzen Sie das Häkchen, um zuzustimmen."],"q8yluz":["Ihr Name"],"rgySXy":["Danke! Sie sind angemeldet."],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"x6dU53":["Sehen Sie zur Bestätigung in Ihr Postfach."],"y3k2zM":["Fast geschafft. Sehen Sie in Ihr Postfach und bestätigen Sie Ihr Abonnement."]}');var A=JSON.parse('{"-g5O6h":["En az bir liste seçin."],"1w51t9":["Abone olunuyor…"],"EDl9kS":["Abone ol"],"E_LjOR":["Adınızı girin."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"ScJ9fj":["Gizlilik politikası"],"XJURKP":["E-posta adresi"],"YnOaHp":["Adınız (isteğe bağlı)"],"dMJfG5":[["list"]," hakkında ",["inbox"]," tarafından gönderilen e-postaları almak istiyorum. Aboneliğimi istediğim zaman bırakabilirim."],"eku1-t":["Hesabınızda henüz bir e-posta adresi yok."],"h16FyT":["Listeler"],"jWgNnM":["Abone olunamadı. Yeniden deneyin."],"lDEbTy":["Onaylamak için kutuyu işaretleyin."],"q8yluz":["Adınız"],"rgySXy":["Teşekkürler! Abone oldunuz."],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"x6dU53":["Onaylamak için gelen kutunuza bakın."],"y3k2zM":["Neredeyse bitti. Gelen kutunuza bakın ve aboneliğinizi onaylayın."]}');function P(e,t,i){let n=e[t.id]??i[t.id],s=t.values??{};if(typeof n==="string")return n;if(Array.isArray(n))return n.map((r)=>typeof r==="string"?r:Array.isArray(r)?String(s[r[0]]??""):"").join("");return t.message??t.id}var I=new Set(["ar","fa","he","ur"]),R="en";function E(e,t){for(let i of t){if(!i)continue;let n=i.toLowerCase();if(e[n])return n;let s=n.split(/[-_]/)[0]??"";if(e[s])return s}return R}function M(e){return I.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}function z(e){let t=Number.parseInt(e.slice(1),16),[i,n,s]=[t>>16&255,t>>8&255,t&255].map((r)=>{let o=r/255;return o<=0.03928?o/12.92:((o+0.055)/1.055)**2.4});return 0.2126*i+0.7152*n+0.0722*s>0.4?"#111827":"#ffffff"}var L={en:g,tr:A,de:w},D=2100,y=(e,t)=>fetch(e,t),_=typeof HTMLElement>"u"?class{}:HTMLElement,x=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",O=`
1
+ (()=>{class p extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function b(e,t,i,{method:n="GET",json:s,body:r,headers:o={},token:a,blob:c}={}){if(o={...o},a)o.Authorization=`Bearer ${a}`;let h=r;if(s!==void 0)o["Content-Type"]="application/json",h=JSON.stringify(s);let u;try{u=await e(t+i,{method:n,headers:o,body:h,credentials:"omit"})}catch{throw new p(0,"network")}if(!u.ok){let d="error";try{d=(await u.json()).code??d}catch{}throw new p(u.status,d)}if(u.status===204)return;return c?await u.blob():await u.json()}function C(e,t,i){return b(e,t,`/client/v1/channels/${encodeURIComponent(i)}/lists`)}function k(e,t,i,n){return b(e,t,`/client/v1/channels/${encodeURIComponent(i)}/subscriptions`,{method:"POST",json:n})}function l(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}var g=JSON.parse('{"-g5O6h":["Choose at least one list."],"1w51t9":["Subscribing…"],"EDl9kS":["Subscribe"],"E_LjOR":["Enter your name."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"ScJ9fj":["Privacy policy"],"XJURKP":["E-mail address"],"YnOaHp":["Your name (optional)"],"dMJfG5":["I want to receive e-mails about ",["list"]," from ",["inbox"],". I can unsubscribe at any time."],"eku1-t":["Your account has no e-mail address yet."],"h16FyT":["Lists"],"jWgNnM":["Could not subscribe. Try again."],"lDEbTy":["Tick the box to agree."],"q8yluz":["Your name"],"rgySXy":["Thanks! You are subscribed."],"tzsBOP":["Too many attempts. Wait a moment and try again."],"x6dU53":["Check your inbox to confirm."],"y3k2zM":["Almost done. Check your inbox and confirm your subscription."]}');var w=JSON.parse('{"-g5O6h":["Wählen Sie mindestens eine Liste."],"1w51t9":["Wird angemeldet…"],"EDl9kS":["Abonnieren"],"E_LjOR":["Geben Sie Ihren Namen ein."],"E_qvzP":["Geben Sie eine gültige E-Mail-Adresse ein."],"GQVIIl":["Sie scheinen offline zu sein."],"ScJ9fj":["Datenschutzerklärung"],"XJURKP":["E-Mail-Adresse"],"YnOaHp":["Ihr Name (optional)"],"dMJfG5":["Ich möchte E-Mails von ",["inbox"]," zu ",["list"]," erhalten. Ich kann mich jederzeit abmelden."],"eku1-t":["Ihr Konto hat noch keine E-Mail-Adresse."],"h16FyT":["Listen"],"jWgNnM":["Anmeldung fehlgeschlagen. Versuchen Sie es erneut."],"lDEbTy":["Setzen Sie das Häkchen, um zuzustimmen."],"q8yluz":["Ihr Name"],"rgySXy":["Danke! Sie sind angemeldet."],"tzsBOP":["Zu viele Versuche. Warten Sie einen Moment und versuchen Sie es erneut."],"x6dU53":["Sehen Sie zur Bestätigung in Ihr Postfach."],"y3k2zM":["Fast geschafft. Sehen Sie in Ihr Postfach und bestätigen Sie Ihr Abonnement."]}');var A=JSON.parse('{"-g5O6h":["En az bir liste seçin."],"1w51t9":["Abone olunuyor…"],"EDl9kS":["Abone ol"],"E_LjOR":["Adınızı girin."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"ScJ9fj":["Gizlilik politikası"],"XJURKP":["E-posta adresi"],"YnOaHp":["Adınız (isteğe bağlı)"],"dMJfG5":[["list"]," hakkında ",["inbox"]," tarafından gönderilen e-postaları almak istiyorum. Aboneliğimi istediğim zaman bırakabilirim."],"eku1-t":["Hesabınızda henüz bir e-posta adresi yok."],"h16FyT":["Listeler"],"jWgNnM":["Abone olunamadı. Yeniden deneyin."],"lDEbTy":["Onaylamak için kutuyu işaretleyin."],"q8yluz":["Adınız"],"rgySXy":["Teşekkürler! Abone oldunuz."],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"x6dU53":["Onaylamak için gelen kutunuza bakın."],"y3k2zM":["Neredeyse bitti. Gelen kutunuza bakın ve aboneliğinizi onaylayın."]}');function E(e,t,i){let n=e[t.id]??i[t.id],s=t.values??{};if(typeof n==="string")return n;if(Array.isArray(n))return n.map((r)=>typeof r==="string"?r:Array.isArray(r)?String(s[r[0]]??""):"").join("");return t.message??t.id}var D=new Set(["ar","fa","he","ur"]),_="en";function M(e,t){for(let i of t){if(!i)continue;let n=i.toLowerCase();if(e[n])return n;let s=n.split(/[-_]/)[0]??"";if(e[s])return s}return _}function P(e){return D.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var z=new Map;function O(e){if(typeof CSSStyleSheet>"u"||!("replaceSync"in CSSStyleSheet.prototype))return null;let t=z.get(e);if(!t)t=new CSSStyleSheet,t.replaceSync(e),z.set(e,t);return t}function q(e){let t=document.createElement("style");return t.textContent=e,t}function L(e,t){let i=O(t);if(!i)return q(t);return e.adoptedStyleSheets=[i],null}function T(e){let t=Number.parseInt(e.slice(1),16),[i,n,s]=[t>>16&255,t>>8&255,t&255].map((r)=>{let o=r/255;return o<=0.03928?o/12.92:((o+0.055)/1.055)**2.4});return 0.2126*i+0.7152*n+0.0722*s>0.4?"#111827":"#ffffff"}var I={en:g,tr:A,de:w},N=2100,y=(e,t)=>fetch(e,t),j=typeof HTMLElement>"u"?class{}:HTMLElement,S=typeof document<"u"&&document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",U=`
2
2
  :host{display:block;line-height:1.5}
3
3
  :host([hidden]),[hidden]{display:none!important}
4
4
  *{box-sizing:border-box}
@@ -30,4 +30,4 @@ legend{padding:0;margin-block-end:4px;font-weight:600}
30
30
  .error{color:var(--d)}
31
31
  .trap{position:absolute;inset-inline-start:-1e4px;inline-size:1px;overflow:hidden}
32
32
  @media (max-width:480px){input{font-size:16px}}
33
- `;class f extends _{static observedAttributes=["channel","server","locale","dir","lists","layout","name","button-text","consent","privacy-url","identity-token"];static loadClient=null;#l;#L=g;#g=!1;#a=0;#i="loading";#C=!1;#b=null;#c=[];#h=new Set;#v="";#k=0;#w=!1;#r="";#u="";#y="";#d="";#x=null;#p=null;#S=new Set;#t=c("input");#n=c("input");#m=c("input");#o=c("input");#f=c("p");constructor(){super();this.#l=this.attachShadow({mode:"open"}),this.#t.type="email",this.#t.autocomplete="email",this.#t.required=!0,this.#t.maxLength=320,this.#t.id="email",this.#n.autocomplete="name",this.#n.maxLength=200,this.#n.id="name",this.#m.name="website",this.#m.tabIndex=-1,this.#m.autocomplete="off",this.#o.type="checkbox",this.#o.id="consent",this.#o.addEventListener("change",()=>{this.#d="",this.#s()});for(let e of[this.#t,this.#n])e.setAttribute("part","field"),e.dir="auto";this.#f.setAttribute("part","status"),this.#f.setAttribute("role","status"),this.#f.setAttribute("aria-live","polite")}get channel(){return this.getAttribute("channel")}set channel(e){this.#A("channel",e)}get server(){return(this.getAttribute("server")||(x?new URL(x).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#A("server",e)}get locale(){return E(L,[this.getAttribute("locale"),navigator.language])}set locale(e){this.#A("locale",e)}get lists(){return this.#c.map((e)=>e.list)}setIdentityToken(e){if(this.#x=e,this.#g)this.#P()}connectedCallback(){this.#g=!0,this.#P()}disconnectedCallback(){this.#g=!1}attributeChangedCallback(e,t,i){if(!this.#g||t===i)return;if(["channel","server","lists","identity-token"].includes(e))return void this.#P();this.#s()}#A(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}#e(e){return P(this.#L,e,g)}get#q(){return!!this.#x||this.hasAttribute("identity-token")}async#T(){return this.#x?await this.#x()??null:this.getAttribute("identity-token")}#I(e){let t=(this.getAttribute("lists")??"").split(",").map((n)=>n.trim()).filter((n)=>n&&n!=="all");if(t.length===0)return e;let i=t.map((n)=>e.find((s)=>s.id===n)).filter((n)=>!!n);if(i.length<t.length)console.warn(`Yuva: some lists in "${t.join(",")}" are not public lists`);return i}async#P(){let e=++this.#a,t=this.channel;if(this.#C=!1,this.#i="loading",this.#c=[],this.#r="",this.#p=null,this.#s(),!t)return;let i=this.server;try{let n=b(y,i,`/client/v1/channels/${encodeURIComponent(t)}`),s=null;if(this.#q&&f.loadClient&&await this.#T()){let{createYuvaClient:r}=await f.loadClient(),o=r({server:i,channel:t,identityToken:()=>this.#T()});try{let{items:a}=await o.subscriptions(),l=new Set(this.#I(a.map((h)=>h.list)));s=a.filter((h)=>l.has(h.list)),this.#p=o}catch(a){if(!(a instanceof p)||a.code!=="identity_required")throw a}}if(!s){let{lists:r,form_token:o}=await C(y,i,t);s=this.#I(r).map((a)=>({list:a})),this.#v=o,this.#k=Date.now()}if(this.#b=await n,e!==this.#a)return;if(this.#c=s,this.#h=new Set(s.length===1?[s[0].list.id]:[]),this.#i="idle",s.length===0)console.warn(`Yuva: channel ${t} has no public mailing lists to offer`)}catch(n){if(e!==this.#a)return;if(this.#R(n))return;this.#i="idle",this.#r=this.#E(n)}this.#s()}#R(e){let t=e instanceof p&&(e.status===404||e.code==="origin_not_allowed"||e.code==="page_origin");if(t)this.#C=!0,console.warn(`Yuva: channel ${this.channel} is unknown, offers no such list or does not allow ${location.origin}`),this.#s();return t}#E(e){let t=e instanceof p?e.code:"";if(t==="rate_limited")return this.#e({id:"tzsBOP"});if(t==="network")return this.#e({id:"GQVIIl"});if(t==="no_email")return this.#e({id:"eku1-t"});return this.#e({id:"jWgNnM"})}#M(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#D(e){this.#M("yuva-subscribe-error",{code:e instanceof p?e.code:"error"})}consentText(e=this.#_()){let t=this.getAttribute("consent")?.trim();if(t)return t;let i=(e.length?e:this.lists).map((r)=>r.name),n=new Intl.ListFormat(this.locale,{type:"conjunction"}).format(i),s=this.#b?.name??"";return this.#e({id:"dMJfG5",values:{list:n,inbox:s}})}#_(){return this.lists.filter((e)=>this.#h.has(e.id))}async#N(){if(this.#i!=="idle"||!this.channel)return;let e=this.#_(),t=this.#t.value.trim(),i=this.#n.value.trim(),n=this.getAttribute("name");if(this.#r=e.length===0?this.#e({id:"-g5O6h"}):"",this.#u=this.#t.checkValidity()&&t?"":this.#e({id:"E_qvzP"}),this.#y=n==="required"&&!i?this.#e({id:"E_LjOR"}):"",this.#d=this.#o.checked?"":this.#e({id:"lDEbTy"}),this.#r||this.#u||this.#y||this.#d){this.#s();let l=[this.#u&&this.#t,this.#y&&this.#n,this.#d&&this.#o];for(let h of l)if(h)return h.focus();return}let s=this.channel,r=this.#a,o=this.consentText(e);this.#i="submitting",this.#s();let a=async(l)=>{let h=this.#k+D-Date.now();if(h>0)await new Promise((u)=>setTimeout(u,h));try{let{confirmation:u}=await k(y,this.server,s,{email:t,name:n==="optional"||n==="required"?i||void 0:void 0,list_ids:e.map((d)=>d.id),locale:this.locale,page_url:location.href.split("#")[0].slice(0,2000),consent_text:o,form_token:this.#v,website:this.#m.value||void 0});return this.#w=u,!0}catch(u){if(l&&u instanceof p&&u.code==="form_token"){let d=await C(y,this.server,s);return this.#v=d.form_token,this.#k=Date.now(),a(!1)}throw u}};try{await a(!0)}catch(l){if(r!==this.#a)return;if(this.#D(l),this.#i="idle",this.#R(l))return;if(l instanceof p&&l.code==="invalid_email")return this.#u=this.#e({id:"E_qvzP"}),this.#s(),this.#t.focus();return this.#r=this.#E(l),this.#s()}if(r!==this.#a)return;this.#i="done",this.#M("yuva-subscribe",{lists:e.map((l)=>l.id),confirmation:this.#w}),this.#s()}async#j(e,t){let i=this.#p;if(!i||this.#S.has(e.list.id))return;this.#S.add(e.list.id),this.#r="",this.#s();try{if(t){let{state:n}=await i.subscribeList(e.list.id,{consent_text:this.consentText([e.list]),page_url:location.href.split("#")[0].slice(0,2000)});e.state=n,this.#M("yuva-subscribe",{lists:[e.list.id],confirmation:n==="pending"})}else await i.unsubscribeList(e.list.id),e.state="unsubscribed"}catch(n){this.#D(n),this.#r=this.#E(n)}if(this.#S.delete(e.list.id),i===this.#p)this.#s()}#z(e,t){if(e.setAttribute("aria-invalid",String(!!t)),!t)return e.removeAttribute("aria-describedby"),null;let i=`${e.id}-error`;e.setAttribute("aria-describedby",i);let n=c("p","error",t);return n.id=i,n}#U(e,t,i,n){let s=c("label","check"),r=c("input");r.type="checkbox",r.checked=t,r.dataset.key=n,r.addEventListener("change",()=>i(r.checked));let o=c("span","text");return o.append(...e),s.append(r,o),s}#O(e){if(!e&&this.#c.length<2)return null;let t=c("fieldset");t.append(c("legend","",this.#e({id:"h16FyT"})));for(let i of this.#c){let n=[c("span","",i.list.name)];if(i.list.description)n.push(c("span","muted",i.list.description));if(e){if(n.push(c("span","muted consent",this.consentText([i.list]))),i.state==="pending")n.push(c("span","muted",this.#e({id:"x6dU53"})))}let s=e?i.state==="subscribed"||i.state==="pending":this.#h.has(i.list.id),r=this.#U(n,s,(a)=>{if(e)return void this.#j(i,a);if(a)this.#h.add(i.list.id);else this.#h.delete(i.list.id);this.#r="",this.#s()},i.list.id),o=r.querySelector("input");if(e)o.setAttribute("role","switch"),o.setAttribute("aria-checked",String(o.checked)),o.addEventListener("keydown",(a)=>{if(a.key!=="Enter")return;a.preventDefault(),o.click()}),o.disabled=this.#S.has(i.list.id);else o.disabled=this.#i==="submitting";t.append(r)}return t}#J(){let e=c("form",this.getAttribute("layout")==="inline"?"inline":"");e.noValidate=!0,e.addEventListener("submit",(m)=>{m.preventDefault(),this.#N()});let t=this.#i==="submitting",i=this.#O(!1);if(i)e.append(i);let n=c("div","row"),s=[],r=this.getAttribute("name");if(r==="optional"||r==="required"){this.#n.placeholder=r==="required"?this.#e({id:"q8yluz"}):this.#e({id:"YnOaHp"}),this.#n.setAttribute("aria-label",this.#n.placeholder),this.#n.required=r==="required",this.#n.disabled=t,n.append(this.#n);let m=this.#z(this.#n,this.#y);if(m)s.push(m)}this.#t.placeholder=this.#e({id:"XJURKP"}),this.#t.setAttribute("aria-label",this.#t.placeholder),this.#t.disabled=t,n.append(this.#t);let o=this.#z(this.#t,this.#u);if(o)s.push(o);let a=c("button","",t?this.#e({id:"1w51t9"}):this.getAttribute("button-text")||this.#e({id:"EDl9kS"}));a.type="submit",a.disabled=t,a.setAttribute("part","button"),n.append(a);let l=c("div","trap");l.setAttribute("aria-hidden","true"),l.append(this.#m);let h=c("span","",this.consentText()),u=c("label","check consent");u.setAttribute("part","consent"),this.#o.disabled=t;let d=c("span");d.append(h);let S=this.getAttribute("privacy-url");if(S&&/^https?:\/\//i.test(S)){let m=c("a","",this.#e({id:"ScJ9fj"}));m.href=S,m.target="_blank",m.rel="noopener noreferrer",d.append(" ",m)}u.append(this.#o,d);let v=this.#z(this.#o,this.#d);if(e.append(n,...s,u),v)e.append(v);return e.append(l),e}#s(){if(this.#C||!this.channel||this.#i!=="loading"&&this.#c.length===0&&!this.#r){this.#l.replaceChildren();return}let e=this.locale;this.#L=L[e]??g;let t=this.getAttribute("dir"),i=c("div","frame");i.dir=t==="rtl"||t==="ltr"?t:M(e),i.lang=e;let n=this.#b?.chat.launcher_color??this.#b?.branding.color;if(n&&/^#[0-9a-f]{6}$/i.test(n))i.style.setProperty("--brand",n),i.style.setProperty("--brand-on",z(n));let s="";if(this.#i==="done")s=this.#w?this.#e({id:"y3k2zM"}):this.#e({id:"rgySXy"});if(this.#f.textContent=s,this.#i==="idle"||this.#i==="submitting"){let h=this.#p?this.#O(!0):this.#J();if(h)i.append(h)}if(i.append(this.#f),this.#r){let h=c("p","error",this.#r);h.setAttribute("role","alert"),i.append(h)}let r,o=null;try{o=this.#l.activeElement}catch{}if(o instanceof HTMLInputElement)r=o.dataset.key;let a=c("style");a.textContent=O,this.#l.replaceChildren(a,i);let l=r?this.#l.querySelector(`[data-key="${r}"]`):o;if(l instanceof HTMLElement&&l.isConnected)l.focus({preventScroll:!0})}}function T(){if(typeof customElements>"u")return;if(!customElements.get("yuva-subscribe"))customElements.define("yuva-subscribe",f)}f.loadClient=()=>import(new URL("widget/yuva-subscribe-client-kba66fz1.js",x||location.href).href);T();})();
33
+ `;class m extends j{static observedAttributes=["channel","server","locale","dir","lists","layout","name","button-text","consent","privacy-url","identity-token"];static loadClient=null;#a;#L=g;#g=!1;#l=0;#i="loading";#C=!1;#b=null;#c=[];#h=new Set;#v="";#k=0;#w=!1;#r="";#u="";#y="";#d="";#S=null;#p=null;#x=new Set;#t=l("input");#n=l("input");#f=l("input");#o=l("input");#m=l("p");constructor(){super();this.#a=this.attachShadow({mode:"open"}),this.#t.type="email",this.#t.autocomplete="email",this.#t.required=!0,this.#t.maxLength=320,this.#t.id="email",this.#n.autocomplete="name",this.#n.maxLength=200,this.#n.id="name",this.#f.name="website",this.#f.tabIndex=-1,this.#f.autocomplete="off",this.#o.type="checkbox",this.#o.id="consent",this.#o.addEventListener("change",()=>{this.#d="",this.#s()});for(let e of[this.#t,this.#n])e.setAttribute("part","field"),e.dir="auto";this.#m.setAttribute("part","status"),this.#m.setAttribute("role","status"),this.#m.setAttribute("aria-live","polite")}get channel(){return this.getAttribute("channel")}set channel(e){this.#A("channel",e)}get server(){return(this.getAttribute("server")||(S?new URL(S).origin:location.origin)).replace(/\/+$/,"")}set server(e){this.#A("server",e)}get locale(){return M(I,[this.getAttribute("locale"),navigator.language])}set locale(e){this.#A("locale",e)}get lists(){return this.#c.map((e)=>e.list)}setIdentityToken(e){if(this.#S=e,this.#g)this.#E()}connectedCallback(){this.#g=!0,this.#E()}disconnectedCallback(){this.#g=!1}attributeChangedCallback(e,t,i){if(!this.#g||t===i)return;if(["channel","server","lists","identity-token"].includes(e))return void this.#E();this.#s()}#A(e,t){if(t===null||t===void 0||t==="")this.removeAttribute(e);else this.setAttribute(e,t)}#e(e){return E(this.#L,e,g)}get#q(){return!!this.#S||this.hasAttribute("identity-token")}async#T(){return this.#S?await this.#S()??null:this.getAttribute("identity-token")}#I(e){let t=(this.getAttribute("lists")??"").split(",").map((n)=>n.trim()).filter((n)=>n&&n!=="all");if(t.length===0)return e;let i=t.map((n)=>e.find((s)=>s.id===n)).filter((n)=>!!n);if(i.length<t.length)console.warn(`Yuva: some lists in "${t.join(",")}" are not public lists`);return i}async#E(){let e=++this.#l,t=this.channel;if(this.#C=!1,this.#i="loading",this.#c=[],this.#r="",this.#p=null,this.#s(),!t)return;let i=this.server;try{let n=b(y,i,`/client/v1/channels/${encodeURIComponent(t)}`),s=null;if(this.#q&&m.loadClient&&await this.#T()){let{createYuvaClient:r}=await m.loadClient(),o=r({server:i,channel:t,identityToken:()=>this.#T()});try{let{items:a}=await o.subscriptions(),c=new Set(this.#I(a.map((h)=>h.list)));s=a.filter((h)=>c.has(h.list)),this.#p=o}catch(a){if(!(a instanceof p)||a.code!=="identity_required")throw a}}if(!s){let{lists:r,form_token:o}=await C(y,i,t);s=this.#I(r).map((a)=>({list:a})),this.#v=o,this.#k=Date.now()}if(this.#b=await n,e!==this.#l)return;if(this.#c=s,this.#h=new Set(s.length===1?[s[0].list.id]:[]),this.#i="idle",s.length===0)console.warn(`Yuva: channel ${t} has no public mailing lists to offer`)}catch(n){if(e!==this.#l)return;if(this.#R(n))return;this.#i="idle",this.#r=this.#M(n)}this.#s()}#R(e){let t=e instanceof p&&(e.status===404||e.code==="origin_not_allowed"||e.code==="page_origin");if(t)this.#C=!0,console.warn(`Yuva: channel ${this.channel} is unknown, offers no such list or does not allow ${location.origin}`),this.#s();return t}#M(e){let t=e instanceof p?e.code:"";if(t==="rate_limited")return this.#e({id:"tzsBOP"});if(t==="network")return this.#e({id:"GQVIIl"});if(t==="no_email")return this.#e({id:"eku1-t"});return this.#e({id:"jWgNnM"})}#P(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}#D(e){this.#P("yuva-subscribe-error",{code:e instanceof p?e.code:"error"})}consentText(e=this.#_()){let t=this.getAttribute("consent")?.trim();if(t)return t;let i=(e.length?e:this.lists).map((r)=>r.name),n=new Intl.ListFormat(this.locale,{type:"conjunction"}).format(i),s=this.#b?.name??"";return this.#e({id:"dMJfG5",values:{list:n,inbox:s}})}#_(){return this.lists.filter((e)=>this.#h.has(e.id))}async#N(){if(this.#i!=="idle"||!this.channel)return;let e=this.#_(),t=this.#t.value.trim(),i=this.#n.value.trim(),n=this.getAttribute("name");if(this.#r=e.length===0?this.#e({id:"-g5O6h"}):"",this.#u=this.#t.checkValidity()&&t?"":this.#e({id:"E_qvzP"}),this.#y=n==="required"&&!i?this.#e({id:"E_LjOR"}):"",this.#d=this.#o.checked?"":this.#e({id:"lDEbTy"}),this.#r||this.#u||this.#y||this.#d){this.#s();let c=[this.#u&&this.#t,this.#y&&this.#n,this.#d&&this.#o];for(let h of c)if(h)return h.focus();return}let s=this.channel,r=this.#l,o=this.consentText(e);this.#i="submitting",this.#s();let a=async(c)=>{let h=this.#k+N-Date.now();if(h>0)await new Promise((u)=>setTimeout(u,h));try{let{confirmation:u}=await k(y,this.server,s,{email:t,name:n==="optional"||n==="required"?i||void 0:void 0,list_ids:e.map((d)=>d.id),locale:this.locale,page_url:location.href.split("#")[0].slice(0,2000),consent_text:o,form_token:this.#v,website:this.#f.value||void 0});return this.#w=u,!0}catch(u){if(c&&u instanceof p&&u.code==="form_token"){let d=await C(y,this.server,s);return this.#v=d.form_token,this.#k=Date.now(),a(!1)}throw u}};try{await a(!0)}catch(c){if(r!==this.#l)return;if(this.#D(c),this.#i="idle",this.#R(c))return;if(c instanceof p&&c.code==="invalid_email")return this.#u=this.#e({id:"E_qvzP"}),this.#s(),this.#t.focus();return this.#r=this.#M(c),this.#s()}if(r!==this.#l)return;this.#i="done",this.#P("yuva-subscribe",{lists:e.map((c)=>c.id),confirmation:this.#w}),this.#s()}async#j(e,t){let i=this.#p;if(!i||this.#x.has(e.list.id))return;this.#x.add(e.list.id),this.#r="",this.#s();try{if(t){let{state:n}=await i.subscribeList(e.list.id,{consent_text:this.consentText([e.list]),page_url:location.href.split("#")[0].slice(0,2000)});e.state=n,this.#P("yuva-subscribe",{lists:[e.list.id],confirmation:n==="pending"})}else await i.unsubscribeList(e.list.id),e.state="unsubscribed"}catch(n){this.#D(n),this.#r=this.#M(n)}if(this.#x.delete(e.list.id),i===this.#p)this.#s()}#z(e,t){if(e.setAttribute("aria-invalid",String(!!t)),!t)return e.removeAttribute("aria-describedby"),null;let i=`${e.id}-error`;e.setAttribute("aria-describedby",i);let n=l("p","error",t);return n.id=i,n}#U(e,t,i,n){let s=l("label","check"),r=l("input");r.type="checkbox",r.checked=t,r.dataset.key=n,r.addEventListener("change",()=>i(r.checked));let o=l("span","text");return o.append(...e),s.append(r,o),s}#O(e){if(!e&&this.#c.length<2)return null;let t=l("fieldset");t.append(l("legend","",this.#e({id:"h16FyT"})));for(let i of this.#c){let n=[l("span","",i.list.name)];if(i.list.description)n.push(l("span","muted",i.list.description));if(e){if(n.push(l("span","muted consent",this.consentText([i.list]))),i.state==="pending")n.push(l("span","muted",this.#e({id:"x6dU53"})))}let s=e?i.state==="subscribed"||i.state==="pending":this.#h.has(i.list.id),r=this.#U(n,s,(a)=>{if(e)return void this.#j(i,a);if(a)this.#h.add(i.list.id);else this.#h.delete(i.list.id);this.#r="",this.#s()},i.list.id),o=r.querySelector("input");if(e)o.setAttribute("role","switch"),o.setAttribute("aria-checked",String(o.checked)),o.addEventListener("keydown",(a)=>{if(a.key!=="Enter")return;a.preventDefault(),o.click()}),o.disabled=this.#x.has(i.list.id);else o.disabled=this.#i==="submitting";t.append(r)}return t}#H(){let e=l("form",this.getAttribute("layout")==="inline"?"inline":"");e.noValidate=!0,e.addEventListener("submit",(f)=>{f.preventDefault(),this.#N()});let t=this.#i==="submitting",i=this.#O(!1);if(i)e.append(i);let n=l("div","row"),s=[],r=this.getAttribute("name");if(r==="optional"||r==="required"){this.#n.placeholder=r==="required"?this.#e({id:"q8yluz"}):this.#e({id:"YnOaHp"}),this.#n.setAttribute("aria-label",this.#n.placeholder),this.#n.required=r==="required",this.#n.disabled=t,n.append(this.#n);let f=this.#z(this.#n,this.#y);if(f)s.push(f)}this.#t.placeholder=this.#e({id:"XJURKP"}),this.#t.setAttribute("aria-label",this.#t.placeholder),this.#t.disabled=t,n.append(this.#t);let o=this.#z(this.#t,this.#u);if(o)s.push(o);let a=l("button","",t?this.#e({id:"1w51t9"}):this.getAttribute("button-text")||this.#e({id:"EDl9kS"}));a.type="submit",a.disabled=t,a.setAttribute("part","button"),n.append(a);let c=l("div","trap");c.setAttribute("aria-hidden","true"),c.append(this.#f);let h=l("span","",this.consentText()),u=l("label","check consent");u.setAttribute("part","consent"),this.#o.disabled=t;let d=l("span");d.append(h);let x=this.getAttribute("privacy-url");if(x&&/^https?:\/\//i.test(x)){let f=l("a","",this.#e({id:"ScJ9fj"}));f.href=x,f.target="_blank",f.rel="noopener noreferrer",d.append(" ",f)}u.append(this.#o,d);let v=this.#z(this.#o,this.#d);if(e.append(n,...s,u),v)e.append(v);return e.append(c),e}#s(){if(this.#C||!this.channel||this.#i!=="loading"&&this.#c.length===0&&!this.#r){this.#a.replaceChildren();return}let e=this.locale;this.#L=I[e]??g;let t=this.getAttribute("dir"),i=l("div","frame");i.dir=t==="rtl"||t==="ltr"?t:P(e),i.lang=e;let n=this.#b?.chat.launcher_color??this.#b?.branding.color;if(n&&/^#[0-9a-f]{6}$/i.test(n))i.style.setProperty("--brand",n),i.style.setProperty("--brand-on",T(n));let s="";if(this.#i==="done")s=this.#w?this.#e({id:"y3k2zM"}):this.#e({id:"rgySXy"});if(this.#m.textContent=s,this.#i==="idle"||this.#i==="submitting"){let h=this.#p?this.#O(!0):this.#H();if(h)i.append(h)}if(i.append(this.#m),this.#r){let h=l("p","error",this.#r);h.setAttribute("role","alert"),i.append(h)}let r,o=null;try{o=this.#a.activeElement}catch{}if(o instanceof HTMLInputElement)r=o.dataset.key;let a=L(this.#a,U);this.#a.replaceChildren(...a?[a]:[],i);let c=r?this.#a.querySelector(`[data-key="${r}"]`):o;if(c instanceof HTMLElement&&c.isConnected)c.focus({preventScroll:!0})}}function R(){if(typeof customElements>"u")return;if(!customElements.get("yuva-subscribe"))customElements.define("yuva-subscribe",m)}m.loadClient=()=>import(new URL("widget/yuva-subscribe-client-kba66fz1.js",S||location.href).href);R();})();
package/dist/yuva.js CHANGED
@@ -1,4 +1,4 @@
1
- (()=>{var r=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var f=JSON.parse('{"6I7cJR":["Chat öffnen"],"OkHvGB":["Chat öffnen, ",["count"]," ungelesen"],"pqZJT2":["Chat schließen"]}');var g=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function y(e,t,n){let i=e[t.id]??n[t.id],s=t.values??{};if(typeof i==="string")return i;if(Array.isArray(i))return i.map((o)=>typeof o==="string"?o:Array.isArray(o)?String(s[o[0]]??""):"").join("");return t.message??t.id}var O=new Set(["ar","fa","he","ur"]),m="en";function b(e,t){for(let n of t){if(!n)continue;let i=n.toLowerCase();if(e[i])return i;let s=i.split(/[-_]/)[0]??"";if(e[s])return s}return m}function c(e){return O.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var v={en:r,tr:g,de:f};function x(...e){return b(v,e)}function S(e){return v[e]??r}function a(e,t,n=r){return y(e,t,n)}function k(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function C(e){let t=Number.parseInt(e.slice(1),16),[n,i,s]=[t>>16&255,t>>8&255,t&255].map((o)=>{let l=o/255;return l<=0.03928?l/12.92:((l+0.055)/1.055)**2.4});return 0.2126*n+0.7152*i+0.0722*s>0.4?"#111827":"#ffffff"}function w(e){return`yuva:${e}`}function h(e){try{let t=localStorage.getItem(w(e));return t?JSON.parse(t):{}}catch{return{}}}function M(e,t){try{localStorage.setItem(w(e),JSON.stringify(t))}catch{}}var L=`
1
+ (()=>{var r=JSON.parse('{"6I7cJR":["Open chat"],"OkHvGB":["Open chat, ",["count"]," unread"],"pqZJT2":["Close chat"]}');var p=JSON.parse('{"6I7cJR":["Chat öffnen"],"OkHvGB":["Chat öffnen, ",["count"]," ungelesen"],"pqZJT2":["Chat schließen"]}');var f=JSON.parse('{"6I7cJR":["Sohbeti aç"],"OkHvGB":["Sohbeti aç, ",["count"]," okunmamış"],"pqZJT2":["Sohbeti kapat"]}');function g(e,t,n){let i=e[t.id]??n[t.id],s=t.values??{};if(typeof i==="string")return i;if(Array.isArray(i))return i.map((o)=>typeof o==="string"?o:Array.isArray(o)?String(s[o[0]]??""):"").join("");return t.message??t.id}var O=new Set(["ar","fa","he","ur"]),y="en";function m(e,t){for(let n of t){if(!n)continue;let i=n.toLowerCase();if(e[i])return i;let s=i.split(/[-_]/)[0]??"";if(e[s])return s}return y}function c(e){return O.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var b={en:r,tr:f,de:p};function v(...e){return m(b,e)}function x(e){return b[e]??r}function a(e,t,n=r){return g(e,t,n)}var S=new Map;function I(e){if(typeof CSSStyleSheet>"u"||!("replaceSync"in CSSStyleSheet.prototype))return null;let t=S.get(e);if(!t)t=new CSSStyleSheet,t.replaceSync(e),S.set(e,t);return t}function z(e){let t=document.createElement("style");return t.textContent=e,t}function k(e,t){let n=I(t);if(!n||!(e instanceof ShadowRoot))return z(t);if(!e.adoptedStyleSheets.includes(n))e.adoptedStyleSheets=[...e.adoptedStyleSheets,n];return null}function C(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function w(e){let t=Number.parseInt(e.slice(1),16),[n,i,s]=[t>>16&255,t>>8&255,t&255].map((o)=>{let l=o/255;return l<=0.03928?l/12.92:((l+0.055)/1.055)**2.4});return 0.2126*n+0.7152*i+0.0722*s>0.4?"#111827":"#ffffff"}function M(e){return`yuva:${e}`}function h(e){try{let t=localStorage.getItem(M(e));return t?JSON.parse(t):{}}catch{return{}}}function L(e,t){try{localStorage.setItem(M(e),JSON.stringify(t))}catch{}}var E=`
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
- `,u=null;function I(e){if(!("replaceSync"in CSSStyleSheet.prototype)){let t=document.createElement("style");return t.textContent=L,t}return u??=new CSSStyleSheet,u.replaceSync(L),e.adoptedStyleSheets=[u],null}var z='<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>',E='<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>',d=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class p extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",d||location.href).href);#s;#o=null;#i=null;#n;#e=null;#a={};#t=!1;#u=0;#l=null;#r=!1;constructor(){super();this.#s=this.attachShadow({mode:"open"}),this.#n=document.createElement("section"),this.#n.className="panel",this.#n.setAttribute("role","dialog"),this.#n.hidden=!0,this.#n.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&this.layout==="launcher")this.close()})}get layout(){return this.getAttribute("layout")==="embedded"?"embedded":"launcher"}get channel(){return this.getAttribute("channel")}get server(){return(this.getAttribute("server")||(d?new URL(d).origin:location.origin)).replace(/\/+$/,"")}get locale(){return x(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#t}get unread(){return this.#u}setIdentityToken(e){if(this.#l=e,this.#e)this.#e.then((t)=>t.identityChanged())}async signOut(){if(this.#l=null,this.removeAttribute("identity-token"),this.#e)await(await this.#e).signOut()}async rate(e,t,n){return(await this.#d()).rate(e,t,n)}connectedCallback(){this.#c();let e=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!e)return;let t=h(e);if(t.launcher)this.#p(t.launcher);let n=()=>{if(!this.isConnected||this.#e||this.channel!==e)return;if(t.session)this.#d();else this.#g(e)};if("requestIdleCallback"in window)requestIdleCallback(n,{timeout:3000});else setTimeout(n,1000)}#g(e){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(e)}`,{credentials:"omit"}).then((t)=>{if(t.status===403||t.status===404)this.#f();return t.ok?t.json():null}).then((t)=>{if(!t||this.channel!==e||this.#e)return;let n=k(t);this.#p(n),M(e,{...h(e),launcher:n})}).catch(()=>{return})}disconnectedCallback(){let e=this.#e;if(this.#e=null,e)e.then((t)=>t.destroy())}attributeChangedCallback(e,t,n){if(!this.isConnected||t===n)return;if(e==="open"){n===null?this.close():this.open();return}if(e==="identity-token"){if(this.#e)this.#e.then((i)=>i.identityChanged());return}if(e==="channel"||e==="server"){this.disconnectedCallback(),this.#r=!1,this.#c();return}if(this.#c(),this.#e)this.#e.then((i)=>i.update())}async open(){if(this.#t||this.#r)return;this.#t=!0,this.toggleAttribute("open-panel",!0),this.#h();let e=await this.#d();if(!this.#t)return;if(this.#n.hidden=!1,e.opened(),this.layout!=="embedded")this.dispatchEvent(new Event("yuva-open",{bubbles:!0,composed:!0}))}close(){if(!this.#t||this.layout==="embedded")return;if(this.#t=!1,this.toggleAttribute("open-panel",!1),this.#n.hidden=!0,this.#h(),this.#o?.focus(),this.#e)this.#e.then((e)=>e.closed())}toggle(){return this.#t?this.close():this.open()}#y(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#d(){return this.#e??=p.loadPanel().then(({mount:e})=>e({panel:this.#n,config:()=>this.#y(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#t,close:()=>this.close(),setUnread:(t)=>{this.#u=t,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:t}}))},setLauncher:(t)=>this.#p(t),refused:()=>this.#f()})),this.#e}#f(){if(this.#r)return;this.#r=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#t=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(e){if(this.setAttribute("position",e.position==="left"?"left":"right"),e.color&&/^#[0-9a-f]{6}$/i.test(e.color))this.style.setProperty("--yuva-accent",e.color),this.style.setProperty("--yuva-on-accent",C(e.color))}#c(){let e=this.locale;this.#a=S(e),this.setAttribute("lang",e);let t=I(this.#s),n=t?[t]:[];if(this.#n.dir=this.getAttribute("dir")??c(e),this.#n.setAttribute("aria-modal","false"),this.#r){this.#o=null,this.#i=null,this.#s.replaceChildren();return}if(this.layout==="embedded"){this.#o=null,this.#i=null,this.#s.replaceChildren(...n,this.#n),this.#t=!1,this.open();return}let i=document.createElement("button");if(i.type="button",i.className="launcher",i.addEventListener("click",()=>void this.toggle()),this.#o=i,this.#i=document.createElement("span"),this.#i.className="badge",this.#i.setAttribute("aria-hidden","true"),this.#s.replaceChildren(...n,this.#n,i),this.#h(),this.hasAttribute("open")&&!this.#t)this.open()}#h(){let e=this.#o,t=this.#i;if(!e||!t)return;let n=this.#u;e.setAttribute("aria-expanded",String(this.#t)),e.setAttribute("aria-label",this.#t?a(this.#a,{id:"pqZJT2"}):n>0?a(this.#a,{id:"OkHvGB",values:{count:n}}):a(this.#a,{id:"6I7cJR"})),e.innerHTML=this.#t?E:z,t.textContent=n>9?"9+":String(n),t.hidden=this.#t||n===0,e.append(t)}}function A(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",p)}A();})();
109
+ `,T='<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>',R='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',u=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class d extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",u||location.href).href);#s;#o=null;#i=null;#n;#e=null;#a={};#t=!1;#u=0;#l=null;#r=!1;constructor(){super();this.#s=this.attachShadow({mode:"open"}),this.#n=document.createElement("section"),this.#n.className="panel",this.#n.setAttribute("role","dialog"),this.#n.hidden=!0,this.#n.addEventListener("keydown",(e)=>{if(e.key==="Escape"&&this.layout==="launcher")this.close()})}get layout(){return this.getAttribute("layout")==="embedded"?"embedded":"launcher"}get channel(){return this.getAttribute("channel")}get server(){return(this.getAttribute("server")||(u?new URL(u).origin:location.origin)).replace(/\/+$/,"")}get locale(){return v(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#t}get unread(){return this.#u}setIdentityToken(e){if(this.#l=e,this.#e)this.#e.then((t)=>t.identityChanged())}async signOut(){if(this.#l=null,this.removeAttribute("identity-token"),this.#e)await(await this.#e).signOut()}async rate(e,t,n){return(await this.#d()).rate(e,t,n)}connectedCallback(){this.#c();let e=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!e)return;let t=h(e);if(t.launcher)this.#p(t.launcher);let n=()=>{if(!this.isConnected||this.#e||this.channel!==e)return;if(t.session)this.#d();else this.#g(e)};if("requestIdleCallback"in window)requestIdleCallback(n,{timeout:3000});else setTimeout(n,1000)}#g(e){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(e)}`,{credentials:"omit"}).then((t)=>{if(t.status===403||t.status===404)this.#f();return t.ok?t.json():null}).then((t)=>{if(!t||this.channel!==e||this.#e)return;let n=C(t);this.#p(n),L(e,{...h(e),launcher:n})}).catch(()=>{return})}disconnectedCallback(){let e=this.#e;if(this.#e=null,e)e.then((t)=>t.destroy())}attributeChangedCallback(e,t,n){if(!this.isConnected||t===n)return;if(e==="open"){n===null?this.close():this.open();return}if(e==="identity-token"){if(this.#e)this.#e.then((i)=>i.identityChanged());return}if(e==="channel"||e==="server"){this.disconnectedCallback(),this.#r=!1,this.#c();return}if(this.#c(),this.#e)this.#e.then((i)=>i.update())}async open(){if(this.#t||this.#r)return;this.#t=!0,this.toggleAttribute("open-panel",!0),this.#h();let e=await this.#d();if(!this.#t)return;if(this.#n.hidden=!1,e.opened(),this.layout!=="embedded")this.dispatchEvent(new Event("yuva-open",{bubbles:!0,composed:!0}))}close(){if(!this.#t||this.layout==="embedded")return;if(this.#t=!1,this.toggleAttribute("open-panel",!1),this.#n.hidden=!0,this.#h(),this.#o?.focus(),this.#e)this.#e.then((e)=>e.closed())}toggle(){return this.#t?this.close():this.open()}#y(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#d(){return this.#e??=d.loadPanel().then(({mount:e})=>e({panel:this.#n,config:()=>this.#y(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#t,close:()=>this.close(),setUnread:(t)=>{this.#u=t,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:t}}))},setLauncher:(t)=>this.#p(t),refused:()=>this.#f()})),this.#e}#f(){if(this.#r)return;this.#r=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#t=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(e){if(this.setAttribute("position",e.position==="left"?"left":"right"),e.color&&/^#[0-9a-f]{6}$/i.test(e.color))this.style.setProperty("--yuva-accent",e.color),this.style.setProperty("--yuva-on-accent",w(e.color))}#c(){let e=this.locale;this.#a=x(e),this.setAttribute("lang",e);let t=k(this.#s,E),n=t?[t]:[];if(this.#n.dir=this.getAttribute("dir")??c(e),this.#n.setAttribute("aria-modal","false"),this.#r){this.#o=null,this.#i=null,this.#s.replaceChildren();return}if(this.layout==="embedded"){this.#o=null,this.#i=null,this.#s.replaceChildren(...n,this.#n),this.#t=!1,this.open();return}let i=document.createElement("button");if(i.type="button",i.className="launcher",i.addEventListener("click",()=>void this.toggle()),this.#o=i,this.#i=document.createElement("span"),this.#i.className="badge",this.#i.setAttribute("aria-hidden","true"),this.#s.replaceChildren(...n,this.#n,i),this.#h(),this.hasAttribute("open")&&!this.#t)this.open()}#h(){let e=this.#o,t=this.#i;if(!e||!t)return;let n=this.#u;e.setAttribute("aria-expanded",String(this.#t)),e.setAttribute("aria-label",this.#t?a(this.#a,{id:"pqZJT2"}):n>0?a(this.#a,{id:"OkHvGB",values:{count:n}}):a(this.#a,{id:"6I7cJR"})),e.innerHTML=this.#t?R:T,t.textContent=n>9?"9+":String(n),t.hidden=this.#t||n===0,e.append(t)}}function A(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",d)}A();})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "useyuva",
3
- "version": "0.0.12",
4
- "description": "Yuva for the web: a headless client for contacts, the <yuva-chat> element, documentation page feedback and discussions, the <yuva-subscribe> mailing list form, cookieless web analytics, React hooks, a Nuxt module and a typed /v1 client.",
3
+ "version": "0.0.14",
4
+ "description": "Yuva for the web: a headless client for contacts, the <yuva-chat> element, documentation page feedback and discussions, the <yuva-subscribe> mailing list form, cookieless web analytics, React hooks, a Nuxt module, a typed /v1 client and server helpers for identity tokens, webhooks and server-side analytics.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -17,6 +17,7 @@
17
17
  "web-component",
18
18
  "customer-messaging",
19
19
  "nuxt",
20
+ "nitro",
20
21
  "newsletter",
21
22
  "analytics"
22
23
  ],
@@ -61,6 +62,14 @@
61
62
  "types": "./dist/types/api.d.ts",
62
63
  "default": "./dist/esm/api.js"
63
64
  },
65
+ "./server": {
66
+ "types": "./dist/types/server.d.ts",
67
+ "default": "./dist/esm/server.js"
68
+ },
69
+ "./h3": {
70
+ "types": "./dist/types/h3.d.ts",
71
+ "default": "./dist/esm/h3.js"
72
+ },
64
73
  "./nuxt": {
65
74
  "types": "./dist/types/nuxt/module.d.ts",
66
75
  "default": "./dist/esm/nuxt/module.js"
@@ -77,6 +86,14 @@
77
86
  "types": "./dist/types/nuxt/runtime/plugin.d.ts",
78
87
  "default": "./dist/esm/nuxt/runtime/plugin.js"
79
88
  },
89
+ "./nitro": {
90
+ "types": "./dist/types/nitro/module.d.ts",
91
+ "default": "./dist/esm/nitro/module.js"
92
+ },
93
+ "./nitro/runtime": {
94
+ "types": "./dist/types/nitro/runtime/define.d.ts",
95
+ "default": "./dist/esm/nitro/runtime/define.js"
96
+ },
80
97
  "./package.json": "./package.json"
81
98
  },
82
99
  "types": "./dist/types/index.d.ts",
@@ -105,6 +122,7 @@
105
122
  },
106
123
  "peerDependencies": {
107
124
  "@nuxt/kit": ">=3.15.0",
125
+ "h3": "^2.0.0",
108
126
  "react": ">=18",
109
127
  "vue": ">=3.5.0"
110
128
  },
@@ -112,6 +130,9 @@
112
130
  "@nuxt/kit": {
113
131
  "optional": true
114
132
  },
133
+ "h3": {
134
+ "optional": true
135
+ },
115
136
  "react": {
116
137
  "optional": true
117
138
  },
@@ -130,7 +151,10 @@
130
151
  "@types/bun": "^1.4.2",
131
152
  "@types/react": "19.2.2",
132
153
  "@types/react-dom": "19.2.2",
154
+ "h3": "2.0.2",
155
+ "h3-v1": "npm:h3@1.15.11",
133
156
  "happy-dom": "^20.14.5",
157
+ "nitro": "3.0.260903-beta",
134
158
  "oxfmt": "0.72.0",
135
159
  "oxlint": "1.87.0",
136
160
  "react": "19.2.0",
@@ -1,2 +0,0 @@
1
- function translate(messages,descriptor,fallback){let entry=messages[descriptor.id]??fallback[descriptor.id],values=descriptor.values??{};if(typeof entry==="string")return entry;if(Array.isArray(entry))return entry.map((part)=>typeof part==="string"?part:Array.isArray(part)?String(values[part[0]]??""):"").join("");return descriptor.message??descriptor.id}var rtlLanguages=new Set(["ar","fa","he","ur"]),sourceLocale="en";function localeIn(catalogs,candidates){for(let candidate of candidates){if(!candidate)continue;let tag=candidate.toLowerCase();if(catalogs[tag])return tag;let language=tag.split(/[-_]/)[0]??"";if(catalogs[language])return language}return sourceLocale}function directionOf(locale){return rtlLanguages.has(locale.split(/[-_]/)[0]??"")?"rtl":"ltr"}function launcherOf(inbox){return{position:inbox.chat.launcher_position,color:inbox.chat.launcher_color??inbox.branding.color}}function contrastOn(color){let n=Number.parseInt(color.slice(1),16),[r,g,b]=[n>>16&255,n>>8&255,n&255].map((c)=>{let s=c/255;return s<=0.03928?s/12.92:((s+0.055)/1.055)**2.4});return 0.2126*r+0.7152*g+0.0722*b>0.4?"#111827":"#ffffff"}function storageKey(channel){return`yuva:${channel}`}function readStored(channel){try{let raw=localStorage.getItem(storageKey(channel));return raw?JSON.parse(raw):{}}catch{return{}}}function writeStored(channel,state){try{localStorage.setItem(storageKey(channel),JSON.stringify(state))}catch{}}
2
- export{translate,localeIn,directionOf,launcherOf,contrastOn,readStored,writeStored};