@akropolys/kiku 2.2.3 → 2.2.5
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/EMBED.md +44 -0
- package/README.md +4 -0
- package/dist/embed/chunk-NMSSMVCV.js +37 -0
- package/dist/embed/embed.js +44 -0
- package/dist/embed/lazy-U2YUNGCD.js +37 -0
- package/dist/embed/meta.json +1 -0
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/kiku.js +47 -0
- package/dist/lazy-7F2WZMLO.mjs +39 -0
- package/dist/lazy-7F2WZMLO.mjs.map +1 -0
- package/package.json +9 -6
- package/dist/lazy-CDXIO5AJ.mjs +0 -39
- package/dist/lazy-CDXIO5AJ.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{a as z,c as E,d as K,e as Y,h as Z,o as j}from"./chunk-NRT5W2SK.mjs";import{useState as ee,useEffect as te,useRef as oe}from"react";import{useSearch as ye,useAkropolysContext as ge,useCardFields as ke}from"@akropolys/sdk";import{Fragment as se,jsx as o,jsxs as i}from"react/jsx-runtime";var ne=()=>i("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("circle",{cx:"8.5",cy:"8.5",r:"5.5"}),o("line",{x1:"13",y1:"13",x2:"18",y2:"18"})]});function be({placeholder:u="Search products\u2026",limit:b=10,debounceMs:w=150,onSelect:v,className:p,inputClassName:C,dropdownClassName:N,renderResult:S,theme:a,classNames:h={}}){let[n,m]=ee(""),[s,r]=ee(!1),{results:c,loading:A,search:H,clear:f}=ye({debounceMs:w}),g=ge(),R=ke(),P=oe(null),F=oe(!1);te(()=>{if(F.current){F.current=!1;return}if(!n.trim()){f(),r(!1);return}r(!0),H(n,b)},[n]),te(()=>{let e=L=>{P.current&&!P.current.contains(L.target)&&r(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let l=e=>{n.trim()&&g.api.searchVector(n,1,void 0,!0).catch(()=>{}),F.current=!0,r(!1),m(e.entity.title??e.entity.name??""),v?.(e)},q=()=>{n.trim()&&(g.api.searchVector(n,1,void 0,!0).catch(()=>{}),c.length>0&&l(c[0]))},U=s&&n.trim().length>0,T={...a?.primaryColor&&{"--hsk-primary":a.primaryColor},...a?.backgroundColor&&{"--hsk-bg":a.backgroundColor},...a?.textColor&&{"--hsk-text":a.textColor},...a?.fontFamily&&{"--hsk-font":a.fontFamily},...a?.borderRadius&&{"--hsk-border-radius":a.borderRadius}};return i("div",{className:E("hsk-sb-wrap",h.root,p),ref:P,style:T,children:[o("span",{className:"hsk-sb-icon",children:o(ne,{})}),o("input",{className:E("hsk-sb-input",h.input,C),type:"text",value:n,placeholder:u,onChange:e=>m(e.target.value),onFocus:()=>c.length>0&&n.trim()&&r(!0),onKeyDown:e=>{e.key==="Enter"&&q()},autoComplete:"off",spellCheck:!1}),U&&i("div",{className:E("hsk-sb-drop",h.dropdown,N),style:{position:"absolute"},children:[A&&o("div",{className:"hsk-sb-loading-bar"}),A&&c.length===0?i(se,{children:[i("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1"}),o("div",{className:"hsk-sb-skeleton-text2"})]})]}),i("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1",style:{width:"45%"}}),o("div",{className:"hsk-sb-skeleton-text2",style:{width:"25%"}})]})]})]}):i(se,{children:[c.length===0&&!A&&i("div",{className:"hsk-sb-empty",children:["No results for \u201C",n,"\u201D"]}),c.map((e,L)=>{if(S)return o("div",{onClick:()=>l(e),className:"hsk-sb-fade",style:{animationDelay:`${L*18}ms`},children:S(e)},e.id);let B=e.entity.image??e.entity.thumbnail??e.entity.images?.[0];return i("div",{className:E("hsk-sb-row hsk-sb-fade",h.row),style:{animationDelay:`${L*18}ms`},onClick:()=>l(e),children:[o("span",{className:"hsk-sb-row-thumb",children:B?o("img",{src:B,alt:"",loading:"lazy",onError:D=>{D.currentTarget.style.display="none"}}):o(ne,{})}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-row-title",children:e.entity.title??e.entity.name}),z({fields:e.entity.fields??e.entity},R)[0]&&o("div",{className:"hsk-sb-row-sub",children:z({fields:e.entity.fields??e.entity},R)[0].value})]})]},e.id)})]})]})]})}import{useState as _,useEffect as ie,useCallback as O,useRef as G}from"react";import{createPortal as le}from"react-dom";import{useEffect as ae,useRef as we,useState as ve}from"react";import{jsx as d,jsxs as M}from"react/jsx-runtime";function re({title:u,logo:b,theme:w,backdropColor:v,backdropBlur:p,failed:C,onClose:N,onRetry:S}){let[a,h]=ve(!1),n=we(null),{vars:m}=K(w);return ae(()=>{if(h(!1),C)return;let s=setTimeout(()=>h(!0),250);return()=>clearTimeout(s)},[C]),ae(()=>{let s=document.body.style.overflow;return document.body.style.overflow="hidden",n.current?.focus(),()=>{document.body.style.overflow=s}},[]),d("div",{className:"hsk-opening-shell","data-hsk-theme":Y(w),role:"dialog","aria-modal":"true","aria-label":u||"Kiku chat",style:{...m,...v?{background:v}:{},...p?{backdropFilter:`blur(${typeof p=="number"?`${p}px`:p})`}:{}},onKeyDown:s=>{if(s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),N()),s.key==="Tab"){let r=Array.from(s.currentTarget.querySelectorAll("button:not(:disabled)")),c=r.indexOf(document.activeElement);s.preventDefault(),r[(c+(s.shiftKey?-1:1)+r.length)%r.length]?.focus()}},children:M("div",{className:"hsk-opening-panel",children:[M("header",{className:"hsk-opening-header",children:[b?d("img",{src:b,alt:u||"Kiku",className:"hsk-opening-logo"}):d("span",{children:u||"Kiku"}),d("button",{ref:n,type:"button",className:"hsk-opening-close",onClick:N,"aria-label":"Close chat",children:"\xD7"})]}),d("div",{className:"hsk-opening-content",children:C?M("div",{className:"hsk-opening-feedback",role:"alert",children:[d("p",{children:"Chat couldn\u2019t load."}),d("button",{type:"button",className:"hsk-opening-retry",onClick:S,children:"Try again"})]}):a?M("div",{className:"hsk-opening-feedback",role:"status",children:[M("svg",{className:"hsk-cb-opening-spinner",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[d("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.2"}),d("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),d("span",{children:"Loading chat\u2026"})]}):null})]})})}import{useAkropolysContext as Ce}from"@akropolys/sdk";import{Fragment as ce,jsx as V,jsxs as J}from"react/jsx-runtime";var Q=null;function Ne(){return Q??(Q=import("./lazy-
|
|
2
|
+
import{a as z,c as E,d as K,e as Y,h as Z,o as j}from"./chunk-NRT5W2SK.mjs";import{useState as ee,useEffect as te,useRef as oe}from"react";import{useSearch as ye,useAkropolysContext as ge,useCardFields as ke}from"@akropolys/sdk";import{Fragment as se,jsx as o,jsxs as i}from"react/jsx-runtime";var ne=()=>i("svg",{width:"15",height:"15",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[o("circle",{cx:"8.5",cy:"8.5",r:"5.5"}),o("line",{x1:"13",y1:"13",x2:"18",y2:"18"})]});function be({placeholder:u="Search products\u2026",limit:b=10,debounceMs:w=150,onSelect:v,className:p,inputClassName:C,dropdownClassName:N,renderResult:S,theme:a,classNames:h={}}){let[n,m]=ee(""),[s,r]=ee(!1),{results:c,loading:A,search:H,clear:f}=ye({debounceMs:w}),g=ge(),R=ke(),P=oe(null),F=oe(!1);te(()=>{if(F.current){F.current=!1;return}if(!n.trim()){f(),r(!1);return}r(!0),H(n,b)},[n]),te(()=>{let e=L=>{P.current&&!P.current.contains(L.target)&&r(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);let l=e=>{n.trim()&&g.api.searchVector(n,1,void 0,!0).catch(()=>{}),F.current=!0,r(!1),m(e.entity.title??e.entity.name??""),v?.(e)},q=()=>{n.trim()&&(g.api.searchVector(n,1,void 0,!0).catch(()=>{}),c.length>0&&l(c[0]))},U=s&&n.trim().length>0,T={...a?.primaryColor&&{"--hsk-primary":a.primaryColor},...a?.backgroundColor&&{"--hsk-bg":a.backgroundColor},...a?.textColor&&{"--hsk-text":a.textColor},...a?.fontFamily&&{"--hsk-font":a.fontFamily},...a?.borderRadius&&{"--hsk-border-radius":a.borderRadius}};return i("div",{className:E("hsk-sb-wrap",h.root,p),ref:P,style:T,children:[o("span",{className:"hsk-sb-icon",children:o(ne,{})}),o("input",{className:E("hsk-sb-input",h.input,C),type:"text",value:n,placeholder:u,onChange:e=>m(e.target.value),onFocus:()=>c.length>0&&n.trim()&&r(!0),onKeyDown:e=>{e.key==="Enter"&&q()},autoComplete:"off",spellCheck:!1}),U&&i("div",{className:E("hsk-sb-drop",h.dropdown,N),style:{position:"absolute"},children:[A&&o("div",{className:"hsk-sb-loading-bar"}),A&&c.length===0?i(se,{children:[i("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1"}),o("div",{className:"hsk-sb-skeleton-text2"})]})]}),i("div",{className:"hsk-sb-skeleton-row",children:[o("span",{className:"hsk-sb-skeleton-icon"}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-skeleton-text1",style:{width:"45%"}}),o("div",{className:"hsk-sb-skeleton-text2",style:{width:"25%"}})]})]})]}):i(se,{children:[c.length===0&&!A&&i("div",{className:"hsk-sb-empty",children:["No results for \u201C",n,"\u201D"]}),c.map((e,L)=>{if(S)return o("div",{onClick:()=>l(e),className:"hsk-sb-fade",style:{animationDelay:`${L*18}ms`},children:S(e)},e.id);let B=e.entity.image??e.entity.thumbnail??e.entity.images?.[0];return i("div",{className:E("hsk-sb-row hsk-sb-fade",h.row),style:{animationDelay:`${L*18}ms`},onClick:()=>l(e),children:[o("span",{className:"hsk-sb-row-thumb",children:B?o("img",{src:B,alt:"",loading:"lazy",onError:D=>{D.currentTarget.style.display="none"}}):o(ne,{})}),i("div",{className:"hsk-sb-row-body",children:[o("div",{className:"hsk-sb-row-title",children:e.entity.title??e.entity.name}),z({fields:e.entity.fields??e.entity},R)[0]&&o("div",{className:"hsk-sb-row-sub",children:z({fields:e.entity.fields??e.entity},R)[0].value})]})]},e.id)})]})]})]})}import{useState as _,useEffect as ie,useCallback as O,useRef as G}from"react";import{createPortal as le}from"react-dom";import{useEffect as ae,useRef as we,useState as ve}from"react";import{jsx as d,jsxs as M}from"react/jsx-runtime";function re({title:u,logo:b,theme:w,backdropColor:v,backdropBlur:p,failed:C,onClose:N,onRetry:S}){let[a,h]=ve(!1),n=we(null),{vars:m}=K(w);return ae(()=>{if(h(!1),C)return;let s=setTimeout(()=>h(!0),250);return()=>clearTimeout(s)},[C]),ae(()=>{let s=document.body.style.overflow;return document.body.style.overflow="hidden",n.current?.focus(),()=>{document.body.style.overflow=s}},[]),d("div",{className:"hsk-opening-shell","data-hsk-theme":Y(w),role:"dialog","aria-modal":"true","aria-label":u||"Kiku chat",style:{...m,...v?{background:v}:{},...p?{backdropFilter:`blur(${typeof p=="number"?`${p}px`:p})`}:{}},onKeyDown:s=>{if(s.key==="Escape"&&(s.preventDefault(),s.stopPropagation(),N()),s.key==="Tab"){let r=Array.from(s.currentTarget.querySelectorAll("button:not(:disabled)")),c=r.indexOf(document.activeElement);s.preventDefault(),r[(c+(s.shiftKey?-1:1)+r.length)%r.length]?.focus()}},children:M("div",{className:"hsk-opening-panel",children:[M("header",{className:"hsk-opening-header",children:[b?d("img",{src:b,alt:u||"Kiku",className:"hsk-opening-logo"}):d("span",{children:u||"Kiku"}),d("button",{ref:n,type:"button",className:"hsk-opening-close",onClick:N,"aria-label":"Close chat",children:"\xD7"})]}),d("div",{className:"hsk-opening-content",children:C?M("div",{className:"hsk-opening-feedback",role:"alert",children:[d("p",{children:"Chat couldn\u2019t load."}),d("button",{type:"button",className:"hsk-opening-retry",onClick:S,children:"Try again"})]}):a?M("div",{className:"hsk-opening-feedback",role:"status",children:[M("svg",{className:"hsk-cb-opening-spinner",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[d("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.2"}),d("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),d("span",{children:"Loading chat\u2026"})]}):null})]})})}import{useAkropolysContext as Ce}from"@akropolys/sdk";import{Fragment as ce,jsx as V,jsxs as J}from"react/jsx-runtime";var Q=null;function Ne(){return Q??(Q=import("./lazy-7F2WZMLO.mjs").catch(u=>{throw Q=null,u})),Q}function Se({label:u="Ask AI",children:b,icon:w,title:v,logo:p,placeholder:C,backdropColor:N,backdropBlur:S,className:a,onSelectSource:h,chips:n,theme:m,classNames:s={},enableVoice:r=!1,voiceLang:c,ttsVoice:A,enableVision:H=!1}){let f=Ce(),[g,R]=_(!1),[P,F]=_(null),[l,q]=_(null),[U,T]=_(!1),e=G(!0),L=G(!1),[B,D]=_(0);ie(()=>{if(g){D(0);return}let t=!0;return f?.api?.unreadFromTeam?.().then(k=>{t&&D(k)}).catch(()=>{}),()=>{t=!1}},[g,f]);let y=O(()=>{Ne().then(t=>{t.getShadowContainer(),e.current&&(q(t),T(!1)),t.warmChrome(f,f?.getShopperLanguage?.()??"",t.DEFAULT_UI_STRINGS),f?.api?.widgetSettings?.().then(k=>{k?.detectedLanguage&&k.detectedLanguage.toLowerCase()!=="english"&&t.warmLanguage(f,k.detectedLanguage,t.DEFAULT_UI_STRINGS)}).catch(()=>{})}).catch(()=>{e.current&&T(!0)})},[f]),$=G(null),de=O(()=>{let t=$.current?.getBoundingClientRect();F(t?{x:t.left+t.width/2,y:t.top+t.height/2}:null),L.current=!l,T(!1),R(!0),y();try{Z()}catch{}},[y,l]);ie(()=>{e.current=!0;let t=window.requestIdleCallback,k=t?t(y,{timeout:2e3}):setTimeout(y,300);if(typeof window<"u"&&!window.__akropolys_nav_patched){window.__akropolys_nav_patched=!0;let x=window.location.pathname,me=window.history.pushState,fe=window.history.replaceState;window.history.pushState=function(...W){me.apply(this,W),window.location.pathname!==x&&(x=window.location.pathname,window.dispatchEvent(new CustomEvent("akropolys:navigation")))},window.history.replaceState=function(...W){fe.apply(this,W),window.location.pathname!==x&&(x=window.location.pathname,window.dispatchEvent(new CustomEvent("akropolys:navigation")))}}let I=()=>{R(!1)};return window.addEventListener("popstate",I),window.addEventListener("akropolys:navigation",I),()=>{e.current=!1;let x=window.cancelIdleCallback;t&&x?x(k):clearTimeout(k),window.removeEventListener("popstate",I),window.removeEventListener("akropolys:navigation",I)}},[y]);let X=O(()=>{R(!1),requestAnimationFrame(()=>$.current?.focus())},[]),ue=O(()=>{T(!1),y()},[y]),{themeAttr:pe,vars:he}=K(m);return j(m),J(ce,{children:[J("button",{ref:$,className:E("hsk-cb-btn",s.button,a),onClick:de,onPointerEnter:y,onPointerDown:y,style:he,"data-hsk-theme":pe,"aria-label":"Open AI chat","aria-haspopup":"dialog","aria-expanded":g,children:[b!==void 0?b:J(ce,{children:[w?V("span",{className:"hsk-cb-btn-icon",style:{display:"flex",alignItems:"center"},children:w}):null,u]}),B>0&&V("span",{className:"hsk-cb-btn-badge","aria-label":`${B} new replies`,children:B})]}),g&&!l&&le(V(re,{title:v,logo:p,theme:m,failed:U,backdropColor:N,backdropBlur:S,onClose:X,onRetry:ue}),document.body),g&&l&&le(V(l.ChatModal,{title:v,logo:p,placeholder:C,backdropColor:N,backdropBlur:S,origin:L.current?void 0:P,onClose:X,onSelectSource:h,chips:n??l.DEFAULT_CHIPS,theme:m,classNames:s,enableVoice:r,voiceLang:c,enableVision:H,ttsVoice:A}),l.getShadowContainer()??document.body)]})}export{Se as KikuButton,be as SearchBar};
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/kiku.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
if (window.Kiku) return;
|
|
3
|
+
const script = document.currentScript;
|
|
4
|
+
const url = new URL('./embed/embed.js', script.src).href;
|
|
5
|
+
const styles = document.createElement('link');
|
|
6
|
+
styles.rel = 'stylesheet';
|
|
7
|
+
styles.href = new URL('./styles.css', script.src).href;
|
|
8
|
+
const styled = new Promise((resolve, reject) => {
|
|
9
|
+
styles.onload = resolve;
|
|
10
|
+
styles.onerror = () => reject(new Error('Kiku styles could not load.'));
|
|
11
|
+
});
|
|
12
|
+
document.head.append(styles);
|
|
13
|
+
let instance;
|
|
14
|
+
let pending;
|
|
15
|
+
const api = window.Kiku = {
|
|
16
|
+
mount(options) {
|
|
17
|
+
if (pending) return pending;
|
|
18
|
+
pending = Promise.all([
|
|
19
|
+
import(url),
|
|
20
|
+
styled,
|
|
21
|
+
document.body ? Promise.resolve() : new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve, { once: true }))
|
|
22
|
+
]).then(([module]) => { instance = module.mount(options); return instance; })
|
|
23
|
+
.catch(error => { pending = undefined; throw error; });
|
|
24
|
+
return pending;
|
|
25
|
+
},
|
|
26
|
+
open() { return ready().then(widget => widget.open()); },
|
|
27
|
+
ingest(data) { return ready().then(widget => widget.ingest(data)); },
|
|
28
|
+
updateIdentity(identity) { return ready().then(widget => widget.updateIdentity(identity)); },
|
|
29
|
+
async destroy() {
|
|
30
|
+
if (!pending) return;
|
|
31
|
+
try { (await pending).destroy(); } finally { instance = undefined; pending = undefined; }
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function ready() {
|
|
35
|
+
return pending || Promise.reject(new Error('Call Kiku.mount() first.'));
|
|
36
|
+
}
|
|
37
|
+
if (script.dataset.siteId) {
|
|
38
|
+
api.ready = api.mount({ siteId: script.dataset.siteId, apiToken: script.dataset.apiToken,
|
|
39
|
+
apiUrl: script.dataset.apiUrl, voiceUrl: script.dataset.voiceUrl,
|
|
40
|
+
button: { label: script.dataset.label || 'Ask Kiku', enableVoice: script.dataset.voice === 'true' }
|
|
41
|
+
});
|
|
42
|
+
api.ready.catch(error => {
|
|
43
|
+
window.dispatchEvent(new CustomEvent('kiku:error', { detail: error }));
|
|
44
|
+
console.error('[Kiku]', error);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
})();
|