@schmitech/chatbot-widget 0.4.3 → 0.4.4
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.
|
@@ -23729,7 +23729,7 @@ $1 $2
|
|
|
23729
23729
|
),
|
|
23730
23730
|
/* @__PURE__ */ R.jsx("h4", { className: "font-medium text-2xl mb-3", style: { color: r.text.primary }, children: n.welcome.title }),
|
|
23731
23731
|
/* @__PURE__ */ R.jsx("div", { className: "w-full px-3 mb-4", children: /* @__PURE__ */ R.jsx("div", { className: "max-w-lg mx-auto sm:max-w-2xl", children: /* @__PURE__ */ R.jsx("p", { className: "text-xl text-left px-1 py-2", style: { color: r.text.secondary }, children: n.welcome.description }) }) }),
|
|
23732
|
-
/* @__PURE__ */ R.jsx("div", { className: "w-full px-2", children: /* @__PURE__ */ R.jsx("div", { className: "grid
|
|
23732
|
+
/* @__PURE__ */ R.jsx("div", { className: "w-full px-2", children: /* @__PURE__ */ R.jsx("div", { className: "grid gap-2 max-w-2xl mx-auto grid-cols-1 sm:grid-cols-2", children: n.suggestedQuestions.map((N, $) => {
|
|
23733
23733
|
var V;
|
|
23734
23734
|
return /* @__PURE__ */ R.jsxs(
|
|
23735
23735
|
"div",
|
|
@@ -748,7 +748,7 @@ $1 $2
|
|
|
748
748
|
|
|
749
749
|
`),t=t.replace(/\n```/g,"\n\n```"),t=t.replace(/```\n/g,"```\n\n"),t=t.replace(/[ \t]+$/gm,"");const r=new RegExp("(?<!\\]\\()(?<!\\$)(https?:\\/\\/[^\\s)$]+)(?!\\))(?!\\$)","g");t=t.replace(r,"[$1]($1)"),t=t.trim(),t&&!t.endsWith(`
|
|
750
750
|
`)&&(t+=`
|
|
751
|
-
`)}catch(r){return console.warn("Error preprocessing markdown:",r),e}return t},a3=({children:e,href:t,...r})=>R.jsx("a",{...r,href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline decoration-1 underline-offset-2 transition-colors duration-200",style:{wordBreak:"break-word",overflowWrap:"break-word"},children:e}),zu=({content:e,className:t=""})=>{const r=i3(e);return r?R.jsx("div",{className:`markdown-content ${t}`,style:{color:"inherit",fontSize:"inherit",lineHeight:"1.6",wordBreak:"break-word",overflowWrap:"break-word",maxWidth:"100%"},children:R.jsx(r4,{remarkPlugins:[vd,n3],rehypePlugins:[$d],components:{a:a3,p:({children:n,...i})=>R.jsx("p",{...i,style:{color:"inherit",margin:"0 0 12px 0",lineHeight:"1.6",wordBreak:"break-word",overflowWrap:"break-word"},children:n}),h1:({children:n,...i})=>R.jsx("h1",{...i,style:{color:"inherit",margin:"20px 0 12px 0",fontSize:"1.5em",fontWeight:"600",lineHeight:"1.4"},children:n}),h2:({children:n,...i})=>R.jsx("h2",{...i,style:{color:"inherit",margin:"18px 0 10px 0",fontSize:"1.3em",fontWeight:"600",lineHeight:"1.4"},children:n}),h3:({children:n,...i})=>R.jsx("h3",{...i,style:{color:"inherit",margin:"16px 0 8px 0",fontSize:"1.2em",fontWeight:"600",lineHeight:"1.4"},children:n}),h4:({children:n,...i})=>R.jsx("h4",{...i,style:{color:"inherit",margin:"14px 0 6px 0",fontSize:"1.1em",fontWeight:"600",lineHeight:"1.4"},children:n}),h5:({children:n,...i})=>R.jsx("h5",{...i,style:{color:"inherit",margin:"12px 0 6px 0",fontSize:"1.05em",fontWeight:"600",lineHeight:"1.4"},children:n}),h6:({children:n,...i})=>R.jsx("h6",{...i,style:{color:"inherit",margin:"12px 0 6px 0",fontSize:"1em",fontWeight:"600",lineHeight:"1.4"},children:n}),ul:({children:n,...i})=>R.jsx("ul",{...i,style:{color:"inherit",margin:"8px 0 12px 0",paddingLeft:"20px",listStyleType:"disc"},children:n}),ol:({children:n,...i})=>R.jsx("ol",{...i,style:{color:"inherit",margin:"8px 0 12px 0",paddingLeft:"20px",listStyleType:"decimal"},children:n}),li:({children:n,...i})=>R.jsx("li",{...i,style:{color:"inherit",marginBottom:"4px",lineHeight:"1.6"},children:n}),pre:({children:n,...i})=>R.jsx("pre",{...i,style:{overflow:"auto",padding:"12px 16px",margin:"12px 0",borderRadius:"6px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid rgba(0, 0, 0, 0.1)",fontSize:"0.9em",lineHeight:"1.4",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}),code:({children:n,...i})=>i.inline?R.jsx("code",{...i,style:{padding:"2px 6px",borderRadius:"4px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid rgba(0, 0, 0, 0.1)",fontSize:"0.9em",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}):R.jsx("code",{...i,style:{fontSize:"0.9em",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}),blockquote:({children:n,...i})=>R.jsx("blockquote",{...i,style:{margin:"12px 0",paddingLeft:"16px",borderLeft:"4px solid rgba(0, 0, 0, 0.2)",fontStyle:"italic",color:"inherit",opacity:.8},children:n}),hr:({...n})=>R.jsx("hr",{...n,style:{margin:"20px 0",border:"none",borderTop:"1px solid rgba(0, 0, 0, 0.2)",opacity:.5}}),table:({children:n,...i})=>R.jsx("div",{style:{overflowX:"auto",margin:"12px 0"},children:R.jsx("table",{...i,style:{width:"100%",borderCollapse:"collapse",fontSize:"0.9em"},children:n})}),thead:({children:n,...i})=>R.jsx("thead",{...i,style:{backgroundColor:"rgba(0, 0, 0, 0.05)"},children:n}),th:({children:n,...i})=>R.jsx("th",{...i,style:{padding:"8px 12px",border:"1px solid rgba(0, 0, 0, 0.2)",fontWeight:"600",textAlign:"left"},children:n}),td:({children:n,...i})=>R.jsx("td",{...i,style:{padding:"8px 12px",border:"1px solid rgba(0, 0, 0, 0.2)"},children:n}),br:({...n})=>R.jsx("br",{...n})},children:r})}):null},l3=({content:e,onComplete:t,messageIndex:r,inputRef:n,hasBeenAnimated:i,typingProgressRef:a,isTypingRef:l,setIsAnimating:o,scrollToBottom:s})=>{const[u,f]=J.useState(()=>{const D=a.current.get(r);return D?e.slice(0,D):""}),[h,d]=J.useState(!0),p=J.useRef(a.current.get(r)||0),v=J.useRef(!1),b=J.useRef(),E=J.useRef(!1),w=J.useRef(e);J.useEffect(()=>{if(i(r)){f(e),d(!1),t(),a.current.set(r,e.length);return}if(E.current&&e!==w.current){w.current=e;return}if(!E.current)return E.current=!0,w.current=e,setTimeout(()=>{C()},10),()=>{b.current&&cancelAnimationFrame(b.current)}},[r,e,i,t]);const C=()=>{if(v.current||!E.current)return;v.current=!0,l.current=!0,o(!0);let D=p.current,B=0,I=0;const P=15;d(D===0);const X=H=>{if(!(!v.current||!E.current)){if(H-I<P){b.current=requestAnimationFrame(X);return}if(I=H,D<w.current.length){const N=w.current.slice(0,D+1);f(N),a.current.set(r,D+1),D===0&&d(!1),H-B>he.ANIMATIONS.ANIMATION_SCROLL_INTERVAL&&(s(),B=H),D++,p.current=D,b.current=requestAnimationFrame(X)}else z()}};setTimeout(()=>{v.current&&E.current&&(b.current=requestAnimationFrame(X))},0)},z=()=>{l.current=!1,t(),v.current=!1,o(!1),s(),a.current.set(r,w.current.length)};return J.useEffect(()=>{const D=()=>{v.current&&(b.current&&cancelAnimationFrame(b.current),f(w.current),d(!1),z(),a.current.set(r,w.current.length))},B=n.current;return B&&B.addEventListener("input",D),()=>{B&&B.removeEventListener("input",D)}},[n]),J.useEffect(()=>{let D=null;const B=()=>{if(document.hidden)b.current&&(cancelAnimationFrame(b.current),v.current=!1),D=Date.now();else if(E.current&&!v.current&&p.current>0&&p.current<w.current.length){const I=Date.now();D&&I-D>he.ANIMATIONS.VISIBILITY_SKIP_THRESHOLD?(f(w.current),d(!1),z(),a.current.set(r,w.current.length)):C(),D=null}};return document.addEventListener("visibilitychange",B),()=>{document.removeEventListener("visibilitychange",B)}},[]),h&&p.current===0?R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]}):R.jsx("div",{children:R.jsx(zu,{content:u})})},o3=({message:e,index:t,isLatestAssistantMessage:r,showTypingAnimation:n,theme:i,copiedMessageId:a,onCopyToClipboard:l,onMarkMessageAnimated:o,messagesLength:s,scrollToBottom:u,inputRef:f,hasBeenAnimated:h,typingProgressRef:d,isTypingRef:p,setIsAnimating:v,formatTime:b,lastMessageRef:E})=>{const w=new Date;return w.setMinutes(w.getMinutes()-(s-t)),R.jsx("div",{className:cr("flex",e.role==="user"?"justify-end":"justify-start"),ref:t===s-1?E:null,children:R.jsxs("div",{className:cr("max-w-[85%] rounded-xl p-4 shadow-sm",e.role==="user"?"rounded-tr-none":"rounded-tl-none"),style:{background:e.role==="user"?i.message.user:i.message.assistant,color:e.role==="user"?i.message.userText:i.text.primary,border:e.role==="assistant"?`1px solid ${i.input.border}`:"none",width:"100%",maxWidth:"85%",wordWrap:"break-word",overflowWrap:"anywhere"},children:[e.role==="assistant"?e.content?!h(t)&&r?R.jsx(l3,{content:e.content,onComplete:()=>o(t,s,u),messageIndex:t,inputRef:f,hasBeenAnimated:h,typingProgressRef:d,isTypingRef:p,setIsAnimating:v,scrollToBottom:u}):R.jsx(zu,{content:e.content}):R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]}):R.jsx("p",{className:"text-base",style:{overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"pre-wrap",width:"100%"},children:e.content}),R.jsxs("div",{className:cr("flex text-xs mt-2",e.role==="user"?"justify-start text-white/70":"justify-between text-gray-400"),children:[R.jsx("span",{children:b(w)}),e.role==="assistant"&&!n&&R.jsxs("div",{className:"relative",children:[R.jsx("button",{onClick:()=>l(e.content,t),className:"text-gray-400 hover:text-gray-600 transition-colors ml-2 p-1 rounded-full","aria-label":"Copy to clipboard",children:a===t?R.jsx(Xu,{size:16}):R.jsx(Qu,{size:16})}),a===t&&R.jsx("div",{className:"absolute bottom-full right-0 mb-1 px-2 py-1 text-xs rounded-md shadow-sm animate-fade-in-out whitespace-nowrap",style:{backgroundColor:i.secondary,color:i.text.inverse},children:"Copied!"})]})]})]})})},s3=({messages:e,isLoading:t,theme:r,currentConfig:n,showScrollTop:i,showScrollBottom:a,isAnimating:l,messagesContainerRef:o,messagesEndRef:s,scrollToTop:u,scrollToBottom:f,handleScroll:h,sendMessage:d,focusInput:p,copiedMessageId:v,onCopyToClipboard:b,onMarkMessageAnimated:E,inputRef:w,hasBeenAnimated:C,typingProgressRef:z,isTypingRef:D,setIsAnimating:B,formatTime:I,lastMessageRef:P,maxSuggestedQuestionLength:X,maxSuggestedQuestionQueryLength:H})=>R.jsxs("div",{ref:o,className:"flex-1 p-2 overflow-y-auto scroll-smooth relative messages-container",style:{background:r.input.background,overflowY:"auto"},onScroll:h,children:[i&&R.jsx("button",{onClick:u,className:"sticky top-3 left-[calc(100%-48px)] z-10 flex items-center justify-center p-2 rounded-full shadow-md",style:{backgroundColor:r.primary,color:r.text.inverse},"aria-label":"Scroll to top",title:"Scroll to top",children:R.jsx(Ku,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON})}),a&&!l&&R.jsx("button",{onClick:()=>f(),className:"sticky bottom-3 left-[calc(100%-48px)] z-10 flex items-center justify-center p-2 rounded-full shadow-md",style:{backgroundColor:r.primary,color:r.text.inverse},"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:R.jsx($u,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON})}),e.length===0?R.jsxs("div",{className:"text-center py-4",children:[R.jsx(za,{iconName:n.icon,size:he.BUTTON_SIZES.ICON_SIZES.WELCOME,className:"mx-auto mb-2",style:{color:r.iconColor}}),R.jsx("h4",{className:"font-medium text-2xl mb-3",style:{color:r.text.primary},children:n.welcome.title}),R.jsx("div",{className:"w-full px-3 mb-4",children:R.jsx("div",{className:"max-w-lg mx-auto sm:max-w-2xl",children:R.jsx("p",{className:"text-xl text-left px-1 py-2",style:{color:r.text.secondary},children:n.welcome.description})})}),R.jsx("div",{className:"w-full px-2",children:R.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 max-w-lg mx-auto sm:max-w-2xl",children:n.suggestedQuestions.map((N,V)=>{var G;return R.jsxs("div",{onClick:()=>{var K;const le=H??he.MAX_SUGGESTED_QUESTION_QUERY_LENGTH,ie=((K=N.query)==null?void 0:K.length)>le?N.query.substring(0,le):N.query;d(ie),setTimeout(()=>{p()},he.ANIMATIONS.TOGGLE_DELAY)},className:"flex items-center cursor-pointer p-2.5 text-left text-base rounded-lg transition-all duration-300 ease-in-out hover:opacity-80 hover:translate-x-1 hover:shadow-sm transform-gpu",style:{backgroundColor:"transparent",color:r.suggestedQuestions.text},title:N.text,children:[R.jsx(li,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON,className:"mr-2.5 flex-shrink-0 opacity-70"}),R.jsx("span",{className:"flex-1 text-ellipsis overflow-hidden whitespace-nowrap font-medium",children:((G=N.text)==null?void 0:G.length)>(X??he.MAX_SUGGESTED_QUESTION_LENGTH)?`${N.text.substring(0,X??he.MAX_SUGGESTED_QUESTION_LENGTH)}...`:N.text})]},V)})})})]}):R.jsxs("div",{className:"space-y-3",children:[e.map((N,V)=>{const G=N.role==="assistant"&&V===e.length-1,le=G&&t;return R.jsx(o3,{message:N,index:V,isLatestAssistantMessage:G,showTypingAnimation:le,theme:r,copiedMessageId:v,onCopyToClipboard:b,onMarkMessageAnimated:E,messagesLength:e.length,scrollToBottom:f,inputRef:w,hasBeenAnimated:C,typingProgressRef:z,isTypingRef:D,setIsAnimating:B,formatTime:I,lastMessageRef:P},V)}),t&&e.length===0&&R.jsx("div",{className:"flex justify-start",children:R.jsx("div",{className:"bg-white border border-gray-200 rounded-xl rounded-tl-none max-w-[85%] p-4 shadow-sm",children:R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium text-lg",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]})})}),R.jsx("div",{ref:s})]})]}),u3=({message:e,isFocused:t,isLoading:r,theme:n,inputRef:i,handleMessageChange:a,handleKeyDown:l,handleSendMessage:o,setIsFocused:s})=>R.jsxs("div",{className:"p-4 border-t-0 shrink-0 relative",style:{background:`linear-gradient(180deg, transparent, ${n.background}f8)`,backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},children:[R.jsx("div",{className:"absolute top-0 left-0 right-0 h-px",style:{background:"linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent)"}}),R.jsxs("div",{className:"flex items-end gap-3",children:[R.jsxs("div",{className:cr("flex-1 relative rounded-2xl transition-all duration-300 overflow-hidden input-modern shadow-soft",t?"ring-2 ring-opacity-50":"ring-0"),style:{borderColor:t?n.secondary:"rgba(0, 0, 0, 0.1)",border:"1px solid",background:`linear-gradient(145deg, ${n.input.background}, ${n.input.background}f8)`,backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",boxShadow:t?`0 8px 25px -8px rgba(0, 0, 0, 0.1), 0 0 0 1px ${n.secondary}40`:"0 2px 10px -3px rgba(0, 0, 0, 0.1)"},children:[R.jsx("textarea",{ref:i,value:e,onChange:a,onKeyDown:l,onFocus:()=>s(!0),onBlur:()=>s(!1),placeholder:"Type your message...",maxLength:he.MAX_MESSAGE_LENGTH,className:"w-full resize-none outline-none p-4 pr-12 text-base custom-scrollbar focus:ring-0 focus:outline-none placeholder-gray-400 transition-all duration-200",style:{background:"transparent",color:n.text.primary,height:"52px",minHeight:"52px",maxHeight:"120px",overflow:"auto",lineHeight:"1.5",boxSizing:"border-box",fontWeight:"400"}}),e.length>0&&R.jsxs("div",{className:"absolute bottom-2 right-3 text-xs px-2.5 py-1 rounded-full transition-all duration-200 backdrop-blur-sm",style:{...Ic(e.length,he.MAX_MESSAGE_LENGTH),backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",fontWeight:"500"},children:[e.length,"/",he.MAX_MESSAGE_LENGTH]})]}),R.jsxs("button",{onClick:o,disabled:!e.trim()||r,className:cr("btn-modern rounded-2xl transition-all duration-300 flex items-center justify-center shrink-0 shadow-soft relative overflow-hidden group",e.trim()&&!r?"animate-button-hover":"cursor-not-allowed opacity-50"),style:{background:e.trim()&&!r?`linear-gradient(135deg, ${n.secondary}, ${n.secondary}e6)`:"linear-gradient(135deg, #e5e7eb, #f3f4f6)",color:e.trim()&&!r?"white":"#9ca3af",width:"52px",height:"54px",minHeight:"54px",transform:"translateY(-2px)",padding:"0",border:"none",boxShadow:e.trim()&&!r?`0 4px 12px -2px ${n.secondary}40`:"0 2px 4px -1px rgba(0, 0, 0, 0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,position:"relative"},"aria-label":"Send message",children:[R.jsx("div",{className:"absolute inset-0 opacity-0 transition-opacity duration-300 group-hover:opacity-100",style:{background:"linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0))"}}),R.jsx("div",{className:"absolute inset-0 flex items-center justify-center",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%"},children:R.jsx(rc,{size:he.BUTTON_SIZES.ICON_SIZES.SEND,className:"transition-transform duration-200 group-hover:translate-x-0.5 drop-shadow-sm",style:{display:"block",strokeWidth:2,transform:"translate(0.5px, -0.5px)"}})})]})]})]}),Jn=e=>{var ct,or;const[t,r]=J.useState(!1),[n,i]=J.useState(!1),[a,l]=J.useState(!1),[o,s]=J.useState(null),{isAnimating:u,typingProgressRef:f,isTypingRef:h,lastMessageRef:d,markMessageAnimated:p,hasBeenAnimated:v,clearAnimationTrackers:b,setIsAnimating:E}=Dc(),{showScrollTop:w,showScrollBottom:C,messagesContainerRef:z,messagesEndRef:D,shouldScrollRef:B,scrollTimeoutRef:I,scrollToBottom:P,scrollToTop:X,handleScroll:H}=Lc(u),[N,V]=J.useState(window.innerWidth);J.useEffect(()=>{const je=()=>V(window.innerWidth);return window.addEventListener("resize",je),()=>window.removeEventListener("resize",je)},[]);const G=ur(),[le,ie]=J.useState({...G,...e}),K=le.theme||Ma;J.useEffect(()=>{e.apiUrl&&e.apiKey&&e.sessionId&&Sr(e.apiUrl,e.apiKey,e.sessionId)},[e.apiUrl,e.apiKey,e.sessionId]),J.useEffect(()=>{const je=Ct=>{ie(Ct.detail)};return window.addEventListener("chatbot-config-update",je),()=>{window.removeEventListener("chatbot-config-update",je)}},[]),J.useEffect(()=>{e&&ie(je=>({...je,...e}))},[e]),J.useEffect(()=>{Nc({MAX_SUGGESTED_QUESTION_LENGTH:e.maxSuggestedQuestionLength??he.MAX_SUGGESTED_QUESTION_LENGTH,MAX_SUGGESTED_QUESTION_QUERY_LENGTH:e.maxSuggestedQuestionQueryLength??he.MAX_SUGGESTED_QUESTION_QUERY_LENGTH})},[e.maxSuggestedQuestionLength,e.maxSuggestedQuestionQueryLength]);const{messages:pe,isLoading:be,sendMessage:Ie,clearMessages:Ve}=di(),{message:S,isFocused:Me,inputRef:ke,handleMessageChange:A,handleKeyDown:He,handleSendMessage:Ge,setIsFocused:Ne,focusInput:We}=Bc({onSendMessage:je=>{B.current=!0,Ie(je),setTimeout(()=>P(!0),he.ANIMATIONS.TOGGLE_DELAY)},isLoading:be,isOpen:t});J.useEffect(()=>{pe.length===0&&b()},[pe.length,b]);const De=()=>{r(!t),t||(i(!1),setTimeout(()=>P(!0),he.ANIMATIONS.TOGGLE_DELAY))},Ye=async(je,Ct)=>{try{await navigator.clipboard.writeText(je),s(Ct),setTimeout(()=>{s(null)},he.ANIMATIONS.COPY_FEEDBACK_DURATION)}catch($t){console.error("Failed to copy text: ",$t)}},$e=je=>je.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return J.useEffect(()=>{(be||pe.length===0)&&P(!0)},[pe,be,P]),J.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[I]),R.jsxs("div",{className:"fixed bottom-8 right-8 z-50 flex flex-col items-end font-sans",style:{fontFamily:zc},children:[t&&R.jsxs("div",{className:"mb-4 w-full rounded-2xl shadow-elegant flex flex-col overflow-hidden border-0 transition-all duration-300 ease-in-out animate-slide-in-up backdrop-blur-lg",style:{background:`linear-gradient(145deg, ${K.background}, ${K.background}f0)`,height:he.WINDOW_DIMENSIONS.HEIGHT,maxHeight:he.WINDOW_DIMENSIONS.MAX_HEIGHT,width:Cc(N),minWidth:Mc(N),backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",border:"1px solid rgba(255, 255, 255, 0.2)",boxShadow:`
|
|
751
|
+
`)}catch(r){return console.warn("Error preprocessing markdown:",r),e}return t},a3=({children:e,href:t,...r})=>R.jsx("a",{...r,href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline decoration-1 underline-offset-2 transition-colors duration-200",style:{wordBreak:"break-word",overflowWrap:"break-word"},children:e}),zu=({content:e,className:t=""})=>{const r=i3(e);return r?R.jsx("div",{className:`markdown-content ${t}`,style:{color:"inherit",fontSize:"inherit",lineHeight:"1.6",wordBreak:"break-word",overflowWrap:"break-word",maxWidth:"100%"},children:R.jsx(r4,{remarkPlugins:[vd,n3],rehypePlugins:[$d],components:{a:a3,p:({children:n,...i})=>R.jsx("p",{...i,style:{color:"inherit",margin:"0 0 12px 0",lineHeight:"1.6",wordBreak:"break-word",overflowWrap:"break-word"},children:n}),h1:({children:n,...i})=>R.jsx("h1",{...i,style:{color:"inherit",margin:"20px 0 12px 0",fontSize:"1.5em",fontWeight:"600",lineHeight:"1.4"},children:n}),h2:({children:n,...i})=>R.jsx("h2",{...i,style:{color:"inherit",margin:"18px 0 10px 0",fontSize:"1.3em",fontWeight:"600",lineHeight:"1.4"},children:n}),h3:({children:n,...i})=>R.jsx("h3",{...i,style:{color:"inherit",margin:"16px 0 8px 0",fontSize:"1.2em",fontWeight:"600",lineHeight:"1.4"},children:n}),h4:({children:n,...i})=>R.jsx("h4",{...i,style:{color:"inherit",margin:"14px 0 6px 0",fontSize:"1.1em",fontWeight:"600",lineHeight:"1.4"},children:n}),h5:({children:n,...i})=>R.jsx("h5",{...i,style:{color:"inherit",margin:"12px 0 6px 0",fontSize:"1.05em",fontWeight:"600",lineHeight:"1.4"},children:n}),h6:({children:n,...i})=>R.jsx("h6",{...i,style:{color:"inherit",margin:"12px 0 6px 0",fontSize:"1em",fontWeight:"600",lineHeight:"1.4"},children:n}),ul:({children:n,...i})=>R.jsx("ul",{...i,style:{color:"inherit",margin:"8px 0 12px 0",paddingLeft:"20px",listStyleType:"disc"},children:n}),ol:({children:n,...i})=>R.jsx("ol",{...i,style:{color:"inherit",margin:"8px 0 12px 0",paddingLeft:"20px",listStyleType:"decimal"},children:n}),li:({children:n,...i})=>R.jsx("li",{...i,style:{color:"inherit",marginBottom:"4px",lineHeight:"1.6"},children:n}),pre:({children:n,...i})=>R.jsx("pre",{...i,style:{overflow:"auto",padding:"12px 16px",margin:"12px 0",borderRadius:"6px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid rgba(0, 0, 0, 0.1)",fontSize:"0.9em",lineHeight:"1.4",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}),code:({children:n,...i})=>i.inline?R.jsx("code",{...i,style:{padding:"2px 6px",borderRadius:"4px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid rgba(0, 0, 0, 0.1)",fontSize:"0.9em",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}):R.jsx("code",{...i,style:{fontSize:"0.9em",fontFamily:'Monaco, Consolas, "Liberation Mono", "Courier New", monospace'},children:n}),blockquote:({children:n,...i})=>R.jsx("blockquote",{...i,style:{margin:"12px 0",paddingLeft:"16px",borderLeft:"4px solid rgba(0, 0, 0, 0.2)",fontStyle:"italic",color:"inherit",opacity:.8},children:n}),hr:({...n})=>R.jsx("hr",{...n,style:{margin:"20px 0",border:"none",borderTop:"1px solid rgba(0, 0, 0, 0.2)",opacity:.5}}),table:({children:n,...i})=>R.jsx("div",{style:{overflowX:"auto",margin:"12px 0"},children:R.jsx("table",{...i,style:{width:"100%",borderCollapse:"collapse",fontSize:"0.9em"},children:n})}),thead:({children:n,...i})=>R.jsx("thead",{...i,style:{backgroundColor:"rgba(0, 0, 0, 0.05)"},children:n}),th:({children:n,...i})=>R.jsx("th",{...i,style:{padding:"8px 12px",border:"1px solid rgba(0, 0, 0, 0.2)",fontWeight:"600",textAlign:"left"},children:n}),td:({children:n,...i})=>R.jsx("td",{...i,style:{padding:"8px 12px",border:"1px solid rgba(0, 0, 0, 0.2)"},children:n}),br:({...n})=>R.jsx("br",{...n})},children:r})}):null},l3=({content:e,onComplete:t,messageIndex:r,inputRef:n,hasBeenAnimated:i,typingProgressRef:a,isTypingRef:l,setIsAnimating:o,scrollToBottom:s})=>{const[u,f]=J.useState(()=>{const D=a.current.get(r);return D?e.slice(0,D):""}),[h,d]=J.useState(!0),p=J.useRef(a.current.get(r)||0),v=J.useRef(!1),b=J.useRef(),E=J.useRef(!1),w=J.useRef(e);J.useEffect(()=>{if(i(r)){f(e),d(!1),t(),a.current.set(r,e.length);return}if(E.current&&e!==w.current){w.current=e;return}if(!E.current)return E.current=!0,w.current=e,setTimeout(()=>{C()},10),()=>{b.current&&cancelAnimationFrame(b.current)}},[r,e,i,t]);const C=()=>{if(v.current||!E.current)return;v.current=!0,l.current=!0,o(!0);let D=p.current,B=0,I=0;const P=15;d(D===0);const X=H=>{if(!(!v.current||!E.current)){if(H-I<P){b.current=requestAnimationFrame(X);return}if(I=H,D<w.current.length){const N=w.current.slice(0,D+1);f(N),a.current.set(r,D+1),D===0&&d(!1),H-B>he.ANIMATIONS.ANIMATION_SCROLL_INTERVAL&&(s(),B=H),D++,p.current=D,b.current=requestAnimationFrame(X)}else z()}};setTimeout(()=>{v.current&&E.current&&(b.current=requestAnimationFrame(X))},0)},z=()=>{l.current=!1,t(),v.current=!1,o(!1),s(),a.current.set(r,w.current.length)};return J.useEffect(()=>{const D=()=>{v.current&&(b.current&&cancelAnimationFrame(b.current),f(w.current),d(!1),z(),a.current.set(r,w.current.length))},B=n.current;return B&&B.addEventListener("input",D),()=>{B&&B.removeEventListener("input",D)}},[n]),J.useEffect(()=>{let D=null;const B=()=>{if(document.hidden)b.current&&(cancelAnimationFrame(b.current),v.current=!1),D=Date.now();else if(E.current&&!v.current&&p.current>0&&p.current<w.current.length){const I=Date.now();D&&I-D>he.ANIMATIONS.VISIBILITY_SKIP_THRESHOLD?(f(w.current),d(!1),z(),a.current.set(r,w.current.length)):C(),D=null}};return document.addEventListener("visibilitychange",B),()=>{document.removeEventListener("visibilitychange",B)}},[]),h&&p.current===0?R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]}):R.jsx("div",{children:R.jsx(zu,{content:u})})},o3=({message:e,index:t,isLatestAssistantMessage:r,showTypingAnimation:n,theme:i,copiedMessageId:a,onCopyToClipboard:l,onMarkMessageAnimated:o,messagesLength:s,scrollToBottom:u,inputRef:f,hasBeenAnimated:h,typingProgressRef:d,isTypingRef:p,setIsAnimating:v,formatTime:b,lastMessageRef:E})=>{const w=new Date;return w.setMinutes(w.getMinutes()-(s-t)),R.jsx("div",{className:cr("flex",e.role==="user"?"justify-end":"justify-start"),ref:t===s-1?E:null,children:R.jsxs("div",{className:cr("max-w-[85%] rounded-xl p-4 shadow-sm",e.role==="user"?"rounded-tr-none":"rounded-tl-none"),style:{background:e.role==="user"?i.message.user:i.message.assistant,color:e.role==="user"?i.message.userText:i.text.primary,border:e.role==="assistant"?`1px solid ${i.input.border}`:"none",width:"100%",maxWidth:"85%",wordWrap:"break-word",overflowWrap:"anywhere"},children:[e.role==="assistant"?e.content?!h(t)&&r?R.jsx(l3,{content:e.content,onComplete:()=>o(t,s,u),messageIndex:t,inputRef:f,hasBeenAnimated:h,typingProgressRef:d,isTypingRef:p,setIsAnimating:v,scrollToBottom:u}):R.jsx(zu,{content:e.content}):R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]}):R.jsx("p",{className:"text-base",style:{overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"pre-wrap",width:"100%"},children:e.content}),R.jsxs("div",{className:cr("flex text-xs mt-2",e.role==="user"?"justify-start text-white/70":"justify-between text-gray-400"),children:[R.jsx("span",{children:b(w)}),e.role==="assistant"&&!n&&R.jsxs("div",{className:"relative",children:[R.jsx("button",{onClick:()=>l(e.content,t),className:"text-gray-400 hover:text-gray-600 transition-colors ml-2 p-1 rounded-full","aria-label":"Copy to clipboard",children:a===t?R.jsx(Xu,{size:16}):R.jsx(Qu,{size:16})}),a===t&&R.jsx("div",{className:"absolute bottom-full right-0 mb-1 px-2 py-1 text-xs rounded-md shadow-sm animate-fade-in-out whitespace-nowrap",style:{backgroundColor:i.secondary,color:i.text.inverse},children:"Copied!"})]})]})]})})},s3=({messages:e,isLoading:t,theme:r,currentConfig:n,showScrollTop:i,showScrollBottom:a,isAnimating:l,messagesContainerRef:o,messagesEndRef:s,scrollToTop:u,scrollToBottom:f,handleScroll:h,sendMessage:d,focusInput:p,copiedMessageId:v,onCopyToClipboard:b,onMarkMessageAnimated:E,inputRef:w,hasBeenAnimated:C,typingProgressRef:z,isTypingRef:D,setIsAnimating:B,formatTime:I,lastMessageRef:P,maxSuggestedQuestionLength:X,maxSuggestedQuestionQueryLength:H})=>R.jsxs("div",{ref:o,className:"flex-1 p-2 overflow-y-auto scroll-smooth relative messages-container",style:{background:r.input.background,overflowY:"auto"},onScroll:h,children:[i&&R.jsx("button",{onClick:u,className:"sticky top-3 left-[calc(100%-48px)] z-10 flex items-center justify-center p-2 rounded-full shadow-md",style:{backgroundColor:r.primary,color:r.text.inverse},"aria-label":"Scroll to top",title:"Scroll to top",children:R.jsx(Ku,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON})}),a&&!l&&R.jsx("button",{onClick:()=>f(),className:"sticky bottom-3 left-[calc(100%-48px)] z-10 flex items-center justify-center p-2 rounded-full shadow-md",style:{backgroundColor:r.primary,color:r.text.inverse},"aria-label":"Scroll to bottom",title:"Scroll to bottom",children:R.jsx($u,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON})}),e.length===0?R.jsxs("div",{className:"text-center py-4",children:[R.jsx(za,{iconName:n.icon,size:he.BUTTON_SIZES.ICON_SIZES.WELCOME,className:"mx-auto mb-2",style:{color:r.iconColor}}),R.jsx("h4",{className:"font-medium text-2xl mb-3",style:{color:r.text.primary},children:n.welcome.title}),R.jsx("div",{className:"w-full px-3 mb-4",children:R.jsx("div",{className:"max-w-lg mx-auto sm:max-w-2xl",children:R.jsx("p",{className:"text-xl text-left px-1 py-2",style:{color:r.text.secondary},children:n.welcome.description})})}),R.jsx("div",{className:"w-full px-2",children:R.jsx("div",{className:"grid gap-2 max-w-2xl mx-auto grid-cols-1 sm:grid-cols-2",children:n.suggestedQuestions.map((N,V)=>{var G;return R.jsxs("div",{onClick:()=>{var K;const le=H??he.MAX_SUGGESTED_QUESTION_QUERY_LENGTH,ie=((K=N.query)==null?void 0:K.length)>le?N.query.substring(0,le):N.query;d(ie),setTimeout(()=>{p()},he.ANIMATIONS.TOGGLE_DELAY)},className:"flex items-center cursor-pointer p-2.5 text-left text-base rounded-lg transition-all duration-300 ease-in-out hover:opacity-80 hover:translate-x-1 hover:shadow-sm transform-gpu",style:{backgroundColor:"transparent",color:r.suggestedQuestions.text},title:N.text,children:[R.jsx(li,{size:he.BUTTON_SIZES.ICON_SIZES.BUTTON,className:"mr-2.5 flex-shrink-0 opacity-70"}),R.jsx("span",{className:"flex-1 text-ellipsis overflow-hidden whitespace-nowrap font-medium",children:((G=N.text)==null?void 0:G.length)>(X??he.MAX_SUGGESTED_QUESTION_LENGTH)?`${N.text.substring(0,X??he.MAX_SUGGESTED_QUESTION_LENGTH)}...`:N.text})]},V)})})})]}):R.jsxs("div",{className:"space-y-3",children:[e.map((N,V)=>{const G=N.role==="assistant"&&V===e.length-1,le=G&&t;return R.jsx(o3,{message:N,index:V,isLatestAssistantMessage:G,showTypingAnimation:le,theme:r,copiedMessageId:v,onCopyToClipboard:b,onMarkMessageAnimated:E,messagesLength:e.length,scrollToBottom:f,inputRef:w,hasBeenAnimated:C,typingProgressRef:z,isTypingRef:D,setIsAnimating:B,formatTime:I,lastMessageRef:P},V)}),t&&e.length===0&&R.jsx("div",{className:"flex justify-start",children:R.jsx("div",{className:"bg-white border border-gray-200 rounded-xl rounded-tl-none max-w-[85%] p-4 shadow-sm",children:R.jsxs("div",{className:"text-gray-500",children:[R.jsx("span",{className:"font-medium text-lg",children:"Thinking"}),R.jsxs("span",{className:"animate-dots ml-1",children:[R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."}),R.jsx("span",{className:"dot",children:"."})]})]})})}),R.jsx("div",{ref:s})]})]}),u3=({message:e,isFocused:t,isLoading:r,theme:n,inputRef:i,handleMessageChange:a,handleKeyDown:l,handleSendMessage:o,setIsFocused:s})=>R.jsxs("div",{className:"p-4 border-t-0 shrink-0 relative",style:{background:`linear-gradient(180deg, transparent, ${n.background}f8)`,backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)"},children:[R.jsx("div",{className:"absolute top-0 left-0 right-0 h-px",style:{background:"linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent)"}}),R.jsxs("div",{className:"flex items-end gap-3",children:[R.jsxs("div",{className:cr("flex-1 relative rounded-2xl transition-all duration-300 overflow-hidden input-modern shadow-soft",t?"ring-2 ring-opacity-50":"ring-0"),style:{borderColor:t?n.secondary:"rgba(0, 0, 0, 0.1)",border:"1px solid",background:`linear-gradient(145deg, ${n.input.background}, ${n.input.background}f8)`,backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",boxShadow:t?`0 8px 25px -8px rgba(0, 0, 0, 0.1), 0 0 0 1px ${n.secondary}40`:"0 2px 10px -3px rgba(0, 0, 0, 0.1)"},children:[R.jsx("textarea",{ref:i,value:e,onChange:a,onKeyDown:l,onFocus:()=>s(!0),onBlur:()=>s(!1),placeholder:"Type your message...",maxLength:he.MAX_MESSAGE_LENGTH,className:"w-full resize-none outline-none p-4 pr-12 text-base custom-scrollbar focus:ring-0 focus:outline-none placeholder-gray-400 transition-all duration-200",style:{background:"transparent",color:n.text.primary,height:"52px",minHeight:"52px",maxHeight:"120px",overflow:"auto",lineHeight:"1.5",boxSizing:"border-box",fontWeight:"400"}}),e.length>0&&R.jsxs("div",{className:"absolute bottom-2 right-3 text-xs px-2.5 py-1 rounded-full transition-all duration-200 backdrop-blur-sm",style:{...Ic(e.length,he.MAX_MESSAGE_LENGTH),backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)",fontWeight:"500"},children:[e.length,"/",he.MAX_MESSAGE_LENGTH]})]}),R.jsxs("button",{onClick:o,disabled:!e.trim()||r,className:cr("btn-modern rounded-2xl transition-all duration-300 flex items-center justify-center shrink-0 shadow-soft relative overflow-hidden group",e.trim()&&!r?"animate-button-hover":"cursor-not-allowed opacity-50"),style:{background:e.trim()&&!r?`linear-gradient(135deg, ${n.secondary}, ${n.secondary}e6)`:"linear-gradient(135deg, #e5e7eb, #f3f4f6)",color:e.trim()&&!r?"white":"#9ca3af",width:"52px",height:"54px",minHeight:"54px",transform:"translateY(-2px)",padding:"0",border:"none",boxShadow:e.trim()&&!r?`0 4px 12px -2px ${n.secondary}40`:"0 2px 4px -1px rgba(0, 0, 0, 0.1)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,position:"relative"},"aria-label":"Send message",children:[R.jsx("div",{className:"absolute inset-0 opacity-0 transition-opacity duration-300 group-hover:opacity-100",style:{background:"linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0))"}}),R.jsx("div",{className:"absolute inset-0 flex items-center justify-center",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%"},children:R.jsx(rc,{size:he.BUTTON_SIZES.ICON_SIZES.SEND,className:"transition-transform duration-200 group-hover:translate-x-0.5 drop-shadow-sm",style:{display:"block",strokeWidth:2,transform:"translate(0.5px, -0.5px)"}})})]})]})]}),Jn=e=>{var ct,or;const[t,r]=J.useState(!1),[n,i]=J.useState(!1),[a,l]=J.useState(!1),[o,s]=J.useState(null),{isAnimating:u,typingProgressRef:f,isTypingRef:h,lastMessageRef:d,markMessageAnimated:p,hasBeenAnimated:v,clearAnimationTrackers:b,setIsAnimating:E}=Dc(),{showScrollTop:w,showScrollBottom:C,messagesContainerRef:z,messagesEndRef:D,shouldScrollRef:B,scrollTimeoutRef:I,scrollToBottom:P,scrollToTop:X,handleScroll:H}=Lc(u),[N,V]=J.useState(window.innerWidth);J.useEffect(()=>{const je=()=>V(window.innerWidth);return window.addEventListener("resize",je),()=>window.removeEventListener("resize",je)},[]);const G=ur(),[le,ie]=J.useState({...G,...e}),K=le.theme||Ma;J.useEffect(()=>{e.apiUrl&&e.apiKey&&e.sessionId&&Sr(e.apiUrl,e.apiKey,e.sessionId)},[e.apiUrl,e.apiKey,e.sessionId]),J.useEffect(()=>{const je=Ct=>{ie(Ct.detail)};return window.addEventListener("chatbot-config-update",je),()=>{window.removeEventListener("chatbot-config-update",je)}},[]),J.useEffect(()=>{e&&ie(je=>({...je,...e}))},[e]),J.useEffect(()=>{Nc({MAX_SUGGESTED_QUESTION_LENGTH:e.maxSuggestedQuestionLength??he.MAX_SUGGESTED_QUESTION_LENGTH,MAX_SUGGESTED_QUESTION_QUERY_LENGTH:e.maxSuggestedQuestionQueryLength??he.MAX_SUGGESTED_QUESTION_QUERY_LENGTH})},[e.maxSuggestedQuestionLength,e.maxSuggestedQuestionQueryLength]);const{messages:pe,isLoading:be,sendMessage:Ie,clearMessages:Ve}=di(),{message:S,isFocused:Me,inputRef:ke,handleMessageChange:A,handleKeyDown:He,handleSendMessage:Ge,setIsFocused:Ne,focusInput:We}=Bc({onSendMessage:je=>{B.current=!0,Ie(je),setTimeout(()=>P(!0),he.ANIMATIONS.TOGGLE_DELAY)},isLoading:be,isOpen:t});J.useEffect(()=>{pe.length===0&&b()},[pe.length,b]);const De=()=>{r(!t),t||(i(!1),setTimeout(()=>P(!0),he.ANIMATIONS.TOGGLE_DELAY))},Ye=async(je,Ct)=>{try{await navigator.clipboard.writeText(je),s(Ct),setTimeout(()=>{s(null)},he.ANIMATIONS.COPY_FEEDBACK_DURATION)}catch($t){console.error("Failed to copy text: ",$t)}},$e=je=>je.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return J.useEffect(()=>{(be||pe.length===0)&&P(!0)},[pe,be,P]),J.useEffect(()=>()=>{I.current&&clearTimeout(I.current)},[I]),R.jsxs("div",{className:"fixed bottom-8 right-8 z-50 flex flex-col items-end font-sans",style:{fontFamily:zc},children:[t&&R.jsxs("div",{className:"mb-4 w-full rounded-2xl shadow-elegant flex flex-col overflow-hidden border-0 transition-all duration-300 ease-in-out animate-slide-in-up backdrop-blur-lg",style:{background:`linear-gradient(145deg, ${K.background}, ${K.background}f0)`,height:he.WINDOW_DIMENSIONS.HEIGHT,maxHeight:he.WINDOW_DIMENSIONS.MAX_HEIGHT,width:Cc(N),minWidth:Mc(N),backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",border:"1px solid rgba(255, 255, 255, 0.2)",boxShadow:`
|
|
752
752
|
0 25px 50px -12px rgba(0, 0, 0, 0.15),
|
|
753
753
|
0 0 0 1px rgba(255, 255, 255, 0.1),
|
|
754
754
|
inset 0 1px 0 rgba(255, 255, 255, 0.1)
|