@ziila/sdk 0.1.58 → 0.1.69
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/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/src/types.d.ts +0 -6
- package/dist/widget.iife.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.style.cssText=`width:100%;height:100%;border:none;`,e.appendChild(this.iframe),window.addEventListener(`message`,this.handleHandshake)}send(e){this.port?.postMessage(e)}destroy(){window.removeEventListener(`message`,this.handleHandshake),this.port?.close(),this.iframe?.remove(),this.iframe=null,this.port=null}},t=class{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){this.handlers.get(e)?.forEach(e=>e(t))}destroy(){this.handlers.clear()}},n=e=>`position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.4);padding:24px;font-family:${e.fontFamily??`system-ui,-apple-system,sans-serif`};`,r=e=>`width:100%;max-width:24rem;border-radius:${e.borderRadius??`12px`};background:${e.backgroundColor??`#fff`};padding:16px;box-shadow:2px 4px 2px rgba(0,0,0,0.1);display:flex;flex-direction:column;gap:16px;`,i=`display:flex;justify-content:flex-end;`,a=e=>`border:none;background:${e.mutedColor??`#f0f0f0`};border-radius:${e.buttonRadius??`12px`};width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:${e.mutedFg??`#555`};line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,ee=e=>`margin:0;font-size:24px;font-weight:700;color:${e.primaryColor??`#195f6b`};text-align:center;`,s=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,c=`display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;`,te=e=>`flex:1;border:1px solid ${e.primaryColor??`#195f6b`};border-radius:${e.buttonRadius??`8px`};background:${e.backgroundColor??`#fff`};color:${e.primaryColor??`#195f6b`};padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,l=e=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,u=class{constructor(){this.overlay=null,this.pendingResolve=null,this.previousFocus=null}show(e){return this.pendingResolve?.(!1),this.pendingResolve=null,this.close(),new Promise(t=>{this.pendingResolve=t;let u=e=>{this.pendingResolve=null,this.close(),t(e)},d=e.tokens??{},f=document.createElement(`div`);f.style.cssText=n(d);let p=document.createElement(`div`);p.setAttribute(`role`,`dialog`),p.setAttribute(`aria-modal`,`true`),p.setAttribute(`aria-labelledby`,`ziila-confirm-title`),p.style.cssText=r(d),p.dir=e.dir;let m=document.createElement(`div`);m.style.cssText=i;let h=document.createElement(`button`);h.type=`button`,h.setAttribute(`aria-label`,e.closeLabel),h.textContent=`✕`,h.style.cssText=a(d),h.addEventListener(`click`,()=>u(!1)),m.appendChild(h);let g=document.createElement(`div`);g.style.cssText=o;let _=document.createElement(`h2`);_.id=`ziila-confirm-title`,_.textContent=e.title,_.style.cssText=ee(d);let v=document.createElement(`p`);v.textContent=e.message,v.style.cssText=s(d);let y=document.createElement(`button`);y.type=`button`,y.textContent=e.cancelLabel,y.style.cssText=te(d),y.addEventListener(`click`,()=>u(!1));let b=document.createElement(`button`);b.type=`button`,b.textContent=e.confirmLabel,b.style.cssText=l(d),b.addEventListener(`click`,()=>u(!0));let x=document.createElement(`div`);x.style.cssText=c,x.append(y,b),g.append(_,v,x),p.append(m,g),f.appendChild(p);let S=[h,y,b];f.addEventListener(`keydown`,e=>{if(e.key===`Escape`){u(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(S.indexOf(document.activeElement)+(e.shiftKey?-1:1)+S.length)%S.length;S[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=f,document.body.appendChild(f),y.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},d={primaryColor:[`--primary`,`--primary-color`,`--color-primary`,`--brand`,`--brand-color`,`--accent-color`,`--bs-primary`,`--mui-palette-primary-main`,`--ant-color-primary`],borderRadius:[`--radius`,`--border-radius`,`--rounded`,`--bs-border-radius`]},f=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function p(e){return!!e&&!f.has(e.trim().toLowerCase())}function m(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(p(r.fontFamily)&&(i.fontFamily=r.fontFamily),p(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),p(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(d))for(let r of t){let t=n.getPropertyValue(r).trim();if(p(t)){i[e]=t;break}}return i}function h(e,t={}){let n={...m(t.doc??document),...e?.tokens},r={};return Object.keys(n).length>0&&(r.tokens=n),e?.elements&&Object.keys(e.elements).length>0&&(r.elements=e.elements),r}var g={},_=[`en`,`ar`],v=`PARAGLIDE_LOCALE`,y=[`baseLocale`],b=[],x,S;function C(e){if(b.length===0)return;let t=typeof e==`string`?e:e.href;if(x===t)return S;let n=new URL(t,`http://dummy.com`),r;for(let e of b)if(new g(e.match,n.href).exec(n.href)){r=e;break}return x=t,S=r,r}function w(e){let t=C(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:y}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var T=!1,E=()=>{let e=y;typeof window<`u`&&window.location?.href&&(e=w(window.location.href));let t=D(e,typeof window<`u`?window.location?.href:void 0);if(t)return T||(T=!0,A(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function D(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(F(t)&&P.has(t)){let e=P.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return M(t)}}let e=j(n);if(e)return e}}var O=e=>{E=e},k=e=>{e?window.location.href=e:window.location.reload()},A=(e,t)=>{let n={reload:!0,...t},r;try{r=E()}catch{}let i=[],a=y;typeof window<`u`&&window.location?.href&&(a=w(window.location.href));for(let t of a)if(t===`baseLocale`)continue;else if(F(t)&&P.has(t)){let n=P.get(t);if(n){let r=n.setLocale(e);r instanceof Promise&&(r=r.catch(e=>{throw Error(`Custom strategy "${t}" setLocale failed.`,{cause:e})}),i.push(r))}}let o=()=>{n.reload&&window.location&&e!==r&&k(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function j(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of _)if(e.toLowerCase()===t)return e}function M(e){let t=j(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(`, `)}`)}var N=v.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${N}=([^;]*)`);var P=new Map;function F(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var I=()=>`End Chat`,L=()=>`إنهاء المحادثة`,R=((e={},t={})=>(t.locale??E())===`en`?I(e):L(e)),z=()=>`Are you sure you want to end this chat?`,B=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,V=((e={},t={})=>(t.locale??E())===`en`?z(e):B(e)),H=()=>`End Chat`,U=()=>`إنهاء المحادثة`,W=((e={},t={})=>(t.locale??E())===`en`?H(e):U(e)),G=()=>`Cancel`,K=()=>`إلغاء`,q=((e={},t={})=>(t.locale??E())===`en`?G(e):K(e)),J=()=>`Close`,Y=()=>`إغلاق`,X=((e={},t={})=>(t.locale??E())===`en`?J(e):Y(e)),Z=new Set(_),Q=`en`;O(()=>Q);function ne(){return Q}function $(e){Q=e&&Z.has(e)?e:`en`}function re(e){return e===`ar`?`rtl`:`ltr`}function ie(){return{title:R(),message:V(),confirmLabel:W(),cancelLabel:q(),closeLabel:X(),dir:re(ne())}}var ae=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new u,this.resolvedTheme={},this._isDirty=!1,this.handleBeforeUnload=e=>{this._isDirty&&(e.preventDefault(),e.returnValue=``)},this.handleMessage=e=>{let t=e.data;t.type===`READY`?this.bus.emit(`ready`):t.type===`EVENT`?this.bus.emit(t.event,t.payload):t.type===`DIRTY_STATE`?this._isDirty=t.isDirty:t.type===`CONFIRM_REQUEST`&&this.handleConfirmRequest(t.kind)},this.config=e,$(e.locale)}mount(){if(this.bridge)return;let t=typeof this.config.container==`string`?document.querySelector(this.config.container):this.config.container;if(!t)throw Error(`Ziila: container not found: ${this.config.container}`);this.bridge=new e(e=>{e.onmessage=this.handleMessage;let{container:t,...n}=this.config,r=h(this.config.theme);this.resolvedTheme=r,this.bridge?.send({type:`INIT`,payload:{...n,theme:r}})},this.config.widgetUrl),this.bridge.mount(t),window.addEventListener(`beforeunload`,this.handleBeforeUnload)}handleConfirmRequest(e){this.confirmDialog.show({...ie(),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t})})}on(e,t){return this.bus.on(e,t)}off(e,t){this.bus.off(e,t)}emit(e,t){this.bridge?.send({type:`COMMAND`,command:e,payload:t})}update(e){this.config={...this.config,...e},e.locale!==void 0&&$(e.locale),`theme`in e&&(this.resolvedTheme=h(this.config.theme)),this.bridge?.send({type:`UPDATE`,payload:e})}destroy(){window.removeEventListener(`beforeunload`,this.handleBeforeUnload),this.confirmDialog.close(),this.bridge?.destroy(),this.bus.destroy(),this.bridge=null}};function oe(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=ae,exports.isZiilaError=oe;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.setAttribute(`allow`,`microphone; autoplay`),this.iframe.style.cssText=`width:100%;height:100%;border:none;`,e.appendChild(this.iframe),window.addEventListener(`message`,this.handleHandshake)}send(e){this.port?.postMessage(e)}destroy(){window.removeEventListener(`message`,this.handleHandshake),this.port?.close(),this.iframe?.remove(),this.iframe=null,this.port=null}},t=class{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){this.handlers.get(e)?.forEach(e=>e(t))}destroy(){this.handlers.clear()}},n=e=>`position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.4);padding:24px;font-family:${e.fontFamily??`system-ui,-apple-system,sans-serif`};`,r=e=>`width:100%;max-width:24rem;border-radius:${e.borderRadius??`12px`};background:${e.backgroundColor??`#fff`};padding:16px;box-shadow:2px 4px 2px rgba(0,0,0,0.1);display:flex;flex-direction:column;gap:16px;`,i=`display:flex;justify-content:flex-end;`,a=e=>`border:none;background:${e.mutedColor??`#f0f0f0`};border-radius:${e.buttonRadius??`12px`};width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:${e.mutedFg??`#555`};line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,ee=e=>`margin:0;font-size:24px;font-weight:700;color:${e.primaryColor??`#195f6b`};text-align:center;`,s=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,c=`display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;`,te=e=>`flex:1;border:1px solid ${e.primaryColor??`#195f6b`};border-radius:${e.buttonRadius??`8px`};background:${e.backgroundColor??`#fff`};color:${e.primaryColor??`#195f6b`};padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,l=e=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,u=class{constructor(){this.overlay=null,this.pendingResolve=null,this.previousFocus=null}show(e){return this.pendingResolve?.(!1),this.pendingResolve=null,this.close(),new Promise(t=>{this.pendingResolve=t;let u=e=>{this.pendingResolve=null,this.close(),t(e)},d=e.tokens??{},f=document.createElement(`div`);f.style.cssText=n(d);let p=document.createElement(`div`);p.setAttribute(`role`,`dialog`),p.setAttribute(`aria-modal`,`true`),p.setAttribute(`aria-labelledby`,`ziila-confirm-title`),p.style.cssText=r(d),p.dir=e.dir;let m=document.createElement(`div`);m.style.cssText=i;let h=document.createElement(`button`);h.type=`button`,h.setAttribute(`aria-label`,e.closeLabel),h.textContent=`✕`,h.style.cssText=a(d),h.addEventListener(`click`,()=>u(!1)),m.appendChild(h);let g=document.createElement(`div`);g.style.cssText=o;let _=document.createElement(`h2`);_.id=`ziila-confirm-title`,_.textContent=e.title,_.style.cssText=ee(d);let v=document.createElement(`p`);v.textContent=e.message,v.style.cssText=s(d);let y=document.createElement(`button`);y.type=`button`,y.textContent=e.cancelLabel,y.style.cssText=te(d),y.addEventListener(`click`,()=>u(!1));let b=document.createElement(`button`);b.type=`button`,b.textContent=e.confirmLabel,b.style.cssText=l(d),b.addEventListener(`click`,()=>u(!0));let x=document.createElement(`div`);x.style.cssText=c,x.append(y,b),g.append(_,v,x),p.append(m,g),f.appendChild(p);let S=[h,y,b];f.addEventListener(`keydown`,e=>{if(e.key===`Escape`){u(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(S.indexOf(document.activeElement)+(e.shiftKey?-1:1)+S.length)%S.length;S[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=f,document.body.appendChild(f),y.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},d={primaryColor:[`--primary`,`--primary-color`,`--color-primary`,`--brand`,`--brand-color`,`--accent-color`,`--bs-primary`,`--mui-palette-primary-main`,`--ant-color-primary`],borderRadius:[`--radius`,`--border-radius`,`--rounded`,`--bs-border-radius`]},f=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function p(e){return!!e&&!f.has(e.trim().toLowerCase())}function m(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(p(r.fontFamily)&&(i.fontFamily=r.fontFamily),p(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),p(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(d))for(let r of t){let t=n.getPropertyValue(r).trim();if(p(t)){i[e]=t;break}}return i}function h(e,t={}){let n={...m(t.doc??document),...e?.tokens},r={};return Object.keys(n).length>0&&(r.tokens=n),e?.elements&&Object.keys(e.elements).length>0&&(r.elements=e.elements),r}var g={},_=[`en`,`ar`],v=`PARAGLIDE_LOCALE`,y=[`baseLocale`],b=[],x,S;function C(e){if(b.length===0)return;let t=typeof e==`string`?e:e.href;if(x===t)return S;let n=new URL(t,`http://dummy.com`),r;for(let e of b)if(new g(e.match,n.href).exec(n.href)){r=e;break}return x=t,S=r,r}function w(e){let t=C(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:y}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var T=!1,E=()=>{let e=y;typeof window<`u`&&window.location?.href&&(e=w(window.location.href));let t=D(e,typeof window<`u`?window.location?.href:void 0);if(t)return T||(T=!0,A(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function D(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(F(t)&&P.has(t)){let e=P.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return M(t)}}let e=j(n);if(e)return e}}var O=e=>{E=e},k=e=>{e?window.location.href=e:window.location.reload()},A=(e,t)=>{let n={reload:!0,...t},r;try{r=E()}catch{}let i=[],a=y;typeof window<`u`&&window.location?.href&&(a=w(window.location.href));for(let t of a)if(t===`baseLocale`)continue;else if(F(t)&&P.has(t)){let n=P.get(t);if(n){let r=n.setLocale(e);r instanceof Promise&&(r=r.catch(e=>{throw Error(`Custom strategy "${t}" setLocale failed.`,{cause:e})}),i.push(r))}}let o=()=>{n.reload&&window.location&&e!==r&&k(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function j(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of _)if(e.toLowerCase()===t)return e}function M(e){let t=j(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(`, `)}`)}var N=v.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${N}=([^;]*)`);var P=new Map;function F(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var I=()=>`End Chat`,L=()=>`إنهاء المحادثة`,R=((e={},t={})=>(t.locale??E())===`en`?I(e):L(e)),z=()=>`Are you sure you want to end this chat?`,B=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,V=((e={},t={})=>(t.locale??E())===`en`?z(e):B(e)),H=()=>`End Chat`,U=()=>`إنهاء المحادثة`,W=((e={},t={})=>(t.locale??E())===`en`?H(e):U(e)),G=()=>`Cancel`,K=()=>`إلغاء`,q=((e={},t={})=>(t.locale??E())===`en`?G(e):K(e)),J=()=>`Close`,Y=()=>`إغلاق`,X=((e={},t={})=>(t.locale??E())===`en`?J(e):Y(e)),Z=new Set(_),Q=`en`;O(()=>Q);function ne(){return Q}function $(e){Q=e&&Z.has(e)?e:`en`}function re(e){return e===`ar`?`rtl`:`ltr`}function ie(){return{title:R(),message:V(),confirmLabel:W(),cancelLabel:q(),closeLabel:X(),dir:re(ne())}}var ae=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new u,this.resolvedTheme={},this._isDirty=!1,this.handleBeforeUnload=e=>{this._isDirty&&(e.preventDefault(),e.returnValue=``)},this.handleMessage=e=>{let t=e.data;t.type===`READY`?this.bus.emit(`ready`):t.type===`EVENT`?this.bus.emit(t.event,t.payload):t.type===`DIRTY_STATE`?this._isDirty=t.isDirty:t.type===`CONFIRM_REQUEST`&&this.handleConfirmRequest(t.kind)},this.config=e,$(e.locale)}mount(){if(this.bridge)return;let t=typeof this.config.container==`string`?document.querySelector(this.config.container):this.config.container;if(!t)throw Error(`Ziila: container not found: ${this.config.container}`);this.bridge=new e(e=>{e.onmessage=this.handleMessage;let{container:t,...n}=this.config,r=h(this.config.theme);this.resolvedTheme=r,this.bridge?.send({type:`INIT`,payload:{...n,theme:r}})},this.config.widgetUrl),this.bridge.mount(t),window.addEventListener(`beforeunload`,this.handleBeforeUnload)}handleConfirmRequest(e){this.confirmDialog.show({...ie(),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t})})}on(e,t){return this.bus.on(e,t)}off(e,t){this.bus.off(e,t)}emit(e,t){this.bridge?.send({type:`COMMAND`,command:e,payload:t})}update(e){this.config={...this.config,...e},e.locale!==void 0&&$(e.locale),`theme`in e&&(this.resolvedTheme=h(this.config.theme)),this.bridge?.send({type:`UPDATE`,payload:e})}destroy(){window.removeEventListener(`beforeunload`,this.handleBeforeUnload),this.confirmDialog.close(),this.bridge?.destroy(),this.bus.destroy(),this.bridge=null}};function oe(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=ae,exports.isZiilaError=oe;
|
package/dist/index.esm.js
CHANGED
|
@@ -11,7 +11,7 @@ var e = class {
|
|
|
11
11
|
}
|
|
12
12
|
mount(e) {
|
|
13
13
|
let t = new URL(this.url);
|
|
14
|
-
t.searchParams.set("embedded", "1"), this.iframe = document.createElement("iframe"), this.iframe.src = t.toString(), this.iframe.title = "Ziila Shopping Assistant", this.iframe.style.cssText = "width:100%;height:100%;border:none;", e.appendChild(this.iframe), window.addEventListener("message", this.handleHandshake);
|
|
14
|
+
t.searchParams.set("embedded", "1"), this.iframe = document.createElement("iframe"), this.iframe.src = t.toString(), this.iframe.title = "Ziila Shopping Assistant", this.iframe.setAttribute("allow", "microphone; autoplay"), this.iframe.style.cssText = "width:100%;height:100%;border:none;", e.appendChild(this.iframe), window.addEventListener("message", this.handleHandshake);
|
|
15
15
|
}
|
|
16
16
|
send(e) {
|
|
17
17
|
this.port?.postMessage(e);
|
package/dist/src/types.d.ts
CHANGED
|
@@ -73,12 +73,6 @@ export interface ZiilaConfig {
|
|
|
73
73
|
locale?: string;
|
|
74
74
|
widgetTitle?: string;
|
|
75
75
|
theme?: Partial<ThemeStyles>;
|
|
76
|
-
/** Absolute URL of this merchant's checkout page. May contain a
|
|
77
|
-
* `{locale}` placeholder, resolved against the widget's active locale
|
|
78
|
-
* at click time (e.g. `https://shop.example/{locale}/checkout`). The
|
|
79
|
-
* cart's checkout buttons navigate the top window here; omitted, they
|
|
80
|
-
* render disabled. */
|
|
81
|
-
checkoutUrl?: string;
|
|
82
76
|
widgetUrl?: string;
|
|
83
77
|
}
|
|
84
78
|
export interface AddToCartPayload {
|
package/dist/widget.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.style.cssText=`width:100%;height:100%;border:none;`,e.appendChild(this.iframe),window.addEventListener(`message`,this.handleHandshake)}send(e){this.port?.postMessage(e)}destroy(){window.removeEventListener(`message`,this.handleHandshake),this.port?.close(),this.iframe?.remove(),this.iframe=null,this.port=null}},t=class{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){this.handlers.get(e)?.forEach(e=>e(t))}destroy(){this.handlers.clear()}},n=e=>`position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.4);padding:24px;font-family:${e.fontFamily??`system-ui,-apple-system,sans-serif`};`,r=e=>`width:100%;max-width:24rem;border-radius:${e.borderRadius??`12px`};background:${e.backgroundColor??`#fff`};padding:16px;box-shadow:2px 4px 2px rgba(0,0,0,0.1);display:flex;flex-direction:column;gap:16px;`,i=`display:flex;justify-content:flex-end;`,a=e=>`border:none;background:${e.mutedColor??`#f0f0f0`};border-radius:${e.buttonRadius??`12px`};width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:${e.mutedFg??`#555`};line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,s=e=>`margin:0;font-size:24px;font-weight:700;color:${e.primaryColor??`#195f6b`};text-align:center;`,ee=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,te=`display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;`,c=e=>`flex:1;border:1px solid ${e.primaryColor??`#195f6b`};border-radius:${e.buttonRadius??`8px`};background:${e.backgroundColor??`#fff`};color:${e.primaryColor??`#195f6b`};padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,l=e=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,u=class{constructor(){this.overlay=null,this.pendingResolve=null,this.previousFocus=null}show(e){return this.pendingResolve?.(!1),this.pendingResolve=null,this.close(),new Promise(t=>{this.pendingResolve=t;let u=e=>{this.pendingResolve=null,this.close(),t(e)},d=e.tokens??{},f=document.createElement(`div`);f.style.cssText=n(d);let p=document.createElement(`div`);p.setAttribute(`role`,`dialog`),p.setAttribute(`aria-modal`,`true`),p.setAttribute(`aria-labelledby`,`ziila-confirm-title`),p.style.cssText=r(d),p.dir=e.dir;let m=document.createElement(`div`);m.style.cssText=i;let h=document.createElement(`button`);h.type=`button`,h.setAttribute(`aria-label`,e.closeLabel),h.textContent=`✕`,h.style.cssText=a(d),h.addEventListener(`click`,()=>u(!1)),m.appendChild(h);let g=document.createElement(`div`);g.style.cssText=o;let _=document.createElement(`h2`);_.id=`ziila-confirm-title`,_.textContent=e.title,_.style.cssText=s(d);let v=document.createElement(`p`);v.textContent=e.message,v.style.cssText=ee(d);let y=document.createElement(`button`);y.type=`button`,y.textContent=e.cancelLabel,y.style.cssText=c(d),y.addEventListener(`click`,()=>u(!1));let b=document.createElement(`button`);b.type=`button`,b.textContent=e.confirmLabel,b.style.cssText=l(d),b.addEventListener(`click`,()=>u(!0));let x=document.createElement(`div`);x.style.cssText=te,x.append(y,b),g.append(_,v,x),p.append(m,g),f.appendChild(p);let S=[h,y,b];f.addEventListener(`keydown`,e=>{if(e.key===`Escape`){u(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(S.indexOf(document.activeElement)+(e.shiftKey?-1:1)+S.length)%S.length;S[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=f,document.body.appendChild(f),y.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},d={primaryColor:[`--primary`,`--primary-color`,`--color-primary`,`--brand`,`--brand-color`,`--accent-color`,`--bs-primary`,`--mui-palette-primary-main`,`--ant-color-primary`],borderRadius:[`--radius`,`--border-radius`,`--rounded`,`--bs-border-radius`]},f=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function p(e){return!!e&&!f.has(e.trim().toLowerCase())}function m(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(p(r.fontFamily)&&(i.fontFamily=r.fontFamily),p(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),p(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(d))for(let r of t){let t=n.getPropertyValue(r).trim();if(p(t)){i[e]=t;break}}return i}function h(e,t={}){let n={...m(t.doc??document),...e?.tokens},r={};return Object.keys(n).length>0&&(r.tokens=n),e?.elements&&Object.keys(e.elements).length>0&&(r.elements=e.elements),r}var g={},_=[`en`,`ar`],v=`PARAGLIDE_LOCALE`,y=[`baseLocale`],b=[],x,S;function ne(e){if(b.length===0)return;let t=typeof e==`string`?e:e.href;if(x===t)return S;let n=new URL(t,`http://dummy.com`),r;for(let e of b)if(new g(e.match,n.href).exec(n.href)){r=e;break}return x=t,S=r,r}function C(e){let t=ne(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:y}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var w=!1,T=()=>{let e=y;typeof window<`u`&&window.location?.href&&(e=C(window.location.href));let t=re(e,typeof window<`u`?window.location?.href:void 0);if(t)return w||(w=!0,ae(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function re(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(j(t)&&A.has(t)){let e=A.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return O(t)}}let e=D(n);if(e)return e}}var E=e=>{T=e},ie=e=>{e?window.location.href=e:window.location.reload()},ae=(e,t)=>{let n={reload:!0,...t},r;try{r=T()}catch{}let i=[],a=y;typeof window<`u`&&window.location?.href&&(a=C(window.location.href));for(let t of a)if(t===`baseLocale`)continue;else if(j(t)&&A.has(t)){let n=A.get(t);if(n){let r=n.setLocale(e);r instanceof Promise&&(r=r.catch(e=>{throw Error(`Custom strategy "${t}" setLocale failed.`,{cause:e})}),i.push(r))}}let o=()=>{n.reload&&window.location&&e!==r&&ie(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function D(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of _)if(e.toLowerCase()===t)return e}function O(e){let t=D(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(`, `)}`)}var k=v.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${k}=([^;]*)`);var A=new Map;function j(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var M=()=>`End Chat`,N=()=>`إنهاء المحادثة`,P=((e={},t={})=>(t.locale??T())===`en`?M(e):N(e)),F=()=>`Are you sure you want to end this chat?`,I=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,L=((e={},t={})=>(t.locale??T())===`en`?F(e):I(e)),R=()=>`End Chat`,z=()=>`إنهاء المحادثة`,B=((e={},t={})=>(t.locale??T())===`en`?R(e):z(e)),V=()=>`Cancel`,H=()=>`إلغاء`,oe=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),U=()=>`Close`,W=()=>`إغلاق`,G=((e={},t={})=>(t.locale??T())===`en`?U(e):W(e)),K=new Set(_),q=`en`;E(()=>q);function J(){return q}function Y(e){q=e&&K.has(e)?e:`en`}function se(e){return e===`ar`?`rtl`:`ltr`}function ce(){return{title:P(),message:L(),confirmLabel:B(),cancelLabel:oe(),closeLabel:G(),dir:se(J())}}var le=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new u,this.resolvedTheme={},this._isDirty=!1,this.handleBeforeUnload=e=>{this._isDirty&&(e.preventDefault(),e.returnValue=``)},this.handleMessage=e=>{let t=e.data;t.type===`READY`?this.bus.emit(`ready`):t.type===`EVENT`?this.bus.emit(t.event,t.payload):t.type===`DIRTY_STATE`?this._isDirty=t.isDirty:t.type===`CONFIRM_REQUEST`&&this.handleConfirmRequest(t.kind)},this.config=e,Y(e.locale)}mount(){if(this.bridge)return;let t=typeof this.config.container==`string`?document.querySelector(this.config.container):this.config.container;if(!t)throw Error(`Ziila: container not found: ${this.config.container}`);this.bridge=new e(e=>{e.onmessage=this.handleMessage;let{container:t,...n}=this.config,r=h(this.config.theme);this.resolvedTheme=r,this.bridge?.send({type:`INIT`,payload:{...n,theme:r}})},this.config.widgetUrl),this.bridge.mount(t),window.addEventListener(`beforeunload`,this.handleBeforeUnload)}handleConfirmRequest(e){this.confirmDialog.show({...ce(),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t})})}on(e,t){return this.bus.on(e,t)}off(e,t){this.bus.off(e,t)}emit(e,t){this.bridge?.send({type:`COMMAND`,command:e,payload:t})}update(e){this.config={...this.config,...e},e.locale!==void 0&&Y(e.locale),`theme`in e&&(this.resolvedTheme=h(this.config.theme)),this.bridge?.send({type:`UPDATE`,payload:e})}destroy(){window.removeEventListener(`beforeunload`,this.handleBeforeUnload),this.confirmDialog.close(),this.bridge?.destroy(),this.bus.destroy(),this.bridge=null}},X=null,ue=window.Ziila?.q??[],Z=document.currentScript,de=Z instanceof HTMLScriptElement&&Z.src?new URL(`..`,Z.src).toString():void 0;function Q(e){X?.destroy(),X=new le(e.widgetUrl?e:{...e,widgetUrl:de}),X.mount()}var $=function(e){Q(e)};$.on=function(e,t){if(!X)throw Error(`Ziila: call Ziila(config) before Ziila.on()`);return X.on(e,t)},$.off=function(e,t){X?.off(e,t)},$.emit=function(e,t){X?.emit(e,t)},$.update=function(e){X?.update(e)},$.mount=function(){X?.mount()},$.destroy=function(){X?.destroy(),X=null},Object.defineProperty($,"isDirty",{get:()=>X?.isDirty??!1,enumerable:!0,configurable:!1}),window.Ziila=$,ue.forEach(Q)})();
|
|
1
|
+
(function(){var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.setAttribute(`allow`,`microphone; autoplay`),this.iframe.style.cssText=`width:100%;height:100%;border:none;`,e.appendChild(this.iframe),window.addEventListener(`message`,this.handleHandshake)}send(e){this.port?.postMessage(e)}destroy(){window.removeEventListener(`message`,this.handleHandshake),this.port?.close(),this.iframe?.remove(),this.iframe=null,this.port=null}},t=class{constructor(){this.handlers=new Map}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){this.handlers.get(e)?.forEach(e=>e(t))}destroy(){this.handlers.clear()}},n=e=>`position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.4);padding:24px;font-family:${e.fontFamily??`system-ui,-apple-system,sans-serif`};`,r=e=>`width:100%;max-width:24rem;border-radius:${e.borderRadius??`12px`};background:${e.backgroundColor??`#fff`};padding:16px;box-shadow:2px 4px 2px rgba(0,0,0,0.1);display:flex;flex-direction:column;gap:16px;`,i=`display:flex;justify-content:flex-end;`,a=e=>`border:none;background:${e.mutedColor??`#f0f0f0`};border-radius:${e.buttonRadius??`12px`};width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:${e.mutedFg??`#555`};line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,s=e=>`margin:0;font-size:24px;font-weight:700;color:${e.primaryColor??`#195f6b`};text-align:center;`,ee=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,te=`display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;`,c=e=>`flex:1;border:1px solid ${e.primaryColor??`#195f6b`};border-radius:${e.buttonRadius??`8px`};background:${e.backgroundColor??`#fff`};color:${e.primaryColor??`#195f6b`};padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,l=e=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight:${e.buttonFontWeight??`500`};cursor:pointer;`,u=class{constructor(){this.overlay=null,this.pendingResolve=null,this.previousFocus=null}show(e){return this.pendingResolve?.(!1),this.pendingResolve=null,this.close(),new Promise(t=>{this.pendingResolve=t;let u=e=>{this.pendingResolve=null,this.close(),t(e)},d=e.tokens??{},f=document.createElement(`div`);f.style.cssText=n(d);let p=document.createElement(`div`);p.setAttribute(`role`,`dialog`),p.setAttribute(`aria-modal`,`true`),p.setAttribute(`aria-labelledby`,`ziila-confirm-title`),p.style.cssText=r(d),p.dir=e.dir;let m=document.createElement(`div`);m.style.cssText=i;let h=document.createElement(`button`);h.type=`button`,h.setAttribute(`aria-label`,e.closeLabel),h.textContent=`✕`,h.style.cssText=a(d),h.addEventListener(`click`,()=>u(!1)),m.appendChild(h);let g=document.createElement(`div`);g.style.cssText=o;let _=document.createElement(`h2`);_.id=`ziila-confirm-title`,_.textContent=e.title,_.style.cssText=s(d);let v=document.createElement(`p`);v.textContent=e.message,v.style.cssText=ee(d);let y=document.createElement(`button`);y.type=`button`,y.textContent=e.cancelLabel,y.style.cssText=c(d),y.addEventListener(`click`,()=>u(!1));let b=document.createElement(`button`);b.type=`button`,b.textContent=e.confirmLabel,b.style.cssText=l(d),b.addEventListener(`click`,()=>u(!0));let x=document.createElement(`div`);x.style.cssText=te,x.append(y,b),g.append(_,v,x),p.append(m,g),f.appendChild(p);let S=[h,y,b];f.addEventListener(`keydown`,e=>{if(e.key===`Escape`){u(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(S.indexOf(document.activeElement)+(e.shiftKey?-1:1)+S.length)%S.length;S[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=f,document.body.appendChild(f),y.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},d={primaryColor:[`--primary`,`--primary-color`,`--color-primary`,`--brand`,`--brand-color`,`--accent-color`,`--bs-primary`,`--mui-palette-primary-main`,`--ant-color-primary`],borderRadius:[`--radius`,`--border-radius`,`--rounded`,`--bs-border-radius`]},f=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function p(e){return!!e&&!f.has(e.trim().toLowerCase())}function m(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(p(r.fontFamily)&&(i.fontFamily=r.fontFamily),p(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),p(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(d))for(let r of t){let t=n.getPropertyValue(r).trim();if(p(t)){i[e]=t;break}}return i}function h(e,t={}){let n={...m(t.doc??document),...e?.tokens},r={};return Object.keys(n).length>0&&(r.tokens=n),e?.elements&&Object.keys(e.elements).length>0&&(r.elements=e.elements),r}var g={},_=[`en`,`ar`],v=`PARAGLIDE_LOCALE`,y=[`baseLocale`],b=[],x,S;function ne(e){if(b.length===0)return;let t=typeof e==`string`?e:e.href;if(x===t)return S;let n=new URL(t,`http://dummy.com`),r;for(let e of b)if(new g(e.match,n.href).exec(n.href)){r=e;break}return x=t,S=r,r}function C(e){let t=ne(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:y}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var w=!1,T=()=>{let e=y;typeof window<`u`&&window.location?.href&&(e=C(window.location.href));let t=re(e,typeof window<`u`?window.location?.href:void 0);if(t)return w||(w=!0,ae(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function re(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(j(t)&&A.has(t)){let e=A.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return O(t)}}let e=D(n);if(e)return e}}var E=e=>{T=e},ie=e=>{e?window.location.href=e:window.location.reload()},ae=(e,t)=>{let n={reload:!0,...t},r;try{r=T()}catch{}let i=[],a=y;typeof window<`u`&&window.location?.href&&(a=C(window.location.href));for(let t of a)if(t===`baseLocale`)continue;else if(j(t)&&A.has(t)){let n=A.get(t);if(n){let r=n.setLocale(e);r instanceof Promise&&(r=r.catch(e=>{throw Error(`Custom strategy "${t}" setLocale failed.`,{cause:e})}),i.push(r))}}let o=()=>{n.reload&&window.location&&e!==r&&ie(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function D(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of _)if(e.toLowerCase()===t)return e}function O(e){let t=D(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(`, `)}`)}var k=v.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${k}=([^;]*)`);var A=new Map;function j(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var M=()=>`End Chat`,N=()=>`إنهاء المحادثة`,P=((e={},t={})=>(t.locale??T())===`en`?M(e):N(e)),F=()=>`Are you sure you want to end this chat?`,I=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,L=((e={},t={})=>(t.locale??T())===`en`?F(e):I(e)),R=()=>`End Chat`,z=()=>`إنهاء المحادثة`,B=((e={},t={})=>(t.locale??T())===`en`?R(e):z(e)),V=()=>`Cancel`,H=()=>`إلغاء`,oe=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),U=()=>`Close`,W=()=>`إغلاق`,G=((e={},t={})=>(t.locale??T())===`en`?U(e):W(e)),K=new Set(_),q=`en`;E(()=>q);function J(){return q}function Y(e){q=e&&K.has(e)?e:`en`}function se(e){return e===`ar`?`rtl`:`ltr`}function ce(){return{title:P(),message:L(),confirmLabel:B(),cancelLabel:oe(),closeLabel:G(),dir:se(J())}}var le=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new u,this.resolvedTheme={},this._isDirty=!1,this.handleBeforeUnload=e=>{this._isDirty&&(e.preventDefault(),e.returnValue=``)},this.handleMessage=e=>{let t=e.data;t.type===`READY`?this.bus.emit(`ready`):t.type===`EVENT`?this.bus.emit(t.event,t.payload):t.type===`DIRTY_STATE`?this._isDirty=t.isDirty:t.type===`CONFIRM_REQUEST`&&this.handleConfirmRequest(t.kind)},this.config=e,Y(e.locale)}mount(){if(this.bridge)return;let t=typeof this.config.container==`string`?document.querySelector(this.config.container):this.config.container;if(!t)throw Error(`Ziila: container not found: ${this.config.container}`);this.bridge=new e(e=>{e.onmessage=this.handleMessage;let{container:t,...n}=this.config,r=h(this.config.theme);this.resolvedTheme=r,this.bridge?.send({type:`INIT`,payload:{...n,theme:r}})},this.config.widgetUrl),this.bridge.mount(t),window.addEventListener(`beforeunload`,this.handleBeforeUnload)}handleConfirmRequest(e){this.confirmDialog.show({...ce(),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t})})}on(e,t){return this.bus.on(e,t)}off(e,t){this.bus.off(e,t)}emit(e,t){this.bridge?.send({type:`COMMAND`,command:e,payload:t})}update(e){this.config={...this.config,...e},e.locale!==void 0&&Y(e.locale),`theme`in e&&(this.resolvedTheme=h(this.config.theme)),this.bridge?.send({type:`UPDATE`,payload:e})}destroy(){window.removeEventListener(`beforeunload`,this.handleBeforeUnload),this.confirmDialog.close(),this.bridge?.destroy(),this.bus.destroy(),this.bridge=null}},X=null,ue=window.Ziila?.q??[],Z=document.currentScript,de=Z instanceof HTMLScriptElement&&Z.src?new URL(`..`,Z.src).toString():void 0;function Q(e){X?.destroy(),X=new le(e.widgetUrl?e:{...e,widgetUrl:de}),X.mount()}var $=function(e){Q(e)};$.on=function(e,t){if(!X)throw Error(`Ziila: call Ziila(config) before Ziila.on()`);return X.on(e,t)},$.off=function(e,t){X?.off(e,t)},$.emit=function(e,t){X?.emit(e,t)},$.update=function(e){X?.update(e)},$.mount=function(){X?.mount()},$.destroy=function(){X?.destroy(),X=null},Object.defineProperty($,"isDirty",{get:()=>X?.isDirty??!1,enumerable:!0,configurable:!1}),window.Ziila=$,ue.forEach(Q)})();
|