claudius-chat-widget 1.6.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -0
  3. package/dist/api/client.d.ts +24 -0
  4. package/dist/api/errors.d.ts +9 -0
  5. package/dist/api/index.d.ts +4 -0
  6. package/dist/api/types.d.ts +22 -0
  7. package/dist/claudius.cjs +2 -0
  8. package/dist/claudius.css +1 -0
  9. package/dist/claudius.iife.js +41 -0
  10. package/dist/claudius.js +1373 -0
  11. package/dist/components/ChatInput.d.ts +9 -0
  12. package/dist/components/ChatMessage.d.ts +10 -0
  13. package/dist/components/ChatSources.d.ts +7 -0
  14. package/dist/components/ChatToggleButton.d.ts +10 -0
  15. package/dist/components/ChatWidget.d.ts +29 -0
  16. package/dist/components/ChatWindow.d.ts +21 -0
  17. package/dist/components/GreetingBubble.d.ts +10 -0
  18. package/dist/components/SourceIcon.d.ts +7 -0
  19. package/dist/embed.d.ts +38 -0
  20. package/dist/hooks/useChat.d.ts +20 -0
  21. package/dist/hooks/useFocusTrap.d.ts +2 -0
  22. package/dist/hooks/useMediaQuery.d.ts +1 -0
  23. package/dist/hooks/useSwipeToDismiss.d.ts +4 -0
  24. package/dist/hooks/useTriggers.d.ts +32 -0
  25. package/dist/i18n.d.ts +21 -0
  26. package/dist/index.d.ts +12 -0
  27. package/dist/locales/de.d.ts +2 -0
  28. package/dist/locales/en.d.ts +2 -0
  29. package/dist/locales/es.d.ts +2 -0
  30. package/dist/locales/fr.d.ts +2 -0
  31. package/dist/locales/index.d.ts +9 -0
  32. package/dist/main.d.ts +1 -0
  33. package/dist/test-utils/MockChatApiClient.d.ts +64 -0
  34. package/dist/theme/index.d.ts +4 -0
  35. package/dist/theme/resolve.d.ts +19 -0
  36. package/dist/theme/themes.d.ts +8 -0
  37. package/dist/theme/types.d.ts +34 -0
  38. package/dist/theme/useTheme.d.ts +14 -0
  39. package/dist/utils/sanitize.d.ts +36 -0
  40. package/dist/utils/stripAnnouncementFormatting.d.ts +1 -0
  41. package/package.json +102 -0
@@ -0,0 +1,1373 @@
1
+ var ye = Object.defineProperty;
2
+ var we = (t, e, r) => e in t ? ye(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var $ = (t, e, r) => we(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { jsx as i, jsxs as d, Fragment as ve } from "react/jsx-runtime";
5
+ import { useMemo as F, useState as C, useRef as N, useCallback as R, useEffect as k, forwardRef as Ee, memo as K, useId as Re } from "react";
6
+ class U extends Error {
7
+ constructor(e, r, s, n) {
8
+ super(e), this.status = r, this.code = s, this.retryAfter = n, this.name = "ChatApiError";
9
+ }
10
+ }
11
+ class se extends Error {
12
+ constructor() {
13
+ super("Request debounced"), this.name = "DebounceError";
14
+ }
15
+ }
16
+ const Te = 3e4;
17
+ class Me {
18
+ constructor(e, r) {
19
+ $(this, "baseUrl");
20
+ $(this, "maxRetries");
21
+ $(this, "debounceMs");
22
+ $(this, "timeoutMs");
23
+ $(this, "lastSendTime", 0);
24
+ this.baseUrl = e, this.maxRetries = (r == null ? void 0 : r.maxRetries) ?? 2, this.debounceMs = (r == null ? void 0 : r.debounceMs) ?? 300, this.timeoutMs = (r == null ? void 0 : r.timeoutMs) ?? Te;
25
+ }
26
+ async sendMessage(e) {
27
+ if (this.debounceMs > 0 && Date.now() - this.lastSendTime < this.debounceMs)
28
+ throw new se();
29
+ this.lastSendTime = Date.now();
30
+ let r;
31
+ for (let s = 0; s <= this.maxRetries; s++)
32
+ try {
33
+ const n = await this.fetchWithTimeout(e);
34
+ if (n.ok)
35
+ return await n.json();
36
+ const o = await n.json().catch(() => ({})), a = n.headers.get("Retry-After"), l = a ? Number(a) : void 0;
37
+ if (r = new U(
38
+ o.error ?? `Request failed with status ${n.status}`,
39
+ n.status,
40
+ o.code,
41
+ l
42
+ ), !this.isRetryable(n.status))
43
+ throw r;
44
+ if (s < this.maxRetries) {
45
+ const c = this.getRetryDelay(n, s);
46
+ await this.delay(c);
47
+ }
48
+ } catch (n) {
49
+ if (n instanceof U) {
50
+ if (!this.isRetryable(n.status, n.code))
51
+ throw n;
52
+ if (r = n, s < this.maxRetries) {
53
+ const o = this.getRetryDelay(null, s);
54
+ await this.delay(o);
55
+ }
56
+ } else if (r = new U(
57
+ "Failed to connect. Please try again.",
58
+ 0,
59
+ "NETWORK_ERROR"
60
+ ), s < this.maxRetries) {
61
+ const o = this.getRetryDelay(null, s);
62
+ await this.delay(o);
63
+ }
64
+ }
65
+ throw r;
66
+ }
67
+ async fetchWithTimeout(e) {
68
+ if (this.timeoutMs <= 0)
69
+ return fetch(`${this.baseUrl}/api/chat`, {
70
+ method: "POST",
71
+ headers: { "Content-Type": "application/json" },
72
+ body: JSON.stringify({ messages: e })
73
+ });
74
+ const r = new AbortController(), s = setTimeout(() => r.abort(), this.timeoutMs);
75
+ try {
76
+ return await fetch(`${this.baseUrl}/api/chat`, {
77
+ method: "POST",
78
+ headers: { "Content-Type": "application/json" },
79
+ body: JSON.stringify({ messages: e }),
80
+ signal: r.signal
81
+ });
82
+ } catch (n) {
83
+ throw r.signal.aborted ? new U(
84
+ "Request timed out. Please try again.",
85
+ 0,
86
+ "TIMEOUT"
87
+ ) : n;
88
+ } finally {
89
+ clearTimeout(s);
90
+ }
91
+ }
92
+ isRetryable(e, r) {
93
+ return r === "TIMEOUT" || r === "NETWORK_ERROR" ? !0 : e === 429 || e === 503;
94
+ }
95
+ getRetryDelay(e, r) {
96
+ if (e && e.status === 429) {
97
+ const s = e.headers.get("Retry-After");
98
+ if (s) {
99
+ const n = Number(s);
100
+ return Math.min(n * 1e3, 6e4);
101
+ }
102
+ }
103
+ return r === 0 ? 1e3 : 3e3;
104
+ }
105
+ delay(e) {
106
+ return new Promise((r) => setTimeout(r, e));
107
+ }
108
+ }
109
+ const Ce = 200, Ne = "claudius:messages";
110
+ function Se(t, e) {
111
+ let r;
112
+ try {
113
+ r = new URL(e).host;
114
+ } catch {
115
+ r = e;
116
+ }
117
+ return `${t}:${r}`;
118
+ }
119
+ function V() {
120
+ try {
121
+ return typeof sessionStorage < "u" ? sessionStorage : null;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ function Le(t) {
127
+ const e = V();
128
+ if (!e) return [];
129
+ try {
130
+ const r = e.getItem(t);
131
+ if (!r) return [];
132
+ const s = JSON.parse(r);
133
+ return Array.isArray(s) ? s : [];
134
+ } catch {
135
+ return [];
136
+ }
137
+ }
138
+ function ke({
139
+ apiUrl: t,
140
+ persistMessages: e = !0,
141
+ storageKeyPrefix: r = Ne,
142
+ timeoutMs: s,
143
+ translations: n
144
+ }) {
145
+ const o = F(
146
+ () => new Me(t, { debounceMs: 0, timeoutMs: s }),
147
+ [t, s]
148
+ ), a = Se(r, t), l = e ? Le(a) : [], [c, u] = C(l), [h, E] = C(!1), [g, x] = C(null), [f, w] = C(!1), v = N(l.length), y = N(!1), T = N(l), O = R(
149
+ (m) => {
150
+ if (!e) return;
151
+ const p = V();
152
+ if (p)
153
+ try {
154
+ const H = m.slice(-Ce);
155
+ p.setItem(a, JSON.stringify(H));
156
+ } catch {
157
+ }
158
+ },
159
+ [e, a]
160
+ ), A = () => (v.current += 1, `msg-${v.current}`), I = R(
161
+ (m, p) => {
162
+ if (!n)
163
+ return p ?? "Something went wrong. Please try again.";
164
+ switch (m) {
165
+ case "TIMEOUT":
166
+ return n.errorTimeout;
167
+ case "NETWORK_ERROR":
168
+ return n.errorConnection;
169
+ case "RATE_LIMITED":
170
+ return p != null && p.includes("minute") ? n.errorRateLimitMinute : n.errorRateLimitHour;
171
+ case "VALIDATION_ERROR":
172
+ case "CONFIG_ERROR":
173
+ case "SERVICE_ERROR":
174
+ case "UNKNOWN_ERROR":
175
+ default:
176
+ return p ?? n.errorGeneric;
177
+ }
178
+ },
179
+ [n]
180
+ ), M = R((m) => !(m instanceof U) || m.code === "TIMEOUT" || m.code === "NETWORK_ERROR" || m.code === "RATE_LIMITED" || m.code === "SERVICE_ERROR" || m.code === "UNKNOWN_ERROR" || m.status >= 500 || m.status === 0, []), D = R(
181
+ async (m) => {
182
+ E(!0), y.current = !0, x(null), w(!1);
183
+ try {
184
+ const p = await o.sendMessage(m), H = {
185
+ id: A(),
186
+ role: "assistant",
187
+ content: p.reply,
188
+ sources: p.sources
189
+ }, S = [...m, H];
190
+ T.current = S, u(S), O(S);
191
+ } catch (p) {
192
+ if (p instanceof se) return;
193
+ p instanceof U ? x(I(p.code, p.message)) : x(
194
+ (n == null ? void 0 : n.errorConnection) ?? "Failed to connect. Please try again."
195
+ ), w(M(p));
196
+ } finally {
197
+ E(!1), y.current = !1;
198
+ }
199
+ },
200
+ [o, I, M, O, n]
201
+ ), _ = R(
202
+ async (m) => {
203
+ const p = m.trim();
204
+ if (!p || y.current) return;
205
+ const H = {
206
+ id: A(),
207
+ role: "user",
208
+ content: p
209
+ }, S = [...T.current, H];
210
+ T.current = S, u(S), O(S), await D(S);
211
+ },
212
+ [O, D]
213
+ ), b = R(async () => {
214
+ if (y.current) return;
215
+ const m = T.current[T.current.length - 1];
216
+ !m || m.role !== "user" || await D(T.current);
217
+ }, [D]), j = R(() => {
218
+ if (T.current = [], u([]), x(null), w(!1), e) {
219
+ const m = V();
220
+ if (!m) return;
221
+ try {
222
+ m.removeItem(a);
223
+ } catch {
224
+ }
225
+ }
226
+ }, [e, a]);
227
+ return {
228
+ messages: c,
229
+ isLoading: h,
230
+ error: g,
231
+ canRetry: f,
232
+ sendMessage: _,
233
+ retry: b,
234
+ clearMessages: j
235
+ };
236
+ }
237
+ function Oe(t) {
238
+ const [e, r] = C(() => typeof window > "u" ? !1 : window.matchMedia(t).matches);
239
+ return k(() => {
240
+ const s = window.matchMedia(t);
241
+ r(s.matches);
242
+ const n = (o) => r(o.matches);
243
+ return s.addEventListener("change", n), () => s.removeEventListener("change", n);
244
+ }, [t]), e;
245
+ }
246
+ function W(t, e) {
247
+ return t instanceof RegExp ? t.test(e) : e.toLowerCase().includes(t.toLowerCase());
248
+ }
249
+ function Ae() {
250
+ const t = document.documentElement, e = document.body, r = t.scrollTop || e.scrollTop || 0, s = Math.max(t.scrollHeight, e.scrollHeight), n = t.clientHeight || window.innerHeight, o = s - n;
251
+ return o <= 0 ? 100 : r / o * 100;
252
+ }
253
+ function Ie({
254
+ triggers: t,
255
+ enabled: e,
256
+ onOpen: r,
257
+ onGreeting: s
258
+ }) {
259
+ k(() => {
260
+ if (!e || !t || t.length === 0) return;
261
+ const n = /* @__PURE__ */ new Set(), o = [], a = typeof window < "u" ? window.location.href : "", l = (c, u) => {
262
+ n.has(c) || (n.add(c), u === "open" ? r() : s(u.greeting));
263
+ };
264
+ return t.forEach((c, u) => {
265
+ switch (c.on) {
266
+ case "url": {
267
+ W(c.pattern, a) && l(u, c.action);
268
+ break;
269
+ }
270
+ case "time": {
271
+ if (c.matchUrl && !W(c.matchUrl, a))
272
+ return;
273
+ const h = window.setTimeout(
274
+ () => l(u, c.action),
275
+ Math.max(0, c.seconds * 1e3)
276
+ );
277
+ o.push(() => window.clearTimeout(h));
278
+ break;
279
+ }
280
+ case "scroll": {
281
+ if (c.matchUrl && !W(c.matchUrl, a))
282
+ return;
283
+ const h = () => {
284
+ Ae() >= c.percent && l(u, c.action);
285
+ };
286
+ h(), window.addEventListener("scroll", h, { passive: !0 }), o.push(() => window.removeEventListener("scroll", h));
287
+ break;
288
+ }
289
+ case "exit-intent": {
290
+ if (c.matchUrl && !W(c.matchUrl, a))
291
+ return;
292
+ const h = (E) => {
293
+ E.clientY <= 0 && l(u, c.action);
294
+ };
295
+ document.addEventListener("mouseleave", h), o.push(
296
+ () => document.removeEventListener("mouseleave", h)
297
+ );
298
+ break;
299
+ }
300
+ }
301
+ }), () => {
302
+ o.forEach((c) => c());
303
+ };
304
+ }, [t, e, r, s]);
305
+ }
306
+ const De = {
307
+ "bottom-right": "bottom-6 right-6",
308
+ "bottom-left": "bottom-6 left-6",
309
+ "top-right": "top-6 right-6",
310
+ "top-left": "top-6 left-6"
311
+ }, He = Ee(function({ isOpen: e, onClick: r, position: s = "bottom-right", translations: n }, o) {
312
+ const a = e ? (n == null ? void 0 : n.closeChat) ?? "Close chat" : (n == null ? void 0 : n.openChat) ?? "Open chat";
313
+ return /* @__PURE__ */ i(
314
+ "button",
315
+ {
316
+ ref: o,
317
+ onClick: r,
318
+ "aria-label": a,
319
+ className: `fixed ${De[s]} z-50 flex h-14 w-14 items-center justify-center rounded-claudius-full bg-claudius-accent text-claudius-accent-text shadow-claudius-floating transition-transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-claudius-accent focus:ring-offset-2`,
320
+ children: e ? /* @__PURE__ */ d(
321
+ "svg",
322
+ {
323
+ width: "24",
324
+ height: "24",
325
+ viewBox: "0 0 24 24",
326
+ fill: "none",
327
+ stroke: "currentColor",
328
+ strokeWidth: "2",
329
+ strokeLinecap: "round",
330
+ strokeLinejoin: "round",
331
+ "aria-hidden": "true",
332
+ children: [
333
+ /* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
334
+ /* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
335
+ ]
336
+ }
337
+ ) : /* @__PURE__ */ i(
338
+ "svg",
339
+ {
340
+ width: "24",
341
+ height: "24",
342
+ viewBox: "0 0 24 24",
343
+ fill: "none",
344
+ stroke: "currentColor",
345
+ strokeWidth: "2",
346
+ strokeLinecap: "round",
347
+ strokeLinejoin: "round",
348
+ "aria-hidden": "true",
349
+ children: /* @__PURE__ */ i("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
350
+ }
351
+ )
352
+ }
353
+ );
354
+ }), _e = K(function({
355
+ count: e,
356
+ isActive: r,
357
+ onClick: s
358
+ }) {
359
+ return /* @__PURE__ */ d(
360
+ "button",
361
+ {
362
+ onClick: s,
363
+ "aria-label": "View sources",
364
+ title: "View sources",
365
+ className: `group relative flex h-7 w-7 items-center justify-center rounded-claudius-full transition-colors ${r ? "bg-claudius-accent text-claudius-accent-text" : "text-claudius-text-muted hover:bg-claudius-surface-muted hover:text-claudius-text"}`,
366
+ children: [
367
+ /* @__PURE__ */ d(
368
+ "svg",
369
+ {
370
+ width: "14",
371
+ height: "14",
372
+ viewBox: "0 0 24 24",
373
+ fill: "none",
374
+ stroke: "currentColor",
375
+ strokeWidth: "2",
376
+ strokeLinecap: "round",
377
+ strokeLinejoin: "round",
378
+ "aria-hidden": "true",
379
+ children: [
380
+ /* @__PURE__ */ i("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
381
+ /* @__PURE__ */ i("polyline", { points: "14 2 14 8 20 8" }),
382
+ /* @__PURE__ */ i("line", { x1: "16", y1: "13", x2: "8", y2: "13" }),
383
+ /* @__PURE__ */ i("line", { x1: "16", y1: "17", x2: "8", y2: "17" })
384
+ ]
385
+ }
386
+ ),
387
+ /* @__PURE__ */ i("span", { className: "absolute -right-1 -top-1 flex h-4 min-w-4 items-center justify-center rounded-claudius-full bg-claudius-accent px-1 text-[10px] font-bold text-claudius-accent-text", children: e })
388
+ ]
389
+ }
390
+ );
391
+ }), je = ["http:", "https:"];
392
+ function oe(t) {
393
+ if (!t || typeof t != "string")
394
+ return null;
395
+ const e = t.trim();
396
+ if (!e)
397
+ return null;
398
+ try {
399
+ const r = new URL(e);
400
+ return je.includes(r.protocol) ? e : null;
401
+ } catch {
402
+ return null;
403
+ }
404
+ }
405
+ const Q = /(https?:\/\/[^\s)]+)/, ee = /(\*\*[^*]+\*\*)/, te = /(\*[^*]+\*)/;
406
+ function $e(t, e) {
407
+ const r = t.match(/[.,;:!?'"]+$/), s = r ? t.slice(0, -r[0].length) : t, n = r ? r[0] : "", o = oe(s);
408
+ return o ? /* @__PURE__ */ d(ve, { children: [
409
+ /* @__PURE__ */ d(
410
+ "a",
411
+ {
412
+ href: o,
413
+ target: "_blank",
414
+ rel: "noopener noreferrer",
415
+ className: "underline font-medium hover:opacity-80 text-claudius-link",
416
+ children: [
417
+ o.replace(/^https?:\/\//, ""),
418
+ /* @__PURE__ */ i("span", { className: "sr-only", children: " (opens in a new tab)" })
419
+ ]
420
+ },
421
+ e
422
+ ),
423
+ n
424
+ ] }) : t;
425
+ }
426
+ function Ue(t, e) {
427
+ const r = t.split(ee), s = [];
428
+ return r.forEach((n, o) => {
429
+ if (ee.test(n)) {
430
+ const a = n.slice(2, -2);
431
+ s.push(/* @__PURE__ */ i("strong", { children: a }, `${e}-b${o}`));
432
+ } else
433
+ n.split(te).forEach((l, c) => {
434
+ if (te.test(l)) {
435
+ const u = l.slice(1, -1);
436
+ s.push(/* @__PURE__ */ i("em", { children: u }, `${e}-b${o}-i${c}`));
437
+ } else
438
+ l.split(Q).forEach((h, E) => {
439
+ Q.test(h) ? s.push(
440
+ $e(h, `${e}-b${o}-i${c}-u${E}`)
441
+ ) : h && s.push(h);
442
+ });
443
+ });
444
+ }), s;
445
+ }
446
+ function Be(t) {
447
+ const e = t.split(`
448
+ `);
449
+ return e.map((r, s) => /* @__PURE__ */ d("span", { children: [
450
+ Ue(r, `l${s}`),
451
+ s < e.length - 1 && /* @__PURE__ */ i("br", {})
452
+ ] }, s));
453
+ }
454
+ const Ge = K(function({
455
+ role: e,
456
+ content: r,
457
+ sources: s,
458
+ onSourceClick: n,
459
+ isSourceActive: o
460
+ }) {
461
+ const a = e === "user";
462
+ return /* @__PURE__ */ d("div", { className: `${a ? "ml-auto" : "mr-auto"} max-w-[85%]`, children: [
463
+ /* @__PURE__ */ i(
464
+ "div",
465
+ {
466
+ className: `rounded-claudius-bubble px-4 py-2.5 text-sm leading-relaxed font-body ${a ? "bg-claudius-user-bubble text-claudius-user-bubble-text rounded-br-claudius-tail" : "bg-claudius-assistant-bubble text-claudius-assistant-bubble-text rounded-bl-claudius-tail"}`,
467
+ children: Be(r)
468
+ }
469
+ ),
470
+ !a && s && s.length > 0 && n && /* @__PURE__ */ i("div", { className: "mt-1", children: /* @__PURE__ */ i(
471
+ _e,
472
+ {
473
+ count: s.length,
474
+ isActive: o ?? !1,
475
+ onClick: n
476
+ }
477
+ ) })
478
+ ] });
479
+ }), z = 2e3, Pe = 1800;
480
+ function We({
481
+ onSend: t,
482
+ isLoading: e,
483
+ placeholder: r,
484
+ translations: s
485
+ }) {
486
+ const [n, o] = C(""), a = N(null), l = n.length, c = l >= Pe, u = l >= z, h = r ?? (s == null ? void 0 : s.placeholder) ?? "Type your message...", E = (s == null ? void 0 : s.sendMessage) ?? "Send message", g = (s == null ? void 0 : s.typeYourMessage) ?? "Type your message";
487
+ return k(() => {
488
+ var w;
489
+ e || (w = a.current) == null || w.focus();
490
+ }, [e]), /* @__PURE__ */ d(
491
+ "form",
492
+ {
493
+ onSubmit: (w) => {
494
+ w.preventDefault();
495
+ const v = n.trim();
496
+ !v || u || (t(v), o(""));
497
+ },
498
+ className: "border-t border-claudius-border bg-claudius-surface p-3",
499
+ children: [
500
+ /* @__PURE__ */ d("div", { className: "flex gap-2", children: [
501
+ /* @__PURE__ */ i(
502
+ "input",
503
+ {
504
+ ref: a,
505
+ type: "text",
506
+ value: n,
507
+ onChange: (w) => {
508
+ const v = w.target.value;
509
+ v.length <= z && o(v);
510
+ },
511
+ placeholder: h,
512
+ disabled: e,
513
+ "aria-label": g,
514
+ "aria-describedby": c ? "char-count" : void 0,
515
+ className: "flex-1 rounded-claudius-sm border border-claudius-border bg-claudius-field px-3 py-2 text-sm font-body text-claudius-text placeholder:text-claudius-text-muted focus:border-claudius-accent focus:outline-none focus:ring-1 focus:ring-claudius-accent disabled:opacity-50"
516
+ }
517
+ ),
518
+ /* @__PURE__ */ i(
519
+ "button",
520
+ {
521
+ type: "submit",
522
+ disabled: e || u,
523
+ "aria-label": E,
524
+ className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-claudius-sm bg-claudius-accent text-claudius-accent-text transition-colors hover:opacity-90 disabled:opacity-50",
525
+ children: /* @__PURE__ */ d(
526
+ "svg",
527
+ {
528
+ width: "16",
529
+ height: "16",
530
+ viewBox: "0 0 24 24",
531
+ fill: "none",
532
+ stroke: "currentColor",
533
+ strokeWidth: "2",
534
+ strokeLinecap: "round",
535
+ strokeLinejoin: "round",
536
+ "aria-hidden": "true",
537
+ children: [
538
+ /* @__PURE__ */ i("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
539
+ /* @__PURE__ */ i("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
540
+ ]
541
+ }
542
+ )
543
+ }
544
+ )
545
+ ] }),
546
+ c && /* @__PURE__ */ d(
547
+ "div",
548
+ {
549
+ id: "char-count",
550
+ className: `mt-1 text-xs text-right ${u ? "text-claudius-error" : "text-claudius-text-muted"}`,
551
+ "aria-live": "polite",
552
+ children: [
553
+ l,
554
+ "/",
555
+ z
556
+ ]
557
+ }
558
+ )
559
+ ]
560
+ }
561
+ );
562
+ }
563
+ const Fe = ["blog", "page", "external"], Ye = {
564
+ blog: "Blog",
565
+ page: "Page",
566
+ external: "External"
567
+ };
568
+ function ze(t) {
569
+ try {
570
+ return new URL(t).hostname;
571
+ } catch {
572
+ return t;
573
+ }
574
+ }
575
+ const Ve = K(function({
576
+ sources: e,
577
+ onClose: r
578
+ }) {
579
+ const s = Fe.map((o) => ({
580
+ type: o,
581
+ label: Ye[o],
582
+ items: e.filter((a) => a.type === o)
583
+ })).filter((o) => o.items.length > 0), n = e.length === 1 ? "1 source found" : `${e.length} sources found`;
584
+ return /* @__PURE__ */ d("div", { className: "absolute inset-y-0 left-0 z-10 flex w-[280px] flex-col border-r-2 border-claudius-border bg-claudius-surface rounded-r-claudius-lg transition-transform duration-200 ease-out", children: [
585
+ /* @__PURE__ */ d("div", { className: "flex items-center justify-between border-b border-claudius-border px-4 py-3", children: [
586
+ /* @__PURE__ */ d("div", { children: [
587
+ /* @__PURE__ */ i("h3", { className: "text-sm font-heading font-semibold text-claudius-text", children: "Sources" }),
588
+ /* @__PURE__ */ i("p", { className: "text-xs text-claudius-text-muted", children: n })
589
+ ] }),
590
+ /* @__PURE__ */ i(
591
+ "button",
592
+ {
593
+ onClick: r,
594
+ "aria-label": "Close sources",
595
+ className: "flex h-7 w-7 items-center justify-center rounded-claudius-full text-claudius-text-muted transition-colors hover:bg-claudius-surface-muted hover:text-claudius-text",
596
+ children: /* @__PURE__ */ d(
597
+ "svg",
598
+ {
599
+ width: "14",
600
+ height: "14",
601
+ viewBox: "0 0 24 24",
602
+ fill: "none",
603
+ stroke: "currentColor",
604
+ strokeWidth: "2",
605
+ strokeLinecap: "round",
606
+ strokeLinejoin: "round",
607
+ "aria-hidden": "true",
608
+ children: [
609
+ /* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
610
+ /* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
611
+ ]
612
+ }
613
+ )
614
+ }
615
+ )
616
+ ] }),
617
+ /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto px-3 py-3 space-y-4", children: s.map((o) => /* @__PURE__ */ d("div", { children: [
618
+ /* @__PURE__ */ i("h4", { className: "mb-2 text-xs font-semibold uppercase tracking-wide text-claudius-text-muted", children: o.label }),
619
+ /* @__PURE__ */ i("div", { className: "space-y-2", children: o.items.map((a) => {
620
+ const l = oe(a.url);
621
+ return l ? /* @__PURE__ */ d(
622
+ "a",
623
+ {
624
+ href: l,
625
+ target: "_blank",
626
+ rel: "noopener noreferrer",
627
+ className: "block rounded-claudius-md border-2 border-claudius-border bg-claudius-surface-muted p-3 transition-colors hover:bg-claudius-border",
628
+ children: [
629
+ /* @__PURE__ */ i("p", { className: "truncate text-sm font-medium text-claudius-text", children: a.title }),
630
+ /* @__PURE__ */ i("p", { className: "mt-0.5 text-xs text-claudius-text-muted", children: ze(l) })
631
+ ]
632
+ },
633
+ l
634
+ ) : null;
635
+ }) })
636
+ ] }, o.type)) })
637
+ ] });
638
+ });
639
+ function Ke(t, e, r) {
640
+ const [s, n] = C(0), o = N(0), a = N(0), l = N(0), c = N(!1);
641
+ return k(() => {
642
+ const u = t.current;
643
+ if (!r || !u) return;
644
+ const h = (x) => {
645
+ if (u.scrollTop > 0) {
646
+ c.current = !1;
647
+ return;
648
+ }
649
+ c.current = !0, a.current = x.touches[0].clientY, l.current = Date.now();
650
+ }, E = (x) => {
651
+ if (!c.current) return;
652
+ let f = x.touches[0].clientY - a.current;
653
+ f < 0 && (f = f * 0.3), o.current = f, n(f);
654
+ }, g = () => {
655
+ if (!c.current) return;
656
+ c.current = !1;
657
+ const x = o.current, f = (Date.now() - l.current) / 1e3, w = u.getBoundingClientRect().height, v = f > 0.05 && x > 0 && x / f > 500, y = x > w * 0.3;
658
+ v || y ? e() : (o.current = 0, n(0));
659
+ };
660
+ return u.addEventListener("touchstart", h, { passive: !0 }), u.addEventListener("touchmove", E, { passive: !0 }), u.addEventListener("touchend", g), () => {
661
+ u.removeEventListener("touchstart", h), u.removeEventListener("touchmove", E), u.removeEventListener("touchend", g);
662
+ };
663
+ }, [t, e, r]), { offsetY: s };
664
+ }
665
+ const qe = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
666
+ function Xe(t, e) {
667
+ k(() => {
668
+ const r = t.current;
669
+ if (!r) return;
670
+ const s = (n) => {
671
+ if (n.key !== "Tab") return;
672
+ const o = Array.from(
673
+ r.querySelectorAll(qe)
674
+ ).filter((u) => !u.hasAttribute("aria-hidden"));
675
+ if (o.length === 0) return;
676
+ const a = o[0], l = o[o.length - 1], c = document.activeElement;
677
+ n.shiftKey && c === a ? (n.preventDefault(), l.focus()) : !n.shiftKey && c === l && (n.preventDefault(), a.focus());
678
+ };
679
+ return r.addEventListener("keydown", s), () => r.removeEventListener("keydown", s);
680
+ }, [t, e]);
681
+ }
682
+ const Je = /\*\*([^*]+)\*\*/g, Ze = /\*([^*]+)\*/g, Qe = /https?:\/\/[^\s)]+/g;
683
+ function et(t) {
684
+ return t.replace(Je, "$1").replace(Ze, "$1").replace(Qe, (e) => {
685
+ try {
686
+ return new URL(e).hostname;
687
+ } catch {
688
+ return e;
689
+ }
690
+ });
691
+ }
692
+ function tt({ label: t }) {
693
+ return /* @__PURE__ */ i(
694
+ "div",
695
+ {
696
+ role: "status",
697
+ "aria-live": "polite",
698
+ "aria-label": t,
699
+ className: "mr-auto flex max-w-[85%]",
700
+ children: /* @__PURE__ */ d("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
701
+ /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:0ms]" }),
702
+ /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:150ms]" }),
703
+ /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:300ms]" })
704
+ ] })
705
+ }
706
+ );
707
+ }
708
+ const rt = {
709
+ "bottom-right": "bottom-24 right-3 sm:right-6",
710
+ "bottom-left": "bottom-24 left-3 sm:left-6",
711
+ "top-right": "top-24 right-3 sm:right-6",
712
+ "top-left": "top-24 left-3 sm:left-6"
713
+ };
714
+ function nt({
715
+ messages: t,
716
+ isLoading: e,
717
+ error: r,
718
+ canRetry: s = !1,
719
+ onSend: n,
720
+ onRetry: o,
721
+ onClose: a,
722
+ title: l = "Chat",
723
+ subtitle: c = "Ask me anything",
724
+ welcomeMessage: u = "Hi! How can I help you today?",
725
+ placeholder: h,
726
+ position: E = "bottom-right",
727
+ translations: g,
728
+ isMobile: x = !1
729
+ }) {
730
+ const f = Re(), w = N(null), v = N(null), [y, T] = C(null);
731
+ Xe(w, !0);
732
+ const { offsetY: O } = Ke(
733
+ v,
734
+ a,
735
+ x
736
+ ), A = O !== 0, I = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
737
+ k(() => {
738
+ const b = v.current;
739
+ b && (b.scrollTop = b.scrollHeight);
740
+ }, [t, e]), k(() => {
741
+ const b = (j) => {
742
+ j.key === "Escape" && !j.isComposing && a();
743
+ };
744
+ return document.addEventListener("keydown", b), () => document.removeEventListener("keydown", b);
745
+ }, [a]);
746
+ const M = (g == null ? void 0 : g.closeChat) ?? "Close chat", D = (g == null ? void 0 : g.chatMessages) ?? "Chat messages", _ = [...t].reverse().find((b) => b.role === "assistant");
747
+ return /* @__PURE__ */ d(
748
+ "div",
749
+ {
750
+ ref: w,
751
+ role: "dialog",
752
+ "aria-modal": x ? "true" : void 0,
753
+ "aria-labelledby": f,
754
+ className: x ? "claudius-bottom-sheet fixed inset-x-0 bottom-0 z-50 flex h-[90vh] w-full flex-col overflow-hidden rounded-t-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body" : `fixed ${rt[E]} z-50 flex h-[min(500px,calc(100vh-7rem))] w-[calc(100vw-1.5rem)] max-w-[380px] sm:max-w-[400px] md:max-w-[440px] flex-col overflow-hidden rounded-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body`,
755
+ style: x && !I ? { transform: `translateY(${Math.max(0, O)}px)` } : void 0,
756
+ "data-dragging": A || void 0,
757
+ children: [
758
+ x && /* @__PURE__ */ i("div", { className: "flex justify-center py-2", "aria-hidden": "true", children: /* @__PURE__ */ i("div", { className: "h-1 w-8 rounded-claudius-full bg-claudius-border" }) }),
759
+ /* @__PURE__ */ d("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
760
+ /* @__PURE__ */ i(
761
+ "div",
762
+ {
763
+ "aria-hidden": "true",
764
+ className: "flex h-8 w-8 items-center justify-center rounded-claudius-full bg-claudius-accent-soft text-sm font-bold text-claudius-accent-text",
765
+ children: l.charAt(0).toUpperCase()
766
+ }
767
+ ),
768
+ /* @__PURE__ */ d("div", { className: "flex-1", children: [
769
+ /* @__PURE__ */ i(
770
+ "h2",
771
+ {
772
+ id: f,
773
+ className: "text-sm font-heading font-semibold text-claudius-accent-text",
774
+ children: l
775
+ }
776
+ ),
777
+ /* @__PURE__ */ i("p", { className: "text-xs text-claudius-accent-text", children: c })
778
+ ] }),
779
+ /* @__PURE__ */ i(
780
+ "button",
781
+ {
782
+ onClick: a,
783
+ "aria-label": M,
784
+ className: "flex h-10 w-10 items-center justify-center rounded-claudius-full text-claudius-accent-text-muted transition-colors hover:bg-claudius-accent-soft hover:text-claudius-accent-text",
785
+ children: /* @__PURE__ */ d(
786
+ "svg",
787
+ {
788
+ width: "18",
789
+ height: "18",
790
+ viewBox: "0 0 24 24",
791
+ fill: "none",
792
+ stroke: "currentColor",
793
+ strokeWidth: "2",
794
+ strokeLinecap: "round",
795
+ strokeLinejoin: "round",
796
+ "aria-hidden": "true",
797
+ children: [
798
+ /* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
799
+ /* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
800
+ ]
801
+ }
802
+ )
803
+ }
804
+ )
805
+ ] }),
806
+ /* @__PURE__ */ d("div", { className: "relative flex-1 overflow-hidden", children: [
807
+ y && /* @__PURE__ */ i(
808
+ Ve,
809
+ {
810
+ sources: y.sources,
811
+ onClose: () => T(null)
812
+ }
813
+ ),
814
+ /* @__PURE__ */ d(
815
+ "div",
816
+ {
817
+ ref: v,
818
+ role: "log",
819
+ "aria-label": D,
820
+ className: "h-full space-y-3 overflow-y-auto px-4 py-4",
821
+ children: [
822
+ t.length === 0 && !r && /* @__PURE__ */ i("div", { className: "mr-auto flex max-w-[85%]", children: /* @__PURE__ */ i("div", { className: "rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-2.5 text-sm leading-relaxed text-claudius-assistant-bubble-text", children: u }) }),
823
+ t.map((b) => /* @__PURE__ */ i(
824
+ Ge,
825
+ {
826
+ role: b.role,
827
+ content: b.content,
828
+ sources: b.sources,
829
+ isSourceActive: (y == null ? void 0 : y.messageId) === b.id,
830
+ onSourceClick: () => {
831
+ (y == null ? void 0 : y.messageId) === b.id ? T(null) : b.sources && b.sources.length > 0 && T({ messageId: b.id, sources: b.sources });
832
+ }
833
+ },
834
+ b.id
835
+ )),
836
+ e && /* @__PURE__ */ i(
837
+ tt,
838
+ {
839
+ label: (g == null ? void 0 : g.typingIndicator) ?? "Assistant is typing"
840
+ }
841
+ ),
842
+ r && /* @__PURE__ */ d(
843
+ "div",
844
+ {
845
+ role: "alert",
846
+ className: "mx-auto flex max-w-[90%] flex-col items-center gap-2 rounded-claudius-sm bg-claudius-error-surface px-3 py-2 text-center text-xs text-claudius-error",
847
+ children: [
848
+ /* @__PURE__ */ i("span", { children: r }),
849
+ s && o && !e && /* @__PURE__ */ i(
850
+ "button",
851
+ {
852
+ type: "button",
853
+ onClick: o,
854
+ className: "rounded-claudius-md bg-claudius-error px-3 py-1 text-xs font-semibold text-claudius-error-text transition-opacity hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-error focus-visible:ring-offset-1",
855
+ children: (g == null ? void 0 : g.errorRetry) ?? "Retry"
856
+ }
857
+ )
858
+ ]
859
+ }
860
+ )
861
+ ]
862
+ }
863
+ )
864
+ ] }),
865
+ /* @__PURE__ */ i(
866
+ "div",
867
+ {
868
+ "data-claudius-live": "assistant",
869
+ "aria-live": "polite",
870
+ "aria-atomic": "true",
871
+ className: "sr-only",
872
+ children: _ ? et(_.content) : ""
873
+ }
874
+ ),
875
+ /* @__PURE__ */ i(
876
+ We,
877
+ {
878
+ onSend: n,
879
+ isLoading: e,
880
+ placeholder: h,
881
+ translations: g
882
+ }
883
+ )
884
+ ]
885
+ }
886
+ );
887
+ }
888
+ function st({
889
+ message: t,
890
+ position: e,
891
+ onOpen: r,
892
+ onDismiss: s,
893
+ dismissLabel: n
894
+ }) {
895
+ const o = e.startsWith("bottom"), a = e.endsWith("right"), l = [
896
+ "claudius-greeting-bubble",
897
+ "fixed z-40 max-w-xs",
898
+ o ? "bottom-20" : "top-20",
899
+ a ? "right-4" : "left-4"
900
+ ].join(" ");
901
+ return /* @__PURE__ */ d("div", { className: l, role: "status", "aria-live": "polite", children: [
902
+ /* @__PURE__ */ i(
903
+ "button",
904
+ {
905
+ type: "button",
906
+ onClick: r,
907
+ className: "block w-full rounded-claudius-lg bg-claudius-surface p-4 pr-8 text-left text-sm font-body text-claudius-text shadow-claudius-floating ring-1 ring-claudius-border transition hover:shadow-claudius-floating-hover focus:outline-none focus:ring-2 focus:ring-claudius-accent",
908
+ children: t
909
+ }
910
+ ),
911
+ /* @__PURE__ */ i(
912
+ "button",
913
+ {
914
+ type: "button",
915
+ onClick: (c) => {
916
+ c.stopPropagation(), s();
917
+ },
918
+ "aria-label": n,
919
+ className: "absolute right-1 top-1 flex h-6 w-6 items-center justify-center rounded-claudius-full text-claudius-text-muted hover:bg-claudius-surface-muted focus:outline-none focus:ring-2 focus:ring-claudius-accent",
920
+ children: /* @__PURE__ */ i("span", { "aria-hidden": "true", children: "×" })
921
+ }
922
+ )
923
+ ] });
924
+ }
925
+ const ie = {
926
+ // ChatWindow
927
+ title: "Chat",
928
+ subtitle: "Ask me anything",
929
+ welcomeMessage: "Hi! How can I help you today?",
930
+ closeChat: "Close chat",
931
+ chatMessages: "Chat messages",
932
+ typingIndicator: "Assistant is typing",
933
+ // ChatInput
934
+ placeholder: "Type your message...",
935
+ sendMessage: "Send message",
936
+ typeYourMessage: "Type your message",
937
+ // ChatToggleButton
938
+ openChat: "Open chat",
939
+ // GreetingBubble
940
+ dismissGreeting: "Dismiss greeting",
941
+ // Errors
942
+ errorGeneric: "Something went wrong. Please try again.",
943
+ errorConnection: "Failed to connect. Please try again.",
944
+ errorTimeout: "Request timed out. Please try again.",
945
+ errorRateLimitMinute: "Too many requests. Please wait a minute.",
946
+ errorRateLimitHour: "Hourly limit reached. Please try again later.",
947
+ errorRetry: "Retry"
948
+ }, ot = ie;
949
+ function Nt(t) {
950
+ return { ...ot, ...t };
951
+ }
952
+ const it = {
953
+ // ChatWindow
954
+ title: "Chat",
955
+ subtitle: "Pregúntame lo que quieras",
956
+ welcomeMessage: "¡Hola! ¿En qué puedo ayudarte hoy?",
957
+ closeChat: "Cerrar chat",
958
+ chatMessages: "Mensajes del chat",
959
+ typingIndicator: "El asistente está escribiendo",
960
+ // ChatInput
961
+ placeholder: "Escribe tu mensaje...",
962
+ sendMessage: "Enviar mensaje",
963
+ typeYourMessage: "Escribe tu mensaje",
964
+ // ChatToggleButton
965
+ openChat: "Abrir chat",
966
+ // GreetingBubble
967
+ dismissGreeting: "Descartar saludo",
968
+ // Errors
969
+ errorGeneric: "Algo salió mal. Inténtalo de nuevo.",
970
+ errorConnection: "No se pudo conectar. Inténtalo de nuevo.",
971
+ errorTimeout: "La solicitud tardó demasiado. Inténtalo de nuevo.",
972
+ errorRateLimitMinute: "Demasiadas solicitudes. Espera un minuto.",
973
+ errorRateLimitHour: "Has alcanzado el límite por hora. Inténtalo más tarde.",
974
+ errorRetry: "Reintentar"
975
+ }, at = {
976
+ // ChatWindow
977
+ title: "Chat",
978
+ subtitle: "Posez-moi vos questions",
979
+ welcomeMessage: "Bonjour ! Comment puis-je vous aider aujourd'hui ?",
980
+ closeChat: "Fermer le chat",
981
+ chatMessages: "Messages du chat",
982
+ typingIndicator: "L'assistant écrit",
983
+ // ChatInput
984
+ placeholder: "Saisissez votre message...",
985
+ sendMessage: "Envoyer le message",
986
+ typeYourMessage: "Saisissez votre message",
987
+ // ChatToggleButton
988
+ openChat: "Ouvrir le chat",
989
+ // GreetingBubble
990
+ dismissGreeting: "Ignorer le message d'accueil",
991
+ // Errors
992
+ errorGeneric: "Une erreur s'est produite. Veuillez réessayer.",
993
+ errorConnection: "Échec de la connexion. Veuillez réessayer.",
994
+ errorTimeout: "La requête a expiré. Veuillez réessayer.",
995
+ errorRateLimitMinute: "Trop de requêtes. Veuillez patienter une minute.",
996
+ errorRateLimitHour: "Limite horaire atteinte. Veuillez réessayer plus tard.",
997
+ errorRetry: "Réessayer"
998
+ }, ct = {
999
+ // ChatWindow
1000
+ title: "Chat",
1001
+ subtitle: "Fragen Sie mich alles",
1002
+ welcomeMessage: "Hallo! Wie kann ich Ihnen heute helfen?",
1003
+ closeChat: "Chat schließen",
1004
+ chatMessages: "Chat-Nachrichten",
1005
+ typingIndicator: "Der Assistent schreibt",
1006
+ // ChatInput
1007
+ placeholder: "Geben Sie Ihre Nachricht ein...",
1008
+ sendMessage: "Nachricht senden",
1009
+ typeYourMessage: "Geben Sie Ihre Nachricht ein",
1010
+ // ChatToggleButton
1011
+ openChat: "Chat öffnen",
1012
+ // GreetingBubble
1013
+ dismissGreeting: "Begrüßung schließen",
1014
+ // Errors
1015
+ errorGeneric: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.",
1016
+ errorConnection: "Verbindung fehlgeschlagen. Bitte versuchen Sie es erneut.",
1017
+ errorTimeout: "Zeitüberschreitung der Anfrage. Bitte versuchen Sie es erneut.",
1018
+ errorRateLimitMinute: "Zu viele Anfragen. Bitte warten Sie eine Minute.",
1019
+ errorRateLimitHour: "Stündliches Limit erreicht. Bitte versuchen Sie es später erneut.",
1020
+ errorRetry: "Erneut versuchen"
1021
+ }, ae = {
1022
+ en: ie,
1023
+ es: it,
1024
+ fr: at,
1025
+ de: ct
1026
+ };
1027
+ function re(t) {
1028
+ if (!t) return;
1029
+ const e = t.toLowerCase().split("-")[0];
1030
+ return Object.prototype.hasOwnProperty.call(ae, e) ? e : void 0;
1031
+ }
1032
+ function ut() {
1033
+ const t = typeof document < "u" ? re(document.documentElement.lang) : void 0;
1034
+ if (t) return t;
1035
+ const e = typeof navigator < "u" ? re(navigator.language) : void 0;
1036
+ return e || "en";
1037
+ }
1038
+ function lt(t = {}) {
1039
+ const { locale: e, translations: r } = t, s = ae[e ?? ut()];
1040
+ return r ? { ...s, ...r } : { ...s };
1041
+ }
1042
+ const ne = [
1043
+ "accent",
1044
+ "accentText",
1045
+ "accentSoft",
1046
+ "accentTextMuted",
1047
+ "surface",
1048
+ "surfaceMuted",
1049
+ "text",
1050
+ "textMuted",
1051
+ "border",
1052
+ "userBubble",
1053
+ "userBubbleText",
1054
+ "assistantBubble",
1055
+ "assistantBubbleText",
1056
+ "field",
1057
+ "error",
1058
+ "errorSurface",
1059
+ "errorText",
1060
+ "link",
1061
+ "scrim"
1062
+ ], dt = ["sm", "md", "lg", "full", "tail"], ht = [
1063
+ "elevated",
1064
+ "floating",
1065
+ "floatingHover"
1066
+ ], ft = ["heading", "body"], ce = {
1067
+ default: {
1068
+ name: "default"
1069
+ },
1070
+ minimal: {
1071
+ name: "minimal",
1072
+ colors: {
1073
+ accent: "#171717",
1074
+ accentText: "#ffffff",
1075
+ surface: "#ffffff",
1076
+ surfaceMuted: "#f5f5f5",
1077
+ text: "#171717",
1078
+ textMuted: "#737373",
1079
+ border: "#e5e5e5",
1080
+ link: "#171717"
1081
+ },
1082
+ colorsDark: {
1083
+ accent: "#fafafa",
1084
+ accentText: "#171717",
1085
+ surface: "#0a0a0a",
1086
+ surfaceMuted: "#1c1c1c",
1087
+ text: "#fafafa",
1088
+ textMuted: "#a3a3a3",
1089
+ border: "#2e2e2e",
1090
+ field: "#1c1c1c",
1091
+ link: "#fafafa"
1092
+ },
1093
+ radii: { sm: "4px", md: "6px", lg: "10px" },
1094
+ shadows: {
1095
+ elevated: "0 4px 16px rgb(0 0 0 / 0.12)",
1096
+ floating: "0 2px 8px rgb(0 0 0 / 0.12)",
1097
+ floatingHover: "0 4px 12px rgb(0 0 0 / 0.16)"
1098
+ }
1099
+ },
1100
+ playful: {
1101
+ name: "playful",
1102
+ colors: {
1103
+ accent: "#8b5cf6",
1104
+ surfaceMuted: "#f5f3ff",
1105
+ assistantBubbleText: "#4c1d95",
1106
+ link: "#7c3aed"
1107
+ },
1108
+ colorsDark: {
1109
+ accent: "#a78bfa",
1110
+ surfaceMuted: "#2e1065",
1111
+ assistantBubbleText: "#ede9fe",
1112
+ link: "#c4b5fd"
1113
+ },
1114
+ radii: { sm: "12px", md: "16px", lg: "24px", tail: "8px" },
1115
+ shadows: {
1116
+ elevated: "0 24px 48px -12px rgb(139 92 246 / 0.35)",
1117
+ floating: "0 10px 20px -5px rgb(139 92 246 / 0.4)",
1118
+ floatingHover: "0 16px 28px -6px rgb(139 92 246 / 0.5)"
1119
+ },
1120
+ fonts: {
1121
+ heading: "ui-rounded, 'Hiragino Maru Gothic ProN', system-ui",
1122
+ body: "ui-rounded, 'Hiragino Maru Gothic ProN', system-ui"
1123
+ }
1124
+ },
1125
+ corporate: {
1126
+ name: "corporate",
1127
+ colors: {
1128
+ accent: "#1e3a5f",
1129
+ surfaceMuted: "#f3f4f6",
1130
+ text: "#1f2937",
1131
+ textMuted: "#6b7280",
1132
+ border: "#d1d5db",
1133
+ link: "#1d4ed8"
1134
+ },
1135
+ colorsDark: {
1136
+ accent: "#2c5282",
1137
+ link: "#93c5fd"
1138
+ },
1139
+ radii: { sm: "4px", md: "6px", lg: "8px", tail: "2px" },
1140
+ shadows: {
1141
+ elevated: "0 8px 24px rgb(15 23 42 / 0.16)",
1142
+ floating: "0 4px 12px rgb(15 23 42 / 0.18)",
1143
+ floatingHover: "0 6px 16px rgb(15 23 42 / 0.24)"
1144
+ },
1145
+ fonts: {
1146
+ heading: "'Segoe UI', 'Helvetica Neue', Arial, system-ui",
1147
+ body: "'Segoe UI', 'Helvetica Neue', Arial, system-ui"
1148
+ }
1149
+ }
1150
+ };
1151
+ function mt(t) {
1152
+ return Object.prototype.hasOwnProperty.call(ce, t);
1153
+ }
1154
+ const gt = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
1155
+ function bt(t) {
1156
+ if (t === void 0)
1157
+ return { mode: "light" };
1158
+ if (typeof t == "string") {
1159
+ if (gt.has(t))
1160
+ return { mode: t };
1161
+ if (mt(t)) {
1162
+ const e = ce[t];
1163
+ return { mode: e.colorScheme ?? "light", theme: e };
1164
+ }
1165
+ return { mode: "light", url: t };
1166
+ }
1167
+ return { mode: t.colorScheme ?? "light", theme: t };
1168
+ }
1169
+ function pt(t) {
1170
+ return t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
1171
+ }
1172
+ function xt(t, e) {
1173
+ console.warn(
1174
+ `[Claudius] Ignoring unknown theme token "${e}" in "${t}"`
1175
+ );
1176
+ }
1177
+ function B(t, e, r, s, n, o = "") {
1178
+ if (n)
1179
+ for (const [a, l] of Object.entries(n)) {
1180
+ if (!s.includes(a)) {
1181
+ xt(e, a);
1182
+ continue;
1183
+ }
1184
+ typeof l == "string" && (t[`${r}${pt(a)}${o}`] = l);
1185
+ }
1186
+ }
1187
+ function yt(t) {
1188
+ const e = {};
1189
+ B(e, "colors", "--cl-color-", ne, t.colors);
1190
+ for (const [r, s] of Object.entries({ ...e }))
1191
+ e[`${r}-dark`] = s;
1192
+ return B(
1193
+ e,
1194
+ "colorsDark",
1195
+ "--cl-color-",
1196
+ ne,
1197
+ t.colorsDark,
1198
+ "-dark"
1199
+ ), B(e, "radii", "--cl-radius-", dt, t.radii), B(e, "shadows", "--cl-shadow-", ht, t.shadows), B(e, "fonts", "--cl-font-", ft, t.fonts), e;
1200
+ }
1201
+ function wt(t) {
1202
+ return typeof t == "object" && t !== null && !Array.isArray(t);
1203
+ }
1204
+ function vt(t) {
1205
+ const e = F(() => bt(t), [t]), [r, s] = C(null), n = e.url;
1206
+ k(() => {
1207
+ if (s(null), !n) return;
1208
+ const c = new AbortController();
1209
+ return fetch(n, { signal: c.signal }).then((u) => {
1210
+ if (!u.ok)
1211
+ throw new Error(`HTTP ${u.status}`);
1212
+ return u.json();
1213
+ }).then((u) => {
1214
+ if (!wt(u))
1215
+ throw new Error("theme JSON must be an object");
1216
+ s(u);
1217
+ }).catch((u) => {
1218
+ c.signal.aborted || console.error(`[Claudius] Failed to load theme from ${n}:`, u);
1219
+ }), () => c.abort();
1220
+ }, [n]);
1221
+ const o = e.theme ?? r ?? null, a = (r == null ? void 0 : r.colorScheme) ?? e.mode, l = F(
1222
+ () => o ? yt(o) : {},
1223
+ [o]
1224
+ );
1225
+ return { mode: a, cssVars: l };
1226
+ }
1227
+ const ue = "claudius:triggers:dismissed";
1228
+ function Et() {
1229
+ if (typeof window > "u") return !1;
1230
+ try {
1231
+ return window.sessionStorage.getItem(ue) === "1";
1232
+ } catch {
1233
+ return !1;
1234
+ }
1235
+ }
1236
+ function Rt() {
1237
+ if (!(typeof window > "u"))
1238
+ try {
1239
+ window.sessionStorage.setItem(ue, "1");
1240
+ } catch {
1241
+ }
1242
+ }
1243
+ function St({
1244
+ apiUrl: t,
1245
+ title: e,
1246
+ subtitle: r,
1247
+ welcomeMessage: s,
1248
+ placeholder: n,
1249
+ persistMessages: o,
1250
+ storageKeyPrefix: a,
1251
+ requestTimeoutMs: l,
1252
+ theme: c = "light",
1253
+ accentColor: u,
1254
+ position: h = "bottom-right",
1255
+ locale: E,
1256
+ translations: g,
1257
+ triggers: x
1258
+ }) {
1259
+ const [f, w] = C(!1), [v, y] = C(null), [T, O] = C(Et), A = N(!1), I = Oe("(max-width: 639px)"), M = F(
1260
+ () => lt({ locale: E, translations: g }),
1261
+ [E, g]
1262
+ ), { messages: D, isLoading: _, error: b, canRetry: j, sendMessage: m, retry: p } = ke({
1263
+ apiUrl: t,
1264
+ persistMessages: o,
1265
+ storageKeyPrefix: a,
1266
+ timeoutMs: l,
1267
+ translations: M
1268
+ }), H = N(null), S = N(f), { mode: G, cssVars: le } = vt(c), [de, q] = C(!1);
1269
+ k(() => {
1270
+ if (G !== "auto") return;
1271
+ const L = window.matchMedia("(prefers-color-scheme: dark)");
1272
+ q(L.matches);
1273
+ const Z = (xe) => q(xe.matches);
1274
+ return L.addEventListener("change", Z), () => L.removeEventListener("change", Z);
1275
+ }, [G]), k(() => {
1276
+ var L;
1277
+ S.current && !f && ((L = H.current) == null || L.focus()), S.current = f;
1278
+ }, [f]);
1279
+ const P = R(() => {
1280
+ O(!0), Rt();
1281
+ }, []), X = R(() => {
1282
+ w(!1), A.current && (A.current = !1, P());
1283
+ }, [P]), he = R(() => {
1284
+ w((L) => !L);
1285
+ }, []), Y = R(() => {
1286
+ A.current = !0, y(null), w(!0);
1287
+ }, []), fe = R((L) => {
1288
+ y(L);
1289
+ }, []), me = R(() => {
1290
+ y(null), Y();
1291
+ }, [Y]), ge = R(() => {
1292
+ y(null), P();
1293
+ }, [P]);
1294
+ Ie({
1295
+ triggers: x,
1296
+ enabled: !T && !f,
1297
+ onOpen: Y,
1298
+ onGreeting: fe
1299
+ });
1300
+ const be = G === "dark" || G === "auto" && de, J = {
1301
+ ...le,
1302
+ ...u ? {
1303
+ "--cl-color-accent": u,
1304
+ "--cl-color-accent-dark": u
1305
+ } : {}
1306
+ }, pe = Object.keys(J).length > 0 ? J : void 0;
1307
+ return (
1308
+ // Outer div carries theme token vars; the inner div carries the dark-mode
1309
+ // attribute so the [data-claudius-dark] token reassignments in styles.css
1310
+ // beat inherited (inline) light values.
1311
+ /* @__PURE__ */ i("div", { className: "claudius-root", style: pe, children: /* @__PURE__ */ d("div", { "data-claudius-dark": be ? "true" : "false", children: [
1312
+ f && I && /* @__PURE__ */ i(
1313
+ "div",
1314
+ {
1315
+ className: "claudius-scrim fixed inset-0 z-40 bg-claudius-scrim",
1316
+ onClick: X,
1317
+ "aria-hidden": "true"
1318
+ }
1319
+ ),
1320
+ f && /* @__PURE__ */ i(
1321
+ nt,
1322
+ {
1323
+ messages: D,
1324
+ isLoading: _,
1325
+ error: b,
1326
+ canRetry: j,
1327
+ onSend: m,
1328
+ onRetry: p,
1329
+ onClose: X,
1330
+ title: e ?? M.title,
1331
+ subtitle: r ?? M.subtitle,
1332
+ welcomeMessage: s ?? M.welcomeMessage,
1333
+ placeholder: n ?? M.placeholder,
1334
+ position: h,
1335
+ translations: M,
1336
+ isMobile: I
1337
+ }
1338
+ ),
1339
+ !(f && I) && /* @__PURE__ */ i(
1340
+ He,
1341
+ {
1342
+ ref: H,
1343
+ isOpen: f,
1344
+ onClick: he,
1345
+ position: h,
1346
+ translations: M
1347
+ }
1348
+ ),
1349
+ !f && v && /* @__PURE__ */ i(
1350
+ st,
1351
+ {
1352
+ message: v,
1353
+ position: h,
1354
+ onOpen: me,
1355
+ onDismiss: ge,
1356
+ dismissLabel: M.dismissGreeting
1357
+ }
1358
+ )
1359
+ ] }) })
1360
+ );
1361
+ }
1362
+ export {
1363
+ Me as ChatApiClient,
1364
+ U as ChatApiError,
1365
+ St as ChatWidget,
1366
+ se as DebounceError,
1367
+ ce as builtinThemes,
1368
+ Nt as createTranslations,
1369
+ ot as defaultTranslations,
1370
+ ut as detectLocale,
1371
+ ae as locales,
1372
+ lt as resolveTranslations
1373
+ };