@ariaflowagents/widget 0.5.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.
- package/README.md +113 -0
- package/dist/style.css +1 -0
- package/dist/widget.js +833 -0
- package/dist/widget.umd.cjs +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @ariaflowagents/widget
|
|
2
|
+
|
|
3
|
+
Embeddable chat widget for the AriaFlow Universal Inbox.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Include the widget script on your website:
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script src="https://cdn.yourdomain.com/widget/v1.js"></script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Add the widget element to your HTML:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<ariaflow-widget
|
|
19
|
+
widget-id="widget_abc123"
|
|
20
|
+
inbox-url="https://your-convex-app.convex.cloud"
|
|
21
|
+
position="bottom-right"
|
|
22
|
+
primary-color="#2563eb"
|
|
23
|
+
theme="light"
|
|
24
|
+
title="Chat with us"
|
|
25
|
+
subtitle="We typically reply within minutes">
|
|
26
|
+
</ariaflow-widget>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Attributes
|
|
30
|
+
|
|
31
|
+
| Attribute | Type | Default | Description |
|
|
32
|
+
|-----------|------|---------|-------------|
|
|
33
|
+
| `widget-id` | string | required | The public ID of your widget |
|
|
34
|
+
| `inbox-url` | string | required | Your Convex deployment URL |
|
|
35
|
+
| `position` | string | `"bottom-right"` | Widget position: `bottom-right`, `bottom-left`, `top-right`, `top-left` |
|
|
36
|
+
| `primary-color` | string | `"#2563eb"` | Widget theme color (hex) |
|
|
37
|
+
| `theme` | string | `"light"` | Theme: `light` or `dark` |
|
|
38
|
+
| `title` | string | `"Chat with us"` | Header title |
|
|
39
|
+
| `subtitle` | string | `"We typically reply within minutes"` | Header subtitle |
|
|
40
|
+
| `avatar-url` | string | - | Avatar image URL |
|
|
41
|
+
| `user-name` | string | - | Pre-fill user name |
|
|
42
|
+
| `user-email` | string | - | Pre-fill user email |
|
|
43
|
+
|
|
44
|
+
## Programmatic Usage
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { WidgetClient } from '@ariaflowagents/widget';
|
|
48
|
+
|
|
49
|
+
const client = new WidgetClient('https://your-convex-app.convex.cloud');
|
|
50
|
+
|
|
51
|
+
// Initialize
|
|
52
|
+
const config = await client.initWidget('widget_abc123');
|
|
53
|
+
|
|
54
|
+
// Get or create conversation
|
|
55
|
+
const conversationId = await client.getOrCreateConversation(
|
|
56
|
+
'user@example.com',
|
|
57
|
+
undefined,
|
|
58
|
+
'John Doe'
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Send message
|
|
62
|
+
await client.sendMessage('Hello!');
|
|
63
|
+
|
|
64
|
+
// Listen for messages
|
|
65
|
+
client.onMessages((messages) => {
|
|
66
|
+
console.log('New messages:', messages);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Get current messages
|
|
70
|
+
const messages = await client.getMessages();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Architecture
|
|
74
|
+
|
|
75
|
+
The widget uses a **Convex-first architecture**:
|
|
76
|
+
|
|
77
|
+
1. **Widget → Convex**: All messages go through Convex backend
|
|
78
|
+
2. **Convex → Agent**: Convex forwards messages to deployed AI agent
|
|
79
|
+
3. **Agent → Convex**: Agent responds via HTTP callback
|
|
80
|
+
4. **Convex → Widget**: Real-time updates via WebSocket
|
|
81
|
+
|
|
82
|
+
This ensures:
|
|
83
|
+
- Single source of truth for all messages
|
|
84
|
+
- Real-time sync across admin inbox and customer widget
|
|
85
|
+
- Centralized rate limiting and debugging
|
|
86
|
+
- No direct widget-agent connection needed
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Install dependencies
|
|
92
|
+
bun install
|
|
93
|
+
|
|
94
|
+
# Build widget
|
|
95
|
+
bun run build
|
|
96
|
+
|
|
97
|
+
# Watch mode
|
|
98
|
+
bun run dev
|
|
99
|
+
|
|
100
|
+
# Type check
|
|
101
|
+
bun run typecheck
|
|
102
|
+
|
|
103
|
+
# Clean
|
|
104
|
+
bun run clean
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Bundle Size
|
|
108
|
+
|
|
109
|
+
The widget is optimized to be under 50KB (gzipped) for fast loading.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ariaflow-widget-container{position:fixed;z-index:9999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,sans-serif;--ariaflow-accent-color: #14B8A6;--ariaflow-base-color: #ffffff;--ariaflow-window-bg: #ffffff;--ariaflow-messages-bg: #f8fafc;--ariaflow-text-primary: #1e293b;--ariaflow-text-secondary: #64748b;--ariaflow-border-color: #e2e8f0;--ariaflow-input-bg: #ffffff;--ariaflow-assistant-bubble-bg: #ffffff;--ariaflow-assistant-bubble-text: #1e293b;--ariaflow-input-focus-border: var(--ariaflow-accent-color)}.ariaflow-widget-bottom-right{bottom:20px;right:20px}.ariaflow-widget-bottom-left{bottom:20px;left:20px}.ariaflow-widget-top-right{top:20px;right:20px}.ariaflow-widget-top-left{top:20px;left:20px}.ariaflow-widget-launcher{width:60px;height:60px;border-radius:30px;border:none;cursor:pointer;display:flex;align-items:center;justify-content:center;color:#fff;box-shadow:0 4px 12px #00000026;transition:transform .2s,box-shadow .2s}.ariaflow-widget-launcher:hover{transform:scale(1.05);box-shadow:0 6px 16px #0003}.ariaflow-widget-window{max-height:calc(100vh - 40px);background:#fff;border-radius:16px;box-shadow:0 8px 32px #00000026;display:flex;flex-direction:column;overflow:hidden;animation:ariaflow-slide-up .3s ease-out}.ariaflow-widget-tiny .ariaflow-widget-window{width:320px;height:400px}.ariaflow-widget-compact .ariaflow-widget-window{width:360px;height:500px}.ariaflow-widget-full .ariaflow-widget-window{width:380px;height:600px}@keyframes ariaflow-slide-up{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}.ariaflow-widget-header{padding:16px 20px;color:#fff;display:flex;align-items:center;justify-content:space-between}.ariaflow-widget-header-content{display:flex;align-items:center;gap:12px}.ariaflow-widget-avatar{width:40px;height:40px;border-radius:20px;object-fit:cover}.ariaflow-widget-title-group{display:flex;flex-direction:column;gap:2px}.ariaflow-widget-title{margin:0;font-size:16px;font-weight:600}.ariaflow-widget-subtitle{margin:0;font-size:13px;opacity:.9}.ariaflow-widget-close{background:#fff3;border:none;border-radius:20px;width:32px;height:32px;display:flex;align-items:center;justify-content:center;color:#fff;cursor:pointer;transition:background .2s}.ariaflow-widget-close:hover{background:#ffffff4d}.ariaflow-widget-status{padding:8px 16px;display:flex;align-items:center;gap:8px;font-size:13px;color:#64748b;background:#f1f5f9}.ariaflow-widget-status-dot{width:8px;height:8px;border-radius:50%;background:#fbbf24;animation:ariaflow-pulse 1.5s infinite}@keyframes ariaflow-pulse{0%,to{opacity:1}50%{opacity:.5}}.ariaflow-widget-messages{flex:1;padding:16px;overflow-y:auto;display:flex;flex-direction:column;gap:12px;background:#f8fafc}.ariaflow-widget-empty{display:flex;align-items:center;justify-content:center;height:100%;color:#64748b;font-size:14px}.ariaflow-widget-message{display:flex}.ariaflow-widget-message-user{justify-content:flex-end}.ariaflow-widget-message-assistant{justify-content:flex-start}.ariaflow-widget-message-bubble{max-width:80%;padding:12px 16px;border-radius:16px;font-size:14px;line-height:1.5;word-wrap:break-word;white-space:pre-wrap}.ariaflow-widget-message-user .ariaflow-widget-message-bubble{background:var(--ariaflow-accent-color, #14B8A6);color:#fff;border-bottom-right-radius:4px}.ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg, #ffffff);color:var(--ariaflow-assistant-bubble-text, #1e293b);border:1px solid var(--ariaflow-border-color, #e2e8f0);border-bottom-left-radius:4px}.ariaflow-widget-input{padding:12px 16px;background:#fff;border-top:1px solid #e2e8f0;display:flex;gap:8px;align-items:flex-end}.ariaflow-widget-input textarea{flex:1;border:1px solid #e2e8f0;border-radius:20px;padding:10px 14px;font-size:14px;font-family:inherit;resize:none;max-height:100px;outline:none;transition:border-color .2s}.ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border, #2563eb)}.ariaflow-widget-input textarea::placeholder{color:#94a3b8}.ariaflow-widget-send{width:40px;height:40px;border-radius:20px;border:none;color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:opacity .2s,transform .2s;flex-shrink:0}.ariaflow-widget-send:hover:not(:disabled){transform:scale(1.05)}.ariaflow-widget-send:disabled{opacity:.5;cursor:not-allowed}.ariaflow-widget-container[data-theme=dark]{--ariaflow-window-bg: var(--ariaflow-base-color, #1e293b);--ariaflow-messages-bg: #0f172a;--ariaflow-text-primary: #f1f5f9;--ariaflow-text-secondary: #94a3b8;--ariaflow-border-color: #334155;--ariaflow-input-bg: #1e293b;--ariaflow-assistant-bubble-bg: #334155;--ariaflow-assistant-bubble-text: #f1f5f9;--ariaflow-input-focus-border: #3b82f6}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-window{background:var(--ariaflow-window-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages{background:var(--ariaflow-messages-bg)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-message-assistant .ariaflow-widget-message-bubble{background:var(--ariaflow-assistant-bubble-bg);color:var(--ariaflow-assistant-bubble-text);border-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input{background:var(--ariaflow-input-bg);border-top-color:var(--ariaflow-border-color)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea{background:var(--ariaflow-messages-bg);border-color:var(--ariaflow-border-color);color:var(--ariaflow-text-primary)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea:focus{border-color:var(--ariaflow-input-focus-border)}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-input textarea::placeholder{color:var(--ariaflow-text-secondary)}.ariaflow-widget-messages::-webkit-scrollbar{width:6px}.ariaflow-widget-messages::-webkit-scrollbar-track{background:transparent}.ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px}.ariaflow-widget-container[data-theme=dark] .ariaflow-widget-messages::-webkit-scrollbar-thumb{background:#475569}.ariaflow-widget-messages::-webkit-scrollbar-thumb:hover{background:#94a3b8}
|
package/dist/widget.js
ADDED
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
var B, m, Ae, T, de, Me, He, We, se, oe, re, R = {}, Te = [], Ye = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, X = Array.isArray;
|
|
2
|
+
function S(t, e) {
|
|
3
|
+
for (var n in e) t[n] = e[n];
|
|
4
|
+
return t;
|
|
5
|
+
}
|
|
6
|
+
function le(t) {
|
|
7
|
+
t && t.parentNode && t.parentNode.removeChild(t);
|
|
8
|
+
}
|
|
9
|
+
function D(t, e, n) {
|
|
10
|
+
var r, i, o, s = {};
|
|
11
|
+
for (o in e) o == "key" ? r = e[o] : o == "ref" ? i = e[o] : s[o] = e[o];
|
|
12
|
+
if (arguments.length > 2 && (s.children = arguments.length > 3 ? B.call(arguments, 2) : n), typeof t == "function" && t.defaultProps != null) for (o in t.defaultProps) s[o] === void 0 && (s[o] = t.defaultProps[o]);
|
|
13
|
+
return L(t, s, r, i, null);
|
|
14
|
+
}
|
|
15
|
+
function L(t, e, n, r, i) {
|
|
16
|
+
var o = { type: t, props: e, key: n, ref: r, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: i ?? ++Ae, __i: -1, __u: 0 };
|
|
17
|
+
return i == null && m.vnode != null && m.vnode(o), o;
|
|
18
|
+
}
|
|
19
|
+
function O(t) {
|
|
20
|
+
return t.children;
|
|
21
|
+
}
|
|
22
|
+
function q(t, e) {
|
|
23
|
+
this.props = t, this.context = e;
|
|
24
|
+
}
|
|
25
|
+
function I(t, e) {
|
|
26
|
+
if (e == null) return t.__ ? I(t.__, t.__i + 1) : null;
|
|
27
|
+
for (var n; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) return n.__e;
|
|
28
|
+
return typeof t.type == "function" ? I(t) : null;
|
|
29
|
+
}
|
|
30
|
+
function Pe(t) {
|
|
31
|
+
var e, n;
|
|
32
|
+
if ((t = t.__) != null && t.__c != null) {
|
|
33
|
+
for (t.__e = t.__c.base = null, e = 0; e < t.__k.length; e++) if ((n = t.__k[e]) != null && n.__e != null) {
|
|
34
|
+
t.__e = t.__c.base = n.__e;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return Pe(t);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function he(t) {
|
|
41
|
+
(!t.__d && (t.__d = !0) && T.push(t) && !J.__r++ || de != m.debounceRendering) && ((de = m.debounceRendering) || Me)(J);
|
|
42
|
+
}
|
|
43
|
+
function J() {
|
|
44
|
+
for (var t, e, n, r, i, o, s, l = 1; T.length; ) T.length > l && T.sort(He), t = T.shift(), l = T.length, t.__d && (n = void 0, r = void 0, i = (r = (e = t).__v).__e, o = [], s = [], e.__P && ((n = S({}, r)).__v = r.__v + 1, m.vnode && m.vnode(n), ae(e.__P, n, r, e.__n, e.__P.namespaceURI, 32 & r.__u ? [i] : null, o, i ?? I(r), !!(32 & r.__u), s), n.__v = r.__v, n.__.__k[n.__i] = n, De(o, n, s), r.__e = r.__ = null, n.__e != i && Pe(n)));
|
|
45
|
+
J.__r = 0;
|
|
46
|
+
}
|
|
47
|
+
function Fe(t, e, n, r, i, o, s, l, c, a, f) {
|
|
48
|
+
var _, d, u, v, k, y, g, h = r && r.__k || Te, N = e.length;
|
|
49
|
+
for (c = Ze(n, e, h, c, N), _ = 0; _ < N; _++) (u = n.__k[_]) != null && (d = u.__i == -1 ? R : h[u.__i] || R, u.__i = _, y = ae(t, u, d, i, o, s, l, c, a, f), v = u.__e, u.ref && d.ref != u.ref && (d.ref && ce(d.ref, null, u), f.push(u.ref, u.__c || v, u)), k == null && v != null && (k = v), (g = !!(4 & u.__u)) || d.__k === u.__k ? c = Ue(u, c, t, g) : typeof u.type == "function" && y !== void 0 ? c = y : v && (c = v.nextSibling), u.__u &= -7);
|
|
50
|
+
return n.__e = k, c;
|
|
51
|
+
}
|
|
52
|
+
function Ze(t, e, n, r, i) {
|
|
53
|
+
var o, s, l, c, a, f = n.length, _ = f, d = 0;
|
|
54
|
+
for (t.__k = new Array(i), o = 0; o < i; o++) (s = e[o]) != null && typeof s != "boolean" && typeof s != "function" ? (typeof s == "string" || typeof s == "number" || typeof s == "bigint" || s.constructor == String ? s = t.__k[o] = L(null, s, null, null, null) : X(s) ? s = t.__k[o] = L(O, { children: s }, null, null, null) : s.constructor === void 0 && s.__b > 0 ? s = t.__k[o] = L(s.type, s.props, s.key, s.ref ? s.ref : null, s.__v) : t.__k[o] = s, c = o + d, s.__ = t, s.__b = t.__b + 1, l = null, (a = s.__i = et(s, n, c, _)) != -1 && (_--, (l = n[a]) && (l.__u |= 2)), l == null || l.__v == null ? (a == -1 && (i > f ? d-- : i < f && d++), typeof s.type != "function" && (s.__u |= 4)) : a != c && (a == c - 1 ? d-- : a == c + 1 ? d++ : (a > c ? d-- : d++, s.__u |= 4))) : t.__k[o] = null;
|
|
55
|
+
if (_) for (o = 0; o < f; o++) (l = n[o]) != null && !(2 & l.__u) && (l.__e == r && (r = I(l)), Oe(l, l));
|
|
56
|
+
return r;
|
|
57
|
+
}
|
|
58
|
+
function Ue(t, e, n, r) {
|
|
59
|
+
var i, o;
|
|
60
|
+
if (typeof t.type == "function") {
|
|
61
|
+
for (i = t.__k, o = 0; i && o < i.length; o++) i[o] && (i[o].__ = t, e = Ue(i[o], e, n, r));
|
|
62
|
+
return e;
|
|
63
|
+
}
|
|
64
|
+
t.__e != e && (r && (e && t.type && !e.parentNode && (e = I(t)), n.insertBefore(t.__e, e || null)), e = t.__e);
|
|
65
|
+
do
|
|
66
|
+
e = e && e.nextSibling;
|
|
67
|
+
while (e != null && e.nodeType == 8);
|
|
68
|
+
return e;
|
|
69
|
+
}
|
|
70
|
+
function et(t, e, n, r) {
|
|
71
|
+
var i, o, s, l = t.key, c = t.type, a = e[n], f = a != null && (2 & a.__u) == 0;
|
|
72
|
+
if (a === null && l == null || f && l == a.key && c == a.type) return n;
|
|
73
|
+
if (r > (f ? 1 : 0)) {
|
|
74
|
+
for (i = n - 1, o = n + 1; i >= 0 || o < e.length; ) if ((a = e[s = i >= 0 ? i-- : o++]) != null && !(2 & a.__u) && l == a.key && c == a.type) return s;
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
}
|
|
78
|
+
function pe(t, e, n) {
|
|
79
|
+
e[0] == "-" ? t.setProperty(e, n ?? "") : t[e] = n == null ? "" : typeof n != "number" || Ye.test(e) ? n : n + "px";
|
|
80
|
+
}
|
|
81
|
+
function z(t, e, n, r, i) {
|
|
82
|
+
var o, s;
|
|
83
|
+
e: if (e == "style") if (typeof n == "string") t.style.cssText = n;
|
|
84
|
+
else {
|
|
85
|
+
if (typeof r == "string" && (t.style.cssText = r = ""), r) for (e in r) n && e in n || pe(t.style, e, "");
|
|
86
|
+
if (n) for (e in n) r && n[e] == r[e] || pe(t.style, e, n[e]);
|
|
87
|
+
}
|
|
88
|
+
else if (e[0] == "o" && e[1] == "n") o = e != (e = e.replace(We, "$1")), s = e.toLowerCase(), e = s in t || e == "onFocusOut" || e == "onFocusIn" ? s.slice(2) : e.slice(2), t.l || (t.l = {}), t.l[e + o] = n, n ? r ? n.u = r.u : (n.u = se, t.addEventListener(e, o ? re : oe, o)) : t.removeEventListener(e, o ? re : oe, o);
|
|
89
|
+
else {
|
|
90
|
+
if (i == "http://www.w3.org/2000/svg") e = e.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
|
|
91
|
+
else if (e != "width" && e != "height" && e != "href" && e != "list" && e != "form" && e != "tabIndex" && e != "download" && e != "rowSpan" && e != "colSpan" && e != "role" && e != "popover" && e in t) try {
|
|
92
|
+
t[e] = n ?? "";
|
|
93
|
+
break e;
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
typeof n == "function" || (n == null || n === !1 && e[4] != "-" ? t.removeAttribute(e) : t.setAttribute(e, e == "popover" && n == 1 ? "" : n));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function ge(t) {
|
|
100
|
+
return function(e) {
|
|
101
|
+
if (this.l) {
|
|
102
|
+
var n = this.l[e.type + t];
|
|
103
|
+
if (e.t == null) e.t = se++;
|
|
104
|
+
else if (e.t < n.u) return;
|
|
105
|
+
return n(m.event ? m.event(e) : e);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function ae(t, e, n, r, i, o, s, l, c, a) {
|
|
110
|
+
var f, _, d, u, v, k, y, g, h, N, C, P, M, V, A, H, W, $ = e.type;
|
|
111
|
+
if (e.constructor !== void 0) return null;
|
|
112
|
+
128 & n.__u && (c = !!(32 & n.__u), o = [l = e.__e = n.__e]), (f = m.__b) && f(e);
|
|
113
|
+
e: if (typeof $ == "function") try {
|
|
114
|
+
if (g = e.props, h = "prototype" in $ && $.prototype.render, N = (f = $.contextType) && r[f.__c], C = f ? N ? N.props.value : f.__ : r, n.__c ? y = (_ = e.__c = n.__c).__ = _.__E : (h ? e.__c = _ = new $(g, C) : (e.__c = _ = new q(g, C), _.constructor = $, _.render = nt), N && N.sub(_), _.state || (_.state = {}), _.__n = r, d = _.__d = !0, _.__h = [], _._sb = []), h && _.__s == null && (_.__s = _.state), h && $.getDerivedStateFromProps != null && (_.__s == _.state && (_.__s = S({}, _.__s)), S(_.__s, $.getDerivedStateFromProps(g, _.__s))), u = _.props, v = _.state, _.__v = e, d) h && $.getDerivedStateFromProps == null && _.componentWillMount != null && _.componentWillMount(), h && _.componentDidMount != null && _.__h.push(_.componentDidMount);
|
|
115
|
+
else {
|
|
116
|
+
if (h && $.getDerivedStateFromProps == null && g !== u && _.componentWillReceiveProps != null && _.componentWillReceiveProps(g, C), e.__v == n.__v || !_.__e && _.shouldComponentUpdate != null && _.shouldComponentUpdate(g, _.__s, C) === !1) {
|
|
117
|
+
for (e.__v != n.__v && (_.props = g, _.state = _.__s, _.__d = !1), e.__e = n.__e, e.__k = n.__k, e.__k.some(function(E) {
|
|
118
|
+
E && (E.__ = e);
|
|
119
|
+
}), P = 0; P < _._sb.length; P++) _.__h.push(_._sb[P]);
|
|
120
|
+
_._sb = [], _.__h.length && s.push(_);
|
|
121
|
+
break e;
|
|
122
|
+
}
|
|
123
|
+
_.componentWillUpdate != null && _.componentWillUpdate(g, _.__s, C), h && _.componentDidUpdate != null && _.__h.push(function() {
|
|
124
|
+
_.componentDidUpdate(u, v, k);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (_.context = C, _.props = g, _.__P = t, _.__e = !1, M = m.__r, V = 0, h) {
|
|
128
|
+
for (_.state = _.__s, _.__d = !1, M && M(e), f = _.render(_.props, _.state, _.context), A = 0; A < _._sb.length; A++) _.__h.push(_._sb[A]);
|
|
129
|
+
_._sb = [];
|
|
130
|
+
} else do
|
|
131
|
+
_.__d = !1, M && M(e), f = _.render(_.props, _.state, _.context), _.state = _.__s;
|
|
132
|
+
while (_.__d && ++V < 25);
|
|
133
|
+
_.state = _.__s, _.getChildContext != null && (r = S(S({}, r), _.getChildContext())), h && !d && _.getSnapshotBeforeUpdate != null && (k = _.getSnapshotBeforeUpdate(u, v)), H = f, f != null && f.type === O && f.key == null && (H = Ie(f.props.children)), l = Fe(t, X(H) ? H : [H], e, n, r, i, o, s, l, c, a), _.base = e.__e, e.__u &= -161, _.__h.length && s.push(_), y && (_.__E = _.__ = null);
|
|
134
|
+
} catch (E) {
|
|
135
|
+
if (e.__v = null, c || o != null) if (E.then) {
|
|
136
|
+
for (e.__u |= c ? 160 : 128; l && l.nodeType == 8 && l.nextSibling; ) l = l.nextSibling;
|
|
137
|
+
o[o.indexOf(l)] = null, e.__e = l;
|
|
138
|
+
} else {
|
|
139
|
+
for (W = o.length; W--; ) le(o[W]);
|
|
140
|
+
ie(e);
|
|
141
|
+
}
|
|
142
|
+
else e.__e = n.__e, e.__k = n.__k, E.then || ie(e);
|
|
143
|
+
m.__e(E, e, n);
|
|
144
|
+
}
|
|
145
|
+
else o == null && e.__v == n.__v ? (e.__k = n.__k, e.__e = n.__e) : l = e.__e = tt(n.__e, e, n, r, i, o, s, c, a);
|
|
146
|
+
return (f = m.diffed) && f(e), 128 & e.__u ? void 0 : l;
|
|
147
|
+
}
|
|
148
|
+
function ie(t) {
|
|
149
|
+
t && t.__c && (t.__c.__e = !0), t && t.__k && t.__k.forEach(ie);
|
|
150
|
+
}
|
|
151
|
+
function De(t, e, n) {
|
|
152
|
+
for (var r = 0; r < n.length; r++) ce(n[r], n[++r], n[++r]);
|
|
153
|
+
m.__c && m.__c(e, t), t.some(function(i) {
|
|
154
|
+
try {
|
|
155
|
+
t = i.__h, i.__h = [], t.some(function(o) {
|
|
156
|
+
o.call(i);
|
|
157
|
+
});
|
|
158
|
+
} catch (o) {
|
|
159
|
+
m.__e(o, i.__v);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function Ie(t) {
|
|
164
|
+
return typeof t != "object" || t == null || t.__b && t.__b > 0 ? t : X(t) ? t.map(Ie) : S({}, t);
|
|
165
|
+
}
|
|
166
|
+
function tt(t, e, n, r, i, o, s, l, c) {
|
|
167
|
+
var a, f, _, d, u, v, k, y = n.props || R, g = e.props, h = e.type;
|
|
168
|
+
if (h == "svg" ? i = "http://www.w3.org/2000/svg" : h == "math" ? i = "http://www.w3.org/1998/Math/MathML" : i || (i = "http://www.w3.org/1999/xhtml"), o != null) {
|
|
169
|
+
for (a = 0; a < o.length; a++) if ((u = o[a]) && "setAttribute" in u == !!h && (h ? u.localName == h : u.nodeType == 3)) {
|
|
170
|
+
t = u, o[a] = null;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (t == null) {
|
|
175
|
+
if (h == null) return document.createTextNode(g);
|
|
176
|
+
t = document.createElementNS(i, h, g.is && g), l && (m.__m && m.__m(e, o), l = !1), o = null;
|
|
177
|
+
}
|
|
178
|
+
if (h == null) y === g || l && t.data == g || (t.data = g);
|
|
179
|
+
else {
|
|
180
|
+
if (o = o && B.call(t.childNodes), !l && o != null) for (y = {}, a = 0; a < t.attributes.length; a++) y[(u = t.attributes[a]).name] = u.value;
|
|
181
|
+
for (a in y) if (u = y[a], a != "children") {
|
|
182
|
+
if (a == "dangerouslySetInnerHTML") _ = u;
|
|
183
|
+
else if (!(a in g)) {
|
|
184
|
+
if (a == "value" && "defaultValue" in g || a == "checked" && "defaultChecked" in g) continue;
|
|
185
|
+
z(t, a, null, u, i);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
for (a in g) u = g[a], a == "children" ? d = u : a == "dangerouslySetInnerHTML" ? f = u : a == "value" ? v = u : a == "checked" ? k = u : l && typeof u != "function" || y[a] === u || z(t, a, u, y[a], i);
|
|
189
|
+
if (f) l || _ && (f.__html == _.__html || f.__html == t.innerHTML) || (t.innerHTML = f.__html), e.__k = [];
|
|
190
|
+
else if (_ && (t.innerHTML = ""), Fe(e.type == "template" ? t.content : t, X(d) ? d : [d], e, n, r, h == "foreignObject" ? "http://www.w3.org/1999/xhtml" : i, o, s, o ? o[0] : n.__k && I(n, 0), l, c), o != null) for (a = o.length; a--; ) le(o[a]);
|
|
191
|
+
l || (a = "value", h == "progress" && v == null ? t.removeAttribute("value") : v != null && (v !== t[a] || h == "progress" && !v || h == "option" && v != y[a]) && z(t, a, v, y[a], i), a = "checked", k != null && k != t[a] && z(t, a, k, y[a], i));
|
|
192
|
+
}
|
|
193
|
+
return t;
|
|
194
|
+
}
|
|
195
|
+
function ce(t, e, n) {
|
|
196
|
+
try {
|
|
197
|
+
if (typeof t == "function") {
|
|
198
|
+
var r = typeof t.__u == "function";
|
|
199
|
+
r && t.__u(), r && e == null || (t.__u = t(e));
|
|
200
|
+
} else t.current = e;
|
|
201
|
+
} catch (i) {
|
|
202
|
+
m.__e(i, n);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function Oe(t, e, n) {
|
|
206
|
+
var r, i;
|
|
207
|
+
if (m.unmount && m.unmount(t), (r = t.ref) && (r.current && r.current != t.__e || ce(r, null, e)), (r = t.__c) != null) {
|
|
208
|
+
if (r.componentWillUnmount) try {
|
|
209
|
+
r.componentWillUnmount();
|
|
210
|
+
} catch (o) {
|
|
211
|
+
m.__e(o, e);
|
|
212
|
+
}
|
|
213
|
+
r.base = r.__P = null;
|
|
214
|
+
}
|
|
215
|
+
if (r = t.__k) for (i = 0; i < r.length; i++) r[i] && Oe(r[i], e, n || typeof t.type != "function");
|
|
216
|
+
n || le(t.__e), t.__c = t.__ = t.__e = void 0;
|
|
217
|
+
}
|
|
218
|
+
function nt(t, e, n) {
|
|
219
|
+
return this.constructor(t, n);
|
|
220
|
+
}
|
|
221
|
+
function Y(t, e, n) {
|
|
222
|
+
var r, i, o, s;
|
|
223
|
+
e == document && (e = document.documentElement), m.__ && m.__(t, e), i = (r = typeof n == "function") ? null : n && n.__k || e.__k, o = [], s = [], ae(e, t = (!r && n || e).__k = D(O, null, [t]), i || R, R, e.namespaceURI, !r && n ? [n] : i ? null : e.firstChild ? B.call(e.childNodes) : null, o, !r && n ? n : i ? i.__e : e.firstChild, r, s), De(o, t, s);
|
|
224
|
+
}
|
|
225
|
+
function Le(t, e) {
|
|
226
|
+
Y(t, e, Le);
|
|
227
|
+
}
|
|
228
|
+
function Re(t, e, n) {
|
|
229
|
+
var r, i, o, s, l = S({}, t.props);
|
|
230
|
+
for (o in t.type && t.type.defaultProps && (s = t.type.defaultProps), e) o == "key" ? r = e[o] : o == "ref" ? i = e[o] : l[o] = e[o] === void 0 && s != null ? s[o] : e[o];
|
|
231
|
+
return arguments.length > 2 && (l.children = arguments.length > 3 ? B.call(arguments, 2) : n), L(t.type, l, r || t.key, i || t.ref, null);
|
|
232
|
+
}
|
|
233
|
+
B = Te.slice, m = { __e: function(t, e, n, r) {
|
|
234
|
+
for (var i, o, s; e = e.__; ) if ((i = e.__c) && !i.__) try {
|
|
235
|
+
if ((o = i.constructor) && o.getDerivedStateFromError != null && (i.setState(o.getDerivedStateFromError(t)), s = i.__d), i.componentDidCatch != null && (i.componentDidCatch(t, r || {}), s = i.__d), s) return i.__E = i;
|
|
236
|
+
} catch (l) {
|
|
237
|
+
t = l;
|
|
238
|
+
}
|
|
239
|
+
throw t;
|
|
240
|
+
} }, Ae = 0, q.prototype.setState = function(t, e) {
|
|
241
|
+
var n;
|
|
242
|
+
n = this.__s != null && this.__s != this.state ? this.__s : this.__s = S({}, this.state), typeof t == "function" && (t = t(S({}, n), this.props)), t && S(n, t), t != null && this.__v && (e && this._sb.push(e), he(this));
|
|
243
|
+
}, q.prototype.forceUpdate = function(t) {
|
|
244
|
+
this.__v && (this.__e = !0, t && this.__h.push(t), he(this));
|
|
245
|
+
}, q.prototype.render = O, T = [], Me = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, He = function(t, e) {
|
|
246
|
+
return t.__v.__b - e.__v.__b;
|
|
247
|
+
}, J.__r = 0, We = /(PointerCapture)$|Capture$/i, se = 0, oe = ge(!1), re = ge(!0);
|
|
248
|
+
function G() {
|
|
249
|
+
return G = Object.assign ? Object.assign.bind() : function(t) {
|
|
250
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
251
|
+
var n = arguments[e];
|
|
252
|
+
for (var r in n) Object.prototype.hasOwnProperty.call(n, r) && (t[r] = n[r]);
|
|
253
|
+
}
|
|
254
|
+
return t;
|
|
255
|
+
}, G.apply(this, arguments);
|
|
256
|
+
}
|
|
257
|
+
function je(t, e) {
|
|
258
|
+
if (t == null) return {};
|
|
259
|
+
var n, r, i = {}, o = Object.keys(t);
|
|
260
|
+
for (r = 0; r < o.length; r++) e.indexOf(n = o[r]) >= 0 || (i[n] = t[n]);
|
|
261
|
+
return i;
|
|
262
|
+
}
|
|
263
|
+
var ot = ["context", "children"], rt = ["useFragment"];
|
|
264
|
+
function it(t, e, n, r) {
|
|
265
|
+
function i() {
|
|
266
|
+
var o = Reflect.construct(HTMLElement, [], i);
|
|
267
|
+
return o._vdomComponent = t, o._root = o, o;
|
|
268
|
+
}
|
|
269
|
+
return (i.prototype = Object.create(HTMLElement.prototype)).constructor = i, i.prototype.connectedCallback = function() {
|
|
270
|
+
st.call(this, r);
|
|
271
|
+
}, i.prototype.attributeChangedCallback = lt, i.prototype.disconnectedCallback = at, n = n || t.observedAttributes || Object.keys(t.propTypes || {}), i.observedAttributes = n, t.formAssociated && (i.formAssociated = !0), n.forEach(function(o) {
|
|
272
|
+
Object.defineProperty(i.prototype, o, { get: function() {
|
|
273
|
+
return this._vdom ? this._vdom.props[o] : this._props[o];
|
|
274
|
+
}, set: function(s) {
|
|
275
|
+
this._vdom ? this.attributeChangedCallback(o, null, s) : (this._props || (this._props = {}), this._props[o] = s);
|
|
276
|
+
var l = typeof s;
|
|
277
|
+
s != null && l !== "string" && l !== "boolean" && l !== "number" || this.setAttribute(o, s);
|
|
278
|
+
} });
|
|
279
|
+
}), customElements.define(e, i), i;
|
|
280
|
+
}
|
|
281
|
+
function _t(t) {
|
|
282
|
+
this.getChildContext = function() {
|
|
283
|
+
return t.context;
|
|
284
|
+
};
|
|
285
|
+
var e = t.children, n = je(t, ot);
|
|
286
|
+
return Re(e, n);
|
|
287
|
+
}
|
|
288
|
+
function st(t) {
|
|
289
|
+
var e = new CustomEvent("_preact", { detail: {}, bubbles: !0, cancelable: !0 });
|
|
290
|
+
this.dispatchEvent(e), this._vdom = D(_t, G({}, this._props, { context: e.detail.context }), Ve(this, this._vdomComponent, t)), (this.hasAttribute("hydrate") ? Le : Y)(this._vdom, this._root);
|
|
291
|
+
}
|
|
292
|
+
function Be(t) {
|
|
293
|
+
return t.replace(/-(\w)/g, function(e, n) {
|
|
294
|
+
return n ? n.toUpperCase() : "";
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function lt(t, e, n) {
|
|
298
|
+
if (this._vdom) {
|
|
299
|
+
var r = {};
|
|
300
|
+
r[t] = n = n ?? void 0, r[Be(t)] = n, this._vdom = Re(this._vdom, r), Y(this._vdom, this._root);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function at() {
|
|
304
|
+
Y(this._vdom = null, this._root);
|
|
305
|
+
}
|
|
306
|
+
function me(t, e) {
|
|
307
|
+
var n = this, r = t.useFragment, i = je(t, rt);
|
|
308
|
+
return D(r ? O : "slot", G({}, i, { ref: function(o) {
|
|
309
|
+
o ? (n.ref = o, n._listener || (n._listener = function(s) {
|
|
310
|
+
s.stopPropagation(), s.detail.context = e;
|
|
311
|
+
}, o.addEventListener("_preact", n._listener))) : n.ref.removeEventListener("_preact", n._listener);
|
|
312
|
+
} }));
|
|
313
|
+
}
|
|
314
|
+
function Ve(t, e, n) {
|
|
315
|
+
if (t.nodeType === 3) return t.data;
|
|
316
|
+
if (t.nodeType !== 1) return null;
|
|
317
|
+
var r = [], i = {}, o = 0, s = t.attributes, l = t.childNodes;
|
|
318
|
+
for (o = s.length; o--; ) s[o].name !== "slot" && (i[s[o].name] = s[o].value, i[Be(s[o].name)] = s[o].value);
|
|
319
|
+
for (o = l.length; o--; ) {
|
|
320
|
+
var c = Ve(l[o], null, n), a = l[o].slot;
|
|
321
|
+
a ? i[a] = D(me, { name: a }, c) : r[o] = c;
|
|
322
|
+
}
|
|
323
|
+
var f = !(!n || !n.shadow), _ = e ? D(me, { useFragment: !f }, r) : r;
|
|
324
|
+
return !f && e && (t.innerHTML = ""), D(e || t.nodeName.toLowerCase(), i, _);
|
|
325
|
+
}
|
|
326
|
+
var ct = 0;
|
|
327
|
+
function p(t, e, n, r, i, o) {
|
|
328
|
+
e || (e = {});
|
|
329
|
+
var s, l, c = e;
|
|
330
|
+
if ("ref" in c) for (l in c = {}, e) l == "ref" ? s = e[l] : c[l] = e[l];
|
|
331
|
+
var a = { type: t, props: c, key: n, ref: s, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --ct, __i: -1, __u: 0, __source: i, __self: o };
|
|
332
|
+
if (typeof t == "function" && (s = t.defaultProps)) for (l in s) c[l] === void 0 && (c[l] = s[l]);
|
|
333
|
+
return m.vnode && m.vnode(a), a;
|
|
334
|
+
}
|
|
335
|
+
var j, w, ee, ve, Q = 0, ze = [], b = m, ye = b.__b, we = b.__r, be = b.diffed, ke = b.__c, Ce = b.unmount, $e = b.__;
|
|
336
|
+
function ue(t, e) {
|
|
337
|
+
b.__h && b.__h(w, t, Q || e), Q = 0;
|
|
338
|
+
var n = w.__H || (w.__H = { __: [], __h: [] });
|
|
339
|
+
return t >= n.__.length && n.__.push({}), n.__[t];
|
|
340
|
+
}
|
|
341
|
+
function U(t) {
|
|
342
|
+
return Q = 1, ut(Ke, t);
|
|
343
|
+
}
|
|
344
|
+
function ut(t, e, n) {
|
|
345
|
+
var r = ue(j++, 2);
|
|
346
|
+
if (r.t = t, !r.__c && (r.__ = [Ke(void 0, e), function(l) {
|
|
347
|
+
var c = r.__N ? r.__N[0] : r.__[0], a = r.t(c, l);
|
|
348
|
+
c !== a && (r.__N = [a, r.__[1]], r.__c.setState({}));
|
|
349
|
+
}], r.__c = w, !w.__f)) {
|
|
350
|
+
var i = function(l, c, a) {
|
|
351
|
+
if (!r.__c.__H) return !0;
|
|
352
|
+
var f = r.__c.__H.__.filter(function(d) {
|
|
353
|
+
return !!d.__c;
|
|
354
|
+
});
|
|
355
|
+
if (f.every(function(d) {
|
|
356
|
+
return !d.__N;
|
|
357
|
+
})) return !o || o.call(this, l, c, a);
|
|
358
|
+
var _ = r.__c.props !== l;
|
|
359
|
+
return f.forEach(function(d) {
|
|
360
|
+
if (d.__N) {
|
|
361
|
+
var u = d.__[0];
|
|
362
|
+
d.__ = d.__N, d.__N = void 0, u !== d.__[0] && (_ = !0);
|
|
363
|
+
}
|
|
364
|
+
}), o && o.call(this, l, c, a) || _;
|
|
365
|
+
};
|
|
366
|
+
w.__f = !0;
|
|
367
|
+
var o = w.shouldComponentUpdate, s = w.componentWillUpdate;
|
|
368
|
+
w.componentWillUpdate = function(l, c, a) {
|
|
369
|
+
if (this.__e) {
|
|
370
|
+
var f = o;
|
|
371
|
+
o = void 0, i(l, c, a), o = f;
|
|
372
|
+
}
|
|
373
|
+
s && s.call(this, l, c, a);
|
|
374
|
+
}, w.shouldComponentUpdate = i;
|
|
375
|
+
}
|
|
376
|
+
return r.__N || r.__;
|
|
377
|
+
}
|
|
378
|
+
function xe(t, e) {
|
|
379
|
+
var n = ue(j++, 3);
|
|
380
|
+
!b.__s && qe(n.__H, e) && (n.__ = t, n.u = e, w.__H.__h.push(n));
|
|
381
|
+
}
|
|
382
|
+
function Ne(t) {
|
|
383
|
+
return Q = 5, ft(function() {
|
|
384
|
+
return { current: t };
|
|
385
|
+
}, []);
|
|
386
|
+
}
|
|
387
|
+
function ft(t, e) {
|
|
388
|
+
var n = ue(j++, 7);
|
|
389
|
+
return qe(n.__H, e) && (n.__ = t(), n.__H = e, n.__h = t), n.__;
|
|
390
|
+
}
|
|
391
|
+
function dt() {
|
|
392
|
+
for (var t; t = ze.shift(); ) if (t.__P && t.__H) try {
|
|
393
|
+
t.__H.__h.forEach(K), t.__H.__h.forEach(_e), t.__H.__h = [];
|
|
394
|
+
} catch (e) {
|
|
395
|
+
t.__H.__h = [], b.__e(e, t.__v);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
b.__b = function(t) {
|
|
399
|
+
w = null, ye && ye(t);
|
|
400
|
+
}, b.__ = function(t, e) {
|
|
401
|
+
t && e.__k && e.__k.__m && (t.__m = e.__k.__m), $e && $e(t, e);
|
|
402
|
+
}, b.__r = function(t) {
|
|
403
|
+
we && we(t), j = 0;
|
|
404
|
+
var e = (w = t.__c).__H;
|
|
405
|
+
e && (ee === w ? (e.__h = [], w.__h = [], e.__.forEach(function(n) {
|
|
406
|
+
n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
|
|
407
|
+
})) : (e.__h.forEach(K), e.__h.forEach(_e), e.__h = [], j = 0)), ee = w;
|
|
408
|
+
}, b.diffed = function(t) {
|
|
409
|
+
be && be(t);
|
|
410
|
+
var e = t.__c;
|
|
411
|
+
e && e.__H && (e.__H.__h.length && (ze.push(e) !== 1 && ve === b.requestAnimationFrame || ((ve = b.requestAnimationFrame) || ht)(dt)), e.__H.__.forEach(function(n) {
|
|
412
|
+
n.u && (n.__H = n.u), n.u = void 0;
|
|
413
|
+
})), ee = w = null;
|
|
414
|
+
}, b.__c = function(t, e) {
|
|
415
|
+
e.some(function(n) {
|
|
416
|
+
try {
|
|
417
|
+
n.__h.forEach(K), n.__h = n.__h.filter(function(r) {
|
|
418
|
+
return !r.__ || _e(r);
|
|
419
|
+
});
|
|
420
|
+
} catch (r) {
|
|
421
|
+
e.some(function(i) {
|
|
422
|
+
i.__h && (i.__h = []);
|
|
423
|
+
}), e = [], b.__e(r, n.__v);
|
|
424
|
+
}
|
|
425
|
+
}), ke && ke(t, e);
|
|
426
|
+
}, b.unmount = function(t) {
|
|
427
|
+
Ce && Ce(t);
|
|
428
|
+
var e, n = t.__c;
|
|
429
|
+
n && n.__H && (n.__H.__.forEach(function(r) {
|
|
430
|
+
try {
|
|
431
|
+
K(r);
|
|
432
|
+
} catch (i) {
|
|
433
|
+
e = i;
|
|
434
|
+
}
|
|
435
|
+
}), n.__H = void 0, e && b.__e(e, n.__v));
|
|
436
|
+
};
|
|
437
|
+
var Se = typeof requestAnimationFrame == "function";
|
|
438
|
+
function ht(t) {
|
|
439
|
+
var e, n = function() {
|
|
440
|
+
clearTimeout(r), Se && cancelAnimationFrame(e), setTimeout(t);
|
|
441
|
+
}, r = setTimeout(n, 35);
|
|
442
|
+
Se && (e = requestAnimationFrame(n));
|
|
443
|
+
}
|
|
444
|
+
function K(t) {
|
|
445
|
+
var e = w, n = t.__c;
|
|
446
|
+
typeof n == "function" && (t.__c = void 0, n()), w = e;
|
|
447
|
+
}
|
|
448
|
+
function _e(t) {
|
|
449
|
+
var e = w;
|
|
450
|
+
t.__c = t.__(), w = e;
|
|
451
|
+
}
|
|
452
|
+
function qe(t, e) {
|
|
453
|
+
return !t || t.length !== e.length || e.some(function(n, r) {
|
|
454
|
+
return n !== t[r];
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function Ke(t, e) {
|
|
458
|
+
return typeof e == "function" ? e(t) : e;
|
|
459
|
+
}
|
|
460
|
+
const pt = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
461
|
+
let te = (t = 21) => {
|
|
462
|
+
let e = "", n = crypto.getRandomValues(new Uint8Array(t |= 0));
|
|
463
|
+
for (; t--; )
|
|
464
|
+
e += pt[n[t] & 63];
|
|
465
|
+
return e;
|
|
466
|
+
};
|
|
467
|
+
class gt {
|
|
468
|
+
constructor(e) {
|
|
469
|
+
this.apiUrl = e, this.config = null, this.ws = null, this.messageCallbacks = /* @__PURE__ */ new Set(), this.connectionCallbacks = /* @__PURE__ */ new Set(), this.messages = [], this.reconnectAttempts = 0, this.maxReconnectAttempts = 5, this.reconnectDelay = 1e3;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Initialize the widget by fetching config from TanStack Start API
|
|
473
|
+
*/
|
|
474
|
+
async initWidget(e) {
|
|
475
|
+
try {
|
|
476
|
+
const n = await fetch(`${this.apiUrl}/api/widget/${e}`);
|
|
477
|
+
if (!n.ok)
|
|
478
|
+
throw new Error(`Failed to fetch widget config: ${n.status}`);
|
|
479
|
+
const r = await n.json();
|
|
480
|
+
return !r || !r.isActive ? (console.error("Widget not found or inactive"), null) : (this.config = r, await this.connectToAgent(), r);
|
|
481
|
+
} catch (n) {
|
|
482
|
+
return console.error("Failed to initialize widget:", n), null;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Connect directly to the agent via WebSocket
|
|
487
|
+
*/
|
|
488
|
+
async connectToAgent() {
|
|
489
|
+
if (!this.config?.agentUrl)
|
|
490
|
+
throw new Error("No agent URL configured");
|
|
491
|
+
const e = this.getSessionId(), n = `${this.config.agentUrl}/agents/chat/${e}`;
|
|
492
|
+
return new Promise((r, i) => {
|
|
493
|
+
try {
|
|
494
|
+
this.ws = new WebSocket(n), this.ws.onopen = () => {
|
|
495
|
+
console.log("[Widget] Connected to agent"), this.reconnectAttempts = 0, this.notifyConnectionChange(!0), r();
|
|
496
|
+
}, this.ws.onmessage = (o) => {
|
|
497
|
+
this.handleMessage(o);
|
|
498
|
+
}, this.ws.onclose = () => {
|
|
499
|
+
if (console.log("[Widget] Disconnected from agent"), this.notifyConnectionChange(!1), this.reconnectAttempts < this.maxReconnectAttempts) {
|
|
500
|
+
this.reconnectAttempts++;
|
|
501
|
+
const o = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
502
|
+
console.log(`[Widget] Reconnecting in ${o}ms... (attempt ${this.reconnectAttempts})`), setTimeout(() => this.connectToAgent(), o);
|
|
503
|
+
}
|
|
504
|
+
}, this.ws.onerror = (o) => {
|
|
505
|
+
console.error("[Widget] WebSocket error:", o), i(o);
|
|
506
|
+
};
|
|
507
|
+
} catch (o) {
|
|
508
|
+
i(o);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Handle incoming WebSocket messages from the agent
|
|
514
|
+
*/
|
|
515
|
+
handleMessage(e) {
|
|
516
|
+
try {
|
|
517
|
+
const n = JSON.parse(e.data);
|
|
518
|
+
n.type === "text-delta" ? this.setMessages((r) => {
|
|
519
|
+
const i = r[r.length - 1];
|
|
520
|
+
return i && i.role === "assistant" ? [
|
|
521
|
+
...r.slice(0, -1),
|
|
522
|
+
{ ...i, content: i.content + n.text }
|
|
523
|
+
] : [
|
|
524
|
+
...r,
|
|
525
|
+
{ id: te(), role: "assistant", content: n.text, timestamp: Date.now() }
|
|
526
|
+
];
|
|
527
|
+
}) : n.type === "done" ? console.log("[Widget] Response complete") : n.type === "handoff" ? console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`) : n.type === "tool-call" ? console.log("[Widget] Tool call:", n.tool) : console.log("[Widget] Unknown message type:", n.type);
|
|
528
|
+
} catch (n) {
|
|
529
|
+
console.error("[Widget] Error parsing message:", e.data, n);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Send a message via WebSocket
|
|
534
|
+
*/
|
|
535
|
+
async sendMessage(e) {
|
|
536
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN)
|
|
537
|
+
throw new Error("Not connected to agent");
|
|
538
|
+
const n = {
|
|
539
|
+
id: te(),
|
|
540
|
+
role: "user",
|
|
541
|
+
content: e,
|
|
542
|
+
timestamp: Date.now()
|
|
543
|
+
};
|
|
544
|
+
this.setMessages((i) => [...i, n]);
|
|
545
|
+
const r = this.getSessionId();
|
|
546
|
+
this.ws.send(JSON.stringify({ message: e, sessionId: r }));
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Get or generate session ID
|
|
550
|
+
*/
|
|
551
|
+
getSessionId() {
|
|
552
|
+
let e = sessionStorage.getItem("ariaflow_session_id");
|
|
553
|
+
return e || (e = te(), sessionStorage.setItem("ariaflow_session_id", e)), e;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Update messages state
|
|
557
|
+
*/
|
|
558
|
+
setMessages(e) {
|
|
559
|
+
this.messages = e(this.messages), this.messageCallbacks.forEach((n) => n(this.messages));
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Register a callback for message updates
|
|
563
|
+
*/
|
|
564
|
+
onMessages(e) {
|
|
565
|
+
return this.messageCallbacks.add(e), e(this.messages), () => {
|
|
566
|
+
this.messageCallbacks.delete(e);
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Register a callback for connection state changes
|
|
571
|
+
*/
|
|
572
|
+
onConnectionChange(e) {
|
|
573
|
+
return this.connectionCallbacks.add(e), () => {
|
|
574
|
+
this.connectionCallbacks.delete(e);
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Notify all connection callbacks
|
|
579
|
+
*/
|
|
580
|
+
notifyConnectionChange(e) {
|
|
581
|
+
this.connectionCallbacks.forEach((n) => n(e));
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Get current messages
|
|
585
|
+
*/
|
|
586
|
+
getMessages() {
|
|
587
|
+
return this.messages;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Get the current configuration
|
|
591
|
+
*/
|
|
592
|
+
getConfig() {
|
|
593
|
+
return this.config;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Check if connected
|
|
597
|
+
*/
|
|
598
|
+
isConnected() {
|
|
599
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Disconnect and cleanup
|
|
603
|
+
*/
|
|
604
|
+
dispose() {
|
|
605
|
+
this.ws && (this.ws.close(), this.ws = null), this.messageCallbacks.clear(), this.connectionCallbacks.clear();
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const ne = {
|
|
609
|
+
none: "0",
|
|
610
|
+
small: "0.375rem",
|
|
611
|
+
medium: "0.75rem",
|
|
612
|
+
large: "1rem"
|
|
613
|
+
};
|
|
614
|
+
function mt({
|
|
615
|
+
widgetId: t,
|
|
616
|
+
apiUrl: e,
|
|
617
|
+
mode: n = "chat",
|
|
618
|
+
theme: r = "light",
|
|
619
|
+
position: i = "bottom-right",
|
|
620
|
+
size: o = "full",
|
|
621
|
+
radius: s = "medium",
|
|
622
|
+
baseColor: l,
|
|
623
|
+
accentColor: c = "#14B8A6",
|
|
624
|
+
buttonBaseColor: a = "#000000",
|
|
625
|
+
buttonAccentColor: f = "#FFFFFF",
|
|
626
|
+
title: _,
|
|
627
|
+
subtitle: d,
|
|
628
|
+
emptyChatMessage: u
|
|
629
|
+
}) {
|
|
630
|
+
const [v, k] = U(!1), [y, g] = U([]), [h, N] = U(""), [C, P] = U(!1), [M, V] = U(!1), [A, H] = U(null), W = Ne(null), $ = Ne(null);
|
|
631
|
+
xe(() => ((async () => {
|
|
632
|
+
const F = new gt(e);
|
|
633
|
+
W.current = F;
|
|
634
|
+
const fe = await F.initWidget(t);
|
|
635
|
+
fe && (H(fe), V(!0), F.onMessages((Z) => {
|
|
636
|
+
g(Z);
|
|
637
|
+
}), F.onConnectionChange((Z) => {
|
|
638
|
+
P(Z);
|
|
639
|
+
}));
|
|
640
|
+
})(), () => {
|
|
641
|
+
W.current?.dispose();
|
|
642
|
+
}), [t, e]), xe(() => {
|
|
643
|
+
$.current?.scrollIntoView({ behavior: "smooth" });
|
|
644
|
+
}, [y]);
|
|
645
|
+
const E = async () => {
|
|
646
|
+
if (!h.trim() || !C) return;
|
|
647
|
+
const x = h.trim();
|
|
648
|
+
N("");
|
|
649
|
+
try {
|
|
650
|
+
await W.current?.sendMessage(x);
|
|
651
|
+
} catch (F) {
|
|
652
|
+
console.error("Failed to send message:", F);
|
|
653
|
+
}
|
|
654
|
+
}, Je = (x) => {
|
|
655
|
+
x.key === "Enter" && !x.shiftKey && (x.preventDefault(), E());
|
|
656
|
+
};
|
|
657
|
+
if (!M)
|
|
658
|
+
return null;
|
|
659
|
+
const Ge = _ || A?.title || "Chat with us", Qe = d || A?.subtitle || "We typically reply within minutes", Xe = u || A?.config?.emptyChatMessage || "Start a conversation...";
|
|
660
|
+
return /* @__PURE__ */ p(
|
|
661
|
+
"div",
|
|
662
|
+
{
|
|
663
|
+
className: `ariaflow-widget-container ariaflow-widget-${i} ariaflow-widget-${o} ariaflow-widget-radius-${s}`,
|
|
664
|
+
"data-theme": r,
|
|
665
|
+
style: {
|
|
666
|
+
"--ariaflow-accent-color": c,
|
|
667
|
+
"--ariaflow-base-color": l
|
|
668
|
+
},
|
|
669
|
+
children: [
|
|
670
|
+
!v && /* @__PURE__ */ p(
|
|
671
|
+
"button",
|
|
672
|
+
{
|
|
673
|
+
className: "ariaflow-widget-launcher",
|
|
674
|
+
onClick: () => k(!0),
|
|
675
|
+
style: {
|
|
676
|
+
backgroundColor: a,
|
|
677
|
+
color: f
|
|
678
|
+
},
|
|
679
|
+
"aria-label": "Open chat",
|
|
680
|
+
children: /* @__PURE__ */ p(
|
|
681
|
+
"svg",
|
|
682
|
+
{
|
|
683
|
+
width: "24",
|
|
684
|
+
height: "24",
|
|
685
|
+
viewBox: "0 0 24 24",
|
|
686
|
+
fill: "none",
|
|
687
|
+
stroke: "currentColor",
|
|
688
|
+
strokeWidth: "2",
|
|
689
|
+
children: /* @__PURE__ */ p("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
|
|
690
|
+
}
|
|
691
|
+
)
|
|
692
|
+
}
|
|
693
|
+
),
|
|
694
|
+
v && /* @__PURE__ */ p(
|
|
695
|
+
"div",
|
|
696
|
+
{
|
|
697
|
+
className: "ariaflow-widget-window",
|
|
698
|
+
style: {
|
|
699
|
+
backgroundColor: r === "dark" && l ? l : void 0,
|
|
700
|
+
borderRadius: ne[s]
|
|
701
|
+
},
|
|
702
|
+
children: [
|
|
703
|
+
/* @__PURE__ */ p(
|
|
704
|
+
"div",
|
|
705
|
+
{
|
|
706
|
+
className: "ariaflow-widget-header",
|
|
707
|
+
style: {
|
|
708
|
+
backgroundColor: c,
|
|
709
|
+
borderRadius: s === "none" ? "0" : `${ne[s]} ${ne[s]} 0 0`
|
|
710
|
+
},
|
|
711
|
+
children: [
|
|
712
|
+
/* @__PURE__ */ p("div", { className: "ariaflow-widget-header-content", children: /* @__PURE__ */ p("div", { className: "ariaflow-widget-title-group", children: [
|
|
713
|
+
/* @__PURE__ */ p("h3", { className: "ariaflow-widget-title", children: Ge }),
|
|
714
|
+
/* @__PURE__ */ p("p", { className: "ariaflow-widget-subtitle", children: Qe })
|
|
715
|
+
] }) }),
|
|
716
|
+
/* @__PURE__ */ p(
|
|
717
|
+
"button",
|
|
718
|
+
{
|
|
719
|
+
className: "ariaflow-widget-close",
|
|
720
|
+
onClick: () => k(!1),
|
|
721
|
+
"aria-label": "Close chat",
|
|
722
|
+
children: /* @__PURE__ */ p(
|
|
723
|
+
"svg",
|
|
724
|
+
{
|
|
725
|
+
width: "20",
|
|
726
|
+
height: "20",
|
|
727
|
+
viewBox: "0 0 24 24",
|
|
728
|
+
fill: "none",
|
|
729
|
+
stroke: "currentColor",
|
|
730
|
+
strokeWidth: "2",
|
|
731
|
+
children: [
|
|
732
|
+
/* @__PURE__ */ p("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
733
|
+
/* @__PURE__ */ p("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
734
|
+
]
|
|
735
|
+
}
|
|
736
|
+
)
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
),
|
|
742
|
+
!C && /* @__PURE__ */ p("div", { className: "ariaflow-widget-status", children: [
|
|
743
|
+
/* @__PURE__ */ p("span", { className: "ariaflow-widget-status-dot" }),
|
|
744
|
+
"Connecting..."
|
|
745
|
+
] }),
|
|
746
|
+
/* @__PURE__ */ p("div", { className: "ariaflow-widget-messages", children: y.length === 0 ? /* @__PURE__ */ p("div", { className: "ariaflow-widget-empty", children: /* @__PURE__ */ p("p", { children: C ? Xe : "Connecting to agent..." }) }) : /* @__PURE__ */ p(O, { children: [
|
|
747
|
+
y.map((x) => /* @__PURE__ */ p(
|
|
748
|
+
"div",
|
|
749
|
+
{
|
|
750
|
+
className: `ariaflow-widget-message ariaflow-widget-message-${x.role}`,
|
|
751
|
+
children: /* @__PURE__ */ p("div", { className: "ariaflow-widget-message-bubble", children: x.content })
|
|
752
|
+
},
|
|
753
|
+
x.id
|
|
754
|
+
)),
|
|
755
|
+
/* @__PURE__ */ p("div", { ref: $ })
|
|
756
|
+
] }) }),
|
|
757
|
+
/* @__PURE__ */ p("div", { className: "ariaflow-widget-input", children: [
|
|
758
|
+
/* @__PURE__ */ p(
|
|
759
|
+
"textarea",
|
|
760
|
+
{
|
|
761
|
+
value: h,
|
|
762
|
+
onInput: (x) => N(x.target.value),
|
|
763
|
+
onKeyDown: Je,
|
|
764
|
+
placeholder: C ? "Type your message..." : "Connecting...",
|
|
765
|
+
rows: 1,
|
|
766
|
+
disabled: !C
|
|
767
|
+
}
|
|
768
|
+
),
|
|
769
|
+
/* @__PURE__ */ p(
|
|
770
|
+
"button",
|
|
771
|
+
{
|
|
772
|
+
className: "ariaflow-widget-send",
|
|
773
|
+
onClick: E,
|
|
774
|
+
disabled: !h.trim() || !C,
|
|
775
|
+
style: { backgroundColor: c },
|
|
776
|
+
"aria-label": "Send message",
|
|
777
|
+
children: /* @__PURE__ */ p(
|
|
778
|
+
"svg",
|
|
779
|
+
{
|
|
780
|
+
width: "18",
|
|
781
|
+
height: "18",
|
|
782
|
+
viewBox: "0 0 24 24",
|
|
783
|
+
fill: "none",
|
|
784
|
+
stroke: "currentColor",
|
|
785
|
+
strokeWidth: "2",
|
|
786
|
+
children: [
|
|
787
|
+
/* @__PURE__ */ p("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
|
|
788
|
+
/* @__PURE__ */ p("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
|
|
789
|
+
]
|
|
790
|
+
}
|
|
791
|
+
)
|
|
792
|
+
}
|
|
793
|
+
)
|
|
794
|
+
] })
|
|
795
|
+
]
|
|
796
|
+
}
|
|
797
|
+
)
|
|
798
|
+
]
|
|
799
|
+
}
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
it(
|
|
803
|
+
mt,
|
|
804
|
+
"ariaflow-widget",
|
|
805
|
+
// Properties to observe from HTML attributes (mirror Vapi's naming convention)
|
|
806
|
+
[
|
|
807
|
+
"widget-id",
|
|
808
|
+
"api-url",
|
|
809
|
+
"mode",
|
|
810
|
+
"theme",
|
|
811
|
+
"position",
|
|
812
|
+
"size",
|
|
813
|
+
"radius",
|
|
814
|
+
"base-color",
|
|
815
|
+
"accent-color",
|
|
816
|
+
"button-base-color",
|
|
817
|
+
"button-accent-color",
|
|
818
|
+
"title",
|
|
819
|
+
"subtitle",
|
|
820
|
+
"empty-chat-message"
|
|
821
|
+
],
|
|
822
|
+
// Shadow DOM (optional, set to false for light DOM)
|
|
823
|
+
!1
|
|
824
|
+
);
|
|
825
|
+
typeof document < "u" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", Ee) : Ee());
|
|
826
|
+
function Ee() {
|
|
827
|
+
const t = document.querySelectorAll("ariaflow-widget");
|
|
828
|
+
console.log(`[AriaFlow] Initializing ${t.length} widget(s)`);
|
|
829
|
+
}
|
|
830
|
+
export {
|
|
831
|
+
mt as Widget,
|
|
832
|
+
gt as WidgetClient
|
|
833
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(W,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(W=typeof globalThis<"u"?globalThis:W||self,E(W.AriaFlowWidget={}))})(this,function(W){"use strict";var E,g,de,T,he,pe,ge,me,ee,te,ne,j={},ve=[],Xe=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,z=Array.isArray;function S(t,e){for(var n in e)t[n]=e[n];return t}function oe(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function U(t,e,n){var i,r,o,s={};for(o in e)o=="key"?i=e[o]:o=="ref"?r=e[o]:s[o]=e[o];if(arguments.length>2&&(s.children=arguments.length>3?E.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return B(t,s,i,r,null)}function B(t,e,n,i,r){var o={type:t,props:e,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:r??++de,__i:-1,__u:0};return r==null&&g.vnode!=null&&g.vnode(o),o}function D(t){return t.children}function q(t,e){this.props=t,this.context=e}function I(t,e){if(e==null)return t.__?I(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?I(t):null}function ye(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return ye(t)}}function we(t){(!t.__d&&(t.__d=!0)&&T.push(t)&&!K.__r++||he!=g.debounceRendering)&&((he=g.debounceRendering)||pe)(K)}function K(){for(var t,e,n,i,r,o,s,l=1;T.length;)T.length>l&&T.sort(ge),t=T.shift(),l=T.length,t.__d&&(n=void 0,i=void 0,r=(i=(e=t).__v).__e,o=[],s=[],e.__P&&((n=S({},i)).__v=i.__v+1,g.vnode&&g.vnode(n),ie(e.__P,n,i,e.__n,e.__P.namespaceURI,32&i.__u?[r]:null,o,r??I(i),!!(32&i.__u),s),n.__v=i.__v,n.__.__k[n.__i]=n,xe(o,n,s),i.__e=i.__=null,n.__e!=r&&ye(n)));K.__r=0}function be(t,e,n,i,r,o,s,l,c,a,f){var _,d,u,y,k,w,m,h=i&&i.__k||ve,N=e.length;for(c=Ye(n,e,h,c,N),_=0;_<N;_++)(u=n.__k[_])!=null&&(d=u.__i==-1?j:h[u.__i]||j,u.__i=_,w=ie(t,u,d,r,o,s,l,c,a,f),y=u.__e,u.ref&&d.ref!=u.ref&&(d.ref&&_e(d.ref,null,u),f.push(u.ref,u.__c||y,u)),k==null&&y!=null&&(k=y),(m=!!(4&u.__u))||d.__k===u.__k?c=ke(u,c,t,m):typeof u.type=="function"&&w!==void 0?c=w:y&&(c=y.nextSibling),u.__u&=-7);return n.__e=k,c}function Ye(t,e,n,i,r){var o,s,l,c,a,f=n.length,_=f,d=0;for(t.__k=new Array(r),o=0;o<r;o++)(s=e[o])!=null&&typeof s!="boolean"&&typeof s!="function"?(typeof s=="string"||typeof s=="number"||typeof s=="bigint"||s.constructor==String?s=t.__k[o]=B(null,s,null,null,null):z(s)?s=t.__k[o]=B(D,{children:s},null,null,null):s.constructor===void 0&&s.__b>0?s=t.__k[o]=B(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):t.__k[o]=s,c=o+d,s.__=t,s.__b=t.__b+1,l=null,(a=s.__i=Ze(s,n,c,_))!=-1&&(_--,(l=n[a])&&(l.__u|=2)),l==null||l.__v==null?(a==-1&&(r>f?d--:r<f&&d++),typeof s.type!="function"&&(s.__u|=4)):a!=c&&(a==c-1?d--:a==c+1?d++:(a>c?d--:d++,s.__u|=4))):t.__k[o]=null;if(_)for(o=0;o<f;o++)(l=n[o])!=null&&!(2&l.__u)&&(l.__e==i&&(i=I(l)),Se(l,l));return i}function ke(t,e,n,i){var r,o;if(typeof t.type=="function"){for(r=t.__k,o=0;r&&o<r.length;o++)r[o]&&(r[o].__=t,e=ke(r[o],e,n,i));return e}t.__e!=e&&(i&&(e&&t.type&&!e.parentNode&&(e=I(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function Ze(t,e,n,i){var r,o,s,l=t.key,c=t.type,a=e[n],f=a!=null&&(2&a.__u)==0;if(a===null&&l==null||f&&l==a.key&&c==a.type)return n;if(i>(f?1:0)){for(r=n-1,o=n+1;r>=0||o<e.length;)if((a=e[s=r>=0?r--:o++])!=null&&!(2&a.__u)&&l==a.key&&c==a.type)return s}return-1}function Ce(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||Xe.test(e)?n:n+"px"}function J(t,e,n,i,r){var o,s;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof i=="string"&&(t.style.cssText=i=""),i)for(e in i)n&&e in n||Ce(t.style,e,"");if(n)for(e in n)i&&n[e]==i[e]||Ce(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(me,"$1")),s=e.toLowerCase(),e=s in t||e=="onFocusOut"||e=="onFocusIn"?s.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+o]=n,n?i?n.u=i.u:(n.u=ee,t.addEventListener(e,o?ne:te,o)):t.removeEventListener(e,o?ne:te,o);else{if(r=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function $e(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ee++;else if(e.t<n.u)return;return n(g.event?g.event(e):e)}}}function ie(t,e,n,i,r,o,s,l,c,a){var f,_,d,u,y,k,w,m,h,N,C,L,H,Z,M,P,F,$=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(c=!!(32&n.__u),o=[l=e.__e=n.__e]),(f=g.__b)&&f(e);e:if(typeof $=="function")try{if(m=e.props,h="prototype"in $&&$.prototype.render,N=(f=$.contextType)&&i[f.__c],C=f?N?N.props.value:f.__:i,n.__c?w=(_=e.__c=n.__c).__=_.__E:(h?e.__c=_=new $(m,C):(e.__c=_=new q(m,C),_.constructor=$,_.render=tt),N&&N.sub(_),_.state||(_.state={}),_.__n=i,d=_.__d=!0,_.__h=[],_._sb=[]),h&&_.__s==null&&(_.__s=_.state),h&&$.getDerivedStateFromProps!=null&&(_.__s==_.state&&(_.__s=S({},_.__s)),S(_.__s,$.getDerivedStateFromProps(m,_.__s))),u=_.props,y=_.state,_.__v=e,d)h&&$.getDerivedStateFromProps==null&&_.componentWillMount!=null&&_.componentWillMount(),h&&_.componentDidMount!=null&&_.__h.push(_.componentDidMount);else{if(h&&$.getDerivedStateFromProps==null&&m!==u&&_.componentWillReceiveProps!=null&&_.componentWillReceiveProps(m,C),e.__v==n.__v||!_.__e&&_.shouldComponentUpdate!=null&&_.shouldComponentUpdate(m,_.__s,C)===!1){for(e.__v!=n.__v&&(_.props=m,_.state=_.__s,_.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(A){A&&(A.__=e)}),L=0;L<_._sb.length;L++)_.__h.push(_._sb[L]);_._sb=[],_.__h.length&&s.push(_);break e}_.componentWillUpdate!=null&&_.componentWillUpdate(m,_.__s,C),h&&_.componentDidUpdate!=null&&_.__h.push(function(){_.componentDidUpdate(u,y,k)})}if(_.context=C,_.props=m,_.__P=t,_.__e=!1,H=g.__r,Z=0,h){for(_.state=_.__s,_.__d=!1,H&&H(e),f=_.render(_.props,_.state,_.context),M=0;M<_._sb.length;M++)_.__h.push(_._sb[M]);_._sb=[]}else do _.__d=!1,H&&H(e),f=_.render(_.props,_.state,_.context),_.state=_.__s;while(_.__d&&++Z<25);_.state=_.__s,_.getChildContext!=null&&(i=S(S({},i),_.getChildContext())),h&&!d&&_.getSnapshotBeforeUpdate!=null&&(k=_.getSnapshotBeforeUpdate(u,y)),P=f,f!=null&&f.type===D&&f.key==null&&(P=Ne(f.props.children)),l=be(t,z(P)?P:[P],e,n,i,r,o,s,l,c,a),_.base=e.__e,e.__u&=-161,_.__h.length&&s.push(_),w&&(_.__E=_.__=null)}catch(A){if(e.__v=null,c||o!=null)if(A.then){for(e.__u|=c?160:128;l&&l.nodeType==8&&l.nextSibling;)l=l.nextSibling;o[o.indexOf(l)]=null,e.__e=l}else{for(F=o.length;F--;)oe(o[F]);re(e)}else e.__e=n.__e,e.__k=n.__k,A.then||re(e);g.__e(A,e,n)}else o==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):l=e.__e=et(n.__e,e,n,i,r,o,s,c,a);return(f=g.diffed)&&f(e),128&e.__u?void 0:l}function re(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(re)}function xe(t,e,n){for(var i=0;i<n.length;i++)_e(n[i],n[++i],n[++i]);g.__c&&g.__c(e,t),t.some(function(r){try{t=r.__h,r.__h=[],t.some(function(o){o.call(r)})}catch(o){g.__e(o,r.__v)}})}function Ne(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:z(t)?t.map(Ne):S({},t)}function et(t,e,n,i,r,o,s,l,c){var a,f,_,d,u,y,k,w=n.props||j,m=e.props,h=e.type;if(h=="svg"?r="http://www.w3.org/2000/svg":h=="math"?r="http://www.w3.org/1998/Math/MathML":r||(r="http://www.w3.org/1999/xhtml"),o!=null){for(a=0;a<o.length;a++)if((u=o[a])&&"setAttribute"in u==!!h&&(h?u.localName==h:u.nodeType==3)){t=u,o[a]=null;break}}if(t==null){if(h==null)return document.createTextNode(m);t=document.createElementNS(r,h,m.is&&m),l&&(g.__m&&g.__m(e,o),l=!1),o=null}if(h==null)w===m||l&&t.data==m||(t.data=m);else{if(o=o&&E.call(t.childNodes),!l&&o!=null)for(w={},a=0;a<t.attributes.length;a++)w[(u=t.attributes[a]).name]=u.value;for(a in w)if(u=w[a],a!="children"){if(a=="dangerouslySetInnerHTML")_=u;else if(!(a in m)){if(a=="value"&&"defaultValue"in m||a=="checked"&&"defaultChecked"in m)continue;J(t,a,null,u,r)}}for(a in m)u=m[a],a=="children"?d=u:a=="dangerouslySetInnerHTML"?f=u:a=="value"?y=u:a=="checked"?k=u:l&&typeof u!="function"||w[a]===u||J(t,a,u,w[a],r);if(f)l||_&&(f.__html==_.__html||f.__html==t.innerHTML)||(t.innerHTML=f.__html),e.__k=[];else if(_&&(t.innerHTML=""),be(e.type=="template"?t.content:t,z(d)?d:[d],e,n,i,h=="foreignObject"?"http://www.w3.org/1999/xhtml":r,o,s,o?o[0]:n.__k&&I(n,0),l,c),o!=null)for(a=o.length;a--;)oe(o[a]);l||(a="value",h=="progress"&&y==null?t.removeAttribute("value"):y!=null&&(y!==t[a]||h=="progress"&&!y||h=="option"&&y!=w[a])&&J(t,a,y,w[a],r),a="checked",k!=null&&k!=t[a]&&J(t,a,k,w[a],r))}return t}function _e(t,e,n){try{if(typeof t=="function"){var i=typeof t.__u=="function";i&&t.__u(),i&&e==null||(t.__u=t(e))}else t.current=e}catch(r){g.__e(r,n)}}function Se(t,e,n){var i,r;if(g.unmount&&g.unmount(t),(i=t.ref)&&(i.current&&i.current!=t.__e||_e(i,null,e)),(i=t.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(o){g.__e(o,e)}i.base=i.__P=null}if(i=t.__k)for(r=0;r<i.length;r++)i[r]&&Se(i[r],e,n||typeof t.type!="function");n||oe(t.__e),t.__c=t.__=t.__e=void 0}function tt(t,e,n){return this.constructor(t,n)}function G(t,e,n){var i,r,o,s;e==document&&(e=document.documentElement),g.__&&g.__(t,e),r=(i=typeof n=="function")?null:n&&n.__k||e.__k,o=[],s=[],ie(e,t=(!i&&n||e).__k=U(D,null,[t]),r||j,j,e.namespaceURI,!i&&n?[n]:r?null:e.firstChild?E.call(e.childNodes):null,o,!i&&n?n:r?r.__e:e.firstChild,i,s),xe(o,t,s)}function Ee(t,e){G(t,e,Ee)}function Ae(t,e,n){var i,r,o,s,l=S({},t.props);for(o in t.type&&t.type.defaultProps&&(s=t.type.defaultProps),e)o=="key"?i=e[o]:o=="ref"?r=e[o]:l[o]=e[o]===void 0&&s!=null?s[o]:e[o];return arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):n),B(t.type,l,i||t.key,r||t.ref,null)}E=ve.slice,g={__e:function(t,e,n,i){for(var r,o,s;e=e.__;)if((r=e.__c)&&!r.__)try{if((o=r.constructor)&&o.getDerivedStateFromError!=null&&(r.setState(o.getDerivedStateFromError(t)),s=r.__d),r.componentDidCatch!=null&&(r.componentDidCatch(t,i||{}),s=r.__d),s)return r.__E=r}catch(l){t=l}throw t}},de=0,q.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=S({},this.state),typeof t=="function"&&(t=t(S({},n),this.props)),t&&S(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),we(this))},q.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),we(this))},q.prototype.render=D,T=[],pe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ge=function(t,e){return t.__v.__b-e.__v.__b},K.__r=0,me=/(PointerCapture)$|Capture$/i,ee=0,te=$e(!1),ne=$e(!0);function Q(){return Q=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},Q.apply(this,arguments)}function Me(t,e){if(t==null)return{};var n,i,r={},o=Object.keys(t);for(i=0;i<o.length;i++)e.indexOf(n=o[i])>=0||(r[n]=t[n]);return r}var nt=["context","children"],ot=["useFragment"];function it(t,e,n,i){function r(){var o=Reflect.construct(HTMLElement,[],r);return o._vdomComponent=t,o._root=o,o}return(r.prototype=Object.create(HTMLElement.prototype)).constructor=r,r.prototype.connectedCallback=function(){_t.call(this,i)},r.prototype.attributeChangedCallback=st,r.prototype.disconnectedCallback=lt,n=n||t.observedAttributes||Object.keys(t.propTypes||{}),r.observedAttributes=n,t.formAssociated&&(r.formAssociated=!0),n.forEach(function(o){Object.defineProperty(r.prototype,o,{get:function(){return this._vdom?this._vdom.props[o]:this._props[o]},set:function(s){this._vdom?this.attributeChangedCallback(o,null,s):(this._props||(this._props={}),this._props[o]=s);var l=typeof s;s!=null&&l!=="string"&&l!=="boolean"&&l!=="number"||this.setAttribute(o,s)}})}),customElements.define(e,r),r}function rt(t){this.getChildContext=function(){return t.context};var e=t.children,n=Me(t,nt);return Ae(e,n)}function _t(t){var e=new CustomEvent("_preact",{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e),this._vdom=U(rt,Q({},this._props,{context:e.detail.context}),He(this,this._vdomComponent,t)),(this.hasAttribute("hydrate")?Ee:G)(this._vdom,this._root)}function We(t){return t.replace(/-(\w)/g,function(e,n){return n?n.toUpperCase():""})}function st(t,e,n){if(this._vdom){var i={};i[t]=n=n??void 0,i[We(t)]=n,this._vdom=Ae(this._vdom,i),G(this._vdom,this._root)}}function lt(){G(this._vdom=null,this._root)}function Te(t,e){var n=this,i=t.useFragment,r=Me(t,ot);return U(i?D:"slot",Q({},r,{ref:function(o){o?(n.ref=o,n._listener||(n._listener=function(s){s.stopPropagation(),s.detail.context=e},o.addEventListener("_preact",n._listener))):n.ref.removeEventListener("_preact",n._listener)}}))}function He(t,e,n){if(t.nodeType===3)return t.data;if(t.nodeType!==1)return null;var i=[],r={},o=0,s=t.attributes,l=t.childNodes;for(o=s.length;o--;)s[o].name!=="slot"&&(r[s[o].name]=s[o].value,r[We(s[o].name)]=s[o].value);for(o=l.length;o--;){var c=He(l[o],null,n),a=l[o].slot;a?r[a]=U(Te,{name:a},c):i[o]=c}var f=!(!n||!n.shadow),_=e?U(Te,{useFragment:!f},i):i;return!f&&e&&(t.innerHTML=""),U(e||t.nodeName.toLowerCase(),r,_)}var at=0;function p(t,e,n,i,r,o){e||(e={});var s,l,c=e;if("ref"in c)for(l in c={},e)l=="ref"?s=e[l]:c[l]=e[l];var a={type:t,props:c,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--at,__i:-1,__u:0,__source:r,__self:o};if(typeof t=="function"&&(s=t.defaultProps))for(l in s)c[l]===void 0&&(c[l]=s[l]);return g.vnode&&g.vnode(a),a}var V,v,se,Pe,X=0,Fe=[],b=g,Ue=b.__b,De=b.__r,Ie=b.diffed,Oe=b.__c,Le=b.unmount,Re=b.__;function le(t,e){b.__h&&b.__h(v,t,X||e),X=0;var n=v.__H||(v.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function O(t){return X=1,ct(qe,t)}function ct(t,e,n){var i=le(V++,2);if(i.t=t,!i.__c&&(i.__=[qe(void 0,e),function(l){var c=i.__N?i.__N[0]:i.__[0],a=i.t(c,l);c!==a&&(i.__N=[a,i.__[1]],i.__c.setState({}))}],i.__c=v,!v.__f)){var r=function(l,c,a){if(!i.__c.__H)return!0;var f=i.__c.__H.__.filter(function(d){return!!d.__c});if(f.every(function(d){return!d.__N}))return!o||o.call(this,l,c,a);var _=i.__c.props!==l;return f.forEach(function(d){if(d.__N){var u=d.__[0];d.__=d.__N,d.__N=void 0,u!==d.__[0]&&(_=!0)}}),o&&o.call(this,l,c,a)||_};v.__f=!0;var o=v.shouldComponentUpdate,s=v.componentWillUpdate;v.componentWillUpdate=function(l,c,a){if(this.__e){var f=o;o=void 0,r(l,c,a),o=f}s&&s.call(this,l,c,a)},v.shouldComponentUpdate=r}return i.__N||i.__}function je(t,e){var n=le(V++,3);!b.__s&&ze(n.__H,e)&&(n.__=t,n.u=e,v.__H.__h.push(n))}function Be(t){return X=5,ut(function(){return{current:t}},[])}function ut(t,e){var n=le(V++,7);return ze(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function ft(){for(var t;t=Fe.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Y),t.__H.__h.forEach(ae),t.__H.__h=[]}catch(e){t.__H.__h=[],b.__e(e,t.__v)}}b.__b=function(t){v=null,Ue&&Ue(t)},b.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Re&&Re(t,e)},b.__r=function(t){De&&De(t),V=0;var e=(v=t.__c).__H;e&&(se===v?(e.__h=[],v.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(Y),e.__h.forEach(ae),e.__h=[],V=0)),se=v},b.diffed=function(t){Ie&&Ie(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Fe.push(e)!==1&&Pe===b.requestAnimationFrame||((Pe=b.requestAnimationFrame)||dt)(ft)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),se=v=null},b.__c=function(t,e){e.some(function(n){try{n.__h.forEach(Y),n.__h=n.__h.filter(function(i){return!i.__||ae(i)})}catch(i){e.some(function(r){r.__h&&(r.__h=[])}),e=[],b.__e(i,n.__v)}}),Oe&&Oe(t,e)},b.unmount=function(t){Le&&Le(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(i){try{Y(i)}catch(r){e=r}}),n.__H=void 0,e&&b.__e(e,n.__v))};var Ve=typeof requestAnimationFrame=="function";function dt(t){var e,n=function(){clearTimeout(i),Ve&&cancelAnimationFrame(e),setTimeout(t)},i=setTimeout(n,35);Ve&&(e=requestAnimationFrame(n))}function Y(t){var e=v,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),v=e}function ae(t){var e=v;t.__c=t.__(),v=e}function ze(t,e){return!t||t.length!==e.length||e.some(function(n,i){return n!==t[i]})}function qe(t,e){return typeof e=="function"?e(t):e}const ht="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ce=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=ht[n[t]&63];return e};class Ke{constructor(e){this.apiUrl=e,this.config=null,this.ws=null,this.messageCallbacks=new Set,this.connectionCallbacks=new Set,this.messages=[],this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectDelay=1e3}async initWidget(e){try{const n=await fetch(`${this.apiUrl}/api/widget/${e}`);if(!n.ok)throw new Error(`Failed to fetch widget config: ${n.status}`);const i=await n.json();return!i||!i.isActive?(console.error("Widget not found or inactive"),null):(this.config=i,await this.connectToAgent(),i)}catch(n){return console.error("Failed to initialize widget:",n),null}}async connectToAgent(){if(!this.config?.agentUrl)throw new Error("No agent URL configured");const e=this.getSessionId(),n=`${this.config.agentUrl}/agents/chat/${e}`;return new Promise((i,r)=>{try{this.ws=new WebSocket(n),this.ws.onopen=()=>{console.log("[Widget] Connected to agent"),this.reconnectAttempts=0,this.notifyConnectionChange(!0),i()},this.ws.onmessage=o=>{this.handleMessage(o)},this.ws.onclose=()=>{if(console.log("[Widget] Disconnected from agent"),this.notifyConnectionChange(!1),this.reconnectAttempts<this.maxReconnectAttempts){this.reconnectAttempts++;const o=this.reconnectDelay*Math.pow(2,this.reconnectAttempts-1);console.log(`[Widget] Reconnecting in ${o}ms... (attempt ${this.reconnectAttempts})`),setTimeout(()=>this.connectToAgent(),o)}},this.ws.onerror=o=>{console.error("[Widget] WebSocket error:",o),r(o)}}catch(o){r(o)}})}handleMessage(e){try{const n=JSON.parse(e.data);n.type==="text-delta"?this.setMessages(i=>{const r=i[i.length-1];return r&&r.role==="assistant"?[...i.slice(0,-1),{...r,content:r.content+n.text}]:[...i,{id:ce(),role:"assistant",content:n.text,timestamp:Date.now()}]}):n.type==="done"?console.log("[Widget] Response complete"):n.type==="handoff"?console.log(`[Widget] Handoff: ${n.from} -> ${n.to}: ${n.reason}`):n.type==="tool-call"?console.log("[Widget] Tool call:",n.tool):console.log("[Widget] Unknown message type:",n.type)}catch(n){console.error("[Widget] Error parsing message:",e.data,n)}}async sendMessage(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("Not connected to agent");const n={id:ce(),role:"user",content:e,timestamp:Date.now()};this.setMessages(r=>[...r,n]);const i=this.getSessionId();this.ws.send(JSON.stringify({message:e,sessionId:i}))}getSessionId(){let e=sessionStorage.getItem("ariaflow_session_id");return e||(e=ce(),sessionStorage.setItem("ariaflow_session_id",e)),e}setMessages(e){this.messages=e(this.messages),this.messageCallbacks.forEach(n=>n(this.messages))}onMessages(e){return this.messageCallbacks.add(e),e(this.messages),()=>{this.messageCallbacks.delete(e)}}onConnectionChange(e){return this.connectionCallbacks.add(e),()=>{this.connectionCallbacks.delete(e)}}notifyConnectionChange(e){this.connectionCallbacks.forEach(n=>n(e))}getMessages(){return this.messages}getConfig(){return this.config}isConnected(){return this.ws?.readyState===WebSocket.OPEN}dispose(){this.ws&&(this.ws.close(),this.ws=null),this.messageCallbacks.clear(),this.connectionCallbacks.clear()}}const ue={none:"0",small:"0.375rem",medium:"0.75rem",large:"1rem"};function Je({widgetId:t,apiUrl:e,mode:n="chat",theme:i="light",position:r="bottom-right",size:o="full",radius:s="medium",baseColor:l,accentColor:c="#14B8A6",buttonBaseColor:a="#000000",buttonAccentColor:f="#FFFFFF",title:_,subtitle:d,emptyChatMessage:u}){const[y,k]=O(!1),[w,m]=O([]),[h,N]=O(""),[C,L]=O(!1),[H,Z]=O(!1),[M,P]=O(null),F=Be(null),$=Be(null);je(()=>((async()=>{const R=new Ke(e);F.current=R;const Qe=await R.initWidget(t);Qe&&(P(Qe),Z(!0),R.onMessages(fe=>{m(fe)}),R.onConnectionChange(fe=>{L(fe)}))})(),()=>{F.current?.dispose()}),[t,e]),je(()=>{$.current?.scrollIntoView({behavior:"smooth"})},[w]);const A=async()=>{if(!h.trim()||!C)return;const x=h.trim();N("");try{await F.current?.sendMessage(x)}catch(R){console.error("Failed to send message:",R)}},pt=x=>{x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),A())};if(!H)return null;const gt=_||M?.title||"Chat with us",mt=d||M?.subtitle||"We typically reply within minutes",vt=u||M?.config?.emptyChatMessage||"Start a conversation...";return p("div",{className:`ariaflow-widget-container ariaflow-widget-${r} ariaflow-widget-${o} ariaflow-widget-radius-${s}`,"data-theme":i,style:{"--ariaflow-accent-color":c,"--ariaflow-base-color":l},children:[!y&&p("button",{className:"ariaflow-widget-launcher",onClick:()=>k(!0),style:{backgroundColor:a,color:f},"aria-label":"Open chat",children:p("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:p("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),y&&p("div",{className:"ariaflow-widget-window",style:{backgroundColor:i==="dark"&&l?l:void 0,borderRadius:ue[s]},children:[p("div",{className:"ariaflow-widget-header",style:{backgroundColor:c,borderRadius:s==="none"?"0":`${ue[s]} ${ue[s]} 0 0`},children:[p("div",{className:"ariaflow-widget-header-content",children:p("div",{className:"ariaflow-widget-title-group",children:[p("h3",{className:"ariaflow-widget-title",children:gt}),p("p",{className:"ariaflow-widget-subtitle",children:mt})]})}),p("button",{className:"ariaflow-widget-close",onClick:()=>k(!1),"aria-label":"Close chat",children:p("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[p("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),p("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),!C&&p("div",{className:"ariaflow-widget-status",children:[p("span",{className:"ariaflow-widget-status-dot"}),"Connecting..."]}),p("div",{className:"ariaflow-widget-messages",children:w.length===0?p("div",{className:"ariaflow-widget-empty",children:p("p",{children:C?vt:"Connecting to agent..."})}):p(D,{children:[w.map(x=>p("div",{className:`ariaflow-widget-message ariaflow-widget-message-${x.role}`,children:p("div",{className:"ariaflow-widget-message-bubble",children:x.content})},x.id)),p("div",{ref:$})]})}),p("div",{className:"ariaflow-widget-input",children:[p("textarea",{value:h,onInput:x=>N(x.target.value),onKeyDown:pt,placeholder:C?"Type your message...":"Connecting...",rows:1,disabled:!C}),p("button",{className:"ariaflow-widget-send",onClick:A,disabled:!h.trim()||!C,style:{backgroundColor:c},"aria-label":"Send message",children:p("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[p("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),p("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})]})}it(Je,"ariaflow-widget",["widget-id","api-url","mode","theme","position","size","radius","base-color","accent-color","button-base-color","button-accent-color","title","subtitle","empty-chat-message"],!1),typeof document<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ge):Ge());function Ge(){const t=document.querySelectorAll("ariaflow-widget");console.log(`[AriaFlow] Initializing ${t.length} widget(s)`)}W.Widget=Je,W.WidgetClient=Ke,Object.defineProperty(W,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ariaflowagents/widget",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Embeddable chat widget for AriaFlow Universal Inbox",
|
|
6
|
+
"main": "./dist/widget.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/widget.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "vite build",
|
|
20
|
+
"dev": "vite build --watch",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"typecheck": "tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"nanoid": "^5.0.9"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@preact/preset-vite": "^2.9.0",
|
|
29
|
+
"convex": "^1.31.7",
|
|
30
|
+
"preact": "^10.23.2",
|
|
31
|
+
"preact-custom-element": "^4.3.0",
|
|
32
|
+
"typescript": "^5.3.0",
|
|
33
|
+
"vite": "^5.4.11"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"preact": "^10.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|