@gauravrathod674/super-customizable-chatbot 0.1.2 → 0.3.1

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.
@@ -0,0 +1,776 @@
1
+ import { jsx as e, jsxs as u } from "react/jsx-runtime";
2
+ import { useState as S, useRef as j, useMemo as M, useEffect as D, useCallback as we } from "react";
3
+ import { AnimatePresence as Q, motion as C } from "framer-motion";
4
+ import { FontAwesomeIcon as $e } from "@fortawesome/react-fontawesome";
5
+ import { faCommentDots as Ie } from "@fortawesome/free-solid-svg-icons";
6
+ import { GoogleGenerativeAI as Se } from "@google/generative-ai";
7
+ import De from "openai";
8
+ import ze from "@anthropic-ai/sdk";
9
+ import Ee from "groq-sdk";
10
+ import T from "react-markdown";
11
+ const Le = () => /* @__PURE__ */ u(
12
+ "svg",
13
+ {
14
+ viewBox: "0 0 24 24",
15
+ fill: "none",
16
+ stroke: "currentColor",
17
+ strokeWidth: "1.5",
18
+ className: "w-full h-full",
19
+ children: [
20
+ /* @__PURE__ */ e("path", { d: "M12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4Z" }),
21
+ /* @__PURE__ */ e(
22
+ "path",
23
+ {
24
+ d: "M16.5 14C16.5 14 15 15.5 12 15.5C9 15.5 7.5 14 7.5 14",
25
+ strokeLinecap: "round"
26
+ }
27
+ ),
28
+ /* @__PURE__ */ e("circle", { cx: "9", cy: "10", r: "1", fill: "currentColor" }),
29
+ /* @__PURE__ */ e("circle", { cx: "15", cy: "10", r: "1", fill: "currentColor" })
30
+ ]
31
+ }
32
+ ), Re = () => /* @__PURE__ */ u(
33
+ "svg",
34
+ {
35
+ viewBox: "0 0 24 24",
36
+ fill: "none",
37
+ stroke: "currentColor",
38
+ strokeWidth: "1.5",
39
+ className: "w-full h-full",
40
+ children: [
41
+ /* @__PURE__ */ e(
42
+ "path",
43
+ {
44
+ d: "M12 12C14.2091 12 16 10.2091 16 8C16 5.79086 14.2091 4 12 4C9.79086 4 8 5.79086 8 8C8 10.2091 9.79086 12 12 12Z",
45
+ strokeLinecap: "round"
46
+ }
47
+ ),
48
+ /* @__PURE__ */ e(
49
+ "path",
50
+ {
51
+ d: "M19.21 17.14C19.21 17.14 19 19 12 19C5 19 4.79 17.14 4.79 17.14C4.79 17.14 6.33 15 12 15C17.67 15 19.21 17.14 19.21 17.14Z",
52
+ strokeLinecap: "round"
53
+ }
54
+ )
55
+ ]
56
+ }
57
+ ), Ae = () => /* @__PURE__ */ u(
58
+ "svg",
59
+ {
60
+ fill: "none",
61
+ viewBox: "0 0 24 24",
62
+ strokeWidth: 1.5,
63
+ stroke: "currentColor",
64
+ className: "w-5 h-5",
65
+ children: [
66
+ /* @__PURE__ */ e(
67
+ "path",
68
+ {
69
+ strokeLinecap: "round",
70
+ strokeLinejoin: "round",
71
+ d: "M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.875L6 12z"
72
+ }
73
+ ),
74
+ /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 12h9" })
75
+ ]
76
+ }
77
+ ), Fe = () => /* @__PURE__ */ u("div", { className: "flex items-center space-x-1 p-3", children: [
78
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.3s]" }),
79
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.15s]" }),
80
+ /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse" })
81
+ ] }), Oe = ({ fullText: c, onComplete: d, components: b }) => {
82
+ const a = typeof c == "string" ? c : "", [$, r] = S("");
83
+ return D(() => {
84
+ if (a.length === 0) {
85
+ d == null || d();
86
+ return;
87
+ }
88
+ let w = 0;
89
+ r("");
90
+ const h = setInterval(() => {
91
+ if (w < a.length) {
92
+ const g = a.charAt(w);
93
+ r((R) => R + g), w++;
94
+ } else
95
+ clearInterval(h), d == null || d();
96
+ }, 25);
97
+ return () => clearInterval(h);
98
+ }, [a, d]), /* @__PURE__ */ e(
99
+ "div",
100
+ {
101
+ className: "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5",
102
+ style: { color: "inherit" },
103
+ children: /* @__PURE__ */ e(T, { components: b, children: $ || "" })
104
+ }
105
+ );
106
+ }, Pe = ({ text: c, animationType: d, components: b }) => {
107
+ const a = "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5";
108
+ switch (d) {
109
+ case "typing":
110
+ return /* @__PURE__ */ e(Oe, { fullText: c, components: b });
111
+ case "fade-in":
112
+ return /* @__PURE__ */ e(
113
+ C.div,
114
+ {
115
+ initial: { opacity: 0, y: 10 },
116
+ animate: { opacity: 1, y: 0 },
117
+ transition: { duration: 1.5, ease: "easeOut" },
118
+ children: /* @__PURE__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
119
+ }
120
+ );
121
+ case "slide-up":
122
+ return /* @__PURE__ */ e(
123
+ C.div,
124
+ {
125
+ initial: { y: 50, opacity: 0 },
126
+ animate: { y: 0, opacity: 1 },
127
+ transition: { duration: 0.7, ease: "anticipate" },
128
+ children: /* @__PURE__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
129
+ }
130
+ );
131
+ case "zoom-in":
132
+ return /* @__PURE__ */ e(
133
+ C.div,
134
+ {
135
+ initial: { scale: 0.5, opacity: 0 },
136
+ animate: { scale: 1, opacity: 1 },
137
+ transition: { duration: 1, ease: "backOut" },
138
+ children: /* @__PURE__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
139
+ }
140
+ );
141
+ case "flip":
142
+ return /* @__PURE__ */ e(
143
+ C.div,
144
+ {
145
+ initial: { rotateX: -90, opacity: 0 },
146
+ animate: { rotateX: 0, opacity: 1 },
147
+ transition: { duration: 1, ease: "easeOut" },
148
+ style: { transformPerspective: 400 },
149
+ children: /* @__PURE__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
150
+ }
151
+ );
152
+ default:
153
+ return /* @__PURE__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) });
154
+ }
155
+ }, je = (c) => {
156
+ const d = [];
157
+ if (!c || c.length === 0)
158
+ return d;
159
+ let a = c.reduce((r, w) => {
160
+ const h = r.length > 0 ? r[r.length - 1] : null;
161
+ if (h && h.sender === w.sender) {
162
+ const g = {
163
+ ...h,
164
+ text: `${h.text}
165
+ ${w.text}`
166
+ };
167
+ r[r.length - 1] = g;
168
+ } else
169
+ r.push({ ...w });
170
+ return r;
171
+ }, []).map((r) => ({
172
+ role: r.sender === "bot" ? "model" : "user",
173
+ parts: [{ text: r.text }]
174
+ }));
175
+ const $ = a.findIndex((r) => r.role === "user");
176
+ if ($ > -1)
177
+ a = a.slice($);
178
+ else
179
+ return [];
180
+ return a;
181
+ }, Qe = ({
182
+ botName: c = "ChatBot",
183
+ botAvatar: d = /* @__PURE__ */ e(Le, {}),
184
+ userAvatar: b = /* @__PURE__ */ e(Re, {}),
185
+ welcomeMessage: a = "Hello! How can I help?",
186
+ placeholderText: $ = "Type a message...",
187
+ customInstruction: r = "",
188
+ isOpen: w = !1,
189
+ disabled: h = !1,
190
+ isTyping: g = !1,
191
+ onSend: R = () => {
192
+ },
193
+ theme: y = {},
194
+ geminiApiKey: W,
195
+ geminiModelName: K = "gemini-1.5-flash",
196
+ openaiApiKey: G,
197
+ openaiModelName: ee = "gpt-4o-mini",
198
+ anthropicApiKey: H,
199
+ anthropicModelName: oe = "claude-3-haiku-20240307",
200
+ grokApiKey: q,
201
+ grokModelName: te = "llama3-8b-8192",
202
+ messages: re
203
+ }) => {
204
+ const [k] = S(
205
+ () => `chatbot-instance-${Math.random().toString(36).substring(2, 9)}`
206
+ ), [N, A] = S(w), [ye, xe] = S(() => a ? [{ id: 1, text: a, sender: "bot" }] : []), [F, se] = S(""), [O, f] = S(!1), z = typeof re < "u", v = z ? re : ye, m = z ? () => {
207
+ } : xe, ne = j(null), ae = j(null), le = j(null), ve = j(null), U = M(() => {
208
+ if (!W) return null;
209
+ try {
210
+ return new Se(W).getGenerativeModel({
211
+ model: K,
212
+ systemInstruction: r
213
+ });
214
+ } catch (o) {
215
+ return console.error("Failed to initialize Gemini:", o), null;
216
+ }
217
+ }, [W, K, r]), V = M(() => G ? new De({ apiKey: G, dangerouslyAllowBrowser: !0 }) : null, [G]), Z = M(() => H ? new ze({
218
+ apiKey: H,
219
+ dangerouslyAllowBrowser: !0
220
+ }) : null, [H]), X = M(() => q ? new Ee({ apiKey: q, dangerouslyAllowBrowser: !0 }) : null, [q]), t = M(() => {
221
+ var l;
222
+ const o = ((l = y == null ? void 0 : y.window) == null ? void 0 : l.placement) === "center", s = {
223
+ launcher: {
224
+ backgroundColor: "#4f46e5",
225
+ iconColor: "#ffffff",
226
+ size: "3.5rem"
227
+ },
228
+ header: {
229
+ backgroundColor: "#4f46e5",
230
+ textColor: "#ffffff",
231
+ fontFamily: "inherit",
232
+ fontWeight: "600"
233
+ },
234
+ messages: {
235
+ userBackgroundColor: "#4f46e5",
236
+ userTextColor: "#ffffff",
237
+ botBackgroundColor: "#f3f4f6",
238
+ botTextColor: "#1f2937",
239
+ fontFamily: "inherit",
240
+ fontSize: "0.9rem",
241
+ showAvatars: !0,
242
+ bubbleShape: "rounded",
243
+ bubblePointer: !0,
244
+ animation: "fade-in",
245
+ markdownStyles: {}
246
+ },
247
+ input: {
248
+ backgroundColor: "#ffffff",
249
+ textColor: "#1f2937",
250
+ placeholderTextColor: "#9ca3af",
251
+ borderColor: "#e5e7eb",
252
+ focusRingColor: "#4f46e5"
253
+ },
254
+ window: {
255
+ backgroundColor: "#ffffff",
256
+ borderColor: "#e5e7eb",
257
+ borderRadius: "0.75rem",
258
+ width: o ? "80vw" : "22rem",
259
+ height: o ? "80vh" : "30rem",
260
+ placement: "bottom-right",
261
+ backdrop: !1,
262
+ backdropColor: "rgba(0, 0, 0, 0.4)",
263
+ backdropBlur: "4px",
264
+ scrollbarThumbColor: "#a1a1aa",
265
+ // neutral-400
266
+ scrollbarTrackColor: "#f1f5f9"
267
+ // slate-100
268
+ }
269
+ };
270
+ return {
271
+ launcher: { ...s.launcher, ...y.launcher },
272
+ header: { ...s.header, ...y.header },
273
+ messages: { ...s.messages, ...y.messages },
274
+ input: { ...s.input, ...y.input },
275
+ window: { ...s.window, ...y.window }
276
+ };
277
+ }, [y]), Ce = M(
278
+ () => ({
279
+ // Launcher
280
+ "--chatbot-launcher-bg": t.launcher.backgroundColor,
281
+ "--chatbot-launcher-icon-color": t.launcher.iconColor,
282
+ "--chatbot-launcher-size": t.launcher.size,
283
+ // Header
284
+ "--chatbot-header-bg": t.header.backgroundColor,
285
+ "--chatbot-header-text-color": t.header.textColor,
286
+ "--chatbot-header-font-family": t.header.fontFamily,
287
+ "--chatbot-header-font-weight": t.header.fontWeight,
288
+ // Messages
289
+ "--chatbot-user-msg-bg": t.messages.userBackgroundColor,
290
+ "--chatbot-user-msg-text-color": t.messages.userTextColor,
291
+ "--chatbot-bot-msg-bg": t.messages.botBackgroundColor,
292
+ "--chatbot-bot-msg-text-color": t.messages.botTextColor,
293
+ "--chatbot-msg-font-family": t.messages.fontFamily,
294
+ "--chatbot-msg-font-size": t.messages.fontSize,
295
+ // Input
296
+ "--chatbot-input-bg": t.input.backgroundColor,
297
+ "--chatbot-input-text-color": t.input.textColor,
298
+ "--chatbot-input-placeholder-color": t.input.placeholderTextColor,
299
+ "--chatbot-input-border-color": t.input.borderColor,
300
+ "--chatbot-input-focus-ring": t.input.focusRingColor,
301
+ // Window
302
+ "--chatbot-window-bg": t.window.backgroundColor,
303
+ "--chatbot-window-border-color": t.window.borderColor,
304
+ "--chatbot-window-border-radius": t.window.borderRadius,
305
+ "--chatbot-window-width": t.window.width,
306
+ "--chatbot-window-height": t.window.height
307
+ }),
308
+ [t]
309
+ ), ie = M(() => {
310
+ const o = t.messages.markdownStyles || {};
311
+ return {
312
+ strong: ({ node: s, ...l }) => /* @__PURE__ */ e("strong", { style: { color: o.boldColor || "inherit" }, ...l }),
313
+ em: ({ node: s, ...l }) => /* @__PURE__ */ e("em", { style: { color: o.italicColor || "inherit" }, ...l }),
314
+ a: ({ node: s, ...l }) => /* @__PURE__ */ e("a", { style: { color: o.linkColor || "#3b82f6" }, ...l }),
315
+ code: ({ node: s, ...l }) => /* @__PURE__ */ e(
316
+ "code",
317
+ {
318
+ style: {
319
+ color: o.codeColor || "inherit",
320
+ backgroundColor: o.codeBackgroundColor || "rgba(0, 0, 0, 0.1)",
321
+ padding: "0.1rem 0.3rem",
322
+ borderRadius: "0.25rem"
323
+ },
324
+ ...l
325
+ }
326
+ )
327
+ };
328
+ }, [t.messages.markdownStyles]);
329
+ D(() => {
330
+ var E;
331
+ const o = t.window.scrollbarThumbColor, s = t.window.scrollbarTrackColor, l = `scrollbar-style-${k}`;
332
+ (E = document.getElementById(l)) == null || E.remove();
333
+ const I = document.createElement("style");
334
+ return I.id = l, I.innerHTML = `
335
+ /* Modern browsers */
336
+ #${k} .chatbot-message-list {
337
+ scrollbar-width: thin;
338
+ scrollbar-color: ${o} ${s};
339
+ }
340
+ /* WebKit-based browsers (Chrome, Safari, Edge) */
341
+ #${k} .chatbot-message-list::-webkit-scrollbar {
342
+ width: 8px;
343
+ }
344
+ #${k} .chatbot-message-list::-webkit-scrollbar-track {
345
+ background: ${s};
346
+ border-radius: 4px;
347
+ }
348
+ #${k} .chatbot-message-list::-webkit-scrollbar-thumb {
349
+ background-color: ${o};
350
+ border-radius: 4px;
351
+ border: 2px solid ${s};
352
+ }
353
+ `, document.head.appendChild(I), () => {
354
+ var L;
355
+ (L = document.getElementById(l)) == null || L.remove();
356
+ };
357
+ }, [
358
+ k,
359
+ t.window.scrollbarThumbColor,
360
+ t.window.scrollbarTrackColor
361
+ ]), D(() => {
362
+ f(g);
363
+ }, [g]), D(() => {
364
+ var o;
365
+ (o = ae.current) == null || o.scrollIntoView({ behavior: "smooth" });
366
+ }, [v, O, g]), D(() => {
367
+ var o, s;
368
+ N ? (o = ne.current) == null || o.focus() : (s = le.current) == null || s.focus();
369
+ }, [N]), D(() => {
370
+ const o = (s) => {
371
+ s.key === "Escape" && N && A(!1);
372
+ };
373
+ return window.addEventListener("keydown", o), () => window.removeEventListener("keydown", o);
374
+ }, [N]);
375
+ const Y = we(async () => {
376
+ var I, E, L, de, ue, he, be, fe, me, ge, pe;
377
+ const o = F.trim();
378
+ if (!o || h || O || g) return;
379
+ const s = {
380
+ id: Date.now(),
381
+ text: o,
382
+ sender: "user"
383
+ }, l = [...v, s];
384
+ if (z || m((n) => [...n, s]), R(o), se(""), U) {
385
+ f(!0);
386
+ try {
387
+ const n = je(l), i = n.slice(0, -1), B = ((E = (I = n[n.length - 1]) == null ? void 0 : I.parts[0]) == null ? void 0 : E.text) || "", Be = await (await (await U.startChat({ history: i }).sendMessage(B)).response).text() || "(no response)", Me = { id: Date.now() + 1, text: Be, sender: "bot" };
388
+ m((Te) => [...Te, Me]);
389
+ } catch (n) {
390
+ console.error("Gemini API Error:", n);
391
+ const i = {
392
+ id: Date.now() + 1,
393
+ text: "Sorry, an error occurred. Please try again.",
394
+ sender: "bot"
395
+ };
396
+ m((B) => [...B, i]);
397
+ } finally {
398
+ f(!1);
399
+ }
400
+ } else if (V) {
401
+ f(!0);
402
+ try {
403
+ const n = r ? [{ role: "system", content: r }] : [], i = v.map((p) => ({
404
+ role: p.sender === "bot" ? "assistant" : "user",
405
+ content: p.text
406
+ })), x = ((he = (ue = (de = (L = (await V.chat.completions.create({
407
+ model: ee,
408
+ messages: [
409
+ ...n,
410
+ ...i,
411
+ { role: "user", content: o }
412
+ ]
413
+ })).choices) == null ? void 0 : L[0]) == null ? void 0 : de.message) == null ? void 0 : ue.content) == null ? void 0 : he.trim()) || "(no response)";
414
+ m((p) => [
415
+ ...p,
416
+ { id: Date.now() + 1, text: x, sender: "bot" }
417
+ ]);
418
+ } catch (n) {
419
+ console.error("OpenAI Error:", n), m((i) => [
420
+ ...i,
421
+ {
422
+ id: Date.now() + 1,
423
+ text: "Sorry, something went wrong with OpenAI.",
424
+ sender: "bot"
425
+ }
426
+ ]);
427
+ } finally {
428
+ f(!1);
429
+ }
430
+ } else if (Z) {
431
+ f(!0);
432
+ try {
433
+ const n = v.map((x) => ({
434
+ role: x.sender === "bot" ? "assistant" : "user",
435
+ content: x.text
436
+ })), B = ((fe = (be = (await Z.messages.create({
437
+ model: oe,
438
+ system: r,
439
+ // Pass instruction to the dedicated 'system' parameter
440
+ messages: [
441
+ ...n,
442
+ { role: "user", content: o }
443
+ ],
444
+ max_tokens: 1024
445
+ })).content[0]) == null ? void 0 : be.text) == null ? void 0 : fe.trim()) || "(no response)";
446
+ m((x) => [
447
+ ...x,
448
+ { id: Date.now() + 1, text: B, sender: "bot" }
449
+ ]);
450
+ } catch (n) {
451
+ console.error("Anthropic API Error:", n), m((i) => [
452
+ ...i,
453
+ {
454
+ id: Date.now() + 1,
455
+ text: "Sorry, an error occurred with Claude.",
456
+ sender: "bot"
457
+ }
458
+ ]);
459
+ } finally {
460
+ f(!1);
461
+ }
462
+ } else if (X) {
463
+ f(!0);
464
+ try {
465
+ const n = r ? [{ role: "system", content: r }] : [], i = v.map((p) => ({
466
+ role: p.sender === "bot" ? "assistant" : "user",
467
+ content: p.text
468
+ })), x = ((pe = (ge = (me = (await X.chat.completions.create({
469
+ messages: [
470
+ ...n,
471
+ ...i,
472
+ { role: "user", content: o }
473
+ ],
474
+ model: te
475
+ })).choices[0]) == null ? void 0 : me.message) == null ? void 0 : ge.content) == null ? void 0 : pe.trim()) || "(no response)";
476
+ m((p) => [
477
+ ...p,
478
+ { id: Date.now() + 1, text: x, sender: "bot" }
479
+ ]);
480
+ } catch (n) {
481
+ console.error("Groq API Error:", n), m((i) => [
482
+ ...i,
483
+ {
484
+ id: Date.now() + 1,
485
+ text: "Sorry, an error occurred with Groq.",
486
+ sender: "bot"
487
+ }
488
+ ]);
489
+ } finally {
490
+ f(!1);
491
+ }
492
+ } else z || (f(!0), setTimeout(() => {
493
+ const n = {
494
+ id: Date.now() + 1,
495
+ text: `You said: "${o}"`,
496
+ sender: "bot"
497
+ };
498
+ m((i) => [...i, n]), f(!1);
499
+ }, 800));
500
+ }, [
501
+ F,
502
+ h,
503
+ O,
504
+ g,
505
+ R,
506
+ U,
507
+ V,
508
+ Z,
509
+ X,
510
+ z,
511
+ v,
512
+ m,
513
+ ee,
514
+ oe,
515
+ te,
516
+ r
517
+ // Add to dependency array
518
+ ]), ke = we(
519
+ (o) => {
520
+ o.key === "Enter" && Y();
521
+ },
522
+ [Y]
523
+ ), _ = (o) => typeof o == "string" ? /* @__PURE__ */ e(
524
+ "img",
525
+ {
526
+ src: o,
527
+ alt: "avatar",
528
+ className: "w-8 h-8 rounded-full object-cover"
529
+ }
530
+ ) : /* @__PURE__ */ e("div", { className: "w-8 h-8 rounded-full text-gray-500", children: o }), J = O || g, ce = {
531
+ "bottom-right": "bottom-5 right-5",
532
+ "bottom-left": "bottom-5 left-5",
533
+ center: "top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"
534
+ }, Ne = t.window.placement === "center", P = {
535
+ rounded: "rounded-xl",
536
+ square: "rounded-md"
537
+ };
538
+ return /* @__PURE__ */ u("div", { id: k, style: Ce, className: "font-sans", children: [
539
+ /* @__PURE__ */ e(Q, { children: !N && /* @__PURE__ */ e(
540
+ C.button,
541
+ {
542
+ ref: le,
543
+ onClick: () => A(!0),
544
+ "aria-label": "Open Chat",
545
+ initial: { scale: 0, opacity: 0 },
546
+ animate: { scale: 1, opacity: 1 },
547
+ exit: { scale: 0, opacity: 0 },
548
+ transition: { duration: 0.2, ease: "easeOut" },
549
+ className: "fixed bottom-10 right-10 z-50 rounded-full shadow-lg flex items-center justify-center cursor-pointer border-2 border-white/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-[--chatbot-launcher-bg]",
550
+ style: {
551
+ backgroundColor: "var(--chatbot-launcher-bg)",
552
+ color: "var(--chatbot-launcher-icon-color)",
553
+ width: "var(--chatbot-launcher-size)",
554
+ height: "var(--chatbot-launcher-size)"
555
+ },
556
+ children: /* @__PURE__ */ e($e, { icon: Ie })
557
+ }
558
+ ) }),
559
+ /* @__PURE__ */ u(Q, { children: [
560
+ N && Ne && t.window.backdrop && /* @__PURE__ */ e(
561
+ C.div,
562
+ {
563
+ initial: { opacity: 0 },
564
+ animate: { opacity: 1 },
565
+ exit: { opacity: 0 },
566
+ style: {
567
+ backgroundColor: t.window.backdropColor,
568
+ backdropFilter: `blur(${t.window.backdropBlur})`,
569
+ // For Safari compatibility
570
+ WebkitBackdropFilter: `blur(${t.window.backdropBlur})`
571
+ },
572
+ className: "fixed inset-0 z-40",
573
+ onClick: () => A(!1)
574
+ },
575
+ "chatbot-backdrop"
576
+ ),
577
+ N && /* @__PURE__ */ u(
578
+ "div",
579
+ {
580
+ ref: ve,
581
+ "aria-modal": "true",
582
+ role: "dialog",
583
+ className: `fixed ${ce[t.window.placement] || ce["bottom-right"]} z-50 flex flex-col overflow-hidden shadow-2xl border`,
584
+ style: {
585
+ width: "var(--chatbot-window-width)",
586
+ height: "var(--chatbot-window-height)",
587
+ borderRadius: "var(--chatbot-window-border-radius)",
588
+ backgroundColor: "var(--chatbot-window-bg)",
589
+ borderColor: "var(--chatbot-window-border-color)"
590
+ },
591
+ children: [
592
+ /* @__PURE__ */ u(
593
+ "header",
594
+ {
595
+ className: "flex items-center justify-between p-3 flex-shrink-0",
596
+ style: {
597
+ background: "var(--chatbot-header-bg)",
598
+ color: "var(--chatbot-header-text-color)"
599
+ },
600
+ children: [
601
+ /* @__PURE__ */ u("div", { className: "flex items-center space-x-3", children: [
602
+ /* @__PURE__ */ e("div", { className: "w-10 h-10 rounded-full bg-white/30 flex items-center justify-center p-1", children: _(d) }),
603
+ /* @__PURE__ */ e(
604
+ "span",
605
+ {
606
+ style: {
607
+ fontFamily: "var(--chatbot-header-font-family)",
608
+ fontWeight: "var(--chatbot-header-font-weight)"
609
+ },
610
+ className: "text-lg",
611
+ children: c
612
+ }
613
+ )
614
+ ] }),
615
+ /* @__PURE__ */ e(
616
+ "button",
617
+ {
618
+ onClick: () => A(!1),
619
+ "aria-label": "Close Chat",
620
+ className: "p-1 rounded-full hover:bg-white/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-white",
621
+ children: /* @__PURE__ */ e(
622
+ "svg",
623
+ {
624
+ xmlns: "http://www.w3.org/2000/svg",
625
+ fill: "none",
626
+ viewBox: "0 0 24 24",
627
+ strokeWidth: 2,
628
+ stroke: "currentColor",
629
+ className: "w-6 h-6",
630
+ children: /* @__PURE__ */ e(
631
+ "path",
632
+ {
633
+ strokeLinecap: "round",
634
+ strokeLinejoin: "round",
635
+ d: "M6 18L18 6M6 6l12 12"
636
+ }
637
+ )
638
+ }
639
+ )
640
+ }
641
+ )
642
+ ]
643
+ }
644
+ ),
645
+ /* @__PURE__ */ u(
646
+ "div",
647
+ {
648
+ role: "log",
649
+ "aria-live": "polite",
650
+ className: "chatbot-message-list flex-1 p-4 overflow-y-auto space-y-4",
651
+ children: [
652
+ /* @__PURE__ */ e(Q, { initial: !1, children: v.map((o, s) => /* @__PURE__ */ u(
653
+ C.div,
654
+ {
655
+ layout: !0,
656
+ initial: { opacity: 0, y: 20 },
657
+ animate: { opacity: 1, y: 0 },
658
+ exit: { opacity: 0, y: -10 },
659
+ transition: { duration: 0.3, ease: "easeOut" },
660
+ className: `flex items-end max-w-[85%] gap-2 ${o.sender === "user" ? "ml-auto flex-row-reverse" : "mr-auto"}`,
661
+ children: [
662
+ t.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: _(
663
+ o.sender === "user" ? b : d
664
+ ) }),
665
+ /* @__PURE__ */ e(
666
+ C.div,
667
+ {
668
+ layout: "position",
669
+ transition: { duration: 0.2, ease: "easeOut" },
670
+ className: `px-3 py-2 ${P[t.messages.bubbleShape] || P.rounded} ${t.messages.bubblePointer ? o.sender === "user" ? "rounded-br-none" : "rounded-bl-none" : ""}`,
671
+ style: {
672
+ backgroundColor: o.sender === "user" ? "var(--chatbot-user-msg-bg)" : "var(--chatbot-bot-msg-bg)",
673
+ color: o.sender === "user" ? "var(--chatbot-user-msg-text-color)" : "var(--chatbot-bot-msg-text-color)",
674
+ fontFamily: "var(--chatbot-msg-font-family)",
675
+ fontSize: "var(--chatbot-msg-font-size)"
676
+ },
677
+ children: o.sender === "bot" && s === v.length - 1 ? /* @__PURE__ */ e(
678
+ Pe,
679
+ {
680
+ text: o.text,
681
+ animationType: t.messages.animation,
682
+ components: ie
683
+ }
684
+ ) : /* @__PURE__ */ e(
685
+ "div",
686
+ {
687
+ className: "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5",
688
+ style: { color: "inherit" },
689
+ children: /* @__PURE__ */ e(T, { components: ie, children: o.text })
690
+ }
691
+ )
692
+ }
693
+ )
694
+ ]
695
+ },
696
+ o.id
697
+ )) }),
698
+ J && /* @__PURE__ */ u(
699
+ "div",
700
+ {
701
+ className: "flex items-end max-w-[85%] gap-2 mr-auto",
702
+ children: [
703
+ " ",
704
+ t.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: _(d) }),
705
+ /* @__PURE__ */ e(
706
+ "div",
707
+ {
708
+ className: `px-3 py-2 ${P[t.messages.bubbleShape] || P.rounded} rounded-bl-none`,
709
+ style: { backgroundColor: "var(--chatbot-bot-msg-bg)" },
710
+ children: /* @__PURE__ */ e(Fe, {})
711
+ }
712
+ )
713
+ ]
714
+ },
715
+ "typing-indicator"
716
+ ),
717
+ /* @__PURE__ */ e("div", { ref: ae })
718
+ ]
719
+ }
720
+ ),
721
+ /* @__PURE__ */ e(
722
+ "footer",
723
+ {
724
+ className: "p-3 border-t flex-shrink-0",
725
+ style: {
726
+ borderColor: "var(--chatbot-window-border-color)",
727
+ backgroundColor: "var(--chatbot-input-bg)"
728
+ },
729
+ children: /* @__PURE__ */ u("div", { className: "flex items-center space-x-2", children: [
730
+ /* @__PURE__ */ e(
731
+ "input",
732
+ {
733
+ ref: ne,
734
+ type: "text",
735
+ value: F,
736
+ onChange: (o) => se(o.target.value),
737
+ onKeyPress: ke,
738
+ placeholder: $,
739
+ disabled: h || J,
740
+ "aria-label": "Chat input",
741
+ className: "flex-1 w-full px-4 py-2 bg-transparent rounded-full border focus:outline-none focus:ring-2 disabled:cursor-not-allowed disabled:opacity-60",
742
+ style: {
743
+ color: "var(--chatbot-input-text-color)",
744
+ borderColor: "var(--chatbot-input-border-color)",
745
+ "--tw-ring-color": "var(--chatbot-input-focus-ring)"
746
+ }
747
+ }
748
+ ),
749
+ /* @__PURE__ */ e(
750
+ "button",
751
+ {
752
+ onClick: Y,
753
+ disabled: !F.trim() || h || J,
754
+ "aria-label": "Send Message",
755
+ className: "px-4 h-10 rounded-full flex items-center justify-center flex-shrink-0 font-semibold text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
756
+ style: {
757
+ backgroundColor: "var(--chatbot-user-msg-bg)",
758
+ color: "var(--chatbot-user-msg-text-color)",
759
+ "--tw-ring-color": "var(--chatbot-user-msg-bg)"
760
+ },
761
+ children: /* @__PURE__ */ e(Ae, {})
762
+ }
763
+ )
764
+ ] })
765
+ }
766
+ )
767
+ ]
768
+ },
769
+ "chatbot-window"
770
+ )
771
+ ] })
772
+ ] });
773
+ };
774
+ export {
775
+ Qe as ChatBot
776
+ };