@ziila/sdk 0.1.228 → 0.1.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +47 -21
- package/dist/src/ConfirmDialog.d.ts +6 -0
- package/dist/src/ZiilaWidget.d.ts +2 -0
- package/dist/src/types.d.ts +2 -1
- package/dist/widget.iife.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.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;
|
|
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,t)=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:${t===`primary`?e.primaryColor??`#195f6b`:`#cc0000`};color:${t===`primary`?e.primaryFg??`#fff`:`#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,e.tone??`destructive`),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=()=>`Go to Checkout`,ee=()=>`الذهاب للدفع`,q=((e={},t={})=>(t.locale??O())===`en`?K(e):ee(e)),J=()=>`You will leave this chat and continue to the store's checkout page.`,Y=()=>`سوف تغادر هذه المحادثة وتنتقل إلى صفحة الدفع في المتجر.`,X=((e={},t={})=>(t.locale??O())===`en`?J(e):Y(e)),Z=()=>`Continue`,Q=()=>`متابعة`,$=((e={},t={})=>(t.locale??O())===`en`?Z(e):Q(e)),te=()=>`Cancel`,ne=()=>`إلغاء`,re=((e={},t={})=>(t.locale??O())===`en`?te(e):ne(e)),ie=()=>`Close`,ae=()=>`إغلاق`,oe=((e={},t={})=>(t.locale??O())===`en`?ie(e):ae(e)),se=new Set(y);function ce(e){return e&&se.has(e)?e:`en`}function le(e){return e===`ar`?`rtl`:`ltr`}function ue(e,t){let n={cancelLabel:re({},{locale:t}),closeLabel:oe({},{locale:t}),dir:le(t)};switch(e){case`checkout`:return{...n,title:q({},{locale:t}),message:X({},{locale:t}),confirmLabel:$({},{locale:t}),tone:`primary`};case`endChat`:return{...n,title:z({},{locale:t}),message:H({},{locale:t}),confirmLabel:G({},{locale:t}),tone:`destructive`}}}function de(e){let t;try{t=new URL(e,window.location.href)}catch{return null}return t.protocol!==`https:`&&t.protocol!==`http:`?null:t.href}var fe=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,t.url)},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,n){this.confirmDialog.show({...ue(e,ce(t)),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t}),t&&e===`checkout`&&n&&this.navigateToCheckout(n)})}navigateToCheckout(e){let t=de(e);t&&window.location.assign(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 pe(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=fe,exports.isZiilaError=pe;
|
package/dist/index.esm.js
CHANGED
|
@@ -35,7 +35,7 @@ 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;", 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
|
|
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, t) => `flex:1;border:none;border-radius:${e.buttonRadius ?? "8px"};background:${t === "primary" ? e.primaryColor ?? "#195f6b" : "#cc0000"};color:${t === "primary" ? e.primaryFg ?? "#fff" : "#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
|
}
|
|
@@ -61,7 +61,7 @@ var e = class {
|
|
|
61
61
|
let x = document.createElement("button");
|
|
62
62
|
x.type = "button", x.textContent = e.cancelLabel, x.style.cssText = u(p), x.addEventListener("click", () => f(!1));
|
|
63
63
|
let S = document.createElement("button");
|
|
64
|
-
S.type = "button", S.textContent = e.confirmLabel, S.style.cssText = d(p), S.addEventListener("click", () => f(!0));
|
|
64
|
+
S.type = "button", S.textContent = e.confirmLabel, S.style.cssText = d(p, e.tone ?? "destructive"), S.addEventListener("click", () => f(!0));
|
|
65
65
|
let C = document.createElement("div");
|
|
66
66
|
C.style.cssText = l, C.append(x, S), v.append(y, b, C), h.append(g, v), m.appendChild(h);
|
|
67
67
|
let w = [
|
|
@@ -228,26 +228,48 @@ function I(e) {
|
|
|
228
228
|
}
|
|
229
229
|
//#endregion
|
|
230
230
|
//#region src/paraglide/messages/dialog_end_title.js
|
|
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 = () => "
|
|
232
|
-
function
|
|
233
|
-
return e &&
|
|
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 = () => "Go to Checkout", ee = () => "الذهاب للدفع", q = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? K(e) : ee(e)), J = () => "You will leave this chat and continue to the store's checkout page.", Y = () => "سوف تغادر هذه المحادثة وتنتقل إلى صفحة الدفع في المتجر.", X = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? J(e) : Y(e)), Z = () => "Continue", Q = () => "متابعة", $ = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? Z(e) : Q(e)), te = () => "Cancel", ne = () => "إلغاء", re = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? te(e) : ne(e)), ie = () => "Close", ae = () => "إغلاق", oe = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? ie(e) : ae(e)), se = new Set(y);
|
|
232
|
+
function ce(e) {
|
|
233
|
+
return e && se.has(e) ? e : "en";
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function le(e) {
|
|
236
236
|
return e === "ar" ? "rtl" : "ltr";
|
|
237
237
|
}
|
|
238
238
|
//#endregion
|
|
239
239
|
//#region src/ZiilaWidget.ts
|
|
240
|
-
function
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
cancelLabel: J({}, { locale: e }),
|
|
246
|
-
closeLabel: Z({}, { locale: e }),
|
|
247
|
-
dir: ee(e)
|
|
240
|
+
function ue(e, t) {
|
|
241
|
+
let n = {
|
|
242
|
+
cancelLabel: re({}, { locale: t }),
|
|
243
|
+
closeLabel: oe({}, { locale: t }),
|
|
244
|
+
dir: le(t)
|
|
248
245
|
};
|
|
246
|
+
switch (e) {
|
|
247
|
+
case "checkout": return {
|
|
248
|
+
...n,
|
|
249
|
+
title: q({}, { locale: t }),
|
|
250
|
+
message: X({}, { locale: t }),
|
|
251
|
+
confirmLabel: $({}, { locale: t }),
|
|
252
|
+
tone: "primary"
|
|
253
|
+
};
|
|
254
|
+
case "endChat": return {
|
|
255
|
+
...n,
|
|
256
|
+
title: z({}, { locale: t }),
|
|
257
|
+
message: H({}, { locale: t }),
|
|
258
|
+
confirmLabel: G({}, { locale: t }),
|
|
259
|
+
tone: "destructive"
|
|
260
|
+
};
|
|
261
|
+
}
|
|
249
262
|
}
|
|
250
|
-
|
|
263
|
+
function de(e) {
|
|
264
|
+
let t;
|
|
265
|
+
try {
|
|
266
|
+
t = new URL(e, window.location.href);
|
|
267
|
+
} catch {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
return t.protocol !== "https:" && t.protocol !== "http:" ? null : t.href;
|
|
271
|
+
}
|
|
272
|
+
var fe = class {
|
|
251
273
|
get isDirty() {
|
|
252
274
|
return this._isDirty;
|
|
253
275
|
}
|
|
@@ -256,7 +278,7 @@ var ne = class {
|
|
|
256
278
|
this._isDirty && (e.preventDefault(), e.returnValue = "");
|
|
257
279
|
}, this.handleMessage = (e) => {
|
|
258
280
|
let t = e.data;
|
|
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);
|
|
281
|
+
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, t.url);
|
|
260
282
|
}, this.config = e;
|
|
261
283
|
}
|
|
262
284
|
mount() {
|
|
@@ -275,18 +297,22 @@ var ne = class {
|
|
|
275
297
|
});
|
|
276
298
|
}, this.config.widgetUrl), this.bridge.mount(t), window.addEventListener("beforeunload", this.handleBeforeUnload);
|
|
277
299
|
}
|
|
278
|
-
handleConfirmRequest(e, t) {
|
|
300
|
+
handleConfirmRequest(e, t, n) {
|
|
279
301
|
this.confirmDialog.show({
|
|
280
|
-
...
|
|
302
|
+
...ue(e, ce(t)),
|
|
281
303
|
tokens: this.resolvedTheme.tokens
|
|
282
304
|
}).then((t) => {
|
|
283
305
|
this.bridge?.send({
|
|
284
306
|
type: "CONFIRM_RESULT",
|
|
285
307
|
kind: e,
|
|
286
308
|
confirmed: t
|
|
287
|
-
});
|
|
309
|
+
}), t && e === "checkout" && n && this.navigateToCheckout(n);
|
|
288
310
|
});
|
|
289
311
|
}
|
|
312
|
+
navigateToCheckout(e) {
|
|
313
|
+
let t = de(e);
|
|
314
|
+
t && window.location.assign(t);
|
|
315
|
+
}
|
|
290
316
|
on(e, t) {
|
|
291
317
|
return this.bus.on(e, t);
|
|
292
318
|
}
|
|
@@ -315,8 +341,8 @@ var ne = class {
|
|
|
315
341
|
};
|
|
316
342
|
//#endregion
|
|
317
343
|
//#region src/utils.ts
|
|
318
|
-
function
|
|
344
|
+
function pe(e) {
|
|
319
345
|
return typeof e == "object" && !!e && typeof e.code == "string" && typeof e.message == "string";
|
|
320
346
|
}
|
|
321
347
|
//#endregion
|
|
322
|
-
export {
|
|
348
|
+
export { fe as ZiilaWidget, pe as isZiilaError };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { ThemeTokens } from './types';
|
|
2
|
+
/** Confirm button look, named after the widget Button variant it mirrors:
|
|
3
|
+
* `destructive` for prompts that destroy something (end chat), `primary`
|
|
4
|
+
* for prompts that just move the user on (checkout). */
|
|
5
|
+
export type ConfirmTone = 'destructive' | 'primary';
|
|
2
6
|
export interface ConfirmDialogOptions {
|
|
3
7
|
title: string;
|
|
4
8
|
message: string;
|
|
@@ -6,6 +10,8 @@ export interface ConfirmDialogOptions {
|
|
|
6
10
|
cancelLabel: string;
|
|
7
11
|
closeLabel: string;
|
|
8
12
|
dir: 'ltr' | 'rtl';
|
|
13
|
+
/** Defaults to 'destructive' — the original single-caller look. */
|
|
14
|
+
tone?: ConfirmTone;
|
|
9
15
|
/** Resolved theme tokens (config + host-page sniff); each style falls back
|
|
10
16
|
* to the dialog's built-in default when a token is absent. */
|
|
11
17
|
tokens?: Partial<ThemeTokens>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ZiilaConfig, ZiilaEvent, ZiilaCommand, EventPayloadMap, CommandPayloadMap } from './types';
|
|
2
|
+
export declare function safeCheckoutUrl(url: string): string | null;
|
|
2
3
|
export declare class ZiilaWidget {
|
|
3
4
|
private config;
|
|
4
5
|
private bridge;
|
|
@@ -12,6 +13,7 @@ export declare class ZiilaWidget {
|
|
|
12
13
|
private handleBeforeUnload;
|
|
13
14
|
private handleMessage;
|
|
14
15
|
private handleConfirmRequest;
|
|
16
|
+
private navigateToCheckout;
|
|
15
17
|
on<K extends ZiilaEvent>(event: K, handler: (data: EventPayloadMap[K]) => void): () => void;
|
|
16
18
|
off<K extends ZiilaEvent>(event: K, handler: (data: EventPayloadMap[K]) => void): void;
|
|
17
19
|
emit<K extends ZiilaCommand>(command: K, payload?: CommandPayloadMap[K]): void;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export interface EventPayloadMap {
|
|
|
120
120
|
export interface CommandPayloadMap {
|
|
121
121
|
clear: undefined;
|
|
122
122
|
}
|
|
123
|
-
export type ConfirmKind = 'endChat';
|
|
123
|
+
export type ConfirmKind = 'endChat' | 'checkout';
|
|
124
124
|
export type HandshakeMessage = {
|
|
125
125
|
type: 'HANDSHAKE';
|
|
126
126
|
} | {
|
|
@@ -158,4 +158,5 @@ export type WidgetMessage = {
|
|
|
158
158
|
type: 'CONFIRM_REQUEST';
|
|
159
159
|
kind: ConfirmKind;
|
|
160
160
|
locale: string;
|
|
161
|
+
url?: string;
|
|
161
162
|
};
|
package/dist/widget.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var e=class{constructor(e,t){this.iframe=null,this.port=null,this.handleHandshake=e=>{let t=this.iframe?.contentWindow;if(!t||e.source!==t||e.origin!==new URL(this.url).origin)return;let n=e.data;if(typeof n!=`object`||!n||n.type!==`HANDSHAKE`)return;let r=new MessageChannel;t.postMessage({type:`HANDSHAKE_ACK`},new URL(this.url).origin,[r.port2]),this.port=r.port1,this.port.start(),window.removeEventListener(`message`,this.handleHandshake),this.onPortReady(r.port1)},this.onPortReady=e,this.url=t??`https://widget.ziila.com`}mount(e){let t=new URL(this.url);t.searchParams.set(`embedded`,`1`),this.iframe=document.createElement(`iframe`),this.iframe.src=t.toString(),this.iframe.title=`Ziila Shopping Assistant`,this.iframe.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)})();
|
|
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;`,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;`,ne=(e,t)=>`flex:1;border:none;border-radius:${e.buttonRadius??`8px`};background:${t===`primary`?e.primaryColor??`#195f6b`:`#cc0000`};color:${t===`primary`?e.primaryFg??`#fff`:`#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=ee(u);let _=document.createElement(`p`);_.textContent=e.message,_.style.cssText=s(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,e.tone??`destructive`),y.addEventListener(`click`,()=>l(!0));let b=document.createElement(`div`);b.style.cssText=c,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=()=>`Go to Checkout`,H=()=>`الذهاب للدفع`,U=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),W=()=>`You will leave this chat and continue to the store's checkout page.`,G=()=>`سوف تغادر هذه المحادثة وتنتقل إلى صفحة الدفع في المتجر.`,ae=((e={},t={})=>(t.locale??T())===`en`?W(e):G(e)),K=()=>`Continue`,q=()=>`متابعة`,J=((e={},t={})=>(t.locale??T())===`en`?K(e):q(e)),oe=()=>`Cancel`,se=()=>`إلغاء`,ce=((e={},t={})=>(t.locale??T())===`en`?oe(e):se(e)),le=()=>`Close`,ue=()=>`إغلاق`,de=((e={},t={})=>(t.locale??T())===`en`?le(e):ue(e)),fe=new Set(g);function pe(e){return e&&fe.has(e)?e:`en`}function me(e){return e===`ar`?`rtl`:`ltr`}function he(e,t){let n={cancelLabel:ce({},{locale:t}),closeLabel:de({},{locale:t}),dir:me(t)};switch(e){case`checkout`:return{...n,title:U({},{locale:t}),message:ae({},{locale:t}),confirmLabel:J({},{locale:t}),tone:`primary`};case`endChat`:return{...n,title:P({},{locale:t}),message:L({},{locale:t}),confirmLabel:B({},{locale:t}),tone:`destructive`}}}function ge(e){let t;try{t=new URL(e,window.location.href)}catch{return null}return t.protocol!==`https:`&&t.protocol!==`http:`?null:t.href}var _e=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,t.url)},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,n){this.confirmDialog.show({...he(e,pe(t)),tokens:this.resolvedTheme.tokens}).then(t=>{this.bridge?.send({type:`CONFIRM_RESULT`,kind:e,confirmed:t}),t&&e===`checkout`&&n&&this.navigateToCheckout(n)})}navigateToCheckout(e){let t=ge(e);t&&window.location.assign(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}},Y=null,ve=window.Ziila?.q??[],X=document.currentScript,Z=X instanceof HTMLScriptElement&&X.src?new URL(`..`,X.src).toString():void 0;function Q(e){Y?.destroy(),Y=new _e(e.widgetUrl?e:{...e,widgetUrl:Z}),Y.mount()}var $=function(e){Q(e)};$.on=function(e,t){if(!Y)throw Error(`Ziila: call Ziila(config) before Ziila.on()`);return Y.on(e,t)},$.off=function(e,t){Y?.off(e,t)},$.emit=function(e,t){Y?.emit(e,t)},$.update=function(e){Y?.update(e)},$.mount=function(){Y?.mount()},$.destroy=function(){Y?.destroy(),Y=null},Object.defineProperty($,"isDirty",{get:()=>Y?.isDirty??!1,enumerable:!0,configurable:!1}),window.Ziila=$,ve.forEach(Q)})();
|