useyuva 0.0.11 → 0.0.12

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 CHANGED
@@ -106,4 +106,4 @@ import{resolveLocale,catalogFor,translatePlain}from"./index-c6q8br7d.js";import{
106
106
  block-size: 100%;
107
107
  min-block-size: 320px;
108
108
  }
109
- `,chatIcon='<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>',closeIcon='<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>',scriptSrc=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class YuvaChatElement extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",scriptSrc||location.href).href);#root;#launcher=null;#badge=null;#panel;#controller=null;#messages={};#open=!1;#unread=0;#identity=null;#refused=!1;constructor(){super();this.#root=this.attachShadow({mode:"open"}),this.#panel=document.createElement("section"),this.#panel.className="panel",this.#panel.setAttribute("role","dialog"),this.#panel.hidden=!0,this.#panel.addEventListener("keydown",(event)=>{if(event.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")||(scriptSrc?new URL(scriptSrc).origin:location.origin)).replace(/\/+$/,"")}get locale(){return resolveLocale(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#open}get unread(){return this.#unread}setIdentityToken(source){if(this.#identity=source,this.#controller)this.#controller.then((controller)=>controller.identityChanged())}async signOut(){if(this.#identity=null,this.removeAttribute("identity-token"),this.#controller)await(await this.#controller).signOut()}async rate(conversationId,rating,comment){return(await this.#ensureController()).rate(conversationId,rating,comment)}connectedCallback(){this.#render();let channel=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!channel)return;let stored=readStored(channel);if(stored.launcher)this.#applyLauncher(stored.launcher);let idle=()=>{if(!this.isConnected||this.#controller||this.channel!==channel)return;if(stored.session)this.#ensureController();else this.#styleLauncher(channel)};if("requestIdleCallback"in window)requestIdleCallback(idle,{timeout:3000});else setTimeout(idle,1000)}#styleLauncher(channel){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(channel)}`,{credentials:"omit"}).then((response)=>{if(response.status===403||response.status===404)this.#refuse();return response.ok?response.json():null}).then((inbox)=>{if(!inbox||this.channel!==channel||this.#controller)return;let launcher=launcherOf(inbox);this.#applyLauncher(launcher),writeStored(channel,{...readStored(channel),launcher})}).catch(()=>{return})}disconnectedCallback(){let controller=this.#controller;if(this.#controller=null,controller)controller.then((c)=>c.destroy())}attributeChangedCallback(name,previous,value){if(!this.isConnected||previous===value)return;if(name==="open"){value===null?this.close():this.open();return}if(name==="identity-token"){if(this.#controller)this.#controller.then((controller)=>controller.identityChanged());return}if(name==="channel"||name==="server"){this.disconnectedCallback(),this.#refused=!1,this.#render();return}if(this.#render(),this.#controller)this.#controller.then((controller)=>controller.update())}async open(){if(this.#open||this.#refused)return;this.#open=!0,this.toggleAttribute("open-panel",!0),this.#syncLauncher();let controller=await this.#ensureController();if(!this.#open)return;if(this.#panel.hidden=!1,controller.opened(),this.layout!=="embedded")this.dispatchEvent(new Event("yuva-open",{bubbles:!0,composed:!0}))}close(){if(!this.#open||this.layout==="embedded")return;if(this.#open=!1,this.toggleAttribute("open-panel",!1),this.#panel.hidden=!0,this.#syncLauncher(),this.#launcher?.focus(),this.#controller)this.#controller.then((controller)=>controller.closed())}toggle(){return this.#open?this.close():this.open()}#config(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#ensureController(){return this.#controller??=YuvaChatElement.loadPanel().then(({mount})=>mount({panel:this.#panel,config:()=>this.#config(),identityToken:async()=>this.#identity?await this.#identity()??null:this.getAttribute("identity-token"),isOpen:()=>this.#open,close:()=>this.close(),setUnread:(count)=>{this.#unread=count,this.#syncLauncher(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count}}))},setLauncher:(style)=>this.#applyLauncher(style),refused:()=>this.#refuse()})),this.#controller}#refuse(){if(this.#refused)return;this.#refused=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#open=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#render()}#applyLauncher(style){if(this.setAttribute("position",style.position==="left"?"left":"right"),style.color&&/^#[0-9a-f]{6}$/i.test(style.color))this.style.setProperty("--yuva-accent",style.color),this.style.setProperty("--yuva-on-accent",contrastOn(style.color))}#render(){let locale=this.locale;this.#messages=catalogFor(locale),this.setAttribute("lang",locale);let style=document.createElement("style");if(style.textContent=styles,this.#panel.dir=this.getAttribute("dir")??directionOf(locale),this.#panel.setAttribute("aria-modal","false"),this.#refused){this.#launcher=null,this.#badge=null,this.#root.replaceChildren();return}if(this.layout==="embedded"){this.#launcher=null,this.#badge=null,this.#root.replaceChildren(style,this.#panel),this.#open=!1,this.open();return}let launcher=document.createElement("button");if(launcher.type="button",launcher.className="launcher",launcher.addEventListener("click",()=>void this.toggle()),this.#launcher=launcher,this.#badge=document.createElement("span"),this.#badge.className="badge",this.#badge.setAttribute("aria-hidden","true"),this.#root.replaceChildren(style,this.#panel,launcher),this.#syncLauncher(),this.hasAttribute("open")&&!this.#open)this.open()}#syncLauncher(){let launcher=this.#launcher,badge=this.#badge;if(!launcher||!badge)return;let count=this.#unread;launcher.setAttribute("aria-expanded",String(this.#open)),launcher.setAttribute("aria-label",this.#open?translatePlain(this.#messages,{id:"pqZJT2"}):count>0?translatePlain(this.#messages,{id:"OkHvGB",values:{count}}):translatePlain(this.#messages,{id:"6I7cJR"})),launcher.innerHTML=this.#open?closeIcon:chatIcon,badge.textContent=count>9?"9+":String(count),badge.hidden=this.#open||count===0,launcher.append(badge)}}function define(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",YuvaChatElement)}YuvaChatElement.loadPanel=()=>import("./yuva-chat-kf9vz8r3.js");define();export{YuvaChatElement,define};
109
+ `,styleSheet=null;function adoptStyles(root){if(!("replaceSync"in CSSStyleSheet.prototype)){let style=document.createElement("style");return style.textContent=styles,style}return styleSheet??=new CSSStyleSheet,styleSheet.replaceSync(styles),root.adoptedStyleSheets=[styleSheet],null}var chatIcon='<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>',closeIcon='<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>',scriptSrc=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class YuvaChatElement extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",scriptSrc||location.href).href);#root;#launcher=null;#badge=null;#panel;#controller=null;#messages={};#open=!1;#unread=0;#identity=null;#refused=!1;constructor(){super();this.#root=this.attachShadow({mode:"open"}),this.#panel=document.createElement("section"),this.#panel.className="panel",this.#panel.setAttribute("role","dialog"),this.#panel.hidden=!0,this.#panel.addEventListener("keydown",(event)=>{if(event.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")||(scriptSrc?new URL(scriptSrc).origin:location.origin)).replace(/\/+$/,"")}get locale(){return resolveLocale(this.getAttribute("locale"),navigator.language)}get isOpen(){return this.#open}get unread(){return this.#unread}setIdentityToken(source){if(this.#identity=source,this.#controller)this.#controller.then((controller)=>controller.identityChanged())}async signOut(){if(this.#identity=null,this.removeAttribute("identity-token"),this.#controller)await(await this.#controller).signOut()}async rate(conversationId,rating,comment){return(await this.#ensureController()).rate(conversationId,rating,comment)}connectedCallback(){this.#render();let channel=this.channel;if(this.layout==="embedded"||this.hasAttribute("open")||!channel)return;let stored=readStored(channel);if(stored.launcher)this.#applyLauncher(stored.launcher);let idle=()=>{if(!this.isConnected||this.#controller||this.channel!==channel)return;if(stored.session)this.#ensureController();else this.#styleLauncher(channel)};if("requestIdleCallback"in window)requestIdleCallback(idle,{timeout:3000});else setTimeout(idle,1000)}#styleLauncher(channel){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(channel)}`,{credentials:"omit"}).then((response)=>{if(response.status===403||response.status===404)this.#refuse();return response.ok?response.json():null}).then((inbox)=>{if(!inbox||this.channel!==channel||this.#controller)return;let launcher=launcherOf(inbox);this.#applyLauncher(launcher),writeStored(channel,{...readStored(channel),launcher})}).catch(()=>{return})}disconnectedCallback(){let controller=this.#controller;if(this.#controller=null,controller)controller.then((c)=>c.destroy())}attributeChangedCallback(name,previous,value){if(!this.isConnected||previous===value)return;if(name==="open"){value===null?this.close():this.open();return}if(name==="identity-token"){if(this.#controller)this.#controller.then((controller)=>controller.identityChanged());return}if(name==="channel"||name==="server"){this.disconnectedCallback(),this.#refused=!1,this.#render();return}if(this.#render(),this.#controller)this.#controller.then((controller)=>controller.update())}async open(){if(this.#open||this.#refused)return;this.#open=!0,this.toggleAttribute("open-panel",!0),this.#syncLauncher();let controller=await this.#ensureController();if(!this.#open)return;if(this.#panel.hidden=!1,controller.opened(),this.layout!=="embedded")this.dispatchEvent(new Event("yuva-open",{bubbles:!0,composed:!0}))}close(){if(!this.#open||this.layout==="embedded")return;if(this.#open=!1,this.toggleAttribute("open-panel",!1),this.#panel.hidden=!0,this.#syncLauncher(),this.#launcher?.focus(),this.#controller)this.#controller.then((controller)=>controller.closed())}toggle(){return this.#open?this.close():this.open()}#config(){return{channel:this.channel,server:this.server,layout:this.layout,locale:this.locale}}#ensureController(){return this.#controller??=YuvaChatElement.loadPanel().then(({mount})=>mount({panel:this.#panel,config:()=>this.#config(),identityToken:async()=>this.#identity?await this.#identity()??null:this.getAttribute("identity-token"),isOpen:()=>this.#open,close:()=>this.close(),setUnread:(count)=>{this.#unread=count,this.#syncLauncher(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count}}))},setLauncher:(style)=>this.#applyLauncher(style),refused:()=>this.#refuse()})),this.#controller}#refuse(){if(this.#refused)return;this.#refused=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#open=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#render()}#applyLauncher(style){if(this.setAttribute("position",style.position==="left"?"left":"right"),style.color&&/^#[0-9a-f]{6}$/i.test(style.color))this.style.setProperty("--yuva-accent",style.color),this.style.setProperty("--yuva-on-accent",contrastOn(style.color))}#render(){let locale=this.locale;this.#messages=catalogFor(locale),this.setAttribute("lang",locale);let fallbackStyle=adoptStyles(this.#root),head=fallbackStyle?[fallbackStyle]:[];if(this.#panel.dir=this.getAttribute("dir")??directionOf(locale),this.#panel.setAttribute("aria-modal","false"),this.#refused){this.#launcher=null,this.#badge=null,this.#root.replaceChildren();return}if(this.layout==="embedded"){this.#launcher=null,this.#badge=null,this.#root.replaceChildren(...head,this.#panel),this.#open=!1,this.open();return}let launcher=document.createElement("button");if(launcher.type="button",launcher.className="launcher",launcher.addEventListener("click",()=>void this.toggle()),this.#launcher=launcher,this.#badge=document.createElement("span"),this.#badge.className="badge",this.#badge.setAttribute("aria-hidden","true"),this.#root.replaceChildren(...head,this.#panel,launcher),this.#syncLauncher(),this.hasAttribute("open")&&!this.#open)this.open()}#syncLauncher(){let launcher=this.#launcher,badge=this.#badge;if(!launcher||!badge)return;let count=this.#unread;launcher.setAttribute("aria-expanded",String(this.#open)),launcher.setAttribute("aria-label",this.#open?translatePlain(this.#messages,{id:"pqZJT2"}):count>0?translatePlain(this.#messages,{id:"OkHvGB",values:{count}}):translatePlain(this.#messages,{id:"6I7cJR"})),launcher.innerHTML=this.#open?closeIcon:chatIcon,badge.textContent=count>9?"9+":String(count),badge.hidden=this.#open||count===0,launcher.append(badge)}}function define(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",YuvaChatElement)}YuvaChatElement.loadPanel=()=>import("./yuva-chat-kf9vz8r3.js");define();export{YuvaChatElement,define};
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 p=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 f(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 L=new Set(["ar","fa","he","ur"]),m="en";function y(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 L.has(e.split(/[-_]/)[0]??"")?"rtl":"ltr"}var b={en:r,tr:g,de:p};function v(...e){return y(b,e)}function x(e){return b[e]??r}function a(e,t,n=r){return f(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 S(e,t){try{localStorage.setItem(w(e),JSON.stringify(t))}catch{}}var A=`
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=`
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
- `,O='<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>',I='<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',u=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"";class d extends HTMLElement{static observedAttributes=["channel","server","layout","locale","dir","identity-token","open"];static loadPanel=()=>import(new URL("yuva-chat.js",u||location.href).href);#r;#s=null;#i=null;#n;#e=null;#a={};#t=!1;#u=0;#l=null;#o=!1;constructor(){super();this.#r=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.#f(e)};if("requestIdleCallback"in window)requestIdleCallback(n,{timeout:3000});else setTimeout(n,1000)}#f(e){fetch(`${this.server}/client/v1/channels/${encodeURIComponent(e)}`,{credentials:"omit"}).then((t)=>{if(t.status===403||t.status===404)this.#g();return t.ok?t.json():null}).then((t)=>{if(!t||this.channel!==e||this.#e)return;let n=k(t);this.#p(n),S(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.#o=!1,this.#c();return}if(this.#c(),this.#e)this.#e.then((i)=>i.update())}async open(){if(this.#t||this.#o)return;this.#t=!0,this.toggleAttribute("open-panel",!0),this.#h();let e=await this.#d();if(!this.#t)return;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.#s?.focus(),this.#e)this.#e.then((e)=>e.closed())}toggle(){return this.#t?this.close():this.open()}#m(){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.#m(),identityToken:async()=>this.#l?await this.#l()??null:this.getAttribute("identity-token"),isOpen:()=>this.#t,close:()=>this.close(),setUnread:(t)=>{this.#u=t,this.#h(),this.dispatchEvent(new CustomEvent("yuva-unread",{detail:{count:t}}))},setLauncher:(t)=>this.#p(t),refused:()=>this.#g()})),this.#e}#g(){if(this.#o)return;this.#o=!0,console.warn(`Yuva: channel ${this.channel} is unknown or does not allow ${location.origin}`),this.#t=!1,this.toggleAttribute("open-panel",!1),this.disconnectedCallback(),this.#c()}#p(e){if(this.setAttribute("position",e.position==="left"?"left":"right"),e.color&&/^#[0-9a-f]{6}$/i.test(e.color))this.style.setProperty("--yuva-accent",e.color),this.style.setProperty("--yuva-on-accent",C(e.color))}#c(){let e=this.locale;this.#a=x(e),this.setAttribute("lang",e);let t=document.createElement("style");if(t.textContent=A,this.#n.dir=this.getAttribute("dir")??c(e),this.#n.setAttribute("aria-modal","false"),this.#o){this.#s=null,this.#i=null,this.#r.replaceChildren();return}if(this.layout==="embedded"){this.#s=null,this.#i=null,this.#r.replaceChildren(t,this.#n),this.#t=!1,this.open();return}let n=document.createElement("button");if(n.type="button",n.className="launcher",n.addEventListener("click",()=>void this.toggle()),this.#s=n,this.#i=document.createElement("span"),this.#i.className="badge",this.#i.setAttribute("aria-hidden","true"),this.#r.replaceChildren(t,this.#n,n),this.#h(),this.hasAttribute("open")&&!this.#t)this.open()}#h(){let e=this.#s,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?I:O,t.textContent=n>9?"9+":String(n),t.hidden=this.#t||n===0,e.append(t)}}function M(){if(!customElements.get("yuva-chat"))customElements.define("yuva-chat",d)}M();})();
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();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "useyuva",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Yuva for the web: a headless client for contacts, the <yuva-chat> element, documentation page feedback and discussions, the <yuva-subscribe> mailing list form, cookieless web analytics, React hooks, a Nuxt module and a typed /v1 client.",
5
5
  "license": "MIT",
6
6
  "repository": {