@aiden-voice/widget 0.0.0 → 0.1.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 +296 -1
- package/dist/api/client.d.ts +14 -0
- package/dist/api/sse.d.ts +17 -0
- package/dist/components/App.d.ts +4 -0
- package/dist/components/Composer.d.ts +8 -0
- package/dist/components/ErrorBanner.d.ts +3 -0
- package/dist/components/Launcher.d.ts +7 -0
- package/dist/components/MessageFeedback.d.ts +10 -0
- package/dist/components/MessageList.d.ts +10 -0
- package/dist/components/Panel.d.ts +7 -0
- package/dist/config.d.ts +3 -0
- package/dist/controller.d.ts +45 -0
- package/dist/index.d.ts +3 -0
- package/dist/markdown/render.d.ts +2 -0
- package/dist/markdown/reveal.d.ts +6 -0
- package/dist/markdown/tokenizer.d.ts +23 -0
- package/dist/mount.d.ts +2 -0
- package/dist/storage.d.ts +3 -0
- package/dist/theme.d.ts +3 -0
- package/dist/types.d.ts +12 -0
- package/dist/version.d.ts +1 -0
- package/dist/widget.iife.js +6 -0
- package/dist/widget.js +1193 -0
- package/package.json +51 -4
package/dist/widget.js
ADDED
|
@@ -0,0 +1,1193 @@
|
|
|
1
|
+
function e(e) {
|
|
2
|
+
if ((typeof e.publishableKey == "string" && e.publishableKey.length > 0) == (typeof e.sessionToken == "string" && e.sessionToken.length > 0)) throw Error("whoo-aiden-widget: init() requires exactly one of `publishableKey` or `sessionToken`, not both or neither.");
|
|
3
|
+
}
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region node_modules/.pnpm/preact@10.29.8/node_modules/preact/dist/preact.module.js
|
|
6
|
+
var t, n, r, i, a, o, s, c, l, u, d, f, p, m, h = {}, g = [], _ = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, v = Array.isArray;
|
|
7
|
+
function y(e, t) {
|
|
8
|
+
for (var n in t) e[n] = t[n];
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function b(e) {
|
|
12
|
+
e && e.parentNode && e.parentNode.removeChild(e);
|
|
13
|
+
}
|
|
14
|
+
function x(e, n, r) {
|
|
15
|
+
var i, a, o, s = {};
|
|
16
|
+
for (o in n) o == "key" ? i = n[o] : o == "ref" ? a = n[o] : s[o] = n[o];
|
|
17
|
+
if (arguments.length > 2 && (s.children = arguments.length > 3 ? t.call(arguments, 2) : r), typeof e == "function" && e.defaultProps != null) for (o in e.defaultProps) s[o] === void 0 && (s[o] = e.defaultProps[o]);
|
|
18
|
+
return S(e, s, i, a, null);
|
|
19
|
+
}
|
|
20
|
+
function S(e, t, i, a, o) {
|
|
21
|
+
var s = {
|
|
22
|
+
type: e,
|
|
23
|
+
props: t,
|
|
24
|
+
key: i,
|
|
25
|
+
ref: a,
|
|
26
|
+
__k: null,
|
|
27
|
+
__: null,
|
|
28
|
+
__b: 0,
|
|
29
|
+
__e: null,
|
|
30
|
+
__c: null,
|
|
31
|
+
constructor: void 0,
|
|
32
|
+
__v: o ?? ++r,
|
|
33
|
+
__i: -1,
|
|
34
|
+
__u: 0
|
|
35
|
+
};
|
|
36
|
+
return o == null && n.vnode != null && n.vnode(s), s;
|
|
37
|
+
}
|
|
38
|
+
function C(e) {
|
|
39
|
+
return e.children;
|
|
40
|
+
}
|
|
41
|
+
function w(e, t) {
|
|
42
|
+
this.props = e, this.context = t;
|
|
43
|
+
}
|
|
44
|
+
function T(e, t) {
|
|
45
|
+
if (t == null) return e.__ ? T(e.__, e.__i + 1) : null;
|
|
46
|
+
for (var n; t < e.__k.length; t++) if ((n = e.__k[t]) != null && n.__e != null) return n.__e;
|
|
47
|
+
return typeof e.type == "function" ? T(e) : null;
|
|
48
|
+
}
|
|
49
|
+
function E(e) {
|
|
50
|
+
if (e.__P && e.__d) {
|
|
51
|
+
var t = e.__v, r = t.__e, i = [], a = [], o = y({}, t);
|
|
52
|
+
o.__v = t.__v + 1, n.vnode && n.vnode(o), F(e.__P, o, t, e.__n, e.__P.namespaceURI, 32 & t.__u ? [r] : null, i, r ?? T(t), !!(32 & t.__u), a), o.__v = t.__v, o.__.__k[o.__i] = o, re(i, o, a), t.__e = t.__ = null, o.__e != r && D(o);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function D(e) {
|
|
56
|
+
if ((e = e.__) != null && e.__c != null) return e.__e = e.__c.base = null, e.__k.some(function(t) {
|
|
57
|
+
if (t != null && t.__e != null) return e.__e = e.__c.base = t.__e;
|
|
58
|
+
}), D(e);
|
|
59
|
+
}
|
|
60
|
+
function O(e) {
|
|
61
|
+
(!e.__d && (e.__d = !0) && i.push(e) && !k.__r++ || a != n.debounceRendering) && ((a = n.debounceRendering) || o)(k);
|
|
62
|
+
}
|
|
63
|
+
function k() {
|
|
64
|
+
try {
|
|
65
|
+
for (var e, t = 1; i.length;) i.length > t && i.sort(s), e = i.shift(), t = i.length, E(e);
|
|
66
|
+
} finally {
|
|
67
|
+
i.length = k.__r = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function ee(e, t, n, r, i, a, o, s, c, l, u) {
|
|
71
|
+
var d, f, p, m, _, v, y = r && r.__k || g, b = t.length;
|
|
72
|
+
for (c = A(n, t, y, c, b), d = 0; d < b; d++) (p = n.__k[d]) != null && (f = p.__i != -1 && y[p.__i] || h, p.__i = d, v = F(e, p, f, i, a, o, s, c, l, u), m = p.__e, p.ref && f.ref != p.ref && (f.ref && I(f.ref, null, p), u.push(p.ref, p.__c || m, p)), _ == null && m != null && (_ = m), 4 & p.__u ? (c = j(p, c, e), f.__e && (f.__e = null)) : typeof p.type == "function" && v !== void 0 ? c = v : m && (c = m.nextSibling), p.__u &= -7);
|
|
73
|
+
return n.__e = _, c;
|
|
74
|
+
}
|
|
75
|
+
function A(e, t, n, r, i) {
|
|
76
|
+
var a, o, s, c, l, u = n.length, d = u, f = 0;
|
|
77
|
+
for (e.__k = Array(i), a = 0; a < i; a++) (o = t[a]) != null && typeof o != "boolean" && typeof o != "function" ? (typeof o == "string" || typeof o == "number" || typeof o == "bigint" || o.constructor == String ? o = e.__k[a] = S(null, o, null, null, null) : v(o) ? o = e.__k[a] = S(C, { children: o }, null, null, null) : o.constructor === void 0 && o.__b > 0 ? o = e.__k[a] = S(o.type, o.props, o.key, o.ref ? o.ref : null, o.__v) : e.__k[a] = o, c = a + f, o.__ = e, o.__b = e.__b + 1, s = null, (l = o.__i = M(o, n, c, d)) != -1 && (d--, (s = n[l]) && (s.__u |= 2)), s == null || s.__v == null ? (l == -1 && (i > u ? f-- : i < u && f++), typeof o.type != "function" && (o.__u |= 4)) : l != c && (l == c - 1 ? f-- : l == c + 1 ? f++ : (l > c ? f-- : f++, o.__u |= 4))) : e.__k[a] = null;
|
|
78
|
+
if (d) for (a = 0; a < u; a++) (s = n[a]) != null && !(2 & s.__u) && (s.__e == r && (r = T(s)), oe(s, s));
|
|
79
|
+
return r;
|
|
80
|
+
}
|
|
81
|
+
function j(e, t, n) {
|
|
82
|
+
var r, i;
|
|
83
|
+
if (typeof e.type == "function") {
|
|
84
|
+
for (r = e.__k, i = 0; r && i < r.length; i++) r[i] && (r[i].__ = e, t = j(r[i], t, n));
|
|
85
|
+
return t;
|
|
86
|
+
}
|
|
87
|
+
e.__e != t && (t && e.type && !t.parentNode && (t = T(e)), t = n.insertBefore(e.__e, t || null));
|
|
88
|
+
do
|
|
89
|
+
t &&= t.nextSibling;
|
|
90
|
+
while (t != null && t.nodeType == 8);
|
|
91
|
+
return t;
|
|
92
|
+
}
|
|
93
|
+
function M(e, t, n, r) {
|
|
94
|
+
var i, a, o, s = e.key, c = e.type, l = t[n], u = l != null && !(2 & l.__u);
|
|
95
|
+
if (l === null && s == null || u && s == l.key && c == l.type) return n;
|
|
96
|
+
if (r > +!!u) {
|
|
97
|
+
for (i = n - 1, a = n + 1; i >= 0 || a < t.length;) if ((l = t[o = i >= 0 ? i-- : a++]) != null && !(2 & l.__u) && s == l.key && c == l.type) return o;
|
|
98
|
+
}
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
function N(e, t, n) {
|
|
102
|
+
t[0] == "-" ? e.setProperty(t, n ?? "") : e[t] = n == null ? "" : typeof n != "number" || _.test(t) ? n : n + "px";
|
|
103
|
+
}
|
|
104
|
+
function P(e, t, n, r, i) {
|
|
105
|
+
var a, o;
|
|
106
|
+
n: if (t == "style") {
|
|
107
|
+
if (typeof n == "string") e.style.cssText = n;
|
|
108
|
+
else {
|
|
109
|
+
if (typeof r == "string" && (e.style.cssText = r = ""), r) for (t in r) n && t in n || N(e.style, t, "");
|
|
110
|
+
if (n) for (t in n) r && n[t] == r[t] || N(e.style, t, n[t]);
|
|
111
|
+
}
|
|
112
|
+
} else if (t[0] == "o" && t[1] == "n") a = t != (t = t.replace(d, "$1")), o = t.toLowerCase(), t = o in e || t == "onFocusOut" || t == "onFocusIn" ? o.slice(2) : t.slice(2), e.l ||= {}, e.l[t + a] = n, n ? r ? n[u] = r[u] : (n[u] = f, e.addEventListener(t, a ? m : p, a)) : e.removeEventListener(t, a ? m : p, a);
|
|
113
|
+
else {
|
|
114
|
+
if (i == "http://www.w3.org/2000/svg") t = t.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
|
|
115
|
+
else if (t != "width" && t != "height" && t != "href" && t != "list" && t != "form" && t != "tabIndex" && t != "download" && t != "rowSpan" && t != "colSpan" && t != "role" && t != "popover" && t in e) try {
|
|
116
|
+
e[t] = n ?? "";
|
|
117
|
+
break n;
|
|
118
|
+
} catch {}
|
|
119
|
+
typeof n == "function" || (n == null || !1 === n && t[4] != "-" ? e.removeAttribute(t) : e.setAttribute(t, t == "popover" && n == 1 ? "" : n));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function te(e) {
|
|
123
|
+
return function(t) {
|
|
124
|
+
if (this.l) {
|
|
125
|
+
var r = this.l[t.type + e];
|
|
126
|
+
if (t[l] == null) t[l] = f++;
|
|
127
|
+
else if (t[l] < r[u]) return;
|
|
128
|
+
return r(n.event ? n.event(t) : t);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function F(e, t, r, i, a, o, s, c, l, u) {
|
|
133
|
+
var d, f, p, m, h, _, x, S, E, D, O, k, A, j, M, N, P = t.type;
|
|
134
|
+
if (t.constructor !== void 0) return null;
|
|
135
|
+
128 & r.__u && (l = !!(32 & r.__u), o = [c = t.__e = r.__e]), (d = n.__b) && d(t);
|
|
136
|
+
n: if (typeof P == "function") {
|
|
137
|
+
f = s.length;
|
|
138
|
+
try {
|
|
139
|
+
if (E = t.props, D = P.prototype && P.prototype.render, O = (d = P.contextType) && i[d.__c], k = d ? O ? O.props.value : d.__ : i, r.__c ? S = (p = t.__c = r.__c).__ = p.__E : (D ? t.__c = p = new P(E, k) : (t.__c = p = new w(E, k), p.constructor = P, p.render = se), O && O.sub(p), p.state || (p.state = {}), p.__n = i, m = p.__d = !0, p.__h = [], p._sb = []), D && p.__s == null && (p.__s = p.state), D && P.getDerivedStateFromProps != null && (p.__s == p.state && (p.__s = y({}, p.__s)), y(p.__s, P.getDerivedStateFromProps(E, p.__s))), h = p.props, _ = p.state, p.__v = t, m) D && P.getDerivedStateFromProps == null && p.componentWillMount != null && p.componentWillMount(), D && p.componentDidMount != null && p.__h.push(p.componentDidMount);
|
|
140
|
+
else {
|
|
141
|
+
if (D && P.getDerivedStateFromProps == null && E !== h && p.componentWillReceiveProps != null && p.componentWillReceiveProps(E, k), t.__v == r.__v || !p.__e && p.shouldComponentUpdate != null && !1 === p.shouldComponentUpdate(E, p.__s, k)) {
|
|
142
|
+
t.__v != r.__v && (p.props = E, p.state = p.__s, p.__d = !1), t.__e = r.__e, t.__k = r.__k, t.__k.some(function(e) {
|
|
143
|
+
e && (e.__ = t);
|
|
144
|
+
}), g.push.apply(p.__h, p._sb), p._sb = [], p.__h.length && s.push(p), c = T(r);
|
|
145
|
+
break n;
|
|
146
|
+
}
|
|
147
|
+
p.componentWillUpdate != null && p.componentWillUpdate(E, p.__s, k), D && p.componentDidUpdate != null && p.__h.push(function() {
|
|
148
|
+
p.componentDidUpdate(h, _, x);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (p.context = k, p.props = E, p.__P = e, p.__e = !1, A = n.__r, j = 0, D) p.state = p.__s, p.__d = !1, A && A(t), d = p.render(p.props, p.state, p.context), g.push.apply(p.__h, p._sb), p._sb = [];
|
|
152
|
+
else do
|
|
153
|
+
p.__d = !1, A && A(t), d = p.render(p.props, p.state, p.context), p.state = p.__s;
|
|
154
|
+
while (p.__d && ++j < 25);
|
|
155
|
+
p.state = p.__s, p.getChildContext != null && (i = y(y({}, i), p.getChildContext())), D && !m && p.getSnapshotBeforeUpdate != null && (x = p.getSnapshotBeforeUpdate(h, _)), M = d != null && d.type === C && d.key == null ? ie(d.props.children) : d, c = ee(e, v(M) ? M : [M], t, r, i, a, o, s, c, l, u), p.base = t.__e, t.__u &= -161, p.__h.length && s.push(p), S && (p.__E = p.__ = null);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
if (s.length = f, t.__v = null, l || o != null) {
|
|
158
|
+
if (e.then) {
|
|
159
|
+
for (t.__u |= l ? 160 : 128; c && c.nodeType == 8 && c.nextSibling;) c = c.nextSibling;
|
|
160
|
+
o != null && (o[o.indexOf(c)] = null), t.__e = c;
|
|
161
|
+
} else if (o != null) for (N = o.length; N--;) b(o[N]);
|
|
162
|
+
} else t.__e = r.__e;
|
|
163
|
+
t.__k ??= r.__k || [], e.then || ne(t), n.__e(e, t, r);
|
|
164
|
+
}
|
|
165
|
+
} else o == null && t.__v == r.__v ? (t.__k = r.__k, t.__e = r.__e) : c = t.__e = ae(r.__e, t, r, i, a, o, s, l, u);
|
|
166
|
+
return (d = n.diffed) && d(t), 128 & t.__u ? void 0 : c;
|
|
167
|
+
}
|
|
168
|
+
function ne(e) {
|
|
169
|
+
e && (e.__c && (e.__c.__e = !0), e.__k && e.__k.some(ne));
|
|
170
|
+
}
|
|
171
|
+
function re(e, t, r) {
|
|
172
|
+
for (var i = 0; i < r.length; i++) I(r[i], r[++i], r[++i]);
|
|
173
|
+
n.__c && n.__c(t, e), e.some(function(t) {
|
|
174
|
+
try {
|
|
175
|
+
e = t.__h, t.__h = [], e.some(function(e) {
|
|
176
|
+
e.call(t);
|
|
177
|
+
});
|
|
178
|
+
} catch (e) {
|
|
179
|
+
n.__e(e, t.__v);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function ie(e) {
|
|
184
|
+
return typeof e != "object" || !e || e.__b > 0 ? e : v(e) ? e.map(ie) : e.constructor === void 0 ? y({}, e) : null;
|
|
185
|
+
}
|
|
186
|
+
function ae(e, r, i, a, o, s, c, l, u) {
|
|
187
|
+
var d, f, p, m, g, _, y, x = i.props || h, S = r.props, C = r.type;
|
|
188
|
+
if (C == "svg" ? o = "http://www.w3.org/2000/svg" : C == "math" ? o = "http://www.w3.org/1998/Math/MathML" : o ||= "http://www.w3.org/1999/xhtml", s != null) {
|
|
189
|
+
for (d = 0; d < s.length; d++) if ((g = s[d]) && "setAttribute" in g == !!C && (C ? g.localName == C : g.nodeType == 3)) {
|
|
190
|
+
e = g, s[d] = null;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (e == null) {
|
|
195
|
+
if (C == null) return document.createTextNode(S);
|
|
196
|
+
e = document.createElementNS(o, C, S.is && S), l &&= (n.__m && n.__m(r, s), !1), s = null;
|
|
197
|
+
}
|
|
198
|
+
if (C == null) x === S || l && e.data == S || (e.data = S);
|
|
199
|
+
else {
|
|
200
|
+
if (s = C == "textarea" && S.defaultValue != null ? null : s && t.call(e.childNodes), !l && s != null) for (x = {}, d = 0; d < e.attributes.length; d++) x[(g = e.attributes[d]).name] = g.value;
|
|
201
|
+
for (d in x) g = x[d], d == "dangerouslySetInnerHTML" ? p = g : d == "children" || d in S || d == "value" && "defaultValue" in S || d == "checked" && "defaultChecked" in S || P(e, d, null, g, o);
|
|
202
|
+
for (d in S) g = S[d], d == "children" ? m = g : d == "dangerouslySetInnerHTML" ? f = g : d == "value" ? _ = g : d == "checked" ? y = g : l && typeof g != "function" || x[d] === g || P(e, d, g, x[d], o);
|
|
203
|
+
if (f) l || p && (f.__html == p.__html || f.__html == e.innerHTML) || (e.innerHTML = f.__html), r.__k = [];
|
|
204
|
+
else if (p && (e.innerHTML = ""), ee(r.type == "template" ? e.content : e, v(m) ? m : [m], r, i, a, C == "foreignObject" ? "http://www.w3.org/1999/xhtml" : o, s, c, s ? s[0] : i.__k && T(i, 0), l, u), s != null) for (d = s.length; d--;) b(s[d]);
|
|
205
|
+
l && C != "textarea" || (d = "value", C == "progress" && _ == null ? e.removeAttribute("value") : _ != null && (_ !== e[d] || C == "progress" && !_ || C == "option" && _ != x[d]) && P(e, d, _, x[d], o), d = "checked", y != null && y != e[d] && P(e, d, y, x[d], o));
|
|
206
|
+
}
|
|
207
|
+
return e;
|
|
208
|
+
}
|
|
209
|
+
function I(e, t, r) {
|
|
210
|
+
try {
|
|
211
|
+
if (typeof e == "function") {
|
|
212
|
+
var i = typeof e.__u == "function";
|
|
213
|
+
i && e.__u(), i && t == null || (e.__u = e(t));
|
|
214
|
+
} else e.current = t;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
n.__e(e, r);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function oe(e, t, r) {
|
|
220
|
+
var i, a;
|
|
221
|
+
if (n.unmount && n.unmount(e), (i = e.ref) && (i.current && i.current != e.__e || I(i, null, t)), (i = e.__c) != null) {
|
|
222
|
+
if (i.componentWillUnmount) try {
|
|
223
|
+
i.componentWillUnmount();
|
|
224
|
+
} catch (e) {
|
|
225
|
+
n.__e(e, t);
|
|
226
|
+
}
|
|
227
|
+
i.base = i.__P = i.__n = null;
|
|
228
|
+
}
|
|
229
|
+
if (i = e.__k) for (a = 0; a < i.length; a++) i[a] && oe(i[a], t, r || typeof e.type != "function");
|
|
230
|
+
r || b(e.__e), e.__c = e.__ = e.__e = void 0;
|
|
231
|
+
}
|
|
232
|
+
function se(e, t, n) {
|
|
233
|
+
return this.constructor(e, n);
|
|
234
|
+
}
|
|
235
|
+
function ce(e, r, i) {
|
|
236
|
+
var a, o, s, c;
|
|
237
|
+
r == document && (r = document.documentElement), n.__ && n.__(e, r), o = (a = typeof i == "function") ? null : i && i.__k || r.__k, s = [], c = [], F(r, e = (!a && i || r).__k = x(C, null, [e]), o || h, h, r.namespaceURI, !a && i ? [i] : o ? null : r.firstChild ? t.call(r.childNodes) : null, s, !a && i ? i : o ? o.__e : r.firstChild, a, c), re(s, e, c), e.props.children = null;
|
|
238
|
+
}
|
|
239
|
+
t = g.slice, n = { __e: function(e, t, n, r) {
|
|
240
|
+
for (var i, a, o; t = t.__;) if ((i = t.__c) && !i.__) try {
|
|
241
|
+
if ((a = i.constructor) && a.getDerivedStateFromError != null && (i.setState(a.getDerivedStateFromError(e)), o = i.__d), i.componentDidCatch != null && (i.componentDidCatch(e, r || {}), o = i.__d), o) return i.__E = i;
|
|
242
|
+
} catch (t) {
|
|
243
|
+
e = t;
|
|
244
|
+
}
|
|
245
|
+
throw e;
|
|
246
|
+
} }, r = 0, w.prototype.setState = function(e, t) {
|
|
247
|
+
var n = this.__s != null && this.__s != this.state ? this.__s : this.__s = y({}, this.state);
|
|
248
|
+
typeof e == "function" && (e = e(y({}, n), this.props)), e && y(n, e), e != null && this.__v && (t && this._sb.push(t), O(this));
|
|
249
|
+
}, w.prototype.forceUpdate = function(e) {
|
|
250
|
+
this.__v && (this.__e = !0, e && this.__h.push(e), O(this));
|
|
251
|
+
}, w.prototype.render = C, i = [], o = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, s = function(e, t) {
|
|
252
|
+
return e.__v.__b - t.__v.__b;
|
|
253
|
+
}, k.__r = 0, c = Math.random().toString(8), l = "__d" + c, u = "__a" + c, d = /(PointerCapture)$|Capture$/i, f = 0, p = te(!1), m = te(!0);
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region node_modules/.pnpm/preact@10.29.8/node_modules/preact/hooks/dist/hooks.module.js
|
|
256
|
+
var L, R, le, ue, z = 0, de = [], B = n, fe = B.__b, pe = B.__r, me = B.diffed, he = B.__c, ge = B.unmount, _e = B.__;
|
|
257
|
+
function V(e, t) {
|
|
258
|
+
B.__h && B.__h(R, e, z || t), z = 0;
|
|
259
|
+
var n = R.__H || (R.__H = {
|
|
260
|
+
__: [],
|
|
261
|
+
__h: []
|
|
262
|
+
});
|
|
263
|
+
return e >= n.__.length && n.__.push({}), n.__[e];
|
|
264
|
+
}
|
|
265
|
+
function H(e) {
|
|
266
|
+
return z = 1, ve(we, e);
|
|
267
|
+
}
|
|
268
|
+
function ve(e, t, n) {
|
|
269
|
+
var r = V(L++, 2);
|
|
270
|
+
if (r.t = e, !r.__c && (r.__ = [n ? n(t) : we(void 0, t), function(e) {
|
|
271
|
+
var t = r.__N ? r.__N[0] : r.__[0], n = r.t(t, e);
|
|
272
|
+
t !== n && (r.__N = [n, r.__[1]], r.__c.setState({}));
|
|
273
|
+
}], r.__c = R, !R.__f)) {
|
|
274
|
+
var i = function(e, t, n) {
|
|
275
|
+
if (!r.__c.__H) return !0;
|
|
276
|
+
var i = !1, o = r.__c.props !== e;
|
|
277
|
+
if (r.__c.__H.__.some(function(e) {
|
|
278
|
+
if (e.__N) {
|
|
279
|
+
i = !0;
|
|
280
|
+
var t = e.__[0];
|
|
281
|
+
e.__ = e.__N, e.__N = void 0, t !== e.__[0] && (o = !0);
|
|
282
|
+
}
|
|
283
|
+
}), a) {
|
|
284
|
+
var s = a.call(this, e, t, n);
|
|
285
|
+
return i ? s || o : s;
|
|
286
|
+
}
|
|
287
|
+
return !i || o;
|
|
288
|
+
};
|
|
289
|
+
R.__f = !0;
|
|
290
|
+
var a = R.shouldComponentUpdate, o = R.componentWillUpdate;
|
|
291
|
+
R.componentWillUpdate = function(e, t, n) {
|
|
292
|
+
if (this.__e) {
|
|
293
|
+
var r = a;
|
|
294
|
+
a = void 0, i(e, t, n), a = r;
|
|
295
|
+
}
|
|
296
|
+
o && o.call(this, e, t, n);
|
|
297
|
+
}, R.shouldComponentUpdate = i;
|
|
298
|
+
}
|
|
299
|
+
return r.__N || r.__;
|
|
300
|
+
}
|
|
301
|
+
function U(e, t) {
|
|
302
|
+
var n = V(L++, 3);
|
|
303
|
+
!B.__s && Ce(n.__H, t) && (n.__ = e, n.u = t, R.__H.__h.push(n));
|
|
304
|
+
}
|
|
305
|
+
function W(e) {
|
|
306
|
+
return z = 5, ye(function() {
|
|
307
|
+
return { current: e };
|
|
308
|
+
}, []);
|
|
309
|
+
}
|
|
310
|
+
function ye(e, t) {
|
|
311
|
+
var n = V(L++, 7);
|
|
312
|
+
return Ce(n.__H, t) && (n.__ = e(), n.__H = t, n.__h = e), n.__;
|
|
313
|
+
}
|
|
314
|
+
function be() {
|
|
315
|
+
for (var e; e = de.shift();) {
|
|
316
|
+
var t = e.__H;
|
|
317
|
+
if (e.__P && t) try {
|
|
318
|
+
t.__h.some(G), t.__h.some(K), t.__h = [];
|
|
319
|
+
} catch (n) {
|
|
320
|
+
t.__h = [], B.__e(n, e.__v);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
B.__b = function(e) {
|
|
325
|
+
R = null, fe && fe(e);
|
|
326
|
+
}, B.__ = function(e, t) {
|
|
327
|
+
e && t.__k && t.__k.__m && (e.__m = t.__k.__m), _e && _e(e, t);
|
|
328
|
+
}, B.__r = function(e) {
|
|
329
|
+
pe && pe(e), L = 0;
|
|
330
|
+
var t = (R = e.__c).__H;
|
|
331
|
+
t && (le === R ? (t.__h = [], R.__h = [], t.__.some(function(e) {
|
|
332
|
+
e.__N && (e.__ = e.__N), e.u = e.__N = void 0;
|
|
333
|
+
})) : (t.__h.some(G), t.__h.some(K), t.__h = [], L = 0)), le = R;
|
|
334
|
+
}, B.diffed = function(e) {
|
|
335
|
+
me && me(e);
|
|
336
|
+
var t = e.__c;
|
|
337
|
+
t && t.__H && (t.__H.__h.length && (de.push(t) !== 1 && ue === B.requestAnimationFrame || ((ue = B.requestAnimationFrame) || Se)(be)), t.__H.__.some(function(e) {
|
|
338
|
+
e.u &&= (e.__H = e.u, void 0);
|
|
339
|
+
})), le = R = null;
|
|
340
|
+
}, B.__c = function(e, t) {
|
|
341
|
+
t.some(function(e) {
|
|
342
|
+
try {
|
|
343
|
+
e.__h.some(G), e.__h = e.__h.filter(function(e) {
|
|
344
|
+
return !e.__ || K(e);
|
|
345
|
+
});
|
|
346
|
+
} catch (n) {
|
|
347
|
+
t.some(function(e) {
|
|
348
|
+
e.__h &&= [];
|
|
349
|
+
}), t = [], B.__e(n, e.__v);
|
|
350
|
+
}
|
|
351
|
+
}), he && he(e, t);
|
|
352
|
+
}, B.unmount = function(e) {
|
|
353
|
+
ge && ge(e);
|
|
354
|
+
var t, n = e.__c;
|
|
355
|
+
n && n.__H && (n.__H.__.some(function(e) {
|
|
356
|
+
try {
|
|
357
|
+
G(e);
|
|
358
|
+
} catch (e) {
|
|
359
|
+
t = e;
|
|
360
|
+
}
|
|
361
|
+
}), n.__H = void 0, t && B.__e(t, n.__v));
|
|
362
|
+
};
|
|
363
|
+
var xe = typeof requestAnimationFrame == "function";
|
|
364
|
+
function Se(e) {
|
|
365
|
+
var t, n = function() {
|
|
366
|
+
clearTimeout(r), xe && cancelAnimationFrame(t), setTimeout(e);
|
|
367
|
+
}, r = setTimeout(n, 35);
|
|
368
|
+
xe && (t = requestAnimationFrame(n));
|
|
369
|
+
}
|
|
370
|
+
function G(e) {
|
|
371
|
+
var t = R, n = e.__c;
|
|
372
|
+
typeof n == "function" && (e.__c = void 0, n()), R = t;
|
|
373
|
+
}
|
|
374
|
+
function K(e) {
|
|
375
|
+
var t = R;
|
|
376
|
+
e.__c = e.__(), R = t;
|
|
377
|
+
}
|
|
378
|
+
function Ce(e, t) {
|
|
379
|
+
return !e || e.length !== t.length || t.some(function(t, n) {
|
|
380
|
+
return t !== e[n];
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function we(e, t) {
|
|
384
|
+
return typeof t == "function" ? t(e) : t;
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region node_modules/.pnpm/preact@10.29.8/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js
|
|
388
|
+
var Te = 0;
|
|
389
|
+
Array.isArray;
|
|
390
|
+
function q(e, t, r, i, a, o) {
|
|
391
|
+
t ||= {};
|
|
392
|
+
var s, c, l = t;
|
|
393
|
+
if ("ref" in l) for (c in l = {}, t) c == "ref" ? s = t[c] : l[c] = t[c];
|
|
394
|
+
var u = {
|
|
395
|
+
type: e,
|
|
396
|
+
props: l,
|
|
397
|
+
key: r,
|
|
398
|
+
ref: s,
|
|
399
|
+
__k: null,
|
|
400
|
+
__: null,
|
|
401
|
+
__b: 0,
|
|
402
|
+
__e: null,
|
|
403
|
+
__c: null,
|
|
404
|
+
constructor: void 0,
|
|
405
|
+
__v: --Te,
|
|
406
|
+
__i: -1,
|
|
407
|
+
__u: 0,
|
|
408
|
+
__source: a,
|
|
409
|
+
__self: o
|
|
410
|
+
};
|
|
411
|
+
if (typeof e == "function" && (s = e.defaultProps)) for (c in s) l[c] === void 0 && (l[c] = s[c]);
|
|
412
|
+
return n.vnode && n.vnode(u), u;
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/components/Launcher.tsx
|
|
416
|
+
function Ee({ isOpen: e, onClick: t, logoUrl: n, buttonRef: r }) {
|
|
417
|
+
return /* @__PURE__ */ q("button", {
|
|
418
|
+
type: "button",
|
|
419
|
+
class: "whoo-widget-launcher",
|
|
420
|
+
onClick: t,
|
|
421
|
+
"aria-label": e ? "Close chat" : "Open chat",
|
|
422
|
+
ref: r,
|
|
423
|
+
children: e ? /* @__PURE__ */ q("span", {
|
|
424
|
+
"aria-hidden": "true",
|
|
425
|
+
children: "✕"
|
|
426
|
+
}) : n ? /* @__PURE__ */ q("img", {
|
|
427
|
+
class: "whoo-widget-launcher-logo",
|
|
428
|
+
src: n,
|
|
429
|
+
alt: ""
|
|
430
|
+
}) : /* @__PURE__ */ q("span", {
|
|
431
|
+
"aria-hidden": "true",
|
|
432
|
+
children: "💬"
|
|
433
|
+
})
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/components/Composer.tsx
|
|
438
|
+
function De({ value: e, onChange: t, onSend: n, disabled: r, inputRef: i }) {
|
|
439
|
+
return /* @__PURE__ */ q("div", {
|
|
440
|
+
class: "whoo-widget-composer",
|
|
441
|
+
children: [
|
|
442
|
+
/* @__PURE__ */ q("label", {
|
|
443
|
+
class: "whoo-widget-sr-only",
|
|
444
|
+
for: "whoo-widget-composer-input",
|
|
445
|
+
children: "Message"
|
|
446
|
+
}),
|
|
447
|
+
/* @__PURE__ */ q("input", {
|
|
448
|
+
id: "whoo-widget-composer-input",
|
|
449
|
+
class: "whoo-widget-composer-input",
|
|
450
|
+
value: e,
|
|
451
|
+
readOnly: r,
|
|
452
|
+
"aria-disabled": r,
|
|
453
|
+
ref: i,
|
|
454
|
+
onInput: (e) => t(e.target.value),
|
|
455
|
+
onKeyDown: (e) => {
|
|
456
|
+
e.key === "Enter" && n();
|
|
457
|
+
}
|
|
458
|
+
}),
|
|
459
|
+
/* @__PURE__ */ q("button", {
|
|
460
|
+
type: "button",
|
|
461
|
+
class: "whoo-widget-composer-send",
|
|
462
|
+
onClick: n,
|
|
463
|
+
disabled: r,
|
|
464
|
+
children: "Send"
|
|
465
|
+
})
|
|
466
|
+
]
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/components/ErrorBanner.tsx
|
|
471
|
+
function Oe({ message: e }) {
|
|
472
|
+
return /* @__PURE__ */ q("div", {
|
|
473
|
+
class: "whoo-widget-error-banner",
|
|
474
|
+
role: "alert",
|
|
475
|
+
children: e
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region src/markdown/tokenizer.ts
|
|
480
|
+
var J = /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/y, Y = /\*\*([^*]+)\*\*/y, X = /(?<![A-Za-z0-9_])_([^_\s](?:[^_]*[^_\s])?)_(?![A-Za-z0-9_])/y, Z = /\*([^*]+)\*/y, ke = /https?:\/\/\S+/y, Ae = /[.,;:!?)\]}>]+$/;
|
|
481
|
+
function Q(e) {
|
|
482
|
+
let t = [], n = 0, r = 0, i = (n) => {
|
|
483
|
+
n > r && t.push({
|
|
484
|
+
type: "text",
|
|
485
|
+
value: e.slice(r, n),
|
|
486
|
+
start: r,
|
|
487
|
+
end: n
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
for (; n < e.length;) {
|
|
491
|
+
if (e[n] === "!" && n + 1 < e.length && e[n + 1] === "[") {
|
|
492
|
+
let t = /!\[([^\]]*)\]\(([^)]*)\)/y;
|
|
493
|
+
t.lastIndex = n;
|
|
494
|
+
let r = t.exec(e);
|
|
495
|
+
if (r) {
|
|
496
|
+
n += r[0].length;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (e[n - 1] !== "!") {
|
|
501
|
+
J.lastIndex = n;
|
|
502
|
+
let a = J.exec(e);
|
|
503
|
+
if (a) {
|
|
504
|
+
i(n), t.push({
|
|
505
|
+
type: "link",
|
|
506
|
+
text: a[1],
|
|
507
|
+
url: a[2],
|
|
508
|
+
start: n,
|
|
509
|
+
end: J.lastIndex
|
|
510
|
+
}), n = J.lastIndex, r = n;
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
Y.lastIndex = n;
|
|
515
|
+
let a = Y.exec(e);
|
|
516
|
+
if (a) {
|
|
517
|
+
i(n), t.push({
|
|
518
|
+
type: "bold",
|
|
519
|
+
value: a[1],
|
|
520
|
+
start: n,
|
|
521
|
+
end: Y.lastIndex
|
|
522
|
+
}), n = Y.lastIndex, r = n;
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
X.lastIndex = n;
|
|
526
|
+
let o = X.exec(e);
|
|
527
|
+
if (o) {
|
|
528
|
+
i(n), t.push({
|
|
529
|
+
type: "italic",
|
|
530
|
+
value: o[1],
|
|
531
|
+
start: n,
|
|
532
|
+
end: X.lastIndex
|
|
533
|
+
}), n = X.lastIndex, r = n;
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
Z.lastIndex = n;
|
|
537
|
+
let s = Z.exec(e);
|
|
538
|
+
if (s) {
|
|
539
|
+
i(n), t.push({
|
|
540
|
+
type: "italic",
|
|
541
|
+
value: s[1],
|
|
542
|
+
start: n,
|
|
543
|
+
end: Z.lastIndex
|
|
544
|
+
}), n = Z.lastIndex, r = n;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
ke.lastIndex = n;
|
|
548
|
+
let c = ke.exec(e);
|
|
549
|
+
if (c) {
|
|
550
|
+
let e = c[0].match(Ae), a = e ? c[0].slice(0, c[0].length - e[0].length) : c[0];
|
|
551
|
+
if (a.length > 0) {
|
|
552
|
+
i(n), t.push({
|
|
553
|
+
type: "link",
|
|
554
|
+
text: a,
|
|
555
|
+
url: a,
|
|
556
|
+
start: n,
|
|
557
|
+
end: n + a.length
|
|
558
|
+
}), n += a.length, r = n;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
n += 1;
|
|
563
|
+
}
|
|
564
|
+
return i(e.length), t;
|
|
565
|
+
}
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/markdown/render.tsx
|
|
568
|
+
function je(e) {
|
|
569
|
+
return Q(e).map((e, t) => {
|
|
570
|
+
switch (e.type) {
|
|
571
|
+
case "bold": return /* @__PURE__ */ q("strong", { children: e.value }, t);
|
|
572
|
+
case "italic": return /* @__PURE__ */ q("em", { children: e.value }, t);
|
|
573
|
+
case "link": return /* @__PURE__ */ q("a", {
|
|
574
|
+
href: e.url,
|
|
575
|
+
target: "_blank",
|
|
576
|
+
rel: "noopener noreferrer",
|
|
577
|
+
children: [e.text, /* @__PURE__ */ q("span", {
|
|
578
|
+
class: "whoo-widget-sr-only",
|
|
579
|
+
children: " (opens in new tab)"
|
|
580
|
+
})]
|
|
581
|
+
}, t);
|
|
582
|
+
default: return e.value;
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region src/components/MessageFeedback.tsx
|
|
588
|
+
var Me = [
|
|
589
|
+
{
|
|
590
|
+
value: "",
|
|
591
|
+
label: "Select a reason (optional)"
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
value: "factual",
|
|
595
|
+
label: "Factual error"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
value: "incomplete",
|
|
599
|
+
label: "Incomplete"
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
value: "tone",
|
|
603
|
+
label: "Off tone"
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
value: "other",
|
|
607
|
+
label: "Other"
|
|
608
|
+
}
|
|
609
|
+
];
|
|
610
|
+
function Ne({ state: e, containerRef: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancel: a }) {
|
|
611
|
+
let [o, s] = H(""), [c, l] = H(""), u = W(e.status);
|
|
612
|
+
if (U(() => {
|
|
613
|
+
let n = u.current;
|
|
614
|
+
if (u.current = e.status, n === e.status) return;
|
|
615
|
+
let r = t?.current;
|
|
616
|
+
if (!r) return;
|
|
617
|
+
let i = r.getRootNode();
|
|
618
|
+
r.contains(i.activeElement) || r.focus();
|
|
619
|
+
}, [e.status, t]), e.status === "submitted") return /* @__PURE__ */ q("div", {
|
|
620
|
+
class: "whoo-widget-feedback-submitted",
|
|
621
|
+
role: "status",
|
|
622
|
+
children: "Thanks for the feedback"
|
|
623
|
+
});
|
|
624
|
+
if (e.status === "expanded") return /* @__PURE__ */ q("div", {
|
|
625
|
+
class: "whoo-widget-feedback-form",
|
|
626
|
+
children: [
|
|
627
|
+
/* @__PURE__ */ q("label", { children: [/* @__PURE__ */ q("span", {
|
|
628
|
+
class: "whoo-widget-sr-only",
|
|
629
|
+
children: "Additional feedback"
|
|
630
|
+
}), /* @__PURE__ */ q("textarea", {
|
|
631
|
+
class: "whoo-widget-feedback-textarea",
|
|
632
|
+
value: o,
|
|
633
|
+
onInput: (e) => s(e.target.value),
|
|
634
|
+
placeholder: "What was wrong? (optional)"
|
|
635
|
+
})] }),
|
|
636
|
+
/* @__PURE__ */ q("select", {
|
|
637
|
+
class: "whoo-widget-feedback-select",
|
|
638
|
+
"aria-label": "Feedback category",
|
|
639
|
+
value: c,
|
|
640
|
+
onChange: (e) => l(e.target.value),
|
|
641
|
+
children: Me.map((e) => /* @__PURE__ */ q("option", {
|
|
642
|
+
value: e.value,
|
|
643
|
+
children: e.label
|
|
644
|
+
}, e.value))
|
|
645
|
+
}),
|
|
646
|
+
/* @__PURE__ */ q("div", {
|
|
647
|
+
class: "whoo-widget-feedback-form-buttons",
|
|
648
|
+
children: [/* @__PURE__ */ q("button", {
|
|
649
|
+
type: "button",
|
|
650
|
+
class: "whoo-widget-feedback-submit",
|
|
651
|
+
onClick: () => i(o, c),
|
|
652
|
+
children: "Submit"
|
|
653
|
+
}), /* @__PURE__ */ q("button", {
|
|
654
|
+
type: "button",
|
|
655
|
+
class: "whoo-widget-feedback-cancel",
|
|
656
|
+
onClick: a,
|
|
657
|
+
children: "Cancel"
|
|
658
|
+
})]
|
|
659
|
+
})
|
|
660
|
+
]
|
|
661
|
+
});
|
|
662
|
+
let d = e.status === "submitting";
|
|
663
|
+
return /* @__PURE__ */ q("div", {
|
|
664
|
+
class: "whoo-widget-feedback",
|
|
665
|
+
children: [/* @__PURE__ */ q("div", {
|
|
666
|
+
class: "whoo-widget-feedback-buttons",
|
|
667
|
+
children: [/* @__PURE__ */ q("button", {
|
|
668
|
+
type: "button",
|
|
669
|
+
"aria-label": "Good response",
|
|
670
|
+
disabled: d,
|
|
671
|
+
onClick: n,
|
|
672
|
+
children: "👍"
|
|
673
|
+
}), /* @__PURE__ */ q("button", {
|
|
674
|
+
type: "button",
|
|
675
|
+
"aria-label": "Bad response",
|
|
676
|
+
disabled: d,
|
|
677
|
+
onClick: r,
|
|
678
|
+
children: "👎"
|
|
679
|
+
})]
|
|
680
|
+
}), e.status === "error" ? /* @__PURE__ */ q("div", {
|
|
681
|
+
class: "whoo-widget-feedback-error",
|
|
682
|
+
role: "status",
|
|
683
|
+
children: "Couldn't send feedback"
|
|
684
|
+
}) : null]
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region src/components/MessageList.tsx
|
|
689
|
+
function Pe({ message: e, feedbackState: t, onThumbsUp: n, onThumbsDown: r, onSubmitDetailed: i, onCancelFeedback: a }) {
|
|
690
|
+
let o = W(null), s = e.id;
|
|
691
|
+
return /* @__PURE__ */ q("div", {
|
|
692
|
+
ref: o,
|
|
693
|
+
tabIndex: -1,
|
|
694
|
+
class: `whoo-widget-message whoo-widget-message--${e.role}`,
|
|
695
|
+
children: [je(e.content), e.role === "assistant" && s ? /* @__PURE__ */ q(Ne, {
|
|
696
|
+
state: t,
|
|
697
|
+
containerRef: o,
|
|
698
|
+
onThumbsUp: () => n(s),
|
|
699
|
+
onThumbsDown: () => r(s),
|
|
700
|
+
onSubmitDetailed: (e, t) => i(s, e, t),
|
|
701
|
+
onCancel: () => a(s)
|
|
702
|
+
}) : null]
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
function Fe({ messages: e, messageFeedback: t, lastCompletedMessageText: n, onThumbsUp: r, onThumbsDown: i, onSubmitDetailed: a, onCancelFeedback: o }) {
|
|
706
|
+
let s = W(null);
|
|
707
|
+
return U(() => {
|
|
708
|
+
let e = s.current;
|
|
709
|
+
e && (e.scrollTop = e.scrollHeight);
|
|
710
|
+
}, [e]), /* @__PURE__ */ q(C, { children: [/* @__PURE__ */ q("div", {
|
|
711
|
+
class: "whoo-widget-message-list",
|
|
712
|
+
ref: s,
|
|
713
|
+
children: e.map((e, n) => /* @__PURE__ */ q(Pe, {
|
|
714
|
+
message: e,
|
|
715
|
+
feedbackState: e.id ? t[e.id] ?? { status: "idle" } : { status: "idle" },
|
|
716
|
+
onThumbsUp: r,
|
|
717
|
+
onThumbsDown: i,
|
|
718
|
+
onSubmitDetailed: a,
|
|
719
|
+
onCancelFeedback: o
|
|
720
|
+
}, e.id ?? n))
|
|
721
|
+
}), /* @__PURE__ */ q("div", {
|
|
722
|
+
class: "whoo-widget-sr-only",
|
|
723
|
+
"aria-live": "polite",
|
|
724
|
+
"aria-atomic": "true",
|
|
725
|
+
children: n ?? ""
|
|
726
|
+
})] });
|
|
727
|
+
}
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/components/Panel.tsx
|
|
730
|
+
var Ie = "button:not(:disabled), [href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex=\"-1\"])";
|
|
731
|
+
function Le(e) {
|
|
732
|
+
return Array.from(e.querySelectorAll(Ie)).filter((e) => {
|
|
733
|
+
let t = getComputedStyle(e);
|
|
734
|
+
return t.display !== "none" && t.visibility !== "hidden";
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function Re({ state: e, controller: t, greeting: n }) {
|
|
738
|
+
let [r, i] = H(""), a = W(null), o = W(null);
|
|
739
|
+
U(() => {
|
|
740
|
+
o.current?.focus();
|
|
741
|
+
}, []);
|
|
742
|
+
let s = (e) => {
|
|
743
|
+
if (e.key === "Escape") {
|
|
744
|
+
t.close();
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (e.key !== "Tab") return;
|
|
748
|
+
let n = a.current;
|
|
749
|
+
if (!n) return;
|
|
750
|
+
let r = Le(n);
|
|
751
|
+
if (r.length === 0) return;
|
|
752
|
+
let i = r[0], o = r[r.length - 1], s = n.getRootNode().activeElement;
|
|
753
|
+
if (!n.contains(s)) {
|
|
754
|
+
e.preventDefault(), i.focus();
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
e.shiftKey && s === i ? (e.preventDefault(), o.focus()) : !e.shiftKey && s === o && (e.preventDefault(), i.focus());
|
|
758
|
+
}, c = () => {
|
|
759
|
+
let n = r.trim();
|
|
760
|
+
!n || e.isStreaming || (i(""), t.sendMessage(n));
|
|
761
|
+
}, l = e.messages.length === 0 && n ? [{
|
|
762
|
+
role: "assistant",
|
|
763
|
+
content: n,
|
|
764
|
+
id: null
|
|
765
|
+
}] : e.messages;
|
|
766
|
+
return /* @__PURE__ */ q("div", {
|
|
767
|
+
class: "whoo-widget-panel",
|
|
768
|
+
role: "dialog",
|
|
769
|
+
"aria-modal": "true",
|
|
770
|
+
"aria-label": "Chat with Aiden",
|
|
771
|
+
ref: a,
|
|
772
|
+
onKeyDown: s,
|
|
773
|
+
children: [
|
|
774
|
+
/* @__PURE__ */ q("div", {
|
|
775
|
+
class: "whoo-widget-header",
|
|
776
|
+
children: [/* @__PURE__ */ q("button", {
|
|
777
|
+
type: "button",
|
|
778
|
+
class: "whoo-widget-header-close",
|
|
779
|
+
onClick: () => t.close(),
|
|
780
|
+
children: "Close chat"
|
|
781
|
+
}), e.messages.length > 0 && /* @__PURE__ */ q("button", {
|
|
782
|
+
type: "button",
|
|
783
|
+
class: "whoo-widget-header-reset",
|
|
784
|
+
onClick: () => t.resetConversation(),
|
|
785
|
+
children: "New conversation"
|
|
786
|
+
})]
|
|
787
|
+
}),
|
|
788
|
+
/* @__PURE__ */ q(Fe, {
|
|
789
|
+
messages: l,
|
|
790
|
+
messageFeedback: e.messageFeedback,
|
|
791
|
+
lastCompletedMessageText: e.lastCompletedMessageText,
|
|
792
|
+
onThumbsUp: (e) => t.submitFeedback(e, "up"),
|
|
793
|
+
onThumbsDown: (e) => t.expandFeedback(e),
|
|
794
|
+
onSubmitDetailed: (e, n, r) => t.submitFeedback(e, "down", n || void 0, r || void 0),
|
|
795
|
+
onCancelFeedback: (e) => t.cancelFeedback(e)
|
|
796
|
+
}),
|
|
797
|
+
e.runtimeError && /* @__PURE__ */ q(Oe, { message: e.runtimeError }),
|
|
798
|
+
/* @__PURE__ */ q(De, {
|
|
799
|
+
value: r,
|
|
800
|
+
onChange: i,
|
|
801
|
+
onSend: c,
|
|
802
|
+
disabled: e.isStreaming,
|
|
803
|
+
inputRef: o
|
|
804
|
+
})
|
|
805
|
+
]
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
//#endregion
|
|
809
|
+
//#region src/components/App.tsx
|
|
810
|
+
function ze({ controller: e }) {
|
|
811
|
+
let [t, n] = H(e.getState()), r = W(null), i = W(t.isOpen);
|
|
812
|
+
return U(() => (n(e.getState()), e.subscribe(n)), [e]), U(() => {
|
|
813
|
+
i.current && !t.isOpen && r.current?.focus(), i.current = t.isOpen;
|
|
814
|
+
}, [t.isOpen]), t.initError ? null : /* @__PURE__ */ q(C, { children: [/* @__PURE__ */ q(Ee, {
|
|
815
|
+
isOpen: t.isOpen,
|
|
816
|
+
onClick: () => t.isOpen ? e.close() : e.open(),
|
|
817
|
+
logoUrl: e.config.logoUrl,
|
|
818
|
+
buttonRef: r
|
|
819
|
+
}), t.isOpen && /* @__PURE__ */ q(Re, {
|
|
820
|
+
state: t,
|
|
821
|
+
controller: e,
|
|
822
|
+
greeting: e.config.greeting
|
|
823
|
+
})] });
|
|
824
|
+
}
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/api/client.ts
|
|
827
|
+
var Be = class extends Error {
|
|
828
|
+
status;
|
|
829
|
+
constructor(e, t) {
|
|
830
|
+
super(e), this.name = "WidgetApiError", this.status = t;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
async function Ve(e, t) {
|
|
834
|
+
let n = await fetch(`${e}/api/v1/widget/session`, {
|
|
835
|
+
method: "POST",
|
|
836
|
+
headers: { "Content-Type": "application/json" },
|
|
837
|
+
body: JSON.stringify({ publishable_key: t })
|
|
838
|
+
});
|
|
839
|
+
if (!n.ok) throw new Be(`Failed to create widget session (${n.status})`, n.status);
|
|
840
|
+
let r = await n.json();
|
|
841
|
+
return {
|
|
842
|
+
token: r.token,
|
|
843
|
+
primaryColor: r.primary_color ?? null
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
async function He(e, t, n) {
|
|
847
|
+
let r = await fetch(`${e}/api/v1/widget/feedback`, {
|
|
848
|
+
method: "POST",
|
|
849
|
+
headers: {
|
|
850
|
+
"Content-Type": "application/json",
|
|
851
|
+
Authorization: `Bearer ${t}`
|
|
852
|
+
},
|
|
853
|
+
body: JSON.stringify({
|
|
854
|
+
message_id: n.messageId,
|
|
855
|
+
rating: n.rating,
|
|
856
|
+
correction: n.correction ?? null,
|
|
857
|
+
category: n.category ?? null
|
|
858
|
+
})
|
|
859
|
+
});
|
|
860
|
+
if (!r.ok) throw new Be(`Feedback submission failed (${r.status})`, r.status);
|
|
861
|
+
}
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region src/api/sse.ts
|
|
864
|
+
async function* Ue(e, t, n, r, i) {
|
|
865
|
+
let a = await fetch(`${e}/api/v1/widget/chat`, {
|
|
866
|
+
method: "POST",
|
|
867
|
+
headers: {
|
|
868
|
+
"Content-Type": "application/json",
|
|
869
|
+
Authorization: `Bearer ${t}`
|
|
870
|
+
},
|
|
871
|
+
body: JSON.stringify({
|
|
872
|
+
conversation_id: n,
|
|
873
|
+
message: r
|
|
874
|
+
}),
|
|
875
|
+
signal: i
|
|
876
|
+
});
|
|
877
|
+
if (!a.ok || !a.body) throw new Be(`Chat request failed (${a.status})`, a.status);
|
|
878
|
+
let o = a.body.getReader(), s = new TextDecoder(), c = "";
|
|
879
|
+
for (;;) {
|
|
880
|
+
let { done: e, value: t } = await o.read();
|
|
881
|
+
if (e) break;
|
|
882
|
+
c += s.decode(t, { stream: !0 });
|
|
883
|
+
let n = c.indexOf("\n\n");
|
|
884
|
+
for (; n !== -1;) {
|
|
885
|
+
let e = c.slice(0, n);
|
|
886
|
+
c = c.slice(n + 2);
|
|
887
|
+
let t = e.split("\n").find((e) => e.startsWith("data: "));
|
|
888
|
+
t && (yield We(JSON.parse(t.slice(6)))), n = c.indexOf("\n\n");
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function We(e) {
|
|
893
|
+
return typeof e.error == "string" ? {
|
|
894
|
+
type: "error",
|
|
895
|
+
error: e.error,
|
|
896
|
+
conversationId: e.conversation_id
|
|
897
|
+
} : e.done === !0 ? {
|
|
898
|
+
type: "done",
|
|
899
|
+
conversationId: e.conversation_id,
|
|
900
|
+
messageId: e.message_id ?? null
|
|
901
|
+
} : typeof e.delta == "string" ? e.verbatim === !0 ? {
|
|
902
|
+
type: "delta",
|
|
903
|
+
delta: e.delta,
|
|
904
|
+
verbatim: !0
|
|
905
|
+
} : {
|
|
906
|
+
type: "delta",
|
|
907
|
+
delta: e.delta
|
|
908
|
+
} : {
|
|
909
|
+
type: "conversation_id",
|
|
910
|
+
conversationId: e.conversation_id
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
//#endregion
|
|
914
|
+
//#region src/markdown/reveal.ts
|
|
915
|
+
var Ge = 40, Ke = 120;
|
|
916
|
+
function qe(e) {
|
|
917
|
+
let t = [];
|
|
918
|
+
for (let n of Q(e)) if (n.type === "text") {
|
|
919
|
+
let e = n.value.split(/(\s+)/), r = n.start;
|
|
920
|
+
for (let n of e) r += n.length, n.trim().length > 0 && t.push(r);
|
|
921
|
+
} else t.push(n.end);
|
|
922
|
+
return t;
|
|
923
|
+
}
|
|
924
|
+
function Je(e) {
|
|
925
|
+
let t = null;
|
|
926
|
+
return e?.addEventListener("abort", () => {
|
|
927
|
+
t?.();
|
|
928
|
+
}, { once: !0 }), function(e) {
|
|
929
|
+
return new Promise((n) => {
|
|
930
|
+
let r = setTimeout(() => {
|
|
931
|
+
t = null, n();
|
|
932
|
+
}, e);
|
|
933
|
+
t = () => {
|
|
934
|
+
clearTimeout(r), t = null, n();
|
|
935
|
+
};
|
|
936
|
+
});
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
async function Ye(e, t, n) {
|
|
940
|
+
let r = n?.wordIntervalMs ?? Ge, i = n?.tokenIntervalMs ?? Ke, a = n?.signal, o = Q(e), s = new Set(o.filter((e) => e.type !== "text").map((e) => e.end)), c = Je(a), l = "";
|
|
941
|
+
for (let n of qe(e)) if (a?.aborted || (l = e.slice(0, n), t(l), await c(s.has(n) ? i : r), a?.aborted)) return;
|
|
942
|
+
l !== e && t(e);
|
|
943
|
+
}
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/storage.ts
|
|
946
|
+
function Xe(e) {
|
|
947
|
+
return `whoo-aiden-widget:conversation:${e}`;
|
|
948
|
+
}
|
|
949
|
+
function Ze(e) {
|
|
950
|
+
try {
|
|
951
|
+
return window.sessionStorage.getItem(Xe(e));
|
|
952
|
+
} catch {
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
function Qe(e, t) {
|
|
957
|
+
try {
|
|
958
|
+
window.sessionStorage.setItem(Xe(e), t);
|
|
959
|
+
} catch {}
|
|
960
|
+
}
|
|
961
|
+
function $e(e) {
|
|
962
|
+
try {
|
|
963
|
+
window.sessionStorage.removeItem(Xe(e));
|
|
964
|
+
} catch {}
|
|
965
|
+
}
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region src/controller.ts
|
|
968
|
+
var et = class {
|
|
969
|
+
config;
|
|
970
|
+
state;
|
|
971
|
+
listeners = /* @__PURE__ */ new Set();
|
|
972
|
+
sessionToken = null;
|
|
973
|
+
conversationId = null;
|
|
974
|
+
storageIdentifier;
|
|
975
|
+
activeRequestController = null;
|
|
976
|
+
prefersReducedMotion;
|
|
977
|
+
constructor(e) {
|
|
978
|
+
this.config = e, this.storageIdentifier = e.publishableKey ?? "session-token-mode", this.prefersReducedMotion = typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches, this.state = {
|
|
979
|
+
isOpen: !1,
|
|
980
|
+
messages: [],
|
|
981
|
+
isStreaming: !1,
|
|
982
|
+
initError: null,
|
|
983
|
+
runtimeError: null,
|
|
984
|
+
messageFeedback: {},
|
|
985
|
+
primaryColor: null,
|
|
986
|
+
lastCompletedMessageText: null
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
getState() {
|
|
990
|
+
return this.state;
|
|
991
|
+
}
|
|
992
|
+
subscribe(e) {
|
|
993
|
+
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
994
|
+
}
|
|
995
|
+
setState(e) {
|
|
996
|
+
this.state = {
|
|
997
|
+
...this.state,
|
|
998
|
+
...e
|
|
999
|
+
};
|
|
1000
|
+
for (let e of this.listeners) e(this.state);
|
|
1001
|
+
}
|
|
1002
|
+
async init() {
|
|
1003
|
+
let e = this.config.apiBaseUrl ?? "https://api.aidenvoice.com";
|
|
1004
|
+
try {
|
|
1005
|
+
if (this.config.sessionToken) this.sessionToken = this.config.sessionToken;
|
|
1006
|
+
else if (this.config.publishableKey) {
|
|
1007
|
+
let { token: t, primaryColor: n } = await Ve(e, this.config.publishableKey);
|
|
1008
|
+
this.sessionToken = t, this.setState({ primaryColor: n });
|
|
1009
|
+
} else throw Error("WidgetConfig must include exactly one of publishableKey or sessionToken");
|
|
1010
|
+
} catch (e) {
|
|
1011
|
+
console.error("[whoo-aiden-widget] initialization failed:", e), this.setState({ initError: e instanceof Error ? e.message : String(e) });
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
this.conversationId = Ze(this.storageIdentifier);
|
|
1015
|
+
}
|
|
1016
|
+
open() {
|
|
1017
|
+
this.setState({ isOpen: !0 });
|
|
1018
|
+
}
|
|
1019
|
+
resetConversation() {
|
|
1020
|
+
this.activeRequestController?.abort(), this.activeRequestController = null, this.conversationId = null, $e(this.storageIdentifier), this.setState({
|
|
1021
|
+
messages: [],
|
|
1022
|
+
messageFeedback: {},
|
|
1023
|
+
runtimeError: null,
|
|
1024
|
+
isStreaming: !1,
|
|
1025
|
+
lastCompletedMessageText: null
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
close() {
|
|
1029
|
+
this.activeRequestController?.abort(), this.activeRequestController = null, this.setState({ isOpen: !1 });
|
|
1030
|
+
}
|
|
1031
|
+
async sendMessage(e) {
|
|
1032
|
+
if (!this.sessionToken) return;
|
|
1033
|
+
let t = this.config.apiBaseUrl ?? "https://api.aidenvoice.com", n = {
|
|
1034
|
+
role: "user",
|
|
1035
|
+
content: e,
|
|
1036
|
+
id: null
|
|
1037
|
+
}, r = {
|
|
1038
|
+
role: "assistant",
|
|
1039
|
+
content: "",
|
|
1040
|
+
id: null
|
|
1041
|
+
};
|
|
1042
|
+
this.setState({
|
|
1043
|
+
messages: [
|
|
1044
|
+
...this.state.messages,
|
|
1045
|
+
n,
|
|
1046
|
+
r
|
|
1047
|
+
],
|
|
1048
|
+
isStreaming: !0,
|
|
1049
|
+
runtimeError: null
|
|
1050
|
+
});
|
|
1051
|
+
let i = (e) => {
|
|
1052
|
+
let t = [...this.state.messages];
|
|
1053
|
+
t[t.length - 1] = {
|
|
1054
|
+
...t[t.length - 1],
|
|
1055
|
+
content: e
|
|
1056
|
+
}, this.setState({ messages: t });
|
|
1057
|
+
};
|
|
1058
|
+
this.activeRequestController = new AbortController();
|
|
1059
|
+
let { signal: a } = this.activeRequestController, o = "";
|
|
1060
|
+
try {
|
|
1061
|
+
for await (let n of Ue(t, this.sessionToken, this.conversationId, e, a)) if (n.type === "conversation_id") this.conversationId = n.conversationId, Qe(this.storageIdentifier, n.conversationId);
|
|
1062
|
+
else if (n.type === "delta") n.verbatim && !this.prefersReducedMotion ? (await Ye(n.delta, (e) => i(e), { signal: a }), o = n.delta) : n.verbatim ? (o = n.delta, i(o)) : (o += n.delta, i(o));
|
|
1063
|
+
else if (n.type === "done") {
|
|
1064
|
+
if (n.conversationId && (this.conversationId = n.conversationId, Qe(this.storageIdentifier, n.conversationId)), n.messageId) {
|
|
1065
|
+
let e = [...this.state.messages];
|
|
1066
|
+
e[e.length - 1] = {
|
|
1067
|
+
...e[e.length - 1],
|
|
1068
|
+
id: n.messageId
|
|
1069
|
+
}, this.setState({ messages: e });
|
|
1070
|
+
}
|
|
1071
|
+
this.setState({ lastCompletedMessageText: o });
|
|
1072
|
+
} else n.type === "error" && (console.error("[whoo-aiden-widget] chat error:", n.error), this.setState({ runtimeError: "Something went wrong, please try again." }));
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
e?.name === "AbortError" || (console.error("[whoo-aiden-widget] chat request failed:", e), this.setState({ runtimeError: "Something went wrong, please try again." }));
|
|
1075
|
+
} finally {
|
|
1076
|
+
this.activeRequestController = null, this.setState({ isStreaming: !1 });
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
expandFeedback(e) {
|
|
1080
|
+
this.setState({ messageFeedback: {
|
|
1081
|
+
...this.state.messageFeedback,
|
|
1082
|
+
[e]: { status: "expanded" }
|
|
1083
|
+
} });
|
|
1084
|
+
}
|
|
1085
|
+
cancelFeedback(e) {
|
|
1086
|
+
this.setState({ messageFeedback: {
|
|
1087
|
+
...this.state.messageFeedback,
|
|
1088
|
+
[e]: { status: "idle" }
|
|
1089
|
+
} });
|
|
1090
|
+
}
|
|
1091
|
+
async submitFeedback(e, t, n, r) {
|
|
1092
|
+
if (!this.sessionToken) return;
|
|
1093
|
+
let i = this.config.apiBaseUrl ?? "https://api.aidenvoice.com";
|
|
1094
|
+
this.setState({ messageFeedback: {
|
|
1095
|
+
...this.state.messageFeedback,
|
|
1096
|
+
[e]: {
|
|
1097
|
+
status: "submitting",
|
|
1098
|
+
rating: t
|
|
1099
|
+
}
|
|
1100
|
+
} });
|
|
1101
|
+
try {
|
|
1102
|
+
await He(i, this.sessionToken, {
|
|
1103
|
+
messageId: e,
|
|
1104
|
+
rating: t,
|
|
1105
|
+
correction: n,
|
|
1106
|
+
category: r
|
|
1107
|
+
}), this.setState({ messageFeedback: {
|
|
1108
|
+
...this.state.messageFeedback,
|
|
1109
|
+
[e]: {
|
|
1110
|
+
status: "submitted",
|
|
1111
|
+
rating: t
|
|
1112
|
+
}
|
|
1113
|
+
} });
|
|
1114
|
+
} catch (n) {
|
|
1115
|
+
console.error("[whoo-aiden-widget] feedback submission failed:", n), this.setState({ messageFeedback: {
|
|
1116
|
+
...this.state.messageFeedback,
|
|
1117
|
+
[e]: {
|
|
1118
|
+
status: "error",
|
|
1119
|
+
rating: t
|
|
1120
|
+
}
|
|
1121
|
+
} });
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}, tt = ":host,.whoo-widget-root{all:initial;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.whoo-widget-launcher{bottom:20px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:var(--whoo-widget-color,#4f46e5);width:56px;height:56px;color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:50%;justify-content:center;align-items:center;padding:0;font-size:24px;display:flex;position:fixed;box-shadow:0 2px 8px #0003}.whoo-widget-launcher:focus-visible{box-shadow:0 2px 8px #0003,0 0 0 4px #fff}.whoo-widget-launcher-logo{object-fit:cover;border-radius:50%;width:32px;height:32px}.whoo-widget-panel{bottom:88px;left:var(--whoo-widget-inset-left,auto);right:var(--whoo-widget-inset-right,20px);background:#fff;border-radius:12px;flex-direction:column;width:360px;height:480px;max-height:90vh;display:flex;position:fixed;overflow:hidden;box-shadow:0 4px 16px #0003}.whoo-widget-header{flex-shrink:0;justify-content:space-between;align-items:center;padding:8px 12px 0;display:flex}.whoo-widget-header-close,.whoo-widget-header-reset{color:var(--whoo-widget-color,#4f46e5);cursor:pointer;background:0 0;border:none;padding:4px 6px;font-size:12px}.whoo-widget-message-list{flex:1;min-height:100px;padding:12px;overflow-y:auto}.whoo-widget-message{border-radius:8px;max-width:80%;margin-bottom:8px;padding:8px 12px}.whoo-widget-message--user{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);margin-left:auto}.whoo-widget-message--assistant{color:#111;background:#f0f0f0}.whoo-widget-error-banner{color:#991b1b;background:#fee2e2;padding:8px 12px;font-size:13px}.whoo-widget-composer{border-top:1px solid #e5e5e5;gap:8px;padding:12px;display:flex}.whoo-widget-composer-input{border:1px solid #6b7280;border-radius:6px;flex:1;padding:8px}.whoo-widget-composer-send{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px}.whoo-widget-composer-send:disabled,.whoo-widget-composer-input[aria-disabled=true]{opacity:.6;cursor:not-allowed}.whoo-widget-feedback{align-items:center;gap:6px;margin-top:4px;display:flex}.whoo-widget-feedback-buttons{gap:6px;display:flex}.whoo-widget-feedback-buttons button{cursor:pointer;opacity:.6;background:0 0;border:none;padding:2px 4px;font-size:14px}.whoo-widget-feedback-buttons button:disabled{opacity:.3;cursor:not-allowed}.whoo-widget-feedback-form{flex-direction:column;gap:6px;margin-top:6px;display:flex}.whoo-widget-feedback-textarea{box-sizing:border-box;resize:vertical;border:1px solid #6b7280;border-radius:6px;width:100%;padding:6px;font-size:12px}.whoo-widget-feedback-select{border:1px solid #6b7280;border-radius:6px;padding:4px;font-size:12px}.whoo-widget-feedback-form-buttons{gap:6px;display:flex}.whoo-widget-feedback-submit{background:var(--whoo-widget-color,#4f46e5);color:var(--whoo-widget-text-on-color,#fff);cursor:pointer;border:none;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-cancel{color:#111;cursor:pointer;background:#fff;border:1px solid #6b7280;border-radius:6px;padding:8px 16px;font-size:13px}.whoo-widget-feedback-submitted{color:#6b7280;margin-top:4px;font-size:12px}.whoo-widget-feedback-error{color:#991b1b;font-size:12px}.whoo-widget-sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{outline-offset:2px;outline:2px solid #111827;box-shadow:0 0 0 4px #fff}";
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/theme.ts
|
|
1127
|
+
function nt(e) {
|
|
1128
|
+
let t = document.createElement("div");
|
|
1129
|
+
if (t.style.color = e, t.style.color === "") return null;
|
|
1130
|
+
document.body.appendChild(t);
|
|
1131
|
+
let n = getComputedStyle(t).color;
|
|
1132
|
+
document.body.removeChild(t);
|
|
1133
|
+
let r = n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
1134
|
+
return r ? [
|
|
1135
|
+
Number(r[1]),
|
|
1136
|
+
Number(r[2]),
|
|
1137
|
+
Number(r[3])
|
|
1138
|
+
] : null;
|
|
1139
|
+
}
|
|
1140
|
+
function $([e, t, n]) {
|
|
1141
|
+
let r = (e) => {
|
|
1142
|
+
let t = e / 255;
|
|
1143
|
+
return t <= .03928 ? t / 12.92 : ((t + .055) / 1.055) ** 2.4;
|
|
1144
|
+
};
|
|
1145
|
+
return .2126 * r(e) + .7152 * r(t) + .0722 * r(n);
|
|
1146
|
+
}
|
|
1147
|
+
function rt(e, t) {
|
|
1148
|
+
let n = Math.max(e, t), r = Math.min(e, t);
|
|
1149
|
+
return (n + .05) / (r + .05);
|
|
1150
|
+
}
|
|
1151
|
+
function it(e) {
|
|
1152
|
+
let t = nt(e);
|
|
1153
|
+
if (!t) return console.warn(`[whoo-aiden-widget] Could not parse color "${e}" for contrast calculation; defaulting to white text.`), "#ffffff";
|
|
1154
|
+
let n = $(t);
|
|
1155
|
+
return rt(n, $([
|
|
1156
|
+
0,
|
|
1157
|
+
0,
|
|
1158
|
+
0
|
|
1159
|
+
])) >= rt(n, $([
|
|
1160
|
+
255,
|
|
1161
|
+
255,
|
|
1162
|
+
255
|
|
1163
|
+
])) ? "#000000" : "#ffffff";
|
|
1164
|
+
}
|
|
1165
|
+
function at(e, t) {
|
|
1166
|
+
let n = t.color ?? "#4f46e5";
|
|
1167
|
+
e.style.setProperty("--whoo-widget-color", n), e.style.setProperty("--whoo-widget-text-on-color", it(n));
|
|
1168
|
+
let r = t.position === "bottom-left";
|
|
1169
|
+
e.style.setProperty("--whoo-widget-inset-left", r ? "20px" : "auto"), e.style.setProperty("--whoo-widget-inset-right", r ? "auto" : "20px");
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/mount.tsx
|
|
1173
|
+
function ot(e) {
|
|
1174
|
+
let t = document.createElement("div");
|
|
1175
|
+
t.id = "whoo-aiden-widget-host";
|
|
1176
|
+
let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
|
|
1177
|
+
r.textContent = tt, n.appendChild(r);
|
|
1178
|
+
let i = document.createElement("div");
|
|
1179
|
+
n.appendChild(i), at(i, e);
|
|
1180
|
+
let a = new et(e);
|
|
1181
|
+
return a.subscribe((e) => {
|
|
1182
|
+
e.primaryColor && (i.style.setProperty("--whoo-widget-color", e.primaryColor), i.style.setProperty("--whoo-widget-text-on-color", it(e.primaryColor)));
|
|
1183
|
+
}), ce(/* @__PURE__ */ q(ze, { controller: a }), i), a.init(), document.body.appendChild(t), { unmount() {
|
|
1184
|
+
ce(null, i), t.remove();
|
|
1185
|
+
} };
|
|
1186
|
+
}
|
|
1187
|
+
//#endregion
|
|
1188
|
+
//#region src/index.ts
|
|
1189
|
+
function st(t) {
|
|
1190
|
+
return e(t), ot(t);
|
|
1191
|
+
}
|
|
1192
|
+
//#endregion
|
|
1193
|
+
export { st as init };
|