@ziila/sdk 0.1.40 → 0.1.58

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.
@@ -1,3 +1,3 @@
1
1
  export { ZiilaWidget } from '../src/ZiilaWidget';
2
2
  export { isZiilaError } from '../src/utils';
3
- export type { ThemeTokens, ThemeStyles, ButtonElementStyle, ButtonVariant, ButtonSize, ButtonVariantStyle, ButtonSizeStyle, InputElementStyle, ThemeElement, ZiilaConfig, WidgetInitConfig, ZiilaEvent, ZiilaCommand, EventPayloadMap, CommandPayloadMap, AddToCartPayload, ProductViewedPayload, SearchPayload, ErrorPayload, ParentMessage, WidgetMessage, HandshakeMessage, ConfirmKind, } from '../src/types';
3
+ export type { ThemeTokens, ThemeStyles, ButtonElementStyle, ButtonVariant, ButtonSize, ButtonVariantStyle, ButtonSizeStyle, InputElementStyle, ThemeElement, ZiilaConfig, WidgetInitConfig, ZiilaEvent, ZiilaCommand, EventPayloadMap, CommandPayloadMap, AddToCartPayload, RemoveFromCartPayload, CartUpdatedItem, CartUpdatedPayload, ProductViewedPayload, SearchPayload, ErrorPayload, ParentMessage, WidgetMessage, HandshakeMessage, ConfirmKind, } from '../src/types';
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=`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:system-ui,-apple-system,sans-serif;`,r=`width:100%;max-width:24rem;border-radius:12px;background:#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=`border:none;background:#f0f0f0;border-radius:12px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:#555;line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,ee=`margin:0;font-size:24px;font-weight:700;color:#195f6b;text-align:center;`,s=`margin:0;font-size:16px;color:#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=`flex:1;border:1px solid #195f6b;border-radius:8px;background:#fff;color:#195f6b;padding:16px;font-size:16px;font-weight:500;cursor:pointer;`,ne=`flex:1;border:none;border-radius:8px;background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight: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=document.createElement(`div`);u.style.cssText=n;let d=document.createElement(`div`);d.setAttribute(`role`,`dialog`),d.setAttribute(`aria-modal`,`true`),d.setAttribute(`aria-labelledby`,`ziila-confirm-title`),d.style.cssText=r,d.dir=e.dir;let f=document.createElement(`div`);f.style.cssText=i;let p=document.createElement(`button`);p.type=`button`,p.setAttribute(`aria-label`,e.closeLabel),p.textContent=`✕`,p.style.cssText=a,p.addEventListener(`click`,()=>l(!1)),f.appendChild(p);let m=document.createElement(`div`);m.style.cssText=o;let h=document.createElement(`h2`);h.id=`ziila-confirm-title`,h.textContent=e.title,h.style.cssText=ee;let g=document.createElement(`p`);g.textContent=e.message,g.style.cssText=s;let _=document.createElement(`button`);_.type=`button`,_.textContent=e.cancelLabel,_.style.cssText=te,_.addEventListener(`click`,()=>l(!1));let v=document.createElement(`button`);v.type=`button`,v.textContent=e.confirmLabel,v.style.cssText=ne,v.addEventListener(`click`,()=>l(!0));let y=document.createElement(`div`);y.style.cssText=c,y.append(_,v),m.append(h,g,y),d.append(f,m),u.appendChild(d);let b=[p,_,v];u.addEventListener(`keydown`,e=>{if(e.key===`Escape`){l(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(b.indexOf(document.activeElement)+(e.shiftKey?-1:1)+b.length)%b.length;b[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=u,document.body.appendChild(u),_.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=E(e,typeof window<`u`?window.location?.href:void 0);if(t)return w||(w=!0,k(t,{reload:!1})),t;throw Error(`No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found`)};function E(e,t){let n;for(let t of e){if(t===`baseLocale`)n=`en`;else if(P(t)&&N.has(t)){let e=N.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return j(t)}}let e=A(n);if(e)return e}}var D=e=>{T=e},O=e=>{e?window.location.href=e:window.location.reload()},k=(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(P(t)&&N.has(t)){let n=N.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&&O(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function A(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of g)if(e.toLowerCase()===t)return e}function j(e){let t=A(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${g.join(`, `)}`)}var M=_.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${M}=([^;]*)`);var N=new Map;function P(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var F=()=>`End Chat`,I=()=>`إنهاء المحادثة`,L=((e={},t={})=>(t.locale??T())===`en`?F(e):I(e)),R=()=>`Are you sure you want to end this chat?`,z=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,B=((e={},t={})=>(t.locale??T())===`en`?R(e):z(e)),V=()=>`End Chat`,H=()=>`إنهاء المحادثة`,U=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),W=()=>`Cancel`,G=()=>`إلغاء`,re=((e={},t={})=>(t.locale??T())===`en`?W(e):G(e)),K=()=>`Leave Chat`,q=()=>`مغادرة المحادثة`,J=((e={},t={})=>(t.locale??T())===`en`?K(e):q(e)),Y=()=>`If you leave now, your chat will end. Are you sure you want to leave?`,X=()=>`إذا غادرت الآن، ستنتهي محادثتك. هل أنت متأكد أنك تريد المغادرة؟`,ie=((e={},t={})=>(t.locale??T())===`en`?Y(e):X(e)),ae=()=>`Leave`,oe=()=>`مغادرة`,se=((e={},t={})=>(t.locale??T())===`en`?ae(e):oe(e)),ce=()=>`Stay`,le=()=>`البقاء`,ue=((e={},t={})=>(t.locale??T())===`en`?ce(e):le(e)),de=()=>`Close`,fe=()=>`إغلاق`,pe=((e={},t={})=>(t.locale??T())===`en`?de(e):fe(e)),me=new Set(g),Z=`en`;D(()=>Z);function Q(){return Z}function $(e){Z=e&&me.has(e)?e:`en`}function he(e){return e===`ar`?`rtl`:`ltr`}function ge(e){let t=he(Q()),n=pe();return e===`endChat`?{title:L(),message:B(),confirmLabel:U(),cancelLabel:re(),closeLabel:n,dir:t}:{title:J(),message:ie(),confirmLabel:se(),cancelLabel:ue(),closeLabel:n,dir:t}}var _e=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new l,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=m(this.config.theme);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(ge(e)).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),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 ve(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=_e,exports.isZiilaError=ve;
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;
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 = "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:system-ui,-apple-system,sans-serif;", r = "width:100%;max-width:24rem;border-radius:12px;background:#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 = "border:none;background:#f0f0f0;border-radius:12px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:#555;line-height:1;padding:0;", o = "display:flex;flex-direction:column;gap:16px;align-items:center;", ee = "margin:0;font-size:24px;font-weight:700;color:#195f6b;text-align:center;", s = "margin:0;font-size:16px;color:#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 = "flex:1;border:1px solid #195f6b;border-radius:8px;background:#fff;color:#195f6b;padding:16px;font-size:16px;font-weight:500;cursor:pointer;", ne = "flex:1;border:none;border-radius:8px;background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight:500;cursor:pointer;", l = 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;", 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 {
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 l = (e) => {
45
+ let u = (e) => {
46
46
  this.pendingResolve = null, this.close(), t(e);
47
- }, u = document.createElement("div");
48
- u.style.cssText = n;
49
- let d = document.createElement("div");
50
- d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-labelledby", "ziila-confirm-title"), d.style.cssText = r, d.dir = e.dir;
51
- let f = document.createElement("div");
52
- f.style.cssText = i;
53
- let p = document.createElement("button");
54
- p.type = "button", p.setAttribute("aria-label", e.closeLabel), p.textContent = "✕", p.style.cssText = a, p.addEventListener("click", () => l(!1)), f.appendChild(p);
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;
55
51
  let m = document.createElement("div");
56
- m.style.cssText = o;
57
- let h = document.createElement("h2");
58
- h.id = "ziila-confirm-title", h.textContent = e.title, h.style.cssText = ee;
59
- let g = document.createElement("p");
60
- g.textContent = e.message, g.style.cssText = s;
61
- let _ = document.createElement("button");
62
- _.type = "button", _.textContent = e.cancelLabel, _.style.cssText = te, _.addEventListener("click", () => l(!1));
63
- let v = document.createElement("button");
64
- v.type = "button", v.textContent = e.confirmLabel, v.style.cssText = ne, v.addEventListener("click", () => l(!0));
65
- let y = document.createElement("div");
66
- y.style.cssText = c, y.append(_, v), m.append(h, g, y), d.append(f, m), u.appendChild(d);
67
- let b = [
68
- p,
69
- _,
70
- v
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);
55
+ 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
71
71
  ];
72
- u.addEventListener("keydown", (e) => {
72
+ f.addEventListener("keydown", (e) => {
73
73
  if (e.key === "Escape") {
74
- l(!1);
74
+ u(!1);
75
75
  return;
76
76
  }
77
77
  if (e.key === "Tab") {
78
78
  e.preventDefault();
79
- let t = (b.indexOf(document.activeElement) + (e.shiftKey ? -1 : 1) + b.length) % b.length;
80
- b[t].focus();
79
+ let t = (S.indexOf(document.activeElement) + (e.shiftKey ? -1 : 1) + S.length) % S.length;
80
+ S[t].focus();
81
81
  }
82
- }), this.previousFocus = document.activeElement, this.overlay = u, document.body.appendChild(u), _.focus();
82
+ }), this.previousFocus = document.activeElement, this.overlay = f, document.body.appendChild(f), y.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
- }, u = {
88
+ }, d = {
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
- }, d = /* @__PURE__ */ new Set([
106
+ }, f = /* @__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 f(e) {
118
- return !!e && !d.has(e.trim().toLowerCase());
117
+ function p(e) {
118
+ return !!e && !f.has(e.trim().toLowerCase());
119
119
  }
120
- function p(e = document) {
120
+ function m(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 && (f(r.fontFamily) && (i.fontFamily = r.fontFamily), f(r.backgroundColor) && (i.backgroundColor = r.backgroundColor), f(r.color) && (i.foregroundColor = r.color));
123
- for (let [e, t] of Object.entries(u)) for (let r of t) {
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) {
124
124
  let t = n.getPropertyValue(r).trim();
125
- if (f(t)) {
125
+ if (p(t)) {
126
126
  i[e] = t;
127
127
  break;
128
128
  }
@@ -131,72 +131,72 @@ function p(e = document) {
131
131
  }
132
132
  //#endregion
133
133
  //#region src/themeStyles.ts
134
- function m(e, t = {}) {
134
+ function h(e, t = {}) {
135
135
  let n = {
136
- ...p(t.doc ?? document),
136
+ ...m(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 h = {}, g = ["en", "ar"], _ = "PARAGLIDE_LOCALE", v = ["baseLocale"], y = [], b, x;
144
- function S(e) {
145
- if (y.length === 0) return;
143
+ var g = {}, _ = ["en", "ar"], v = "PARAGLIDE_LOCALE", y = ["baseLocale"], b = [], x, S;
144
+ function C(e) {
145
+ if (b.length === 0) return;
146
146
  let t = typeof e == "string" ? e : e.href;
147
- if (b === t) return x;
147
+ if (x === t) return S;
148
148
  let n = new URL(t, "http://dummy.com"), r;
149
- for (let e of y) if (new h(e.match, n.href).exec(n.href)) {
149
+ for (let e of b) if (new g(e.match, n.href).exec(n.href)) {
150
150
  r = e;
151
151
  break;
152
152
  }
153
- return b = t, x = r, r;
153
+ return x = t, S = r, r;
154
154
  }
155
- function C(e) {
156
- let t = S(e);
157
- return t && t.exclude !== !0 && Array.isArray(t.strategy) ? t.strategy : v;
155
+ function w(e) {
156
+ let t = C(e);
157
+ return t && t.exclude !== !0 && Array.isArray(t.strategy) ? t.strategy : y;
158
158
  }
159
159
  globalThis.__paraglide = globalThis.__paraglide ?? {}, globalThis.__paraglide.ssr = globalThis.__paraglide.ssr ?? {};
160
- var w = !1, T = () => {
161
- let e = v;
162
- typeof window < "u" && window.location?.href && (e = C(window.location.href));
163
- let t = E(e, typeof window < "u" ? window.location?.href : void 0);
164
- if (t) return w || (w = !0, k(t, { reload: !1 })), t;
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;
165
165
  throw Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
166
166
  };
167
- function E(e, t) {
167
+ function D(e, t) {
168
168
  let n;
169
169
  for (let t of e) {
170
170
  if (t === "baseLocale") n = "en";
171
- else if (P(t) && N.has(t)) {
172
- let e = N.get(t);
171
+ else if (F(t) && P.has(t)) {
172
+ let e = P.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 j(t);
176
+ if (t !== void 0) return M(t);
177
177
  }
178
178
  }
179
- let e = A(n);
179
+ let e = j(n);
180
180
  if (e) return e;
181
181
  }
182
182
  }
183
- var D = (e) => {
184
- T = e;
185
- }, O = (e) => {
183
+ var O = (e) => {
184
+ E = e;
185
+ }, k = (e) => {
186
186
  e ? window.location.href = e : window.location.reload();
187
- }, k = (e, t) => {
187
+ }, A = (e, t) => {
188
188
  let n = {
189
189
  reload: !0,
190
190
  ...t
191
191
  }, r;
192
192
  try {
193
- r = T();
193
+ r = E();
194
194
  } catch {}
195
- let i = [], a = v;
196
- typeof window < "u" && window.location?.href && (a = C(window.location.href));
195
+ let i = [], a = y;
196
+ typeof window < "u" && window.location?.href && (a = w(window.location.href));
197
197
  for (let t of a) if (t === "baseLocale") continue;
198
- else if (P(t) && N.has(t)) {
199
- let n = N.get(t);
198
+ else if (F(t) && P.has(t)) {
199
+ let n = P.get(t);
200
200
  if (n) {
201
201
  let r = n.setLocale(e);
202
202
  r instanceof Promise && (r = r.catch((e) => {
@@ -205,68 +205,60 @@ var D = (e) => {
205
205
  }
206
206
  }
207
207
  let o = () => {
208
- n.reload && window.location && e !== r && O(void 0);
208
+ n.reload && window.location && e !== r && k(void 0);
209
209
  };
210
210
  if (i.length) return Promise.all(i).then(() => {
211
211
  o();
212
212
  });
213
213
  o();
214
214
  };
215
- function A(e) {
215
+ function j(e) {
216
216
  if (typeof e != "string") return;
217
217
  let t = e.toLowerCase();
218
- for (let e of g) if (e.toLowerCase() === t) return e;
218
+ for (let e of _) if (e.toLowerCase() === t) return e;
219
219
  }
220
- function j(e) {
221
- let t = A(e);
220
+ function M(e) {
221
+ let t = j(e);
222
222
  if (t) return t;
223
- throw Error(`Invalid locale: ${e}. Expected one of: ${g.join(", ")}`);
223
+ throw Error(`Invalid locale: ${e}. Expected one of: ${_.join(", ")}`);
224
224
  }
225
- var M = _.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
226
- RegExp(`(?:^|;\\s*)${M}=([^;]*)`);
227
- var N = /* @__PURE__ */ new Map();
228
- function P(e) {
225
+ var N = v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
226
+ RegExp(`(?:^|;\\s*)${N}=([^;]*)`);
227
+ var P = /* @__PURE__ */ new Map();
228
+ function F(e) {
229
229
  return typeof e == "string" && /^custom-[A-Za-z0-9_-]+$/.test(e);
230
230
  }
231
231
  //#endregion
232
232
  //#region src/paraglide/messages/dialog_end_title.js
233
- var F = () => "End Chat", I = () => "إنهاء المحادثة", L = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? F(e) : I(e)), R = () => "Are you sure you want to end this chat?", z = () => "هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟", B = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? R(e) : z(e)), V = () => "End Chat", H = () => "إنهاء المحادثة", U = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? V(e) : H(e)), W = () => "Cancel", G = () => "إلغاء", re = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? W(e) : G(e)), K = () => "Leave Chat", q = () => "مغادرة المحادثة", J = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? K(e) : q(e)), Y = () => "If you leave now, your chat will end. Are you sure you want to leave?", X = () => "إذا غادرت الآن، ستنتهي محادثتك. هل أنت متأكد أنك تريد المغادرة؟", ie = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? Y(e) : X(e)), ae = () => "Leave", oe = () => "مغادرة", se = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? ae(e) : oe(e)), ce = () => "Stay", le = () => "البقاء", ue = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? ce(e) : le(e)), de = () => "Close", fe = () => "إغلاق", pe = ((e = {}, t = {}) => (t.locale ?? T()) === "en" ? de(e) : fe(e)), me = new Set(g), Z = "en";
234
- D(() => Z);
235
- function Q() {
236
- return Z;
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
237
  }
238
238
  function $(e) {
239
- Z = e && me.has(e) ? e : "en";
239
+ Q = e && Z.has(e) ? e : "en";
240
240
  }
241
- function he(e) {
241
+ function re(e) {
242
242
  return e === "ar" ? "rtl" : "ltr";
243
243
  }
244
244
  //#endregion
245
245
  //#region src/ZiilaWidget.ts
246
- function ge(e) {
247
- let t = he(Q()), n = pe();
248
- return e === "endChat" ? {
249
- title: L(),
250
- message: B(),
251
- confirmLabel: U(),
252
- cancelLabel: re(),
253
- closeLabel: n,
254
- dir: t
255
- } : {
256
- title: J(),
257
- message: ie(),
258
- confirmLabel: se(),
259
- cancelLabel: ue(),
260
- closeLabel: n,
261
- dir: t
246
+ function ie() {
247
+ return {
248
+ title: R(),
249
+ message: V(),
250
+ confirmLabel: W(),
251
+ cancelLabel: q(),
252
+ closeLabel: X(),
253
+ dir: re(ne())
262
254
  };
263
255
  }
264
- var _e = class {
256
+ var ae = class {
265
257
  get isDirty() {
266
258
  return this._isDirty;
267
259
  }
268
260
  constructor(e) {
269
- this.bridge = null, this.bus = new t(), this.confirmDialog = new l(), this._isDirty = !1, this.handleBeforeUnload = (e) => {
261
+ this.bridge = null, this.bus = new t(), this.confirmDialog = new u(), this.resolvedTheme = {}, this._isDirty = !1, this.handleBeforeUnload = (e) => {
270
262
  this._isDirty && (e.preventDefault(), e.returnValue = "");
271
263
  }, this.handleMessage = (e) => {
272
264
  let t = e.data;
@@ -279,8 +271,8 @@ var _e = class {
279
271
  if (!t) throw Error(`Ziila: container not found: ${this.config.container}`);
280
272
  this.bridge = new e((e) => {
281
273
  e.onmessage = this.handleMessage;
282
- let { container: t, ...n } = this.config, r = m(this.config.theme);
283
- this.bridge?.send({
274
+ let { container: t, ...n } = this.config, r = h(this.config.theme);
275
+ this.resolvedTheme = r, this.bridge?.send({
284
276
  type: "INIT",
285
277
  payload: {
286
278
  ...n,
@@ -290,7 +282,10 @@ var _e = class {
290
282
  }, this.config.widgetUrl), this.bridge.mount(t), window.addEventListener("beforeunload", this.handleBeforeUnload);
291
283
  }
292
284
  handleConfirmRequest(e) {
293
- this.confirmDialog.show(ge(e)).then((t) => {
285
+ this.confirmDialog.show({
286
+ ...ie(),
287
+ tokens: this.resolvedTheme.tokens
288
+ }).then((t) => {
294
289
  this.bridge?.send({
295
290
  type: "CONFIRM_RESULT",
296
291
  kind: e,
@@ -315,7 +310,7 @@ var _e = class {
315
310
  this.config = {
316
311
  ...this.config,
317
312
  ...e
318
- }, e.locale !== void 0 && $(e.locale), this.bridge?.send({
313
+ }, e.locale !== void 0 && $(e.locale), "theme" in e && (this.resolvedTheme = h(this.config.theme)), this.bridge?.send({
319
314
  type: "UPDATE",
320
315
  payload: e
321
316
  });
@@ -326,8 +321,8 @@ var _e = class {
326
321
  };
327
322
  //#endregion
328
323
  //#region src/utils.ts
329
- function ve(e) {
324
+ function oe(e) {
330
325
  return typeof e == "object" && !!e && typeof e.code == "string" && typeof e.message == "string";
331
326
  }
332
327
  //#endregion
333
- export { _e as ZiilaWidget, ve as isZiilaError };
328
+ export { ae as ZiilaWidget, oe as isZiilaError };
@@ -1,3 +1,4 @@
1
+ import { ThemeTokens } from './types';
1
2
  export interface ConfirmDialogOptions {
2
3
  title: string;
3
4
  message: string;
@@ -5,6 +6,9 @@ export interface ConfirmDialogOptions {
5
6
  cancelLabel: string;
6
7
  closeLabel: string;
7
8
  dir: 'ltr' | 'rtl';
9
+ /** Resolved theme tokens (config + host-page sniff); each style falls back
10
+ * to the dialog's built-in default when a token is absent. */
11
+ tokens?: Partial<ThemeTokens>;
8
12
  }
9
13
  export declare class ConfirmDialog {
10
14
  private overlay;
@@ -4,6 +4,7 @@ export declare class ZiilaWidget {
4
4
  private bridge;
5
5
  private readonly bus;
6
6
  private readonly confirmDialog;
7
+ private resolvedTheme;
7
8
  private _isDirty;
8
9
  get isDirty(): boolean;
9
10
  constructor(config: ZiilaConfig);
@@ -14,6 +15,6 @@ export declare class ZiilaWidget {
14
15
  on<K extends ZiilaEvent>(event: K, handler: (data: EventPayloadMap[K]) => void): () => void;
15
16
  off<K extends ZiilaEvent>(event: K, handler: (data: EventPayloadMap[K]) => void): void;
16
17
  emit<K extends ZiilaCommand>(command: K, payload?: CommandPayloadMap[K]): void;
17
- update(updates: Partial<Pick<ZiilaConfig, 'locale' | 'theme'>>): void;
18
+ update(updates: Partial<Pick<ZiilaConfig, 'locale' | 'theme' | 'cartId'>>): void;
18
19
  destroy(): void;
19
20
  }
@@ -67,16 +67,40 @@ export interface ThemeStyles {
67
67
  export interface ZiilaConfig {
68
68
  apiKey: string;
69
69
  agentId: string;
70
+ /** Merchant cart id — required; all cart mutations target this cart. */
71
+ cartId: string;
70
72
  container: string | HTMLElement;
71
73
  locale?: string;
72
74
  widgetTitle?: string;
73
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;
74
82
  widgetUrl?: string;
75
83
  }
76
84
  export interface AddToCartPayload {
77
85
  sku: string;
86
+ /** The sku's new total quantity in the cart — never a delta. */
78
87
  quantity: number;
79
88
  }
89
+ export interface RemoveFromCartPayload {
90
+ sku: string;
91
+ /** The sku's new total quantity; 0 means fully removed. */
92
+ quantity: number;
93
+ }
94
+ export interface CartUpdatedItem {
95
+ sku: string;
96
+ quantity: number;
97
+ price: number;
98
+ }
99
+ export interface CartUpdatedPayload {
100
+ items: CartUpdatedItem[];
101
+ totalItems: number;
102
+ grandTotal: number;
103
+ }
80
104
  export interface ProductViewedPayload {
81
105
  sku: string;
82
106
  }
@@ -87,11 +111,13 @@ export interface ErrorPayload {
87
111
  code: string;
88
112
  message: string;
89
113
  }
90
- export type ZiilaEvent = 'ready' | 'addToCart' | 'productViewed' | 'search' | 'error';
114
+ export type ZiilaEvent = 'ready' | 'addToCart' | 'removeFromCart' | 'cartUpdated' | 'productViewed' | 'search' | 'error';
91
115
  export type ZiilaCommand = 'clear';
92
116
  export interface EventPayloadMap {
93
117
  ready: undefined;
94
118
  addToCart: AddToCartPayload;
119
+ removeFromCart: RemoveFromCartPayload;
120
+ cartUpdated: CartUpdatedPayload;
95
121
  productViewed: ProductViewedPayload;
96
122
  search: SearchPayload;
97
123
  error: ErrorPayload;
@@ -99,7 +125,7 @@ export interface EventPayloadMap {
99
125
  export interface CommandPayloadMap {
100
126
  clear: undefined;
101
127
  }
102
- export type ConfirmKind = 'endChat' | 'leaveChat';
128
+ export type ConfirmKind = 'endChat';
103
129
  export type HandshakeMessage = {
104
130
  type: 'HANDSHAKE';
105
131
  } | {
@@ -115,7 +141,7 @@ export type ParentMessage = {
115
141
  payload?: unknown;
116
142
  } | {
117
143
  type: 'UPDATE';
118
- payload: Partial<Pick<ZiilaConfig, 'locale' | 'theme'>>;
144
+ payload: Partial<Pick<ZiilaConfig, 'locale' | 'theme' | 'cartId'>>;
119
145
  } | {
120
146
  type: 'THEME_UPDATE';
121
147
  payload: Partial<ThemeTokens>;
@@ -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=`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:system-ui,-apple-system,sans-serif;`,r=`width:100%;max-width:24rem;border-radius:12px;background:#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=`border:none;background:#f0f0f0;border-radius:12px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:14px;color:#555;line-height:1;padding:0;`,o=`display:flex;flex-direction:column;gap:16px;align-items:center;`,ee=`margin:0;font-size:24px;font-weight:700;color:#195f6b;text-align:center;`,s=`margin:0;font-size:16px;color:#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=`flex:1;border:1px solid #195f6b;border-radius:8px;background:#fff;color:#195f6b;padding:16px;font-size:16px;font-weight:500;cursor:pointer;`,ne=`flex:1;border:none;border-radius:8px;background:#cc0000;color:#fff;padding:16px;font-size:16px;font-weight: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=document.createElement(`div`);u.style.cssText=n;let d=document.createElement(`div`);d.setAttribute(`role`,`dialog`),d.setAttribute(`aria-modal`,`true`),d.setAttribute(`aria-labelledby`,`ziila-confirm-title`),d.style.cssText=r,d.dir=e.dir;let f=document.createElement(`div`);f.style.cssText=i;let p=document.createElement(`button`);p.type=`button`,p.setAttribute(`aria-label`,e.closeLabel),p.textContent=`✕`,p.style.cssText=a,p.addEventListener(`click`,()=>l(!1)),f.appendChild(p);let m=document.createElement(`div`);m.style.cssText=o;let h=document.createElement(`h2`);h.id=`ziila-confirm-title`,h.textContent=e.title,h.style.cssText=ee;let g=document.createElement(`p`);g.textContent=e.message,g.style.cssText=s;let _=document.createElement(`button`);_.type=`button`,_.textContent=e.cancelLabel,_.style.cssText=te,_.addEventListener(`click`,()=>l(!1));let v=document.createElement(`button`);v.type=`button`,v.textContent=e.confirmLabel,v.style.cssText=ne,v.addEventListener(`click`,()=>l(!0));let y=document.createElement(`div`);y.style.cssText=c,y.append(_,v),m.append(h,g,y),d.append(f,m),u.appendChild(d);let b=[p,_,v];u.addEventListener(`keydown`,e=>{if(e.key===`Escape`){l(!1);return}if(e.key===`Tab`){e.preventDefault();let t=(b.indexOf(document.activeElement)+(e.shiftKey?-1:1)+b.length)%b.length;b[t].focus()}}),this.previousFocus=document.activeElement,this.overlay=u,document.body.appendChild(u),_.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,oe(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(A(t)&&k.has(t)){let e=k.get(t);if(e){let t=e.getLocale();if(t instanceof Promise)continue;if(t!==void 0)return D(t)}}let e=E(n);if(e)return e}}var ie=e=>{T=e},ae=e=>{e?window.location.href=e:window.location.reload()},oe=(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(A(t)&&k.has(t)){let n=k.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&&ae(void 0)};if(i.length)return Promise.all(i).then(()=>{o()});o()};function E(e){if(typeof e!=`string`)return;let t=e.toLowerCase();for(let e of g)if(e.toLowerCase()===t)return e}function D(e){let t=E(e);if(t)return t;throw Error(`Invalid locale: ${e}. Expected one of: ${g.join(`, `)}`)}var O=_.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:^|;\\s*)${O}=([^;]*)`);var k=new Map;function A(e){return typeof e==`string`&&/^custom-[A-Za-z0-9_-]+$/.test(e)}var j=()=>`End Chat`,M=()=>`إنهاء المحادثة`,N=((e={},t={})=>(t.locale??T())===`en`?j(e):M(e)),P=()=>`Are you sure you want to end this chat?`,F=()=>`هل أنت متأكد أنك تريد إنهاء هذه المحادثة؟`,I=((e={},t={})=>(t.locale??T())===`en`?P(e):F(e)),L=()=>`End Chat`,R=()=>`إنهاء المحادثة`,z=((e={},t={})=>(t.locale??T())===`en`?L(e):R(e)),B=()=>`Cancel`,V=()=>`إلغاء`,H=((e={},t={})=>(t.locale??T())===`en`?B(e):V(e)),U=()=>`Leave Chat`,W=()=>`مغادرة المحادثة`,G=((e={},t={})=>(t.locale??T())===`en`?U(e):W(e)),se=()=>`If you leave now, your chat will end. Are you sure you want to leave?`,K=()=>`إذا غادرت الآن، ستنتهي محادثتك. هل أنت متأكد أنك تريد المغادرة؟`,ce=((e={},t={})=>(t.locale??T())===`en`?se(e):K(e)),le=()=>`Leave`,ue=()=>`مغادرة`,de=((e={},t={})=>(t.locale??T())===`en`?le(e):ue(e)),fe=()=>`Stay`,pe=()=>`البقاء`,me=((e={},t={})=>(t.locale??T())===`en`?fe(e):pe(e)),he=()=>`Close`,ge=()=>`إغلاق`,_e=((e={},t={})=>(t.locale??T())===`en`?he(e):ge(e)),ve=new Set(g),q=`en`;ie(()=>q);function J(){return q}function Y(e){q=e&&ve.has(e)?e:`en`}function ye(e){return e===`ar`?`rtl`:`ltr`}function be(e){let t=ye(J()),n=_e();return e===`endChat`?{title:N(),message:I(),confirmLabel:z(),cancelLabel:H(),closeLabel:n,dir:t}:{title:G(),message:ce(),confirmLabel:de(),cancelLabel:me(),closeLabel:n,dir:t}}var xe=class{get isDirty(){return this._isDirty}constructor(e){this.bridge=null,this.bus=new t,this.confirmDialog=new l,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=m(this.config.theme);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(be(e)).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),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 xe(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)})();
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)})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziila/sdk",
3
- "version": "0.1.40",
3
+ "version": "0.1.58",
4
4
  "description": "Ziila Shopping Assistant SDK — embeddable widget loader and host-page bridge.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "scripts": {
25
25
  "build": "vite build --config vite.lib.config.ts && vite build --config vite.embed.config.ts",
26
26
  "dev": "vite build --config vite.lib.config.ts --watch --mode development",
27
- "test": "vitest run",
27
+ "test": "vitest run --coverage",
28
28
  "test:watch": "vitest",
29
29
  "typecheck": "tsc --noEmit",
30
30
  "compile:i18n": "paraglide-js compile --project ../../project.inlang --outdir ./src/paraglide"
@@ -32,6 +32,7 @@
32
32
  "devDependencies": {
33
33
  "@inlang/paraglide-js": "^2.18.2",
34
34
  "@types/node": "^24.0.0",
35
+ "@vitest/coverage-v8": "4.1.8",
35
36
  "jsdom": "^29.0.0",
36
37
  "typescript": "^6.0.0",
37
38
  "vite": "^8.0.0",