@ziila/sdk 0.1.115 → 0.1.128
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 +21 -15
- package/dist/src/types.d.ts +5 -3
- 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=>`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=()=>`Change Language`,ee=()=>`تغيير اللغة`,q=((e={},t={})=>(t.locale??O())===`en`?K(e):ee(e)),J=()=>`Changing the language will start a new conversation, your message history will be lost.`,Y=()=>`سيؤدي تغيير اللغة إلى بدء محادثة جديدة وسيتم فقدان سجل رسائلك.`,X=((e={},t={})=>(t.locale??O())===`en`?J(e):Y(e)),Z=()=>`Change Language`,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){return{...e===`switchLocale`?{title:q({},{locale:t}),message:X({},{locale:t}),confirmLabel:$({},{locale:t})}:{title:z({},{locale:t}),message:H({},{locale:t}),confirmLabel:G({},{locale:t})},cancelLabel:re({},{locale:t}),closeLabel:oe({},{locale:t}),dir:le(t)}}var de=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({...ue(e,ce(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 fe(e){return typeof e==`object`&&!!e&&typeof e.code==`string`&&typeof e.message==`string`}exports.ZiilaWidget=de,exports.isZiilaError=fe;
|
package/dist/index.esm.js
CHANGED
|
@@ -228,26 +228,32 @@ 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 = () => "Change Language", ee = () => "تغيير اللغة", q = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? K(e) : ee(e)), J = () => "Changing the language will start a new conversation, your message history will be lost.", Y = () => "سيؤدي تغيير اللغة إلى بدء محادثة جديدة وسيتم فقدان سجل رسائلك.", X = ((e = {}, t = {}) => (t.locale ?? O()) === "en" ? J(e) : Y(e)), Z = () => "Change Language", 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
|
|
240
|
+
function ue(e, t) {
|
|
241
241
|
return {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
...e === "switchLocale" ? {
|
|
243
|
+
title: q({}, { locale: t }),
|
|
244
|
+
message: X({}, { locale: t }),
|
|
245
|
+
confirmLabel: $({}, { locale: t })
|
|
246
|
+
} : {
|
|
247
|
+
title: z({}, { locale: t }),
|
|
248
|
+
message: H({}, { locale: t }),
|
|
249
|
+
confirmLabel: G({}, { locale: t })
|
|
250
|
+
},
|
|
251
|
+
cancelLabel: re({}, { locale: t }),
|
|
252
|
+
closeLabel: oe({}, { locale: t }),
|
|
253
|
+
dir: le(t)
|
|
248
254
|
};
|
|
249
255
|
}
|
|
250
|
-
var
|
|
256
|
+
var de = class {
|
|
251
257
|
get isDirty() {
|
|
252
258
|
return this._isDirty;
|
|
253
259
|
}
|
|
@@ -277,7 +283,7 @@ var ne = class {
|
|
|
277
283
|
}
|
|
278
284
|
handleConfirmRequest(e, t) {
|
|
279
285
|
this.confirmDialog.show({
|
|
280
|
-
...
|
|
286
|
+
...ue(e, ce(t)),
|
|
281
287
|
tokens: this.resolvedTheme.tokens
|
|
282
288
|
}).then((t) => {
|
|
283
289
|
this.bridge?.send({
|
|
@@ -315,8 +321,8 @@ var ne = class {
|
|
|
315
321
|
};
|
|
316
322
|
//#endregion
|
|
317
323
|
//#region src/utils.ts
|
|
318
|
-
function
|
|
324
|
+
function fe(e) {
|
|
319
325
|
return typeof e == "object" && !!e && typeof e.code == "string" && typeof e.message == "string";
|
|
320
326
|
}
|
|
321
327
|
//#endregion
|
|
322
|
-
export {
|
|
328
|
+
export { de as ZiilaWidget, fe as isZiilaError };
|
package/dist/src/types.d.ts
CHANGED
|
@@ -62,11 +62,13 @@ export interface ThemeStyles {
|
|
|
62
62
|
}
|
|
63
63
|
export interface ZiilaConfig {
|
|
64
64
|
apiKey: string;
|
|
65
|
-
agentId: string;
|
|
66
65
|
/** Merchant cart id — required; all cart mutations target this cart. */
|
|
67
66
|
cartId: string;
|
|
68
67
|
container: string | HTMLElement;
|
|
69
|
-
locale
|
|
68
|
+
/** Conversation + UI locale. The widget resolves the merchant's agent for
|
|
69
|
+
* this locale itself (GET /agent) — there is no agent id in the config.
|
|
70
|
+
* Defaults to 'en'. */
|
|
71
|
+
locale?: 'en' | 'ar';
|
|
70
72
|
widgetTitle?: string;
|
|
71
73
|
theme?: Partial<ThemeStyles>;
|
|
72
74
|
widgetUrl?: string;
|
|
@@ -115,7 +117,7 @@ export interface EventPayloadMap {
|
|
|
115
117
|
export interface CommandPayloadMap {
|
|
116
118
|
clear: undefined;
|
|
117
119
|
}
|
|
118
|
-
export type ConfirmKind = 'endChat';
|
|
120
|
+
export type ConfirmKind = 'endChat' | 'switchLocale';
|
|
119
121
|
export type HandshakeMessage = {
|
|
120
122
|
type: 'HANDSHAKE';
|
|
121
123
|
} | {
|
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=>`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=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),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=()=>`Change Language`,H=()=>`تغيير اللغة`,U=((e={},t={})=>(t.locale??T())===`en`?V(e):H(e)),W=()=>`Changing the language will start a new conversation, your message history will be lost.`,G=()=>`سيؤدي تغيير اللغة إلى بدء محادثة جديدة وسيتم فقدان سجل رسائلك.`,ae=((e={},t={})=>(t.locale??T())===`en`?W(e):G(e)),K=()=>`Change Language`,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){return{...e===`switchLocale`?{title:U({},{locale:t}),message:ae({},{locale:t}),confirmLabel:J({},{locale:t})}:{title:P({},{locale:t}),message:L({},{locale:t}),confirmLabel:B({},{locale:t})},cancelLabel:ce({},{locale:t}),closeLabel:de({},{locale:t}),dir:me(t)}}var ge=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({...he(e,pe(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}},Y=null,X=window.Ziila?.q??[],Z=document.currentScript,_e=Z instanceof HTMLScriptElement&&Z.src?new URL(`..`,Z.src).toString():void 0;function Q(e){Y?.destroy(),Y=new ge(e.widgetUrl?e:{...e,widgetUrl:_e}),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=$,X.forEach(Q)})();
|