@ziila/sdk 0.1.91 → 0.1.95

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 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.setAttribute(`allow`,`microphone; autoplay`),this.iframe.style.cssText=`display:block;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=`display:block;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;`,c=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,l=`display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;`,u=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;`,d=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;`,f=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 f=e=>{this.pendingResolve=null,this.close(),t(e)},p=e.tokens??{},m=document.createElement(`div`);m.style.cssText=n(p);let h=document.createElement(`div`);h.setAttribute(`role`,`dialog`),h.setAttribute(`aria-modal`,`true`),h.setAttribute(`aria-labelledby`,`ziila-confirm-title`),h.style.cssText=r(p),h.dir=e.dir;let g=document.createElement(`div`);g.style.cssText=i;let _=document.createElement(`button`);_.type=`button`,_.setAttribute(`aria-label`,e.closeLabel),_.textContent=`✕`,_.style.cssText=a(p),_.addEventListener(`click`,()=>f(!1)),g.appendChild(_);let v=document.createElement(`div`);v.style.cssText=o;let y=document.createElement(`h2`);y.id=`ziila-confirm-title`,y.textContent=e.title,y.style.cssText=s(p);let b=document.createElement(`p`);b.textContent=e.message,b.style.cssText=c(p);let x=document.createElement(`button`);x.type=`button`,x.textContent=e.cancelLabel,x.style.cssText=u(p),x.addEventListener(`click`,()=>f(!1));let S=document.createElement(`button`);S.type=`button`,S.textContent=e.confirmLabel,S.style.cssText=d(p),S.addEventListener(`click`,()=>f(!0));let C=document.createElement(`div`);C.style.cssText=l,C.append(x,S),v.append(y,b,C),h.append(g,v),m.appendChild(h);let w=[_,x,S];m.addEventListener(`keydown`,e=>{if(e.key===`Escape`){f(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(w.indexOf(document.activeElement)+(e.shiftKey?-1:1)+w.length)%w.length;w[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=m,document.body.appendChild(m),x.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},p={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`]},m=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function h(e){return!!e&&!m.has(e.trim().toLowerCase())}function g(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(h(r.fontFamily)&&(i.fontFamily=r.fontFamily),h(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),h(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(p))for(let r of t){let t=n.getPropertyValue(r).trim();if(h(t)){i[e]=t;break}}return i}function _(e,t={}){let n={...g(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 v={},y=[`en`,`ar`],b=`PARAGLIDE_LOCALE`,x=[`baseLocale`],S=[],C,w;function T(e){if(S.length===0)return;let t=typeof e==`string`?e:e.href;if(C===t)return w;let n=new URL(t,`http://dummy.com`),r;for(let e of S)if(new v(e.match,n.href).exec(n.href)){r=e;break}return C=t,w=r,r}function E(e){let t=T(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:x}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var D=!1,O=()=>{let e=x;typeof window<`u`&&window.location?.href&&(e=E(window.location.href));let t=k(e,typeof window<`u`?window.location?.href:void 0);if(t)return D||(D=!0,j(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function k(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(I(t)&&F.has(t)){let e=F.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return N(t)}}let e=M(n);if(e)return e}}var A=e=>{e?window.location.href=e:window.location.reload()},j=(e,t)=>{let n={reload:!0,...t},r;try{r=O()}catch{}let i=[],a=x;typeof window<`u`&&window.location?.href&&(a=E(window.location.href));for(let t of a)if(t===`baseLocale`)continue;else if(I(t)&&F.has(t)){let n=F.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&&A(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function M(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of y)if(e.toLowerCase()===t)return e}function N(e){let t=M(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${y.join(`, `)}`)}var P=b.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${P}=([^;]*)`);var F=new Map;function I(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var L=()=>`End Chat`,R=()=>`إنهاء المحادثة`,z=((e={},t={})=>(t.locale??O())===`en`?L(e):R(e)),B=()=>`Are you sure you want to end this chat?`,V=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,H=((e={},t={})=>(t.locale??O())===`en`?B(e):V(e)),U=()=>`End Chat`,W=()=>`إنهاء المحادثة`,G=((e={},t={})=>(t.locale??O())===`en`?U(e):W(e)),K=()=>`Cancel`,q=()=>`إلغاء`,J=((e={},t={})=>(t.locale??O())===`en`?K(e):q(e)),Y=()=>`Close`,X=()=>`إغلاق`,Z=((e={},t={})=>(t.locale??O())===`en`?Y(e):X(e)),Q=new Set(y);function $(e){return e&&Q.has(e)?e:`en`}function ee(e){return e===`ar`?`rtl`:`ltr`}function te(e){return{title:z({},{locale:e}),message:H({},{locale:e}),confirmLabel:G({},{locale:e}),cancelLabel:J({},{locale:e}),closeLabel:Z({},{locale:e}),dir:ee(e)}}var ne=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new f,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,t.locale)},this.config=e}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=_(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,t){this.confirmDialog.show({...te($(t)),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},`theme`in e&&(this.resolvedTheme=_(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 re(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=ne,exports.isZiilaError=re;
package/dist/index.esm.js CHANGED
@@ -35,57 +35,57 @@ var e = class {
35
35
  destroy() {
36
36
  this.handlers.clear();
37
37
  }
38
- }, 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 {
38
+ }, 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;`, c = (e) => `margin:0;font-size:16px;color:${e.foregroundColor ?? "#2d2d2d"};font-weight:500;line-height:27px;text-align:center;max-width:345px;`, l = "display:flex;gap:16px;padding:0 16px;width:100%;box-sizing:border-box;", u = (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;`, d = (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;`, f = class {
39
39
  constructor() {
40
40
  this.overlay = null, this.pendingResolve = null, this.previousFocus = null;
41
41
  }
42
42
  show(e) {
43
43
  return this.pendingResolve?.(!1), this.pendingResolve = null, this.close(), new Promise((t) => {
44
44
  this.pendingResolve = t;
45
- let u = (e) => {
45
+ let f = (e) => {
46
46
  this.pendingResolve = null, this.close(), t(e);
47
- }, d = e.tokens ?? {}, f = document.createElement("div");
48
- f.style.cssText = n(d);
49
- let p = document.createElement("div");
50
- 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;
51
- let m = document.createElement("div");
52
- m.style.cssText = i;
53
- let h = document.createElement("button");
54
- h.type = "button", h.setAttribute("aria-label", e.closeLabel), h.textContent = "✕", h.style.cssText = a(d), h.addEventListener("click", () => u(!1)), m.appendChild(h);
47
+ }, p = e.tokens ?? {}, m = document.createElement("div");
48
+ m.style.cssText = n(p);
49
+ let h = document.createElement("div");
50
+ h.setAttribute("role", "dialog"), h.setAttribute("aria-modal", "true"), h.setAttribute("aria-labelledby", "ziila-confirm-title"), h.style.cssText = r(p), h.dir = e.dir;
55
51
  let g = document.createElement("div");
56
- g.style.cssText = o;
57
- let _ = document.createElement("h2");
58
- _.id = "ziila-confirm-title", _.textContent = e.title, _.style.cssText = ee(d);
59
- let v = document.createElement("p");
60
- v.textContent = e.message, v.style.cssText = s(d);
61
- let y = document.createElement("button");
62
- y.type = "button", y.textContent = e.cancelLabel, y.style.cssText = te(d), y.addEventListener("click", () => u(!1));
63
- let b = document.createElement("button");
64
- b.type = "button", b.textContent = e.confirmLabel, b.style.cssText = l(d), b.addEventListener("click", () => u(!0));
65
- let x = document.createElement("div");
66
- x.style.cssText = c, x.append(y, b), g.append(_, v, x), p.append(m, g), f.appendChild(p);
67
- let S = [
68
- h,
69
- y,
70
- b
52
+ g.style.cssText = i;
53
+ let _ = document.createElement("button");
54
+ _.type = "button", _.setAttribute("aria-label", e.closeLabel), _.textContent = "✕", _.style.cssText = a(p), _.addEventListener("click", () => f(!1)), g.appendChild(_);
55
+ let v = document.createElement("div");
56
+ v.style.cssText = o;
57
+ let y = document.createElement("h2");
58
+ y.id = "ziila-confirm-title", y.textContent = e.title, y.style.cssText = s(p);
59
+ let b = document.createElement("p");
60
+ b.textContent = e.message, b.style.cssText = c(p);
61
+ let x = document.createElement("button");
62
+ x.type = "button", x.textContent = e.cancelLabel, x.style.cssText = u(p), x.addEventListener("click", () => f(!1));
63
+ let S = document.createElement("button");
64
+ S.type = "button", S.textContent = e.confirmLabel, S.style.cssText = d(p), S.addEventListener("click", () => f(!0));
65
+ let C = document.createElement("div");
66
+ C.style.cssText = l, C.append(x, S), v.append(y, b, C), h.append(g, v), m.appendChild(h);
67
+ let w = [
68
+ _,
69
+ x,
70
+ S
71
71
  ];
72
- f.addEventListener("keydown", (e) => {
72
+ m.addEventListener("keydown", (e) => {
73
73
  if (e.key === "Escape") {
74
- u(!1);
74
+ f(!1);
75
75
  return;
76
76
  }
77
77
  if (e.key === "Tab") {
78
78
  e.preventDefault();
79
- let t = (S.indexOf(document.activeElement) + (e.shiftKey ? -1 : 1) + S.length) % S.length;
80
- S[t].focus();
79
+ let t = (w.indexOf(document.activeElement) + (e.shiftKey ? -1 : 1) + w.length) % w.length;
80
+ w[t].focus();
81
81
  }
82
- }), this.previousFocus = document.activeElement, this.overlay = f, document.body.appendChild(f), y.focus();
82
+ }), this.previousFocus = document.activeElement, this.overlay = m, document.body.appendChild(m), x.focus();
83
83
  });
84
84
  }
85
85
  close() {
86
86
  this.overlay?.remove(), this.overlay = null, this.previousFocus?.focus(), this.previousFocus = null;
87
87
  }
88
- }, d = {
88
+ }, p = {
89
89
  primaryColor: [
90
90
  "--primary",
91
91
  "--primary-color",
@@ -103,7 +103,7 @@ var e = class {
103
103
  "--rounded",
104
104
  "--bs-border-radius"
105
105
  ]
106
- }, f = /* @__PURE__ */ new Set([
106
+ }, m = /* @__PURE__ */ new Set([
107
107
  "",
108
108
  "transparent",
109
109
  "inherit",
@@ -114,15 +114,15 @@ var e = class {
114
114
  "rgb(0, 0, 0)",
115
115
  "depends on user agent"
116
116
  ]);
117
- function p(e) {
118
- return !!e && !f.has(e.trim().toLowerCase());
117
+ function h(e) {
118
+ return !!e && !m.has(e.trim().toLowerCase());
119
119
  }
120
- function m(e = document) {
120
+ function g(e = document) {
121
121
  let t = e.defaultView ?? globalThis, n = t.getComputedStyle(e.documentElement), r = e.body ? t.getComputedStyle(e.body) : null, i = {};
122
- r && (p(r.fontFamily) && (i.fontFamily = r.fontFamily), p(r.backgroundColor) && (i.backgroundColor = r.backgroundColor), p(r.color) && (i.foregroundColor = r.color));
123
- for (let [e, t] of Object.entries(d)) for (let r of t) {
122
+ r && (h(r.fontFamily) && (i.fontFamily = r.fontFamily), h(r.backgroundColor) && (i.backgroundColor = r.backgroundColor), h(r.color) && (i.foregroundColor = r.color));
123
+ for (let [e, t] of Object.entries(p)) for (let r of t) {
124
124
  let t = n.getPropertyValue(r).trim();
125
- if (p(t)) {
125
+ if (h(t)) {
126
126
  i[e] = t;
127
127
  break;
128
128
  }
@@ -131,72 +131,70 @@ function m(e = document) {
131
131
  }
132
132
  //#endregion
133
133
  //#region src/themeStyles.ts
134
- function h(e, t = {}) {
134
+ function _(e, t = {}) {
135
135
  let n = {
136
- ...m(t.doc ?? document),
136
+ ...g(t.doc ?? document),
137
137
  ...e?.tokens
138
138
  }, r = {};
139
139
  return Object.keys(n).length > 0 && (r.tokens = n), e?.elements && Object.keys(e.elements).length > 0 && (r.elements = e.elements), r;
140
140
  }
141
141
  //#endregion
142
142
  //#region src/paraglide/runtime.js
143
- var g = {}, _ = ["en", "ar"], v = "PARAGLIDE_LOCALE", y = ["baseLocale"], b = [], x, S;
144
- function C(e) {
145
- if (b.length === 0) return;
143
+ var v = {}, y = ["en", "ar"], b = "PARAGLIDE_LOCALE", x = ["baseLocale"], S = [], C, w;
144
+ function T(e) {
145
+ if (S.length === 0) return;
146
146
  let t = typeof e == "string" ? e : e.href;
147
- if (x === t) return S;
147
+ if (C === t) return w;
148
148
  let n = new URL(t, "http://dummy.com"), r;
149
- for (let e of b) if (new g(e.match, n.href).exec(n.href)) {
149
+ for (let e of S) if (new v(e.match, n.href).exec(n.href)) {
150
150
  r = e;
151
151
  break;
152
152
  }
153
- return x = t, S = r, r;
153
+ return C = t, w = r, r;
154
154
  }
155
- function w(e) {
156
- let t = C(e);
157
- return t && t.exclude !== !0 && Array.isArray(t.strategy) ? t.strategy : y;
155
+ function E(e) {
156
+ let t = T(e);
157
+ return t && t.exclude !== !0 && Array.isArray(t.strategy) ? t.strategy : x;
158
158
  }
159
159
  globalThis.__paraglide = globalThis.__paraglide ?? {}, globalThis.__paraglide.ssr = globalThis.__paraglide.ssr ?? {};
160
- var T = !1, E = () => {
161
- let e = y;
162
- typeof window < "u" && window.location?.href && (e = w(window.location.href));
163
- let t = D(e, typeof window < "u" ? window.location?.href : void 0);
164
- if (t) return T || (T = !0, A(t, { reload: !1 })), t;
160
+ var D = !1, O = () => {
161
+ let e = x;
162
+ typeof window < "u" && window.location?.href && (e = E(window.location.href));
163
+ let t = k(e, typeof window < "u" ? window.location?.href : void 0);
164
+ if (t) return D || (D = !0, j(t, { reload: !1 })), t;
165
165
  throw Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
166
166
  };
167
- function D(e, t) {
167
+ function k(e, t) {
168
168
  let n;
169
169
  for (let t of e) {
170
170
  if (t === "baseLocale") n = "en";
171
- else if (F(t) && P.has(t)) {
172
- let e = P.get(t);
171
+ else if (I(t) && F.has(t)) {
172
+ let e = F.get(t);
173
173
  if (e) {
174
174
  let t = e.getLocale();
175
175
  if (t instanceof Promise) continue;
176
- if (t !== void 0) return M(t);
176
+ if (t !== void 0) return N(t);
177
177
  }
178
178
  }
179
- let e = j(n);
179
+ let e = M(n);
180
180
  if (e) return e;
181
181
  }
182
182
  }
183
- var O = (e) => {
184
- E = e;
185
- }, k = (e) => {
183
+ var A = (e) => {
186
184
  e ? window.location.href = e : window.location.reload();
187
- }, A = (e, t) => {
185
+ }, j = (e, t) => {
188
186
  let n = {
189
187
  reload: !0,
190
188
  ...t
191
189
  }, r;
192
190
  try {
193
- r = E();
191
+ r = O();
194
192
  } catch {}
195
- let i = [], a = y;
196
- typeof window < "u" && window.location?.href && (a = w(window.location.href));
193
+ let i = [], a = x;
194
+ typeof window < "u" && window.location?.href && (a = E(window.location.href));
197
195
  for (let t of a) if (t === "baseLocale") continue;
198
- else if (F(t) && P.has(t)) {
199
- let n = P.get(t);
196
+ else if (I(t) && F.has(t)) {
197
+ let n = F.get(t);
200
198
  if (n) {
201
199
  let r = n.setLocale(e);
202
200
  r instanceof Promise && (r = r.catch((e) => {
@@ -205,65 +203,61 @@ var O = (e) => {
205
203
  }
206
204
  }
207
205
  let o = () => {
208
- n.reload && window.location && e !== r && k(void 0);
206
+ n.reload && window.location && e !== r && A(void 0);
209
207
  };
210
208
  if (i.length) return Promise.all(i).then(() => {
211
209
  o();
212
210
  });
213
211
  o();
214
212
  };
215
- function j(e) {
213
+ function M(e) {
216
214
  if (typeof e != "string") return;
217
215
  let t = e.toLowerCase();
218
- for (let e of _) if (e.toLowerCase() === t) return e;
216
+ for (let e of y) if (e.toLowerCase() === t) return e;
219
217
  }
220
- function M(e) {
221
- let t = j(e);
218
+ function N(e) {
219
+ let t = M(e);
222
220
  if (t) return t;
223
- throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(", ")}`);
221
+ throw Error(`Invalid locale: ${e}. Expected one of: ${y.join(", ")}`);
224
222
  }
225
- var N = v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
226
- RegExp(`(?:^|;\\s*)${N}=([^;]*)`);
227
- var P = /* @__PURE__ */ new Map();
228
- function F(e) {
223
+ var P = b.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
224
+ RegExp(`(?:^|;\\s*)${P}=([^;]*)`);
225
+ var F = /* @__PURE__ */ new Map();
226
+ function I(e) {
229
227
  return typeof e == "string" && /^custom-[A-Za-z0-9_-]+$/.test(e);
230
228
  }
231
229
  //#endregion
232
230
  //#region src/paraglide/messages/dialog_end_title.js
233
- 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";
234
- O(() => Q);
235
- function ne() {
236
- return Q;
237
- }
231
+ var L = () => "End Chat", R = () => "إنهاء المحادثة", z = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? L(e) : R(e)), B = () => "Are you sure you want to end this chat?", V = () => "هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟", H = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? B(e) : V(e)), U = () => "End Chat", W = () => "إنهاء المحادثة", G = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? U(e) : W(e)), K = () => "Cancel", q = () => "إلغاء", J = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? K(e) : q(e)), Y = () => "Close", X = () => "إغلاق", Z = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? Y(e) : X(e)), Q = new Set(y);
238
232
  function $(e) {
239
- Q = e && Z.has(e) ? e : "en";
233
+ return e && Q.has(e) ? e : "en";
240
234
  }
241
- function re(e) {
235
+ function ee(e) {
242
236
  return e === "ar" ? "rtl" : "ltr";
243
237
  }
244
238
  //#endregion
245
239
  //#region src/ZiilaWidget.ts
246
- function ie() {
240
+ function te(e) {
247
241
  return {
248
- title: R(),
249
- message: V(),
250
- confirmLabel: W(),
251
- cancelLabel: q(),
252
- closeLabel: X(),
253
- dir: re(ne())
242
+ title: z({}, { locale: e }),
243
+ message: H({}, { locale: e }),
244
+ confirmLabel: G({}, { locale: e }),
245
+ cancelLabel: J({}, { locale: e }),
246
+ closeLabel: Z({}, { locale: e }),
247
+ dir: ee(e)
254
248
  };
255
249
  }
256
- var ae = class {
250
+ var ne = class {
257
251
  get isDirty() {
258
252
  return this._isDirty;
259
253
  }
260
254
  constructor(e) {
261
- this.bridge = null, this.bus = new t(), this.confirmDialog = new u(), this.resolvedTheme = {}, this._isDirty = !1, this.handleBeforeUnload = (e) => {
255
+ this.bridge = null, this.bus = new t(), this.confirmDialog = new f(), this.resolvedTheme = {}, this._isDirty = !1, this.handleBeforeUnload = (e) => {
262
256
  this._isDirty && (e.preventDefault(), e.returnValue = "");
263
257
  }, this.handleMessage = (e) => {
264
258
  let t = e.data;
265
- 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);
266
- }, this.config = e, $(e.locale);
259
+ 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, t.locale);
260
+ }, this.config = e;
267
261
  }
268
262
  mount() {
269
263
  if (this.bridge) return;
@@ -271,7 +265,7 @@ var ae = class {
271
265
  if (!t) throw Error(`Ziila: container not found: ${this.config.container}`);
272
266
  this.bridge = new e((e) => {
273
267
  e.onmessage = this.handleMessage;
274
- let { container: t, ...n } = this.config, r = h(this.config.theme);
268
+ let { container: t, ...n } = this.config, r = _(this.config.theme);
275
269
  this.resolvedTheme = r, this.bridge?.send({
276
270
  type: "INIT",
277
271
  payload: {
@@ -281,9 +275,9 @@ var ae = class {
281
275
  });
282
276
  }, this.config.widgetUrl), this.bridge.mount(t), window.addEventListener("beforeunload", this.handleBeforeUnload);
283
277
  }
284
- handleConfirmRequest(e) {
278
+ handleConfirmRequest(e, t) {
285
279
  this.confirmDialog.show({
286
- ...ie(),
280
+ ...te($(t)),
287
281
  tokens: this.resolvedTheme.tokens
288
282
  }).then((t) => {
289
283
  this.bridge?.send({
@@ -310,7 +304,7 @@ var ae = class {
310
304
  this.config = {
311
305
  ...this.config,
312
306
  ...e
313
- }, e.locale !== void 0 && $(e.locale), "theme" in e && (this.resolvedTheme = h(this.config.theme)), this.bridge?.send({
307
+ }, "theme" in e && (this.resolvedTheme = _(this.config.theme)), this.bridge?.send({
314
308
  type: "UPDATE",
315
309
  payload: e
316
310
  });
@@ -321,8 +315,8 @@ var ae = class {
321
315
  };
322
316
  //#endregion
323
317
  //#region src/utils.ts
324
- function oe(e) {
318
+ function re(e) {
325
319
  return typeof e == "object" && !!e && typeof e.code == "string" && typeof e.message == "string";
326
320
  }
327
321
  //#endregion
328
- export { ae as ZiilaWidget, oe as isZiilaError };
322
+ export { ne as ZiilaWidget, re as isZiilaError };
@@ -1,5 +1,4 @@
1
1
  import { locales } from './paraglide/runtime';
2
2
  export type Locale = (typeof locales)[number];
3
- export declare function getSdkLocale(): Locale;
4
- export declare function setSdkLocale(value: string | undefined | null): void;
3
+ export declare function toSdkLocale(value: string | undefined | null): Locale;
5
4
  export declare function directionForLocale(locale: Locale): 'ltr' | 'rtl';
@@ -156,4 +156,5 @@ export type WidgetMessage = {
156
156
  } | {
157
157
  type: 'CONFIRM_REQUEST';
158
158
  kind: ConfirmKind;
159
+ locale: string;
159
160
  };
@@ -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.setAttribute(`allow`,`microphone; autoplay`),this.iframe.style.cssText=`display:block;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=`display:block;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;`,c=e=>`margin:0;font-size:16px;color:${e.foregroundColor??`#2d2d2d`};font-weight:500;line-height:27px;text-align:center;max-width:345px;`,ee=`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;`,ne=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;`,l=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 l=e=>{this.pendingResolve=null,this.close(),t(e)},u=e.tokens??{},d=document.createElement(`div`);d.style.cssText=n(u);let f=document.createElement(`div`);f.setAttribute(`role`,`dialog`),f.setAttribute(`aria-modal`,`true`),f.setAttribute(`aria-labelledby`,`ziila-confirm-title`),f.style.cssText=r(u),f.dir=e.dir;let p=document.createElement(`div`);p.style.cssText=i;let m=document.createElement(`button`);m.type=`button`,m.setAttribute(`aria-label`,e.closeLabel),m.textContent=`✕`,m.style.cssText=a(u),m.addEventListener(`click`,()=>l(!1)),p.appendChild(m);let h=document.createElement(`div`);h.style.cssText=o;let g=document.createElement(`h2`);g.id=`ziila-confirm-title`,g.textContent=e.title,g.style.cssText=s(u);let _=document.createElement(`p`);_.textContent=e.message,_.style.cssText=c(u);let v=document.createElement(`button`);v.type=`button`,v.textContent=e.cancelLabel,v.style.cssText=te(u),v.addEventListener(`click`,()=>l(!1));let y=document.createElement(`button`);y.type=`button`,y.textContent=e.confirmLabel,y.style.cssText=ne(u),y.addEventListener(`click`,()=>l(!0));let b=document.createElement(`div`);b.style.cssText=ee,b.append(v,y),h.append(g,_,b),f.append(p,h),d.appendChild(f);let x=[m,v,y];d.addEventListener(`keydown`,e=>{if(e.key===`Escape`){l(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(x.indexOf(document.activeElement)+(e.shiftKey?-1:1)+x.length)%x.length;x[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=d,document.body.appendChild(d),v.focus()})}close(){this.overlay?.remove(),this.overlay=null,this.previousFocus?.focus(),this.previousFocus=null}},u={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`]},d=new Set([``,`transparent`,`inherit`,`initial`,`unset`,`none`,`rgba(0, 0, 0, 0)`,`rgb(0, 0, 0)`,`depends on user agent`]);function f(e){return!!e&&!d.has(e.trim().toLowerCase())}function p(e=document){let t=e.defaultView??globalThis,n=t.getComputedStyle(e.documentElement),r=e.body?t.getComputedStyle(e.body):null,i={};r&&(f(r.fontFamily)&&(i.fontFamily=r.fontFamily),f(r.backgroundColor)&&(i.backgroundColor=r.backgroundColor),f(r.color)&&(i.foregroundColor=r.color));for(let[e,t]of Object.entries(u))for(let r of t){let t=n.getPropertyValue(r).trim();if(f(t)){i[e]=t;break}}return i}function m(e,t={}){let n={...p(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 h={},g=[`en`,`ar`],_=`PARAGLIDE_LOCALE`,v=[`baseLocale`],y=[],b,x;function S(e){if(y.length===0)return;let t=typeof e==`string`?e:e.href;if(b===t)return x;let n=new URL(t,`http://dummy.com`),r;for(let e of y)if(new h(e.match,n.href).exec(n.href)){r=e;break}return b=t,x=r,r}function C(e){let t=S(e);return t&&t.exclude!==!0&&Array.isArray(t.strategy)?t.strategy:v}globalThis.__paraglide=globalThis.__paraglide??{},globalThis.__paraglide.ssr=globalThis.__paraglide.ssr??{};var w=!1,T=()=>{let e=v;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,E(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 ie=e=>{e?window.location.href=e:window.location.reload()},E=(e,t)=>{let n={reload:!0,...t},r;try{r=T()}catch{}let i=[],a=v;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 g)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: ${g.join(`, `)}`)}var k=_.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=()=>`إلغاء`,U=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),W=()=>`Close`,G=()=>`إغلاق`,K=((e={},t={})=>(t.locale??T())===`en`?W(e):G(e)),q=new Set(g);function J(e){return e&&q.has(e)?e:`en`}function ae(e){return e===`ar`?`rtl`:`ltr`}function oe(e){return{title:P({},{locale:e}),message:L({},{locale:e}),confirmLabel:B({},{locale:e}),cancelLabel:U({},{locale:e}),closeLabel:K({},{locale:e}),dir:ae(e)}}var Y=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new l,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,t.locale)},this.config=e}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=m(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,t){this.confirmDialog.show({...oe(J(t)),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},`theme`in e&&(this.resolvedTheme=m(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,se=window.Ziila?.q??[],Z=document.currentScript,ce=Z instanceof HTMLScriptElement&&Z.src?new URL(`..`,Z.src).toString():void 0;function Q(e){X?.destroy(),X=new Y(e.widgetUrl?e:{...e,widgetUrl:ce}),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=$,se.forEach(Q)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziila/sdk",
3
- "version": "0.1.91",
3
+ "version": "0.1.95",
4
4
  "description": "Ziila Shopping Assistant SDK — embeddable widget loader and host-page bridge.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {