sitemana-widget-embed 0.1.5 → 0.1.6
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/widget.js +1 -0
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -62,6 +62,7 @@ If you want to hide the \`${r.titleName}\`, you can wrap it with our VisuallyHid
|
|
|
62
62
|
For more information, see https://radix-ui.com/primitives/docs/components/${r.docsSlug}`;return x.useEffect(()=>{a&&(document.getElementById(a)||console.error(o))},[o,a]),null},rA="DialogDescriptionWarning",iA=({contentRef:a,descriptionId:r})=>{const o=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Ig(rA).contentName}}.`;return x.useEffect(()=>{const l=a.current?.getAttribute("aria-describedby");r&&l&&(document.getElementById(r)||console.warn(o))},[o,a,r]),null},oA=Gg,lA=Xg,sA=Zg,cA=Kg,uA=Pg,dA=Jg,fA=_e((a=>{var r=ro();function o(w,C){return w===C&&(w!==0||1/w===1/C)||w!==w&&C!==C}var l=typeof Object.is=="function"?Object.is:o,c=r.useState,d=r.useEffect,f=r.useLayoutEffect,h=r.useDebugValue;function v(w,C){var k=C(),T=c({inst:{value:k,getSnapshot:C}}),M=T[0].inst,U=T[1];return f(function(){M.value=k,M.getSnapshot=C,m(M)&&U({inst:M})},[w,k,C]),d(function(){return m(M)&&U({inst:M}),w(function(){m(M)&&U({inst:M})})},[w]),h(k),k}function m(w){var C=w.getSnapshot;w=w.value;try{var k=C();return!l(w,k)}catch{return!0}}function g(w,C){return C()}var b=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?g:v;a.useSyncExternalStore=r.useSyncExternalStore!==void 0?r.useSyncExternalStore:b})),hA=_e(((a,r)=>{r.exports=fA()})),pA=hA();function vA(){return(0,pA.useSyncExternalStore)(gA,()=>!0,()=>!1)}function gA(){return()=>{}}var Qc="Avatar",[mA,i3]=dg(Qc),[bA,tm]=mA(Qc),em=x.forwardRef((a,r)=>{const{__scopeAvatar:o,...l}=a,[c,d]=x.useState("idle");return(0,D.jsx)(bA,{scope:o,imageLoadingStatus:c,onImageLoadingStatusChange:d,children:(0,D.jsx)(Ne.span,{...l,ref:r})})});em.displayName=Qc;var am="AvatarImage",nm=x.forwardRef((a,r)=>{const{__scopeAvatar:o,src:l,onLoadingStatusChange:c=()=>{},...d}=a,f=tm(am,o),h=yA(l,d),v=sr(m=>{c(m),f.onImageLoadingStatusChange(m)});return Ga(()=>{h!=="idle"&&v(h)},[h,v]),h==="loaded"?(0,D.jsx)(Ne.img,{...d,ref:r,src:l}):null});nm.displayName=am;var rm="AvatarFallback",im=x.forwardRef((a,r)=>{const{__scopeAvatar:o,delayMs:l,...c}=a,d=tm(rm,o),[f,h]=x.useState(l===void 0);return x.useEffect(()=>{if(l!==void 0){const v=window.setTimeout(()=>h(!0),l);return()=>window.clearTimeout(v)}},[l]),f&&d.imageLoadingStatus!=="loaded"?(0,D.jsx)(Ne.span,{...c,ref:r}):null});im.displayName=rm;function om(a,r){return a?r?(a.src!==r&&(a.src=r),a.complete&&a.naturalWidth>0?"loaded":"loading"):"error":"idle"}function yA(a,{referrerPolicy:r,crossOrigin:o}){const l=vA(),c=x.useRef(null),d=l?(c.current||(c.current=new window.Image),c.current):null,[f,h]=x.useState(()=>om(d,a));return Ga(()=>{h(om(d,a))},[d,a]),Ga(()=>{const v=b=>()=>{h(b)};if(!d)return;const m=v("loaded"),g=v("error");return d.addEventListener("load",m),d.addEventListener("error",g),r&&(d.referrerPolicy=r),typeof o=="string"&&(d.crossOrigin=o),()=>{d.removeEventListener("load",m),d.removeEventListener("error",g)}},[d,o,r]),f}var wA=em,xA=nm,SA=im;function Pc({className:a,size:r="default",...o}){return(0,D.jsx)(wA,{"data-slot":"avatar","data-size":r,className:Vt("group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",a),...o})}function Fc({className:a,...r}){return(0,D.jsx)(xA,{"data-slot":"avatar-image",className:Vt("aspect-square size-full rounded-full object-cover",a),...r})}function Wc({className:a,...r}){return(0,D.jsx)(SA,{"data-slot":"avatar-fallback",className:Vt("flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",a),...r})}var lm=a=>typeof a=="boolean"?`${a}`:a===0?"0":a,sm=jf,kA=(a,r)=>o=>{var l;if(r?.variants==null)return sm(a,o?.class,o?.className);const{variants:c,defaultVariants:d}=r,f=Object.keys(c).map(v=>{const m=o?.[v],g=d?.[v];if(m===null)return null;const b=lm(m)||lm(g);return c[v][b]}),h=o&&Object.entries(o).reduce((v,m)=>{let[g,b]=m;return b===void 0||(v[g]=b),v},{});return sm(a,f,r==null||(l=r.compoundVariants)===null||l===void 0?void 0:l.reduce((v,m)=>{let{class:g,className:b,...w}=m;return Object.entries(w).every(C=>{let[k,T]=C;return Array.isArray(T)?T.includes({...d,...h}[k]):{...d,...h}[k]===T})?[...v,g,b]:v},[]),o?.class,o?.className)},TA=kA("group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none cursor-pointer focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground [a]:hover:bg-primary/80",outline:"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",ghost:"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",destructive:"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",link:"text-primary underline-offset-4 hover:underline",brand:"bg-brand text-brand-foreground hover:bg-brand/80 aria-expanded:bg-brand aria-expanded:text-brand-foreground"},size:{default:"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",xs:"h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",lg:"h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",icon:"size-8","icon-xs":"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg","icon-lg":"size-9"}},defaultVariants:{variant:"default",size:"default"}});function da({className:a,variant:r="default",size:o="default",asChild:l=!1,...c}){return(0,D.jsx)(l?zT:"button",{"data-slot":"button","data-variant":r,"data-size":o,className:Vt(TA({variant:r,size:o,className:a})),...c})}function EA({className:a,...r}){return(0,D.jsx)("textarea",{"data-slot":"textarea",className:Vt("flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",a),...r})}var cm=(...a)=>a.filter((r,o,l)=>!!r&&r.trim()!==""&&l.indexOf(r)===o).join(" ").trim(),AA=a=>a.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),CA=a=>a.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,o,l)=>l?l.toUpperCase():o.toLowerCase()),um=a=>{const r=CA(a);return r.charAt(0).toUpperCase()+r.slice(1)},zA={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},MA=a=>{for(const r in a)if(r.startsWith("aria-")||r==="role"||r==="title")return!0;return!1},DA=(0,x.forwardRef)(({color:a="currentColor",size:r=24,strokeWidth:o=2,absoluteStrokeWidth:l,className:c="",children:d,iconNode:f,...h},v)=>(0,x.createElement)("svg",{ref:v,...zA,width:r,height:r,stroke:a,strokeWidth:l?Number(o)*24/Number(r):o,className:cm("lucide",c),...!d&&!MA(h)&&{"aria-hidden":"true"},...h},[...f.map(([m,g])=>(0,x.createElement)(m,g)),...Array.isArray(d)?d:[d]])),Cn=(a,r)=>{const o=(0,x.forwardRef)(({className:l,...c},d)=>(0,x.createElement)(DA,{ref:d,iconNode:r,className:cm(`lucide-${AA(um(a))}`,`lucide-${a}`,l),...c}));return o.displayName=um(a),o},_A=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],Jc=Cn("chevron-down",_A),RA=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],OA=Cn("message-circle-x",RA),NA=[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]],jA=Cn("minimize-2",NA),VA=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],LA=Cn("search",VA),UA=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],BA=Cn("send",UA),HA=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],GA=Cn("sparkles",HA),YA=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],qA=Cn("x",YA),$c=768;function XA(){const[a,r]=x.useState(void 0);return x.useEffect(()=>{const o=window.matchMedia(`(max-width: ${$c-1}px)`),l=()=>{r(window.innerWidth<$c)};return o.addEventListener("change",l),r(window.innerWidth<$c),()=>o.removeEventListener("change",l)},[]),!!a}function ZA({...a}){return(0,D.jsx)(oA,{"data-slot":"dialog",...a})}function KA({...a}){return(0,D.jsx)(lA,{"data-slot":"dialog-portal",...a})}function QA({className:a,...r}){return(0,D.jsx)(sA,{"data-slot":"dialog-overlay",className:Vt("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",a),...r})}function PA({className:a,children:r,showCloseButton:o=!0,container:l,...c}){return(0,D.jsxs)(KA,{container:l,children:[(0,D.jsx)(QA,{}),(0,D.jsxs)(cA,{"data-slot":"dialog-content",className:Vt("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-background p-4 text-sm ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",a),...c,children:[r,o&&(0,D.jsx)(dA,{"data-slot":"dialog-close",asChild:!0,children:(0,D.jsxs)(da,{variant:"ghost",className:"absolute top-2 right-2",size:"icon-sm",children:[(0,D.jsx)(qA,{}),(0,D.jsx)("span",{className:"sr-only",children:"Close"})]})})]})]})}function FA({className:a,...r}){return(0,D.jsx)(uA,{"data-slot":"dialog-title",className:Vt("text-base leading-none font-medium",a),...r})}var Ic=["Ask me anything…","How can I help you today?","Try: What can you do?"],WA="Need help?",JA="Assistant",$A="Mana",IA="Start chat",t5="Ask anything…",tu="Powered by Mana Agents",e5="No messages yet",a5="Start a conversation to see messages here",n5={type:"spring",stiffness:400,damping:35},r5=40,i5=2e3;function dm(a,r){const o=r?.typingSpeedMs??r5,l=r?.pauseAfterMs??i5,[c,d]=x.useState(0),[f,h]=x.useState(0),[v,m]=x.useState("typing"),g=a.length>0?a[c%a.length]:"",b=g.slice(0,f);return x.useEffect(()=>{if(a.length!==0){if(v==="paused"){const w=setTimeout(()=>{d(C=>(C+1)%a.length),h(0),m("typing")},l);return()=>clearTimeout(w)}if(f<g.length){const w=setTimeout(()=>h(C=>C+1),o);return()=>clearTimeout(w)}m("paused")}},[a.length,c,f,g.length,v,o,l]),b}function o5(a,r=3e3){const[o,l]=x.useState(0);return x.useEffect(()=>{if(a.length<=1)return;const c=setInterval(()=>{l(d=>(d+1)%a.length)},r);return()=>clearInterval(c)},[a.length,r]),a.length>0?a[o%a.length]:""}function eu({agentName:a="Assistant",agentAvatarUrl:r,appearance:o,statusText:l="Online",className:c,onStopConversation:d,onClose:f}){const h=d!=null||f!=null;return(0,D.jsxs)("div",{className:Vt("flex items-center gap-2 w-full",c),children:[(0,D.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[(0,D.jsxs)(Pc,{size:"lg",style:r?void 0:ps(o),children:[r?(0,D.jsx)(Fc,{src:r,alt:a}):null,(0,D.jsx)(Wc,{className:Vt(o?"bg-transparent text-white":void 0),children:a.slice(0,2).toUpperCase()})]}),(0,D.jsxs)("div",{className:"min-w-0",children:[(0,D.jsx)("div",{className:"truncate text-sm font-semibold",children:a}),(0,D.jsx)("div",{className:"text-xs text-muted-foreground",children:l})]})]}),h&&(0,D.jsxs)("div",{className:"flex shrink-0 items-center gap-1 ml-auto",children:[d!=null&&(0,D.jsx)(da,{variant:"ghost",size:"icon","aria-label":"Stop conversation",title:"Stop conversation",onClick:d,children:(0,D.jsx)(OA,{})}),f!=null&&(0,D.jsx)(da,{variant:"ghost",size:"icon","aria-label":"Close",title:"Close",onClick:f,children:(0,D.jsx)(jA,{})})]})]})}function l5({className:a}){return(0,D.jsx)("div",{className:"w-full flex",children:(0,D.jsx)("div",{className:Vt("max-w-[85%] rounded-2xl px-3 py-2 text-sm leading-relaxed","bg-muted text-foreground",a),children:(0,D.jsx)("div",{className:"flex items-center gap-1 py-0.5","aria-label":"Thinking",children:[0,1,2].map(r=>(0,D.jsx)(ua.span,{className:"size-1.5 rounded-full bg-current opacity-60",animate:{y:[0,-4,0]},transition:{duration:.5,repeat:1/0,delay:r*.12,ease:"easeInOut"}},r))})})})}function au({messages:a,isTyping:r=!1,status:o="idle",welcomeMessage:l,suggestions:c,loadingText:d,errorMessage:f,appearance:h,onSuggestion:v,className:m,emptyTitle:g=e5,emptyDescription:b=a5,emptyAction:w}){const C=x.useRef(null);return x.useEffect(()=>{const k=C.current;k&&(k.scrollTop=k.scrollHeight)},[a,r]),(0,D.jsx)("div",{className:Vt("relative size-full",m),children:(0,D.jsx)("div",{ref:C,className:"h-full overflow-y-auto p-0 flex flex-col gap-2",children:a.length===0&&!r?o==="booting"?(0,D.jsx)("div",{className:"state",children:d??"Preparing your chat..."}):o==="error"?(0,D.jsx)("div",{className:"state error",children:f??"Something went wrong."}):l?.trim()?(0,D.jsxs)("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 py-6 px-4 text-center",children:[(0,D.jsx)("div",{className:"max-w-[24rem] rounded-2xl border border-border/70 bg-background/90 px-4 py-3 shadow-sm",children:(0,D.jsx)("p",{className:"text-sm leading-relaxed text-foreground",children:l})}),w&&(0,D.jsx)(da,{onClick:w.onClick,className:"rounded-full",children:w.label})]}):(0,D.jsxs)("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 px-4 py-6 text-center",children:[(0,D.jsxs)("div",{children:[(0,D.jsx)("p",{className:"font-medium",children:g}),(0,D.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:b})]}),c&&c.length>0?(0,D.jsx)("div",{className:"flex flex-wrap justify-center gap-2",children:c.map(k=>(0,D.jsx)(da,{variant:"outline",size:"sm",onClick:()=>v?.(k),children:k},k))}):null,w&&(0,D.jsx)(da,{onClick:w.onClick,className:"rounded-full",children:w.label})]}):(0,D.jsxs)(D.Fragment,{children:[a.map(k=>(0,D.jsx)(ua.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:Vt("w-full flex",k.role==="user"?"justify-end":"justify-start"),children:(0,D.jsxs)("div",{className:"max-w-[85%] flex flex-col gap-2",children:[(0,D.jsx)("div",{className:Vt("rounded-2xl px-3 py-2 text-sm leading-relaxed whitespace-pre-wrap",k.role==="user"?"text-white":"bg-muted text-foreground"),style:k.role==="user"?Jn(h):void 0,children:k.content}),k.actions&&k.actions.length>0&&(0,D.jsx)("div",{className:"flex flex-wrap gap-2 px-1",children:k.actions.map((T,M)=>(0,D.jsx)(da,{size:"sm",variant:T.variant??"outline",onClick:T.onClick,children:T.label},M))})]})},k.id)),r&&(0,D.jsx)(ua.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:"w-full",children:(0,D.jsx)(l5,{})})]})})})}var s5=2;function nu({placeholder:a=t5,value:r,onChange:o,onSubmit:l,appearance:c,disabled:d=!1,className:f}){const h=r!==void 0&&o!==void 0,[v,m]=x.useState(""),g=h?r:v,b=x.useRef(null),w=T=>{const M=T.target.value;h?o(M):m(M)},C=()=>{const T=g.trim();!T||!l||(l(T),h&&o?o(""):m(""),b.current?.focus())},k=T=>{T.key==="Enter"&&(T.shiftKey||(T.preventDefault(),C()))};return(0,D.jsxs)("div",{className:Vt("flex items-end gap-2",f),children:[(0,D.jsx)(EA,{ref:b,placeholder:a,value:g,onChange:w,onKeyDown:k,rows:s5,disabled:d,className:Vt("min-h-10 max-h-32 flex-1 resize-none py-2.5","focus-visible:ring-2")}),(0,D.jsx)(da,{type:"button",size:"icon",className:"h-10 w-10 shrink-0 text-white",style:Jn(c),"aria-label":"Send",disabled:d||!l,onClick:C,children:(0,D.jsx)(BA,{className:"size-4"})})]})}function ru({text:a="Powered by Mana Agents",className:r}){return(0,D.jsx)("div",{className:Vt("text-center text-xs text-muted-foreground",r),children:a})}function iu({open:a,onOpenChange:r,children:o,desktopClassName:l,desktopStyle:c,portalContainer:d}){return XA()?(0,D.jsx)(ZA,{open:a,onOpenChange:r,children:(0,D.jsxs)(PA,{container:d,showCloseButton:!1,className:Vt("fixed inset-0 top-0 left-0 right-0 bottom-0 z-50 flex h-full w-full max-w-none flex-col gap-0 rounded-none border-0 p-0 shadow-lg","translate-x-0 translate-y-0 data-[state=open]:zoom-in-100 data-[state=closed]:zoom-out-100"),children:[(0,D.jsx)(FA,{className:"sr-only",children:"Chat"}),o]})}):(0,D.jsx)(ua.div,{className:Vt(l,"z-10 flex h-[450px] flex-col"),style:{...c,pointerEvents:a?"auto":"none"},initial:!1,animate:{opacity:a?1:0,visibility:a?"visible":"hidden",scale:a?1:.96},transition:n5,children:o})}var c5=360,Po=56,u5=8,d5=12,f5={duration:.4};function fm({agentName:a=JA,agentAvatarUrl:r,appearance:o,welcomeMessage:l,spotlightMessages:c=[],messages:d=[],poweredBy:f=tu,headerStatus:h="Online",loadingText:v,errorMessage:m,status:g="idle",sendDisabled:b=!1,onSendMessage:w,isTyping:C,onSuggestion:k,className:T,open:M,defaultOpen:U=!1,onOpenChange:X,previewOnly:L=!1,onStopConversation:j,emptyAction:I,portalContainer:tt}){const[J,N]=x.useState(L?!1:U),[P,$]=x.useState(""),dt=c.length>0?c:[...Ic],ot=o5(dt,3e3),gt=L?!1:M??J,zt=x.useCallback(mt=>{if(X){X(mt);return}N(mt)},[X]);return(0,D.jsxs)("div",{className:Vt("relative",T),style:{width:dt.length>0?260:Po,height:dt.length>0?Po+u5+56:Po},children:[dt.length>0&&!gt&&(0,D.jsx)(bk,{mode:"wait",children:(0,D.jsxs)(ua.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:f5,className:"absolute right-0 bottom-[calc(56px+SPOTLIGHT_GAP)] flex w-full max-w-[260px] flex-col items-end",children:[(0,D.jsx)("div",{className:"rounded-2xl border bg-background/95 px-4 py-3 text-right shadow-lg backdrop-blur-sm dark:bg-background/90",children:(0,D.jsx)("p",{className:"text-sm leading-relaxed text-foreground",children:ot})}),(0,D.jsx)("div",{className:"flex w-full justify-end pr-6","aria-hidden":!0,children:(0,D.jsx)("span",{className:"border-[6px] border-transparent border-t-background/95 bg-transparent dark:border-t-background/90"})})]},ot)}),!L&&(0,D.jsxs)(iu,{open:gt,onOpenChange:zt,portalContainer:tt,desktopClassName:"absolute right-0 overflow-hidden rounded-2xl border bg-background shadow-xl",desktopStyle:{width:c5,bottom:Po+d5},children:[(0,D.jsx)("div",{className:"flex shrink-0 border-b p-4",children:(0,D.jsx)(eu,{agentName:a,agentAvatarUrl:r,appearance:o,statusText:h,onStopConversation:j??void 0,onClose:()=>zt(!1)})}),(0,D.jsx)("div",{className:"flex min-h-0 flex-1 flex-col p-4 overflow-hidden",children:(0,D.jsx)(au,{messages:d,isTyping:C??g==="sending",status:g,welcomeMessage:l,suggestions:c,loadingText:v,errorMessage:m,appearance:o,onSuggestion:mt=>{$(mt),k?.(mt)},emptyAction:I})}),!(I&&d.length===0&&!C)&&(0,D.jsxs)("div",{className:"shrink-0 border-t p-3",children:[(0,D.jsx)(nu,{value:P,onChange:$,onSubmit:w,appearance:o,disabled:b||g==="booting"}),(0,D.jsx)(ru,{text:f,className:"mt-2"})]})]}),(0,D.jsx)(ua.button,{type:"button",onClick:L?void 0:()=>zt(!gt),className:Vt("absolute bottom-0 right-0 flex size-14 shrink-0 items-center justify-center rounded-full text-white shadow-lg",L&&"pointer-events-none"),style:o?Jn(o):void 0,"aria-label":gt?"Close chat":"Open chat","aria-expanded":gt,animate:{scale:1},whileHover:L?void 0:{scale:1.02},whileTap:L?void 0:{scale:.98},children:gt?(0,D.jsx)(Jc,{className:"size-6"}):(0,D.jsxs)(Pc,{className:"size-12",style:o?ps(o):void 0,children:[r?(0,D.jsx)(Fc,{src:r,alt:a}):null,(0,D.jsx)(Wc,{className:"bg-transparent text-white",children:a.slice(0,2).toUpperCase()})]})})]})}var h5=360,p5=12,hm=280,pm=120,Fo=56,v5={type:"spring",stiffness:400,damping:35};function g5({agentName:a=WA,agentAvatarUrl:r,appearance:o,welcomeMessage:l,spotlightMessages:c=[],messages:d=[],poweredBy:f=tu,headerStatus:h="Online",loadingText:v,errorMessage:m,status:g="idle",sendDisabled:b=!1,startChatLabel:w=IA,onSendMessage:C,isTyping:k,onSuggestion:T,className:M,open:U,defaultOpen:X=!1,onOpenChange:L,previewOnly:j=!1,onStopConversation:I,emptyAction:tt,portalContainer:J}){const[N,P]=x.useState(j?!1:X),[$,dt]=x.useState(""),ot=j?!1:U??N,gt=x.useCallback(ct=>{if(L){L(ct);return}P(ct)},[L]),zt=dm(c.length>0?c:[...Ic]),mt=l!=null&&String(l).trim()!==""?String(l).trim():zt,K=ot?Fo:pm,H=ot?Fo:hm,Z={width:Fo,height:Fo,...o?Jn(o):{},pointerEvents:ot?"auto":"none"};return(0,D.jsxs)("div",{className:Vt("relative",M),style:{width:H,height:K},children:[!j&&(0,D.jsxs)(iu,{open:ot,onOpenChange:gt,portalContainer:J,desktopClassName:"absolute right-0 overflow-hidden rounded-2xl border bg-background shadow-xl",desktopStyle:{width:h5,bottom:K+p5},children:[(0,D.jsx)("div",{className:"flex shrink-0 border-b p-4",children:(0,D.jsx)(eu,{agentName:a,agentAvatarUrl:r,appearance:o,statusText:h,onStopConversation:I??void 0,onClose:()=>gt(!1)})}),(0,D.jsx)("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden p-4 md:max-h-[360px]",children:(0,D.jsx)(au,{messages:d,isTyping:k??g==="sending",status:g,welcomeMessage:l,suggestions:c,loadingText:v,errorMessage:m,appearance:o,onSuggestion:ct=>{dt(ct),T?.(ct)},emptyAction:tt})}),!(tt&&d.length===0&&!k)&&(0,D.jsxs)("div",{className:"border-t p-3 shrink-0",children:[(0,D.jsx)(nu,{value:$,onChange:dt,onSubmit:C,appearance:o,disabled:b||g==="booting"}),(0,D.jsx)(ru,{text:f,className:"mt-2"})]})]}),!ot&&(0,D.jsxs)(ua.div,{className:"absolute bottom-0 right-0 flex flex-col gap-4 rounded-2xl border bg-background p-4 shadow-xl",style:{width:hm,height:pm},initial:!1,animate:{opacity:1},children:[(0,D.jsxs)("div",{className:"flex flex-1 items-start gap-2",children:[(0,D.jsxs)(Pc,{className:"size-9 shrink-0",style:o?ps(o):void 0,children:[r?(0,D.jsx)(Fc,{src:r,alt:a}):null,(0,D.jsx)(Wc,{className:"bg-transparent text-white text-xs",children:a.slice(0,2).toUpperCase()})]}),(0,D.jsx)("p",{className:"min-w-0 flex-1 text-sm leading-snug text-foreground",children:mt})]}),(0,D.jsx)(da,{className:Vt("w-full rounded-full",j&&"pointer-events-none"),onClick:j?void 0:()=>gt(!0),style:o?Jn(o):void 0,children:o?.actionText?.trim()||w})]}),!j&&(0,D.jsx)(ua.button,{type:"button",onClick:()=>gt(!1),className:"absolute bottom-0 right-0 flex items-center justify-center rounded-full text-primary-foreground shadow-lg",style:Z,"aria-label":"Close chat",initial:!1,animate:{opacity:ot?1:0,visibility:ot?"visible":"hidden"},transition:v5,whileHover:ot?{scale:1.02}:void 0,whileTap:ot?{scale:.98}:void 0,children:(0,D.jsx)(Jc,{className:"size-6"})})]})}var ou=560,vm=320,lu=48,m5=48,b5=10,y5={type:"spring",stiffness:400,damping:35};function w5({agentName:a=$A,agentAvatarUrl:r,appearance:o,welcomeMessage:l,spotlightMessages:c=[],messages:d=[],poweredBy:f=tu,headerStatus:h="Online",loadingText:v,errorMessage:m,status:g="idle",sendDisabled:b=!1,launcherLabel:w="Ask",onSendMessage:C,isTyping:k,onSuggestion:T,className:M,open:U,defaultOpen:X=!1,onOpenChange:L,previewOnly:j=!1,onStopConversation:I,emptyAction:tt,portalContainer:J}){const[N,P]=x.useState(j?!1:X),[$,dt]=x.useState(""),ot=j?!1:U??N,gt=x.useCallback(Z=>{if(L){L(Z);return}P(Z)},[L]),zt=dm(c.length>0?c:[...Ic]),mt=x.useRef(null),[K,H]=x.useState(ou);return x.useEffect(()=>{if(ot)return;const Z=mt.current;if(!Z)return;const ct=new ResizeObserver(Q=>{const Zt=Q[0]?.contentRect.width;typeof Zt=="number"&&H(Zt)});return ct.observe(Z),()=>ct.disconnect()},[ot]),(0,D.jsxs)("div",{className:Vt("relative w-full max-w-full shrink-0",M),style:{maxWidth:ou,minWidth:vm,minHeight:lu},children:[!j&&(0,D.jsxs)(iu,{open:ot,onOpenChange:gt,portalContainer:J,desktopClassName:Vt("absolute left-0 right-0 mx-auto overflow-hidden rounded-2xl border bg-white/90 shadow-lg backdrop-blur-xl dark:bg-background/90"),desktopStyle:{width:"100%",minWidth:vm,maxWidth:ou,bottom:lu+b5},children:[(0,D.jsx)("div",{className:"flex shrink-0 border-b p-4",children:(0,D.jsx)(eu,{agentName:a,agentAvatarUrl:r,appearance:o,statusText:h,onStopConversation:I??void 0,onClose:()=>gt(!1)})}),(0,D.jsx)("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden p-4 md:max-h-[340px]",children:(0,D.jsx)(au,{messages:d,isTyping:k??g==="sending",status:g,welcomeMessage:l,suggestions:c,loadingText:v,errorMessage:m,appearance:o,onSuggestion:Z=>{dt(Z),T?.(Z)},emptyAction:tt})}),!(tt&&d.length===0&&!k)&&(0,D.jsxs)("div",{className:"border-t p-3 shrink-0",children:[(0,D.jsx)(nu,{value:$,onChange:dt,onSubmit:C,appearance:o,disabled:b||g==="booting"}),(0,D.jsx)(ru,{text:f,className:"mt-2"})]})]}),(0,D.jsx)("div",{className:"absolute bottom-0 left-0 right-0 z-0 flex w-full justify-center",children:(0,D.jsx)("div",{ref:mt,className:"flex w-full max-w-full justify-center",children:(0,D.jsx)(ua.button,{type:"button",onClick:j?void 0:()=>gt(!ot),className:Vt("flex shrink-0 items-center gap-2.5 rounded-full border bg-white/80 px-4 py-3 shadow-lg backdrop-blur-xl dark:bg-white/10",ot&&"justify-center",j&&"pointer-events-none","focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"),style:{height:lu},initial:!1,animate:{width:ot?m5:K,borderRadius:9999},transition:y5,"aria-label":ot?"Close chat":"Open chat","aria-expanded":ot,whileHover:j?void 0:{scale:1.02},whileTap:j?void 0:{scale:.98},children:ot?(0,D.jsx)(Jc,{className:"size-5 shrink-0 text-foreground"}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(LA,{className:"size-5 shrink-0 text-muted-foreground"}),(0,D.jsx)("span",{className:"min-w-0 flex-1 truncate text-left text-sm text-muted-foreground",children:zt}),(0,D.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-white",style:o?Jn(o):void 0,children:[(0,D.jsx)(GA,{className:"size-4"}),o?.actionText?.trim()||w]})]})})})})]})}var x5={default:fm,box:g5,chatbar:w5};function S5({mode:a,agentId:r,variant:o,placement:l,appearance:c,widgetTitle:d,welcomeMessage:f,spotlights:h,open:v,status:m,messages:g,errorMessage:b,sendDisabled:w=!1,onOpenChange:C,onSendMessage:k,onStopConversation:T,portalContainer:M}){const{horizontal:U,vertical:X}=Of(l),L=x5[o]??fm,j=k5(a,l),I=c.avatarImageUrl?.trim()||void 0,tt=c.loadingText?.trim()||void 0;return(0,D.jsx)("div",{"data-agent-id":r,"data-mode":a,"data-horizontal":U,"data-vertical":X,"data-variant":o,"data-open":String(v),"data-status":m,style:j,className:"widget-shell",children:(0,D.jsx)("div",{style:{pointerEvents:"auto"},children:(0,D.jsx)(L,{agentName:d,agentAvatarUrl:I,appearance:c,welcomeMessage:f,loadingText:tt,spotlightMessages:h,messages:g,status:m,errorMessage:b,sendDisabled:w||m==="booting",onSendMessage:k,open:v,onOpenChange:C,onStopConversation:T,portalContainer:M})})})}function k5(a,r){const o={pointerEvents:"none"};if(a==="preview"){const{horizontal:l,vertical:c}=Of(r);return Object.assign(o,{position:"relative",display:"flex",width:"100%",minHeight:"720px",padding:"24px",overflow:"hidden",alignItems:c==="top"?"flex-start":"flex-end",justifyContent:l==="left"?"flex-start":l==="center"?"center":"flex-end"}),o}switch(Object.assign(o,{position:"fixed",zIndex:2147483646}),r){case"top-left":Object.assign(o,{left:"24px",top:"24px"});break;case"top-center":Object.assign(o,{left:"50%",top:"24px",transform:"translateX(-50%)"});break;case"top-right":Object.assign(o,{right:"24px",top:"24px"});break;case"bottom-left":Object.assign(o,{left:"24px",bottom:"24px"});break;case"bottom-center":Object.assign(o,{left:"50%",bottom:"24px",transform:"translateX(-50%)"});break;default:Object.assign(o,{right:"24px",bottom:"24px"});break}return o}function gm(a){const r=a?.trim();return r?r.replace(/\/+$/,""):null}function T5(){const a="http://localhost:4000",r=globalThis.__SITEMANA_WIDGET_API_BASE__;return gm(a)??gm(r)??"http://localhost:4000"}async function Wo(a,r){const o=await fetch(new URL(a,`${T5()}/`).toString(),{...r,headers:{"Content-Type":"application/json",...r.headers??{}},credentials:"omit"}),l=await o.text(),c=l?JSON.parse(l):null;if(!o.ok)throw new Error(typeof c=="object"&&c&&"error"in c?String(c.error??o.statusText):o.statusText);return c}async function E5(a){return Wo("/api/widget/sessions",{method:"POST",body:JSON.stringify(a)})}async function A5(a){return Wo("/api/widget/messages",{method:"POST",body:JSON.stringify(a)})}async function C5(a){return Wo(`/api/conversations/public/by-token/${encodeURIComponent(a)}`,{method:"GET"})}async function z5(a){const r=new URLSearchParams({clientToken:a.clientToken});return a.cursor&&r.set("cursor",a.cursor),Wo(`/api/conversations/public/${encodeURIComponent(a.conversationId)}/messages?${r.toString()}`,{method:"GET"})}function su(a){return`sitemana-widget:${a}`}function mm(a){try{const r=sessionStorage.getItem(su(a));if(!r)return null;const o=JSON.parse(r);return!o?.sessionId||!o?.sessionToken||!o?.expiresAt?null:o}catch{return null}}function cu(a,r){sessionStorage.setItem(su(a),JSON.stringify(r))}function M5(a){sessionStorage.removeItem(su(a))}function uu(a){return[...a].sort((r,o)=>new Date(r.createdAt).getTime()-new Date(o.createdAt).getTime())}async function D5(a){const r=mm(a.agentId),o=await E5({agentId:a.agentId,origin:window.location.origin,pageUrl:a.pageUrl,referrer:a.referrer,sessionToken:r?.sessionToken}),l={sessionId:o.sessionId,sessionToken:o.token,expiresAt:o.expiresAt,conversationId:r?.conversationId};cu(a.agentId,l);let c=r?.conversationId,d=[];if(!c)try{c=(await C5(o.sessionId)).id,d=uu((await z5({conversationId:c,clientToken:o.sessionId})).data)}catch{c=void 0,d=[]}return c&&(l.conversationId=c,cu(a.agentId,l)),{session:l,sessionTokenExpiry:o.expiresAt,conversationId:c,messages:d,widgetConfig:o.widgetConfig}}async function _5(a){const r=mm(a.agentId);if(!r)throw new Error("Widget session not initialized");const o=await A5({sessionId:r.sessionId,sessionToken:r.sessionToken,content:a.content}),l={...r,conversationId:o.conversation.id};return cu(a.agentId,l),{session:l,conversationId:o.conversation.id,messages:uu([...o.userMessage?[o.userMessage]:[],...o.assistantMessages]),userMessage:o.userMessage,assistantMessages:o.assistantMessages}}async function R5(a){M5(a)}function O5(a,r){const o=new Date(a).getTime(),l=Math.max(5e3,o-Date.now()-6e4),c=window.setTimeout(()=>{r()},l);return()=>window.clearTimeout(c)}var N5=`
|
|
63
63
|
:host {
|
|
64
64
|
color-scheme: light;
|
|
65
|
+
--tw-border-style: solid;
|
|
65
66
|
--radius: 0.625rem;
|
|
66
67
|
--font-geist-sans: Geist, sans-serif;
|
|
67
68
|
--font-geist-mono: Geist_Mono, monospace;
|