UNPKG

@paperlinkai/chat

Version:

PaperLink AI Chat Widget - Easy integration for any website

1,362 lines 117 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a2, b2) => { for (var prop in b2 || (b2 = {})) if (__hasOwnProp.call(b2, prop)) __defNormalProp(a2, prop, b2[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b2)) { if (__propIsEnum.call(b2, prop)) __defNormalProp(a2, prop, b2[prop]); } return a2; }; var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e2) { reject(e2); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e2) { reject(e2); } }; var step = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var n, l$1, u$2, i$1, r$1, o$1, e$1, f$2, c$1, s$1, a$1, p$1 = {}, v$1 = [], y$1 = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, w$1 = Array.isArray; function d$1(n2, l2) { for (var u2 in l2) n2[u2] = l2[u2]; return n2; } function g(n2) { n2 && n2.parentNode && n2.parentNode.removeChild(n2); } function _(l2, u2, t2) { var i2, r2, o2, e2 = {}; for (o2 in u2) "key" == o2 ? i2 = u2[o2] : "ref" == o2 ? r2 = u2[o2] : e2[o2] = u2[o2]; if (arguments.length > 2 && (e2.children = arguments.length > 3 ? n.call(arguments, 2) : t2), "function" == typeof l2 && null != l2.defaultProps) for (o2 in l2.defaultProps) void 0 === e2[o2] && (e2[o2] = l2.defaultProps[o2]); return m$1(l2, e2, i2, r2, null); } function m$1(n2, t2, i2, r2, o2) { var e2 = { type: n2, props: t2, key: i2, ref: r2, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: null == o2 ? ++u$2 : o2, __i: -1, __u: 0 }; return null == o2 && null != l$1.vnode && l$1.vnode(e2), e2; } function b() { return { current: null }; } function k$1(n2) { return n2.children; } function x(n2, l2) { this.props = n2, this.context = l2; } function S(n2, l2) { if (null == l2) return n2.__ ? S(n2.__, n2.__i + 1) : null; for (var u2; l2 < n2.__k.length; l2++) if (null != (u2 = n2.__k[l2]) && null != u2.__e) return u2.__e; return "function" == typeof n2.type ? S(n2) : null; } function C$1(n2) { var l2, u2; if (null != (n2 = n2.__) && null != n2.__c) { for (n2.__e = n2.__c.base = null, l2 = 0; l2 < n2.__k.length; l2++) if (null != (u2 = n2.__k[l2]) && null != u2.__e) { n2.__e = n2.__c.base = u2.__e; break; } return C$1(n2); } } function M(n2) { (!n2.__d && (n2.__d = true) && i$1.push(n2) && !$.__r++ || r$1 != l$1.debounceRendering) && ((r$1 = l$1.debounceRendering) || o$1)($); } function $() { for (var n2, u2, t2, r2, o2, f2, c2, s2 = 1; i$1.length; ) i$1.length > s2 && i$1.sort(e$1), n2 = i$1.shift(), s2 = i$1.length, n2.__d && (t2 = void 0, o2 = (r2 = (u2 = n2).__v).__e, f2 = [], c2 = [], u2.__P && ((t2 = d$1({}, r2)).__v = r2.__v + 1, l$1.vnode && l$1.vnode(t2), O(u2.__P, t2, r2, u2.__n, u2.__P.namespaceURI, 32 & r2.__u ? [o2] : null, f2, null == o2 ? S(r2) : o2, !!(32 & r2.__u), c2), t2.__v = r2.__v, t2.__.__k[t2.__i] = t2, N(f2, t2, c2), t2.__e != o2 && C$1(t2))); $.__r = 0; } function I(n2, l2, u2, t2, i2, r2, o2, e2, f2, c2, s2) { var a2, h2, y2, w2, d2, g2, _2 = t2 && t2.__k || v$1, m2 = l2.length; for (f2 = P(u2, l2, _2, f2, m2), a2 = 0; a2 < m2; a2++) null != (y2 = u2.__k[a2]) && (h2 = -1 == y2.__i ? p$1 : _2[y2.__i] || p$1, y2.__i = a2, g2 = O(n2, y2, h2, i2, r2, o2, e2, f2, c2, s2), w2 = y2.__e, y2.ref && h2.ref != y2.ref && (h2.ref && B$1(h2.ref, null, y2), s2.push(y2.ref, y2.__c || w2, y2)), null == d2 && null != w2 && (d2 = w2), 4 & y2.__u || h2.__k === y2.__k ? f2 = A(y2, f2, n2) : "function" == typeof y2.type && void 0 !== g2 ? f2 = g2 : w2 && (f2 = w2.nextSibling), y2.__u &= -7); return u2.__e = d2, f2; } function P(n2, l2, u2, t2, i2) { var r2, o2, e2, f2, c2, s2 = u2.length, a2 = s2, h2 = 0; for (n2.__k = new Array(i2), r2 = 0; r2 < i2; r2++) null != (o2 = l2[r2]) && "boolean" != typeof o2 && "function" != typeof o2 ? (f2 = r2 + h2, (o2 = n2.__k[r2] = "string" == typeof o2 || "number" == typeof o2 || "bigint" == typeof o2 || o2.constructor == String ? m$1(null, o2, null, null, null) : w$1(o2) ? m$1(k$1, { children: o2 }, null, null, null) : null == o2.constructor && o2.__b > 0 ? m$1(o2.type, o2.props, o2.key, o2.ref ? o2.ref : null, o2.__v) : o2).__ = n2, o2.__b = n2.__b + 1, e2 = null, -1 != (c2 = o2.__i = L(o2, u2, f2, a2)) && (a2--, (e2 = u2[c2]) && (e2.__u |= 2)), null == e2 || null == e2.__v ? (-1 == c2 && (i2 > s2 ? h2-- : i2 < s2 && h2++), "function" != typeof o2.type && (o2.__u |= 4)) : c2 != f2 && (c2 == f2 - 1 ? h2-- : c2 == f2 + 1 ? h2++ : (c2 > f2 ? h2-- : h2++, o2.__u |= 4))) : n2.__k[r2] = null; if (a2) for (r2 = 0; r2 < s2; r2++) null != (e2 = u2[r2]) && 0 == (2 & e2.__u) && (e2.__e == t2 && (t2 = S(e2)), D$1(e2, e2)); return t2; } function A(n2, l2, u2) { var t2, i2; if ("function" == typeof n2.type) { for (t2 = n2.__k, i2 = 0; t2 && i2 < t2.length; i2++) t2[i2] && (t2[i2].__ = n2, l2 = A(t2[i2], l2, u2)); return l2; } n2.__e != l2 && (l2 && n2.type && !u2.contains(l2) && (l2 = S(n2)), u2.insertBefore(n2.__e, l2 || null), l2 = n2.__e); do { l2 = l2 && l2.nextSibling; } while (null != l2 && 8 == l2.nodeType); return l2; } function L(n2, l2, u2, t2) { var i2, r2, o2, e2 = n2.key, f2 = n2.type, c2 = l2[u2], s2 = null != c2 && 0 == (2 & c2.__u); if (null === c2 && null == n2.key || s2 && e2 == c2.key && f2 == c2.type) return u2; if (t2 > (s2 ? 1 : 0)) { for (i2 = u2 - 1, r2 = u2 + 1; i2 >= 0 || r2 < l2.length; ) if (null != (c2 = l2[o2 = i2 >= 0 ? i2-- : r2++]) && 0 == (2 & c2.__u) && e2 == c2.key && f2 == c2.type) return o2; } return -1; } function T(n2, l2, u2) { "-" == l2[0] ? n2.setProperty(l2, null == u2 ? "" : u2) : n2[l2] = null == u2 ? "" : "number" != typeof u2 || y$1.test(l2) ? u2 : u2 + "px"; } function j$1(n2, l2, u2, t2, i2) { var r2, o2; n: if ("style" == l2) if ("string" == typeof u2) n2.style.cssText = u2; else { if ("string" == typeof t2 && (n2.style.cssText = t2 = ""), t2) for (l2 in t2) u2 && l2 in u2 || T(n2.style, l2, ""); if (u2) for (l2 in u2) t2 && u2[l2] == t2[l2] || T(n2.style, l2, u2[l2]); } else if ("o" == l2[0] && "n" == l2[1]) r2 = l2 != (l2 = l2.replace(f$2, "$1")), o2 = l2.toLowerCase(), l2 = o2 in n2 || "onFocusOut" == l2 || "onFocusIn" == l2 ? o2.slice(2) : l2.slice(2), n2.l || (n2.l = {}), n2.l[l2 + r2] = u2, u2 ? t2 ? u2.u = t2.u : (u2.u = c$1, n2.addEventListener(l2, r2 ? a$1 : s$1, r2)) : n2.removeEventListener(l2, r2 ? a$1 : s$1, r2); else { if ("http://www.w3.org/2000/svg" == i2) l2 = l2.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s"); else if ("width" != l2 && "height" != l2 && "href" != l2 && "list" != l2 && "form" != l2 && "tabIndex" != l2 && "download" != l2 && "rowSpan" != l2 && "colSpan" != l2 && "role" != l2 && "popover" != l2 && l2 in n2) try { n2[l2] = null == u2 ? "" : u2; break n; } catch (n3) { } "function" == typeof u2 || (null == u2 || false === u2 && "-" != l2[4] ? n2.removeAttribute(l2) : n2.setAttribute(l2, "popover" == l2 && 1 == u2 ? "" : u2)); } } function F(n2) { return function(u2) { if (this.l) { var t2 = this.l[u2.type + n2]; if (null == u2.t) u2.t = c$1++; else if (u2.t < t2.u) return; return t2(l$1.event ? l$1.event(u2) : u2); } }; } function O(n2, u2, t2, i2, r2, o2, e2, f2, c2, s2) { var a2, h2, p2, v2, y2, _2, m2, b2, S2, C2, M2, $2, P2, A2, H, L2, T2, j2 = u2.type; if (null != u2.constructor) return null; 128 & t2.__u && (c2 = !!(32 & t2.__u), o2 = [f2 = u2.__e = t2.__e]), (a2 = l$1.__b) && a2(u2); n: if ("function" == typeof j2) try { if (b2 = u2.props, S2 = "prototype" in j2 && j2.prototype.render, C2 = (a2 = j2.contextType) && i2[a2.__c], M2 = a2 ? C2 ? C2.props.value : a2.__ : i2, t2.__c ? m2 = (h2 = u2.__c = t2.__c).__ = h2.__E : (S2 ? u2.__c = h2 = new j2(b2, M2) : (u2.__c = h2 = new x(b2, M2), h2.constructor = j2, h2.render = E), C2 && C2.sub(h2), h2.props = b2, h2.state || (h2.state = {}), h2.context = M2, h2.__n = i2, p2 = h2.__d = true, h2.__h = [], h2._sb = []), S2 && null == h2.__s && (h2.__s = h2.state), S2 && null != j2.getDerivedStateFromProps && (h2.__s == h2.state && (h2.__s = d$1({}, h2.__s)), d$1(h2.__s, j2.getDerivedStateFromProps(b2, h2.__s))), v2 = h2.props, y2 = h2.state, h2.__v = u2, p2) S2 && null == j2.getDerivedStateFromProps && null != h2.componentWillMount && h2.componentWillMount(), S2 && null != h2.componentDidMount && h2.__h.push(h2.componentDidMount); else { if (S2 && null == j2.getDerivedStateFromProps && b2 !== v2 && null != h2.componentWillReceiveProps && h2.componentWillReceiveProps(b2, M2), !h2.__e && null != h2.shouldComponentUpdate && false === h2.shouldComponentUpdate(b2, h2.__s, M2) || u2.__v == t2.__v) { for (u2.__v != t2.__v && (h2.props = b2, h2.state = h2.__s, h2.__d = false), u2.__e = t2.__e, u2.__k = t2.__k, u2.__k.some(function(n3) { n3 && (n3.__ = u2); }), $2 = 0; $2 < h2._sb.length; $2++) h2.__h.push(h2._sb[$2]); h2._sb = [], h2.__h.length && e2.push(h2); break n; } null != h2.componentWillUpdate && h2.componentWillUpdate(b2, h2.__s, M2), S2 && null != h2.componentDidUpdate && h2.__h.push(function() { h2.componentDidUpdate(v2, y2, _2); }); } if (h2.context = M2, h2.props = b2, h2.__P = n2, h2.__e = false, P2 = l$1.__r, A2 = 0, S2) { for (h2.state = h2.__s, h2.__d = false, P2 && P2(u2), a2 = h2.render(h2.props, h2.state, h2.context), H = 0; H < h2._sb.length; H++) h2.__h.push(h2._sb[H]); h2._sb = []; } else do { h2.__d = false, P2 && P2(u2), a2 = h2.render(h2.props, h2.state, h2.context), h2.state = h2.__s; } while (h2.__d && ++A2 < 25); h2.state = h2.__s, null != h2.getChildContext && (i2 = d$1(d$1({}, i2), h2.getChildContext())), S2 && !p2 && null != h2.getSnapshotBeforeUpdate && (_2 = h2.getSnapshotBeforeUpdate(v2, y2)), L2 = a2, null != a2 && a2.type === k$1 && null == a2.key && (L2 = V(a2.props.children)), f2 = I(n2, w$1(L2) ? L2 : [L2], u2, t2, i2, r2, o2, e2, f2, c2, s2), h2.base = u2.__e, u2.__u &= -161, h2.__h.length && e2.push(h2), m2 && (h2.__E = h2.__ = null); } catch (n3) { if (u2.__v = null, c2 || null != o2) if (n3.then) { for (u2.__u |= c2 ? 160 : 128; f2 && 8 == f2.nodeType && f2.nextSibling; ) f2 = f2.nextSibling; o2[o2.indexOf(f2)] = null, u2.__e = f2; } else { for (T2 = o2.length; T2--; ) g(o2[T2]); z$1(u2); } else u2.__e = t2.__e, u2.__k = t2.__k, n3.then || z$1(u2); l$1.__e(n3, u2, t2); } else null == o2 && u2.__v == t2.__v ? (u2.__k = t2.__k, u2.__e = t2.__e) : f2 = u2.__e = q(t2.__e, u2, t2, i2, r2, o2, e2, c2, s2); return (a2 = l$1.diffed) && a2(u2), 128 & u2.__u ? void 0 : f2; } function z$1(n2) { n2 && n2.__c && (n2.__c.__e = true), n2 && n2.__k && n2.__k.forEach(z$1); } function N(n2, u2, t2) { for (var i2 = 0; i2 < t2.length; i2++) B$1(t2[i2], t2[++i2], t2[++i2]); l$1.__c && l$1.__c(u2, n2), n2.some(function(u3) { try { n2 = u3.__h, u3.__h = [], n2.some(function(n3) { n3.call(u3); }); } catch (n3) { l$1.__e(n3, u3.__v); } }); } function V(n2) { return "object" != typeof n2 || null == n2 || n2.__b && n2.__b > 0 ? n2 : w$1(n2) ? n2.map(V) : d$1({}, n2); } function q(u2, t2, i2, r2, o2, e2, f2, c2, s2) { var a2, h2, v2, y2, d2, _2, m2, b2 = i2.props, k2 = t2.props, x2 = t2.type; if ("svg" == x2 ? o2 = "http://www.w3.org/2000/svg" : "math" == x2 ? o2 = "http://www.w3.org/1998/Math/MathML" : o2 || (o2 = "http://www.w3.org/1999/xhtml"), null != e2) { for (a2 = 0; a2 < e2.length; a2++) if ((d2 = e2[a2]) && "setAttribute" in d2 == !!x2 && (x2 ? d2.localName == x2 : 3 == d2.nodeType)) { u2 = d2, e2[a2] = null; break; } } if (null == u2) { if (null == x2) return document.createTextNode(k2); u2 = document.createElementNS(o2, x2, k2.is && k2), c2 && (l$1.__m && l$1.__m(t2, e2), c2 = false), e2 = null; } if (null == x2) b2 === k2 || c2 && u2.data == k2 || (u2.data = k2); else { if (e2 = e2 && n.call(u2.childNodes), b2 = i2.props || p$1, !c2 && null != e2) for (b2 = {}, a2 = 0; a2 < u2.attributes.length; a2++) b2[(d2 = u2.attributes[a2]).name] = d2.value; for (a2 in b2) if (d2 = b2[a2], "children" == a2) ; else if ("dangerouslySetInnerHTML" == a2) v2 = d2; else if (!(a2 in k2)) { if ("value" == a2 && "defaultValue" in k2 || "checked" == a2 && "defaultChecked" in k2) continue; j$1(u2, a2, null, d2, o2); } for (a2 in k2) d2 = k2[a2], "children" == a2 ? y2 = d2 : "dangerouslySetInnerHTML" == a2 ? h2 = d2 : "value" == a2 ? _2 = d2 : "checked" == a2 ? m2 = d2 : c2 && "function" != typeof d2 || b2[a2] === d2 || j$1(u2, a2, d2, b2[a2], o2); if (h2) c2 || v2 && (h2.__html == v2.__html || h2.__html == u2.innerHTML) || (u2.innerHTML = h2.__html), t2.__k = []; else if (v2 && (u2.innerHTML = ""), I("template" == t2.type ? u2.content : u2, w$1(y2) ? y2 : [y2], t2, i2, r2, "foreignObject" == x2 ? "http://www.w3.org/1999/xhtml" : o2, e2, f2, e2 ? e2[0] : i2.__k && S(i2, 0), c2, s2), null != e2) for (a2 = e2.length; a2--; ) g(e2[a2]); c2 || (a2 = "value", "progress" == x2 && null == _2 ? u2.removeAttribute("value") : null != _2 && (_2 !== u2[a2] || "progress" == x2 && !_2 || "option" == x2 && _2 != b2[a2]) && j$1(u2, a2, _2, b2[a2], o2), a2 = "checked", null != m2 && m2 != u2[a2] && j$1(u2, a2, m2, b2[a2], o2)); } return u2; } function B$1(n2, u2, t2) { try { if ("function" == typeof n2) { var i2 = "function" == typeof n2.__u; i2 && n2.__u(), i2 && null == u2 || (n2.__u = n2(u2)); } else n2.current = u2; } catch (n3) { l$1.__e(n3, t2); } } function D$1(n2, u2, t2) { var i2, r2; if (l$1.unmount && l$1.unmount(n2), (i2 = n2.ref) && (i2.current && i2.current != n2.__e || B$1(i2, null, u2)), null != (i2 = n2.__c)) { if (i2.componentWillUnmount) try { i2.componentWillUnmount(); } catch (n3) { l$1.__e(n3, u2); } i2.base = i2.__P = null; } if (i2 = n2.__k) for (r2 = 0; r2 < i2.length; r2++) i2[r2] && D$1(i2[r2], u2, t2 || "function" != typeof n2.type); t2 || g(n2.__e), n2.__c = n2.__ = n2.__e = void 0; } function E(n2, l2, u2) { return this.constructor(n2, u2); } function G(u2, t2, i2) { var r2, o2, e2, f2; t2 == document && (t2 = document.documentElement), l$1.__ && l$1.__(u2, t2), o2 = (r2 = false) ? null : t2.__k, e2 = [], f2 = [], O(t2, u2 = t2.__k = _(k$1, null, [u2]), o2 || p$1, p$1, t2.namespaceURI, o2 ? null : t2.firstChild ? n.call(t2.childNodes) : null, e2, o2 ? o2.__e : t2.firstChild, r2, f2), N(e2, u2, f2); } n = v$1.slice, l$1 = { __e: function(n2, l2, u2, t2) { for (var i2, r2, o2; l2 = l2.__; ) if ((i2 = l2.__c) && !i2.__) try { if ((r2 = i2.constructor) && null != r2.getDerivedStateFromError && (i2.setState(r2.getDerivedStateFromError(n2)), o2 = i2.__d), null != i2.componentDidCatch && (i2.componentDidCatch(n2, t2 || {}), o2 = i2.__d), o2) return i2.__E = i2; } catch (l3) { n2 = l3; } throw n2; } }, u$2 = 0, x.prototype.setState = function(n2, l2) { var u2; u2 = null != this.__s && this.__s != this.state ? this.__s : this.__s = d$1({}, this.state), "function" == typeof n2 && (n2 = n2(d$1({}, u2), this.props)), n2 && d$1(u2, n2), null != n2 && this.__v && (l2 && this._sb.push(l2), M(this)); }, x.prototype.forceUpdate = function(n2) { this.__v && (this.__e = true, n2 && this.__h.push(n2), M(this)); }, x.prototype.render = k$1, i$1 = [], o$1 = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, e$1 = function(n2, l2) { return n2.__v.__b - l2.__v.__b; }, $.__r = 0, f$2 = /(PointerCapture)$|Capture$/i, c$1 = 0, s$1 = F(false), a$1 = F(true); var f$1 = 0; function u$1(e2, t2, n2, o2, i2, u2) { t2 || (t2 = {}); var a2, c2, p2 = t2; if ("ref" in p2) for (c2 in p2 = {}, t2) "ref" == c2 ? a2 = t2[c2] : p2[c2] = t2[c2]; var l2 = { type: e2, props: p2, key: n2, ref: a2, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --f$1, __i: -1, __u: 0, __source: i2, __self: u2 }; if ("function" == typeof e2 && (a2 = e2.defaultProps)) for (c2 in a2) void 0 === p2[c2] && (p2[c2] = a2[c2]); return l$1.vnode && l$1.vnode(l2), l2; } var LogLevel = /* @__PURE__ */ ((LogLevel2) => { LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG"; LogLevel2[LogLevel2["INFO"] = 1] = "INFO"; LogLevel2[LogLevel2["WARN"] = 2] = "WARN"; LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR"; return LogLevel2; })(LogLevel || {}); class Logger { constructor() { __publicField(this, "logLevel", 1); __publicField(this, "prefix", "[PaperlinkWidget]"); } setLevel(level) { this.logLevel = level; } log(level, message, ...args) { if (level < this.logLevel || typeof console === "undefined") { return; } const timestamp = (/* @__PURE__ */ new Date()).toISOString(); const levelName = LogLevel[level]; const formattedMessage = `${this.prefix} [${timestamp}] ${levelName}: ${message}`; switch (level) { case 0: console.debug(formattedMessage, ...args); break; case 1: console.info(formattedMessage, ...args); break; case 2: console.warn(formattedMessage, ...args); break; case 3: console.error(formattedMessage, ...args); break; } } debug(message, ...args) { this.log(0, message, ...args); } info(message, ...args) { this.log(1, message, ...args); } warn(message, ...args) { this.log(2, message, ...args); } error(message, ...args) { this.log(3, message, ...args); } group(label) { if (this.logLevel <= 0 && typeof console !== "undefined") { console.group(`${this.prefix} ${label}`); } } groupEnd() { if (this.logLevel <= 0 && typeof console !== "undefined") { console.groupEnd(); } } } const logger = new Logger(); class ApiError extends Error { constructor(code, message, status, details) { super(message); this.code = code; this.status = status; this.details = details; this.name = "ApiError"; } } class ApiClient { // 3 second constructor(config) { __publicField(this, "baseUrl"); __publicField(this, "organizationId"); __publicField(this, "defaultTimeout", 6e4); // 60 seconds __publicField(this, "defaultRetries", 3); __publicField(this, "defaultRetryDelay", 3e3); this.baseUrl = "https://dev-api.paperlinkai.com/api/v1"; this.organizationId = config.apiKey && config.apiKey !== "demo-api-key" ? config.apiKey : "f24ee8c8-cfdf-4dfb-bbb6-e26e9149a26c"; } /** * Make HTTP request with error handling and retries */ request(_0) { return __async(this, arguments, function* (endpoint, options = {}) { const _a = options, { timeout = this.defaultTimeout, retries = this.defaultRetries, retryDelay = this.defaultRetryDelay } = _a, fetchOptions = __objRest(_a, [ "timeout", "retries", "retryDelay" ]); const url = `${this.baseUrl}${endpoint}`; const headers = __spreadValues({ "Content-Type": "application/json" }, fetchOptions.headers); const requestConfig = __spreadProps(__spreadValues({}, fetchOptions), { headers }); let lastError = null; for (let attempt = 0; attempt <= retries; attempt++) { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), timeout); const response = yield fetch(url, __spreadProps(__spreadValues({}, requestConfig), { signal: controller.signal })); clearTimeout(timeoutId); const responseData = yield response.json().catch(() => null); if (!response.ok) { throw new ApiError( "HTTP_ERROR", (responseData == null ? void 0 : responseData.message) || `HTTP ${response.status}: ${response.statusText}`, response.status, responseData ); } return responseData; } catch (error) { lastError = error instanceof Error ? error : new Error(String(error)); if (error instanceof ApiError) { if (error.status && error.status >= 400 && error.status < 500 && error.status !== 429) { throw error; } } if (attempt < retries) { const delay = retryDelay * Math.pow(2, attempt); logger.warn(`API request failed, retrying in ${delay}ms`, { url, attempt: attempt + 1, error: lastError.message }); yield this.sleep(delay); } } } logger.error("API request failed after all retries", { url, error: lastError }); throw lastError || new ApiError("REQUEST_FAILED", "Request failed after all retries"); }); } /** * Sleep utility for delays */ sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } /** * Start a new chat session with first message */ startSession(message) { return __async(this, null, function* () { const requestData = { message: message.trim(), organizationId: this.organizationId }; const response = yield this.request( "/chat/session/start", { method: "POST", body: JSON.stringify(requestData) } ); if (!response.success || !response.data) { throw new ApiError( "SESSION_START_FAILED", response.message || "Failed to start session", response.status ); } return response.data; }); } /** * Continue existing session with a new message */ continueSession(sessionId, message) { return __async(this, null, function* () { const requestData = { sessionId, message: message.trim(), organizationId: this.organizationId }; const response = yield this.request( "/chat/session/continue", { method: "POST", body: JSON.stringify(requestData) } ); if (!response.success || !response.data) { throw new ApiError( "SESSION_CONTINUE_FAILED", response.message || "Failed to continue session", response.status ); } return response.data; }); } /** * Get session conversation history */ getSessionHistory(sessionId, limit = 50) { return __async(this, null, function* () { const url = `/chat/session/${sessionId}/history?organizationId=${this.organizationId}&limit=${limit}`; const response = yield this.request(url, { method: "GET" }); if (!response.success || !response.data) { throw new ApiError( "HISTORY_FETCH_FAILED", response.message || "Failed to fetch session history", response.status ); } return response.data; }); } /** * Send a message (either start session or continue) */ sendMessage(sessionId, message) { return __async(this, null, function* () { try { if (!sessionId || sessionId.trim() === "") { const response2 = yield this.startSession(message); const userMessage2 = { id: `user-${Date.now()}`, role: "USER", content: message, timestamp: (/* @__PURE__ */ new Date()).toISOString(), sources: null }; const assistantMessage2 = { id: `assistant-${Date.now()}`, role: "ASSISTANT", content: response2.message, timestamp: (/* @__PURE__ */ new Date()).toISOString(), sources: null, processing_time: response2.processing_time }; return { sessionId: response2.session_id, assistantMessage: assistantMessage2, userMessage: userMessage2, followupQuestions: response2.followup_questions || [] }; } const response = yield this.continueSession(sessionId, message); const userMessage = { id: `user-${Date.now()}`, role: "USER", content: message, timestamp: (/* @__PURE__ */ new Date()).toISOString(), sources: null }; const assistantMessage = { id: `assistant-${Date.now()}`, role: "ASSISTANT", content: response.message, timestamp: (/* @__PURE__ */ new Date()).toISOString(), sources: null, processing_time: response.processing_time }; return { sessionId: response.session_id, assistantMessage, userMessage, followupQuestions: response.followup_questions || [] }; } catch (error) { logger.error("Failed to send message", { error, sessionId, message }); throw error; } }); } /** * Health check */ healthCheck() { return __async(this, null, function* () { try { yield this.request("/chat/session/start", { method: "POST", body: JSON.stringify({ message: "test", organizationId: this.organizationId }), timeout: 5e3, retries: 0 }); return true; } catch (error) { logger.warn("Health check failed", { error }); return false; } }); } } class StorageManager { constructor(storageType = "sessionStorage") { __publicField(this, "prefix", "paperlink_widget_"); this.storageType = storageType; } /** * Get storage instance */ getStorage() { try { const storage2 = this.storageType === "localStorage" ? window.localStorage : window.sessionStorage; const testKey = "__storage_test__"; storage2.setItem(testKey, "test"); storage2.removeItem(testKey); return storage2; } catch (error) { logger.warn("Storage not available", { type: this.storageType, error }); return null; } } /** * Generate prefixed key */ getKey(key) { return `${this.prefix}${key}`; } /** * Set item in storage */ set(key, value) { try { const storage2 = this.getStorage(); if (!storage2) { return false; } const serializedValue = JSON.stringify({ value, timestamp: Date.now(), type: typeof value }); storage2.setItem(this.getKey(key), serializedValue); logger.debug("Storage set", { key, type: typeof value }); return true; } catch (error) { logger.error("Failed to set storage item", { key, error }); return false; } } /** * Get item from storage */ get(key, defaultValue) { try { const storage2 = this.getStorage(); if (!storage2) { return defaultValue || null; } const item = storage2.getItem(this.getKey(key)); if (!item) { return defaultValue || null; } const parsed = JSON.parse(item); logger.debug("Storage get", { key, type: parsed.type }); return parsed.value; } catch (error) { logger.error("Failed to get storage item", { key, error }); return defaultValue || null; } } /** * Remove item from storage */ remove(key) { try { const storage2 = this.getStorage(); if (!storage2) { return false; } storage2.removeItem(this.getKey(key)); logger.debug("Storage remove", { key }); return true; } catch (error) { logger.error("Failed to remove storage item", { key, error }); return false; } } /** * Clear all widget-related storage items */ clear() { try { const storage2 = this.getStorage(); if (!storage2) { return false; } const keysToRemove = []; for (let i2 = 0; i2 < storage2.length; i2++) { const key = storage2.key(i2); if (key && key.startsWith(this.prefix)) { keysToRemove.push(key); } } keysToRemove.forEach((key) => storage2.removeItem(key)); logger.debug("Storage cleared", { removedKeys: keysToRemove.length }); return true; } catch (error) { logger.error("Failed to clear storage", { error }); return false; } } /** * Check if key exists */ has(key) { try { const storage2 = this.getStorage(); if (!storage2) { return false; } return storage2.getItem(this.getKey(key)) !== null; } catch (error) { logger.error("Failed to check storage key", { key, error }); return false; } } /** * Get all widget keys */ getAllKeys() { try { const storage2 = this.getStorage(); if (!storage2) { return []; } const keys = []; for (let i2 = 0; i2 < storage2.length; i2++) { const key = storage2.key(i2); if (key && key.startsWith(this.prefix)) { keys.push(key.replace(this.prefix, "")); } } return keys; } catch (error) { logger.error("Failed to get all keys", { error }); return []; } } /** * Get storage size in bytes (approximate) */ getSize() { try { const storage2 = this.getStorage(); if (!storage2) { return 0; } let size = 0; for (let i2 = 0; i2 < storage2.length; i2++) { const key = storage2.key(i2); if (key && key.startsWith(this.prefix)) { const value = storage2.getItem(key); if (value) { size += key.length + value.length; } } } return size; } catch (error) { logger.error("Failed to get storage size", { error }); return 0; } } /** * Set item with expiration */ setWithExpiry(key, value, expiryMs) { const expiryTime = Date.now() + expiryMs; return this.set(key, { value, expiry: expiryTime }); } /** * Get item with expiration check */ getWithExpiry(key, defaultValue) { const item = this.get(key); if (!item || !item.expiry) { return defaultValue || null; } if (Date.now() > item.expiry) { this.remove(key); return defaultValue || null; } return item.value; } } const sessionStorage$1 = new StorageManager("sessionStorage"); const storage = sessionStorage$1; const ICON_SPECIFICATIONS = { bot: { width: 20, height: 20, maxSize: 500 * 1024 }, // Bot avatar size send: { width: 24, height: 24, maxSize: 500 * 1024 }, // Material Icons size minimize: { width: 24, height: 24, maxSize: 500 * 1024 }, scrollDown: { width: 24, height: 24, maxSize: 500 * 1024 }, chatButton: { width: 25, height: 25, maxSize: 500 * 1024 } }; const SUPPORTED_FORMATS = ["svg", "png", "jpg", "jpeg", "webp"]; const LOADING_TIMEOUT = 5e3; const CACHE_PREFIX = "paperlink_icon_"; class IconLoader { constructor() { __publicField(this, "cache", /* @__PURE__ */ new Map()); __publicField(this, "loadingPromises", /* @__PURE__ */ new Map()); this.loadCacheFromStorage(); } /** * Load and validate a custom icon */ loadIcon(iconType, url) { return __async(this, null, function* () { const cacheKey = `${iconType}_${url}`; const cached = this.getCachedIcon(cacheKey); if (cached) { logger.info(`Using cached icon for ${iconType}`, { url }); return { success: true, dataUrl: cached.dataUrl }; } if (this.loadingPromises.has(cacheKey)) { logger.info(`Icon already loading for ${iconType}, waiting...`, { url }); return yield this.loadingPromises.get(cacheKey); } const loadingPromise = this.loadIconInternal(iconType, url, cacheKey); this.loadingPromises.set(cacheKey, loadingPromise); try { const result = yield loadingPromise; return result; } finally { this.loadingPromises.delete(cacheKey); } }); } /** * Internal icon loading logic */ loadIconInternal(iconType, url, cacheKey) { return __async(this, null, function* () { const startTime = Date.now(); try { const urlObj = new URL(url); if (!["http:", "https:"].includes(urlObj.protocol)) { throw new Error( `Invalid protocol: ${urlObj.protocol}. Only HTTP and HTTPS are supported.` ); } const extension = this.getFileExtension(url); if (!SUPPORTED_FORMATS.includes(extension.toLowerCase())) { throw new Error( `Unsupported format: ${extension}. Supported formats: ${SUPPORTED_FORMATS.join( ", " )}` ); } if (false) ; const result = yield Promise.race([ this.loadImageWithValidation(url, iconType), this.timeoutPromise(LOADING_TIMEOUT) ]); const loadTime = Date.now() - startTime; if (false) ; const cachedIcon = { url, dataUrl: result.dataUrl, timestamp: Date.now(), dimensions: result.dimensions }; this.cache.set(cacheKey, cachedIcon); this.saveCacheToStorage(); logger.info(`Successfully loaded custom icon for ${iconType}`, { url, loadTime: loadTime + "ms", dimensions: result.dimensions, size: Math.round(result.dataUrl.length * 3 / 4) + " bytes" }); return { success: true, dataUrl: result.dataUrl }; } catch (error) { const loadTime = Date.now() - startTime; const errorMessage = error instanceof Error ? error.message : "Unknown error"; logger.error( `Custom icon loading failed for '${iconType}': ${errorMessage}. Using default icon.`, { url, error: errorMessage, loadTime: loadTime + "ms", troubleshooting: this.getTroubleshootingTips(errorMessage) } ); return { success: false, error: errorMessage }; } }); } /** * Load image with validation */ loadImageWithValidation(url, iconType) { return __async(this, null, function* () { return new Promise((resolve, reject) => { const img = new Image(); const constraints = ICON_SPECIFICATIONS[iconType]; img.onload = () => { try { const { width, height } = img; logger.info(`Loaded image dimensions for ${iconType}:`, { width, height, expected: constraints }); if (false) ; const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); if (!ctx) { reject(new Error("Canvas context not available")); return; } canvas.width = width; canvas.height = height; ctx.drawImage(img, 0, 0); try { const dataUrl = canvas.toDataURL(); const sizeBytes = Math.round(dataUrl.length * 3 / 4); if (sizeBytes > constraints.maxSize) { logger.warn( `Icon size warning for ${iconType}: ${Math.round( sizeBytes / 1024 )}KB exceeds recommended ${Math.round( constraints.maxSize / 1024 )}KB`, { url, sizeBytes, maxSize: constraints.maxSize } ); } resolve({ dataUrl, dimensions: { width, height } }); } catch (canvasError) { reject( new Error(`Failed to convert image to data URL: ${canvasError}`) ); } } catch (validationError) { reject(validationError); } }; img.onerror = () => { reject( new Error( `Failed to load image. Check that the URL is accessible and returns a valid image.` ) ); }; img.crossOrigin = "anonymous"; img.src = url; }); }); } /** * Create timeout promise */ timeoutPromise(ms) { return new Promise((_2, reject) => { setTimeout(() => { reject( new Error( `Loading timeout after ${ms}ms. The image took too long to load.` ) ); }, ms); }); } /** * Extract file extension from URL */ getFileExtension(url) { try { const pathname = new URL(url).pathname; const extension = pathname.split(".").pop() || ""; return extension; } catch (e2) { return ""; } } /** * Get cached icon if valid */ getCachedIcon(cacheKey) { const cached = this.cache.get(cacheKey); if (!cached) return null; return cached; } /** * Load cache from sessionStorage */ loadCacheFromStorage() { if (typeof window === "undefined") return; try { Object.keys(sessionStorage).forEach((key) => { if (key.startsWith(CACHE_PREFIX)) { const cacheKey = key.substring(CACHE_PREFIX.length); const cached = JSON.parse(sessionStorage.getItem(key) || ""); this.cache.set(cacheKey, cached); } }); } catch (error) { logger.warn("Failed to load icon cache from sessionStorage:", error); } } /** * Save cache to sessionStorage */ saveCacheToStorage() { if (typeof window === "undefined") return; try { this.cache.forEach((cached, cacheKey) => { sessionStorage.setItem(CACHE_PREFIX + cacheKey, JSON.stringify(cached)); }); } catch (error) { logger.warn("Failed to save icon cache to sessionStorage:", error); } } /** * Get troubleshooting tips based on error message */ getTroubleshootingTips(errorMessage) { const tips = []; if (errorMessage.includes("CORS")) { tips.push("Enable CORS headers on your image server"); tips.push("Ensure the image server allows cross-origin requests"); } if (errorMessage.includes("404") || errorMessage.includes("Failed to load")) { tips.push("Verify the image URL is accessible"); tips.push("Check that the image exists at the specified URL"); } if (errorMessage.includes("timeout")) { tips.push("Check your internet connection"); tips.push("Ensure the image server is responsive"); tips.push("Consider using a smaller image file"); } if (errorMessage.includes("format")) { tips.push(`Use supported formats: ${SUPPORTED_FORMATS.join(", ")}`); } if (tips.length === 0) { tips.push("Verify the image URL is correct and accessible"); tips.push("Check browser console for additional error details"); } return tips; } /** * Clear all cached icons (useful for development) */ clearCache() { this.cache.clear(); if (typeof window !== "undefined") { Object.keys(sessionStorage).forEach((key) => { if (key.startsWith(CACHE_PREFIX)) { sessionStorage.removeItem(key); } }); } logger.info("Icon cache cleared"); } } const iconLoader = new IconLoader(); var t, r, u, i, o = 0, f = [], c = l$1, e = c.__b, a = c.__r, v = c.diffed, l = c.__c, m = c.unmount, s = c.__; function p(n2, t2) { c.__h && c.__h(r, n2, o || t2), o = 0; var u2 = r.__H || (r.__H = { __: [], __h: [] }); return n2 >= u2.__.length && u2.__.push({}), u2.__[n2]; } function d(n2) { return o = 1, h(D, n2); } function h(n2, u2, i2) { var o2 = p(t++, 2); if (o2.t = n2, !o2.__c && (o2.__ = [D(void 0, u2), function(n3) { var t2 = o2.__N ? o2.__N[0] : o2.__[0], r2 = o2.t(t2, n3); t2 !== r2 && (o2.__N = [r2, o2.__[1]], o2.__c.setState({})); }], o2.__c = r, !r.__f)) { var f2 = function(n3, t2, r2) { if (!o2.__c.__H) return true; var u3 = o2.__c.__H.__.filter(function(n4) { return !!n4.__c; }); if (u3.every(function(n4) { return !n4.__N; })) return !c2 || c2.call(this, n3, t2, r2); var i3 = o2.__c.props !== n3; return u3.forEach(function(n4) { if (n4.__N) { var t3 = n4.__[0]; n4.__ = n4.__N, n4.__N = void 0, t3 !== n4.__[0] && (i3 = true); } }), c2 && c2.call(this, n3, t2, r2) || i3; }; r.__f = true; var c2 = r.shouldComponentUpdate, e2 = r.componentWillUpdate; r.componentWillUpdate = function(n3, t2, r2) { if (this.__e) { var u3 = c2; c2 = void 0, f2(n3, t2, r2), c2 = u3; } e2 && e2.call(this, n3, t2, r2); }, r.shouldComponentUpdate = f2; } return o2.__N || o2.__; } function y(n2, u2) { var i2 = p(t++, 3); !c.__s && C(i2.__H, u2) && (i2.__ = n2, i2.u = u2, r.__H.__h.push(i2)); } function j() { for (var n2; n2 = f.shift(); ) if (n2.__P && n2.__H) try { n2.__H.__h.forEach(z), n2.__H.__h.forEach(B), n2.__H.__h = []; } catch (t2) { n2.__H.__h = [], c.__e(t2, n2.__v); } } c.__b = function(n2) { r = null, e && e(n2); }, c.__ = function(n2, t2) { n2 && t2.__k && t2.__k.__m && (n2.__m = t2.__k.__m), s && s(n2, t2); }, c.__r = function(n2) { a && a(n2), t = 0; var i2 = (r = n2.__c).__H; i2 && (u === r ? (i2.__h = [], r.__h = [], i2.__.forEach(function(n3) { n3.__N && (n3.__ = n3.__N), n3.u = n3.__N = void 0; })) : (i2.__h.forEach(z), i2.__h.forEach(B), i2.__h = [], t = 0)), u = r; }, c.diffed = function(n2) { v && v(n2); var t2 = n2.__c; t2 && t2.__H && (t2.__H.__h.length && (1 !== f.push(t2) && i === c.requestAnimationFrame || ((i = c.requestAnimationFrame) || w)(j)), t2.__H.__.forEach(function(n3) { n3.u && (n3.__H = n3.u), n3.u = void 0; })), u = r = null; }, c.__c = function(n2, t2) { t2.some(function(n3) { try { n3.__h.forEach(z), n3.__h = n3.__h.filter(function(n4) { return !n4.__ || B(n4); }); } catch (r2) { t2.some(function(n4) { n4.__h && (n4.__h = []); }), t2 = [], c.__e(r2, n3.__v); } }), l && l(n2, t2); }, c.unmount = function(n2) { m && m(n2); var t2, r2 = n2.__c; r2 && r2.__H && (r2.__H.__.forEach(function(n3) { try { z(n3); } catch (n4) { t2 = n4; } }), r2.__H = void 0, t2 && c.__e(t2, r2.__v)); }; var k = "function" == typeof requestAnimationFrame; function w(n2) { var t2, r2 = function() { clearTimeout(u2), k && cancelAnimationFrame(t2), setTimeout(n2); }, u2 = setTimeout(r2, 35); k && (t2 = requestAnimationFrame(r2)); } function z(n2) { var t2 = r, u2 = n2.__c; "function" == typeof u2 && (n2.__c = void 0, u2()), r = t2; } function B(n2) { var t2 = r; n2.__c = n2.__(), r = t2; } function C(n2, t2) { return !n2 || n2.length !== t2.length || t2.some(function(t3, r2) { return t3 !== n2[r2]; }); } function D(n2, t2) { return "function" == typeof t2 ? t2(n2) : t2; } function BotIcon(props) { const _a = props, { width = 24, height = 24, fill = "#2563eb" } = _a, rest = __objRest(_a, ["width", "height", "fill"]); return /* @__PURE__ */ u$1( "svg", __spreadProps(__spreadValues({ xmlns: "http://www.w3.org/2000/svg", width, height, viewBox: "0 0 24 24", fill, style: { marginTop: "5px" } }, rest), { children: /* @__PURE__ */ u$1("path", { d: "M20,9V7c0-1.1-0.9-2-2-2h-3c0-1.66-1.34-3-3-3S9,3.34,9,5H6C4.9,5,4,5.9,4,7v2\n c-1.66,0-3,1.34-3,3c0,1.66,1.34,3,3,3v4c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-4\n c1.66,0,3-1.34,3-3C23,10.34,21.66,9,20,9z\n M7.5,11.5C7.5,10.67,8.17,10,9,10s1.5,0.67,1.5,1.5S9.83,13,9,13S7.5,12.33,7.5,11.5z\n M16,17H8v-2h8V17z\n M15,13c-0.83,0-1.5-0.67-1.5-1.5S14.17,10,15,10\n s1.5,0.67,1.5,1.5S15.83,13,15,13z" }) }) ); } const MaterialIcon = ({ icon, className = "" }) => /* @__PURE__ */ u$1("span", { className: `material-icons ${className}`, children: icon }); const DefaultIcons = { bot: BotIcon, send: () => /* @__PURE__ */ u$1(MaterialIcon, { icon: "send" }), minimize: () => /* @__PURE__ */ u$1(MaterialIcon, { icon: "remove" }), scrollDown: () => /* @__PURE__ */ u$1(MaterialIcon, { icon: "keyboard_arrow_down" }), chatButton: () => /* @__PURE__ */ u$1( "svg", { fill: "white", stroke: "white", strokeWidth: "0", viewBox: "0 0 24 24", height: "25px", width: "25px", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ u$1("path", { d: "M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z" }) } ) }; const DynamicIcon = ({ type, customUrl, className = "", fill, style = {} }) => { const [iconState, setIconState] = d({ isLoading: false, customIcon: null, error: null }); y(() => { if (!customUrl) { setIconState({ isLoading: false, customIcon: null, error: null }); return; } let mounted = true; const loadCustomIcon = () => __async(void 0, null, function* () { setIconState((prev) => __spreadProps(__spreadValues({}, prev), { isLoading: true, error: null })); try { const result = yield iconLoader.loadIcon(type, customUrl); if (!mounted) return; if (result.success && result.dataUrl) { setIconState({ isLoading: false, customIcon: result.dataUrl, error: null }); } else { setIconState({ isLoading: false, customIcon: null, error: result.error || "Failed to load icon" }); } } catch (error) { if (!mounted) return; setIconState({ isLoading: false, customIcon: null, error: error instanceof Error ? error.message : "Unknown error" }); } }); loadCustomIcon(); return () => { mounted = false; }; }, [customUrl, type]); if (iconState.isLoading) { const DefaultIconComponent2 = DefaultIcons[type]; return /* @__PURE__ */ u$1("div", { className: `dynamic-icon loading ${className}`, style, title: "Loading custom icon...", children: /* @__PURE__ */ u$1(DefaultIconComponent2, { className, fill }) }); } if (iconState.customIcon) { const getIconDimensions = () => { switch (type) { case "bot": return { width: "20px", height: "20px" }; case "send": case "minimize": case "scrollDown": return { width: "24px", height: "24px" }; case "chatButton": return { width: "25px", height: "25px" }; default: return { width: "20px", height: "20px" }; } }; const iconDimensions = getIconDimensions(); return /* @__PURE__ */ u$1( "img", { src: iconState.customIcon, alt: `Custom ${type} icon`, className: `dynamic-icon custom ${className}`, style: __spreadValues({ display: "inline-block", verticalAlign: "middle", width: iconDimensions.width, height: iconDimensions.height, objectFit: "contain" }, style), onError: () => { setIconState((prev) => __spreadProps(__spreadValues({}, prev), { customIcon: null, error: "Failed to render custom icon" })); } } ); } const DefaultIconComponent = DefaultIcons[type]; return /* @__PURE__ */ u$1("div", { className: `dynamic-icon default ${className}`, style, children: /* @__PURE__ */ u$1(DefaultIconComponent, { className, fill }) }); }; class ChatButton extends x { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this); } handleClick(event) { event.preventDefault(); event.stopPropagation(); this.props.onClick(); } handleKeyDown(event) { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); this.props.onClick(); } } render() { var _a; const { isOpen, hasNewMessage, config } = this.props; if (isOpen) { return null; } const buttonStyles = {}; if (config.showChatButtonBackground !== false && config.chatButtonBackgroundColor) { buttonStyles["--chat-button-bg"] = config.chatButtonBackgroundColor; buttonStyles["--chat-butt