@pocketping/widget 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.
@@ -0,0 +1,1475 @@
1
+ "use strict";
2
+ var PocketPing = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ close: () => close,
25
+ default: () => index_default,
26
+ destroy: () => destroy,
27
+ init: () => init,
28
+ open: () => open,
29
+ sendMessage: () => sendMessage,
30
+ toggle: () => toggle
31
+ });
32
+
33
+ // ../../node_modules/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.mjs
34
+ var n;
35
+ var l;
36
+ var u;
37
+ var t;
38
+ var i;
39
+ var o;
40
+ var r;
41
+ var e;
42
+ var f;
43
+ var c;
44
+ var s;
45
+ var a;
46
+ var h;
47
+ var p = {};
48
+ var v = [];
49
+ var y = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
50
+ var d = Array.isArray;
51
+ function w(n2, l3) {
52
+ for (var u4 in l3) n2[u4] = l3[u4];
53
+ return n2;
54
+ }
55
+ function g(n2) {
56
+ n2 && n2.parentNode && n2.parentNode.removeChild(n2);
57
+ }
58
+ function _(l3, u4, t3) {
59
+ var i3, o3, r3, e3 = {};
60
+ for (r3 in u4) "key" == r3 ? i3 = u4[r3] : "ref" == r3 ? o3 = u4[r3] : e3[r3] = u4[r3];
61
+ if (arguments.length > 2 && (e3.children = arguments.length > 3 ? n.call(arguments, 2) : t3), "function" == typeof l3 && null != l3.defaultProps) for (r3 in l3.defaultProps) void 0 === e3[r3] && (e3[r3] = l3.defaultProps[r3]);
62
+ return m(l3, e3, i3, o3, null);
63
+ }
64
+ function m(n2, t3, i3, o3, r3) {
65
+ var e3 = { type: n2, props: t3, key: i3, ref: o3, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: null == r3 ? ++u : r3, __i: -1, __u: 0 };
66
+ return null == r3 && null != l.vnode && l.vnode(e3), e3;
67
+ }
68
+ function k(n2) {
69
+ return n2.children;
70
+ }
71
+ function x(n2, l3) {
72
+ this.props = n2, this.context = l3;
73
+ }
74
+ function S(n2, l3) {
75
+ if (null == l3) return n2.__ ? S(n2.__, n2.__i + 1) : null;
76
+ for (var u4; l3 < n2.__k.length; l3++) if (null != (u4 = n2.__k[l3]) && null != u4.__e) return u4.__e;
77
+ return "function" == typeof n2.type ? S(n2) : null;
78
+ }
79
+ function C(n2) {
80
+ var l3, u4;
81
+ if (null != (n2 = n2.__) && null != n2.__c) {
82
+ for (n2.__e = n2.__c.base = null, l3 = 0; l3 < n2.__k.length; l3++) if (null != (u4 = n2.__k[l3]) && null != u4.__e) {
83
+ n2.__e = n2.__c.base = u4.__e;
84
+ break;
85
+ }
86
+ return C(n2);
87
+ }
88
+ }
89
+ function M(n2) {
90
+ (!n2.__d && (n2.__d = true) && i.push(n2) && !$.__r++ || o != l.debounceRendering) && ((o = l.debounceRendering) || r)($);
91
+ }
92
+ function $() {
93
+ for (var n2, u4, t3, o3, r3, f4, c3, s3 = 1; i.length; ) i.length > s3 && i.sort(e), n2 = i.shift(), s3 = i.length, n2.__d && (t3 = void 0, o3 = void 0, r3 = (o3 = (u4 = n2).__v).__e, f4 = [], c3 = [], u4.__P && ((t3 = w({}, o3)).__v = o3.__v + 1, l.vnode && l.vnode(t3), O(u4.__P, t3, o3, u4.__n, u4.__P.namespaceURI, 32 & o3.__u ? [r3] : null, f4, null == r3 ? S(o3) : r3, !!(32 & o3.__u), c3), t3.__v = o3.__v, t3.__.__k[t3.__i] = t3, N(f4, t3, c3), o3.__e = o3.__ = null, t3.__e != r3 && C(t3)));
94
+ $.__r = 0;
95
+ }
96
+ function I(n2, l3, u4, t3, i3, o3, r3, e3, f4, c3, s3) {
97
+ var a3, h4, y3, d3, w3, g2, _2, m3 = t3 && t3.__k || v, b = l3.length;
98
+ for (f4 = P(u4, l3, m3, f4, b), a3 = 0; a3 < b; a3++) null != (y3 = u4.__k[a3]) && (h4 = -1 == y3.__i ? p : m3[y3.__i] || p, y3.__i = a3, g2 = O(n2, y3, h4, i3, o3, r3, e3, f4, c3, s3), d3 = y3.__e, y3.ref && h4.ref != y3.ref && (h4.ref && B(h4.ref, null, y3), s3.push(y3.ref, y3.__c || d3, y3)), null == w3 && null != d3 && (w3 = d3), (_2 = !!(4 & y3.__u)) || h4.__k === y3.__k ? f4 = A(y3, f4, n2, _2) : "function" == typeof y3.type && void 0 !== g2 ? f4 = g2 : d3 && (f4 = d3.nextSibling), y3.__u &= -7);
99
+ return u4.__e = w3, f4;
100
+ }
101
+ function P(n2, l3, u4, t3, i3) {
102
+ var o3, r3, e3, f4, c3, s3 = u4.length, a3 = s3, h4 = 0;
103
+ for (n2.__k = new Array(i3), o3 = 0; o3 < i3; o3++) null != (r3 = l3[o3]) && "boolean" != typeof r3 && "function" != typeof r3 ? ("string" == typeof r3 || "number" == typeof r3 || "bigint" == typeof r3 || r3.constructor == String ? r3 = n2.__k[o3] = m(null, r3, null, null, null) : d(r3) ? r3 = n2.__k[o3] = m(k, { children: r3 }, null, null, null) : void 0 === r3.constructor && r3.__b > 0 ? r3 = n2.__k[o3] = m(r3.type, r3.props, r3.key, r3.ref ? r3.ref : null, r3.__v) : n2.__k[o3] = r3, f4 = o3 + h4, r3.__ = n2, r3.__b = n2.__b + 1, e3 = null, -1 != (c3 = r3.__i = L(r3, u4, f4, a3)) && (a3--, (e3 = u4[c3]) && (e3.__u |= 2)), null == e3 || null == e3.__v ? (-1 == c3 && (i3 > s3 ? h4-- : i3 < s3 && h4++), "function" != typeof r3.type && (r3.__u |= 4)) : c3 != f4 && (c3 == f4 - 1 ? h4-- : c3 == f4 + 1 ? h4++ : (c3 > f4 ? h4-- : h4++, r3.__u |= 4))) : n2.__k[o3] = null;
104
+ if (a3) for (o3 = 0; o3 < s3; o3++) null != (e3 = u4[o3]) && 0 == (2 & e3.__u) && (e3.__e == t3 && (t3 = S(e3)), D(e3, e3));
105
+ return t3;
106
+ }
107
+ function A(n2, l3, u4, t3) {
108
+ var i3, o3;
109
+ if ("function" == typeof n2.type) {
110
+ for (i3 = n2.__k, o3 = 0; i3 && o3 < i3.length; o3++) i3[o3] && (i3[o3].__ = n2, l3 = A(i3[o3], l3, u4, t3));
111
+ return l3;
112
+ }
113
+ n2.__e != l3 && (t3 && (l3 && n2.type && !l3.parentNode && (l3 = S(n2)), u4.insertBefore(n2.__e, l3 || null)), l3 = n2.__e);
114
+ do {
115
+ l3 = l3 && l3.nextSibling;
116
+ } while (null != l3 && 8 == l3.nodeType);
117
+ return l3;
118
+ }
119
+ function L(n2, l3, u4, t3) {
120
+ var i3, o3, r3, e3 = n2.key, f4 = n2.type, c3 = l3[u4], s3 = null != c3 && 0 == (2 & c3.__u);
121
+ if (null === c3 && null == e3 || s3 && e3 == c3.key && f4 == c3.type) return u4;
122
+ if (t3 > (s3 ? 1 : 0)) {
123
+ for (i3 = u4 - 1, o3 = u4 + 1; i3 >= 0 || o3 < l3.length; ) if (null != (c3 = l3[r3 = i3 >= 0 ? i3-- : o3++]) && 0 == (2 & c3.__u) && e3 == c3.key && f4 == c3.type) return r3;
124
+ }
125
+ return -1;
126
+ }
127
+ function T(n2, l3, u4) {
128
+ "-" == l3[0] ? n2.setProperty(l3, null == u4 ? "" : u4) : n2[l3] = null == u4 ? "" : "number" != typeof u4 || y.test(l3) ? u4 : u4 + "px";
129
+ }
130
+ function j(n2, l3, u4, t3, i3) {
131
+ var o3, r3;
132
+ n: if ("style" == l3) if ("string" == typeof u4) n2.style.cssText = u4;
133
+ else {
134
+ if ("string" == typeof t3 && (n2.style.cssText = t3 = ""), t3) for (l3 in t3) u4 && l3 in u4 || T(n2.style, l3, "");
135
+ if (u4) for (l3 in u4) t3 && u4[l3] == t3[l3] || T(n2.style, l3, u4[l3]);
136
+ }
137
+ else if ("o" == l3[0] && "n" == l3[1]) o3 = l3 != (l3 = l3.replace(f, "$1")), r3 = l3.toLowerCase(), l3 = r3 in n2 || "onFocusOut" == l3 || "onFocusIn" == l3 ? r3.slice(2) : l3.slice(2), n2.l || (n2.l = {}), n2.l[l3 + o3] = u4, u4 ? t3 ? u4.u = t3.u : (u4.u = c, n2.addEventListener(l3, o3 ? a : s, o3)) : n2.removeEventListener(l3, o3 ? a : s, o3);
138
+ else {
139
+ if ("http://www.w3.org/2000/svg" == i3) l3 = l3.replace(/xlink(H|:h)/, "h").replace(/sName$/, "s");
140
+ else if ("width" != l3 && "height" != l3 && "href" != l3 && "list" != l3 && "form" != l3 && "tabIndex" != l3 && "download" != l3 && "rowSpan" != l3 && "colSpan" != l3 && "role" != l3 && "popover" != l3 && l3 in n2) try {
141
+ n2[l3] = null == u4 ? "" : u4;
142
+ break n;
143
+ } catch (n3) {
144
+ }
145
+ "function" == typeof u4 || (null == u4 || false === u4 && "-" != l3[4] ? n2.removeAttribute(l3) : n2.setAttribute(l3, "popover" == l3 && 1 == u4 ? "" : u4));
146
+ }
147
+ }
148
+ function F(n2) {
149
+ return function(u4) {
150
+ if (this.l) {
151
+ var t3 = this.l[u4.type + n2];
152
+ if (null == u4.t) u4.t = c++;
153
+ else if (u4.t < t3.u) return;
154
+ return t3(l.event ? l.event(u4) : u4);
155
+ }
156
+ };
157
+ }
158
+ function O(n2, u4, t3, i3, o3, r3, e3, f4, c3, s3) {
159
+ var a3, h4, p3, v3, y3, _2, m3, b, S2, C3, M2, $2, P2, A3, H, L2, T3, j3 = u4.type;
160
+ if (void 0 !== u4.constructor) return null;
161
+ 128 & t3.__u && (c3 = !!(32 & t3.__u), r3 = [f4 = u4.__e = t3.__e]), (a3 = l.__b) && a3(u4);
162
+ n: if ("function" == typeof j3) try {
163
+ if (b = u4.props, S2 = "prototype" in j3 && j3.prototype.render, C3 = (a3 = j3.contextType) && i3[a3.__c], M2 = a3 ? C3 ? C3.props.value : a3.__ : i3, t3.__c ? m3 = (h4 = u4.__c = t3.__c).__ = h4.__E : (S2 ? u4.__c = h4 = new j3(b, M2) : (u4.__c = h4 = new x(b, M2), h4.constructor = j3, h4.render = E), C3 && C3.sub(h4), h4.state || (h4.state = {}), h4.__n = i3, p3 = h4.__d = true, h4.__h = [], h4._sb = []), S2 && null == h4.__s && (h4.__s = h4.state), S2 && null != j3.getDerivedStateFromProps && (h4.__s == h4.state && (h4.__s = w({}, h4.__s)), w(h4.__s, j3.getDerivedStateFromProps(b, h4.__s))), v3 = h4.props, y3 = h4.state, h4.__v = u4, p3) S2 && null == j3.getDerivedStateFromProps && null != h4.componentWillMount && h4.componentWillMount(), S2 && null != h4.componentDidMount && h4.__h.push(h4.componentDidMount);
164
+ else {
165
+ if (S2 && null == j3.getDerivedStateFromProps && b !== v3 && null != h4.componentWillReceiveProps && h4.componentWillReceiveProps(b, M2), u4.__v == t3.__v || !h4.__e && null != h4.shouldComponentUpdate && false === h4.shouldComponentUpdate(b, h4.__s, M2)) {
166
+ for (u4.__v != t3.__v && (h4.props = b, h4.state = h4.__s, h4.__d = false), u4.__e = t3.__e, u4.__k = t3.__k, u4.__k.some(function(n3) {
167
+ n3 && (n3.__ = u4);
168
+ }), $2 = 0; $2 < h4._sb.length; $2++) h4.__h.push(h4._sb[$2]);
169
+ h4._sb = [], h4.__h.length && e3.push(h4);
170
+ break n;
171
+ }
172
+ null != h4.componentWillUpdate && h4.componentWillUpdate(b, h4.__s, M2), S2 && null != h4.componentDidUpdate && h4.__h.push(function() {
173
+ h4.componentDidUpdate(v3, y3, _2);
174
+ });
175
+ }
176
+ if (h4.context = M2, h4.props = b, h4.__P = n2, h4.__e = false, P2 = l.__r, A3 = 0, S2) {
177
+ for (h4.state = h4.__s, h4.__d = false, P2 && P2(u4), a3 = h4.render(h4.props, h4.state, h4.context), H = 0; H < h4._sb.length; H++) h4.__h.push(h4._sb[H]);
178
+ h4._sb = [];
179
+ } else do {
180
+ h4.__d = false, P2 && P2(u4), a3 = h4.render(h4.props, h4.state, h4.context), h4.state = h4.__s;
181
+ } while (h4.__d && ++A3 < 25);
182
+ h4.state = h4.__s, null != h4.getChildContext && (i3 = w(w({}, i3), h4.getChildContext())), S2 && !p3 && null != h4.getSnapshotBeforeUpdate && (_2 = h4.getSnapshotBeforeUpdate(v3, y3)), L2 = a3, null != a3 && a3.type === k && null == a3.key && (L2 = V(a3.props.children)), f4 = I(n2, d(L2) ? L2 : [L2], u4, t3, i3, o3, r3, e3, f4, c3, s3), h4.base = u4.__e, u4.__u &= -161, h4.__h.length && e3.push(h4), m3 && (h4.__E = h4.__ = null);
183
+ } catch (n3) {
184
+ if (u4.__v = null, c3 || null != r3) if (n3.then) {
185
+ for (u4.__u |= c3 ? 160 : 128; f4 && 8 == f4.nodeType && f4.nextSibling; ) f4 = f4.nextSibling;
186
+ r3[r3.indexOf(f4)] = null, u4.__e = f4;
187
+ } else {
188
+ for (T3 = r3.length; T3--; ) g(r3[T3]);
189
+ z(u4);
190
+ }
191
+ else u4.__e = t3.__e, u4.__k = t3.__k, n3.then || z(u4);
192
+ l.__e(n3, u4, t3);
193
+ }
194
+ else null == r3 && u4.__v == t3.__v ? (u4.__k = t3.__k, u4.__e = t3.__e) : f4 = u4.__e = q(t3.__e, u4, t3, i3, o3, r3, e3, c3, s3);
195
+ return (a3 = l.diffed) && a3(u4), 128 & u4.__u ? void 0 : f4;
196
+ }
197
+ function z(n2) {
198
+ n2 && n2.__c && (n2.__c.__e = true), n2 && n2.__k && n2.__k.forEach(z);
199
+ }
200
+ function N(n2, u4, t3) {
201
+ for (var i3 = 0; i3 < t3.length; i3++) B(t3[i3], t3[++i3], t3[++i3]);
202
+ l.__c && l.__c(u4, n2), n2.some(function(u5) {
203
+ try {
204
+ n2 = u5.__h, u5.__h = [], n2.some(function(n3) {
205
+ n3.call(u5);
206
+ });
207
+ } catch (n3) {
208
+ l.__e(n3, u5.__v);
209
+ }
210
+ });
211
+ }
212
+ function V(n2) {
213
+ return "object" != typeof n2 || null == n2 || n2.__b && n2.__b > 0 ? n2 : d(n2) ? n2.map(V) : w({}, n2);
214
+ }
215
+ function q(u4, t3, i3, o3, r3, e3, f4, c3, s3) {
216
+ var a3, h4, v3, y3, w3, _2, m3, b = i3.props || p, k3 = t3.props, x2 = t3.type;
217
+ if ("svg" == x2 ? r3 = "http://www.w3.org/2000/svg" : "math" == x2 ? r3 = "http://www.w3.org/1998/Math/MathML" : r3 || (r3 = "http://www.w3.org/1999/xhtml"), null != e3) {
218
+ for (a3 = 0; a3 < e3.length; a3++) if ((w3 = e3[a3]) && "setAttribute" in w3 == !!x2 && (x2 ? w3.localName == x2 : 3 == w3.nodeType)) {
219
+ u4 = w3, e3[a3] = null;
220
+ break;
221
+ }
222
+ }
223
+ if (null == u4) {
224
+ if (null == x2) return document.createTextNode(k3);
225
+ u4 = document.createElementNS(r3, x2, k3.is && k3), c3 && (l.__m && l.__m(t3, e3), c3 = false), e3 = null;
226
+ }
227
+ if (null == x2) b === k3 || c3 && u4.data == k3 || (u4.data = k3);
228
+ else {
229
+ if (e3 = e3 && n.call(u4.childNodes), !c3 && null != e3) for (b = {}, a3 = 0; a3 < u4.attributes.length; a3++) b[(w3 = u4.attributes[a3]).name] = w3.value;
230
+ for (a3 in b) if (w3 = b[a3], "children" == a3) ;
231
+ else if ("dangerouslySetInnerHTML" == a3) v3 = w3;
232
+ else if (!(a3 in k3)) {
233
+ if ("value" == a3 && "defaultValue" in k3 || "checked" == a3 && "defaultChecked" in k3) continue;
234
+ j(u4, a3, null, w3, r3);
235
+ }
236
+ for (a3 in k3) w3 = k3[a3], "children" == a3 ? y3 = w3 : "dangerouslySetInnerHTML" == a3 ? h4 = w3 : "value" == a3 ? _2 = w3 : "checked" == a3 ? m3 = w3 : c3 && "function" != typeof w3 || b[a3] === w3 || j(u4, a3, w3, b[a3], r3);
237
+ if (h4) c3 || v3 && (h4.__html == v3.__html || h4.__html == u4.innerHTML) || (u4.innerHTML = h4.__html), t3.__k = [];
238
+ else if (v3 && (u4.innerHTML = ""), I("template" == t3.type ? u4.content : u4, d(y3) ? y3 : [y3], t3, i3, o3, "foreignObject" == x2 ? "http://www.w3.org/1999/xhtml" : r3, e3, f4, e3 ? e3[0] : i3.__k && S(i3, 0), c3, s3), null != e3) for (a3 = e3.length; a3--; ) g(e3[a3]);
239
+ c3 || (a3 = "value", "progress" == x2 && null == _2 ? u4.removeAttribute("value") : null != _2 && (_2 !== u4[a3] || "progress" == x2 && !_2 || "option" == x2 && _2 != b[a3]) && j(u4, a3, _2, b[a3], r3), a3 = "checked", null != m3 && m3 != u4[a3] && j(u4, a3, m3, b[a3], r3));
240
+ }
241
+ return u4;
242
+ }
243
+ function B(n2, u4, t3) {
244
+ try {
245
+ if ("function" == typeof n2) {
246
+ var i3 = "function" == typeof n2.__u;
247
+ i3 && n2.__u(), i3 && null == u4 || (n2.__u = n2(u4));
248
+ } else n2.current = u4;
249
+ } catch (n3) {
250
+ l.__e(n3, t3);
251
+ }
252
+ }
253
+ function D(n2, u4, t3) {
254
+ var i3, o3;
255
+ if (l.unmount && l.unmount(n2), (i3 = n2.ref) && (i3.current && i3.current != n2.__e || B(i3, null, u4)), null != (i3 = n2.__c)) {
256
+ if (i3.componentWillUnmount) try {
257
+ i3.componentWillUnmount();
258
+ } catch (n3) {
259
+ l.__e(n3, u4);
260
+ }
261
+ i3.base = i3.__P = null;
262
+ }
263
+ if (i3 = n2.__k) for (o3 = 0; o3 < i3.length; o3++) i3[o3] && D(i3[o3], u4, t3 || "function" != typeof n2.type);
264
+ t3 || g(n2.__e), n2.__c = n2.__ = n2.__e = void 0;
265
+ }
266
+ function E(n2, l3, u4) {
267
+ return this.constructor(n2, u4);
268
+ }
269
+ function G(u4, t3, i3) {
270
+ var o3, r3, e3, f4;
271
+ t3 == document && (t3 = document.documentElement), l.__ && l.__(u4, t3), r3 = (o3 = "function" == typeof i3) ? null : i3 && i3.__k || t3.__k, e3 = [], f4 = [], O(t3, u4 = (!o3 && i3 || t3).__k = _(k, null, [u4]), r3 || p, p, t3.namespaceURI, !o3 && i3 ? [i3] : r3 ? null : t3.firstChild ? n.call(t3.childNodes) : null, e3, !o3 && i3 ? i3 : r3 ? r3.__e : t3.firstChild, o3, f4), N(e3, u4, f4);
272
+ }
273
+ n = v.slice, l = { __e: function(n2, l3, u4, t3) {
274
+ for (var i3, o3, r3; l3 = l3.__; ) if ((i3 = l3.__c) && !i3.__) try {
275
+ if ((o3 = i3.constructor) && null != o3.getDerivedStateFromError && (i3.setState(o3.getDerivedStateFromError(n2)), r3 = i3.__d), null != i3.componentDidCatch && (i3.componentDidCatch(n2, t3 || {}), r3 = i3.__d), r3) return i3.__E = i3;
276
+ } catch (l4) {
277
+ n2 = l4;
278
+ }
279
+ throw n2;
280
+ } }, u = 0, t = function(n2) {
281
+ return null != n2 && void 0 === n2.constructor;
282
+ }, x.prototype.setState = function(n2, l3) {
283
+ var u4;
284
+ u4 = null != this.__s && this.__s != this.state ? this.__s : this.__s = w({}, this.state), "function" == typeof n2 && (n2 = n2(w({}, u4), this.props)), n2 && w(u4, n2), null != n2 && this.__v && (l3 && this._sb.push(l3), M(this));
285
+ }, x.prototype.forceUpdate = function(n2) {
286
+ this.__v && (this.__e = true, n2 && this.__h.push(n2), M(this));
287
+ }, x.prototype.render = k, i = [], r = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, e = function(n2, l3) {
288
+ return n2.__v.__b - l3.__v.__b;
289
+ }, $.__r = 0, f = /(PointerCapture)$|Capture$/i, c = 0, s = F(false), a = F(true), h = 0;
290
+
291
+ // ../../node_modules/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.mjs
292
+ var t2;
293
+ var r2;
294
+ var u2;
295
+ var i2;
296
+ var o2 = 0;
297
+ var f2 = [];
298
+ var c2 = l;
299
+ var e2 = c2.__b;
300
+ var a2 = c2.__r;
301
+ var v2 = c2.diffed;
302
+ var l2 = c2.__c;
303
+ var m2 = c2.unmount;
304
+ var s2 = c2.__;
305
+ function p2(n2, t3) {
306
+ c2.__h && c2.__h(r2, n2, o2 || t3), o2 = 0;
307
+ var u4 = r2.__H || (r2.__H = { __: [], __h: [] });
308
+ return n2 >= u4.__.length && u4.__.push({}), u4.__[n2];
309
+ }
310
+ function d2(n2) {
311
+ return o2 = 1, h2(D2, n2);
312
+ }
313
+ function h2(n2, u4, i3) {
314
+ var o3 = p2(t2++, 2);
315
+ if (o3.t = n2, !o3.__c && (o3.__ = [i3 ? i3(u4) : D2(void 0, u4), function(n3) {
316
+ var t3 = o3.__N ? o3.__N[0] : o3.__[0], r3 = o3.t(t3, n3);
317
+ t3 !== r3 && (o3.__N = [r3, o3.__[1]], o3.__c.setState({}));
318
+ }], o3.__c = r2, !r2.__f)) {
319
+ var f4 = function(n3, t3, r3) {
320
+ if (!o3.__c.__H) return true;
321
+ var u5 = o3.__c.__H.__.filter(function(n4) {
322
+ return !!n4.__c;
323
+ });
324
+ if (u5.every(function(n4) {
325
+ return !n4.__N;
326
+ })) return !c3 || c3.call(this, n3, t3, r3);
327
+ var i4 = o3.__c.props !== n3;
328
+ return u5.forEach(function(n4) {
329
+ if (n4.__N) {
330
+ var t4 = n4.__[0];
331
+ n4.__ = n4.__N, n4.__N = void 0, t4 !== n4.__[0] && (i4 = true);
332
+ }
333
+ }), c3 && c3.call(this, n3, t3, r3) || i4;
334
+ };
335
+ r2.__f = true;
336
+ var c3 = r2.shouldComponentUpdate, e3 = r2.componentWillUpdate;
337
+ r2.componentWillUpdate = function(n3, t3, r3) {
338
+ if (this.__e) {
339
+ var u5 = c3;
340
+ c3 = void 0, f4(n3, t3, r3), c3 = u5;
341
+ }
342
+ e3 && e3.call(this, n3, t3, r3);
343
+ }, r2.shouldComponentUpdate = f4;
344
+ }
345
+ return o3.__N || o3.__;
346
+ }
347
+ function y2(n2, u4) {
348
+ var i3 = p2(t2++, 3);
349
+ !c2.__s && C2(i3.__H, u4) && (i3.__ = n2, i3.u = u4, r2.__H.__h.push(i3));
350
+ }
351
+ function A2(n2) {
352
+ return o2 = 5, T2(function() {
353
+ return { current: n2 };
354
+ }, []);
355
+ }
356
+ function T2(n2, r3) {
357
+ var u4 = p2(t2++, 7);
358
+ return C2(u4.__H, r3) && (u4.__ = n2(), u4.__H = r3, u4.__h = n2), u4.__;
359
+ }
360
+ function q2(n2, t3) {
361
+ return o2 = 8, T2(function() {
362
+ return n2;
363
+ }, t3);
364
+ }
365
+ function j2() {
366
+ for (var n2; n2 = f2.shift(); ) if (n2.__P && n2.__H) try {
367
+ n2.__H.__h.forEach(z2), n2.__H.__h.forEach(B2), n2.__H.__h = [];
368
+ } catch (t3) {
369
+ n2.__H.__h = [], c2.__e(t3, n2.__v);
370
+ }
371
+ }
372
+ c2.__b = function(n2) {
373
+ r2 = null, e2 && e2(n2);
374
+ }, c2.__ = function(n2, t3) {
375
+ n2 && t3.__k && t3.__k.__m && (n2.__m = t3.__k.__m), s2 && s2(n2, t3);
376
+ }, c2.__r = function(n2) {
377
+ a2 && a2(n2), t2 = 0;
378
+ var i3 = (r2 = n2.__c).__H;
379
+ i3 && (u2 === r2 ? (i3.__h = [], r2.__h = [], i3.__.forEach(function(n3) {
380
+ n3.__N && (n3.__ = n3.__N), n3.u = n3.__N = void 0;
381
+ })) : (i3.__h.forEach(z2), i3.__h.forEach(B2), i3.__h = [], t2 = 0)), u2 = r2;
382
+ }, c2.diffed = function(n2) {
383
+ v2 && v2(n2);
384
+ var t3 = n2.__c;
385
+ t3 && t3.__H && (t3.__H.__h.length && (1 !== f2.push(t3) && i2 === c2.requestAnimationFrame || ((i2 = c2.requestAnimationFrame) || w2)(j2)), t3.__H.__.forEach(function(n3) {
386
+ n3.u && (n3.__H = n3.u), n3.u = void 0;
387
+ })), u2 = r2 = null;
388
+ }, c2.__c = function(n2, t3) {
389
+ t3.some(function(n3) {
390
+ try {
391
+ n3.__h.forEach(z2), n3.__h = n3.__h.filter(function(n4) {
392
+ return !n4.__ || B2(n4);
393
+ });
394
+ } catch (r3) {
395
+ t3.some(function(n4) {
396
+ n4.__h && (n4.__h = []);
397
+ }), t3 = [], c2.__e(r3, n3.__v);
398
+ }
399
+ }), l2 && l2(n2, t3);
400
+ }, c2.unmount = function(n2) {
401
+ m2 && m2(n2);
402
+ var t3, r3 = n2.__c;
403
+ r3 && r3.__H && (r3.__H.__.forEach(function(n3) {
404
+ try {
405
+ z2(n3);
406
+ } catch (n4) {
407
+ t3 = n4;
408
+ }
409
+ }), r3.__H = void 0, t3 && c2.__e(t3, r3.__v));
410
+ };
411
+ var k2 = "function" == typeof requestAnimationFrame;
412
+ function w2(n2) {
413
+ var t3, r3 = function() {
414
+ clearTimeout(u4), k2 && cancelAnimationFrame(t3), setTimeout(n2);
415
+ }, u4 = setTimeout(r3, 35);
416
+ k2 && (t3 = requestAnimationFrame(r3));
417
+ }
418
+ function z2(n2) {
419
+ var t3 = r2, u4 = n2.__c;
420
+ "function" == typeof u4 && (n2.__c = void 0, u4()), r2 = t3;
421
+ }
422
+ function B2(n2) {
423
+ var t3 = r2;
424
+ n2.__c = n2.__(), r2 = t3;
425
+ }
426
+ function C2(n2, t3) {
427
+ return !n2 || n2.length !== t3.length || t3.some(function(t4, r3) {
428
+ return t4 !== n2[r3];
429
+ });
430
+ }
431
+ function D2(n2, t3) {
432
+ return "function" == typeof t3 ? t3(n2) : t3;
433
+ }
434
+
435
+ // src/components/styles.ts
436
+ function styles(primaryColor, theme) {
437
+ const isDark = theme === "dark";
438
+ const colors = {
439
+ bg: isDark ? "#1f2937" : "#ffffff",
440
+ bgSecondary: isDark ? "#374151" : "#f3f4f6",
441
+ text: isDark ? "#f9fafb" : "#111827",
442
+ textSecondary: isDark ? "#9ca3af" : "#6b7280",
443
+ border: isDark ? "#4b5563" : "#e5e7eb",
444
+ messageBg: isDark ? "#374151" : "#f3f4f6"
445
+ };
446
+ return `
447
+ #pocketping-container {
448
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
449
+ font-size: 14px;
450
+ line-height: 1.5;
451
+ color: ${colors.text};
452
+ }
453
+
454
+ .pp-toggle {
455
+ position: fixed;
456
+ width: 56px;
457
+ height: 56px;
458
+ border-radius: 50%;
459
+ background: ${primaryColor};
460
+ color: white;
461
+ border: none;
462
+ cursor: pointer;
463
+ display: flex;
464
+ align-items: center;
465
+ justify-content: center;
466
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
467
+ transition: transform 0.2s, box-shadow 0.2s;
468
+ z-index: 9999;
469
+ }
470
+
471
+ .pp-toggle:hover {
472
+ transform: scale(1.05);
473
+ box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
474
+ }
475
+
476
+ .pp-toggle svg {
477
+ width: 24px;
478
+ height: 24px;
479
+ }
480
+
481
+ .pp-toggle.pp-bottom-right {
482
+ bottom: 20px;
483
+ right: 20px;
484
+ }
485
+
486
+ .pp-toggle.pp-bottom-left {
487
+ bottom: 20px;
488
+ left: 20px;
489
+ }
490
+
491
+ .pp-online-dot {
492
+ position: absolute;
493
+ top: 4px;
494
+ right: 4px;
495
+ width: 12px;
496
+ height: 12px;
497
+ background: #22c55e;
498
+ border-radius: 50%;
499
+ border: 2px solid white;
500
+ }
501
+
502
+ .pp-window {
503
+ position: fixed;
504
+ width: 380px;
505
+ height: 520px;
506
+ max-height: calc(100vh - 100px);
507
+ background: ${colors.bg};
508
+ border-radius: 16px;
509
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
510
+ display: flex;
511
+ flex-direction: column;
512
+ overflow: hidden;
513
+ z-index: 9998;
514
+ }
515
+
516
+ .pp-window.pp-bottom-right {
517
+ bottom: 88px;
518
+ right: 20px;
519
+ }
520
+
521
+ .pp-window.pp-bottom-left {
522
+ bottom: 88px;
523
+ left: 20px;
524
+ }
525
+
526
+ @media (max-width: 480px) {
527
+ .pp-window {
528
+ width: calc(100vw - 20px);
529
+ height: calc(100vh - 100px);
530
+ bottom: 80px;
531
+ right: 10px;
532
+ left: 10px;
533
+ border-radius: 12px;
534
+ }
535
+ }
536
+
537
+ .pp-header {
538
+ display: flex;
539
+ align-items: center;
540
+ justify-content: space-between;
541
+ padding: 16px;
542
+ background: ${primaryColor};
543
+ color: white;
544
+ }
545
+
546
+ .pp-header-info {
547
+ display: flex;
548
+ align-items: center;
549
+ gap: 12px;
550
+ }
551
+
552
+ .pp-avatar {
553
+ width: 40px;
554
+ height: 40px;
555
+ border-radius: 50%;
556
+ object-fit: cover;
557
+ }
558
+
559
+ .pp-header-title {
560
+ font-weight: 600;
561
+ font-size: 16px;
562
+ }
563
+
564
+ .pp-header-status {
565
+ font-size: 12px;
566
+ opacity: 0.9;
567
+ display: flex;
568
+ align-items: center;
569
+ gap: 4px;
570
+ }
571
+
572
+ .pp-status-dot {
573
+ width: 8px;
574
+ height: 8px;
575
+ border-radius: 50%;
576
+ background: rgba(255, 255, 255, 0.5);
577
+ }
578
+
579
+ .pp-status-dot.pp-online {
580
+ background: #22c55e;
581
+ }
582
+
583
+ .pp-close-btn {
584
+ background: transparent;
585
+ border: none;
586
+ color: white;
587
+ cursor: pointer;
588
+ padding: 4px;
589
+ border-radius: 4px;
590
+ opacity: 0.8;
591
+ transition: opacity 0.2s;
592
+ }
593
+
594
+ .pp-close-btn:hover {
595
+ opacity: 1;
596
+ }
597
+
598
+ .pp-close-btn svg {
599
+ width: 20px;
600
+ height: 20px;
601
+ }
602
+
603
+ .pp-messages {
604
+ flex: 1;
605
+ overflow-y: auto;
606
+ padding: 16px;
607
+ display: flex;
608
+ flex-direction: column;
609
+ gap: 12px;
610
+ }
611
+
612
+ .pp-welcome {
613
+ text-align: center;
614
+ color: ${colors.textSecondary};
615
+ padding: 24px;
616
+ font-size: 13px;
617
+ }
618
+
619
+ .pp-message {
620
+ max-width: 80%;
621
+ padding: 10px 14px;
622
+ border-radius: 16px;
623
+ word-wrap: break-word;
624
+ }
625
+
626
+ .pp-message-visitor {
627
+ align-self: flex-end;
628
+ background: ${primaryColor};
629
+ color: white;
630
+ border-bottom-right-radius: 4px;
631
+ }
632
+
633
+ .pp-message-operator,
634
+ .pp-message-ai {
635
+ align-self: flex-start;
636
+ background: ${colors.messageBg};
637
+ color: ${colors.text};
638
+ border-bottom-left-radius: 4px;
639
+ }
640
+
641
+ .pp-message-content {
642
+ margin-bottom: 4px;
643
+ }
644
+
645
+ .pp-message-time {
646
+ font-size: 11px;
647
+ opacity: 0.7;
648
+ display: flex;
649
+ align-items: center;
650
+ gap: 4px;
651
+ }
652
+
653
+ .pp-ai-badge {
654
+ background: rgba(0, 0, 0, 0.1);
655
+ padding: 1px 4px;
656
+ border-radius: 4px;
657
+ font-size: 10px;
658
+ font-weight: 600;
659
+ }
660
+
661
+ .pp-status {
662
+ display: inline-flex;
663
+ align-items: center;
664
+ margin-left: 4px;
665
+ }
666
+
667
+ .pp-status svg {
668
+ width: 14px;
669
+ height: 14px;
670
+ }
671
+
672
+ .pp-check,
673
+ .pp-check-double {
674
+ stroke: rgba(255, 255, 255, 0.7);
675
+ }
676
+
677
+ .pp-check-read {
678
+ stroke: #34b7f1;
679
+ }
680
+
681
+ .pp-status-sending .pp-check {
682
+ opacity: 0.5;
683
+ }
684
+
685
+ .pp-typing {
686
+ display: flex;
687
+ gap: 4px;
688
+ padding: 14px 18px;
689
+ }
690
+
691
+ .pp-typing span {
692
+ width: 8px;
693
+ height: 8px;
694
+ background: ${colors.textSecondary};
695
+ border-radius: 50%;
696
+ animation: pp-bounce 1.4s infinite ease-in-out both;
697
+ }
698
+
699
+ .pp-typing span:nth-child(1) { animation-delay: -0.32s; }
700
+ .pp-typing span:nth-child(2) { animation-delay: -0.16s; }
701
+
702
+ @keyframes pp-bounce {
703
+ 0%, 80%, 100% { transform: scale(0); }
704
+ 40% { transform: scale(1); }
705
+ }
706
+
707
+ .pp-input-form {
708
+ display: flex;
709
+ padding: 12px;
710
+ gap: 8px;
711
+ border-top: 1px solid ${colors.border};
712
+ }
713
+
714
+ .pp-input {
715
+ flex: 1;
716
+ padding: 10px 14px;
717
+ border: 1px solid ${colors.border};
718
+ border-radius: 20px;
719
+ background: ${colors.bg};
720
+ color: ${colors.text};
721
+ font-size: 14px;
722
+ outline: none;
723
+ transition: border-color 0.2s;
724
+ }
725
+
726
+ .pp-input:focus {
727
+ border-color: ${primaryColor};
728
+ }
729
+
730
+ .pp-input::placeholder {
731
+ color: ${colors.textSecondary};
732
+ }
733
+
734
+ .pp-send-btn {
735
+ width: 40px;
736
+ height: 40px;
737
+ border-radius: 50%;
738
+ background: ${primaryColor};
739
+ color: white;
740
+ border: none;
741
+ cursor: pointer;
742
+ display: flex;
743
+ align-items: center;
744
+ justify-content: center;
745
+ transition: opacity 0.2s;
746
+ }
747
+
748
+ .pp-send-btn:disabled {
749
+ opacity: 0.5;
750
+ cursor: not-allowed;
751
+ }
752
+
753
+ .pp-send-btn svg {
754
+ width: 18px;
755
+ height: 18px;
756
+ }
757
+
758
+ .pp-footer {
759
+ text-align: center;
760
+ padding: 8px;
761
+ font-size: 11px;
762
+ color: ${colors.textSecondary};
763
+ border-top: 1px solid ${colors.border};
764
+ }
765
+
766
+ .pp-footer a {
767
+ color: ${primaryColor};
768
+ text-decoration: none;
769
+ }
770
+
771
+ .pp-footer a:hover {
772
+ text-decoration: underline;
773
+ }
774
+ `;
775
+ }
776
+
777
+ // ../../node_modules/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs
778
+ var f3 = 0;
779
+ function u3(e3, t3, n2, o3, i3, u4) {
780
+ t3 || (t3 = {});
781
+ var a3, c3, p3 = t3;
782
+ if ("ref" in p3) for (c3 in p3 = {}, t3) "ref" == c3 ? a3 = t3[c3] : p3[c3] = t3[c3];
783
+ var l3 = { type: e3, props: p3, key: n2, ref: a3, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --f3, __i: -1, __u: 0, __source: i3, __self: u4 };
784
+ if ("function" == typeof e3 && (a3 = e3.defaultProps)) for (c3 in a3) void 0 === p3[c3] && (p3[c3] = a3[c3]);
785
+ return l.vnode && l.vnode(l3), l3;
786
+ }
787
+
788
+ // src/components/ChatWidget.tsx
789
+ function ChatWidget({ client: client2, config }) {
790
+ const [isOpen, setIsOpen] = d2(false);
791
+ const [messages, setMessages] = d2([]);
792
+ const [inputValue, setInputValue] = d2("");
793
+ const [isTyping, setIsTyping] = d2(false);
794
+ const [operatorOnline, setOperatorOnline] = d2(false);
795
+ const [isConnected, setIsConnected] = d2(false);
796
+ const messagesEndRef = A2(null);
797
+ const inputRef = A2(null);
798
+ y2(() => {
799
+ const unsubOpen = client2.on("openChange", setIsOpen);
800
+ const unsubMessage = client2.on("message", () => {
801
+ setMessages([...client2.getMessages()]);
802
+ });
803
+ const unsubTyping = client2.on("typing", (data) => {
804
+ setIsTyping(data.isTyping);
805
+ });
806
+ const unsubPresence = client2.on("presence", (data) => {
807
+ setOperatorOnline(data.online);
808
+ });
809
+ const unsubConnect = client2.on("connect", () => {
810
+ setIsConnected(true);
811
+ setMessages(client2.getMessages());
812
+ setOperatorOnline(client2.getSession()?.operatorOnline ?? false);
813
+ });
814
+ if (client2.isConnected()) {
815
+ setIsConnected(true);
816
+ setMessages(client2.getMessages());
817
+ setOperatorOnline(client2.getSession()?.operatorOnline ?? false);
818
+ }
819
+ return () => {
820
+ unsubOpen();
821
+ unsubMessage();
822
+ unsubTyping();
823
+ unsubPresence();
824
+ unsubConnect();
825
+ };
826
+ }, [client2]);
827
+ y2(() => {
828
+ messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
829
+ }, [messages]);
830
+ y2(() => {
831
+ if (isOpen) {
832
+ inputRef.current?.focus();
833
+ }
834
+ }, [isOpen]);
835
+ const markMessagesAsRead = q2(() => {
836
+ if (!isOpen || !isConnected) return;
837
+ const unreadMessages = messages.filter(
838
+ (msg) => msg.sender !== "visitor" && msg.status !== "read"
839
+ );
840
+ if (unreadMessages.length > 0) {
841
+ const messageIds = unreadMessages.map((msg) => msg.id);
842
+ client2.sendReadStatus(messageIds, "read");
843
+ }
844
+ }, [isOpen, isConnected, messages, client2]);
845
+ y2(() => {
846
+ if (!isOpen || !isConnected) return;
847
+ const timer = setTimeout(() => {
848
+ markMessagesAsRead();
849
+ }, 1e3);
850
+ return () => clearTimeout(timer);
851
+ }, [isOpen, isConnected, messages, markMessagesAsRead]);
852
+ y2(() => {
853
+ const handleVisibilityChange = () => {
854
+ if (document.visibilityState === "visible" && isOpen) {
855
+ markMessagesAsRead();
856
+ }
857
+ };
858
+ document.addEventListener("visibilitychange", handleVisibilityChange);
859
+ return () => document.removeEventListener("visibilitychange", handleVisibilityChange);
860
+ }, [isOpen, markMessagesAsRead]);
861
+ y2(() => {
862
+ const unsubRead = client2.on(
863
+ "read",
864
+ () => {
865
+ setMessages([...client2.getMessages()]);
866
+ }
867
+ );
868
+ return () => unsubRead();
869
+ }, [client2]);
870
+ const shouldShow = checkPageVisibility(config);
871
+ if (!shouldShow) return null;
872
+ const handleSubmit = async (e3) => {
873
+ e3.preventDefault();
874
+ if (!inputValue.trim()) return;
875
+ const content = inputValue;
876
+ setInputValue("");
877
+ try {
878
+ await client2.sendMessage(content);
879
+ } catch (err) {
880
+ console.error("[PocketPing] Failed to send message:", err);
881
+ }
882
+ };
883
+ const handleInputChange = (e3) => {
884
+ const target = e3.target;
885
+ setInputValue(target.value);
886
+ client2.sendTyping(true);
887
+ };
888
+ const position = config.position ?? "bottom-right";
889
+ const theme = getTheme(config.theme ?? "auto");
890
+ const primaryColor = config.primaryColor ?? "#6366f1";
891
+ return /* @__PURE__ */ u3(k, { children: [
892
+ /* @__PURE__ */ u3("style", { children: styles(primaryColor, theme) }),
893
+ /* @__PURE__ */ u3(
894
+ "button",
895
+ {
896
+ class: `pp-toggle pp-${position}`,
897
+ onClick: () => client2.toggleOpen(),
898
+ "aria-label": isOpen ? "Close chat" : "Open chat",
899
+ children: [
900
+ isOpen ? /* @__PURE__ */ u3(CloseIcon, {}) : /* @__PURE__ */ u3(ChatIcon, {}),
901
+ !isOpen && operatorOnline && /* @__PURE__ */ u3("span", { class: "pp-online-dot" })
902
+ ]
903
+ }
904
+ ),
905
+ isOpen && /* @__PURE__ */ u3("div", { class: `pp-window pp-${position} pp-theme-${theme}`, children: [
906
+ /* @__PURE__ */ u3("div", { class: "pp-header", children: [
907
+ /* @__PURE__ */ u3("div", { class: "pp-header-info", children: [
908
+ config.operatorAvatar && /* @__PURE__ */ u3("img", { src: config.operatorAvatar, alt: "", class: "pp-avatar" }),
909
+ /* @__PURE__ */ u3("div", { children: [
910
+ /* @__PURE__ */ u3("div", { class: "pp-header-title", children: config.operatorName ?? "Support" }),
911
+ /* @__PURE__ */ u3("div", { class: "pp-header-status", children: operatorOnline ? /* @__PURE__ */ u3(k, { children: [
912
+ /* @__PURE__ */ u3("span", { class: "pp-status-dot pp-online" }),
913
+ " Online"
914
+ ] }) : /* @__PURE__ */ u3(k, { children: [
915
+ /* @__PURE__ */ u3("span", { class: "pp-status-dot" }),
916
+ " Away"
917
+ ] }) })
918
+ ] })
919
+ ] }),
920
+ /* @__PURE__ */ u3(
921
+ "button",
922
+ {
923
+ class: "pp-close-btn",
924
+ onClick: () => client2.setOpen(false),
925
+ "aria-label": "Close chat",
926
+ children: /* @__PURE__ */ u3(CloseIcon, {})
927
+ }
928
+ )
929
+ ] }),
930
+ /* @__PURE__ */ u3("div", { class: "pp-messages", children: [
931
+ config.welcomeMessage && messages.length === 0 && /* @__PURE__ */ u3("div", { class: "pp-welcome", children: config.welcomeMessage }),
932
+ messages.map((msg) => /* @__PURE__ */ u3(
933
+ "div",
934
+ {
935
+ class: `pp-message pp-message-${msg.sender}`,
936
+ children: [
937
+ /* @__PURE__ */ u3("div", { class: "pp-message-content", children: msg.content }),
938
+ /* @__PURE__ */ u3("div", { class: "pp-message-time", children: [
939
+ formatTime(msg.timestamp),
940
+ msg.sender === "ai" && /* @__PURE__ */ u3("span", { class: "pp-ai-badge", children: "AI" }),
941
+ msg.sender === "visitor" && /* @__PURE__ */ u3("span", { class: `pp-status pp-status-${msg.status ?? "sent"}`, children: /* @__PURE__ */ u3(StatusIcon, { status: msg.status }) })
942
+ ] })
943
+ ]
944
+ },
945
+ msg.id
946
+ )),
947
+ isTyping && /* @__PURE__ */ u3("div", { class: "pp-message pp-message-operator pp-typing", children: [
948
+ /* @__PURE__ */ u3("span", {}),
949
+ /* @__PURE__ */ u3("span", {}),
950
+ /* @__PURE__ */ u3("span", {})
951
+ ] }),
952
+ /* @__PURE__ */ u3("div", { ref: messagesEndRef })
953
+ ] }),
954
+ /* @__PURE__ */ u3("form", { class: "pp-input-form", onSubmit: handleSubmit, children: [
955
+ /* @__PURE__ */ u3(
956
+ "input",
957
+ {
958
+ ref: inputRef,
959
+ type: "text",
960
+ class: "pp-input",
961
+ placeholder: config.placeholder ?? "Type a message...",
962
+ value: inputValue,
963
+ onInput: handleInputChange,
964
+ disabled: !isConnected
965
+ }
966
+ ),
967
+ /* @__PURE__ */ u3(
968
+ "button",
969
+ {
970
+ type: "submit",
971
+ class: "pp-send-btn",
972
+ disabled: !inputValue.trim() || !isConnected,
973
+ "aria-label": "Send message",
974
+ children: /* @__PURE__ */ u3(SendIcon, {})
975
+ }
976
+ )
977
+ ] }),
978
+ /* @__PURE__ */ u3("div", { class: "pp-footer", children: [
979
+ "Powered by ",
980
+ /* @__PURE__ */ u3("a", { href: "https://github.com/pocketping/pocketping", target: "_blank", rel: "noopener", children: "PocketPing" })
981
+ ] })
982
+ ] })
983
+ ] });
984
+ }
985
+ function checkPageVisibility(config) {
986
+ const path = window.location.pathname;
987
+ if (config.hideOnPages?.some((pattern) => new RegExp(pattern).test(path))) {
988
+ return false;
989
+ }
990
+ if (config.showOnPages?.length) {
991
+ return config.showOnPages.some((pattern) => new RegExp(pattern).test(path));
992
+ }
993
+ return true;
994
+ }
995
+ function getTheme(theme) {
996
+ if (theme === "auto") {
997
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
998
+ }
999
+ return theme;
1000
+ }
1001
+ function formatTime(timestamp) {
1002
+ const date = new Date(timestamp);
1003
+ return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
1004
+ }
1005
+ function ChatIcon() {
1006
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", children: /* @__PURE__ */ u3("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
1007
+ }
1008
+ function CloseIcon() {
1009
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
1010
+ /* @__PURE__ */ u3("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1011
+ /* @__PURE__ */ u3("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1012
+ ] });
1013
+ }
1014
+ function SendIcon() {
1015
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
1016
+ /* @__PURE__ */ u3("line", { x1: "22", y1: "2", x2: "11", y2: "13" }),
1017
+ /* @__PURE__ */ u3("polygon", { points: "22 2 15 22 11 13 2 9 22 2" })
1018
+ ] });
1019
+ }
1020
+ function StatusIcon({ status }) {
1021
+ if (!status || status === "sending" || status === "sent") {
1022
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", "stroke-width": "2", class: "pp-check", children: /* @__PURE__ */ u3("polyline", { points: "3 8 7 12 13 4" }) });
1023
+ }
1024
+ if (status === "delivered") {
1025
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 20 16", fill: "none", stroke: "currentColor", "stroke-width": "2", class: "pp-check-double", children: [
1026
+ /* @__PURE__ */ u3("polyline", { points: "1 8 5 12 11 4" }),
1027
+ /* @__PURE__ */ u3("polyline", { points: "7 8 11 12 17 4" })
1028
+ ] });
1029
+ }
1030
+ if (status === "read") {
1031
+ return /* @__PURE__ */ u3("svg", { viewBox: "0 0 20 16", fill: "none", stroke: "currentColor", "stroke-width": "2", class: "pp-check-double pp-check-read", children: [
1032
+ /* @__PURE__ */ u3("polyline", { points: "1 8 5 12 11 4" }),
1033
+ /* @__PURE__ */ u3("polyline", { points: "7 8 11 12 17 4" })
1034
+ ] });
1035
+ }
1036
+ return null;
1037
+ }
1038
+
1039
+ // src/client.ts
1040
+ var PocketPingClient = class {
1041
+ constructor(config) {
1042
+ this.session = null;
1043
+ this.ws = null;
1044
+ this.isOpen = false;
1045
+ this.listeners = /* @__PURE__ */ new Map();
1046
+ this.reconnectAttempts = 0;
1047
+ this.maxReconnectAttempts = 5;
1048
+ this.reconnectTimeout = null;
1049
+ this.config = config;
1050
+ }
1051
+ // ─────────────────────────────────────────────────────────────────
1052
+ // Public API
1053
+ // ─────────────────────────────────────────────────────────────────
1054
+ async connect() {
1055
+ const visitorId = this.getOrCreateVisitorId();
1056
+ const storedSessionId = this.getStoredSessionId();
1057
+ const response = await this.fetch("/connect", {
1058
+ method: "POST",
1059
+ body: JSON.stringify({
1060
+ visitorId,
1061
+ sessionId: storedSessionId,
1062
+ metadata: {
1063
+ url: window.location.href,
1064
+ referrer: document.referrer || void 0,
1065
+ pageTitle: document.title || void 0,
1066
+ userAgent: navigator.userAgent,
1067
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
1068
+ language: navigator.language,
1069
+ screenResolution: `${window.screen.width}x${window.screen.height}`
1070
+ }
1071
+ })
1072
+ });
1073
+ this.session = {
1074
+ sessionId: response.sessionId,
1075
+ visitorId: response.visitorId,
1076
+ operatorOnline: response.operatorOnline ?? false,
1077
+ messages: response.messages ?? []
1078
+ };
1079
+ this.storeSessionId(response.sessionId);
1080
+ this.connectWebSocket();
1081
+ this.emit("connect", this.session);
1082
+ this.config.onConnect?.(response.sessionId);
1083
+ return this.session;
1084
+ }
1085
+ disconnect() {
1086
+ this.ws?.close();
1087
+ this.ws = null;
1088
+ this.session = null;
1089
+ if (this.reconnectTimeout) {
1090
+ clearTimeout(this.reconnectTimeout);
1091
+ }
1092
+ }
1093
+ async sendMessage(content) {
1094
+ if (!this.session) {
1095
+ throw new Error("Not connected");
1096
+ }
1097
+ const tempId = `temp-${this.generateId()}`;
1098
+ const tempMessage = {
1099
+ id: tempId,
1100
+ sessionId: this.session.sessionId,
1101
+ content,
1102
+ sender: "visitor",
1103
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1104
+ status: "sending"
1105
+ };
1106
+ this.session.messages.push(tempMessage);
1107
+ this.emit("message", tempMessage);
1108
+ try {
1109
+ const response = await this.fetch("/message", {
1110
+ method: "POST",
1111
+ body: JSON.stringify({
1112
+ sessionId: this.session.sessionId,
1113
+ content,
1114
+ sender: "visitor"
1115
+ })
1116
+ });
1117
+ const messageIndex = this.session.messages.findIndex((m3) => m3.id === tempId);
1118
+ if (messageIndex >= 0) {
1119
+ this.session.messages[messageIndex].id = response.messageId;
1120
+ this.session.messages[messageIndex].timestamp = response.timestamp;
1121
+ this.session.messages[messageIndex].status = "sent";
1122
+ this.emit("message", this.session.messages[messageIndex]);
1123
+ }
1124
+ const message = this.session.messages[messageIndex] || {
1125
+ id: response.messageId,
1126
+ sessionId: this.session.sessionId,
1127
+ content,
1128
+ sender: "visitor",
1129
+ timestamp: response.timestamp,
1130
+ status: "sent"
1131
+ };
1132
+ this.config.onMessage?.(message);
1133
+ return message;
1134
+ } catch (error) {
1135
+ const messageIndex = this.session.messages.findIndex((m3) => m3.id === tempId);
1136
+ if (messageIndex >= 0) {
1137
+ this.session.messages.splice(messageIndex, 1);
1138
+ this.emit("message", tempMessage);
1139
+ }
1140
+ throw error;
1141
+ }
1142
+ }
1143
+ async fetchMessages(after) {
1144
+ if (!this.session) {
1145
+ throw new Error("Not connected");
1146
+ }
1147
+ const params = new URLSearchParams({
1148
+ sessionId: this.session.sessionId
1149
+ });
1150
+ if (after) {
1151
+ params.set("after", after);
1152
+ }
1153
+ const response = await this.fetch(
1154
+ `/messages?${params}`,
1155
+ { method: "GET" }
1156
+ );
1157
+ return response.messages;
1158
+ }
1159
+ async sendTyping(isTyping = true) {
1160
+ if (!this.session) return;
1161
+ await this.fetch("/typing", {
1162
+ method: "POST",
1163
+ body: JSON.stringify({
1164
+ sessionId: this.session.sessionId,
1165
+ sender: "visitor",
1166
+ isTyping
1167
+ })
1168
+ });
1169
+ }
1170
+ async sendReadStatus(messageIds, status) {
1171
+ if (!this.session || messageIds.length === 0) return;
1172
+ try {
1173
+ await this.fetch("/read", {
1174
+ method: "POST",
1175
+ body: JSON.stringify({
1176
+ sessionId: this.session.sessionId,
1177
+ messageIds,
1178
+ status
1179
+ })
1180
+ });
1181
+ for (const msg of this.session.messages) {
1182
+ if (messageIds.includes(msg.id)) {
1183
+ msg.status = status;
1184
+ if (status === "delivered") {
1185
+ msg.deliveredAt = (/* @__PURE__ */ new Date()).toISOString();
1186
+ } else if (status === "read") {
1187
+ msg.readAt = (/* @__PURE__ */ new Date()).toISOString();
1188
+ }
1189
+ }
1190
+ }
1191
+ this.emit("readStatusSent", { messageIds, status });
1192
+ } catch (err) {
1193
+ console.error("[PocketPing] Failed to send read status:", err);
1194
+ }
1195
+ }
1196
+ async getPresence() {
1197
+ return this.fetch("/presence", { method: "GET" });
1198
+ }
1199
+ // ─────────────────────────────────────────────────────────────────
1200
+ // State
1201
+ // ─────────────────────────────────────────────────────────────────
1202
+ getSession() {
1203
+ return this.session;
1204
+ }
1205
+ getMessages() {
1206
+ return this.session?.messages ?? [];
1207
+ }
1208
+ isConnected() {
1209
+ return this.session !== null;
1210
+ }
1211
+ isWidgetOpen() {
1212
+ return this.isOpen;
1213
+ }
1214
+ setOpen(open2) {
1215
+ this.isOpen = open2;
1216
+ this.emit("openChange", open2);
1217
+ if (open2) {
1218
+ this.config.onOpen?.();
1219
+ } else {
1220
+ this.config.onClose?.();
1221
+ }
1222
+ }
1223
+ toggleOpen() {
1224
+ this.setOpen(!this.isOpen);
1225
+ }
1226
+ // ─────────────────────────────────────────────────────────────────
1227
+ // Events
1228
+ // ─────────────────────────────────────────────────────────────────
1229
+ on(event, listener) {
1230
+ if (!this.listeners.has(event)) {
1231
+ this.listeners.set(event, /* @__PURE__ */ new Set());
1232
+ }
1233
+ this.listeners.get(event).add(listener);
1234
+ return () => {
1235
+ this.listeners.get(event)?.delete(listener);
1236
+ };
1237
+ }
1238
+ emit(event, data) {
1239
+ this.listeners.get(event)?.forEach((listener) => listener(data));
1240
+ }
1241
+ // ─────────────────────────────────────────────────────────────────
1242
+ // WebSocket
1243
+ // ─────────────────────────────────────────────────────────────────
1244
+ connectWebSocket() {
1245
+ if (!this.session) return;
1246
+ const wsUrl = this.config.endpoint.replace(/^http/, "ws").replace(/\/$/, "") + `/stream?sessionId=${this.session.sessionId}`;
1247
+ try {
1248
+ this.ws = new WebSocket(wsUrl);
1249
+ this.ws.onopen = () => {
1250
+ this.reconnectAttempts = 0;
1251
+ this.emit("wsConnected", null);
1252
+ };
1253
+ this.ws.onmessage = (event) => {
1254
+ try {
1255
+ const wsEvent = JSON.parse(event.data);
1256
+ this.handleWebSocketEvent(wsEvent);
1257
+ } catch (err) {
1258
+ console.error("[PocketPing] Failed to parse WS message:", err);
1259
+ }
1260
+ };
1261
+ this.ws.onclose = () => {
1262
+ this.emit("wsDisconnected", null);
1263
+ this.scheduleReconnect();
1264
+ };
1265
+ this.ws.onerror = (err) => {
1266
+ console.error("[PocketPing] WebSocket error:", err);
1267
+ };
1268
+ } catch (err) {
1269
+ console.warn("[PocketPing] WebSocket unavailable, using polling");
1270
+ this.startPolling();
1271
+ }
1272
+ }
1273
+ handleWebSocketEvent(event) {
1274
+ switch (event.type) {
1275
+ case "message":
1276
+ const message = event.data;
1277
+ if (this.session) {
1278
+ let existingIndex = this.session.messages.findIndex((m3) => m3.id === message.id);
1279
+ if (existingIndex < 0 && message.sender === "visitor") {
1280
+ existingIndex = this.session.messages.findIndex(
1281
+ (m3) => m3.id.startsWith("temp-") && m3.content === message.content && m3.sender === "visitor"
1282
+ );
1283
+ if (existingIndex >= 0) {
1284
+ this.session.messages[existingIndex].id = message.id;
1285
+ }
1286
+ }
1287
+ if (existingIndex < 0 && message.sender !== "visitor") {
1288
+ const msgTime = new Date(message.timestamp).getTime();
1289
+ existingIndex = this.session.messages.findIndex(
1290
+ (m3) => m3.sender === message.sender && m3.content === message.content && Math.abs(new Date(m3.timestamp).getTime() - msgTime) < 2e3
1291
+ );
1292
+ }
1293
+ if (existingIndex >= 0) {
1294
+ const existing = this.session.messages[existingIndex];
1295
+ if (message.status && message.status !== existing.status) {
1296
+ existing.status = message.status;
1297
+ if (message.deliveredAt) existing.deliveredAt = message.deliveredAt;
1298
+ if (message.readAt) existing.readAt = message.readAt;
1299
+ this.emit("read", { messageIds: [message.id], status: message.status });
1300
+ }
1301
+ } else {
1302
+ this.session.messages.push(message);
1303
+ this.emit("message", message);
1304
+ this.config.onMessage?.(message);
1305
+ }
1306
+ }
1307
+ if (message.sender !== "visitor") {
1308
+ this.emit("typing", { isTyping: false });
1309
+ }
1310
+ break;
1311
+ case "typing":
1312
+ const typingData = event.data;
1313
+ if (typingData.sender !== "visitor") {
1314
+ this.emit("typing", { isTyping: typingData.isTyping });
1315
+ }
1316
+ break;
1317
+ case "presence":
1318
+ if (this.session) {
1319
+ this.session.operatorOnline = event.data.online;
1320
+ }
1321
+ this.emit("presence", event.data);
1322
+ break;
1323
+ case "ai_takeover":
1324
+ this.emit("aiTakeover", event.data);
1325
+ break;
1326
+ case "read":
1327
+ const readData = event.data;
1328
+ if (this.session) {
1329
+ for (const msg of this.session.messages) {
1330
+ if (readData.messageIds.includes(msg.id)) {
1331
+ msg.status = readData.status;
1332
+ if (readData.deliveredAt) msg.deliveredAt = readData.deliveredAt;
1333
+ if (readData.readAt) msg.readAt = readData.readAt;
1334
+ }
1335
+ }
1336
+ }
1337
+ this.emit("read", readData);
1338
+ break;
1339
+ }
1340
+ }
1341
+ scheduleReconnect() {
1342
+ if (this.reconnectAttempts >= this.maxReconnectAttempts) {
1343
+ console.warn("[PocketPing] Max reconnect attempts reached, switching to polling");
1344
+ this.startPolling();
1345
+ return;
1346
+ }
1347
+ const delay = Math.min(1e3 * Math.pow(2, this.reconnectAttempts), 3e4);
1348
+ this.reconnectAttempts++;
1349
+ this.reconnectTimeout = setTimeout(() => {
1350
+ this.connectWebSocket();
1351
+ }, delay);
1352
+ }
1353
+ startPolling() {
1354
+ const poll = async () => {
1355
+ if (!this.session) return;
1356
+ try {
1357
+ const lastMessageId = this.session.messages[this.session.messages.length - 1]?.id;
1358
+ const newMessages = await this.fetchMessages(lastMessageId);
1359
+ for (const message of newMessages) {
1360
+ if (!this.session.messages.find((m3) => m3.id === message.id)) {
1361
+ this.session.messages.push(message);
1362
+ this.emit("message", message);
1363
+ this.config.onMessage?.(message);
1364
+ }
1365
+ }
1366
+ } catch (err) {
1367
+ console.error("[PocketPing] Polling error:", err);
1368
+ }
1369
+ if (this.session) {
1370
+ setTimeout(poll, 3e3);
1371
+ }
1372
+ };
1373
+ poll();
1374
+ }
1375
+ // ─────────────────────────────────────────────────────────────────
1376
+ // HTTP
1377
+ // ─────────────────────────────────────────────────────────────────
1378
+ async fetch(path, options) {
1379
+ const url = this.config.endpoint.replace(/\/$/, "") + path;
1380
+ const response = await fetch(url, {
1381
+ ...options,
1382
+ headers: {
1383
+ "Content-Type": "application/json",
1384
+ ...options.headers
1385
+ }
1386
+ });
1387
+ if (!response.ok) {
1388
+ const error = await response.text();
1389
+ throw new Error(`PocketPing API error: ${response.status} ${error}`);
1390
+ }
1391
+ return response.json();
1392
+ }
1393
+ // ─────────────────────────────────────────────────────────────────
1394
+ // Storage
1395
+ // ─────────────────────────────────────────────────────────────────
1396
+ getOrCreateVisitorId() {
1397
+ const key = "pocketping_visitor_id";
1398
+ let visitorId = localStorage.getItem(key);
1399
+ if (!visitorId) {
1400
+ visitorId = this.generateId();
1401
+ localStorage.setItem(key, visitorId);
1402
+ }
1403
+ return visitorId;
1404
+ }
1405
+ getStoredSessionId() {
1406
+ return localStorage.getItem("pocketping_session_id");
1407
+ }
1408
+ storeSessionId(sessionId) {
1409
+ localStorage.setItem("pocketping_session_id", sessionId);
1410
+ }
1411
+ generateId() {
1412
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 11)}`;
1413
+ }
1414
+ };
1415
+
1416
+ // src/index.ts
1417
+ var client = null;
1418
+ var container = null;
1419
+ function init(config) {
1420
+ if (client) {
1421
+ console.warn("[PocketPing] Already initialized");
1422
+ return client;
1423
+ }
1424
+ if (!config.endpoint) {
1425
+ throw new Error("[PocketPing] endpoint is required");
1426
+ }
1427
+ client = new PocketPingClient(config);
1428
+ container = document.createElement("div");
1429
+ container.id = "pocketping-container";
1430
+ document.body.appendChild(container);
1431
+ G(_(ChatWidget, { client, config }), container);
1432
+ client.connect().catch((err) => {
1433
+ console.error("[PocketPing] Failed to connect:", err);
1434
+ });
1435
+ return client;
1436
+ }
1437
+ function destroy() {
1438
+ if (container) {
1439
+ G(null, container);
1440
+ container.remove();
1441
+ container = null;
1442
+ }
1443
+ if (client) {
1444
+ client.disconnect();
1445
+ client = null;
1446
+ }
1447
+ }
1448
+ function open() {
1449
+ client?.setOpen(true);
1450
+ }
1451
+ function close() {
1452
+ client?.setOpen(false);
1453
+ }
1454
+ function toggle() {
1455
+ client?.toggleOpen();
1456
+ }
1457
+ function sendMessage(content) {
1458
+ if (!client) {
1459
+ throw new Error("[PocketPing] Not initialized");
1460
+ }
1461
+ return client.sendMessage(content);
1462
+ }
1463
+ if (typeof document !== "undefined") {
1464
+ const script = document.currentScript;
1465
+ if (script?.dataset.endpoint) {
1466
+ init({
1467
+ endpoint: script.dataset.endpoint,
1468
+ theme: script.dataset.theme || "auto",
1469
+ position: script.dataset.position || "bottom-right"
1470
+ });
1471
+ }
1472
+ }
1473
+ var index_default = { init, destroy, open, close, toggle, sendMessage };
1474
+ return __toCommonJS(index_exports);
1475
+ })();